api-def 0.9.1 → 0.9.3
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/README.md +1 -1
- package/cjs/Api.d.ts +35 -35
- package/cjs/Api.js +140 -144
- package/cjs/ApiConstants.d.ts +58 -58
- package/cjs/ApiConstants.js +55 -55
- package/cjs/ApiTypes.d.ts +103 -103
- package/cjs/ApiTypes.js +4 -4
- package/cjs/ApiUtils.d.ts +6 -6
- package/cjs/ApiUtils.js +51 -53
- package/cjs/Endpoint.d.ts +52 -52
- package/cjs/Endpoint.js +104 -108
- package/cjs/EndpointBuilder.d.ts +14 -14
- package/cjs/EndpointBuilder.js +46 -46
- package/cjs/MockingTypes.d.ts +30 -30
- package/cjs/MockingTypes.js +2 -2
- package/cjs/QueryHandling.d.ts +3 -3
- package/cjs/QueryHandling.js +24 -24
- package/cjs/RequestConfig.d.ts +2 -2
- package/cjs/RequestConfig.js +74 -74
- package/cjs/RequestContext.d.ts +48 -48
- package/cjs/RequestContext.js +235 -238
- package/cjs/RequestError.d.ts +30 -30
- package/cjs/RequestError.js +47 -47
- package/cjs/Requester.d.ts +3 -3
- package/cjs/Requester.js +335 -336
- package/cjs/TextDecoding.d.ts +1 -1
- package/cjs/TextDecoding.js +152 -139
- package/cjs/UtilTypes.d.ts +5 -5
- package/cjs/UtilTypes.js +2 -2
- package/cjs/Utils.d.ts +15 -15
- package/cjs/Utils.js +79 -77
- package/cjs/Validation.d.ts +8 -8
- package/cjs/Validation.js +2 -2
- package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
- package/cjs/backend/AxiosRequestBackend.js +99 -99
- package/cjs/backend/FetchRequestBackend.d.ts +15 -15
- package/cjs/backend/FetchRequestBackend.js +203 -202
- package/cjs/backend/MockRequestBackend.d.ts +11 -11
- package/cjs/backend/MockRequestBackend.js +164 -164
- package/cjs/backend/RequestBackend.d.ts +19 -19
- package/cjs/backend/RequestBackend.js +2 -2
- package/cjs/cache/CacheBackend.d.ts +6 -6
- package/cjs/cache/CacheBackend.js +2 -2
- package/cjs/cache/Caching.d.ts +10 -10
- package/cjs/cache/Caching.js +88 -88
- package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
- package/cjs/cache/LocalForageCacheBackend.js +24 -24
- package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
- package/cjs/cache/LocalStorageCacheBackend.js +77 -77
- package/cjs/index.d.ts +13 -13
- package/cjs/index.js +41 -41
- package/cjs/middleware/CacheMiddleware.d.ts +7 -7
- package/cjs/middleware/CacheMiddleware.js +107 -107
- package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
- package/cjs/middleware/LoggingMiddleware.js +82 -88
- package/cjs/util/retry/index.d.ts +3 -3
- package/cjs/util/retry/index.js +52 -52
- package/cjs/util/retry/lib/retry.d.ts +3 -3
- package/cjs/util/retry/lib/retry.js +50 -54
- package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
- package/cjs/util/retry/lib/retryOperation.js +130 -134
- package/esm/Api.d.ts +35 -35
- package/esm/Api.js +92 -98
- package/esm/ApiConstants.d.ts +58 -58
- package/esm/ApiConstants.js +52 -52
- package/esm/ApiTypes.d.ts +103 -103
- package/esm/ApiTypes.js +1 -1
- package/esm/ApiUtils.d.ts +6 -6
- package/esm/ApiUtils.js +43 -45
- package/esm/Endpoint.d.ts +52 -52
- package/esm/Endpoint.js +66 -70
- package/esm/EndpointBuilder.d.ts +14 -14
- package/esm/EndpointBuilder.js +31 -31
- package/esm/MockingTypes.d.ts +30 -30
- package/esm/MockingTypes.js +1 -1
- package/esm/QueryHandling.d.ts +3 -3
- package/esm/QueryHandling.js +19 -19
- package/esm/RequestConfig.d.ts +2 -2
- package/esm/RequestConfig.js +56 -56
- package/esm/RequestContext.d.ts +48 -48
- package/esm/RequestContext.js +167 -170
- package/esm/RequestError.d.ts +30 -30
- package/esm/RequestError.js +42 -42
- package/esm/Requester.d.ts +3 -3
- package/esm/Requester.js +252 -253
- package/esm/TextDecoding.d.ts +1 -1
- package/esm/TextDecoding.js +148 -135
- package/esm/UtilTypes.d.ts +5 -5
- package/esm/UtilTypes.js +1 -1
- package/esm/Utils.d.ts +15 -15
- package/esm/Utils.js +66 -68
- package/esm/Validation.d.ts +8 -8
- package/esm/Validation.js +1 -1
- package/esm/backend/AxiosRequestBackend.d.ts +13 -13
- package/esm/backend/AxiosRequestBackend.js +62 -62
- package/esm/backend/FetchRequestBackend.d.ts +15 -15
- package/esm/backend/FetchRequestBackend.js +136 -136
- package/esm/backend/MockRequestBackend.d.ts +11 -11
- package/esm/backend/MockRequestBackend.js +116 -116
- package/esm/backend/RequestBackend.d.ts +19 -19
- package/esm/backend/RequestBackend.js +1 -1
- package/esm/cache/CacheBackend.d.ts +6 -6
- package/esm/cache/CacheBackend.js +1 -1
- package/esm/cache/Caching.d.ts +10 -10
- package/esm/cache/Caching.js +39 -39
- package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
- package/esm/cache/LocalForageCacheBackend.js +20 -20
- package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
- package/esm/cache/LocalStorageCacheBackend.js +32 -32
- package/esm/index.d.ts +13 -13
- package/esm/index.js +14 -15
- package/esm/middleware/CacheMiddleware.d.ts +7 -7
- package/esm/middleware/CacheMiddleware.js +58 -58
- package/esm/middleware/LoggingMiddleware.d.ts +6 -6
- package/esm/middleware/LoggingMiddleware.js +77 -83
- package/esm/util/retry/index.d.ts +3 -3
- package/esm/util/retry/index.js +50 -50
- package/esm/util/retry/lib/retry.d.ts +3 -3
- package/esm/util/retry/lib/retry.js +35 -39
- package/esm/util/retry/lib/retryOperation.d.ts +27 -27
- package/esm/util/retry/lib/retryOperation.js +126 -132
- package/package.json +19 -34
|
@@ -1,132 +1,126 @@
|
|
|
1
|
-
function RetryOperation(timeouts, options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
RetryOperation.prototype.
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
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
|
-
this._operationTimeoutCb
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
RetryOperation.prototype.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
mainErrorCount = count;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return mainError;
|
|
131
|
-
};
|
|
132
|
-
export default RetryOperation;
|
|
1
|
+
function RetryOperation(timeouts, options) {
|
|
2
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
3
|
+
this._timeouts = timeouts;
|
|
4
|
+
this._options = options || {};
|
|
5
|
+
this._maxRetryTime = (options === null || options === void 0 ? void 0 : options.maxRetryTime) || Infinity;
|
|
6
|
+
this._fn = null;
|
|
7
|
+
this._errors = [];
|
|
8
|
+
this._attempts = 1;
|
|
9
|
+
this._operationTimeout = null;
|
|
10
|
+
this._operationTimeoutCb = null;
|
|
11
|
+
this._timeout = null;
|
|
12
|
+
this._operationStart = null;
|
|
13
|
+
this._timer = null;
|
|
14
|
+
if (this._options.forever) {
|
|
15
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
RetryOperation.prototype.reset = function () {
|
|
19
|
+
this._attempts = 1;
|
|
20
|
+
this._timeouts = this._originalTimeouts.slice(0);
|
|
21
|
+
};
|
|
22
|
+
RetryOperation.prototype.stop = function () {
|
|
23
|
+
if (this._timeout) {
|
|
24
|
+
clearTimeout(this._timeout);
|
|
25
|
+
}
|
|
26
|
+
if (this._timer) {
|
|
27
|
+
clearTimeout(this._timer);
|
|
28
|
+
}
|
|
29
|
+
this._timeouts = [];
|
|
30
|
+
this._cachedTimeouts = null;
|
|
31
|
+
};
|
|
32
|
+
RetryOperation.prototype.retry = function (err) {
|
|
33
|
+
if (this._timeout) {
|
|
34
|
+
clearTimeout(this._timeout);
|
|
35
|
+
}
|
|
36
|
+
if (!err) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const currentTime = new Date().getTime();
|
|
40
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
41
|
+
this._errors.push(err);
|
|
42
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
this._errors.push(err);
|
|
46
|
+
let timeout = this._timeouts.shift();
|
|
47
|
+
if (timeout === undefined) {
|
|
48
|
+
if (this._cachedTimeouts) {
|
|
49
|
+
// retry forever, only keep last error
|
|
50
|
+
this._errors.splice(0, this._errors.length - 1);
|
|
51
|
+
timeout = this._cachedTimeouts.slice(-1);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this._timer = setTimeout(() => {
|
|
58
|
+
this._attempts++;
|
|
59
|
+
if (this._operationTimeoutCb) {
|
|
60
|
+
this._timeout = setTimeout(() => {
|
|
61
|
+
this._operationTimeoutCb(this._attempts);
|
|
62
|
+
}, this._operationTimeout);
|
|
63
|
+
if (this._options.unref) {
|
|
64
|
+
this._timeout.unref();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
this._fn(this._attempts);
|
|
68
|
+
}, timeout);
|
|
69
|
+
if (this._options.unref) {
|
|
70
|
+
this._timer.unref();
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
};
|
|
74
|
+
RetryOperation.prototype.attempt = function (fn, timeoutOps) {
|
|
75
|
+
this._fn = fn;
|
|
76
|
+
if (timeoutOps) {
|
|
77
|
+
if (timeoutOps.timeout) {
|
|
78
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
79
|
+
}
|
|
80
|
+
if (timeoutOps.cb) {
|
|
81
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this._operationTimeoutCb) {
|
|
85
|
+
this._timeout = setTimeout(() => {
|
|
86
|
+
this._operationTimeoutCb();
|
|
87
|
+
}, this._operationTimeout);
|
|
88
|
+
}
|
|
89
|
+
this._operationStart = new Date().getTime();
|
|
90
|
+
this._fn(this._attempts);
|
|
91
|
+
};
|
|
92
|
+
RetryOperation.prototype.try = function (fn) {
|
|
93
|
+
// console.log("Using RetryOperation.try() is deprecated");
|
|
94
|
+
this.attempt(fn);
|
|
95
|
+
};
|
|
96
|
+
RetryOperation.prototype.start = function (fn) {
|
|
97
|
+
// console.log("Using RetryOperation.start() is deprecated");
|
|
98
|
+
this.attempt(fn);
|
|
99
|
+
};
|
|
100
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
101
|
+
RetryOperation.prototype.errors = function () {
|
|
102
|
+
return this._errors;
|
|
103
|
+
};
|
|
104
|
+
RetryOperation.prototype.attempts = function () {
|
|
105
|
+
return this._attempts;
|
|
106
|
+
};
|
|
107
|
+
RetryOperation.prototype.mainError = function () {
|
|
108
|
+
if (this._errors.length === 0) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const counts = {};
|
|
112
|
+
let mainError = null;
|
|
113
|
+
let mainErrorCount = 0;
|
|
114
|
+
for (let i = 0; i < this._errors.length; i++) {
|
|
115
|
+
const error = this._errors[i];
|
|
116
|
+
const message = error.message;
|
|
117
|
+
const count = (counts[message] || 0) + 1;
|
|
118
|
+
counts[message] = count;
|
|
119
|
+
if (count >= mainErrorCount) {
|
|
120
|
+
mainError = error;
|
|
121
|
+
mainErrorCount = count;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return mainError;
|
|
125
|
+
};
|
|
126
|
+
export default RetryOperation;
|
package/package.json
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-def",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Typed API definitions with middleware support",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"types": "esm/index.d.ts",
|
|
7
7
|
"module": "esm/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"scripts": {
|
|
10
|
-
"prepublishOnly": "npm run test && npm run build",
|
|
11
|
-
"test": "
|
|
12
|
-
"test:unit": "ava",
|
|
13
|
-
"test:lint": "npm run lint:strict",
|
|
14
|
-
"test:types": "tsc --noEmit -p .",
|
|
10
|
+
"prepublishOnly": "npm run check && npm run test && npm run build",
|
|
11
|
+
"test": "jest",
|
|
15
12
|
"example:start": "cd example && npm run start",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"lint:fix": "npm run lint -- --fix",
|
|
19
|
-
"lint:strict": "npm run lint -- --max-warnings 0",
|
|
13
|
+
"check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --apply-unsafe .",
|
|
14
|
+
"check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check .",
|
|
20
15
|
"cleanup": "rimraf esm && rimraf cjs",
|
|
21
16
|
"build": "npm run cleanup && npm run build:esm && npm run build:cjs",
|
|
22
17
|
"build:esm": "tsc --module es2015 --target es2016 --outDir esm --preserveWatchOutput",
|
|
23
18
|
"build:cjs": "tsc --module commonjs --target es5 --outDir cjs --preserveWatchOutput",
|
|
24
|
-
"build:watch": "npm-run-all -p \"build:esm -- -w\" \"build:cjs -- -w\" \"lint:watch\"",
|
|
25
19
|
"website:dev": "cd website && npm run start",
|
|
26
20
|
"website:deploy": "cd website && npm run deploy"
|
|
27
21
|
},
|
|
@@ -45,35 +39,26 @@
|
|
|
45
39
|
"esm/",
|
|
46
40
|
"cjs/"
|
|
47
41
|
],
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
],
|
|
53
|
-
"files": [
|
|
54
|
-
"src/tests/**/*.test.ts"
|
|
55
|
-
],
|
|
56
|
-
"nodeArguments": [
|
|
57
|
-
"--require=@esbuild-kit/cjs-loader"
|
|
58
|
-
]
|
|
42
|
+
"jest": {
|
|
43
|
+
"transform": {
|
|
44
|
+
"^.+\\.(t|j)sx?$": "@swc/jest"
|
|
45
|
+
}
|
|
59
46
|
},
|
|
47
|
+
"repository": "https://github.com/Censkh/api-def",
|
|
60
48
|
"devDependencies": {
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@esbuild-kit/cjs-loader": "2.4.0",
|
|
49
|
+
"@biomejs/biome": "^1.5.3",
|
|
50
|
+
"@swc/jest": "0.2.31",
|
|
64
51
|
"@types/axios": "0.14.0",
|
|
65
|
-
"@types/
|
|
66
|
-
"@types/
|
|
67
|
-
"@
|
|
68
|
-
"
|
|
69
|
-
"ava": "5.0.1",
|
|
70
|
-
"axios": "1.1.3",
|
|
52
|
+
"@types/jest": "^29.5.11",
|
|
53
|
+
"@types/node": "20.11.6",
|
|
54
|
+
"@types/qs": "6.9.11",
|
|
55
|
+
"axios": "1.6.6",
|
|
71
56
|
"cross-env": "7.0.3",
|
|
72
|
-
"
|
|
73
|
-
"eslint-watch": "7.0.0",
|
|
57
|
+
"jest": "29.7.0",
|
|
74
58
|
"npm-run-all": "4.1.5",
|
|
75
59
|
"qs": "6.11.2",
|
|
76
|
-
"
|
|
60
|
+
"rimraf": "5.0.5",
|
|
61
|
+
"typescript": "5.3.3",
|
|
77
62
|
"zod": "3.22.4"
|
|
78
63
|
}
|
|
79
64
|
}
|