api-def 0.12.1 → 0.13.0
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 +1 -1
- package/cjs/ApiUtils.js +30 -32
- package/cjs/Endpoint.d.ts +1 -1
- package/cjs/Endpoint.js +112 -175
- package/cjs/EndpointBuilder.js +23 -32
- package/cjs/QueryHandling.js +12 -13
- package/cjs/RequestConfig.js +54 -36
- package/cjs/RequestContext.d.ts +1 -1
- package/cjs/RequestContext.js +125 -180
- package/cjs/RequestError.js +16 -19
- package/cjs/Requester.js +230 -312
- package/cjs/TextDecoding.js +31 -31
- package/cjs/Utils.js +20 -23
- 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 +5 -5
- 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 +4 -4
- package/esm/EndpointBuilder.js +2 -2
- 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 +7 -7
- package/esm/RequestContext.js +15 -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 +44 -50
- package/esm/UtilTypes.d.ts +1 -1
- package/esm/Utils.js +2 -1
- package/esm/Validation.d.ts +1 -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 +49 -63
- 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 +66 -28
package/cjs/Endpoint.js
CHANGED
|
@@ -1,162 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 };
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
47
7
|
}
|
|
48
|
-
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
49
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var _a, _b;
|
|
36
|
+
const ApiUtils_1 = require("./ApiUtils");
|
|
37
|
+
const RequestConfig_1 = require("./RequestConfig");
|
|
38
|
+
const Requester = __importStar(require("./Requester"));
|
|
39
|
+
class Endpoint {
|
|
40
|
+
constructor(api, options) {
|
|
56
41
|
this.api = api;
|
|
57
|
-
this.info =
|
|
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
|
-
Object.defineProperty(Endpoint.prototype, "responseType", {
|
|
110
|
-
get: function () {
|
|
111
|
-
return this.info.responseType;
|
|
112
|
-
},
|
|
113
|
-
enumerable: false,
|
|
114
|
-
configurable: true
|
|
115
|
-
});
|
|
116
|
-
Object.defineProperty(Endpoint.prototype, "mocking", {
|
|
117
|
-
get: function () {
|
|
118
|
-
return this.info.mocking;
|
|
119
|
-
},
|
|
120
|
-
enumerable: false,
|
|
121
|
-
configurable: true
|
|
122
|
-
});
|
|
123
|
-
Object.defineProperty(Endpoint.prototype, "validation", {
|
|
124
|
-
get: function () {
|
|
125
|
-
return this.info.validation;
|
|
126
|
-
},
|
|
127
|
-
enumerable: false,
|
|
128
|
-
configurable: true
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(Endpoint.prototype, "middleware", {
|
|
131
|
-
get: function () {
|
|
132
|
-
return this.info.middleware || [];
|
|
133
|
-
},
|
|
134
|
-
enumerable: false,
|
|
135
|
-
configurable: true
|
|
136
|
-
});
|
|
137
|
-
Endpoint.prototype.submit = function (config) {
|
|
138
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
var mock, apiMocking, mockingEnabled;
|
|
140
|
-
var _a, _b;
|
|
141
|
-
return __generator(this, function (_c) {
|
|
142
|
-
mock = false;
|
|
143
|
-
apiMocking = this.api.mocking;
|
|
144
|
-
if (apiMocking) {
|
|
145
|
-
mockingEnabled = (_a = (typeof apiMocking.enabled === "function" ? apiMocking.enabled() : apiMocking.enabled)) !== null && _a !== void 0 ? _a : false;
|
|
146
|
-
if (mockingEnabled) {
|
|
147
|
-
if (!((_b = this.mocking) === null || _b === void 0 ? void 0 : _b.handler)) {
|
|
148
|
-
throw new Error("[api-def] Endpoint for '".concat(this.path, "' has no mocking"));
|
|
149
|
-
}
|
|
150
|
-
mock = true;
|
|
151
|
-
}
|
|
42
|
+
this.info = {
|
|
43
|
+
...options,
|
|
44
|
+
config: undefined,
|
|
45
|
+
name: options.name || options.id,
|
|
46
|
+
validation: options.validation || {},
|
|
47
|
+
middleware: options.middleware || [],
|
|
48
|
+
defaultRequestConfig: options.defaultRequestConfig ?? options.config ?? {},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
get id() {
|
|
52
|
+
return this.info.id;
|
|
53
|
+
}
|
|
54
|
+
get method() {
|
|
55
|
+
return this.info.method;
|
|
56
|
+
}
|
|
57
|
+
get path() {
|
|
58
|
+
return this.info.path;
|
|
59
|
+
}
|
|
60
|
+
get name() {
|
|
61
|
+
return this.info.name;
|
|
62
|
+
}
|
|
63
|
+
get description() {
|
|
64
|
+
return this.info.description;
|
|
65
|
+
}
|
|
66
|
+
/** @deprecated Use `defaultRequestConfig` instead */
|
|
67
|
+
get config() {
|
|
68
|
+
return this.defaultRequestConfig;
|
|
69
|
+
}
|
|
70
|
+
get defaultRequestConfig() {
|
|
71
|
+
return this.info.defaultRequestConfig;
|
|
72
|
+
}
|
|
73
|
+
get responseType() {
|
|
74
|
+
return this.info.responseType;
|
|
75
|
+
}
|
|
76
|
+
get mocking() {
|
|
77
|
+
return this.info.mocking;
|
|
78
|
+
}
|
|
79
|
+
get validation() {
|
|
80
|
+
return this.info.validation;
|
|
81
|
+
}
|
|
82
|
+
get middleware() {
|
|
83
|
+
return this.info.middleware || [];
|
|
84
|
+
}
|
|
85
|
+
async submit(config) {
|
|
86
|
+
let mock = false;
|
|
87
|
+
const apiMocking = this.api.mocking;
|
|
88
|
+
if (apiMocking) {
|
|
89
|
+
const mockingEnabled = (typeof apiMocking.enabled === "function" ? apiMocking.enabled() : apiMocking.enabled) ?? false;
|
|
90
|
+
if (mockingEnabled) {
|
|
91
|
+
if (!this.mocking?.handler) {
|
|
92
|
+
throw new Error(`[api-def] Endpoint for '${this.path}' has no mocking`);
|
|
152
93
|
}
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
94
|
+
mock = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return Requester.submit(this, config, mock ? this.mocking : null);
|
|
98
|
+
}
|
|
99
|
+
resolveUrl(options) {
|
|
100
|
+
const { query } = options;
|
|
101
|
+
const url = this.api.resolveUrl({
|
|
160
102
|
path: this.resolvePath(options),
|
|
161
103
|
baseUrl: options.baseUrl,
|
|
162
104
|
});
|
|
@@ -164,32 +106,27 @@ var Endpoint = /** @class */ (function () {
|
|
|
164
106
|
url.search = new URLSearchParams(query).toString();
|
|
165
107
|
}
|
|
166
108
|
return url;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
109
|
+
}
|
|
110
|
+
resolvePath(options) {
|
|
111
|
+
const { params } = options;
|
|
170
112
|
return (0, ApiUtils_1.resolvePathParams)(this.path, params);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
},
|
|
176
|
-
enumerable: false,
|
|
177
|
-
configurable: true
|
|
178
|
-
});
|
|
113
|
+
}
|
|
114
|
+
get baseUrl() {
|
|
115
|
+
return this.api.baseUrl;
|
|
116
|
+
}
|
|
179
117
|
/**
|
|
180
118
|
* @deprecated Use `defaultRequestConfig` instead
|
|
181
119
|
*/
|
|
182
|
-
|
|
120
|
+
computeConfig(config) {
|
|
183
121
|
return this.computeRequestConfig(config);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
122
|
+
}
|
|
123
|
+
computeRequestConfig(config) {
|
|
124
|
+
const apiDefaults = this.api.computeRequestConfig();
|
|
125
|
+
const endpointDefaults = this.defaultRequestConfig || {};
|
|
188
126
|
return (0, RequestConfig_1.processRequestConfigs)([apiDefaults, endpointDefaults, config]);
|
|
189
|
-
}
|
|
190
|
-
|
|
127
|
+
}
|
|
128
|
+
getRequestBackend() {
|
|
191
129
|
return this.api.requestBackend;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
}());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
195
132
|
exports.default = Endpoint;
|
package/cjs/EndpointBuilder.js
CHANGED
|
@@ -1,52 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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);
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
4
|
};
|
|
13
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const Endpoint_1 = __importDefault(require("./Endpoint"));
|
|
7
|
+
class EndpointBuilder {
|
|
8
|
+
constructor(api) {
|
|
17
9
|
this.validation = {};
|
|
18
10
|
this.api = api;
|
|
19
11
|
}
|
|
20
|
-
|
|
12
|
+
queryOf(schema) {
|
|
21
13
|
this.validation.query = schema;
|
|
22
14
|
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
15
|
+
}
|
|
16
|
+
paramsOf() {
|
|
25
17
|
return this;
|
|
26
|
-
}
|
|
27
|
-
|
|
18
|
+
}
|
|
19
|
+
bodyOf(schema) {
|
|
28
20
|
this.validation.body = schema;
|
|
29
21
|
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
22
|
+
}
|
|
23
|
+
responseOf(schema) {
|
|
32
24
|
this.validation.response = schema;
|
|
33
25
|
return this;
|
|
34
|
-
}
|
|
35
|
-
|
|
26
|
+
}
|
|
27
|
+
stateOf(schema) {
|
|
36
28
|
this.validation.state = schema;
|
|
37
29
|
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
30
|
+
}
|
|
31
|
+
requestHeadersOf() {
|
|
40
32
|
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
33
|
+
}
|
|
34
|
+
responseHeadersOf() {
|
|
43
35
|
return this;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
}
|
|
37
|
+
build(options) {
|
|
38
|
+
const endpoint = new Endpoint_1.default(this.api, { ...options, validation: this.validation });
|
|
47
39
|
this.api.endpoints[endpoint.id] = endpoint;
|
|
48
40
|
return endpoint;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
}());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
52
43
|
exports.default = EndpointBuilder;
|
package/cjs/QueryHandling.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_QUERY_PARSE = exports.DEFAULT_QUERY_STRINGIFY = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
queryStrings.push("".concat(key, "=").concat((_b = (_a = query[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ""));
|
|
4
|
+
const DEFAULT_QUERY_STRINGIFY = (query) => {
|
|
5
|
+
const queryStrings = [];
|
|
6
|
+
const queryKeys = Object.keys(query);
|
|
7
|
+
for (let i = 0; i < queryKeys.length; i++) {
|
|
8
|
+
const key = queryKeys[i];
|
|
9
|
+
queryStrings.push(`${key}=${query[key]?.toString() ?? ""}`);
|
|
11
10
|
}
|
|
12
11
|
return queryStrings.join("&");
|
|
13
12
|
};
|
|
14
13
|
exports.DEFAULT_QUERY_STRINGIFY = DEFAULT_QUERY_STRINGIFY;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (
|
|
19
|
-
|
|
20
|
-
query[key] = !
|
|
14
|
+
const DEFAULT_QUERY_PARSE = (queryString) => {
|
|
15
|
+
const query = {};
|
|
16
|
+
const queryStrings = queryString.split("&");
|
|
17
|
+
for (let i = 0; i < queryStrings.length; i++) {
|
|
18
|
+
const [key, value] = queryStrings[i].split("=");
|
|
19
|
+
query[key] = !value?.length ? true : value;
|
|
21
20
|
}
|
|
22
21
|
return query;
|
|
23
22
|
};
|
package/cjs/RequestConfig.js
CHANGED
|
@@ -1,46 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.processRequestConfigs = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (config === null || config === void 0 ? void 0 : config[key]) {
|
|
37
|
+
const ApiTypes_1 = require("./ApiTypes");
|
|
38
|
+
const QueryHandling_1 = require("./QueryHandling");
|
|
39
|
+
const Utils = __importStar(require("./Utils"));
|
|
40
|
+
const MERGED_CONFIG_KEYS = ["headers"];
|
|
41
|
+
const processRequestConfigs = (configs) => {
|
|
42
|
+
const computedConfig = Utils.assign({
|
|
43
|
+
[ApiTypes_1.COMPUTED_CONFIG_SYMBOL]: true,
|
|
44
|
+
}, ...configs);
|
|
45
|
+
// merge other values
|
|
46
|
+
for (const key of MERGED_CONFIG_KEYS) {
|
|
47
|
+
computedConfig[key] = Utils.assign({}, ...configs.reduce((acc, config) => {
|
|
48
|
+
if (config?.[key]) {
|
|
26
49
|
acc.push(config[key]);
|
|
27
50
|
}
|
|
28
51
|
return acc;
|
|
29
|
-
}, [])
|
|
30
|
-
};
|
|
31
|
-
// merge other values
|
|
32
|
-
for (var _i = 0, MERGED_CONFIG_KEYS_1 = MERGED_CONFIG_KEYS; _i < MERGED_CONFIG_KEYS_1.length; _i++) {
|
|
33
|
-
var key = MERGED_CONFIG_KEYS_1[_i];
|
|
34
|
-
_loop_1(key);
|
|
52
|
+
}, []));
|
|
35
53
|
}
|
|
36
54
|
computedConfig.queryHandling = {
|
|
37
|
-
parse:
|
|
38
|
-
stringify:
|
|
55
|
+
parse: computedConfig.queryHandling?.parse || QueryHandling_1.DEFAULT_QUERY_PARSE,
|
|
56
|
+
stringify: computedConfig.queryHandling?.stringify || computedConfig.queryParser || QueryHandling_1.DEFAULT_QUERY_STRINGIFY,
|
|
39
57
|
};
|
|
40
58
|
computedConfig.queryParser = undefined;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
const query = computedConfig.query;
|
|
60
|
+
let queryString = "";
|
|
61
|
+
let queryObject = {};
|
|
44
62
|
if (query) {
|
|
45
63
|
if (typeof query === "string") {
|
|
46
64
|
queryString = query;
|
|
@@ -52,19 +70,19 @@ var processRequestConfigs = function (configs) {
|
|
|
52
70
|
}
|
|
53
71
|
}
|
|
54
72
|
Object.defineProperty(computedConfig, "queryString", {
|
|
55
|
-
get
|
|
73
|
+
get() {
|
|
56
74
|
return queryString;
|
|
57
75
|
},
|
|
58
|
-
set
|
|
76
|
+
set(value) {
|
|
59
77
|
queryString = value;
|
|
60
78
|
queryObject = computedConfig.queryHandling.parse(value);
|
|
61
79
|
},
|
|
62
80
|
});
|
|
63
81
|
Object.defineProperty(computedConfig, "queryObject", {
|
|
64
|
-
get
|
|
82
|
+
get() {
|
|
65
83
|
return queryObject;
|
|
66
84
|
},
|
|
67
|
-
set
|
|
85
|
+
set(value) {
|
|
68
86
|
queryObject = value;
|
|
69
87
|
queryString = computedConfig.queryHandling.stringify(value);
|
|
70
88
|
},
|
package/cjs/RequestContext.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Api } from "./Api";
|
|
2
2
|
import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
|
|
3
3
|
import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo, RequestEventHandlers, RequestHost, RequestStats, State } from "./ApiTypes";
|
|
4
|
+
import type RequestBackend from "./backend/RequestBackend";
|
|
4
5
|
import type { EndpointMockingConfig } from "./MockingTypes";
|
|
5
6
|
import type { RequestError } from "./RequestError";
|
|
6
7
|
import type { Validation } from "./Validation";
|
|
7
|
-
import type RequestBackend from "./backend/RequestBackend";
|
|
8
8
|
export default class RequestContext<TResponse = any, TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State> {
|
|
9
9
|
readonly id: number;
|
|
10
10
|
readonly key: string;
|