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.mjs
CHANGED
|
@@ -2,102 +2,226 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
|
-
// src/
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(orchestrator, executor) {
|
|
12
|
-
__publicField(this, _b);
|
|
13
|
-
__publicField(this, _a);
|
|
14
|
-
this[OrchestratorProperty] = orchestrator;
|
|
15
|
-
this[ExecutorProperty] = executor;
|
|
5
|
+
// src/exception/exception.ts
|
|
6
|
+
import { CustomError } from "ts-custom-error";
|
|
7
|
+
var Exception = class extends CustomError {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
Object.defineProperty(this, "name", { value: "KeqError" });
|
|
16
11
|
}
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/exception/type.exception.ts
|
|
15
|
+
var TypeException = class extends Exception {
|
|
16
|
+
constructor(msg) {
|
|
17
|
+
super(msg || "Invalid Type");
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The middleware context of the current middleware
|
|
29
|
-
*/
|
|
30
|
-
get middleware() {
|
|
31
|
-
return this[ExecutorProperty].context;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/exception/abort.exception.ts
|
|
22
|
+
var AbortException = class _AbortException extends DOMException {
|
|
23
|
+
constructor(msg) {
|
|
24
|
+
super(msg, "AbortError");
|
|
25
|
+
Object.setPrototypeOf(this, _AbortException.prototype);
|
|
32
26
|
}
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/exception/timeout.exception.ts
|
|
30
|
+
var TimeoutException = class extends AbortException {
|
|
31
|
+
constructor(msg) {
|
|
32
|
+
super(msg);
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/exception/http-exceptions/request.exception.ts
|
|
37
|
+
var RequestException = class extends Exception {
|
|
38
|
+
constructor(statusCode, message, retry = true) {
|
|
39
|
+
super(message);
|
|
40
|
+
__publicField(this, "statusCode");
|
|
41
|
+
__publicField(this, "retry");
|
|
42
|
+
this.statusCode = statusCode;
|
|
43
|
+
this.retry = retry;
|
|
44
|
+
Object.defineProperty(this, "name", { value: "RequestException" });
|
|
38
45
|
}
|
|
39
46
|
};
|
|
40
47
|
|
|
41
|
-
// src/
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var KeqExecutionContext = class {
|
|
47
|
-
constructor(orchestrator, executor) {
|
|
48
|
-
__publicField(this, _b2);
|
|
49
|
-
__publicField(this, _a2);
|
|
50
|
-
this[ContextOrchestratorProperty] = orchestrator;
|
|
51
|
-
this[ContextOrchestrationProperty] = new KeqOrchestratorContext(orchestrator, executor);
|
|
48
|
+
// src/exception/http-exceptions/bad-request.exception.ts
|
|
49
|
+
var BadRequestException = class extends RequestException {
|
|
50
|
+
constructor(message = "Bad Request", retry = false) {
|
|
51
|
+
super(400, message, retry);
|
|
52
|
+
Object.defineProperty(this, "name", { value: "BadRequestException" });
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/exception/http-exceptions/unauthorized.exception.ts
|
|
57
|
+
var UnauthorizedException = class extends RequestException {
|
|
58
|
+
constructor(message = "Unauthorized", retry = false) {
|
|
59
|
+
super(401, message, retry);
|
|
60
|
+
Object.defineProperty(this, "name", { value: "UnauthorizedException" });
|
|
55
61
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/exception/http-exceptions/forbidden.exception.ts
|
|
65
|
+
var ForbiddenException = class extends RequestException {
|
|
66
|
+
constructor(message = "Forbidden", retry = false) {
|
|
67
|
+
super(403, message, retry);
|
|
68
|
+
Object.defineProperty(this, "name", { value: "ForbiddenException" });
|
|
61
69
|
}
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/exception/http-exceptions/not-founded.exception.ts
|
|
73
|
+
var NotFoundedException = class extends RequestException {
|
|
74
|
+
constructor(message = "Not Founded", retry = false) {
|
|
75
|
+
super(404, message, retry);
|
|
76
|
+
Object.defineProperty(this, "name", { value: "NotFoundedException" });
|
|
64
77
|
}
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/exception/http-exceptions/method-not-allowed.exception.ts
|
|
81
|
+
var MethodNotAllowedException = class extends RequestException {
|
|
82
|
+
constructor(message = "Method Not Allowed", retry = false) {
|
|
83
|
+
super(405, message, retry);
|
|
84
|
+
Object.defineProperty(this, "name", {
|
|
85
|
+
value: "MethodNotAllowedException"
|
|
86
|
+
});
|
|
67
87
|
}
|
|
68
|
-
|
|
69
|
-
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/exception/http-exceptions/not-acceptable.exception.ts
|
|
91
|
+
var NotAcceptableException = class extends RequestException {
|
|
92
|
+
constructor(message = "Not Acceptable", retry = false) {
|
|
93
|
+
super(406, message, retry);
|
|
94
|
+
Object.defineProperty(this, "name", { value: "NotAcceptableException" });
|
|
70
95
|
}
|
|
71
|
-
|
|
72
|
-
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/exception/http-exceptions/proxy-authentication-required.exception.ts
|
|
99
|
+
var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
100
|
+
constructor(message = "Proxy Authentication Required", retry = false) {
|
|
101
|
+
super(407, message, retry);
|
|
102
|
+
Object.defineProperty(this, "name", {
|
|
103
|
+
value: "ProxyAuthenticationRequiredException"
|
|
104
|
+
});
|
|
73
105
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/exception/http-exceptions/request-timeout.exception.ts
|
|
109
|
+
var RequestTimeoutException = class extends RequestException {
|
|
110
|
+
constructor(message = "Request Timeout", retry = true) {
|
|
111
|
+
super(408, message, retry);
|
|
112
|
+
Object.defineProperty(this, "name", {
|
|
113
|
+
value: "RequestTimeoutException"
|
|
114
|
+
});
|
|
80
115
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/exception/http-exceptions/conflict.exception.ts
|
|
119
|
+
var ConflictException = class extends RequestException {
|
|
120
|
+
constructor(message = "Conflict", retry = false) {
|
|
121
|
+
super(409, message, retry);
|
|
122
|
+
Object.defineProperty(this, "name", { value: "ConflictException" });
|
|
84
123
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/exception/http-exceptions/precondition-failed.exception.ts
|
|
127
|
+
var PreconditionFailedException = class extends RequestException {
|
|
128
|
+
constructor(message = "Precondition Failed", retry = false) {
|
|
129
|
+
super(412, message, retry);
|
|
130
|
+
Object.defineProperty(this, "name", {
|
|
131
|
+
value: "PreconditionFailedException"
|
|
132
|
+
});
|
|
88
133
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/exception/http-exceptions/content-too-large.exception.ts
|
|
137
|
+
var ContentTooLargeException = class extends RequestException {
|
|
138
|
+
constructor(message = "Content Too Large", retry = false) {
|
|
139
|
+
super(413, message, retry);
|
|
140
|
+
Object.defineProperty(this, "name", {
|
|
141
|
+
value: "ContentTooLargeException"
|
|
142
|
+
});
|
|
92
143
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/exception/http-exceptions/uri-too-long.exception.ts
|
|
147
|
+
var UriTooLongException = class extends RequestException {
|
|
148
|
+
constructor(message = "URI Too Long", retry = false) {
|
|
149
|
+
super(414, message, retry);
|
|
150
|
+
Object.defineProperty(this, "name", { value: "UriTooLongException" });
|
|
96
151
|
}
|
|
97
152
|
};
|
|
98
153
|
|
|
99
|
-
// src/
|
|
100
|
-
|
|
154
|
+
// src/exception/http-exceptions/unsupported-media-type.exception.ts
|
|
155
|
+
var UnsupportedMediaTypeException = class extends RequestException {
|
|
156
|
+
constructor(message = "Unsupported Media Type", retry = false) {
|
|
157
|
+
super(415, message, retry);
|
|
158
|
+
Object.defineProperty(this, "name", { value: "UnsupportedMediaTypeException" });
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/exception/http-exceptions/im-a-teapot.exception.ts
|
|
163
|
+
var ImATeapotException = class extends RequestException {
|
|
164
|
+
constructor(message = "I'm a teapot", retry = false) {
|
|
165
|
+
super(418, message, retry);
|
|
166
|
+
Object.defineProperty(this, "name", { value: "ImATeapotException" });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/exception/http-exceptions/too-many-requests.exception.ts
|
|
171
|
+
var TooManyRequestsException = class extends RequestException {
|
|
172
|
+
constructor(message = "Too Many Requests", retry = true) {
|
|
173
|
+
super(429, message, retry);
|
|
174
|
+
Object.defineProperty(this, "name", { value: "TooManyRequestsException" });
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/exception/http-exceptions/internal-server-error.exception.ts
|
|
179
|
+
var InternalServerErrorException = class extends RequestException {
|
|
180
|
+
constructor(message = "Internal Server Error", retry = true) {
|
|
181
|
+
super(500, message, retry);
|
|
182
|
+
Object.defineProperty(this, "name", {
|
|
183
|
+
value: "InternalServerErrorException"
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/exception/http-exceptions/not-implemented.exception.ts
|
|
189
|
+
var NotImplementedException = class extends RequestException {
|
|
190
|
+
constructor(message = "Not Implemented", retry = false) {
|
|
191
|
+
super(501, message, retry);
|
|
192
|
+
Object.defineProperty(this, "name", { value: "NotImplementedException" });
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// src/exception/http-exceptions/bad-gateway.exception.ts
|
|
197
|
+
var BadGatewayException = class extends RequestException {
|
|
198
|
+
constructor(message = "Bad Gateway", retry = true) {
|
|
199
|
+
super(502, message, retry);
|
|
200
|
+
Object.defineProperty(this, "name", { value: "BadGatewayException" });
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/exception/http-exceptions/service-unavailable.exception.ts
|
|
205
|
+
var ServiceUnavailableException = class extends RequestException {
|
|
206
|
+
constructor(message = "Service Unavailable", retry = true) {
|
|
207
|
+
super(503, message, retry);
|
|
208
|
+
Object.defineProperty(this, "name", {
|
|
209
|
+
value: "ServiceUnavailableException"
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/exception/http-exceptions/gateway-timeout.exception.ts
|
|
215
|
+
var GatewayTimeoutException = class extends RequestException {
|
|
216
|
+
constructor(message = "Gateway Timeout", retry = true) {
|
|
217
|
+
super(504, message, retry);
|
|
218
|
+
Object.defineProperty(this, "name", { value: "GatewayTimeoutException" });
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/utils/base64.ts
|
|
223
|
+
var base64Encode = globalThis.btoa || ((str) => Buffer.from(str).toString("base64"));
|
|
224
|
+
var base64Decode = globalThis.atob || ((str) => Buffer.from(str, "base64").toString("utf8"));
|
|
101
225
|
|
|
102
226
|
// src/validator/validator.ts
|
|
103
227
|
var Validator = class _Validator {
|
|
@@ -212,14 +336,10 @@ function shallowClone(obj) {
|
|
|
212
336
|
return obj;
|
|
213
337
|
}
|
|
214
338
|
|
|
215
|
-
// src/
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
super(message);
|
|
220
|
-
Object.defineProperty(this, "name", { value: "KeqError" });
|
|
221
|
-
}
|
|
222
|
-
};
|
|
339
|
+
// src/utils/sleep.ts
|
|
340
|
+
function sleep(ms) {
|
|
341
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
342
|
+
}
|
|
223
343
|
|
|
224
344
|
// src/request-init/utils/clone-body.ts
|
|
225
345
|
function cloneBody(obj) {
|
|
@@ -335,8 +455,8 @@ function cloneRequestInit(init) {
|
|
|
335
455
|
|
|
336
456
|
// src/request-init/request-init.ts
|
|
337
457
|
var AbortControllerProperty = /* @__PURE__ */ Symbol("context.request.abortController");
|
|
338
|
-
var
|
|
339
|
-
|
|
458
|
+
var _a;
|
|
459
|
+
_a = AbortControllerProperty;
|
|
340
460
|
var KeqRequestInit = class {
|
|
341
461
|
constructor(options) {
|
|
342
462
|
__publicField(this, "url");
|
|
@@ -352,7 +472,7 @@ var KeqRequestInit = class {
|
|
|
352
472
|
__publicField(this, "redirect");
|
|
353
473
|
__publicField(this, "referrer");
|
|
354
474
|
__publicField(this, "referrerPolicy");
|
|
355
|
-
__publicField(this,
|
|
475
|
+
__publicField(this, _a, new AbortController());
|
|
356
476
|
this.url = new URL(options.url.href);
|
|
357
477
|
this.pathParameters = shallowClone(options.pathParameters);
|
|
358
478
|
this.method = options.method;
|
|
@@ -411,32 +531,129 @@ var KeqRequestInit = class {
|
|
|
411
531
|
}
|
|
412
532
|
throw new Exception("Cannot auto serialize request.body with Content-Type: ".concat(contentType));
|
|
413
533
|
}
|
|
414
|
-
toFetchArguments() {
|
|
415
|
-
const contentType = this.getContentType();
|
|
416
|
-
const headers = cloneHeaders(this.headers);
|
|
417
|
-
if (contentType) headers.set("Content-Type", contentType);
|
|
418
|
-
const body = this.toFetchBody(contentType);
|
|
419
|
-
if (contentType === "multipart/form-data") {
|
|
420
|
-
headers.delete("Content-Type");
|
|
421
|
-
}
|
|
422
|
-
const requestInit = {
|
|
423
|
-
method: this.method.toUpperCase(),
|
|
424
|
-
headers,
|
|
425
|
-
body,
|
|
426
|
-
cache: this.cache,
|
|
427
|
-
credentials: this.credentials,
|
|
428
|
-
integrity: this.integrity,
|
|
429
|
-
keepalive: this.keepalive,
|
|
430
|
-
mode: this.mode,
|
|
431
|
-
redirect: this.redirect,
|
|
432
|
-
referrer: this.referrer,
|
|
433
|
-
referrerPolicy: this.referrerPolicy,
|
|
434
|
-
signal: this.signal
|
|
435
|
-
};
|
|
436
|
-
return [this.__url__.href, requestInit];
|
|
534
|
+
toFetchArguments() {
|
|
535
|
+
const contentType = this.getContentType();
|
|
536
|
+
const headers = cloneHeaders(this.headers);
|
|
537
|
+
if (contentType) headers.set("Content-Type", contentType);
|
|
538
|
+
const body = this.toFetchBody(contentType);
|
|
539
|
+
if (contentType === "multipart/form-data") {
|
|
540
|
+
headers.delete("Content-Type");
|
|
541
|
+
}
|
|
542
|
+
const requestInit = {
|
|
543
|
+
method: this.method.toUpperCase(),
|
|
544
|
+
headers,
|
|
545
|
+
body,
|
|
546
|
+
cache: this.cache,
|
|
547
|
+
credentials: this.credentials,
|
|
548
|
+
integrity: this.integrity,
|
|
549
|
+
keepalive: this.keepalive,
|
|
550
|
+
mode: this.mode,
|
|
551
|
+
redirect: this.redirect,
|
|
552
|
+
referrer: this.referrer,
|
|
553
|
+
referrerPolicy: this.referrerPolicy,
|
|
554
|
+
signal: this.signal
|
|
555
|
+
};
|
|
556
|
+
return [this.__url__.href, requestInit];
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// src/context/orchestrator-context.ts
|
|
561
|
+
var OrchestratorProperty = /* @__PURE__ */ Symbol("protected context.orchestration.orchestrator");
|
|
562
|
+
var ExecutorProperty = /* @__PURE__ */ Symbol("protected context.orchestration.executor");
|
|
563
|
+
var _a2, _b;
|
|
564
|
+
_b = OrchestratorProperty, _a2 = ExecutorProperty;
|
|
565
|
+
var KeqOrchestratorContext = class {
|
|
566
|
+
constructor(orchestrator, executor) {
|
|
567
|
+
__publicField(this, _b);
|
|
568
|
+
__publicField(this, _a2);
|
|
569
|
+
this[OrchestratorProperty] = orchestrator;
|
|
570
|
+
this[ExecutorProperty] = executor;
|
|
571
|
+
}
|
|
572
|
+
get middlewares() {
|
|
573
|
+
return this[OrchestratorProperty].executors.map((exe) => exe.context);
|
|
574
|
+
}
|
|
575
|
+
// NOTE: For Future
|
|
576
|
+
// get executing(): KeqMiddlewareContext {
|
|
577
|
+
// const current = this[OrchestratorProperty].current
|
|
578
|
+
// const executors = this[OrchestratorProperty].executors
|
|
579
|
+
// const executor = executors[current]
|
|
580
|
+
// return executor.context
|
|
581
|
+
// }
|
|
582
|
+
/**
|
|
583
|
+
* The middleware context of the current middleware
|
|
584
|
+
*/
|
|
585
|
+
get middleware() {
|
|
586
|
+
return this[ExecutorProperty].context;
|
|
587
|
+
}
|
|
588
|
+
fork() {
|
|
589
|
+
return this[OrchestratorProperty].fork();
|
|
590
|
+
}
|
|
591
|
+
merge(source) {
|
|
592
|
+
this[OrchestratorProperty].merge(source);
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
// src/context/execution-context.ts
|
|
597
|
+
var ContextOrchestratorProperty = /* @__PURE__ */ Symbol("protected context.orchestrator");
|
|
598
|
+
var ContextOrchestrationProperty = /* @__PURE__ */ Symbol("protected context.orchestration");
|
|
599
|
+
var _a3, _b2;
|
|
600
|
+
_b2 = ContextOrchestratorProperty, _a3 = ContextOrchestrationProperty;
|
|
601
|
+
var KeqExecutionContext = class {
|
|
602
|
+
constructor(orchestrator, executor) {
|
|
603
|
+
__publicField(this, _b2);
|
|
604
|
+
__publicField(this, _a3);
|
|
605
|
+
this[ContextOrchestratorProperty] = orchestrator;
|
|
606
|
+
this[ContextOrchestrationProperty] = new KeqOrchestratorContext(orchestrator, executor);
|
|
607
|
+
}
|
|
608
|
+
get orchestration() {
|
|
609
|
+
return this[ContextOrchestrationProperty];
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* The unique identifier of the request's location in the code
|
|
613
|
+
*/
|
|
614
|
+
get locationId() {
|
|
615
|
+
return this[ContextOrchestratorProperty].context.locationId;
|
|
616
|
+
}
|
|
617
|
+
get request() {
|
|
618
|
+
return this[ContextOrchestratorProperty].context.request;
|
|
619
|
+
}
|
|
620
|
+
get global() {
|
|
621
|
+
return this[ContextOrchestratorProperty].context.global;
|
|
622
|
+
}
|
|
623
|
+
get emitter() {
|
|
624
|
+
return this[ContextOrchestratorProperty].context.emitter;
|
|
625
|
+
}
|
|
626
|
+
get options() {
|
|
627
|
+
return this[ContextOrchestratorProperty].context.options;
|
|
628
|
+
}
|
|
629
|
+
// The result get by user if resolveWith is set to 'intelligent' or not set
|
|
630
|
+
set output(value) {
|
|
631
|
+
if (this.options.resolveWith && this.options.resolveWith !== "intelligent") {
|
|
632
|
+
console.warn("The request is configured to resolve with ".concat(this.options.resolveWith, ", so setting context.output maybe no effect."));
|
|
633
|
+
}
|
|
634
|
+
this[ContextOrchestratorProperty].context.output = value;
|
|
635
|
+
}
|
|
636
|
+
// The original response
|
|
637
|
+
get res() {
|
|
638
|
+
return this[ContextOrchestratorProperty].context.res;
|
|
639
|
+
}
|
|
640
|
+
// The original response
|
|
641
|
+
set res(value) {
|
|
642
|
+
this[ContextOrchestratorProperty].context.res = value;
|
|
643
|
+
}
|
|
644
|
+
// The request response
|
|
645
|
+
get response() {
|
|
646
|
+
return this[ContextOrchestratorProperty].context.response;
|
|
647
|
+
}
|
|
648
|
+
// The properties extends by middleware
|
|
649
|
+
get data() {
|
|
650
|
+
return this[ContextOrchestratorProperty].context.data;
|
|
437
651
|
}
|
|
438
652
|
};
|
|
439
653
|
|
|
654
|
+
// src/context/shared-context.ts
|
|
655
|
+
import mitt from "mitt";
|
|
656
|
+
|
|
440
657
|
// src/context/utils/watch-object.ts
|
|
441
658
|
function watchObject(obj, listeners) {
|
|
442
659
|
return new Proxy(obj, {
|
|
@@ -657,223 +874,6 @@ var KeqSharedContext = class {
|
|
|
657
874
|
}
|
|
658
875
|
};
|
|
659
876
|
|
|
660
|
-
// src/exception/type.exception.ts
|
|
661
|
-
var TypeException = class extends Exception {
|
|
662
|
-
constructor(msg) {
|
|
663
|
-
super(msg || "Invalid Type");
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
// src/exception/abort.exception.ts
|
|
668
|
-
var AbortException = class _AbortException extends DOMException {
|
|
669
|
-
constructor(msg) {
|
|
670
|
-
super(msg, "AbortError");
|
|
671
|
-
Object.setPrototypeOf(this, _AbortException.prototype);
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
// src/exception/timeout.exception.ts
|
|
676
|
-
var TimeoutException = class extends AbortException {
|
|
677
|
-
constructor(msg) {
|
|
678
|
-
super(msg);
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
// src/exception/http-exceptions/request.exception.ts
|
|
683
|
-
var RequestException = class extends Exception {
|
|
684
|
-
constructor(statusCode, message, retry = true) {
|
|
685
|
-
super(message);
|
|
686
|
-
__publicField(this, "statusCode");
|
|
687
|
-
__publicField(this, "retry");
|
|
688
|
-
this.statusCode = statusCode;
|
|
689
|
-
this.retry = retry;
|
|
690
|
-
Object.defineProperty(this, "name", { value: "RequestException" });
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
// src/exception/http-exceptions/bad-request.exception.ts
|
|
695
|
-
var BadRequestException = class extends RequestException {
|
|
696
|
-
constructor(message = "Bad Request", retry = false) {
|
|
697
|
-
super(400, message, retry);
|
|
698
|
-
Object.defineProperty(this, "name", { value: "BadRequestException" });
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
// src/exception/http-exceptions/unauthorized.exception.ts
|
|
703
|
-
var UnauthorizedException = class extends RequestException {
|
|
704
|
-
constructor(message = "Unauthorized", retry = false) {
|
|
705
|
-
super(401, message, retry);
|
|
706
|
-
Object.defineProperty(this, "name", { value: "UnauthorizedException" });
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
// src/exception/http-exceptions/forbidden.exception.ts
|
|
711
|
-
var ForbiddenException = class extends RequestException {
|
|
712
|
-
constructor(message = "Forbidden", retry = false) {
|
|
713
|
-
super(403, message, retry);
|
|
714
|
-
Object.defineProperty(this, "name", { value: "ForbiddenException" });
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
// src/exception/http-exceptions/not-founded.exception.ts
|
|
719
|
-
var NotFoundedException = class extends RequestException {
|
|
720
|
-
constructor(message = "Not Founded", retry = false) {
|
|
721
|
-
super(404, message, retry);
|
|
722
|
-
Object.defineProperty(this, "name", { value: "NotFoundedException" });
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
|
|
726
|
-
// src/exception/http-exceptions/method-not-allowed.exception.ts
|
|
727
|
-
var MethodNotAllowedException = class extends RequestException {
|
|
728
|
-
constructor(message = "Method Not Allowed", retry = false) {
|
|
729
|
-
super(405, message, retry);
|
|
730
|
-
Object.defineProperty(this, "name", {
|
|
731
|
-
value: "MethodNotAllowedException"
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
// src/exception/http-exceptions/not-acceptable.exception.ts
|
|
737
|
-
var NotAcceptableException = class extends RequestException {
|
|
738
|
-
constructor(message = "Not Acceptable", retry = false) {
|
|
739
|
-
super(406, message, retry);
|
|
740
|
-
Object.defineProperty(this, "name", { value: "NotAcceptableException" });
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
|
|
744
|
-
// src/exception/http-exceptions/proxy-authentication-required.exception.ts
|
|
745
|
-
var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
746
|
-
constructor(message = "Proxy Authentication Required", retry = false) {
|
|
747
|
-
super(407, message, retry);
|
|
748
|
-
Object.defineProperty(this, "name", {
|
|
749
|
-
value: "ProxyAuthenticationRequiredException"
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
// src/exception/http-exceptions/request-timeout.exception.ts
|
|
755
|
-
var RequestTimeoutException = class extends RequestException {
|
|
756
|
-
constructor(message = "Request Timeout", retry = true) {
|
|
757
|
-
super(408, message, retry);
|
|
758
|
-
Object.defineProperty(this, "name", {
|
|
759
|
-
value: "RequestTimeoutException"
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
|
|
764
|
-
// src/exception/http-exceptions/conflict.exception.ts
|
|
765
|
-
var ConflictException = class extends RequestException {
|
|
766
|
-
constructor(message = "Conflict", retry = false) {
|
|
767
|
-
super(409, message, retry);
|
|
768
|
-
Object.defineProperty(this, "name", { value: "ConflictException" });
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
// src/exception/http-exceptions/precondition-failed.exception.ts
|
|
773
|
-
var PreconditionFailedException = class extends RequestException {
|
|
774
|
-
constructor(message = "Precondition Failed", retry = false) {
|
|
775
|
-
super(412, message, retry);
|
|
776
|
-
Object.defineProperty(this, "name", {
|
|
777
|
-
value: "PreconditionFailedException"
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
// src/exception/http-exceptions/content-too-large.exception.ts
|
|
783
|
-
var ContentTooLargeException = class extends RequestException {
|
|
784
|
-
constructor(message = "Content Too Large", retry = false) {
|
|
785
|
-
super(413, message, retry);
|
|
786
|
-
Object.defineProperty(this, "name", {
|
|
787
|
-
value: "ContentTooLargeException"
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
};
|
|
791
|
-
|
|
792
|
-
// src/exception/http-exceptions/uri-too-long.exception.ts
|
|
793
|
-
var UriTooLongException = class extends RequestException {
|
|
794
|
-
constructor(message = "URI Too Long", retry = false) {
|
|
795
|
-
super(414, message, retry);
|
|
796
|
-
Object.defineProperty(this, "name", { value: "UriTooLongException" });
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
// src/exception/http-exceptions/unsupported-media-type.exception.ts
|
|
801
|
-
var UnsupportedMediaTypeException = class extends RequestException {
|
|
802
|
-
constructor(message = "Unsupported Media Type", retry = false) {
|
|
803
|
-
super(415, message, retry);
|
|
804
|
-
Object.defineProperty(this, "name", { value: "UnsupportedMediaTypeException" });
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
// src/exception/http-exceptions/im-a-teapot.exception.ts
|
|
809
|
-
var ImATeapotException = class extends RequestException {
|
|
810
|
-
constructor(message = "I'm a teapot", retry = false) {
|
|
811
|
-
super(418, message, retry);
|
|
812
|
-
Object.defineProperty(this, "name", { value: "ImATeapotException" });
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
|
|
816
|
-
// src/exception/http-exceptions/too-many-requests.exception.ts
|
|
817
|
-
var TooManyRequestsException = class extends RequestException {
|
|
818
|
-
constructor(message = "Too Many Requests", retry = true) {
|
|
819
|
-
super(429, message, retry);
|
|
820
|
-
Object.defineProperty(this, "name", { value: "TooManyRequestsException" });
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
|
|
824
|
-
// src/exception/http-exceptions/internal-server-error.exception.ts
|
|
825
|
-
var InternalServerErrorException = class extends RequestException {
|
|
826
|
-
constructor(message = "Internal Server Error", retry = true) {
|
|
827
|
-
super(500, message, retry);
|
|
828
|
-
Object.defineProperty(this, "name", {
|
|
829
|
-
value: "InternalServerErrorException"
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// src/exception/http-exceptions/not-implemented.exception.ts
|
|
835
|
-
var NotImplementedException = class extends RequestException {
|
|
836
|
-
constructor(message = "Not Implemented", retry = false) {
|
|
837
|
-
super(501, message, retry);
|
|
838
|
-
Object.defineProperty(this, "name", { value: "NotImplementedException" });
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
// src/exception/http-exceptions/bad-gateway.exception.ts
|
|
843
|
-
var BadGatewayException = class extends RequestException {
|
|
844
|
-
constructor(message = "Bad Gateway", retry = true) {
|
|
845
|
-
super(502, message, retry);
|
|
846
|
-
Object.defineProperty(this, "name", { value: "BadGatewayException" });
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
// src/exception/http-exceptions/service-unavailable.exception.ts
|
|
851
|
-
var ServiceUnavailableException = class extends RequestException {
|
|
852
|
-
constructor(message = "Service Unavailable", retry = true) {
|
|
853
|
-
super(503, message, retry);
|
|
854
|
-
Object.defineProperty(this, "name", {
|
|
855
|
-
value: "ServiceUnavailableException"
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
// src/exception/http-exceptions/gateway-timeout.exception.ts
|
|
861
|
-
var GatewayTimeoutException = class extends RequestException {
|
|
862
|
-
constructor(message = "Gateway Timeout", retry = true) {
|
|
863
|
-
super(504, message, retry);
|
|
864
|
-
Object.defineProperty(this, "name", { value: "GatewayTimeoutException" });
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
// src/utils/base64.ts
|
|
869
|
-
var base64Encode = globalThis.btoa || ((str) => Buffer.from(str).toString("base64"));
|
|
870
|
-
var base64Decode = globalThis.atob || ((str) => Buffer.from(str, "base64").toString("utf8"));
|
|
871
|
-
|
|
872
|
-
// src/utils/sleep.ts
|
|
873
|
-
function sleep(ms) {
|
|
874
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
875
|
-
}
|
|
876
|
-
|
|
877
877
|
// src/middleware/utils/get-middleware-name.ts
|
|
878
878
|
function getMiddlewareName(middleware) {
|
|
879
879
|
return middleware.__keqMiddlewareName__ || middleware.name || "anonymous";
|
|
@@ -1090,6 +1090,22 @@ function getLocationId(depth = 0) {
|
|
|
1090
1090
|
return stackLine.trim();
|
|
1091
1091
|
}
|
|
1092
1092
|
|
|
1093
|
+
// src/request/utils/resolve-with.ts
|
|
1094
|
+
import { EventSourceParserStream } from "eventsource-parser/stream";
|
|
1095
|
+
async function resolveWith(response, mode) {
|
|
1096
|
+
if (mode === "response") return response.clone();
|
|
1097
|
+
if (mode === "text") return await response.text();
|
|
1098
|
+
if (mode === "json") return unwrap(await response.json());
|
|
1099
|
+
if (mode === "form-data") return await response.formData();
|
|
1100
|
+
if (mode === "blob") return await response.blob();
|
|
1101
|
+
if (mode === "array-buffer") return await response.arrayBuffer();
|
|
1102
|
+
if (mode === "sse") {
|
|
1103
|
+
if (!response.body) return response.body;
|
|
1104
|
+
return response.clone().body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
|
|
1105
|
+
}
|
|
1106
|
+
return void 0;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1093
1109
|
// src/request/utils/intelligent-parse-response.ts
|
|
1094
1110
|
async function intelligentParseResponse(response) {
|
|
1095
1111
|
if (!response) return void 0;
|
|
@@ -1098,15 +1114,18 @@ async function intelligentParseResponse(response) {
|
|
|
1098
1114
|
}
|
|
1099
1115
|
const contentType = response.headers.get("content-type") || "";
|
|
1100
1116
|
try {
|
|
1101
|
-
if (contentType.
|
|
1102
|
-
return
|
|
1117
|
+
if (contentType.match(/^application\/(.+\+)?json/)) {
|
|
1118
|
+
return resolveWith(response, "json");
|
|
1103
1119
|
} else if (contentType.includes("multipart/form-data")) {
|
|
1104
|
-
return
|
|
1120
|
+
return resolveWith(response, "form-data");
|
|
1105
1121
|
} else if (contentType.includes("plain/text")) {
|
|
1106
|
-
return
|
|
1122
|
+
return resolveWith(response, "text");
|
|
1123
|
+
} else if (contentType.includes("text/event-stream")) {
|
|
1124
|
+
return resolveWith(response, "sse");
|
|
1107
1125
|
}
|
|
1108
|
-
} catch (
|
|
1109
|
-
console.warn("Failed to
|
|
1126
|
+
} catch (err) {
|
|
1127
|
+
console.warn("Failed to intelligent parse response body: ".concat(response.url), err);
|
|
1128
|
+
throw err;
|
|
1110
1129
|
}
|
|
1111
1130
|
return void 0;
|
|
1112
1131
|
}
|
|
@@ -1312,33 +1331,26 @@ var Core = class {
|
|
|
1312
1331
|
async end() {
|
|
1313
1332
|
var _a6;
|
|
1314
1333
|
const coreContext = await this.run();
|
|
1315
|
-
|
|
1334
|
+
const resolveWithMode = coreContext.options.resolveWith;
|
|
1335
|
+
if (resolveWithMode === "response") {
|
|
1316
1336
|
return (_a6 = coreContext.response) == null ? void 0 : _a6.clone();
|
|
1317
1337
|
}
|
|
1318
1338
|
const response = coreContext.response;
|
|
1319
|
-
if (
|
|
1339
|
+
if (!resolveWithMode || resolveWithMode === "intelligent") {
|
|
1340
|
+
const output = coreContext.output;
|
|
1341
|
+
if (output !== void 0) {
|
|
1342
|
+
return output;
|
|
1343
|
+
}
|
|
1344
|
+
return await intelligentParseResponse(response);
|
|
1345
|
+
}
|
|
1346
|
+
if (!response) {
|
|
1320
1347
|
throw new Exception([
|
|
1321
|
-
"Unable to process the response with '".concat(
|
|
1348
|
+
"Unable to process the response with '".concat(resolveWithMode, "'. Possible causes:"),
|
|
1322
1349
|
"1. The request was never initiated or sent",
|
|
1323
1350
|
"2. The request failed before a response was received."
|
|
1324
1351
|
].join("\n"));
|
|
1325
1352
|
}
|
|
1326
|
-
|
|
1327
|
-
return await response.text();
|
|
1328
|
-
} else if (coreContext.options.resolveWith === "json") {
|
|
1329
|
-
return unwrap(await response.json());
|
|
1330
|
-
} else if (coreContext.options.resolveWith === "form-data") {
|
|
1331
|
-
return await response.formData();
|
|
1332
|
-
} else if (coreContext.options.resolveWith === "blob") {
|
|
1333
|
-
return await response.blob();
|
|
1334
|
-
} else if (coreContext.options.resolveWith === "array-buffer") {
|
|
1335
|
-
return await response.arrayBuffer();
|
|
1336
|
-
}
|
|
1337
|
-
const output = coreContext.output;
|
|
1338
|
-
if (output !== void 0) {
|
|
1339
|
-
return output;
|
|
1340
|
-
}
|
|
1341
|
-
return await intelligentParseResponse(response);
|
|
1353
|
+
return await resolveWith(response, resolveWithMode);
|
|
1342
1354
|
}
|
|
1343
1355
|
/**
|
|
1344
1356
|
* Attaches callbacks for the resolution and/or rejection of the Promise.
|