@timber-js/app 0.2.0-alpha.221 → 0.2.0-alpha.222

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 (118) hide show
  1. package/dist/_chunks/{actions-BDqn4Oxj.js → actions-vBHr2vqd.js} +3 -3
  2. package/dist/_chunks/{actions-BDqn4Oxj.js.map → actions-vBHr2vqd.js.map} +1 -1
  3. package/dist/_chunks/{cache-api-GE4AOe2H.js → cache-api-DdcDLpBj.js} +54 -6
  4. package/dist/_chunks/cache-api-DdcDLpBj.js.map +1 -0
  5. package/dist/_chunks/chains-B8TCLved.js +1 -0
  6. package/dist/_chunks/{chains-e_Buf9vg.js → chains-BchW_AtW.js} +2 -2
  7. package/dist/_chunks/{chains-e_Buf9vg.js.map → chains-BchW_AtW.js.map} +1 -1
  8. package/dist/_chunks/{classify-2Yp3xJY1.js → classify-IqzMpxMs.js} +2 -2
  9. package/dist/_chunks/{classify-2Yp3xJY1.js.map → classify-IqzMpxMs.js.map} +1 -1
  10. package/dist/_chunks/{cli-check-DDwCkeDY.js → cli-check-DQne_YhU.js} +3 -3
  11. package/dist/_chunks/{cli-check-DDwCkeDY.js.map → cli-check-DQne_YhU.js.map} +1 -1
  12. package/dist/_chunks/{cli-schema-sync-BdIebmk3.js → cli-schema-sync-BS-RFGE2.js} +2 -2
  13. package/dist/_chunks/{cli-schema-sync-BdIebmk3.js.map → cli-schema-sync-BS-RFGE2.js.map} +1 -1
  14. package/dist/_chunks/{cli-schema-sync-CLNfXQDK.js → cli-schema-sync-v872sHms.js} +1 -1
  15. package/dist/_chunks/{client-dep-entries-BOkpKjj1.js → client-dep-entries-BJyP9SIu.js} +2 -2
  16. package/dist/_chunks/{client-dep-entries-BOkpKjj1.js.map → client-dep-entries-BJyP9SIu.js.map} +1 -1
  17. package/dist/_chunks/{convention-lint-ByKJ6aqD.js → convention-lint-VwzrtjIt.js} +3 -3
  18. package/dist/_chunks/{convention-lint-ByKJ6aqD.js.map → convention-lint-VwzrtjIt.js.map} +1 -1
  19. package/dist/_chunks/{dev-server-DIy-SY-J.js → dev-server-BNr5drEO.js} +49 -5
  20. package/dist/_chunks/dev-server-BNr5drEO.js.map +1 -0
  21. package/dist/_chunks/dev-server-CUg7Mqh_.js +1 -0
  22. package/dist/_chunks/{flight-source-node-HptmGMT8.js → flight-source-node-BdHUOUqg.js} +3 -3
  23. package/dist/_chunks/{flight-source-node-HptmGMT8.js.map → flight-source-node-BdHUOUqg.js.map} +1 -1
  24. package/dist/_chunks/global-context-B9PFncvb.js +48 -0
  25. package/dist/_chunks/global-context-B9PFncvb.js.map +1 -0
  26. package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js → json-lossy-check-C3Sht92C.js} +2 -2
  27. package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js.map → json-lossy-check-C3Sht92C.js.map} +1 -1
  28. package/dist/_chunks/{live-graph-tSWrv8eH.js → live-graph-DEu_GWbc.js} +4 -4
  29. package/dist/_chunks/{live-graph-tSWrv8eH.js.map → live-graph-DEu_GWbc.js.map} +1 -1
  30. package/dist/_chunks/{logger-CbLdcy-W.js → logger-CI_hThfy.js} +10 -2
  31. package/dist/_chunks/{logger-CbLdcy-W.js.map → logger-CI_hThfy.js.map} +1 -1
  32. package/dist/_chunks/{node-response-rkQqcFGq.js → node-response-bF0bKoig.js} +2 -2
  33. package/dist/_chunks/{node-response-rkQqcFGq.js.map → node-response-bF0bKoig.js.map} +1 -1
  34. package/dist/_chunks/{poison-scan-C4FgMxFl.js → poison-scan-DTWIfNgD.js} +2 -2
  35. package/dist/_chunks/{poison-scan-C4FgMxFl.js.map → poison-scan-DTWIfNgD.js.map} +1 -1
  36. package/dist/_chunks/{render-timeout-joFhz4KH.js → render-timeout-Ln_u7fX-.js} +19 -2
  37. package/dist/_chunks/{render-timeout-joFhz4KH.js.map → render-timeout-Ln_u7fX-.js.map} +1 -1
  38. package/dist/_chunks/{resolve-schema-CBR6Lm4i.js → resolve-schema-CkAInout.js} +2 -2
  39. package/dist/_chunks/{resolve-schema-CBR6Lm4i.js.map → resolve-schema-CkAInout.js.map} +1 -1
  40. package/dist/_chunks/{scanner-Cb3fSjAC.js → scanner-C8fdKvKG.js} +2 -2
  41. package/dist/_chunks/{scanner-Cb3fSjAC.js.map → scanner-C8fdKvKG.js.map} +1 -1
  42. package/dist/_chunks/{schema-bridge-C83xa9lT.js → schema-bridge-DpOmvZlI.js} +60 -23
  43. package/dist/_chunks/schema-bridge-DpOmvZlI.js.map +1 -0
  44. package/dist/_chunks/{segment-context-xtPUGfdq.js → segment-context-D3DNxKFq.js} +4 -8
  45. package/dist/_chunks/segment-context-D3DNxKFq.js.map +1 -0
  46. package/dist/_chunks/{sizeof-QPE5nd3u.js → sizeof-CO3dk0V1.js} +2 -2
  47. package/dist/_chunks/{sizeof-QPE5nd3u.js.map → sizeof-CO3dk0V1.js.map} +1 -1
  48. package/dist/_chunks/{walkers-qu8TpiLh.js → walkers-BqzxnwGC.js} +3 -3
  49. package/dist/_chunks/{walkers-qu8TpiLh.js.map → walkers-BqzxnwGC.js.map} +1 -1
  50. package/dist/adapters/cloudflare-kv-cache.js +1 -1
  51. package/dist/analyze/crawl-entry.js +3 -3
  52. package/dist/analyze/graph-command.js +2 -2
  53. package/dist/cache/guarded-read.d.ts +29 -0
  54. package/dist/cache/guarded-read.d.ts.map +1 -0
  55. package/dist/cache/index.js +2 -2
  56. package/dist/cache/stores/memory.js +1 -1
  57. package/dist/cache/timber-cache.d.ts.map +1 -1
  58. package/dist/cli.js +3 -3
  59. package/dist/client/global-context.d.ts +21 -1
  60. package/dist/client/global-context.d.ts.map +1 -1
  61. package/dist/client/index.js +3 -12
  62. package/dist/client/index.js.map +1 -1
  63. package/dist/client/internal.js +1 -1
  64. package/dist/client/navigation-context.d.ts.map +1 -1
  65. package/dist/client/params-context.d.ts.map +1 -1
  66. package/dist/client/slot-context.d.ts +2 -2
  67. package/dist/client/slot-context.d.ts.map +1 -1
  68. package/dist/codec.js +1 -1
  69. package/dist/cookies/index.js +1 -1
  70. package/dist/index.js +7 -7
  71. package/dist/params/index.js +1 -1
  72. package/dist/plugins/dev-server.d.ts +1 -1
  73. package/dist/plugins/dev-server.d.ts.map +1 -1
  74. package/dist/plugins/dev-store-clear.d.ts +28 -0
  75. package/dist/plugins/dev-store-clear.d.ts.map +1 -0
  76. package/dist/routing/index.js +2 -2
  77. package/dist/schema-bridge.d.ts +28 -19
  78. package/dist/schema-bridge.d.ts.map +1 -1
  79. package/dist/search-params/define.d.ts +1 -1
  80. package/dist/search-params/define.d.ts.map +1 -1
  81. package/dist/search-params/index.js +7 -8
  82. package/dist/search-params/index.js.map +1 -1
  83. package/dist/search-params/wrappers.d.ts +3 -3
  84. package/dist/server/index.js +2 -2
  85. package/dist/server/internal.js +27 -24
  86. package/dist/server/internal.js.map +1 -1
  87. package/dist/server/logger.d.ts +9 -0
  88. package/dist/server/logger.d.ts.map +1 -1
  89. package/dist/server/prebuilt/overlay.d.ts +9 -3
  90. package/dist/server/prebuilt/overlay.d.ts.map +1 -1
  91. package/dist/server/prebuilt-runtime.d.ts.map +1 -1
  92. package/docs/api/33-api-search-params.mdx +3 -1
  93. package/docs/learn/06-typed-params.mdx +2 -2
  94. package/package.json +1 -1
  95. package/src/cache/guarded-read.ts +44 -0
  96. package/src/cache/timber-cache.ts +4 -2
  97. package/src/client/global-context.ts +42 -14
  98. package/src/client/navigation-context.ts +4 -11
  99. package/src/client/params-context.ts +5 -17
  100. package/src/client/segment-update-context.ts +1 -1
  101. package/src/client/slot-content-cache-context.ts +1 -1
  102. package/src/client/slot-context.ts +6 -17
  103. package/src/plugins/dev-server.ts +37 -3
  104. package/src/plugins/dev-store-clear.ts +47 -0
  105. package/src/rsc-runtime/vendor-types.d.ts +8 -0
  106. package/src/schema-bridge.ts +93 -38
  107. package/src/search-params/define.ts +5 -6
  108. package/src/search-params/wrappers.ts +3 -3
  109. package/src/server/action-handler.ts +18 -2
  110. package/src/server/logger.ts +9 -0
  111. package/src/server/prebuilt/overlay.ts +14 -4
  112. package/src/server/prebuilt-runtime.ts +20 -1
  113. package/dist/_chunks/cache-api-GE4AOe2H.js.map +0 -1
  114. package/dist/_chunks/chains-CDK1AWZQ.js +0 -1
  115. package/dist/_chunks/dev-server-BiWNMBVU.js +0 -1
  116. package/dist/_chunks/dev-server-DIy-SY-J.js.map +0 -1
  117. package/dist/_chunks/schema-bridge-C83xa9lT.js.map +0 -1
  118. package/dist/_chunks/segment-context-xtPUGfdq.js.map +0 -1
@@ -45,18 +45,20 @@ function fromParamSchema(fieldName, schema) {
45
45
  *
46
46
  * @param fieldName - used in error messages
47
47
  * @param value - the codec or schema to resolve
48
+ * Search params don't come through here: `defineSearchParams` wraps
49
+ * schemas with `fromSchema`, whose `serialize` may return `string[]`.
50
+ *
51
+ * @param fieldName - used in error messages
52
+ * @param value - the codec or schema to resolve
48
53
  * @param mode - 'param' uses fromParamSchema (throws on parse failure),
49
- * 'search' uses fromSchema (falls back to default on failure,
50
- * tolerant of the repeated-key array shape),
51
- * 'cookie' uses fromCookieSchema (same, minus the array shape,
52
- * which a cookie value cannot have)
54
+ * 'cookie' uses fromCookieSchema (falls back to default on
55
+ * failure; scalar shape only, since a cookie has no array shape)
53
56
  */
54
- function resolveCodecOrSchema(fieldName, value, mode = "search") {
57
+ function resolveCodecOrSchema(fieldName, value, mode) {
55
58
  if (isCodec(value)) return value;
56
59
  if (isStandardSchema(value)) {
57
60
  if (mode === "param") return fromParamSchema(fieldName, value);
58
- if (mode === "cookie") return fromCookieSchema(value);
59
- return fromSchema(value);
61
+ return fromCookieSchema(value);
60
62
  }
61
63
  throw new Error(`[timber] Field '${fieldName}' is not a valid codec or Standard Schema. Expected an object with { parse, serialize } methods, or a Standard Schema object (Zod, Valibot, ArkType).`);
62
64
  }
@@ -111,10 +113,9 @@ function parseThroughSchema(schema, candidates, value) {
111
113
  * schema should have a `.default()` call). If that also fails, returns
112
114
  * `undefined`.
113
115
  *
114
- * Serialize: `String()` for primitives, `null` for null/undefined. Note
115
- * that `String(['a','b'])` is `'a,b'` — the same string `fromArraySchema`
116
- * writes — so a bare array schema round-trips exactly as design/09
117
- * §"Array params" describes.
116
+ * Serialize: `String()` for primitives, `null` for null/undefined. An
117
+ * array is written in whichever encoding the schema reads back as the same
118
+ * array — see `serializeArrayForSchema`.
118
119
  *
119
120
  * This is the SEARCH-PARAM bridge. Cookies use `fromCookieSchema`; a
120
121
  * cookie has no array shape (see below).
@@ -129,13 +130,54 @@ function parseThroughSchema(schema, candidates, value) {
129
130
  function fromSchema(schema) {
130
131
  return {
131
132
  parse: (value) => parseThroughSchema(schema, scalarFirst, value),
132
- serialize(value) {
133
- if (value === null || value === void 0) return null;
134
- return String(value);
135
- }
133
+ serialize: (value) => Array.isArray(value) ? serializeArrayForSchema(schema, value) : serializeSearchValue(value)
136
134
  };
137
135
  }
138
136
  /**
137
+ * An array value has two URL encodings, and the schema alone decides which
138
+ * one reads back. `z.array(z.string())` reads repeated keys
139
+ * (`?tags=a&tags=b`); the comma idiom, `z.string().transform(v =>
140
+ * v.split(','))`, reads ONE key (`?tags=a,b`) and takes only the first of
141
+ * repeated keys. Writing the wrong one is silent data corruption: joining
142
+ * for an array schema reads back as the single element `'a,b'`, and
143
+ * repeating for the comma idiom reads back as `['a']`.
144
+ *
145
+ * Standard Schema exposes no input type at runtime, so ask the schema:
146
+ * parse the preferred encoding exactly as a request would deliver it, and
147
+ * keep it if the same array comes back. Otherwise write the joined string,
148
+ * which is what the comma idiom reads.
149
+ *
150
+ * An empty array prefers omitting the key, which reads back as `[]` for
151
+ * `z.array(z.string()).default([])`. A comma schema whose absent value is
152
+ * a non-empty default (`.catch(['all'])`) instead needs `tags=`, which its
153
+ * transform turns into `[]` — omitting would read back as `['all']`.
154
+ */
155
+ function serializeArrayForSchema(schema, value) {
156
+ const preferred = value.length === 0 ? null : value.map(String);
157
+ return readsBack(schema, preferred, value) ? preferred : String(value);
158
+ }
159
+ /** Does `encoded`, delivered as a request would, parse back to `value`? */
160
+ function readsBack(schema, encoded, value) {
161
+ const delivered = encoded === null ? void 0 : encoded.length === 1 ? encoded[0] : encoded;
162
+ let readBack;
163
+ try {
164
+ readBack = parseThroughSchema(schema, scalarFirst, delivered);
165
+ } catch {
166
+ return false;
167
+ }
168
+ return Array.isArray(readBack) && readBack.length === value.length && readBack.every((item, i) => String(item) === String(value[i]));
169
+ }
170
+ /**
171
+ * Search-param serialize for `fromSchema` and `fromArraySchema`. An array
172
+ * becomes `string[]` so it is written as repeated keys (TIM-1353); an empty
173
+ * array omits the key.
174
+ */
175
+ function serializeSearchValue(value) {
176
+ if (value === null || value === void 0) return null;
177
+ if (Array.isArray(value)) return value.length === 0 ? null : value.map(String);
178
+ return String(value);
179
+ }
180
+ /**
139
181
  * Bridge a Standard Schema for a COOKIE value.
140
182
  *
141
183
  * Identical to `fromSchema` minus the array shape, because a cookie cannot
@@ -180,20 +222,15 @@ function fromCookieSchema(schema) {
180
222
  * 2. An array schema wrapped in `.catch([])`, which swallows the failure
181
223
  * that would otherwise trigger the array attempt.
182
224
  *
183
- * It also serializes an empty array to `null` (omitting the key) where
184
- * `fromSchema` writes `''`.
225
+ * Serialization is identical to `fromSchema`.
185
226
  */
186
227
  function fromArraySchema(schema) {
187
228
  return {
188
229
  parse: (value) => parseThroughSchema(schema, arrayFirst, value),
189
- serialize(value) {
190
- if (value === null || value === void 0) return null;
191
- if (Array.isArray(value)) return value.length === 0 ? null : value.map(String);
192
- return String(value);
193
- }
230
+ serialize: serializeSearchValue
194
231
  };
195
232
  }
196
233
  //#endregion
197
234
  export { resolveCodecOrSchema as a, isStandardSchema as i, fromSchema as n, isCodec as r, fromArraySchema as t };
198
235
 
199
- //# sourceMappingURL=schema-bridge-C83xa9lT.js.map
236
+ //# sourceMappingURL=schema-bridge-DpOmvZlI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-bridge-DpOmvZlI.js","names":[],"sources":["../../src/schema-bridge.ts"],"sourcesContent":["/**\n * Standard Schema bridge — shared helpers for bridging Standard Schema-compatible\n * validation libraries (Zod, Valibot, ArkType) to the Codec<T> protocol.\n *\n * This module is the single source of truth for:\n * - StandardSchemaV1 interface (subset of the Standard Schema spec)\n * - validateSync() helper\n * - fromSchema() — search-param bridge; scalar shape first, array second\n * - fromArraySchema() — same loop, array shape first\n * - fromCookieSchema() — scalar shape only; a cookie has no array shape\n * - fromParamSchema() — route params; throws on failure (invalid param → 404)\n *\n * One parse loop, four candidate orders. Which shapes a bridge offers, and\n * in what order, is the ONLY thing that differs — see §\"Shape tolerance\"\n * below and in design/23-search-params.md. `serialize` is shared only by\n * the two search-param bridges (`serializeSearchValue`), never with the\n * cookie bridge: `null` means \"omit the key\" for a search param and\n * \"delete the cookie\" for a cookie, so unifying it silently changed what\n * `cookie.set([])` did (TIM-1352).\n *\n * These are re-exported from @timber-js/app/search-params, @timber-js/app/segment-params,\n * and @timber-js/app/cookies for convenience. The canonical import is\n * @timber-js/app/codec.\n *\n * Design doc: design/23a-search-params-triage.md §\"Unify Codec<T> type\"\n */\n\nimport type { Codec } from './codec.ts';\n\n// ---------------------------------------------------------------------------\n// Standard Schema interface (subset)\n//\n// Standard Schema (https://github.com/standard-schema/standard-schema) defines\n// a minimal interface that Zod ≥3.24, Valibot ≥1.0, and ArkType all implement.\n// We depend only on `~standard.validate` to avoid coupling to any specific lib.\n// ---------------------------------------------------------------------------\n\n/** Minimal Standard Schema interface for auto-detection. */\nexport interface StandardSchemaV1<Output = unknown> {\n readonly '~standard': {\n readonly validate: (\n value: unknown\n ) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;\n };\n}\n\nexport type StandardSchemaResult<Output> =\n | { value: Output; issues?: undefined }\n | { value?: undefined; issues: ReadonlyArray<{ message: string }> };\n\n// ---------------------------------------------------------------------------\n// Sync validate helper\n// ---------------------------------------------------------------------------\n\n/**\n * Run a Standard Schema's `~standard.validate()` synchronously.\n *\n * Zod v4's signature includes `Promise` in the return union to satisfy the\n * Standard Schema spec, but in practice Zod always validates synchronously\n * for the schema types we use. We assert the result is sync and throw if\n * it isn't — codec parsing must be synchronous.\n */\nexport function validateSync<Output>(\n schema: StandardSchemaV1<Output>,\n value: unknown\n): StandardSchemaResult<Output> {\n const result = schema['~standard'].validate(value);\n if (result instanceof Promise) {\n throw new Error(\n '[timber] fromSchema: schema returned a Promise — only sync schemas are supported.'\n );\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Type guards\n// ---------------------------------------------------------------------------\n\n/** Check if a value is a Standard Schema object. */\nexport function isStandardSchema(value: unknown): value is StandardSchemaV1 {\n return (\n typeof value === 'object' &&\n value !== null &&\n '~standard' in value &&\n typeof (value as StandardSchemaV1)['~standard']?.validate === 'function'\n );\n}\n\n/** Check if a value is a Codec (has parse + serialize methods). */\nexport function isCodec(value: unknown): value is Codec<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as Codec<unknown>).parse === 'function' &&\n typeof (value as Codec<unknown>).serialize === 'function'\n );\n}\n\n// ---------------------------------------------------------------------------\n// fromParamSchema — bridge from Standard Schema to Codec<T> for route params\n// ---------------------------------------------------------------------------\n\n/**\n * Bridge a Standard Schema to a Codec for route params.\n * Parse throws on failure (invalid param → 404). Serialize returns string.\n */\nexport function fromParamSchema<T>(fieldName: string, schema: StandardSchemaV1<T>): Codec<T> {\n return {\n parse(value: string | string[] | undefined): T {\n const result = validateSync(schema, value);\n if (!result.issues) {\n return result.value;\n }\n const messages = result.issues.map((i) => i.message).join(', ');\n throw new Error(`[timber] Param '${fieldName}' coercion failed: ${messages}`);\n },\n serialize(value: T): string | null {\n if (value === null || value === undefined) return null;\n if (Array.isArray(value)) return value.join('/');\n return String(value);\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// resolveCodecOrSchema — generic resolver for any codec-or-schema field\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve a field value to a Codec. Accepts Codec<T>, StandardSchemaV1<T>,\n * or (for route params) auto-wraps via fromParamSchema.\n *\n * @param fieldName - used in error messages\n * @param value - the codec or schema to resolve\n * Search params don't come through here: `defineSearchParams` wraps\n * schemas with `fromSchema`, whose `serialize` may return `string[]`.\n *\n * @param fieldName - used in error messages\n * @param value - the codec or schema to resolve\n * @param mode - 'param' uses fromParamSchema (throws on parse failure),\n * 'cookie' uses fromCookieSchema (falls back to default on\n * failure; scalar shape only, since a cookie has no array shape)\n */\nexport function resolveCodecOrSchema(\n fieldName: string,\n value: unknown,\n mode: 'param' | 'cookie'\n): Codec<unknown> {\n if (isCodec(value)) return value;\n if (isStandardSchema(value)) {\n if (mode === 'param') return fromParamSchema(fieldName, value);\n return fromCookieSchema(value) as Codec<unknown>;\n }\n throw new Error(\n `[timber] Field '${fieldName}' is not a valid codec or Standard Schema. ` +\n `Expected an object with { parse, serialize } methods, or a Standard Schema object ` +\n `(Zod, Valibot, ArkType).`\n );\n}\n\n// ---------------------------------------------------------------------------\n// fromSchema — bridge from Standard Schema to Codec<T>\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Shape tolerance — the shared parse loop for both bridges\n//\n// A URL value is `string | string[] | undefined`, but a schema is written\n// against ONE of those: `z.string()` wants `'a'`, `z.array(z.string())`\n// wants `['a']`. Nothing in Standard Schema says which — `~standard.types`\n// exists at the type level only, and probing at runtime is not reliable\n// (design/23-search-params.md §\"Shape tolerance\"). So a bridge tries BOTH\n// shapes rather than committing to one and discarding the value when it\n// guessed wrong.\n//\n// Each bridge only chooses WHICH candidates, and in what order. The first\n// candidate is always the shape that bridge already passed, so nothing that\n// parses today changes meaning; a later one is reached only where the old\n// code fell through to the default. `fromCookieSchema` offers ONE candidate,\n// because a cookie has no array shape at all.\n// ---------------------------------------------------------------------------\n\n/**\n * The scalar shape, and only it. A value that cannot be repeated — a cookie —\n * has no array shape to tolerate, so its bridge stays exactly where it was.\n */\nfunction scalarOnly(value: string | string[] | undefined): unknown[] {\n return [Array.isArray(value) ? value[0] : value];\n}\n\n/** Candidate inputs for the scalar bridge: scalar first, array second. */\nfunction scalarFirst(value: string | string[] | undefined): unknown[] {\n if (value === undefined) return [undefined];\n if (typeof value === 'string') return [value, [value]];\n // Repeated keys: `value[0]` matches URLSearchParams.get().\n //\n // A raw `[]` carries no value at all. `value[0]` is `undefined`, which is\n // the shape the scalar bridge has always passed for it, so `undefined`\n // stays FIRST — an empty array must keep meaning \"absent\" and land on the\n // schema's default. Only `defineSearchParams().parse({ tags: [] })`, the\n // record form, can produce one: URLSearchParams never yields an empty list.\n return value.length > 0 ? [value[0], value] : [undefined, value];\n}\n\n/** Candidate inputs for the array bridge: array first, scalar second. */\nfunction arrayFirst(value: string | string[] | undefined): unknown[] {\n if (value === undefined) return [undefined];\n if (typeof value === 'string') return [[value], value];\n // `[]` first here for the same reason, inverted: the array bridge has\n // always passed the empty array straight through.\n return value.length > 0 ? [value, value[0]] : [value, undefined];\n}\n\n/**\n * Validate `value` against `schema` in each candidate shape, then fall back\n * to the schema's default. Shared by every bridge — they differ only in\n * which candidates they offer, and in what order.\n */\nfunction parseThroughSchema<T>(\n schema: StandardSchemaV1<T>,\n candidates: (value: string | string[] | undefined) => unknown[],\n value: string | string[] | undefined\n): T {\n const inputs = candidates(value);\n for (let i = 0; i < inputs.length; i++) {\n // A throw from the FIRST candidate propagates, unchanged: that is the\n // shape the schema was written against, and a throw from it is the\n // deliberate signal design/23 protects — an app schema may `redirect()`\n // or `notFound()` on a value it refuses, and `validateSync` throws on\n // an async schema.\n //\n // A throw from a LATER candidate is ours, not the app's. We invented\n // that shape; the schema never agreed to receive it. A scalar-only\n // hand-written validator doing `value.toUpperCase()`, or a schema that\n // is async for the array shape only, would turn a field that used to\n // fall back to its default into a render-phase 500. Treat it as \"this\n // shape does not fit\" and keep going.\n let result: StandardSchemaResult<T>;\n try {\n result = validateSync(schema, inputs[i]);\n } catch (error) {\n if (i === 0) throw error;\n continue;\n }\n if (!result.issues) {\n return result.value;\n }\n }\n\n // No shape validated — try parsing undefined to get the default.\n // Re-validate each time so factory defaults (e.g. .default(() => []))\n // produce fresh values.\n const defaultResult = validateSync(schema, undefined);\n if (!defaultResult.issues) {\n return defaultResult.value;\n }\n\n // No default available — the field is implicitly optional. Return\n // undefined; defineSearchParams widens the field's inferred type to\n // T | undefined via InferField so this doesn't lie.\n // design/23-search-params.md §\"Implicit Optionality\"\n return undefined as T;\n}\n\n/**\n * Bridge a Standard Schema-compatible schema (Zod, Valibot, ArkType) to a\n * Codec<T>.\n *\n * Parse: coerces the raw URL value through the schema, trying the scalar\n * shape and then the array shape (see `scalarFirst`), so an array schema\n * works bare: `z.array(z.string()).default([])` yields `[]` when absent,\n * `['a']` for `?tags=a`, and `['a','b']` for `?tags=a&tags=b`. When no\n * shape validates, parses `undefined` to get the schema's default (the\n * schema should have a `.default()` call). If that also fails, returns\n * `undefined`.\n *\n * Serialize: `String()` for primitives, `null` for null/undefined. An\n * array is written in whichever encoding the schema reads back as the same\n * array — see `serializeArrayForSchema`.\n *\n * This is the SEARCH-PARAM bridge. Cookies use `fromCookieSchema`; a\n * cookie has no array shape (see below).\n *\n * ```ts\n * import { z } from 'zod/v4'\n *\n * const pageCodec = fromSchema(z.coerce.number().int().min(1).default(1))\n * const tagsCodec = fromSchema(z.array(z.string()).default([]))\n * ```\n */\nexport function fromSchema<T>(schema: StandardSchemaV1<T>): SearchValueCodec<T> {\n return {\n parse: (value: string | string[] | undefined): T =>\n parseThroughSchema(schema, scalarFirst, value),\n serialize: (value: T): string | string[] | null =>\n Array.isArray(value) ? serializeArrayForSchema(schema, value) : serializeSearchValue(value),\n };\n}\n\n/**\n * An array value has two URL encodings, and the schema alone decides which\n * one reads back. `z.array(z.string())` reads repeated keys\n * (`?tags=a&tags=b`); the comma idiom, `z.string().transform(v =>\n * v.split(','))`, reads ONE key (`?tags=a,b`) and takes only the first of\n * repeated keys. Writing the wrong one is silent data corruption: joining\n * for an array schema reads back as the single element `'a,b'`, and\n * repeating for the comma idiom reads back as `['a']`.\n *\n * Standard Schema exposes no input type at runtime, so ask the schema:\n * parse the preferred encoding exactly as a request would deliver it, and\n * keep it if the same array comes back. Otherwise write the joined string,\n * which is what the comma idiom reads.\n *\n * An empty array prefers omitting the key, which reads back as `[]` for\n * `z.array(z.string()).default([])`. A comma schema whose absent value is\n * a non-empty default (`.catch(['all'])`) instead needs `tags=`, which its\n * transform turns into `[]` — omitting would read back as `['all']`.\n */\nfunction serializeArrayForSchema<T>(\n schema: StandardSchemaV1<T>,\n value: unknown[]\n): string | string[] | null {\n const preferred = value.length === 0 ? null : value.map(String);\n return readsBack(schema, preferred, value) ? preferred : String(value);\n}\n\n/** Does `encoded`, delivered as a request would, parse back to `value`? */\nfunction readsBack<T>(\n schema: StandardSchemaV1<T>,\n encoded: string[] | null,\n value: unknown[]\n): boolean {\n // An omitted key arrives as undefined; URLSearchParams.getAll() yields\n // one value as a plain string.\n const delivered = encoded === null ? undefined : encoded.length === 1 ? encoded[0] : encoded;\n let readBack: unknown;\n try {\n readBack = parseThroughSchema(schema, scalarFirst, delivered);\n } catch {\n // The schema refuses this URL outright, so it is not the encoding.\n return false;\n }\n return (\n Array.isArray(readBack) &&\n readBack.length === value.length &&\n readBack.every((item, i) => String(item) === String(value[i]))\n );\n}\n\n/**\n * The codec shape both search-param bridges return. Structurally a\n * `SearchParamCodec<T>` (search-params/define.ts), declared here because\n * define.ts imports this module.\n */\ninterface SearchValueCodec<T> {\n parse(value: string | string[] | undefined): T;\n serialize(value: T): string | string[] | null;\n}\n\n/**\n * Search-param serialize for `fromSchema` and `fromArraySchema`. An array\n * becomes `string[]` so it is written as repeated keys (TIM-1353); an empty\n * array omits the key.\n */\nfunction serializeSearchValue(value: unknown): string | string[] | null {\n if (value === null || value === undefined) return null;\n if (Array.isArray(value)) return value.length === 0 ? null : value.map(String);\n return String(value);\n}\n\n// ---------------------------------------------------------------------------\n// fromCookieSchema — bridge for cookie values\n// ---------------------------------------------------------------------------\n\n/**\n * Bridge a Standard Schema for a COOKIE value.\n *\n * Identical to `fromSchema` minus the array shape, because a cookie cannot\n * carry one: `Cookie:` headers and `document.cookie` yield a single string\n * per name, and there is no repeated-key concept to be tolerant of. Sharing\n * the search-param bridge here meant a cookie written by this very codec —\n * `serialize(['a','b'])` → `a,b` — read back as the one-element array\n * `['a,b']` instead of failing to its default: no repeated key in sight,\n * just a delimiter reinterpreted as data.\n *\n * The `serialize` contract also differs by domain and must not be unified:\n * for a search param `null` means \"omit the key\", for a cookie it means\n * **delete the cookie** (design/29-cookies.md).\n */\nexport function fromCookieSchema<T>(schema: StandardSchemaV1<T>): Codec<T> {\n return {\n parse: (value: string | string[] | undefined): T =>\n parseThroughSchema(schema, scalarOnly, value),\n serialize(value: T): string | null {\n if (value === null || value === undefined) {\n return null;\n }\n return String(value);\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// fromArraySchema — bridge for array-valued codecs\n// ---------------------------------------------------------------------------\n\n/**\n * Bridge a Standard Schema for array values. Handles both single strings\n * and repeated query keys (`?tag=a&tag=b`).\n *\n * ```ts\n * import { fromArraySchema } from '@timber-js/app/codec'\n * import { z } from 'zod/v4'\n *\n * const tagsCodec = fromArraySchema(z.array(z.string()).default([]))\n * ```\n *\n * Since TIM-1352 a bare array schema works through `fromSchema` too, so\n * this is no longer required to make an array field parse. Two cases still\n * want it, both listed in design/23 §\"Shape tolerance\":\n *\n * 1. A **permissive** schema meant as an array — one that accepts a string\n * as readily as an array (`z.any()`, a hand-written coercing validator)\n * — where scalar-first ordering would settle on the scalar shape.\n * 2. An array schema wrapped in `.catch([])`, which swallows the failure\n * that would otherwise trigger the array attempt.\n *\n * Serialization is identical to `fromSchema`.\n */\nexport function fromArraySchema<T>(schema: StandardSchemaV1<T>): SearchValueCodec<T> {\n return {\n parse: (value: string | string[] | undefined): T =>\n parseThroughSchema(schema, arrayFirst, value),\n serialize: serializeSearchValue,\n };\n}\n"],"mappings":";;;;;;;;;AA8DA,SAAgB,aACd,QACA,OAC8B;CAC9B,MAAM,SAAS,OAAO,YAAY,CAAC,SAAS,KAAK;CACjD,IAAI,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AAW,IAAI,QAAQ,KAAK;CACrF,IAAI;CACJ,IAAI;EACF,WAAW,mBAAmB,QAAQ,aAAa,SAAS;CAC9D,QAAQ;EAEN,OAAO;CACT;CACA,OACE,MAAM,QAAQ,QAAQ,KACtB,SAAS,WAAW,MAAM,UAC1B,SAAS,OAAO,MAAM,MAAM,OAAO,IAAI,MAAM,OAAO,MAAM,EAAE,CAAC;AAEjE;;;;;;AAiBA,SAAS,qBAAqB,OAA0C;CACtE,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,WAAW,IAAI,OAAO,MAAM,IAAI,MAAM;CAC7E,OAAO,OAAO,KAAK;AACrB;;;;;;;;;;;;;;;;AAqBA,SAAgB,iBAAoB,QAAuC;CACzE,OAAO;EACL,QAAQ,UACN,mBAAmB,QAAQ,YAAY,KAAK;EAC9C,UAAU,OAAyB;GACjC,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC9B,OAAO;GAET,OAAO,OAAO,KAAK;EACrB;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,gBAAmB,QAAkD;CACnF,OAAO;EACL,QAAQ,UACN,mBAAmB,QAAQ,YAAY,KAAK;EAC9C,WAAW;CACb;AACF"}
@@ -1,3 +1,4 @@
1
+ import { t as createGlobalContext } from "./global-context-B9PFncvb.js";
1
2
  import { createContext, createElement, useContext, useMemo } from "react";
2
3
  //#region src/client/navigation-context.ts
3
4
  /**
@@ -54,15 +55,10 @@ import { createContext, createElement, useContext, useMemo } from "react";
54
55
  * The shims plugin resolves next/navigation to navigation-rsc.ts in RSC,
55
56
  * which has throwing stubs for the hooks (TIM-1420).
56
57
  *
57
- * See design/27-chunking-strategy.md §"Singleton Safety"
58
+ * See design/19-client-navigation.md §"Singleton Guarantee via globalThis"
58
59
  */
59
- var NAV_CTX_KEY = Symbol.for("__timber_nav_ctx");
60
60
  function getOrCreateContext() {
61
- const existing = globalThis[NAV_CTX_KEY];
62
- if (existing !== void 0) return existing;
63
- const ctx = createContext(null);
64
- globalThis[NAV_CTX_KEY] = ctx;
65
- return ctx;
61
+ return createGlobalContext(Symbol.for("__timber_nav_ctx"), null);
66
62
  }
67
63
  /**
68
64
  * Read the navigation context. Returns null only when no provider is above
@@ -134,4 +130,4 @@ function SegmentProvider({ segments, segmentId: _segmentId, parallelRouteKeys, c
134
130
  //#endregion
135
131
  export { useNavigationContext as i, useSegmentContext as n, NavigationProvider as r, SegmentProvider as t };
136
132
 
137
- //# sourceMappingURL=segment-context-xtPUGfdq.js.map
133
+ //# sourceMappingURL=segment-context-D3DNxKFq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segment-context-D3DNxKFq.js","names":[],"sources":["../../src/client/navigation-context.ts","../../src/client/segment-context.ts"],"sourcesContent":["'use client';\n\n/**\n * NavigationContext — React context for navigation state.\n *\n * Holds the current pathname and search, updated atomically with the RSC\n * tree on each navigation. This replaces the previous useSyncExternalStore\n * approach for usePathname() and useSearchParams(), which suffered from a\n * timing gap: the new tree could commit before the external store\n * re-renders fired, causing a frame where both old and new active states\n * were visible simultaneously.\n *\n * Segment params are NOT here — see the note on NavigationState below.\n *\n * By wrapping the RSC payload element in NavigationProvider inside the\n * router's `renderTree` (browser-entry/router-init.ts), the context value and the element tree are passed to\n * reactRoot.render() in the same call — atomic by construction.\n * All consumers (usePathname, useSearchParams) see the new values in the\n * same render pass as the new tree.\n *\n * During SSR, the wrapper chain mounts this same provider with the\n * request's pathname and raw search string (TIM-1424), so the hooks\n * resolve through the identical code path on both sides. Per-request\n * isolation is by construction — the value is part of the request's\n * element tree.\n *\n * This module is `'use client'` and is never evaluated in the RSC\n * environment. The shims plugin resolves next/navigation to\n * navigation-rsc.ts in RSC, which has throwing stubs (TIM-1420).\n *\n * SINGLETON GUARANTEE: All shared mutable state uses globalThis via\n * Symbol.for keys. The RSC client bundler can duplicate this module\n * across chunks (browser-entry graph + client-reference graph). With\n * ESM output, each chunk gets its own module scope — module-level\n * variables would create separate singleton instances per chunk.\n * globalThis guarantees a single instance regardless of duplication.\n *\n * This workaround will be removed when Rolldown ships `format: 'app'`\n * (module registry format that deduplicates like webpack/Turbopack).\n * See design/27-chunking-strategy.md.\n *\n * See design/19-client-navigation.md §\"NavigationContext\"\n */\n\nimport { useContext, createElement, type ReactNode } from 'react';\nimport { createGlobalContext } from './global-context.ts';\n\n// ---------------------------------------------------------------------------\n// Context type\n// ---------------------------------------------------------------------------\n\n/**\n * What the browser knows about the current location.\n *\n * Params are deliberately absent: they are a property of the tree the server\n * rendered, not of the address bar, and they now travel inside the payload as\n * the payload root. Keeping a copy here meant the router had to thread\n * the record from a response header into context on every path — navigation,\n * traversal, prefetch, revalidation — and each of those was a place to drop it\n * (TIM-1294).\n */\nexport interface NavigationState {\n pathname: string;\n search: string;\n}\n\n// ---------------------------------------------------------------------------\n// Lazy context initialization\n// ---------------------------------------------------------------------------\n\n/**\n * Context instances are stored on globalThis (NOT in module-level\n * variables) because the ESM bundler can duplicate this module across\n * chunks. Module-level variables would create separate instances per\n * chunk — the provider in NavigationRoot (index chunk) would use\n * context A while the consumer in usePendingNavigation (shared chunk)\n * reads from context B. globalThis guarantees a single instance.\n *\n * This module is `'use client'` so it is never evaluated in the RSC\n * environment — `createContext` and `useContext` are always available.\n * The shims plugin resolves next/navigation to navigation-rsc.ts in RSC,\n * which has throwing stubs for the hooks (TIM-1420).\n *\n * See design/19-client-navigation.md §\"Singleton Guarantee via globalThis\"\n */\n\nfunction getOrCreateContext(): import('react').Context<NavigationState | null> {\n return createGlobalContext<NavigationState | null>(Symbol.for('__timber_nav_ctx'), null);\n}\n\n/**\n * Read the navigation context. Returns null only when no provider is above\n * the caller — a component rendered outside the timber app.\n *\n * Internal — used by usePathname() and useSearchParams().\n */\nexport function useNavigationContext(): NavigationState | null {\n return useContext(getOrCreateContext());\n}\n\n// ---------------------------------------------------------------------------\n// Provider component\n// ---------------------------------------------------------------------------\n\nexport interface NavigationProviderProps {\n value: NavigationState;\n children?: ReactNode;\n}\n\n/**\n * Wraps children with NavigationContext.Provider.\n *\n * Used in browser-entry/router-init.ts `renderTree` to wrap the RSC payload element\n * so that navigation state updates atomically with the tree render.\n */\nexport function NavigationProvider({\n value,\n children,\n}: NavigationProviderProps): import('react').ReactElement {\n return createElement(getOrCreateContext().Provider, { value }, children);\n}\n\n// ---------------------------------------------------------------------------\n// Pending navigation state lives in the router, not here\n// ---------------------------------------------------------------------------\n\n/**\n * There was a second React context here — `PendingNavigationContext`, holding\n * the in-flight navigation URL, provided by `NavigationRoot` out of a\n * `useState` — plus a `usePendingNavigationUrl()` reader for it. Both are gone\n * (TIM-1307).\n *\n * Nothing read them. `usePendingNavigation()` (use-pending-navigation.ts) and\n * `TopLoader` both subscribe to the router's external pending store via\n * `useSyncExternalStore`: sync priority, immune to transition entanglement,\n * and cleared by `runNavigation`'s supersession-guarded `finally` (TIM-1034).\n * The context was a parallel representation of the same fact that no consumer\n * ever migrated to, and one that could not even agree with the store — a\n * navigation superseded by a cached popstate replay left its URL set until the\n * next full navigation, because the staleness guard skipped the clear and no\n * other path touched it.\n *\n * One representation, and it is the router's. See\n * design/19-client-navigation.md §\"How Pending State Works\".\n */\n","/**\n * Segment Context — provides layout segment position for useSelectedLayoutSegment hooks.\n *\n * Each layout in the segment tree is wrapped with a SegmentProvider that stores\n * the URL segments from root to the current layout level. The hooks read this\n * context to determine which child segments are active below the calling layout.\n *\n * The context value is intentionally minimal: just the segment path array and\n * parallel route keys. No internal cache details are exposed.\n *\n * Design docs: design/19-client-navigation.md, design/14-ecosystem.md\n */\n\n'use client';\n\nimport { createContext, useContext, createElement, useMemo } from 'react';\n\n// ─── Types ───────────────────────────────────────────────────────\n\nexport interface SegmentContextValue {\n /** URL segments from root to this layout (e.g. ['', 'dashboard', 'settings']) */\n segments: string[];\n /** Parallel route slot keys available at this layout level (e.g. ['sidebar', 'modal']) */\n parallelRouteKeys: string[];\n}\n\n// ─── Context ─────────────────────────────────────────────────────\n\nconst SegmentContext = createContext<SegmentContextValue | null>(null);\n\n/** Read the segment context. Returns null if no provider is above this component. */\nexport function useSegmentContext(): SegmentContextValue | null {\n return useContext(SegmentContext);\n}\n\n// ─── Provider ────────────────────────────────────────────────────\n\ninterface SegmentProviderProps {\n segments: string[];\n /**\n * Unique identifier for this segment, used by the client-side segment\n * merger for element caching. For route groups this includes the group\n * name (e.g., \"/(marketing)\") since groups share their parent's urlPath.\n * Falls back to the reconstructed path from `segments` if not provided.\n */\n segmentId?: string;\n parallelRouteKeys: string[];\n children: React.ReactNode;\n}\n\n/**\n * Wraps each layout to provide segment position context.\n * Injected by rsc-entry.ts during element tree construction.\n */\nexport function SegmentProvider({\n segments,\n segmentId: _segmentId,\n parallelRouteKeys,\n children,\n}: SegmentProviderProps) {\n const value = useMemo(\n () => ({ segments, parallelRouteKeys }),\n // segments and parallelRouteKeys are static per layout — the layout's\n // position in the tree is fixed. The arrays are used directly as deps\n // (React Compiler requires simple expressions here). Referential stability\n // of the context value doesn't matter: every consumer\n // (useSelectedLayoutSegment/useSelectedLayoutSegments) also calls\n // usePathname(), so it re-renders on every navigation regardless.\n [segments, parallelRouteKeys]\n );\n return createElement(SegmentContext.Provider, { value }, children);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,SAAS,qBAAsE;CAC7E,OAAO,oBAA4C,OAAO,IAAI,kBAAkB,GAAG,IAAI;AACzF;;;;;;;AAQA,SAAgB,uBAA+C;CAC7D,OAAO,WAAW,mBAAmB,CAAC;AACxC;;;;;;;AAiBA,SAAgB,mBAAmB,EACjC,OACA,YACwD;CACxD,OAAO,cAAc,mBAAmB,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;AACzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5FA,IAAM,iBAAiB,cAA0C,IAAI;;AAGrE,SAAgB,oBAAgD;CAC9D,OAAO,WAAW,cAAc;AAClC;;;;;AAqBA,SAAgB,gBAAgB,EAC9B,UACA,WAAW,YACX,mBACA,YACuB;CACvB,MAAM,QAAQ,eACL;EAAE;EAAU;CAAkB,IAOrC,CAAC,UAAU,iBAAiB,CAC9B;CACA,OAAO,cAAc,eAAe,UAAU,EAAE,MAAM,GAAG,QAAQ;AACnE"}
@@ -1,4 +1,4 @@
1
- import { v as swallow } from "./logger-CbLdcy-W.js";
1
+ import { y as swallow } from "./logger-CI_hThfy.js";
2
2
  //#region src/cache/sizeof.ts
3
3
  /**
4
4
  * Lightweight byte-size estimation for cache entries.
@@ -33,4 +33,4 @@ function estimateByteSize(value) {
33
33
  //#endregion
34
34
  export { estimateByteSize as t };
35
35
 
36
- //# sourceMappingURL=sizeof-QPE5nd3u.js.map
36
+ //# sourceMappingURL=sizeof-CO3dk0V1.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sizeof-QPE5nd3u.js","names":[],"sources":["../../src/cache/sizeof.ts"],"sourcesContent":["/**\n * Lightweight byte-size estimation for cache entries.\n *\n * Estimates the in-memory byte cost of a JavaScript value using\n * JSON.stringify().length * 2 (UTF-16 char width). This is a rough\n * approximation — it doesn't account for V8 object overhead, Map\n * metadata, or non-serializable values — but it's fast and good\n * enough for cache budget enforcement.\n *\n * Values that fail JSON serialization (circular references, BigInt,\n * etc.) return 0, allowing the entry to be cached without counting\n * toward the byte budget. This is a conservative choice: it's better\n * to cache and undercount than to reject the entry.\n */\n\nimport { swallow } from '../server/logger.ts';\n\n/**\n * Estimate the byte size of a value.\n *\n * Uses `JSON.stringify(value).length * 2` to approximate UTF-16\n * in-memory size. Returns 0 if the value is not serializable.\n */\nexport function estimateByteSize(value: unknown): number {\n try {\n const json = JSON.stringify(value);\n if (json === undefined) return 0;\n // Each JS string character is 2 bytes (UTF-16)\n return json.length * 2;\n } catch (e) {\n // Circular reference or non-serializable value\n swallow(e, 'sizeof estimation failed', { level: 'debug' });\n return 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,iBAAiB,OAAwB;CACvD,IAAI;EACF,MAAM,OAAO,KAAK,UAAU,KAAK;EACjC,IAAI,SAAS,KAAA,GAAW,OAAO;EAE/B,OAAO,KAAK,SAAS;CACvB,SAAS,GAAG;EAEV,QAAQ,GAAG,4BAA4B,EAAE,OAAO,QAAQ,CAAC;EACzD,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"sizeof-CO3dk0V1.js","names":[],"sources":["../../src/cache/sizeof.ts"],"sourcesContent":["/**\n * Lightweight byte-size estimation for cache entries.\n *\n * Estimates the in-memory byte cost of a JavaScript value using\n * JSON.stringify().length * 2 (UTF-16 char width). This is a rough\n * approximation — it doesn't account for V8 object overhead, Map\n * metadata, or non-serializable values — but it's fast and good\n * enough for cache budget enforcement.\n *\n * Values that fail JSON serialization (circular references, BigInt,\n * etc.) return 0, allowing the entry to be cached without counting\n * toward the byte budget. This is a conservative choice: it's better\n * to cache and undercount than to reject the entry.\n */\n\nimport { swallow } from '../server/logger.ts';\n\n/**\n * Estimate the byte size of a value.\n *\n * Uses `JSON.stringify(value).length * 2` to approximate UTF-16\n * in-memory size. Returns 0 if the value is not serializable.\n */\nexport function estimateByteSize(value: unknown): number {\n try {\n const json = JSON.stringify(value);\n if (json === undefined) return 0;\n // Each JS string character is 2 bytes (UTF-16)\n return json.length * 2;\n } catch (e) {\n // Circular reference or non-serializable value\n swallow(e, 'sizeof estimation failed', { level: 'debug' });\n return 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,iBAAiB,OAAwB;CACvD,IAAI;EACF,MAAM,OAAO,KAAK,UAAU,KAAK;EACjC,IAAI,SAAS,KAAA,GAAW,OAAO;EAE/B,OAAO,KAAK,SAAS;CACvB,SAAS,GAAG;EAEV,QAAQ,GAAG,4BAA4B,EAAE,OAAO,QAAQ,CAAC;EACzD,OAAO;CACT;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { n as classifyUrlSegment } from "./segment-classify-C539Pa2O.js";
2
- import { u as readFileCached } from "./scanner-Cb3fSjAC.js";
3
- import { a as parseExistingSchemaKeys, r as findSchemaFile } from "./cli-schema-sync-BdIebmk3.js";
2
+ import { u as readFileCached } from "./scanner-C8fdKvKG.js";
3
+ import { a as parseExistingSchemaKeys, r as findSchemaFile } from "./cli-schema-sync-BS-RFGE2.js";
4
4
  //#region src/routing/schema-validation.ts
5
5
  /**
6
6
  * Schema key/value validation against the filesystem route tree.
@@ -141,4 +141,4 @@ function walk(node, chain, result, includeSlots) {
141
141
  //#endregion
142
142
  export { collectDynamicSegmentsFromTree as n, validateSchemaAgainstRoutes as r, collectLeafRoutes as t };
143
143
 
144
- //# sourceMappingURL=walkers-qu8TpiLh.js.map
144
+ //# sourceMappingURL=walkers-BqzxnwGC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"walkers-qu8TpiLh.js","names":[],"sources":["../../src/routing/schema-validation.ts","../../src/routing/walkers.ts"],"sourcesContent":["/**\n * Schema key/value validation against the filesystem route tree.\n *\n * Runs at codegen time (build + dev) to catch mismatches between\n * app/schema.ts keys and the actual dynamic segments on disk.\n *\n * Design doc: design/41-global-params.md\n */\n\nimport { readFileCached } from './file-cache.ts';\nimport type { RouteTree, SegmentNode } from './types.ts';\nimport { findSchemaFile, parseExistingSchemaKeys } from '../cli-schema-sync.ts';\nimport { classifyUrlSegment } from './segment-classify.ts';\n\nexport interface SchemaWarning {\n type: 'stale-key' | 'missing-key' | 'bracket-mismatch';\n key: string;\n message: string;\n filesystemKey?: string;\n}\n\n/**\n * Collect all unique bracket-keyed dynamic segment names from a route tree.\n * Returns entries like '[artistSlug]', '[...slug]', '[[...topic]]'.\n */\nexport function collectDynamicSegmentsFromTree(tree: RouteTree): Set<string> {\n const segments = new Set<string>();\n walkTree(tree.root, segments);\n return segments;\n}\n\nfunction walkTree(node: SegmentNode, segments: Set<string>): void {\n if (node.paramName && node.segmentName) {\n const classified = classifyUrlSegment(node.segmentName);\n if (classified.kind !== 'static') {\n // Use bare bracket form for schema keys — affixed segments like\n // `img-[id].png` register as `[id]`, matching runtime codec lookup.\n if (classified.kind === 'dynamic' && (classified.prefix || classified.suffix)) {\n segments.add(`[${classified.name}]`);\n } else {\n segments.add(node.segmentName);\n }\n }\n }\n for (const child of node.children) {\n walkTree(child, segments);\n }\n for (const slot of Object.values(node.slots)) {\n walkTree(slot, segments);\n }\n}\n\n/**\n * Extract the param name from a bracket key.\n * '[id]' → 'id', '[...slug]' → 'slug', '[[...topic]]' → 'topic'\n */\nfunction extractParamName(bracketKey: string): string | null {\n const seg = classifyUrlSegment(bracketKey);\n if (seg.kind === 'static') return null;\n return seg.name;\n}\n\n/**\n * Validate schema keys against the filesystem route tree.\n *\n * Returns warnings for:\n * - Stale keys: schema keys that don't match any filesystem segment\n * - Bracket form mismatches: same param name, different bracket form\n * - Missing keys: filesystem segments not registered in schema (informational)\n */\nexport function validateSchemaAgainstRoutes(tree: RouteTree, appDir: string): SchemaWarning[] {\n const schemaPath = findSchemaFile(appDir);\n if (!schemaPath) return [];\n\n const content = readFileCached(schemaPath);\n const schemaKeys = parseExistingSchemaKeys(content);\n\n if (schemaKeys.length === 0) return [];\n\n const filesystemSegments = collectDynamicSegmentsFromTree(tree);\n\n return validateKeys(schemaKeys, filesystemSegments);\n}\n\n/**\n * Core validation: compare schema keys against filesystem segments.\n * Exported separately for testing without filesystem dependencies.\n */\nexport function validateKeys(\n schemaKeys: string[],\n filesystemSegments: Set<string>\n): SchemaWarning[] {\n const warnings: SchemaWarning[] = [];\n\n // Build a map of param name → bracket form for filesystem segments\n const fsParamToKey = new Map<string, string>();\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name) {\n fsParamToKey.set(name, fsKey);\n }\n }\n\n // Build a set of schema param names for the missing-key check\n const schemaParamNames = new Set<string>();\n\n for (const schemaKey of schemaKeys) {\n const schemaParamName = extractParamName(schemaKey);\n if (!schemaParamName) continue;\n\n schemaParamNames.add(schemaParamName);\n\n if (filesystemSegments.has(schemaKey)) {\n // Exact match — no issue\n continue;\n }\n\n // Check if the param name exists but with a different bracket form\n const fsKey = fsParamToKey.get(schemaParamName);\n if (fsKey) {\n warnings.push({\n type: 'bracket-mismatch',\n key: schemaKey,\n filesystemKey: fsKey,\n message:\n `Schema key '${schemaKey}' does not match filesystem bracket form '${fsKey}'. ` +\n `Update the schema key to '${fsKey}'.`,\n });\n } else {\n warnings.push({\n type: 'stale-key',\n key: schemaKey,\n message:\n `Schema key '${schemaKey}' does not match any dynamic segment in the filesystem. ` +\n `Remove it from app/schema.ts or create the corresponding route segment.`,\n });\n }\n }\n\n // Check for filesystem segments not in schema (informational)\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name && !schemaParamNames.has(name)) {\n warnings.push({\n type: 'missing-key',\n key: fsKey,\n message:\n `Dynamic segment '${fsKey}' has no codec in app/schema.ts (defaults to string). ` +\n `Run: timber schema sync`,\n });\n }\n }\n\n return warnings;\n}\n","/**\n * Shared route-tree walkers (TIM-848).\n *\n * Tiny helpers that walk a `SegmentNode<TFile>` tree generically. Both the\n * build-time tree (`SegmentNode<RouteFile>`) and the runtime manifest\n * tree (`SegmentNode<ManifestFile>`) flow through these helpers because\n * the walker only reads the structural fields shared by both shapes\n * (`children`, `slots`, `page`, `route`, `urlPath`).\n *\n * Before this module, three near-identical `collectRoutes` functions\n * lived in `plugins/dev-404-page.ts`, `plugins/build-report.ts`, and\n * `routing/codegen.ts`. The codegen one is special-purpose (it\n * accumulates `ParamEntry[]` and resolves codec chains) and stays\n * local; the other two now share `collectLeafRoutes` from this file.\n */\n\nimport type { SegmentNode } from './types.ts';\n\n/** A leaf route discovered while walking the segment tree. */\nexport interface LeafRoute<TFile> {\n /** URL path of the leaf (root is \"/\"). */\n urlPath: string;\n /** Segment chain from root to this leaf, inclusive. */\n segments: SegmentNode<TFile>[];\n /** The page file at this leaf, if any. */\n page?: TFile;\n /** The route handler file at this leaf, if any. */\n route?: TFile;\n}\n\n/** Options for `collectLeafRoutes`. */\nexport interface CollectLeafRoutesOptions {\n /**\n * If true, recurse into parallel slots and emit slot leaves alongside\n * the main route tree. Defaults to `false` because slots render\n * alongside their parent at the same URL and are not separately\n * URL-addressable. The build report excludes slots; route-listing\n * UIs that want to show \"all leaves with a page handler\" can opt in.\n */\n includeSlots?: boolean;\n}\n\n/**\n * Walk a segment tree and collect every leaf with a `page` or `route`\n * handler. Generic over `TFile` so it works on both the build-time\n * scanner output and the runtime manifest tree.\n *\n * - Pages and route handlers at the same URL produce two distinct\n * entries (the build report deduplicates by URL afterward).\n * - Parallel slots are skipped unless `includeSlots: true` (slots\n * share their parent's URL and are not addressable on their own).\n * - Intercepting subtrees are skipped unconditionally. They render only\n * on soft navigation and add no URL depth, so their computed `urlPath`s\n * are not addresses — listing them would advertise routes (`/[year]`)\n * that no request can reach. This matches every other consumer of the\n * tree that produces URLs: the sitemap generator, the static generator,\n * prerendering and the prebuilt-payload builder all skip them too.\n * - Result is sorted by `urlPath` for deterministic output.\n */\nexport function collectLeafRoutes<TFile>(\n root: SegmentNode<TFile>,\n options: CollectLeafRoutesOptions = {}\n): LeafRoute<TFile>[] {\n const { includeSlots = false } = options;\n const result: LeafRoute<TFile>[] = [];\n walk(root, [], result, includeSlots);\n result.sort((a, b) => a.urlPath.localeCompare(b.urlPath));\n return result;\n}\n\nfunction walk<TFile>(\n node: SegmentNode<TFile>,\n chain: SegmentNode<TFile>[],\n result: LeafRoute<TFile>[],\n includeSlots: boolean\n): void {\n if (node.segmentType === 'intercepting') return;\n\n const currentChain = [...chain, node];\n const path = node.urlPath || '/';\n\n if (node.page) {\n result.push({ urlPath: path, segments: currentChain, page: node.page });\n }\n if (node.route) {\n result.push({ urlPath: path, segments: currentChain, route: node.route });\n }\n\n for (const child of node.children) {\n walk(child, currentChain, result, includeSlots);\n }\n\n if (includeSlots) {\n for (const slotNode of Object.values(node.slots)) {\n walk(slotNode, currentChain, result, includeSlots);\n }\n }\n}\n"],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K,MAAM,YAAY,OAAO,OAAO,KAAK,KAAK,GAC7C,KAAK,UAAU,cAAc,QAAQ,YAAY;AAGvD"}
1
+ {"version":3,"file":"walkers-BqzxnwGC.js","names":[],"sources":["../../src/routing/schema-validation.ts","../../src/routing/walkers.ts"],"sourcesContent":["/**\n * Schema key/value validation against the filesystem route tree.\n *\n * Runs at codegen time (build + dev) to catch mismatches between\n * app/schema.ts keys and the actual dynamic segments on disk.\n *\n * Design doc: design/41-global-params.md\n */\n\nimport { readFileCached } from './file-cache.ts';\nimport type { RouteTree, SegmentNode } from './types.ts';\nimport { findSchemaFile, parseExistingSchemaKeys } from '../cli-schema-sync.ts';\nimport { classifyUrlSegment } from './segment-classify.ts';\n\nexport interface SchemaWarning {\n type: 'stale-key' | 'missing-key' | 'bracket-mismatch';\n key: string;\n message: string;\n filesystemKey?: string;\n}\n\n/**\n * Collect all unique bracket-keyed dynamic segment names from a route tree.\n * Returns entries like '[artistSlug]', '[...slug]', '[[...topic]]'.\n */\nexport function collectDynamicSegmentsFromTree(tree: RouteTree): Set<string> {\n const segments = new Set<string>();\n walkTree(tree.root, segments);\n return segments;\n}\n\nfunction walkTree(node: SegmentNode, segments: Set<string>): void {\n if (node.paramName && node.segmentName) {\n const classified = classifyUrlSegment(node.segmentName);\n if (classified.kind !== 'static') {\n // Use bare bracket form for schema keys — affixed segments like\n // `img-[id].png` register as `[id]`, matching runtime codec lookup.\n if (classified.kind === 'dynamic' && (classified.prefix || classified.suffix)) {\n segments.add(`[${classified.name}]`);\n } else {\n segments.add(node.segmentName);\n }\n }\n }\n for (const child of node.children) {\n walkTree(child, segments);\n }\n for (const slot of Object.values(node.slots)) {\n walkTree(slot, segments);\n }\n}\n\n/**\n * Extract the param name from a bracket key.\n * '[id]' → 'id', '[...slug]' → 'slug', '[[...topic]]' → 'topic'\n */\nfunction extractParamName(bracketKey: string): string | null {\n const seg = classifyUrlSegment(bracketKey);\n if (seg.kind === 'static') return null;\n return seg.name;\n}\n\n/**\n * Validate schema keys against the filesystem route tree.\n *\n * Returns warnings for:\n * - Stale keys: schema keys that don't match any filesystem segment\n * - Bracket form mismatches: same param name, different bracket form\n * - Missing keys: filesystem segments not registered in schema (informational)\n */\nexport function validateSchemaAgainstRoutes(tree: RouteTree, appDir: string): SchemaWarning[] {\n const schemaPath = findSchemaFile(appDir);\n if (!schemaPath) return [];\n\n const content = readFileCached(schemaPath);\n const schemaKeys = parseExistingSchemaKeys(content);\n\n if (schemaKeys.length === 0) return [];\n\n const filesystemSegments = collectDynamicSegmentsFromTree(tree);\n\n return validateKeys(schemaKeys, filesystemSegments);\n}\n\n/**\n * Core validation: compare schema keys against filesystem segments.\n * Exported separately for testing without filesystem dependencies.\n */\nexport function validateKeys(\n schemaKeys: string[],\n filesystemSegments: Set<string>\n): SchemaWarning[] {\n const warnings: SchemaWarning[] = [];\n\n // Build a map of param name → bracket form for filesystem segments\n const fsParamToKey = new Map<string, string>();\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name) {\n fsParamToKey.set(name, fsKey);\n }\n }\n\n // Build a set of schema param names for the missing-key check\n const schemaParamNames = new Set<string>();\n\n for (const schemaKey of schemaKeys) {\n const schemaParamName = extractParamName(schemaKey);\n if (!schemaParamName) continue;\n\n schemaParamNames.add(schemaParamName);\n\n if (filesystemSegments.has(schemaKey)) {\n // Exact match — no issue\n continue;\n }\n\n // Check if the param name exists but with a different bracket form\n const fsKey = fsParamToKey.get(schemaParamName);\n if (fsKey) {\n warnings.push({\n type: 'bracket-mismatch',\n key: schemaKey,\n filesystemKey: fsKey,\n message:\n `Schema key '${schemaKey}' does not match filesystem bracket form '${fsKey}'. ` +\n `Update the schema key to '${fsKey}'.`,\n });\n } else {\n warnings.push({\n type: 'stale-key',\n key: schemaKey,\n message:\n `Schema key '${schemaKey}' does not match any dynamic segment in the filesystem. ` +\n `Remove it from app/schema.ts or create the corresponding route segment.`,\n });\n }\n }\n\n // Check for filesystem segments not in schema (informational)\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name && !schemaParamNames.has(name)) {\n warnings.push({\n type: 'missing-key',\n key: fsKey,\n message:\n `Dynamic segment '${fsKey}' has no codec in app/schema.ts (defaults to string). ` +\n `Run: timber schema sync`,\n });\n }\n }\n\n return warnings;\n}\n","/**\n * Shared route-tree walkers (TIM-848).\n *\n * Tiny helpers that walk a `SegmentNode<TFile>` tree generically. Both the\n * build-time tree (`SegmentNode<RouteFile>`) and the runtime manifest\n * tree (`SegmentNode<ManifestFile>`) flow through these helpers because\n * the walker only reads the structural fields shared by both shapes\n * (`children`, `slots`, `page`, `route`, `urlPath`).\n *\n * Before this module, three near-identical `collectRoutes` functions\n * lived in `plugins/dev-404-page.ts`, `plugins/build-report.ts`, and\n * `routing/codegen.ts`. The codegen one is special-purpose (it\n * accumulates `ParamEntry[]` and resolves codec chains) and stays\n * local; the other two now share `collectLeafRoutes` from this file.\n */\n\nimport type { SegmentNode } from './types.ts';\n\n/** A leaf route discovered while walking the segment tree. */\nexport interface LeafRoute<TFile> {\n /** URL path of the leaf (root is \"/\"). */\n urlPath: string;\n /** Segment chain from root to this leaf, inclusive. */\n segments: SegmentNode<TFile>[];\n /** The page file at this leaf, if any. */\n page?: TFile;\n /** The route handler file at this leaf, if any. */\n route?: TFile;\n}\n\n/** Options for `collectLeafRoutes`. */\nexport interface CollectLeafRoutesOptions {\n /**\n * If true, recurse into parallel slots and emit slot leaves alongside\n * the main route tree. Defaults to `false` because slots render\n * alongside their parent at the same URL and are not separately\n * URL-addressable. The build report excludes slots; route-listing\n * UIs that want to show \"all leaves with a page handler\" can opt in.\n */\n includeSlots?: boolean;\n}\n\n/**\n * Walk a segment tree and collect every leaf with a `page` or `route`\n * handler. Generic over `TFile` so it works on both the build-time\n * scanner output and the runtime manifest tree.\n *\n * - Pages and route handlers at the same URL produce two distinct\n * entries (the build report deduplicates by URL afterward).\n * - Parallel slots are skipped unless `includeSlots: true` (slots\n * share their parent's URL and are not addressable on their own).\n * - Intercepting subtrees are skipped unconditionally. They render only\n * on soft navigation and add no URL depth, so their computed `urlPath`s\n * are not addresses — listing them would advertise routes (`/[year]`)\n * that no request can reach. This matches every other consumer of the\n * tree that produces URLs: the sitemap generator, the static generator,\n * prerendering and the prebuilt-payload builder all skip them too.\n * - Result is sorted by `urlPath` for deterministic output.\n */\nexport function collectLeafRoutes<TFile>(\n root: SegmentNode<TFile>,\n options: CollectLeafRoutesOptions = {}\n): LeafRoute<TFile>[] {\n const { includeSlots = false } = options;\n const result: LeafRoute<TFile>[] = [];\n walk(root, [], result, includeSlots);\n result.sort((a, b) => a.urlPath.localeCompare(b.urlPath));\n return result;\n}\n\nfunction walk<TFile>(\n node: SegmentNode<TFile>,\n chain: SegmentNode<TFile>[],\n result: LeafRoute<TFile>[],\n includeSlots: boolean\n): void {\n if (node.segmentType === 'intercepting') return;\n\n const currentChain = [...chain, node];\n const path = node.urlPath || '/';\n\n if (node.page) {\n result.push({ urlPath: path, segments: currentChain, page: node.page });\n }\n if (node.route) {\n result.push({ urlPath: path, segments: currentChain, route: node.route });\n }\n\n for (const child of node.children) {\n walk(child, currentChain, result, includeSlots);\n }\n\n if (includeSlots) {\n for (const slotNode of Object.values(node.slots)) {\n walk(slotNode, currentChain, result, includeSlots);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAgB,+BAA+B,MAA8B;CAC3E,MAAM,2BAAW,IAAI,IAAY;CACjC,SAAS,KAAK,MAAM,QAAQ;CAC5B,OAAO;AACT;AAEA,SAAS,SAAS,MAAmB,UAA6B;CAChE,IAAI,KAAK,aAAa,KAAK,aAAa;EACtC,MAAM,aAAa,mBAAmB,KAAK,WAAW;EACtD,IAAI,WAAW,SAAS,UAAU;GAGhC,IAAI,WAAW,SAAS,cAAc,WAAW,UAAU,WAAW,SACpE,SAAS,IAAI,IAAI,WAAW,KAAK,EAAE;QAEnC,SAAS,IAAI,KAAK,WAAW;EAEjC;CACF;CACA,KAAK,MAAM,SAAS,KAAK,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Q,CAAC,iBAAiB,IAAI,IAAI,GACpC,SAAS,KAAK;GACZ,MAAM;GACN,KAAK;GACL,SACE,oBAAoB,MAAM;EAE9B,CAAC;CAEL;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;AC/FA,SAAgB,kBACd,MACA,UAAoC,CAAC,GACjB;CACpB,MAAM,EAAE,eAAe,UAAU;CACjC,MAAM,SAA6B,CAAC;CACpC,KAAK,MAAM,CAAC,GAAG,QAAQ,YAAY;CACnC,OAAO,MAAM,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,CAAC;CACxD,OAAO;AACT;AAEA,SAAS,KACP,MACA,OACA,QACA,cACM;CACN,IAAI,KAAK,gBAAgB,gBAAgB;CAEzC,MAAM,eAAe,CAAC,GAAG,OAAO,IAAI;CACpC,MAAM,OAAO,KAAK,WAAW;CAE7B,IAAI,KAAK,MACP,OAAO,KAAK;EAAE,SAAS;EAAM,UAAU;EAAc,MAAM,KAAK;CAAK,CAAC;CAExE,IAAI,KAAK,OACP,OAAO,KAAK;EAAE,SAAS;EAAM,UAAU;EAAc,OAAO,KAAK;CAAM,CAAC;CAG1E,KAAK,MAAM,SAAS,KAAK,UACvB,KAAK,OAAO,cAAc,QAAQ,YAAY;CAGhD,IAAI,cACF,KAAK,MAAM,YAAY,OAAO,OAAO,KAAK,KAAK,GAC7C,KAAK,UAAU,cAAc,QAAQ,YAAY;AAGvD"}
@@ -1,4 +1,4 @@
1
- import { t as warnLossyJsonValue } from "../_chunks/json-lossy-check-C8zBY2uZ.js";
1
+ import { t as warnLossyJsonValue } from "../_chunks/json-lossy-check-C3Sht92C.js";
2
2
  import { l as getCloudflareBindings } from "../_chunks/cloudflare-Byxl8FWP.js";
3
3
  //#region src/adapters/cloudflare-kv-cache.ts
4
4
  var LEGACY_GRACE_MS = 2592e6;
@@ -1,8 +1,8 @@
1
1
  import { i as scanProjectSourceFiles, n as isScannableSourceFile, t as buildSourceExtensions } from "../_chunks/scan-BoP17W3w.js";
2
2
  import { s as isTimberPluginApi, u as resolveAppDir } from "../_chunks/plugin-context-DxMMvjUt.js";
3
- import { i as detectDirective, r as classifyModules } from "../_chunks/classify-2Yp3xJY1.js";
4
- import { n as stitchImportChains } from "../_chunks/chains-e_Buf9vg.js";
5
- import { n as importSignals, r as poisoningsFor, t as collectImportSpecifiers } from "../_chunks/poison-scan-C4FgMxFl.js";
3
+ import { i as detectDirective, r as classifyModules } from "../_chunks/classify-IqzMpxMs.js";
4
+ import { n as stitchImportChains } from "../_chunks/chains-BchW_AtW.js";
5
+ import { n as importSignals, r as poisoningsFor, t as collectImportSpecifiers } from "../_chunks/poison-scan-DTWIfNgD.js";
6
6
  import { normalizePath } from "vite";
7
7
  import { join, resolve } from "node:path";
8
8
  import { readFile, realpath, writeFile } from "node:fs/promises";
@@ -378,7 +378,7 @@ async function printSingleFile(input, target, module, answer, json) {
378
378
  console.log(` environments: ${envs.length > 0 ? envs.join(", ") : "none"}`);
379
379
  if (module.subtreeUnknown) console.log(" note: reachable, but its subtree is unknown (never transformed)");
380
380
  if (module.chains.length > 0) {
381
- const { formatChains } = await import("../_chunks/chains-CDK1AWZQ.js");
381
+ const { formatChains } = await import("../_chunks/chains-B8TCLved.js");
382
382
  console.log(" import chains:");
383
383
  console.log(formatChains(module.chains, root));
384
384
  }
@@ -397,7 +397,7 @@ async function printDevServerText(data, configDir) {
397
397
  console.log(` environments: ${envList.length > 0 ? envList.join(", ") : "none"}`);
398
398
  if (data.subtreeUnknown) console.log(" note: reachable, but its subtree is unknown (never transformed)");
399
399
  if (data.chains.length > 0) {
400
- const { formatChains } = await import("../_chunks/chains-CDK1AWZQ.js");
400
+ const { formatChains } = await import("../_chunks/chains-B8TCLved.js");
401
401
  console.log(" import chains:");
402
402
  console.log(formatChains(data.chains, configDir));
403
403
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Cache reads never fail a request.
3
+ *
4
+ * A cache is an optimization: when the store is down, slow, or returns
5
+ * garbage, the request must still succeed by doing the work the cache would
6
+ * have skipped. Writes already follow this rule (timber-cache.ts swallows a
7
+ * failed handler.set, TIM-1046); reads go through here so a throwing or hung
8
+ * handler.get costs a live fetch or render, never a failed or stalled request.
9
+ *
10
+ * The timeout matters as much as the catch. Shared-store clients often queue
11
+ * commands while disconnected (ioredis retries each one up to 20 times by
12
+ * default), so an outage shows up as a read that never settles, not an error.
13
+ *
14
+ * Invalidation is deliberately NOT guarded: a failed invalidate that looked
15
+ * like success would leave stale data in place silently.
16
+ *
17
+ * See design/06-caching.md §"Store failures".
18
+ */
19
+ /** Ceiling for a single cache read. A healthy store answers in milliseconds. */
20
+ export declare const CACHE_READ_TIMEOUT_MS = 1000;
21
+ /**
22
+ * Run a cache read. A throw, a rejection, or no answer within
23
+ * CACHE_READ_TIMEOUT_MS logs a warning and resolves to `onFailure`, which the
24
+ * caller picks: `null` where a failed read means "miss", a distinct value
25
+ * where a miss would fall back to something the failed read might have
26
+ * overridden (an invalidated build seed — server/prebuilt/overlay.ts).
27
+ */
28
+ export declare function guardedRead<T, F>(cacheKey: string, read: () => Promise<T>, onFailure: F): Promise<T | F>;
29
+ //# sourceMappingURL=guarded-read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guarded-read.d.ts","sourceRoot":"","sources":["../../src/cache/guarded-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAE3C;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,GACX,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAOhB"}
@@ -1,4 +1,4 @@
1
1
  import { g as getCacheHandler, v as setCacheHandler } from "../_chunks/dev-store-BOa304m_.js";
2
- import { d as MemoryCacheHandler, f as TagAwareCacheHandler, m as setDefaultSingleflightTimeout, p as RedisCacheHandler, t as cache } from "../_chunks/cache-api-GE4AOe2H.js";
3
- import { t as estimateByteSize } from "../_chunks/sizeof-QPE5nd3u.js";
2
+ import { d as MemoryCacheHandler, f as TagAwareCacheHandler, m as setDefaultSingleflightTimeout, p as RedisCacheHandler, t as cache } from "../_chunks/cache-api-DdcDLpBj.js";
3
+ import { t as estimateByteSize } from "../_chunks/sizeof-CO3dk0V1.js";
4
4
  export { MemoryCacheHandler, RedisCacheHandler, TagAwareCacheHandler, cache, estimateByteSize, getCacheHandler, setCacheHandler, setDefaultSingleflightTimeout };
@@ -1,4 +1,4 @@
1
- import { t as estimateByteSize } from "../../_chunks/sizeof-QPE5nd3u.js";
1
+ import { t as estimateByteSize } from "../../_chunks/sizeof-CO3dk0V1.js";
2
2
  //#region src/cache/stores/memory.ts
3
3
  var MemoryCacheStore = class {
4
4
  store = /* @__PURE__ */ new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"timber-cache.d.ts","sourceRoot":"","sources":["../../src/cache/timber-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAgC7D;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAErE;AAoED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAAgB,WAAW,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EACrE,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,EACtB,UAAU,EAAE,MAAM,YAAY,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,EAAE,CAoHJ"}
1
+ {"version":3,"file":"timber-cache.d.ts","sourceRoot":"","sources":["../../src/cache/timber-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAiC7D;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAErE;AAoED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAAgB,WAAW,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EACrE,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,EACtB,UAAU,EAAE,MAAM,YAAY,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,EAAE,CAqHJ"}
package/dist/cli.js CHANGED
@@ -90,7 +90,7 @@ async function runDev(options, _deps) {
90
90
  return;
91
91
  }
92
92
  const { fork } = await import("node:child_process");
93
- const { RESTART_EXIT_CODE } = await import("./_chunks/dev-server-BiWNMBVU.js");
93
+ const { RESTART_EXIT_CODE } = await import("./_chunks/dev-server-CUg7Mqh_.js");
94
94
  while (true) {
95
95
  const result = await new Promise((resolve) => {
96
96
  const child = fork(process.argv[1], process.argv.slice(2), {
@@ -170,7 +170,7 @@ async function runPreview(options, _deps) {
170
170
  * `--project` names the tsconfig handed to tsgo.
171
171
  */
172
172
  async function runCheck(options, _deps) {
173
- const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-DDwCkeDY.js");
173
+ const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-DQne_YhU.js");
174
174
  const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);
175
175
  await runTypeCheck({
176
176
  root,
@@ -186,7 +186,7 @@ async function runCheck(options, _deps) {
186
186
  async function runSchema(args) {
187
187
  const subcommand = args[0];
188
188
  if (subcommand !== "sync") throw new Error(`Unknown schema subcommand: ${subcommand ?? "(none)"}. Usage: timber schema sync`);
189
- const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync-CLNfXQDK.js");
189
+ const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync-v872sHms.js");
190
190
  const result = runSchemaSync(process.cwd());
191
191
  if (result.filesystemSegments.length === 0) {
192
192
  console.log("[timber] No dynamic segments found in app/.");
@@ -8,8 +8,28 @@
8
8
  * level would create separate instances per chunk. globalThis guarantees a
9
9
  * single instance regardless of duplication.
10
10
  *
11
+ * One context per React instance, not per process. Duplicated chunks share
12
+ * one React, so they share the context. A dev SSR program reload evaluates
13
+ * React and react-dom/server again, in the same process: the new renderer
14
+ * must get a context of its own. Handed the previous one, React logs
15
+ * "Detected multiple renderers concurrently rendering the same context
16
+ * provider" on every client-component edit, and the stale context keeps a
17
+ * piece of the discarded copy alive (TIM-1590).
18
+ *
11
19
  * See design/19-client-navigation.md §"Singleton Guarantee via globalThis"
12
20
  */
13
21
  import React from 'react';
14
- export declare function createGlobalContext<T>(key: string, defaultValue: T): React.Context<T>;
22
+ /** The part of a React instance a context comes from. */
23
+ export interface ContextFactory {
24
+ createContext?: typeof React.createContext;
25
+ }
26
+ /**
27
+ * The context `key` names for this React instance, created on first use.
28
+ * Pass the key as a `Symbol.for('…')` literal at the call site, so each key
29
+ * stays greppable in the build output (tests/bundle-singleton-audit.test.ts
30
+ * checks `__timber_nav_ctx`).
31
+ */
32
+ export declare function createGlobalContext<T>(key: symbol, defaultValue: T): React.Context<T>;
33
+ /** createGlobalContext for a given React instance. Exported for tests. */
34
+ export declare function createGlobalContextFor<T>(react: ContextFactory, key: symbol, defaultValue: T): React.Context<T>;
15
35
  //# sourceMappingURL=global-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"global-context.d.ts","sourceRoot":"","sources":["../../src/client/global-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAarF"}
1
+ {"version":3,"file":"global-context.d.ts","sourceRoot":"","sources":["../../src/client/global-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B,aAAa,CAAC,EAAE,OAAO,KAAK,CAAC,aAAa,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAErF;AAED,0EAA0E;AAC1E,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,KAAK,EAAE,cAAc,EACrB,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,CAAC,GACd,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAelB"}
@@ -3,10 +3,11 @@ import { n as classifyUrlSegment } from "../_chunks/segment-classify-C539Pa2O.js
3
3
  import { c as stripRscCacheKey } from "../_chunks/rsc-cache-key-ClUiXQnK.js";
4
4
  import { a as mergePreservedSearchParams, i as validateNavigationHref, n as isInternalHref, o as resolveSegmentParams } from "../_chunks/href-validation-BIrxavIy.js";
5
5
  import "../_chunks/param-value-C8TNYchQ.js";
6
+ import { t as createGlobalContext } from "../_chunks/global-context-B9PFncvb.js";
6
7
  import { i as getRouterOrNull, n as usePendingNavigation } from "../_chunks/navigation-root-BQfo1-kG.js";
7
8
  import { t as getSsrData } from "../_chunks/ssr-data-nA3I70_n.js";
8
9
  import { t as getLinkCodec } from "../_chunks/codec-registry-oOUxugz3.js";
9
- import { i as useNavigationContext, n as useSegmentContext } from "../_chunks/segment-context-xtPUGfdq.js";
10
+ import { i as useNavigationContext, n as useSegmentContext } from "../_chunks/segment-context-D3DNxKFq.js";
10
11
  import { n as useQueryStates } from "../_chunks/use-query-states-I3JMng6J.js";
11
12
  import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
12
13
  import { flushSync } from "react-dom";
@@ -757,17 +758,7 @@ function useFieldState(defaultValue) {
757
758
  *
758
759
  * See design/19-client-navigation.md §"Singleton Guarantee via globalThis"
759
760
  */
760
- var PARAMS_CTX_KEY = Symbol.for("__timber_params_ctx");
761
- function getOrCreateContext() {
762
- const store = globalThis;
763
- const existing = store[PARAMS_CTX_KEY];
764
- if (existing !== void 0) return existing;
765
- if (typeof React.createContext !== "function") return;
766
- const ctx = React.createContext(null);
767
- store[PARAMS_CTX_KEY] = ctx;
768
- return ctx;
769
- }
770
- var ParamsContext = getOrCreateContext();
761
+ var ParamsContext = createGlobalContext(Symbol.for("__timber_params_ctx"), null);
771
762
  /**
772
763
  * Read the params provided by the tree. Returns null only when no provider
773
764
  * is above the caller — a component rendered outside a timber route. During