@timber-js/app 0.2.0-alpha.217 → 0.2.0-alpha.219
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.
- package/agent-skill.md +5 -5
- package/dist/_chunks/{actions-CUh3cClk.js → actions-BwkmAYXq.js} +8 -1
- package/dist/_chunks/actions-BwkmAYXq.js.map +1 -0
- package/dist/_chunks/cloudflare-Byxl8FWP.js.map +1 -1
- package/dist/_chunks/dev-server-B8zsT-ee.js.map +1 -1
- package/dist/_chunks/dist-DtrJyBbw.js.map +1 -1
- package/dist/_chunks/graph-cache-CYiUS2aS.js.map +1 -1
- package/dist/_chunks/use-query-states-I3JMng6J.js.map +1 -1
- package/dist/adapters/cloudflare.js +1 -2
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/analyze/graph-command.js.map +1 -1
- package/dist/client/error-boundary.js +1 -2
- package/dist/client/form.d.ts +34 -37
- package/dist/client/form.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +40 -75
- package/dist/client/index.js.map +1 -1
- package/dist/client/{use-form-field.d.ts → use-field-state.d.ts} +10 -7
- package/dist/client/use-field-state.d.ts.map +1 -0
- package/dist/config-types.d.ts +15 -18
- package/dist/config-types.d.ts.map +1 -1
- package/dist/cookies/index.js.map +1 -1
- package/dist/index.js +29 -27
- package/dist/index.js.map +1 -1
- package/dist/plugins/build-manifest.d.ts.map +1 -1
- package/dist/plugins/shims.d.ts.map +1 -1
- package/dist/search-params/index.js.map +1 -1
- package/dist/server/action-client.d.ts +11 -172
- package/dist/server/action-client.d.ts.map +1 -1
- package/dist/server/action-handler.d.ts +0 -7
- package/dist/server/action-handler.d.ts.map +1 -1
- package/dist/server/action-schema.d.ts +126 -0
- package/dist/server/action-schema.d.ts.map +1 -0
- package/dist/server/action-types.d.ts +108 -0
- package/dist/server/action-types.d.ts.map +1 -0
- package/dist/server/form-data.d.ts +7 -0
- package/dist/server/form-data.d.ts.map +1 -1
- package/dist/server/index.d.ts +3 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +511 -148
- package/dist/server/index.js.map +1 -1
- package/dist/server/internal.js +12 -3
- package/dist/server/internal.js.map +1 -1
- package/dist/server/pipeline-metadata.d.ts +9 -0
- package/dist/server/pipeline-metadata.d.ts.map +1 -1
- package/dist/server/pipeline-phases.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-dispatcher.d.ts +0 -3
- package/dist/server/rsc-entry/action-dispatcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/schema-introspection.d.ts +68 -0
- package/dist/server/schema-introspection.d.ts.map +1 -0
- package/dist/server/sensitive-fields.d.ts +40 -26
- package/dist/server/sensitive-fields.d.ts.map +1 -1
- package/dist/server/sitemap-handler.d.ts.map +1 -1
- package/docs/api/31-api-client.mdx +19 -18
- package/docs/api/34-api-config.mdx +1 -1
- package/docs/learn/08-forms-and-actions.mdx +57 -23
- package/package.json +8 -8
- package/src/client/browser-entry/index.ts +7 -1
- package/src/client/form.tsx +57 -108
- package/src/client/index.ts +3 -3
- package/src/client/{use-form-field.ts → use-field-state.ts} +20 -8
- package/src/config-types.ts +15 -18
- package/src/plugins/build-manifest.ts +12 -27
- package/src/plugins/shims.ts +0 -1
- package/src/server/action-client.ts +82 -307
- package/src/server/action-handler.ts +1 -42
- package/src/server/action-schema.ts +203 -0
- package/src/server/action-types.ts +145 -0
- package/src/server/form-data.ts +7 -0
- package/src/server/index.ts +5 -3
- package/src/server/pipeline-metadata.ts +11 -1
- package/src/server/pipeline-phases.ts +9 -2
- package/src/server/rsc-entry/action-dispatcher.ts +0 -4
- package/src/server/rsc-entry/index.ts +1 -2
- package/src/server/schema-introspection.ts +393 -0
- package/src/server/sensitive-fields.ts +115 -58
- package/src/server/sitemap-handler.ts +14 -21
- package/dist/_chunks/actions-CUh3cClk.js.map +0 -1
- package/dist/client/use-form-field.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-manifest.d.ts","sourceRoot":"","sources":["../../src/plugins/build-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"build-manifest.d.ts","sourceRoot":"","sources":["../../src/plugins/build-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAKvF,UAAU,WAAW;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC3E;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC;AAK9D;;;GAGG;AACH,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAC/C,IAAI,EAAE,MAAM,GACX,aAAa,CAmBf;AAqCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,aAAa,CA0Cf;AAiID;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CA0J9D"}
|
|
@@ -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,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/search-params/define.ts","../../src/search-params/wrappers.ts"],"sourcesContent":["/**\n * defineSearchParams — factory for SearchParamsDefinition<T>.\n *\n * Creates a typed, composable definition for a route's search parameters.\n * Accepts both SearchParamCodec values and Standard Schema objects (Zod,\n * Valibot, ArkType) with auto-detection. Supports URL key aliasing via\n * withUrlKey(), default-omission serialization, and composition via\n * .extend() / .pick().\n *\n * Design doc: design/23-search-params.md §\"defineSearchParams — The Factory\"\n */\n\nimport { useQueryStates as clientUseQueryStates } from '../client/use-query-states.ts';\nimport { fromSchema, isStandardSchema, isCodec } from '../schema-bridge.ts';\nimport type { StandardSchemaV1 } from '../schema-bridge.ts';\nimport type { Codec } from '../codec.ts';\n// Server-only reference for .get() — avoids pulling server ALS into client\n// bundles. In client environments, .get() throws before reaching this code\n// path. The slot lives in its own leaf module so that `request-context.ts`\n// can register the getter without importing this file, which would drag\n// `nuqs` into every server entry (TIM-1298). See shared/als-slots.ts.\nimport { getSearchParamsFromAls } from '../shared/als-slots.ts';\nimport { parseTotal } from './parse-total.ts';\nimport { serializedEqual } from './serialize-equal.ts';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * A codec that converts between URL string values and typed values.\n *\n * `parse` receives the RAW url value: `string | string[] | undefined`.\n * A codec must be TOTAL over that domain — return a default rather than\n * throwing on an absent or repeated param.\n *\n * A codec whose own `parse` covers only a PRESENT, SINGLE-VALUED param\n * may publish `parseServerSide` instead, and timber calls that. nuqs\n * parsers do exactly this, which is how they become total here: absent →\n * `null` (or their `withDefault` value), repeated → the first value, and\n * a throw from the inner parse → `null`. See\n * design/23-search-params.md §'nuqs parsers, made total',\n * `parse-total.ts`, and tests/nuqs-codec-boundary.test.ts (TIM-1350).\n *\n * Standard Schema objects (Zod, Valibot, ArkType) are auto-detected\n * by defineSearchParams and wrapped via fromSchema; those ARE total\n * through `parse` and are called that way.\n */\nexport interface SearchParamCodec<T> extends Omit<Codec<T>, 'serialize'> {\n /**\n * Typed value → URL string(s). Return `null` to omit/clear.\n *\n * A codec MAY return `string[]` to emit repeated keys (`?tag=a&tag=b`).\n * `buildSearchParams` appends one `key=value` entry per array element;\n * the nuqs bridge forwards the array to nuqs, which does the same.\n * Codecs that always produce a single value return a plain string.\n *\n * Wider than `Codec<T>.serialize` (`string | null`) because search params\n * have a repeated-key concept that cookies and segment params do not.\n */\n serialize(value: T): string | string[] | null;\n /** Optional URL key alias, set by withUrlKey(). */\n urlKey?: string;\n /**\n * Optional TOTAL entry point over `string | string[] | undefined`,\n * preferred over `parse` wherever timber invokes a codec. Declared here\n * so the protocol is typed rather than duck-checked at each wrapper:\n * anything that reconstructs a codec has to carry it, and a wrapper\n * cannot carry a property the interface does not admit.\n *\n * It returns `T`, not `T | null`. This is the entry point timber calls,\n * so whatever it returns IS the field's type — admitting a `null` the\n * field type did not carry would let `SearchParamCodec<string>` produce\n * `null` for an absent param under a non-nullable annotation. A codec\n * whose absent-case answer is `null` declares that in `T`, exactly as a\n * bare nuqs parser does: `parseAsString` is a `SearchParamCodec<string |\n * null>` here, never a `SearchParamCodec<string>`.\n *\n * nuqs parser builders satisfy this. See parse-total.ts.\n */\n parseServerSide?(value: string | string[] | undefined): T;\n}\n\n/** A codec with a URL key alias attached via withUrlKey(). */\nexport interface SearchParamCodecWithUrlKey<T> extends SearchParamCodec<T> {\n urlKey: string;\n}\n\n/** Infer the output type of a codec. */\nexport type InferCodec<C> = C extends SearchParamCodec<infer T> ? T : never;\n\n/** Map of property names to codecs. */\nexport type CodecMap<T extends Record<string, unknown>> = {\n [K in keyof T]: SearchParamCodec<T[K]>;\n};\n\n/** Options for useQueryStates setter. */\nexport interface SetParamsOptions {\n /** Update URL without server roundtrip (default: false). */\n shallow?: boolean;\n /** Scroll to top after update (default: true). */\n scroll?: boolean;\n /** 'push' (default) or 'replace' for history state. */\n history?: 'push' | 'replace';\n}\n\n/** Setter function returned by useQueryStates. */\nexport type SetParams<T> = (values: Partial<T>, options?: SetParamsOptions) => void;\n\n/** Options for useQueryStates hook. */\nexport interface QueryStatesOptions {\n /** Update URL without server roundtrip (default: false). */\n shallow?: boolean;\n /** Scroll to top after update (default: true). */\n scroll?: boolean;\n /** 'push' (default) or 'replace' for history state. */\n history?: 'push' | 'replace';\n}\n\n/**\n * A fully typed, composable search params definition.\n *\n * Returned by defineSearchParams(). Carries a phantom _type property\n * for build-time type extraction.\n */\nexport interface SearchParamsDefinition<T extends Record<string, unknown>> {\n /** Parse raw URL search params into typed values. */\n parse(raw: URLSearchParams | Record<string, string | string[] | undefined>): T;\n /** Parse a Promise of URLSearchParams (e.g., from the ALS `searchParams()` API). */\n parse(raw: Promise<URLSearchParams | Record<string, string | string[] | undefined>>): Promise<T>;\n\n /**\n * Get typed search params from the current request context (ALS-backed).\n *\n * Server-only, sync. Reads getSearchParams() from ALS and parses through codecs.\n * Throws on client.\n *\n * ```tsx\n * // app/products/page.tsx\n * import { searchParams } from './search-params'\n * export default function Page() {\n * const { page, category } = searchParams.get()\n * }\n * ```\n */\n get(): T;\n\n /** Client hook — reads current URL params and returns typed values + setter. */\n useQueryStates(options?: QueryStatesOptions): [T, SetParams<T>];\n\n /** Extend with additional codecs or Standard Schema objects. */\n extend<U extends Record<string, SearchParamField>>(\n codecs: U\n ): SearchParamsDefinition<T & { [K in keyof U]: InferField<U[K]> }>;\n\n /** Pick a subset of keys. Preserves codecs and aliases. */\n pick<K extends keyof T & string>(...keys: K[]): SearchParamsDefinition<Pick<T, K>>;\n\n /**\n * Serialize values to a query string (no leading '?'), omitting defaults\n * and applying `withUrlKey` aliases. This is the value to pass to\n * `<Link searchParams={...}>`.\n *\n * Returns a **string**, not a `URLSearchParams`. A `<Link>` prop crosses\n * the RSC Flight boundary, and `URLSearchParams` is iterable — React\n * serializes it as an entries array, which arrives as `[['pg','2'], …]`\n * and renders as `?0=pg&0=2`. A string survives intact.\n */\n buildSearchParams(values: Partial<T>): string;\n\n /** Build a full path with query string, omitting defaults. */\n href(pathname: string, values: Partial<T>): string;\n\n /** Read-only codec map for spreading into .extend(). */\n codecs: { [K in keyof T]: SearchParamCodec<T[K]> };\n\n /** Read-only URL key alias map. Maps property names to URL query parameter keys. */\n readonly urlKeys: Readonly<Record<string, string>>;\n\n /**\n * Phantom property for build-time type extraction.\n * Never set at runtime — exists only in the type system.\n */\n readonly _type?: T;\n}\n\n// StandardSchemaV1 is imported from schema-bridge.ts — single source of truth.\n// Re-export for consumers that import it from this module.\nexport type { StandardSchemaV1 } from '../schema-bridge.ts';\n\n// ---------------------------------------------------------------------------\n// Type-level helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Extract a Standard Schema's declared *input* type from its optional\n * `~standard.types` property (part of the Standard Schema spec; Zod, Valibot,\n * and ArkType all declare it at the type level). Falls back to `never` when\n * the schema doesn't declare types (e.g. hand-written schemas): with no\n * metadata we can't know whether the schema handles `undefined`, so InferField\n * widens conservatively rather than risk a type lie.\n */\ntype InferSchemaInput<V> = V extends { '~standard': { types?: infer TS } }\n ? [NonNullable<TS>] extends [{ input: infer I }]\n ? I\n : never\n : never;\n\n/**\n * Infer the output type from either a SearchParamCodec or a StandardSchemaV1.\n *\n * A codec publishing `parseServerSide` is read through THAT signature, not\n * through `parse` — it is the entry point timber actually calls, and it is\n * the one that tells the truth about absent input. A bare `parseAsString`\n * declares `parse(value: string): string` but answers `null` for a missing\n * param, so the field is `string | null`; `parseAsInteger.withDefault(1)`\n * narrows its own `parseServerSide` to `NonNullable<number>` and the field\n * stays `number`. Reading `parse` instead produced a non-nullable type for\n * a nullable field (TIM-1350).\n *\n * The match is structural, not nuqs-specific: any codec declaring that\n * signature opts into being read through it, which is exactly the contract\n * `parseTotal` applies at runtime. The two must stay in step — a type\n * inferred from `parse` while the runtime calls `parseServerSide` is the\n * lie this branch exists to remove.\n *\n * Schemas whose input type rejects `undefined` (e.g. bare `z.string()`, whose\n * input is `string`) are implicitly optional: the URL might not contain the\n * param, and fromSchema returns `undefined` when the schema rejects absent\n * input and has no default. The output type widens to `T | undefined` so the\n * type doesn't lie. Schemas that accept `undefined` input (`.optional()`,\n * `.default()`) keep their declared output type.\n *\n * Limitation: `z.coerce.*` schemas declare input `unknown`, which accepts\n * `undefined` at the type level — so a coerce schema without `.default()`\n * keeps its narrow output type even though absent input yields `undefined`\n * at runtime. Add `.default()` to coerce schemas for accurate types.\n */\nexport type InferField<V> = V extends {\n parseServerSide(value: string | string[] | undefined): infer R;\n}\n ? R\n : V extends SearchParamCodec<infer T>\n ? T\n : V extends StandardSchemaV1<infer T>\n ? undefined extends InferSchemaInput<V>\n ? T\n : T | undefined\n : never;\n\n/**\n * A codec whose total entry point is `parseServerSide`, even when `parse`\n * has a narrower signature. nuqs multi parsers (`parseAsNativeArrayOf`) have\n * `parse(value: readonly string[])` — too narrow for `SearchParamCodec`'s\n * `parse(string | string[] | undefined)` — but their `parseServerSide`\n * covers the full domain. Timber never calls `parse` directly on these;\n * `parseTotal` always reaches `parseServerSide` first (TIM-1355).\n */\nexport interface TotalSearchParamCodec<T> {\n parseServerSide(value: string | string[] | undefined): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n parse(...args: any[]): any;\n serialize(value: T): string | string[] | null;\n urlKey?: string;\n}\n\n/** Acceptable field value for defineSearchParams: a codec, a total codec, or a Standard Schema. */\nexport type SearchParamField<T = unknown> =\n | SearchParamCodec<T>\n | TotalSearchParamCodec<T>\n | StandardSchemaV1<T>;\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Convert URLSearchParams or a plain record to a normalized record\n * where repeated keys produce arrays.\n */\nfunction normalizeRaw(\n raw: URLSearchParams | Record<string, string | string[] | undefined>\n): Record<string, string | string[] | undefined> {\n if (raw instanceof URLSearchParams) {\n const result: Record<string, string | string[] | undefined> = Object.create(null);\n for (const key of new Set(raw.keys())) {\n const values = raw.getAll(key);\n result[key] = values.length === 1 ? values[0] : values;\n }\n return result;\n }\n return raw;\n}\n\n/**\n * Compute the serialized default value for a codec. Used for\n * default-omission: when serialize(value) === serialize(parse(undefined)),\n * the field is omitted from the URL.\n *\n * Goes through `parseTotal` for the same reason request-time parsing does:\n * a nuqs parser's own `parse` throws on absent input, and this is the\n * absent case by construction.\n *\n * **A codec with no value for an absent param has no default to omit**,\n * and `null` is returned rather than `serialize(null)`. Serializing it\n * makes the \"no value\" case collide with a real one: `parseAsInteger`\n * serializes `null` as the string `'null'`, so `buildSearchParams({ q:\n * 'null' })` would silently drop a legitimate value (before TIM-1350 the\n * absent parse was `undefined` and the swallowed input was the string\n * `'undefined'` — same defect, a less likely input). Nothing is lost:\n * `buildSearchParams` already skips a field whose `serialize` returns\n * `null`, so a codec that encodes \"no value\" as an omission behaves\n * identically, and one that encodes it as a real query value now writes\n * it instead of dropping it.\n *\n * Codecs are documented to return a default rather than throw, but a\n * hand-written codec that throws on absent input must not turn definition\n * into a crash — treat its default as null (nothing to omit). `serialize`\n * is inside the try for the same reason.\n *\n * Typed `SearchParamCodec<unknown>` rather than generic on purpose: the\n * absent-input value is whatever the codec's total entry point returns,\n * which for a nuqs parser is `T | null` while its `serialize` declares\n * `T`. Widening to `unknown` states that honestly instead of casting.\n */\nfunction getDefaultSerialized(codec: SearchParamCodec<unknown>): string | string[] | null {\n try {\n const absent = parseTotal(codec, undefined);\n return absent === null || absent === undefined ? null : codec.serialize(absent);\n } catch {\n return null;\n }\n}\n\n// isStandardSchema and isCodec are imported from schema-bridge.ts.\n\n/**\n * Resolve a field value to a SearchParamCodec. Auto-detects Standard Schema\n * objects and wraps them with fromSchema. Reads .urlKey from codecs.\n *\n * The returned codec is typed as `SearchParamCodec<unknown>` because the\n * codec map uses that type. At runtime, the value may be a `Codec<T>` from\n * `fromSchema` (whose serialize returns `string | null`) or a nuqs parser\n * (whose serialize returns `string | string[] | null`). Both are safe\n * because `buildSearchParams` handles the union.\n */\nfunction resolveField(\n fieldName: string,\n value: SearchParamField\n): { codec: SearchParamCodec<unknown>; urlKey?: string } {\n // Check for codec first (codecs may also have '~standard' if they're nuqs parsers)\n if (isCodec(value)) {\n const urlKey = (value as SearchParamCodec<unknown>).urlKey;\n return { codec: value as SearchParamCodec<unknown>, urlKey };\n }\n\n // Auto-detect Standard Schema. Schemas that reject undefined input and\n // have no default are implicitly optional: fromSchema returns undefined\n // for absent params, and InferField widens the output type to\n // T | undefined. design/23-search-params.md §\"Implicit Optionality\"\n if (isStandardSchema(value)) {\n return { codec: fromSchema(value) as SearchParamCodec<unknown> };\n }\n\n throw new Error(\n `[timber] defineSearchParams: field '${fieldName}' is not a valid codec or Standard Schema. ` +\n `Expected an object with { parse, serialize } methods, or a Standard Schema object ` +\n `(Zod, Valibot, ArkType).`\n );\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Create a SearchParamsDefinition from a map of codecs and/or Standard Schema\n * objects. Accepts both SearchParamCodec values and raw Zod/Valibot/ArkType\n * schemas with auto-detection.\n *\n * ```ts\n * import { defineSearchParams, withDefault, withUrlKey } from '@timber-js/app/search-params'\n * import { parseAsString, parseAsStringEnum } from 'nuqs'\n * import { z } from 'zod/v4'\n *\n * export const searchParams = defineSearchParams({\n * page: z.coerce.number().int().min(1).default(1), // Standard Schema — auto-wrapped\n * q: withUrlKey(parseAsString, 'search'), // nuqs codec with URL alias\n * sort: withDefault(parseAsStringEnum(['price', 'name']), 'price'),\n * })\n * ```\n */\n/**\n * Overload: accept a Standard Schema object schema (e.g., z.object({...})).\n *\n * The schema must have a `.shape` property whose values are themselves\n * Standard Schema objects. Each shape property becomes a field codec\n * via fromSchema().\n *\n * ```ts\n * const searchParams = defineSearchParams(\n * z.object({ page: z.coerce.number().default(1), q: z.string().optional() })\n * )\n * ```\n */\nexport function defineSearchParams<\n S extends StandardSchemaV1<Record<string, unknown>> & {\n shape: Record<string, StandardSchemaV1<unknown>>;\n },\n>(\n schema: S\n): SearchParamsDefinition<{ [K in keyof S['shape'] & string]: InferField<S['shape'][K]> }>;\n\n/**\n * Overload: accept a map of codecs and/or Standard Schema objects.\n */\nexport function defineSearchParams<C extends Record<string, SearchParamField>>(\n codecs: C\n): SearchParamsDefinition<{ [K in keyof C]: InferField<C[K]> }>;\n\nexport function defineSearchParams(\n codecsOrSchema:\n | Record<string, SearchParamField>\n | (StandardSchemaV1<unknown> & { shape: Record<string, StandardSchemaV1<unknown>> })\n): SearchParamsDefinition<Record<string, unknown>> {\n // Detect Standard Schema object with .shape (e.g., z.object(...))\n if (isStandardSchema(codecsOrSchema) && hasShape(codecsOrSchema)) {\n const fieldCodecs: Record<string, SearchParamField> = {};\n for (const [key, fieldSchema] of Object.entries(codecsOrSchema.shape)) {\n if (isStandardSchema(fieldSchema)) {\n fieldCodecs[key] = fieldSchema;\n } else {\n throw new Error(\n `[timber] defineSearchParams: field '${key}' in schema.shape is not a Standard Schema. ` +\n `All shape properties must be Standard Schema objects (Zod, Valibot, ArkType).`\n );\n }\n }\n return defineSearchParamsFromMap(fieldCodecs);\n }\n\n return defineSearchParamsFromMap(codecsOrSchema as Record<string, SearchParamField>);\n}\n\n/** Check if a schema has a .shape property with object-type values. */\nfunction hasShape(schema: unknown): schema is { shape: Record<string, unknown> } {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n 'shape' in schema &&\n typeof (schema as { shape: unknown }).shape === 'object' &&\n (schema as { shape: unknown }).shape !== null\n );\n}\n\nfunction defineSearchParamsFromMap(\n codecs: Record<string, SearchParamField>\n): SearchParamsDefinition<Record<string, unknown>> {\n const resolvedCodecs: Record<string, SearchParamCodec<unknown>> = {};\n const urlKeys: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(codecs)) {\n const resolved = resolveField(key, value as SearchParamField);\n resolvedCodecs[key] = resolved.codec;\n if (resolved.urlKey) {\n urlKeys[key] = resolved.urlKey;\n }\n }\n\n return buildDefinition(resolvedCodecs as unknown as CodecMap<Record<string, unknown>>, urlKeys);\n}\n\n// ---------------------------------------------------------------------------\n// Internal: build the definition object\n// ---------------------------------------------------------------------------\n\n/**\n * Internal: build a SearchParamsDefinition from a typed codec map and url keys.\n */\nfunction buildDefinition<T extends Record<string, unknown>>(\n codecMap: CodecMap<T>,\n urlKeys: Record<string, string>\n): SearchParamsDefinition<T> {\n // Pre-compute default serialized values for omission check\n const defaultSerialized: Record<string, string | string[] | null> = {};\n for (const key of Object.keys(codecMap)) {\n defaultSerialized[key] = getDefaultSerialized(codecMap[key as keyof T]);\n }\n\n function getUrlKey(prop: string): string {\n return urlKeys[prop] ?? prop;\n }\n\n // ---- parse ----\n function parseSync(raw: URLSearchParams | Record<string, string | string[] | undefined>): T {\n const normalized = normalizeRaw(raw);\n const result: Record<string, unknown> = {};\n\n for (const prop of Object.keys(codecMap)) {\n const urlKey = getUrlKey(prop);\n const rawValue = normalized[urlKey];\n result[prop] = parseTotal(codecMap[prop as keyof T] as SearchParamCodec<unknown>, rawValue);\n }\n\n return result as T;\n }\n\n // Overloaded parse: sync when given raw params, async when given a Promise.\n // This enables the ergonomic pattern: await def.parse(searchParams())\n function parse(raw: URLSearchParams | Record<string, string | string[] | undefined>): T;\n function parse(\n raw: Promise<URLSearchParams | Record<string, string | string[] | undefined>>\n ): Promise<T>;\n function parse(\n raw:\n | URLSearchParams\n | Record<string, string | string[] | undefined>\n | Promise<URLSearchParams | Record<string, string | string[] | undefined>>\n ): T | Promise<T> {\n if (raw instanceof Promise) {\n return raw.then(parseSync);\n }\n return parseSync(raw);\n }\n\n // ---- buildSearchParams ----\n //\n // Returns a query string. It used to have a URLSearchParams-returning\n // sibling (`toSearchParams`) that `<Link>` consumed; that shape cannot\n // cross the RSC Flight boundary (see the interface docstring), and having\n // two methods produce the same query two ways was a drift waiting to\n // happen. One method now.\n function buildSearchParams(values: Partial<T>): string {\n const parts: string[] = [];\n\n for (const prop of Object.keys(codecMap)) {\n if (!(prop in values)) continue;\n const codec = codecMap[prop as keyof T] as SearchParamCodec<unknown>;\n\n // TIM-1354: serialize may not be total over null — nuqs parsers like\n // parseAsIsoDate throw TypeError on null (null.toISOString()). Catch\n // TypeError and omit, matching what setParams does on the client.\n // Only TypeError — a deliberate throw (redirect(), notFound()) from a\n // codec's serialize must propagate, not be silently swallowed.\n let serialized: string | string[] | null;\n try {\n serialized = codec.serialize(values[prop as keyof T] as unknown);\n } catch (error) {\n if (error instanceof TypeError) continue;\n throw error;\n }\n\n if (serialized === null) continue;\n // Omit if serialized value matches the default\n if (serializedEqual(serialized, defaultSerialized[prop])) continue;\n\n // TIM-1353: string[] → repeated keys (?tag=a&tag=b)\n const urlKey = encodeURIComponent(getUrlKey(prop));\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n parts.push(`${urlKey}=${encodeURIComponent(entry)}`);\n }\n } else {\n parts.push(`${urlKey}=${encodeURIComponent(serialized)}`);\n }\n }\n\n return parts.join('&');\n }\n\n // ---- href ----\n function href(pathname: string, values: Partial<T>): string {\n const qs = buildSearchParams(values);\n return qs ? `${pathname}?${qs}` : pathname;\n }\n\n // ---- extend ----\n function extend<U extends Record<string, SearchParamField>>(\n newCodecs: U\n ): SearchParamsDefinition<T & { [K in keyof U]: InferField<U[K]> }> {\n type Combined = T & { [K in keyof U]: InferField<U[K]> };\n\n // Resolve any Standard Schema objects in the extension\n const resolvedNewCodecs: Record<string, SearchParamCodec<unknown>> = {};\n const newUrlKeys: Record<string, string> = {};\n for (const [key, value] of Object.entries(newCodecs)) {\n const resolved = resolveField(key, value as SearchParamField);\n resolvedNewCodecs[key] = resolved.codec;\n if (resolved.urlKey) {\n newUrlKeys[key] = resolved.urlKey;\n }\n }\n\n const combinedCodecs = {\n ...codecMap,\n ...resolvedNewCodecs,\n } as unknown as CodecMap<Combined>;\n\n // Merge URL keys: base keys + new codec urlKeys from withUrlKey\n const combinedUrlKeys: Record<string, string> = { ...urlKeys, ...newUrlKeys };\n\n return buildDefinition<Combined>(combinedCodecs, combinedUrlKeys);\n }\n\n // ---- pick ----\n function pick<K extends keyof T & string>(...keys: K[]): SearchParamsDefinition<Pick<T, K>> {\n const pickedCodecs: Record<string, SearchParamCodec<unknown>> = {};\n const pickedUrlKeys: Record<string, string> = {};\n\n for (const key of keys) {\n // Explicit guard — TypeScript prevents this, but JS callers and\n // casts reach here, and \"Cannot read properties of undefined\n // (reading 'serialize')\" is no help (TIM-1066).\n if (!(key in codecMap)) {\n throw new Error(\n `[timber] pick('${key}'): unknown key. ` +\n `Available keys: ${Object.keys(codecMap)\n .map((k) => `'${k}'`)\n .join(', ')}.`\n );\n }\n pickedCodecs[key] = codecMap[key] as SearchParamCodec<unknown>;\n if (key in urlKeys) {\n pickedUrlKeys[key] = urlKeys[key];\n }\n }\n\n return buildDefinition<Pick<T, K>>(\n pickedCodecs as unknown as CodecMap<Pick<T, K>>,\n pickedUrlKeys\n );\n }\n\n // ---- useQueryStates ----\n // Delegates to the 'use client' implementation from use-query-states.ts.\n //\n // In the RSC environment: use-query-states.ts is transformed by the RSC\n // plugin into a client reference proxy. Calling it throws — correct,\n // because hooks can't run during server component rendering.\n // In SSR: use-query-states.ts is the real nuqs-backed function. Hooks\n // work during SSR's renderToReadableStream, so this works correctly.\n // On the client: same as SSR — the real function is available.\n function useQueryStates(options?: QueryStatesOptions): [T, SetParams<T>] {\n return clientUseQueryStates(codecMap, options, Object.freeze({ ...urlKeys })) as [\n T,\n SetParams<T>,\n ];\n }\n\n // ---- get ----\n // ALS-backed: reads getSearchParams() from the current request context\n // and parses through codecs. Server-only, sync.\n function get(): T {\n if (typeof window !== 'undefined') {\n throw new Error(\n '[timber] searchParams.get() is server-only. ' +\n 'Use searchParams.useQueryStates() on the client.'\n );\n }\n const raw = getSearchParamsFromAls();\n return parseSync(raw);\n }\n\n const definition: SearchParamsDefinition<T> = {\n parse,\n get,\n useQueryStates,\n extend,\n pick,\n href,\n buildSearchParams,\n codecs: codecMap,\n urlKeys: Object.freeze({ ...urlKeys }),\n };\n\n return definition;\n}\n","/**\n * Codec wrappers — withDefault and withUrlKey.\n *\n * These are timber-specific utilities that work with any SearchParamCodec.\n * For actual codecs (string, integer, boolean, etc.), use nuqs parsers\n * or Standard Schema objects (Zod, Valibot, ArkType) with auto-detection.\n *\n * Design doc: design/23-search-params.md\n */\n\nimport type {\n InferField,\n SearchParamCodec,\n SearchParamCodecWithUrlKey,\n SearchParamField,\n} from './define.ts';\nimport { isCodec, isStandardSchema, fromSchema } from '../schema-bridge.ts';\nimport { parseTotal } from './parse-total.ts';\n\n// ---------------------------------------------------------------------------\n// withDefault\n// ---------------------------------------------------------------------------\n\n/**\n * Wrap a nullable codec with a default value. The output type becomes\n * non-nullable, and the wrapper is TOTAL over `string | string[] |\n * undefined` even when the inner codec is not.\n *\n * The default is substituted for `null` — the documented \"no value\"\n * answer — and for `undefined`, which is what an implicitly-optional\n * Standard Schema field and a bare `parseAsString` produce for an absent\n * param. Substituting only for `null` left a field typed non-nullable\n * `string` holding `undefined` (TIM-1350).\n *\n * The inner codec is invoked through `parseTotal`, so a nuqs parser gets\n * its own normalization (absent → null, repeated → first value, inner\n * throw → null) before either check applies. That is what makes\n * `withDefault(parseAsBoolean, false)` total; the wrapper itself does NOT\n * catch. A throw from a codec is a deliberate signal — `fromSchema` throws\n * on an async schema, and an app codec may `redirect()` or `notFound()` on\n * a value it refuses — and swallowing it would convert a loud failure into\n * a permanently-default field. design/09 §\"The SearchParamCodec Protocol\":\n * a codec that throws bubbles as a render-phase error, by design.\n *\n * Works with any codec — nuqs parsers, custom codecs, fromSchema results.\n *\n * ```ts\n * import { parseAsInteger } from 'nuqs'\n * import { withDefault } from '@timber-js/app/search-params'\n *\n * const page = withDefault(parseAsInteger, 1)\n * // page.parse(undefined) → 1 (not null)\n * // page.parse('5') → 5\n * ```\n *\n * The signature strips BOTH nullish constituents from the result, not just\n * `null`, because the runtime substitutes for both. An implicitly-optional\n * schema field is a `SearchParamCodec<string | undefined>`, and wrapping it\n * used to yield `SearchParamCodec<string | undefined>` — a field the\n * wrapper guarantees is always present, still typed as maybe-absent.\n */\nexport function withDefault<T>(\n codec: SearchParamCodec<T | null | undefined>,\n defaultValue: NonNullable<T>\n): SearchParamCodec<NonNullable<T>> {\n // A wrapper that rebuilds a codec from two methods drops everything else\n // the codec carries. `withUrlKey` lost `parseServerSide` that way; this\n // one lost `urlKey`, so `withDefault(withUrlKey(parseAsInteger, 'p'), 1)`\n // silently read `?page=` instead of `?p=`. Carry it explicitly rather\n // than spreading: this wrapper's own `parse` IS the total entry point,\n // and re-publishing the inner `parseServerSide` would let `parseTotal`\n // reach past it and skip the default entirely.\n const wrapped: SearchParamCodec<NonNullable<T>> = {\n parse(value: string | string[] | undefined): NonNullable<T> {\n const result = parseTotal(codec, value);\n return result === null || result === undefined ? defaultValue : result;\n },\n serialize(value: NonNullable<T>): string | string[] | null {\n return codec.serialize(value);\n },\n };\n if (codec.urlKey !== undefined) wrapped.urlKey = codec.urlKey;\n return wrapped;\n}\n\n// ---------------------------------------------------------------------------\n// withUrlKey\n// ---------------------------------------------------------------------------\n\n/**\n * Attach a URL key alias to a codec. The alias determines what query\n * parameter key is used in the URL, while the TypeScript property name\n * stays descriptive.\n *\n * Aliases travel with codecs through object spread composition — when\n * you spread a bundle containing aliased codecs into defineSearchParams,\n * the aliases come along automatically.\n *\n * ```ts\n * import { parseAsString } from 'nuqs'\n * import { withUrlKey } from '@timber-js/app/search-params'\n *\n * export const searchable = {\n * q: withUrlKey(parseAsString, 'search'),\n * // ?search=shoes → { q: 'shoes' }\n * }\n * ```\n *\n * Composes with withDefault:\n * ```ts\n * import { parseAsInteger } from 'nuqs'\n * withUrlKey(withDefault(parseAsInteger, 1), 'p')\n * ```\n */\nexport function withUrlKey<F extends SearchParamField>(\n codecOrSchema: F,\n urlKey: string\n): SearchParamCodecWithUrlKey<InferField<F>> {\n type T = InferField<F>;\n // Auto-detect Standard Schema (Zod, Valibot, ArkType) and wrap. Schemas\n // that reject undefined input are implicitly optional — fromSchema returns\n // undefined for absent params, and InferField widens the type to include\n // undefined. design/23-search-params.md §\"Implicit Optionality\"\n const codec: SearchParamCodec<T> = isCodec(codecOrSchema)\n ? (codecOrSchema as SearchParamCodec<T>)\n : isStandardSchema(codecOrSchema)\n ? (fromSchema(codecOrSchema) as SearchParamCodec<T>)\n : (codecOrSchema as SearchParamCodec<T>);\n // Carry the total entry point, bound like the other two methods. A\n // codec's totality lives in a THIRD property, `parseServerSide` (see\n // parse-total.ts); picking only `parse`/`serialize` silently produced a\n // non-total alias, so `withUrlKey(parseAsBoolean, 'b')` threw on an\n // absent param while the bare parser did not (TIM-1350).\n //\n // Bound explicitly rather than spread: a spread copies own enumerable\n // properties only, so a class-based codec — whose `parse` and\n // `serialize` this wrapper already reaches through the prototype —\n // would have kept its methods and lost exactly the one that makes it\n // total. Three properties, one rule, no dependence on how the inner\n // codec was constructed.\n const wrapped: SearchParamCodecWithUrlKey<T> = {\n parse: codec.parse.bind(codec),\n serialize: codec.serialize.bind(codec),\n urlKey,\n };\n if (typeof codec.parseServerSide === 'function') {\n wrapped.parseServerSide = codec.parseServerSide.bind(codec);\n }\n return wrapped;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwRA,SAAS,aACP,KAC+C;CAC/C,IAAI,eAAe,iBAAiB;EAClC,MAAM,SAAwD,OAAO,OAAO,IAAI;EAChF,KAAK,MAAM,OAAO,IAAI,IAAI,IAAI,KAAK,CAAC,GAAG;GACrC,MAAM,SAAS,IAAI,OAAO,GAAG;GAC7B,OAAO,OAAO,OAAO,WAAW,IAAI,OAAO,KAAK;EAClD;EACA,OAAO;CACT;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAS,qBAAqB,OAA4D;CACxF,IAAI;EACF,MAAM,SAAS,WAAW,OAAO,KAAA,CAAS;EAC1C,OAAO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C9B;CACF;CACA,IAAI,MAAM,WAAW,KAAA,GAAW,QAAQ,SAAS,MAAM;CACvD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,WACd,eACA,QAC2C;CAM3C,MAAM,QAA6B,QAAQ,aAAa,IACnD,gBACD,iBAAiB,aAAa,IAC3B,WAAW,aAAa,IACxB;CAaP,MAAM,UAAyC;EAC7C,OAAO,MAAM,MAAM,KAAK,KAAK;EAC7B,WAAW,MAAM,UAAU,KAAK,KAAK;EACrC;CACF;CACA,IAAI,OAAO,MAAM,oBAAoB,YACnC,QAAQ,kBAAkB,MAAM,gBAAgB,KAAK,KAAK;CAE5D,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useQueryStates","clientUseQueryStates"],"sources":["../../src/search-params/define.ts","../../src/search-params/wrappers.ts"],"sourcesContent":["/**\n * defineSearchParams — factory for SearchParamsDefinition<T>.\n *\n * Creates a typed, composable definition for a route's search parameters.\n * Accepts both SearchParamCodec values and Standard Schema objects (Zod,\n * Valibot, ArkType) with auto-detection. Supports URL key aliasing via\n * withUrlKey(), default-omission serialization, and composition via\n * .extend() / .pick().\n *\n * Design doc: design/23-search-params.md §\"defineSearchParams — The Factory\"\n */\n\nimport { useQueryStates as clientUseQueryStates } from '../client/use-query-states.ts';\nimport { fromSchema, isStandardSchema, isCodec } from '../schema-bridge.ts';\nimport type { StandardSchemaV1 } from '../schema-bridge.ts';\nimport type { Codec } from '../codec.ts';\n// Server-only reference for .get() — avoids pulling server ALS into client\n// bundles. In client environments, .get() throws before reaching this code\n// path. The slot lives in its own leaf module so that `request-context.ts`\n// can register the getter without importing this file, which would drag\n// `nuqs` into every server entry (TIM-1298). See shared/als-slots.ts.\nimport { getSearchParamsFromAls } from '../shared/als-slots.ts';\nimport { parseTotal } from './parse-total.ts';\nimport { serializedEqual } from './serialize-equal.ts';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * A codec that converts between URL string values and typed values.\n *\n * `parse` receives the RAW url value: `string | string[] | undefined`.\n * A codec must be TOTAL over that domain — return a default rather than\n * throwing on an absent or repeated param.\n *\n * A codec whose own `parse` covers only a PRESENT, SINGLE-VALUED param\n * may publish `parseServerSide` instead, and timber calls that. nuqs\n * parsers do exactly this, which is how they become total here: absent →\n * `null` (or their `withDefault` value), repeated → the first value, and\n * a throw from the inner parse → `null`. See\n * design/23-search-params.md §'nuqs parsers, made total',\n * `parse-total.ts`, and tests/nuqs-codec-boundary.test.ts (TIM-1350).\n *\n * Standard Schema objects (Zod, Valibot, ArkType) are auto-detected\n * by defineSearchParams and wrapped via fromSchema; those ARE total\n * through `parse` and are called that way.\n */\nexport interface SearchParamCodec<T> extends Omit<Codec<T>, 'serialize'> {\n /**\n * Typed value → URL string(s). Return `null` to omit/clear.\n *\n * A codec MAY return `string[]` to emit repeated keys (`?tag=a&tag=b`).\n * `buildSearchParams` appends one `key=value` entry per array element;\n * the nuqs bridge forwards the array to nuqs, which does the same.\n * Codecs that always produce a single value return a plain string.\n *\n * Wider than `Codec<T>.serialize` (`string | null`) because search params\n * have a repeated-key concept that cookies and segment params do not.\n */\n serialize(value: T): string | string[] | null;\n /** Optional URL key alias, set by withUrlKey(). */\n urlKey?: string;\n /**\n * Optional TOTAL entry point over `string | string[] | undefined`,\n * preferred over `parse` wherever timber invokes a codec. Declared here\n * so the protocol is typed rather than duck-checked at each wrapper:\n * anything that reconstructs a codec has to carry it, and a wrapper\n * cannot carry a property the interface does not admit.\n *\n * It returns `T`, not `T | null`. This is the entry point timber calls,\n * so whatever it returns IS the field's type — admitting a `null` the\n * field type did not carry would let `SearchParamCodec<string>` produce\n * `null` for an absent param under a non-nullable annotation. A codec\n * whose absent-case answer is `null` declares that in `T`, exactly as a\n * bare nuqs parser does: `parseAsString` is a `SearchParamCodec<string |\n * null>` here, never a `SearchParamCodec<string>`.\n *\n * nuqs parser builders satisfy this. See parse-total.ts.\n */\n parseServerSide?(value: string | string[] | undefined): T;\n}\n\n/** A codec with a URL key alias attached via withUrlKey(). */\nexport interface SearchParamCodecWithUrlKey<T> extends SearchParamCodec<T> {\n urlKey: string;\n}\n\n/** Infer the output type of a codec. */\nexport type InferCodec<C> = C extends SearchParamCodec<infer T> ? T : never;\n\n/** Map of property names to codecs. */\nexport type CodecMap<T extends Record<string, unknown>> = {\n [K in keyof T]: SearchParamCodec<T[K]>;\n};\n\n/** Options for useQueryStates setter. */\nexport interface SetParamsOptions {\n /** Update URL without server roundtrip (default: false). */\n shallow?: boolean;\n /** Scroll to top after update (default: true). */\n scroll?: boolean;\n /** 'push' (default) or 'replace' for history state. */\n history?: 'push' | 'replace';\n}\n\n/** Setter function returned by useQueryStates. */\nexport type SetParams<T> = (values: Partial<T>, options?: SetParamsOptions) => void;\n\n/** Options for useQueryStates hook. */\nexport interface QueryStatesOptions {\n /** Update URL without server roundtrip (default: false). */\n shallow?: boolean;\n /** Scroll to top after update (default: true). */\n scroll?: boolean;\n /** 'push' (default) or 'replace' for history state. */\n history?: 'push' | 'replace';\n}\n\n/**\n * A fully typed, composable search params definition.\n *\n * Returned by defineSearchParams(). Carries a phantom _type property\n * for build-time type extraction.\n */\nexport interface SearchParamsDefinition<T extends Record<string, unknown>> {\n /** Parse raw URL search params into typed values. */\n parse(raw: URLSearchParams | Record<string, string | string[] | undefined>): T;\n /** Parse a Promise of URLSearchParams (e.g., from the ALS `searchParams()` API). */\n parse(raw: Promise<URLSearchParams | Record<string, string | string[] | undefined>>): Promise<T>;\n\n /**\n * Get typed search params from the current request context (ALS-backed).\n *\n * Server-only, sync. Reads getSearchParams() from ALS and parses through codecs.\n * Throws on client.\n *\n * ```tsx\n * // app/products/page.tsx\n * import { searchParams } from './search-params'\n * export default function Page() {\n * const { page, category } = searchParams.get()\n * }\n * ```\n */\n get(): T;\n\n /** Client hook — reads current URL params and returns typed values + setter. */\n useQueryStates(options?: QueryStatesOptions): [T, SetParams<T>];\n\n /** Extend with additional codecs or Standard Schema objects. */\n extend<U extends Record<string, SearchParamField>>(\n codecs: U\n ): SearchParamsDefinition<T & { [K in keyof U]: InferField<U[K]> }>;\n\n /** Pick a subset of keys. Preserves codecs and aliases. */\n pick<K extends keyof T & string>(...keys: K[]): SearchParamsDefinition<Pick<T, K>>;\n\n /**\n * Serialize values to a query string (no leading '?'), omitting defaults\n * and applying `withUrlKey` aliases. This is the value to pass to\n * `<Link searchParams={...}>`.\n *\n * Returns a **string**, not a `URLSearchParams`. A `<Link>` prop crosses\n * the RSC Flight boundary, and `URLSearchParams` is iterable — React\n * serializes it as an entries array, which arrives as `[['pg','2'], …]`\n * and renders as `?0=pg&0=2`. A string survives intact.\n */\n buildSearchParams(values: Partial<T>): string;\n\n /** Build a full path with query string, omitting defaults. */\n href(pathname: string, values: Partial<T>): string;\n\n /** Read-only codec map for spreading into .extend(). */\n codecs: { [K in keyof T]: SearchParamCodec<T[K]> };\n\n /** Read-only URL key alias map. Maps property names to URL query parameter keys. */\n readonly urlKeys: Readonly<Record<string, string>>;\n\n /**\n * Phantom property for build-time type extraction.\n * Never set at runtime — exists only in the type system.\n */\n readonly _type?: T;\n}\n\n// StandardSchemaV1 is imported from schema-bridge.ts — single source of truth.\n// Re-export for consumers that import it from this module.\nexport type { StandardSchemaV1 } from '../schema-bridge.ts';\n\n// ---------------------------------------------------------------------------\n// Type-level helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Extract a Standard Schema's declared *input* type from its optional\n * `~standard.types` property (part of the Standard Schema spec; Zod, Valibot,\n * and ArkType all declare it at the type level). Falls back to `never` when\n * the schema doesn't declare types (e.g. hand-written schemas): with no\n * metadata we can't know whether the schema handles `undefined`, so InferField\n * widens conservatively rather than risk a type lie.\n */\ntype InferSchemaInput<V> = V extends { '~standard': { types?: infer TS } }\n ? [NonNullable<TS>] extends [{ input: infer I }]\n ? I\n : never\n : never;\n\n/**\n * Infer the output type from either a SearchParamCodec or a StandardSchemaV1.\n *\n * A codec publishing `parseServerSide` is read through THAT signature, not\n * through `parse` — it is the entry point timber actually calls, and it is\n * the one that tells the truth about absent input. A bare `parseAsString`\n * declares `parse(value: string): string` but answers `null` for a missing\n * param, so the field is `string | null`; `parseAsInteger.withDefault(1)`\n * narrows its own `parseServerSide` to `NonNullable<number>` and the field\n * stays `number`. Reading `parse` instead produced a non-nullable type for\n * a nullable field (TIM-1350).\n *\n * The match is structural, not nuqs-specific: any codec declaring that\n * signature opts into being read through it, which is exactly the contract\n * `parseTotal` applies at runtime. The two must stay in step — a type\n * inferred from `parse` while the runtime calls `parseServerSide` is the\n * lie this branch exists to remove.\n *\n * Schemas whose input type rejects `undefined` (e.g. bare `z.string()`, whose\n * input is `string`) are implicitly optional: the URL might not contain the\n * param, and fromSchema returns `undefined` when the schema rejects absent\n * input and has no default. The output type widens to `T | undefined` so the\n * type doesn't lie. Schemas that accept `undefined` input (`.optional()`,\n * `.default()`) keep their declared output type.\n *\n * Limitation: `z.coerce.*` schemas declare input `unknown`, which accepts\n * `undefined` at the type level — so a coerce schema without `.default()`\n * keeps its narrow output type even though absent input yields `undefined`\n * at runtime. Add `.default()` to coerce schemas for accurate types.\n */\nexport type InferField<V> = V extends {\n parseServerSide(value: string | string[] | undefined): infer R;\n}\n ? R\n : V extends SearchParamCodec<infer T>\n ? T\n : V extends StandardSchemaV1<infer T>\n ? undefined extends InferSchemaInput<V>\n ? T\n : T | undefined\n : never;\n\n/**\n * A codec whose total entry point is `parseServerSide`, even when `parse`\n * has a narrower signature. nuqs multi parsers (`parseAsNativeArrayOf`) have\n * `parse(value: readonly string[])` — too narrow for `SearchParamCodec`'s\n * `parse(string | string[] | undefined)` — but their `parseServerSide`\n * covers the full domain. Timber never calls `parse` directly on these;\n * `parseTotal` always reaches `parseServerSide` first (TIM-1355).\n */\nexport interface TotalSearchParamCodec<T> {\n parseServerSide(value: string | string[] | undefined): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n parse(...args: any[]): any;\n serialize(value: T): string | string[] | null;\n urlKey?: string;\n}\n\n/** Acceptable field value for defineSearchParams: a codec, a total codec, or a Standard Schema. */\nexport type SearchParamField<T = unknown> =\n | SearchParamCodec<T>\n | TotalSearchParamCodec<T>\n | StandardSchemaV1<T>;\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Convert URLSearchParams or a plain record to a normalized record\n * where repeated keys produce arrays.\n */\nfunction normalizeRaw(\n raw: URLSearchParams | Record<string, string | string[] | undefined>\n): Record<string, string | string[] | undefined> {\n if (raw instanceof URLSearchParams) {\n const result: Record<string, string | string[] | undefined> = Object.create(null);\n for (const key of new Set(raw.keys())) {\n const values = raw.getAll(key);\n result[key] = values.length === 1 ? values[0] : values;\n }\n return result;\n }\n return raw;\n}\n\n/**\n * Compute the serialized default value for a codec. Used for\n * default-omission: when serialize(value) === serialize(parse(undefined)),\n * the field is omitted from the URL.\n *\n * Goes through `parseTotal` for the same reason request-time parsing does:\n * a nuqs parser's own `parse` throws on absent input, and this is the\n * absent case by construction.\n *\n * **A codec with no value for an absent param has no default to omit**,\n * and `null` is returned rather than `serialize(null)`. Serializing it\n * makes the \"no value\" case collide with a real one: `parseAsInteger`\n * serializes `null` as the string `'null'`, so `buildSearchParams({ q:\n * 'null' })` would silently drop a legitimate value (before TIM-1350 the\n * absent parse was `undefined` and the swallowed input was the string\n * `'undefined'` — same defect, a less likely input). Nothing is lost:\n * `buildSearchParams` already skips a field whose `serialize` returns\n * `null`, so a codec that encodes \"no value\" as an omission behaves\n * identically, and one that encodes it as a real query value now writes\n * it instead of dropping it.\n *\n * Codecs are documented to return a default rather than throw, but a\n * hand-written codec that throws on absent input must not turn definition\n * into a crash — treat its default as null (nothing to omit). `serialize`\n * is inside the try for the same reason.\n *\n * Typed `SearchParamCodec<unknown>` rather than generic on purpose: the\n * absent-input value is whatever the codec's total entry point returns,\n * which for a nuqs parser is `T | null` while its `serialize` declares\n * `T`. Widening to `unknown` states that honestly instead of casting.\n */\nfunction getDefaultSerialized(codec: SearchParamCodec<unknown>): string | string[] | null {\n try {\n const absent = parseTotal(codec, undefined);\n return absent === null || absent === undefined ? null : codec.serialize(absent);\n } catch {\n return null;\n }\n}\n\n// isStandardSchema and isCodec are imported from schema-bridge.ts.\n\n/**\n * Resolve a field value to a SearchParamCodec. Auto-detects Standard Schema\n * objects and wraps them with fromSchema. Reads .urlKey from codecs.\n *\n * The returned codec is typed as `SearchParamCodec<unknown>` because the\n * codec map uses that type. At runtime, the value may be a `Codec<T>` from\n * `fromSchema` (whose serialize returns `string | null`) or a nuqs parser\n * (whose serialize returns `string | string[] | null`). Both are safe\n * because `buildSearchParams` handles the union.\n */\nfunction resolveField(\n fieldName: string,\n value: SearchParamField\n): { codec: SearchParamCodec<unknown>; urlKey?: string } {\n // Check for codec first (codecs may also have '~standard' if they're nuqs parsers)\n if (isCodec(value)) {\n const urlKey = (value as SearchParamCodec<unknown>).urlKey;\n return { codec: value as SearchParamCodec<unknown>, urlKey };\n }\n\n // Auto-detect Standard Schema. Schemas that reject undefined input and\n // have no default are implicitly optional: fromSchema returns undefined\n // for absent params, and InferField widens the output type to\n // T | undefined. design/23-search-params.md §\"Implicit Optionality\"\n if (isStandardSchema(value)) {\n return { codec: fromSchema(value) as SearchParamCodec<unknown> };\n }\n\n throw new Error(\n `[timber] defineSearchParams: field '${fieldName}' is not a valid codec or Standard Schema. ` +\n `Expected an object with { parse, serialize } methods, or a Standard Schema object ` +\n `(Zod, Valibot, ArkType).`\n );\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Create a SearchParamsDefinition from a map of codecs and/or Standard Schema\n * objects. Accepts both SearchParamCodec values and raw Zod/Valibot/ArkType\n * schemas with auto-detection.\n *\n * ```ts\n * import { defineSearchParams, withDefault, withUrlKey } from '@timber-js/app/search-params'\n * import { parseAsString, parseAsStringEnum } from 'nuqs'\n * import { z } from 'zod/v4'\n *\n * export const searchParams = defineSearchParams({\n * page: z.coerce.number().int().min(1).default(1), // Standard Schema — auto-wrapped\n * q: withUrlKey(parseAsString, 'search'), // nuqs codec with URL alias\n * sort: withDefault(parseAsStringEnum(['price', 'name']), 'price'),\n * })\n * ```\n */\n/**\n * Overload: accept a Standard Schema object schema (e.g., z.object({...})).\n *\n * The schema must have a `.shape` property whose values are themselves\n * Standard Schema objects. Each shape property becomes a field codec\n * via fromSchema().\n *\n * ```ts\n * const searchParams = defineSearchParams(\n * z.object({ page: z.coerce.number().default(1), q: z.string().optional() })\n * )\n * ```\n */\nexport function defineSearchParams<\n S extends StandardSchemaV1<Record<string, unknown>> & {\n shape: Record<string, StandardSchemaV1<unknown>>;\n },\n>(\n schema: S\n): SearchParamsDefinition<{ [K in keyof S['shape'] & string]: InferField<S['shape'][K]> }>;\n\n/**\n * Overload: accept a map of codecs and/or Standard Schema objects.\n */\nexport function defineSearchParams<C extends Record<string, SearchParamField>>(\n codecs: C\n): SearchParamsDefinition<{ [K in keyof C]: InferField<C[K]> }>;\n\nexport function defineSearchParams(\n codecsOrSchema:\n | Record<string, SearchParamField>\n | (StandardSchemaV1<unknown> & { shape: Record<string, StandardSchemaV1<unknown>> })\n): SearchParamsDefinition<Record<string, unknown>> {\n // Detect Standard Schema object with .shape (e.g., z.object(...))\n if (isStandardSchema(codecsOrSchema) && hasShape(codecsOrSchema)) {\n const fieldCodecs: Record<string, SearchParamField> = {};\n for (const [key, fieldSchema] of Object.entries(codecsOrSchema.shape)) {\n if (isStandardSchema(fieldSchema)) {\n fieldCodecs[key] = fieldSchema;\n } else {\n throw new Error(\n `[timber] defineSearchParams: field '${key}' in schema.shape is not a Standard Schema. ` +\n `All shape properties must be Standard Schema objects (Zod, Valibot, ArkType).`\n );\n }\n }\n return defineSearchParamsFromMap(fieldCodecs);\n }\n\n return defineSearchParamsFromMap(codecsOrSchema as Record<string, SearchParamField>);\n}\n\n/** Check if a schema has a .shape property with object-type values. */\nfunction hasShape(schema: unknown): schema is { shape: Record<string, unknown> } {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n 'shape' in schema &&\n typeof (schema as { shape: unknown }).shape === 'object' &&\n (schema as { shape: unknown }).shape !== null\n );\n}\n\nfunction defineSearchParamsFromMap(\n codecs: Record<string, SearchParamField>\n): SearchParamsDefinition<Record<string, unknown>> {\n const resolvedCodecs: Record<string, SearchParamCodec<unknown>> = {};\n const urlKeys: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(codecs)) {\n const resolved = resolveField(key, value as SearchParamField);\n resolvedCodecs[key] = resolved.codec;\n if (resolved.urlKey) {\n urlKeys[key] = resolved.urlKey;\n }\n }\n\n return buildDefinition(resolvedCodecs as unknown as CodecMap<Record<string, unknown>>, urlKeys);\n}\n\n// ---------------------------------------------------------------------------\n// Internal: build the definition object\n// ---------------------------------------------------------------------------\n\n/**\n * Internal: build a SearchParamsDefinition from a typed codec map and url keys.\n */\nfunction buildDefinition<T extends Record<string, unknown>>(\n codecMap: CodecMap<T>,\n urlKeys: Record<string, string>\n): SearchParamsDefinition<T> {\n // Pre-compute default serialized values for omission check\n const defaultSerialized: Record<string, string | string[] | null> = {};\n for (const key of Object.keys(codecMap)) {\n defaultSerialized[key] = getDefaultSerialized(codecMap[key as keyof T]);\n }\n\n function getUrlKey(prop: string): string {\n return urlKeys[prop] ?? prop;\n }\n\n // ---- parse ----\n function parseSync(raw: URLSearchParams | Record<string, string | string[] | undefined>): T {\n const normalized = normalizeRaw(raw);\n const result: Record<string, unknown> = {};\n\n for (const prop of Object.keys(codecMap)) {\n const urlKey = getUrlKey(prop);\n const rawValue = normalized[urlKey];\n result[prop] = parseTotal(codecMap[prop as keyof T] as SearchParamCodec<unknown>, rawValue);\n }\n\n return result as T;\n }\n\n // Overloaded parse: sync when given raw params, async when given a Promise.\n // This enables the ergonomic pattern: await def.parse(searchParams())\n function parse(raw: URLSearchParams | Record<string, string | string[] | undefined>): T;\n function parse(\n raw: Promise<URLSearchParams | Record<string, string | string[] | undefined>>\n ): Promise<T>;\n function parse(\n raw:\n | URLSearchParams\n | Record<string, string | string[] | undefined>\n | Promise<URLSearchParams | Record<string, string | string[] | undefined>>\n ): T | Promise<T> {\n if (raw instanceof Promise) {\n return raw.then(parseSync);\n }\n return parseSync(raw);\n }\n\n // ---- buildSearchParams ----\n //\n // Returns a query string. It used to have a URLSearchParams-returning\n // sibling (`toSearchParams`) that `<Link>` consumed; that shape cannot\n // cross the RSC Flight boundary (see the interface docstring), and having\n // two methods produce the same query two ways was a drift waiting to\n // happen. One method now.\n function buildSearchParams(values: Partial<T>): string {\n const parts: string[] = [];\n\n for (const prop of Object.keys(codecMap)) {\n if (!(prop in values)) continue;\n const codec = codecMap[prop as keyof T] as SearchParamCodec<unknown>;\n\n // TIM-1354: serialize may not be total over null — nuqs parsers like\n // parseAsIsoDate throw TypeError on null (null.toISOString()). Catch\n // TypeError and omit, matching what setParams does on the client.\n // Only TypeError — a deliberate throw (redirect(), notFound()) from a\n // codec's serialize must propagate, not be silently swallowed.\n let serialized: string | string[] | null;\n try {\n serialized = codec.serialize(values[prop as keyof T] as unknown);\n } catch (error) {\n if (error instanceof TypeError) continue;\n throw error;\n }\n\n if (serialized === null) continue;\n // Omit if serialized value matches the default\n if (serializedEqual(serialized, defaultSerialized[prop])) continue;\n\n // TIM-1353: string[] → repeated keys (?tag=a&tag=b)\n const urlKey = encodeURIComponent(getUrlKey(prop));\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n parts.push(`${urlKey}=${encodeURIComponent(entry)}`);\n }\n } else {\n parts.push(`${urlKey}=${encodeURIComponent(serialized)}`);\n }\n }\n\n return parts.join('&');\n }\n\n // ---- href ----\n function href(pathname: string, values: Partial<T>): string {\n const qs = buildSearchParams(values);\n return qs ? `${pathname}?${qs}` : pathname;\n }\n\n // ---- extend ----\n function extend<U extends Record<string, SearchParamField>>(\n newCodecs: U\n ): SearchParamsDefinition<T & { [K in keyof U]: InferField<U[K]> }> {\n type Combined = T & { [K in keyof U]: InferField<U[K]> };\n\n // Resolve any Standard Schema objects in the extension\n const resolvedNewCodecs: Record<string, SearchParamCodec<unknown>> = {};\n const newUrlKeys: Record<string, string> = {};\n for (const [key, value] of Object.entries(newCodecs)) {\n const resolved = resolveField(key, value as SearchParamField);\n resolvedNewCodecs[key] = resolved.codec;\n if (resolved.urlKey) {\n newUrlKeys[key] = resolved.urlKey;\n }\n }\n\n const combinedCodecs = {\n ...codecMap,\n ...resolvedNewCodecs,\n } as unknown as CodecMap<Combined>;\n\n // Merge URL keys: base keys + new codec urlKeys from withUrlKey\n const combinedUrlKeys: Record<string, string> = { ...urlKeys, ...newUrlKeys };\n\n return buildDefinition<Combined>(combinedCodecs, combinedUrlKeys);\n }\n\n // ---- pick ----\n function pick<K extends keyof T & string>(...keys: K[]): SearchParamsDefinition<Pick<T, K>> {\n const pickedCodecs: Record<string, SearchParamCodec<unknown>> = {};\n const pickedUrlKeys: Record<string, string> = {};\n\n for (const key of keys) {\n // Explicit guard — TypeScript prevents this, but JS callers and\n // casts reach here, and \"Cannot read properties of undefined\n // (reading 'serialize')\" is no help (TIM-1066).\n if (!(key in codecMap)) {\n throw new Error(\n `[timber] pick('${key}'): unknown key. ` +\n `Available keys: ${Object.keys(codecMap)\n .map((k) => `'${k}'`)\n .join(', ')}.`\n );\n }\n pickedCodecs[key] = codecMap[key] as SearchParamCodec<unknown>;\n if (key in urlKeys) {\n pickedUrlKeys[key] = urlKeys[key];\n }\n }\n\n return buildDefinition<Pick<T, K>>(\n pickedCodecs as unknown as CodecMap<Pick<T, K>>,\n pickedUrlKeys\n );\n }\n\n // ---- useQueryStates ----\n // Delegates to the 'use client' implementation from use-query-states.ts.\n //\n // In the RSC environment: use-query-states.ts is transformed by the RSC\n // plugin into a client reference proxy. Calling it throws — correct,\n // because hooks can't run during server component rendering.\n // In SSR: use-query-states.ts is the real nuqs-backed function. Hooks\n // work during SSR's renderToReadableStream, so this works correctly.\n // On the client: same as SSR — the real function is available.\n function useQueryStates(options?: QueryStatesOptions): [T, SetParams<T>] {\n return clientUseQueryStates(codecMap, options, Object.freeze({ ...urlKeys })) as [\n T,\n SetParams<T>,\n ];\n }\n\n // ---- get ----\n // ALS-backed: reads getSearchParams() from the current request context\n // and parses through codecs. Server-only, sync.\n function get(): T {\n if (typeof window !== 'undefined') {\n throw new Error(\n '[timber] searchParams.get() is server-only. ' +\n 'Use searchParams.useQueryStates() on the client.'\n );\n }\n const raw = getSearchParamsFromAls();\n return parseSync(raw);\n }\n\n const definition: SearchParamsDefinition<T> = {\n parse,\n get,\n useQueryStates,\n extend,\n pick,\n href,\n buildSearchParams,\n codecs: codecMap,\n urlKeys: Object.freeze({ ...urlKeys }),\n };\n\n return definition;\n}\n","/**\n * Codec wrappers — withDefault and withUrlKey.\n *\n * These are timber-specific utilities that work with any SearchParamCodec.\n * For actual codecs (string, integer, boolean, etc.), use nuqs parsers\n * or Standard Schema objects (Zod, Valibot, ArkType) with auto-detection.\n *\n * Design doc: design/23-search-params.md\n */\n\nimport type {\n InferField,\n SearchParamCodec,\n SearchParamCodecWithUrlKey,\n SearchParamField,\n} from './define.ts';\nimport { isCodec, isStandardSchema, fromSchema } from '../schema-bridge.ts';\nimport { parseTotal } from './parse-total.ts';\n\n// ---------------------------------------------------------------------------\n// withDefault\n// ---------------------------------------------------------------------------\n\n/**\n * Wrap a nullable codec with a default value. The output type becomes\n * non-nullable, and the wrapper is TOTAL over `string | string[] |\n * undefined` even when the inner codec is not.\n *\n * The default is substituted for `null` — the documented \"no value\"\n * answer — and for `undefined`, which is what an implicitly-optional\n * Standard Schema field and a bare `parseAsString` produce for an absent\n * param. Substituting only for `null` left a field typed non-nullable\n * `string` holding `undefined` (TIM-1350).\n *\n * The inner codec is invoked through `parseTotal`, so a nuqs parser gets\n * its own normalization (absent → null, repeated → first value, inner\n * throw → null) before either check applies. That is what makes\n * `withDefault(parseAsBoolean, false)` total; the wrapper itself does NOT\n * catch. A throw from a codec is a deliberate signal — `fromSchema` throws\n * on an async schema, and an app codec may `redirect()` or `notFound()` on\n * a value it refuses — and swallowing it would convert a loud failure into\n * a permanently-default field. design/09 §\"The SearchParamCodec Protocol\":\n * a codec that throws bubbles as a render-phase error, by design.\n *\n * Works with any codec — nuqs parsers, custom codecs, fromSchema results.\n *\n * ```ts\n * import { parseAsInteger } from 'nuqs'\n * import { withDefault } from '@timber-js/app/search-params'\n *\n * const page = withDefault(parseAsInteger, 1)\n * // page.parse(undefined) → 1 (not null)\n * // page.parse('5') → 5\n * ```\n *\n * The signature strips BOTH nullish constituents from the result, not just\n * `null`, because the runtime substitutes for both. An implicitly-optional\n * schema field is a `SearchParamCodec<string | undefined>`, and wrapping it\n * used to yield `SearchParamCodec<string | undefined>` — a field the\n * wrapper guarantees is always present, still typed as maybe-absent.\n */\nexport function withDefault<T>(\n codec: SearchParamCodec<T | null | undefined>,\n defaultValue: NonNullable<T>\n): SearchParamCodec<NonNullable<T>> {\n // A wrapper that rebuilds a codec from two methods drops everything else\n // the codec carries. `withUrlKey` lost `parseServerSide` that way; this\n // one lost `urlKey`, so `withDefault(withUrlKey(parseAsInteger, 'p'), 1)`\n // silently read `?page=` instead of `?p=`. Carry it explicitly rather\n // than spreading: this wrapper's own `parse` IS the total entry point,\n // and re-publishing the inner `parseServerSide` would let `parseTotal`\n // reach past it and skip the default entirely.\n const wrapped: SearchParamCodec<NonNullable<T>> = {\n parse(value: string | string[] | undefined): NonNullable<T> {\n const result = parseTotal(codec, value);\n return result === null || result === undefined ? defaultValue : result;\n },\n serialize(value: NonNullable<T>): string | string[] | null {\n return codec.serialize(value);\n },\n };\n if (codec.urlKey !== undefined) wrapped.urlKey = codec.urlKey;\n return wrapped;\n}\n\n// ---------------------------------------------------------------------------\n// withUrlKey\n// ---------------------------------------------------------------------------\n\n/**\n * Attach a URL key alias to a codec. The alias determines what query\n * parameter key is used in the URL, while the TypeScript property name\n * stays descriptive.\n *\n * Aliases travel with codecs through object spread composition — when\n * you spread a bundle containing aliased codecs into defineSearchParams,\n * the aliases come along automatically.\n *\n * ```ts\n * import { parseAsString } from 'nuqs'\n * import { withUrlKey } from '@timber-js/app/search-params'\n *\n * export const searchable = {\n * q: withUrlKey(parseAsString, 'search'),\n * // ?search=shoes → { q: 'shoes' }\n * }\n * ```\n *\n * Composes with withDefault:\n * ```ts\n * import { parseAsInteger } from 'nuqs'\n * withUrlKey(withDefault(parseAsInteger, 1), 'p')\n * ```\n */\nexport function withUrlKey<F extends SearchParamField>(\n codecOrSchema: F,\n urlKey: string\n): SearchParamCodecWithUrlKey<InferField<F>> {\n type T = InferField<F>;\n // Auto-detect Standard Schema (Zod, Valibot, ArkType) and wrap. Schemas\n // that reject undefined input are implicitly optional — fromSchema returns\n // undefined for absent params, and InferField widens the type to include\n // undefined. design/23-search-params.md §\"Implicit Optionality\"\n const codec: SearchParamCodec<T> = isCodec(codecOrSchema)\n ? (codecOrSchema as SearchParamCodec<T>)\n : isStandardSchema(codecOrSchema)\n ? (fromSchema(codecOrSchema) as SearchParamCodec<T>)\n : (codecOrSchema as SearchParamCodec<T>);\n // Carry the total entry point, bound like the other two methods. A\n // codec's totality lives in a THIRD property, `parseServerSide` (see\n // parse-total.ts); picking only `parse`/`serialize` silently produced a\n // non-total alias, so `withUrlKey(parseAsBoolean, 'b')` threw on an\n // absent param while the bare parser did not (TIM-1350).\n //\n // Bound explicitly rather than spread: a spread copies own enumerable\n // properties only, so a class-based codec — whose `parse` and\n // `serialize` this wrapper already reaches through the prototype —\n // would have kept its methods and lost exactly the one that makes it\n // total. Three properties, one rule, no dependence on how the inner\n // codec was constructed.\n const wrapped: SearchParamCodecWithUrlKey<T> = {\n parse: codec.parse.bind(codec),\n serialize: codec.serialize.bind(codec),\n urlKey,\n };\n if (typeof codec.parseServerSide === 'function') {\n wrapped.parseServerSide = codec.parseServerSide.bind(codec);\n }\n return wrapped;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwRA,SAAS,aACP,KAC+C;CAC/C,IAAI,eAAe,iBAAiB;EAClC,MAAM,SAAwD,OAAO,OAAO,IAAI;EAChF,KAAK,MAAM,OAAO,IAAI,IAAI,IAAI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CAGhC;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvmBA,SAAgB,YACd,OACA,cACkC;CAQlC,MAAM,UAA4C;EAChD,MAAM,OAAsD;GAC1D,MAAM,SAAS,WAAW,OAAO,KAAK;GACtC,OAAO,WAAW,QAAQ,WAAW,KAAA,IAAY,eAAe;EAClE;EACA,UAAU,OAAiD;GACzD,OAAO,MAAM,UAAU,KAAK;EAC9B;CACF;CACA,IAAI,MAAM,WAAW,KAAA,GAAW,QAAQ,SAAS,MAAM;CACvD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,WACd,eACA,QAC2C;CAM3C,MAAM,QAA6B,QAAQ,aAAa,IACnD,gBACD,iBAAiB,aAAa,IAC3B,WAAW,aAAa,IACxB;CAaP,MAAM,UAAyC;EAC7C,OAAO,MAAM,MAAM,KAAK,KAAK;EAC7B,WAAW,MAAM,UAAU,KAAK,KAAK;EACrC;CACF;CACA,IAAI,OAAO,MAAM,oBAAoB,YACnC,QAAQ,kBAAkB,MAAM,gBAAgB,KAAK,KAAK;CAE5D,OAAO;AACT"}
|
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
* 1. Direct call: action(input) → Promise<ActionResult>
|
|
9
9
|
* 2. React useActionState: (prevState, formData) => Promise<ActionResult>
|
|
10
10
|
*
|
|
11
|
+
* Types live in `action-types.ts`, schema handling in `action-schema.ts`, and
|
|
12
|
+
* the schema's declared shape (list fields, sensitive fields) in
|
|
13
|
+
* `schema-introspection.ts`.
|
|
14
|
+
*
|
|
11
15
|
* See design/08-forms-and-actions.md §"Middleware and Server Actions"
|
|
12
16
|
*/
|
|
17
|
+
import { type SensitiveFieldsOption } from './sensitive-fields.ts';
|
|
18
|
+
import type { ActionBuilder, ActionMiddleware, ActionServerError } from './action-types.ts';
|
|
13
19
|
/**
|
|
14
20
|
* Typed error class for server actions. Carries a string code and optional data.
|
|
15
21
|
* When thrown from middleware or the action body, the action short-circuits and
|
|
@@ -23,164 +29,19 @@ export declare class ActionError<TCode extends string = string> extends Error {
|
|
|
23
29
|
readonly data: Record<string, unknown> | undefined;
|
|
24
30
|
constructor(code: TCode, data?: Record<string, unknown>);
|
|
25
31
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Standard Schema v1 interface (subset).
|
|
28
|
-
* Zod ≥3.24, Valibot ≥1.0, and ArkType all implement this.
|
|
29
|
-
* See https://github.com/standard-schema/standard-schema
|
|
30
|
-
*
|
|
31
|
-
* We use permissive types here to accept all compliant libraries without
|
|
32
|
-
* requiring exact structural matches on issues/path shapes.
|
|
33
|
-
*/
|
|
34
|
-
interface StandardSchemaV1<Output = unknown> {
|
|
35
|
-
readonly '~standard': {
|
|
36
|
-
readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
type StandardSchemaResult<Output> = {
|
|
40
|
-
value: Output;
|
|
41
|
-
issues?: undefined;
|
|
42
|
-
} | {
|
|
43
|
-
value?: undefined;
|
|
44
|
-
issues: ReadonlyArray<StandardSchemaIssue>;
|
|
45
|
-
};
|
|
46
|
-
interface StandardSchemaIssue {
|
|
47
|
-
message: string;
|
|
48
|
-
path?: ReadonlyArray<PropertyKey | {
|
|
49
|
-
key: PropertyKey;
|
|
50
|
-
}>;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Minimal schema interface — compatible with Zod, Valibot, ArkType, etc.
|
|
54
|
-
*
|
|
55
|
-
* Accepts either:
|
|
56
|
-
* - Standard Schema (preferred): any object with `~standard.validate()`
|
|
57
|
-
* - Legacy parse interface: objects with `.parse()` / `.safeParse()`
|
|
58
|
-
*
|
|
59
|
-
* At runtime, Standard Schema is detected via `~standard` property and
|
|
60
|
-
* takes priority over the legacy interface.
|
|
61
|
-
*/
|
|
62
|
-
export type ActionSchema<T = unknown> = StandardSchemaV1<T> | LegacyActionSchema<T>;
|
|
63
|
-
/** Legacy schema interface with .parse() / .safeParse(). */
|
|
64
|
-
interface LegacyActionSchema<T = unknown> {
|
|
65
|
-
'parse'(data: unknown): T;
|
|
66
|
-
'safeParse'?(data: unknown): {
|
|
67
|
-
success: true;
|
|
68
|
-
data: T;
|
|
69
|
-
} | {
|
|
70
|
-
success: false;
|
|
71
|
-
error: SchemaError;
|
|
72
|
-
};
|
|
73
|
-
'~standard'?: never;
|
|
74
|
-
}
|
|
75
|
-
/** Schema validation error shape (for legacy .safeParse()/.parse() interface). */
|
|
76
|
-
export interface SchemaError {
|
|
77
|
-
issues?: Array<{
|
|
78
|
-
path?: Array<string | number>;
|
|
79
|
-
message: string;
|
|
80
|
-
}>;
|
|
81
|
-
flatten?(): {
|
|
82
|
-
fieldErrors: Record<string, string[]>;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/** Flattened validation errors keyed by field name. */
|
|
86
|
-
export type ValidationErrors = Record<string, string[]>;
|
|
87
|
-
/** Middleware function: returns context to merge into the action body's ctx. */
|
|
88
|
-
export type ActionMiddleware<TCtx = Record<string, unknown>> = () => Promise<TCtx> | TCtx;
|
|
89
|
-
/** The result type returned to the client. */
|
|
90
|
-
export type ActionResult<TData = unknown> = {
|
|
91
|
-
data: TData;
|
|
92
|
-
validationErrors?: never;
|
|
93
|
-
serverError?: never;
|
|
94
|
-
submittedValues?: never;
|
|
95
|
-
} | {
|
|
96
|
-
data?: never;
|
|
97
|
-
validationErrors: ValidationErrors;
|
|
98
|
-
serverError?: never;
|
|
99
|
-
/** Raw input values on validation failure — for repopulating form fields. */
|
|
100
|
-
submittedValues?: Record<string, unknown>;
|
|
101
|
-
} | {
|
|
102
|
-
data?: never;
|
|
103
|
-
validationErrors?: never;
|
|
104
|
-
serverError: {
|
|
105
|
-
code: string;
|
|
106
|
-
data?: Record<string, unknown>;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* The submitted form, when the input was FormData — for repopulating
|
|
110
|
-
* form fields, which React resets after the action (TIM-1573).
|
|
111
|
-
*/
|
|
112
|
-
submittedValues?: Record<string, unknown>;
|
|
113
|
-
};
|
|
114
|
-
/** Context passed to the action body. */
|
|
115
|
-
export interface ActionContext<TCtx, TInput> {
|
|
116
|
-
ctx: TCtx;
|
|
117
|
-
input: TInput;
|
|
118
|
-
}
|
|
119
32
|
interface ActionClientConfig<TCtx> {
|
|
120
33
|
middleware?: ActionMiddleware<TCtx> | ActionMiddleware<Record<string, unknown>>[];
|
|
121
34
|
/** Max file size in bytes. Files exceeding this are rejected with validation errors. */
|
|
122
35
|
fileSizeLimit?: number;
|
|
123
36
|
/**
|
|
124
|
-
* Override the sensitive-field deny-list for this action client.
|
|
125
|
-
* See `SensitiveFieldsOption` in `./sensitive-fields.ts`. Per-
|
|
37
|
+
* Override the sensitive-field name deny-list for this action client.
|
|
38
|
+
* See `SensitiveFieldsOption` in `./sensitive-fields.ts`. Per-client config
|
|
126
39
|
* takes precedence over the global `forms.stripSensitiveFields` option in
|
|
127
|
-
* `timber.config.ts`.
|
|
40
|
+
* `timber.config.ts`. Fields the schema marks `.meta({ sensitive: true })`
|
|
41
|
+
* are stripped whatever this says. See design/08-forms-and-actions.md.
|
|
128
42
|
*/
|
|
129
43
|
stripSensitiveFields?: SensitiveFieldsOption;
|
|
130
44
|
}
|
|
131
|
-
/** Intermediate builder returned by createActionClient(). */
|
|
132
|
-
export interface ActionBuilder<TCtx> {
|
|
133
|
-
/** Declare the input schema. Validation errors are returned typed. */
|
|
134
|
-
schema<TInput>(schema: ActionSchema<TInput>): ActionBuilderWithSchema<TCtx, TInput>;
|
|
135
|
-
/** Define the action body without input validation. */
|
|
136
|
-
action<TData>(fn: (ctx: ActionContext<TCtx, undefined>) => Promise<TData>): ActionFn<TData, undefined>;
|
|
137
|
-
}
|
|
138
|
-
/** Builder after .schema() has been called. */
|
|
139
|
-
export interface ActionBuilderWithSchema<TCtx, TInput> {
|
|
140
|
-
/** Define the action body with validated input. */
|
|
141
|
-
action<TData>(fn: (ctx: ActionContext<TCtx, TInput>) => Promise<TData>): ActionFn<TData, TInput>;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* The final action function. Callable three ways:
|
|
145
|
-
* - Direct: action(input) → Promise<ActionResult<TData>>
|
|
146
|
-
* - React useActionState: action(prevState, payload) → Promise<ActionResult<TData>>,
|
|
147
|
-
* where payload is the submitted FormData or the value dispatch was called with
|
|
148
|
-
* - React <form action={fn}>: action(formData) → void (return value ignored by React)
|
|
149
|
-
*
|
|
150
|
-
* The third overload exists purely for type compatibility with React's
|
|
151
|
-
* `<form action>` prop, which expects `(formData: FormData) => void`.
|
|
152
|
-
* At runtime the function still returns Promise<ActionResult>, but React
|
|
153
|
-
* discards it. This lets validated actions be passed directly to forms
|
|
154
|
-
* without casts.
|
|
155
|
-
*/
|
|
156
|
-
/**
|
|
157
|
-
* Map schema output keys to `string | undefined` for form-facing APIs.
|
|
158
|
-
* HTML form values are always strings, and fields can be absent.
|
|
159
|
-
* Gives autocomplete for field names without lying about value types.
|
|
160
|
-
*/
|
|
161
|
-
export type InputHint<T> = T extends Record<string, unknown> ? {
|
|
162
|
-
[K in keyof T]: string | undefined;
|
|
163
|
-
} : T;
|
|
164
|
-
/**
|
|
165
|
-
* ActionFn — the callable returned by `createActionClient().action()`.
|
|
166
|
-
*
|
|
167
|
-
* Generic order: `<TData, TInput>` — TData first for backward compatibility.
|
|
168
|
-
* Previously ActionFn had a single `<TData>` generic, so existing code like
|
|
169
|
-
* `ActionFn<MyResult>` must still work with TData in the first position.
|
|
170
|
-
* See TIM-797.
|
|
171
|
-
*/
|
|
172
|
-
export type ActionFn<TData = unknown, TInput = unknown> = {
|
|
173
|
-
/** <form action={fn}> compatibility — React discards the return value. */
|
|
174
|
-
(formData: FormData): void;
|
|
175
|
-
/** Direct call: action(input) — optional when TInput is undefined/unknown (no-schema actions). */
|
|
176
|
-
(...args: undefined extends TInput ? [input?: TInput] : [input: TInput]): Promise<ActionResult<TData>>;
|
|
177
|
-
/**
|
|
178
|
-
* React useActionState: action(prevState, payload). The payload is the
|
|
179
|
-
* submitted FormData, or whatever the hook's dispatch was called with.
|
|
180
|
-
*/
|
|
181
|
-
(prevState: ActionResult<TData> | null, payload: TInput | FormData): Promise<ActionResult<TData>>;
|
|
182
|
-
};
|
|
183
|
-
import { type SensitiveFieldsOption } from './sensitive-fields.ts';
|
|
184
45
|
/**
|
|
185
46
|
* Wrap unexpected errors into a safe server error result.
|
|
186
47
|
* ActionError → typed result. Other errors → INTERNAL_ERROR (no leak).
|
|
@@ -189,10 +50,7 @@ import { type SensitiveFieldsOption } from './sensitive-fields.ts';
|
|
|
189
50
|
* throws is rejected on the client instead (action-handler.ts).
|
|
190
51
|
*/
|
|
191
52
|
export declare function handleActionError(error: unknown): {
|
|
192
|
-
serverError:
|
|
193
|
-
code: string;
|
|
194
|
-
data?: Record<string, unknown>;
|
|
195
|
-
};
|
|
53
|
+
serverError: ActionServerError;
|
|
196
54
|
};
|
|
197
55
|
/**
|
|
198
56
|
* Create a typed action client with middleware and schema validation.
|
|
@@ -215,24 +73,5 @@ export declare function handleActionError(error: unknown): {
|
|
|
215
73
|
* ```
|
|
216
74
|
*/
|
|
217
75
|
export declare function createActionClient<TCtx = Record<string, never>>(config?: ActionClientConfig<TCtx>): ActionBuilder<TCtx>;
|
|
218
|
-
/**
|
|
219
|
-
* Convenience wrapper for the common case: validate input, run handler.
|
|
220
|
-
* No middleware needed.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* 'use server'
|
|
225
|
-
* import { validated } from '@timber-js/app/server'
|
|
226
|
-
* import { z } from 'zod'
|
|
227
|
-
*
|
|
228
|
-
* export const createTodo = validated(
|
|
229
|
-
* z.object({ title: z.string().min(1) }),
|
|
230
|
-
* async (input) => {
|
|
231
|
-
* await db.todos.create(input)
|
|
232
|
-
* }
|
|
233
|
-
* )
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
export declare function validated<TInput, TData>(schema: ActionSchema<TInput>, handler: (input: TInput) => Promise<TData>): ActionFn<TData, TInput>;
|
|
237
76
|
export {};
|
|
238
77
|
//# sourceMappingURL=action-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-client.d.ts","sourceRoot":"","sources":["../../src/server/action-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"action-client.d.ts","sourceRoot":"","sources":["../../src/server/action-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,KAAK,EACV,aAAa,EAGb,gBAAgB,EAEhB,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;GAOG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;IACnE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAEnD,YAAY,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAKtD;CACF;AAID,UAAU,kBAAkB,CAAC,IAAI;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAClF,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,qBAAqB,CAAC;CAC9C;AA0BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,WAAW,EAAE,iBAAiB,CAAA;CAAE,CAqBpF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC7D,MAAM,GAAE,kBAAkB,CAAC,IAAI,CAAM,GACpC,aAAa,CAAC,IAAI,CAAC,CA2HrB"}
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
import { type CsrfConfig } from './csrf.ts';
|
|
17
17
|
import { type RevalidateRenderer } from './actions.ts';
|
|
18
18
|
import { type BodyLimitsConfig } from './body-limits.ts';
|
|
19
|
-
import { type SensitiveFieldsOption } from './sensitive-fields.ts';
|
|
20
19
|
import type { ReactFormState } from 'react-dom/client';
|
|
21
20
|
/** Configuration for the action handler. */
|
|
22
21
|
export interface ActionDispatchConfig {
|
|
@@ -26,12 +25,6 @@ export interface ActionDispatchConfig {
|
|
|
26
25
|
revalidateRenderer?: RevalidateRenderer;
|
|
27
26
|
/** Body size limits (from timber.config.ts). */
|
|
28
27
|
bodyLimits?: BodyLimitsConfig;
|
|
29
|
-
/**
|
|
30
|
-
* Override the sensitive-field deny-list for the no-JS form POST path.
|
|
31
|
-
* Defaults to the global `forms.stripSensitiveFields` from `timber.config.ts`.
|
|
32
|
-
* See `SensitiveFieldsOption` in `./sensitive-fields.ts` and TIM-816.
|
|
33
|
-
*/
|
|
34
|
-
sensitiveFields?: SensitiveFieldsOption;
|
|
35
28
|
}
|
|
36
29
|
/**
|
|
37
30
|
* Check if a request is a server action invocation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-handler.d.ts","sourceRoot":"","sources":["../../src/server/action-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,OAAO,EAAuC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKtE,OAAO,EAAwC,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"action-handler.d.ts","sourceRoot":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@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action input schemas — the Standard Schema protocol (and the legacy
|
|
3
|
+
* `.parse()` interface) as `createActionClient().schema()` accepts them, the
|
|
4
|
+
* input/output types they carry, and running one against an action's input.
|
|
5
|
+
*
|
|
6
|
+
* See design/08-forms-and-actions.md §"Validation Pattern"
|
|
7
|
+
*/
|
|
8
|
+
import type { ValidationErrors } from './action-types.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Standard Schema v1 interface (subset).
|
|
11
|
+
* Zod ≥3.24, Valibot ≥1.0, and ArkType all implement this.
|
|
12
|
+
* See https://github.com/standard-schema/standard-schema
|
|
13
|
+
*
|
|
14
|
+
* `types` is the protocol's type-only carrier: a schema's input type (what a
|
|
15
|
+
* caller passes, before coercion) and output type (what validation produces).
|
|
16
|
+
* We use permissive types for issues and paths to accept all compliant
|
|
17
|
+
* libraries without requiring exact structural matches on their shapes.
|
|
18
|
+
*/
|
|
19
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
20
|
+
readonly '~standard': {
|
|
21
|
+
readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
22
|
+
readonly types?: {
|
|
23
|
+
readonly input: Input;
|
|
24
|
+
readonly output: Output;
|
|
25
|
+
} | undefined;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
type StandardSchemaResult<Output> = {
|
|
29
|
+
value: Output;
|
|
30
|
+
issues?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
value?: undefined;
|
|
33
|
+
issues: ReadonlyArray<StandardSchemaIssue>;
|
|
34
|
+
};
|
|
35
|
+
interface StandardSchemaIssue {
|
|
36
|
+
message: string;
|
|
37
|
+
path?: ReadonlyArray<PropertyKey | {
|
|
38
|
+
key: PropertyKey;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
/** Check if a schema implements the Standard Schema protocol. */
|
|
42
|
+
export declare function isStandardSchema(schema: unknown): schema is StandardSchemaV1;
|
|
43
|
+
/**
|
|
44
|
+
* Minimal schema interface — compatible with Zod, Valibot, ArkType, etc.
|
|
45
|
+
*
|
|
46
|
+
* Accepts either:
|
|
47
|
+
* - Standard Schema (preferred): any object with `~standard.validate()`
|
|
48
|
+
* - Legacy parse interface: objects with `.parse()` / `.safeParse()`
|
|
49
|
+
*
|
|
50
|
+
* At runtime, Standard Schema is detected via `~standard` property and
|
|
51
|
+
* takes priority over the legacy interface.
|
|
52
|
+
*/
|
|
53
|
+
export type ActionSchema<T = unknown> = StandardSchemaV1<unknown, T> | LegacyActionSchema<T>;
|
|
54
|
+
/** Legacy schema interface with .parse() / .safeParse(). */
|
|
55
|
+
interface LegacyActionSchema<T = unknown> {
|
|
56
|
+
'parse'(data: unknown): T;
|
|
57
|
+
'safeParse'?(data: unknown): {
|
|
58
|
+
success: true;
|
|
59
|
+
data: T;
|
|
60
|
+
} | {
|
|
61
|
+
success: false;
|
|
62
|
+
error: SchemaError;
|
|
63
|
+
};
|
|
64
|
+
'~standard'?: never;
|
|
65
|
+
}
|
|
66
|
+
/** Schema validation error shape (for legacy .safeParse()/.parse() interface). */
|
|
67
|
+
export interface SchemaError {
|
|
68
|
+
issues?: Array<{
|
|
69
|
+
path?: Array<string | number>;
|
|
70
|
+
message: string;
|
|
71
|
+
}>;
|
|
72
|
+
flatten?(): {
|
|
73
|
+
fieldErrors: Record<string, string[]>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* What a validated action's body receives: the schema's output, after
|
|
78
|
+
* coercion and defaults.
|
|
79
|
+
*/
|
|
80
|
+
export type SchemaOutput<S> = S extends {
|
|
81
|
+
readonly '~standard': infer Std;
|
|
82
|
+
} ? DeclaredType<Std, 'output', ValidatedValue<S>> : S extends LegacyActionSchema<infer T> ? T : never;
|
|
83
|
+
/**
|
|
84
|
+
* The value a Standard Schema's `validate` produces on success, for a schema
|
|
85
|
+
* that declares no `types`. Only the success branch has a required `value`.
|
|
86
|
+
*/
|
|
87
|
+
type ValidatedValue<S> = S extends {
|
|
88
|
+
readonly '~standard': {
|
|
89
|
+
readonly validate: (value: unknown) => infer R;
|
|
90
|
+
};
|
|
91
|
+
} ? SuccessValue<Awaited<R>> : never;
|
|
92
|
+
/** Distributes over the result union, keeping the members with a value. */
|
|
93
|
+
type SuccessValue<R> = R extends {
|
|
94
|
+
value: infer O;
|
|
95
|
+
} ? O : never;
|
|
96
|
+
/**
|
|
97
|
+
* What a caller passes a validated action: the schema's input, before
|
|
98
|
+
* coercion. A schema that declares no `types` (a hand-written Standard
|
|
99
|
+
* Schema, a legacy `.parse()` schema) has one type for both.
|
|
100
|
+
*/
|
|
101
|
+
export type SchemaInput<S> = S extends {
|
|
102
|
+
readonly '~standard': infer Std;
|
|
103
|
+
} ? DeclaredType<Std, 'input', SchemaOutput<S>> : SchemaOutput<S>;
|
|
104
|
+
/**
|
|
105
|
+
* `Std.types[K]` when the schema declares `types` (Zod, Valibot, ArkType do),
|
|
106
|
+
* else `Fallback`. Read by key, because `types` is optional in the protocol.
|
|
107
|
+
*/
|
|
108
|
+
type DeclaredType<Std, K extends 'input' | 'output', Fallback> = 'types' extends keyof Std ? NonNullable<Std['types' & keyof Std]> extends {
|
|
109
|
+
readonly [P in K]: infer T;
|
|
110
|
+
} ? T : Fallback : Fallback;
|
|
111
|
+
/** The outcome of running an action's schema over its input. */
|
|
112
|
+
export type SchemaValidation<T> = {
|
|
113
|
+
ok: true;
|
|
114
|
+
value: T;
|
|
115
|
+
} | {
|
|
116
|
+
ok: false;
|
|
117
|
+
validationErrors: ValidationErrors;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Validate `input` with `schema`, through Standard Schema when the schema
|
|
121
|
+
* implements it, and through `.safeParse()` / `.parse()` otherwise. Only
|
|
122
|
+
* synchronous Standard Schema validation is supported.
|
|
123
|
+
*/
|
|
124
|
+
export declare function validateWithSchema<T>(schema: ActionSchema<T>, input: unknown): SchemaValidation<T>;
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=action-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-schema.d.ts","sourceRoot":"","sources":["../../src/server/action-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAI1D;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,QAAQ,CAAC,WAAW,EAAE;QACpB,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,OAAO,KACX,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE;YAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;YAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAC;KACjF,CAAC;CACH;AAED,KAAK,oBAAoB,CAAC,MAAM,IAC5B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,GACrC;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;CAAE,CAAC;AAEtE,UAAU,mBAAmB;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,aAAa,CAAC,WAAW,GAAG;QAAE,GAAG,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;CAC1D;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,gBAAgB,CAO5E;AAID;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,IAAI,gBAAgB,CAAC,OAAO,EAAE,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