attaform 0.15.0 → 0.16.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.
Files changed (98) hide show
  1. package/README.md +21 -11
  2. package/dist/chunks/devtools.cjs +4 -4
  3. package/dist/chunks/devtools.cjs.map +1 -1
  4. package/dist/chunks/devtools.mjs +2 -2
  5. package/dist/chunks/indexeddb.cjs +4 -4
  6. package/dist/chunks/indexeddb.cjs.map +1 -1
  7. package/dist/chunks/indexeddb.mjs +1 -1
  8. package/dist/chunks/local-storage.cjs +2 -2
  9. package/dist/chunks/local-storage.cjs.map +1 -1
  10. package/dist/chunks/local-storage.mjs +1 -1
  11. package/dist/chunks/session-storage.cjs +2 -2
  12. package/dist/chunks/session-storage.cjs.map +1 -1
  13. package/dist/chunks/session-storage.mjs +1 -1
  14. package/dist/index.cjs +23 -22
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +76 -71
  17. package/dist/index.d.mts +76 -71
  18. package/dist/index.d.ts +76 -71
  19. package/dist/index.mjs +6 -6
  20. package/dist/nuxt.cjs +5 -11
  21. package/dist/nuxt.cjs.map +1 -1
  22. package/dist/nuxt.d.cts +8 -0
  23. package/dist/nuxt.d.mts +8 -0
  24. package/dist/nuxt.d.ts +8 -0
  25. package/dist/nuxt.mjs +6 -12
  26. package/dist/nuxt.mjs.map +1 -1
  27. package/dist/runtime/plugins/attaform.cjs +3 -2
  28. package/dist/runtime/plugins/attaform.cjs.map +1 -1
  29. package/dist/runtime/plugins/attaform.mjs +2 -1
  30. package/dist/runtime/plugins/attaform.mjs.map +1 -1
  31. package/dist/shared/{attaform.BwaYWtMs.d.cts → attaform.B7rzpK1U.d.cts} +34 -5
  32. package/dist/shared/{attaform.BwaYWtMs.d.mts → attaform.B7rzpK1U.d.mts} +34 -5
  33. package/dist/shared/{attaform.BwaYWtMs.d.ts → attaform.B7rzpK1U.d.ts} +34 -5
  34. package/dist/shared/attaform.BAuJTWuT.d.mts +84 -0
  35. package/dist/shared/{attaform.CRk8NhlD.mjs → attaform.BfMxsfmE.mjs} +428 -49
  36. package/dist/shared/attaform.BfMxsfmE.mjs.map +1 -0
  37. package/dist/shared/attaform.Bp1c-uGF.cjs +1561 -0
  38. package/dist/shared/attaform.Bp1c-uGF.cjs.map +1 -0
  39. package/dist/shared/{attaform.CDJVeoJU.cjs → attaform.C9Ph2SMx.cjs} +49 -42
  40. package/dist/shared/{attaform.qxyip_aN.mjs.map → attaform.C9Ph2SMx.cjs.map} +1 -1
  41. package/dist/shared/attaform.CINUMjPq.mjs +29 -0
  42. package/dist/shared/attaform.CINUMjPq.mjs.map +1 -0
  43. package/dist/shared/attaform.CJttVxRj.cjs +32 -0
  44. package/dist/shared/attaform.CJttVxRj.cjs.map +1 -0
  45. package/dist/shared/{attaform.CPx7zTgS.d.mts → attaform.CVv9Oh0a.d.mts} +9 -7
  46. package/dist/shared/{attaform.riAENZQM.d.ts → attaform.CWCx2r0x.d.ts} +9 -7
  47. package/dist/shared/attaform.CvOXSpCb.mjs +1908 -0
  48. package/dist/shared/attaform.CvOXSpCb.mjs.map +1 -0
  49. package/dist/shared/{attaform.qxyip_aN.mjs → attaform.DILbdvfo.mjs} +12 -5
  50. package/dist/shared/{attaform.CDJVeoJU.cjs.map → attaform.DILbdvfo.mjs.map} +1 -1
  51. package/dist/shared/attaform.DdnithOf.mjs +1555 -0
  52. package/dist/shared/attaform.DdnithOf.mjs.map +1 -0
  53. package/dist/shared/attaform.DfrYByDj.cjs +1916 -0
  54. package/dist/shared/attaform.DfrYByDj.cjs.map +1 -0
  55. package/dist/shared/{attaform.D-eHWfVx.d.cts → attaform.Dq5BabH1.d.cts} +9 -7
  56. package/dist/shared/{attaform.BOi138GE.cjs → attaform.c_NzdRyc.cjs} +4 -4
  57. package/dist/shared/{attaform.BOi138GE.cjs.map → attaform.c_NzdRyc.cjs.map} +1 -1
  58. package/dist/shared/{attaform.DXye3JKf.mjs → attaform.jrxE_xZw.mjs} +2 -2
  59. package/dist/shared/{attaform.DXye3JKf.mjs.map → attaform.jrxE_xZw.mjs.map} +1 -1
  60. package/dist/shared/attaform.ls_7jBYc.d.ts +84 -0
  61. package/dist/shared/{attaform.BgYBU8gV.cjs → attaform.rIRYSUI1.cjs} +461 -61
  62. package/dist/shared/attaform.rIRYSUI1.cjs.map +1 -0
  63. package/dist/shared/attaform.xIcmqscx.d.cts +84 -0
  64. package/dist/vite.cjs +62 -9
  65. package/dist/vite.cjs.map +1 -1
  66. package/dist/vite.d.cts +23 -32
  67. package/dist/vite.d.mts +23 -32
  68. package/dist/vite.d.ts +23 -32
  69. package/dist/vite.mjs +62 -9
  70. package/dist/vite.mjs.map +1 -1
  71. package/dist/zod-v3.cjs +9 -1553
  72. package/dist/zod-v3.cjs.map +1 -1
  73. package/dist/zod-v3.d.cts +1 -1
  74. package/dist/zod-v3.d.mts +1 -1
  75. package/dist/zod-v3.d.ts +1 -1
  76. package/dist/zod-v3.mjs +3 -1553
  77. package/dist/zod-v3.mjs.map +1 -1
  78. package/dist/zod-v4.cjs +21 -0
  79. package/dist/zod-v4.cjs.map +1 -0
  80. package/dist/zod-v4.d.cts +104 -0
  81. package/dist/zod-v4.d.mts +104 -0
  82. package/dist/zod-v4.d.ts +104 -0
  83. package/dist/zod-v4.mjs +4 -0
  84. package/dist/zod-v4.mjs.map +1 -0
  85. package/dist/zod.cjs +19 -1900
  86. package/dist/zod.cjs.map +1 -1
  87. package/dist/zod.d.cts +28 -156
  88. package/dist/zod.d.mts +28 -156
  89. package/dist/zod.d.ts +28 -156
  90. package/dist/zod.mjs +19 -1896
  91. package/dist/zod.mjs.map +1 -1
  92. package/package.json +6 -2
  93. package/dist/shared/attaform.BgYBU8gV.cjs.map +0 -1
  94. package/dist/shared/attaform.CRk8NhlD.mjs.map +0 -1
  95. package/dist/shared/attaform.RypIkgVy.cjs +0 -417
  96. package/dist/shared/attaform.RypIkgVy.cjs.map +0 -1
  97. package/dist/shared/attaform.a99dQV7Q.mjs +0 -392
  98. package/dist/shared/attaform.a99dQV7Q.mjs.map +0 -1
package/dist/zod.d.cts CHANGED
@@ -1,79 +1,40 @@
1
1
  import { z } from 'zod';
2
- import { F as FormKey, b as AbstractSchema, U as UseFormConfiguration, G as GenericForm, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType, n as FieldMetaPayload } from './shared/attaform.0Gxd_OOx.cjs';
3
- export { ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.cjs';
4
- export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.D-eHWfVx.cjs';
5
- import { a as AttaformError } from './shared/attaform.BwaYWtMs.cjs';
2
+ import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType } from './shared/attaform.0Gxd_OOx.cjs';
3
+ export { n as FieldMetaPayload, ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.cjs';
4
+ export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.Dq5BabH1.cjs';
5
+ export { f as fieldMeta, w as withMeta } from './shared/attaform.xIcmqscx.cjs';
6
6
  import 'vue';
7
7
 
8
8
  /**
9
- * Wrap a Zod v4 `ZodObject` schema in an `AbstractSchema` factory.
9
+ * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches
10
+ * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the
11
+ * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes
12
+ * to the v3 wrapper, which already accepts both Zod v3 input and
13
+ * `AbstractSchema` directly via its built-in shape branch.
10
14
  *
11
- * Most consumers never call this directly `useForm` from
12
- * `attaform/zod` does the wrapping automatically. Reach for
13
- * it when you need an adapter outside of `useForm` (e.g. validating
14
- * data with the same library used elsewhere in the form runtime, or
15
- * exposing the adapter to a custom integration).
15
+ * This module is the FALLBACK path. Vite consumers see the
16
+ * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`
17
+ * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build
18
+ * time in that case this dispatch never runs and the consumer
19
+ * bundle ships only the matching adapter. Other bundlers (and
20
+ * non-bundled ESM consumption) hit this dispatch instead, paying a
21
+ * modest size cost for the convenience of a single hello-world import.
16
22
  *
17
- * Throws if the schema isn't Zod v4, or contains kinds the adapter
18
- * cannot represent (`z.promise`, `z.custom`, `z.templateLiteral`,
19
- * recursive `z.lazy(...)`).
23
+ * Power users who want a guaranteed lean bundle on non-Vite tooling
24
+ * can import directly from `attaform/zod-v3` or `attaform/zod-v4`
25
+ * those subpaths are never rewritten and never load the other
26
+ * adapter.
20
27
  */
21
- declare function zodV4Adapter<FormSchema extends z.ZodObject, Form extends z.infer<FormSchema>>(rootSchema: FormSchema): (formKey: FormKey) => AbstractSchema<Form, Form>;
22
28
 
23
29
  /**
24
- * Thrown when a Zod schema includes a kind the form library cannot
25
- * represent: `z.promise`, `z.custom`, `z.templateLiteral`, or a
26
- * recursive `z.lazy(...)` that loops back into itself.
30
+ * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4
31
+ * schemas; the runtime picks the right adapter from the schema's
32
+ * shape.
27
33
  *
28
- * The error message includes the dotted path of the offending node
29
- * so you can locate it without traversing the whole schema.
30
- */
31
- declare class UnsupportedSchemaError extends AttaformError {
32
- }
33
-
34
- /**
35
- * The single file that reads Zod v4's internal `def` shape. Every other
36
- * file in the zod-v4 adapter uses these public-shaped accessors — future
37
- * Zod minor bumps that reshape internals touch only this file.
38
- *
39
- * Design principle: treat `schema.def.*` as an unstable surface, even when
40
- * Zod's docs say otherwise. Each helper returns a narrow, well-typed slice;
41
- * no adapter code outside this file does shape-based pattern matching on
42
- * `def`.
43
- */
44
-
45
- /**
46
- * Stable kind discriminant for a Zod v4 schema. Returned by
47
- * `kindOf(schema)`. Use when building a custom integration that
48
- * needs to branch on schema shape — most consumers don't need this.
49
- */
50
- type ZodKind = 'object' | 'array' | 'set' | 'record' | 'tuple' | 'union' | 'discriminated-union' | 'string' | 'number' | 'boolean' | 'bigint' | 'date' | 'enum' | 'literal' | 'null' | 'undefined' | 'any' | 'unknown' | 'optional' | 'nullable' | 'default' | 'pipe' | 'readonly' | 'nan' | 'void' | 'never' | 'lazy' | 'intersection' | 'catch' | 'promise' | 'custom' | 'template-literal';
51
- /**
52
- * Inspect a Zod v4 schema and return its `ZodKind`. Returns
53
- * `'unknown'` for non-Zod inputs and unrecognised shapes.
54
- *
55
- * Useful when writing introspection helpers that branch on schema
56
- * structure (e.g. custom error formatters or doc generators).
57
- */
58
- declare function kindOf(schema: unknown): ZodKind;
59
- /**
60
- * Verify a schema is Zod v4. Throws a clear error if it's a v3
61
- * schema mistakenly imported through `attaform/zod`.
62
- *
63
- * Most consumers never call this directly — the v4 adapter calls it
64
- * internally on every schema. Reach for it only when wiring a custom
65
- * adapter that needs the same guard.
66
- */
67
- declare function assertZodVersion(schema: unknown): void;
68
-
69
- /**
70
- * Zod v4 adapter entry point. Re-exports the adapter + the useForm
71
- * wrapper that threads zod-v4-specific schema types through
72
- * useAbstractForm.
73
- */
74
-
75
- /**
76
- * Create a form bound to a Zod v4 schema.
34
+ * Type inference targets Zod v4 the recommended major. Consumers
35
+ * still on Zod v3 get correct runtime behavior here, but the strongest
36
+ * TypeScript inference comes from importing `attaform/zod-v3`
37
+ * directly.
77
38
  *
78
39
  * ```ts
79
40
  * import { useForm } from 'attaform/zod'
@@ -84,100 +45,11 @@ declare function assertZodVersion(schema: unknown): void;
84
45
  * email: z.email(),
85
46
  * password: z.string().min(8),
86
47
  * }),
87
- * defaultValues: { email: '' },
88
48
  * })
89
49
  * ```
90
- *
91
- * Returns a form API exposing `register`, `values`, `errors`,
92
- * `fields`, `setValue`, `handleSubmit`, `meta`, field-array
93
- * helpers, and more. See `UseFormReturnType` for the full
94
- * surface.
95
- *
96
- * For Zod v3, import from `attaform/zod-v3` instead.
97
50
  */
98
51
  declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseFormConfiguration<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never, AbstractSchema<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>, DeepPartial<DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>>>, 'schema' | 'validateOn' | 'debounceMs'> & {
99
52
  schema: Schema;
100
53
  } & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
101
54
 
102
- /**
103
- * Field-metadata write/read API for the Zod v4 adapter.
104
- *
105
- * Backed by Zod 4's native `z.registry<T>()` mechanism — the schema
106
- * carries the metadata directly through `schema.register(fieldMeta,
107
- * payload)` (returns the schema, chainable) or the `withMeta()`
108
- * helper (same effect, version-agnostic across the v3 / v4 adapter
109
- * split).
110
- *
111
- * **Registration patterns:** both styles work — register on whatever
112
- * schema reference you assign into the parent's shape, OR on the
113
- * inner schema before wrapping. The adapter's resolver tries the
114
- * walker-returned schema first, then falls back to the peeled
115
- * inner so either ordering hits:
116
- *
117
- * // both equivalent — registry hits at lookup time
118
- * withMeta(z.string(), { label: 'Email' }).optional()
119
- * withMeta(z.string().optional(), { label: 'Email' })
120
- * z.string().optional().register(fieldMeta, { label: 'Email' })
121
- * z.string().register(fieldMeta, { label: 'Email' }).optional()
122
- *
123
- * The path walker returns the wrapper at terminal positions
124
- * (`['email']` against `{ email: z.string().optional() }` resolves
125
- * to `ZodOptional<ZodString>`) and peels at intermediate descent
126
- * (`['address', 'street']` peels through `address`'s wrapper to
127
- * reach the inner object). The two-stage lookup covers both leaf
128
- * and container registrations symmetrically.
129
- */
130
-
131
- /**
132
- * The shared registry every Attaform-aware Zod 4 schema can register
133
- * field metadata against. One module-scoped instance per consumer
134
- * project — re-exported from `attaform/zod` so user code reads the
135
- * same registry the runtime does.
136
- *
137
- * Consumers extending `FieldMetaPayload` via declaration merging
138
- * automatically get the richer payload type at every `register` /
139
- * `add` / `get` call site.
140
- *
141
- * **Shared-instance disambiguation.** A single schema instance reused
142
- * at multiple form paths (e.g. one address schema bound to both
143
- * `pickup` and `delivery`) can carry distinct metadata per path —
144
- * even via the canonical `schema.register(fieldMeta, payload)` chain.
145
- * Internally we maintain a parallel WeakMap of payload LISTS indexed
146
- * per schema reference, and the path-resolver walks the form's
147
- * schema tree counting per-schema occurrences to pick the right
148
- * payload for each path. Object literals evaluate left-to-right, so
149
- * registration order matches tree-walk order, and shared schemas
150
- * pair their two registrations to the two paths correctly:
151
- *
152
- * z.object({
153
- * pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
154
- * delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
155
- * })
156
- * // form.fields('pickup').label → 'Pickup address'
157
- * // form.fields('delivery').label → 'Delivery address'
158
- *
159
- * Schemas reused via `withMeta()` get a fresh clone per call (see
160
- * `withMeta` below), so they never share a registry slot in the
161
- * first place.
162
- */
163
- declare const fieldMeta: z.core.$ZodRegistry<FieldMetaPayload, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
164
- /**
165
- * Attach `payload` to `schema` in the shared `fieldMeta` registry
166
- * and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
167
- * `withMeta()`; user code that uses this helper reads the same on
168
- * either adapter.
169
- *
170
- * Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
171
- * Prefer the native chain for v4-only code; reach for `withMeta`
172
- * when authoring schema modules that may need to compile under both
173
- * adapters.
174
- *
175
- * Registers on the schema reference passed in. See the
176
- * "Registration rule" note in this file's header — register on the
177
- * inner schema before wrapping with `.optional()` / `.nullable()` /
178
- * `.default()` / etc.
179
- */
180
- declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
181
-
182
- export { FieldMetaPayload, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
183
- export type { ZodKind };
55
+ export { useForm };
package/dist/zod.d.mts CHANGED
@@ -1,79 +1,40 @@
1
1
  import { z } from 'zod';
2
- import { F as FormKey, b as AbstractSchema, U as UseFormConfiguration, G as GenericForm, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType, n as FieldMetaPayload } from './shared/attaform.0Gxd_OOx.mjs';
3
- export { ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.mjs';
4
- export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CPx7zTgS.mjs';
5
- import { a as AttaformError } from './shared/attaform.BwaYWtMs.mjs';
2
+ import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType } from './shared/attaform.0Gxd_OOx.mjs';
3
+ export { n as FieldMetaPayload, ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.mjs';
4
+ export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CVv9Oh0a.mjs';
5
+ export { f as fieldMeta, w as withMeta } from './shared/attaform.BAuJTWuT.mjs';
6
6
  import 'vue';
7
7
 
8
8
  /**
9
- * Wrap a Zod v4 `ZodObject` schema in an `AbstractSchema` factory.
9
+ * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches
10
+ * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the
11
+ * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes
12
+ * to the v3 wrapper, which already accepts both Zod v3 input and
13
+ * `AbstractSchema` directly via its built-in shape branch.
10
14
  *
11
- * Most consumers never call this directly `useForm` from
12
- * `attaform/zod` does the wrapping automatically. Reach for
13
- * it when you need an adapter outside of `useForm` (e.g. validating
14
- * data with the same library used elsewhere in the form runtime, or
15
- * exposing the adapter to a custom integration).
15
+ * This module is the FALLBACK path. Vite consumers see the
16
+ * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`
17
+ * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build
18
+ * time in that case this dispatch never runs and the consumer
19
+ * bundle ships only the matching adapter. Other bundlers (and
20
+ * non-bundled ESM consumption) hit this dispatch instead, paying a
21
+ * modest size cost for the convenience of a single hello-world import.
16
22
  *
17
- * Throws if the schema isn't Zod v4, or contains kinds the adapter
18
- * cannot represent (`z.promise`, `z.custom`, `z.templateLiteral`,
19
- * recursive `z.lazy(...)`).
23
+ * Power users who want a guaranteed lean bundle on non-Vite tooling
24
+ * can import directly from `attaform/zod-v3` or `attaform/zod-v4`
25
+ * those subpaths are never rewritten and never load the other
26
+ * adapter.
20
27
  */
21
- declare function zodV4Adapter<FormSchema extends z.ZodObject, Form extends z.infer<FormSchema>>(rootSchema: FormSchema): (formKey: FormKey) => AbstractSchema<Form, Form>;
22
28
 
23
29
  /**
24
- * Thrown when a Zod schema includes a kind the form library cannot
25
- * represent: `z.promise`, `z.custom`, `z.templateLiteral`, or a
26
- * recursive `z.lazy(...)` that loops back into itself.
30
+ * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4
31
+ * schemas; the runtime picks the right adapter from the schema's
32
+ * shape.
27
33
  *
28
- * The error message includes the dotted path of the offending node
29
- * so you can locate it without traversing the whole schema.
30
- */
31
- declare class UnsupportedSchemaError extends AttaformError {
32
- }
33
-
34
- /**
35
- * The single file that reads Zod v4's internal `def` shape. Every other
36
- * file in the zod-v4 adapter uses these public-shaped accessors — future
37
- * Zod minor bumps that reshape internals touch only this file.
38
- *
39
- * Design principle: treat `schema.def.*` as an unstable surface, even when
40
- * Zod's docs say otherwise. Each helper returns a narrow, well-typed slice;
41
- * no adapter code outside this file does shape-based pattern matching on
42
- * `def`.
43
- */
44
-
45
- /**
46
- * Stable kind discriminant for a Zod v4 schema. Returned by
47
- * `kindOf(schema)`. Use when building a custom integration that
48
- * needs to branch on schema shape — most consumers don't need this.
49
- */
50
- type ZodKind = 'object' | 'array' | 'set' | 'record' | 'tuple' | 'union' | 'discriminated-union' | 'string' | 'number' | 'boolean' | 'bigint' | 'date' | 'enum' | 'literal' | 'null' | 'undefined' | 'any' | 'unknown' | 'optional' | 'nullable' | 'default' | 'pipe' | 'readonly' | 'nan' | 'void' | 'never' | 'lazy' | 'intersection' | 'catch' | 'promise' | 'custom' | 'template-literal';
51
- /**
52
- * Inspect a Zod v4 schema and return its `ZodKind`. Returns
53
- * `'unknown'` for non-Zod inputs and unrecognised shapes.
54
- *
55
- * Useful when writing introspection helpers that branch on schema
56
- * structure (e.g. custom error formatters or doc generators).
57
- */
58
- declare function kindOf(schema: unknown): ZodKind;
59
- /**
60
- * Verify a schema is Zod v4. Throws a clear error if it's a v3
61
- * schema mistakenly imported through `attaform/zod`.
62
- *
63
- * Most consumers never call this directly — the v4 adapter calls it
64
- * internally on every schema. Reach for it only when wiring a custom
65
- * adapter that needs the same guard.
66
- */
67
- declare function assertZodVersion(schema: unknown): void;
68
-
69
- /**
70
- * Zod v4 adapter entry point. Re-exports the adapter + the useForm
71
- * wrapper that threads zod-v4-specific schema types through
72
- * useAbstractForm.
73
- */
74
-
75
- /**
76
- * Create a form bound to a Zod v4 schema.
34
+ * Type inference targets Zod v4 the recommended major. Consumers
35
+ * still on Zod v3 get correct runtime behavior here, but the strongest
36
+ * TypeScript inference comes from importing `attaform/zod-v3`
37
+ * directly.
77
38
  *
78
39
  * ```ts
79
40
  * import { useForm } from 'attaform/zod'
@@ -84,100 +45,11 @@ declare function assertZodVersion(schema: unknown): void;
84
45
  * email: z.email(),
85
46
  * password: z.string().min(8),
86
47
  * }),
87
- * defaultValues: { email: '' },
88
48
  * })
89
49
  * ```
90
- *
91
- * Returns a form API exposing `register`, `values`, `errors`,
92
- * `fields`, `setValue`, `handleSubmit`, `meta`, field-array
93
- * helpers, and more. See `UseFormReturnType` for the full
94
- * surface.
95
- *
96
- * For Zod v3, import from `attaform/zod-v3` instead.
97
50
  */
98
51
  declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseFormConfiguration<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never, AbstractSchema<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>, DeepPartial<DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>>>, 'schema' | 'validateOn' | 'debounceMs'> & {
99
52
  schema: Schema;
100
53
  } & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
101
54
 
102
- /**
103
- * Field-metadata write/read API for the Zod v4 adapter.
104
- *
105
- * Backed by Zod 4's native `z.registry<T>()` mechanism — the schema
106
- * carries the metadata directly through `schema.register(fieldMeta,
107
- * payload)` (returns the schema, chainable) or the `withMeta()`
108
- * helper (same effect, version-agnostic across the v3 / v4 adapter
109
- * split).
110
- *
111
- * **Registration patterns:** both styles work — register on whatever
112
- * schema reference you assign into the parent's shape, OR on the
113
- * inner schema before wrapping. The adapter's resolver tries the
114
- * walker-returned schema first, then falls back to the peeled
115
- * inner so either ordering hits:
116
- *
117
- * // both equivalent — registry hits at lookup time
118
- * withMeta(z.string(), { label: 'Email' }).optional()
119
- * withMeta(z.string().optional(), { label: 'Email' })
120
- * z.string().optional().register(fieldMeta, { label: 'Email' })
121
- * z.string().register(fieldMeta, { label: 'Email' }).optional()
122
- *
123
- * The path walker returns the wrapper at terminal positions
124
- * (`['email']` against `{ email: z.string().optional() }` resolves
125
- * to `ZodOptional<ZodString>`) and peels at intermediate descent
126
- * (`['address', 'street']` peels through `address`'s wrapper to
127
- * reach the inner object). The two-stage lookup covers both leaf
128
- * and container registrations symmetrically.
129
- */
130
-
131
- /**
132
- * The shared registry every Attaform-aware Zod 4 schema can register
133
- * field metadata against. One module-scoped instance per consumer
134
- * project — re-exported from `attaform/zod` so user code reads the
135
- * same registry the runtime does.
136
- *
137
- * Consumers extending `FieldMetaPayload` via declaration merging
138
- * automatically get the richer payload type at every `register` /
139
- * `add` / `get` call site.
140
- *
141
- * **Shared-instance disambiguation.** A single schema instance reused
142
- * at multiple form paths (e.g. one address schema bound to both
143
- * `pickup` and `delivery`) can carry distinct metadata per path —
144
- * even via the canonical `schema.register(fieldMeta, payload)` chain.
145
- * Internally we maintain a parallel WeakMap of payload LISTS indexed
146
- * per schema reference, and the path-resolver walks the form's
147
- * schema tree counting per-schema occurrences to pick the right
148
- * payload for each path. Object literals evaluate left-to-right, so
149
- * registration order matches tree-walk order, and shared schemas
150
- * pair their two registrations to the two paths correctly:
151
- *
152
- * z.object({
153
- * pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
154
- * delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
155
- * })
156
- * // form.fields('pickup').label → 'Pickup address'
157
- * // form.fields('delivery').label → 'Delivery address'
158
- *
159
- * Schemas reused via `withMeta()` get a fresh clone per call (see
160
- * `withMeta` below), so they never share a registry slot in the
161
- * first place.
162
- */
163
- declare const fieldMeta: z.core.$ZodRegistry<FieldMetaPayload, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
164
- /**
165
- * Attach `payload` to `schema` in the shared `fieldMeta` registry
166
- * and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
167
- * `withMeta()`; user code that uses this helper reads the same on
168
- * either adapter.
169
- *
170
- * Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
171
- * Prefer the native chain for v4-only code; reach for `withMeta`
172
- * when authoring schema modules that may need to compile under both
173
- * adapters.
174
- *
175
- * Registers on the schema reference passed in. See the
176
- * "Registration rule" note in this file's header — register on the
177
- * inner schema before wrapping with `.optional()` / `.nullable()` /
178
- * `.default()` / etc.
179
- */
180
- declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
181
-
182
- export { FieldMetaPayload, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
183
- export type { ZodKind };
55
+ export { useForm };
package/dist/zod.d.ts CHANGED
@@ -1,79 +1,40 @@
1
1
  import { z } from 'zod';
2
- import { F as FormKey, b as AbstractSchema, U as UseFormConfiguration, G as GenericForm, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType, n as FieldMetaPayload } from './shared/attaform.0Gxd_OOx.js';
3
- export { ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.js';
4
- export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.riAENZQM.js';
5
- import { a as AttaformError } from './shared/attaform.BwaYWtMs.js';
2
+ import { U as UseFormConfiguration, G as GenericForm, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ae as ValidateOnConfig, d as UseFormReturnType } from './shared/attaform.0Gxd_OOx.js';
3
+ export { n as FieldMetaPayload, ac as Unset, am as isUnset, ao as unset } from './shared/attaform.0Gxd_OOx.js';
4
+ export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CWCx2r0x.js';
5
+ export { f as fieldMeta, w as withMeta } from './shared/attaform.ls_7jBYc.js';
6
6
  import 'vue';
7
7
 
8
8
  /**
9
- * Wrap a Zod v4 `ZodObject` schema in an `AbstractSchema` factory.
9
+ * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches
10
+ * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the
11
+ * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes
12
+ * to the v3 wrapper, which already accepts both Zod v3 input and
13
+ * `AbstractSchema` directly via its built-in shape branch.
10
14
  *
11
- * Most consumers never call this directly `useForm` from
12
- * `attaform/zod` does the wrapping automatically. Reach for
13
- * it when you need an adapter outside of `useForm` (e.g. validating
14
- * data with the same library used elsewhere in the form runtime, or
15
- * exposing the adapter to a custom integration).
15
+ * This module is the FALLBACK path. Vite consumers see the
16
+ * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`
17
+ * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build
18
+ * time in that case this dispatch never runs and the consumer
19
+ * bundle ships only the matching adapter. Other bundlers (and
20
+ * non-bundled ESM consumption) hit this dispatch instead, paying a
21
+ * modest size cost for the convenience of a single hello-world import.
16
22
  *
17
- * Throws if the schema isn't Zod v4, or contains kinds the adapter
18
- * cannot represent (`z.promise`, `z.custom`, `z.templateLiteral`,
19
- * recursive `z.lazy(...)`).
23
+ * Power users who want a guaranteed lean bundle on non-Vite tooling
24
+ * can import directly from `attaform/zod-v3` or `attaform/zod-v4`
25
+ * those subpaths are never rewritten and never load the other
26
+ * adapter.
20
27
  */
21
- declare function zodV4Adapter<FormSchema extends z.ZodObject, Form extends z.infer<FormSchema>>(rootSchema: FormSchema): (formKey: FormKey) => AbstractSchema<Form, Form>;
22
28
 
23
29
  /**
24
- * Thrown when a Zod schema includes a kind the form library cannot
25
- * represent: `z.promise`, `z.custom`, `z.templateLiteral`, or a
26
- * recursive `z.lazy(...)` that loops back into itself.
30
+ * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4
31
+ * schemas; the runtime picks the right adapter from the schema's
32
+ * shape.
27
33
  *
28
- * The error message includes the dotted path of the offending node
29
- * so you can locate it without traversing the whole schema.
30
- */
31
- declare class UnsupportedSchemaError extends AttaformError {
32
- }
33
-
34
- /**
35
- * The single file that reads Zod v4's internal `def` shape. Every other
36
- * file in the zod-v4 adapter uses these public-shaped accessors — future
37
- * Zod minor bumps that reshape internals touch only this file.
38
- *
39
- * Design principle: treat `schema.def.*` as an unstable surface, even when
40
- * Zod's docs say otherwise. Each helper returns a narrow, well-typed slice;
41
- * no adapter code outside this file does shape-based pattern matching on
42
- * `def`.
43
- */
44
-
45
- /**
46
- * Stable kind discriminant for a Zod v4 schema. Returned by
47
- * `kindOf(schema)`. Use when building a custom integration that
48
- * needs to branch on schema shape — most consumers don't need this.
49
- */
50
- type ZodKind = 'object' | 'array' | 'set' | 'record' | 'tuple' | 'union' | 'discriminated-union' | 'string' | 'number' | 'boolean' | 'bigint' | 'date' | 'enum' | 'literal' | 'null' | 'undefined' | 'any' | 'unknown' | 'optional' | 'nullable' | 'default' | 'pipe' | 'readonly' | 'nan' | 'void' | 'never' | 'lazy' | 'intersection' | 'catch' | 'promise' | 'custom' | 'template-literal';
51
- /**
52
- * Inspect a Zod v4 schema and return its `ZodKind`. Returns
53
- * `'unknown'` for non-Zod inputs and unrecognised shapes.
54
- *
55
- * Useful when writing introspection helpers that branch on schema
56
- * structure (e.g. custom error formatters or doc generators).
57
- */
58
- declare function kindOf(schema: unknown): ZodKind;
59
- /**
60
- * Verify a schema is Zod v4. Throws a clear error if it's a v3
61
- * schema mistakenly imported through `attaform/zod`.
62
- *
63
- * Most consumers never call this directly — the v4 adapter calls it
64
- * internally on every schema. Reach for it only when wiring a custom
65
- * adapter that needs the same guard.
66
- */
67
- declare function assertZodVersion(schema: unknown): void;
68
-
69
- /**
70
- * Zod v4 adapter entry point. Re-exports the adapter + the useForm
71
- * wrapper that threads zod-v4-specific schema types through
72
- * useAbstractForm.
73
- */
74
-
75
- /**
76
- * Create a form bound to a Zod v4 schema.
34
+ * Type inference targets Zod v4 the recommended major. Consumers
35
+ * still on Zod v3 get correct runtime behavior here, but the strongest
36
+ * TypeScript inference comes from importing `attaform/zod-v3`
37
+ * directly.
77
38
  *
78
39
  * ```ts
79
40
  * import { useForm } from 'attaform/zod'
@@ -84,100 +45,11 @@ declare function assertZodVersion(schema: unknown): void;
84
45
  * email: z.email(),
85
46
  * password: z.string().min(8),
86
47
  * }),
87
- * defaultValues: { email: '' },
88
48
  * })
89
49
  * ```
90
- *
91
- * Returns a form API exposing `register`, `values`, `errors`,
92
- * `fields`, `setValue`, `handleSubmit`, `meta`, field-array
93
- * helpers, and more. See `UseFormReturnType` for the full
94
- * surface.
95
- *
96
- * For Zod v3, import from `attaform/zod-v3` instead.
97
50
  */
98
51
  declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseFormConfiguration<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never, AbstractSchema<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>, DeepPartial<DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>>>, 'schema' | 'validateOn' | 'debounceMs'> & {
99
52
  schema: Schema;
100
53
  } & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
101
54
 
102
- /**
103
- * Field-metadata write/read API for the Zod v4 adapter.
104
- *
105
- * Backed by Zod 4's native `z.registry<T>()` mechanism — the schema
106
- * carries the metadata directly through `schema.register(fieldMeta,
107
- * payload)` (returns the schema, chainable) or the `withMeta()`
108
- * helper (same effect, version-agnostic across the v3 / v4 adapter
109
- * split).
110
- *
111
- * **Registration patterns:** both styles work — register on whatever
112
- * schema reference you assign into the parent's shape, OR on the
113
- * inner schema before wrapping. The adapter's resolver tries the
114
- * walker-returned schema first, then falls back to the peeled
115
- * inner so either ordering hits:
116
- *
117
- * // both equivalent — registry hits at lookup time
118
- * withMeta(z.string(), { label: 'Email' }).optional()
119
- * withMeta(z.string().optional(), { label: 'Email' })
120
- * z.string().optional().register(fieldMeta, { label: 'Email' })
121
- * z.string().register(fieldMeta, { label: 'Email' }).optional()
122
- *
123
- * The path walker returns the wrapper at terminal positions
124
- * (`['email']` against `{ email: z.string().optional() }` resolves
125
- * to `ZodOptional<ZodString>`) and peels at intermediate descent
126
- * (`['address', 'street']` peels through `address`'s wrapper to
127
- * reach the inner object). The two-stage lookup covers both leaf
128
- * and container registrations symmetrically.
129
- */
130
-
131
- /**
132
- * The shared registry every Attaform-aware Zod 4 schema can register
133
- * field metadata against. One module-scoped instance per consumer
134
- * project — re-exported from `attaform/zod` so user code reads the
135
- * same registry the runtime does.
136
- *
137
- * Consumers extending `FieldMetaPayload` via declaration merging
138
- * automatically get the richer payload type at every `register` /
139
- * `add` / `get` call site.
140
- *
141
- * **Shared-instance disambiguation.** A single schema instance reused
142
- * at multiple form paths (e.g. one address schema bound to both
143
- * `pickup` and `delivery`) can carry distinct metadata per path —
144
- * even via the canonical `schema.register(fieldMeta, payload)` chain.
145
- * Internally we maintain a parallel WeakMap of payload LISTS indexed
146
- * per schema reference, and the path-resolver walks the form's
147
- * schema tree counting per-schema occurrences to pick the right
148
- * payload for each path. Object literals evaluate left-to-right, so
149
- * registration order matches tree-walk order, and shared schemas
150
- * pair their two registrations to the two paths correctly:
151
- *
152
- * z.object({
153
- * pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
154
- * delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
155
- * })
156
- * // form.fields('pickup').label → 'Pickup address'
157
- * // form.fields('delivery').label → 'Delivery address'
158
- *
159
- * Schemas reused via `withMeta()` get a fresh clone per call (see
160
- * `withMeta` below), so they never share a registry slot in the
161
- * first place.
162
- */
163
- declare const fieldMeta: z.core.$ZodRegistry<FieldMetaPayload, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
164
- /**
165
- * Attach `payload` to `schema` in the shared `fieldMeta` registry
166
- * and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
167
- * `withMeta()`; user code that uses this helper reads the same on
168
- * either adapter.
169
- *
170
- * Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
171
- * Prefer the native chain for v4-only code; reach for `withMeta`
172
- * when authoring schema modules that may need to compile under both
173
- * adapters.
174
- *
175
- * Registers on the schema reference passed in. See the
176
- * "Registration rule" note in this file's header — register on the
177
- * inner schema before wrapping with `.optional()` / `.nullable()` /
178
- * `.default()` / etc.
179
- */
180
- declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
181
-
182
- export { FieldMetaPayload, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
183
- export type { ZodKind };
55
+ export { useForm };