attaform 0.27.5 → 0.28.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/dist/abstract.d.mts +5 -4
- package/dist/abstract.mjs +4 -3
- package/dist/chunks/fingerprint.mjs +0 -1
- package/dist/chunks/fingerprint2.mjs +1 -2
- package/dist/dev/abstract.mjs +4 -0
- package/dist/{chunks → dev/chunks}/dev-key-collision-warnings.mjs +0 -1
- package/dist/{chunks → dev/chunks}/devtools.mjs +5 -6
- package/dist/{chunks/fingerprint.cjs → dev/chunks/fingerprint.mjs} +7 -10
- package/dist/{chunks/fingerprint2.cjs → dev/chunks/fingerprint2.mjs} +32 -35
- package/dist/dev/directive.mjs +1 -0
- package/dist/dev/history.mjs +89 -0
- package/dist/dev/index.mjs +5 -0
- package/dist/dev/runtime/plugins/attaform.mjs +40 -0
- package/dist/{shared/attaform.f2zyNh5d.cjs → dev/shared/attaform-dev.6qxD-Yqo.mjs} +187 -43
- package/dist/{shared/attaform.CQN9R62B.cjs → dev/shared/attaform-dev.BJGA_UOS.mjs} +1 -4
- package/dist/{shared/attaform.Dc1mx48r.mjs → dev/shared/attaform-dev.BR8u0YOZ.mjs} +6 -7
- package/dist/dev/shared/attaform-dev.BXE2cr0L.mjs +220 -0
- package/dist/dev/shared/attaform-dev.By4PRjt0.mjs +248 -0
- package/dist/{shared/attaform.Cg_8gFQ7.mjs → dev/shared/attaform-dev.D2I8e_Mm.mjs} +132 -568
- package/dist/dev/shared/attaform-dev.Dr2YzS5B.mjs +197 -0
- package/dist/{shared/attaform.nMaz2C5P.mjs → dev/shared/attaform-dev.P7cseiEG.mjs} +178 -397
- package/dist/{shared/attaform.BypWgXRB.mjs → dev/shared/attaform-dev.WmuhD_CZ.mjs} +3955 -5029
- package/dist/{shared/attaform.Dkjh_F30.mjs → dev/shared/attaform-dev.oYrkP9dj.mjs} +160 -508
- package/dist/dev/zod-v3.mjs +17 -0
- package/dist/dev/zod-v4.mjs +16 -0
- package/dist/dev/zod.mjs +5 -0
- package/dist/directive.d.mts +20 -0
- package/dist/directive.mjs +1 -0
- package/dist/esbuild.mjs +0 -1
- package/dist/history.d.mts +59 -0
- package/dist/history.mjs +89 -0
- package/dist/index.d.mts +11 -5
- package/dist/index.mjs +5 -4
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.mjs +5 -2
- package/dist/rollup.mjs +0 -1
- package/dist/rspack.d.mts +6 -1
- package/dist/rspack.mjs +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +9 -8
- package/dist/runtime/plugins/attaform.mjs +1 -2
- package/dist/shared/{attaform.CIBMfxg9.d.ts → attaform.B4VkS43-.d.mts} +2 -2
- package/dist/shared/{attaform.Cg1rUfcF.cjs → attaform.B8k8JrmK.mjs} +3778 -5297
- package/dist/shared/attaform.BJGA_UOS.mjs +0 -1
- package/dist/shared/{attaform.CTiZ9Rrv.mjs → attaform.C09fpdLS.mjs} +172 -16
- package/dist/shared/{attaform.Bh8A6YAc.cjs → attaform.CJP3RkGa.mjs} +141 -590
- package/dist/shared/{attaform.CzL2CZ8U.d.ts → attaform.Cgu-hdSb.d.mts} +328 -78
- package/dist/shared/attaform.Cs2Rbdlo.mjs +0 -1
- package/dist/shared/{attaform.DcFDQVpa.d.ts → attaform.D5V4tZWq.d.mts} +79 -179
- package/dist/shared/{attaform.CF-EnyJn.cjs → attaform.D6DCnnQu.mjs} +11 -16
- package/dist/shared/attaform.DhnPb6nK.mjs +0 -1
- package/dist/shared/attaform.Dq4vWxuG.mjs +197 -0
- package/dist/shared/attaform.JfSWdEcb.d.mts +44 -0
- package/dist/shared/attaform.KvlEedlF.mjs +0 -1
- package/dist/shared/{attaform.Crv0RNiz.cjs → attaform.NLmerepI.mjs} +175 -557
- package/dist/shared/attaform.h0i6LijT.mjs +242 -0
- package/dist/shared/{attaform.Biytrv0-.cjs → attaform.uLbun31C.mjs} +204 -544
- package/dist/shared/attaform.v0fQtWyA.mjs +0 -1
- package/dist/shared/attaform.wfY8XFvm.mjs +197 -0
- package/dist/transforms.mjs +0 -1
- package/dist/vite.d.mts +17 -5
- package/dist/vite.mjs +24 -2
- package/dist/webpack.d.mts +6 -1
- package/dist/webpack.mjs +0 -1
- package/dist/zod-v3.d.mts +11 -6
- package/dist/zod-v3.mjs +17 -4
- package/dist/zod-v4.d.mts +12 -6
- package/dist/zod-v4.mjs +16 -4
- package/dist/zod.d.mts +4 -3
- package/dist/zod.mjs +5 -4
- package/package.json +23 -8
- package/skills/attaform/SKILL.md +2 -1
- package/dist/abstract.cjs +0 -48
- package/dist/abstract.cjs.map +0 -1
- package/dist/abstract.d.cts +0 -42
- package/dist/abstract.d.ts +0 -42
- package/dist/abstract.mjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.cjs +0 -25
- package/dist/chunks/dev-key-collision-warnings.cjs.map +0 -1
- package/dist/chunks/dev-key-collision-warnings.mjs.map +0 -1
- package/dist/chunks/devtools.cjs +0 -157
- package/dist/chunks/devtools.cjs.map +0 -1
- package/dist/chunks/devtools.mjs.map +0 -1
- package/dist/chunks/fingerprint.cjs.map +0 -1
- package/dist/chunks/fingerprint.mjs.map +0 -1
- package/dist/chunks/fingerprint2.cjs.map +0 -1
- package/dist/chunks/fingerprint2.mjs.map +0 -1
- package/dist/esbuild.cjs +0 -28
- package/dist/esbuild.cjs.map +0 -1
- package/dist/esbuild.d.cts +0 -56
- package/dist/esbuild.d.ts +0 -56
- package/dist/esbuild.mjs.map +0 -1
- package/dist/index.cjs +0 -51
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -249
- package/dist/index.d.ts +0 -249
- package/dist/index.mjs.map +0 -1
- package/dist/nuxt.cjs +0 -84
- package/dist/nuxt.cjs.map +0 -1
- package/dist/nuxt.d.cts +0 -66
- package/dist/nuxt.d.ts +0 -66
- package/dist/nuxt.mjs.map +0 -1
- package/dist/rollup.cjs +0 -24
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.cts +0 -35
- package/dist/rollup.d.ts +0 -35
- package/dist/rollup.mjs.map +0 -1
- package/dist/rspack.cjs +0 -10
- package/dist/rspack.cjs.map +0 -1
- package/dist/rspack.d.cts +0 -40
- package/dist/rspack.d.ts +0 -40
- package/dist/rspack.mjs.map +0 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +0 -7
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +0 -35
- package/dist/runtime/plugins/attaform.cjs +0 -43
- package/dist/runtime/plugins/attaform.cjs.map +0 -1
- package/dist/runtime/plugins/attaform.d.cts +0 -5
- package/dist/runtime/plugins/attaform.d.ts +0 -5
- package/dist/runtime/plugins/attaform.mjs.map +0 -1
- package/dist/shared/attaform.B3abZaCV.d.cts +0 -2484
- package/dist/shared/attaform.BJGA_UOS.mjs.map +0 -1
- package/dist/shared/attaform.Bh8A6YAc.cjs.map +0 -1
- package/dist/shared/attaform.Biytrv0-.cjs.map +0 -1
- package/dist/shared/attaform.Bn0IzhD_.cjs +0 -800
- package/dist/shared/attaform.Bn0IzhD_.cjs.map +0 -1
- package/dist/shared/attaform.BypWgXRB.mjs.map +0 -1
- package/dist/shared/attaform.C9fPTxjB.d.cts +0 -41
- package/dist/shared/attaform.C9fPTxjB.d.ts +0 -41
- package/dist/shared/attaform.CF-EnyJn.cjs.map +0 -1
- package/dist/shared/attaform.CJ1Z9Mz4.d.mts +0 -2484
- package/dist/shared/attaform.CQN9R62B.cjs.map +0 -1
- package/dist/shared/attaform.CTiZ9Rrv.mjs.map +0 -1
- package/dist/shared/attaform.Cg1rUfcF.cjs.map +0 -1
- package/dist/shared/attaform.Cg_8gFQ7.mjs.map +0 -1
- package/dist/shared/attaform.Crv0RNiz.cjs.map +0 -1
- package/dist/shared/attaform.Cs2Rbdlo.mjs.map +0 -1
- package/dist/shared/attaform.CzL2CZ8U.d.cts +0 -4713
- package/dist/shared/attaform.CzL2CZ8U.d.mts +0 -4713
- package/dist/shared/attaform.DRUT703x.d.cts +0 -56
- package/dist/shared/attaform.DRUT703x.d.ts +0 -56
- package/dist/shared/attaform.DYwyM5Cp.d.cts +0 -232
- package/dist/shared/attaform.Dc1mx48r.mjs.map +0 -1
- package/dist/shared/attaform.DhnPb6nK.mjs.map +0 -1
- package/dist/shared/attaform.Dkjh_F30.mjs.map +0 -1
- package/dist/shared/attaform.DoQm_Vkd.cjs +0 -58
- package/dist/shared/attaform.DoQm_Vkd.cjs.map +0 -1
- package/dist/shared/attaform.DrHOqB-d.d.mts +0 -232
- package/dist/shared/attaform.KvlEedlF.mjs.map +0 -1
- package/dist/shared/attaform.RaTzp1WF.cjs +0 -26
- package/dist/shared/attaform.RaTzp1WF.cjs.map +0 -1
- package/dist/shared/attaform.f2zyNh5d.cjs.map +0 -1
- package/dist/shared/attaform.nMaz2C5P.mjs.map +0 -1
- package/dist/shared/attaform.v0fQtWyA.mjs.map +0 -1
- package/dist/shared/attaform.yUrz7C2z.cjs +0 -29
- package/dist/shared/attaform.yUrz7C2z.cjs.map +0 -1
- package/dist/transforms.cjs +0 -12
- package/dist/transforms.cjs.map +0 -1
- package/dist/transforms.d.cts +0 -73
- package/dist/transforms.d.ts +0 -73
- package/dist/transforms.mjs.map +0 -1
- package/dist/vite.cjs +0 -363
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.d.cts +0 -133
- package/dist/vite.d.ts +0 -133
- package/dist/vite.mjs.map +0 -1
- package/dist/webpack.cjs +0 -10
- package/dist/webpack.cjs.map +0 -1
- package/dist/webpack.d.cts +0 -37
- package/dist/webpack.d.ts +0 -37
- package/dist/webpack.mjs.map +0 -1
- package/dist/zod-v3.cjs +0 -53
- package/dist/zod-v3.cjs.map +0 -1
- package/dist/zod-v3.d.cts +0 -246
- package/dist/zod-v3.d.ts +0 -246
- package/dist/zod-v3.mjs.map +0 -1
- package/dist/zod-v4.cjs +0 -55
- package/dist/zod-v4.cjs.map +0 -1
- package/dist/zod-v4.d.cts +0 -172
- package/dist/zod-v4.d.ts +0 -172
- package/dist/zod-v4.mjs.map +0 -1
- package/dist/zod.cjs +0 -51
- package/dist/zod.cjs.map +0 -1
- package/dist/zod.d.cts +0 -7
- package/dist/zod.d.ts +0 -7
- package/dist/zod.mjs.map +0 -1
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The Zod v3 schema roots `useForm` accepts. Mirror of the v4
|
|
5
|
-
* `SupportedRootSchema`, expressed in v3's type vocabulary: a
|
|
6
|
-
* fixed-shape `z.object({ … })`, a `z.record(K, V)` dictionary form, or
|
|
7
|
-
* a `z.discriminatedUnion(disc, [...])` variant form.
|
|
8
|
-
*
|
|
9
|
-
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
10
|
-
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
11
|
-
* adapter's runtime construction rejects them with a legible error.
|
|
12
|
-
*
|
|
13
|
-
* The discriminated-union arm is written with v3's parameter order
|
|
14
|
-
* (`<Discriminator, Options>`), the reverse of v4's; both classes
|
|
15
|
-
* require their arguments, so the arm stays fully applied to avoid the
|
|
16
|
-
* single-major `any`-collapse the v4 alias documents.
|
|
17
|
-
*/
|
|
18
|
-
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny> | z.ZodDiscriminatedUnion<string, readonly z.ZodDiscriminatedUnionOption<string>[]>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
22
|
-
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
23
|
-
* Zod's own recursion peels nested defaults inside structural
|
|
24
|
-
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
25
|
-
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
26
|
-
* pre-transform input — transforms only run at submission /
|
|
27
|
-
* validation, not at the write boundary.
|
|
28
|
-
*
|
|
29
|
-
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
30
|
-
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
31
|
-
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
32
|
-
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
33
|
-
* the preprocess input (commonly `unknown`); reach for the
|
|
34
|
-
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
35
|
-
* Transforms preserve their pre-transform input shape, which matches
|
|
36
|
-
* storage.
|
|
37
|
-
*/
|
|
38
|
-
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
39
|
-
[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]>;
|
|
40
|
-
} : z.input<S>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
44
|
-
* `.transform()` wrappers off a Zod v3 schema to reach the form root,
|
|
45
|
-
* then return it: a `ZodObject` (fixed-shape form), a `ZodRecord`
|
|
46
|
-
* (dictionary form), or a `ZodDiscriminatedUnion` (variant form).
|
|
47
|
-
* Returns `never` for any other root, which makes the `useForm`
|
|
48
|
-
* projections collapse to `never` so the call fails to typecheck
|
|
49
|
-
* rather than producing a misshapen form type.
|
|
50
|
-
*
|
|
51
|
-
* Used internally by the v3 `useForm` overload to project an arbitrary
|
|
52
|
-
* supported root to its input / output / storage-read shapes.
|
|
53
|
-
*/
|
|
54
|
-
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;
|
|
55
|
-
|
|
56
|
-
export type { SupportedRootSchema as S, UnwrapZodRoot as U, StorageShape as a };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The Zod v3 schema roots `useForm` accepts. Mirror of the v4
|
|
5
|
-
* `SupportedRootSchema`, expressed in v3's type vocabulary: a
|
|
6
|
-
* fixed-shape `z.object({ … })`, a `z.record(K, V)` dictionary form, or
|
|
7
|
-
* a `z.discriminatedUnion(disc, [...])` variant form.
|
|
8
|
-
*
|
|
9
|
-
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
10
|
-
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
11
|
-
* adapter's runtime construction rejects them with a legible error.
|
|
12
|
-
*
|
|
13
|
-
* The discriminated-union arm is written with v3's parameter order
|
|
14
|
-
* (`<Discriminator, Options>`), the reverse of v4's; both classes
|
|
15
|
-
* require their arguments, so the arm stays fully applied to avoid the
|
|
16
|
-
* single-major `any`-collapse the v4 alias documents.
|
|
17
|
-
*/
|
|
18
|
-
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny> | z.ZodDiscriminatedUnion<string, readonly z.ZodDiscriminatedUnionOption<string>[]>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
22
|
-
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
23
|
-
* Zod's own recursion peels nested defaults inside structural
|
|
24
|
-
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
25
|
-
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
26
|
-
* pre-transform input — transforms only run at submission /
|
|
27
|
-
* validation, not at the write boundary.
|
|
28
|
-
*
|
|
29
|
-
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
30
|
-
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
31
|
-
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
32
|
-
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
33
|
-
* the preprocess input (commonly `unknown`); reach for the
|
|
34
|
-
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
35
|
-
* Transforms preserve their pre-transform input shape, which matches
|
|
36
|
-
* storage.
|
|
37
|
-
*/
|
|
38
|
-
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
39
|
-
[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]>;
|
|
40
|
-
} : z.input<S>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
44
|
-
* `.transform()` wrappers off a Zod v3 schema to reach the form root,
|
|
45
|
-
* then return it: a `ZodObject` (fixed-shape form), a `ZodRecord`
|
|
46
|
-
* (dictionary form), or a `ZodDiscriminatedUnion` (variant form).
|
|
47
|
-
* Returns `never` for any other root, which makes the `useForm`
|
|
48
|
-
* projections collapse to `never` so the call fails to typecheck
|
|
49
|
-
* rather than producing a misshapen form type.
|
|
50
|
-
*
|
|
51
|
-
* Used internally by the v3 `useForm` overload to project an arbitrary
|
|
52
|
-
* supported root to its input / output / storage-read shapes.
|
|
53
|
-
*/
|
|
54
|
-
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;
|
|
55
|
-
|
|
56
|
-
export type { SupportedRootSchema as S, UnwrapZodRoot as U, StorageShape as a };
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm, s as FlatPath, B as NestedType, F as FormKey, U as UseFormConfiguration, A as AbstractSchema, aq as AcceptableDefaults, ae as ValidateOnConfig, a as UseFormReturnType } from './attaform.CzL2CZ8U.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The Zod v4 schema roots `useForm` accepts. A fixed-shape
|
|
6
|
-
* `z.object({ … })` is the common case; `z.record(K, V)` admits a
|
|
7
|
-
* dictionary form (a homogeneous map with runtime-known keys);
|
|
8
|
-
* `z.discriminatedUnion(disc, [...])` admits a variant form (one of
|
|
9
|
-
* several object shapes, picked by a discriminator). Each projects to
|
|
10
|
-
* a `GenericForm`-shaped value the form engine drives: an object root
|
|
11
|
-
* descends into its fixed keys, a record root treats its entries as an
|
|
12
|
-
* open live-keyed container, a variant root lifts the active variant's
|
|
13
|
-
* keys into one addressable surface.
|
|
14
|
-
*
|
|
15
|
-
* Other roots (a bare `z.union`, a root `z.array`, primitives,
|
|
16
|
-
* `z.map` / `z.set`) are not form roots; wrap them under a key. The
|
|
17
|
-
* adapter's runtime construction rejects them with a legible error.
|
|
18
|
-
*
|
|
19
|
-
* `z.ZodObject` MUST keep its `z.ZodRawShape` argument, and the
|
|
20
|
-
* discriminated-union arm MUST stay fully applied. The unified entry's
|
|
21
|
-
* v4 overload constrains on `SupportedRootSchema & ZodV4Internals` to
|
|
22
|
-
* keep v3 schemas out (see `../unified/types-zod-major.ts`). In a
|
|
23
|
-
* single-major (v3-only) consumer install, the published `.d.mts`
|
|
24
|
-
* resolves this `z` to v3, where a bare or under-applied Zod class is
|
|
25
|
-
* missing its required arguments and degrades to an `any`-like error
|
|
26
|
-
* type; `any` then absorbs the union and `any & ZodV4Internals`
|
|
27
|
-
* collapses back to `any`, so the marker stops excluding v3 schemas and
|
|
28
|
-
* the read slot poisons to `never`. `z.ZodRecord` carries defaults for
|
|
29
|
-
* both arguments, so it stays concrete in either major.
|
|
30
|
-
* `z.ZodDiscriminatedUnion` does NOT (v3 requires both arguments, and
|
|
31
|
-
* its parameter order is the reverse of v4's), so the arm is written
|
|
32
|
-
* fully applied; the v3-only bundled-types fixture guards it.
|
|
33
|
-
*/
|
|
34
|
-
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord | z.ZodDiscriminatedUnion<readonly z.ZodObject<z.ZodRawShape>[], string>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The shape `form.values.<key>` returns at runtime.
|
|
38
|
-
*
|
|
39
|
-
* Per leaf:
|
|
40
|
-
*
|
|
41
|
-
* 1. Schema-side input normalizers — `z.preprocess(fn, inner)` AND
|
|
42
|
-
* `z.coerce.X()`. Zod v4 represents these differently
|
|
43
|
-
* (`ZodPipe<ZodTransform, inner>` for preprocess; a primitive
|
|
44
|
-
* with `def.coerce === true` for coerce), but they share the
|
|
45
|
-
* same type-level marker: `_zod.input` is `unknown`. The
|
|
46
|
-
* normalizer runs at parse time, NOT at the write boundary, so
|
|
47
|
-
* storage holds the consumer's raw input and the type collapses
|
|
48
|
-
* to `unknown` to match. Reach the typed value via
|
|
49
|
-
* `handleSubmit`, `validate`, or `validateAsync` — they re-parse
|
|
50
|
-
* storage through the wrapper.
|
|
51
|
-
*
|
|
52
|
-
* 2. `inner.transform(fn)` — compiles to `ZodPipe<inner, ZodTransform>`.
|
|
53
|
-
* Transforms fire at submit / validate, NOT at the write boundary,
|
|
54
|
-
* so storage holds whatever `inner` stores. Recurse `StorageShape`
|
|
55
|
-
* on `inner` so a defaulted leaf inside `inner` still reads `T`
|
|
56
|
-
* (not `T | undefined`).
|
|
57
|
-
*
|
|
58
|
-
* A bare top-level `ZodTransform` (no `in` schema) reads
|
|
59
|
-
* `_zod.input` directly — there's no inner to recurse into.
|
|
60
|
-
*
|
|
61
|
-
* 3. Codec / generic pipe — neither side is a transform. Read
|
|
62
|
-
* `_zod.output`. Codecs aren't write-boundary-synthesized, so the
|
|
63
|
-
* post-parse view is the only honest storage type.
|
|
64
|
-
*
|
|
65
|
-
* 4. Everything else (defaults, catch, readonly, optional, primitives,
|
|
66
|
-
* nested objects) — read `_zod.output`. Defaults and catches fire
|
|
67
|
-
* at parse time, so the post-init view is what storage holds.
|
|
68
|
-
* Nested objects delegate to Zod's own recursion on `_zod.output`,
|
|
69
|
-
* which peels nested defaults inside structural containers.
|
|
70
|
-
*
|
|
71
|
-
* Detection order: case 1 wins via the `_zod.input` IsUnknown check
|
|
72
|
-
* before the pipe/transform cascade fires, so wrapped variants like
|
|
73
|
-
* `z.coerce.number().optional()` (input = `unknown | undefined` →
|
|
74
|
-
* collapses to `unknown`) and `z.preprocess(fn, z.object(...))` (input
|
|
75
|
-
* = `unknown`) both land on `unknown` without descending. The IsAny
|
|
76
|
-
* filter keeps `z.any()` from being mistaken for coerce.
|
|
77
|
-
*
|
|
78
|
-
* Implementation note: direct `_zod` property access mirrors Zod's
|
|
79
|
-
* own `$InferObjectOutput` / `$InferObjectInput`, which read
|
|
80
|
-
* `T[k]['_zod']['output']` / `T[k]['_zod']['input']` directly rather
|
|
81
|
-
* than wrapping in the top-level `output<T>` / `input<T>` conditional.
|
|
82
|
-
* Wrapping per key spawns a fresh conditional instantiation for every
|
|
83
|
-
* key; Volar's web-worker checker collapses that per-key walk to
|
|
84
|
-
* `any` once the schema is non-trivial. Property access has no
|
|
85
|
-
* conditional and resolves cleanly under the same budget.
|
|
86
|
-
*
|
|
87
|
-
* Shape access also goes through `_zod.def.shape` rather than
|
|
88
|
-
* `infer Shape from z.ZodObject<Shape>` — the latter collapses to the
|
|
89
|
-
* `$ZodShape` upper bound in the same worker because of
|
|
90
|
-
* `z.ZodObject`'s `out Shape` covariance markers.
|
|
91
|
-
*/
|
|
92
|
-
type StorageShape<S> = S extends {
|
|
93
|
-
_zod: {
|
|
94
|
-
def: {
|
|
95
|
-
type: 'object';
|
|
96
|
-
shape: infer Shape;
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
} ? {
|
|
100
|
-
[K in keyof Shape]-?: StorageLeaf<Shape[K]>;
|
|
101
|
-
} : StorageLeaf<S>;
|
|
102
|
-
/**
|
|
103
|
-
* Detects a schema whose `_zod.input` is `unknown` — the marker both
|
|
104
|
-
* `z.preprocess(fn, _)` and `z.coerce.X()` share in Zod v4. Excludes
|
|
105
|
-
* `any` via the canonical `0 extends 1 & T` test so `z.any()` leaves
|
|
106
|
-
* fall through to the cascade below and keep their `any` typing.
|
|
107
|
-
*/
|
|
108
|
-
type InputIsUnknown<L> = L extends {
|
|
109
|
-
_zod: {
|
|
110
|
-
input: infer In;
|
|
111
|
-
};
|
|
112
|
-
} ? 0 extends 1 & In ? false : unknown extends In ? true : false : false;
|
|
113
|
-
/**
|
|
114
|
-
* Implementation-detail per-leaf branching for `StorageShape`.
|
|
115
|
-
* Exported so the bundled `.d.ts` carries a single alias body —
|
|
116
|
-
* every leaf of a Zod object schema otherwise re-emits the full
|
|
117
|
-
* pipe / transform / default conditional ladder, which compounds
|
|
118
|
-
* badly with multiple complex schemas in the same scope. Consumers
|
|
119
|
-
* should reach for `StorageShape` instead.
|
|
120
|
-
*/
|
|
121
|
-
type StorageLeaf<L> = InputIsUnknown<L> extends true ? unknown : L extends {
|
|
122
|
-
_zod: {
|
|
123
|
-
def: {
|
|
124
|
-
type: 'pipe';
|
|
125
|
-
in: infer A;
|
|
126
|
-
out: infer B;
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
} ? B extends {
|
|
130
|
-
_zod: {
|
|
131
|
-
def: {
|
|
132
|
-
type: 'transform';
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
} ? StorageShape<A> : L extends {
|
|
136
|
-
_zod: {
|
|
137
|
-
output: infer Out;
|
|
138
|
-
};
|
|
139
|
-
} ? Out : never : L extends {
|
|
140
|
-
_zod: {
|
|
141
|
-
def: {
|
|
142
|
-
type: 'transform';
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
} ? L extends {
|
|
146
|
-
_zod: {
|
|
147
|
-
input: infer In;
|
|
148
|
-
};
|
|
149
|
-
} ? In : never : L extends {
|
|
150
|
-
_zod: {
|
|
151
|
-
output: infer Out;
|
|
152
|
-
};
|
|
153
|
-
} ? Out : never;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Zod v4 adapter entry point. Re-exports the adapter + the useForm
|
|
157
|
-
* wrapper that threads zod-v4-specific schema types through
|
|
158
|
-
* useAbstractForm.
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Type of the value accepted at `Path` for `setValue` / `defaultValues`
|
|
163
|
-
* — the schema's `z.input<Schema>` shape at that path. Matches what
|
|
164
|
-
* `form.values.X` returns at runtime (the honest input view storage
|
|
165
|
-
* holds before transforms run).
|
|
166
|
-
*
|
|
167
|
-
* ```ts
|
|
168
|
-
* const schema = z.object({
|
|
169
|
-
* flag: z.string().transform((v) => v.length > 10),
|
|
170
|
-
* })
|
|
171
|
-
* type FlagWriteIn = PathInput<typeof schema, 'flag'> // string
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
type PathInput<Schema extends z.ZodType, Path extends string> = z.input<Schema> extends GenericForm ? Path extends FlatPath<z.input<Schema>> ? NestedType<z.input<Schema>, Path> : never : never;
|
|
175
|
-
/**
|
|
176
|
-
* Type produced at `Path` after the full parse pipeline — the schema's
|
|
177
|
-
* `z.output<Schema>` shape at that path. Matches the `data` payload of
|
|
178
|
-
* `form.parse()` and the value handed to `handleSubmit`'s callback.
|
|
179
|
-
*
|
|
180
|
-
* ```ts
|
|
181
|
-
* const schema = z.object({
|
|
182
|
-
* flag: z.string().transform((v) => v.length > 10),
|
|
183
|
-
* })
|
|
184
|
-
* type FlagParsedOut = PathOutput<typeof schema, 'flag'> // boolean
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
type PathOutput<Schema extends z.ZodType, Path extends string> = z.output<Schema> extends GenericForm ? Path extends FlatPath<z.output<Schema>> ? NestedType<z.output<Schema>, Path> : never : never;
|
|
188
|
-
/**
|
|
189
|
-
* Create a form bound to a Zod v4 schema.
|
|
190
|
-
*
|
|
191
|
-
* ```ts
|
|
192
|
-
* import { useForm } from 'attaform/zod'
|
|
193
|
-
* import { z } from 'zod'
|
|
194
|
-
*
|
|
195
|
-
* const form = useForm({
|
|
196
|
-
* schema: z.object({
|
|
197
|
-
* email: z.email(),
|
|
198
|
-
* password: z.string().min(8),
|
|
199
|
-
* }),
|
|
200
|
-
* defaultValues: { email: '' },
|
|
201
|
-
* })
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* Returns a form API exposing `register`, `values`, `errors`,
|
|
205
|
-
* `fields`, `setValue`, `handleSubmit`, `meta`, field-array
|
|
206
|
-
* helpers, and more. See `UseFormReturnType` for the full
|
|
207
|
-
* surface.
|
|
208
|
-
*
|
|
209
|
-
* For Zod v3, import from `attaform/zod-v3` instead.
|
|
210
|
-
*/
|
|
211
|
-
/**
|
|
212
|
-
* `FormOf` / `OutOf` / `ReadOf` factor the three identical-shape
|
|
213
|
-
* conditionals out of `useForm`'s public signature. The bundled
|
|
214
|
-
* `.d.ts` then carries one alias per shape rather than re-inlining
|
|
215
|
-
* `z.input<Schema> extends GenericForm ? z.input<Schema> : never`
|
|
216
|
-
* four times — which is what produces TS2589 ("Type instantiation
|
|
217
|
-
* is excessively deep") on consumer call sites with complex schemas
|
|
218
|
-
* (discriminated unions, transform pipes, deep `.register()` chains).
|
|
219
|
-
* Each alias is computed once per `Schema` instantiation; downstream
|
|
220
|
-
* generics ride on the alias rather than re-evaluating the
|
|
221
|
-
* conditional from scratch.
|
|
222
|
-
*/
|
|
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>>, never, K>, 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'> & {
|
|
227
|
-
schema: Schema;
|
|
228
|
-
defaultValues?: AcceptableDefaults<FormOf<Schema>, z.input<Schema>>;
|
|
229
|
-
} & ValidateOnConfig): UseFormReturnType<FormOf<Schema>, OutOf<Schema>, ReadOf<Schema>, K>;
|
|
230
|
-
|
|
231
|
-
export { useForm as u };
|
|
232
|
-
export type { PathInput as P, SupportedRootSchema as S, PathOutput as a, StorageShape as b };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attaform.Dc1mx48r.mjs","sources":["../../src/runtime/core/zod-shape.ts","../../src/runtime/adapters/unified/use-form.ts","../../src/runtime/adapters/unified/field-meta.ts"],"sourcesContent":["/**\n * Shape detectors for Zod schemas. Used by the unified `attaform/zod`\n * entry's runtime dispatch (`runtime/adapters/unified/use-form.ts`)\n * to route to the v3 or v4 adapter based on the schema's runtime\n * shape. Mirrors the discrimination already used by the v4\n * introspection helper (`adapters/zod-v4/introspect.ts`'s\n * `assertZodVersion`, which reads `def.type`) and the v3 wrapper's\n * legitimate-input branch (`composables/use-form.ts`'s `isZodType`,\n * which reads `_def`).\n *\n * Why this discriminator and not `_zod` / `_def`:\n * - Zod v4 retained `_def` for backward compat — reading `_def` alone\n * misclassifies v4 schemas as v3.\n * - Zod v4's stable shape is `def.type: string` (lowercase tag like\n * `'object'`); Zod v3's is `_def.typeName: string` (capitalised tag\n * like `'ZodObject'`). Both are checked structurally so consumers\n * who alias one Zod major to a non-standard import path still work.\n */\n\ninterface ZodV4Shape {\n def: { type: unknown }\n}\n\ninterface ZodV3Shape {\n _def: { typeName: unknown }\n}\n\n/**\n * Returns true when `value` looks like a Zod schema of either major\n * version. Convenience wrapper around the v3 / v4 detectors.\n */\nexport function isZodSchemaShape(value: unknown): boolean {\n return isZodV4SchemaShape(value) || isZodV3SchemaShape(value)\n}\n\n/**\n * Returns true when `value` looks like a Zod v4 schema (has\n * `def.type: string`). Used by the unified entry's runtime-dispatch\n * to route to the v4 adapter.\n */\nexport function isZodV4SchemaShape(value: unknown): value is ZodV4Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { def?: unknown }).def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { type?: unknown }).type === 'string'\n}\n\n/**\n * Returns true when `value` looks like a Zod v3 schema (has\n * `_def.typeName: string`). Kept distinct from `isZodV4SchemaShape`\n * because some v4 schemas also expose `_def` for backward compat —\n * the v4 detector wins first in `isZodSchemaShape`.\n */\nexport function isZodV3SchemaShape(value: unknown): value is ZodV3Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { _def?: unknown })._def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { typeName?: unknown }).typeName === 'string'\n}\n","/**\n * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches\n * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the\n * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes\n * to the v3 wrapper, which already accepts both Zod v3 input and\n * `AbstractSchema` directly via its built-in shape branch.\n *\n * Type-level dispatch happens via TWO typed overloads — v4 first, v3\n * second — plus an untyped impl. Each overload mirrors the matching\n * direct adapter's signature exactly, so a v4-schema call site pays\n * the same per-call depth cost as importing from `attaform/zod-v4`\n * directly. Overload resolution at concrete call sites commits to one\n * overload immediately on argument shape — no type-level dispatch tax.\n *\n * Tests and other call sites that need the equivalent of\n * `typeof useForm<X>` should reach for the `UseFormReturn<X>` /\n * `UseFormConfig<X>` helpers in `types-api.ts` — instantiation\n * expressions on overloaded functions follow brittle resolution rules,\n * and the helper types give a deterministic projection.\n *\n * This module is the FALLBACK path. Vite consumers see the\n * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`\n * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build\n * time — in that case this dispatch never runs and the consumer\n * bundle ships only the matching adapter. Other bundlers (and\n * non-bundled ESM consumption) hit this dispatch instead, paying a\n * modest size cost for the convenience of a single hello-world import.\n *\n * Power users who want a guaranteed lean bundle on non-Vite tooling\n * can import directly from `attaform/zod-v3` or `attaform/zod-v4` —\n * those subpaths are never rewritten and never load the other\n * adapter.\n */\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport type { ZodV4Internals } from './types-zod-major'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n FormKey,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { AcceptableDefaults } from '../../types/types-core'\nimport type { SupportedRootSchema as SupportedRootSchemaV4 } from '../zod-v4/types-root'\nimport type { SupportedRootSchema as SupportedRootSchemaV3 } from '../zod-v3/types-root'\nimport type {\n V3FormOf,\n V3OutOf,\n V3ReadOf,\n V3SchemaInput,\n V4FormOf,\n V4OutOf,\n V4ReadOf,\n V4SchemaInput,\n} from './types-projections'\n\n/**\n * Create a form bound to a Zod v4 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * The constraint intersects `ZodV4Internals` (the v4-only `_zod`\n * brand) so a v3 schema can't bind this overload even when `z`\n * resolves to v3 in a single-major consumer install; v3 schemas fall\n * through to the v3 overload below. See `types-zod-major.ts`.\n */\nexport function useForm<\n Schema extends SupportedRootSchemaV4 & ZodV4Internals,\n K extends FormKey = FormKey,\n>(\n configuration: Omit<\n UseFormConfiguration<\n V4FormOf<Schema>,\n V4OutOf<Schema>,\n AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>,\n // `defaultValues` is Omitted below and re-supplied via the\n // `AcceptableDefaults` intersection, so this `DefaultValues` slot is\n // inert. `never` keeps it from re-instantiating the deep\n // `DefaultValuesInput` cascade here — that redundant instantiation,\n // across both overloads at a concrete call site, tips the bundled\n // `.d.ts` into TS2589.\n never,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'\n > & {\n schema: Schema\n // #422: the `AcceptableDefaults` slot adds the schema's own input\n // (`V4SchemaInput<Schema>`) as a reflexive escape arm so a generic form\n // wrapper forwarding `defaultValues` does not trip TS2589 / TS2769.\n // The arm is redundant at concrete call sites (a schema's input is a\n // subset of its `DefaultValuesInput`), so concrete checking is\n // unchanged. The return type never references the slot, so field\n // inference is preserved through the wrapper. See `AcceptableDefaults`.\n defaultValues?: AcceptableDefaults<V4FormOf<Schema>, V4SchemaInput<Schema>>\n } & ValidateOnConfig\n): UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K>\n/**\n * Create a form bound to a Zod v3 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod-v3'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * v3 schemas match this overload; v4 schemas hit the v4 overload\n * above first and never reach here.\n */\nexport function useForm<Schema extends SupportedRootSchemaV3, K extends FormKey = FormKey>(\n configuration: Omit<\n UseFormConfiguration<\n V3FormOf<Schema>,\n V3OutOf<Schema>,\n AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>,\n // Inert `DefaultValues` slot — see the v4 overload above.\n never,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'\n > & {\n schema: Schema\n // #422 — see the v4 overload above for the escape-arm rationale.\n defaultValues?: AcceptableDefaults<V3FormOf<Schema>, V3SchemaInput<Schema>>\n } & ValidateOnConfig\n): UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useForm(configuration: any): any {\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4>[0])\n }\n return useFormV3(configuration as Parameters<typeof useFormV3>[0])\n}\n","/**\n * Field-metadata write/read API for the unified `attaform/zod` entry.\n *\n * Storage is shared with both adapters via `field-meta-store` — a\n * payload written here is visible to whichever adapter the unified\n * `useForm` dispatches to at runtime, regardless of Zod major. No\n * `zod` runtime import; the type-only `import type` is erased at\n * build, so `attaform/zod` carries no `z.registry` reference even\n * when consumed by a Zod 3 project without the Vite plugin alias.\n *\n * The native v4 chain `schema.register(fieldMeta, payload)` continues\n * to work — Zod 4's `.register()` only calls `.add(this, payload)`\n * structurally, satisfied by the shared store.\n */\nimport type { z } from 'zod'\nimport type { FieldMetaPayload } from '../../core/field-meta'\nimport { fieldMetaStore, getFieldMetaForSchema } from '../../core/field-meta-store'\n\n// Zod v4's `$ZodRegistry` class isn't surfaced under the `z` namespace\n// of the classic external entry, but `z.registry()` returns one — so\n// `ReturnType<typeof z.registry<T>>` resolves to the registry type\n// without needing a direct import. The `import type` keeps the\n// reference type-only; nothing about `z.registry` lands in the bundle.\ntype ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>\n\n/**\n * The shared registry every Attaform-aware Zod schema can register\n * field metadata against, regardless of major. Same instance the v3\n * and v4 adapter entries expose — write in one place, read from\n * any.\n *\n * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native\n * `schema.register(fieldMeta, payload)` chain type-checks for v4\n * users; the runtime call only needs `.add` structurally, which the\n * shared store provides.\n */\nexport const fieldMeta = fieldMetaStore as unknown as ZodFieldMetaRegistry\n\n/**\n * Attach `payload` to `schema` in the shared registry and return a\n * clone of `schema` so each call gets its own identity (the registry\n * keys on schema reference, so cloning prevents last-write-wins\n * collisions for sub-schemas reused at multiple paths).\n *\n * Works on both Zod 3 and Zod 4 schemas — branches on the runtime\n * shape of the schema:\n * - Zod 4 schemas expose a public `.clone()` method; we call it.\n * - Zod 3 schemas don't, so we reconstruct via\n * `new schema.constructor(schema._def)`.\n *\n * Both forms produce a fresh schema with the same effective\n * structure, so the registry slot is unique to this call site.\n */\nexport function withMeta<S>(schema: S, payload: FieldMetaPayload): S {\n const target = schema as object\n const existing = getFieldMetaForSchema(target) ?? {}\n const cloned = cloneSchema(schema)\n fieldMetaStore.add(cloned as object, { ...existing, ...payload })\n return cloned\n}\n\nfunction cloneSchema<S>(schema: S): S {\n const candidate = schema as { clone?: unknown; constructor: unknown; _def: unknown }\n if (typeof candidate.clone === 'function') {\n return (candidate.clone as () => S)()\n }\n // Zod 3 path: reconstruct via constructor + _def (no public\n // `.clone()` on v3).\n const Ctor = candidate.constructor as new (def: unknown) => S\n return new Ctor(candidate._def)\n}\n"],"names":["useFormV4","useFormV3"],"mappings":";;;;;AAwCO,SAAS,mBAAmB,KAAA,EAAqC;AACtE,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,MAAM,MAAO,KAAA,CAA4B,GAAA;AACzC,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,MAAM,OAAO,KAAA;AACpD,EAAA,OAAO,OAAQ,IAA2B,IAAA,KAAS,QAAA;AACrD;;ACqGO,SAAS,QAAQ,aAAA,EAAyB;AAC/C,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAI,yBAAA,EAA0B;AAAA,EACtC;AACA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOA,UAAU,aAAgD,CAAA;AAAA,EACnE;AACA,EAAA,OAAOC,UAAU,aAAgD,CAAA;AACnE;;AC3HO,MAAM,SAAA,GAAY;AAiBlB,SAAS,QAAA,CAAY,QAAW,OAAA,EAA8B;AACnE,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,QAAA,GAAW,qBAAA,CAAsB,MAAM,CAAA,IAAK,EAAC;AACnD,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,EAAA,cAAA,CAAe,IAAI,MAAA,EAAkB,EAAE,GAAG,QAAA,EAAU,GAAG,SAAS,CAAA;AAChE,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,YAAe,MAAA,EAAc;AACpC,EAAA,MAAM,SAAA,GAAY,MAAA;AAClB,EAAA,IAAI,OAAO,SAAA,CAAU,KAAA,KAAU,UAAA,EAAY;AACzC,IAAA,OAAQ,UAAU,KAAA,EAAkB;AAAA,EACtC;AAGA,EAAA,MAAM,OAAO,SAAA,CAAU,WAAA;AACvB,EAAA,OAAO,IAAI,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAChC;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attaform.DhnPb6nK.mjs","sources":["../../src/core/detect-zod-major.ts"],"sourcesContent":["/**\n * Shared build-time Zod-major detection and adapter-alias resolution for\n * the bundler plugins (`attaform/vite`, `attaform/rollup`,\n * `attaform/esbuild`, `attaform/webpack`, `attaform/rspack`).\n *\n * The unified `attaform/zod` entry — and the bare `attaform` barrel, which\n * re-exports the identical surface — runtime-dispatches between the v3 and\n * v4 adapters, so a bundler that does not rewrite the import ships BOTH.\n * Each plugin rewrites those two specifiers (see\n * {@link REWRITABLE_ZOD_SPECIFIER_FILTER}) to the single matching adapter\n * subpath (`attaform/zod-v3` or `attaform/zod-v4`) based on the Zod major\n * resolved from the consumer's project, so the consumer bundle carries\n * one adapter instead of two. This module holds the detection (pure Node,\n * no bundler API) plus the shared diagnostic copy so every plugin behaves\n * and reads identically.\n *\n * Build-time only: imported by the build-tool entries at `src/*.ts`,\n * never by runtime code, so it never reaches a consumer's browser bundle.\n */\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { join } from 'node:path'\n\nexport const ZOD_UNIFIED_SPECIFIER = 'attaform/zod'\nexport const ZOD_V3_SPECIFIER = 'attaform/zod-v3'\nexport const ZOD_V4_SPECIFIER = 'attaform/zod-v4'\nexport const ZOD_BARREL_SPECIFIER = 'attaform'\n\n/**\n * The two specifiers a plugin collapses to a single adapter: the explicit\n * unified `attaform/zod` entry AND the bare `attaform` barrel. Both are\n * structurally identical (the barrel re-exports the same\n * `_shared-exports` + `_zod-binding` surface as `attaform/zod`), so both\n * carry the runtime-dispatching `useForm` that pulls in BOTH adapters —\n * and both rewrite to the same single adapter when one Zod major is\n * detected.\n *\n * The rewrite is value-safe: every runtime binding the barrel exports\n * (`useForm`, `fieldMeta`, `withMeta`, plus everything in\n * `_shared-exports`) is also exported by `attaform/zod-v3` and\n * `attaform/zod-v4`, so redirecting bare `attaform` to a pinned adapter\n * can never strand a runtime import. (Type-only exports are erased before\n * this resolve hook runs and are type-checked against the un-rewritten\n * `attaform` specifier, so their per-adapter asymmetry is irrelevant.)\n *\n * The pattern is anchored (`^...$`) so it matches ONLY those two\n * specifiers: the pinned adapters (`attaform/zod-v3`, `attaform/zod-v4`)\n * and every build-tool / other subpath (`attaform/nuxt`, `attaform/vite`,\n * `attaform/abstract`, `attaform/transforms`, ...) pass through untouched.\n * It serves double duty — as esbuild's `onResolve` `filter` (a Go RE2\n * regexp) and, via `.test()`, as the string-match predicate the other\n * plugins call — so the two representations can never diverge.\n */\nexport const REWRITABLE_ZOD_SPECIFIER_FILTER = /^attaform(?:\\/zod)?$/\n\n/**\n * True when `source` is a specifier the plugins rewrite to a single Zod\n * adapter: the bare `attaform` barrel or the explicit `attaform/zod`.\n * Backed by {@link REWRITABLE_ZOD_SPECIFIER_FILTER} so it stays in lockstep\n * with esbuild's filter.\n */\nexport function isRewritableZodSpecifier(source: string): boolean {\n return REWRITABLE_ZOD_SPECIFIER_FILTER.test(source)\n}\n\nexport type ZodMajorDetection =\n | { major: 3 }\n | { major: 4 }\n | { major: 'missing' }\n | { major: 'unknown' }\n\n/**\n * Read the consumer's installed Zod major by resolving\n * `zod/package.json` from their project root. ESM resolution\n * (`import.meta.resolve`) is sync and stable on Node 20.6+, follows\n * pnpm symlinks, and works with attaform's ESM-only `exports` map.\n *\n * Returns:\n * - `{ major: 3 | 4 }` when zod is resolvable AND its `version`\n * field parses to a known major;\n * - `{ major: 'missing' }` when zod can't be resolved at all;\n * - `{ major: 'unknown' }` for any other failure (corrupted\n * package.json, unexpected version string, monorepo edge case).\n */\nexport function detectZodMajor(consumerRootDir: string): ZodMajorDetection {\n const consumerURL = pathToFileURL(join(consumerRootDir, 'package.json')).href\n let resolved: string\n try {\n resolved = import.meta.resolve('zod/package.json', consumerURL)\n } catch {\n return { major: 'missing' }\n }\n try {\n const pkg = JSON.parse(readFileSync(fileURLToPath(resolved), 'utf8')) as { version?: unknown }\n const version = pkg.version\n if (typeof version !== 'string') return { major: 'unknown' }\n const major = Number.parseInt(version.split('.')[0] ?? '', 10)\n if (major === 3) return { major: 3 }\n if (major === 4) return { major: 4 }\n return { major: 'unknown' }\n } catch {\n return { major: 'unknown' }\n }\n}\n\n/**\n * One-shot latch so a plugin warns about an unclassifiable Zod version\n * only once, however many times its detection runs across a build.\n */\nexport interface ZodDetectionWarnState {\n warned: boolean\n}\n\nfunction missingZodError(tag: string): string {\n return (\n `[${tag}] zod is not installed. attaform requires zod as a peer dependency. ` +\n 'Install `zod@^3` or `zod@^4`, OR pass `attaform({ resolveZodAlias: false })` ' +\n 'to keep the runtime-dispatch unified entry (and silence this check).'\n )\n}\n\nfunction unclassifiableZodWarning(tag: string): string {\n return (\n `[${tag}] Could not classify the installed Zod major (corrupted package.json, ` +\n 'monorepo edge case, or an unexpected version string). Falling through to runtime ' +\n 'dispatch — both Zod adapters will ship in the bundle. ' +\n 'Pass `attaform({ resolveZodAlias: false })` to silence this warning.'\n )\n}\n\n/**\n * Resolve the rewrite target for the unified `attaform/zod` specifier,\n * shared by every bundler plugin so they diagnose identically:\n * - returns `attaform/zod-v3` / `attaform/zod-v4` when the consumer's\n * Zod major is detected;\n * - returns `null` to leave `attaform/zod` on its runtime-dispatch\n * entry, either because `resolveZodAlias` is off or because the\n * version could not be classified (warned once via `warnState`);\n * - throws when zod is not installed at all, a fatal misconfiguration\n * the consumer must fix.\n *\n * `tag` brands the diagnostics (`attaform/vite`, `attaform/rollup`, etc).\n * `resolveZodAlias` and `warnState` are supplied by the calling plugin:\n * its consumer-facing default and its per-instance warn latch live at the\n * plugin surface, not here.\n */\nexport function resolveZodAliasTarget(\n consumerRootDir: string,\n tag: string,\n resolveZodAlias: boolean,\n warnState: ZodDetectionWarnState\n): string | null {\n if (!resolveZodAlias) return null\n const detection = detectZodMajor(consumerRootDir)\n if (detection.major === 'missing') {\n throw new Error(missingZodError(tag))\n }\n if (detection.major === 'unknown') {\n if (!warnState.warned) {\n warnState.warned = true\n console.warn(unclassifiableZodWarning(tag))\n }\n return null\n }\n return detection.major === 4 ? ZOD_V4_SPECIFIER : ZOD_V3_SPECIFIER\n}\n"],"names":[],"mappings":";;;;AAwBO,MAAM,gBAAA,GAAmB,iBAAA;AACzB,MAAM,gBAAA,GAAmB,iBAAA;AA4BzB,MAAM,+BAAA,GAAkC;AAQxC,SAAS,yBAAyB,MAAA,EAAyB;AAChE,EAAA,OAAO,+BAAA,CAAgC,KAAK,MAAM,CAAA;AACpD;AAqBO,SAAS,eAAe,eAAA,EAA4C;AACzE,EAAA,MAAM,cAAc,aAAA,CAAc,IAAA,CAAK,eAAA,EAAiB,cAAc,CAAC,CAAA,CAAE,IAAA;AACzE,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,QAAA,GAAW,MAAA,CAAA,IAAA,CAAY,OAAA,CAAQ,kBAAA,EAAoB,WAAW,CAAA;AAAA,EAChE,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B;AACA,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,KAAK,KAAA,CAAM,YAAA,CAAa,cAAc,QAAQ,CAAA,EAAG,MAAM,CAAC,CAAA;AACpE,IAAA,MAAM,UAAU,GAAA,CAAI,OAAA;AACpB,IAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,EAAE,OAAO,SAAA,EAAU;AAC3D,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,IAAK,EAAA,EAAI,EAAE,CAAA;AAC7D,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,EAAE,OAAO,CAAA,EAAE;AACnC,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,EAAE,OAAO,CAAA,EAAE;AACnC,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B;AACF;AAUA,SAAS,gBAAgB,GAAA,EAAqB;AAC5C,EAAA,OACE,IAAI,GAAG,CAAA,2NAAA,CAAA;AAIX;AAEA,SAAS,yBAAyB,GAAA,EAAqB;AACrD,EAAA,OACE,IAAI,GAAG,CAAA,wRAAA,CAAA;AAKX;AAkBO,SAAS,qBAAA,CACd,eAAA,EACA,GAAA,EACA,eAAA,EACA,SAAA,EACe;AACf,EAAA,IAAI,CAAC,iBAAiB,OAAO,IAAA;AAC7B,EAAA,MAAM,SAAA,GAAY,eAAe,eAAe,CAAA;AAChD,EAAA,IAAI,SAAA,CAAU,UAAU,SAAA,EAAW;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,eAAA,CAAgB,GAAG,CAAC,CAAA;AAAA,EACtC;AACA,EAAA,IAAI,SAAA,CAAU,UAAU,SAAA,EAAW;AACjC,IAAA,IAAI,CAAC,UAAU,MAAA,EAAQ;AACrB,MAAA,SAAA,CAAU,MAAA,GAAS,IAAA;AACnB,MAAA,OAAA,CAAQ,IAAA,CAAK,wBAAA,CAAyB,GAAG,CAAC,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,SAAA,CAAU,KAAA,KAAU,CAAA,GAAI,gBAAA,GAAmB,gBAAA;AACpD;;;;"}
|