apollo-link-timeout 5.0.0 → 5.0.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,9 +1,14 @@
1
1
  "use strict";
2
2
  var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
6
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
7
12
  extendStatics(d, b);
8
13
  function __() { this.constructor = d; }
9
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -1 +1 @@
1
- {"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../src/TimeoutError.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;IAA0C,gCAAK;IAI7C,sBAAY,OAAe,EAAE,OAAe,EAAE,UAAwB;QAAxB,2BAAA,EAAA,gBAAwB;QAAtE,YACE,kBAAM,OAAO,CAAC,SAGf;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IACH,mBAAC;AAAD,CAAC,AATD,CAA0C,KAAK,GAS9C"}
1
+ {"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../src/TimeoutError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;IAA0C,gCAAK;IAI7C,sBAAY,OAAe,EAAE,OAAe,EAAE,UAAwB;QAAxB,2BAAA,EAAA,gBAAwB;QAAtE,YACE,kBAAM,OAAO,CAAC,SAGf;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IACH,mBAAC;AAAD,CAAC,AATD,CAA0C,KAAK,GAS9C"}
package/lib/cjs/cjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var timeoutLink_1 = require("./timeoutLink");
4
- module.exports = timeoutLink_1.default;
5
- module.exports.default = timeoutLink_1.default;
3
+ var timeoutLink_js_1 = require("./timeoutLink.js");
4
+ module.exports = timeoutLink_js_1.default;
5
+ module.exports.default = timeoutLink_js_1.default;
6
6
  //# sourceMappingURL=cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cjs.js","sourceRoot":"","sources":["../../src/cjs.ts"],"names":[],"mappings":";;AAAA,6CAAwC;AAExC,MAAM,CAAC,OAAO,GAAG,qBAAW,CAAC;AAC7B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,qBAAW,CAAC"}
1
+ {"version":3,"file":"cjs.js","sourceRoot":"","sources":["../../src/cjs.ts"],"names":[],"mappings":";;AAAA,mDAA2C;AAE3C,MAAM,CAAC,OAAO,GAAG,wBAAW,CAAC;AAC7B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,wBAAW,CAAC"}
@@ -1,31 +1,47 @@
1
1
  "use strict";
2
2
  var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
6
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
7
12
  extendStatics(d, b);
8
13
  function __() { this.constructor = d; }
9
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10
15
  };
11
16
  })();
12
- var __assign = (this && this.__assign) || Object.assign || function(t) {
13
- for (var s, i = 1, n = arguments.length; i < n; i++) {
14
- s = arguments[i];
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
16
- t[p] = s[p];
17
- }
18
- return t;
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
19
27
  };
20
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ // note, this import is modified when building for ESM via `script/fix_apollo_import.mjs`
21
30
  var core_1 = require("@apollo/client/core");
22
- var TimeoutError_1 = require("./TimeoutError");
31
+ var TimeoutError_js_1 = require("./TimeoutError.js");
23
32
  var DEFAULT_TIMEOUT = 15000;
24
33
  /**
25
34
  * Aborts the request if the timeout expires before the response is received.
26
35
  */
27
36
  var TimeoutLink = /** @class */ (function (_super) {
28
37
  __extends(TimeoutLink, _super);
38
+ /**
39
+ * Creates a new TimeoutLink instance.
40
+ * Aborts the request if the timeout expires before the response is received.
41
+ *
42
+ * @param timeout - The timeout in milliseconds for the request. Default is 15000ms (15 seconds).
43
+ * @param statusCode - The HTTP status code to return when a timeout occurs. Default is 408 (Request Timeout).
44
+ */
29
45
  function TimeoutLink(timeout, statusCode) {
30
46
  var _this = _super.call(this) || this;
31
47
  _this.timeout = timeout || DEFAULT_TIMEOUT;
@@ -44,7 +60,7 @@ var TimeoutLink = /** @class */ (function (_super) {
44
60
  var fetchOptions = context.fetchOptions || {};
45
61
  ourController = new AbortController();
46
62
  controller = fetchOptions.controller || ourController;
47
- fetchOptions = __assign({}, fetchOptions, { controller: controller, signal: controller.signal });
63
+ fetchOptions = __assign(__assign({}, fetchOptions), { controller: controller, signal: controller.signal });
48
64
  operation.setContext({ fetchOptions: fetchOptions });
49
65
  }
50
66
  var chainObservable = forward(operation); // observable for remaining link chain
@@ -80,10 +96,10 @@ var TimeoutLink = /** @class */ (function (_super) {
80
96
  var context = operation.getContext();
81
97
  var fetchOptions = context.fetchOptions || {};
82
98
  if (fetchOptions.controller === ourController && fetchOptions.signal === ourController.signal) {
83
- operation.setContext(__assign({}, fetchOptions, { controller: undefined, signal: undefined }));
99
+ operation.setContext(__assign(__assign({}, fetchOptions), { controller: undefined, signal: undefined }));
84
100
  }
85
101
  }
86
- observer.error(new TimeoutError_1.default('Timeout exceeded', requestTimeout, _this.statusCode));
102
+ observer.error(new TimeoutError_js_1.default('Timeout exceeded', requestTimeout, _this.statusCode));
87
103
  subscription.unsubscribe();
88
104
  }, requestTimeout);
89
105
  var cancelTimeout = function () {
@@ -1 +1 @@
1
- {"version":3,"file":"timeoutLink.js","sourceRoot":"","sources":["../../src/timeoutLink.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,4CAAkF;AAElF,+CAA0C;AAE1C,IAAM,eAAe,GAAW,KAAK,CAAC;AAEtC;;GAEG;AACH;IAAyC,+BAAU;IAIjD,qBAAY,OAAe,EAAE,UAAmB;QAAhD,YACE,iBAAO,SAGR;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAC;QAC1C,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IAEM,6BAAO,GAAd,UAAe,SAAoB,EAAE,OAAiB;QAAtD,iBA4FC;QA3FC,IAAI,UAA2B,CAAC;QAChC,IAAI,aAA8B,CAAC;QAEnC,sCAAsC;Q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UAAU,EAAE,CAAC;oBACvC,IAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;oBAChD,IAAG,YAAY,CAAC,UAAU,KAAK,aAAa,IAAI,YAAY,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM,EAAE;wBAC3F,SAAS,CAAC,UAAU,uBAAM,YAAY,KAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,IAAG,CAAC;qBACtF;iBACF;gBAED,QAAQ,CAAC,KAAK,CAAC,IAAI,yBAAY,CAAC,kBAAkB,EAAE,cAAc,EAAE,KAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBACtF,YAAY,CAAC,WAAW,EAAE,CAAC;YAC7B,CAAC,EAAE,cAAc,CAAC,CAAC;YAEnB,IAAM,aAAa,GAAG;gBACpB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,YAAY,CAAC,WAAW,EAAE,CAAC;YAC7B,CAAC,CAAC;YAEF,IAAM,MAAM,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC;YACjD,IAAI,MAAM,EAAE;gBACV,MAAM,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC;aACxC;YAED,gDAAgD;YAChD,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE;gBAC1C,aAAa,EAAE,CAAC;YAClB,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAEnB,0EAA0E;YAC1E,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC;IACzB,CAAC;IACH,kBAAC;AAAD,CAAC,AA9GD,CAAyC,iBAAU,GA8GlD"}
@@ -1,8 +1,13 @@
1
1
  var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = Object.setPrototypeOf ||
3
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
5
8
  return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
6
11
  extendStatics(d, b);
7
12
  function __() { this.constructor = d; }
8
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -1 +1 @@
1
- {"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../src/TimeoutError.ts"],"names":[],"mappings":";;;;;;;;;;AAAA;IAA0C,gCAAK;IAI7C,sBAAY,OAAe,EAAE,OAAe,EAAE,UAAwB;QAAxB,2BAAA,EAAA,gBAAwB;QAAtE,YACE,kBAAM,OAAO,CAAC,SAGf;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IACH,mBAAC;AAAD,CAAC,AATD,CAA0C,KAAK,GAS9C"}
1
+ {"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../src/TimeoutError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;IAA0C,gCAAK;IAI7C,sBAAY,OAAe,EAAE,OAAe,EAAE,UAAwB;QAAxB,2BAAA,EAAA,gBAAwB;QAAtE,YACE,kBAAM,OAAO,CAAC,SAGf;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IACH,mBAAC;AAAD,CAAC,AATD,CAA0C,KAAK,GAS9C"}
@@ -1,29 +1,45 @@
1
1
  var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = Object.setPrototypeOf ||
3
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
5
8
  return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
6
11
  extendStatics(d, b);
7
12
  function __() { this.constructor = d; }
8
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9
14
  };
10
15
  })();
11
- var __assign = (this && this.__assign) || Object.assign || function(t) {
12
- for (var s, i = 1, n = arguments.length; i < n; i++) {
13
- s = arguments[i];
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
15
- t[p] = s[p];
16
- }
17
- return t;
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
18
26
  };
19
- import { ApolloLink, Observable } from '@apollo/client/core';
20
- import TimeoutError from './TimeoutError';
27
+ // note, this import is modified when building for ESM via `script/fix_apollo_import.mjs`
28
+ import { ApolloLink, Observable } from '@apollo/client/core/index.js';
29
+ import TimeoutError from './TimeoutError.js';
21
30
  var DEFAULT_TIMEOUT = 15000;
22
31
  /**
23
32
  * Aborts the request if the timeout expires before the response is received.
24
33
  */
25
34
  var TimeoutLink = /** @class */ (function (_super) {
26
35
  __extends(TimeoutLink, _super);
36
+ /**
37
+ * Creates a new TimeoutLink instance.
38
+ * Aborts the request if the timeout expires before the response is received.
39
+ *
40
+ * @param timeout - The timeout in milliseconds for the request. Default is 15000ms (15 seconds).
41
+ * @param statusCode - The HTTP status code to return when a timeout occurs. Default is 408 (Request Timeout).
42
+ */
27
43
  function TimeoutLink(timeout, statusCode) {
28
44
  var _this = _super.call(this) || this;
29
45
  _this.timeout = timeout || DEFAULT_TIMEOUT;
@@ -42,7 +58,7 @@ var TimeoutLink = /** @class */ (function (_super) {
42
58
  var fetchOptions = context.fetchOptions || {};
43
59
  ourController = new AbortController();
44
60
  controller = fetchOptions.controller || ourController;
45
- fetchOptions = __assign({}, fetchOptions, { controller: controller, signal: controller.signal });
61
+ fetchOptions = __assign(__assign({}, fetchOptions), { controller: controller, signal: controller.signal });
46
62
  operation.setContext({ fetchOptions: fetchOptions });
47
63
  }
48
64
  var chainObservable = forward(operation); // observable for remaining link chain
@@ -78,7 +94,7 @@ var TimeoutLink = /** @class */ (function (_super) {
78
94
  var context = operation.getContext();
79
95
  var fetchOptions = context.fetchOptions || {};
80
96
  if (fetchOptions.controller === ourController && fetchOptions.signal === ourController.signal) {
81
- operation.setContext(__assign({}, fetchOptions, { controller: undefined, signal: undefined }));
97
+ operation.setContext(__assign(__assign({}, fetchOptions), { controller: undefined, signal: undefined }));
82
98
  }
83
99
  }
84
100
  observer.error(new TimeoutError('Timeout exceeded', requestTimeout, _this.statusCode));
@@ -1 +1 @@
1
- {"version":3,"file":"timeoutLink.js","sourceRoot":"","sources":["../../src/timeoutLink.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAuB,MAAM,qBAAqB,CAAC;AAElF,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,IAAM,eAAe,GAAW,KAAK,CAAC;AAEtC;;GAEG;AACH;IAAyC,+BAAU;IAIjD,qBAAY,OAAe,EAAE,UAAmB;QAAhD,YACE,iBAAO,SAGR;QAFC,KAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CA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AEH,OAAO,eAAe,CAAC;IACzB,CAAC;IACH,kBAAC;AAAD,CAAC,AA9GD,CAAyC,UAAU,GA8GlD"}
@@ -1,11 +1,18 @@
1
1
  /// <reference types="zen-observable" />
2
- import { ApolloLink, Observable, Operation, NextLink } from '@apollo/client/core';
2
+ import { ApolloLink, Observable, type Operation, type NextLink } from '@apollo/client/core';
3
3
  /**
4
4
  * Aborts the request if the timeout expires before the response is received.
5
5
  */
6
6
  export default class TimeoutLink extends ApolloLink {
7
7
  private timeout;
8
8
  private statusCode?;
9
- constructor(timeout: number, statusCode?: number);
10
- request(operation: Operation, forward: NextLink): Observable<{}>;
9
+ /**
10
+ * Creates a new TimeoutLink instance.
11
+ * Aborts the request if the timeout expires before the response is received.
12
+ *
13
+ * @param timeout - The timeout in milliseconds for the request. Default is 15000ms (15 seconds).
14
+ * @param statusCode - The HTTP status code to return when a timeout occurs. Default is 408 (Request Timeout).
15
+ */
16
+ constructor(timeout?: number, statusCode?: number);
17
+ request(operation: Operation, forward: NextLink): Observable<unknown>;
11
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apollo-link-timeout",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Abort requests that take longer than a specified timeout period",
5
5
  "peerDependencies": {
6
6
  "@apollo/client": "^3.0.0"
@@ -11,12 +11,11 @@
11
11
  "@types/node": "^10.3.4",
12
12
  "graphql": "^15.3.0",
13
13
  "graphql-tag": "^2.11.0",
14
- "jest": "^23.1.0",
15
- "react": "^16.13.1",
16
- "ts-jest": "^22.4.6",
17
- "ts-loader": "^4.4.1",
14
+ "jest": "^28.1.3",
15
+ "jest-environment-jsdom": "^28.1.3",
16
+ "ts-jest": "^28.0.8",
18
17
  "tslint": "^5.8.0",
19
- "typescript": "^2.9.2"
18
+ "typescript": "^4.9.5"
20
19
  },
21
20
  "main": "./lib/cjs/cjs.js",
22
21
  "types": "./lib/types/timeoutLink.d.ts",
@@ -37,11 +36,13 @@
37
36
  "scripts": {
38
37
  "build": "yarn build:cjs && yarn build:esm && yarn build:types",
39
38
  "build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
40
- "build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > lib/esm/package.json",
39
+ "build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > lib/esm/package.json && node scripts/fix_apollo_import.mjs",
41
40
  "build:types": "tsc -p tsconfig.types.json",
42
41
  "lint": "tslint src/*.ts* src/**/*.ts*",
43
- "test": "jest",
44
- "prepublish": "yarn lint && yarn test && yarn build",
42
+ "test": "yarn test:unit && yarn test:integration",
43
+ "test:integration": "node __tests__/integration/run.mjs",
44
+ "test:unit": "jest",
45
+ "prepublish": "yarn lint && yarn test:unit && yarn build",
45
46
  "deploy": "yarn publish && git push"
46
47
  },
47
48
  "keywords": [
@@ -57,19 +58,29 @@
57
58
  "src"
58
59
  ],
59
60
  "jest": {
60
- "transform": {
61
- ".(ts|tsx)": "ts-jest"
61
+ "globals": {
62
+ "ts-jest": {
63
+ "useESM": true
64
+ }
62
65
  },
63
- "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
64
66
  "moduleFileExtensions": [
65
67
  "ts",
66
68
  "tsx",
67
69
  "js",
68
70
  "json"
69
71
  ],
72
+ "moduleNameMapper": {
73
+ "(.+)\\.js": "$1"
74
+ },
75
+ "testEnvironment": "jsdom",
70
76
  "testPathIgnorePatterns": [
77
+ "__tests__/integration/",
71
78
  "/node_modules/",
72
79
  "/lib/"
73
- ]
80
+ ],
81
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
82
+ "transform": {
83
+ ".(ts|tsx)": "ts-jest"
84
+ }
74
85
  }
75
86
  }
package/src/cjs.ts CHANGED
@@ -1,4 +1,4 @@
1
- import TimeoutLink from "./timeoutLink";
1
+ import TimeoutLink from "./timeoutLink.js";
2
2
 
3
3
  module.exports = TimeoutLink;
4
4
  module.exports.default = TimeoutLink;
@@ -1,6 +1,7 @@
1
- import { ApolloLink, Observable, Operation, NextLink } from '@apollo/client/core';
2
- import { DefinitionNode } from 'graphql';
3
- import TimeoutError from './TimeoutError';
1
+ // note, this import is modified when building for ESM via `script/fix_apollo_import.mjs`
2
+ import { ApolloLink, Observable, type Operation, type NextLink } from '@apollo/client/core';
3
+ import type { DefinitionNode } from 'graphql';
4
+ import TimeoutError from './TimeoutError.js';
4
5
 
5
6
  const DEFAULT_TIMEOUT: number = 15000;
6
7
 
@@ -11,7 +12,14 @@ export default class TimeoutLink extends ApolloLink {
11
12
  private timeout: number;
12
13
  private statusCode?: number;
13
14
 
14
- constructor(timeout: number, statusCode?: number) {
15
+ /**
16
+ * Creates a new TimeoutLink instance.
17
+ * Aborts the request if the timeout expires before the response is received.
18
+ *
19
+ * @param timeout - The timeout in milliseconds for the request. Default is 15000ms (15 seconds).
20
+ * @param statusCode - The HTTP status code to return when a timeout occurs. Default is 408 (Request Timeout).
21
+ */
22
+ constructor(timeout?: number, statusCode?: number) {
15
23
  super();
16
24
  this.timeout = timeout || DEFAULT_TIMEOUT;
17
25
  this.statusCode = statusCode;