-
Notifications
You must be signed in to change notification settings - Fork 112
/
types.ts
259 lines (231 loc) · 6.24 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import type { ReportOpts } from 'web-vitals';
export interface Metric {
/**
* The name of the metric (in acronym form).
*/
name:
| 'CLS'
| 'FCP'
| 'FID'
| 'INP'
| 'LCP'
| 'TTFB'
| 'RT'
| 'TBT'
| 'NTBT'
| 'ET'
| 'INP';
/**
* The current value of the metric.
*/
value: number;
/**
* The rating as to whether the metric value is within the "good",
* "needs improvement", or "poor" thresholds of the metric.
*/
rating: IVitalsScore;
/**
* The delta between the current value and the last-reported value.
* On the first report, `delta` and `value` will always be the same.
*/
delta?: number;
/**
* A unique ID representing this particular metric instance. This ID can
* be used by an analytics tool to dedupe multiple values sent for the same
* metric instance, or to group multiple deltas together and calculate a
* total. It can also be used to differentiate multiple different metric
* instances sent from the same page, which can happen if the page is
* restored from the back/forward cache (in that case new metrics object
* get created).
*/
id?: string;
/**
* Any performance entries relevant to the metric value calculation.
* The array may also be empty if the metric value was not based on any
* entries (e.g. a CLS value of 0 given no layout shifts).
*/
entries?: PerformanceEntry[];
/**
* The type of navigation
*
* Navigation Timing API (or `undefined` if the browser doesn't
* support that API). For pages that are restored from the bfcache, this
* value will be 'back-forward-cache'.
*/
navigationType?: INavigationType;
/**
* An object containing potentially-helpful debugging information that
* can be sent along with the metric value for the current page visit in
* order to help identify issues happening to real-users in the field.
*/
attribution: {
[key: string]: unknown;
};
}
export interface IAnalyticsTrackerOptions {
attribution: object;
data: IPerfumeData;
metricName: string;
navigatorInformation: INavigatorInfo;
rating: IVitalsScore;
navigationType?: INavigationType;
}
interface WebVitalsReportOptions {
ttfb?: ReportOpts;
cls?: ReportOpts;
fcp?: ReportOpts;
fid?: ReportOpts;
lcp?: ReportOpts;
inp?: ReportOpts;
}
export interface IPerfumeConfig {
// Metrics
isResourceTiming: boolean;
isElementTiming: boolean;
// Analytics
analyticsTracker?: (options: IAnalyticsTrackerOptions) => void;
// Logging
maxTime: number;
// web-vitals report options
reportOptions: WebVitalsReportOptions;
// Steps definitions
steps?: IStepsConfig;
// Callback that will run each time a mark is called
onMarkStep?: (mark: string, steps: string[]) => void;
}
export interface IPerfumeOptions {
// Metrics
resourceTiming?: boolean;
elementTiming?: boolean;
// Analytics
analyticsTracker?: (options: IAnalyticsTrackerOptions) => void;
// Logging
maxMeasureTime?: number;
// web-vitals report options
reportOptions?: WebVitalsReportOptions;
// Steps definitions
steps?: IStepsConfig;
// Callback that will run each time a mark is called
onMarkStep?: (mark: string, steps: string[]) => void;
}
export interface IMetricMap {
[measureName: string]: boolean;
}
export interface INavigatorInfo {
deviceMemory?: number;
hardwareConcurrency?: number;
isLowEndDevice?: boolean;
isLowEndExperience?: boolean;
serviceWorkerStatus?: 'controlled' | 'supported' | 'unsupported';
}
export interface IPerfObservers {
[measureName: string]: any;
}
export type IPerformanceObserverType =
| 'first-input'
| 'largest-contentful-paint'
| 'layout-shift'
| 'longtask'
| 'measure'
| 'navigation'
| 'paint'
| 'element'
| 'resource';
export type IPerformanceEntryInitiatorType =
| 'beacon'
| 'css'
| 'fetch'
| 'img'
| 'other'
| 'script'
| 'xmlhttprequest';
export declare interface IPerformanceEntry {
decodedBodySize?: number;
duration: number;
entryType: IPerformanceObserverType;
initiatorType?: IPerformanceEntryInitiatorType;
loadTime: number;
name: string;
renderTime: number;
startTime: number;
hadRecentInput?: boolean;
value?: number;
identifier?: string;
}
// https://wicg.github.io/event-timing/#sec-performance-event-timing
export interface PerformanceEventTiming extends PerformanceEntry {
processingStart: DOMHighResTimeStamp;
target?: Node;
}
export interface IPerformancePaintTiming {
name: string;
entryType: string;
startTime: number;
duration: number;
}
export interface IPerfumeNavigationTiming {
fetchTime?: number;
workerTime?: number;
totalTime?: number;
downloadTime?: number;
timeToFirstByte?: number;
headerSize?: number;
dnsLookupTime?: number;
redirectTime?: number;
}
export type EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g' | 'lte';
export interface IPerfumeNetworkInformation {
downlink?: number;
effectiveType?: EffectiveConnectionType;
onchange?: () => void;
rtt?: number;
saveData?: boolean;
}
export interface IPerfumeDataConsumption {
beacon: number;
css: number;
fetch: number;
img: number;
other: number;
script: number;
total: number;
xmlhttprequest: number;
}
export type IPerfumeData =
| number
| IPerfumeNavigationTiming
| IPerfumeNetworkInformation;
export type IVitalsScore = 'good' | 'needsImprovement' | 'poor' | null;
export type INavigationType =
| 'navigate'
| 'reload'
| 'back-forward'
| 'back-forward-cache'
| 'prerender';
export interface IVitalsThresholds {
vitalsThresholds: [number, number];
}
export interface IOutlierThreshold {
maxOutlierThreshold: number;
}
export enum IThresholdTier {
instant = 'instant',
quick = 'quick',
moderate = 'moderate',
slow = 'slow',
unavoidable = 'unavoidable',
}
export type IStepsThresholdConfig = IVitalsThresholds & IOutlierThreshold;
export type IStepsThresholds = {
[key in IThresholdTier]: IStepsThresholdConfig;
};
export type ISteps<Steps extends string> = {
steps: Steps[];
} & Partial<IOutlierThreshold>;
export interface IStepMarks<Marks extends string> {
marks: [Marks | 'launch', Marks];
}
export type IStepConfig<Marks extends string> = {
threshold: IThresholdTier;
} & IStepMarks<Marks>;
export type IStepsConfig = Record<string, IStepConfig<string>>;