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.mjs
CHANGED
|
@@ -35,52 +35,54 @@ var TimeoutException = class extends AbortException {
|
|
|
35
35
|
|
|
36
36
|
// src/exception/http-exceptions/request.exception.ts
|
|
37
37
|
var RequestException = class extends Exception {
|
|
38
|
-
constructor(statusCode, message,
|
|
38
|
+
constructor(statusCode, message, options) {
|
|
39
39
|
super(message);
|
|
40
40
|
__publicField(this, "statusCode");
|
|
41
41
|
__publicField(this, "retry");
|
|
42
|
+
__publicField(this, "response");
|
|
42
43
|
this.statusCode = statusCode;
|
|
43
|
-
this.retry =
|
|
44
|
+
this.retry = !(options == null ? void 0 : options.fatal);
|
|
45
|
+
this.response = options == null ? void 0 : options.response;
|
|
44
46
|
Object.defineProperty(this, "name", { value: "RequestException" });
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
// src/exception/http-exceptions/bad-request.exception.ts
|
|
49
51
|
var BadRequestException = class extends RequestException {
|
|
50
|
-
constructor(message = "Bad Request",
|
|
51
|
-
super(400, message,
|
|
52
|
+
constructor(message = "Bad Request", options) {
|
|
53
|
+
super(400, message, { fatal: true, ...options });
|
|
52
54
|
Object.defineProperty(this, "name", { value: "BadRequestException" });
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
// src/exception/http-exceptions/unauthorized.exception.ts
|
|
57
59
|
var UnauthorizedException = class extends RequestException {
|
|
58
|
-
constructor(message = "Unauthorized",
|
|
59
|
-
super(401, message,
|
|
60
|
+
constructor(message = "Unauthorized", options) {
|
|
61
|
+
super(401, message, { fatal: true, ...options });
|
|
60
62
|
Object.defineProperty(this, "name", { value: "UnauthorizedException" });
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
// src/exception/http-exceptions/forbidden.exception.ts
|
|
65
67
|
var ForbiddenException = class extends RequestException {
|
|
66
|
-
constructor(message = "Forbidden",
|
|
67
|
-
super(403, message,
|
|
68
|
+
constructor(message = "Forbidden", options) {
|
|
69
|
+
super(403, message, { fatal: true, ...options });
|
|
68
70
|
Object.defineProperty(this, "name", { value: "ForbiddenException" });
|
|
69
71
|
}
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
// src/exception/http-exceptions/not-founded.exception.ts
|
|
73
75
|
var NotFoundedException = class extends RequestException {
|
|
74
|
-
constructor(message = "Not Founded",
|
|
75
|
-
super(404, message,
|
|
76
|
+
constructor(message = "Not Founded", options) {
|
|
77
|
+
super(404, message, { fatal: true, ...options });
|
|
76
78
|
Object.defineProperty(this, "name", { value: "NotFoundedException" });
|
|
77
79
|
}
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
// src/exception/http-exceptions/method-not-allowed.exception.ts
|
|
81
83
|
var MethodNotAllowedException = class extends RequestException {
|
|
82
|
-
constructor(message = "Method Not Allowed",
|
|
83
|
-
super(405, message,
|
|
84
|
+
constructor(message = "Method Not Allowed", options) {
|
|
85
|
+
super(405, message, { fatal: true, ...options });
|
|
84
86
|
Object.defineProperty(this, "name", {
|
|
85
87
|
value: "MethodNotAllowedException"
|
|
86
88
|
});
|
|
@@ -89,16 +91,16 @@ var MethodNotAllowedException = class extends RequestException {
|
|
|
89
91
|
|
|
90
92
|
// src/exception/http-exceptions/not-acceptable.exception.ts
|
|
91
93
|
var NotAcceptableException = class extends RequestException {
|
|
92
|
-
constructor(message = "Not Acceptable",
|
|
93
|
-
super(406, message,
|
|
94
|
+
constructor(message = "Not Acceptable", options) {
|
|
95
|
+
super(406, message, { fatal: true, ...options });
|
|
94
96
|
Object.defineProperty(this, "name", { value: "NotAcceptableException" });
|
|
95
97
|
}
|
|
96
98
|
};
|
|
97
99
|
|
|
98
100
|
// src/exception/http-exceptions/proxy-authentication-required.exception.ts
|
|
99
101
|
var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
100
|
-
constructor(message = "Proxy Authentication Required",
|
|
101
|
-
super(407, message,
|
|
102
|
+
constructor(message = "Proxy Authentication Required", options) {
|
|
103
|
+
super(407, message, { fatal: true, ...options });
|
|
102
104
|
Object.defineProperty(this, "name", {
|
|
103
105
|
value: "ProxyAuthenticationRequiredException"
|
|
104
106
|
});
|
|
@@ -107,8 +109,8 @@ var ProxyAuthenticationRequiredException = class extends RequestException {
|
|
|
107
109
|
|
|
108
110
|
// src/exception/http-exceptions/request-timeout.exception.ts
|
|
109
111
|
var RequestTimeoutException = class extends RequestException {
|
|
110
|
-
constructor(message = "Request Timeout",
|
|
111
|
-
super(408, message,
|
|
112
|
+
constructor(message = "Request Timeout", options) {
|
|
113
|
+
super(408, message, { fatal: false, ...options });
|
|
112
114
|
Object.defineProperty(this, "name", {
|
|
113
115
|
value: "RequestTimeoutException"
|
|
114
116
|
});
|
|
@@ -117,16 +119,16 @@ var RequestTimeoutException = class extends RequestException {
|
|
|
117
119
|
|
|
118
120
|
// src/exception/http-exceptions/conflict.exception.ts
|
|
119
121
|
var ConflictException = class extends RequestException {
|
|
120
|
-
constructor(message = "Conflict",
|
|
121
|
-
super(409, message,
|
|
122
|
+
constructor(message = "Conflict", options) {
|
|
123
|
+
super(409, message, { fatal: true, ...options });
|
|
122
124
|
Object.defineProperty(this, "name", { value: "ConflictException" });
|
|
123
125
|
}
|
|
124
126
|
};
|
|
125
127
|
|
|
126
128
|
// src/exception/http-exceptions/precondition-failed.exception.ts
|
|
127
129
|
var PreconditionFailedException = class extends RequestException {
|
|
128
|
-
constructor(message = "Precondition Failed",
|
|
129
|
-
super(412, message,
|
|
130
|
+
constructor(message = "Precondition Failed", options) {
|
|
131
|
+
super(412, message, { fatal: true, ...options });
|
|
130
132
|
Object.defineProperty(this, "name", {
|
|
131
133
|
value: "PreconditionFailedException"
|
|
132
134
|
});
|
|
@@ -135,8 +137,8 @@ var PreconditionFailedException = class extends RequestException {
|
|
|
135
137
|
|
|
136
138
|
// src/exception/http-exceptions/content-too-large.exception.ts
|
|
137
139
|
var ContentTooLargeException = class extends RequestException {
|
|
138
|
-
constructor(message = "Content Too Large",
|
|
139
|
-
super(413, message,
|
|
140
|
+
constructor(message = "Content Too Large", options) {
|
|
141
|
+
super(413, message, { fatal: true, ...options });
|
|
140
142
|
Object.defineProperty(this, "name", {
|
|
141
143
|
value: "ContentTooLargeException"
|
|
142
144
|
});
|
|
@@ -145,40 +147,40 @@ var ContentTooLargeException = class extends RequestException {
|
|
|
145
147
|
|
|
146
148
|
// src/exception/http-exceptions/uri-too-long.exception.ts
|
|
147
149
|
var UriTooLongException = class extends RequestException {
|
|
148
|
-
constructor(message = "URI Too Long",
|
|
149
|
-
super(414, message,
|
|
150
|
+
constructor(message = "URI Too Long", options) {
|
|
151
|
+
super(414, message, { fatal: true, ...options });
|
|
150
152
|
Object.defineProperty(this, "name", { value: "UriTooLongException" });
|
|
151
153
|
}
|
|
152
154
|
};
|
|
153
155
|
|
|
154
156
|
// src/exception/http-exceptions/unsupported-media-type.exception.ts
|
|
155
157
|
var UnsupportedMediaTypeException = class extends RequestException {
|
|
156
|
-
constructor(message = "Unsupported Media Type",
|
|
157
|
-
super(415, message,
|
|
158
|
+
constructor(message = "Unsupported Media Type", options) {
|
|
159
|
+
super(415, message, { fatal: true, ...options });
|
|
158
160
|
Object.defineProperty(this, "name", { value: "UnsupportedMediaTypeException" });
|
|
159
161
|
}
|
|
160
162
|
};
|
|
161
163
|
|
|
162
164
|
// src/exception/http-exceptions/im-a-teapot.exception.ts
|
|
163
165
|
var ImATeapotException = class extends RequestException {
|
|
164
|
-
constructor(message = "I'm a teapot",
|
|
165
|
-
super(418, message,
|
|
166
|
+
constructor(message = "I'm a teapot", options) {
|
|
167
|
+
super(418, message, { fatal: true, ...options });
|
|
166
168
|
Object.defineProperty(this, "name", { value: "ImATeapotException" });
|
|
167
169
|
}
|
|
168
170
|
};
|
|
169
171
|
|
|
170
172
|
// src/exception/http-exceptions/too-many-requests.exception.ts
|
|
171
173
|
var TooManyRequestsException = class extends RequestException {
|
|
172
|
-
constructor(message = "Too Many Requests",
|
|
173
|
-
super(429, message,
|
|
174
|
+
constructor(message = "Too Many Requests", options) {
|
|
175
|
+
super(429, message, { fatal: false, ...options });
|
|
174
176
|
Object.defineProperty(this, "name", { value: "TooManyRequestsException" });
|
|
175
177
|
}
|
|
176
178
|
};
|
|
177
179
|
|
|
178
180
|
// src/exception/http-exceptions/internal-server-error.exception.ts
|
|
179
181
|
var InternalServerErrorException = class extends RequestException {
|
|
180
|
-
constructor(message = "Internal Server Error",
|
|
181
|
-
super(500, message,
|
|
182
|
+
constructor(message = "Internal Server Error", options) {
|
|
183
|
+
super(500, message, { fatal: false, ...options });
|
|
182
184
|
Object.defineProperty(this, "name", {
|
|
183
185
|
value: "InternalServerErrorException"
|
|
184
186
|
});
|
|
@@ -187,24 +189,24 @@ var InternalServerErrorException = class extends RequestException {
|
|
|
187
189
|
|
|
188
190
|
// src/exception/http-exceptions/not-implemented.exception.ts
|
|
189
191
|
var NotImplementedException = class extends RequestException {
|
|
190
|
-
constructor(message = "Not Implemented",
|
|
191
|
-
super(501, message,
|
|
192
|
+
constructor(message = "Not Implemented", options) {
|
|
193
|
+
super(501, message, { fatal: true, ...options });
|
|
192
194
|
Object.defineProperty(this, "name", { value: "NotImplementedException" });
|
|
193
195
|
}
|
|
194
196
|
};
|
|
195
197
|
|
|
196
198
|
// src/exception/http-exceptions/bad-gateway.exception.ts
|
|
197
199
|
var BadGatewayException = class extends RequestException {
|
|
198
|
-
constructor(message = "Bad Gateway",
|
|
199
|
-
super(502, message,
|
|
200
|
+
constructor(message = "Bad Gateway", options) {
|
|
201
|
+
super(502, message, { fatal: false, ...options });
|
|
200
202
|
Object.defineProperty(this, "name", { value: "BadGatewayException" });
|
|
201
203
|
}
|
|
202
204
|
};
|
|
203
205
|
|
|
204
206
|
// src/exception/http-exceptions/service-unavailable.exception.ts
|
|
205
207
|
var ServiceUnavailableException = class extends RequestException {
|
|
206
|
-
constructor(message = "Service Unavailable",
|
|
207
|
-
super(503, message,
|
|
208
|
+
constructor(message = "Service Unavailable", options) {
|
|
209
|
+
super(503, message, { fatal: false, ...options });
|
|
208
210
|
Object.defineProperty(this, "name", {
|
|
209
211
|
value: "ServiceUnavailableException"
|
|
210
212
|
});
|
|
@@ -213,8 +215,8 @@ var ServiceUnavailableException = class extends RequestException {
|
|
|
213
215
|
|
|
214
216
|
// src/exception/http-exceptions/gateway-timeout.exception.ts
|
|
215
217
|
var GatewayTimeoutException = class extends RequestException {
|
|
216
|
-
constructor(message = "Gateway Timeout",
|
|
217
|
-
super(504, message,
|
|
218
|
+
constructor(message = "Gateway Timeout", options) {
|
|
219
|
+
super(504, message, { fatal: false, ...options });
|
|
218
220
|
Object.defineProperty(this, "name", { value: "GatewayTimeoutException" });
|
|
219
221
|
}
|
|
220
222
|
};
|
|
@@ -719,15 +721,16 @@ function fork(original) {
|
|
|
719
721
|
return current;
|
|
720
722
|
};
|
|
721
723
|
const createProxy = (path = []) => {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
724
|
+
const getTarget = () => objectPath(current, path);
|
|
725
|
+
return new Proxy(getTarget(), {
|
|
726
|
+
get(target, prop) {
|
|
727
|
+
const realTarget = getTarget();
|
|
728
|
+
if (prop === UnWrapPropertyKey) return realTarget;
|
|
729
|
+
const value = realTarget[prop];
|
|
727
730
|
if (current !== original) {
|
|
728
731
|
return value;
|
|
729
732
|
}
|
|
730
|
-
if (Array.isArray(
|
|
733
|
+
if (Array.isArray(realTarget) && ARRAY_MUTATORS.has(prop)) {
|
|
731
734
|
return new Proxy(value, {
|
|
732
735
|
apply(fn, thisArg, args) {
|
|
733
736
|
ensureCopy();
|
|
@@ -741,15 +744,23 @@ function fork(original) {
|
|
|
741
744
|
}
|
|
742
745
|
return value;
|
|
743
746
|
},
|
|
744
|
-
set(
|
|
747
|
+
set(target, prop, value) {
|
|
745
748
|
ensureCopy();
|
|
746
749
|
objectPath(current, path)[prop] = value;
|
|
747
750
|
return true;
|
|
748
751
|
},
|
|
749
|
-
deleteProperty(
|
|
752
|
+
deleteProperty(target, prop) {
|
|
750
753
|
ensureCopy();
|
|
751
754
|
delete objectPath(current, path)[prop];
|
|
752
755
|
return true;
|
|
756
|
+
},
|
|
757
|
+
ownKeys(target) {
|
|
758
|
+
const realTarget = getTarget();
|
|
759
|
+
return Reflect.ownKeys(realTarget);
|
|
760
|
+
},
|
|
761
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
762
|
+
const realTarget = getTarget();
|
|
763
|
+
return Reflect.getOwnPropertyDescriptor(realTarget, prop);
|
|
753
764
|
}
|
|
754
765
|
});
|
|
755
766
|
};
|
|
@@ -1528,13 +1539,15 @@ var Keq = class extends Core {
|
|
|
1528
1539
|
this.requestInit.mode = mod;
|
|
1529
1540
|
return this;
|
|
1530
1541
|
}
|
|
1531
|
-
flowControl(mode,
|
|
1532
|
-
const
|
|
1542
|
+
flowControl(mode, arg2, arg3) {
|
|
1543
|
+
const concurrencyLimit = typeof arg2 === "number" ? arg2 : void 0;
|
|
1544
|
+
const sig = typeof arg2 === "function" || typeof arg2 === "string" ? arg2 : arg3 && (typeof arg3 === "function" || typeof arg3 === "string") ? arg3 : this.__locationId__;
|
|
1533
1545
|
if (!sig) {
|
|
1534
1546
|
throw new Exception("please set signal to .flowControl()");
|
|
1535
1547
|
}
|
|
1536
1548
|
const flowControl = {
|
|
1537
1549
|
mode,
|
|
1550
|
+
concurrencyLimit,
|
|
1538
1551
|
signal: sig
|
|
1539
1552
|
};
|
|
1540
1553
|
this.option("flowControl", flowControl);
|
|
@@ -1596,11 +1609,11 @@ function keqPathnameRoute(pathname) {
|
|
|
1596
1609
|
}
|
|
1597
1610
|
|
|
1598
1611
|
// src/router/keq-router.ts
|
|
1599
|
-
var KeqRouter = class {
|
|
1612
|
+
var KeqRouter = class _KeqRouter {
|
|
1600
1613
|
constructor(middlewares = []) {
|
|
1601
1614
|
this.middlewares = middlewares;
|
|
1602
1615
|
}
|
|
1603
|
-
buildMiddleware(route, middlewares) {
|
|
1616
|
+
static buildMiddleware(route, middlewares) {
|
|
1604
1617
|
if (middlewares.length === 0) {
|
|
1605
1618
|
throw new TypeException("At least one middleware is required to build a route middleware");
|
|
1606
1619
|
}
|
|
@@ -1611,42 +1624,72 @@ var KeqRouter = class {
|
|
|
1611
1624
|
};
|
|
1612
1625
|
return middleware;
|
|
1613
1626
|
}
|
|
1614
|
-
route(route, ...
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1617
|
-
this.middlewares.push(middleware);
|
|
1627
|
+
route(route, middleware, ...additionalMiddlewares) {
|
|
1628
|
+
const mid = _KeqRouter.route(route, middleware, ...additionalMiddlewares);
|
|
1629
|
+
this.middlewares.push(mid);
|
|
1618
1630
|
return this;
|
|
1619
1631
|
}
|
|
1620
|
-
host(host, ...
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1623
|
-
this.middlewares.push(middleware);
|
|
1632
|
+
host(host, middleware, ...additionalMiddlewares) {
|
|
1633
|
+
const mid = _KeqRouter.host(host, middleware, ...additionalMiddlewares);
|
|
1634
|
+
this.middlewares.push(mid);
|
|
1624
1635
|
return this;
|
|
1625
1636
|
}
|
|
1626
|
-
method(method, ...
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1629
|
-
this.middlewares.push(middleware);
|
|
1637
|
+
method(method, middleware, ...additionalMiddlewares) {
|
|
1638
|
+
const mid = _KeqRouter.method(method, middleware, ...additionalMiddlewares);
|
|
1639
|
+
this.middlewares.push(mid);
|
|
1630
1640
|
return this;
|
|
1631
1641
|
}
|
|
1632
|
-
pathname(pathname, ...
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
this.middlewares.push(middleware);
|
|
1642
|
+
pathname(pathname, middleware, ...additionalMiddlewares) {
|
|
1643
|
+
const mid = _KeqRouter.pathname(pathname, middleware, ...additionalMiddlewares);
|
|
1644
|
+
this.middlewares.push(mid);
|
|
1636
1645
|
return this;
|
|
1637
1646
|
}
|
|
1638
|
-
location(...
|
|
1639
|
-
const
|
|
1640
|
-
|
|
1641
|
-
this.middlewares.push(middleware);
|
|
1647
|
+
location(middleware, ...additionalMiddlewares) {
|
|
1648
|
+
const mid = _KeqRouter.location(middleware, ...additionalMiddlewares);
|
|
1649
|
+
this.middlewares.push(mid);
|
|
1642
1650
|
return this;
|
|
1643
1651
|
}
|
|
1644
|
-
module(moduleName, ...
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1647
|
-
this.middlewares.push(middleware);
|
|
1652
|
+
module(moduleName, middleware, ...additionalMiddlewares) {
|
|
1653
|
+
const mid = _KeqRouter.module(moduleName, middleware, ...additionalMiddlewares);
|
|
1654
|
+
this.middlewares.push(mid);
|
|
1648
1655
|
return this;
|
|
1649
1656
|
}
|
|
1657
|
+
static route(route, middleware, ...additionalMiddlewares) {
|
|
1658
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1659
|
+
const mid = _KeqRouter.buildMiddleware(route, list);
|
|
1660
|
+
mid.__keqMiddlewareName__ = "route(".concat(route.__keqRouteName__ || route.name, ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1661
|
+
return mid;
|
|
1662
|
+
}
|
|
1663
|
+
static host(host, middleware, ...additionalMiddlewares) {
|
|
1664
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1665
|
+
const mid = _KeqRouter.buildMiddleware(keqHostRoute(host), list);
|
|
1666
|
+
mid.__keqMiddlewareName__ = "host(".concat(JSON.stringify(host), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1667
|
+
return mid;
|
|
1668
|
+
}
|
|
1669
|
+
static method(method, middleware, ...additionalMiddlewares) {
|
|
1670
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1671
|
+
const mid = _KeqRouter.buildMiddleware(keqMethodRoute(method), list);
|
|
1672
|
+
mid.__keqMiddlewareName__ = "method(".concat(JSON.stringify(method), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1673
|
+
return mid;
|
|
1674
|
+
}
|
|
1675
|
+
static pathname(pathname, middleware, ...additionalMiddlewares) {
|
|
1676
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1677
|
+
const mid = _KeqRouter.buildMiddleware(keqPathnameRoute(pathname), list);
|
|
1678
|
+
mid.__keqMiddlewareName__ = "pathname(".concat(JSON.stringify(pathname), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1679
|
+
return mid;
|
|
1680
|
+
}
|
|
1681
|
+
static location(middleware, ...additionalMiddlewares) {
|
|
1682
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1683
|
+
const mid = _KeqRouter.buildMiddleware(keqLocationRoute(), list);
|
|
1684
|
+
mid.__keqMiddlewareName__ = "location(".concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1685
|
+
return mid;
|
|
1686
|
+
}
|
|
1687
|
+
static module(moduleName, middleware, ...additionalMiddlewares) {
|
|
1688
|
+
const list = Array.isArray(middleware) ? middleware : [middleware, ...additionalMiddlewares];
|
|
1689
|
+
const mid = _KeqRouter.buildMiddleware(keqModuleRoute(moduleName), list);
|
|
1690
|
+
mid.__keqMiddlewareName__ = "module(".concat(JSON.stringify(moduleName), ", ").concat(list.map(getMiddlewareName).join(", "), ")");
|
|
1691
|
+
return mid;
|
|
1692
|
+
}
|
|
1650
1693
|
};
|
|
1651
1694
|
|
|
1652
1695
|
// src/middlewares/timeout-middleware/index.ts
|
|
@@ -1675,17 +1718,18 @@ function keqTimeoutMiddleware() {
|
|
|
1675
1718
|
import * as fastq from "fastq";
|
|
1676
1719
|
function keqSerialFlowControlMiddleware() {
|
|
1677
1720
|
return async function serialFlowControlMiddleware(ctx, next) {
|
|
1678
|
-
if (!ctx.options.flowControl || ctx.options.flowControl.mode
|
|
1721
|
+
if (!ctx.options.flowControl || !["serial", "concurrent"].includes(ctx.options.flowControl.mode)) {
|
|
1679
1722
|
await next();
|
|
1680
1723
|
return;
|
|
1681
1724
|
}
|
|
1682
1725
|
const { signal } = ctx.options.flowControl;
|
|
1726
|
+
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);
|
|
1683
1727
|
const key = typeof signal === "string" ? signal : signal(ctx);
|
|
1684
1728
|
if (!ctx.global.serialFlowControl) ctx.global.serialFlowControl = {};
|
|
1685
1729
|
if (!ctx.global.serialFlowControl[key]) {
|
|
1686
1730
|
ctx.global.serialFlowControl[key] = fastq.promise(async (next2) => {
|
|
1687
1731
|
await next2();
|
|
1688
|
-
},
|
|
1732
|
+
}, concurrent);
|
|
1689
1733
|
}
|
|
1690
1734
|
const queue = ctx.global.serialFlowControl[key];
|
|
1691
1735
|
await queue.push(next);
|
|
@@ -1848,6 +1892,15 @@ var KeqRequest = class {
|
|
|
1848
1892
|
useRouter() {
|
|
1849
1893
|
return new KeqRouter(this.preMiddlewares);
|
|
1850
1894
|
}
|
|
1895
|
+
on(event, listener) {
|
|
1896
|
+
const middleware = async (context, next) => {
|
|
1897
|
+
context.emitter.on(event, listener);
|
|
1898
|
+
await next();
|
|
1899
|
+
};
|
|
1900
|
+
middleware.__keqMiddlewareName__ = "listen(".concat(event, ", ").concat(listener.name || "anonymous", ")");
|
|
1901
|
+
this.use(middleware);
|
|
1902
|
+
return this;
|
|
1903
|
+
}
|
|
1851
1904
|
};
|
|
1852
1905
|
var request = new KeqRequest();
|
|
1853
1906
|
|
|
@@ -1891,11 +1944,6 @@ export {
|
|
|
1891
1944
|
composeRoute,
|
|
1892
1945
|
createProxyResponse,
|
|
1893
1946
|
createRequest,
|
|
1894
|
-
keqHostRoute,
|
|
1895
|
-
keqLocationRoute,
|
|
1896
|
-
keqMethodRoute,
|
|
1897
|
-
keqModuleRoute,
|
|
1898
|
-
keqPathnameRoute,
|
|
1899
1947
|
request
|
|
1900
1948
|
};
|
|
1901
1949
|
//# sourceMappingURL=index.mjs.map
|