repocairn 0.1.3 → 0.1.4
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/README.md +6 -0
- package/dist/graphify-source.d.ts +17 -0
- package/dist/graphify-source.js +87 -0
- package/dist/graphify-source.js.map +1 -0
- package/dist/index-command.js +3 -1
- package/dist/index-command.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer.d.ts +1 -0
- package/dist/indexer.js +1 -1
- package/dist/indexer.js.map +1 -1
- package/dist/signals.d.ts +13 -0
- package/dist/signals.js +84 -0
- package/dist/signals.js.map +1 -0
- package/node_modules/body-parser/node_modules/content-type/README.md +2 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
- package/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
- package/node_modules/body-parser/node_modules/content-type/package.json +1 -1
- package/node_modules/eventsource-parser/dist/index.cjs +2 -2
- package/node_modules/eventsource-parser/dist/index.cjs.map +1 -1
- package/node_modules/eventsource-parser/dist/index.js +2 -2
- package/node_modules/eventsource-parser/dist/index.js.map +1 -1
- package/node_modules/eventsource-parser/package.json +1 -1
- package/node_modules/eventsource-parser/src/parse.ts +4 -2
- package/node_modules/express-rate-limit/dist/index.cjs +6 -1
- package/node_modules/express-rate-limit/dist/index.mjs +6 -1
- package/node_modules/express-rate-limit/package.json +6 -6
- package/node_modules/fast-uri/index.js +37 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/security.test.js +136 -0
- package/node_modules/hono/dist/cjs/client/client.js +3 -3
- package/node_modules/hono/dist/cjs/client/utils.js +1 -1
- package/node_modules/hono/dist/cjs/context.js +32 -13
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
- package/node_modules/hono/dist/cjs/hono-base.js +3 -2
- package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
- package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
- package/node_modules/hono/dist/cjs/jsx/intrinsic-element/components.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
- package/node_modules/hono/dist/cjs/middleware/cors/index.js +17 -14
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/etag/digest.js +47 -1
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
- package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/request.js +6 -8
- package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
- package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +44 -68
- package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
- package/node_modules/hono/dist/cjs/router.js +1 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
- package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
- package/node_modules/hono/dist/cjs/utils/stream.js +5 -2
- package/node_modules/hono/dist/cjs/utils/url.js +9 -9
- package/node_modules/hono/dist/client/client.js +3 -3
- package/node_modules/hono/dist/client/utils.js +1 -1
- package/node_modules/hono/dist/context.js +32 -13
- package/node_modules/hono/dist/helper/proxy/index.js +4 -0
- package/node_modules/hono/dist/hono-base.js +3 -2
- package/node_modules/hono/dist/jsx/base.js +27 -23
- package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
- package/node_modules/hono/dist/jsx/intrinsic-element/components.js +1 -1
- package/node_modules/hono/dist/middleware/cache/index.js +103 -8
- package/node_modules/hono/dist/middleware/compress/index.js +5 -0
- package/node_modules/hono/dist/middleware/cors/index.js +17 -14
- package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
- package/node_modules/hono/dist/middleware/etag/digest.js +47 -1
- package/node_modules/hono/dist/middleware/etag/index.js +6 -3
- package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
- package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
- package/node_modules/hono/dist/middleware/language/language.js +10 -6
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
- package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/request.js +7 -9
- package/node_modules/hono/dist/router/linear-router/router.js +7 -2
- package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
- package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
- package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
- package/node_modules/hono/dist/router/trie-router/node.js +44 -68
- package/node_modules/hono/dist/router/trie-router/router.js +3 -11
- package/node_modules/hono/dist/router.js +1 -1
- package/node_modules/hono/dist/types/client/types.d.ts +1 -1
- package/node_modules/hono/dist/types/context.d.ts +4 -0
- package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
- package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
- package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
- package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
- package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
- package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
- package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
- package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
- package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
- package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
- package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
- package/node_modules/hono/dist/types/router.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
- package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
- package/node_modules/hono/dist/utils/cookie.js +4 -3
- package/node_modules/hono/dist/utils/ipaddr.js +5 -3
- package/node_modules/hono/dist/utils/stream.js +5 -2
- package/node_modules/hono/dist/utils/url.js +7 -8
- package/node_modules/hono/package.json +10 -3
- package/node_modules/ip-address/README.md +163 -149
- package/node_modules/ip-address/dist/address-error.d.ts +11 -0
- package/node_modules/ip-address/dist/address-error.js.map +1 -1
- package/node_modules/ip-address/dist/common.d.ts +6 -0
- package/node_modules/ip-address/dist/common.js +17 -1
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/dist/ipv4.d.ts +22 -6
- package/node_modules/ip-address/dist/ipv4.js +25 -18
- package/node_modules/ip-address/dist/ipv4.js.map +1 -1
- package/node_modules/ip-address/dist/ipv6.d.ts +19 -5
- package/node_modules/ip-address/dist/ipv6.js +61 -33
- package/node_modules/ip-address/dist/ipv6.js.map +1 -1
- package/node_modules/ip-address/package.json +5 -3
- package/node_modules/jose/README.md +13 -13
- package/node_modules/jose/dist/types/index.d.ts +6 -5
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +8 -19
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +8 -19
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +21 -21
- package/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
- package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
- package/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
- package/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +11 -34
- package/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
- package/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
- package/node_modules/jose/dist/types/key/export.d.ts +0 -14
- package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
- package/node_modules/jose/dist/types/key/import.d.ts +18 -28
- package/node_modules/jose/dist/types/types.d.ts +243 -224
- package/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
- package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
- package/node_modules/jose/dist/types/util/errors.d.ts +128 -121
- package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +4 -22
- package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
- package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +23 -3
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +70 -82
- package/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
- package/node_modules/jose/dist/webapi/jwks/local.js +32 -73
- package/node_modules/jose/dist/webapi/jwks/remote.js +19 -28
- package/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
- package/node_modules/jose/dist/webapi/jws/compact/verify.js +4 -16
- package/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -65
- package/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
- package/node_modules/jose/dist/webapi/jws/general/sign.js +19 -15
- package/node_modules/jose/dist/webapi/jws/general/verify.js +29 -9
- package/node_modules/jose/dist/webapi/jwt/decrypt.js +5 -5
- package/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
- package/node_modules/jose/dist/webapi/jwt/verify.js +6 -6
- package/node_modules/jose/dist/webapi/key/export.js +37 -4
- package/node_modules/jose/dist/webapi/key/generate_key_pair.js +33 -82
- package/node_modules/jose/dist/webapi/key/generate_secret.js +2 -2
- package/node_modules/jose/dist/webapi/key/import.js +8 -8
- package/node_modules/jose/dist/webapi/lib/asn1.js +53 -122
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +34 -109
- package/node_modules/jose/dist/webapi/lib/crypto_key.js +18 -126
- package/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
- package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -1
- package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +107 -0
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +186 -0
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +114 -0
- package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +8 -98
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +73 -0
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +74 -0
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +107 -0
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +68 -109
- package/node_modules/jose/dist/webapi/lib/key.js +132 -0
- package/node_modules/jose/dist/webapi/lib/key_algorithm.js +10 -0
- package/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
- package/node_modules/jose/dist/webapi/lib/key_management.js +162 -92
- package/node_modules/jose/dist/webapi/lib/options.js +48 -0
- package/node_modules/jose/dist/webapi/lib/signing.js +14 -56
- package/node_modules/jose/dist/webapi/lib/type_checks.js +13 -18
- package/node_modules/jose/dist/webapi/util/base64url.js +13 -4
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
- package/node_modules/jose/dist/webapi/util/errors.js +1 -1
- package/node_modules/jose/package.json +2 -4
- package/node_modules/type-is/node_modules/content-type/README.md +2 -0
- package/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
- package/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
- package/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
- package/node_modules/type-is/node_modules/content-type/package.json +1 -1
- package/package.json +5 -3
- package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
- package/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
- package/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
- package/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
- package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
- package/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
- package/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
- package/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
- package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
- package/node_modules/jose/dist/webapi/lib/validate_crit.js +0 -33
|
@@ -5,10 +5,8 @@ var PatternRouter = class {
|
|
|
5
5
|
name = "PatternRouter";
|
|
6
6
|
#routes = [];
|
|
7
7
|
add(method, path, handler) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
path = path.slice(0, -2);
|
|
11
|
-
}
|
|
8
|
+
const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
|
|
9
|
+
path = path.replace(/\*$/, "");
|
|
12
10
|
if (path.at(-1) === "?") {
|
|
13
11
|
path = path.slice(0, -1);
|
|
14
12
|
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
@@ -20,11 +18,7 @@ var PatternRouter = class {
|
|
|
20
18
|
}
|
|
21
19
|
);
|
|
22
20
|
try {
|
|
23
|
-
this.#routes.push([
|
|
24
|
-
new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`),
|
|
25
|
-
method,
|
|
26
|
-
handler
|
|
27
|
-
]);
|
|
21
|
+
this.#routes.push([new RegExp(`^${parts.join("")}${suffix}`), method, handler]);
|
|
28
22
|
} catch {
|
|
29
23
|
throw new UnsupportedPathError();
|
|
30
24
|
}
|
|
@@ -12,7 +12,7 @@ function compareKey(a, b) {
|
|
|
12
12
|
return 1;
|
|
13
13
|
}
|
|
14
14
|
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
15
|
-
return 1;
|
|
15
|
+
return b === TAIL_WILDCARD_REG_EXP_STR ? -1 : 1;
|
|
16
16
|
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
17
17
|
return -1;
|
|
18
18
|
}
|
|
@@ -24,76 +24,75 @@ function compareKey(a, b) {
|
|
|
24
24
|
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
25
25
|
}
|
|
26
26
|
var Node = class _Node {
|
|
27
|
+
// handler index of a dynamic path, or -1 for a static path terminal
|
|
27
28
|
#index;
|
|
28
29
|
#varIndex;
|
|
29
30
|
#children = /* @__PURE__ */ Object.create(null);
|
|
30
|
-
insert(tokens, index, paramMap, context,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
52
|
-
if (/\((?!\?:)/.test(regexpStr)) {
|
|
53
|
-
throw PATH_ERROR;
|
|
31
|
+
insert(tokens, index, paramMap, context, isStatic) {
|
|
32
|
+
let node = this;
|
|
33
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
34
|
+
const token = tokens[i];
|
|
35
|
+
const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : null : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
36
|
+
let nextNode;
|
|
37
|
+
if (pattern) {
|
|
38
|
+
const name = pattern[1];
|
|
39
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
40
|
+
if (name && pattern[2]) {
|
|
41
|
+
if (regexpStr === ".*") {
|
|
42
|
+
throw PATH_ERROR;
|
|
43
|
+
}
|
|
44
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
45
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
46
|
+
throw PATH_ERROR;
|
|
47
|
+
}
|
|
48
|
+
if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) {
|
|
49
|
+
throw PATH_ERROR;
|
|
50
|
+
}
|
|
54
51
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
nextNode = node.#children[regexpStr];
|
|
53
|
+
if (!nextNode) {
|
|
54
|
+
if (regexpStr !== ONLY_WILDCARD_REG_EXP_STR && regexpStr !== TAIL_WILDCARD_REG_EXP_STR) {
|
|
55
|
+
for (const k in node.#children) {
|
|
56
|
+
if (
|
|
57
|
+
// a single-char pattern coexists with single-char literals as a literal does
|
|
58
|
+
(regexpStr.length > 1 || k.length > 1) && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
59
|
+
) {
|
|
60
|
+
throw PATH_ERROR;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
nextNode = node.#children[regexpStr] = new _Node();
|
|
62
65
|
}
|
|
63
|
-
if (pathErrorCheckOnly) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
node = this.#children[regexpStr] = new _Node();
|
|
67
66
|
if (name !== "") {
|
|
68
|
-
|
|
67
|
+
nextNode.#varIndex ??= context.varIndex++;
|
|
68
|
+
paramMap.push([name, nextNode.#varIndex]);
|
|
69
69
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)) {
|
|
80
|
-
throw PATH_ERROR;
|
|
70
|
+
} else {
|
|
71
|
+
nextNode = node.#children[token];
|
|
72
|
+
if (!nextNode) {
|
|
73
|
+
for (const k in node.#children) {
|
|
74
|
+
if (k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) {
|
|
75
|
+
throw PATH_ERROR;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
nextNode = node.#children[token] = new _Node();
|
|
81
79
|
}
|
|
82
|
-
if (pathErrorCheckOnly) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
node = this.#children[token] = new _Node();
|
|
86
80
|
}
|
|
81
|
+
node = nextNode;
|
|
82
|
+
}
|
|
83
|
+
if (node.#index !== void 0) {
|
|
84
|
+
throw PATH_ERROR;
|
|
87
85
|
}
|
|
88
|
-
node
|
|
86
|
+
node.#index = isStatic ? -1 : index;
|
|
89
87
|
}
|
|
90
88
|
buildRegExpStr() {
|
|
91
89
|
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
92
90
|
const strList = childKeys.map((k) => {
|
|
93
91
|
const c = this.#children[k];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
const childStr = c.buildRegExpStr();
|
|
93
|
+
return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
|
|
94
|
+
}).filter(Boolean);
|
|
95
|
+
if (typeof this.#index === "number" && this.#index !== -1) {
|
|
97
96
|
strList.unshift(`#${this.#index}`);
|
|
98
97
|
}
|
|
99
98
|
if (strList.length === 0) {
|
|
@@ -8,7 +8,6 @@ import { checkOptionalParameter } from "../../utils/url.js";
|
|
|
8
8
|
import { match, emptyParam } from "./matcher.js";
|
|
9
9
|
import { PATH_ERROR } from "./node.js";
|
|
10
10
|
import { Trie } from "./trie.js";
|
|
11
|
-
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
12
11
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
13
12
|
function buildWildcardRegExp(path) {
|
|
14
13
|
return wildcardRegExpCache[path] ??= new RegExp(
|
|
@@ -21,63 +20,6 @@ function buildWildcardRegExp(path) {
|
|
|
21
20
|
function clearWildcardRegExpCache() {
|
|
22
21
|
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
23
22
|
}
|
|
24
|
-
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
25
|
-
const trie = new Trie();
|
|
26
|
-
const handlerData = [];
|
|
27
|
-
if (routes.length === 0) {
|
|
28
|
-
return nullMatcher;
|
|
29
|
-
}
|
|
30
|
-
const routesWithStaticPathFlag = routes.map(
|
|
31
|
-
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
32
|
-
).sort(
|
|
33
|
-
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
34
|
-
);
|
|
35
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
36
|
-
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
37
|
-
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
38
|
-
if (pathErrorCheckOnly) {
|
|
39
|
-
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
40
|
-
} else {
|
|
41
|
-
j++;
|
|
42
|
-
}
|
|
43
|
-
let paramAssoc;
|
|
44
|
-
try {
|
|
45
|
-
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
48
|
-
}
|
|
49
|
-
if (pathErrorCheckOnly) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
53
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
54
|
-
paramCount -= 1;
|
|
55
|
-
for (; paramCount >= 0; paramCount--) {
|
|
56
|
-
const [key, value] = paramAssoc[paramCount];
|
|
57
|
-
paramIndexMap[key] = value;
|
|
58
|
-
}
|
|
59
|
-
return [h, paramIndexMap];
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
63
|
-
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
64
|
-
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
65
|
-
const map = handlerData[i][j]?.[1];
|
|
66
|
-
if (!map) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const keys = Object.keys(map);
|
|
70
|
-
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
71
|
-
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const handlerMap = [];
|
|
76
|
-
for (const i in indexReplacementMap) {
|
|
77
|
-
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
78
|
-
}
|
|
79
|
-
return [regexp, handlerMap, staticMap];
|
|
80
|
-
}
|
|
81
23
|
function findMiddleware(middleware, path) {
|
|
82
24
|
if (!middleware) {
|
|
83
25
|
return void 0;
|
|
@@ -93,9 +35,18 @@ var RegExpRouter = class {
|
|
|
93
35
|
name = "RegExpRouter";
|
|
94
36
|
#middleware;
|
|
95
37
|
#routes;
|
|
38
|
+
#tries;
|
|
96
39
|
constructor() {
|
|
97
40
|
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
98
41
|
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
42
|
+
this.#tries = { [METHOD_NAME_ALL]: new Trie() };
|
|
43
|
+
}
|
|
44
|
+
#insertPath(method, path) {
|
|
45
|
+
try {
|
|
46
|
+
this.#tries[method].insert(path, !/\*|\/:/.test(path));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
49
|
+
}
|
|
99
50
|
}
|
|
100
51
|
add(method, path, handler) {
|
|
101
52
|
const middleware = this.#middleware;
|
|
@@ -104,11 +55,12 @@ var RegExpRouter = class {
|
|
|
104
55
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
105
56
|
}
|
|
106
57
|
if (!middleware[method]) {
|
|
107
|
-
;
|
|
58
|
+
this.#tries[method] = new Trie();
|
|
108
59
|
[middleware, routes].forEach((handlerMap) => {
|
|
109
60
|
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
110
61
|
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
111
62
|
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
63
|
+
this.#insertPath(method, p);
|
|
112
64
|
});
|
|
113
65
|
});
|
|
114
66
|
}
|
|
@@ -118,13 +70,12 @@ var RegExpRouter = class {
|
|
|
118
70
|
const paramCount = (path.match(/\/:/g) || []).length;
|
|
119
71
|
if (/\*$/.test(path)) {
|
|
120
72
|
const re = buildWildcardRegExp(path);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
73
|
+
Object.keys(middleware).forEach((m) => {
|
|
74
|
+
if ((method === METHOD_NAME_ALL || method === m) && !middleware[m][path]) {
|
|
75
|
+
this.#insertPath(m, path);
|
|
76
|
+
middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
128
79
|
Object.keys(middleware).forEach((m) => {
|
|
129
80
|
if (method === METHOD_NAME_ALL || method === m) {
|
|
130
81
|
Object.keys(middleware[m]).forEach((p) => {
|
|
@@ -146,9 +97,12 @@ var RegExpRouter = class {
|
|
|
146
97
|
const path2 = paths[i];
|
|
147
98
|
Object.keys(routes).forEach((m) => {
|
|
148
99
|
if (method === METHOD_NAME_ALL || method === m) {
|
|
149
|
-
routes[m][path2]
|
|
150
|
-
|
|
151
|
-
|
|
100
|
+
if (!routes[m][path2]) {
|
|
101
|
+
this.#insertPath(m, path2);
|
|
102
|
+
routes[m][path2] = [
|
|
103
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
104
|
+
];
|
|
105
|
+
}
|
|
152
106
|
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
153
107
|
}
|
|
154
108
|
});
|
|
@@ -160,29 +114,54 @@ var RegExpRouter = class {
|
|
|
160
114
|
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
161
115
|
matchers[method] ||= this.#buildMatcher(method);
|
|
162
116
|
});
|
|
163
|
-
this.#middleware = this.#routes = void 0;
|
|
117
|
+
this.#middleware = this.#routes = this.#tries = void 0;
|
|
164
118
|
clearWildcardRegExpCache();
|
|
165
119
|
return matchers;
|
|
166
120
|
}
|
|
167
121
|
#buildMatcher(method) {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
122
|
+
const middleware = this.#middleware[method];
|
|
123
|
+
const routes = this.#routes[method];
|
|
124
|
+
const trie = this.#tries[method];
|
|
125
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
126
|
+
const handlerData = [];
|
|
127
|
+
[middleware, routes].forEach((r) => {
|
|
128
|
+
for (const path in r) {
|
|
129
|
+
const handlers = r[path];
|
|
130
|
+
const pathData = trie.paths[path];
|
|
131
|
+
if (!pathData) {
|
|
132
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const paramAssoc = pathData[1];
|
|
136
|
+
handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
|
|
137
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
138
|
+
paramCount -= 1;
|
|
139
|
+
for (; paramCount >= 0; paramCount--) {
|
|
140
|
+
const [key, value] = paramAssoc[paramCount];
|
|
141
|
+
paramIndexMap[key] = value;
|
|
142
|
+
}
|
|
143
|
+
return [h, paramIndexMap];
|
|
144
|
+
});
|
|
179
145
|
}
|
|
180
146
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
147
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
148
|
+
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
149
|
+
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
150
|
+
const map = handlerData[i][j]?.[1];
|
|
151
|
+
if (!map) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const keys = Object.keys(map);
|
|
155
|
+
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
156
|
+
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const handlerMap = [];
|
|
161
|
+
for (const i in indexReplacementMap) {
|
|
162
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
185
163
|
}
|
|
164
|
+
return [regexp, handlerMap, staticMap];
|
|
186
165
|
}
|
|
187
166
|
};
|
|
188
167
|
export {
|
|
@@ -3,12 +3,20 @@ import { Node } from "./node.js";
|
|
|
3
3
|
var Trie = class {
|
|
4
4
|
#context = { varIndex: 0 };
|
|
5
5
|
#root = new Node();
|
|
6
|
-
|
|
6
|
+
#index = 0;
|
|
7
|
+
// dynamic path -> [handler index, param assoc]; static paths are not registered
|
|
8
|
+
paths = /* @__PURE__ */ Object.create(null);
|
|
9
|
+
insert(path, isStatic) {
|
|
10
|
+
if (isStatic) {
|
|
11
|
+
this.#root.insert(path.split(""), 0, [], this.#context, true);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
7
14
|
const paramAssoc = [];
|
|
8
15
|
const groups = [];
|
|
16
|
+
let markedPath = path;
|
|
9
17
|
for (let i = 0; ; ) {
|
|
10
18
|
let replaced = false;
|
|
11
|
-
|
|
19
|
+
markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
|
|
12
20
|
const mark = `@\\${i}`;
|
|
13
21
|
groups[i] = [mark, m];
|
|
14
22
|
i++;
|
|
@@ -19,7 +27,7 @@ var Trie = class {
|
|
|
19
27
|
break;
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
|
-
const tokens =
|
|
30
|
+
const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
23
31
|
for (let i = groups.length - 1; i >= 0; i--) {
|
|
24
32
|
const [mark] = groups[i];
|
|
25
33
|
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
@@ -29,8 +37,8 @@ var Trie = class {
|
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
|
-
this.#root.insert(tokens, index, paramAssoc, this.#context,
|
|
33
|
-
|
|
40
|
+
this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
|
|
41
|
+
this.paths[path] = [this.#index++, paramAssoc];
|
|
34
42
|
}
|
|
35
43
|
buildRegExp() {
|
|
36
44
|
let regexp = this.#root.buildRegExpStr();
|
|
@@ -2,76 +2,51 @@
|
|
|
2
2
|
import { METHOD_NAME_ALL } from "../../router.js";
|
|
3
3
|
import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
|
|
4
4
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
5
|
-
var
|
|
6
|
-
for (const _ in children) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
return false;
|
|
10
|
-
};
|
|
5
|
+
var order = 0;
|
|
11
6
|
var Node = class _Node {
|
|
12
|
-
#methods;
|
|
13
|
-
#children;
|
|
14
|
-
#patterns;
|
|
15
|
-
#
|
|
7
|
+
#methods = [];
|
|
8
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
9
|
+
#patterns = [];
|
|
10
|
+
#pattern;
|
|
16
11
|
#params = emptyParams;
|
|
17
|
-
constructor(method, handler, children) {
|
|
18
|
-
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
19
|
-
this.#methods = [];
|
|
20
|
-
if (method && handler) {
|
|
21
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
22
|
-
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
23
|
-
this.#methods = [m];
|
|
24
|
-
}
|
|
25
|
-
this.#patterns = [];
|
|
26
|
-
}
|
|
27
12
|
insert(method, path, handler) {
|
|
28
|
-
this.#order = ++this.#order;
|
|
29
13
|
let curNode = this;
|
|
30
14
|
const parts = splitRoutingPath(path);
|
|
31
|
-
const possibleKeys =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const nextP = parts[i
|
|
35
|
-
const pattern = getPattern(p, nextP);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
continue;
|
|
15
|
+
const possibleKeys = /* @__PURE__ */ new Set();
|
|
16
|
+
let i = 0;
|
|
17
|
+
for (const p of parts) {
|
|
18
|
+
const nextP = parts[++i];
|
|
19
|
+
const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
|
|
20
|
+
const isParam = Array.isArray(pattern);
|
|
21
|
+
const key = isParam ? pattern[0] : pattern || p;
|
|
22
|
+
const child = curNode.#children[key] ||= new _Node();
|
|
23
|
+
if (pattern && !child.#pattern) {
|
|
24
|
+
child.#pattern = pattern;
|
|
25
|
+
curNode.#patterns.push(child);
|
|
43
26
|
}
|
|
44
|
-
curNode
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
possibleKeys.push(pattern[1]);
|
|
27
|
+
curNode = child;
|
|
28
|
+
if (isParam) {
|
|
29
|
+
possibleKeys.add(pattern[1]);
|
|
48
30
|
}
|
|
49
|
-
curNode = curNode.#children[key];
|
|
50
31
|
}
|
|
51
32
|
curNode.#methods.push({
|
|
52
33
|
[method]: {
|
|
53
34
|
handler,
|
|
54
|
-
possibleKeys: possibleKeys
|
|
55
|
-
score:
|
|
35
|
+
possibleKeys: [...possibleKeys],
|
|
36
|
+
score: ++order
|
|
56
37
|
}
|
|
57
38
|
});
|
|
58
|
-
return curNode;
|
|
59
39
|
}
|
|
60
40
|
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
61
41
|
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
62
42
|
const m = node.#methods[i];
|
|
63
43
|
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
64
|
-
|
|
65
|
-
if (handlerSet !== void 0) {
|
|
44
|
+
if (handlerSet) {
|
|
66
45
|
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
67
46
|
handlerSets.push(handlerSet);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const processed = processedSet[handlerSet.score];
|
|
72
|
-
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
73
|
-
processedSet[handlerSet.score] = true;
|
|
74
|
-
}
|
|
47
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
48
|
+
const key = handlerSet.possibleKeys[i2];
|
|
49
|
+
handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
|
|
75
50
|
}
|
|
76
51
|
}
|
|
77
52
|
}
|
|
@@ -103,33 +78,33 @@ var Node = class _Node {
|
|
|
103
78
|
tempNodes.push(nextNode);
|
|
104
79
|
}
|
|
105
80
|
}
|
|
106
|
-
for (
|
|
107
|
-
const pattern =
|
|
81
|
+
for (const child of node.#patterns) {
|
|
82
|
+
const pattern = child.#pattern;
|
|
108
83
|
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
109
|
-
if (pattern === "
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
84
|
+
if (typeof pattern === "string") {
|
|
85
|
+
if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
|
|
86
|
+
this.#pushHandlerSets(handlerSets, child, method, node.#params);
|
|
87
|
+
if (pattern === "*") {
|
|
88
|
+
child.#params = params;
|
|
89
|
+
tempNodes.push(child);
|
|
90
|
+
}
|
|
115
91
|
}
|
|
116
92
|
continue;
|
|
117
93
|
}
|
|
118
|
-
const [
|
|
119
|
-
if (!part &&
|
|
94
|
+
const [, name, matcher] = pattern;
|
|
95
|
+
if (!part && matcher === true) {
|
|
120
96
|
continue;
|
|
121
97
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
partOffsets = new Array(len);
|
|
98
|
+
if (matcher !== true) {
|
|
99
|
+
if (!partOffsets) {
|
|
100
|
+
partOffsets = [];
|
|
126
101
|
let offset = path[0] === "/" ? 1 : 0;
|
|
127
102
|
for (let p = 0; p < len; p++) {
|
|
128
103
|
partOffsets[p] = offset;
|
|
129
104
|
offset += parts[p].length + 1;
|
|
130
105
|
}
|
|
131
106
|
}
|
|
132
|
-
const restPathString = path.
|
|
107
|
+
const restPathString = path.slice(partOffsets[i]);
|
|
133
108
|
const m = matcher.exec(restPathString);
|
|
134
109
|
if (m) {
|
|
135
110
|
params[name] = m[0];
|
|
@@ -143,11 +118,12 @@ var Node = class _Node {
|
|
|
143
118
|
params
|
|
144
119
|
);
|
|
145
120
|
}
|
|
146
|
-
|
|
121
|
+
for (const _ in child.#children) {
|
|
147
122
|
child.#params = params;
|
|
148
|
-
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
123
|
+
const componentCount = m[0].match(/\//g)?.length ?? 0;
|
|
149
124
|
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
150
125
|
targetCurNodes.push(child);
|
|
126
|
+
break;
|
|
151
127
|
}
|
|
152
128
|
continue;
|
|
153
129
|
}
|
|
@@ -175,7 +151,7 @@ var Node = class _Node {
|
|
|
175
151
|
const shifted = curNodesQueue.shift();
|
|
176
152
|
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
177
153
|
}
|
|
178
|
-
if (handlerSets
|
|
154
|
+
if (handlerSets[1]) {
|
|
179
155
|
handlerSets.sort((a, b) => {
|
|
180
156
|
return a.score - b.score;
|
|
181
157
|
});
|
|
@@ -3,19 +3,11 @@ import { checkOptionalParameter } from "../../utils/url.js";
|
|
|
3
3
|
import { Node } from "./node.js";
|
|
4
4
|
var TrieRouter = class {
|
|
5
5
|
name = "TrieRouter";
|
|
6
|
-
#node;
|
|
7
|
-
constructor() {
|
|
8
|
-
this.#node = new Node();
|
|
9
|
-
}
|
|
6
|
+
#node = new Node();
|
|
10
7
|
add(method, path, handler) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
for (let i = 0, len = results.length; i < len; i++) {
|
|
14
|
-
this.#node.insert(method, results[i], handler);
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
8
|
+
for (const result of checkOptionalParameter(path) || [path]) {
|
|
9
|
+
this.#node.insert(method, result, handler);
|
|
17
10
|
}
|
|
18
|
-
this.#node.insert(method, path, handler);
|
|
19
11
|
}
|
|
20
12
|
match(method, path) {
|
|
21
13
|
return this.#node.search(method, path);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/router.ts
|
|
2
2
|
var METHOD_NAME_ALL = "ALL";
|
|
3
3
|
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
4
|
-
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
4
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch", "query"];
|
|
5
5
|
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
6
6
|
var UnsupportedPathError = class extends Error {
|
|
7
7
|
};
|
|
@@ -10,7 +10,7 @@ import type { HasRequiredKeys } from '../utils/types';
|
|
|
10
10
|
type MethodNameAll = `$${typeof METHOD_NAME_ALL_LOWERCASE}`;
|
|
11
11
|
/**
|
|
12
12
|
* Type representing all standard HTTP methods prefixed with '$'
|
|
13
|
-
* e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch'
|
|
13
|
+
* e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch' | '$query'
|
|
14
14
|
*/
|
|
15
15
|
type StandardMethods = `$${(typeof METHODS)[number]}`;
|
|
16
16
|
/**
|
|
@@ -323,6 +323,10 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
323
323
|
* c.header('X-Message', 'Hello!')
|
|
324
324
|
* c.header('Content-Type', 'text/plain')
|
|
325
325
|
*
|
|
326
|
+
* // Append multiple headers using the append option (e.g. Vary)
|
|
327
|
+
* c.header('Vary', 'Accept-Encoding', { append: true })
|
|
328
|
+
* c.header('Vary', 'User-Agent', { append: true })
|
|
329
|
+
*
|
|
326
330
|
* return c.body('Thank you for coming')
|
|
327
331
|
* })
|
|
328
332
|
* ```
|