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

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 (98) 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/_chunks/{use-query-states-pkDV-jSg.js → use-query-states-D3MMl-KM.js} +12 -12
  19. package/dist/_chunks/use-query-states-D3MMl-KM.js.map +1 -0
  20. package/dist/cli.js +1 -1
  21. package/dist/client/index.d.ts +2 -1
  22. package/dist/client/index.d.ts.map +1 -1
  23. package/dist/client/index.js +4 -122
  24. package/dist/client/index.js.map +1 -1
  25. package/dist/client/internal.js +1 -1
  26. package/dist/client/link.d.ts +4 -25
  27. package/dist/client/link.d.ts.map +1 -1
  28. package/dist/client/nuqs-adapter.d.ts.map +1 -1
  29. package/dist/client/use-query-states.d.ts +1 -1
  30. package/dist/client/use-query-states.d.ts.map +1 -1
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +57 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/params/codec-registry.d.ts +21 -11
  36. package/dist/params/codec-registry.d.ts.map +1 -1
  37. package/dist/params/index.d.ts +0 -1
  38. package/dist/params/index.d.ts.map +1 -1
  39. package/dist/params/index.js +1 -2
  40. package/dist/params/index.js.map +1 -1
  41. package/dist/plugins/node-flight-builds.d.ts +38 -0
  42. package/dist/plugins/node-flight-builds.d.ts.map +1 -0
  43. package/dist/plugins/shims.d.ts.map +1 -1
  44. package/dist/routes/href.d.ts +124 -0
  45. package/dist/routes/href.d.ts.map +1 -0
  46. package/dist/routes/index.d.ts +4 -0
  47. package/dist/routes/index.d.ts.map +1 -0
  48. package/dist/routes/index.js +8 -0
  49. package/dist/routes/index.js.map +1 -0
  50. package/dist/routing/codegen.d.ts.map +1 -1
  51. package/dist/routing/index.js +1 -1
  52. package/dist/routing/link-codegen.d.ts +39 -8
  53. package/dist/routing/link-codegen.d.ts.map +1 -1
  54. package/dist/search-params/define.d.ts +37 -17
  55. package/dist/search-params/define.d.ts.map +1 -1
  56. package/dist/search-params/index.d.ts +1 -0
  57. package/dist/search-params/index.d.ts.map +1 -1
  58. package/dist/search-params/index.js +3 -2
  59. package/dist/search-params/index.js.map +1 -1
  60. package/dist/server/index.js +1 -1
  61. package/dist/server/internal.js +4 -6
  62. package/dist/server/internal.js.map +1 -1
  63. package/dist/server/param-coercion.d.ts +0 -7
  64. package/dist/server/param-coercion.d.ts.map +1 -1
  65. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  66. package/dist/shared/href.d.ts +88 -0
  67. package/dist/shared/href.d.ts.map +1 -0
  68. package/docs/api/31-api-client.mdx +1 -1
  69. package/docs/api/35-api-typescript.mdx +47 -15
  70. package/docs/learn/06-typed-params.mdx +33 -0
  71. package/docs/learn/07-typed-routes.mdx +75 -10
  72. package/package.json +6 -2
  73. package/src/client/browser-entry/index.ts +4 -4
  74. package/src/client/index.ts +3 -1
  75. package/src/client/link.tsx +5 -238
  76. package/src/client/nuqs-adapter.tsx +45 -2
  77. package/src/client/use-query-states.ts +27 -23
  78. package/src/index.ts +5 -0
  79. package/src/params/codec-registry.ts +24 -11
  80. package/src/params/index.ts +0 -1
  81. package/src/plugins/node-flight-builds.ts +94 -0
  82. package/src/plugins/shims.ts +10 -0
  83. package/src/routes/href.ts +171 -0
  84. package/src/routes/index.ts +10 -0
  85. package/src/routing/codegen.ts +8 -1
  86. package/src/routing/link-codegen.ts +103 -37
  87. package/src/search-params/define.ts +37 -17
  88. package/src/search-params/index.ts +10 -0
  89. package/src/server/param-coercion.ts +5 -23
  90. package/src/server/rsc-entry/index.ts +6 -3
  91. package/src/server/ssr-entry.ts +2 -2
  92. package/src/shared/href.ts +257 -0
  93. package/dist/_chunks/codec-registry-CPc6bjVl.js +0 -20
  94. package/dist/_chunks/codec-registry-CPc6bjVl.js.map +0 -1
  95. package/dist/_chunks/codegen-B9oWkWGf.js.map +0 -1
  96. package/dist/_chunks/href-validation-CEZy1V-k.js +0 -210
  97. package/dist/_chunks/href-validation-CEZy1V-k.js.map +0 -1
  98. package/dist/_chunks/use-query-states-pkDV-jSg.js.map +0 -1
@@ -0,0 +1,111 @@
1
+ // src/shared/slot-params.ts
2
+ /**
3
+ * The params a slot sees: the main route's as a base, the slot's own on top.
4
+ *
5
+ * Params from segments *above* the slot are not re-derived by the slot's own
6
+ * chain, so they have to come from the main route; params the slot does
7
+ * re-derive may have a different type than the main route gave them, so the
8
+ * slot's win.
9
+ *
10
+ * Null-prototype, like every other param record the framework hands out
11
+ * (`coerceSegmentParams` installs one unconditionally). A spread literal would
12
+ * inherit `Object.prototype`, so a lookup for a param the route does not
13
+ * define would resolve to an inherited member — `params.constructor` returning
14
+ * a function instead of `undefined` — in the one param record that was built
15
+ * by merging. See design/13-security.md #36c.
16
+ */
17
+ function mergeSlotParams(mainParams, slotParams) {
18
+ return Object.assign(Object.create(null), mainParams, slotParams);
19
+ }
20
+ /**
21
+ * Resolve the params for a segment path against a published slot map.
22
+ *
23
+ * Returns the merge when `segmentPath` names a slot that published params,
24
+ * and the main route's record otherwise — an ordinary (non-slot) segment
25
+ * path, an unknown path, or a request with no slots at all. Mirrors the
26
+ * server's `getSegmentParams(segmentPath)` branch exactly.
27
+ *
28
+ * `Object.hasOwn` rather than `in` or a truthiness test: the map arrives from
29
+ * JSON, so a segment path of `constructor` or `toString` would otherwise
30
+ * resolve to an inherited member of `Object.prototype`.
31
+ */
32
+ function resolveSegmentParams(mainParams, slotParams, segmentPath) {
33
+ if (!segmentPath || !slotParams || !Object.hasOwn(slotParams, segmentPath)) return mainParams;
34
+ return cachedMerge(mainParams, slotParams, segmentPath);
35
+ }
36
+ /**
37
+ * The merged record for one (main record, slot map, path) triple, reused until
38
+ * one of the three changes.
39
+ *
40
+ * `useSegmentParams(slotPath)` calls this on every render. Returning a fresh
41
+ * object each time makes the hook's result change by reference on renders where
42
+ * nothing navigated, so a component using it as a `useEffect` dependency
43
+ * re-runs the effect — and re-renders in a loop if that effect sets state —
44
+ * while memoized children below it lose their memoization.
45
+ *
46
+ * Keyed on the *identities* of the two records, not their contents: both are
47
+ * replaced rather than mutated on every navigation (`ParamsProvider`'s memoized
48
+ * value and the server's per-request store), so identity is the correct
49
+ * equality here and a deep comparison would be slower and no more accurate.
50
+ *
51
+ * A `WeakMap` chain rather than a `Map`, so a superseded navigation's records
52
+ * and their merges become collectable as soon as nothing else holds them.
53
+ */
54
+ var mergeCache = /* @__PURE__ */ new WeakMap();
55
+ function cachedMerge(mainParams, slotParams, segmentPath) {
56
+ let bySlotMap = mergeCache.get(mainParams);
57
+ if (!bySlotMap) {
58
+ bySlotMap = /* @__PURE__ */ new WeakMap();
59
+ mergeCache.set(mainParams, bySlotMap);
60
+ }
61
+ let byPath = bySlotMap.get(slotParams);
62
+ if (!byPath) {
63
+ byPath = /* @__PURE__ */ new Map();
64
+ bySlotMap.set(slotParams, byPath);
65
+ }
66
+ const cached = byPath.get(segmentPath);
67
+ if (cached) return cached;
68
+ const merged = mergeSlotParams(mainParams, slotParams[segmentPath]);
69
+ byPath.set(segmentPath, merged);
70
+ return merged;
71
+ }
72
+ // src/shared/merge-search-params.ts
73
+ /**
74
+ * Shared utility for merging preserved search params into a target URL.
75
+ *
76
+ * Used by both <Link> (client) and redirect() (server). Extracted to a shared
77
+ * module to avoid importing client code ('use client') from server modules.
78
+ */
79
+ /**
80
+ * Merge preserved search params from the current URL into a target href.
81
+ *
82
+ * When `preserve` is `true`, all current search params are merged.
83
+ * When `preserve` is a `string[]`, only the named params are merged.
84
+ *
85
+ * The target href's own search params take precedence — preserved params
86
+ * are only added if the target doesn't already define them.
87
+ *
88
+ * @param targetHref - The resolved target href (may already contain query string)
89
+ * @param currentSearch - The current URL's search string (e.g. "?private=access&page=2")
90
+ * @param preserve - `true` to preserve all, or `string[]` to preserve specific params
91
+ * @returns The target href with preserved search params merged in
92
+ */
93
+ function mergePreservedSearchParams(targetHref, currentSearch, preserve) {
94
+ const currentParams = new URLSearchParams(currentSearch);
95
+ if (currentParams.size === 0) return targetHref;
96
+ const hashIdx = targetHref.indexOf("#");
97
+ const hrefWithoutHash = hashIdx >= 0 ? targetHref.slice(0, hashIdx) : targetHref;
98
+ const hash = hashIdx >= 0 ? targetHref.slice(hashIdx) : "";
99
+ const qIdx = hrefWithoutHash.indexOf("?");
100
+ const targetPath = qIdx >= 0 ? hrefWithoutHash.slice(0, qIdx) : hrefWithoutHash;
101
+ const targetParams = new URLSearchParams(qIdx >= 0 ? hrefWithoutHash.slice(qIdx + 1) : "");
102
+ const merged = new URLSearchParams(targetParams);
103
+ for (const [key, value] of currentParams) if (!targetParams.has(key)) {
104
+ if (preserve === true || preserve.includes(key)) merged.append(key, value);
105
+ }
106
+ const qs = merged.toString();
107
+ return (qs ? `${targetPath}?${qs}` : targetPath) + hash;
108
+ }
109
+ export { resolveSegmentParams as n, mergePreservedSearchParams as t };
110
+
111
+ //# sourceMappingURL=merge-search-params-7o_5yX0L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-search-params-7o_5yX0L.js","names":[],"sources":["../../src/shared/slot-params.ts","../../src/shared/merge-search-params.ts"],"sourcesContent":["/**\n * Per-slot segment params — the one definition both halves of the API read.\n *\n * A parallel slot matches the URL through its *own* sub-tree, so it can derive\n * a param the main route never had, or derive the same name with a different\n * type (`[...year]` → `string[]` where the main route's `[year]` gave\n * `string`). The server answers `getSegmentParams(slotPath)` from a per-slot\n * map; the client answers `useSegmentParams(slotPath)` from the same map,\n * published on the RSC payload (TIM-1285).\n *\n * The merge lives here rather than in either half because the two must agree\n * about what \"the slot's params\" are — a divergence is invisible until\n * somebody reads a param of the wrong type, which is exactly the class of bug\n * this module closes.\n *\n * Isomorphic: no server or client imports.\n *\n * See design/41-global-params.md §\"Params in a parallel slot\".\n */\n\nimport type { CoercedParams } from './param-value.ts';\n\n/** Slot tree path → that slot's own coerced params. */\nexport type SlotParamsRecord = Record<string, CoercedParams>;\n\n/**\n * The params a slot sees: the main route's as a base, the slot's own on top.\n *\n * Params from segments *above* the slot are not re-derived by the slot's own\n * chain, so they have to come from the main route; params the slot does\n * re-derive may have a different type than the main route gave them, so the\n * slot's win.\n *\n * Null-prototype, like every other param record the framework hands out\n * (`coerceSegmentParams` installs one unconditionally). A spread literal would\n * inherit `Object.prototype`, so a lookup for a param the route does not\n * define would resolve to an inherited member — `params.constructor` returning\n * a function instead of `undefined` — in the one param record that was built\n * by merging. See design/13-security.md #36c.\n */\nexport function mergeSlotParams(\n mainParams: CoercedParams,\n slotParams: CoercedParams\n): CoercedParams {\n return Object.assign(Object.create(null), mainParams, slotParams);\n}\n\n/**\n * Resolve the params for a segment path against a published slot map.\n *\n * Returns the merge when `segmentPath` names a slot that published params,\n * and the main route's record otherwise — an ordinary (non-slot) segment\n * path, an unknown path, or a request with no slots at all. Mirrors the\n * server's `getSegmentParams(segmentPath)` branch exactly.\n *\n * `Object.hasOwn` rather than `in` or a truthiness test: the map arrives from\n * JSON, so a segment path of `constructor` or `toString` would otherwise\n * resolve to an inherited member of `Object.prototype`.\n */\nexport function resolveSegmentParams(\n mainParams: CoercedParams,\n slotParams: SlotParamsRecord | null | undefined,\n segmentPath: string | undefined\n): CoercedParams {\n if (!segmentPath || !slotParams || !Object.hasOwn(slotParams, segmentPath)) return mainParams;\n return cachedMerge(mainParams, slotParams, segmentPath);\n}\n\n/**\n * The merged record for one (main record, slot map, path) triple, reused until\n * one of the three changes.\n *\n * `useSegmentParams(slotPath)` calls this on every render. Returning a fresh\n * object each time makes the hook's result change by reference on renders where\n * nothing navigated, so a component using it as a `useEffect` dependency\n * re-runs the effect — and re-renders in a loop if that effect sets state —\n * while memoized children below it lose their memoization.\n *\n * Keyed on the *identities* of the two records, not their contents: both are\n * replaced rather than mutated on every navigation (`ParamsProvider`'s memoized\n * value and the server's per-request store), so identity is the correct\n * equality here and a deep comparison would be slower and no more accurate.\n *\n * A `WeakMap` chain rather than a `Map`, so a superseded navigation's records\n * and their merges become collectable as soon as nothing else holds them.\n */\nconst mergeCache = new WeakMap<object, WeakMap<object, Map<string, CoercedParams>>>();\n\nfunction cachedMerge(\n mainParams: CoercedParams,\n slotParams: SlotParamsRecord,\n segmentPath: string\n): CoercedParams {\n let bySlotMap = mergeCache.get(mainParams);\n if (!bySlotMap) {\n bySlotMap = new WeakMap();\n mergeCache.set(mainParams, bySlotMap);\n }\n let byPath = bySlotMap.get(slotParams);\n if (!byPath) {\n byPath = new Map();\n bySlotMap.set(slotParams, byPath);\n }\n const cached = byPath.get(segmentPath);\n if (cached) return cached;\n const merged = mergeSlotParams(mainParams, slotParams[segmentPath]);\n byPath.set(segmentPath, merged);\n return merged;\n}\n","/**\n * Shared utility for merging preserved search params into a target URL.\n *\n * Used by both <Link> (client) and redirect() (server). Extracted to a shared\n * module to avoid importing client code ('use client') from server modules.\n */\n\n/**\n * Merge preserved search params from the current URL into a target href.\n *\n * When `preserve` is `true`, all current search params are merged.\n * When `preserve` is a `string[]`, only the named params are merged.\n *\n * The target href's own search params take precedence — preserved params\n * are only added if the target doesn't already define them.\n *\n * @param targetHref - The resolved target href (may already contain query string)\n * @param currentSearch - The current URL's search string (e.g. \"?private=access&page=2\")\n * @param preserve - `true` to preserve all, or `string[]` to preserve specific params\n * @returns The target href with preserved search params merged in\n */\nexport function mergePreservedSearchParams(\n targetHref: string,\n currentSearch: string,\n preserve: true | string[]\n): string {\n const currentParams = new URLSearchParams(currentSearch);\n if (currentParams.size === 0) return targetHref;\n\n // Split hash fragment from target before processing query params.\n // Hash must come after query string: /path?query=value#hash\n const hashIdx = targetHref.indexOf('#');\n const hrefWithoutHash = hashIdx >= 0 ? targetHref.slice(0, hashIdx) : targetHref;\n const hash = hashIdx >= 0 ? targetHref.slice(hashIdx) : '';\n\n // Split target into path and existing query\n const qIdx = hrefWithoutHash.indexOf('?');\n const targetPath = qIdx >= 0 ? hrefWithoutHash.slice(0, qIdx) : hrefWithoutHash;\n const targetParams = new URLSearchParams(qIdx >= 0 ? hrefWithoutHash.slice(qIdx + 1) : '');\n\n // Collect params to preserve (that aren't already in the target)\n const merged = new URLSearchParams(targetParams);\n for (const [key, value] of currentParams) {\n // Only preserve if: (a) not already in target, and (b) included in preserve list\n if (!targetParams.has(key)) {\n if (preserve === true || preserve.includes(key)) {\n merged.append(key, value);\n }\n }\n }\n\n const qs = merged.toString();\n const pathWithQuery = qs ? `${targetPath}?${qs}` : targetPath;\n return pathWithQuery + hash;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,SAAgB,gBACd,YACA,YACe;CACf,OAAO,OAAO,OAAO,OAAO,OAAO,IAAI,GAAG,YAAY,UAAU;AAClE;;;;;;;;;;;;;AAcA,SAAgB,qB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QAAQ,SAAS,SAAS,GAAG,GAC5C,OAAO,OAAO,KAAK,KAAK;CAAA;CAK9B,MAAM,KAAK,OAAO,SAAS;CAE3B,QADsB,KAAK,GAAG,WAAW,GAAG,OAAO,cAC5B;AACzB"}
@@ -126,6 +126,11 @@ function deriveUrlKeys(codecs) {
126
126
  }
127
127
  /**
128
128
  * Bridge an entire codec map to nuqs-compatible parsers.
129
+ *
130
+ * Keyed by `string`, not `keyof T`: the per-key types are erased across the
131
+ * nuqs boundary anyway (the hook re-types its values as `T` on the way out),
132
+ * and a string-keyed map is what lets the timber-owned `urlKeys` — a
133
+ * `Record<string, string>` — type-check against nuqs's `UrlKeys<KeyMap>`.
129
134
  */
130
135
  function bridgeCodecs(codecs) {
131
136
  const result = {};
@@ -155,17 +160,16 @@ function bridgeCodecs(codecs) {
155
160
  * "not registered yet" failure mode. See design/23-search-params.md
156
161
  * §"Client Access".
157
162
  */
158
- function useQueryStates$1(codecs, _options, urlKeys) {
163
+ function useQueryStates$1(codecs, options, urlKeys) {
159
164
  const bridged = bridgeCodecs(codecs);
160
- const nuqsOptions = {};
161
- if (_options?.shallow !== void 0) nuqsOptions.shallow = _options.shallow;
162
- if (_options?.scroll !== void 0) nuqsOptions.scroll = _options.scroll;
163
- if (_options?.history !== void 0) nuqsOptions.history = _options.history;
164
165
  const resolvedUrlKeys = {
165
166
  ...deriveUrlKeys(codecs),
166
167
  ...urlKeys
167
168
  };
168
- if (Object.keys(resolvedUrlKeys).length > 0) nuqsOptions.urlKeys = resolvedUrlKeys;
169
+ const nuqsOptions = {
170
+ ...options,
171
+ urlKeys: resolvedUrlKeys
172
+ };
169
173
  let values;
170
174
  let setValues;
171
175
  try {
@@ -183,10 +187,6 @@ function useQueryStates$1(codecs, _options, urlKeys) {
183
187
  }
184
188
  }
185
189
  const setParams = (partial, setOptions) => {
186
- const nuqsSetOptions = {};
187
- if (setOptions?.shallow !== void 0) nuqsSetOptions.shallow = setOptions.shallow;
188
- if (setOptions?.scroll !== void 0) nuqsSetOptions.scroll = setOptions.scroll;
189
- if (setOptions?.history !== void 0) nuqsSetOptions.history = setOptions.history;
190
190
  let forwarded = partial;
191
191
  for (const key of Object.keys(partial)) {
192
192
  const value = partial[key];
@@ -205,7 +205,7 @@ function useQueryStates$1(codecs, _options, urlKeys) {
205
205
  }
206
206
  }
207
207
  }
208
- setValues(forwarded, nuqsSetOptions);
208
+ setValues(forwarded, setOptions);
209
209
  };
210
210
  return [normalized, setParams];
211
211
  }
@@ -220,4 +220,4 @@ function bindUseQueryStates(definition) {
220
220
  }
221
221
  export { parseTotal as i, useQueryStates$1 as n, serializedEqual as r, bindUseQueryStates as t };
222
222
 
223
- //# sourceMappingURL=use-query-states-pkDV-jSg.js.map
223
+ //# sourceMappingURL=use-query-states-D3MMl-KM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-query-states-D3MMl-KM.js","names":["useQueryStates","nuqsUseQueryStates"],"sources":["../../src/search-params/parse-total.ts","../../src/search-params/serialize-equal.ts","../../src/client/use-query-states.ts"],"sourcesContent":["/**\n * parseTotal — invoke a codec over the FULL raw domain.\n *\n * `SearchParamCodec.parse` is documented to be total over\n * `string | string[] | undefined`, because that is exactly what a URL\n * hands it: a param can be absent (`undefined`) or repeated (`string[]`).\n * Timber's own codecs and the Standard Schema bridges honour that.\n *\n * nuqs parsers do not. Their `parse` expects a **present scalar string** —\n * nuqs checks presence itself before ever calling it — so `parseAsBoolean`\n * and `parseAsIsoDate` threw a render-phase 500 on an absent param and\n * `parseAsString` returned an array on a repeated one (TIM-1350).\n *\n * nuqs ships the missing adapter: every parser builder exposes\n * `parseServerSide(value: string | string[] | undefined)`, which maps\n * absent → `null` (or the parser's `withDefault` value), takes the FIRST\n * entry of a repeated param (matching `URLSearchParams.get()`), and wraps\n * the inner `parse` so a throw becomes `null`. That is precisely timber's\n * domain, so we call it in preference to `parse` rather than hand-rolling\n * a second normalization that could disagree with the client hook.\n *\n * Feature detection, not an instanceof check: any codec MAY publish\n * `parseServerSide` to declare \"this is my total entry point\" — it is an\n * optional member of `SearchParamCodec` — and a codec that does not is\n * assumed already total and called through `parse`. Timber codecs and\n * schema bridges take the second branch untouched; several of them rely on\n * `parse(undefined)` to produce their default.\n *\n * **Search params only.** Segment params (`server/param-coercion.ts`) call\n * `codec.parse` directly and must keep doing so: their domain is a value\n * the router matched, never absent, and a codec that REJECTS one is how a\n * route produces a 404. Routing a rejection through nuqs's `safeParse`\n * would turn that 404 into a silent `null` param. The two domains differ\n * in what \"no value\" means, not just in plumbing. Cookies are a third\n * domain (`cookies/define-cookie.ts`) and are likewise untouched.\n *\n * `parseServerSide` carries a `@deprecated` tag in nuqs (it steers users to\n * loaders, which timber does not use). It remains public, typed and\n * exercised; `tests/nuqs-codec-boundary.test.ts` asserts totality for every\n * parser through timber's own API, so a nuqs release that drops it fails\n * loudly rather than silently reinstating the 500s.\n *\n * Design doc: design/23-search-params.md §\"nuqs parsers, made total\"\n */\n\n/**\n * Minimal interface for anything `parseTotal` can dispatch. Only `parse` is\n * required; `parseServerSide` is the optional total entry point. `serialize`\n * is deliberately absent — `parseTotal` never calls it, and requiring it\n * would prevent `SearchParamCodec<T>` (whose serialize returns `string |\n * string[] | null`) from being passed where `Codec<T>` (whose serialize\n * returns `string | null`) is expected.\n */\nexport interface ParseableCodec<T> {\n parse(value: string | string[] | undefined): T;\n parseServerSide?(value: string | string[] | undefined): T;\n}\n\n/**\n * A codec that publishes a total entry point over the raw URL domain.\n *\n * The return is `T`, not `T | null`. This is the entry point timber calls,\n * so whatever it answers IS the field's type. A `null` for an absent param\n * belongs in `T` — a bare nuqs parser is a codec of `string | null`, and\n * `parseAsInteger.withDefault(1)` is a codec of `number`, because nuqs\n * narrows its own `parseServerSide` return to `NonNullable<T>`. Declaring\n * `T | null` here would let a codec annotated `SearchParamCodec<string>`\n * hand back `null` under a non-nullable type (TIM-1350 review).\n */\nexport interface TotalCodec<T> {\n parseServerSide(value: string | string[] | undefined): T;\n}\n\nfunction hasParseServerSide<T>(\n codec: ParseableCodec<T>\n): codec is ParseableCodec<T> & TotalCodec<T> {\n return typeof (codec as Partial<TotalCodec<T>>).parseServerSide === 'function';\n}\n\n/**\n * Parse a raw URL value through a codec, using the codec's total entry\n * point when it publishes one.\n *\n * Returns `T`, from both branches. A `null` for an absent param is part of\n * the codec's own `T` — see TotalCodec above — so this signature does not\n * widen it, and a caller that must handle \"no value\" (`withDefault`) sees\n * it because `T` carries it.\n */\nexport function parseTotal<T>(codec: ParseableCodec<T>, raw: string | string[] | undefined): T {\n return hasParseServerSide(codec) ? codec.parseServerSide(raw) : codec.parse(raw);\n}\n","/**\n * Compare two serialize results for equality. Needed because `string[]`\n * from repeated-key codecs does not compare by reference.\n *\n * Shared between define.ts (buildSearchParams default-omission) and\n * use-query-states.ts (bridgeCodec eq). One source of truth.\n */\nexport function serializedEqual(a: string | string[] | null, b: string | string[] | null): boolean {\n if (a === b) return true;\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((v, i) => v === b[i]);\n }\n return false;\n}\n","/**\n * useQueryStates — client-side hook for URL-synced search params.\n *\n * Delegates to nuqs for URL synchronization, batching, React 19 transitions,\n * and throttled URL writes. Bridges timber's SearchParamCodec protocol to\n * nuqs-compatible parsers.\n *\n * Design doc: design/23-search-params.md §\"Codec Bridge\"\n */\n\n'use client';\n\nimport { useQueryStates as nuqsUseQueryStates } from 'nuqs';\nimport type { MultiParser, SetValues, UseQueryStatesOptions } from 'nuqs';\nimport type {\n SearchParamCodec,\n SearchParamsDefinition,\n SetParams,\n QueryStatesOptions,\n} from '../search-params/define.ts';\nimport { parseTotal } from '../search-params/parse-total.ts';\nimport { serializedEqual } from '../search-params/serialize-equal.ts';\n\n// ─── Codec Bridge ─────────────────────────────────────────────────\n\n// nuqs's parser contract conflates values timber codecs distinguish:\n// parse() returning null means \"unparseable, substitute defaultValue\",\n// and undefined entries are skipped entirely. Timber codecs can\n// legitimately produce both — bare z.string() yields undefined for absent\n// params (implicit optionality), and a codec may map a present value to\n// null. Wrap those two values in sentinels across the nuqs boundary and\n// unwrap them before handing values back to the caller, so the client\n// hook returns exactly what server-side parse() returns.\n// Unique object references compared by identity — a codec can never\n// produce these from URL input, so user-controlled strings cannot collide\n// with them (unlike string sentinels), and unlike Symbols they survive\n// nuqs's internal string coercion without throwing.\nconst NULL_SENTINEL: object = { timberSentinel: 'null' };\nconst UNDEFINED_SENTINEL: object = { timberSentinel: 'undefined' };\n\nfunction wrapNuqsValue(value: unknown): unknown {\n if (value === null) return NULL_SENTINEL;\n if (value === undefined) return UNDEFINED_SENTINEL;\n return value;\n}\n\nfunction unwrapNuqsValue(value: unknown): unknown {\n if (value === NULL_SENTINEL) return null;\n if (value === UNDEFINED_SENTINEL) return undefined;\n return value;\n}\n\n/**\n * Bridge a timber SearchParamCodec to a nuqs-compatible MultiParser.\n *\n * nuqs parsers: { parse(string) → T|null, serialize?(T) → string, eq?, defaultValue? }\n * timber codecs: { parse(string|string[]|undefined) → T, serialize(T) → string|null }\n *\n * The defaultValue is computed eagerly, through `parseTotal` — the same\n * entry point server-side `parse()` uses, so the hook and the server agree\n * on what an absent param means (a bare nuqs parser answers `null`, not\n * `undefined`; TIM-1350). Codecs are documented to return a default rather\n * than throw, but a throwing codec must not crash every component that\n * mounts the hook — treat its default as undefined and let its error\n * surface from server-side parse() instead.\n *\n * A `null` absent-value is NOT registered as the nuqs default. nuqs\n * already represents an absent key as `null`, so the hook reads the same\n * value either way — but registering it makes `clearOnDefault` fire on\n * `setParams({ q: null })` and delete the key before the bridged\n * `serialize` runs. For a codec that encodes `null` as a real query value\n * (`serialize(null) === 'none'`), that silently disagrees with\n * `buildSearchParams({ q: null })`, which writes it. Same reasoning as\n * `getDefaultSerialized` on the server: a codec with no value for an\n * absent param has no default to register.\n */\nfunction bridgeCodec<T>(codec: SearchParamCodec<T>): MultiParser<T> & { defaultValue: T } {\n let absent: unknown;\n try {\n absent = parseTotal(codec, undefined);\n } catch {\n absent = undefined;\n }\n\n const parser = {\n // `multi`, so nuqs reads the key with `searchParams.getAll()` and hands\n // us EVERY value. A single parser reads `.get()` — the first value only\n // — which is not the domain a timber codec is defined over. The server\n // parses `?tags=a&tags=b` as `['a','b']`; a single parser made the hook\n // answer `['a']` for the same URL, under a declared `string[]` that\n // admitted no such disagreement (TIM-1352). Scalar codecs are unaffected:\n // they receive the array and take `value[0]`, exactly as they do on the\n // server, so first-value-wins is preserved through the same code path\n // rather than through nuqs's reader.\n //\n // nuqs never calls this with an empty array — `isAbsentFromUrl` treats\n // `[]` as absent and answers `defaultValue` directly — which is what\n // keeps the absent case agreeing with the server's `undefined`.\n //\n // Reading every value is only half of it: the values must arrive in the\n // SAME SHAPE the server would have produced, or the divergence just\n // moves. `normalizeRaw` (search-params/define.ts) collapses a\n // single-valued key to a bare string and keeps an array only for a\n // repeated one, so this mirrors that rule exactly. Handing a codec\n // `['3']` where the server hands it `'3'` breaks every codec whose\n // `parse` is written for the scalar case — which is most hand-written\n // ones, contract or no contract.\n type: 'multi' as const,\n // Through parseTotal, not codec.parse. nuqs's own `.withDefault(d)`\n // overrides ONLY `parseServerSide`, so `parseAsInteger.withDefault(1)`\n // on `?page=abc` returned 1 from the server and null from the hook —\n // a divergence the declared non-nullable `number` did not admit.\n parse: (v: readonly string[]) =>\n wrapNuqsValue(parseTotal(codec, v.length === 1 ? v[0] : [...v])),\n serialize: (v: unknown) => {\n const value = unwrapNuqsValue(v);\n if (value === undefined) return [''];\n // TIM-1354: catch TypeError from codecs whose serialize is not total\n // over null (e.g. parseAsIsoDate.serialize(null) → null.toISOString()).\n // Only TypeError — deliberate signals must not be swallowed.\n let result: string | string[] | null;\n try {\n result = codec.serialize(value as T);\n } catch (error) {\n if (error instanceof TypeError) return [''];\n throw error;\n }\n // TIM-1353: pass through string[] from codecs that emit repeated\n // keys. nuqs multi parsers append one key=value per array element.\n if (Array.isArray(result)) return result;\n return [result ?? ''];\n },\n eq: (a: unknown, b: unknown) => {\n if (a === b) return true;\n try {\n return serializedEqual(\n codec.serialize(unwrapNuqsValue(a) as T),\n codec.serialize(unwrapNuqsValue(b) as T)\n );\n } catch {\n return false;\n }\n },\n } as MultiParser<T> & { defaultValue: T };\n\n if (absent !== null) parser.defaultValue = wrapNuqsValue(absent) as T;\n return parser;\n}\n\n/**\n * Collect `withUrlKey` aliases off a codec map.\n *\n * `withUrlKey(codec, 'q')` returns a codec carrying `urlKey: 'q'`, so the map\n * alone is enough to reconstruct the aliases — `defineSearchParams` builds its\n * own `urlKeys` from exactly this property.\n */\nfunction deriveUrlKeys(codecs: Record<string, SearchParamCodec<unknown>>): Record<string, string> {\n const result: Record<string, string> = {};\n for (const key of Object.keys(codecs)) {\n const alias = codecs[key]?.urlKey;\n if (alias) result[key] = alias;\n }\n return result;\n}\n\ntype BridgedParsers = Record<string, MultiParser<unknown> & { defaultValue: unknown }>;\n\n/**\n * Bridge an entire codec map to nuqs-compatible parsers.\n *\n * Keyed by `string`, not `keyof T`: the per-key types are erased across the\n * nuqs boundary anyway (the hook re-types its values as `T` on the way out),\n * and a string-keyed map is what lets the timber-owned `urlKeys` — a\n * `Record<string, string>` — type-check against nuqs's `UrlKeys<KeyMap>`.\n */\nfunction bridgeCodecs<T extends Record<string, unknown>>(codecs: {\n [K in keyof T]: SearchParamCodec<T[K]>;\n}): BridgedParsers {\n const result: BridgedParsers = {};\n for (const key of Object.keys(codecs)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result[key] = bridgeCodec(codecs[key as keyof T]) as any;\n }\n return result;\n}\n\n// ─── Hook ─────────────────────────────────────────────────────────\n\n/**\n * Read and write typed search params from/to the URL.\n *\n * Delegates to nuqs internally. The timber nuqs adapter (auto-injected in\n * browser-entry.ts) handles RSC navigation on non-shallow updates.\n *\n * Usage:\n * ```ts\n * // Via a SearchParamsDefinition imported from the route's params.ts\n * const [params, setParams] = definition.useQueryStates()\n *\n * // Standalone with inline codecs\n * const [params, setParams] = useQueryStates({\n * page: fromSchema(z.coerce.number().int().min(1).default(1)),\n * })\n * ```\n *\n * There is deliberately no route-string form (`useQueryStates('/products')`).\n * Importing the definition from `params.ts` is the documented way to reach\n * another route's codecs — it needs no runtime registry lookup and so has no\n * \"not registered yet\" failure mode. See design/23-search-params.md\n * §\"Client Access\".\n */\nexport function useQueryStates<T extends Record<string, unknown>>(\n codecs: { [K in keyof T]: SearchParamCodec<T[K]> },\n options?: QueryStatesOptions,\n urlKeys?: Readonly<Record<string, string>>\n): [T, SetParams<T>] {\n const bridged = bridgeCodecs(codecs);\n\n // `withUrlKey` attaches the alias to the codec itself — that is the design's\n // \"URL keys travel with codecs\" principle — so the aliases are derivable\n // here and must be, for the inline codec-map form: nobody passes `urlKeys`\n // on that path, and without this an aliased bundle silently read and wrote\n // the property name instead of the alias. `bindUseQueryStates` still passes\n // the definition's precomputed map, which wins on conflict; it is built from\n // these same codecs, so the two agree by construction rather than by luck.\n const resolvedUrlKeys = { ...deriveUrlKeys(codecs), ...urlKeys };\n\n // Every hook option goes to nuqs whole, so an option nuqs adds later works\n // with no change here (TIM-1623: a field-by-field copy silently dropped\n // `limitUrlUpdates`). These are the defaults for every setter call from\n // this hook; nuqs resolves each write as per-call ?? hook ?? adapter\n // default. `urlKeys` is spread last: timber owns it, and nuqs's `Options`\n // does not declare it, so only an untyped caller could have supplied one.\n const nuqsOptions: Partial<UseQueryStatesOptions<BridgedParsers>> = {\n ...options,\n urlKeys: resolvedUrlKeys,\n };\n\n let values: Record<string, unknown>;\n let setValues: SetValues<BridgedParsers>;\n try {\n [values, setValues] = nuqsUseQueryStates(bridged, nuqsOptions);\n } catch (err) {\n if (\n err instanceof Error &&\n /Invalid hook call|cannot be called|Cannot read properties of null/i.test(err.message)\n ) {\n throw new Error(\n 'useQueryStates is a client component hook and cannot be called outside a React component. ' +\n 'Use definition.parse(searchParams) in server components instead.'\n );\n }\n throw err;\n }\n\n // Unwrap the null/undefined sentinels the bridge injected (see Codec\n // Bridge above) so callers see exactly what server-side parse() returns.\n // Copy-on-write preserves the identity of nuqs's memoized values object\n // when nothing needs unwrapping.\n let normalized = values;\n for (const key of Object.keys(bridged)) {\n const value = normalized[key];\n if (value === NULL_SENTINEL || value === UNDEFINED_SENTINEL) {\n if (normalized === values) normalized = { ...values };\n normalized[key] = unwrapNuqsValue(value);\n }\n }\n\n // Wrap the nuqs setter to match timber's SetParams<T> signature.\n // nuqs's setter accepts Partial<Nullable<Values>> | UpdaterFn | null.\n // timber's setter accepts Partial<T> with optional SetParamsOptions.\n // `setOptions` is nuqs's own `Options` and is forwarded untouched — see\n // the hook options above.\n const setParams: SetParams<T> = (partial, setOptions?) => {\n // nuqs's update loop skips undefined entries and treats null as a\n // key deletion before serialize runs. Timber semantics:\n // - setParams({ q: undefined }) must clear ?q= (absent = undefined),\n // so explicit undefined maps to a null deletion.\n // - setParams({ q: null }) clears the key only when the codec encodes\n // null as \"omit\" (serialize(null) === null). If the codec encodes\n // null as a real query value, forward the sentinel so the bridged\n // serialize writes it — matching definition.serialize({ q: null }).\n let forwarded: Record<string, unknown> = partial;\n for (const key of Object.keys(partial)) {\n const value = partial[key as keyof T];\n if (value === undefined) {\n if (forwarded === partial) forwarded = { ...partial };\n forwarded[key] = null;\n } else if (value === null) {\n let encoded: string | string[] | null = null;\n try {\n const raw = codecs[key as keyof T]?.serialize(null as T[keyof T]);\n // string[] is non-null, but an empty array carries no value\n encoded = raw === null ? null : Array.isArray(raw) ? (raw.length > 0 ? raw : null) : raw;\n } catch {\n // Codec can't serialize null — treat as a deletion.\n }\n if (encoded !== null) {\n if (forwarded === partial) forwarded = { ...partial };\n forwarded[key] = NULL_SENTINEL;\n }\n }\n }\n void setValues(forwarded, setOptions);\n };\n\n return [normalized as T, setParams];\n}\n\n// ─── Definition binding ───────────────────────────────────────────\n\n/**\n * Create a useQueryStates binding for a SearchParamsDefinition.\n * This is used internally by SearchParamsDefinition.useQueryStates().\n */\nexport function bindUseQueryStates<T extends Record<string, unknown>>(\n definition: SearchParamsDefinition<T>\n): (options?: QueryStatesOptions) => [T, SetParams<T>] {\n return (options?: QueryStatesOptions) => {\n return useQueryStates<T>(definition.codecs, options, definition.urlKeys);\n };\n}\n"],"mappings":";;AAyEA,SAAS,mBACP,OAC4C;CAC5C,OAAO,OAAQ,MAAiC,oBAAoB;AACtE;;;;;;;;;;AAWA,SAAgB,WAAc,OAA0B,KAAuC;CAC7F,OAAO,mBAAmB,KAAK,IAAI,MAAM,gBAAgB,GAAG,IAAI,MAAM,MAAM,GAAG;AACjF;;;;;;;;;ACnFA,SAAgB,gBAAgB,GAA6B,GAAsC;CACjG,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GACrC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,MAAM,EAAE,EAAE;CAE9D,OAAO;AACT;;;;;;;;;;;ACwBA,IAAM,gBAAwB,EAAE,gBAAgB,OAAO;AACvD,IAAM,qBAA6B,EAAE,gBAAgB,YAAY;AAEjE,SAAS,cAAc,OAAyB;CAC9C,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,OAAO;AACT;AAEA,SAAS,gBAAgB,OAAyB;CAChD,IAAI,UAAU,eAAe,OAAO;CACpC,IAAI,UAAU,oBAAoB,OAAO,KAAA;CACzC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAS,YAAe,OAAkE;CACxF,IAAI;CACJ,IAAI;EACF,SAAS,WAAW,OAAO,KAAA,CAAS;CACtC,QAAQ;EACN,SAAS,KAAA;CACX;CAEA,MAAM,SAAS;EAuBb,MAAM;EAKN,QAAQ,MACN,cAAc,WAAW,OAAO,EAAE,WAAW,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;EACjE,YAAY,MAAe;GACzB,MAAM,QAAQ,gBAAgB,CAAC;GAC/B,IAAI,UAAU,KAAA,GAAW,OAAO,CAAC,EAAE;GAInC,IAAI;GAC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Aa;CACjB,KAAK,MAAM,OAAO,OAAO,KAAK,OAAO,GAAG;EACtC,MAAM,QAAQ,WAAW;EACzB,IAAI,UAAU,iBAAiB,UAAU,oBAAoB;GAC3D,IAAI,eAAe,QAAQ,aAAa,EAAE,GAAG,OAAO;GACpD,WAAW,OAAO,gBAAgB,KAAK;EACzC;CACF;CAOA,MAAM,aAA2B,SAAS,eAAgB;EASxD,IAAI,YAAqC;EACzC,KAAK,MAAM,OAAO,OAAO,KAAK,OAAO,GAAG;GACtC,MAAM,QAAQ,QAAQ;GACtB,IAAI,UAAU,KAAA,GAAW;IACvB,IAAI,cAAc,SAAS,YAAY,EAAE,GAAG,QAAQ;IACpD,UAAU,OAAO;GACnB,OAAO,IAAI,UAAU,MAAM;IACzB,IAAI,UAAoC;IACxC,IAAI;KACF,MAAM,MAAM,OAAO,IAAe,EAAE,UAAU,IAAkB;KAEhE,UAAU,QAAQ,OAAO,OAAO,MAAM,QAAQ,GAAG,IAAK,IAAI,SAAS,IAAI,MAAM,OAAQ;IACvF,QAAQ,CAER;IACA,IAAI,YAAY,MAAM;KACpB,IAAI,cAAc,SAAS,YAAY,EAAE,GAAG,QAAQ;KACpD,UAAU,OAAO;IACnB;GACF;EACF;EACA,UAAe,WAAW,UAAU;CACtC;CAEA,OAAO,CAAC,YAAiB,SAAS;AACpC;;;;;AAQA,SAAgB,mBACd,YACqD;CACrD,QAAQ,YAAiC;EACvC,OAAOD,iBAAkB,WAAW,QAAQ,SAAS,WAAW,OAAO;CACzE;AACF"}
package/dist/cli.js CHANGED
@@ -179,7 +179,7 @@ async function runPreview(options, _deps) {
179
179
  * `--project` names the tsconfig handed to tsgo.
180
180
  */
181
181
  async function runCheck(options, _deps) {
182
- const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-B-JZkpBD.js");
182
+ const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-BAKOSTkg.js");
183
183
  const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);
184
184
  await runTypeCheck({
185
185
  root,
@@ -1,4 +1,5 @@
1
- export { Link, interpolateParams, resolveHref, validateLinkHref, buildLinkProps } from './link.tsx';
1
+ export { Link, validateLinkHref, buildLinkProps } from './link.tsx';
2
+ export { interpolateParams, resolveHref } from '../shared/href.ts';
2
3
  export { mergePreservedSearchParams } from '../shared/merge-search-params.ts';
3
4
  export type { LinkProps, LinkPropsWithHref, LinkPropsWithParams, LinkBaseProps } from './link.tsx';
4
5
  export type { LinkSegmentParams, OnNavigateHandler, OnNavigateEvent } from './link.tsx';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnG,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA4CxF,MAAM,WAAW,YAAY;CAG5B;AACD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UA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AAY,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAY3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,14 +1,14 @@
1
1
  "use client";
2
- import { n as classifyUrlSegment } from "../_chunks/segment-classify-Ho8jXWeC.js";
3
2
  import { c as stripRscCacheKey } from "../_chunks/rsc-cache-key-D0cb0Gmc.js";
4
- import { a as mergePreservedSearchParams, i as validateNavigationHref, n as isInternalHref, o as resolveSegmentParams } from "../_chunks/href-validation-CEZy1V-k.js";
3
+ import { n as resolveSegmentParams, t as mergePreservedSearchParams } from "../_chunks/merge-search-params-7o_5yX0L.js";
4
+ import { i as validateNavigationHref, n as isInternalHref } from "../_chunks/href-validation-DNg-zV7u.js";
5
5
  import "../_chunks/param-value-DqlGfF57.js";
6
6
  import { t as createGlobalContext } from "../_chunks/global-context-CFSSysdJ.js";
7
+ import { n as interpolateParams, r as resolveHref } from "../_chunks/href-BtspoNc9.js";
7
8
  import { i as useNavigationContext, n as usePendingNavigation, o as getRouterOrNull } from "../_chunks/navigation-root-CoGHIMiE.js";
8
9
  import { t as getSsrData } from "../_chunks/ssr-data-9hPtcNOr.js";
9
- import { t as getLinkCodec } from "../_chunks/codec-registry-CPc6bjVl.js";
10
10
  import { n as useSegmentContext } from "../_chunks/segment-context-GAyTjjtS.js";
11
- import { n as useQueryStates } from "../_chunks/use-query-states-pkDV-jSg.js";
11
+ import { n as useQueryStates } from "../_chunks/use-query-states-D3MMl-KM.js";
12
12
  import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
13
13
  import { flushSync } from "react-dom";
14
14
  import { jsx } from "react/jsx-runtime";
@@ -82,124 +82,6 @@ function isNativeFragmentLink(anchor) {
82
82
  return hashIndex !== -1 && href.slice(0, hashIndex) === window.location.href.split("#", 1)[0];
83
83
  }
84
84
  /**
85
- * Interpolate dynamic segments in a route pattern with actual values.
86
- * e.g. interpolateParams("/products/[id]", { id: "123" }) → "/products/123"
87
- *
88
- * Supports:
89
- * - [param] → single segment
90
- * - [...param] → catch-all (joined with /)
91
- * - [[...param]] → optional catch-all (omitted if undefined/empty)
92
- */
93
- /**
94
- * Parse a route pattern's path portion into classified segments.
95
- * Exported for testing. Uses the shared character-based classifier.
96
- */
97
- function parseSegments(pattern) {
98
- return pattern.split("/").filter(Boolean).map(classifyUrlSegment);
99
- }
100
- /**
101
- * Resolve a single classified segment into its string representation.
102
- * Returns null for optional catch-all with no value (filtered out before join).
103
- *
104
- * When schema codecs are registered (via virtual:timber-schema), uses
105
- * codec.serialize() for URL construction instead of plain String().
106
- */
107
- function resolveSegment(seg, params, pattern) {
108
- switch (seg.kind) {
109
- case "static": return seg.value;
110
- case "optional-catch-all": {
111
- const value = params[seg.name];
112
- if (value === void 0 || Array.isArray(value) && value.length === 0) return null;
113
- const codec = getLinkCodec(`[[...${seg.name}]]`);
114
- if (codec) {
115
- const serialized = codec.serialize(value);
116
- if (!serialized) return null;
117
- return serialized.split("/").map(encodeURIComponent).join("/");
118
- }
119
- return (Array.isArray(value) ? value : [value]).map(encodeURIComponent).join("/");
120
- }
121
- case "catch-all": {
122
- const value = params[seg.name];
123
- if (value === void 0) throw new Error(`<Link> missing required catch-all param "${seg.name}" for pattern "${pattern}".`);
124
- const codec = getLinkCodec(`[...${seg.name}]`);
125
- if (codec) {
126
- const serialized = codec.serialize(value);
127
- if (!serialized) throw new Error(`<Link> catch-all param "${seg.name}" codec returned null for pattern "${pattern}".`);
128
- return serialized.split("/").map(encodeURIComponent).join("/");
129
- }
130
- const segments = Array.isArray(value) ? value : [value];
131
- if (segments.length === 0) throw new Error(`<Link> catch-all param "${seg.name}" must have at least one segment for pattern "${pattern}".`);
132
- return segments.map(encodeURIComponent).join("/");
133
- }
134
- case "dynamic": {
135
- const value = params[seg.name];
136
- if (value === void 0) throw new Error(`<Link> missing required param "${seg.name}" for pattern "${pattern}".`);
137
- if (Array.isArray(value)) throw new Error(`<Link> param "${seg.name}" expected a string but received an array for pattern "${pattern}".`);
138
- const codec = getLinkCodec(`[${seg.name}]`);
139
- const str = codec ? codec.serialize(value) ?? String(value) : String(value);
140
- const encoded = encodeURIComponent(str);
141
- const prefix = seg.prefix ?? "";
142
- const suffix = seg.suffix ?? "";
143
- return prefix + encoded + suffix;
144
- }
145
- }
146
- }
147
- /**
148
- * Split a URL pattern into the path portion and any trailing ?query/#hash suffix.
149
- * Uses URL parsing for correctness rather than manual index arithmetic.
150
- */
151
- function splitPatternSuffix(pattern) {
152
- if (!pattern.includes("?") && !pattern.includes("#")) return [pattern, ""];
153
- const url = new URL(pattern, "http://x");
154
- const suffix = url.search + url.hash;
155
- return [pattern.slice(0, pattern.length - suffix.length), suffix];
156
- }
157
- function interpolateParams(pattern, params) {
158
- const [pathPart, suffix] = splitPatternSuffix(pattern);
159
- return ("/" + parseSegments(pathPart).map((seg) => resolveSegment(seg, params, pattern)).filter((s) => s !== null).join("/") || "/") + suffix;
160
- }
161
- /**
162
- * Resolve the final href string from Link props.
163
- *
164
- * Handles:
165
- * - params interpolation into route patterns
166
- * - searchParams serialization (see the two shapes documented above)
167
- * - Validation that searchParams and inline query strings are exclusive
168
- */
169
- /**
170
- * Tolerate a leading '?'. `buildSearchParams()` never emits one, but callers
171
- * hand-rolling a query string reasonably might, and silently producing
172
- * `?%3Fa=b` for it would be a worse failure than accepting both.
173
- */
174
- function stripLeadingQuestionMark(qs) {
175
- return qs.startsWith("?") ? qs.slice(1) : qs;
176
- }
177
- /**
178
- * Escape-hatch serialization for a plain object: String()-coerce every
179
- * value, append arrays as repeated keys, skip null/undefined.
180
- *
181
- * Deliberately codec-free and alias-free — see the shape docs above.
182
- */
183
- function coerceToQueryString(values) {
184
- const usp = new URLSearchParams();
185
- for (const [key, val] of Object.entries(values)) {
186
- if (val === void 0 || val === null) continue;
187
- if (Array.isArray(val)) for (const item of val) usp.append(key, String(item));
188
- else usp.set(key, String(val));
189
- }
190
- return usp.toString();
191
- }
192
- function resolveHref(href, params, searchParams) {
193
- let resolvedPath = href;
194
- if (params) resolvedPath = interpolateParams(href, params);
195
- if (searchParams) {
196
- if (resolvedPath.includes("?")) throw new Error("<Link> received both a searchParams prop and a query string in href. These are mutually exclusive — use one or the other.");
197
- const qs = typeof searchParams === "string" ? stripLeadingQuestionMark(searchParams) : coerceToQueryString(searchParams);
198
- if (qs) resolvedPath = `${resolvedPath}?${qs}`;
199
- }
200
- return resolvedPath;
201
- }
202
- /**
203
85
  * Build the HTML attributes for a Link. Separated from the component
204
86
  * for testability — the component just spreads these onto an <a>.
205
87
  */