keq 5.0.0-alpha.23 → 5.0.0-alpha.24
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/CHANGELOG.md +6 -0
- package/dist/context/types/keq-context-options/keq-resolve-with-mode.d.ts +1 -1
- package/dist/context/types/keq-context-options/keq-resolve-with-mode.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +363 -351
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +363 -351
- package/dist/index.mjs.map +1 -1
- package/dist/request/core.d.ts.map +1 -1
- package/dist/request/keq.d.ts +4 -1
- package/dist/request/keq.d.ts.map +1 -1
- package/dist/request/types/index.d.ts +1 -0
- package/dist/request/types/index.d.ts.map +1 -1
- package/dist/request/types/server-sent-event.d.ts +3 -0
- package/dist/request/types/server-sent-event.d.ts.map +1 -0
- package/dist/request/utils/index.d.ts +1 -0
- package/dist/request/utils/index.d.ts.map +1 -1
- package/dist/request/utils/intelligent-parse-response.d.ts.map +1 -1
- package/dist/request/utils/resolve-with.d.ts +3 -0
- package/dist/request/utils/resolve-with.d.ts.map +1 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -76,102 +76,226 @@ __export(index_exports, {
|
|
|
76
76
|
});
|
|
77
77
|
module.exports = __toCommonJS(index_exports);
|
|
78
78
|
|
|
79
|
-
// src/
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
constructor(orchestrator, executor) {
|
|
86
|
-
__publicField(this, _b);
|
|
87
|
-
__publicField(this, _a);
|
|
88
|
-
this[OrchestratorProperty] = orchestrator;
|
|
89
|
-
this[ExecutorProperty] = executor;
|
|
79
|
+
// src/exception/exception.ts
|
|
80
|
+
var import_ts_custom_error = require("ts-custom-error");
|
|
81
|
+
var Exception = class extends import_ts_custom_error.CustomError {
|
|
82
|
+
constructor(message) {
|
|
83
|
+
super(message);
|
|
84
|
+
Object.defineProperty(this, "name", { value: "KeqError" });
|
|
90
85
|
}
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/exception/type.exception.ts
|
|
89
|
+
var TypeException = class extends Exception {
|
|
90
|
+
constructor(msg) {
|
|
91
|
+
super(msg || "Invalid Type");
|
|
93
92
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The middleware context of the current middleware
|
|
103
|
-
*/
|
|
104
|
-
get middleware() {
|
|
105
|
-
return this[ExecutorProperty].context;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/exception/abort.exception.ts
|
|
96
|
+
var AbortException = class _AbortException extends DOMException {
|
|
97
|
+
constructor(msg) {
|
|
98
|
+
super(msg, "AbortError");
|
|
99
|
+
Object.setPrototypeOf(this, _AbortException.prototype);
|
|
106
100
|
}
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/exception/timeout.exception.ts
|
|
104
|
+
var TimeoutException = class extends AbortException {
|
|
105
|
+
constructor(msg) {
|
|
106
|
+
super(msg);
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/exception/http-exceptions/request.exception.ts
|
|
111
|
+
var RequestException = class extends Exception {
|
|
112
|
+
constructor(statusCode, message, retry = true) {
|
|
113
|
+
super(message);
|
|
114
|
+
__publicField(this, "statusCode");
|
|
115
|
+
__publicField(this, "retry");
|
|
116
|
+
this.statusCode = statusCode;
|
|
117
|
+
this.retry = retry;
|
|
118
|
+
Object.defineProperty(this, "name", { value: "RequestException" });
|
|
112
119
|
}
|
|
113
120
|
};
|
|
114
121
|
|
|
115
|
-
// src/
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var KeqExecutionContext = class {
|
|
121
|
-
constructor(orchestrator, executor) {
|
|
122
|
-
__publicField(this, _b2);
|
|
123
|
-
__publicField(this, _a2);
|
|
124
|
-
this[ContextOrchestratorProperty] = orchestrator;
|
|
125
|
-
this[ContextOrchestrationProperty] = new KeqOrchestratorContext(orchestrator, executor);
|
|
122
|
+
// src/exception/http-exceptions/bad-request.exception.ts
|
|
123
|
+
var BadRequestException = class extends RequestException {
|
|
124
|
+
constructor(message = "Bad Request", retry = false) {
|
|
125
|
+
super(400, message, retry);
|
|
126
|
+
Object.defineProperty(this, "name", { value: "BadRequestException" });
|
|
126
127
|
}
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/exception/http-exceptions/unauthorized.exception.ts
|
|
131
|
+
var UnauthorizedException = class extends RequestException {
|
|
132
|
+
constructor(message = "Unauthorized", retry = false) {
|
|
133
|
+
super(401, message, retry);
|
|
134
|
+
Object.defineProperty(this, "name", { value: "UnauthorizedException" });
|
|
129
135
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/exception/http-exceptions/forbidden.exception.ts
|
|
139
|
+
var ForbiddenException = class extends RequestException {
|
|
140
|
+
constructor(message = "Forbidden", retry = false) {
|
|
141
|
+
super(403, message, retry);
|
|
142
|
+
Object.defineProperty(this, "name", { value: "ForbiddenException" });
|
|
135
143
|
}
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/exception/http-exceptions/not-founded.exception.ts
|
|
147
|
+
var NotFoundedException = class extends RequestException {
|
|
148
|
+
constructor(message = "Not Founded", retry = false) {
|
|
149
|
+
super(404, message, retry);
|
|
150
|
+
Object.defineProperty(this, "name", { value: "NotFoundedException" });
|
|
138
151
|
}
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/exception/http-exceptions/method-not-allowed.exception.ts
|
|
155
|
+
var MethodNotAllowedException = class extends RequestException {
|
|
156
|
+
constructor(message = "Method Not Allowed", retry = false) {
|
|
157
|
+
super(405, message, retry);
|
|
158
|
+
Object.defineProperty(this, "name", {
|
|
159
|
+
value: "MethodNotAllowedException"
|
|
160
|
+
});
|
|
141
161
|
}
|
|
142
|
-
|
|
143
|
-
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/exception/http-exceptions/not-acceptable.exception.ts
|
|
165
|
+
var NotAcceptableException = class extends RequestException {
|
|
166
|
+
constructor(message = "Not Acceptable", retry = false) {
|
|
167
|
+
super(406, message, retry);
|
|
168
|
+
Object.defineProperty(this, "name", { value: "NotAcceptableException" });
|
|
144
169
|
}
|
|
145
|
-
|
|
146
|
-
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/exception/http-exceptions/proxy-authentication-required.exception.ts
|
|
173
|
+
var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
174
|
+
constructor(message = "Proxy Authentication Required", retry = false) {
|
|
175
|
+
super(407, message, retry);
|
|
176
|
+
Object.defineProperty(this, "name", {
|
|
177
|
+
value: "ProxyAuthenticationRequiredException"
|
|
178
|
+
});
|
|
147
179
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/exception/http-exceptions/request-timeout.exception.ts
|
|
183
|
+
var RequestTimeoutException = class extends RequestException {
|
|
184
|
+
constructor(message = "Request Timeout", retry = true) {
|
|
185
|
+
super(408, message, retry);
|
|
186
|
+
Object.defineProperty(this, "name", {
|
|
187
|
+
value: "RequestTimeoutException"
|
|
188
|
+
});
|
|
154
189
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/exception/http-exceptions/conflict.exception.ts
|
|
193
|
+
var ConflictException = class extends RequestException {
|
|
194
|
+
constructor(message = "Conflict", retry = false) {
|
|
195
|
+
super(409, message, retry);
|
|
196
|
+
Object.defineProperty(this, "name", { value: "ConflictException" });
|
|
158
197
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/exception/http-exceptions/precondition-failed.exception.ts
|
|
201
|
+
var PreconditionFailedException = class extends RequestException {
|
|
202
|
+
constructor(message = "Precondition Failed", retry = false) {
|
|
203
|
+
super(412, message, retry);
|
|
204
|
+
Object.defineProperty(this, "name", {
|
|
205
|
+
value: "PreconditionFailedException"
|
|
206
|
+
});
|
|
162
207
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// src/exception/http-exceptions/content-too-large.exception.ts
|
|
211
|
+
var ContentTooLargeException = class extends RequestException {
|
|
212
|
+
constructor(message = "Content Too Large", retry = false) {
|
|
213
|
+
super(413, message, retry);
|
|
214
|
+
Object.defineProperty(this, "name", {
|
|
215
|
+
value: "ContentTooLargeException"
|
|
216
|
+
});
|
|
166
217
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/exception/http-exceptions/uri-too-long.exception.ts
|
|
221
|
+
var UriTooLongException = class extends RequestException {
|
|
222
|
+
constructor(message = "URI Too Long", retry = false) {
|
|
223
|
+
super(414, message, retry);
|
|
224
|
+
Object.defineProperty(this, "name", { value: "UriTooLongException" });
|
|
170
225
|
}
|
|
171
226
|
};
|
|
172
227
|
|
|
173
|
-
// src/
|
|
174
|
-
var
|
|
228
|
+
// src/exception/http-exceptions/unsupported-media-type.exception.ts
|
|
229
|
+
var UnsupportedMediaTypeException = class extends RequestException {
|
|
230
|
+
constructor(message = "Unsupported Media Type", retry = false) {
|
|
231
|
+
super(415, message, retry);
|
|
232
|
+
Object.defineProperty(this, "name", { value: "UnsupportedMediaTypeException" });
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// src/exception/http-exceptions/im-a-teapot.exception.ts
|
|
237
|
+
var ImATeapotException = class extends RequestException {
|
|
238
|
+
constructor(message = "I'm a teapot", retry = false) {
|
|
239
|
+
super(418, message, retry);
|
|
240
|
+
Object.defineProperty(this, "name", { value: "ImATeapotException" });
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/exception/http-exceptions/too-many-requests.exception.ts
|
|
245
|
+
var TooManyRequestsException = class extends RequestException {
|
|
246
|
+
constructor(message = "Too Many Requests", retry = true) {
|
|
247
|
+
super(429, message, retry);
|
|
248
|
+
Object.defineProperty(this, "name", { value: "TooManyRequestsException" });
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// src/exception/http-exceptions/internal-server-error.exception.ts
|
|
253
|
+
var InternalServerErrorException = class extends RequestException {
|
|
254
|
+
constructor(message = "Internal Server Error", retry = true) {
|
|
255
|
+
super(500, message, retry);
|
|
256
|
+
Object.defineProperty(this, "name", {
|
|
257
|
+
value: "InternalServerErrorException"
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// src/exception/http-exceptions/not-implemented.exception.ts
|
|
263
|
+
var NotImplementedException = class extends RequestException {
|
|
264
|
+
constructor(message = "Not Implemented", retry = false) {
|
|
265
|
+
super(501, message, retry);
|
|
266
|
+
Object.defineProperty(this, "name", { value: "NotImplementedException" });
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// src/exception/http-exceptions/bad-gateway.exception.ts
|
|
271
|
+
var BadGatewayException = class extends RequestException {
|
|
272
|
+
constructor(message = "Bad Gateway", retry = true) {
|
|
273
|
+
super(502, message, retry);
|
|
274
|
+
Object.defineProperty(this, "name", { value: "BadGatewayException" });
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// src/exception/http-exceptions/service-unavailable.exception.ts
|
|
279
|
+
var ServiceUnavailableException = class extends RequestException {
|
|
280
|
+
constructor(message = "Service Unavailable", retry = true) {
|
|
281
|
+
super(503, message, retry);
|
|
282
|
+
Object.defineProperty(this, "name", {
|
|
283
|
+
value: "ServiceUnavailableException"
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/exception/http-exceptions/gateway-timeout.exception.ts
|
|
289
|
+
var GatewayTimeoutException = class extends RequestException {
|
|
290
|
+
constructor(message = "Gateway Timeout", retry = true) {
|
|
291
|
+
super(504, message, retry);
|
|
292
|
+
Object.defineProperty(this, "name", { value: "GatewayTimeoutException" });
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/utils/base64.ts
|
|
297
|
+
var base64Encode = globalThis.btoa || ((str) => Buffer.from(str).toString("base64"));
|
|
298
|
+
var base64Decode = globalThis.atob || ((str) => Buffer.from(str, "base64").toString("utf8"));
|
|
175
299
|
|
|
176
300
|
// src/validator/validator.ts
|
|
177
301
|
var Validator = class _Validator {
|
|
@@ -286,14 +410,10 @@ function shallowClone(obj) {
|
|
|
286
410
|
return obj;
|
|
287
411
|
}
|
|
288
412
|
|
|
289
|
-
// src/
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
super(message);
|
|
294
|
-
Object.defineProperty(this, "name", { value: "KeqError" });
|
|
295
|
-
}
|
|
296
|
-
};
|
|
413
|
+
// src/utils/sleep.ts
|
|
414
|
+
function sleep(ms) {
|
|
415
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
416
|
+
}
|
|
297
417
|
|
|
298
418
|
// src/request-init/utils/clone-body.ts
|
|
299
419
|
function cloneBody(obj) {
|
|
@@ -409,8 +529,8 @@ function cloneRequestInit(init) {
|
|
|
409
529
|
|
|
410
530
|
// src/request-init/request-init.ts
|
|
411
531
|
var AbortControllerProperty = /* @__PURE__ */ Symbol("context.request.abortController");
|
|
412
|
-
var
|
|
413
|
-
|
|
532
|
+
var _a;
|
|
533
|
+
_a = AbortControllerProperty;
|
|
414
534
|
var KeqRequestInit = class {
|
|
415
535
|
constructor(options) {
|
|
416
536
|
__publicField(this, "url");
|
|
@@ -426,7 +546,7 @@ var KeqRequestInit = class {
|
|
|
426
546
|
__publicField(this, "redirect");
|
|
427
547
|
__publicField(this, "referrer");
|
|
428
548
|
__publicField(this, "referrerPolicy");
|
|
429
|
-
__publicField(this,
|
|
549
|
+
__publicField(this, _a, new AbortController());
|
|
430
550
|
this.url = new URL(options.url.href);
|
|
431
551
|
this.pathParameters = shallowClone(options.pathParameters);
|
|
432
552
|
this.method = options.method;
|
|
@@ -485,32 +605,129 @@ var KeqRequestInit = class {
|
|
|
485
605
|
}
|
|
486
606
|
throw new Exception("Cannot auto serialize request.body with Content-Type: ".concat(contentType));
|
|
487
607
|
}
|
|
488
|
-
toFetchArguments() {
|
|
489
|
-
const contentType = this.getContentType();
|
|
490
|
-
const headers = cloneHeaders(this.headers);
|
|
491
|
-
if (contentType) headers.set("Content-Type", contentType);
|
|
492
|
-
const body = this.toFetchBody(contentType);
|
|
493
|
-
if (contentType === "multipart/form-data") {
|
|
494
|
-
headers.delete("Content-Type");
|
|
495
|
-
}
|
|
496
|
-
const requestInit = {
|
|
497
|
-
method: this.method.toUpperCase(),
|
|
498
|
-
headers,
|
|
499
|
-
body,
|
|
500
|
-
cache: this.cache,
|
|
501
|
-
credentials: this.credentials,
|
|
502
|
-
integrity: this.integrity,
|
|
503
|
-
keepalive: this.keepalive,
|
|
504
|
-
mode: this.mode,
|
|
505
|
-
redirect: this.redirect,
|
|
506
|
-
referrer: this.referrer,
|
|
507
|
-
referrerPolicy: this.referrerPolicy,
|
|
508
|
-
signal: this.signal
|
|
509
|
-
};
|
|
510
|
-
return [this.__url__.href, requestInit];
|
|
608
|
+
toFetchArguments() {
|
|
609
|
+
const contentType = this.getContentType();
|
|
610
|
+
const headers = cloneHeaders(this.headers);
|
|
611
|
+
if (contentType) headers.set("Content-Type", contentType);
|
|
612
|
+
const body = this.toFetchBody(contentType);
|
|
613
|
+
if (contentType === "multipart/form-data") {
|
|
614
|
+
headers.delete("Content-Type");
|
|
615
|
+
}
|
|
616
|
+
const requestInit = {
|
|
617
|
+
method: this.method.toUpperCase(),
|
|
618
|
+
headers,
|
|
619
|
+
body,
|
|
620
|
+
cache: this.cache,
|
|
621
|
+
credentials: this.credentials,
|
|
622
|
+
integrity: this.integrity,
|
|
623
|
+
keepalive: this.keepalive,
|
|
624
|
+
mode: this.mode,
|
|
625
|
+
redirect: this.redirect,
|
|
626
|
+
referrer: this.referrer,
|
|
627
|
+
referrerPolicy: this.referrerPolicy,
|
|
628
|
+
signal: this.signal
|
|
629
|
+
};
|
|
630
|
+
return [this.__url__.href, requestInit];
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// src/context/orchestrator-context.ts
|
|
635
|
+
var OrchestratorProperty = /* @__PURE__ */ Symbol("protected context.orchestration.orchestrator");
|
|
636
|
+
var ExecutorProperty = /* @__PURE__ */ Symbol("protected context.orchestration.executor");
|
|
637
|
+
var _a2, _b;
|
|
638
|
+
_b = OrchestratorProperty, _a2 = ExecutorProperty;
|
|
639
|
+
var KeqOrchestratorContext = class {
|
|
640
|
+
constructor(orchestrator, executor) {
|
|
641
|
+
__publicField(this, _b);
|
|
642
|
+
__publicField(this, _a2);
|
|
643
|
+
this[OrchestratorProperty] = orchestrator;
|
|
644
|
+
this[ExecutorProperty] = executor;
|
|
645
|
+
}
|
|
646
|
+
get middlewares() {
|
|
647
|
+
return this[OrchestratorProperty].executors.map((exe) => exe.context);
|
|
648
|
+
}
|
|
649
|
+
// NOTE: For Future
|
|
650
|
+
// get executing(): KeqMiddlewareContext {
|
|
651
|
+
// const current = this[OrchestratorProperty].current
|
|
652
|
+
// const executors = this[OrchestratorProperty].executors
|
|
653
|
+
// const executor = executors[current]
|
|
654
|
+
// return executor.context
|
|
655
|
+
// }
|
|
656
|
+
/**
|
|
657
|
+
* The middleware context of the current middleware
|
|
658
|
+
*/
|
|
659
|
+
get middleware() {
|
|
660
|
+
return this[ExecutorProperty].context;
|
|
661
|
+
}
|
|
662
|
+
fork() {
|
|
663
|
+
return this[OrchestratorProperty].fork();
|
|
664
|
+
}
|
|
665
|
+
merge(source) {
|
|
666
|
+
this[OrchestratorProperty].merge(source);
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
// src/context/execution-context.ts
|
|
671
|
+
var ContextOrchestratorProperty = /* @__PURE__ */ Symbol("protected context.orchestrator");
|
|
672
|
+
var ContextOrchestrationProperty = /* @__PURE__ */ Symbol("protected context.orchestration");
|
|
673
|
+
var _a3, _b2;
|
|
674
|
+
_b2 = ContextOrchestratorProperty, _a3 = ContextOrchestrationProperty;
|
|
675
|
+
var KeqExecutionContext = class {
|
|
676
|
+
constructor(orchestrator, executor) {
|
|
677
|
+
__publicField(this, _b2);
|
|
678
|
+
__publicField(this, _a3);
|
|
679
|
+
this[ContextOrchestratorProperty] = orchestrator;
|
|
680
|
+
this[ContextOrchestrationProperty] = new KeqOrchestratorContext(orchestrator, executor);
|
|
681
|
+
}
|
|
682
|
+
get orchestration() {
|
|
683
|
+
return this[ContextOrchestrationProperty];
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* The unique identifier of the request's location in the code
|
|
687
|
+
*/
|
|
688
|
+
get locationId() {
|
|
689
|
+
return this[ContextOrchestratorProperty].context.locationId;
|
|
690
|
+
}
|
|
691
|
+
get request() {
|
|
692
|
+
return this[ContextOrchestratorProperty].context.request;
|
|
693
|
+
}
|
|
694
|
+
get global() {
|
|
695
|
+
return this[ContextOrchestratorProperty].context.global;
|
|
696
|
+
}
|
|
697
|
+
get emitter() {
|
|
698
|
+
return this[ContextOrchestratorProperty].context.emitter;
|
|
699
|
+
}
|
|
700
|
+
get options() {
|
|
701
|
+
return this[ContextOrchestratorProperty].context.options;
|
|
702
|
+
}
|
|
703
|
+
// The result get by user if resolveWith is set to 'intelligent' or not set
|
|
704
|
+
set output(value) {
|
|
705
|
+
if (this.options.resolveWith && this.options.resolveWith !== "intelligent") {
|
|
706
|
+
console.warn("The request is configured to resolve with ".concat(this.options.resolveWith, ", so setting context.output maybe no effect."));
|
|
707
|
+
}
|
|
708
|
+
this[ContextOrchestratorProperty].context.output = value;
|
|
709
|
+
}
|
|
710
|
+
// The original response
|
|
711
|
+
get res() {
|
|
712
|
+
return this[ContextOrchestratorProperty].context.res;
|
|
713
|
+
}
|
|
714
|
+
// The original response
|
|
715
|
+
set res(value) {
|
|
716
|
+
this[ContextOrchestratorProperty].context.res = value;
|
|
717
|
+
}
|
|
718
|
+
// The request response
|
|
719
|
+
get response() {
|
|
720
|
+
return this[ContextOrchestratorProperty].context.response;
|
|
721
|
+
}
|
|
722
|
+
// The properties extends by middleware
|
|
723
|
+
get data() {
|
|
724
|
+
return this[ContextOrchestratorProperty].context.data;
|
|
511
725
|
}
|
|
512
726
|
};
|
|
513
727
|
|
|
728
|
+
// src/context/shared-context.ts
|
|
729
|
+
var import_mitt = __toESM(require("mitt"));
|
|
730
|
+
|
|
514
731
|
// src/context/utils/watch-object.ts
|
|
515
732
|
function watchObject(obj, listeners) {
|
|
516
733
|
return new Proxy(obj, {
|
|
@@ -731,223 +948,6 @@ var KeqSharedContext = class {
|
|
|
731
948
|
}
|
|
732
949
|
};
|
|
733
950
|
|
|
734
|
-
// src/exception/type.exception.ts
|
|
735
|
-
var TypeException = class extends Exception {
|
|
736
|
-
constructor(msg) {
|
|
737
|
-
super(msg || "Invalid Type");
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
// src/exception/abort.exception.ts
|
|
742
|
-
var AbortException = class _AbortException extends DOMException {
|
|
743
|
-
constructor(msg) {
|
|
744
|
-
super(msg, "AbortError");
|
|
745
|
-
Object.setPrototypeOf(this, _AbortException.prototype);
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
// src/exception/timeout.exception.ts
|
|
750
|
-
var TimeoutException = class extends AbortException {
|
|
751
|
-
constructor(msg) {
|
|
752
|
-
super(msg);
|
|
753
|
-
}
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
// src/exception/http-exceptions/request.exception.ts
|
|
757
|
-
var RequestException = class extends Exception {
|
|
758
|
-
constructor(statusCode, message, retry = true) {
|
|
759
|
-
super(message);
|
|
760
|
-
__publicField(this, "statusCode");
|
|
761
|
-
__publicField(this, "retry");
|
|
762
|
-
this.statusCode = statusCode;
|
|
763
|
-
this.retry = retry;
|
|
764
|
-
Object.defineProperty(this, "name", { value: "RequestException" });
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
|
|
768
|
-
// src/exception/http-exceptions/bad-request.exception.ts
|
|
769
|
-
var BadRequestException = class extends RequestException {
|
|
770
|
-
constructor(message = "Bad Request", retry = false) {
|
|
771
|
-
super(400, message, retry);
|
|
772
|
-
Object.defineProperty(this, "name", { value: "BadRequestException" });
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
// src/exception/http-exceptions/unauthorized.exception.ts
|
|
777
|
-
var UnauthorizedException = class extends RequestException {
|
|
778
|
-
constructor(message = "Unauthorized", retry = false) {
|
|
779
|
-
super(401, message, retry);
|
|
780
|
-
Object.defineProperty(this, "name", { value: "UnauthorizedException" });
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
// src/exception/http-exceptions/forbidden.exception.ts
|
|
785
|
-
var ForbiddenException = class extends RequestException {
|
|
786
|
-
constructor(message = "Forbidden", retry = false) {
|
|
787
|
-
super(403, message, retry);
|
|
788
|
-
Object.defineProperty(this, "name", { value: "ForbiddenException" });
|
|
789
|
-
}
|
|
790
|
-
};
|
|
791
|
-
|
|
792
|
-
// src/exception/http-exceptions/not-founded.exception.ts
|
|
793
|
-
var NotFoundedException = class extends RequestException {
|
|
794
|
-
constructor(message = "Not Founded", retry = false) {
|
|
795
|
-
super(404, message, retry);
|
|
796
|
-
Object.defineProperty(this, "name", { value: "NotFoundedException" });
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
// src/exception/http-exceptions/method-not-allowed.exception.ts
|
|
801
|
-
var MethodNotAllowedException = class extends RequestException {
|
|
802
|
-
constructor(message = "Method Not Allowed", retry = false) {
|
|
803
|
-
super(405, message, retry);
|
|
804
|
-
Object.defineProperty(this, "name", {
|
|
805
|
-
value: "MethodNotAllowedException"
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
|
|
810
|
-
// src/exception/http-exceptions/not-acceptable.exception.ts
|
|
811
|
-
var NotAcceptableException = class extends RequestException {
|
|
812
|
-
constructor(message = "Not Acceptable", retry = false) {
|
|
813
|
-
super(406, message, retry);
|
|
814
|
-
Object.defineProperty(this, "name", { value: "NotAcceptableException" });
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
|
|
818
|
-
// src/exception/http-exceptions/proxy-authentication-required.exception.ts
|
|
819
|
-
var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
820
|
-
constructor(message = "Proxy Authentication Required", retry = false) {
|
|
821
|
-
super(407, message, retry);
|
|
822
|
-
Object.defineProperty(this, "name", {
|
|
823
|
-
value: "ProxyAuthenticationRequiredException"
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
// src/exception/http-exceptions/request-timeout.exception.ts
|
|
829
|
-
var RequestTimeoutException = class extends RequestException {
|
|
830
|
-
constructor(message = "Request Timeout", retry = true) {
|
|
831
|
-
super(408, message, retry);
|
|
832
|
-
Object.defineProperty(this, "name", {
|
|
833
|
-
value: "RequestTimeoutException"
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
};
|
|
837
|
-
|
|
838
|
-
// src/exception/http-exceptions/conflict.exception.ts
|
|
839
|
-
var ConflictException = class extends RequestException {
|
|
840
|
-
constructor(message = "Conflict", retry = false) {
|
|
841
|
-
super(409, message, retry);
|
|
842
|
-
Object.defineProperty(this, "name", { value: "ConflictException" });
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
// src/exception/http-exceptions/precondition-failed.exception.ts
|
|
847
|
-
var PreconditionFailedException = class extends RequestException {
|
|
848
|
-
constructor(message = "Precondition Failed", retry = false) {
|
|
849
|
-
super(412, message, retry);
|
|
850
|
-
Object.defineProperty(this, "name", {
|
|
851
|
-
value: "PreconditionFailedException"
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
|
|
856
|
-
// src/exception/http-exceptions/content-too-large.exception.ts
|
|
857
|
-
var ContentTooLargeException = class extends RequestException {
|
|
858
|
-
constructor(message = "Content Too Large", retry = false) {
|
|
859
|
-
super(413, message, retry);
|
|
860
|
-
Object.defineProperty(this, "name", {
|
|
861
|
-
value: "ContentTooLargeException"
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
// src/exception/http-exceptions/uri-too-long.exception.ts
|
|
867
|
-
var UriTooLongException = class extends RequestException {
|
|
868
|
-
constructor(message = "URI Too Long", retry = false) {
|
|
869
|
-
super(414, message, retry);
|
|
870
|
-
Object.defineProperty(this, "name", { value: "UriTooLongException" });
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
|
|
874
|
-
// src/exception/http-exceptions/unsupported-media-type.exception.ts
|
|
875
|
-
var UnsupportedMediaTypeException = class extends RequestException {
|
|
876
|
-
constructor(message = "Unsupported Media Type", retry = false) {
|
|
877
|
-
super(415, message, retry);
|
|
878
|
-
Object.defineProperty(this, "name", { value: "UnsupportedMediaTypeException" });
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
|
|
882
|
-
// src/exception/http-exceptions/im-a-teapot.exception.ts
|
|
883
|
-
var ImATeapotException = class extends RequestException {
|
|
884
|
-
constructor(message = "I'm a teapot", retry = false) {
|
|
885
|
-
super(418, message, retry);
|
|
886
|
-
Object.defineProperty(this, "name", { value: "ImATeapotException" });
|
|
887
|
-
}
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
// src/exception/http-exceptions/too-many-requests.exception.ts
|
|
891
|
-
var TooManyRequestsException = class extends RequestException {
|
|
892
|
-
constructor(message = "Too Many Requests", retry = true) {
|
|
893
|
-
super(429, message, retry);
|
|
894
|
-
Object.defineProperty(this, "name", { value: "TooManyRequestsException" });
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
// src/exception/http-exceptions/internal-server-error.exception.ts
|
|
899
|
-
var InternalServerErrorException = class extends RequestException {
|
|
900
|
-
constructor(message = "Internal Server Error", retry = true) {
|
|
901
|
-
super(500, message, retry);
|
|
902
|
-
Object.defineProperty(this, "name", {
|
|
903
|
-
value: "InternalServerErrorException"
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
|
-
|
|
908
|
-
// src/exception/http-exceptions/not-implemented.exception.ts
|
|
909
|
-
var NotImplementedException = class extends RequestException {
|
|
910
|
-
constructor(message = "Not Implemented", retry = false) {
|
|
911
|
-
super(501, message, retry);
|
|
912
|
-
Object.defineProperty(this, "name", { value: "NotImplementedException" });
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
// src/exception/http-exceptions/bad-gateway.exception.ts
|
|
917
|
-
var BadGatewayException = class extends RequestException {
|
|
918
|
-
constructor(message = "Bad Gateway", retry = true) {
|
|
919
|
-
super(502, message, retry);
|
|
920
|
-
Object.defineProperty(this, "name", { value: "BadGatewayException" });
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
|
|
924
|
-
// src/exception/http-exceptions/service-unavailable.exception.ts
|
|
925
|
-
var ServiceUnavailableException = class extends RequestException {
|
|
926
|
-
constructor(message = "Service Unavailable", retry = true) {
|
|
927
|
-
super(503, message, retry);
|
|
928
|
-
Object.defineProperty(this, "name", {
|
|
929
|
-
value: "ServiceUnavailableException"
|
|
930
|
-
});
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
|
|
934
|
-
// src/exception/http-exceptions/gateway-timeout.exception.ts
|
|
935
|
-
var GatewayTimeoutException = class extends RequestException {
|
|
936
|
-
constructor(message = "Gateway Timeout", retry = true) {
|
|
937
|
-
super(504, message, retry);
|
|
938
|
-
Object.defineProperty(this, "name", { value: "GatewayTimeoutException" });
|
|
939
|
-
}
|
|
940
|
-
};
|
|
941
|
-
|
|
942
|
-
// src/utils/base64.ts
|
|
943
|
-
var base64Encode = globalThis.btoa || ((str) => Buffer.from(str).toString("base64"));
|
|
944
|
-
var base64Decode = globalThis.atob || ((str) => Buffer.from(str, "base64").toString("utf8"));
|
|
945
|
-
|
|
946
|
-
// src/utils/sleep.ts
|
|
947
|
-
function sleep(ms) {
|
|
948
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
949
|
-
}
|
|
950
|
-
|
|
951
951
|
// src/middleware/utils/get-middleware-name.ts
|
|
952
952
|
function getMiddlewareName(middleware) {
|
|
953
953
|
return middleware.__keqMiddlewareName__ || middleware.name || "anonymous";
|
|
@@ -1164,6 +1164,22 @@ function getLocationId(depth = 0) {
|
|
|
1164
1164
|
return stackLine.trim();
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
|
+
// src/request/utils/resolve-with.ts
|
|
1168
|
+
var import_stream = require("eventsource-parser/stream");
|
|
1169
|
+
async function resolveWith(response, mode) {
|
|
1170
|
+
if (mode === "response") return response.clone();
|
|
1171
|
+
if (mode === "text") return await response.text();
|
|
1172
|
+
if (mode === "json") return unwrap(await response.json());
|
|
1173
|
+
if (mode === "form-data") return await response.formData();
|
|
1174
|
+
if (mode === "blob") return await response.blob();
|
|
1175
|
+
if (mode === "array-buffer") return await response.arrayBuffer();
|
|
1176
|
+
if (mode === "sse") {
|
|
1177
|
+
if (!response.body) return response.body;
|
|
1178
|
+
return response.clone().body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream());
|
|
1179
|
+
}
|
|
1180
|
+
return void 0;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1167
1183
|
// src/request/utils/intelligent-parse-response.ts
|
|
1168
1184
|
async function intelligentParseResponse(response) {
|
|
1169
1185
|
if (!response) return void 0;
|
|
@@ -1172,15 +1188,18 @@ async function intelligentParseResponse(response) {
|
|
|
1172
1188
|
}
|
|
1173
1189
|
const contentType = response.headers.get("content-type") || "";
|
|
1174
1190
|
try {
|
|
1175
|
-
if (contentType.
|
|
1176
|
-
return
|
|
1191
|
+
if (contentType.match(/^application\/(.+\+)?json/)) {
|
|
1192
|
+
return resolveWith(response, "json");
|
|
1177
1193
|
} else if (contentType.includes("multipart/form-data")) {
|
|
1178
|
-
return
|
|
1194
|
+
return resolveWith(response, "form-data");
|
|
1179
1195
|
} else if (contentType.includes("plain/text")) {
|
|
1180
|
-
return
|
|
1196
|
+
return resolveWith(response, "text");
|
|
1197
|
+
} else if (contentType.includes("text/event-stream")) {
|
|
1198
|
+
return resolveWith(response, "sse");
|
|
1181
1199
|
}
|
|
1182
|
-
} catch (
|
|
1183
|
-
console.warn("Failed to
|
|
1200
|
+
} catch (err) {
|
|
1201
|
+
console.warn("Failed to intelligent parse response body: ".concat(response.url), err);
|
|
1202
|
+
throw err;
|
|
1184
1203
|
}
|
|
1185
1204
|
return void 0;
|
|
1186
1205
|
}
|
|
@@ -1386,33 +1405,26 @@ var Core = class {
|
|
|
1386
1405
|
async end() {
|
|
1387
1406
|
var _a6;
|
|
1388
1407
|
const coreContext = await this.run();
|
|
1389
|
-
|
|
1408
|
+
const resolveWithMode = coreContext.options.resolveWith;
|
|
1409
|
+
if (resolveWithMode === "response") {
|
|
1390
1410
|
return (_a6 = coreContext.response) == null ? void 0 : _a6.clone();
|
|
1391
1411
|
}
|
|
1392
1412
|
const response = coreContext.response;
|
|
1393
|
-
if (
|
|
1413
|
+
if (!resolveWithMode || resolveWithMode === "intelligent") {
|
|
1414
|
+
const output = coreContext.output;
|
|
1415
|
+
if (output !== void 0) {
|
|
1416
|
+
return output;
|
|
1417
|
+
}
|
|
1418
|
+
return await intelligentParseResponse(response);
|
|
1419
|
+
}
|
|
1420
|
+
if (!response) {
|
|
1394
1421
|
throw new Exception([
|
|
1395
|
-
"Unable to process the response with '".concat(
|
|
1422
|
+
"Unable to process the response with '".concat(resolveWithMode, "'. Possible causes:"),
|
|
1396
1423
|
"1. The request was never initiated or sent",
|
|
1397
1424
|
"2. The request failed before a response was received."
|
|
1398
1425
|
].join("\n"));
|
|
1399
1426
|
}
|
|
1400
|
-
|
|
1401
|
-
return await response.text();
|
|
1402
|
-
} else if (coreContext.options.resolveWith === "json") {
|
|
1403
|
-
return unwrap(await response.json());
|
|
1404
|
-
} else if (coreContext.options.resolveWith === "form-data") {
|
|
1405
|
-
return await response.formData();
|
|
1406
|
-
} else if (coreContext.options.resolveWith === "blob") {
|
|
1407
|
-
return await response.blob();
|
|
1408
|
-
} else if (coreContext.options.resolveWith === "array-buffer") {
|
|
1409
|
-
return await response.arrayBuffer();
|
|
1410
|
-
}
|
|
1411
|
-
const output = coreContext.output;
|
|
1412
|
-
if (output !== void 0) {
|
|
1413
|
-
return output;
|
|
1414
|
-
}
|
|
1415
|
-
return await intelligentParseResponse(response);
|
|
1427
|
+
return await resolveWith(response, resolveWithMode);
|
|
1416
1428
|
}
|
|
1417
1429
|
/**
|
|
1418
1430
|
* Attaches callbacks for the resolution and/or rejection of the Promise.
|