api-def 0.9.0 → 0.9.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.
Files changed (121) hide show
  1. package/cjs/Api.d.ts +35 -35
  2. package/cjs/Api.js +140 -144
  3. package/cjs/ApiConstants.d.ts +58 -58
  4. package/cjs/ApiConstants.js +55 -55
  5. package/cjs/ApiTypes.d.ts +103 -103
  6. package/cjs/ApiTypes.js +4 -4
  7. package/cjs/ApiUtils.d.ts +6 -6
  8. package/cjs/ApiUtils.js +51 -53
  9. package/cjs/Endpoint.d.ts +52 -52
  10. package/cjs/Endpoint.js +104 -108
  11. package/cjs/EndpointBuilder.d.ts +14 -14
  12. package/cjs/EndpointBuilder.js +46 -46
  13. package/cjs/MockingTypes.d.ts +30 -30
  14. package/cjs/MockingTypes.js +2 -2
  15. package/cjs/QueryHandling.d.ts +3 -3
  16. package/cjs/QueryHandling.js +24 -24
  17. package/cjs/RequestConfig.d.ts +2 -2
  18. package/cjs/RequestConfig.js +74 -74
  19. package/cjs/RequestContext.d.ts +48 -48
  20. package/cjs/RequestContext.js +235 -238
  21. package/cjs/RequestError.d.ts +30 -30
  22. package/cjs/RequestError.js +47 -47
  23. package/cjs/Requester.d.ts +3 -3
  24. package/cjs/Requester.js +335 -336
  25. package/cjs/TextDecoding.d.ts +1 -1
  26. package/cjs/TextDecoding.js +152 -139
  27. package/cjs/UtilTypes.d.ts +5 -5
  28. package/cjs/UtilTypes.js +2 -2
  29. package/cjs/Utils.d.ts +15 -15
  30. package/cjs/Utils.js +79 -77
  31. package/cjs/Validation.d.ts +8 -8
  32. package/cjs/Validation.js +2 -2
  33. package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
  34. package/cjs/backend/AxiosRequestBackend.js +99 -99
  35. package/cjs/backend/FetchRequestBackend.d.ts +15 -15
  36. package/cjs/backend/FetchRequestBackend.js +202 -197
  37. package/cjs/backend/MockRequestBackend.d.ts +11 -11
  38. package/cjs/backend/MockRequestBackend.js +164 -164
  39. package/cjs/backend/RequestBackend.d.ts +19 -19
  40. package/cjs/backend/RequestBackend.js +2 -2
  41. package/cjs/cache/CacheBackend.d.ts +6 -6
  42. package/cjs/cache/CacheBackend.js +2 -2
  43. package/cjs/cache/Caching.d.ts +10 -10
  44. package/cjs/cache/Caching.js +88 -88
  45. package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
  46. package/cjs/cache/LocalForageCacheBackend.js +24 -24
  47. package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
  48. package/cjs/cache/LocalStorageCacheBackend.js +77 -77
  49. package/cjs/index.d.ts +13 -13
  50. package/cjs/index.js +41 -41
  51. package/cjs/middleware/CacheMiddleware.d.ts +7 -7
  52. package/cjs/middleware/CacheMiddleware.js +107 -107
  53. package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
  54. package/cjs/middleware/LoggingMiddleware.js +82 -88
  55. package/cjs/util/retry/index.d.ts +3 -3
  56. package/cjs/util/retry/index.js +52 -52
  57. package/cjs/util/retry/lib/retry.d.ts +3 -3
  58. package/cjs/util/retry/lib/retry.js +50 -54
  59. package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
  60. package/cjs/util/retry/lib/retryOperation.js +130 -134
  61. package/esm/Api.d.ts +35 -35
  62. package/esm/Api.js +92 -98
  63. package/esm/ApiConstants.d.ts +58 -58
  64. package/esm/ApiConstants.js +52 -52
  65. package/esm/ApiTypes.d.ts +103 -103
  66. package/esm/ApiTypes.js +1 -1
  67. package/esm/ApiUtils.d.ts +6 -6
  68. package/esm/ApiUtils.js +43 -45
  69. package/esm/Endpoint.d.ts +52 -52
  70. package/esm/Endpoint.js +66 -70
  71. package/esm/EndpointBuilder.d.ts +14 -14
  72. package/esm/EndpointBuilder.js +31 -31
  73. package/esm/MockingTypes.d.ts +30 -30
  74. package/esm/MockingTypes.js +1 -1
  75. package/esm/QueryHandling.d.ts +3 -3
  76. package/esm/QueryHandling.js +19 -19
  77. package/esm/RequestConfig.d.ts +2 -2
  78. package/esm/RequestConfig.js +56 -56
  79. package/esm/RequestContext.d.ts +48 -48
  80. package/esm/RequestContext.js +167 -170
  81. package/esm/RequestError.d.ts +30 -30
  82. package/esm/RequestError.js +42 -42
  83. package/esm/Requester.d.ts +3 -3
  84. package/esm/Requester.js +252 -253
  85. package/esm/TextDecoding.d.ts +1 -1
  86. package/esm/TextDecoding.js +148 -135
  87. package/esm/UtilTypes.d.ts +5 -5
  88. package/esm/UtilTypes.js +1 -1
  89. package/esm/Utils.d.ts +15 -15
  90. package/esm/Utils.js +66 -68
  91. package/esm/Validation.d.ts +8 -8
  92. package/esm/Validation.js +1 -1
  93. package/esm/backend/AxiosRequestBackend.d.ts +13 -13
  94. package/esm/backend/AxiosRequestBackend.js +62 -62
  95. package/esm/backend/FetchRequestBackend.d.ts +15 -15
  96. package/esm/backend/FetchRequestBackend.js +136 -126
  97. package/esm/backend/MockRequestBackend.d.ts +11 -11
  98. package/esm/backend/MockRequestBackend.js +116 -116
  99. package/esm/backend/RequestBackend.d.ts +19 -19
  100. package/esm/backend/RequestBackend.js +1 -1
  101. package/esm/cache/CacheBackend.d.ts +6 -6
  102. package/esm/cache/CacheBackend.js +1 -1
  103. package/esm/cache/Caching.d.ts +10 -10
  104. package/esm/cache/Caching.js +39 -39
  105. package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
  106. package/esm/cache/LocalForageCacheBackend.js +20 -20
  107. package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
  108. package/esm/cache/LocalStorageCacheBackend.js +32 -32
  109. package/esm/index.d.ts +13 -13
  110. package/esm/index.js +14 -15
  111. package/esm/middleware/CacheMiddleware.d.ts +7 -7
  112. package/esm/middleware/CacheMiddleware.js +58 -58
  113. package/esm/middleware/LoggingMiddleware.d.ts +6 -6
  114. package/esm/middleware/LoggingMiddleware.js +77 -83
  115. package/esm/util/retry/index.d.ts +3 -3
  116. package/esm/util/retry/index.js +50 -50
  117. package/esm/util/retry/lib/retry.d.ts +3 -3
  118. package/esm/util/retry/lib/retry.js +35 -39
  119. package/esm/util/retry/lib/retryOperation.d.ts +27 -27
  120. package/esm/util/retry/lib/retryOperation.js +126 -132
  121. package/package.json +12 -32
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -8,20 +8,16 @@
8
8
  "sideEffects": false,
9
9
  "scripts": {
10
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",
11
+ "test": "npm run test:types && npm run check && npm run test:unit",
12
+ "test:unit": "bun test --timeout 10000",
14
13
  "test:types": "tsc --noEmit -p .",
15
14
  "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",
15
+ "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --apply-unsafe .",
16
+ "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check .",
20
17
  "cleanup": "rimraf esm && rimraf cjs",
21
18
  "build": "npm run cleanup && npm run build:esm && npm run build:cjs",
22
19
  "build:esm": "tsc --module es2015 --target es2016 --outDir esm --preserveWatchOutput",
23
20
  "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
21
  "website:dev": "cd website && npm run start",
26
22
  "website:deploy": "cd website && npm run deploy"
27
23
  },
@@ -46,34 +42,18 @@
46
42
  "cjs/"
47
43
  ],
48
44
  "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
- ]
59
- },
60
45
  "devDependencies": {
61
- "@babel/preset-env": "7.14.8",
62
- "@babel/preset-typescript": "7.14.5",
63
- "@esbuild-kit/cjs-loader": "2.4.0",
46
+ "@biomejs/biome": "^1.5.3",
64
47
  "@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",
48
+ "@types/jest": "^29.5.11",
49
+ "@types/node": "20.11.6",
50
+ "@types/qs": "6.9.11",
51
+ "axios": "1.6.6",
71
52
  "cross-env": "7.0.3",
72
- "eslint": "7.31.0",
73
- "eslint-watch": "7.0.0",
74
53
  "npm-run-all": "4.1.5",
75
54
  "qs": "6.11.2",
76
- "typescript": "4.8.4",
55
+ "rimraf": "5.0.5",
56
+ "typescript": "5.3.3",
77
57
  "zod": "3.22.4"
78
58
  }
79
59
  }