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