repocairn 0.1.2 → 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.
Files changed (233) hide show
  1. package/README.md +13 -2
  2. package/dist/graphify-source.d.ts +17 -0
  3. package/dist/graphify-source.js +87 -0
  4. package/dist/graphify-source.js.map +1 -0
  5. package/dist/index-command.js +3 -1
  6. package/dist/index-command.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/indexer.d.ts +1 -0
  11. package/dist/indexer.js +2 -1
  12. package/dist/indexer.js.map +1 -1
  13. package/dist/signals.d.ts +13 -0
  14. package/dist/signals.js +84 -0
  15. package/dist/signals.js.map +1 -0
  16. package/dist/tree-sitter-extract.js +134 -1
  17. package/dist/tree-sitter-extract.js.map +1 -1
  18. package/node_modules/body-parser/node_modules/content-type/README.md +2 -0
  19. package/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
  20. package/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
  21. package/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
  22. package/node_modules/body-parser/node_modules/content-type/package.json +1 -1
  23. package/node_modules/eventsource-parser/dist/index.cjs +2 -2
  24. package/node_modules/eventsource-parser/dist/index.cjs.map +1 -1
  25. package/node_modules/eventsource-parser/dist/index.js +2 -2
  26. package/node_modules/eventsource-parser/dist/index.js.map +1 -1
  27. package/node_modules/eventsource-parser/package.json +1 -1
  28. package/node_modules/eventsource-parser/src/parse.ts +4 -2
  29. package/node_modules/express-rate-limit/dist/index.cjs +6 -1
  30. package/node_modules/express-rate-limit/dist/index.mjs +6 -1
  31. package/node_modules/express-rate-limit/package.json +6 -6
  32. package/node_modules/fast-uri/index.js +37 -1
  33. package/node_modules/fast-uri/package.json +1 -1
  34. package/node_modules/fast-uri/test/security.test.js +136 -0
  35. package/node_modules/hono/dist/cjs/client/client.js +3 -3
  36. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  37. package/node_modules/hono/dist/cjs/context.js +32 -13
  38. package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
  39. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  40. package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
  41. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
  42. package/node_modules/hono/dist/cjs/jsx/intrinsic-element/components.js +1 -1
  43. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  44. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  45. package/node_modules/hono/dist/cjs/middleware/cors/index.js +17 -14
  46. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  47. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +47 -1
  48. package/node_modules/hono/dist/cjs/middleware/etag/index.js +6 -3
  49. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  50. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  51. package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
  52. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  53. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  54. package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
  55. package/node_modules/hono/dist/cjs/request.js +6 -8
  56. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  57. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  58. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  59. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  60. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  61. package/node_modules/hono/dist/cjs/router/trie-router/node.js +44 -68
  62. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  63. package/node_modules/hono/dist/cjs/router.js +1 -1
  64. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
  65. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  66. package/node_modules/hono/dist/cjs/utils/stream.js +5 -2
  67. package/node_modules/hono/dist/cjs/utils/url.js +9 -9
  68. package/node_modules/hono/dist/client/client.js +3 -3
  69. package/node_modules/hono/dist/client/utils.js +1 -1
  70. package/node_modules/hono/dist/context.js +32 -13
  71. package/node_modules/hono/dist/helper/proxy/index.js +4 -0
  72. package/node_modules/hono/dist/hono-base.js +3 -2
  73. package/node_modules/hono/dist/jsx/base.js +27 -23
  74. package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
  75. package/node_modules/hono/dist/jsx/intrinsic-element/components.js +1 -1
  76. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  77. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  78. package/node_modules/hono/dist/middleware/cors/index.js +17 -14
  79. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  80. package/node_modules/hono/dist/middleware/etag/digest.js +47 -1
  81. package/node_modules/hono/dist/middleware/etag/index.js +6 -3
  82. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  83. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  84. package/node_modules/hono/dist/middleware/language/language.js +10 -6
  85. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  86. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  87. package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
  88. package/node_modules/hono/dist/request.js +7 -9
  89. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  90. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  91. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  92. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  93. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  94. package/node_modules/hono/dist/router/trie-router/node.js +44 -68
  95. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  96. package/node_modules/hono/dist/router.js +1 -1
  97. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  98. package/node_modules/hono/dist/types/context.d.ts +4 -0
  99. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  100. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  101. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  102. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  103. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  104. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  105. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  106. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  107. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  108. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  109. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  110. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  111. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  112. package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
  113. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  114. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  115. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  116. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  117. package/node_modules/hono/dist/types/router.d.ts +1 -1
  118. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  119. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  120. package/node_modules/hono/dist/utils/cookie.js +4 -3
  121. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  122. package/node_modules/hono/dist/utils/stream.js +5 -2
  123. package/node_modules/hono/dist/utils/url.js +7 -8
  124. package/node_modules/hono/package.json +10 -3
  125. package/node_modules/ip-address/README.md +163 -149
  126. package/node_modules/ip-address/dist/address-error.d.ts +11 -0
  127. package/node_modules/ip-address/dist/address-error.js.map +1 -1
  128. package/node_modules/ip-address/dist/common.d.ts +6 -0
  129. package/node_modules/ip-address/dist/common.js +17 -1
  130. package/node_modules/ip-address/dist/common.js.map +1 -1
  131. package/node_modules/ip-address/dist/ipv4.d.ts +22 -6
  132. package/node_modules/ip-address/dist/ipv4.js +25 -18
  133. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  134. package/node_modules/ip-address/dist/ipv6.d.ts +19 -5
  135. package/node_modules/ip-address/dist/ipv6.js +61 -33
  136. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  137. package/node_modules/ip-address/package.json +5 -3
  138. package/node_modules/jose/README.md +13 -13
  139. package/node_modules/jose/dist/types/index.d.ts +6 -5
  140. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
  141. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +8 -19
  142. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
  143. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +8 -19
  144. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
  145. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +21 -21
  146. package/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
  147. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
  148. package/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
  149. package/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
  150. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
  151. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
  152. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
  153. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
  154. package/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
  155. package/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
  156. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
  157. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +11 -34
  158. package/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
  159. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
  160. package/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
  161. package/node_modules/jose/dist/types/key/export.d.ts +0 -14
  162. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
  163. package/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
  164. package/node_modules/jose/dist/types/key/import.d.ts +18 -28
  165. package/node_modules/jose/dist/types/types.d.ts +243 -224
  166. package/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
  167. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
  168. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
  169. package/node_modules/jose/dist/types/util/errors.d.ts +128 -121
  170. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +4 -22
  171. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
  172. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
  173. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +23 -3
  174. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +70 -82
  175. package/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
  176. package/node_modules/jose/dist/webapi/jwks/local.js +32 -73
  177. package/node_modules/jose/dist/webapi/jwks/remote.js +19 -28
  178. package/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
  179. package/node_modules/jose/dist/webapi/jws/compact/verify.js +4 -16
  180. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -65
  181. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
  182. package/node_modules/jose/dist/webapi/jws/general/sign.js +19 -15
  183. package/node_modules/jose/dist/webapi/jws/general/verify.js +29 -9
  184. package/node_modules/jose/dist/webapi/jwt/decrypt.js +5 -5
  185. package/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
  186. package/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
  187. package/node_modules/jose/dist/webapi/jwt/verify.js +6 -6
  188. package/node_modules/jose/dist/webapi/key/export.js +37 -4
  189. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +33 -82
  190. package/node_modules/jose/dist/webapi/key/generate_secret.js +2 -2
  191. package/node_modules/jose/dist/webapi/key/import.js +8 -8
  192. package/node_modules/jose/dist/webapi/lib/asn1.js +53 -122
  193. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
  194. package/node_modules/jose/dist/webapi/lib/content_encryption.js +34 -109
  195. package/node_modules/jose/dist/webapi/lib/crypto_key.js +18 -126
  196. package/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
  197. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -1
  198. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +107 -0
  199. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +186 -0
  200. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +114 -0
  201. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +8 -98
  202. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +73 -0
  203. package/node_modules/jose/dist/webapi/lib/jws_sign.js +74 -0
  204. package/node_modules/jose/dist/webapi/lib/jws_verify.js +107 -0
  205. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +68 -109
  206. package/node_modules/jose/dist/webapi/lib/key.js +132 -0
  207. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +10 -0
  208. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
  209. package/node_modules/jose/dist/webapi/lib/key_management.js +162 -92
  210. package/node_modules/jose/dist/webapi/lib/options.js +48 -0
  211. package/node_modules/jose/dist/webapi/lib/signing.js +14 -56
  212. package/node_modules/jose/dist/webapi/lib/type_checks.js +13 -18
  213. package/node_modules/jose/dist/webapi/util/base64url.js +13 -4
  214. package/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
  215. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
  216. package/node_modules/jose/dist/webapi/util/errors.js +1 -1
  217. package/node_modules/jose/package.json +2 -4
  218. package/node_modules/type-is/node_modules/content-type/README.md +2 -0
  219. package/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
  220. package/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
  221. package/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
  222. package/node_modules/type-is/node_modules/content-type/package.json +1 -1
  223. package/package.json +5 -3
  224. package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  225. package/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  226. package/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  227. package/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  228. package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  229. package/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  230. package/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  231. package/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  232. package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
  233. package/node_modules/jose/dist/webapi/lib/validate_crit.js +0 -33
@@ -32,6 +32,9 @@ var etag = (options) => {
32
32
  return async function etag2(c, next) {
33
33
  const ifNoneMatch = c.req.header("If-None-Match") ?? null;
34
34
  await next();
35
+ if (!(c.req.method === "GET" || c.req.method === "HEAD" || c.req.method === "QUERY") || !c.res.ok) {
36
+ return;
37
+ }
35
38
  const res = c.res;
36
39
  let etag3 = res.headers.get("ETag");
37
40
  if (!etag3) {
@@ -48,7 +51,7 @@ var etag = (options) => {
48
51
  }
49
52
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
50
53
  }
51
- const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD") && res.ok : etagMatches(etag3, ifNoneMatch);
54
+ const matched = ifNoneMatch === "*" || etagMatches(etag3, ifNoneMatch);
52
55
  if (matched) {
53
56
  c.res = new Response(null, {
54
57
  status: 304,
@@ -57,11 +60,11 @@ var etag = (options) => {
57
60
  ETag: etag3
58
61
  }
59
62
  });
60
- c.res.headers.forEach((_, key) => {
63
+ for (const key of Array.from(c.res.headers.keys())) {
61
64
  if (retainedHeaders.indexOf(key.toLowerCase()) === -1) {
62
65
  c.res.headers.delete(key);
63
66
  }
64
- });
67
+ }
65
68
  } else {
66
69
  c.res.headers.set("ETag", etag3);
67
70
  }
@@ -24,7 +24,8 @@ var jwk = (options, init) => {
24
24
  res: unauthorizedResponse({
25
25
  ctx,
26
26
  error: "invalid_request",
27
- errDescription
27
+ errDescription,
28
+ realm: options.realm
28
29
  })
29
30
  });
30
31
  } else {
@@ -62,7 +63,8 @@ var jwk = (options, init) => {
62
63
  res: unauthorizedResponse({
63
64
  ctx,
64
65
  error: "invalid_request",
65
- errDescription
66
+ errDescription,
67
+ realm: options.realm
66
68
  })
67
69
  });
68
70
  }
@@ -89,7 +91,8 @@ var jwk = (options, init) => {
89
91
  ctx,
90
92
  error: "invalid_token",
91
93
  statusText: "Unauthorized",
92
- errDescription: "token verification failure"
94
+ errDescription: "token verification failure",
95
+ realm: options.realm
93
96
  }),
94
97
  cause
95
98
  });
@@ -99,11 +102,13 @@ var jwk = (options, init) => {
99
102
  };
100
103
  };
101
104
  function unauthorizedResponse(opts) {
105
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
106
+ const errDescription = opts.errDescription.replace(/"/g, '\\"');
102
107
  return new Response("Unauthorized", {
103
108
  status: 401,
104
109
  statusText: opts.statusText,
105
110
  headers: {
106
- "WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
111
+ "WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
107
112
  }
108
113
  });
109
114
  }
@@ -27,7 +27,8 @@ var jwt = (options) => {
27
27
  res: unauthorizedResponse({
28
28
  ctx,
29
29
  error: "invalid_request",
30
- errDescription
30
+ errDescription,
31
+ realm: options.realm
31
32
  })
32
33
  });
33
34
  } else {
@@ -62,7 +63,8 @@ var jwt = (options) => {
62
63
  res: unauthorizedResponse({
63
64
  ctx,
64
65
  error: "invalid_request",
65
- errDescription
66
+ errDescription,
67
+ realm: options.realm
66
68
  })
67
69
  });
68
70
  }
@@ -83,7 +85,8 @@ var jwt = (options) => {
83
85
  ctx,
84
86
  error: "invalid_token",
85
87
  statusText: "Unauthorized",
86
- errDescription: "token verification failure"
88
+ errDescription: "token verification failure",
89
+ realm: options.realm
87
90
  }),
88
91
  cause
89
92
  });
@@ -93,11 +96,13 @@ var jwt = (options) => {
93
96
  };
94
97
  };
95
98
  function unauthorizedResponse(opts) {
99
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
100
+ const errDescription = opts.errDescription.replace(/"/g, '\\"');
96
101
  return new Response("Unauthorized", {
97
102
  status: 401,
98
103
  statusText: opts.statusText,
99
104
  headers: {
100
- "WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
105
+ "WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
101
106
  }
102
107
  });
103
108
  }
@@ -39,14 +39,18 @@ var normalizeLanguage = (lang, options) => {
39
39
  if (exactIndex !== -1) {
40
40
  return options.supportedLanguages[exactIndex];
41
41
  }
42
- const parts = compLang.split("-");
43
- for (let i = parts.length - 1; i > 0; i--) {
44
- const candidate = parts.slice(0, i).join("-");
45
- const prefixIndex = compSupported.indexOf(candidate);
46
- if (prefixIndex !== -1) {
47
- return options.supportedLanguages[prefixIndex];
42
+ let longestMatchIndex = -1;
43
+ let longestMatchLength = -1;
44
+ for (let i = 0; i < compSupported.length; i++) {
45
+ const candidate = compSupported[i];
46
+ if (candidate.length < compLang.length && candidate.length > longestMatchLength && compLang.startsWith(candidate) && compLang[candidate.length] === "-") {
47
+ longestMatchIndex = i;
48
+ longestMatchLength = candidate.length;
48
49
  }
49
50
  }
51
+ if (longestMatchIndex !== -1) {
52
+ return options.supportedLanguages[longestMatchIndex];
53
+ }
50
54
  return void 0;
51
55
  } catch {
52
56
  return void 0;
@@ -0,0 +1,68 @@
1
+ // src/middleware/method-not-allowed/index.ts
2
+ import { basePath, matchedRoutes } from "../../helper/route/index.js";
3
+ import { METHOD_NAME_ALL } from "../../router.js";
4
+ import { TrieRouter } from "../../router/trie-router/index.js";
5
+ var methodNotAllowed = (options) => {
6
+ let methodRouter;
7
+ return async function methodNotAllowed2(c, next) {
8
+ const routeIndex = c.req.routeIndex;
9
+ await next();
10
+ if (c.res.status !== 404) {
11
+ return;
12
+ }
13
+ if (c.error) {
14
+ return;
15
+ }
16
+ if (!methodRouter) {
17
+ const methodsByPath = /* @__PURE__ */ new Map();
18
+ for (const route of options.app.routes) {
19
+ if (route.method === METHOD_NAME_ALL || route.method === "HEAD") {
20
+ continue;
21
+ }
22
+ const methods2 = methodsByPath.get(route.path) ?? /* @__PURE__ */ new Set();
23
+ methods2.add(route.method);
24
+ if (route.method === "GET") {
25
+ methods2.add("HEAD");
26
+ }
27
+ methodsByPath.set(route.path, methods2);
28
+ }
29
+ methodRouter = new TrieRouter();
30
+ for (const [path, methods2] of methodsByPath) {
31
+ methodRouter.add(METHOD_NAME_ALL, path, [...methods2]);
32
+ }
33
+ }
34
+ let requestPath = c.req.path;
35
+ const routes = matchedRoutes(c);
36
+ const currentRoute = routes[routeIndex];
37
+ const sourceRoute = options.app.routes.find((route) => route.handler === methodNotAllowed2);
38
+ if (currentRoute && sourceRoute) {
39
+ const currentBasePathParts = basePath(c, routeIndex).split("/").filter(Boolean);
40
+ const sourceBasePathLength = sourceRoute.basePath.split("/").filter(Boolean).length;
41
+ const mountBasePathParts = currentBasePathParts.slice(
42
+ 0,
43
+ currentBasePathParts.length - sourceBasePathLength
44
+ );
45
+ if (mountBasePathParts.length > 0) {
46
+ const mountBasePath = `/${mountBasePathParts.join("/")}`;
47
+ requestPath = c.req.path.slice(mountBasePath.length) || "/";
48
+ }
49
+ }
50
+ const allowedMethods = /* @__PURE__ */ new Set();
51
+ for (const [methods2] of methodRouter.match(METHOD_NAME_ALL, requestPath)[0]) {
52
+ for (const method of methods2) {
53
+ allowedMethods.add(method);
54
+ }
55
+ }
56
+ if (allowedMethods.size === 0 || allowedMethods.has(c.req.method)) {
57
+ return;
58
+ }
59
+ c.res.headers.delete("Allow");
60
+ c.res.headers.delete("Content-Length");
61
+ const methods = [...allowedMethods];
62
+ const allow = methods.join(", ");
63
+ c.res = options.onMethodNotAllowed ? await options.onMethodNotAllowed(c, methods) : c.text("Method Not Allowed", 405, { Allow: allow });
64
+ };
65
+ };
66
+ export {
67
+ methodNotAllowed
68
+ };
@@ -1,10 +1,12 @@
1
1
  // src/middleware/pretty-json/index.ts
2
+ var jsonContentTypeRegex = /^application\/(?:[a-z0-9._-]+\+)?json(?=$|[;\s])/i;
2
3
  var prettyJSON = (options) => {
3
4
  const targetQuery = options?.query ?? "pretty";
4
5
  return async function prettyJSON2(c, next) {
5
6
  const pretty = options?.force || c.req.query(targetQuery) || c.req.query(targetQuery) === "";
6
7
  await next();
7
- if (pretty && c.res.headers.get("Content-Type")?.startsWith("application/json")) {
8
+ const contentType = c.res.headers.get("Content-Type");
9
+ if (pretty && contentType && jsonContentTypeRegex.test(contentType)) {
8
10
  const obj = await c.res.json();
9
11
  c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res);
10
12
  }
@@ -137,14 +137,17 @@ function getPermissionsPolicyDirectives(policy) {
137
137
  return Object.entries(policy).map(([directive, value]) => {
138
138
  const kebabDirective = camelToKebab(directive);
139
139
  if (typeof value === "boolean") {
140
- return `${kebabDirective}=${value ? "*" : "none"}`;
140
+ return `${kebabDirective}=${value ? "*" : "()"}`;
141
141
  }
142
142
  if (Array.isArray(value)) {
143
143
  if (value.length === 0) {
144
144
  return `${kebabDirective}=()`;
145
145
  }
146
- if (value.length === 1 && (value[0] === "*" || value[0] === "none")) {
147
- return `${kebabDirective}=${value[0]}`;
146
+ if (value.length === 1 && value[0] === "*") {
147
+ return `${kebabDirective}=*`;
148
+ }
149
+ if (value.length === 1 && value[0] === "none") {
150
+ return `${kebabDirective}=()`;
148
151
  }
149
152
  const allowlist = value.map((item) => ["self", "src"].includes(item) ? item : `"${item}"`);
150
153
  return `${kebabDirective}=(${allowlist.join(" ")})`;
@@ -2,8 +2,7 @@
2
2
  import { HTTPException } from "./http-exception.js";
3
3
  import { GET_MATCH_RESULT } from "./request/constants.js";
4
4
  import { parseBody } from "./utils/body.js";
5
- import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from "./utils/url.js";
6
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
5
+ import { getQueryParam, getQueryParams, tryDecodeURIComponent } from "./utils/url.js";
7
6
  var HonoRequest = class {
8
7
  /**
9
8
  * `.raw` can get the raw Request object.
@@ -42,7 +41,6 @@ var HonoRequest = class {
42
41
  this.raw = request;
43
42
  this.path = path;
44
43
  this.#matchResult = matchResult;
45
- this.#validatedData = {};
46
44
  }
47
45
  param(key) {
48
46
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
@@ -50,7 +48,7 @@ var HonoRequest = class {
50
48
  #getDecodedParam(key) {
51
49
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
52
50
  const param = this.#getParamValue(paramKey);
53
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
51
+ return param && tryDecodeURIComponent(param);
54
52
  }
55
53
  #getAllDecodedParams() {
56
54
  const decoded = {};
@@ -58,7 +56,7 @@ var HonoRequest = class {
58
56
  for (const key of keys) {
59
57
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
60
58
  if (value !== void 0) {
61
- decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
59
+ decoded[key] = tryDecodeURIComponent(value);
62
60
  }
63
61
  }
64
62
  return decoded;
@@ -91,8 +89,7 @@ var HonoRequest = class {
91
89
  if (cachedBody) {
92
90
  return cachedBody;
93
91
  }
94
- const anyCachedKey = Object.keys(bodyCache)[0];
95
- if (anyCachedKey) {
92
+ for (const anyCachedKey in bodyCache) {
96
93
  return bodyCache[anyCachedKey].then((body) => {
97
94
  if (anyCachedKey === "json") {
98
95
  body = JSON.stringify(body);
@@ -195,10 +192,11 @@ var HonoRequest = class {
195
192
  * @param data - The validated data to add.
196
193
  */
197
194
  addValidatedData(target, data) {
198
- this.#validatedData[target] = data;
195
+ ;
196
+ (this.#validatedData ??= {})[target] = data;
199
197
  }
200
198
  valid(target) {
201
- return this.#validatedData[target];
199
+ return this.#validatedData?.[target];
202
200
  }
203
201
  /**
204
202
  * `.url()` can get the request url strings.
@@ -29,7 +29,8 @@ var LinearRouter = class {
29
29
  }
30
30
  } else if (hasStar && !hasLabel) {
31
31
  const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
32
- const parts = (endsWithStar ? routePath.slice(0, -2) : routePath).split(splitByStarRe);
32
+ const endsWithSlashStar = routePath.endsWith("/*");
33
+ const parts = (endsWithStar ? routePath.slice(0, endsWithSlashStar ? -2 : -1) : routePath).split(splitByStarRe);
33
34
  const lastIndex = parts.length - 1;
34
35
  for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
35
36
  const part = parts[j];
@@ -39,7 +40,11 @@ var LinearRouter = class {
39
40
  }
40
41
  pos += part.length;
41
42
  if (j === lastIndex) {
42
- if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
43
+ if (endsWithSlashStar) {
44
+ if (pos !== path.length && path.charCodeAt(pos) !== 47) {
45
+ continue ROUTES_LOOP;
46
+ }
47
+ } else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
43
48
  continue ROUTES_LOOP;
44
49
  }
45
50
  } else {
@@ -5,10 +5,8 @@ var PatternRouter = class {
5
5
  name = "PatternRouter";
6
6
  #routes = [];
7
7
  add(method, path, handler) {
8
- const endsWithWildcard = path.at(-1) === "*";
9
- if (endsWithWildcard) {
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, pathErrorCheckOnly) {
31
- if (tokens.length === 0) {
32
- if (this.#index !== void 0) {
33
- throw PATH_ERROR;
34
- }
35
- if (pathErrorCheckOnly) {
36
- return;
37
- }
38
- this.#index = index;
39
- return;
40
- }
41
- const [token, ...restTokens] = tokens;
42
- const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
43
- let node;
44
- if (pattern) {
45
- const name = pattern[1];
46
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
47
- if (name && pattern[2]) {
48
- if (regexpStr === ".*") {
49
- throw PATH_ERROR;
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
- node = this.#children[regexpStr];
57
- if (!node) {
58
- if (Object.keys(this.#children).some(
59
- (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
60
- )) {
61
- throw PATH_ERROR;
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
- node.#varIndex = context.varIndex++;
67
+ nextNode.#varIndex ??= context.varIndex++;
68
+ paramMap.push([name, nextNode.#varIndex]);
69
69
  }
70
- }
71
- if (!pathErrorCheckOnly && name !== "") {
72
- paramMap.push([name, node.#varIndex]);
73
- }
74
- } else {
75
- node = this.#children[token];
76
- if (!node) {
77
- if (Object.keys(this.#children).some(
78
- (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
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.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
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
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
95
- });
96
- if (typeof this.#index === "number") {
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) {