@zuplo/cli 6.74.10 → 6.74.12

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 (88) hide show
  1. package/node_modules/@hono/node-server/README.md +47 -1
  2. package/node_modules/@hono/node-server/dist/early-hints.cjs +35 -0
  3. package/node_modules/@hono/node-server/dist/early-hints.d.cts +16 -0
  4. package/node_modules/@hono/node-server/dist/early-hints.d.mts +16 -0
  5. package/node_modules/@hono/node-server/dist/early-hints.mjs +33 -0
  6. package/node_modules/@hono/node-server/dist/index.cjs +4 -1
  7. package/node_modules/@hono/node-server/dist/index.mjs +4 -1
  8. package/node_modules/@hono/node-server/package.json +14 -1
  9. package/node_modules/@zuplo/core/package.json +1 -1
  10. package/node_modules/@zuplo/graphql/out/esm/index.js +12 -12
  11. package/node_modules/@zuplo/graphql/package.json +1 -1
  12. package/node_modules/@zuplo/openapi-tools/package.json +2 -2
  13. package/node_modules/@zuplo/otel/out/esm/{chunk-TXIQ6WNA.js → chunk-AHNBOCFU.js} +1 -1
  14. package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
  15. package/node_modules/@zuplo/otel/package.json +1 -1
  16. package/node_modules/@zuplo/runtime/out/esm/chunk-AVDTZRWM.js +26 -0
  17. package/node_modules/@zuplo/runtime/out/esm/chunk-AVDTZRWM.js.map +1 -0
  18. package/node_modules/@zuplo/runtime/out/esm/{chunk-2EFTGELI.js → chunk-VVVYHDCV.js} +94 -92
  19. package/node_modules/@zuplo/runtime/out/esm/chunk-VVVYHDCV.js.map +1 -0
  20. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  21. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  22. package/node_modules/@zuplo/runtime/out/esm/internal/index.js +1 -1
  23. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  24. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  25. package/node_modules/@zuplo/runtime/out/types/index.d.ts +177 -0
  26. package/node_modules/@zuplo/runtime/package.json +1 -1
  27. package/node_modules/hono/dist/cjs/context.js +28 -13
  28. package/node_modules/hono/dist/cjs/hono-base.js +3 -2
  29. package/node_modules/hono/dist/cjs/jsx/base.js +26 -14
  30. package/node_modules/hono/dist/cjs/jsx/hooks/index.js +2 -2
  31. package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
  32. package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
  33. package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
  34. package/node_modules/hono/dist/cjs/middleware/etag/index.js +1 -1
  35. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
  36. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
  37. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
  38. package/node_modules/hono/dist/cjs/request.js +6 -8
  39. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
  40. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
  41. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
  42. package/node_modules/hono/dist/cjs/router.js +1 -1
  43. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  44. package/node_modules/hono/dist/cjs/utils/url.js +7 -7
  45. package/node_modules/hono/dist/context.js +28 -13
  46. package/node_modules/hono/dist/hono-base.js +3 -2
  47. package/node_modules/hono/dist/jsx/base.js +26 -14
  48. package/node_modules/hono/dist/jsx/hooks/index.js +2 -2
  49. package/node_modules/hono/dist/middleware/cache/index.js +103 -8
  50. package/node_modules/hono/dist/middleware/compress/index.js +5 -0
  51. package/node_modules/hono/dist/middleware/cors/index.js +1 -1
  52. package/node_modules/hono/dist/middleware/etag/index.js +1 -1
  53. package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
  54. package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
  55. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
  56. package/node_modules/hono/dist/request.js +7 -9
  57. package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
  58. package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
  59. package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
  60. package/node_modules/hono/dist/router.js +1 -1
  61. package/node_modules/hono/dist/types/client/types.d.ts +1 -1
  62. package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
  63. package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
  64. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
  65. package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
  66. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
  67. package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
  68. package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
  69. package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
  70. package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
  71. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
  72. package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
  73. package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
  74. package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
  75. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
  76. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
  77. package/node_modules/hono/dist/types/router.d.ts +1 -1
  78. package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
  79. package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
  80. package/node_modules/hono/dist/utils/cookie.js +2 -2
  81. package/node_modules/hono/dist/utils/url.js +5 -6
  82. package/node_modules/hono/package.json +9 -1
  83. package/package.json +6 -6
  84. package/node_modules/@zuplo/runtime/out/esm/chunk-2EFTGELI.js.map +0 -1
  85. package/node_modules/@zuplo/runtime/out/esm/chunk-ZB7PAWBM.js +0 -26
  86. package/node_modules/@zuplo/runtime/out/esm/chunk-ZB7PAWBM.js.map +0 -1
  87. /package/node_modules/@zuplo/otel/out/esm/{chunk-TXIQ6WNA.js.map → chunk-AHNBOCFU.js.map} +0 -0
  88. /package/node_modules/@zuplo/runtime/out/esm/{chunk-2EFTGELI.js.LEGAL.txt → chunk-VVVYHDCV.js.LEGAL.txt} +0 -0
@@ -3162,6 +3162,168 @@ declare interface Category {
3162
3162
  Attribute: Attribute_2[];
3163
3163
  }
3164
3164
 
3165
+ /**
3166
+ * How to combine the configured client policy with a `Cache-Control` the upstream already sent. `strictest` (default) emits the more conservative of the two — the lower `max-age` and the union of restrictive directives. `replace` overwrites whatever upstream sent. `preserve` leaves the upstream header untouched and only adds the CDN headers.
3167
+ * @public
3168
+ */
3169
+ declare type CdnCacheControlClientMode = "strictest" | "replace" | "preserve";
3170
+
3171
+ /**
3172
+ * The `Cache-Control` sent to the browser or app. Separate from `edge` so the CDN can absorb load without clients holding stale data.
3173
+ * @public
3174
+ */
3175
+ declare interface CdnCacheControlClientOptions {
3176
+ /**
3177
+ * Seconds the client may reuse this response. Omit to send no `max-age`.
3178
+ */
3179
+ maxAge?: number;
3180
+ visibility?: CdnCacheControlClientVisibility;
3181
+ /**
3182
+ * Adds `no-cache`, so the client must revalidate before reusing the response. Distinct from `visibility: no-store`, which forbids storing it at all.
3183
+ */
3184
+ noCache?: boolean;
3185
+ /**
3186
+ * Adds `must-revalidate`, so the client may not serve the response once stale.
3187
+ */
3188
+ mustRevalidate?: boolean;
3189
+ mode?: CdnCacheControlClientMode;
3190
+ }
3191
+
3192
+ /**
3193
+ * `public` allows any cache to store the response, `private` restricts it to the client's own cache, `no-store` forbids client caching entirely. With `strategy: targeted` a `private`/`no-store` client policy still permits edge caching, because the CDN reads its own header.
3194
+ * @public
3195
+ */
3196
+ declare type CdnCacheControlClientVisibility =
3197
+ | "public"
3198
+ | "private"
3199
+ | "no-store";
3200
+
3201
+ /**
3202
+ * A cache policy for one response: what the static options normalise into, and
3203
+ * what a `cacheConfig` function returns.
3204
+ *
3205
+ * A function's return value **replaces** this wholesale rather than being merged
3206
+ * field by field. Returning nothing falls back to the static options, which is
3207
+ * how a route enforces defaults and overrides them in only the few cases that
3208
+ * need it.
3209
+ */
3210
+ export declare interface CdnCacheControlConfig {
3211
+ /** Set to false to emit no edge headers or tags for this response. */
3212
+ cache?: boolean;
3213
+ edge?: EdgeCacheDirectives;
3214
+ client?: ClientCacheDirectives;
3215
+ tags?: string[];
3216
+ }
3217
+
3218
+ /**
3219
+ * A `cacheConfig` function: returns the CDN cache policy for one response.
3220
+ *
3221
+ * Return `undefined` or `null` to fall back to the static options, which is how
3222
+ * a route enforces defaults and overrides them only where it needs to.
3223
+ *
3224
+ * @public
3225
+ */
3226
+ export declare type CdnCacheControlConfigFn = (
3227
+ response: Response,
3228
+ request: ZuploRequest,
3229
+ context: ZuploContext
3230
+ ) =>
3231
+ | CdnCacheControlConfig
3232
+ | undefined
3233
+ | null
3234
+ | Promise<CdnCacheControlConfig | undefined | null>;
3235
+
3236
+ /**
3237
+ * A function that overrides the cache configuration per response, for rules that cannot be expressed statically (per-entity purge tags, a TTL that depends on a response header, or skipping an empty result set). Returning nothing (`undefined` or `null`) falls back to the `edge`, `client` and `tags` options, so those stay the enforced default and the function only handles exceptions. A returned config **replaces** those options wholesale rather than being merged directive by directive, so include every directive the response needs. Return `{ cache: false }` to skip caching a response entirely — note that also sends `Cache-Control: no-store` to the client unless `client.mode` is `preserve`. The function receives the live response: it must not consume the body, and should call `response.clone()` if it needs to read it.
3238
+ * @public
3239
+ */
3240
+ declare interface CdnCacheControlConfigFunction {
3241
+ /**
3242
+ * Specifies the export that holds your cache config function, e.g. `default`, `cdnCacheConfig`.
3243
+ */
3244
+ export: string;
3245
+ /**
3246
+ * Specifies the module that holds your cache config function, in the format `$import(./modules/my-module)`.
3247
+ */
3248
+ module: string;
3249
+ }
3250
+
3251
+ /**
3252
+ * How long the CDN may serve this response. These directives are sent only to the CDN, never to the browser (unless `strategy` is `s-maxage`).
3253
+ * @public
3254
+ */
3255
+ declare interface CdnCacheControlEdgeOptions {
3256
+ /**
3257
+ * Seconds the CDN may serve this response without revalidating.
3258
+ */
3259
+ maxAge: number;
3260
+ /**
3261
+ * Seconds the CDN may keep serving a stale response while it revalidates in the background. Not expressible in Akamai's `Edge-Control` — configure it in Property Manager, or use `strategy: s-maxage`.
3262
+ */
3263
+ staleWhileRevalidate?: number;
3264
+ /**
3265
+ * Seconds the CDN may serve a stale response when the gateway returns an error. Not expressible in Akamai's `Edge-Control` — configure it in Property Manager, or use `strategy: s-maxage`.
3266
+ */
3267
+ staleIfError?: number;
3268
+ }
3269
+
3270
+ /**
3271
+ * Sets the response headers that tell a CDN how long it may cache a response and
3272
+ * which purge tags it belongs to, separately from what the browser is told.
3273
+ *
3274
+ * @title CDN Cache Control
3275
+ * @product api-gateway
3276
+ * @public
3277
+ * @param response - The Response
3278
+ * @param request - The ZuploRequest
3279
+ * @param context - The ZuploContext
3280
+ * @param options - The policy options set in policies.json
3281
+ * @param policyName - The name of the policy as set in policies.json
3282
+ * @returns A Response
3283
+ */
3284
+ export declare const CdnCacheControlOutboundPolicy: OutboundPolicyHandler<CdnCacheControlOutboundPolicyOptions>;
3285
+
3286
+ /**
3287
+ * The options for this policy.
3288
+ * @public
3289
+ */
3290
+ export declare interface CdnCacheControlOutboundPolicyOptions {
3291
+ cdn: CdnCacheControlVendor;
3292
+ strategy?: CdnCacheControlStrategy;
3293
+ edge?: CdnCacheControlEdgeOptions;
3294
+ client?: CdnCacheControlClientOptions;
3295
+ /**
3296
+ * Purge tags, rendered in the target CDN's format: comma-joined `Edge-Cache-Tag` (Akamai), space-joined `Surrogate-Key` (Fastly), comma-joined `Cache-Tag` (Cloudflare). CloudFront has no tag purge and rejects this option. Tags are validated against the CDN's length and character limits, because an over-long tag header is silently truncated rather than rejected.
3297
+ */
3298
+ tags?: string[];
3299
+ /**
3300
+ * Request headers that vary this response, unioned with any `Vary` the upstream already sent and emitted as `Vary`. The union is deliberate: replacing an upstream `Vary: Authorization` would stop a shared cache keying on it and let it serve one user's response to another. Off by default: Akamai skips caching any response carrying `Vary` until Cache ID Modification is configured, so enabling this can silently disable edge caching entirely.
3301
+ */
3302
+ vary?: string[];
3303
+ /**
3304
+ * When true (default), an upstream `Cache-Control` of `no-store`/`no-cache`/`private`, or a `Set-Cookie` on the response, suppresses all edge headers and purge tags. This keeps the application's ability to mark a response uncacheable. Set to false to override it — on Akamai this emits `Edge-Control: !no-store`.
3305
+ */
3306
+ respectUpstream?: boolean;
3307
+ cacheConfig?: CdnCacheControlConfigFunction;
3308
+ }
3309
+
3310
+ /**
3311
+ * How the edge TTL is carried. `targeted` uses the CDN's own header (`Edge-Control`, `Surrogate-Control`, `CDN-Cache-Control`) and is the only way to cache at the edge without also caching in the browser. `s-maxage` folds the edge TTL into `Cache-Control` instead, for a property that honors origin `Cache-Control` but not the targeted header. Defaults to `targeted`, except on a CDN that reads no targeted header — CloudFront defaults to `s-maxage`, which is the only thing it supports.
3312
+ * @public
3313
+ */
3314
+ declare type CdnCacheControlStrategy = "targeted" | "s-maxage";
3315
+
3316
+ /**
3317
+ * The CDN in front of this gateway. Required, with no default — each CDN reads a different header for shared-cache TTL and purge tags, and a wrong guess fails silently. Use `generic` for an RFC 9213 CDN that is not listed.
3318
+ * @public
3319
+ */
3320
+ declare type CdnCacheControlVendor =
3321
+ | "akamai"
3322
+ | "fastly"
3323
+ | "cloudflare"
3324
+ | "cloudfront"
3325
+ | "generic";
3326
+
3165
3327
  /**
3166
3328
  * Changes the HTTP method of the incoming request.
3167
3329
  *
@@ -3388,6 +3550,14 @@ export declare interface ClerkJwtInboundPolicyOptions {
3388
3550
  oAuthResourceMetadataEnabled?: boolean;
3389
3551
  }
3390
3552
 
3553
+ /** The client (browser/app) half of the policy. */
3554
+ export declare interface ClientCacheDirectives {
3555
+ maxAge?: number;
3556
+ visibility?: CdnCacheControlClientVisibility;
3557
+ mustRevalidate?: boolean;
3558
+ noCache?: boolean;
3559
+ }
3560
+
3391
3561
  /**
3392
3562
  * Authentication options for OIDC authentication.
3393
3563
  * @public
@@ -4603,6 +4773,13 @@ export declare class DynatraceMetricsPlugin extends MetricsPlugin {
4603
4773
  static setContext(context: ZuploContext, data: DynatraceMetricsContext): void;
4604
4774
  }
4605
4775
 
4776
+ /** The edge (shared cache) half of the policy. */
4777
+ export declare interface EdgeCacheDirectives {
4778
+ maxAge: number;
4779
+ staleWhileRevalidate?: number;
4780
+ staleIfError?: number;
4781
+ }
4782
+
4606
4783
  declare interface EmbeddingsFallbacks {
4607
4784
  fallback?: FallbackModel;
4608
4785
  quotaFallback?: QuotaFallbackModel;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.74.10",
4
+ "version": "6.74.12",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
@@ -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
  /**
@@ -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") {
113
125
  ;
114
126
  buffer[0] += child;
127
+ } else if (child.isEscaped) {
128
+ ;
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) {
@@ -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) {
@@ -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
@@ -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
  }