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.
Files changed (231) hide show
  1. package/README.md +6 -0
  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 +1 -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/node_modules/body-parser/node_modules/content-type/README.md +2 -0
  17. package/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
  18. package/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
  19. package/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
  20. package/node_modules/body-parser/node_modules/content-type/package.json +1 -1
  21. package/node_modules/eventsource-parser/dist/index.cjs +2 -2
  22. package/node_modules/eventsource-parser/dist/index.cjs.map +1 -1
  23. package/node_modules/eventsource-parser/dist/index.js +2 -2
  24. package/node_modules/eventsource-parser/dist/index.js.map +1 -1
  25. package/node_modules/eventsource-parser/package.json +1 -1
  26. package/node_modules/eventsource-parser/src/parse.ts +4 -2
  27. package/node_modules/express-rate-limit/dist/index.cjs +6 -1
  28. package/node_modules/express-rate-limit/dist/index.mjs +6 -1
  29. package/node_modules/express-rate-limit/package.json +6 -6
  30. package/node_modules/fast-uri/index.js +37 -1
  31. package/node_modules/fast-uri/package.json +1 -1
  32. package/node_modules/fast-uri/test/security.test.js +136 -0
  33. package/node_modules/hono/dist/cjs/client/client.js +3 -3
  34. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  35. package/node_modules/hono/dist/cjs/context.js +32 -13
  36. package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
  37. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  38. package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
  39. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
  40. package/node_modules/hono/dist/cjs/jsx/intrinsic-element/components.js +1 -1
  41. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  42. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  43. package/node_modules/hono/dist/cjs/middleware/cors/index.js +17 -14
  44. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  45. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +47 -1
  46. package/node_modules/hono/dist/cjs/middleware/etag/index.js +6 -3
  47. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  48. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  49. package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
  50. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  51. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  52. package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
  53. package/node_modules/hono/dist/cjs/request.js +6 -8
  54. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  55. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  56. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  57. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  58. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  59. package/node_modules/hono/dist/cjs/router/trie-router/node.js +44 -68
  60. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  61. package/node_modules/hono/dist/cjs/router.js +1 -1
  62. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
  63. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  64. package/node_modules/hono/dist/cjs/utils/stream.js +5 -2
  65. package/node_modules/hono/dist/cjs/utils/url.js +9 -9
  66. package/node_modules/hono/dist/client/client.js +3 -3
  67. package/node_modules/hono/dist/client/utils.js +1 -1
  68. package/node_modules/hono/dist/context.js +32 -13
  69. package/node_modules/hono/dist/helper/proxy/index.js +4 -0
  70. package/node_modules/hono/dist/hono-base.js +3 -2
  71. package/node_modules/hono/dist/jsx/base.js +27 -23
  72. package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
  73. package/node_modules/hono/dist/jsx/intrinsic-element/components.js +1 -1
  74. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  75. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  76. package/node_modules/hono/dist/middleware/cors/index.js +17 -14
  77. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  78. package/node_modules/hono/dist/middleware/etag/digest.js +47 -1
  79. package/node_modules/hono/dist/middleware/etag/index.js +6 -3
  80. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  81. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  82. package/node_modules/hono/dist/middleware/language/language.js +10 -6
  83. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  84. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  85. package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
  86. package/node_modules/hono/dist/request.js +7 -9
  87. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  88. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  89. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  90. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  91. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  92. package/node_modules/hono/dist/router/trie-router/node.js +44 -68
  93. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  94. package/node_modules/hono/dist/router.js +1 -1
  95. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  96. package/node_modules/hono/dist/types/context.d.ts +4 -0
  97. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  98. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  99. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  100. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  101. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  102. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  103. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  104. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  105. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  106. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  107. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  108. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  109. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  110. package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
  111. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  112. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  113. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  114. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  115. package/node_modules/hono/dist/types/router.d.ts +1 -1
  116. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  117. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  118. package/node_modules/hono/dist/utils/cookie.js +4 -3
  119. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  120. package/node_modules/hono/dist/utils/stream.js +5 -2
  121. package/node_modules/hono/dist/utils/url.js +7 -8
  122. package/node_modules/hono/package.json +10 -3
  123. package/node_modules/ip-address/README.md +163 -149
  124. package/node_modules/ip-address/dist/address-error.d.ts +11 -0
  125. package/node_modules/ip-address/dist/address-error.js.map +1 -1
  126. package/node_modules/ip-address/dist/common.d.ts +6 -0
  127. package/node_modules/ip-address/dist/common.js +17 -1
  128. package/node_modules/ip-address/dist/common.js.map +1 -1
  129. package/node_modules/ip-address/dist/ipv4.d.ts +22 -6
  130. package/node_modules/ip-address/dist/ipv4.js +25 -18
  131. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  132. package/node_modules/ip-address/dist/ipv6.d.ts +19 -5
  133. package/node_modules/ip-address/dist/ipv6.js +61 -33
  134. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  135. package/node_modules/ip-address/package.json +5 -3
  136. package/node_modules/jose/README.md +13 -13
  137. package/node_modules/jose/dist/types/index.d.ts +6 -5
  138. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
  139. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +8 -19
  140. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
  141. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +8 -19
  142. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
  143. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +21 -21
  144. package/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
  145. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
  146. package/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
  147. package/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
  148. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
  149. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
  150. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
  151. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
  152. package/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
  153. package/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
  154. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
  155. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +11 -34
  156. package/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
  157. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
  158. package/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
  159. package/node_modules/jose/dist/types/key/export.d.ts +0 -14
  160. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
  161. package/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
  162. package/node_modules/jose/dist/types/key/import.d.ts +18 -28
  163. package/node_modules/jose/dist/types/types.d.ts +243 -224
  164. package/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
  165. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
  166. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
  167. package/node_modules/jose/dist/types/util/errors.d.ts +128 -121
  168. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +4 -22
  169. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
  170. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
  171. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +23 -3
  172. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +70 -82
  173. package/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
  174. package/node_modules/jose/dist/webapi/jwks/local.js +32 -73
  175. package/node_modules/jose/dist/webapi/jwks/remote.js +19 -28
  176. package/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
  177. package/node_modules/jose/dist/webapi/jws/compact/verify.js +4 -16
  178. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -65
  179. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
  180. package/node_modules/jose/dist/webapi/jws/general/sign.js +19 -15
  181. package/node_modules/jose/dist/webapi/jws/general/verify.js +29 -9
  182. package/node_modules/jose/dist/webapi/jwt/decrypt.js +5 -5
  183. package/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
  184. package/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
  185. package/node_modules/jose/dist/webapi/jwt/verify.js +6 -6
  186. package/node_modules/jose/dist/webapi/key/export.js +37 -4
  187. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +33 -82
  188. package/node_modules/jose/dist/webapi/key/generate_secret.js +2 -2
  189. package/node_modules/jose/dist/webapi/key/import.js +8 -8
  190. package/node_modules/jose/dist/webapi/lib/asn1.js +53 -122
  191. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
  192. package/node_modules/jose/dist/webapi/lib/content_encryption.js +34 -109
  193. package/node_modules/jose/dist/webapi/lib/crypto_key.js +18 -126
  194. package/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
  195. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -1
  196. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +107 -0
  197. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +186 -0
  198. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +114 -0
  199. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +8 -98
  200. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +73 -0
  201. package/node_modules/jose/dist/webapi/lib/jws_sign.js +74 -0
  202. package/node_modules/jose/dist/webapi/lib/jws_verify.js +107 -0
  203. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +68 -109
  204. package/node_modules/jose/dist/webapi/lib/key.js +132 -0
  205. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +10 -0
  206. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
  207. package/node_modules/jose/dist/webapi/lib/key_management.js +162 -92
  208. package/node_modules/jose/dist/webapi/lib/options.js +48 -0
  209. package/node_modules/jose/dist/webapi/lib/signing.js +14 -56
  210. package/node_modules/jose/dist/webapi/lib/type_checks.js +13 -18
  211. package/node_modules/jose/dist/webapi/util/base64url.js +13 -4
  212. package/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
  213. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
  214. package/node_modules/jose/dist/webapi/util/errors.js +1 -1
  215. package/node_modules/jose/package.json +2 -4
  216. package/node_modules/type-is/node_modules/content-type/README.md +2 -0
  217. package/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
  218. package/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
  219. package/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
  220. package/node_modules/type-is/node_modules/content-type/package.json +1 -1
  221. package/package.json +5 -3
  222. package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  223. package/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  224. package/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  225. package/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  226. package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  227. package/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  228. package/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  229. package/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  230. package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
  231. package/node_modules/jose/dist/webapi/lib/validate_crit.js +0 -33
@@ -224,6 +224,10 @@ class Context {
224
224
  * c.header('X-Message', 'Hello!')
225
225
  * c.header('Content-Type', 'text/plain')
226
226
  *
227
+ * // Append multiple headers using the append option (e.g. Vary)
228
+ * c.header('Vary', 'Accept-Encoding', { append: true })
229
+ * c.header('Vary', 'User-Agent', { append: true })
230
+ *
227
231
  * return c.body('Thank you for coming')
228
232
  * })
229
233
  * ```
@@ -295,11 +299,11 @@ class Context {
295
299
  return Object.fromEntries(this.#var);
296
300
  }
297
301
  #newResponse(data, arg, headers) {
298
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
299
- if (typeof arg === "object" && "headers" in arg) {
300
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
301
- for (const [key, value] of argHeaders) {
302
- if (key.toLowerCase() === "set-cookie") {
302
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
303
+ if (typeof arg === "object" && arg.headers) {
304
+ responseHeaders ??= new Headers();
305
+ for (const [key, value] of new Headers(arg.headers)) {
306
+ if (key === "set-cookie") {
303
307
  responseHeaders.append(key, value);
304
308
  } else {
305
309
  responseHeaders.set(key, value);
@@ -307,19 +311,34 @@ class Context {
307
311
  }
308
312
  }
309
313
  if (headers) {
310
- for (const [k, v] of Object.entries(headers)) {
311
- if (typeof v === "string") {
312
- responseHeaders.set(k, v);
313
- } else {
314
- responseHeaders.delete(k);
315
- for (const v2 of v) {
316
- responseHeaders.append(k, v2);
314
+ if (!responseHeaders) {
315
+ let count = 0;
316
+ for (const k in headers) {
317
+ if (++count > 1 || typeof headers[k] !== "string") {
318
+ responseHeaders = new Headers();
319
+ break;
320
+ }
321
+ }
322
+ }
323
+ if (responseHeaders) {
324
+ for (const k in headers) {
325
+ const v = headers[k];
326
+ if (typeof v === "string") {
327
+ responseHeaders.set(k, v);
328
+ } else {
329
+ responseHeaders.delete(k);
330
+ for (const v2 of v) {
331
+ responseHeaders.append(k, v2);
332
+ }
317
333
  }
318
334
  }
319
335
  }
320
336
  }
321
337
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
322
- return createResponseInstance(data, { status, headers: responseHeaders });
338
+ return createResponseInstance(data, {
339
+ status,
340
+ headers: responseHeaders ?? headers
341
+ });
323
342
  }
324
343
  newResponse = (...args) => this.#newResponse(...args);
325
344
  /**
@@ -92,6 +92,10 @@ const proxy = async (input, proxyInit) => {
92
92
  req.headers.delete("accept-encoding");
93
93
  const res = await (customFetch || fetch)(req);
94
94
  const resHeaders = new Headers(res.headers);
95
+ const connectionValue = resHeaders.get("connection");
96
+ if (connectionValue) {
97
+ connectionValue.split(",").map((h) => h.trim()).filter((h) => ALLOWED_TOKEN_PATTERN.test(h)).forEach((h) => resHeaders.delete(h));
98
+ }
95
99
  hopByHopHeaders.forEach((header) => {
96
100
  resHeaders.delete(header);
97
101
  });
@@ -43,6 +43,7 @@ class Hono {
43
43
  delete;
44
44
  options;
45
45
  patch;
46
+ query;
46
47
  all;
47
48
  on;
48
49
  use;
@@ -342,8 +343,8 @@ class Hono {
342
343
  * @see {@link https://hono.dev/docs/api/hono#fetch}
343
344
  *
344
345
  * @param {Request} request - request Object of request
345
- * @param {Env} Env - env Object
346
- * @param {ExecutionContext} - context of execution
346
+ * @param {Env} env - env Object
347
+ * @param {ExecutionContext} executionCtx - context of execution
347
348
  * @returns {Response | Promise<Response>} response of request
348
349
  *
349
350
  */
@@ -100,6 +100,18 @@ const booleanAttributes = [
100
100
  "reversed",
101
101
  "selected"
102
102
  ];
103
+ const resolveFunctionComponentResult = (result, suspendedContext) => result.then((resolved) => {
104
+ if (!Array.isArray(resolved) && !(resolved instanceof JSXNode)) {
105
+ return resolved;
106
+ }
107
+ const children = Array.isArray(resolved) ? resolved : [resolved];
108
+ const render = () => {
109
+ const buffer = [""];
110
+ childrenToStringToBuffer(children, buffer);
111
+ return buffer.length === 1 ? (0, import_html.raw)(buffer[0], buffer.callbacks) : (0, import_html2.stringBufferToString)(buffer, buffer.callbacks);
112
+ };
113
+ return suspendedContext ? suspendedContext(render) : (0, import_context.runWithRenderContext)(render);
114
+ });
103
115
  const childrenToStringToBuffer = (children, buffer) => {
104
116
  for (let i = 0, len = children.length; i < len; i++) {
105
117
  const child = children[i];
@@ -109,9 +121,17 @@ const childrenToStringToBuffer = (children, buffer) => {
109
121
  continue;
110
122
  } else if (child instanceof JSXNode) {
111
123
  child.toStringToBuffer(buffer);
112
- } else if (typeof child === "number" || child.isEscaped) {
124
+ } else if (typeof child === "number") {
125
+ ;
126
+ buffer[0] += child;
127
+ } else if (child.isEscaped) {
113
128
  ;
114
129
  buffer[0] += child;
130
+ const callbacks = child.callbacks;
131
+ if (callbacks) {
132
+ buffer.callbacks ||= [];
133
+ buffer.callbacks.push(...callbacks);
134
+ }
115
135
  } else if (child instanceof Promise) {
116
136
  buffer.unshift("", child);
117
137
  } else {
@@ -125,7 +145,6 @@ class JSXNode {
125
145
  key;
126
146
  children;
127
147
  isEscaped = true;
128
- suspendedContext;
129
148
  constructor(tag, props, children) {
130
149
  if (typeof tag !== "function" && !(0, import_utils.isValidTagName)(tag)) {
131
150
  throw new Error(`Invalid JSX tag name: ${tag}`);
@@ -148,7 +167,7 @@ class JSXNode {
148
167
  this.toStringToBuffer(buffer);
149
168
  return buffer.length === 1 ? "callbacks" in buffer ? (0, import_html2.resolveCallbackSync)((0, import_html.raw)(buffer[0], buffer.callbacks)).toString() : buffer[0] : (0, import_html2.stringBufferToString)(buffer, buffer.callbacks);
150
169
  };
151
- return this.suspendedContext ? this.suspendedContext(render) : (0, import_context.runWithRenderContext)(render);
170
+ return (0, import_context.runWithRenderContext)(render);
152
171
  }
153
172
  toStringToBuffer(buffer) {
154
173
  const tag = this.tag;
@@ -222,21 +241,14 @@ class JSXFunctionNode extends JSXNode {
222
241
  return;
223
242
  } else if (res instanceof Promise) {
224
243
  if (import_context.globalContexts.length === 0) {
225
- buffer.unshift("", res);
244
+ buffer.unshift("", resolveFunctionComponentResult(res));
226
245
  } else {
227
- const suspendedContext = (0, import_context.captureRenderContext)();
228
- buffer.unshift(
229
- "",
230
- res.then((childRes) => {
231
- if (childRes instanceof JSXNode) {
232
- childRes.suspendedContext = suspendedContext;
233
- }
234
- return childRes;
235
- })
236
- );
246
+ buffer.unshift("", resolveFunctionComponentResult(res, (0, import_context.captureRenderContext)()));
237
247
  }
238
248
  } else if (res instanceof JSXNode) {
239
249
  res.toStringToBuffer(buffer);
250
+ } else if (Array.isArray(res)) {
251
+ childrenToStringToBuffer(res, buffer);
240
252
  } else if (typeof res === "number" || res.isEscaped) {
241
253
  buffer[0] += res;
242
254
  if (res.callbacks) {
@@ -315,15 +327,7 @@ const shallowEqual = (a, b) => {
315
327
  return true;
316
328
  };
317
329
  const memo = (component, propsAreEqual = shallowEqual) => {
318
- let computed = null;
319
- let prevProps = void 0;
320
- const wrapper = ((props) => {
321
- if (prevProps && !propsAreEqual(prevProps, props)) {
322
- computed = null;
323
- }
324
- prevProps = props;
325
- return computed ||= component(props);
326
- });
330
+ const wrapper = ((props) => component(props));
327
331
  wrapper[import_constants.DOM_MEMO] = propsAreEqual;
328
332
  wrapper[import_constants.DOM_RENDERER] = component;
329
333
  return wrapper;
@@ -263,7 +263,7 @@ const useCallback = (callback, deps) => {
263
263
  }
264
264
  return callback;
265
265
  };
266
- const useRef = (initialValue) => {
266
+ function useRef(initialValue) {
267
267
  const buildData = import_render.buildDataStack.at(-1);
268
268
  if (!buildData) {
269
269
  return { current: initialValue };
@@ -272,7 +272,7 @@ const useRef = (initialValue) => {
272
272
  const refArray = node[import_constants.DOM_STASH][1][STASH_REF] ||= [];
273
273
  const hookIndex = node[import_constants.DOM_STASH][0]++;
274
274
  return refArray[hookIndex] ||= { current: initialValue };
275
- };
275
+ }
276
276
  const use = (promise) => {
277
277
  const cachedRes = resolvedPromiseValueMap.get(promise);
278
278
  if (cachedRes) {
@@ -330,19 +330,22 @@ const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
330
330
  }
331
331
  return getServerSnapshot();
332
332
  }
333
- const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
334
- const [state, setState] = useState(
335
- () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
336
- );
333
+ const snapshot = buildData[0][4] && getServerSnapshot ? getServerSnapshot() : getSnapshot();
334
+ const [, setVersion] = useState(0);
335
+ const latestSnapshot = useRef([snapshot, getSnapshot]);
336
+ latestSnapshot.current = [snapshot, getSnapshot];
337
+ const unsubscribeRef = useRef(null);
337
338
  useEffect(() => {
338
- if (serverSnapshotIsUsed) {
339
- setState(getSnapshot());
339
+ const update2 = () => setVersion((version) => version + 1);
340
+ unsubscribeRef.current?.();
341
+ unsubscribeRef.current = subscribe(update2);
342
+ const [snapshot2, getSnapshot2] = latestSnapshot.current;
343
+ if (!Object.is(snapshot2, getSnapshot2())) {
344
+ update2();
340
345
  }
341
- return subscribe(() => {
342
- setState(getSnapshot());
343
- });
344
- }, []);
345
- return state;
346
+ }, [subscribe]);
347
+ useEffect(() => () => unsubscribeRef.current?.(), []);
348
+ return snapshot;
346
349
  };
347
350
  // Annotate the CommonJS export names for ESM import in node:
348
351
  0 && (module.exports = {
@@ -101,7 +101,7 @@ const documentMetadataTag = (tag, children, props, sort) => {
101
101
  const string = new import_base.JSXNode(tag, restProps, (0, import_children.toArray)(children || [])).toString();
102
102
  if (string instanceof Promise) {
103
103
  return string.then(
104
- (resString) => (0, import_html.raw)(string, [
104
+ (resString) => (0, import_html.raw)(resString, [
105
105
  ...resString.callbacks || [],
106
106
  insertIntoHead(tag, resString, restProps, precedence)
107
107
  ])
@@ -20,7 +20,21 @@ __export(cache_exports, {
20
20
  cache: () => cache
21
21
  });
22
22
  module.exports = __toCommonJS(cache_exports);
23
+ var import_request = require("../../request");
24
+ var import_crypto = require("../../utils/crypto");
23
25
  const defaultCacheableStatusCodes = [200];
26
+ const defaultMaxQueryBodySize = 64 * 1024;
27
+ const cacheKeyPath = "/.hono/cache";
28
+ const cacheKeyParameter = "__hono_cache_key";
29
+ const cacheMethodKeyParameter = "__hono_cache_method";
30
+ const queryDigestKeyParameter = "__hono_query_digest";
31
+ const cacheVaryKeyParameter = "__hono_cache_vary";
32
+ const queryRepresentationMetadataHeaders = [
33
+ "content-type",
34
+ "content-encoding",
35
+ "content-language",
36
+ "content-location"
37
+ ];
24
38
  const shouldSkipCacheControl = (cacheControl) => !!cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl);
25
39
  const parseVaryDirectives = (vary) => {
26
40
  if (vary == null) {
@@ -28,17 +42,86 @@ const parseVaryDirectives = (vary) => {
28
42
  }
29
43
  return (Array.isArray(vary) ? vary : vary.split(",")).map((directive) => directive.trim().toLowerCase()).filter(Boolean);
30
44
  };
45
+ const createCacheKey = (key, requestUrl, request, varyHeaders) => {
46
+ const url = new URL(cacheKeyPath, requestUrl);
47
+ url.searchParams.append(cacheKeyParameter, key.split("#", 1)[0]);
48
+ url.searchParams.append(cacheMethodKeyParameter, request.method);
49
+ if (request.method === "QUERY") {
50
+ url.searchParams.append(queryDigestKeyParameter, request.digest);
51
+ }
52
+ for (const header of varyHeaders) {
53
+ url.searchParams.append(cacheVaryKeyParameter, JSON.stringify(header));
54
+ }
55
+ return url.href;
56
+ };
31
57
  const shouldSkipCache = (res, optionsVaryDirectives, responseVary) => responseVary.length && (!optionsVaryDirectives || responseVary.some((name) => !optionsVaryDirectives.has(name))) || shouldSkipCacheControl(res.headers.get("Cache-Control")) || res.headers.has("Set-Cookie");
58
+ const reportCacheNotAvailable = (onCacheNotAvailable, reason) => {
59
+ if (onCacheNotAvailable === false) {
60
+ } else if (onCacheNotAvailable) {
61
+ onCacheNotAvailable(reason);
62
+ } else {
63
+ console.log(reason);
64
+ }
65
+ };
66
+ const createQueryDigest = async (c, maxQueryBodySize) => {
67
+ if (!globalThis.crypto?.subtle) {
68
+ return void 0;
69
+ }
70
+ if (c.req.raw.bodyUsed && Object.keys(c.req.bodyCache)[0] === "formData") {
71
+ return void 0;
72
+ }
73
+ try {
74
+ const requestHeaders = c.req.raw.headers;
75
+ const metadata = new TextEncoder().encode(
76
+ JSON.stringify(
77
+ queryRepresentationMetadataHeaders.map((header) => [header, requestHeaders.get(header)])
78
+ )
79
+ );
80
+ const body = (await (0, import_request.cloneRawRequest)(c.req)).body;
81
+ const chunks = [];
82
+ let bodySize = 0;
83
+ if (body) {
84
+ const reader = body.getReader();
85
+ for (; ; ) {
86
+ const { done, value } = await reader.read();
87
+ if (done) {
88
+ break;
89
+ }
90
+ bodySize += value.byteLength;
91
+ if (bodySize > maxQueryBodySize) {
92
+ void reader.cancel().catch(() => {
93
+ });
94
+ return void 0;
95
+ }
96
+ chunks.push(value);
97
+ }
98
+ }
99
+ const data = new Uint8Array(metadata.byteLength + bodySize);
100
+ data.set(metadata);
101
+ let offset = metadata.byteLength;
102
+ for (const chunk of chunks) {
103
+ data.set(chunk, offset);
104
+ offset += chunk.byteLength;
105
+ }
106
+ return await (0, import_crypto.sha256)(data) ?? void 0;
107
+ } catch {
108
+ return void 0;
109
+ }
110
+ };
32
111
  const cache = (options) => {
33
112
  if (!globalThis.caches) {
34
- if (options.onCacheNotAvailable === false) {
35
- } else if (options.onCacheNotAvailable) {
36
- options.onCacheNotAvailable();
37
- } else {
38
- console.log("Cache Middleware is not enabled because caches is not defined.");
39
- }
113
+ reportCacheNotAvailable(
114
+ options.onCacheNotAvailable,
115
+ "Cache Middleware is not enabled because caches is not defined."
116
+ );
40
117
  return async (_c, next) => await next();
41
118
  }
119
+ if (!globalThis.crypto?.subtle) {
120
+ reportCacheNotAvailable(
121
+ options.onCacheNotAvailable,
122
+ "Cache Middleware cannot cache QUERY requests because Web Crypto is not available."
123
+ );
124
+ }
42
125
  if (options.wait === void 0) {
43
126
  options.wait = false;
44
127
  }
@@ -53,6 +136,7 @@ const cache = (options) => {
53
136
  const cacheableStatusCodes = new Set(
54
137
  options.cacheableStatusCodes ?? defaultCacheableStatusCodes
55
138
  );
139
+ const maxQueryBodySize = options.maxQueryBodySize ?? defaultMaxQueryBodySize;
56
140
  const addHeader = (c, responseVary) => {
57
141
  if (cacheControlDirectives) {
58
142
  const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0].toLowerCase()) ?? [];
@@ -81,20 +165,31 @@ const cache = (options) => {
81
165
  }
82
166
  };
83
167
  return async function cache2(c, next) {
84
- if (c.req.method !== "GET" || c.req.raw.headers.has("Authorization")) {
168
+ if (c.req.method !== "GET" && c.req.method !== "QUERY" || c.req.raw.headers.has("Authorization")) {
85
169
  await next();
86
170
  return;
87
171
  }
172
+ let cacheKeyRequest = { method: "GET" };
173
+ if (c.req.method === "QUERY") {
174
+ const digest = await createQueryDigest(c, maxQueryBodySize);
175
+ if (digest === void 0) {
176
+ await next();
177
+ return;
178
+ }
179
+ cacheKeyRequest = { method: "QUERY", digest };
180
+ }
88
181
  let key = c.req.url;
89
182
  if (options.keyGenerator) {
90
183
  key = await options.keyGenerator(c);
91
184
  }
185
+ const varyHeaders = [];
92
186
  if (varyDirectives) {
93
187
  for (const directive of varyDirectives) {
94
188
  const value = c.req.raw.headers.get(directive) ?? "";
95
- key += `::${directive}=${encodeURIComponent(value)}`;
189
+ varyHeaders.push([directive, value]);
96
190
  }
97
191
  }
192
+ key = createCacheKey(key, c.req.url, cacheKeyRequest, varyHeaders);
98
193
  const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
99
194
  const cache3 = await caches.open(cacheName);
100
195
  const response = await cache3.match(key);
@@ -43,6 +43,7 @@ const selectEncoding = (header, candidates) => {
43
43
  }
44
44
  return best?.encoding;
45
45
  };
46
+ const varyAcceptEncodingRegExp = /(?:^|,)\s*accept-encoding\s*(?:,|$)/i;
46
47
  const compress = (options) => {
47
48
  const threshold = options?.threshold ?? 1024;
48
49
  const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES;
@@ -66,6 +67,10 @@ const compress = (options) => {
66
67
  !shouldTransform(ctx.res)) {
67
68
  return;
68
69
  }
70
+ const current = ctx.res.headers.get("Vary");
71
+ if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) {
72
+ ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
73
+ }
69
74
  const accepted = ctx.req.header("Accept-Encoding");
70
75
  const encoding = selectEncoding(accepted, candidates);
71
76
  if (!encoding || !ctx.res.body) {
@@ -23,11 +23,13 @@ module.exports = __toCommonJS(cors_exports);
23
23
  const cors = (options) => {
24
24
  const opts = {
25
25
  origin: "*",
26
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
26
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
27
27
  allowHeaders: [],
28
28
  exposeHeaders: [],
29
29
  ...options
30
30
  };
31
+ const exposeHeadersStr = opts.exposeHeaders?.length ? opts.exposeHeaders.join(",") : void 0;
32
+ const allowHeadersStr = opts.allowHeaders?.length ? opts.allowHeaders.join(",") : void 0;
31
33
  const findAllowOrigin = ((optsOrigin) => {
32
34
  if (typeof optsOrigin === "string") {
33
35
  if (optsOrigin === "*") {
@@ -43,11 +45,12 @@ const cors = (options) => {
43
45
  })(opts.origin);
44
46
  const findAllowMethods = ((optsAllowMethods) => {
45
47
  if (typeof optsAllowMethods === "function") {
46
- return optsAllowMethods;
48
+ return async (origin, c) => (await optsAllowMethods(origin, c)).join(",");
47
49
  } else if (Array.isArray(optsAllowMethods)) {
48
- return () => optsAllowMethods;
50
+ const methodsStr = optsAllowMethods.join(",");
51
+ return () => methodsStr;
49
52
  } else {
50
- return () => [];
53
+ return () => "";
51
54
  }
52
55
  })(opts.allowMethods);
53
56
  return async function cors2(c, next) {
@@ -61,29 +64,29 @@ const cors = (options) => {
61
64
  if (opts.credentials) {
62
65
  set("Access-Control-Allow-Credentials", "true");
63
66
  }
64
- if (opts.exposeHeaders?.length) {
65
- set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
67
+ if (exposeHeadersStr) {
68
+ set("Access-Control-Expose-Headers", exposeHeadersStr);
66
69
  }
67
70
  if (c.req.method === "OPTIONS") {
68
71
  if (opts.origin !== "*") {
69
- set("Vary", "Origin");
72
+ c.res.headers.append("Vary", "Origin");
70
73
  }
71
74
  if (opts.maxAge != null) {
72
75
  set("Access-Control-Max-Age", opts.maxAge.toString());
73
76
  }
74
77
  const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
75
- if (allowMethods.length) {
76
- set("Access-Control-Allow-Methods", allowMethods.join(","));
78
+ if (allowMethods) {
79
+ set("Access-Control-Allow-Methods", allowMethods);
77
80
  }
78
- let headers = opts.allowHeaders;
79
- if (!headers?.length) {
81
+ let headersStr = allowHeadersStr;
82
+ if (!headersStr) {
80
83
  const requestHeaders = c.req.header("Access-Control-Request-Headers");
81
84
  if (requestHeaders) {
82
- headers = requestHeaders.split(/\s*,\s*/);
85
+ headersStr = requestHeaders.split(",").map((h) => h.trim()).join(",");
83
86
  }
84
87
  }
85
- if (headers?.length) {
86
- set("Access-Control-Allow-Headers", headers.join(","));
88
+ if (headersStr) {
89
+ set("Access-Control-Allow-Headers", headersStr);
87
90
  c.res.headers.append("Vary", "Access-Control-Request-Headers");
88
91
  }
89
92
  c.res.headers.delete("Content-Length");
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(csrf_exports);
23
23
  var import_http_exception = require("../../http-exception");
24
24
  const secFetchSiteValues = ["same-origin", "same-site", "none", "cross-site"];
25
25
  const isSecFetchSite = (value) => secFetchSiteValues.includes(value);
26
- const isSafeMethodRe = /^(GET|HEAD)$/;
26
+ const isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
27
27
  const isRequestedByFormElementRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i;
28
28
  const csrf = (options) => {
29
29
  const originHandler = ((optsOrigin) => {
@@ -31,18 +31,64 @@ const mergeBuffers = (buffer1, buffer2) => {
31
31
  merged.set(buffer2, buffer1.byteLength);
32
32
  return merged;
33
33
  };
34
+ const CHUNK_SIZE = 256 * 1024;
34
35
  const generateDigest = async (stream, generator) => {
35
36
  if (!stream) {
36
37
  return null;
37
38
  }
38
39
  let result = void 0;
40
+ let chunk;
41
+ let chunkLength = 0;
42
+ const digest = async (body) => {
43
+ result = await generator(mergeBuffers(result, body));
44
+ };
39
45
  const reader = stream.getReader();
40
46
  for (; ; ) {
41
47
  const { value, done } = await reader.read();
42
48
  if (done) {
43
49
  break;
44
50
  }
45
- result = await generator(mergeBuffers(result, value));
51
+ let offset = 0;
52
+ while (offset < value.byteLength) {
53
+ const remaining = value.byteLength - offset;
54
+ if (chunkLength === 0 && remaining >= CHUNK_SIZE) {
55
+ await digest(value.subarray(offset, offset + CHUNK_SIZE));
56
+ offset += CHUNK_SIZE;
57
+ continue;
58
+ }
59
+ const requiredLength = chunkLength + remaining;
60
+ if (requiredLength < CHUNK_SIZE) {
61
+ if (!chunk) {
62
+ chunk = value.slice(offset);
63
+ } else {
64
+ if (chunk.byteLength < requiredLength) {
65
+ const nextChunk = new Uint8Array(
66
+ new ArrayBuffer(Math.min(CHUNK_SIZE, Math.max(requiredLength, chunk.byteLength * 2)))
67
+ );
68
+ nextChunk.set(chunk.subarray(0, chunkLength));
69
+ chunk = nextChunk;
70
+ }
71
+ chunk.set(value.subarray(offset), chunkLength);
72
+ }
73
+ chunkLength = requiredLength;
74
+ break;
75
+ }
76
+ const length = CHUNK_SIZE - chunkLength;
77
+ if (chunk?.byteLength !== CHUNK_SIZE) {
78
+ const nextChunk = new Uint8Array(new ArrayBuffer(CHUNK_SIZE));
79
+ if (chunk) {
80
+ nextChunk.set(chunk.subarray(0, chunkLength));
81
+ }
82
+ chunk = nextChunk;
83
+ }
84
+ chunk.set(value.subarray(offset, offset + length), chunkLength);
85
+ await digest(chunk);
86
+ chunkLength = 0;
87
+ offset += length;
88
+ }
89
+ }
90
+ if (chunk && chunkLength > 0) {
91
+ await digest(chunk.subarray(0, chunkLength));
46
92
  }
47
93
  if (!result) {
48
94
  return null;
@@ -54,6 +54,9 @@ const etag = (options) => {
54
54
  return async function etag2(c, next) {
55
55
  const ifNoneMatch = c.req.header("If-None-Match") ?? null;
56
56
  await next();
57
+ if (!(c.req.method === "GET" || c.req.method === "HEAD" || c.req.method === "QUERY") || !c.res.ok) {
58
+ return;
59
+ }
57
60
  const res = c.res;
58
61
  let etag3 = res.headers.get("ETag");
59
62
  if (!etag3) {
@@ -70,7 +73,7 @@ const etag = (options) => {
70
73
  }
71
74
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
72
75
  }
73
- const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD") && res.ok : etagMatches(etag3, ifNoneMatch);
76
+ const matched = ifNoneMatch === "*" || etagMatches(etag3, ifNoneMatch);
74
77
  if (matched) {
75
78
  c.res = new Response(null, {
76
79
  status: 304,
@@ -79,11 +82,11 @@ const etag = (options) => {
79
82
  ETag: etag3
80
83
  }
81
84
  });
82
- c.res.headers.forEach((_, key) => {
85
+ for (const key of Array.from(c.res.headers.keys())) {
83
86
  if (retainedHeaders.indexOf(key.toLowerCase()) === -1) {
84
87
  c.res.headers.delete(key);
85
88
  }
86
- });
89
+ }
87
90
  } else {
88
91
  c.res.headers.set("ETag", etag3);
89
92
  }
@@ -45,7 +45,8 @@ const jwk = (options, init) => {
45
45
  res: unauthorizedResponse({
46
46
  ctx,
47
47
  error: "invalid_request",
48
- errDescription
48
+ errDescription,
49
+ realm: options.realm
49
50
  })
50
51
  });
51
52
  } else {
@@ -83,7 +84,8 @@ const jwk = (options, init) => {
83
84
  res: unauthorizedResponse({
84
85
  ctx,
85
86
  error: "invalid_request",
86
- errDescription
87
+ errDescription,
88
+ realm: options.realm
87
89
  })
88
90
  });
89
91
  }
@@ -110,7 +112,8 @@ const jwk = (options, init) => {
110
112
  ctx,
111
113
  error: "invalid_token",
112
114
  statusText: "Unauthorized",
113
- errDescription: "token verification failure"
115
+ errDescription: "token verification failure",
116
+ realm: options.realm
114
117
  }),
115
118
  cause
116
119
  });
@@ -120,11 +123,13 @@ const jwk = (options, init) => {
120
123
  };
121
124
  };
122
125
  function unauthorizedResponse(opts) {
126
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
127
+ const errDescription = opts.errDescription.replace(/"/g, '\\"');
123
128
  return new Response("Unauthorized", {
124
129
  status: 401,
125
130
  statusText: opts.statusText,
126
131
  headers: {
127
- "WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
132
+ "WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
128
133
  }
129
134
  });
130
135
  }