@e22m4u/js-trie-router 0.0.10 → 0.0.12
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/dist/cjs/index.cjs +362 -15
- package/package.json +11 -11
- package/src/hooks/hook-invoker.spec.js +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/parsers/body-parser.js +1 -1
- package/src/parsers/body-parser.spec.js +3 -3
- package/src/parsers/request-parser.spec.js +1 -1
- package/src/request-context.spec.js +2 -2
- package/src/route.spec.js +2 -2
- package/src/senders/data-sender.spec.js +1 -1
- package/src/senders/error-sender.spec.js +2 -2
- package/src/trie-router.spec.js +2 -2
- package/src/utils/index.d.ts +3 -0
- package/src/utils/index.js +3 -0
package/dist/cjs/index.cjs
CHANGED
|
@@ -1836,6 +1836,7 @@ var require_dist = __commonJS({
|
|
|
1836
1836
|
// src/index.js
|
|
1837
1837
|
var src_exports = {};
|
|
1838
1838
|
__export(src_exports, {
|
|
1839
|
+
BUFFER_ENCODING_LIST: () => BUFFER_ENCODING_LIST,
|
|
1839
1840
|
BodyParser: () => BodyParser,
|
|
1840
1841
|
CookieParser: () => CookieParser,
|
|
1841
1842
|
DataSender: () => DataSender,
|
|
@@ -1854,7 +1855,21 @@ __export(src_exports, {
|
|
|
1854
1855
|
RouterOptions: () => RouterOptions,
|
|
1855
1856
|
TrieRouter: () => TrieRouter,
|
|
1856
1857
|
UNPARSABLE_MEDIA_TYPES: () => UNPARSABLE_MEDIA_TYPES,
|
|
1857
|
-
|
|
1858
|
+
createCookieString: () => createCookieString,
|
|
1859
|
+
createDebugger: () => createDebugger,
|
|
1860
|
+
createError: () => createError,
|
|
1861
|
+
createRequestMock: () => createRequestMock,
|
|
1862
|
+
createResponseMock: () => createResponseMock,
|
|
1863
|
+
fetchRequestBody: () => fetchRequestBody,
|
|
1864
|
+
getRequestPathname: () => getRequestPathname,
|
|
1865
|
+
isPromise: () => isPromise,
|
|
1866
|
+
isReadableStream: () => isReadableStream,
|
|
1867
|
+
isResponseSent: () => isResponseSent,
|
|
1868
|
+
isWritableStream: () => isWritableStream,
|
|
1869
|
+
parseContentType: () => parseContentType,
|
|
1870
|
+
parseCookie: () => parseCookie,
|
|
1871
|
+
parseJsonBody: () => parseJsonBody,
|
|
1872
|
+
toCamelCase: () => toCamelCase
|
|
1858
1873
|
});
|
|
1859
1874
|
module.exports = __toCommonJS(src_exports);
|
|
1860
1875
|
|
|
@@ -2030,15 +2045,6 @@ function isReadableStream(value) {
|
|
|
2030
2045
|
return typeof value.pipe === "function";
|
|
2031
2046
|
}
|
|
2032
2047
|
|
|
2033
|
-
// src/utils/is-writable-stream.js
|
|
2034
|
-
function isWritableStream(value) {
|
|
2035
|
-
if (!value || typeof value !== "object") return false;
|
|
2036
|
-
return typeof value.end === "function";
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
// src/utils/fetch-request-body.js
|
|
2040
|
-
var import_http_errors = __toESM(require_http_errors(), 1);
|
|
2041
|
-
|
|
2042
2048
|
// src/utils/parse-content-type.js
|
|
2043
2049
|
function parseContentType(input) {
|
|
2044
2050
|
if (typeof input !== "string")
|
|
@@ -2057,7 +2063,14 @@ function parseContentType(input) {
|
|
|
2057
2063
|
return res;
|
|
2058
2064
|
}
|
|
2059
2065
|
|
|
2066
|
+
// src/utils/is-writable-stream.js
|
|
2067
|
+
function isWritableStream(value) {
|
|
2068
|
+
if (!value || typeof value !== "object") return false;
|
|
2069
|
+
return typeof value.end === "function";
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2060
2072
|
// src/utils/fetch-request-body.js
|
|
2073
|
+
var import_http_errors = __toESM(require_http_errors(), 1);
|
|
2061
2074
|
var import_http = require("http");
|
|
2062
2075
|
var BUFFER_ENCODING_LIST = [
|
|
2063
2076
|
"ascii",
|
|
@@ -2149,6 +2162,325 @@ function fetchRequestBody(req, bodyBytesLimit = 0) {
|
|
|
2149
2162
|
});
|
|
2150
2163
|
}
|
|
2151
2164
|
|
|
2165
|
+
// src/utils/create-request-mock.js
|
|
2166
|
+
var import_net = require("net");
|
|
2167
|
+
var import_tls = require("tls");
|
|
2168
|
+
var import_http2 = require("http");
|
|
2169
|
+
var import_querystring = __toESM(require("querystring"), 1);
|
|
2170
|
+
|
|
2171
|
+
// src/utils/create-cookie-string.js
|
|
2172
|
+
function createCookieString(data) {
|
|
2173
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
2174
|
+
throw new Errorf(
|
|
2175
|
+
'The first parameter of "createCookieString" should be an Object, but %v given.',
|
|
2176
|
+
data
|
|
2177
|
+
);
|
|
2178
|
+
let cookies = "";
|
|
2179
|
+
for (const key in data) {
|
|
2180
|
+
if (!Object.prototype.hasOwnProperty.call(data, key)) continue;
|
|
2181
|
+
const val = data[key];
|
|
2182
|
+
if (val == null) continue;
|
|
2183
|
+
cookies += `${key}=${val}; `;
|
|
2184
|
+
}
|
|
2185
|
+
return cookies.trim();
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
// src/utils/create-request-mock.js
|
|
2189
|
+
function createRequestMock(patch) {
|
|
2190
|
+
if (patch != null && typeof patch !== "object" || Array.isArray(patch)) {
|
|
2191
|
+
throw new Errorf(
|
|
2192
|
+
'The first parameter of "createRequestMock" should be an Object, but %v given.',
|
|
2193
|
+
patch
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
patch = patch || {};
|
|
2197
|
+
if (patch.host != null && typeof patch.host !== "string")
|
|
2198
|
+
throw new Errorf(
|
|
2199
|
+
'The parameter "host" of "createRequestMock" should be a String, but %v given.',
|
|
2200
|
+
patch.host
|
|
2201
|
+
);
|
|
2202
|
+
if (patch.method != null && typeof patch.method !== "string")
|
|
2203
|
+
throw new Errorf(
|
|
2204
|
+
'The parameter "method" of "createRequestMock" should be a String, but %v given.',
|
|
2205
|
+
patch.method
|
|
2206
|
+
);
|
|
2207
|
+
if (patch.secure != null && typeof patch.secure !== "boolean")
|
|
2208
|
+
throw new Errorf(
|
|
2209
|
+
'The parameter "secure" of "createRequestMock" should be a Boolean, but %v given.',
|
|
2210
|
+
patch.secure
|
|
2211
|
+
);
|
|
2212
|
+
if (patch.path != null && typeof patch.path !== "string")
|
|
2213
|
+
throw new Errorf(
|
|
2214
|
+
'The parameter "path" of "createRequestMock" should be a String, but %v given.',
|
|
2215
|
+
patch.path
|
|
2216
|
+
);
|
|
2217
|
+
if (patch.query != null && typeof patch.query !== "object" && typeof patch.query !== "string" || Array.isArray(patch.query)) {
|
|
2218
|
+
throw new Errorf(
|
|
2219
|
+
'The parameter "query" of "createRequestMock" should be a String or Object, but %v given.',
|
|
2220
|
+
patch.query
|
|
2221
|
+
);
|
|
2222
|
+
}
|
|
2223
|
+
if (patch.cookie != null && typeof patch.cookie !== "string" && typeof patch.cookie !== "object" || Array.isArray(patch.cookie)) {
|
|
2224
|
+
throw new Errorf(
|
|
2225
|
+
'The parameter "cookie" of "createRequestMock" should be a String or Object, but %v given.',
|
|
2226
|
+
patch.cookie
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
if (patch.headers != null && typeof patch.headers !== "object" || Array.isArray(patch.headers)) {
|
|
2230
|
+
throw new Errorf(
|
|
2231
|
+
'The parameter "headers" of "createRequestMock" should be an Object, but %v given.',
|
|
2232
|
+
patch.headers
|
|
2233
|
+
);
|
|
2234
|
+
}
|
|
2235
|
+
if (patch.stream != null && !isReadableStream(patch.stream))
|
|
2236
|
+
throw new Errorf(
|
|
2237
|
+
'The parameter "stream" of "createRequestMock" should be a Stream, but %v given.',
|
|
2238
|
+
patch.stream
|
|
2239
|
+
);
|
|
2240
|
+
if (patch.encoding != null) {
|
|
2241
|
+
if (typeof patch.encoding !== "string")
|
|
2242
|
+
throw new Errorf(
|
|
2243
|
+
'The parameter "encoding" of "createRequestMock" should be a String, but %v given.',
|
|
2244
|
+
patch.encoding
|
|
2245
|
+
);
|
|
2246
|
+
if (!BUFFER_ENCODING_LIST.includes(patch.encoding))
|
|
2247
|
+
throw new Errorf("Buffer encoding %v is not supported.", patch.encoding);
|
|
2248
|
+
}
|
|
2249
|
+
if (patch.stream) {
|
|
2250
|
+
if (patch.secure != null)
|
|
2251
|
+
throw new Errorf(
|
|
2252
|
+
'The "createRequestMock" does not allow specifying the "stream" and "secure" options simultaneously.'
|
|
2253
|
+
);
|
|
2254
|
+
if (patch.body != null)
|
|
2255
|
+
throw new Errorf(
|
|
2256
|
+
'The "createRequestMock" does not allow specifying the "stream" and "body" options simultaneously.'
|
|
2257
|
+
);
|
|
2258
|
+
if (patch.encoding != null)
|
|
2259
|
+
throw new Errorf(
|
|
2260
|
+
'The "createRequestMock" does not allow specifying the "stream" and "encoding" options simultaneously.'
|
|
2261
|
+
);
|
|
2262
|
+
}
|
|
2263
|
+
const req = patch.stream || createRequestStream(patch.secure, patch.body, patch.encoding);
|
|
2264
|
+
req.url = createRequestUrl(patch.path || "/", patch.query);
|
|
2265
|
+
req.headers = createRequestHeaders(
|
|
2266
|
+
patch.host,
|
|
2267
|
+
patch.secure,
|
|
2268
|
+
patch.body,
|
|
2269
|
+
patch.cookie,
|
|
2270
|
+
patch.encoding,
|
|
2271
|
+
patch.headers
|
|
2272
|
+
);
|
|
2273
|
+
req.method = (patch.method || "get").toUpperCase();
|
|
2274
|
+
return req;
|
|
2275
|
+
}
|
|
2276
|
+
function createRequestStream(secure, body, encoding) {
|
|
2277
|
+
if (encoding != null && typeof encoding !== "string")
|
|
2278
|
+
throw new Errorf(
|
|
2279
|
+
'The parameter "encoding" of "createRequestStream" should be a String, but %v given.',
|
|
2280
|
+
encoding
|
|
2281
|
+
);
|
|
2282
|
+
encoding = encoding || "utf-8";
|
|
2283
|
+
let socket = new import_net.Socket();
|
|
2284
|
+
if (secure) socket = new import_tls.TLSSocket(socket);
|
|
2285
|
+
const req = new import_http2.IncomingMessage(socket);
|
|
2286
|
+
if (body != null) {
|
|
2287
|
+
if (typeof body === "string") {
|
|
2288
|
+
req.push(body, encoding);
|
|
2289
|
+
} else if (Buffer.isBuffer(body)) {
|
|
2290
|
+
req.push(body);
|
|
2291
|
+
} else {
|
|
2292
|
+
req.push(JSON.stringify(body));
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
req.push(null);
|
|
2296
|
+
return req;
|
|
2297
|
+
}
|
|
2298
|
+
function createRequestUrl(path, query) {
|
|
2299
|
+
if (typeof path !== "string")
|
|
2300
|
+
throw new Errorf(
|
|
2301
|
+
'The parameter "path" of "createRequestUrl" should be a String, but %v given.',
|
|
2302
|
+
path
|
|
2303
|
+
);
|
|
2304
|
+
if (query != null && typeof query !== "string" && typeof query !== "object" || Array.isArray(query)) {
|
|
2305
|
+
throw new Errorf(
|
|
2306
|
+
'The parameter "query" of "createRequestUrl" should be a String or Object, but %v given.',
|
|
2307
|
+
query
|
|
2308
|
+
);
|
|
2309
|
+
}
|
|
2310
|
+
let url = ("/" + path).replace("//", "/");
|
|
2311
|
+
if (typeof query === "object") {
|
|
2312
|
+
const qs = import_querystring.default.stringify(query);
|
|
2313
|
+
if (qs) url += `?${qs}`;
|
|
2314
|
+
} else if (typeof query === "string") {
|
|
2315
|
+
url += `?${query.replace(/^\?/, "")}`;
|
|
2316
|
+
}
|
|
2317
|
+
return url;
|
|
2318
|
+
}
|
|
2319
|
+
function createRequestHeaders(host, secure, body, cookie, encoding, headers) {
|
|
2320
|
+
if (host != null && typeof host !== "string")
|
|
2321
|
+
throw new Errorf(
|
|
2322
|
+
'The parameter "host" of "createRequestHeaders" a non-empty String, but %v given.',
|
|
2323
|
+
host
|
|
2324
|
+
);
|
|
2325
|
+
host = host || "localhost";
|
|
2326
|
+
if (secure != null && typeof secure !== "boolean")
|
|
2327
|
+
throw new Errorf(
|
|
2328
|
+
'The parameter "secure" of "createRequestHeaders" should be a String, but %v given.',
|
|
2329
|
+
secure
|
|
2330
|
+
);
|
|
2331
|
+
secure = Boolean(secure);
|
|
2332
|
+
if (cookie != null && typeof cookie !== "object" && typeof cookie !== "string" || Array.isArray(cookie)) {
|
|
2333
|
+
throw new Errorf(
|
|
2334
|
+
'The parameter "cookie" of "createRequestHeaders" should be a String or Object, but %v given.',
|
|
2335
|
+
cookie
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2338
|
+
if (headers != null && typeof headers !== "object" || Array.isArray(headers)) {
|
|
2339
|
+
throw new Errorf(
|
|
2340
|
+
'The parameter "headers" of "createRequestHeaders" should be an Object, but %v given.',
|
|
2341
|
+
headers
|
|
2342
|
+
);
|
|
2343
|
+
}
|
|
2344
|
+
headers = headers || {};
|
|
2345
|
+
if (encoding != null && typeof encoding !== "string")
|
|
2346
|
+
throw new Errorf(
|
|
2347
|
+
'The parameter "encoding" of "createRequestHeaders" should be a String, but %v given.',
|
|
2348
|
+
encoding
|
|
2349
|
+
);
|
|
2350
|
+
encoding = encoding || "utf-8";
|
|
2351
|
+
const obj = { ...headers };
|
|
2352
|
+
obj["host"] = host;
|
|
2353
|
+
if (secure) obj["x-forwarded-proto"] = "https";
|
|
2354
|
+
if (cookie != null) {
|
|
2355
|
+
if (typeof cookie === "string") {
|
|
2356
|
+
obj["cookie"] = obj["cookie"] ? obj["cookie"] : "";
|
|
2357
|
+
obj["cookie"] += cookie;
|
|
2358
|
+
} else if (typeof cookie === "object") {
|
|
2359
|
+
obj["cookie"] = obj["cookie"] ? obj["cookie"] : "";
|
|
2360
|
+
obj["cookie"] += createCookieString(cookie);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
if (obj["content-type"] == null) {
|
|
2364
|
+
if (typeof body === "string") {
|
|
2365
|
+
obj["content-type"] = "text/plain";
|
|
2366
|
+
} else if (Buffer.isBuffer(body)) {
|
|
2367
|
+
obj["content-type"] = "application/octet-stream";
|
|
2368
|
+
} else if (typeof body === "object" || typeof body === "boolean" || typeof body === "number") {
|
|
2369
|
+
obj["content-type"] = "application/json";
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
if (body != null && obj["content-length"] == null) {
|
|
2373
|
+
if (typeof body === "string") {
|
|
2374
|
+
const length = Buffer.byteLength(body, encoding);
|
|
2375
|
+
obj["content-length"] = String(length);
|
|
2376
|
+
} else if (Buffer.isBuffer(body)) {
|
|
2377
|
+
const length = Buffer.byteLength(body);
|
|
2378
|
+
obj["content-length"] = String(length);
|
|
2379
|
+
} else if (typeof body === "object" || typeof body === "boolean" || typeof body === "number") {
|
|
2380
|
+
const json = JSON.stringify(body);
|
|
2381
|
+
const length = Buffer.byteLength(json, encoding);
|
|
2382
|
+
obj["content-length"] = String(length);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
return obj;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
// src/utils/create-response-mock.js
|
|
2389
|
+
var import_stream = require("stream");
|
|
2390
|
+
function createResponseMock() {
|
|
2391
|
+
const res = new import_stream.PassThrough();
|
|
2392
|
+
patchEncoding(res);
|
|
2393
|
+
patchHeaders(res);
|
|
2394
|
+
patchBody(res);
|
|
2395
|
+
return res;
|
|
2396
|
+
}
|
|
2397
|
+
function patchEncoding(res) {
|
|
2398
|
+
Object.defineProperty(res, "_encoding", {
|
|
2399
|
+
configurable: true,
|
|
2400
|
+
writable: true,
|
|
2401
|
+
value: void 0
|
|
2402
|
+
});
|
|
2403
|
+
Object.defineProperty(res, "setEncoding", {
|
|
2404
|
+
configurable: true,
|
|
2405
|
+
value: function(enc) {
|
|
2406
|
+
this._encoding = enc;
|
|
2407
|
+
return this;
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
Object.defineProperty(res, "getEncoding", {
|
|
2411
|
+
configurable: true,
|
|
2412
|
+
value: function() {
|
|
2413
|
+
return this._encoding;
|
|
2414
|
+
}
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
function patchHeaders(res) {
|
|
2418
|
+
Object.defineProperty(res, "_headersSent", {
|
|
2419
|
+
configurable: true,
|
|
2420
|
+
writable: true,
|
|
2421
|
+
value: false
|
|
2422
|
+
});
|
|
2423
|
+
Object.defineProperty(res, "headersSent", {
|
|
2424
|
+
configurable: true,
|
|
2425
|
+
get() {
|
|
2426
|
+
return this._headersSent;
|
|
2427
|
+
}
|
|
2428
|
+
});
|
|
2429
|
+
Object.defineProperty(res, "_headers", {
|
|
2430
|
+
configurable: true,
|
|
2431
|
+
writable: true,
|
|
2432
|
+
value: {}
|
|
2433
|
+
});
|
|
2434
|
+
Object.defineProperty(res, "setHeader", {
|
|
2435
|
+
configurable: true,
|
|
2436
|
+
value: function(name, value) {
|
|
2437
|
+
if (this.headersSent)
|
|
2438
|
+
throw new Error(
|
|
2439
|
+
"Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client"
|
|
2440
|
+
);
|
|
2441
|
+
const key = name.toLowerCase();
|
|
2442
|
+
this._headers[key] = String(value);
|
|
2443
|
+
return this;
|
|
2444
|
+
}
|
|
2445
|
+
});
|
|
2446
|
+
Object.defineProperty(res, "getHeader", {
|
|
2447
|
+
configurable: true,
|
|
2448
|
+
value: function(name) {
|
|
2449
|
+
return this._headers[name.toLowerCase()];
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
Object.defineProperty(res, "getHeaders", {
|
|
2453
|
+
configurable: true,
|
|
2454
|
+
value: function() {
|
|
2455
|
+
return JSON.parse(JSON.stringify(this._headers));
|
|
2456
|
+
}
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
function patchBody(res) {
|
|
2460
|
+
let resolve, reject;
|
|
2461
|
+
const promise = new Promise((res2, rej) => {
|
|
2462
|
+
resolve = res2;
|
|
2463
|
+
reject = rej;
|
|
2464
|
+
});
|
|
2465
|
+
const data = [];
|
|
2466
|
+
res.on("data", (c) => data.push(c));
|
|
2467
|
+
res.on("error", (e) => reject(e));
|
|
2468
|
+
res.on("end", () => {
|
|
2469
|
+
res._headersSent = true;
|
|
2470
|
+
resolve(Buffer.concat(data));
|
|
2471
|
+
});
|
|
2472
|
+
Object.defineProperty(res, "getBody", {
|
|
2473
|
+
configurable: true,
|
|
2474
|
+
value: function() {
|
|
2475
|
+
return promise.then((buffer) => {
|
|
2476
|
+
const enc = this.getEncoding();
|
|
2477
|
+
const str = buffer.toString(enc);
|
|
2478
|
+
return data.length ? str : void 0;
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2152
2484
|
// src/utils/get-request-pathname.js
|
|
2153
2485
|
function getRequestPathname(req) {
|
|
2154
2486
|
if (!req || typeof req !== "object" || Array.isArray(req) || typeof req.url !== "string") {
|
|
@@ -2931,7 +3263,7 @@ function parseJsonBody(input) {
|
|
|
2931
3263
|
}
|
|
2932
3264
|
|
|
2933
3265
|
// src/parsers/query-parser.js
|
|
2934
|
-
var
|
|
3266
|
+
var import_querystring2 = __toESM(require("querystring"), 1);
|
|
2935
3267
|
var QueryParser = class extends DebuggableService {
|
|
2936
3268
|
/**
|
|
2937
3269
|
* Parse
|
|
@@ -2941,7 +3273,7 @@ var QueryParser = class extends DebuggableService {
|
|
|
2941
3273
|
*/
|
|
2942
3274
|
parse(req) {
|
|
2943
3275
|
const queryStr = req.url.replace(/^[^?]*\??/, "");
|
|
2944
|
-
const query = queryStr ?
|
|
3276
|
+
const query = queryStr ? import_querystring2.default.parse(queryStr) : {};
|
|
2945
3277
|
const queryKeys = Object.keys(query);
|
|
2946
3278
|
if (queryKeys.length) {
|
|
2947
3279
|
queryKeys.forEach((key) => {
|
|
@@ -2986,7 +3318,7 @@ var CookieParser = class extends DebuggableService {
|
|
|
2986
3318
|
};
|
|
2987
3319
|
|
|
2988
3320
|
// src/parsers/request-parser.js
|
|
2989
|
-
var
|
|
3321
|
+
var import_http3 = require("http");
|
|
2990
3322
|
var RequestParser = class extends DebuggableService {
|
|
2991
3323
|
/**
|
|
2992
3324
|
* Parse.
|
|
@@ -2995,7 +3327,7 @@ var RequestParser = class extends DebuggableService {
|
|
|
2995
3327
|
* @returns {Promise<object>|object}
|
|
2996
3328
|
*/
|
|
2997
3329
|
parse(req) {
|
|
2998
|
-
if (!(req instanceof
|
|
3330
|
+
if (!(req instanceof import_http3.IncomingMessage))
|
|
2999
3331
|
throw new Errorf(
|
|
3000
3332
|
"The first argument of RequestParser.parse should be an instance of IncomingMessage, but %v given.",
|
|
3001
3333
|
req
|
|
@@ -3640,6 +3972,7 @@ var TrieRouter = class extends DebuggableService {
|
|
|
3640
3972
|
};
|
|
3641
3973
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3642
3974
|
0 && (module.exports = {
|
|
3975
|
+
BUFFER_ENCODING_LIST,
|
|
3643
3976
|
BodyParser,
|
|
3644
3977
|
CookieParser,
|
|
3645
3978
|
DataSender,
|
|
@@ -3658,7 +3991,21 @@ var TrieRouter = class extends DebuggableService {
|
|
|
3658
3991
|
RouterOptions,
|
|
3659
3992
|
TrieRouter,
|
|
3660
3993
|
UNPARSABLE_MEDIA_TYPES,
|
|
3661
|
-
|
|
3994
|
+
createCookieString,
|
|
3995
|
+
createDebugger,
|
|
3996
|
+
createError,
|
|
3997
|
+
createRequestMock,
|
|
3998
|
+
createResponseMock,
|
|
3999
|
+
fetchRequestBody,
|
|
4000
|
+
getRequestPathname,
|
|
4001
|
+
isPromise,
|
|
4002
|
+
isReadableStream,
|
|
4003
|
+
isResponseSent,
|
|
4004
|
+
isWritableStream,
|
|
4005
|
+
parseContentType,
|
|
4006
|
+
parseCookie,
|
|
4007
|
+
parseJsonBody,
|
|
4008
|
+
toCamelCase
|
|
3662
4009
|
});
|
|
3663
4010
|
/*! Bundled license information:
|
|
3664
4011
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-trie-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "HTTP router for Node.js based on a prefix tree",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.js",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"homepage": "https://github.com/e22m4u/js-trie-router",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@e22m4u/js-format": "~0.1.
|
|
41
|
-
"@e22m4u/js-path-trie": "~0.0.
|
|
42
|
-
"@e22m4u/js-service": "~0.1.
|
|
40
|
+
"@e22m4u/js-format": "~0.1.5",
|
|
41
|
+
"@e22m4u/js-path-trie": "~0.0.5",
|
|
42
|
+
"@e22m4u/js-service": "~0.1.3",
|
|
43
43
|
"debug": "~4.3.7",
|
|
44
44
|
"http-errors": "~2.0.0",
|
|
45
45
|
"statuses": "~2.0.1"
|
|
@@ -47,21 +47,21 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@commitlint/cli": "~19.5.0",
|
|
49
49
|
"@commitlint/config-conventional": "~19.5.0",
|
|
50
|
-
"@eslint/js": "~9.
|
|
50
|
+
"@eslint/js": "~9.14.0",
|
|
51
51
|
"@types/chai-as-promised": "~8.0.1",
|
|
52
52
|
"c8": "~10.1.2",
|
|
53
|
-
"chai": "~5.1.
|
|
53
|
+
"chai": "~5.1.2",
|
|
54
54
|
"chai-as-promised": "~8.0.0",
|
|
55
55
|
"esbuild": "~0.24.0",
|
|
56
|
-
"eslint": "~9.
|
|
56
|
+
"eslint": "~9.14.0",
|
|
57
57
|
"eslint-config-prettier": "~9.1.0",
|
|
58
58
|
"eslint-plugin-chai-expect": "~3.1.0",
|
|
59
|
-
"eslint-plugin-jsdoc": "~50.3
|
|
59
|
+
"eslint-plugin-jsdoc": "~50.4.3",
|
|
60
60
|
"eslint-plugin-mocha": "~10.5.0",
|
|
61
|
-
"globals": "~15.
|
|
61
|
+
"globals": "~15.12.0",
|
|
62
62
|
"husky": "~9.1.6",
|
|
63
|
-
"mocha": "~10.
|
|
63
|
+
"mocha": "~10.8.2",
|
|
64
64
|
"prettier": "~3.3.3",
|
|
65
|
-
"typescript": "~5.6.
|
|
65
|
+
"typescript": "~5.6.3"
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -5,7 +5,7 @@ import {format} from '@e22m4u/js-format';
|
|
|
5
5
|
import {HOOK_NAME} from './hook-registry.js';
|
|
6
6
|
import {HookInvoker} from './hook-invoker.js';
|
|
7
7
|
import {HookRegistry} from './hook-registry.js';
|
|
8
|
-
import {createResponseMock} from '../utils/
|
|
8
|
+
import {createResponseMock} from '../utils/index.js';
|
|
9
9
|
|
|
10
10
|
describe('HookInvoker', function () {
|
|
11
11
|
describe('invokeAndContinueUntilValueReceived', function () {
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import HttpErrors from 'http-errors';
|
|
|
2
2
|
import {Errorf} from '@e22m4u/js-format';
|
|
3
3
|
import {createError} from '../utils/index.js';
|
|
4
4
|
import {RouterOptions} from '../router-options.js';
|
|
5
|
+
import {parseContentType} from '../utils/index.js';
|
|
5
6
|
import {fetchRequestBody} from '../utils/index.js';
|
|
6
7
|
import {DebuggableService} from '../debuggable-service.js';
|
|
7
|
-
import {parseContentType} from '../utils/parse-content-type.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Method names to be parsed.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {expect} from '../chai.js';
|
|
2
|
+
import HttpErrors from 'http-errors';
|
|
2
3
|
import {HttpMethod} from '../route.js';
|
|
3
4
|
import {format} from '@e22m4u/js-format';
|
|
4
5
|
import {BodyParser} from './body-parser.js';
|
|
5
6
|
import {METHODS_WITH_BODY} from './body-parser.js';
|
|
6
|
-
import {UNPARSABLE_MEDIA_TYPES} from './body-parser.js';
|
|
7
|
-
import {createRequestMock} from '../utils/create-request-mock.js';
|
|
8
7
|
import {RouterOptions} from '../router-options.js';
|
|
9
|
-
import
|
|
8
|
+
import {createRequestMock} from '../utils/index.js';
|
|
9
|
+
import {UNPARSABLE_MEDIA_TYPES} from './body-parser.js';
|
|
10
10
|
|
|
11
11
|
describe('BodyParser', function () {
|
|
12
12
|
describe('defineParser', function () {
|
|
@@ -2,7 +2,7 @@ import {expect} from '../chai.js';
|
|
|
2
2
|
import {HttpMethod} from '../route.js';
|
|
3
3
|
import {format} from '@e22m4u/js-format';
|
|
4
4
|
import {RequestParser} from './request-parser.js';
|
|
5
|
-
import {createRequestMock} from '../utils/
|
|
5
|
+
import {createRequestMock} from '../utils/index.js';
|
|
6
6
|
|
|
7
7
|
describe('RequestParser', function () {
|
|
8
8
|
describe('parse', function () {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {expect} from './chai.js';
|
|
2
2
|
import {format} from '@e22m4u/js-format';
|
|
3
|
+
import {createRequestMock} from './utils/index.js';
|
|
3
4
|
import {RequestContext} from './request-context.js';
|
|
4
5
|
import {ServiceContainer} from '@e22m4u/js-service';
|
|
5
|
-
import {
|
|
6
|
-
import {createResponseMock} from './utils/create-response-mock.js';
|
|
6
|
+
import {createResponseMock} from './utils/index.js';
|
|
7
7
|
|
|
8
8
|
describe('RequestContext', function () {
|
|
9
9
|
describe('constructor', function () {
|
package/src/route.spec.js
CHANGED
|
@@ -3,10 +3,10 @@ import {expect} from './chai.js';
|
|
|
3
3
|
import {HttpMethod} from './route.js';
|
|
4
4
|
import {format} from '@e22m4u/js-format';
|
|
5
5
|
import {HOOK_NAME} from './hooks/index.js';
|
|
6
|
+
import {createRequestMock} from './utils/index.js';
|
|
7
|
+
import {createResponseMock} from './utils/index.js';
|
|
6
8
|
import {RequestContext} from './request-context.js';
|
|
7
9
|
import {ServiceContainer} from '@e22m4u/js-service';
|
|
8
|
-
import {createRequestMock} from './utils/create-request-mock.js';
|
|
9
|
-
import {createResponseMock} from './utils/create-response-mock.js';
|
|
10
10
|
|
|
11
11
|
describe('Route', function () {
|
|
12
12
|
describe('constructor', function () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {expect} from '../chai.js';
|
|
2
2
|
import {Readable, Writable} from 'stream';
|
|
3
3
|
import {DataSender} from './data-sender.js';
|
|
4
|
-
import {createResponseMock} from '../utils/
|
|
4
|
+
import {createResponseMock} from '../utils/index.js';
|
|
5
5
|
|
|
6
6
|
describe('DataSender', function () {
|
|
7
7
|
describe('send', function () {
|
|
@@ -2,9 +2,9 @@ import {Writable} from 'stream';
|
|
|
2
2
|
import {expect} from '../chai.js';
|
|
3
3
|
import HttpErrors from 'http-errors';
|
|
4
4
|
import {ErrorSender} from './error-sender.js';
|
|
5
|
+
import {createRequestMock} from '../utils/index.js';
|
|
6
|
+
import {createResponseMock} from '../utils/index.js';
|
|
5
7
|
import {EXPOSED_ERROR_PROPERTIES} from './error-sender.js';
|
|
6
|
-
import {createRequestMock} from '../utils/create-request-mock.js';
|
|
7
|
-
import {createResponseMock} from '../utils/create-response-mock.js';
|
|
8
8
|
|
|
9
9
|
describe('ErrorSender', function () {
|
|
10
10
|
describe('send', function () {
|
package/src/trie-router.spec.js
CHANGED
|
@@ -7,9 +7,9 @@ import {HOOK_NAME} from './hooks/index.js';
|
|
|
7
7
|
import {HookRegistry} from './hooks/index.js';
|
|
8
8
|
import {DataSender} from './senders/index.js';
|
|
9
9
|
import {ErrorSender} from './senders/index.js';
|
|
10
|
+
import {createRequestMock} from './utils/index.js';
|
|
11
|
+
import {createResponseMock} from './utils/index.js';
|
|
10
12
|
import {RequestContext} from './request-context.js';
|
|
11
|
-
import {createRequestMock} from './utils/create-request-mock.js';
|
|
12
|
-
import {createResponseMock} from './utils/create-response-mock.js';
|
|
13
13
|
|
|
14
14
|
describe('TrieRouter', function () {
|
|
15
15
|
describe('defineRoute', function () {
|
package/src/utils/index.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ export * from './to-camel-case.js';
|
|
|
5
5
|
export * from './create-debugger.js';
|
|
6
6
|
export * from './is-response-sent.js';
|
|
7
7
|
export * from './is-readable-stream.js';
|
|
8
|
+
export * from './parse-content-type.js';
|
|
8
9
|
export * from './is-writable-stream.js';
|
|
9
10
|
export * from './fetch-request-body.js';
|
|
11
|
+
export * from './create-request-mock.js';
|
|
12
|
+
export * from './create-response-mock.js';
|
|
10
13
|
export * from './create-cookie-string.js';
|
|
11
14
|
export * from './get-request-pathname.js';
|
package/src/utils/index.js
CHANGED
|
@@ -5,7 +5,10 @@ export * from './to-camel-case.js';
|
|
|
5
5
|
export * from './create-debugger.js';
|
|
6
6
|
export * from './is-response-sent.js';
|
|
7
7
|
export * from './is-readable-stream.js';
|
|
8
|
+
export * from './parse-content-type.js';
|
|
8
9
|
export * from './is-writable-stream.js';
|
|
9
10
|
export * from './fetch-request-body.js';
|
|
11
|
+
export * from './create-request-mock.js';
|
|
12
|
+
export * from './create-response-mock.js';
|
|
10
13
|
export * from './create-cookie-string.js';
|
|
11
14
|
export * from './get-request-pathname.js';
|