ropegeo-common 1.18.1 → 1.18.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"downloadHttpRequest.d.ts","sourceRoot":"","sources":["../../../src/download/helpers/downloadHttpRequest.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6BH;;;GAGG;AACH,wBAAsB,mBAAmB,CACrC,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,WAAW,CAAC,EAAE,WAAW,EACzB,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,CAmCnB"}
1
+ {"version":3,"file":"downloadHttpRequest.d.ts","sourceRoot":"","sources":["../../../src/download/helpers/downloadHttpRequest.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8CH;;;GAGG;AACH,wBAAsB,mBAAmB,CACrC,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,WAAW,CAAC,EAAE,WAAW,EACzB,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,CAwCnB"}
@@ -5,6 +5,7 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.downloadHttpRequest = downloadHttpRequest;
8
+ const networkRequestPolicy_1 = require("../../helpers/network/networkRequestPolicy");
8
9
  const DEFAULT_HEADERS = {
9
10
  Accept: 'application/json, text/html, application/xml, */*',
10
11
  'Accept-Language': 'en-US,en;q=0.9',
@@ -24,6 +25,20 @@ const buildNonOkMessage = async (response, requestUrl) => {
24
25
  return (`downloadHttpRequest non-OK: status=${response.status} statusText=${response.statusText} ` +
25
26
  `requestUrl=${requestUrl} finalUrl=${finalUrl} server=${server} responseBody=${bodyPreview}`);
26
27
  };
28
+ function abortSignalAfterMs(ms) {
29
+ const controller = new AbortController();
30
+ const timeoutId = setTimeout(() => {
31
+ if (!controller.signal.aborted) {
32
+ controller.abort();
33
+ }
34
+ }, ms);
35
+ return {
36
+ signal: controller.signal,
37
+ dispose: () => {
38
+ clearTimeout(timeoutId);
39
+ },
40
+ };
41
+ }
27
42
  /**
28
43
  * Send a single HTTP request for download list/page JSON fetches.
29
44
  * Aborts when `abortSignal` fires or after 30 seconds. Throws on non-OK responses.
@@ -36,10 +51,11 @@ async function downloadHttpRequest(url, abortSignal, init) {
36
51
  : new Error(String(abortSignal.reason));
37
52
  throw new Error(`downloadHttpRequest aborted: requestUrl=${requestUrl} error=${err.message}`);
38
53
  }
39
- const timeoutSignal = AbortSignal.timeout(DOWNLOAD_HTTP_REQUEST_TIMEOUT_MS);
40
- const requestSignal = abortSignal != null
41
- ? AbortSignal.any([abortSignal, timeoutSignal])
42
- : timeoutSignal;
54
+ const deadline = abortSignal != null
55
+ ? (0, networkRequestPolicy_1.mergeParentSignalWithDeadline)(abortSignal, DOWNLOAD_HTTP_REQUEST_TIMEOUT_MS)
56
+ : null;
57
+ const timeoutOnly = deadline == null ? abortSignalAfterMs(DOWNLOAD_HTTP_REQUEST_TIMEOUT_MS) : null;
58
+ const requestSignal = deadline?.signal ?? timeoutOnly.signal;
43
59
  let response;
44
60
  try {
45
61
  response = await globalThis.fetch(requestUrl, {
@@ -51,6 +67,10 @@ async function downloadHttpRequest(url, abortSignal, init) {
51
67
  catch (error) {
52
68
  throw new Error(`downloadHttpRequest failed: requestUrl=${requestUrl} error=${error}`);
53
69
  }
70
+ finally {
71
+ deadline?.dispose();
72
+ timeoutOnly?.dispose();
73
+ }
54
74
  if (!response.ok) {
55
75
  throw new Error(await buildNonOkMessage(response, requestUrl));
56
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ropegeo-common",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "description": "Shared domain models and helpers for RopeGeo and WebScraper",
5
5
  "license": "ISC",
6
6
  "repository": {