apollo-link-timeout 5.0.0 → 5.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apollo-link-timeout",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
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;
@@ -1,25 +0,0 @@
1
- "use strict";
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]; };
6
- return function (d, b) {
7
- extendStatics(d, b);
8
- function __() { this.constructor = d; }
9
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10
- };
11
- })();
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- var TimeoutError = /** @class */ (function (_super) {
14
- __extends(TimeoutError, _super);
15
- function TimeoutError(message, timeout, statusCode) {
16
- if (statusCode === void 0) { statusCode = 408; }
17
- var _this = _super.call(this, message) || this;
18
- _this.timeout = timeout;
19
- _this.statusCode = statusCode;
20
- return _this;
21
- }
22
- return TimeoutError;
23
- }(Error));
24
- exports.default = TimeoutError;
25
- //# sourceMappingURL=TimeoutError.js.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
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;
6
- //# sourceMappingURL=cjs.js.map
@@ -1 +0,0 @@
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 +0,0 @@
1
- {"type": "commonjs"}
@@ -1,109 +0,0 @@
1
- "use strict";
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]; };
6
- return function (d, b) {
7
- extendStatics(d, b);
8
- function __() { this.constructor = d; }
9
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10
- };
11
- })();
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;
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- var core_1 = require("@apollo/client/core");
22
- var TimeoutError_1 = require("./TimeoutError");
23
- var DEFAULT_TIMEOUT = 15000;
24
- /**
25
- * Aborts the request if the timeout expires before the response is received.
26
- */
27
- var TimeoutLink = /** @class */ (function (_super) {
28
- __extends(TimeoutLink, _super);
29
- function TimeoutLink(timeout, statusCode) {
30
- var _this = _super.call(this) || this;
31
- _this.timeout = timeout || DEFAULT_TIMEOUT;
32
- _this.statusCode = statusCode;
33
- return _this;
34
- }
35
- TimeoutLink.prototype.request = function (operation, forward) {
36
- var _this = this;
37
- var controller;
38
- var ourController;
39
- // override timeout from query context
40
- var requestTimeout = operation.getContext().timeout || this.timeout;
41
- // add abort controller and signal object to fetchOptions if they don't already exist
42
- if (typeof AbortController !== 'undefined') {
43
- var context = operation.getContext();
44
- var fetchOptions = context.fetchOptions || {};
45
- ourController = new AbortController();
46
- controller = fetchOptions.controller || ourController;
47
- fetchOptions = __assign({}, fetchOptions, { controller: controller, signal: controller.signal });
48
- operation.setContext({ fetchOptions: fetchOptions });
49
- }
50
- var chainObservable = forward(operation); // observable for remaining link chain
51
- var operationType = operation.query.definitions.find(function (def) { return def.kind === 'OperationDefinition'; }).operation;
52
- if (requestTimeout <= 0 || operationType === 'subscription') {
53
- return chainObservable; // skip this link if timeout is zero or it's a subscription request
54
- }
55
- // create local observable with timeout functionality (unsubscibe from chain observable and
56
- // return an error if the timeout expires before chain observable resolves)
57
- var localObservable = new core_1.Observable(function (observer) {
58
- var timer;
59
- // listen to chainObservable for result and pass to localObservable if received before timeout
60
- var subscription = chainObservable.subscribe(function (result) {
61
- clearTimeout(timer);
62
- observer.next(result);
63
- observer.complete();
64
- }, function (error) {
65
- clearTimeout(timer);
66
- observer.error(error);
67
- observer.complete();
68
- });
69
- // if timeout expires before observable completes, abort call, unsubscribe, and return error
70
- timer = setTimeout(function () {
71
- if (controller) {
72
- if (controller.signal.aborted) {
73
- // already aborted from somewhere else
74
- return;
75
- }
76
- controller.abort(); // abort fetch operation
77
- // if the AbortController in the operation context is one we created,
78
- // it's now "used up", so we need to remove it to avoid blocking any
79
- // future retry of the operation.
80
- var context = operation.getContext();
81
- var fetchOptions = context.fetchOptions || {};
82
- if (fetchOptions.controller === ourController && fetchOptions.signal === ourController.signal) {
83
- operation.setContext(__assign({}, fetchOptions, { controller: undefined, signal: undefined }));
84
- }
85
- }
86
- observer.error(new TimeoutError_1.default('Timeout exceeded', requestTimeout, _this.statusCode));
87
- subscription.unsubscribe();
88
- }, requestTimeout);
89
- var cancelTimeout = function () {
90
- clearTimeout(timer);
91
- subscription.unsubscribe();
92
- };
93
- var ctxRef = operation.getContext().timeoutRef;
94
- if (ctxRef) {
95
- ctxRef({ unsubscribe: cancelTimeout });
96
- }
97
- // cancel timeout if aborted from somewhere else
98
- controller.signal.addEventListener("abort", function () {
99
- cancelTimeout();
100
- }, { once: true });
101
- // this function is called when a client unsubscribes from localObservable
102
- return cancelTimeout;
103
- });
104
- return localObservable;
105
- };
106
- return TimeoutLink;
107
- }(core_1.ApolloLink));
108
- exports.default = TimeoutLink;
109
- //# sourceMappingURL=timeoutLink.js.map
@@ -1 +0,0 @@
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;QACtC,IAAM,cAAc,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC;QAEtE,qFAAqF;QACrF,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;YAC1C,IAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YACvC,IAAI,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;YAE9C,aAAa,GAAG,IAAI,eAAe,EAAE,CAAC;YACtC,UAAU,GAAG,YAAY,CAAC,UAAU,IAAI,aAAa,CAAC;YAEtD,YAAY,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E;oBACpE,iCAAiC;oBACjC,IAAM,OAAO,GAAG,SAAS,CAAC,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,cAAM,YAAY,IAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,IAAG,CAAC;qBACtF;iBACF;gBAED,QAAQ,CAAC,KAAK,CAAC,IAAI,sBAAY,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,AAvGD,CAAyC,iBAAU,GAuGlD"}
@@ -1,23 +0,0 @@
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]; };
5
- return function (d, b) {
6
- extendStatics(d, b);
7
- function __() { this.constructor = d; }
8
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9
- };
10
- })();
11
- var TimeoutError = /** @class */ (function (_super) {
12
- __extends(TimeoutError, _super);
13
- function TimeoutError(message, timeout, statusCode) {
14
- if (statusCode === void 0) { statusCode = 408; }
15
- var _this = _super.call(this, message) || this;
16
- _this.timeout = timeout;
17
- _this.statusCode = statusCode;
18
- return _this;
19
- }
20
- return TimeoutError;
21
- }(Error));
22
- export default TimeoutError;
23
- //# sourceMappingURL=TimeoutError.js.map
@@ -1 +0,0 @@
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 +0,0 @@
1
- {"type": "module"}
@@ -1,107 +0,0 @@
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]; };
5
- return function (d, b) {
6
- extendStatics(d, b);
7
- function __() { this.constructor = d; }
8
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9
- };
10
- })();
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;
18
- };
19
- import { ApolloLink, Observable } from '@apollo/client/core';
20
- import TimeoutError from './TimeoutError';
21
- var DEFAULT_TIMEOUT = 15000;
22
- /**
23
- * Aborts the request if the timeout expires before the response is received.
24
- */
25
- var TimeoutLink = /** @class */ (function (_super) {
26
- __extends(TimeoutLink, _super);
27
- function TimeoutLink(timeout, statusCode) {
28
- var _this = _super.call(this) || this;
29
- _this.timeout = timeout || DEFAULT_TIMEOUT;
30
- _this.statusCode = statusCode;
31
- return _this;
32
- }
33
- TimeoutLink.prototype.request = function (operation, forward) {
34
- var _this = this;
35
- var controller;
36
- var ourController;
37
- // override timeout from query context
38
- var requestTimeout = operation.getContext().timeout || this.timeout;
39
- // add abort controller and signal object to fetchOptions if they don't already exist
40
- if (typeof AbortController !== 'undefined') {
41
- var context = operation.getContext();
42
- var fetchOptions = context.fetchOptions || {};
43
- ourController = new AbortController();
44
- controller = fetchOptions.controller || ourController;
45
- fetchOptions = __assign({}, fetchOptions, { controller: controller, signal: controller.signal });
46
- operation.setContext({ fetchOptions: fetchOptions });
47
- }
48
- var chainObservable = forward(operation); // observable for remaining link chain
49
- var operationType = operation.query.definitions.find(function (def) { return def.kind === 'OperationDefinition'; }).operation;
50
- if (requestTimeout <= 0 || operationType === 'subscription') {
51
- return chainObservable; // skip this link if timeout is zero or it's a subscription request
52
- }
53
- // create local observable with timeout functionality (unsubscibe from chain observable and
54
- // return an error if the timeout expires before chain observable resolves)
55
- var localObservable = new Observable(function (observer) {
56
- var timer;
57
- // listen to chainObservable for result and pass to localObservable if received before timeout
58
- var subscription = chainObservable.subscribe(function (result) {
59
- clearTimeout(timer);
60
- observer.next(result);
61
- observer.complete();
62
- }, function (error) {
63
- clearTimeout(timer);
64
- observer.error(error);
65
- observer.complete();
66
- });
67
- // if timeout expires before observable completes, abort call, unsubscribe, and return error
68
- timer = setTimeout(function () {
69
- if (controller) {
70
- if (controller.signal.aborted) {
71
- // already aborted from somewhere else
72
- return;
73
- }
74
- controller.abort(); // abort fetch operation
75
- // if the AbortController in the operation context is one we created,
76
- // it's now "used up", so we need to remove it to avoid blocking any
77
- // future retry of the operation.
78
- var context = operation.getContext();
79
- var fetchOptions = context.fetchOptions || {};
80
- if (fetchOptions.controller === ourController && fetchOptions.signal === ourController.signal) {
81
- operation.setContext(__assign({}, fetchOptions, { controller: undefined, signal: undefined }));
82
- }
83
- }
84
- observer.error(new TimeoutError('Timeout exceeded', requestTimeout, _this.statusCode));
85
- subscription.unsubscribe();
86
- }, requestTimeout);
87
- var cancelTimeout = function () {
88
- clearTimeout(timer);
89
- subscription.unsubscribe();
90
- };
91
- var ctxRef = operation.getContext().timeoutRef;
92
- if (ctxRef) {
93
- ctxRef({ unsubscribe: cancelTimeout });
94
- }
95
- // cancel timeout if aborted from somewhere else
96
- controller.signal.addEventListener("abort", function () {
97
- cancelTimeout();
98
- }, { once: true });
99
- // this function is called when a client unsubscribes from localObservable
100
- return cancelTimeout;
101
- });
102
- return localObservable;
103
- };
104
- return TimeoutLink;
105
- }(ApolloLink));
106
- export default TimeoutLink;
107
- //# sourceMappingURL=timeoutLink.js.map
@@ -1 +0,0 @@
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,CAAC;QAC1C,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IAEM,6BAAO,GAAd,UA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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,AAvGD,CAAyC,UAAU,GAuGlD"}
@@ -1,5 +0,0 @@
1
- export default class TimeoutError extends Error {
2
- timeout: number;
3
- statusCode: number;
4
- constructor(message: string, timeout: number, statusCode?: number);
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- /// <reference types="zen-observable" />
2
- import { ApolloLink, Observable, Operation, NextLink } from '@apollo/client/core';
3
- /**
4
- * Aborts the request if the timeout expires before the response is received.
5
- */
6
- export default class TimeoutLink extends ApolloLink {
7
- private timeout;
8
- private statusCode?;
9
- constructor(timeout: number, statusCode?: number);
10
- request(operation: Operation, forward: NextLink): Observable<{}>;
11
- }