api-def 0.12.1 → 0.14.0-alpha.1
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 +3 -0
- package/bin/index.js +312 -313
- package/cjs/Api.d.ts +1 -1
- package/cjs/Api.js +99 -145
- package/cjs/ApiTypes.d.ts +3 -2
- package/cjs/ApiUtils.js +30 -32
- package/cjs/Endpoint.d.ts +1 -1
- package/cjs/Endpoint.js +112 -175
- package/cjs/EndpointBuilder.d.ts +17 -0
- package/cjs/EndpointBuilder.js +55 -36
- package/cjs/QueryHandling.js +12 -13
- package/cjs/RequestConfig.js +54 -36
- package/cjs/RequestContext.d.ts +2 -1
- package/cjs/RequestContext.js +143 -180
- package/cjs/RequestError.js +16 -19
- package/cjs/Requester.js +231 -312
- package/cjs/TextDecoding.js +31 -31
- package/cjs/Utils.d.ts +1 -0
- package/cjs/Utils.js +74 -25
- package/cjs/Validation.d.ts +8 -1
- package/cjs/backend/AxiosRequestBackend.d.ts +1 -1
- package/cjs/backend/AxiosRequestBackend.js +65 -172
- package/cjs/backend/FetchRequestBackend.d.ts +1 -1
- package/cjs/backend/FetchRequestBackend.js +108 -154
- package/cjs/backend/MockRequestBackend.d.ts +1 -1
- package/cjs/backend/MockRequestBackend.js +146 -208
- package/cjs/cache/ClientCaching.js +26 -74
- package/cjs/cache/LocalForageClientCacheBackend.js +15 -83
- package/cjs/cache/LocalStorageClientCacheBackend.js +14 -73
- package/cjs/index.d.ts +11 -11
- package/cjs/index.js +24 -21
- package/cjs/middleware/ClientCacheMiddleware.js +80 -103
- package/cjs/middleware/LoggingMiddleware.js +71 -42
- package/cjs/util/retry/index.js +42 -9
- package/cjs/util/retry/lib/retry.js +25 -27
- package/cjs/util/retry/lib/retryOperation.d.ts +1 -26
- package/cjs/util/retry/lib/retryOperation.js +21 -23
- package/esm/Api.d.ts +6 -6
- package/esm/Api.js +12 -25
- package/esm/ApiConstants.d.ts +1 -1
- package/esm/ApiTypes.d.ts +7 -6
- package/esm/ApiUtils.d.ts +2 -2
- package/esm/ApiUtils.js +4 -5
- package/esm/Endpoint.d.ts +6 -6
- package/esm/Endpoint.js +22 -28
- package/esm/EndpointBuilder.d.ts +21 -4
- package/esm/EndpointBuilder.js +38 -10
- package/esm/MockingTypes.d.ts +1 -1
- package/esm/QueryHandling.d.ts +1 -1
- package/esm/QueryHandling.js +2 -3
- package/esm/RequestConfig.d.ts +1 -1
- package/esm/RequestConfig.js +6 -7
- package/esm/RequestContext.d.ts +8 -7
- package/esm/RequestContext.js +33 -27
- package/esm/RequestError.d.ts +3 -3
- package/esm/RequestError.js +2 -3
- package/esm/Requester.d.ts +2 -2
- package/esm/Requester.js +45 -50
- package/esm/UtilTypes.d.ts +1 -1
- package/esm/Utils.d.ts +1 -0
- package/esm/Utils.js +54 -2
- package/esm/Validation.d.ts +8 -1
- package/esm/backend/AxiosRequestBackend.d.ts +4 -4
- package/esm/backend/AxiosRequestBackend.js +47 -84
- package/esm/backend/FetchRequestBackend.d.ts +5 -5
- package/esm/backend/FetchRequestBackend.js +50 -64
- package/esm/backend/MockRequestBackend.d.ts +4 -4
- package/esm/backend/MockRequestBackend.js +105 -136
- package/esm/backend/RequestBackend.d.ts +2 -2
- package/esm/cache/ClientCaching.d.ts +1 -1
- package/esm/cache/ClientCaching.js +8 -17
- package/esm/cache/LocalForageClientCacheBackend.d.ts +1 -1
- package/esm/cache/LocalForageClientCacheBackend.js +8 -25
- package/esm/cache/LocalStorageClientCacheBackend.d.ts +1 -1
- package/esm/cache/LocalStorageClientCacheBackend.js +9 -26
- package/esm/index.d.ts +16 -16
- package/esm/index.js +15 -15
- package/esm/middleware/ClientCacheMiddleware.d.ts +1 -1
- package/esm/middleware/ClientCacheMiddleware.js +8 -17
- package/esm/middleware/LoggingMiddleware.d.ts +1 -1
- package/esm/middleware/LoggingMiddleware.js +5 -6
- package/esm/util/retry/index.js +1 -1
- package/esm/util/retry/lib/retry.d.ts +1 -1
- package/esm/util/retry/lib/retry.js +13 -7
- package/esm/util/retry/lib/retryOperation.d.ts +1 -26
- package/esm/util/retry/lib/retryOperation.js +1 -1
- package/package.json +67 -28
package/cjs/TextDecoding.js
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.textDecode = void 0;
|
|
4
4
|
// polyfill from https://github.com/anonyco/FastestSmallestTextEncoderDecoder/blob/master/EncoderDecoderTogether.src.js
|
|
5
|
-
|
|
5
|
+
const textDecode = (inputArrayOrBuffer, options) => {
|
|
6
6
|
if (typeof TextDecoder !== "undefined") {
|
|
7
7
|
return new TextDecoder("utf-8").decode(inputArrayOrBuffer);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
const fromCharCode = String.fromCharCode;
|
|
10
|
+
const Object_prototype_toString = {}.toString;
|
|
11
|
+
const sharedArrayBufferString = Object_prototype_toString.call(window.SharedArrayBuffer);
|
|
12
|
+
const undefinedObjectString = Object_prototype_toString();
|
|
13
|
+
const NativeUint8Array = window.Uint8Array;
|
|
14
|
+
const patchedU8Array = NativeUint8Array || Array;
|
|
15
|
+
const nativeArrayBuffer = NativeUint8Array ? ArrayBuffer : patchedU8Array;
|
|
16
|
+
const arrayBuffer_isView = nativeArrayBuffer.isView || ((x) => x && "length" in x);
|
|
17
|
+
const arrayBufferString = Object_prototype_toString.call(nativeArrayBuffer.prototype);
|
|
18
|
+
const tmpBufferU16 = new (NativeUint8Array ? Uint16Array : patchedU8Array)(32);
|
|
19
|
+
let inputAs8 = inputArrayOrBuffer;
|
|
20
|
+
let asObjectString;
|
|
21
21
|
if (!arrayBuffer_isView(inputAs8)) {
|
|
22
22
|
asObjectString = Object_prototype_toString.call(inputAs8);
|
|
23
23
|
if (asObjectString !== arrayBufferString &&
|
|
@@ -26,18 +26,18 @@ var textDecode = function (inputArrayOrBuffer, options) {
|
|
|
26
26
|
throw TypeError("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
|
|
27
27
|
inputAs8 = NativeUint8Array ? new patchedU8Array(inputAs8) : inputAs8 || [];
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
let resultingString = "";
|
|
30
|
+
let tmpStr = "";
|
|
31
|
+
let index = 0;
|
|
32
|
+
const len = inputAs8.length | 0;
|
|
33
|
+
const lenMinus32 = (len - 32) | 0;
|
|
34
|
+
let nextEnd = 0;
|
|
35
|
+
let cp0 = 0;
|
|
36
|
+
let codePoint = 0;
|
|
37
|
+
let minBits = 0;
|
|
38
|
+
let cp1 = 0;
|
|
39
|
+
let pos = 0;
|
|
40
|
+
let tmp = -1;
|
|
41
41
|
// Note that tmp represents the 2nd half of a surrogate pair incase a surrogate gets divided between blocks
|
|
42
42
|
while (index < len) {
|
|
43
43
|
nextEnd = index <= lenMinus32 ? 32 : (len - index) | 0;
|
|
@@ -47,29 +47,29 @@ var textDecode = function (inputArrayOrBuffer, options) {
|
|
|
47
47
|
// biome-ignore lint: optimised code
|
|
48
48
|
case 15:
|
|
49
49
|
cp1 = inputAs8[(index = (index + 1) | 0)] & 0xff;
|
|
50
|
-
if (cp1 >> 6 !==
|
|
50
|
+
if (cp1 >> 6 !== 0b10 || 0b11110111 < cp0) {
|
|
51
51
|
index = (index - 1) | 0;
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
|
-
codePoint = ((cp0 &
|
|
54
|
+
codePoint = ((cp0 & 0b111) << 6) | (cp1 & 0b00111111);
|
|
55
55
|
minBits = 5; // 20 ensures it never passes -> all invalid replacements
|
|
56
56
|
cp0 = 0x100; // keep track of th bit size
|
|
57
57
|
// biome-ignore lint: optimised code
|
|
58
58
|
case 14:
|
|
59
59
|
cp1 = inputAs8[(index = (index + 1) | 0)] & 0xff;
|
|
60
60
|
codePoint <<= 6;
|
|
61
|
-
codePoint |= ((cp0 &
|
|
62
|
-
minBits = cp1 >> 6 ===
|
|
61
|
+
codePoint |= ((cp0 & 0b1111) << 6) | (cp1 & 0b00111111);
|
|
62
|
+
minBits = cp1 >> 6 === 0b10 ? (minBits + 4) | 0 : 24; // 24 ensures it never passes -> all invalid replacements
|
|
63
63
|
cp0 = (cp0 + 0x100) & 0x300; // keep track of th bit size
|
|
64
64
|
case 13:
|
|
65
65
|
// biome-ignore lint: optimised code
|
|
66
66
|
case 12:
|
|
67
67
|
cp1 = inputAs8[(index = (index + 1) | 0)] & 0xff;
|
|
68
68
|
codePoint <<= 6;
|
|
69
|
-
codePoint |= ((cp0 &
|
|
69
|
+
codePoint |= ((cp0 & 0b11111) << 6) | (cp1 & 0b00111111);
|
|
70
70
|
minBits = (minBits + 7) | 0;
|
|
71
71
|
// Now, process the code point
|
|
72
|
-
if (index < len && cp1 >> 6 ===
|
|
72
|
+
if (index < len && cp1 >> 6 === 0b10 && codePoint >> minBits && codePoint < 0x110000) {
|
|
73
73
|
cp0 = codePoint;
|
|
74
74
|
codePoint = (codePoint - 0x10000) | 0;
|
|
75
75
|
if (0 <= codePoint /*0xffff < codePoint*/) {
|
package/cjs/Utils.d.ts
CHANGED
|
@@ -14,3 +14,4 @@ export declare const noop: () => void;
|
|
|
14
14
|
export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
|
|
15
15
|
export declare const randInt: (min: number, max: number) => number;
|
|
16
16
|
export declare const isFormData: (value: any) => value is FormData;
|
|
17
|
+
export declare const toFormData: (body: any) => FormData;
|
package/cjs/Utils.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isFormData = exports.randInt = exports.delayThenReturn = exports.noop = exports.getGlobalFetch = exports.getGlobal = exports.padNumber = exports.assign = void 0;
|
|
3
|
+
exports.toFormData = exports.isFormData = exports.randInt = exports.delayThenReturn = exports.noop = exports.getGlobalFetch = exports.getGlobal = exports.padNumber = exports.assign = void 0;
|
|
4
4
|
// polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
5
|
+
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
5
6
|
exports.assign = Object.assign ||
|
|
6
|
-
(
|
|
7
|
-
var varArgs = [];
|
|
8
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
9
|
-
varArgs[_i - 1] = arguments[_i];
|
|
10
|
-
}
|
|
7
|
+
((target, ...varArgs) => {
|
|
11
8
|
if (target === null || target === undefined) {
|
|
12
9
|
throw new TypeError("Cannot convert undefined or null to object");
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
for (
|
|
16
|
-
|
|
11
|
+
const to = Object(target);
|
|
12
|
+
for (let index = 0; index < varArgs.length; index++) {
|
|
13
|
+
const nextSource = varArgs[index];
|
|
17
14
|
if (nextSource !== null && nextSource !== undefined) {
|
|
18
|
-
for (
|
|
15
|
+
for (const nextKey in nextSource) {
|
|
19
16
|
// Avoid bugs when hasOwnProperty is shadowed
|
|
20
|
-
if (
|
|
17
|
+
if (hasOwn(nextSource, nextKey)) {
|
|
21
18
|
to[nextKey] = nextSource[nextKey];
|
|
22
19
|
}
|
|
23
20
|
}
|
|
@@ -25,12 +22,12 @@ exports.assign = Object.assign ||
|
|
|
25
22
|
}
|
|
26
23
|
return to;
|
|
27
24
|
});
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const padNumber = (stringOrNumber, maxLength) => {
|
|
26
|
+
const string = stringOrNumber.toString();
|
|
30
27
|
return string.length >= maxLength ? string : "0".repeat(maxLength - string.length) + string;
|
|
31
28
|
};
|
|
32
29
|
exports.padNumber = padNumber;
|
|
33
|
-
|
|
30
|
+
const getGlobal = () => {
|
|
34
31
|
if (typeof global !== "undefined") {
|
|
35
32
|
return global;
|
|
36
33
|
}
|
|
@@ -40,15 +37,15 @@ var getGlobal = function () {
|
|
|
40
37
|
return undefined;
|
|
41
38
|
};
|
|
42
39
|
exports.getGlobal = getGlobal;
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const getGlobalFetch = () => {
|
|
41
|
+
const global = (0, exports.getGlobal)();
|
|
45
42
|
if (global && typeof global.fetch === "function") {
|
|
46
43
|
return global.fetch.bind(global);
|
|
47
44
|
}
|
|
48
45
|
return undefined;
|
|
49
46
|
};
|
|
50
47
|
exports.getGlobalFetch = getGlobalFetch;
|
|
51
|
-
|
|
48
|
+
const noop = () => { };
|
|
52
49
|
exports.noop = noop;
|
|
53
50
|
/**
|
|
54
51
|
* Just used to simulate lag, or loading times.
|
|
@@ -56,10 +53,10 @@ exports.noop = noop;
|
|
|
56
53
|
* @param delayMs The delay in ms
|
|
57
54
|
* @returns The `value` param as a Promise
|
|
58
55
|
*/
|
|
59
|
-
|
|
60
|
-
return new Promise(
|
|
56
|
+
const delayThenReturn = (value, delayMs) => {
|
|
57
|
+
return new Promise((resolve) => {
|
|
61
58
|
if (delayMs > 0) {
|
|
62
|
-
setTimeout(
|
|
59
|
+
setTimeout(() => {
|
|
63
60
|
resolve(value);
|
|
64
61
|
}, delayMs);
|
|
65
62
|
}
|
|
@@ -69,13 +66,65 @@ var delayThenReturn = function (value, delayMs) {
|
|
|
69
66
|
});
|
|
70
67
|
};
|
|
71
68
|
exports.delayThenReturn = delayThenReturn;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const randInt = (min, max) => {
|
|
70
|
+
const minI = Math.ceil(min);
|
|
71
|
+
const maxI = Math.floor(max);
|
|
75
72
|
return Math.floor(Math.random() * (maxI - minI + 1)) + minI;
|
|
76
73
|
};
|
|
77
74
|
exports.randInt = randInt;
|
|
78
|
-
|
|
79
|
-
return value instanceof FormData;
|
|
75
|
+
const isFormData = (value) => {
|
|
76
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
80
77
|
};
|
|
81
78
|
exports.isFormData = isFormData;
|
|
79
|
+
const isPlainObject = (value) => {
|
|
80
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
81
|
+
};
|
|
82
|
+
const isBlob = (value) => {
|
|
83
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
84
|
+
};
|
|
85
|
+
const isArrayBuffer = (value) => {
|
|
86
|
+
return typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer;
|
|
87
|
+
};
|
|
88
|
+
const isArrayBufferView = (value) => {
|
|
89
|
+
return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(value);
|
|
90
|
+
};
|
|
91
|
+
const toFormDataValue = (value) => {
|
|
92
|
+
if (isBlob(value)) {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
if ((isArrayBuffer(value) || isArrayBufferView(value)) && typeof Blob !== "undefined") {
|
|
96
|
+
return new Blob([value]);
|
|
97
|
+
}
|
|
98
|
+
return String(value);
|
|
99
|
+
};
|
|
100
|
+
const toFormData = (body) => {
|
|
101
|
+
if ((0, exports.isFormData)(body)) {
|
|
102
|
+
return body;
|
|
103
|
+
}
|
|
104
|
+
const formData = new FormData();
|
|
105
|
+
const appendValue = (key, value) => {
|
|
106
|
+
if (value === undefined || value === null) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
for (const item of value) {
|
|
111
|
+
appendValue(key, item);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (isPlainObject(value) && !isBlob(value)) {
|
|
116
|
+
for (const nestedKey of Object.keys(value)) {
|
|
117
|
+
appendValue(`${key}.${nestedKey}`, value[nestedKey]);
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
formData.append(key, toFormDataValue(value));
|
|
122
|
+
};
|
|
123
|
+
if (isPlainObject(body)) {
|
|
124
|
+
for (const key of Object.keys(body)) {
|
|
125
|
+
appendValue(key, body[key]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return formData;
|
|
129
|
+
};
|
|
130
|
+
exports.toFormData = toFormData;
|
package/cjs/Validation.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type * as zod from "zod";
|
|
2
|
-
import type { Body, Params, Query, State } from "./ApiTypes";
|
|
2
|
+
import type { Body, Params, Query, RequestBodyEncoding, State } from "./ApiTypes";
|
|
3
|
+
export interface ValidationOptions<TValue> {
|
|
4
|
+
schema?: zod.Schema<TValue>;
|
|
5
|
+
}
|
|
6
|
+
export interface BodyValidationOptions<TBody extends Body> extends ValidationOptions<TBody> {
|
|
7
|
+
encoding?: RequestBodyEncoding;
|
|
8
|
+
}
|
|
3
9
|
export interface Validation<TResponse = any, TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State> {
|
|
4
10
|
query?: zod.Schema<TQuery>;
|
|
5
11
|
params?: zod.Schema<TParams>;
|
|
6
12
|
body?: zod.Schema<TBody>;
|
|
13
|
+
bodyEncoding?: RequestBodyEncoding;
|
|
7
14
|
response?: zod.Schema<TResponse>;
|
|
8
15
|
state?: zod.Schema<TState>;
|
|
9
16
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AxiosError, AxiosResponse } from "axios";
|
|
2
2
|
import type { ApiResponse } from "../ApiTypes";
|
|
3
3
|
import type RequestContext from "../RequestContext";
|
|
4
|
-
import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
|
|
5
4
|
import type RequestBackend from "./RequestBackend";
|
|
5
|
+
import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
|
|
6
6
|
export declare const isAxiosError: (error: Error) => error is AxiosError;
|
|
7
7
|
export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
|
|
8
8
|
readonly id = "axios";
|
|
@@ -1,96 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
50
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
51
|
-
var m = o[Symbol.asyncIterator], i;
|
|
52
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
53
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
54
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
55
|
-
};
|
|
56
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
57
|
-
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
58
|
-
var i, p;
|
|
59
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
60
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
61
|
-
};
|
|
62
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
63
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
64
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
65
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
66
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
67
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
68
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
69
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
70
|
-
function fulfill(value) { resume("next", value); }
|
|
71
|
-
function reject(value) { resume("throw", value); }
|
|
72
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
73
|
-
};
|
|
74
|
-
var __values = (this && this.__values) || function(o) {
|
|
75
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
76
|
-
if (m) return m.call(o);
|
|
77
|
-
if (o && typeof o.length === "number") return {
|
|
78
|
-
next: function () {
|
|
79
|
-
if (o && i >= o.length) o = void 0;
|
|
80
|
-
return { value: o && o[i++], done: !o };
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
84
|
-
};
|
|
85
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
3
|
exports.isAxiosError = void 0;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
4
|
+
const ApiUtils_1 = require("../ApiUtils");
|
|
5
|
+
let axios;
|
|
6
|
+
const isAxiosError = (error) => {
|
|
90
7
|
return "isAxiosError" in error;
|
|
91
8
|
};
|
|
92
9
|
exports.isAxiosError = isAxiosError;
|
|
93
|
-
|
|
10
|
+
const getCacheHeaders = (browserCache) => {
|
|
94
11
|
switch (browserCache) {
|
|
95
12
|
case "no-store":
|
|
96
13
|
return {
|
|
@@ -114,105 +31,81 @@ var getCacheHeaders = function (browserCache) {
|
|
|
114
31
|
return {};
|
|
115
32
|
}
|
|
116
33
|
};
|
|
117
|
-
|
|
118
|
-
|
|
34
|
+
class AxiosRequestBackend {
|
|
35
|
+
constructor(axiosLibrary) {
|
|
119
36
|
this.id = "axios";
|
|
120
37
|
axios = axiosLibrary;
|
|
121
38
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
throw new Error("[api-def] Response data is null for streaming response");
|
|
39
|
+
async extractResponseFromError(error) {
|
|
40
|
+
if ((0, exports.isAxiosError)(error)) {
|
|
41
|
+
return error.response ? error.response : null;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
async convertResponse(context, response) {
|
|
46
|
+
const contentType = response.headers["content-type"];
|
|
47
|
+
const responseType = context.responseType ?? (0, ApiUtils_1.inferResponseType)(contentType == null ? contentType : String(contentType));
|
|
48
|
+
let data;
|
|
49
|
+
if (responseType === "stream") {
|
|
50
|
+
// For streaming responses, we create an async iterator from the response data
|
|
51
|
+
if (!response.data) {
|
|
52
|
+
throw new Error("[api-def] Response data is null for streaming response");
|
|
53
|
+
}
|
|
54
|
+
data = {
|
|
55
|
+
async *[Symbol.asyncIterator]() {
|
|
56
|
+
const stream = response.data;
|
|
57
|
+
if (stream[Symbol.asyncIterator]) {
|
|
58
|
+
yield* stream;
|
|
143
59
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
_a);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
data = response.data;
|
|
179
|
-
}
|
|
180
|
-
return [2 /*return*/, {
|
|
181
|
-
method: context.method,
|
|
182
|
-
url: (_d = (_c = response.request.res) === null || _c === void 0 ? void 0 : _c.responseUrl) !== null && _d !== void 0 ? _d : (_f = (_e = response.request) === null || _e === void 0 ? void 0 : _e._redirectable) === null || _f === void 0 ? void 0 : _f._currentUrl,
|
|
183
|
-
data: data,
|
|
184
|
-
headers: response.headers,
|
|
185
|
-
status: response.status,
|
|
186
|
-
state: context.requestConfig.state,
|
|
187
|
-
__lowercaseHeaders: response._lowerCaseResponseHeaders,
|
|
188
|
-
stats: context.stats,
|
|
189
|
-
}];
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
AxiosRequestBackend.prototype.makeRequest = function (context) {
|
|
194
|
-
var requestConfig = context.requestConfig;
|
|
195
|
-
var url = context.requestUrl;
|
|
196
|
-
var canceler = null;
|
|
197
|
-
var promise = axios({
|
|
60
|
+
else if (stream.on) {
|
|
61
|
+
// Handle Node.js streams
|
|
62
|
+
yield* stream;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error("[api-def] Response data is not a valid stream");
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
data = response.data;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
method: context.method,
|
|
75
|
+
url: response.request.res?.responseUrl ?? response.request?._redirectable?._currentUrl,
|
|
76
|
+
data: data,
|
|
77
|
+
headers: response.headers,
|
|
78
|
+
status: response.status,
|
|
79
|
+
state: context.requestConfig.state,
|
|
80
|
+
__lowercaseHeaders: response._lowerCaseResponseHeaders,
|
|
81
|
+
stats: context.stats,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
makeRequest(context) {
|
|
85
|
+
const { requestConfig } = context;
|
|
86
|
+
const url = context.requestUrl;
|
|
87
|
+
let canceler = null;
|
|
88
|
+
const promise = axios({
|
|
198
89
|
method: context.method,
|
|
199
90
|
url: url.href,
|
|
200
91
|
data: context.getParsedBody(),
|
|
201
|
-
headers:
|
|
92
|
+
headers: {
|
|
93
|
+
...getCacheHeaders(requestConfig.browserCache),
|
|
94
|
+
...requestConfig.headers,
|
|
95
|
+
},
|
|
202
96
|
responseType: context.responseType,
|
|
203
97
|
withCredentials: requestConfig.credentials === "include" || requestConfig.credentials === "same-origin",
|
|
204
|
-
cancelToken: new axios.CancelToken(
|
|
98
|
+
cancelToken: new axios.CancelToken((cancellerFunc) => {
|
|
205
99
|
canceler = cancellerFunc;
|
|
206
100
|
}),
|
|
207
101
|
});
|
|
208
102
|
return {
|
|
209
103
|
promise: promise,
|
|
210
|
-
canceler:
|
|
104
|
+
canceler: () => canceler?.(),
|
|
211
105
|
};
|
|
212
|
-
}
|
|
213
|
-
|
|
106
|
+
}
|
|
107
|
+
getErrorInfo(error, response) {
|
|
214
108
|
return undefined;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
}());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
218
111
|
exports.default = AxiosRequestBackend;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ApiResponse } from "../ApiTypes";
|
|
2
2
|
import type RequestContext from "../RequestContext";
|
|
3
3
|
import { type Fetch } from "../Utils";
|
|
4
|
-
import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
|
|
5
4
|
import type RequestBackend from "./RequestBackend";
|
|
5
|
+
import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
|
|
6
6
|
export default class FetchRequestBackend implements RequestBackend<Response> {
|
|
7
7
|
fetch: (((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) & typeof fetch) | undefined;
|
|
8
8
|
readonly id = "fetch";
|