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.
Files changed (122) hide show
  1. package/README.md +1 -1
  2. package/cjs/Api.d.ts +35 -35
  3. package/cjs/Api.js +140 -144
  4. package/cjs/ApiConstants.d.ts +58 -58
  5. package/cjs/ApiConstants.js +55 -55
  6. package/cjs/ApiTypes.d.ts +103 -103
  7. package/cjs/ApiTypes.js +4 -4
  8. package/cjs/ApiUtils.d.ts +6 -6
  9. package/cjs/ApiUtils.js +51 -53
  10. package/cjs/Endpoint.d.ts +52 -52
  11. package/cjs/Endpoint.js +104 -108
  12. package/cjs/EndpointBuilder.d.ts +14 -14
  13. package/cjs/EndpointBuilder.js +46 -46
  14. package/cjs/MockingTypes.d.ts +30 -30
  15. package/cjs/MockingTypes.js +2 -2
  16. package/cjs/QueryHandling.d.ts +3 -3
  17. package/cjs/QueryHandling.js +24 -24
  18. package/cjs/RequestConfig.d.ts +2 -2
  19. package/cjs/RequestConfig.js +74 -74
  20. package/cjs/RequestContext.d.ts +48 -48
  21. package/cjs/RequestContext.js +235 -238
  22. package/cjs/RequestError.d.ts +30 -30
  23. package/cjs/RequestError.js +47 -47
  24. package/cjs/Requester.d.ts +3 -3
  25. package/cjs/Requester.js +335 -336
  26. package/cjs/TextDecoding.d.ts +1 -1
  27. package/cjs/TextDecoding.js +152 -139
  28. package/cjs/UtilTypes.d.ts +5 -5
  29. package/cjs/UtilTypes.js +2 -2
  30. package/cjs/Utils.d.ts +15 -15
  31. package/cjs/Utils.js +79 -77
  32. package/cjs/Validation.d.ts +8 -8
  33. package/cjs/Validation.js +2 -2
  34. package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
  35. package/cjs/backend/AxiosRequestBackend.js +99 -99
  36. package/cjs/backend/FetchRequestBackend.d.ts +15 -15
  37. package/cjs/backend/FetchRequestBackend.js +203 -202
  38. package/cjs/backend/MockRequestBackend.d.ts +11 -11
  39. package/cjs/backend/MockRequestBackend.js +164 -164
  40. package/cjs/backend/RequestBackend.d.ts +19 -19
  41. package/cjs/backend/RequestBackend.js +2 -2
  42. package/cjs/cache/CacheBackend.d.ts +6 -6
  43. package/cjs/cache/CacheBackend.js +2 -2
  44. package/cjs/cache/Caching.d.ts +10 -10
  45. package/cjs/cache/Caching.js +88 -88
  46. package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
  47. package/cjs/cache/LocalForageCacheBackend.js +24 -24
  48. package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
  49. package/cjs/cache/LocalStorageCacheBackend.js +77 -77
  50. package/cjs/index.d.ts +13 -13
  51. package/cjs/index.js +41 -41
  52. package/cjs/middleware/CacheMiddleware.d.ts +7 -7
  53. package/cjs/middleware/CacheMiddleware.js +107 -107
  54. package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
  55. package/cjs/middleware/LoggingMiddleware.js +82 -88
  56. package/cjs/util/retry/index.d.ts +3 -3
  57. package/cjs/util/retry/index.js +52 -52
  58. package/cjs/util/retry/lib/retry.d.ts +3 -3
  59. package/cjs/util/retry/lib/retry.js +50 -54
  60. package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
  61. package/cjs/util/retry/lib/retryOperation.js +130 -134
  62. package/esm/Api.d.ts +35 -35
  63. package/esm/Api.js +92 -98
  64. package/esm/ApiConstants.d.ts +58 -58
  65. package/esm/ApiConstants.js +52 -52
  66. package/esm/ApiTypes.d.ts +103 -103
  67. package/esm/ApiTypes.js +1 -1
  68. package/esm/ApiUtils.d.ts +6 -6
  69. package/esm/ApiUtils.js +43 -45
  70. package/esm/Endpoint.d.ts +52 -52
  71. package/esm/Endpoint.js +66 -70
  72. package/esm/EndpointBuilder.d.ts +14 -14
  73. package/esm/EndpointBuilder.js +31 -31
  74. package/esm/MockingTypes.d.ts +30 -30
  75. package/esm/MockingTypes.js +1 -1
  76. package/esm/QueryHandling.d.ts +3 -3
  77. package/esm/QueryHandling.js +19 -19
  78. package/esm/RequestConfig.d.ts +2 -2
  79. package/esm/RequestConfig.js +56 -56
  80. package/esm/RequestContext.d.ts +48 -48
  81. package/esm/RequestContext.js +167 -170
  82. package/esm/RequestError.d.ts +30 -30
  83. package/esm/RequestError.js +42 -42
  84. package/esm/Requester.d.ts +3 -3
  85. package/esm/Requester.js +252 -253
  86. package/esm/TextDecoding.d.ts +1 -1
  87. package/esm/TextDecoding.js +148 -135
  88. package/esm/UtilTypes.d.ts +5 -5
  89. package/esm/UtilTypes.js +1 -1
  90. package/esm/Utils.d.ts +15 -15
  91. package/esm/Utils.js +66 -68
  92. package/esm/Validation.d.ts +8 -8
  93. package/esm/Validation.js +1 -1
  94. package/esm/backend/AxiosRequestBackend.d.ts +13 -13
  95. package/esm/backend/AxiosRequestBackend.js +62 -62
  96. package/esm/backend/FetchRequestBackend.d.ts +15 -15
  97. package/esm/backend/FetchRequestBackend.js +136 -136
  98. package/esm/backend/MockRequestBackend.d.ts +11 -11
  99. package/esm/backend/MockRequestBackend.js +116 -116
  100. package/esm/backend/RequestBackend.d.ts +19 -19
  101. package/esm/backend/RequestBackend.js +1 -1
  102. package/esm/cache/CacheBackend.d.ts +6 -6
  103. package/esm/cache/CacheBackend.js +1 -1
  104. package/esm/cache/Caching.d.ts +10 -10
  105. package/esm/cache/Caching.js +39 -39
  106. package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
  107. package/esm/cache/LocalForageCacheBackend.js +20 -20
  108. package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
  109. package/esm/cache/LocalStorageCacheBackend.js +32 -32
  110. package/esm/index.d.ts +13 -13
  111. package/esm/index.js +14 -15
  112. package/esm/middleware/CacheMiddleware.d.ts +7 -7
  113. package/esm/middleware/CacheMiddleware.js +58 -58
  114. package/esm/middleware/LoggingMiddleware.d.ts +6 -6
  115. package/esm/middleware/LoggingMiddleware.js +77 -83
  116. package/esm/util/retry/index.d.ts +3 -3
  117. package/esm/util/retry/index.js +50 -50
  118. package/esm/util/retry/lib/retry.d.ts +3 -3
  119. package/esm/util/retry/lib/retry.js +35 -39
  120. package/esm/util/retry/lib/retryOperation.d.ts +27 -27
  121. package/esm/util/retry/lib/retryOperation.js +126 -132
  122. package/package.json +19 -34
@@ -1,132 +1,126 @@
1
- function RetryOperation(timeouts, options) {
2
- // Compatibility for the old (timeouts, retryForever) signature
3
- if (typeof options === "boolean") {
4
- options = { forever: options };
5
- }
6
- this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
7
- this._timeouts = timeouts;
8
- this._options = options || {};
9
- this._maxRetryTime = options && options.maxRetryTime || Infinity;
10
- this._fn = null;
11
- this._errors = [];
12
- this._attempts = 1;
13
- this._operationTimeout = null;
14
- this._operationTimeoutCb = null;
15
- this._timeout = null;
16
- this._operationStart = null;
17
- this._timer = null;
18
- if (this._options.forever) {
19
- this._cachedTimeouts = this._timeouts.slice(0);
20
- }
21
- }
22
- RetryOperation.prototype.reset = function () {
23
- this._attempts = 1;
24
- this._timeouts = this._originalTimeouts.slice(0);
25
- };
26
- RetryOperation.prototype.stop = function () {
27
- if (this._timeout) {
28
- clearTimeout(this._timeout);
29
- }
30
- if (this._timer) {
31
- clearTimeout(this._timer);
32
- }
33
- this._timeouts = [];
34
- this._cachedTimeouts = null;
35
- };
36
- RetryOperation.prototype.retry = function (err) {
37
- if (this._timeout) {
38
- clearTimeout(this._timeout);
39
- }
40
- if (!err) {
41
- return false;
42
- }
43
- var currentTime = new Date().getTime();
44
- if (err && currentTime - this._operationStart >= this._maxRetryTime) {
45
- this._errors.push(err);
46
- this._errors.unshift(new Error("RetryOperation timeout occurred"));
47
- return false;
48
- }
49
- this._errors.push(err);
50
- var timeout = this._timeouts.shift();
51
- if (timeout === undefined) {
52
- if (this._cachedTimeouts) {
53
- // retry forever, only keep last error
54
- this._errors.splice(0, this._errors.length - 1);
55
- timeout = this._cachedTimeouts.slice(-1);
56
- }
57
- else {
58
- return false;
59
- }
60
- }
61
- var self = this;
62
- this._timer = setTimeout(function () {
63
- self._attempts++;
64
- if (self._operationTimeoutCb) {
65
- self._timeout = setTimeout(function () {
66
- self._operationTimeoutCb(self._attempts);
67
- }, self._operationTimeout);
68
- if (self._options.unref) {
69
- self._timeout.unref();
70
- }
71
- }
72
- self._fn(self._attempts);
73
- }, timeout);
74
- if (this._options.unref) {
75
- this._timer.unref();
76
- }
77
- return true;
78
- };
79
- RetryOperation.prototype.attempt = function (fn, timeoutOps) {
80
- this._fn = fn;
81
- if (timeoutOps) {
82
- if (timeoutOps.timeout) {
83
- this._operationTimeout = timeoutOps.timeout;
84
- }
85
- if (timeoutOps.cb) {
86
- this._operationTimeoutCb = timeoutOps.cb;
87
- }
88
- }
89
- var self = this;
90
- if (this._operationTimeoutCb) {
91
- this._timeout = setTimeout(function () {
92
- self._operationTimeoutCb();
93
- }, self._operationTimeout);
94
- }
95
- this._operationStart = new Date().getTime();
96
- this._fn(this._attempts);
97
- };
98
- RetryOperation.prototype.try = function (fn) {
99
- // console.log("Using RetryOperation.try() is deprecated");
100
- this.attempt(fn);
101
- };
102
- RetryOperation.prototype.start = function (fn) {
103
- // console.log("Using RetryOperation.start() is deprecated");
104
- this.attempt(fn);
105
- };
106
- RetryOperation.prototype.start = RetryOperation.prototype.try;
107
- RetryOperation.prototype.errors = function () {
108
- return this._errors;
109
- };
110
- RetryOperation.prototype.attempts = function () {
111
- return this._attempts;
112
- };
113
- RetryOperation.prototype.mainError = function () {
114
- if (this._errors.length === 0) {
115
- return null;
116
- }
117
- var counts = {};
118
- var mainError = null;
119
- var mainErrorCount = 0;
120
- for (var i = 0; i < this._errors.length; i++) {
121
- var error = this._errors[i];
122
- var message = error.message;
123
- var count = (counts[message] || 0) + 1;
124
- counts[message] = count;
125
- if (count >= mainErrorCount) {
126
- mainError = error;
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.1",
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": "npm run test:types && npm run test:lint && npm run test:unit",
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
- "lint": "esw --ext .tsx,.ts src",
17
- "lint:watch": "npm run lint -- --watch",
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
- "repository": "https://github.com/Censkh/api-def",
49
- "ava": {
50
- "extensions": [
51
- "ts"
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
- "@babel/preset-env": "7.14.8",
62
- "@babel/preset-typescript": "7.14.5",
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/node": "16.4.6",
66
- "@types/qs": "6.9.8",
67
- "@typescript-eslint/eslint-plugin": "4.28.5",
68
- "@typescript-eslint/parser": "4.28.5",
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
- "eslint": "7.31.0",
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
- "typescript": "4.8.4",
60
+ "rimraf": "5.0.5",
61
+ "typescript": "5.3.3",
77
62
  "zod": "3.22.4"
78
63
  }
79
64
  }