keq 5.0.0-alpha.24 → 5.0.0-alpha.26
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 +31 -0
- package/dist/context/utils/fork.d.ts.map +1 -1
- package/dist/exception/http-exceptions/bad-gateway.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/bad-gateway.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/bad-request.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/bad-request.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/conflict.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/conflict.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/content-too-large.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/content-too-large.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/forbidden.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/forbidden.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/gateway-timeout.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/gateway-timeout.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/http-version-not-supported.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/http-version-not-supported.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/im-a-teapot.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/im-a-teapot.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/internal-server-error.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/internal-server-error.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/method-not-allowed.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/method-not-allowed.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/not-acceptable.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/not-acceptable.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/not-founded.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/not-founded.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/not-implemented.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/not-implemented.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/precondition-failed.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/precondition-failed.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/proxy-authentication-required.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/proxy-authentication-required.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/request-timeout.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/request-timeout.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/request.exception.d.ts +7 -2
- package/dist/exception/http-exceptions/request.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/service-unavailable.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/service-unavailable.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/too-many-requests.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/too-many-requests.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/unauthorized.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/unauthorized.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/unsupported-media-type.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/unsupported-media-type.exception.d.ts.map +1 -1
- package/dist/exception/http-exceptions/uri-too-long.exception.d.ts +2 -2
- package/dist/exception/http-exceptions/uri-too-long.exception.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +133 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -85
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/flow-control-middleware/serial-flow-control-middleware.d.ts.map +1 -1
- package/dist/middlewares/flow-control-middleware/types/keq-flow-control.d.ts +2 -1
- package/dist/middlewares/flow-control-middleware/types/keq-flow-control.d.ts.map +1 -1
- package/dist/request/keq.d.ts +4 -2
- package/dist/request/keq.d.ts.map +1 -1
- package/dist/request/request.d.ts +2 -1
- package/dist/request/request.d.ts.map +1 -1
- package/dist/router/index.d.ts +0 -5
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/keq-router.d.ts +25 -7
- package/dist/router/keq-router.d.ts.map +1 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -67,11 +67,6 @@ __export(index_exports, {
|
|
|
67
67
|
composeRoute: () => composeRoute,
|
|
68
68
|
createProxyResponse: () => createProxyResponse,
|
|
69
69
|
createRequest: () => createRequest,
|
|
70
|
-
keqHostRoute: () => keqHostRoute,
|
|
71
|
-
keqLocationRoute: () => keqLocationRoute,
|
|
72
|
-
keqMethodRoute: () => keqMethodRoute,
|
|
73
|
-
keqModuleRoute: () => keqModuleRoute,
|
|
74
|
-
keqPathnameRoute: () => keqPathnameRoute,
|
|
75
70
|
request: () => request
|
|
76
71
|
});
|
|
77
72
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -109,52 +104,54 @@ var TimeoutException = class extends AbortException {
|
|
|
109
104
|
|
|
110
105
|
// src/exception/http-exceptions/request.exception.ts
|
|
111
106
|
var RequestException = class extends Exception {
|
|
112
|
-
constructor(statusCode, message,
|
|
107
|
+
constructor(statusCode, message, options) {
|
|
113
108
|
super(message);
|
|
114
109
|
__publicField(this, "statusCode");
|
|
115
110
|
__publicField(this, "retry");
|
|
111
|
+
__publicField(this, "response");
|
|
116
112
|
this.statusCode = statusCode;
|
|
117
|
-
this.retry =
|
|
113
|
+
this.retry = !(options == null ? void 0 : options.fatal);
|
|
114
|
+
this.response = options == null ? void 0 : options.response;
|
|
118
115
|
Object.defineProperty(this, "name", { value: "RequestException" });
|
|
119
116
|
}
|
|
120
117
|
};
|
|
121
118
|
|
|
122
119
|
// src/exception/http-exceptions/bad-request.exception.ts
|
|
123
120
|
var BadRequestException = class extends RequestException {
|
|
124
|
-
constructor(message = "Bad Request",
|
|
125
|
-
super(400, message,
|
|
121
|
+
constructor(message = "Bad Request", options) {
|
|
122
|
+
super(400, message, { fatal: true, ...options });
|
|
126
123
|
Object.defineProperty(this, "name", { value: "BadRequestException" });
|
|
127
124
|
}
|
|
128
125
|
};
|
|
129
126
|
|
|
130
127
|
// src/exception/http-exceptions/unauthorized.exception.ts
|
|
131
128
|
var UnauthorizedException = class extends RequestException {
|
|
132
|
-
constructor(message = "Unauthorized",
|
|
133
|
-
super(401, message,
|
|
129
|
+
constructor(message = "Unauthorized", options) {
|
|
130
|
+
super(401, message, { fatal: true, ...options });
|
|
134
131
|
Object.defineProperty(this, "name", { value: "UnauthorizedException" });
|
|
135
132
|
}
|
|
136
133
|
};
|
|
137
134
|
|
|
138
135
|
// src/exception/http-exceptions/forbidden.exception.ts
|
|
139
136
|
var ForbiddenException = class extends RequestException {
|
|
140
|
-
constructor(message = "Forbidden",
|
|
141
|
-
super(403, message,
|
|
137
|
+
constructor(message = "Forbidden", options) {
|
|
138
|
+
super(403, message, { fatal: true, ...options });
|
|
142
139
|
Object.defineProperty(this, "name", { value: "ForbiddenException" });
|
|
143
140
|
}
|
|
144
141
|
};
|
|
145
142
|
|
|
146
143
|
// src/exception/http-exceptions/not-founded.exception.ts
|
|
147
144
|
var NotFoundedException = class extends RequestException {
|
|
148
|
-
constructor(message = "Not Founded",
|
|
149
|
-
super(404, message,
|
|
145
|
+
constructor(message = "Not Founded", options) {
|
|
146
|
+
super(404, message, { fatal: true, ...options });
|
|
150
147
|
Object.defineProperty(this, "name", { value: "NotFoundedException" });
|
|
151
148
|
}
|
|
152
149
|
};
|
|
153
150
|
|
|
154
151
|
// src/exception/http-exceptions/method-not-allowed.exception.ts
|
|
155
152
|
var MethodNotAllowedException = class extends RequestException {
|
|
156
|
-
constructor(message = "Method Not Allowed",
|
|
157
|
-
super(405, message,
|
|
153
|
+
constructor(message = "Method Not Allowed", options) {
|
|
154
|
+
super(405, message, { fatal: true, ...options });
|
|
158
155
|
Object.defineProperty(this, "name", {
|
|
159
156
|
value: "MethodNotAllowedException"
|
|
160
157
|
});
|
|
@@ -163,16 +160,16 @@ var MethodNotAllowedException = class extends RequestException {
|
|
|
163
160
|
|
|
164
161
|
// src/exception/http-exceptions/not-acceptable.exception.ts
|
|
165
162
|
var NotAcceptableException = class extends RequestException {
|
|
166
|
-
constructor(message = "Not Acceptable",
|
|
167
|
-
super(406, message,
|
|
163
|
+
constructor(message = "Not Acceptable", options) {
|
|
164
|
+
super(406, message, { fatal: true, ...options });
|
|
168
165
|
Object.defineProperty(this, "name", { value: "NotAcceptableException" });
|
|
169
166
|
}
|
|
170
167
|
};
|
|
171
168
|
|
|
172
169
|
// src/exception/http-exceptions/proxy-authentication-required.exception.ts
|
|
173
170
|
var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
174
|
-
constructor(message = "Proxy Authentication Required",
|
|
175
|
-
super(407, message,
|
|
171
|
+
constructor(message = "Proxy Authentication Required", options) {
|
|
172
|
+
super(407, message, { fatal: true, ...options });
|
|
176
173
|
Object.defineProperty(this, "name", {
|
|
177
174
|
value: "ProxyAuthenticationRequiredException"
|
|
178
175
|
});
|
|
@@ -181,8 +178,8 @@ var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
|
181
178
|
|
|
182
179
|
// src/exception/http-exceptions/request-timeout.exception.ts
|
|
183
180
|
var RequestTimeoutException = class extends RequestException {
|
|
184
|
-
constructor(message = "Request Timeout",
|
|
185
|
-
super(408, message,
|
|
181
|
+
constructor(message = "Request Timeout", options) {
|
|
182
|
+
super(408, message, { fatal: false, ...options });
|
|
186
183
|
Object.defineProperty(this, "name", {
|
|
187
184
|
value: "RequestTimeoutException"
|
|
188
185
|
});
|
|
@@ -191,16 +188,16 @@ var RequestTimeoutException = class extends RequestException {
|
|
|
191
188
|
|
|
192
189
|
// src/exception/http-exceptions/conflict.exception.ts
|
|
193
190
|
var ConflictException = class extends RequestException {
|
|
194
|
-
constructor(message = "Conflict",
|
|
195
|
-
super(409, message,
|
|
191
|
+
constructor(message = "Conflict", options) {
|
|
192
|
+
super(409, message, { fatal: true, ...options });
|
|
196
193
|
Object.defineProperty(this, "name", { value: "ConflictException" });
|
|
197
194
|
}
|
|
198
195
|
};
|
|
199
196
|
|
|
200
197
|
// src/exception/http-exceptions/precondition-failed.exception.ts
|
|
201
198
|
var PreconditionFailedException = class extends RequestException {
|
|
202
|
-
constructor(message = "Precondition Failed",
|
|
203
|
-
super(412, message,
|
|
199
|
+
constructor(message = "Precondition Failed", options) {
|
|
200
|
+
super(412, message, { fatal: true, ...options });
|
|
204
201
|
Object.defineProperty(this, "name", {
|
|
205
202
|
value: "PreconditionFailedException"
|
|
206
203
|
});
|
|
@@ -209,8 +206,8 @@ var PreconditionFailedException = class extends RequestException {
|
|
|
209
206
|
|
|
210
207
|
// src/exception/http-exceptions/content-too-large.exception.ts
|
|
211
208
|
var ContentTooLargeException = class extends RequestException {
|
|
212
|
-
constructor(message = "Content Too Large",
|
|
213
|
-
super(413, message,
|
|
209
|
+
constructor(message = "Content Too Large", options) {
|
|
210
|
+
super(413, message, { fatal: true, ...options });
|
|
214
211
|
Object.defineProperty(this, "name", {
|
|
215
212
|
value: "ContentTooLargeException"
|
|
216
213
|
});
|
|
@@ -219,40 +216,40 @@ var ContentTooLargeException = class extends RequestException {
|
|
|
219
216
|
|
|
220
217
|
// src/exception/http-exceptions/uri-too-long.exception.ts
|
|
221
218
|
var UriTooLongException = class extends RequestException {
|
|
222
|
-
constructor(message = "URI Too Long",
|
|
223
|
-
super(414, message,
|
|
219
|
+
constructor(message = "URI Too Long", options) {
|
|
220
|
+
super(414, message, { fatal: true, ...options });
|
|
224
221
|
Object.defineProperty(this, "name", { value: "UriTooLongException" });
|
|
225
222
|
}
|
|
226
223
|
};
|
|
227
224
|
|
|
228
225
|
// src/exception/http-exceptions/unsupported-media-type.exception.ts
|
|
229
226
|
var UnsupportedMediaTypeException = class extends RequestException {
|
|
230
|
-
constructor(message = "Unsupported Media Type",
|
|
231
|
-
super(415, message,
|
|
227
|
+
constructor(message = "Unsupported Media Type", options) {
|
|
228
|
+
super(415, message, { fatal: true, ...options });
|
|
232
229
|
Object.defineProperty(this, "name", { value: "UnsupportedMediaTypeException" });
|
|
233
230
|
}
|
|
234
231
|
};
|
|
235
232
|
|
|
236
233
|
// src/exception/http-exceptions/im-a-teapot.exception.ts
|
|
237
234
|
var ImATeapotException = class extends RequestException {
|
|
238
|
-
constructor(message = "I'm a teapot",
|
|
239
|
-
super(418, message,
|
|
235
|
+
constructor(message = "I'm a teapot", options) {
|
|
236
|
+
super(418, message, { fatal: true, ...options });
|
|
240
237
|
Object.defineProperty(this, "name", { value: "ImATeapotException" });
|
|
241
238
|
}
|
|
242
239
|
};
|
|
243
240
|
|
|
244
241
|
// src/exception/http-exceptions/too-many-requests.exception.ts
|
|
245
242
|
var TooManyRequestsException = class extends RequestException {
|
|
246
|
-
constructor(message = "Too Many Requests",
|
|
247
|
-
super(429, message,
|
|
243
|
+
constructor(message = "Too Many Requests", options) {
|
|
244
|
+
super(429, message, { fatal: false, ...options });
|
|
248
245
|
Object.defineProperty(this, "name", { value: "TooManyRequestsException" });
|
|
249
246
|
}
|
|
250
247
|
};
|
|
251
248
|
|
|
252
249
|
// src/exception/http-exceptions/internal-server-error.exception.ts
|
|
253
250
|
var InternalServerErrorException = class extends RequestException {
|
|
254
|
-
constructor(message = "Internal Server Error",
|
|
255
|
-
super(500, message,
|
|
251
|
+
constructor(message = "Internal Server Error", options) {
|
|
252
|
+
super(500, message, { fatal: false, ...options });
|
|
256
253
|
Object.defineProperty(this, "name", {
|
|
257
254
|
value: "InternalServerErrorException"
|
|
258
255
|
});
|
|
@@ -261,24 +258,24 @@ var InternalServerErrorException = class extends RequestException {
|
|
|
261
258
|
|
|
262
259
|
// src/exception/http-exceptions/not-implemented.exception.ts
|
|
263
260
|
var NotImplementedException = class extends RequestException {
|
|
264
|
-
constructor(message = "Not Implemented",
|
|
265
|
-
super(501, message,
|
|
261
|
+
constructor(message = "Not Implemented", options) {
|
|
262
|
+
super(501, message, { fatal: true, ...options });
|
|
266
263
|
Object.defineProperty(this, "name", { value: "NotImplementedException" });
|
|
267
264
|
}
|
|
268
265
|
};
|
|
269
266
|
|
|
270
267
|
// src/exception/http-exceptions/bad-gateway.exception.ts
|
|
271
268
|
var BadGatewayException = class extends RequestException {
|
|
272
|
-
constructor(message = "Bad Gateway",
|
|
273
|
-
super(502, message,
|
|
269
|
+
constructor(message = "Bad Gateway", options) {
|
|
270
|
+
super(502, message, { fatal: false, ...options });
|
|
274
271
|
Object.defineProperty(this, "name", { value: "BadGatewayException" });
|
|
275
272
|
}
|
|
276
273
|
};
|
|
277
274
|
|
|
278
275
|
// src/exception/http-exceptions/service-unavailable.exception.ts
|
|
279
276
|
var ServiceUnavailableException = class extends RequestException {
|
|
280
|
-
constructor(message = "Service Unavailable",
|
|
281
|
-
super(503, message,
|
|
277
|
+
constructor(message = "Service Unavailable", options) {
|
|
278
|
+
super(503, message, { fatal: false, ...options });
|
|
282
279
|
Object.defineProperty(this, "name", {
|
|
283
280
|
value: "ServiceUnavailableException"
|
|
284
281
|
});
|
|
@@ -287,8 +284,8 @@ var ServiceUnavailableException = class extends RequestException {
|
|
|
287
284
|
|
|
288
285
|
// src/exception/http-exceptions/gateway-timeout.exception.ts
|
|
289
286
|
var GatewayTimeoutException = class extends RequestException {
|
|
290
|
-
constructor(message = "Gateway Timeout",
|
|
291
|
-
super(504, message,
|
|
287
|
+
constructor(message = "Gateway Timeout", options) {
|
|
288
|
+
super(504, message, { fatal: false, ...options });
|
|
292
289
|
Object.defineProperty(this, "name", { value: "GatewayTimeoutException" });
|
|
293
290
|
}
|
|
294
291
|
};
|
|
@@ -793,15 +790,16 @@ function fork(original) {
|
|
|
793
790
|
return current;
|
|
794
791
|
};
|
|
795
792
|
const createProxy = (path = []) => {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
793
|
+
const getTarget = () => objectPath(current, path);
|
|
794
|
+
return new Proxy(getTarget(), {
|
|
795
|
+
get(target, prop) {
|
|
796
|
+
const realTarget = getTarget();
|
|
797
|
+
if (prop === UnWrapPropertyKey) return realTarget;
|
|
798
|
+
const value = realTarget[prop];
|
|
801
799
|
if (current !== original) {
|
|
802
800
|
return value;
|
|
803
801
|
}
|
|
804
|
-
if (Array.isArray(
|
|
802
|
+
if (Array.isArray(realTarget) && ARRAY_MUTATORS.has(prop)) {
|
|
805
803
|
return new Proxy(value, {
|
|
806
804
|
apply(fn, thisArg, args) {
|
|
807
805
|
ensureCopy();
|
|
@@ -815,15 +813,23 @@ function fork(original) {
|
|
|
815
813
|
}
|
|
816
814
|
return value;
|
|
817
815
|
},
|
|
818
|
-
set(
|
|
816
|
+
set(target, prop, value) {
|
|
819
817
|
ensureCopy();
|
|
820
818
|
objectPath(current, path)[prop] = value;
|
|
821
819
|
return true;
|
|
822
820
|
},
|
|
823
|
-
deleteProperty(
|
|
821
|
+
deleteProperty(target, prop) {
|
|
824
822
|
ensureCopy();
|
|
825
823
|
delete objectPath(current, path)[prop];
|
|
826
824
|
return true;
|
|
825
|
+
},
|
|
826
|
+
ownKeys(target) {
|
|
827
|
+
const realTarget = getTarget();
|
|
828
|
+
return Reflect.ownKeys(realTarget);
|
|
829
|
+
},
|
|
830
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
831
|
+
const realTarget = getTarget();
|
|
832
|
+
return Reflect.getOwnPropertyDescriptor(realTarget, prop);
|
|
827
833
|
}
|
|
828
834
|
});
|
|
829
835
|
};
|
|
@@ -1602,13 +1608,15 @@ var Keq = class extends Core {
|
|
|
1602
1608
|
this.requestInit.mode = mod;
|
|
1603
1609
|
return this;
|
|
1604
1610
|
}
|
|
1605
|
-
flowControl(mode,
|
|
1606
|
-
const
|
|
1611
|
+
flowControl(mode, arg2, arg3) {
|
|
1612
|
+
const concurrencyLimit = typeof arg2 === "number" ? arg2 : void 0;
|
|
1613
|
+
const sig = typeof arg2 === "function" || typeof arg2 === "string" ? arg2 : arg3 && (typeof arg3 === "function" || typeof arg3 === "string") ? arg3 : this.__locationId__;
|
|
1607
1614
|
if (!sig) {
|
|
1608
1615
|
throw new Exception("please set signal to .flowControl()");
|
|
1609
1616
|
}
|
|
1610
1617
|
const flowControl = {
|
|
1611
1618
|
mode,
|
|
1619
|
+
concurrencyLimit,
|
|
1612
1620
|
signal: sig
|
|
1613
1621
|
};
|
|
1614
1622
|
this.option("flowControl", flowControl);
|
|
@@ -1670,11 +1678,11 @@ function keqPathnameRoute(pathname) {
|
|
|
1670
1678
|
}
|
|
1671
1679
|
|
|
1672
1680
|
// src/router/keq-router.ts
|
|
1673
|
-
var KeqRouter = class {
|
|
1681
|
+
var KeqRouter = class _KeqRouter {
|
|
1674
1682
|
constructor(middlewares = []) {
|
|
1675
1683
|
this.middlewares = middlewares;
|
|
1676
1684
|
}
|
|
1677
|
-
buildMiddleware(route, middlewares) {
|
|
1685
|
+
static buildMiddleware(route, middlewares) {
|
|
1678
1686
|
if (middlewares.length === 0) {
|
|
1679
1687
|
throw new TypeException("At least one middleware is required to build a route middleware");
|
|
1680
1688
|
}
|
|
@@ -1685,42 +1693,72 @@ var KeqRouter = class {
|
|
|
1685
1693
|
};
|
|
1686
1694
|
return middleware;
|
|
1687
1695
|
}
|
|
1688
|
-
route(route, ...
|
|
1689
|
-
const
|
|
1690
|
-
|
|
1691
|
-
this.middlewares.push(middleware);
|
|
1696
|
+
route(route, middleware, ...additionalMiddlewares) {
|
|
1697
|
+
const mid = _KeqRouter.route(route, middleware, ...additionalMiddlewares);
|
|
1698
|
+
this.middlewares.push(mid);
|
|
1692
1699
|
return this;
|
|
1693
1700
|
}
|
|
1694
|
-
host(host, ...
|
|
1695
|
-
const
|
|
1696
|
-
|
|
1697
|
-
this.middlewares.push(middleware);
|
|
1701
|
+
host(host, middleware, ...additionalMiddlewares) {
|
|
1702
|
+
const mid = _KeqRouter.host(host, middleware, ...additionalMiddlewares);
|
|
1703
|
+
this.middlewares.push(mid);
|
|
1698
1704
|
return this;
|
|
1699
1705
|
}
|
|
1700
|
-
method(method, ...
|
|
1701
|
-
const
|
|
1702
|
-
|
|
1703
|
-
this.middlewares.push(middleware);
|
|
1706
|
+
method(method, middleware, ...additionalMiddlewares) {
|
|
1707
|
+
const mid = _KeqRouter.method(method, middleware, ...additionalMiddlewares);
|
|
1708
|
+
this.middlewares.push(mid);
|
|
1704
1709
|
return this;
|
|
1705
1710
|
}
|
|
1706
|
-
pathname(pathname, ...
|
|
1707
|
-
const
|
|
1708
|
-
|
|
1709
|
-
this.middlewares.push(middleware);
|
|
1711
|
+
pathname(pathname, middleware, ...additionalMiddlewares) {
|
|
1712
|
+
const mid = _KeqRouter.pathname(pathname, middleware, ...additionalMiddlewares);
|
|
1713
|
+
this.middlewares.push(mid);
|
|
1710
1714
|
return this;
|
|
1711
1715
|
}
|
|
1712
|
-
location(...
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1715
|
-
this.middlewares.push(middleware);
|
|
1716
|
+
location(middleware, ...additionalMiddlewares) {
|
|
1717
|
+
const mid = _KeqRouter.location(middleware, ...additionalMiddlewares);
|
|
1718
|
+
this.middlewares.push(mid);
|
|
1716
1719
|
return this;
|
|
1717
1720
|
}
|
|
1718
|
-
module(moduleName, ...
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1721
|
-
this.middlewares.push(middleware);
|
|
1721
|
+
module(moduleName, middleware, ...additionalMiddlewares) {
|
|
1722
|
+
const mid = _KeqRouter.module(moduleName, middleware, ...additionalMiddlewares);
|
|
1723
|
+
this.middlewares.push(mid);
|
|
1722
1724
|
return this;
|
|
1723
1725
|
}
|
|
1726
|
+
static route(route, middleware, ...additionalMiddlewares) {
|
|
1727
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1728
|
+
const mid = _KeqRouter.buildMiddleware(route, list);
|
|
1729
|
+
mid.__keqMiddlewareName__ = "route(".concat(route.__keqRouteName__ || route.name, ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1730
|
+
return mid;
|
|
1731
|
+
}
|
|
1732
|
+
static host(host, middleware, ...additionalMiddlewares) {
|
|
1733
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1734
|
+
const mid = _KeqRouter.buildMiddleware(keqHostRoute(host), list);
|
|
1735
|
+
mid.__keqMiddlewareName__ = "host(".concat(JSON.stringify(host), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1736
|
+
return mid;
|
|
1737
|
+
}
|
|
1738
|
+
static method(method, middleware, ...additionalMiddlewares) {
|
|
1739
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1740
|
+
const mid = _KeqRouter.buildMiddleware(keqMethodRoute(method), list);
|
|
1741
|
+
mid.__keqMiddlewareName__ = "method(".concat(JSON.stringify(method), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1742
|
+
return mid;
|
|
1743
|
+
}
|
|
1744
|
+
static pathname(pathname, middleware, ...additionalMiddlewares) {
|
|
1745
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1746
|
+
const mid = _KeqRouter.buildMiddleware(keqPathnameRoute(pathname), list);
|
|
1747
|
+
mid.__keqMiddlewareName__ = "pathname(".concat(JSON.stringify(pathname), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1748
|
+
return mid;
|
|
1749
|
+
}
|
|
1750
|
+
static location(middleware, ...additionalMiddlewares) {
|
|
1751
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1752
|
+
const mid = _KeqRouter.buildMiddleware(keqLocationRoute(), list);
|
|
1753
|
+
mid.__keqMiddlewareName__ = "location(".concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1754
|
+
return mid;
|
|
1755
|
+
}
|
|
1756
|
+
static module(moduleName, middleware, ...additionalMiddlewares) {
|
|
1757
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1758
|
+
const mid = _KeqRouter.buildMiddleware(keqModuleRoute(moduleName), list);
|
|
1759
|
+
mid.__keqMiddlewareName__ = "module(".concat(JSON.stringify(moduleName), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1760
|
+
return mid;
|
|
1761
|
+
}
|
|
1724
1762
|
};
|
|
1725
1763
|
|
|
1726
1764
|
// src/middlewares/timeout-middleware/index.ts
|
|
@@ -1749,17 +1787,18 @@ function keqTimeoutMiddleware() {
|
|
|
1749
1787
|
var fastq = __toESM(require("fastq"));
|
|
1750
1788
|
function keqSerialFlowControlMiddleware() {
|
|
1751
1789
|
return async function serialFlowControlMiddleware(ctx, next) {
|
|
1752
|
-
if (!ctx.options.flowControl || ctx.options.flowControl.mode
|
|
1790
|
+
if (!ctx.options.flowControl || !["serial", "concurrent"].includes(ctx.options.flowControl.mode)) {
|
|
1753
1791
|
await next();
|
|
1754
1792
|
return;
|
|
1755
1793
|
}
|
|
1756
1794
|
const { signal } = ctx.options.flowControl;
|
|
1795
|
+
const concurrent = ctx.options.flowControl.mode === "serial" ? 1 : !ctx.options.flowControl.concurrencyLimit ? 1 : ctx.options.flowControl.concurrencyLimit < 1 ? 1 : parseInt(ctx.options.flowControl.concurrencyLimit, 10);
|
|
1757
1796
|
const key = typeof signal === "string" ? signal : signal(ctx);
|
|
1758
1797
|
if (!ctx.global.serialFlowControl) ctx.global.serialFlowControl = {};
|
|
1759
1798
|
if (!ctx.global.serialFlowControl[key]) {
|
|
1760
1799
|
ctx.global.serialFlowControl[key] = fastq.promise(async (next2) => {
|
|
1761
1800
|
await next2();
|
|
1762
|
-
},
|
|
1801
|
+
}, concurrent);
|
|
1763
1802
|
}
|
|
1764
1803
|
const queue = ctx.global.serialFlowControl[key];
|
|
1765
1804
|
await queue.push(next);
|
|
@@ -1922,6 +1961,15 @@ var KeqRequest = class {
|
|
|
1922
1961
|
useRouter() {
|
|
1923
1962
|
return new KeqRouter(this.preMiddlewares);
|
|
1924
1963
|
}
|
|
1964
|
+
on(event, listener) {
|
|
1965
|
+
const middleware = async (context, next) => {
|
|
1966
|
+
context.emitter.on(event, listener);
|
|
1967
|
+
await next();
|
|
1968
|
+
};
|
|
1969
|
+
middleware.__keqMiddlewareName__ = "listen(".concat(event, ", ").concat(listener.name || "anonymous", ")");
|
|
1970
|
+
this.use(middleware);
|
|
1971
|
+
return this;
|
|
1972
|
+
}
|
|
1925
1973
|
};
|
|
1926
1974
|
var request = new KeqRequest();
|
|
1927
1975
|
|