ropegeo-common 1.12.6 → 1.12.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/RopeGeoCursorPaginationHttpRequest.d.ts +8 -3
- package/dist/components/RopeGeoCursorPaginationHttpRequest.d.ts.map +1 -1
- package/dist/components/RopeGeoCursorPaginationHttpRequest.js +58 -35
- package/dist/components/RopeGeoHttpRequest.d.ts +8 -3
- package/dist/components/RopeGeoHttpRequest.d.ts.map +1 -1
- package/dist/components/RopeGeoHttpRequest.js +35 -17
- package/dist/components/RopeGeoPaginationHttpRequest.d.ts +9 -4
- package/dist/components/RopeGeoPaginationHttpRequest.d.ts.map +1 -1
- package/dist/components/RopeGeoPaginationHttpRequest.js +59 -31
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -3
- package/dist/helpers/network/index.d.ts +1 -1
- package/dist/helpers/network/index.d.ts.map +1 -1
- package/dist/helpers/network/index.js +2 -3
- package/dist/helpers/network/networkRequestPolicy.d.ts +6 -10
- package/dist/helpers/network/networkRequestPolicy.d.ts.map +1 -1
- package/dist/helpers/network/networkRequestPolicy.js +11 -12
- package/package.json +1 -1
|
@@ -8,10 +8,15 @@ export type RopeGeoCursorPaginationHttpRequestProps<T = unknown> = {
|
|
|
8
8
|
pathParams?: Record<string, string>;
|
|
9
9
|
queryParams: CursorPaginationParams;
|
|
10
10
|
/**
|
|
11
|
-
* Request deadline in seconds for each fetch (initial and `loadMore`).
|
|
12
|
-
*
|
|
11
|
+
* Request deadline in seconds for each fetch (initial and `loadMore`). When omitted, timeout
|
|
12
|
+
* and countdown are disabled.
|
|
13
13
|
*/
|
|
14
14
|
timeoutAfterSeconds?: number;
|
|
15
|
+
/**
|
|
16
|
+
* When `false`, no HTTP requests run and children receive {@link NO_NETWORK_MESSAGE} as the error.
|
|
17
|
+
* Same semantics as `isOnline` on {@link RopeGeoHttpRequest}.
|
|
18
|
+
*/
|
|
19
|
+
isOnline?: boolean;
|
|
15
20
|
/**
|
|
16
21
|
* Response body is parsed via CursorPaginationResults.fromResponseBody (must include resultType).
|
|
17
22
|
* Parsed shape is ValidatedCursorPaginationResponse; children receive result.results as data.
|
|
@@ -26,5 +31,5 @@ export type RopeGeoCursorPaginationHttpRequestProps<T = unknown> = {
|
|
|
26
31
|
timeoutCountdown: number | null;
|
|
27
32
|
}) => ReactNode;
|
|
28
33
|
};
|
|
29
|
-
export declare function RopeGeoCursorPaginationHttpRequest<T = unknown>({ service, method, path, pathParams, queryParams, timeoutAfterSeconds, children, }: RopeGeoCursorPaginationHttpRequestProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export declare function RopeGeoCursorPaginationHttpRequest<T = unknown>({ service, method, path, pathParams, queryParams, timeoutAfterSeconds, isOnline, children, }: RopeGeoCursorPaginationHttpRequestProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
30
35
|
//# sourceMappingURL=RopeGeoCursorPaginationHttpRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RopeGeoCursorPaginationHttpRequest.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoCursorPaginationHttpRequest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"RopeGeoCursorPaginationHttpRequest.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoCursorPaginationHttpRequest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASvC,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAoB,MAAM,sBAAsB,CAAC;AAsCzE,MAAM,MAAM,uCAAuC,CAAC,CAAC,GAAG,OAAO,IAAI;IACjE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,sBAAsB,CAAC;IACpC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,WAAW,EAAE,OAAO,CAAC;QACrB,IAAI,EAAE,CAAC,EAAE,CAAC;QACV,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;QACrB,OAAO,EAAE,OAAO,CAAC;QACjB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KACjC,KAAK,SAAS,CAAC;CACjB,CAAC;AAEF,wBAAgB,kCAAkC,CAAC,CAAC,GAAG,OAAO,EAAE,EAC9D,OAAO,EACP,MAAmB,EACnB,IAAI,EACJ,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,QAAQ,GACT,EAAE,uCAAuC,CAAC,CAAC,CAAC,2CAoQ5C"}
|
|
@@ -30,7 +30,7 @@ function getResponseBody(raw) {
|
|
|
30
30
|
}
|
|
31
31
|
return raw;
|
|
32
32
|
}
|
|
33
|
-
function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.Method.GET, path, pathParams, queryParams, timeoutAfterSeconds, children, }) {
|
|
33
|
+
function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.Method.GET, path, pathParams, queryParams, timeoutAfterSeconds, isOnline, children, }) {
|
|
34
34
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
35
35
|
const [loadingMore, setLoadingMore] = (0, react_1.useState)(false);
|
|
36
36
|
const [data, setData] = (0, react_1.useState)([]);
|
|
@@ -48,6 +48,14 @@ function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpReque
|
|
|
48
48
|
return new URL(fullPath, baseUrl).toString();
|
|
49
49
|
}, [service, path, pathParams]);
|
|
50
50
|
(0, react_1.useEffect)(() => {
|
|
51
|
+
if (isOnline === false) {
|
|
52
|
+
setData([]);
|
|
53
|
+
setParams(queryParams);
|
|
54
|
+
setLoading(false);
|
|
55
|
+
setErrors(new Error(network_1.NO_NETWORK_MESSAGE));
|
|
56
|
+
setTimeoutCountdown(null);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
51
59
|
let cancelled = false;
|
|
52
60
|
const abortController = new AbortController();
|
|
53
61
|
const timedOutRef = { current: false };
|
|
@@ -58,21 +66,23 @@ function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpReque
|
|
|
58
66
|
setLoading(true);
|
|
59
67
|
setErrors(null);
|
|
60
68
|
setTimeoutCountdown(null);
|
|
61
|
-
const policyDispose =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
const policyDispose = timeoutMs == null
|
|
70
|
+
? () => { }
|
|
71
|
+
: (0, network_1.installNetworkRequestPolicyTimers)(requestStartedAt, timeoutMs, {
|
|
72
|
+
isActive: () => !cancelled,
|
|
73
|
+
onTimeoutCountdown: (seconds) => {
|
|
74
|
+
if (!cancelled)
|
|
75
|
+
setTimeoutCountdown(seconds);
|
|
76
|
+
},
|
|
77
|
+
onClearTimeoutCountdown: () => {
|
|
78
|
+
if (!cancelled)
|
|
79
|
+
setTimeoutCountdown(null);
|
|
80
|
+
},
|
|
81
|
+
onHardTimeout: () => {
|
|
82
|
+
timedOutRef.current = true;
|
|
83
|
+
abortController.abort();
|
|
84
|
+
},
|
|
85
|
+
});
|
|
76
86
|
const url = buildUrl(queryParams);
|
|
77
87
|
const init = {
|
|
78
88
|
method,
|
|
@@ -146,13 +156,24 @@ function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpReque
|
|
|
146
156
|
policyDispose();
|
|
147
157
|
abortController.abort();
|
|
148
158
|
};
|
|
149
|
-
}, [
|
|
159
|
+
}, [
|
|
160
|
+
service,
|
|
161
|
+
method,
|
|
162
|
+
path,
|
|
163
|
+
pathParams,
|
|
164
|
+
queryParams,
|
|
165
|
+
buildUrl,
|
|
166
|
+
timeoutAfterSeconds,
|
|
167
|
+
isOnline,
|
|
168
|
+
]);
|
|
150
169
|
(0, react_1.useEffect)(() => {
|
|
151
170
|
return () => {
|
|
152
171
|
loadMoreAbortRef.current?.abort();
|
|
153
172
|
};
|
|
154
173
|
}, []);
|
|
155
174
|
const loadMore = (0, react_1.useCallback)(() => {
|
|
175
|
+
if (isOnline === false)
|
|
176
|
+
return;
|
|
156
177
|
if (params.cursor == null)
|
|
157
178
|
return;
|
|
158
179
|
if (loadingMoreRef.current)
|
|
@@ -164,23 +185,25 @@ function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpReque
|
|
|
164
185
|
const timedOutRef = { current: false };
|
|
165
186
|
const requestStartedAt = Date.now();
|
|
166
187
|
const timeoutMs = (0, network_1.resolveRequestTimeoutMs)(timeoutAfterSeconds);
|
|
167
|
-
const policyDispose =
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
188
|
+
const policyDispose = timeoutMs == null
|
|
189
|
+
? () => { }
|
|
190
|
+
: (0, network_1.installNetworkRequestPolicyTimers)(requestStartedAt, timeoutMs, {
|
|
191
|
+
isActive: () => loadMoreAbortRef.current === outer,
|
|
192
|
+
onTimeoutCountdown: (seconds) => {
|
|
193
|
+
if (loadMoreAbortRef.current === outer) {
|
|
194
|
+
setTimeoutCountdown(seconds);
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
onClearTimeoutCountdown: () => {
|
|
198
|
+
if (loadMoreAbortRef.current === outer) {
|
|
199
|
+
setTimeoutCountdown(null);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
onHardTimeout: () => {
|
|
203
|
+
timedOutRef.current = true;
|
|
204
|
+
outer.abort();
|
|
205
|
+
},
|
|
206
|
+
});
|
|
184
207
|
const url = buildUrl(params);
|
|
185
208
|
const init = {
|
|
186
209
|
method,
|
|
@@ -234,7 +257,7 @@ function RopeGeoCursorPaginationHttpRequest({ service, method = RopeGeoHttpReque
|
|
|
234
257
|
loadingMoreRef.current = false;
|
|
235
258
|
setLoadingMore(false);
|
|
236
259
|
});
|
|
237
|
-
}, [params, method, buildUrl, timeoutAfterSeconds]);
|
|
260
|
+
}, [params, method, buildUrl, timeoutAfterSeconds, isOnline]);
|
|
238
261
|
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children({
|
|
239
262
|
loading,
|
|
240
263
|
loadingMore,
|
|
@@ -19,10 +19,15 @@ export type RopeGeoHttpRequestProps<T = unknown> = {
|
|
|
19
19
|
queryParams?: Record<string, string | number | boolean | undefined>;
|
|
20
20
|
body?: object;
|
|
21
21
|
/**
|
|
22
|
-
* Request deadline in seconds (abort + timeout error).
|
|
23
|
-
* (`NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS` from `ropegeo-common/helpers`) when omitted.
|
|
22
|
+
* Request deadline in seconds (abort + timeout error). When omitted, no timeout is enforced.
|
|
24
23
|
*/
|
|
25
24
|
timeoutAfterSeconds?: number;
|
|
25
|
+
/**
|
|
26
|
+
* When `false`, the request is not started and children receive {@link NO_NETWORK_MESSAGE} as the
|
|
27
|
+
* error. When `true` or omitted, behavior is unchanged. Pass from app-level connectivity (e.g.
|
|
28
|
+
* `expo-network`) so fetches are not fired while offline.
|
|
29
|
+
*/
|
|
30
|
+
isOnline?: boolean;
|
|
26
31
|
/**
|
|
27
32
|
* Response body is parsed via Result.fromResponseBody (must include resultType and result).
|
|
28
33
|
* Children receive the validated result.result as data (typed by T).
|
|
@@ -39,5 +44,5 @@ export type RopeGeoHttpRequestProps<T = unknown> = {
|
|
|
39
44
|
timeoutCountdown: number | null;
|
|
40
45
|
}) => ReactNode;
|
|
41
46
|
};
|
|
42
|
-
export declare function RopeGeoHttpRequest<T = unknown>({ service, method, path, pathParams, queryParams, body, timeoutAfterSeconds, children, }: RopeGeoHttpRequestProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export declare function RopeGeoHttpRequest<T = unknown>({ service, method, path, pathParams, queryParams, body, timeoutAfterSeconds, isOnline, children, }: RopeGeoHttpRequestProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
43
48
|
//# sourceMappingURL=RopeGeoHttpRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RopeGeoHttpRequest.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoHttpRequest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"RopeGeoHttpRequest.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoHttpRequest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAWvC,eAAO,MAAM,OAAO;;CAEV,CAAC;AACX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE7D,eAAO,MAAM,MAAM;;;;;CAKT,CAAC;AACX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAEpD,CAAC;AAmCF,MAAM,MAAM,uBAAuB,CAAC,CAAC,GAAG,OAAO,IAAI;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACf,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;QACrB;;;;WAIG;QACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KACjC,KAAK,SAAS,CAAC;CACjB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAAE,EAC9C,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,WAAW,EACX,IAAI,EACJ,mBAAmB,EACnB,QAAQ,EACR,QAAQ,GACT,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAyJ5B"}
|
|
@@ -40,7 +40,7 @@ function buildUrl(baseUrl, path, pathParams, queryParams) {
|
|
|
40
40
|
}
|
|
41
41
|
return url.toString();
|
|
42
42
|
}
|
|
43
|
-
function RopeGeoHttpRequest({ service, method, path, pathParams, queryParams, body, timeoutAfterSeconds, children, }) {
|
|
43
|
+
function RopeGeoHttpRequest({ service, method, path, pathParams, queryParams, body, timeoutAfterSeconds, isOnline, children, }) {
|
|
44
44
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
45
45
|
const [data, setData] = (0, react_1.useState)(null);
|
|
46
46
|
const [errors, setErrors] = (0, react_1.useState)(null);
|
|
@@ -53,6 +53,13 @@ function RopeGeoHttpRequest({ service, method, path, pathParams, queryParams, bo
|
|
|
53
53
|
? JSON.stringify(body)
|
|
54
54
|
: body;
|
|
55
55
|
(0, react_1.useEffect)(() => {
|
|
56
|
+
if (isOnline === false) {
|
|
57
|
+
setLoading(false);
|
|
58
|
+
setData(null);
|
|
59
|
+
setErrors(new Error(network_1.NO_NETWORK_MESSAGE));
|
|
60
|
+
setTimeoutCountdown(null);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
56
63
|
let cancelled = false;
|
|
57
64
|
const abortController = new AbortController();
|
|
58
65
|
const timedOutRef = { current: false };
|
|
@@ -61,21 +68,23 @@ function RopeGeoHttpRequest({ service, method, path, pathParams, queryParams, bo
|
|
|
61
68
|
setLoading(true);
|
|
62
69
|
setErrors(null);
|
|
63
70
|
setTimeoutCountdown(null);
|
|
64
|
-
const policyDispose =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
const policyDispose = timeoutMs == null
|
|
72
|
+
? () => { }
|
|
73
|
+
: (0, network_1.installNetworkRequestPolicyTimers)(requestStartedAt, timeoutMs, {
|
|
74
|
+
isActive: () => !cancelled,
|
|
75
|
+
onTimeoutCountdown: (seconds) => {
|
|
76
|
+
if (!cancelled)
|
|
77
|
+
setTimeoutCountdown(seconds);
|
|
78
|
+
},
|
|
79
|
+
onClearTimeoutCountdown: () => {
|
|
80
|
+
if (!cancelled)
|
|
81
|
+
setTimeoutCountdown(null);
|
|
82
|
+
},
|
|
83
|
+
onHardTimeout: () => {
|
|
84
|
+
timedOutRef.current = true;
|
|
85
|
+
abortController.abort();
|
|
86
|
+
},
|
|
87
|
+
});
|
|
79
88
|
const baseUrl = exports.SERVICE_BASE_URL[service];
|
|
80
89
|
const url = buildUrl(baseUrl, path, pathParams, queryParams);
|
|
81
90
|
const init = {
|
|
@@ -152,7 +161,16 @@ function RopeGeoHttpRequest({ service, method, path, pathParams, queryParams, bo
|
|
|
152
161
|
policyDispose();
|
|
153
162
|
abortController.abort();
|
|
154
163
|
};
|
|
155
|
-
}, [
|
|
164
|
+
}, [
|
|
165
|
+
service,
|
|
166
|
+
method,
|
|
167
|
+
path,
|
|
168
|
+
pathParamsKey,
|
|
169
|
+
queryParamsKey,
|
|
170
|
+
bodyKey,
|
|
171
|
+
timeoutAfterSeconds,
|
|
172
|
+
isOnline,
|
|
173
|
+
]);
|
|
156
174
|
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children({
|
|
157
175
|
loading,
|
|
158
176
|
data,
|
|
@@ -14,10 +14,15 @@ export type RopeGeoPaginationHttpRequestProps<T = unknown> = {
|
|
|
14
14
|
*/
|
|
15
15
|
batchSize?: number;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* Deadline in seconds for each request phase: initial page fetch, then each concurrent page batch.
|
|
18
|
+
* When omitted, timeout and countdown are disabled.
|
|
19
19
|
*/
|
|
20
20
|
timeoutAfterSeconds?: number;
|
|
21
|
+
/**
|
|
22
|
+
* When `false`, no HTTP requests run and children receive {@link NO_NETWORK_MESSAGE} as the error.
|
|
23
|
+
* Same semantics as `isOnline` on {@link RopeGeoHttpRequest}.
|
|
24
|
+
*/
|
|
25
|
+
isOnline?: boolean;
|
|
21
26
|
children: (args: {
|
|
22
27
|
loading: boolean;
|
|
23
28
|
received: number;
|
|
@@ -29,7 +34,7 @@ export type RopeGeoPaginationHttpRequestProps<T = unknown> = {
|
|
|
29
34
|
data: T[] | null;
|
|
30
35
|
/** Set when `data` is `null` after a terminal failure; cleared only when all pages succeed. */
|
|
31
36
|
errors: Error | null;
|
|
32
|
-
/** Timeout countdown for the
|
|
37
|
+
/** Timeout countdown for the active phase (initial page or current batch); `null` between phases. */
|
|
33
38
|
timeoutCountdown: number | null;
|
|
34
39
|
}) => ReactNode;
|
|
35
40
|
};
|
|
@@ -39,5 +44,5 @@ export type RopeGeoPaginationHttpRequestProps<T = unknown> = {
|
|
|
39
44
|
* {@link PaginationResults.fromResponseBody}. Final `data` is pages concatenated in page order.
|
|
40
45
|
* In-flight requests use one {@link AbortController}: unmount or any failure aborts the rest.
|
|
41
46
|
*/
|
|
42
|
-
export declare function RopeGeoPaginationHttpRequest<T = unknown>({ service, method, path, pathParams, queryParams, batchSize, timeoutAfterSeconds, children, }: RopeGeoPaginationHttpRequestProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export declare function RopeGeoPaginationHttpRequest<T = unknown>({ service, method, path, pathParams, queryParams, batchSize, timeoutAfterSeconds, isOnline, children, }: RopeGeoPaginationHttpRequestProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
43
48
|
//# sourceMappingURL=RopeGeoPaginationHttpRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RopeGeoPaginationHttpRequest.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoPaginationHttpRequest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"RopeGeoPaginationHttpRequest.d.ts","sourceRoot":"","sources":["../../src/components/RopeGeoPaginationHttpRequest.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUvC,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAoB,MAAM,sBAAsB,CAAC;AA8DzE,MAAM,MAAM,iCAAiC,CAAC,CAAC,GAAG,OAAO,IAAI;IAC3D,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,gBAAgB,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB;;;WAGG;QACH,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,+FAA+F;QAC/F,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;QACrB,qGAAqG;QACrG,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KACjC,KAAK,SAAS,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,GAAG,OAAO,EAAE,EACxD,OAAO,EACP,MAAmB,EACnB,IAAI,EACJ,UAAU,EACV,WAAW,EACX,SAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,QAAQ,GACT,EAAE,iCAAiC,CAAC,CAAC,CAAC,2CAuPtC"}
|
|
@@ -57,7 +57,7 @@ function concatPaginationResultItemsSorted(pagesByNum) {
|
|
|
57
57
|
* {@link PaginationResults.fromResponseBody}. Final `data` is pages concatenated in page order.
|
|
58
58
|
* In-flight requests use one {@link AbortController}: unmount or any failure aborts the rest.
|
|
59
59
|
*/
|
|
60
|
-
function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.Method.GET, path, pathParams, queryParams, batchSize = 10, timeoutAfterSeconds, children, }) {
|
|
60
|
+
function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.Method.GET, path, pathParams, queryParams, batchSize = 10, timeoutAfterSeconds, isOnline, children, }) {
|
|
61
61
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
62
62
|
const [received, setReceived] = (0, react_1.useState)(0);
|
|
63
63
|
const [total, setTotal] = (0, react_1.useState)(null);
|
|
@@ -68,6 +68,15 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
68
68
|
const queryParamsKey = queryParams.toQueryString();
|
|
69
69
|
const effectiveBatch = Math.max(1, Math.floor(batchSize));
|
|
70
70
|
(0, react_1.useEffect)(() => {
|
|
71
|
+
if (isOnline === false) {
|
|
72
|
+
setLoading(false);
|
|
73
|
+
setReceived(0);
|
|
74
|
+
setTotal(null);
|
|
75
|
+
setData(null);
|
|
76
|
+
setErrors(new Error(network_1.NO_NETWORK_MESSAGE));
|
|
77
|
+
setTimeoutCountdown(null);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
71
80
|
let cancelled = false;
|
|
72
81
|
const abortController = new AbortController();
|
|
73
82
|
const { signal } = abortController;
|
|
@@ -87,6 +96,47 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
87
96
|
(async () => {
|
|
88
97
|
const pagesByNum = new Map();
|
|
89
98
|
const limit = queryParams.limit;
|
|
99
|
+
let activePolicyDispose = null;
|
|
100
|
+
const clearActivePolicy = () => {
|
|
101
|
+
activePolicyDispose?.();
|
|
102
|
+
activePolicyDispose = null;
|
|
103
|
+
};
|
|
104
|
+
const runWithPhaseCountdown = async (runner) => {
|
|
105
|
+
if (timeoutMs == null) {
|
|
106
|
+
if (!cancelled)
|
|
107
|
+
setTimeoutCountdown(null);
|
|
108
|
+
return runner();
|
|
109
|
+
}
|
|
110
|
+
let phaseTimedOut = false;
|
|
111
|
+
clearActivePolicy();
|
|
112
|
+
activePolicyDispose = (0, network_1.installNetworkRequestPolicyTimers)(Date.now(), timeoutMs, {
|
|
113
|
+
isActive: () => !cancelled,
|
|
114
|
+
onTimeoutCountdown: (seconds) => {
|
|
115
|
+
if (!cancelled)
|
|
116
|
+
setTimeoutCountdown(seconds);
|
|
117
|
+
},
|
|
118
|
+
onClearTimeoutCountdown: () => {
|
|
119
|
+
if (!cancelled)
|
|
120
|
+
setTimeoutCountdown(null);
|
|
121
|
+
},
|
|
122
|
+
onHardTimeout: () => {
|
|
123
|
+
phaseTimedOut = true;
|
|
124
|
+
abortController.abort();
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
try {
|
|
128
|
+
return await runner();
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
if (phaseTimedOut) {
|
|
132
|
+
throw new Error(network_1.NETWORK_REQUEST_TIMED_OUT_MESSAGE);
|
|
133
|
+
}
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
clearActivePolicy();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
90
140
|
const fetchPage = async (pageNum) => {
|
|
91
141
|
const params = queryParams.withPage(pageNum);
|
|
92
142
|
const queryString = params.toQueryString();
|
|
@@ -94,31 +144,14 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
94
144
|
? `${resolvedPath}?${queryString}`
|
|
95
145
|
: resolvedPath;
|
|
96
146
|
const url = new URL(fullPath, baseUrl).toString();
|
|
97
|
-
let pageOnePolicyDispose = null;
|
|
98
|
-
const pageOneTimedOutRef = { current: false };
|
|
99
|
-
if (pageNum === 1) {
|
|
100
|
-
const startedAt = Date.now();
|
|
101
|
-
pageOnePolicyDispose = (0, network_1.installNetworkRequestPolicyTimers)(startedAt, timeoutMs, {
|
|
102
|
-
isActive: () => !cancelled,
|
|
103
|
-
onTimeoutCountdown: (seconds) => {
|
|
104
|
-
if (!cancelled)
|
|
105
|
-
setTimeoutCountdown(seconds);
|
|
106
|
-
},
|
|
107
|
-
onClearTimeoutCountdown: () => {
|
|
108
|
-
if (!cancelled)
|
|
109
|
-
setTimeoutCountdown(null);
|
|
110
|
-
},
|
|
111
|
-
onHardTimeout: () => {
|
|
112
|
-
pageOneTimedOutRef.current = true;
|
|
113
|
-
abortController.abort();
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
147
|
let merged = null;
|
|
118
148
|
let signalForFetch;
|
|
119
149
|
if (pageNum === 1) {
|
|
120
150
|
signalForFetch = signal;
|
|
121
151
|
}
|
|
152
|
+
else if (timeoutMs == null) {
|
|
153
|
+
signalForFetch = signal;
|
|
154
|
+
}
|
|
122
155
|
else {
|
|
123
156
|
merged = (0, network_1.mergeParentSignalWithDeadline)(signal, timeoutMs);
|
|
124
157
|
signalForFetch = merged.signal;
|
|
@@ -164,21 +197,14 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
164
197
|
abortController.abort();
|
|
165
198
|
throw new Error(network_1.NETWORK_REQUEST_TIMED_OUT_MESSAGE);
|
|
166
199
|
}
|
|
167
|
-
if (pageNum === 1 && pageOneTimedOutRef.current) {
|
|
168
|
-
throw new Error(network_1.NETWORK_REQUEST_TIMED_OUT_MESSAGE);
|
|
169
|
-
}
|
|
170
200
|
throw err;
|
|
171
201
|
}
|
|
172
202
|
finally {
|
|
173
|
-
pageOnePolicyDispose?.();
|
|
174
203
|
merged?.dispose();
|
|
175
|
-
if (pageNum === 1 && !cancelled) {
|
|
176
|
-
setTimeoutCountdown(null);
|
|
177
|
-
}
|
|
178
204
|
}
|
|
179
205
|
};
|
|
180
206
|
try {
|
|
181
|
-
const first = await fetchPage(1);
|
|
207
|
+
const first = await runWithPhaseCountdown(() => fetchPage(1));
|
|
182
208
|
if (cancelled)
|
|
183
209
|
return;
|
|
184
210
|
pagesByNum.set(1, first);
|
|
@@ -206,14 +232,14 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
206
232
|
if (sumReceived(pagesByNum) >= totalCount)
|
|
207
233
|
break;
|
|
208
234
|
const chunk = toFetch.slice(i, i + effectiveBatch);
|
|
209
|
-
await Promise.all(chunk.map(async (pageNum) => {
|
|
235
|
+
await runWithPhaseCountdown(() => Promise.all(chunk.map(async (pageNum) => {
|
|
210
236
|
const parsed = await fetchPage(pageNum);
|
|
211
237
|
if (cancelled)
|
|
212
238
|
return;
|
|
213
239
|
pagesByNum.set(pageNum, parsed);
|
|
214
240
|
setReceived(sumReceived(pagesByNum));
|
|
215
241
|
setTotal(totalCount);
|
|
216
|
-
}));
|
|
242
|
+
})));
|
|
217
243
|
if (cancelled)
|
|
218
244
|
return;
|
|
219
245
|
if (sumReceived(pagesByNum) >= totalCount)
|
|
@@ -234,6 +260,7 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
234
260
|
setData(null);
|
|
235
261
|
}
|
|
236
262
|
finally {
|
|
263
|
+
clearActivePolicy();
|
|
237
264
|
if (!cancelled)
|
|
238
265
|
setLoading(false);
|
|
239
266
|
}
|
|
@@ -251,6 +278,7 @@ function RopeGeoPaginationHttpRequest({ service, method = RopeGeoHttpRequest_1.M
|
|
|
251
278
|
queryParams,
|
|
252
279
|
effectiveBatch,
|
|
253
280
|
timeoutAfterSeconds,
|
|
281
|
+
isOnline,
|
|
254
282
|
]);
|
|
255
283
|
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children({
|
|
256
284
|
loading,
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { httpRequest } from './httpRequest';
|
|
2
2
|
export { default as ProgressLogger } from './progressLogger';
|
|
3
3
|
export { timeoutAfter } from './timeoutAfter';
|
|
4
|
-
export {
|
|
4
|
+
export { NETWORK_REQUEST_TIMED_OUT_MESSAGE, installNetworkRequestPolicyTimers, isAbortError, isNetworkRequestTimeoutError, mergeParentSignalWithDeadline, resolveRequestTimeoutMs, type MergedDeadlineHandles, type NetworkRequestPolicyTimerCallbacks, } from './network';
|
|
5
5
|
export { getS3Client, resetS3ClientForTests } from './s3/getS3Client';
|
|
6
6
|
export { default as listS3Objects, type S3ObjectEntry } from './s3/listS3Objects';
|
|
7
7
|
export { default as getS3Object, type GetS3ObjectResult } from './s3/getS3Object';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACH,iCAAiC,EACjC,iCAAiC,EACjC,YAAY,EACZ,4BAA4B,EAC5B,6BAA6B,EAC7B,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,kCAAkC,GAC1C,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAEvG,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createCloudFrontInvalidation = exports.changeSQSMessageVisibilityTimeout = exports.deleteSQSMessage = exports.sendSQSMessage = exports.resetSQSClientForTests = exports.getSQSClient = exports.replaceS3Folder = exports.putS3Folder = exports.listS3Folder = exports.deleteS3Object = exports.putS3Object = exports.getS3Object = exports.listS3Objects = exports.resetS3ClientForTests = exports.getS3Client = exports.resolveRequestTimeoutMs = exports.mergeParentSignalWithDeadline = exports.isNetworkRequestTimeoutError = exports.isAbortError = exports.installNetworkRequestPolicyTimers = exports.NETWORK_REQUEST_TIMED_OUT_MESSAGE = exports.
|
|
6
|
+
exports.createCloudFrontInvalidation = exports.changeSQSMessageVisibilityTimeout = exports.deleteSQSMessage = exports.sendSQSMessage = exports.resetSQSClientForTests = exports.getSQSClient = exports.replaceS3Folder = exports.putS3Folder = exports.listS3Folder = exports.deleteS3Object = exports.putS3Object = exports.getS3Object = exports.listS3Objects = exports.resetS3ClientForTests = exports.getS3Client = exports.resolveRequestTimeoutMs = exports.mergeParentSignalWithDeadline = exports.isNetworkRequestTimeoutError = exports.isAbortError = exports.installNetworkRequestPolicyTimers = exports.NETWORK_REQUEST_TIMED_OUT_MESSAGE = exports.timeoutAfter = exports.ProgressLogger = exports.httpRequest = void 0;
|
|
7
7
|
var httpRequest_1 = require("./httpRequest");
|
|
8
8
|
Object.defineProperty(exports, "httpRequest", { enumerable: true, get: function () { return httpRequest_1.httpRequest; } });
|
|
9
9
|
var progressLogger_1 = require("./progressLogger");
|
|
@@ -11,8 +11,6 @@ Object.defineProperty(exports, "ProgressLogger", { enumerable: true, get: functi
|
|
|
11
11
|
var timeoutAfter_1 = require("./timeoutAfter");
|
|
12
12
|
Object.defineProperty(exports, "timeoutAfter", { enumerable: true, get: function () { return timeoutAfter_1.timeoutAfter; } });
|
|
13
13
|
var network_1 = require("./network");
|
|
14
|
-
Object.defineProperty(exports, "NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS", { enumerable: true, get: function () { return network_1.NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS; } });
|
|
15
|
-
Object.defineProperty(exports, "NETWORK_REQUEST_HARD_TIMEOUT_MS", { enumerable: true, get: function () { return network_1.NETWORK_REQUEST_HARD_TIMEOUT_MS; } });
|
|
16
14
|
Object.defineProperty(exports, "NETWORK_REQUEST_TIMED_OUT_MESSAGE", { enumerable: true, get: function () { return network_1.NETWORK_REQUEST_TIMED_OUT_MESSAGE; } });
|
|
17
15
|
Object.defineProperty(exports, "installNetworkRequestPolicyTimers", { enumerable: true, get: function () { return network_1.installNetworkRequestPolicyTimers; } });
|
|
18
16
|
Object.defineProperty(exports, "isAbortError", { enumerable: true, get: function () { return network_1.isAbortError; } });
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Published as `ropegeo-common/helpers/network`. Prefer this entry over `ropegeo-common/helpers` in
|
|
4
4
|
* Metro/RN bundles so the full helpers barrel (S3 folder upload, etc.) is not resolved.
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
6
|
+
export { NETWORK_REQUEST_TIMED_OUT_MESSAGE, NO_NETWORK_MESSAGE, installNetworkRequestPolicyTimers, isAbortError, isNetworkRequestTimeoutError, mergeParentSignalWithDeadline, resolveRequestTimeoutMs, type MergedDeadlineHandles, type NetworkRequestPolicyTimerCallbacks, } from "./networkRequestPolicy";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/network/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/network/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iCAAiC,EACjC,kBAAkB,EAClB,iCAAiC,EACjC,YAAY,EACZ,4BAA4B,EAC5B,6BAA6B,EAC7B,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,kCAAkC,GACxC,MAAM,wBAAwB,CAAC"}
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* Metro/RN bundles so the full helpers barrel (S3 folder upload, etc.) is not resolved.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.resolveRequestTimeoutMs = exports.mergeParentSignalWithDeadline = exports.isNetworkRequestTimeoutError = exports.isAbortError = exports.installNetworkRequestPolicyTimers = exports.
|
|
8
|
+
exports.resolveRequestTimeoutMs = exports.mergeParentSignalWithDeadline = exports.isNetworkRequestTimeoutError = exports.isAbortError = exports.installNetworkRequestPolicyTimers = exports.NO_NETWORK_MESSAGE = exports.NETWORK_REQUEST_TIMED_OUT_MESSAGE = void 0;
|
|
9
9
|
var networkRequestPolicy_1 = require("./networkRequestPolicy");
|
|
10
|
-
Object.defineProperty(exports, "NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS", { enumerable: true, get: function () { return networkRequestPolicy_1.NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS; } });
|
|
11
|
-
Object.defineProperty(exports, "NETWORK_REQUEST_HARD_TIMEOUT_MS", { enumerable: true, get: function () { return networkRequestPolicy_1.NETWORK_REQUEST_HARD_TIMEOUT_MS; } });
|
|
12
10
|
Object.defineProperty(exports, "NETWORK_REQUEST_TIMED_OUT_MESSAGE", { enumerable: true, get: function () { return networkRequestPolicy_1.NETWORK_REQUEST_TIMED_OUT_MESSAGE; } });
|
|
11
|
+
Object.defineProperty(exports, "NO_NETWORK_MESSAGE", { enumerable: true, get: function () { return networkRequestPolicy_1.NO_NETWORK_MESSAGE; } });
|
|
13
12
|
Object.defineProperty(exports, "installNetworkRequestPolicyTimers", { enumerable: true, get: function () { return networkRequestPolicy_1.installNetworkRequestPolicyTimers; } });
|
|
14
13
|
Object.defineProperty(exports, "isAbortError", { enumerable: true, get: function () { return networkRequestPolicy_1.isAbortError; } });
|
|
15
14
|
Object.defineProperty(exports, "isNetworkRequestTimeoutError", { enumerable: true, get: function () { return networkRequestPolicy_1.isNetworkRequestTimeoutError; } });
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defaults for HTTP wrappers and other network clients (see plan: mobile-network-resilience).
|
|
3
|
-
* Apps may pass their own deadline via `timeoutAfterSeconds` on components; when omitted,
|
|
4
|
-
* {@link NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS} applies.
|
|
5
|
-
*/
|
|
6
|
-
export declare const NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS = 30;
|
|
7
|
-
export declare const NETWORK_REQUEST_HARD_TIMEOUT_MS: number;
|
|
1
|
+
/** Network helpers for optional request deadlines and timeout countdowns. */
|
|
8
2
|
/** Use this exact message so callers can detect timeout vs other failures. */
|
|
9
3
|
export declare const NETWORK_REQUEST_TIMED_OUT_MESSAGE = "Network request timed out";
|
|
4
|
+
/** Use this exact message for client-side offline gating and RN fetch failures treated as offline. */
|
|
5
|
+
export declare const NO_NETWORK_MESSAGE = "No network connection";
|
|
10
6
|
export declare function isNetworkRequestTimeoutError(e: unknown): boolean;
|
|
11
7
|
export declare function isAbortError(e: unknown): boolean;
|
|
12
|
-
/** Milliseconds for `timeoutAfterSeconds` on request components
|
|
13
|
-
export declare function resolveRequestTimeoutMs(timeoutAfterSeconds?: number): number;
|
|
8
|
+
/** Milliseconds for `timeoutAfterSeconds` on request components; `null` when timeout is disabled. */
|
|
9
|
+
export declare function resolveRequestTimeoutMs(timeoutAfterSeconds?: number): number | null;
|
|
14
10
|
export type NetworkRequestPolicyTimerCallbacks = {
|
|
15
11
|
isActive: () => boolean;
|
|
16
12
|
onTimeoutCountdown: (secondsRemaining: number) => void;
|
|
@@ -33,5 +29,5 @@ export type MergedDeadlineHandles = {
|
|
|
33
29
|
* Call `dispose()` after the request settles to clear the timer; then `consumeDidTimeout()` to see
|
|
34
30
|
* whether the deadline fired (vs parent abort only).
|
|
35
31
|
*/
|
|
36
|
-
export declare function mergeParentSignalWithDeadline(parentSignal: AbortSignal, deadlineMs
|
|
32
|
+
export declare function mergeParentSignalWithDeadline(parentSignal: AbortSignal, deadlineMs: number): MergedDeadlineHandles;
|
|
37
33
|
//# sourceMappingURL=networkRequestPolicy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networkRequestPolicy.d.ts","sourceRoot":"","sources":["../../../src/helpers/network/networkRequestPolicy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"networkRequestPolicy.d.ts","sourceRoot":"","sources":["../../../src/helpers/network/networkRequestPolicy.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,8EAA8E;AAC9E,eAAO,MAAM,iCAAiC,8BAA8B,CAAC;AAE7E,sGAAsG;AACtG,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,wBAAgB,4BAA4B,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEhE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAUhD;AAED,qGAAqG;AACrG,wBAAgB,uBAAuB,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASnF;AAED,MAAM,MAAM,kCAAkC,GAAG;IAC/C,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,kBAAkB,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,uBAAuB,EAAE,MAAM,IAAI,CAAC;IACpC,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,kBAAkB,EAAE,MAAM,EAC1B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,kCAAkC,GAC5C,MAAM,IAAI,CAuCZ;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,iBAAiB,EAAE,MAAM,OAAO,CAAC;CAClC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,WAAW,EACzB,UAAU,EAAE,MAAM,GACjB,qBAAqB,CAqCvB"}
|
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Defaults for HTTP wrappers and other network clients (see plan: mobile-network-resilience).
|
|
4
|
-
* Apps may pass their own deadline via `timeoutAfterSeconds` on components; when omitted,
|
|
5
|
-
* {@link NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS} applies.
|
|
6
|
-
*/
|
|
2
|
+
/** Network helpers for optional request deadlines and timeout countdowns. */
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
4
|
+
exports.NO_NETWORK_MESSAGE = exports.NETWORK_REQUEST_TIMED_OUT_MESSAGE = void 0;
|
|
9
5
|
exports.isNetworkRequestTimeoutError = isNetworkRequestTimeoutError;
|
|
10
6
|
exports.isAbortError = isAbortError;
|
|
11
7
|
exports.resolveRequestTimeoutMs = resolveRequestTimeoutMs;
|
|
12
8
|
exports.installNetworkRequestPolicyTimers = installNetworkRequestPolicyTimers;
|
|
13
9
|
exports.mergeParentSignalWithDeadline = mergeParentSignalWithDeadline;
|
|
14
|
-
exports.NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS = 30;
|
|
15
|
-
exports.NETWORK_REQUEST_HARD_TIMEOUT_MS = exports.NETWORK_REQUEST_DEFAULT_TIMEOUT_SECONDS * 1000;
|
|
16
10
|
/** Use this exact message so callers can detect timeout vs other failures. */
|
|
17
11
|
exports.NETWORK_REQUEST_TIMED_OUT_MESSAGE = "Network request timed out";
|
|
12
|
+
/** Use this exact message for client-side offline gating and RN fetch failures treated as offline. */
|
|
13
|
+
exports.NO_NETWORK_MESSAGE = "No network connection";
|
|
18
14
|
function isNetworkRequestTimeoutError(e) {
|
|
19
15
|
return e instanceof Error && e.message === exports.NETWORK_REQUEST_TIMED_OUT_MESSAGE;
|
|
20
16
|
}
|
|
21
17
|
function isAbortError(e) {
|
|
22
|
-
if (
|
|
18
|
+
if (typeof DOMException !== "undefined" &&
|
|
19
|
+
e instanceof DOMException &&
|
|
20
|
+
e.name === "AbortError") {
|
|
23
21
|
return true;
|
|
22
|
+
}
|
|
24
23
|
if (e instanceof Error && e.name === "AbortError")
|
|
25
24
|
return true;
|
|
26
25
|
return false;
|
|
27
26
|
}
|
|
28
|
-
/** Milliseconds for `timeoutAfterSeconds` on request components
|
|
27
|
+
/** Milliseconds for `timeoutAfterSeconds` on request components; `null` when timeout is disabled. */
|
|
29
28
|
function resolveRequestTimeoutMs(timeoutAfterSeconds) {
|
|
30
29
|
if (timeoutAfterSeconds != null &&
|
|
31
30
|
Number.isFinite(timeoutAfterSeconds) &&
|
|
32
31
|
timeoutAfterSeconds > 0) {
|
|
33
32
|
return Math.floor(timeoutAfterSeconds) * 1000;
|
|
34
33
|
}
|
|
35
|
-
return
|
|
34
|
+
return null;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
37
|
* Emits whole seconds until {@link hardTimeoutMs} on install and roughly every second after
|
|
@@ -83,7 +82,7 @@ function installNetworkRequestPolicyTimers(requestStartedAtMs, hardTimeoutMs, ca
|
|
|
83
82
|
* Call `dispose()` after the request settles to clear the timer; then `consumeDidTimeout()` to see
|
|
84
83
|
* whether the deadline fired (vs parent abort only).
|
|
85
84
|
*/
|
|
86
|
-
function mergeParentSignalWithDeadline(parentSignal, deadlineMs
|
|
85
|
+
function mergeParentSignalWithDeadline(parentSignal, deadlineMs) {
|
|
87
86
|
const controller = new AbortController();
|
|
88
87
|
let didTimeout = false;
|
|
89
88
|
const onParentAbort = () => {
|