@pome-sh/cli 0.19.0 → 0.20.0

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 (89) hide show
  1. package/dist/build-info.json +3 -3
  2. package/node_modules/@hono/node-server/README.md +47 -1
  3. package/node_modules/@hono/node-server/dist/early-hints.cjs +35 -0
  4. package/node_modules/@hono/node-server/dist/early-hints.d.cts +16 -0
  5. package/node_modules/@hono/node-server/dist/early-hints.d.mts +16 -0
  6. package/node_modules/@hono/node-server/dist/early-hints.mjs +33 -0
  7. package/node_modules/@hono/node-server/dist/index.cjs +10 -6
  8. package/node_modules/@hono/node-server/dist/index.mjs +10 -6
  9. package/node_modules/@hono/node-server/package.json +14 -3
  10. package/node_modules/@pome-sh/sdk/package.json +4 -4
  11. package/node_modules/@pome-sh/shared-types/package.json +1 -1
  12. package/node_modules/@pome-sh/shared-types/trace-contract.json +1 -1
  13. package/node_modules/@pome-sh/twin-github/dist/src/check-repos.d.ts +3 -0
  14. package/node_modules/@pome-sh/twin-github/dist/src/check-repos.js +86 -1
  15. package/node_modules/@pome-sh/twin-github/dist/src/check-repos.js.map +1 -1
  16. package/node_modules/@pome-sh/twin-github/dist/src/check-state.d.ts +1 -0
  17. package/node_modules/@pome-sh/twin-github/dist/src/check-state.js +15 -0
  18. package/node_modules/@pome-sh/twin-github/dist/src/check-state.js.map +1 -1
  19. package/node_modules/@pome-sh/twin-github/dist/src/checks.d.ts +2 -0
  20. package/node_modules/@pome-sh/twin-github/dist/src/checks.js +5 -1
  21. package/node_modules/@pome-sh/twin-github/dist/src/checks.js.map +1 -1
  22. package/node_modules/@pome-sh/twin-github/package.json +6 -6
  23. package/node_modules/@pome-sh/twin-gmail/CHANGELOG.md +7 -0
  24. package/node_modules/@pome-sh/twin-gmail/package.json +5 -5
  25. package/node_modules/@pome-sh/twin-linear/CHANGELOG.md +7 -0
  26. package/node_modules/@pome-sh/twin-linear/package.json +5 -5
  27. package/node_modules/@pome-sh/twin-slack/package.json +6 -6
  28. package/node_modules/@pome-sh/twin-stripe/package.json +6 -6
  29. package/node_modules/hono/dist/cjs/context.js +28 -13
  30. package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
  31. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  32. package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
  33. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
  34. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  35. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  36. package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -2
  37. package/node_modules/hono/dist/cjs/middleware/etag/index.js +1 -1
  38. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  39. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  40. package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
  41. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  42. package/node_modules/hono/dist/cjs/request.js +6 -8
  43. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  44. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  45. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  46. package/node_modules/hono/dist/cjs/router.js +1 -1
  47. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
  48. package/node_modules/hono/dist/cjs/utils/url.js +7 -7
  49. package/node_modules/hono/dist/context.js +28 -13
  50. package/node_modules/hono/dist/helper/proxy/index.js +4 -0
  51. package/node_modules/hono/dist/hono-base.js +3 -2
  52. package/node_modules/hono/dist/jsx/base.js +27 -23
  53. package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
  54. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  55. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  56. package/node_modules/hono/dist/middleware/cors/index.js +2 -2
  57. package/node_modules/hono/dist/middleware/etag/index.js +1 -1
  58. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  59. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  60. package/node_modules/hono/dist/middleware/language/language.js +10 -6
  61. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  62. package/node_modules/hono/dist/request.js +7 -9
  63. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  64. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  65. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  66. package/node_modules/hono/dist/router.js +1 -1
  67. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  68. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  69. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  70. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  71. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  72. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  73. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  74. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  75. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  76. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  77. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  78. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  79. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  80. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  81. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  82. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  83. package/node_modules/hono/dist/types/router.d.ts +1 -1
  84. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  85. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  86. package/node_modules/hono/dist/utils/cookie.js +4 -3
  87. package/node_modules/hono/dist/utils/url.js +5 -6
  88. package/node_modules/hono/package.json +10 -3
  89. package/package.json +21 -21
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pome-sh/twin-gmail",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Deterministic Gmail-shaped twin for agent testing — SQLite-backed domain core.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -47,10 +47,10 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@hono/node-server": "^2.0.10",
51
- "@pome-sh/sdk": "0.11.0",
52
- "hono": "^4.12.31",
53
- "zod": "^4.1.13"
50
+ "@hono/node-server": "^2.1.0",
51
+ "@pome-sh/sdk": "0.11.1",
52
+ "hono": "^4.13.0",
53
+ "zod": "^4.4.3"
54
54
  },
55
55
  "keywords": [
56
56
  "gmail",
@@ -1,6 +1,13 @@
1
1
  # @pome-sh/twin-linear — CHANGELOG
2
2
 
3
3
 
4
+ ## 0.3.3 — 2026-08-04
5
+
6
+ Dependency-only patch (#302): `hono` `^4.12.31` → `^4.13.0`, `zod` `^4.1.13` → `^4.4.3`, `@hono/node-server` `^2.0.10` → `^2.1.0`.
7
+ No source file changed and `npm run test:contract` is green, so the surface is
8
+ identical — this exists so the npm artifact stops differing from `main`, which is
9
+ the staleness the publish skip-guard cannot see.
10
+
4
11
  ## 0.3.2 — 2026-08-04
5
12
 
6
13
  - Re-pinned to `@pome-sh/sdk@0.11.0` for the F-1200 parent-vocabulary
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pome-sh/twin-linear",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Deterministic Linear-shaped twin for agent testing — SQLite-backed GraphQL + MCP + OAuth.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -41,11 +41,11 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@hono/node-server": "^2.0.10",
45
- "@pome-sh/sdk": "0.11.0",
44
+ "@hono/node-server": "^2.1.0",
45
+ "@pome-sh/sdk": "0.11.1",
46
46
  "graphql": "^16.11.0",
47
- "hono": "^4.12.31",
48
- "zod": "^4.1.13"
47
+ "hono": "^4.13.0",
48
+ "zod": "^4.4.3"
49
49
  },
50
50
  "keywords": [
51
51
  "linear",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pome-sh/twin-slack",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Deterministic Slack Web API twin for agent testing — REST + MCP, SQLite-backed state.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -33,11 +33,11 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@hono/node-server": "^2.0.10",
37
- "@pome-sh/sdk": "0.11.0",
38
- "@pome-sh/shared-types": "0.14.0",
39
- "hono": "^4.12.31",
40
- "zod": "^4.1.13"
36
+ "@hono/node-server": "^2.1.0",
37
+ "@pome-sh/sdk": "0.11.1",
38
+ "@pome-sh/shared-types": "0.14.1",
39
+ "hono": "^4.13.0",
40
+ "zod": "^4.4.3"
41
41
  },
42
42
  "keywords": [
43
43
  "slack",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pome-sh/twin-stripe",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Deterministic test double for Stripe x402 machine payments — stateful clone agents can drive without burning sandbox quota or real chain gas.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -52,11 +52,11 @@
52
52
  },
53
53
  "license": "Apache-2.0",
54
54
  "dependencies": {
55
- "@hono/node-server": "^2.0.10",
56
- "@pome-sh/sdk": "0.11.0",
57
- "@pome-sh/shared-types": "0.14.0",
58
- "hono": "^4.12.31",
59
- "zod": "^4.1.13"
55
+ "@hono/node-server": "^2.1.0",
56
+ "@pome-sh/sdk": "0.11.1",
57
+ "@pome-sh/shared-types": "0.14.1",
58
+ "hono": "^4.13.0",
59
+ "zod": "^4.4.3"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=24"
@@ -295,11 +295,11 @@ class Context {
295
295
  return Object.fromEntries(this.#var);
296
296
  }
297
297
  #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") {
298
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
299
+ if (typeof arg === "object" && arg.headers) {
300
+ responseHeaders ??= new Headers();
301
+ for (const [key, value] of new Headers(arg.headers)) {
302
+ if (key === "set-cookie") {
303
303
  responseHeaders.append(key, value);
304
304
  } else {
305
305
  responseHeaders.set(key, value);
@@ -307,19 +307,34 @@ class Context {
307
307
  }
308
308
  }
309
309
  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);
310
+ if (!responseHeaders) {
311
+ let count = 0;
312
+ for (const k in headers) {
313
+ if (++count > 1 || typeof headers[k] !== "string") {
314
+ responseHeaders = new Headers();
315
+ break;
316
+ }
317
+ }
318
+ }
319
+ if (responseHeaders) {
320
+ for (const k in headers) {
321
+ const v = headers[k];
322
+ if (typeof v === "string") {
323
+ responseHeaders.set(k, v);
324
+ } else {
325
+ responseHeaders.delete(k);
326
+ for (const v2 of v) {
327
+ responseHeaders.append(k, v2);
328
+ }
317
329
  }
318
330
  }
319
331
  }
320
332
  }
321
333
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
322
- return createResponseInstance(data, { status, headers: responseHeaders });
334
+ return createResponseInstance(data, {
335
+ status,
336
+ headers: responseHeaders ?? headers
337
+ });
323
338
  }
324
339
  newResponse = (...args) => this.#newResponse(...args);
325
340
  /**
@@ -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 = {
@@ -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,7 +23,7 @@ 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
@@ -79,7 +79,7 @@ const cors = (options) => {
79
79
  if (!headers?.length) {
80
80
  const requestHeaders = c.req.header("Access-Control-Request-Headers");
81
81
  if (requestHeaders) {
82
- headers = requestHeaders.split(/\s*,\s*/);
82
+ headers = requestHeaders.split(",").map((h) => h.trim());
83
83
  }
84
84
  }
85
85
  if (headers?.length) {
@@ -70,7 +70,7 @@ const etag = (options) => {
70
70
  }
71
71
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
72
72
  }
73
- const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD") && res.ok : etagMatches(etag3, ifNoneMatch);
73
+ const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD" || c.req.method === "QUERY") && res.ok : etagMatches(etag3, ifNoneMatch);
74
74
  if (matched) {
75
75
  c.res = new Response(null, {
76
76
  status: 304,
@@ -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
  }
@@ -52,7 +52,8 @@ const jwt = (options) => {
52
52
  res: unauthorizedResponse({
53
53
  ctx,
54
54
  error: "invalid_request",
55
- errDescription
55
+ errDescription,
56
+ realm: options.realm
56
57
  })
57
58
  });
58
59
  } else {
@@ -87,7 +88,8 @@ const jwt = (options) => {
87
88
  res: unauthorizedResponse({
88
89
  ctx,
89
90
  error: "invalid_request",
90
- errDescription
91
+ errDescription,
92
+ realm: options.realm
91
93
  })
92
94
  });
93
95
  }
@@ -108,7 +110,8 @@ const jwt = (options) => {
108
110
  ctx,
109
111
  error: "invalid_token",
110
112
  statusText: "Unauthorized",
111
- errDescription: "token verification failure"
113
+ errDescription: "token verification failure",
114
+ realm: options.realm
112
115
  }),
113
116
  cause
114
117
  });
@@ -118,11 +121,13 @@ const jwt = (options) => {
118
121
  };
119
122
  };
120
123
  function unauthorizedResponse(opts) {
124
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
125
+ const errDescription = opts.errDescription.replace(/"/g, '\\"');
121
126
  return new Response("Unauthorized", {
122
127
  status: 401,
123
128
  statusText: opts.statusText,
124
129
  headers: {
125
- "WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
130
+ "WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
126
131
  }
127
132
  });
128
133
  }