attaform 0.23.0 → 0.24.0
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/README.md +1 -1
- package/dist/chunks/devtools.cjs +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/chunks/fingerprint2.cjs +1 -1
- package/dist/chunks/fingerprint2.mjs +1 -1
- package/dist/index.cjs +3 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -132
- package/dist/index.d.mts +6 -132
- package/dist/index.d.ts +6 -132
- package/dist/index.mjs +4 -150
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +2 -2
- package/dist/runtime/plugins/attaform.cjs +2 -2
- package/dist/runtime/plugins/attaform.mjs +2 -2
- package/dist/shared/{attaform.CzVta5o2.mjs → attaform.BJ_W7q3U.mjs} +8 -6
- package/dist/shared/attaform.BJ_W7q3U.mjs.map +1 -0
- package/dist/shared/{attaform.D52oJiYC.d.cts → attaform.BNmkKz0q.d.mts} +38 -6
- package/dist/shared/{attaform.CaYj3ZfY.cjs → attaform.BV_HyaMO.cjs} +6 -4
- package/dist/shared/attaform.BV_HyaMO.cjs.map +1 -0
- package/dist/shared/{attaform.Cmb_LCie.cjs → attaform.BnUXV01g.cjs} +4 -4
- package/dist/shared/attaform.BnUXV01g.cjs.map +1 -0
- package/dist/shared/{attaform.alpG7rT7.mjs → attaform.C-dAB90u.mjs} +4 -4
- package/dist/shared/attaform.C-dAB90u.mjs.map +1 -0
- package/dist/shared/{attaform.DsQkXE3o.cjs → attaform.C42wL7EJ.cjs} +195 -179
- package/dist/shared/attaform.C42wL7EJ.cjs.map +1 -0
- package/dist/shared/{attaform.BGMRvckW.d.ts → attaform.C6eE50re.d.ts} +18 -11
- package/dist/shared/{attaform.Dx9-QQE2.mjs → attaform.CAWKNCzc.mjs} +2 -2
- package/dist/shared/{attaform.Dx9-QQE2.mjs.map → attaform.CAWKNCzc.mjs.map} +1 -1
- package/dist/shared/{attaform.CtJOd7ox.mjs → attaform.CuBdtfbe.mjs} +196 -179
- package/dist/shared/attaform.CuBdtfbe.mjs.map +1 -0
- package/dist/shared/{attaform.WEwfXcHq.d.ts → attaform.CwFZGv5-.d.ts} +38 -6
- package/dist/shared/{attaform.DuPneYR0.d.cts → attaform.DdUYEhkV.d.cts} +18 -11
- package/dist/shared/attaform.DdjDqTah.d.cts +56 -0
- package/dist/shared/attaform.DdjDqTah.d.mts +56 -0
- package/dist/shared/attaform.DdjDqTah.d.ts +56 -0
- package/dist/shared/{attaform.BhI9Icek.mjs → attaform.Df-s8j1X.mjs} +2 -4
- package/dist/shared/attaform.Df-s8j1X.mjs.map +1 -0
- package/dist/shared/{attaform.DrY8srOp.d.mts → attaform.DiWNbKWa.d.mts} +18 -11
- package/dist/shared/{attaform.Db4E4IW6.cjs → attaform.DwkU0oY9.cjs} +1 -5
- package/dist/shared/attaform.DwkU0oY9.cjs.map +1 -0
- package/dist/shared/{attaform.BJnNK75Y.d.cts → attaform.GJbSmwLB.d.cts} +181 -156
- package/dist/shared/{attaform.BJnNK75Y.d.mts → attaform.GJbSmwLB.d.mts} +181 -156
- package/dist/shared/{attaform.BJnNK75Y.d.ts → attaform.GJbSmwLB.d.ts} +181 -156
- package/dist/shared/{attaform.DCkSNnPr.d.mts → attaform.K-3glmiT.d.cts} +38 -6
- package/dist/shared/{attaform.DbyTD8N2.cjs → attaform.Z1qTwOYE.cjs} +8 -6
- package/dist/shared/attaform.Z1qTwOYE.cjs.map +1 -0
- package/dist/shared/{attaform.BibT5AS_.cjs → attaform.nycEksJn.cjs} +2 -2
- package/dist/shared/{attaform.BibT5AS_.cjs.map → attaform.nycEksJn.cjs.map} +1 -1
- package/dist/shared/{attaform.Dd1Kmmaj.mjs → attaform.o95Kjd3U.mjs} +6 -4
- package/dist/shared/attaform.o95Kjd3U.mjs.map +1 -0
- package/dist/zod-v3.cjs +2 -2
- package/dist/zod-v3.d.cts +12 -11
- package/dist/zod-v3.d.mts +12 -11
- package/dist/zod-v3.d.ts +12 -11
- package/dist/zod-v3.mjs +2 -2
- package/dist/zod-v4.cjs +2 -2
- package/dist/zod-v4.d.cts +6 -5
- package/dist/zod-v4.d.mts +6 -5
- package/dist/zod-v4.d.ts +6 -5
- package/dist/zod-v4.mjs +2 -2
- package/dist/zod.cjs +5 -5
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +21 -52
- package/dist/zod.d.mts +21 -52
- package/dist/zod.d.ts +21 -52
- package/dist/zod.mjs +5 -5
- package/dist/zod.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/shared/attaform.BhI9Icek.mjs.map +0 -1
- package/dist/shared/attaform.CaYj3ZfY.cjs.map +0 -1
- package/dist/shared/attaform.Cmb_LCie.cjs.map +0 -1
- package/dist/shared/attaform.CtJOd7ox.mjs.map +0 -1
- package/dist/shared/attaform.CzVta5o2.mjs.map +0 -1
- package/dist/shared/attaform.Db4E4IW6.cjs.map +0 -1
- package/dist/shared/attaform.DbyTD8N2.cjs.map +0 -1
- package/dist/shared/attaform.Dd1Kmmaj.mjs.map +0 -1
- package/dist/shared/attaform.DsQkXE3o.cjs.map +0 -1
- package/dist/shared/attaform.alpG7rT7.mjs.map +0 -1
- package/dist/shared/attaform.nf83TIR5.d.cts +0 -35
- package/dist/shared/attaform.nf83TIR5.d.mts +0 -35
- package/dist/shared/attaform.nf83TIR5.d.ts +0 -35
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm,
|
|
2
|
+
import { G as GenericForm, u as FlatPath, O as NestedType, F as FormKey, U as UseFormConfiguration, a as AbstractSchema, D as DefaultValuesInput, af as ValidateOnConfig, b as UseFormReturnType } from './attaform.GJbSmwLB.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The shape `form.values.<key>` returns at runtime.
|
|
@@ -120,6 +120,38 @@ type StorageLeaf<L> = InputIsUnknown<L> extends true ? unknown : L extends {
|
|
|
120
120
|
};
|
|
121
121
|
} ? Out : never;
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* The Zod v4 schema roots `useForm` accepts. A fixed-shape
|
|
125
|
+
* `z.object({ … })` is the common case; `z.record(K, V)` admits a
|
|
126
|
+
* dictionary form (a homogeneous map with runtime-known keys);
|
|
127
|
+
* `z.discriminatedUnion(disc, [...])` admits a variant form (one of
|
|
128
|
+
* several object shapes, picked by a discriminator). Each projects to
|
|
129
|
+
* a `GenericForm`-shaped value the form engine drives: an object root
|
|
130
|
+
* descends into its fixed keys, a record root treats its entries as an
|
|
131
|
+
* open live-keyed container, a variant root lifts the active variant's
|
|
132
|
+
* keys into one addressable surface.
|
|
133
|
+
*
|
|
134
|
+
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
135
|
+
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
136
|
+
* adapter's runtime construction rejects them with a legible error.
|
|
137
|
+
*
|
|
138
|
+
* `z.ZodObject` MUST keep its `z.ZodRawShape` argument, and the
|
|
139
|
+
* discriminated-union arm MUST stay fully applied. The unified entry's
|
|
140
|
+
* v4 overload constrains on `SupportedRootSchema & ZodV4Internals` to
|
|
141
|
+
* keep v3 schemas out (see `../unified/types-zod-major.ts`). In a
|
|
142
|
+
* single-major (v3-only) consumer install, the published `.d.mts`
|
|
143
|
+
* resolves this `z` to v3, where a bare or under-applied Zod class is
|
|
144
|
+
* missing its required arguments and degrades to an `any`-like error
|
|
145
|
+
* type; `any` then absorbs the union and `any & ZodV4Internals`
|
|
146
|
+
* collapses back to `any`, so the marker stops excluding v3 schemas and
|
|
147
|
+
* the read slot poisons to `never`. `z.ZodRecord` carries defaults for
|
|
148
|
+
* both arguments, so it stays concrete in either major.
|
|
149
|
+
* `z.ZodDiscriminatedUnion` does NOT (v3 requires both arguments, and
|
|
150
|
+
* its parameter order is the reverse of v4's), so the arm is written
|
|
151
|
+
* fully applied; the v3-only bundled-types fixture guards it.
|
|
152
|
+
*/
|
|
153
|
+
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord | z.ZodDiscriminatedUnion<readonly z.ZodObject<z.ZodRawShape>[], string>;
|
|
154
|
+
|
|
123
155
|
/**
|
|
124
156
|
* Zod v4 adapter entry point. Re-exports the adapter + the useForm
|
|
125
157
|
* wrapper that threads zod-v4-specific schema types through
|
|
@@ -188,12 +220,12 @@ type PathOutput<Schema extends z.ZodType, Path extends string> = z.output<Schema
|
|
|
188
220
|
* generics ride on the alias rather than re-evaluating the
|
|
189
221
|
* conditional from scratch.
|
|
190
222
|
*/
|
|
191
|
-
type FormOf<Schema extends
|
|
192
|
-
type OutOf<Schema extends
|
|
193
|
-
type ReadOf<Schema extends
|
|
194
|
-
declare function useForm<Schema extends
|
|
223
|
+
type FormOf<Schema extends SupportedRootSchema> = z.input<Schema> extends GenericForm ? z.input<Schema> : never;
|
|
224
|
+
type OutOf<Schema extends SupportedRootSchema> = z.output<Schema> extends GenericForm ? z.output<Schema> : never;
|
|
225
|
+
type ReadOf<Schema extends SupportedRootSchema> = StorageShape<Schema> extends GenericForm ? StorageShape<Schema> : never;
|
|
226
|
+
declare function useForm<Schema extends SupportedRootSchema, K extends FormKey = FormKey>(configuration: Omit<UseFormConfiguration<FormOf<Schema>, OutOf<Schema>, AbstractSchema<FormOf<Schema>, OutOf<Schema>>, DefaultValuesInput<FormOf<Schema>>, K>, 'schema' | 'validateOn' | 'debounceMs'> & {
|
|
195
227
|
schema: Schema;
|
|
196
228
|
} & ValidateOnConfig): UseFormReturnType<FormOf<Schema>, OutOf<Schema>, ReadOf<Schema>, K>;
|
|
197
229
|
|
|
198
230
|
export { useForm as u };
|
|
199
|
-
export type { PathInput as P,
|
|
231
|
+
export type { PathInput as P, SupportedRootSchema as S, PathOutput as a, StorageShape as b };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FormKey,
|
|
1
|
+
import { F as FormKey, W as PathKey, m as DisplayCtx, d as GetDisplayState, n as DisplayMachine, V as Path, aa as SlimPrimitiveKind, C as CoercionEntry, g as CoercionRegistry, G as GenericForm, ag as ValidationError, a as AbstractSchema, ak as WriteMeta, j as DeepPartial, al as WriteShape, as as TransformAbortHolder, ae as ValidateOn, A as AttaformDefaults, b as UseFormReturnType, c as RegisterValue } from './attaform.GJbSmwLB.cjs';
|
|
2
2
|
import { Ref, ComputedRef, App, InjectionKey } from 'vue';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -643,12 +643,12 @@ type FormStore<F extends GenericForm, G extends GenericForm = F> = {
|
|
|
643
643
|
* Schema-driven errors. Written ONLY by the schema validation pipeline:
|
|
644
644
|
* `scheduleFieldValidation`, `handleSubmit`, the construction-time seed,
|
|
645
645
|
* history restore, and hydration. Cleared by `reset` / `resetField` and by
|
|
646
|
-
* a successful submit. `
|
|
646
|
+
* a successful submit. `setErrors` / `clearErrors` do NOT touch this Map.
|
|
647
647
|
*/
|
|
648
648
|
readonly schemaErrors: Map<PathKey, ValidationError[]>;
|
|
649
649
|
/**
|
|
650
|
-
* User-injected errors. Written ONLY by the `
|
|
651
|
-
* (and history / hydration replay). Survives schema revalidation and
|
|
650
|
+
* User-injected errors. Written ONLY by the `setErrors` / `clearErrors`
|
|
651
|
+
* API surface (and history / hydration replay). Survives schema revalidation and
|
|
652
652
|
* successful submits — the consumer owns its lifetime explicitly.
|
|
653
653
|
*/
|
|
654
654
|
readonly userErrors: Map<PathKey, ValidationError[]>;
|
|
@@ -1005,7 +1005,7 @@ type FormStore<F extends GenericForm, G extends GenericForm = F> = {
|
|
|
1005
1005
|
*/
|
|
1006
1006
|
applySchemaErrorsForSubtree(path: Path, errors: ValidationError[]): void;
|
|
1007
1007
|
setAllUserErrors(errors: readonly ValidationError[]): void;
|
|
1008
|
-
|
|
1008
|
+
setUserErrorsForPath(path: Path, errors: readonly ValidationError[]): void;
|
|
1009
1009
|
clearUserErrors(path?: Path): void;
|
|
1010
1010
|
/**
|
|
1011
1011
|
* Merged read — returns `[...schemaErrors[path], ...userErrors[path]]`.
|
|
@@ -1311,9 +1311,8 @@ type SerializedFormData = {
|
|
|
1311
1311
|
*/
|
|
1312
1312
|
readonly schemaErrors: ReadonlyArray<readonly [string, unknown]>;
|
|
1313
1313
|
/**
|
|
1314
|
-
* Errors set explicitly via `
|
|
1315
|
-
*
|
|
1316
|
-
* at snapshot time. Replayed at hydration; persists across
|
|
1314
|
+
* Errors set explicitly via `setErrors` (typically a server
|
|
1315
|
+
* response) at snapshot time. Replayed at hydration; persists across
|
|
1317
1316
|
* client-side re-validation.
|
|
1318
1317
|
*/
|
|
1319
1318
|
readonly userErrors: ReadonlyArray<readonly [string, unknown]>;
|
|
@@ -1741,9 +1740,9 @@ declare function lazy<Ctx = WizardCtx>(resolve: (ctx: Ctx) => AnyForm | string |
|
|
|
1741
1740
|
* `issue.code` (e.g. `zod:too_small`). No enum here because
|
|
1742
1741
|
* Zod's code list evolves.
|
|
1743
1742
|
* - consumer-defined — anything the consumer's backend / app stamps
|
|
1744
|
-
* onto a `ValidationError` (
|
|
1745
|
-
* or
|
|
1746
|
-
*
|
|
1743
|
+
* onto a `ValidationError` (a server response handed to `setErrors`,
|
|
1744
|
+
* or a code passed inline). Pick a scope (`api:`, `auth:`, etc.) and
|
|
1745
|
+
* stay consistent.
|
|
1747
1746
|
*
|
|
1748
1747
|
* Use these constants in tests and error-routing UI:
|
|
1749
1748
|
*
|
|
@@ -1787,6 +1786,14 @@ declare const AttaformErrorCode: {
|
|
|
1787
1786
|
* `form.hydrateError` for retry UX.
|
|
1788
1787
|
*/
|
|
1789
1788
|
readonly ActivationFailed: "atta:activation-failed";
|
|
1789
|
+
/**
|
|
1790
|
+
* Default code stamped on a manual error set through `form.setErrors`
|
|
1791
|
+
* when the caller omits an explicit `code`. The `setErrors` input is
|
|
1792
|
+
* lenient (`code` optional), so this is the fallback that keeps every
|
|
1793
|
+
* produced `ValidationError` carrying a stable, branchable identifier.
|
|
1794
|
+
* Override it per error by passing your own `code` (`api:…`, `auth:…`).
|
|
1795
|
+
*/
|
|
1796
|
+
readonly UserError: "atta:user-error";
|
|
1790
1797
|
};
|
|
1791
1798
|
type AttaformErrorCode = (typeof AttaformErrorCode)[keyof typeof AttaformErrorCode];
|
|
1792
1799
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
5
|
+
* `.transform()` wrappers off a Zod v3 schema to reach the form root,
|
|
6
|
+
* then return it: a `ZodObject` (fixed-shape form), a `ZodRecord`
|
|
7
|
+
* (dictionary form), or a `ZodDiscriminatedUnion` (variant form).
|
|
8
|
+
* Returns `never` for any other root, which makes the `useForm`
|
|
9
|
+
* projections collapse to `never` so the call fails to typecheck
|
|
10
|
+
* rather than producing a misshapen form type.
|
|
11
|
+
*
|
|
12
|
+
* Used internally by the v3 `useForm` overload to project an arbitrary
|
|
13
|
+
* supported root to its input / output / storage-read shapes.
|
|
14
|
+
*/
|
|
15
|
+
type UnwrapZodRoot<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : T extends z.ZodRecord<infer Key, infer Value> ? z.ZodRecord<Key, Value> : T extends z.ZodDiscriminatedUnion<infer Disc, infer Options> ? z.ZodDiscriminatedUnion<Disc, Options> : never;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The Zod v3 schema roots `useForm` accepts. Mirror of the v4
|
|
19
|
+
* `SupportedRootSchema`, expressed in v3's type vocabulary: a
|
|
20
|
+
* fixed-shape `z.object({ … })`, a `z.record(K, V)` dictionary form, or
|
|
21
|
+
* a `z.discriminatedUnion(disc, [...])` variant form.
|
|
22
|
+
*
|
|
23
|
+
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
24
|
+
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
25
|
+
* adapter's runtime construction rejects them with a legible error.
|
|
26
|
+
*
|
|
27
|
+
* The discriminated-union arm is written with v3's parameter order
|
|
28
|
+
* (`<Discriminator, Options>`), the reverse of v4's; both classes
|
|
29
|
+
* require their arguments, so the arm stays fully applied to avoid the
|
|
30
|
+
* single-major `any`-collapse the v4 alias documents.
|
|
31
|
+
*/
|
|
32
|
+
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny> | z.ZodDiscriminatedUnion<string, readonly z.ZodDiscriminatedUnionOption<string>[]>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
36
|
+
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
37
|
+
* Zod's own recursion peels nested defaults inside structural
|
|
38
|
+
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
39
|
+
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
40
|
+
* pre-transform input — transforms only run at submission /
|
|
41
|
+
* validation, not at the write boundary.
|
|
42
|
+
*
|
|
43
|
+
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
44
|
+
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
45
|
+
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
46
|
+
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
47
|
+
* the preprocess input (commonly `unknown`); reach for the
|
|
48
|
+
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
49
|
+
* Transforms preserve their pre-transform input shape, which matches
|
|
50
|
+
* storage.
|
|
51
|
+
*/
|
|
52
|
+
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
53
|
+
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
54
|
+
} : z.input<S>;
|
|
55
|
+
|
|
56
|
+
export type { SupportedRootSchema as S, UnwrapZodRoot as U, StorageShape as a };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
5
|
+
* `.transform()` wrappers off a Zod v3 schema to reach the form root,
|
|
6
|
+
* then return it: a `ZodObject` (fixed-shape form), a `ZodRecord`
|
|
7
|
+
* (dictionary form), or a `ZodDiscriminatedUnion` (variant form).
|
|
8
|
+
* Returns `never` for any other root, which makes the `useForm`
|
|
9
|
+
* projections collapse to `never` so the call fails to typecheck
|
|
10
|
+
* rather than producing a misshapen form type.
|
|
11
|
+
*
|
|
12
|
+
* Used internally by the v3 `useForm` overload to project an arbitrary
|
|
13
|
+
* supported root to its input / output / storage-read shapes.
|
|
14
|
+
*/
|
|
15
|
+
type UnwrapZodRoot<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : T extends z.ZodRecord<infer Key, infer Value> ? z.ZodRecord<Key, Value> : T extends z.ZodDiscriminatedUnion<infer Disc, infer Options> ? z.ZodDiscriminatedUnion<Disc, Options> : never;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The Zod v3 schema roots `useForm` accepts. Mirror of the v4
|
|
19
|
+
* `SupportedRootSchema`, expressed in v3's type vocabulary: a
|
|
20
|
+
* fixed-shape `z.object({ … })`, a `z.record(K, V)` dictionary form, or
|
|
21
|
+
* a `z.discriminatedUnion(disc, [...])` variant form.
|
|
22
|
+
*
|
|
23
|
+
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
24
|
+
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
25
|
+
* adapter's runtime construction rejects them with a legible error.
|
|
26
|
+
*
|
|
27
|
+
* The discriminated-union arm is written with v3's parameter order
|
|
28
|
+
* (`<Discriminator, Options>`), the reverse of v4's; both classes
|
|
29
|
+
* require their arguments, so the arm stays fully applied to avoid the
|
|
30
|
+
* single-major `any`-collapse the v4 alias documents.
|
|
31
|
+
*/
|
|
32
|
+
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny> | z.ZodDiscriminatedUnion<string, readonly z.ZodDiscriminatedUnionOption<string>[]>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
36
|
+
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
37
|
+
* Zod's own recursion peels nested defaults inside structural
|
|
38
|
+
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
39
|
+
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
40
|
+
* pre-transform input — transforms only run at submission /
|
|
41
|
+
* validation, not at the write boundary.
|
|
42
|
+
*
|
|
43
|
+
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
44
|
+
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
45
|
+
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
46
|
+
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
47
|
+
* the preprocess input (commonly `unknown`); reach for the
|
|
48
|
+
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
49
|
+
* Transforms preserve their pre-transform input shape, which matches
|
|
50
|
+
* storage.
|
|
51
|
+
*/
|
|
52
|
+
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
53
|
+
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
54
|
+
} : z.input<S>;
|
|
55
|
+
|
|
56
|
+
export type { SupportedRootSchema as S, UnwrapZodRoot as U, StorageShape as a };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
5
|
+
* `.transform()` wrappers off a Zod v3 schema to reach the form root,
|
|
6
|
+
* then return it: a `ZodObject` (fixed-shape form), a `ZodRecord`
|
|
7
|
+
* (dictionary form), or a `ZodDiscriminatedUnion` (variant form).
|
|
8
|
+
* Returns `never` for any other root, which makes the `useForm`
|
|
9
|
+
* projections collapse to `never` so the call fails to typecheck
|
|
10
|
+
* rather than producing a misshapen form type.
|
|
11
|
+
*
|
|
12
|
+
* Used internally by the v3 `useForm` overload to project an arbitrary
|
|
13
|
+
* supported root to its input / output / storage-read shapes.
|
|
14
|
+
*/
|
|
15
|
+
type UnwrapZodRoot<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodRoot<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : T extends z.ZodRecord<infer Key, infer Value> ? z.ZodRecord<Key, Value> : T extends z.ZodDiscriminatedUnion<infer Disc, infer Options> ? z.ZodDiscriminatedUnion<Disc, Options> : never;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The Zod v3 schema roots `useForm` accepts. Mirror of the v4
|
|
19
|
+
* `SupportedRootSchema`, expressed in v3's type vocabulary: a
|
|
20
|
+
* fixed-shape `z.object({ … })`, a `z.record(K, V)` dictionary form, or
|
|
21
|
+
* a `z.discriminatedUnion(disc, [...])` variant form.
|
|
22
|
+
*
|
|
23
|
+
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
24
|
+
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
25
|
+
* adapter's runtime construction rejects them with a legible error.
|
|
26
|
+
*
|
|
27
|
+
* The discriminated-union arm is written with v3's parameter order
|
|
28
|
+
* (`<Discriminator, Options>`), the reverse of v4's; both classes
|
|
29
|
+
* require their arguments, so the arm stays fully applied to avoid the
|
|
30
|
+
* single-major `any`-collapse the v4 alias documents.
|
|
31
|
+
*/
|
|
32
|
+
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny> | z.ZodDiscriminatedUnion<string, readonly z.ZodDiscriminatedUnionOption<string>[]>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
36
|
+
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
37
|
+
* Zod's own recursion peels nested defaults inside structural
|
|
38
|
+
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
39
|
+
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
40
|
+
* pre-transform input — transforms only run at submission /
|
|
41
|
+
* validation, not at the write boundary.
|
|
42
|
+
*
|
|
43
|
+
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
44
|
+
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
45
|
+
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
46
|
+
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
47
|
+
* the preprocess input (commonly `unknown`); reach for the
|
|
48
|
+
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
49
|
+
* Transforms preserve their pre-transform input shape, which matches
|
|
50
|
+
* storage.
|
|
51
|
+
*/
|
|
52
|
+
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
53
|
+
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
54
|
+
} : z.input<S>;
|
|
55
|
+
|
|
56
|
+
export type { SupportedRootSchema as S, UnwrapZodRoot as U, StorageShape as a };
|
|
@@ -1427,8 +1427,6 @@ function coerceToPathKey(input) {
|
|
|
1427
1427
|
}
|
|
1428
1428
|
const ROOT_PATH = Object.freeze([]);
|
|
1429
1429
|
const ROOT_PATH_KEY = "[]";
|
|
1430
|
-
const FORM_ERRORS_PATH = Object.freeze([""]);
|
|
1431
|
-
const FORM_ERRORS_PATH_KEY = '[""]';
|
|
1432
1430
|
function isPathPrefix(prefix, path) {
|
|
1433
1431
|
if (path.length < prefix.length) return false;
|
|
1434
1432
|
for (let i = 0; i < prefix.length; i++) {
|
|
@@ -1444,5 +1442,5 @@ function pathsEqual(a, b) {
|
|
|
1444
1442
|
return true;
|
|
1445
1443
|
}
|
|
1446
1444
|
|
|
1447
|
-
export { AttaformError as A,
|
|
1448
|
-
//# sourceMappingURL=attaform.
|
|
1445
|
+
export { AttaformError as A, REGISTER_OWNER_MARKER as B, kAttaformAncestorWizard as C, InvalidPathError as I, OutsideSetupError as O, ROOT_PATH as R, SubmitErrorHandlerError as S, V_REGISTER_MARKER as V, __DEV__ as _, InvalidUseFormConfigError as a, ROOT_PATH_KEY as b, RegistryNotInstalledError as c, ReservedFormKeyError as d, assignKey as e, canonicalizePath as f, createAttaform as g, createRegistry as h, getRegistryFromApp as i, isPathPrefix as j, isRegisterValue as k, kAttaformRegistry as l, kAttaformWizardActiveStepResolver as m, pathKeyToDotted as n, pathsEqual as o, parseDottedPath as p, keyForSegments as q, INTERACTIVE_TAG_NAMES as r, segmentsForPathKey as s, toError as t, useRegistry as u, vRegister as v, coerceToPathKey as w, ensureAttaformInstalled as x, kFormContext as y, kFormInstanceId as z };
|
|
1446
|
+
//# sourceMappingURL=attaform.Df-s8j1X.mjs.map
|