api-def 0.6.0-alpha1 → 0.6.0-alpha10
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/ApiTypes.d.ts +2 -1
- package/cjs/ApiUtils.js +2 -1
- package/cjs/Requester.js +2 -5
- package/cjs/UtilTypes.d.ts +5 -0
- package/cjs/UtilTypes.js +2 -0
- package/cjs/backend/AxiosRequestBackend.js +6 -3
- package/cjs/backend/FetchRequestBackend.js +32 -23
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/esm/ApiTypes.d.ts +2 -1
- package/esm/ApiUtils.js +2 -1
- package/esm/Requester.js +2 -5
- package/esm/UtilTypes.d.ts +5 -0
- package/esm/UtilTypes.js +1 -0
- package/esm/backend/AxiosRequestBackend.js +6 -3
- package/esm/backend/FetchRequestBackend.js +32 -23
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/package.json +1 -1
- package/CHANGELOG.md +0 -65
package/cjs/ApiTypes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType
|
|
|
4
4
|
export declare type AcceptableStatus = number | [min: number, max: number];
|
|
5
5
|
export declare type Headers = Record<string, string | number | boolean | null | undefined>;
|
|
6
6
|
export declare type Params = string;
|
|
7
|
-
export declare type Query = Record<string,
|
|
7
|
+
export declare type Query = Record<string, any>;
|
|
8
8
|
export declare type Body = string | number | Record<string, any>;
|
|
9
9
|
export interface ApiResponse<T = any> {
|
|
10
10
|
status: number;
|
|
@@ -17,6 +17,7 @@ export interface BaseRequestConfig {
|
|
|
17
17
|
retry?: number | false;
|
|
18
18
|
headers?: Readonly<Headers>;
|
|
19
19
|
acceptableStatus?: AcceptableStatus[];
|
|
20
|
+
queryParser?: (query: any) => string;
|
|
20
21
|
}
|
|
21
22
|
export declare type RequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = (P extends undefined ? {
|
|
22
23
|
params?: never;
|
package/cjs/ApiUtils.js
CHANGED
|
@@ -23,7 +23,8 @@ var parseResponseDataToObject = function (response) {
|
|
|
23
23
|
response.data = JSON.parse(decodedData);
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
|
-
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
console.warn("[api-def] Couldn't parse array buffer content to JSON response", e);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
package/cjs/Requester.js
CHANGED
|
@@ -60,7 +60,7 @@ var locks = {};
|
|
|
60
60
|
var runningOperations = {};
|
|
61
61
|
var MOCK_REQUEST_BACKEND = new MockRequestBackend_1.default();
|
|
62
62
|
var submit = function (host, config, mocking) { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var computedConfig, backend, context, key,
|
|
63
|
+
var computedConfig, backend, context, key, lock, lockedContext, response, successEventResult, error_1;
|
|
64
64
|
return __generator(this, function (_a) {
|
|
65
65
|
switch (_a.label) {
|
|
66
66
|
case 0:
|
|
@@ -71,10 +71,6 @@ var submit = function (host, config, mocking) { return __awaiter(void 0, void 0,
|
|
|
71
71
|
}
|
|
72
72
|
context = new RequestContext_1.default(backend, host, computedConfig, host.computePath(host.path, config), mocking);
|
|
73
73
|
key = context.key;
|
|
74
|
-
sameRequest = runningOperations[key];
|
|
75
|
-
if (sameRequest) {
|
|
76
|
-
return [2 /*return*/, sameRequest];
|
|
77
|
-
}
|
|
78
74
|
lock = (context.computedConfig || {}).lock;
|
|
79
75
|
if (lock) {
|
|
80
76
|
lockedContext = locks[lock];
|
|
@@ -122,6 +118,7 @@ var makeRequest = function (context) { return __awaiter(void 0, void 0, void 0,
|
|
|
122
118
|
if (process.env.NODE_ENV === "development") {
|
|
123
119
|
if (Api.isRequestBackendDefault() && !defaultBackendMessageShown) {
|
|
124
120
|
defaultBackendMessageShown = true;
|
|
121
|
+
// eslint-disable-next-line
|
|
125
122
|
console.warn("[api-def] Using default fetch backend, you can use a different one with 'setRequestBackend()' (dev only message)");
|
|
126
123
|
}
|
|
127
124
|
}
|
|
@@ -0,0 +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;
|
package/cjs/UtilTypes.js
ADDED
|
@@ -62,14 +62,16 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
62
62
|
};
|
|
63
63
|
AxiosRequestBackend.prototype.convertResponse = function (context, response) {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var inferredResponseType;
|
|
65
|
+
var contentType, inferredResponseType;
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
|
-
|
|
67
|
+
contentType = response.headers["content-type"];
|
|
68
|
+
inferredResponseType = ApiUtils_1.inferResponseType(contentType);
|
|
68
69
|
// expand to array buffer once we support that in inferResponseType
|
|
69
70
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
70
71
|
throw RequestError_1.convertToRequestError({
|
|
71
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
72
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
72
73
|
code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
74
|
+
response: response,
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
77
|
return [2 /*return*/, response];
|
|
@@ -90,6 +92,7 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
90
92
|
cancelToken: new axios.CancelToken(function (cancellerFunc) {
|
|
91
93
|
canceler = cancellerFunc;
|
|
92
94
|
}),
|
|
95
|
+
paramsSerializer: context.computedConfig.queryParser,
|
|
93
96
|
});
|
|
94
97
|
return {
|
|
95
98
|
promise: promise,
|
|
@@ -85,29 +85,36 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
85
85
|
};
|
|
86
86
|
FetchRequestBackend.prototype.convertResponse = function (context, response, error) {
|
|
87
87
|
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
-
var data, inferredResponseType, responseType, _a,
|
|
88
|
+
var data, contentType, inferredResponseType, responseType, _a, status, headers, error_1;
|
|
89
89
|
return __generator(this, function (_b) {
|
|
90
90
|
switch (_b.label) {
|
|
91
91
|
case 0:
|
|
92
|
-
|
|
92
|
+
contentType = response.headers.get("Content-Type");
|
|
93
|
+
inferredResponseType = ApiUtils_1.inferResponseType(contentType);
|
|
93
94
|
responseType = error ? inferredResponseType : context.responseType;
|
|
95
|
+
if (!!response.__text) return [3 /*break*/, 2];
|
|
96
|
+
_a = response;
|
|
97
|
+
return [4 /*yield*/, response.clone().text()];
|
|
98
|
+
case 1:
|
|
99
|
+
_a.__text = _b.sent();
|
|
100
|
+
_b.label = 2;
|
|
101
|
+
case 2:
|
|
102
|
+
status = response.status, headers = response.headers;
|
|
94
103
|
// expand to array buffer once we support that in inferResponseType
|
|
95
104
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
96
105
|
throw RequestError_1.convertToRequestError({
|
|
97
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
106
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
98
107
|
code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
108
|
+
response: {
|
|
109
|
+
data: response.__text,
|
|
110
|
+
status: status,
|
|
111
|
+
headers: headers,
|
|
112
|
+
},
|
|
99
113
|
});
|
|
100
114
|
}
|
|
101
|
-
_b.label = 1;
|
|
102
|
-
case 1:
|
|
103
|
-
_b.trys.push([1, 8, , 9]);
|
|
104
|
-
if (!!response.__text) return [3 /*break*/, 3];
|
|
105
|
-
_a = response;
|
|
106
|
-
return [4 /*yield*/, response.clone().text()];
|
|
107
|
-
case 2:
|
|
108
|
-
_a.__text = _b.sent();
|
|
109
115
|
_b.label = 3;
|
|
110
116
|
case 3:
|
|
117
|
+
_b.trys.push([3, 8, , 9]);
|
|
111
118
|
if (!(responseType === ApiConstants_1.ResponseType.Text)) return [3 /*break*/, 4];
|
|
112
119
|
data = response.__text;
|
|
113
120
|
return [3 /*break*/, 7];
|
|
@@ -128,13 +135,11 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
128
135
|
throw Object.assign(new Error("[api-def] Invalid '" + context.responseType + "' response, got: '" + response.__text + "'"), {
|
|
129
136
|
response: response,
|
|
130
137
|
});
|
|
131
|
-
case 9:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
headers: response.headers,
|
|
137
|
-
}];
|
|
138
|
+
case 9: return [2 /*return*/, {
|
|
139
|
+
data: data,
|
|
140
|
+
status: status,
|
|
141
|
+
headers: headers,
|
|
142
|
+
}];
|
|
138
143
|
}
|
|
139
144
|
});
|
|
140
145
|
});
|
|
@@ -157,10 +162,15 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
157
162
|
}
|
|
158
163
|
var url = new URL(path, origin);
|
|
159
164
|
if (computedConfig.query) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
if (context.computedConfig.queryParser) {
|
|
166
|
+
url.search = context.computedConfig.queryParser(computedConfig.query);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
var queryKeys = Object.keys(computedConfig.query);
|
|
170
|
+
for (var i = 0; i < queryKeys.length; i++) {
|
|
171
|
+
var key = queryKeys[i];
|
|
172
|
+
url.searchParams.append(key, ((_a = computedConfig.query[key]) === null || _a === void 0 ? void 0 : _a.toString()) || "");
|
|
173
|
+
}
|
|
164
174
|
}
|
|
165
175
|
}
|
|
166
176
|
// abort controller is a newer feature than fetch
|
|
@@ -203,7 +213,6 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
203
213
|
canceler: abortSignal
|
|
204
214
|
? function () { return !responded && abortController.abort(); }
|
|
205
215
|
: function () {
|
|
206
|
-
console.warn("Request aborted");
|
|
207
216
|
softAbort = true;
|
|
208
217
|
},
|
|
209
218
|
};
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.LoggingMiddleware = exports.CacheMiddleware = exports.FetchRequestBackend = exports.AxiosRequestBackend = exports.LocaleForageCacheBackend = exports.LocalStorageCacheBackend = exports.setCacheBackend = exports.clearCache = exports.isRequestError = void 0;
|
|
15
15
|
__exportStar(require("./Api"), exports);
|
|
16
16
|
__exportStar(require("./ApiTypes"), exports);
|
|
17
|
+
__exportStar(require("./UtilTypes"), exports);
|
|
17
18
|
__exportStar(require("./ApiConstants"), exports);
|
|
18
19
|
var RequestError_1 = require("./RequestError");
|
|
19
20
|
Object.defineProperty(exports, "isRequestError", { enumerable: true, get: function () { return RequestError_1.isRequestError; } });
|
package/esm/ApiTypes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType
|
|
|
4
4
|
export declare type AcceptableStatus = number | [min: number, max: number];
|
|
5
5
|
export declare type Headers = Record<string, string | number | boolean | null | undefined>;
|
|
6
6
|
export declare type Params = string;
|
|
7
|
-
export declare type Query = Record<string,
|
|
7
|
+
export declare type Query = Record<string, any>;
|
|
8
8
|
export declare type Body = string | number | Record<string, any>;
|
|
9
9
|
export interface ApiResponse<T = any> {
|
|
10
10
|
status: number;
|
|
@@ -17,6 +17,7 @@ export interface BaseRequestConfig {
|
|
|
17
17
|
retry?: number | false;
|
|
18
18
|
headers?: Readonly<Headers>;
|
|
19
19
|
acceptableStatus?: AcceptableStatus[];
|
|
20
|
+
queryParser?: (query: any) => string;
|
|
20
21
|
}
|
|
21
22
|
export declare type RequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = (P extends undefined ? {
|
|
22
23
|
params?: never;
|
package/esm/ApiUtils.js
CHANGED
|
@@ -18,7 +18,8 @@ export var parseResponseDataToObject = function (response) {
|
|
|
18
18
|
response.data = JSON.parse(decodedData);
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
21
|
-
|
|
21
|
+
// eslint-disable-next-line
|
|
22
|
+
console.warn("[api-def] Couldn't parse array buffer content to JSON response", e);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
}
|
package/esm/Requester.js
CHANGED
|
@@ -57,7 +57,7 @@ var locks = {};
|
|
|
57
57
|
var runningOperations = {};
|
|
58
58
|
var MOCK_REQUEST_BACKEND = new MockRequestBackend();
|
|
59
59
|
export var submit = function (host, config, mocking) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
-
var computedConfig, backend, context, key,
|
|
60
|
+
var computedConfig, backend, context, key, lock, lockedContext, response, successEventResult, error_1;
|
|
61
61
|
return __generator(this, function (_a) {
|
|
62
62
|
switch (_a.label) {
|
|
63
63
|
case 0:
|
|
@@ -68,10 +68,6 @@ export var submit = function (host, config, mocking) { return __awaiter(void 0,
|
|
|
68
68
|
}
|
|
69
69
|
context = new RequestContext(backend, host, computedConfig, host.computePath(host.path, config), mocking);
|
|
70
70
|
key = context.key;
|
|
71
|
-
sameRequest = runningOperations[key];
|
|
72
|
-
if (sameRequest) {
|
|
73
|
-
return [2 /*return*/, sameRequest];
|
|
74
|
-
}
|
|
75
71
|
lock = (context.computedConfig || {}).lock;
|
|
76
72
|
if (lock) {
|
|
77
73
|
lockedContext = locks[lock];
|
|
@@ -118,6 +114,7 @@ var makeRequest = function (context) { return __awaiter(void 0, void 0, void 0,
|
|
|
118
114
|
if (process.env.NODE_ENV === "development") {
|
|
119
115
|
if (Api.isRequestBackendDefault() && !defaultBackendMessageShown) {
|
|
120
116
|
defaultBackendMessageShown = true;
|
|
117
|
+
// eslint-disable-next-line
|
|
121
118
|
console.warn("[api-def] Using default fetch backend, you can use a different one with 'setRequestBackend()' (dev only message)");
|
|
122
119
|
}
|
|
123
120
|
}
|
|
@@ -0,0 +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;
|
package/esm/UtilTypes.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -58,14 +58,16 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
58
58
|
};
|
|
59
59
|
AxiosRequestBackend.prototype.convertResponse = function (context, response) {
|
|
60
60
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
var inferredResponseType;
|
|
61
|
+
var contentType, inferredResponseType;
|
|
62
62
|
return __generator(this, function (_a) {
|
|
63
|
-
|
|
63
|
+
contentType = response.headers["content-type"];
|
|
64
|
+
inferredResponseType = inferResponseType(contentType);
|
|
64
65
|
// expand to array buffer once we support that in inferResponseType
|
|
65
66
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
66
67
|
throw convertToRequestError({
|
|
67
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
68
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
68
69
|
code: RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
70
|
+
response: response,
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
return [2 /*return*/, response];
|
|
@@ -86,6 +88,7 @@ var AxiosRequestBackend = /** @class */ (function () {
|
|
|
86
88
|
cancelToken: new axios.CancelToken(function (cancellerFunc) {
|
|
87
89
|
canceler = cancellerFunc;
|
|
88
90
|
}),
|
|
91
|
+
paramsSerializer: context.computedConfig.queryParser,
|
|
89
92
|
});
|
|
90
93
|
return {
|
|
91
94
|
promise: promise,
|
|
@@ -83,29 +83,36 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
83
83
|
};
|
|
84
84
|
FetchRequestBackend.prototype.convertResponse = function (context, response, error) {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
var data, inferredResponseType, responseType, _a,
|
|
86
|
+
var data, contentType, inferredResponseType, responseType, _a, status, headers, error_1;
|
|
87
87
|
return __generator(this, function (_b) {
|
|
88
88
|
switch (_b.label) {
|
|
89
89
|
case 0:
|
|
90
|
-
|
|
90
|
+
contentType = response.headers.get("Content-Type");
|
|
91
|
+
inferredResponseType = inferResponseType(contentType);
|
|
91
92
|
responseType = error ? inferredResponseType : context.responseType;
|
|
93
|
+
if (!!response.__text) return [3 /*break*/, 2];
|
|
94
|
+
_a = response;
|
|
95
|
+
return [4 /*yield*/, response.clone().text()];
|
|
96
|
+
case 1:
|
|
97
|
+
_a.__text = _b.sent();
|
|
98
|
+
_b.label = 2;
|
|
99
|
+
case 2:
|
|
100
|
+
status = response.status, headers = response.headers;
|
|
92
101
|
// expand to array buffer once we support that in inferResponseType
|
|
93
102
|
if (inferredResponseType === "text" && context.responseType === "json") {
|
|
94
103
|
throw convertToRequestError({
|
|
95
|
-
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "'"),
|
|
104
|
+
error: new Error("[api-def] Expected '" + context.responseType + "' response, got '" + inferredResponseType + "' (from 'Content-Type' of '" + contentType + "')"),
|
|
96
105
|
code: RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
|
|
106
|
+
response: {
|
|
107
|
+
data: response.__text,
|
|
108
|
+
status: status,
|
|
109
|
+
headers: headers,
|
|
110
|
+
},
|
|
97
111
|
});
|
|
98
112
|
}
|
|
99
|
-
_b.label = 1;
|
|
100
|
-
case 1:
|
|
101
|
-
_b.trys.push([1, 8, , 9]);
|
|
102
|
-
if (!!response.__text) return [3 /*break*/, 3];
|
|
103
|
-
_a = response;
|
|
104
|
-
return [4 /*yield*/, response.clone().text()];
|
|
105
|
-
case 2:
|
|
106
|
-
_a.__text = _b.sent();
|
|
107
113
|
_b.label = 3;
|
|
108
114
|
case 3:
|
|
115
|
+
_b.trys.push([3, 8, , 9]);
|
|
109
116
|
if (!(responseType === ResponseType.Text)) return [3 /*break*/, 4];
|
|
110
117
|
data = response.__text;
|
|
111
118
|
return [3 /*break*/, 7];
|
|
@@ -126,13 +133,11 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
126
133
|
throw Object.assign(new Error("[api-def] Invalid '" + context.responseType + "' response, got: '" + response.__text + "'"), {
|
|
127
134
|
response: response,
|
|
128
135
|
});
|
|
129
|
-
case 9:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
headers: response.headers,
|
|
135
|
-
}];
|
|
136
|
+
case 9: return [2 /*return*/, {
|
|
137
|
+
data: data,
|
|
138
|
+
status: status,
|
|
139
|
+
headers: headers,
|
|
140
|
+
}];
|
|
136
141
|
}
|
|
137
142
|
});
|
|
138
143
|
});
|
|
@@ -155,10 +160,15 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
155
160
|
}
|
|
156
161
|
var url = new URL(path, origin);
|
|
157
162
|
if (computedConfig.query) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
if (context.computedConfig.queryParser) {
|
|
164
|
+
url.search = context.computedConfig.queryParser(computedConfig.query);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
var queryKeys = Object.keys(computedConfig.query);
|
|
168
|
+
for (var i = 0; i < queryKeys.length; i++) {
|
|
169
|
+
var key = queryKeys[i];
|
|
170
|
+
url.searchParams.append(key, ((_a = computedConfig.query[key]) === null || _a === void 0 ? void 0 : _a.toString()) || "");
|
|
171
|
+
}
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
174
|
// abort controller is a newer feature than fetch
|
|
@@ -201,7 +211,6 @@ var FetchRequestBackend = /** @class */ (function () {
|
|
|
201
211
|
canceler: abortSignal
|
|
202
212
|
? function () { return !responded && abortController.abort(); }
|
|
203
213
|
: function () {
|
|
204
|
-
console.warn("Request aborted");
|
|
205
214
|
softAbort = true;
|
|
206
215
|
},
|
|
207
216
|
};
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
package/package.json
CHANGED
package/CHANGELOG.md
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# 0.6.0
|
|
2
|
-
|
|
3
|
-
## Breaking Changes
|
|
4
|
-
|
|
5
|
-
- axios will enforce ResponseType
|
|
6
|
-
|
|
7
|
-
### Fixes
|
|
8
|
-
|
|
9
|
-
- absolute paths as `baseUrl` is now supported in fetch backend
|
|
10
|
-
|
|
11
|
-
# 0.5.0
|
|
12
|
-
|
|
13
|
-
## Breaking Changes
|
|
14
|
-
|
|
15
|
-
- Undocumented mocking API has been overhauled
|
|
16
|
-
|
|
17
|
-
## Changes
|
|
18
|
-
|
|
19
|
-
- Add mocking!
|
|
20
|
-
- Restructured mocking so that mocks are defined on the endpoint level (documentation updated)
|
|
21
|
-
- Add `acceptableStatus` to specify which status codes are considered successful
|
|
22
|
-
- Extend retry logic to use exponential back-off, rather than retrying immediately
|
|
23
|
-
- Support for additional hot-request methods:
|
|
24
|
-
- PUT, DELETE
|
|
25
|
-
|
|
26
|
-
# 0.4.1
|
|
27
|
-
|
|
28
|
-
- fix fetch backend not working with unbound fetch
|
|
29
|
-
- add better error handling on parse
|
|
30
|
-
|
|
31
|
-
# 0.4.0
|
|
32
|
-
|
|
33
|
-
## Breaking Changes
|
|
34
|
-
|
|
35
|
-
- Move config values from options object up one layer
|
|
36
|
-
- In config `retries` -> `retry`
|
|
37
|
-
- `defaults` -> `config`
|
|
38
|
-
|
|
39
|
-
## Changes
|
|
40
|
-
|
|
41
|
-
- Remove need for enum imports
|
|
42
|
-
- Make `name` and `description` optional in endpoint definition
|
|
43
|
-
|
|
44
|
-
# 0.3.11
|
|
45
|
-
|
|
46
|
-
## Changes
|
|
47
|
-
|
|
48
|
-
- Make fetch backend default if fetch is present
|
|
49
|
-
- Fix fetch backends text response type support
|
|
50
|
-
|
|
51
|
-
# 0.3.0
|
|
52
|
-
|
|
53
|
-
## Features
|
|
54
|
-
|
|
55
|
-
- allow defaults to be a function on api
|
|
56
|
-
- add content type header in fetch backend to match axios backend
|
|
57
|
-
- remove `flatted`
|
|
58
|
-
- polyfill object.assign for ie
|
|
59
|
-
- change retry logic so that if a middleware event responds with Retry we always attempt a retry
|
|
60
|
-
|
|
61
|
-
# 0.2.5
|
|
62
|
-
|
|
63
|
-
## Changes
|
|
64
|
-
|
|
65
|
-
- Remove `window` usages to allow node support
|