api-def 0.9.1 → 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.
- 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 +202 -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 +12 -32
package/esm/TextDecoding.js
CHANGED
|
@@ -1,135 +1,148 @@
|
|
|
1
|
-
/* eslint-disable prefer-const */
|
|
2
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
3
|
-
// polyfill from https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/EncoderDecoderTogether.src.js
|
|
4
|
-
export const textDecode = (inputArrayOrBuffer, options) => {
|
|
5
|
-
if (typeof TextDecoder !== "undefined") {
|
|
6
|
-
return new TextDecoder("utf-8").decode(inputArrayOrBuffer);
|
|
7
|
-
}
|
|
8
|
-
const fromCharCode = String.fromCharCode;
|
|
9
|
-
const Object_prototype_toString =
|
|
10
|
-
const sharedArrayBufferString = Object_prototype_toString.call(window
|
|
11
|
-
const undefinedObjectString = Object_prototype_toString();
|
|
12
|
-
const NativeUint8Array = window.Uint8Array;
|
|
13
|
-
const patchedU8Array = NativeUint8Array || Array;
|
|
14
|
-
const nativeArrayBuffer = NativeUint8Array ? ArrayBuffer : patchedU8Array;
|
|
15
|
-
const arrayBuffer_isView = nativeArrayBuffer.isView ||
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
case
|
|
46
|
-
cp1 = inputAs8[index = index + 1 | 0] & 0xff;
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
case
|
|
111
|
-
case
|
|
112
|
-
case
|
|
113
|
-
case
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
/* eslint-disable prefer-const */
|
|
2
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
3
|
+
// polyfill from https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/EncoderDecoderTogether.src.js
|
|
4
|
+
export const textDecode = (inputArrayOrBuffer, options) => {
|
|
5
|
+
if (typeof TextDecoder !== "undefined") {
|
|
6
|
+
return new TextDecoder("utf-8").decode(inputArrayOrBuffer);
|
|
7
|
+
}
|
|
8
|
+
const fromCharCode = String.fromCharCode;
|
|
9
|
+
const Object_prototype_toString = {}.toString;
|
|
10
|
+
const sharedArrayBufferString = Object_prototype_toString.call(window.SharedArrayBuffer);
|
|
11
|
+
const undefinedObjectString = Object_prototype_toString();
|
|
12
|
+
const NativeUint8Array = window.Uint8Array;
|
|
13
|
+
const patchedU8Array = NativeUint8Array || Array;
|
|
14
|
+
const nativeArrayBuffer = NativeUint8Array ? ArrayBuffer : patchedU8Array;
|
|
15
|
+
const arrayBuffer_isView = nativeArrayBuffer.isView || ((x) => x && "length" in x);
|
|
16
|
+
const arrayBufferString = Object_prototype_toString.call(nativeArrayBuffer.prototype);
|
|
17
|
+
const tmpBufferU16 = new (NativeUint8Array ? Uint16Array : patchedU8Array)(32);
|
|
18
|
+
let inputAs8 = inputArrayOrBuffer;
|
|
19
|
+
let asObjectString;
|
|
20
|
+
if (!arrayBuffer_isView(inputAs8)) {
|
|
21
|
+
asObjectString = Object_prototype_toString.call(inputAs8);
|
|
22
|
+
if (asObjectString !== arrayBufferString && asObjectString !== sharedArrayBufferString && asObjectString !== undefinedObjectString)
|
|
23
|
+
throw TypeError("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
|
|
24
|
+
inputAs8 = NativeUint8Array ? new patchedU8Array(inputAs8) : inputAs8 || [];
|
|
25
|
+
}
|
|
26
|
+
let resultingString = "";
|
|
27
|
+
let tmpStr = "";
|
|
28
|
+
let index = 0;
|
|
29
|
+
const len = inputAs8.length | 0;
|
|
30
|
+
const lenMinus32 = (len - 32) | 0;
|
|
31
|
+
let nextEnd = 0;
|
|
32
|
+
let cp0 = 0;
|
|
33
|
+
let codePoint = 0;
|
|
34
|
+
let minBits = 0;
|
|
35
|
+
let cp1 = 0;
|
|
36
|
+
let pos = 0;
|
|
37
|
+
let tmp = -1;
|
|
38
|
+
// Note that tmp represents the 2nd half of a surrogate pair incase a surrogate gets divided between blocks
|
|
39
|
+
while (index < len) {
|
|
40
|
+
nextEnd = index <= lenMinus32 ? 32 : (len - index) | 0;
|
|
41
|
+
for (; pos < nextEnd; index = (index + 1) | 0, pos = (pos + 1) | 0) {
|
|
42
|
+
cp0 = inputAs8[index] & 0xff;
|
|
43
|
+
switch (cp0 >> 4) {
|
|
44
|
+
// biome-ignore lint: optimised code
|
|
45
|
+
case 15:
|
|
46
|
+
cp1 = inputAs8[(index = (index + 1) | 0)] & 0xff;
|
|
47
|
+
if (cp1 >> 6 !== 0b10 || 0b11110111 < cp0) {
|
|
48
|
+
index = (index - 1) | 0;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
codePoint = ((cp0 & 0b111) << 6) | (cp1 & 0b00111111);
|
|
52
|
+
minBits = 5; // 20 ensures it never passes -> all invalid replacements
|
|
53
|
+
cp0 = 0x100; // keep track of th bit size
|
|
54
|
+
// biome-ignore lint: optimised code
|
|
55
|
+
case 14:
|
|
56
|
+
cp1 = inputAs8[(index = (index + 1) | 0)] & 0xff;
|
|
57
|
+
codePoint <<= 6;
|
|
58
|
+
codePoint |= ((cp0 & 0b1111) << 6) | (cp1 & 0b00111111);
|
|
59
|
+
minBits = cp1 >> 6 === 0b10 ? (minBits + 4) | 0 : 24; // 24 ensures it never passes -> all invalid replacements
|
|
60
|
+
cp0 = (cp0 + 0x100) & 0x300; // keep track of th bit size
|
|
61
|
+
case 13:
|
|
62
|
+
// biome-ignore lint: optimised code
|
|
63
|
+
case 12:
|
|
64
|
+
cp1 = inputAs8[(index = (index + 1) | 0)] & 0xff;
|
|
65
|
+
codePoint <<= 6;
|
|
66
|
+
codePoint |= ((cp0 & 0b11111) << 6) | (cp1 & 0b00111111);
|
|
67
|
+
minBits = (minBits + 7) | 0;
|
|
68
|
+
// Now, process the code point
|
|
69
|
+
if (index < len && cp1 >> 6 === 0b10 && codePoint >> minBits && codePoint < 0x110000) {
|
|
70
|
+
cp0 = codePoint;
|
|
71
|
+
codePoint = (codePoint - 0x10000) | 0;
|
|
72
|
+
if (0 <= codePoint /*0xffff < codePoint*/) {
|
|
73
|
+
// BMP code point
|
|
74
|
+
//nextEnd = nextEnd - 1|0;
|
|
75
|
+
tmp = ((codePoint >> 10) + 0xd800) | 0; // highSurrogate
|
|
76
|
+
cp0 = ((codePoint & 0x3ff) + 0xdc00) | 0; // lowSurrogate (will be inserted later in the switch-statement)
|
|
77
|
+
if (pos < 31) {
|
|
78
|
+
// notice 31 instead of 32
|
|
79
|
+
tmpBufferU16[pos] = tmp;
|
|
80
|
+
pos = (pos + 1) | 0;
|
|
81
|
+
tmp = -1;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// else, we are at the end of the inputAs8 and let tmp0 be filled in later on
|
|
85
|
+
// NOTE that cp1 is being used as a temporary variable for the swapping of tmp with cp0
|
|
86
|
+
cp1 = tmp;
|
|
87
|
+
tmp = cp0;
|
|
88
|
+
cp0 = cp1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
nextEnd = (nextEnd + 1) | 0; // because we are advancing i without advancing pos
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// invalid code point means replacing the whole thing with null replacement characters
|
|
96
|
+
cp0 >>= 8;
|
|
97
|
+
index = (index - cp0 - 1) | 0; // reset index back to what it was before
|
|
98
|
+
cp0 = 0xfffd;
|
|
99
|
+
}
|
|
100
|
+
// Finally, reset the variables for the next go-around
|
|
101
|
+
minBits = 0;
|
|
102
|
+
codePoint = 0;
|
|
103
|
+
nextEnd = index <= lenMinus32 ? 32 : (len - index) | 0;
|
|
104
|
+
/*case 11:
|
|
105
|
+
case 10:
|
|
106
|
+
case 9:
|
|
107
|
+
case 8:
|
|
108
|
+
codePoint ? codePoint = 0 : cp0 = 0xfffd; // fill with invalid replacement character
|
|
109
|
+
case 7:
|
|
110
|
+
case 6:
|
|
111
|
+
case 5:
|
|
112
|
+
case 4:
|
|
113
|
+
case 3:
|
|
114
|
+
case 2:
|
|
115
|
+
case 1:
|
|
116
|
+
case 0:
|
|
117
|
+
tmpBufferU16[pos] = cp0;
|
|
118
|
+
continue;*/
|
|
119
|
+
// biome-ignore lint: optimised code
|
|
120
|
+
default: // fill with invalid replacement character
|
|
121
|
+
tmpBufferU16[pos] = cp0;
|
|
122
|
+
continue;
|
|
123
|
+
case 11:
|
|
124
|
+
case 10:
|
|
125
|
+
case 9:
|
|
126
|
+
case 8:
|
|
127
|
+
}
|
|
128
|
+
tmpBufferU16[pos] = 0xfffd; // fill with invalid replacement character
|
|
129
|
+
}
|
|
130
|
+
tmpStr += fromCharCode(tmpBufferU16[0], tmpBufferU16[1], tmpBufferU16[2], tmpBufferU16[3], tmpBufferU16[4], tmpBufferU16[5], tmpBufferU16[6], tmpBufferU16[7], tmpBufferU16[8], tmpBufferU16[9], tmpBufferU16[10], tmpBufferU16[11], tmpBufferU16[12], tmpBufferU16[13], tmpBufferU16[14], tmpBufferU16[15], tmpBufferU16[16], tmpBufferU16[17], tmpBufferU16[18], tmpBufferU16[19], tmpBufferU16[20], tmpBufferU16[21], tmpBufferU16[22], tmpBufferU16[23], tmpBufferU16[24], tmpBufferU16[25], tmpBufferU16[26], tmpBufferU16[27], tmpBufferU16[28], tmpBufferU16[29], tmpBufferU16[30], tmpBufferU16[31]);
|
|
131
|
+
if (pos < 32)
|
|
132
|
+
tmpStr = tmpStr.slice(0, (pos - 32) | 0); //-(32-pos));
|
|
133
|
+
if (index < len) {
|
|
134
|
+
//fromCharCode.apply(0, tmpBufferU16 : NativeUint8Array ? tmpBufferU16.subarray(0,pos) : tmpBufferU16.slice(0,pos));
|
|
135
|
+
tmpBufferU16[0] = tmp;
|
|
136
|
+
pos = ~tmp >>> 31; //tmp !== -1 ? 1 : 0;
|
|
137
|
+
tmp = -1;
|
|
138
|
+
if (tmpStr.length < resultingString.length)
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
else if (tmp !== -1) {
|
|
142
|
+
tmpStr += fromCharCode(tmp);
|
|
143
|
+
}
|
|
144
|
+
resultingString += tmpStr;
|
|
145
|
+
tmpStr = "";
|
|
146
|
+
}
|
|
147
|
+
return resultingString;
|
|
148
|
+
};
|
package/esm/UtilTypes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Endpoint from "./Endpoint";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
import Endpoint from "./Endpoint";
|
|
2
|
+
export type ResponseOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<infer R, any, any, any> ? R : never;
|
|
3
|
+
export type ParamsOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, infer P, any, any> ? P : never;
|
|
4
|
+
export type QueryOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, infer Q, any> ? Q : never;
|
|
5
|
+
export type BodyOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, any, infer B> ? B : never;
|
package/esm/UtilTypes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/esm/Utils.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export declare const assign: typeof Object["assign"];
|
|
2
|
-
export declare const padNumber: (stringOrNumber: string | number, maxLength: number) => string;
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export declare const getGlobal: () => any;
|
|
6
|
-
export declare const getGlobalFetch: () => Fetch | undefined;
|
|
7
|
-
export declare const noop: () => void;
|
|
8
|
-
/**
|
|
9
|
-
* Just used to simulate lag, or loading times.
|
|
10
|
-
* @param value The value you want to return after the delay
|
|
11
|
-
* @param delayMs The delay in ms
|
|
12
|
-
* @returns The `value` param as a Promise
|
|
13
|
-
*/
|
|
14
|
-
export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
|
|
15
|
-
export declare const randInt: (min: number, max: number) => number;
|
|
1
|
+
export declare const assign: (typeof Object)["assign"];
|
|
2
|
+
export declare const padNumber: (stringOrNumber: string | number, maxLength: number) => string;
|
|
3
|
+
export type EnumOf<T extends Record<string, any>> = T[keyof T];
|
|
4
|
+
export type Fetch = typeof window.fetch;
|
|
5
|
+
export declare const getGlobal: () => any;
|
|
6
|
+
export declare const getGlobalFetch: () => Fetch | undefined;
|
|
7
|
+
export declare const noop: () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Just used to simulate lag, or loading times.
|
|
10
|
+
* @param value The value you want to return after the delay
|
|
11
|
+
* @param delayMs The delay in ms
|
|
12
|
+
* @returns The `value` param as a Promise
|
|
13
|
+
*/
|
|
14
|
+
export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
|
|
15
|
+
export declare const randInt: (min: number, max: number) => number;
|
package/esm/Utils.js
CHANGED
|
@@ -1,68 +1,66 @@
|
|
|
1
|
-
// polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
2
|
-
export const assign = Object.assign ||
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
return (Math.floor(Math.random() * (maxI - minI + 1)) + minI);
|
|
68
|
-
};
|
|
1
|
+
// polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
2
|
+
export const assign = Object.assign ||
|
|
3
|
+
((target, ...varArgs) => {
|
|
4
|
+
if (target === null || target === undefined) {
|
|
5
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
6
|
+
}
|
|
7
|
+
const to = Object(target);
|
|
8
|
+
for (let index = 0; index < varArgs.length; index++) {
|
|
9
|
+
// eslint-disable-next-line prefer-rest-params
|
|
10
|
+
const nextSource = varArgs[index];
|
|
11
|
+
if (nextSource !== null && nextSource !== undefined) {
|
|
12
|
+
for (const nextKey in nextSource) {
|
|
13
|
+
// Avoid bugs when hasOwnProperty is shadowed
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
15
|
+
to[nextKey] = nextSource[nextKey];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
});
|
|
22
|
+
export const padNumber = (stringOrNumber, maxLength) => {
|
|
23
|
+
const string = stringOrNumber.toString();
|
|
24
|
+
return string.length >= maxLength ? string : "0".repeat(maxLength - string.length) + string;
|
|
25
|
+
};
|
|
26
|
+
export const getGlobal = () => {
|
|
27
|
+
if (typeof global !== "undefined") {
|
|
28
|
+
return global;
|
|
29
|
+
}
|
|
30
|
+
if (typeof window !== "undefined") {
|
|
31
|
+
return window;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
};
|
|
35
|
+
export const getGlobalFetch = () => {
|
|
36
|
+
const global = getGlobal();
|
|
37
|
+
if (global && typeof global.fetch === "function") {
|
|
38
|
+
return global.fetch.bind(global);
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
};
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
43
|
+
export const noop = () => { };
|
|
44
|
+
/**
|
|
45
|
+
* Just used to simulate lag, or loading times.
|
|
46
|
+
* @param value The value you want to return after the delay
|
|
47
|
+
* @param delayMs The delay in ms
|
|
48
|
+
* @returns The `value` param as a Promise
|
|
49
|
+
*/
|
|
50
|
+
export const delayThenReturn = (value, delayMs) => {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
if (delayMs > 0) {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
resolve(value);
|
|
55
|
+
}, delayMs);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
resolve(value);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
export const randInt = (min, max) => {
|
|
63
|
+
const minI = Math.ceil(min);
|
|
64
|
+
const maxI = Math.floor(max);
|
|
65
|
+
return Math.floor(Math.random() * (maxI - minI + 1)) + minI;
|
|
66
|
+
};
|
package/esm/Validation.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as zod from "zod";
|
|
2
|
-
import { Body, Params, Query } from "./ApiTypes";
|
|
3
|
-
export interface Validation<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
4
|
-
query?: zod.Schema<Q>;
|
|
5
|
-
params?: zod.Schema<P>;
|
|
6
|
-
body?: zod.Schema<B>;
|
|
7
|
-
response?: zod.Schema<R>;
|
|
8
|
-
}
|
|
1
|
+
import * as zod from "zod";
|
|
2
|
+
import { Body, Params, Query } from "./ApiTypes";
|
|
3
|
+
export interface Validation<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
4
|
+
query?: zod.Schema<Q>;
|
|
5
|
+
params?: zod.Schema<P>;
|
|
6
|
+
body?: zod.Schema<B>;
|
|
7
|
+
response?: zod.Schema<R>;
|
|
8
|
+
}
|
package/esm/Validation.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiResponse } from "../ApiTypes";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
|
|
6
|
-
export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
|
|
7
|
-
readonly id = "axios";
|
|
8
|
-
constructor(axiosLibrary: any);
|
|
9
|
-
extractResponseFromError(error: Error): Promise<AxiosResponse | null | undefined>;
|
|
10
|
-
convertResponse<T>(context: RequestContext, response: AxiosResponse): Promise<ConvertedApiResponse<T>>;
|
|
11
|
-
makeRequest(context: RequestContext): RequestOperation<AxiosResponse>;
|
|
12
|
-
getErrorInfo(error: Error, response: ApiResponse | undefined | null): RequestBackendErrorInfo | undefined;
|
|
13
|
-
}
|
|
1
|
+
import type { AxiosError, AxiosResponse } from "axios";
|
|
2
|
+
import { ApiResponse } from "../ApiTypes";
|
|
3
|
+
import RequestContext from "../RequestContext";
|
|
4
|
+
import RequestBackend, { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
|
|
5
|
+
export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
|
|
6
|
+
export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
|
|
7
|
+
readonly id = "axios";
|
|
8
|
+
constructor(axiosLibrary: any);
|
|
9
|
+
extractResponseFromError(error: Error): Promise<AxiosResponse | null | undefined>;
|
|
10
|
+
convertResponse<T>(context: RequestContext, response: AxiosResponse): Promise<ConvertedApiResponse<T>>;
|
|
11
|
+
makeRequest(context: RequestContext): RequestOperation<AxiosResponse>;
|
|
12
|
+
getErrorInfo(error: Error, response: ApiResponse | undefined | null): RequestBackendErrorInfo | undefined;
|
|
13
|
+
}
|