@timber-js/app 0.2.0-alpha.230 → 0.2.0-alpha.231

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 (77) hide show
  1. package/agent-skill.md +13 -0
  2. package/dist/_chunks/{actions-DHum77eH.js → actions-CYjRMpZI.js} +3 -2
  3. package/dist/_chunks/{actions-DHum77eH.js.map → actions-CYjRMpZI.js.map} +1 -1
  4. package/dist/_chunks/{cli-check-B-JZkpBD.js → cli-check-BAKOSTkg.js} +2 -2
  5. package/dist/_chunks/{cli-check-B-JZkpBD.js.map → cli-check-BAKOSTkg.js.map} +1 -1
  6. package/dist/_chunks/codec-registry-C8hOGmZo.js +13 -0
  7. package/dist/_chunks/codec-registry-C8hOGmZo.js.map +1 -0
  8. package/dist/_chunks/{codegen-B9oWkWGf.js → codegen-vaCyFyVN.js} +67 -17
  9. package/dist/_chunks/codegen-vaCyFyVN.js.map +1 -0
  10. package/dist/_chunks/{convention-lint-CrDKERHg.js → convention-lint-D54k6uUM.js} +2 -2
  11. package/dist/_chunks/{convention-lint-CrDKERHg.js.map → convention-lint-D54k6uUM.js.map} +1 -1
  12. package/dist/_chunks/href-BtspoNc9.js +164 -0
  13. package/dist/_chunks/href-BtspoNc9.js.map +1 -0
  14. package/dist/_chunks/href-validation-DNg-zV7u.js +102 -0
  15. package/dist/_chunks/href-validation-DNg-zV7u.js.map +1 -0
  16. package/dist/_chunks/merge-search-params-7o_5yX0L.js +111 -0
  17. package/dist/_chunks/merge-search-params-7o_5yX0L.js.map +1 -0
  18. package/dist/cli.js +1 -1
  19. package/dist/client/index.d.ts +2 -1
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/index.js +3 -121
  22. package/dist/client/index.js.map +1 -1
  23. package/dist/client/link.d.ts +4 -25
  24. package/dist/client/link.d.ts.map +1 -1
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +4 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/params/codec-registry.d.ts +21 -11
  30. package/dist/params/codec-registry.d.ts.map +1 -1
  31. package/dist/params/index.d.ts +0 -1
  32. package/dist/params/index.d.ts.map +1 -1
  33. package/dist/params/index.js +1 -2
  34. package/dist/params/index.js.map +1 -1
  35. package/dist/plugins/shims.d.ts.map +1 -1
  36. package/dist/routes/href.d.ts +124 -0
  37. package/dist/routes/href.d.ts.map +1 -0
  38. package/dist/routes/index.d.ts +4 -0
  39. package/dist/routes/index.d.ts.map +1 -0
  40. package/dist/routes/index.js +8 -0
  41. package/dist/routes/index.js.map +1 -0
  42. package/dist/routing/codegen.d.ts.map +1 -1
  43. package/dist/routing/index.js +1 -1
  44. package/dist/routing/link-codegen.d.ts +39 -8
  45. package/dist/routing/link-codegen.d.ts.map +1 -1
  46. package/dist/server/index.js +1 -1
  47. package/dist/server/internal.js +4 -6
  48. package/dist/server/internal.js.map +1 -1
  49. package/dist/server/param-coercion.d.ts +0 -7
  50. package/dist/server/param-coercion.d.ts.map +1 -1
  51. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  52. package/dist/shared/href.d.ts +88 -0
  53. package/dist/shared/href.d.ts.map +1 -0
  54. package/docs/api/31-api-client.mdx +1 -1
  55. package/docs/api/35-api-typescript.mdx +47 -15
  56. package/docs/learn/07-typed-routes.mdx +75 -10
  57. package/package.json +5 -1
  58. package/src/client/browser-entry/index.ts +4 -4
  59. package/src/client/index.ts +3 -1
  60. package/src/client/link.tsx +5 -238
  61. package/src/index.ts +3 -0
  62. package/src/params/codec-registry.ts +24 -11
  63. package/src/params/index.ts +0 -1
  64. package/src/plugins/shims.ts +10 -0
  65. package/src/routes/href.ts +171 -0
  66. package/src/routes/index.ts +10 -0
  67. package/src/routing/codegen.ts +8 -1
  68. package/src/routing/link-codegen.ts +103 -37
  69. package/src/server/param-coercion.ts +5 -23
  70. package/src/server/rsc-entry/index.ts +6 -3
  71. package/src/server/ssr-entry.ts +2 -2
  72. package/src/shared/href.ts +257 -0
  73. package/dist/_chunks/codec-registry-CPc6bjVl.js +0 -20
  74. package/dist/_chunks/codec-registry-CPc6bjVl.js.map +0 -1
  75. package/dist/_chunks/codegen-B9oWkWGf.js.map +0 -1
  76. package/dist/_chunks/href-validation-CEZy1V-k.js +0 -210
  77. package/dist/_chunks/href-validation-CEZy1V-k.js.map +0 -1
@@ -1,26 +1,36 @@
1
1
  /**
2
- * Client-side registry for schema segment param codecs.
2
+ * The app/schema.ts segment-param codecs, resolved and keyed by bracket form
3
+ * (`'[id]'`, `'[...slug]'`, `'[[...path]]'`).
3
4
  *
4
- * The Link component uses codec `serialize` functions to convert typed
5
- * segment param values back to URL-safe strings. Without this registry,
6
- * Link falls back to `String(value)` — which works for simple types
7
- * but breaks for custom codecs (e.g., Date → '2026-04-10').
5
+ * One store per module graph, read in both directions:
8
6
  *
9
- * Populated at startup by the browser entry importing `virtual:timber-schema`.
10
- * Also usable on the server (isomorphic).
7
+ * - **parse** — `server/param-coercion.ts` runs `codec.parse` over the raw
8
+ * matcher output before middleware and rendering (RSC).
9
+ * - **serialize** — `shared/href.ts` runs `codec.serialize` when it
10
+ * interpolates a pattern for `<Link>` or `href()` (RSC, SSR, browser).
11
+ *
12
+ * Every entry registers it at startup from `virtual:timber-schema`: the RSC
13
+ * entry, the SSR entry and the browser entry. RSC and SSR are separate Vite
14
+ * module graphs with separate instances of this module, so each must
15
+ * register its own. Until TIM-1621 the RSC entry wrote a second,
16
+ * parse-only store instead, so an `href()` evaluated in a server component
17
+ * silently skipped `codec.serialize` and fell back to `String(value)`.
11
18
  *
12
19
  * Design doc: design/41-global-params.md §"Link Component"
13
20
  */
14
21
  import type { Codec } from '../codec.ts';
15
22
  /**
16
- * Register the resolved schema codecs for use by Link's URL interpolation.
17
- * Called once at startup from the browser entry or RSC entry.
23
+ * Register the resolved schema codecs. Called once at startup by each entry.
24
+ * `null` means the app has no schema — every segment stays a raw string.
18
25
  * @internal
19
26
  */
20
- export declare function setLinkCodecs(codecs: Record<string, Codec<unknown>> | null): void;
27
+ export declare function setSchemaCodecs(codecs: Record<string, Codec<unknown>> | null): void;
21
28
  /**
22
29
  * Look up a codec by bracket key (e.g. '[id]', '[...slug]').
23
30
  * Returns undefined if no schema is registered or the key has no codec.
31
+ * @internal
24
32
  */
25
- export declare function getLinkCodec(bracketKey: string): Codec<unknown> | undefined;
33
+ export declare function getSchemaCodec(bracketKey: string): Codec<unknown> | undefined;
34
+ /** True once a schema with segment codecs has been registered. @internal */
35
+ export declare function hasSchemaCodecs(): boolean;
26
36
  //# sourceMappingURL=codec-registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec-registry.d.ts","sourceRoot":"","sources":["../../src/params/codec-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIzC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAEjF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS,CAE3E"}
1
+ {"version":3,"file":"codec-registry.d.ts","sourceRoot":"","sources":["../../src/params/codec-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIzC;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAEnF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS,CAE7E;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,IAAI,OAAO,CAEzC"}
@@ -1,5 +1,4 @@
1
1
  export { defineSchema } from './define-schema.ts';
2
2
  export type { InferCodecType, SchemaConfig, SegmentParamCodec, ValidDynamicSegmentKeys, ValidDynamicSegmentKeysRegistry, } from './define-schema.ts';
3
3
  export { resolveSchemaCodecs, toBracketKey } from './resolve-schema.ts';
4
- export { setLinkCodecs, getLinkCodec } from './codec-registry.ts';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/params/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/params/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { n as toBracketKey, t as resolveSchemaCodecs } from "../_chunks/resolve-schema-B-aCuTu3.js";
2
- import { n as setLinkCodecs, t as getLinkCodec } from "../_chunks/codec-registry-CPc6bjVl.js";
3
2
  // src/params/define-schema.ts
4
3
  /**
5
4
  * Define the global segment param schema.
@@ -28,6 +27,6 @@ import { n as setLinkCodecs, t as getLinkCodec } from "../_chunks/codec-registry
28
27
  function defineSchema(config) {
29
28
  return config;
30
29
  }
31
- export { defineSchema, getLinkCodec, resolveSchemaCodecs, setLinkCodecs, toBracketKey };
30
+ export { defineSchema, resolveSchemaCodecs, toBracketKey };
32
31
 
33
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/params/define-schema.ts"],"sourcesContent":["/**\n * defineSchema — global segment param schema definition.\n *\n * Identity function at runtime; the type information is what matters.\n * The Vite plugin reads the schema at build time for codegen, and\n * the pipeline reads it at runtime for coercion.\n *\n * Design doc: design/41-global-params.md\n */\n\nimport type { Codec, CatchAllCodec, OptionalCatchAllCodec } from '../codec.ts';\nimport type { StandardSchemaV1 } from '../schema-bridge.ts';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Infer the output type from a Codec, StandardSchemaV1, or nuqs parser.\n *\n * Used by codegen to reference schema types without hardcoding:\n * `InferCodecType<typeof schema.segmentParams['[year]']>`\n */\nexport type InferCodecType<V> =\n V extends Codec<infer T>\n ? T\n : V extends StandardSchemaV1<infer T>\n ? T\n : V extends { parseServerSide: (value: string) => infer T }\n ? T\n : string;\n\n/** Acceptable codec value for segment params: a Codec or Standard Schema. */\nexport type SegmentParamCodec = Codec<unknown> | StandardSchemaV1<unknown>;\n\n/** Codec constraint for catch-all segment keys (`[...name]`). */\nexport type CatchAllParamCodec = CatchAllCodec<unknown> | StandardSchemaV1<readonly unknown[]>;\n\n/** Codec constraint for optional catch-all segment keys (`[[...name]]`). */\nexport type OptionalCatchAllParamCodec =\n | OptionalCatchAllCodec<unknown>\n | StandardSchemaV1<readonly unknown[] | undefined>;\n\n/**\n * Resolves the required codec type for a given bracket key pattern.\n * - `[...name]` → requires a catch-all codec\n * - `[[...name]]` → requires an optional catch-all codec\n * - `[name]` → accepts any segment param codec\n */\nexport type CodecForKey<K extends string> = K extends `[[...${string}]]`\n ? OptionalCatchAllParamCodec\n : K extends `[...${string}]`\n ? CatchAllParamCodec\n : SegmentParamCodec;\n\n/**\n * Registry interface augmented by codegen with known filesystem bracket keys.\n * When empty (no codegen yet), ValidDynamicSegmentKeys falls back to string.\n */\n// eslint-disable-next-line typescript/no-empty-interface -- augmented by codegen\nexport interface ValidDynamicSegmentKeysRegistry {}\n\n/**\n * Union of valid bracket keys for defineSchema.\n * After codegen runs, this is the set of filesystem segment names.\n * Before codegen (fresh project), accepts any string.\n */\nexport type ValidDynamicSegmentKeys = keyof ValidDynamicSegmentKeysRegistry extends never\n ? string\n : keyof ValidDynamicSegmentKeysRegistry & string;\n\n/** Configuration object for defineSchema. */\nexport interface SchemaConfig<S extends Record<string, SegmentParamCodec>> {\n segmentParams: S;\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Define the global segment param schema.\n *\n * Each key uses the bracket syntax from the filesystem (`[id]`, `[...slug]`,\n * `[[...slug]]`) mapped to a codec. This makes the relationship between\n * filesystem segments and codecs visually obvious.\n *\n * A dynamic segment with no key here defaults to `string` at codegen time.\n *\n * ```ts\n * // app/schema.ts\n * import { defineSchema } from '@timber-js/app/params';\n * import { codec } from '@timber-js/app/codec';\n * import { z } from 'zod';\n *\n * export default defineSchema({\n * segmentParams: {\n * '[artistSlug]': codec.string,\n * '[year]': codec.integer,\n * '[id]': z.coerce.number().int(),\n * },\n * });\n * ```\n */\nexport function defineSchema<\n S extends {\n [K in keyof S]: K extends ValidDynamicSegmentKeys\n ? K extends string\n ? CodecForKey<K>\n : SegmentParamCodec\n : never;\n },\n>(config: { segmentParams: S }): { segmentParams: S } {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,aAQd,QAAoD;CACpD,OAAO;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/params/define-schema.ts"],"sourcesContent":["/**\n * defineSchema — global segment param schema definition.\n *\n * Identity function at runtime; the type information is what matters.\n * The Vite plugin reads the schema at build time for codegen, and\n * the pipeline reads it at runtime for coercion.\n *\n * Design doc: design/41-global-params.md\n */\n\nimport type { Codec, CatchAllCodec, OptionalCatchAllCodec } from '../codec.ts';\nimport type { StandardSchemaV1 } from '../schema-bridge.ts';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Infer the output type from a Codec, StandardSchemaV1, or nuqs parser.\n *\n * Used by codegen to reference schema types without hardcoding:\n * `InferCodecType<typeof schema.segmentParams['[year]']>`\n */\nexport type InferCodecType<V> =\n V extends Codec<infer T>\n ? T\n : V extends StandardSchemaV1<infer T>\n ? T\n : V extends { parseServerSide: (value: string) => infer T }\n ? T\n : string;\n\n/** Acceptable codec value for segment params: a Codec or Standard Schema. */\nexport type SegmentParamCodec = Codec<unknown> | StandardSchemaV1<unknown>;\n\n/** Codec constraint for catch-all segment keys (`[...name]`). */\nexport type CatchAllParamCodec = CatchAllCodec<unknown> | StandardSchemaV1<readonly unknown[]>;\n\n/** Codec constraint for optional catch-all segment keys (`[[...name]]`). */\nexport type OptionalCatchAllParamCodec =\n | OptionalCatchAllCodec<unknown>\n | StandardSchemaV1<readonly unknown[] | undefined>;\n\n/**\n * Resolves the required codec type for a given bracket key pattern.\n * - `[...name]` → requires a catch-all codec\n * - `[[...name]]` → requires an optional catch-all codec\n * - `[name]` → accepts any segment param codec\n */\nexport type CodecForKey<K extends string> = K extends `[[...${string}]]`\n ? OptionalCatchAllParamCodec\n : K extends `[...${string}]`\n ? CatchAllParamCodec\n : SegmentParamCodec;\n\n/**\n * Registry interface augmented by codegen with known filesystem bracket keys.\n * When empty (no codegen yet), ValidDynamicSegmentKeys falls back to string.\n */\n// eslint-disable-next-line typescript/no-empty-interface -- augmented by codegen\nexport interface ValidDynamicSegmentKeysRegistry {}\n\n/**\n * Union of valid bracket keys for defineSchema.\n * After codegen runs, this is the set of filesystem segment names.\n * Before codegen (fresh project), accepts any string.\n */\nexport type ValidDynamicSegmentKeys = keyof ValidDynamicSegmentKeysRegistry extends never\n ? string\n : keyof ValidDynamicSegmentKeysRegistry & string;\n\n/** Configuration object for defineSchema. */\nexport interface SchemaConfig<S extends Record<string, SegmentParamCodec>> {\n segmentParams: S;\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Define the global segment param schema.\n *\n * Each key uses the bracket syntax from the filesystem (`[id]`, `[...slug]`,\n * `[[...slug]]`) mapped to a codec. This makes the relationship between\n * filesystem segments and codecs visually obvious.\n *\n * A dynamic segment with no key here defaults to `string` at codegen time.\n *\n * ```ts\n * // app/schema.ts\n * import { defineSchema } from '@timber-js/app/params';\n * import { codec } from '@timber-js/app/codec';\n * import { z } from 'zod';\n *\n * export default defineSchema({\n * segmentParams: {\n * '[artistSlug]': codec.string,\n * '[year]': codec.integer,\n * '[id]': z.coerce.number().int(),\n * },\n * });\n * ```\n */\nexport function defineSchema<\n S extends {\n [K in keyof S]: K extends ValidDynamicSegmentKeys\n ? K extends string\n ? CodecForKey<K>\n : SegmentParamCodec\n : never;\n },\n>(config: { segmentParams: S }): { segmentParams: S } {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,aAQd,QAAoD;CACpD,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/plugins/shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAsB1D;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsBlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EA0BhD,CAAC;AA2CF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAoOvD"}
1
+ {"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/plugins/shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAsB1D;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuBlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EA0BhD,CAAC;AA2CF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CA6OvD"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * `href()` — the typed URL builder over the generated `Routes` map.
3
+ *
4
+ * Every internal URL string — `router.push`, `redirect()`, an href passed
5
+ * as a prop, metadata — goes through this one function, so a renamed route
6
+ * directory breaks the build instead of silently breaking a link, and every
7
+ * segment value serializes through its app/schema.ts codec.
8
+ *
9
+ * Isomorphic by construction: no `'use client'`, no React, no ALS. The same
10
+ * call works in a server component, a client component, middleware, an
11
+ * action, or a plain module.
12
+ *
13
+ * Design doc: design/09-typescript.md §"Building URLs — href()".
14
+ */
15
+ import type { Routes } from '../index.ts';
16
+ import { type SearchParamsArg } from '../shared/href.ts';
17
+ /** A URL pattern known to the generated route map (groups stripped). */
18
+ export type RoutePattern = keyof Routes;
19
+ /**
20
+ * Every URL `pattern` resolves to, as a template-literal type:
21
+ * `RouteHref<'/products/[id]'>` is `` `/products/${string}` ``.
22
+ *
23
+ * Use it to require a route-shaped string in a prop
24
+ * (`rowHref: RouteHref<'/artists/[artistSlug]'>`). It is a shape check, not
25
+ * a brand: a hand-built `` `/artists/${slug}` `` satisfies it too, which is
26
+ * how `<Link>` already treats literal hrefs. So does any route nested under
27
+ * it (`/artists/${string}` matches `/artists/a/songs/b`).
28
+ *
29
+ * Read from `Routes[P]['href']`, which codegen emits from the same function
30
+ * that builds `<Link>`'s resolved-template variants. Falls back to `string`
31
+ * only for a route map generated before that member existed.
32
+ */
33
+ export type RouteHref<P extends keyof Routes> = Routes[P] extends {
34
+ href: infer H extends string;
35
+ } ? H : string;
36
+ /**
37
+ * `RouteHref<P>` with a query. The bare form stays in the union because an
38
+ * empty query (`buildSearchParams({})` → `''`) appends nothing — not a bare
39
+ * `?`.
40
+ */
41
+ export type RouteHrefWithSearch<P extends keyof Routes> = RouteHref<P> | `${RouteHref<P>}?${string}`;
42
+ type SegmentParamsOf<P extends keyof Routes> = Routes[P] extends {
43
+ segmentParams: infer S;
44
+ } ? S : never;
45
+ /**
46
+ * The params the PATTERN lets a caller omit: only an optional catch-all,
47
+ * which is always the last segment (`/docs/[[...path]]`). Read from the
48
+ * pattern's syntax, not from the param types — a schema codec may return
49
+ * `T | undefined` for a required `[id]`, and the runtime still throws for
50
+ * a missing `[id]` before any codec runs.
51
+ */
52
+ type OmittableKeys<P extends keyof Routes, T> = {
53
+ [K in keyof T]: P extends `${string}[[...${K & string}]]` ? K : never;
54
+ }[keyof T];
55
+ /**
56
+ * Codegen types an optional catch-all as a required key whose value may be
57
+ * `undefined` (`path: string[] | undefined`). Omittable keys become optional;
58
+ * every other key is required and cannot be `undefined` (the runtime throws
59
+ * on it, whatever the codec's type says).
60
+ */
61
+ type ParamsShape<P extends keyof Routes, T> = {
62
+ [K in keyof T as K extends OmittableKeys<P, T> ? never : K]: Exclude<T[K], undefined>;
63
+ } & {
64
+ [K in keyof T as K extends OmittableKeys<P, T> ? K : never]?: T[K];
65
+ };
66
+ /** Flatten an intersection so diagnostics print one object type. */
67
+ type Flatten<T> = {
68
+ [K in keyof T]: T[K];
69
+ };
70
+ /**
71
+ * The segment params `href(pattern, …)` takes. `Record<string, never>` for a
72
+ * route with none, so `href('/venues', { x: 1 })` is an error rather than a
73
+ * silent no-op (`{}` would accept any object).
74
+ */
75
+ export type HrefParams<P extends keyof Routes> = [keyof SegmentParamsOf<P>] extends [never] ? Record<string, never> : Flatten<ParamsShape<P, SegmentParamsOf<P>>>;
76
+ /** True when `T` is a union of more than one member. */
77
+ type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
78
+ /** True when no member of `P` has a required segment param. */
79
+ type EveryParamOptional<P extends keyof Routes> = (P extends unknown ? ({} extends HrefParams<P> ? true : false) : never) extends true ? true : false;
80
+ /**
81
+ * The arguments after `pattern`. Segment params are required unless every
82
+ * param is optional (none, or only an optional catch-all); the query is
83
+ * always optional.
84
+ *
85
+ * A UNION pattern (`'/products/[id]' | '/venues'`) has no single params
86
+ * shape: `keyof` a union of param objects is `never`, which would read as
87
+ * "no params" and let `href(pattern)` compile, then throw for the dynamic
88
+ * member. So a union takes no segment params at all, and only when none of
89
+ * its members requires one; otherwise the call needs an argument of type
90
+ * `never`, which nothing satisfies. Narrow the pattern before calling.
91
+ *
92
+ * The exception is `P` = all of `keyof Routes`: that is what TS infers when
93
+ * the pattern is NOT a known route, and the arity error would hide the
94
+ * useful one ("'/nope' is not assignable to keyof Routes"). That case takes
95
+ * the permissive shape so the pattern error is the one reported.
96
+ */
97
+ export type HrefArgs<P extends keyof Routes, S extends SearchParamsArg | undefined = SearchParamsArg | undefined> = true extends IsUnion<P> ? EveryParamOptional<P> extends true ? [segmentParams?: undefined, searchParams?: S] : [keyof Routes] extends [P] ? [segmentParams?: undefined, searchParams?: S] : [narrow_the_pattern_union_to_one_route: never] : {} extends HrefParams<P> ? [segmentParams?: HrefParams<P>, searchParams?: S] : [segmentParams: HrefParams<P>, searchParams?: S];
98
+ /**
99
+ * Build the URL for a route pattern.
100
+ *
101
+ * ```ts
102
+ * href('/venues') // '/venues'
103
+ * href('/products/[id]', { id }) // `/products/${string}`
104
+ * href('/docs/[[...path]]') // '/docs'
105
+ * href('/artists/[artistSlug]', { artistSlug }, artistParams.buildSearchParams({ sort }))
106
+ * ```
107
+ *
108
+ * - **Segment params** are typed from `Routes[pattern]['segmentParams']` —
109
+ * the app/schema.ts codec types when a schema exists — and serialized
110
+ * through those codecs, then percent-encoded per segment.
111
+ * - **Search params** (third argument) take the string
112
+ * `definition.buildSearchParams()` returns (codecs, `withUrlKey` aliases,
113
+ * default omission) or a plain record as the uncodec'd escape hatch. An
114
+ * empty query appends nothing.
115
+ * - The result is validated like every navigation sink: a value that would
116
+ * produce a protocol-relative URL (`/[...slug]` with `['', 'evil.com']` →
117
+ * `//evil.com`) throws instead of returning an open redirect.
118
+ *
119
+ * `href(ROUTE, …)` works with the `ROUTE` constant from a route's generated
120
+ * `./$segment` module whenever that directory is a page or route handler.
121
+ */
122
+ export declare function href<P extends keyof Routes, S extends SearchParamsArg | undefined = undefined>(pattern: P, ...args: HrefArgs<P, S>): S extends SearchParamsArg ? RouteHrefWithSearch<P> : RouteHref<P>;
123
+ export {};
124
+ //# sourceMappingURL=href.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"href.d.ts","sourceRoot":"","sources":["../../src/routes/href.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ export { href } from './href.ts';
2
+ export type { HrefArgs, HrefParams, RouteHref, RouteHrefWithSearch, RoutePattern } from './href.ts';
3
+ export type { SearchParamsArg } from '../shared/href.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpG,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { t as buildHref } from "../_chunks/href-BtspoNc9.js";
2
+ // src/routes/href.ts
3
+ function href(pattern, segmentParams, searchParams) {
4
+ return buildHref(pattern, segmentParams, searchParams);
5
+ }
6
+ export { href };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/routes/href.ts"],"sourcesContent":["/**\n * `href()` — the typed URL builder over the generated `Routes` map.\n *\n * Every internal URL string — `router.push`, `redirect()`, an href passed\n * as a prop, metadata — goes through this one function, so a renamed route\n * directory breaks the build instead of silently breaking a link, and every\n * segment value serializes through its app/schema.ts codec.\n *\n * Isomorphic by construction: no `'use client'`, no React, no ALS. The same\n * call works in a server component, a client component, middleware, an\n * action, or a plain module.\n *\n * Design doc: design/09-typescript.md §\"Building URLs — href()\".\n */\n\nimport type { Routes } from '../index.ts';\nimport { buildHref, type ParamValue, type SearchParamsArg } from '../shared/href.ts';\n\n/** A URL pattern known to the generated route map (groups stripped). */\nexport type RoutePattern = keyof Routes;\n\n/**\n * Every URL `pattern` resolves to, as a template-literal type:\n * `RouteHref<'/products/[id]'>` is `` `/products/${string}` ``.\n *\n * Use it to require a route-shaped string in a prop\n * (`rowHref: RouteHref<'/artists/[artistSlug]'>`). It is a shape check, not\n * a brand: a hand-built `` `/artists/${slug}` `` satisfies it too, which is\n * how `<Link>` already treats literal hrefs. So does any route nested under\n * it (`/artists/${string}` matches `/artists/a/songs/b`).\n *\n * Read from `Routes[P]['href']`, which codegen emits from the same function\n * that builds `<Link>`'s resolved-template variants. Falls back to `string`\n * only for a route map generated before that member existed.\n */\nexport type RouteHref<P extends keyof Routes> = Routes[P] extends {\n href: infer H extends string;\n}\n ? H\n : string;\n\n/**\n * `RouteHref<P>` with a query. The bare form stays in the union because an\n * empty query (`buildSearchParams({})` → `''`) appends nothing — not a bare\n * `?`.\n */\nexport type RouteHrefWithSearch<P extends keyof Routes> =\n | RouteHref<P>\n | `${RouteHref<P>}?${string}`;\n\ntype SegmentParamsOf<P extends keyof Routes> = Routes[P] extends { segmentParams: infer S }\n ? S\n : never;\n\n/**\n * The params the PATTERN lets a caller omit: only an optional catch-all,\n * which is always the last segment (`/docs/[[...path]]`). Read from the\n * pattern's syntax, not from the param types — a schema codec may return\n * `T | undefined` for a required `[id]`, and the runtime still throws for\n * a missing `[id]` before any codec runs.\n */\ntype OmittableKeys<P extends keyof Routes, T> = {\n [K in keyof T]: P extends `${string}[[...${K & string}]]` ? K : never;\n}[keyof T];\n\n/**\n * Codegen types an optional catch-all as a required key whose value may be\n * `undefined` (`path: string[] | undefined`). Omittable keys become optional;\n * every other key is required and cannot be `undefined` (the runtime throws\n * on it, whatever the codec's type says).\n */\ntype ParamsShape<P extends keyof Routes, T> = {\n [K in keyof T as K extends OmittableKeys<P, T> ? never : K]: Exclude<T[K], undefined>;\n} & {\n [K in keyof T as K extends OmittableKeys<P, T> ? K : never]?: T[K];\n};\n\n/** Flatten an intersection so diagnostics print one object type. */\ntype Flatten<T> = { [K in keyof T]: T[K] };\n\n/**\n * The segment params `href(pattern, …)` takes. `Record<string, never>` for a\n * route with none, so `href('/venues', { x: 1 })` is an error rather than a\n * silent no-op (`{}` would accept any object).\n */\nexport type HrefParams<P extends keyof Routes> = [keyof SegmentParamsOf<P>] extends [never]\n ? Record<string, never>\n : Flatten<ParamsShape<P, SegmentParamsOf<P>>>;\n\n/** True when `T` is a union of more than one member. */\ntype IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;\n\n/** True when no member of `P` has a required segment param. */\ntype EveryParamOptional<P extends keyof Routes> = (\n P extends unknown ? ({} extends HrefParams<P> ? true : false) : never\n) extends true\n ? true\n : false;\n\n/**\n * The arguments after `pattern`. Segment params are required unless every\n * param is optional (none, or only an optional catch-all); the query is\n * always optional.\n *\n * A UNION pattern (`'/products/[id]' | '/venues'`) has no single params\n * shape: `keyof` a union of param objects is `never`, which would read as\n * \"no params\" and let `href(pattern)` compile, then throw for the dynamic\n * member. So a union takes no segment params at all, and only when none of\n * its members requires one; otherwise the call needs an argument of type\n * `never`, which nothing satisfies. Narrow the pattern before calling.\n *\n * The exception is `P` = all of `keyof Routes`: that is what TS infers when\n * the pattern is NOT a known route, and the arity error would hide the\n * useful one (\"'/nope' is not assignable to keyof Routes\"). That case takes\n * the permissive shape so the pattern error is the one reported.\n */\nexport type HrefArgs<\n P extends keyof Routes,\n S extends SearchParamsArg | undefined = SearchParamsArg | undefined,\n> =\n true extends IsUnion<P>\n ? EveryParamOptional<P> extends true\n ? [segmentParams?: undefined, searchParams?: S]\n : [keyof Routes] extends [P]\n ? [segmentParams?: undefined, searchParams?: S]\n : [narrow_the_pattern_union_to_one_route: never]\n : {} extends HrefParams<P>\n ? [segmentParams?: HrefParams<P>, searchParams?: S]\n : [segmentParams: HrefParams<P>, searchParams?: S];\n\n// One signature, not an overload per query shape: with two, a call missing\n// its segment params was reported against whichever overload TS tried last\n// (\"Expected 3 arguments\"). `S` is inferred from the query argument alone,\n// so segment params are still checked against `HrefParams<P>` directly and\n// keep excess-property errors; a maybe-undefined query distributes to the\n// union of both return shapes.\n/**\n * Build the URL for a route pattern.\n *\n * ```ts\n * href('/venues') // '/venues'\n * href('/products/[id]', { id }) // `/products/${string}`\n * href('/docs/[[...path]]') // '/docs'\n * href('/artists/[artistSlug]', { artistSlug }, artistParams.buildSearchParams({ sort }))\n * ```\n *\n * - **Segment params** are typed from `Routes[pattern]['segmentParams']` —\n * the app/schema.ts codec types when a schema exists — and serialized\n * through those codecs, then percent-encoded per segment.\n * - **Search params** (third argument) take the string\n * `definition.buildSearchParams()` returns (codecs, `withUrlKey` aliases,\n * default omission) or a plain record as the uncodec'd escape hatch. An\n * empty query appends nothing.\n * - The result is validated like every navigation sink: a value that would\n * produce a protocol-relative URL (`/[...slug]` with `['', 'evil.com']` →\n * `//evil.com`) throws instead of returning an open redirect.\n *\n * `href(ROUTE, …)` works with the `ROUTE` constant from a route's generated\n * `./$segment` module whenever that directory is a page or route handler.\n */\nexport function href<P extends keyof Routes, S extends SearchParamsArg | undefined = undefined>(\n pattern: P,\n ...args: HrefArgs<P, S>\n): S extends SearchParamsArg ? RouteHrefWithSearch<P> : RouteHref<P>;\nexport function href(\n pattern: string,\n segmentParams?: Record<string, ParamValue>,\n searchParams?: SearchParamsArg\n): string {\n return buildHref(pattern, segmentParams, searchParams);\n}\n"],"mappings":";;AAoKA,SAAgB,KACd,SACA,eACA,cACQ;CACR,OAAO,UAAU,SAAS,eAAe,YAAY;AACvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/routing/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAMzD,wCAAwC;AACxC,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CActF"}
1
+ {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/routing/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAUzD,wCAAwC;AACxC,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CActF"}
@@ -1,5 +1,5 @@
1
1
  import { a as INTERCEPTION_MARKERS, i as DEFAULT_PAGE_EXTENSIONS, n as classifyUrlSegment, t as classifySegment } from "../_chunks/segment-classify-Ho8jXWeC.js";
2
2
  import { d as collectInterceptionRewrites, n as scanRoutes } from "../_chunks/scanner-BNQ4qnLX.js";
3
- import { t as generateRouteMap } from "../_chunks/codegen-B9oWkWGf.js";
3
+ import { t as generateRouteMap } from "../_chunks/codegen-vaCyFyVN.js";
4
4
  import { n as collectDynamicSegmentsFromTree, r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "../_chunks/walkers-D_QHR_nf.js";
5
5
  export { DEFAULT_PAGE_EXTENSIONS, INTERCEPTION_MARKERS, classifySegment, classifyUrlSegment, collectDynamicSegmentsFromTree, collectInterceptionRewrites, collectLeafRoutes, generateRouteMap, scanRoutes, validateSchemaAgainstRoutes };
@@ -37,16 +37,47 @@ import type { ParamEntry, RouteEntry } from './codegen-types.ts';
37
37
  * Declared once so the three emission sites cannot drift apart.
38
38
  */
39
39
  export declare const SEARCH_PARAMS_PROP_TYPE = "string | Record<string, unknown>";
40
- /** Shared Link base-props type literal used in every emitted call signature. */
41
- export declare const LINK_BASE_PROPS_TYPE = "Omit<import('react').AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & { prefetch?: boolean; scroll?: boolean; preserveSearchParams?: true | string[]; onNavigate?: import('./client/link.js').OnNavigateHandler; children?: import('react').ReactNode }";
42
40
  /**
43
- * Build a TypeScript template literal pattern for a dynamic route.
44
- * e.g. '/products/[id]' → '/products/${string}'
45
- * '/blog/[...slug]' → '/blog/${string}'
46
- * '/docs/[[...path]]' → '/docs/${string}' (also matches /docs)
47
- * '/[org]/[repo]' → '/${string}/${string}'
41
+ * Link base props in every emitted call signature: the real `LinkBaseProps`
42
+ * from `@timber-js/app/client`, by reference.
43
+ *
44
+ * Until TIM-1621 this was an inline copy of the type. It drifted —
45
+ * `replace` and `transitionTypes` were never added, so typed `<Link>`
46
+ * rejected both — and its `onNavigate` came from `./client/link.js`, a
47
+ * path relative to `.timber/` that never resolved, so that prop was
48
+ * silently `any`. A reference cannot drift.
49
+ */
50
+ export declare const LINK_BASE_PROPS_TYPE = "import('@timber-js/app/client').LinkBaseProps";
51
+ /**
52
+ * Build the TypeScript type of every URL a route resolves to — a type
53
+ * EXPRESSION, ready to drop into a declaration:
54
+ *
55
+ * '/venues' → '/venues'
56
+ * '/products/[id]' → `/products/${string}`
57
+ * '/img-[id].png' → `/img-${string}.png`
58
+ * '/blog/[...slug]' → `/blog/${string}`
59
+ * '/docs/[[...path]]' → '/docs' | `/docs/${string}`
60
+ * '/[[...path]]' → '/' | `/${string}`
61
+ *
62
+ * An optional catch-all that is omitted drops its segment AND its slash
63
+ * (`interpolateParams('/docs/[[...path]]', {})` is `/docs`), and
64
+ * `/docs/${string}` does not match `/docs` — so a trailing optional
65
+ * catch-all needs the bare prefix as a second member. Before TIM-1621 this
66
+ * emitted only the template, and `<Link href="/docs">` matched no route.
67
+ *
68
+ * Emitted once per route as `Routes[P]['href']` — the type `href()`
69
+ * returns — and reused for `<Link>`'s resolved-template variants, so the
70
+ * two cannot disagree about what a route's URLs look like.
71
+ */
72
+ export declare function buildResolvedPattern(route: RouteEntry): string;
73
+ /**
74
+ * `<Link>`'s query-bearing href type: each member of `buildResolvedPattern`
75
+ * that ends in a static part, with `?${string}` appended. `href(pattern,
76
+ * params, search)` can return such a value, and a `/venues?${string}` is
77
+ * not wide `string`, so without this it would match no Link overload.
78
+ * `null` when every member ends in `${string}` (which already matches a query).
48
79
  */
49
- export declare function buildResolvedPattern(route: RouteEntry): string | null;
80
+ export declare function buildResolvedPatternWithQuery(route: RouteEntry): string | null;
50
81
  /**
51
82
  * Format the segmentParams type for Link overloads.
52
83
  *
@@ -1 +1 @@
1
- {"version":3,"file":"link-codegen.d.ts","sourceRoot":"","sources":["../../src/routing/link-codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIjE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,8PAC4N,CAAC;AAE9P;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAoBrE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAWtF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,EAAE,CA+DtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAwE5F"}
1
+ {"version":3,"file":"link-codegen.d.ts","sourceRoot":"","sources":["../../src/routing/link-codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIjE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,kDAAkD,CAAC;AAKpF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI9D;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAO9E;AAgCD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAWtF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,EAAE,CA+DtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAmF5F"}
@@ -1,6 +1,6 @@
1
1
  import { C as addSpanEvent, D as getSpanId, I as isDenySignal, L as isRedirectSignal, M as withSpan, O as getTraceId, S as isDevMode, x as isDebug } from "../_chunks/logger-YtMSKfft.js";
2
2
  import { t as formatSize } from "../_chunks/format-DuPOoXUP.js";
3
- import { _ as getHeaders, a as parseFormData, c as deny, d as waitUntil, i as coerce, l as redirect, n as revalidatePath, p as getCookieJar, r as revalidateTag, u as redirectExternal, y as getSegmentParams } from "../_chunks/actions-DHum77eH.js";
3
+ import { _ as getHeaders, a as parseFormData, c as deny, d as waitUntil, i as coerce, l as redirect, n as revalidatePath, p as getCookieJar, r as revalidateTag, u as redirectExternal, y as getSegmentParams } from "../_chunks/actions-CYjRMpZI.js";
4
4
  // src/shared/redirect-type.ts
5
5
  /**
6
6
  * Next.js redirect type discriminator.
@@ -11,11 +11,12 @@ import { A as runWithTraceId, E as getOtelTraceId, F as isControlFlowSignal, I a
11
11
  import { n as isHttpMethod, t as HTTP_METHODS } from "../_chunks/route-methods-Dk2kZc0n.js";
12
12
  import { c as collectRouteModulepreloads, i as traceTimingEntry, o as collectRouteCss, s as collectRouteFonts } from "../_chunks/dev-span-_NzMX-au.js";
13
13
  import { i as isRscCacheKeyShape, n as RSC_KEY_PARAM, r as appVisibleSearch, s as rscCacheKey, t as RSC_KEY_HEADERS } from "../_chunks/rsc-cache-key-D0cb0Gmc.js";
14
- import { C as setMatchedSegmentPath, E as runOutsideReactCacheScope, S as runWithSegmentParams, T as setSegmentParams, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setMutableCookieContext, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-DHum77eH.js";
14
+ import { C as setMatchedSegmentPath, E as runOutsideReactCacheScope, S as runWithSegmentParams, T as setSegmentParams, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setMutableCookieContext, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-CYjRMpZI.js";
15
15
  import { _ as getWaitUntil, a as storeOverlayEntry, c as lookupArtifactSeed, d as checkVersionSkew, g as observeKeyDiscipline, i as overlayKey, l as setPrebuiltPayloadSource, n as lookupOverlay, o as hasPrebuiltPayloadSource, r as mayStoreRerender, s as isParamIndependent, u as applyReloadHeaders } from "../_chunks/cache-api-BZJNt01a.js";
16
16
  import { n as createSingleflight } from "../_chunks/singleflight-CzoOVB9Y.js";
17
17
  import { s as TIMBER_ERROR_HEADER, t as StatusPageMarker } from "../_chunks/status-page-marker-U6B1aFMb.js";
18
18
  import { n as toBracketKey } from "../_chunks/resolve-schema-B-aCuTu3.js";
19
+ import { n as hasSchemaCodecs, t as getSchemaCodec } from "../_chunks/codec-registry-C8hOGmZo.js";
19
20
  import { t as normalizeParamValue } from "../_chunks/param-value-DqlGfF57.js";
20
21
  import { t as createGlobalContext } from "../_chunks/global-context-CFSSysdJ.js";
21
22
  import { createHash } from "node:crypto";
@@ -1255,8 +1256,6 @@ function warnParamCoercionFailure(method, pathname, segments, error) {
1255
1256
  const segmentChain = segments.map((s) => s.segmentName || "/").join(" → ");
1256
1257
  console.warn(`[timber] Param coercion failed for ${method} ${pathname} — responding with 404\n Matched segments: ${segmentChain}\n Error: ${error.message}\n This usually means a codec in app/schema.ts rejected the URL value.\n Check the codec for the bracket key of the segment named above.`);
1257
1258
  }
1258
- /** Global schema codecs, set once at startup from virtual:timber-schema. */
1259
- var _globalCodecs = null;
1260
1259
  /**
1261
1260
  * Coerce the matched route's raw segment params and return the result.
1262
1261
  *
@@ -1283,14 +1282,13 @@ var _globalCodecs = null;
1283
1282
  * ordering has always had, for no gain.
1284
1283
  */
1285
1284
  async function coerceSegmentParams(match) {
1286
- const globalCodecs = _globalCodecs;
1287
1285
  const mergeTarget = Object.create(null);
1288
1286
  for (const key of Object.keys(match.rawSegmentParams)) if (key !== "__proto__") mergeTarget[key] = match.rawSegmentParams[key];
1289
- if (globalCodecs) for (const node of match.segments) {
1287
+ if (hasSchemaCodecs()) for (const node of match.segments) {
1290
1288
  const segment = effectiveUrlSegment(node);
1291
1289
  if (!segment.paramName) continue;
1292
1290
  const bracketKey = toBracketKey(segment.segmentType, segment.paramName);
1293
- const codec = globalCodecs[bracketKey];
1291
+ const codec = getSchemaCodec(bracketKey);
1294
1292
  if (!codec) continue;
1295
1293
  const key = segment.paramName;
1296
1294
  if (!(key in mergeTarget)) continue;