-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.d.ts
176 lines (176 loc) · 5.69 KB
/
index.d.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
/**
* @typedef {{ key: string, fetch?: function }} CreateOptions
* @typedef {{ url?: string, origin?: string, formFactor?: FormFactor, effectiveConnectionType?: Connection }} QueryRecordOptions
* @typedef {'ALL_FORM_FACTORS' | 'PHONE' | 'DESKTOP' | 'TABLET'} FormFactor
* @typedef {'4G' | '3G' | '2G' | 'slow-2G' | 'offline'} Connection
* @typedef {{ histogram: { start: number | string, end: number | string, density: number }[], percentiles: { p75: number | string } }} MetricValue
* @typedef {{ year: number, month: number, day: number }} MetricDate
* @typedef {{ firstDate: MetricDate, lastDate: MetricDate }} CollectionPeriod
* @typedef {{ error: { code: number, message: string, status: string } }} ErrorResponse
* @typedef {{
* record: {
* key: {
* url?: string,
* origin?: string,
* effectiveConnectionType?: Connection,
* formFactor?: FormFactor
* },
* metrics: {
* first_contentful_paint?: MetricValue,
* largest_contentful_paint?: MetricValue,
* first_input_delay?: MetricValue,
* cumulative_layout_shift?: MetricValue,
* interaction_to_next_paint?: MetricValue,
* experimental_time_to_first_byte?: MetricValue,
* },
* collectionPeriod: CollectionPeriod
* },
* urlNormalizationDetails?: {
* originalUrl: string,
* normalizedUrl: string
* }
* }} SuccessResponse
*
* @typedef {(?number | string)[]} PercentileValues
* @typedef {{ start: number, end?: number, densities: (number | 'NaN')[] }} HistorgramTimeserie
* @typedef {{
* histogramTimeseries: HistorgramTimeserie[],
* percentilesTimeseries: { p75s: PercentileValues }
* }} HistoryValue
*
* @typedef {{
* record: {
* key: {
* url?: string,
* origin?: string,
* formFactor?: FormFactor
* },
* metrics: {
* first_input_delay?: HistoryValue,
* first_contentful_paint?: HistoryValue,
* largest_contentful_paint?: HistoryValue,
* cumulative_layout_shift?: HistoryValue,
* interaction_to_next_paint?: HistoryValue,
* experimental_time_to_first_byte?: HistoryValue,
* }
* collectionPeriods: CollectionPeriod[]
* },
* urlNormalizationDetails?: {
* originalUrl: string,
* normalizedUrl: string
* },
* }} HistoryResponse
*/
/** @param {CreateOptions} createOptions @return {function(QueryRecordOptions): Promise<SuccessResponse | null>} */
export function createQueryRecord(createOptions: CreateOptions): (arg0: QueryRecordOptions) => Promise<SuccessResponse | null>;
/** @param {CreateOptions} createOptions @return {function(QueryRecordOptions): Promise<HistoryResponse | null>} */
export function createQueryHistoryRecord(createOptions: CreateOptions): (arg0: QueryRecordOptions) => Promise<HistoryResponse | null>;
/**
* Normalize URL to match CrUX API key.
*
* @param {string} url
*/
export function normalizeUrl(url: string): string;
/**
* Random delay from 1ms to `maxRetryTimeout`.
* Random logic is based on: https://stackoverflow.com/a/29246176
*
* @param {number} retryCounter
* @param {function} request
*/
export function retryAfterTimeout(retryCounter: number, request: Function): Promise<any>;
export type CreateOptions = {
key: string;
fetch?: Function;
};
export type QueryRecordOptions = {
url?: string;
origin?: string;
formFactor?: FormFactor;
effectiveConnectionType?: Connection;
};
export type FormFactor = 'ALL_FORM_FACTORS' | 'PHONE' | 'DESKTOP' | 'TABLET';
export type Connection = '4G' | '3G' | '2G' | 'slow-2G' | 'offline';
export type MetricValue = {
histogram: {
start: number | string;
end: number | string;
density: number;
}[];
percentiles: {
p75: number | string;
};
};
export type MetricDate = {
year: number;
month: number;
day: number;
};
export type CollectionPeriod = {
firstDate: MetricDate;
lastDate: MetricDate;
};
export type ErrorResponse = {
error: {
code: number;
message: string;
status: string;
};
};
export type SuccessResponse = {
record: {
key: {
url?: string;
origin?: string;
effectiveConnectionType?: Connection;
formFactor?: FormFactor;
};
metrics: {
first_contentful_paint?: MetricValue;
largest_contentful_paint?: MetricValue;
first_input_delay?: MetricValue;
cumulative_layout_shift?: MetricValue;
interaction_to_next_paint?: MetricValue;
experimental_time_to_first_byte?: MetricValue;
};
collectionPeriod: CollectionPeriod;
};
urlNormalizationDetails?: {
originalUrl: string;
normalizedUrl: string;
};
};
export type PercentileValues = ((number | string) | null)[];
export type HistorgramTimeserie = {
start: number;
end?: number;
densities: (number | 'NaN')[];
};
export type HistoryValue = {
histogramTimeseries: HistorgramTimeserie[];
percentilesTimeseries: {
p75s: (string | number)[];
};
};
export type HistoryResponse = {
record: {
key: {
url?: string;
origin?: string;
formFactor?: FormFactor;
};
metrics: {
first_input_delay?: HistoryValue;
first_contentful_paint?: HistoryValue;
largest_contentful_paint?: HistoryValue;
cumulative_layout_shift?: HistoryValue;
interaction_to_next_paint?: HistoryValue;
experimental_time_to_first_byte?: HistoryValue;
};
collectionPeriods: CollectionPeriod[];
};
urlNormalizationDetails?: {
originalUrl: string;
normalizedUrl: string;
};
};