@pome-sh/cli 0.18.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 (151) hide show
  1. package/dist/build-info.json +3 -3
  2. package/dist/src/capture-server/index.js +1 -1
  3. package/dist/src/runner/mergeAdapterSignals.d.ts +23 -0
  4. package/dist/src/runner/mergeAdapterSignals.js +45 -3
  5. package/dist/src/scaffolds/mcp-loop/loop.js +3 -3
  6. package/node_modules/@hono/node-server/README.md +47 -1
  7. package/node_modules/@hono/node-server/dist/early-hints.cjs +35 -0
  8. package/node_modules/@hono/node-server/dist/early-hints.d.cts +16 -0
  9. package/node_modules/@hono/node-server/dist/early-hints.d.mts +16 -0
  10. package/node_modules/@hono/node-server/dist/early-hints.mjs +33 -0
  11. package/node_modules/@hono/node-server/dist/index.cjs +10 -6
  12. package/node_modules/@hono/node-server/dist/index.mjs +10 -6
  13. package/node_modules/@hono/node-server/package.json +14 -3
  14. package/node_modules/@pome-sh/sdk/dist/check-state-path.d.ts +71 -0
  15. package/node_modules/@pome-sh/sdk/dist/check-state-path.js +200 -0
  16. package/node_modules/@pome-sh/sdk/dist/check-state-path.js.map +1 -0
  17. package/node_modules/@pome-sh/sdk/dist/checks.d.ts +2 -0
  18. package/node_modules/@pome-sh/sdk/dist/checks.js +5 -0
  19. package/node_modules/@pome-sh/sdk/dist/checks.js.map +1 -1
  20. package/node_modules/@pome-sh/sdk/dist/recorder.d.ts +10 -1
  21. package/node_modules/@pome-sh/sdk/dist/recorder.js +11 -2
  22. package/node_modules/@pome-sh/sdk/dist/recorder.js.map +1 -1
  23. package/node_modules/@pome-sh/sdk/package.json +4 -4
  24. package/node_modules/@pome-sh/shared-types/dist/otel/event-schema.d.ts +111 -24
  25. package/node_modules/@pome-sh/shared-types/dist/otel/fixtures/data.js +3 -3
  26. package/node_modules/@pome-sh/shared-types/dist/otel/fixtures/data.js.map +1 -1
  27. package/node_modules/@pome-sh/shared-types/dist/otel/legacy-shim.d.ts +6 -3
  28. package/node_modules/@pome-sh/shared-types/dist/otel/legacy-shim.js +7 -2
  29. package/node_modules/@pome-sh/shared-types/dist/otel/legacy-shim.js.map +1 -1
  30. package/node_modules/@pome-sh/shared-types/dist/otel/map-span.js +1 -1
  31. package/node_modules/@pome-sh/shared-types/dist/otel/map-span.js.map +1 -1
  32. package/node_modules/@pome-sh/shared-types/dist/otel/span-event.d.ts +68 -4
  33. package/node_modules/@pome-sh/shared-types/dist/otel/span-event.js +19 -5
  34. package/node_modules/@pome-sh/shared-types/dist/otel/span-event.js.map +1 -1
  35. package/node_modules/@pome-sh/shared-types/dist/recorder-events.d.ts +60 -28
  36. package/node_modules/@pome-sh/shared-types/dist/recorder-events.js +81 -10
  37. package/node_modules/@pome-sh/shared-types/dist/recorder-events.js.map +1 -1
  38. package/node_modules/@pome-sh/shared-types/package.json +1 -1
  39. package/node_modules/@pome-sh/shared-types/trace-contract.json +49 -1
  40. package/node_modules/@pome-sh/twin-github/dist/src/check-issues.js +35 -9
  41. package/node_modules/@pome-sh/twin-github/dist/src/check-issues.js.map +1 -1
  42. package/node_modules/@pome-sh/twin-github/dist/src/check-pulls.js +21 -5
  43. package/node_modules/@pome-sh/twin-github/dist/src/check-pulls.js.map +1 -1
  44. package/node_modules/@pome-sh/twin-github/dist/src/check-repos.d.ts +3 -0
  45. package/node_modules/@pome-sh/twin-github/dist/src/check-repos.js +111 -6
  46. package/node_modules/@pome-sh/twin-github/dist/src/check-repos.js.map +1 -1
  47. package/node_modules/@pome-sh/twin-github/dist/src/check-state.d.ts +21 -1
  48. package/node_modules/@pome-sh/twin-github/dist/src/check-state.js +77 -10
  49. package/node_modules/@pome-sh/twin-github/dist/src/check-state.js.map +1 -1
  50. package/node_modules/@pome-sh/twin-github/dist/src/checks.d.ts +2 -0
  51. package/node_modules/@pome-sh/twin-github/dist/src/checks.js +5 -1
  52. package/node_modules/@pome-sh/twin-github/dist/src/checks.js.map +1 -1
  53. package/node_modules/@pome-sh/twin-github/package.json +6 -6
  54. package/node_modules/@pome-sh/twin-gmail/CHANGELOG.md +36 -0
  55. package/node_modules/@pome-sh/twin-gmail/dist/src/check-drafts.js +19 -4
  56. package/node_modules/@pome-sh/twin-gmail/dist/src/check-drafts.js.map +1 -1
  57. package/node_modules/@pome-sh/twin-gmail/dist/src/check-labels.js +15 -4
  58. package/node_modules/@pome-sh/twin-gmail/dist/src/check-labels.js.map +1 -1
  59. package/node_modules/@pome-sh/twin-gmail/dist/src/check-messages.js +19 -3
  60. package/node_modules/@pome-sh/twin-gmail/dist/src/check-messages.js.map +1 -1
  61. package/node_modules/@pome-sh/twin-gmail/dist/src/check-state.d.ts +26 -1
  62. package/node_modules/@pome-sh/twin-gmail/dist/src/check-state.js +52 -16
  63. package/node_modules/@pome-sh/twin-gmail/dist/src/check-state.js.map +1 -1
  64. package/node_modules/@pome-sh/twin-gmail/package.json +5 -5
  65. package/node_modules/@pome-sh/twin-linear/CHANGELOG.md +36 -0
  66. package/node_modules/@pome-sh/twin-linear/dist/src/check-comments.js +15 -3
  67. package/node_modules/@pome-sh/twin-linear/dist/src/check-comments.js.map +1 -1
  68. package/node_modules/@pome-sh/twin-linear/dist/src/check-issues.js +31 -4
  69. package/node_modules/@pome-sh/twin-linear/dist/src/check-issues.js.map +1 -1
  70. package/node_modules/@pome-sh/twin-linear/dist/src/check-state.d.ts +27 -2
  71. package/node_modules/@pome-sh/twin-linear/dist/src/check-state.js +73 -20
  72. package/node_modules/@pome-sh/twin-linear/dist/src/check-state.js.map +1 -1
  73. package/node_modules/@pome-sh/twin-linear/package.json +5 -5
  74. package/node_modules/@pome-sh/twin-slack/dist/src/check-messages.js +28 -7
  75. package/node_modules/@pome-sh/twin-slack/dist/src/check-messages.js.map +1 -1
  76. package/node_modules/@pome-sh/twin-slack/dist/src/check-secrets.js +16 -3
  77. package/node_modules/@pome-sh/twin-slack/dist/src/check-secrets.js.map +1 -1
  78. package/node_modules/@pome-sh/twin-slack/dist/src/check-state.d.ts +26 -1
  79. package/node_modules/@pome-sh/twin-slack/dist/src/check-state.js +31 -4
  80. package/node_modules/@pome-sh/twin-slack/dist/src/check-state.js.map +1 -1
  81. package/node_modules/@pome-sh/twin-slack/package.json +6 -6
  82. package/node_modules/@pome-sh/twin-stripe/dist/src/check-payments.d.ts +1 -1
  83. package/node_modules/@pome-sh/twin-stripe/dist/src/check-payments.js +16 -0
  84. package/node_modules/@pome-sh/twin-stripe/dist/src/check-payments.js.map +1 -1
  85. package/node_modules/@pome-sh/twin-stripe/dist/src/check-refunds.js +11 -3
  86. package/node_modules/@pome-sh/twin-stripe/dist/src/check-refunds.js.map +1 -1
  87. package/node_modules/@pome-sh/twin-stripe/dist/src/check-state.d.ts +25 -1
  88. package/node_modules/@pome-sh/twin-stripe/dist/src/check-state.js +31 -3
  89. package/node_modules/@pome-sh/twin-stripe/dist/src/check-state.js.map +1 -1
  90. package/node_modules/@pome-sh/twin-stripe/package.json +6 -6
  91. package/node_modules/hono/dist/cjs/context.js +28 -13
  92. package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
  93. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  94. package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
  95. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
  96. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  97. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  98. package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -2
  99. package/node_modules/hono/dist/cjs/middleware/etag/index.js +1 -1
  100. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  101. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  102. package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
  103. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  104. package/node_modules/hono/dist/cjs/request.js +6 -8
  105. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  106. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  107. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  108. package/node_modules/hono/dist/cjs/router.js +1 -1
  109. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
  110. package/node_modules/hono/dist/cjs/utils/url.js +7 -7
  111. package/node_modules/hono/dist/context.js +28 -13
  112. package/node_modules/hono/dist/helper/proxy/index.js +4 -0
  113. package/node_modules/hono/dist/hono-base.js +3 -2
  114. package/node_modules/hono/dist/jsx/base.js +27 -23
  115. package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
  116. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  117. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  118. package/node_modules/hono/dist/middleware/cors/index.js +2 -2
  119. package/node_modules/hono/dist/middleware/etag/index.js +1 -1
  120. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  121. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  122. package/node_modules/hono/dist/middleware/language/language.js +10 -6
  123. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  124. package/node_modules/hono/dist/request.js +7 -9
  125. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  126. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  127. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  128. package/node_modules/hono/dist/router.js +1 -1
  129. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  130. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  131. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  132. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  133. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  134. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  135. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  136. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  137. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  138. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  139. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  140. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  141. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  142. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  143. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  144. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  145. package/node_modules/hono/dist/types/router.d.ts +1 -1
  146. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  147. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  148. package/node_modules/hono/dist/utils/cookie.js +4 -3
  149. package/node_modules/hono/dist/utils/url.js +5 -6
  150. package/node_modules/hono/package.json +10 -3
  151. package/package.json +21 -21
@@ -69,6 +69,18 @@ var booleanAttributes = [
69
69
  "reversed",
70
70
  "selected"
71
71
  ];
72
+ var resolveFunctionComponentResult = (result, suspendedContext) => result.then((resolved) => {
73
+ if (!Array.isArray(resolved) && !(resolved instanceof JSXNode)) {
74
+ return resolved;
75
+ }
76
+ const children = Array.isArray(resolved) ? resolved : [resolved];
77
+ const render = () => {
78
+ const buffer = [""];
79
+ childrenToStringToBuffer(children, buffer);
80
+ return buffer.length === 1 ? raw(buffer[0], buffer.callbacks) : stringBufferToString(buffer, buffer.callbacks);
81
+ };
82
+ return suspendedContext ? suspendedContext(render) : runWithRenderContext(render);
83
+ });
72
84
  var childrenToStringToBuffer = (children, buffer) => {
73
85
  for (let i = 0, len = children.length; i < len; i++) {
74
86
  const child = children[i];
@@ -78,9 +90,17 @@ var childrenToStringToBuffer = (children, buffer) => {
78
90
  continue;
79
91
  } else if (child instanceof JSXNode) {
80
92
  child.toStringToBuffer(buffer);
81
- } else if (typeof child === "number" || child.isEscaped) {
93
+ } else if (typeof child === "number") {
94
+ ;
95
+ buffer[0] += child;
96
+ } else if (child.isEscaped) {
82
97
  ;
83
98
  buffer[0] += child;
99
+ const callbacks = child.callbacks;
100
+ if (callbacks) {
101
+ buffer.callbacks ||= [];
102
+ buffer.callbacks.push(...callbacks);
103
+ }
84
104
  } else if (child instanceof Promise) {
85
105
  buffer.unshift("", child);
86
106
  } else {
@@ -94,7 +114,6 @@ var JSXNode = class {
94
114
  key;
95
115
  children;
96
116
  isEscaped = true;
97
- suspendedContext;
98
117
  constructor(tag, props, children) {
99
118
  if (typeof tag !== "function" && !isValidTagName(tag)) {
100
119
  throw new Error(`Invalid JSX tag name: ${tag}`);
@@ -117,7 +136,7 @@ var JSXNode = class {
117
136
  this.toStringToBuffer(buffer);
118
137
  return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
119
138
  };
120
- return this.suspendedContext ? this.suspendedContext(render) : runWithRenderContext(render);
139
+ return runWithRenderContext(render);
121
140
  }
122
141
  toStringToBuffer(buffer) {
123
142
  const tag = this.tag;
@@ -191,21 +210,14 @@ var JSXFunctionNode = class extends JSXNode {
191
210
  return;
192
211
  } else if (res instanceof Promise) {
193
212
  if (globalContexts.length === 0) {
194
- buffer.unshift("", res);
213
+ buffer.unshift("", resolveFunctionComponentResult(res));
195
214
  } else {
196
- const suspendedContext = captureRenderContext();
197
- buffer.unshift(
198
- "",
199
- res.then((childRes) => {
200
- if (childRes instanceof JSXNode) {
201
- childRes.suspendedContext = suspendedContext;
202
- }
203
- return childRes;
204
- })
205
- );
215
+ buffer.unshift("", resolveFunctionComponentResult(res, captureRenderContext()));
206
216
  }
207
217
  } else if (res instanceof JSXNode) {
208
218
  res.toStringToBuffer(buffer);
219
+ } else if (Array.isArray(res)) {
220
+ childrenToStringToBuffer(res, buffer);
209
221
  } else if (typeof res === "number" || res.isEscaped) {
210
222
  buffer[0] += res;
211
223
  if (res.callbacks) {
@@ -284,15 +296,7 @@ var shallowEqual = (a, b) => {
284
296
  return true;
285
297
  };
286
298
  var memo = (component, propsAreEqual = shallowEqual) => {
287
- let computed = null;
288
- let prevProps = void 0;
289
- const wrapper = ((props) => {
290
- if (prevProps && !propsAreEqual(prevProps, props)) {
291
- computed = null;
292
- }
293
- prevProps = props;
294
- return computed ||= component(props);
295
- });
299
+ const wrapper = ((props) => component(props));
296
300
  wrapper[DOM_MEMO] = propsAreEqual;
297
301
  wrapper[DOM_RENDERER] = component;
298
302
  return wrapper;
@@ -222,7 +222,7 @@ var useCallback = (callback, deps) => {
222
222
  }
223
223
  return callback;
224
224
  };
225
- var useRef = (initialValue) => {
225
+ function useRef(initialValue) {
226
226
  const buildData = buildDataStack.at(-1);
227
227
  if (!buildData) {
228
228
  return { current: initialValue };
@@ -231,7 +231,7 @@ var useRef = (initialValue) => {
231
231
  const refArray = node[DOM_STASH][1][STASH_REF] ||= [];
232
232
  const hookIndex = node[DOM_STASH][0]++;
233
233
  return refArray[hookIndex] ||= { current: initialValue };
234
- };
234
+ }
235
235
  var use = (promise) => {
236
236
  const cachedRes = resolvedPromiseValueMap.get(promise);
237
237
  if (cachedRes) {
@@ -289,19 +289,22 @@ var useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
289
289
  }
290
290
  return getServerSnapshot();
291
291
  }
292
- const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
293
- const [state, setState] = useState(
294
- () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
295
- );
292
+ const snapshot = buildData[0][4] && getServerSnapshot ? getServerSnapshot() : getSnapshot();
293
+ const [, setVersion] = useState(0);
294
+ const latestSnapshot = useRef([snapshot, getSnapshot]);
295
+ latestSnapshot.current = [snapshot, getSnapshot];
296
+ const unsubscribeRef = useRef(null);
296
297
  useEffect(() => {
297
- if (serverSnapshotIsUsed) {
298
- setState(getSnapshot());
298
+ const update2 = () => setVersion((version) => version + 1);
299
+ unsubscribeRef.current?.();
300
+ unsubscribeRef.current = subscribe(update2);
301
+ const [snapshot2, getSnapshot2] = latestSnapshot.current;
302
+ if (!Object.is(snapshot2, getSnapshot2())) {
303
+ update2();
299
304
  }
300
- return subscribe(() => {
301
- setState(getSnapshot());
302
- });
303
- }, []);
304
- return state;
305
+ }, [subscribe]);
306
+ useEffect(() => () => unsubscribeRef.current?.(), []);
307
+ return snapshot;
305
308
  };
306
309
  export {
307
310
  STASH_EFFECT,
@@ -1,5 +1,19 @@
1
1
  // src/middleware/cache/index.ts
2
+ import { cloneRawRequest } from "../../request.js";
3
+ import { sha256 } from "../../utils/crypto.js";
2
4
  var defaultCacheableStatusCodes = [200];
5
+ var defaultMaxQueryBodySize = 64 * 1024;
6
+ var cacheKeyPath = "/.hono/cache";
7
+ var cacheKeyParameter = "__hono_cache_key";
8
+ var cacheMethodKeyParameter = "__hono_cache_method";
9
+ var queryDigestKeyParameter = "__hono_query_digest";
10
+ var cacheVaryKeyParameter = "__hono_cache_vary";
11
+ var queryRepresentationMetadataHeaders = [
12
+ "content-type",
13
+ "content-encoding",
14
+ "content-language",
15
+ "content-location"
16
+ ];
3
17
  var shouldSkipCacheControl = (cacheControl) => !!cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl);
4
18
  var parseVaryDirectives = (vary) => {
5
19
  if (vary == null) {
@@ -7,17 +21,86 @@ var parseVaryDirectives = (vary) => {
7
21
  }
8
22
  return (Array.isArray(vary) ? vary : vary.split(",")).map((directive) => directive.trim().toLowerCase()).filter(Boolean);
9
23
  };
24
+ var createCacheKey = (key, requestUrl, request, varyHeaders) => {
25
+ const url = new URL(cacheKeyPath, requestUrl);
26
+ url.searchParams.append(cacheKeyParameter, key.split("#", 1)[0]);
27
+ url.searchParams.append(cacheMethodKeyParameter, request.method);
28
+ if (request.method === "QUERY") {
29
+ url.searchParams.append(queryDigestKeyParameter, request.digest);
30
+ }
31
+ for (const header of varyHeaders) {
32
+ url.searchParams.append(cacheVaryKeyParameter, JSON.stringify(header));
33
+ }
34
+ return url.href;
35
+ };
10
36
  var shouldSkipCache = (res, optionsVaryDirectives, responseVary) => responseVary.length && (!optionsVaryDirectives || responseVary.some((name) => !optionsVaryDirectives.has(name))) || shouldSkipCacheControl(res.headers.get("Cache-Control")) || res.headers.has("Set-Cookie");
37
+ var reportCacheNotAvailable = (onCacheNotAvailable, reason) => {
38
+ if (onCacheNotAvailable === false) {
39
+ } else if (onCacheNotAvailable) {
40
+ onCacheNotAvailable(reason);
41
+ } else {
42
+ console.log(reason);
43
+ }
44
+ };
45
+ var createQueryDigest = async (c, maxQueryBodySize) => {
46
+ if (!globalThis.crypto?.subtle) {
47
+ return void 0;
48
+ }
49
+ if (c.req.raw.bodyUsed && Object.keys(c.req.bodyCache)[0] === "formData") {
50
+ return void 0;
51
+ }
52
+ try {
53
+ const requestHeaders = c.req.raw.headers;
54
+ const metadata = new TextEncoder().encode(
55
+ JSON.stringify(
56
+ queryRepresentationMetadataHeaders.map((header) => [header, requestHeaders.get(header)])
57
+ )
58
+ );
59
+ const body = (await cloneRawRequest(c.req)).body;
60
+ const chunks = [];
61
+ let bodySize = 0;
62
+ if (body) {
63
+ const reader = body.getReader();
64
+ for (; ; ) {
65
+ const { done, value } = await reader.read();
66
+ if (done) {
67
+ break;
68
+ }
69
+ bodySize += value.byteLength;
70
+ if (bodySize > maxQueryBodySize) {
71
+ void reader.cancel().catch(() => {
72
+ });
73
+ return void 0;
74
+ }
75
+ chunks.push(value);
76
+ }
77
+ }
78
+ const data = new Uint8Array(metadata.byteLength + bodySize);
79
+ data.set(metadata);
80
+ let offset = metadata.byteLength;
81
+ for (const chunk of chunks) {
82
+ data.set(chunk, offset);
83
+ offset += chunk.byteLength;
84
+ }
85
+ return await sha256(data) ?? void 0;
86
+ } catch {
87
+ return void 0;
88
+ }
89
+ };
11
90
  var cache = (options) => {
12
91
  if (!globalThis.caches) {
13
- if (options.onCacheNotAvailable === false) {
14
- } else if (options.onCacheNotAvailable) {
15
- options.onCacheNotAvailable();
16
- } else {
17
- console.log("Cache Middleware is not enabled because caches is not defined.");
18
- }
92
+ reportCacheNotAvailable(
93
+ options.onCacheNotAvailable,
94
+ "Cache Middleware is not enabled because caches is not defined."
95
+ );
19
96
  return async (_c, next) => await next();
20
97
  }
98
+ if (!globalThis.crypto?.subtle) {
99
+ reportCacheNotAvailable(
100
+ options.onCacheNotAvailable,
101
+ "Cache Middleware cannot cache QUERY requests because Web Crypto is not available."
102
+ );
103
+ }
21
104
  if (options.wait === void 0) {
22
105
  options.wait = false;
23
106
  }
@@ -32,6 +115,7 @@ var cache = (options) => {
32
115
  const cacheableStatusCodes = new Set(
33
116
  options.cacheableStatusCodes ?? defaultCacheableStatusCodes
34
117
  );
118
+ const maxQueryBodySize = options.maxQueryBodySize ?? defaultMaxQueryBodySize;
35
119
  const addHeader = (c, responseVary) => {
36
120
  if (cacheControlDirectives) {
37
121
  const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0].toLowerCase()) ?? [];
@@ -60,20 +144,31 @@ var cache = (options) => {
60
144
  }
61
145
  };
62
146
  return async function cache2(c, next) {
63
- if (c.req.method !== "GET" || c.req.raw.headers.has("Authorization")) {
147
+ if (c.req.method !== "GET" && c.req.method !== "QUERY" || c.req.raw.headers.has("Authorization")) {
64
148
  await next();
65
149
  return;
66
150
  }
151
+ let cacheKeyRequest = { method: "GET" };
152
+ if (c.req.method === "QUERY") {
153
+ const digest = await createQueryDigest(c, maxQueryBodySize);
154
+ if (digest === void 0) {
155
+ await next();
156
+ return;
157
+ }
158
+ cacheKeyRequest = { method: "QUERY", digest };
159
+ }
67
160
  let key = c.req.url;
68
161
  if (options.keyGenerator) {
69
162
  key = await options.keyGenerator(c);
70
163
  }
164
+ const varyHeaders = [];
71
165
  if (varyDirectives) {
72
166
  for (const directive of varyDirectives) {
73
167
  const value = c.req.raw.headers.get(directive) ?? "";
74
- key += `::${directive}=${encodeURIComponent(value)}`;
168
+ varyHeaders.push([directive, value]);
75
169
  }
76
170
  }
171
+ key = createCacheKey(key, c.req.url, cacheKeyRequest, varyHeaders);
77
172
  const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
78
173
  const cache3 = await caches.open(cacheName);
79
174
  const response = await cache3.match(key);
@@ -21,6 +21,7 @@ var selectEncoding = (header, candidates) => {
21
21
  }
22
22
  return best?.encoding;
23
23
  };
24
+ var varyAcceptEncodingRegExp = /(?:^|,)\s*accept-encoding\s*(?:,|$)/i;
24
25
  var compress = (options) => {
25
26
  const threshold = options?.threshold ?? 1024;
26
27
  const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES;
@@ -44,6 +45,10 @@ var compress = (options) => {
44
45
  !shouldTransform(ctx.res)) {
45
46
  return;
46
47
  }
48
+ const current = ctx.res.headers.get("Vary");
49
+ if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) {
50
+ ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
51
+ }
47
52
  const accepted = ctx.req.header("Accept-Encoding");
48
53
  const encoding = selectEncoding(accepted, candidates);
49
54
  if (!encoding || !ctx.res.body) {
@@ -2,7 +2,7 @@
2
2
  var cors = (options) => {
3
3
  const opts = {
4
4
  origin: "*",
5
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
5
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
6
6
  allowHeaders: [],
7
7
  exposeHeaders: [],
8
8
  ...options
@@ -58,7 +58,7 @@ var cors = (options) => {
58
58
  if (!headers?.length) {
59
59
  const requestHeaders = c.req.header("Access-Control-Request-Headers");
60
60
  if (requestHeaders) {
61
- headers = requestHeaders.split(/\s*,\s*/);
61
+ headers = requestHeaders.split(",").map((h) => h.trim());
62
62
  }
63
63
  }
64
64
  if (headers?.length) {
@@ -48,7 +48,7 @@ var etag = (options) => {
48
48
  }
49
49
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
50
50
  }
51
- const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD") && res.ok : etagMatches(etag3, ifNoneMatch);
51
+ const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD" || c.req.method === "QUERY") && res.ok : etagMatches(etag3, ifNoneMatch);
52
52
  if (matched) {
53
53
  c.res = new Response(null, {
54
54
  status: 304,
@@ -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
+ };
@@ -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.