attaform 0.16.2 → 0.16.4
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 +7 -7
- package/dist/chunks/devtools.cjs +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -4
- package/dist/index.d.mts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.mjs +3 -3
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/shared/attaform.C8CyvYa_.cjs +36 -0
- package/dist/shared/attaform.C8CyvYa_.cjs.map +1 -0
- package/dist/shared/{attaform.CWCx2r0x.d.ts → attaform.CCQkY4Ta.d.ts} +1 -1
- package/dist/shared/{attaform.c_NzdRyc.cjs → attaform.CIwZtbGV.cjs} +6 -2
- package/dist/shared/attaform.CIwZtbGV.cjs.map +1 -0
- package/dist/shared/{attaform.CVv9Oh0a.d.mts → attaform.CMRmwGDt.d.cts} +1 -1
- package/dist/shared/{attaform.0Gxd_OOx.d.cts → attaform.CU3JperC.d.cts} +193 -27
- package/dist/shared/{attaform.0Gxd_OOx.d.mts → attaform.CU3JperC.d.mts} +193 -27
- package/dist/shared/{attaform.0Gxd_OOx.d.ts → attaform.CU3JperC.d.ts} +193 -27
- package/dist/shared/{attaform.Dq5BabH1.d.cts → attaform.CXMOheyZ.d.mts} +1 -1
- package/dist/shared/attaform.D13GMFgK.mjs +32 -0
- package/dist/shared/attaform.D13GMFgK.mjs.map +1 -0
- package/dist/shared/{attaform.jrxE_xZw.mjs → attaform.DZRj9s0s.mjs} +5 -3
- package/dist/shared/attaform.DZRj9s0s.mjs.map +1 -0
- package/dist/shared/{attaform.Bp1c-uGF.cjs → attaform.Dd_pWnmn.cjs} +17 -29
- package/dist/shared/attaform.Dd_pWnmn.cjs.map +1 -0
- package/dist/shared/{attaform.DILbdvfo.mjs → attaform.DyV1O4tI.mjs} +111 -22
- package/dist/shared/attaform.DyV1O4tI.mjs.map +1 -0
- package/dist/shared/{attaform.DdnithOf.mjs → attaform.UA19EF3J.mjs} +17 -29
- package/dist/shared/attaform.UA19EF3J.mjs.map +1 -0
- package/dist/shared/{attaform.C9Ph2SMx.cjs → attaform.fegmBJaq.cjs} +111 -21
- package/dist/shared/attaform.fegmBJaq.cjs.map +1 -0
- package/dist/shared/{attaform.CvOXSpCb.mjs → attaform.g7rfuXdz.mjs} +13 -16
- package/dist/shared/attaform.g7rfuXdz.mjs.map +1 -0
- package/dist/shared/{attaform.DfrYByDj.cjs → attaform.keLBaHB6.cjs} +13 -16
- package/dist/shared/attaform.keLBaHB6.cjs.map +1 -0
- package/dist/zod-v3.cjs +2 -2
- package/dist/zod-v3.d.cts +19 -14
- package/dist/zod-v3.d.mts +19 -14
- package/dist/zod-v3.d.ts +19 -14
- package/dist/zod-v3.mjs +2 -2
- package/dist/zod-v4.cjs +2 -2
- package/dist/zod-v4.d.cts +94 -5
- package/dist/zod-v4.d.mts +94 -5
- package/dist/zod-v4.d.ts +94 -5
- package/dist/zod-v4.mjs +2 -2
- package/dist/zod.cjs +23 -5
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +51 -7
- package/dist/zod.d.mts +51 -7
- package/dist/zod.d.ts +51 -7
- package/dist/zod.mjs +22 -5
- package/dist/zod.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/shared/attaform.BAuJTWuT.d.mts +0 -84
- package/dist/shared/attaform.Bp1c-uGF.cjs.map +0 -1
- package/dist/shared/attaform.C9Ph2SMx.cjs.map +0 -1
- package/dist/shared/attaform.CvOXSpCb.mjs.map +0 -1
- package/dist/shared/attaform.DILbdvfo.mjs.map +0 -1
- package/dist/shared/attaform.DdnithOf.mjs.map +0 -1
- package/dist/shared/attaform.DfrYByDj.cjs.map +0 -1
- package/dist/shared/attaform.c_NzdRyc.cjs.map +0 -1
- package/dist/shared/attaform.jrxE_xZw.mjs.map +0 -1
- package/dist/shared/attaform.ls_7jBYc.d.ts +0 -84
- package/dist/shared/attaform.xIcmqscx.d.cts +0 -84
package/dist/zod-v3.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.
|
|
2
|
+
import { ag as ValidateOnConfig, F as FormKey, E as OnInvalidSubmitPolicy, X as PersistConfig, y as HistoryConfig, C as CoercionRegistry, G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType, o as FieldMetaPayload } from './shared/attaform.CU3JperC.mjs';
|
|
3
|
+
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.CU3JperC.mjs';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CXMOheyZ.mjs';
|
|
5
5
|
import 'vue';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -163,11 +163,16 @@ declare function isZodSchemaType<K extends keyof ZodTypeMap>(schema: unknown, ex
|
|
|
163
163
|
/**
|
|
164
164
|
* Field-metadata write/read API for the Zod v3 adapter.
|
|
165
165
|
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
166
|
+
* Storage lives in the shared `field-meta-store` core — every entry
|
|
167
|
+
* (`attaform/zod`, `attaform/zod-v3`, `attaform/zod-v4`) writes to and
|
|
168
|
+
* reads from the same `WeakMap`s, so a payload registered via any
|
|
169
|
+
* entry surfaces at lookup regardless of which adapter actually runs.
|
|
170
|
+
*
|
|
171
|
+
* Zod 3 has no `z.registry()` mechanism, so `fieldMeta` is the
|
|
172
|
+
* shared registry-shaped object exposing `add` / `get` / `has` /
|
|
173
|
+
* `remove`. The public `withMeta(schema, payload)` write API matches
|
|
174
|
+
* `attaform/zod`'s so schema authoring reads identically across the
|
|
175
|
+
* two adapters.
|
|
171
176
|
*
|
|
172
177
|
* **Registration patterns:** both styles work — register on whatever
|
|
173
178
|
* schema reference you assign into the parent's shape, OR on the
|
|
@@ -186,9 +191,9 @@ declare function isZodSchemaType<K extends keyof ZodTypeMap>(schema: unknown, ex
|
|
|
186
191
|
|
|
187
192
|
/**
|
|
188
193
|
* The shared registry every Attaform-aware Zod 3 schema can register
|
|
189
|
-
* field metadata against.
|
|
190
|
-
*
|
|
191
|
-
*
|
|
194
|
+
* field metadata against. Backed by the cross-adapter
|
|
195
|
+
* `fieldMetaStore` — a payload registered here is visible to the v4
|
|
196
|
+
* adapter and the unified `attaform/zod` entry, and vice versa.
|
|
192
197
|
*/
|
|
193
198
|
type FieldMetaRegistryV3 = {
|
|
194
199
|
/**
|
|
@@ -210,7 +215,7 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
210
215
|
* and return a clone of `schema` (chainable, with the new metadata).
|
|
211
216
|
* Cross-version with `attaform/zod`'s `withMeta()`.
|
|
212
217
|
*
|
|
213
|
-
* **Why clone, not mutate.** The
|
|
218
|
+
* **Why clone, not mutate.** The shared store keys metadata on the
|
|
214
219
|
* schema reference. Calling `withMeta` twice on the same instance
|
|
215
220
|
* would overwrite (last-write-wins) — so a sub-schema reused at
|
|
216
221
|
* multiple form paths (e.g. an address schema shared between pickup
|
|
@@ -228,8 +233,8 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
228
233
|
* registers once and surfaces at every path.
|
|
229
234
|
*
|
|
230
235
|
* `schema.register()` does NOT exist on Zod 3 — `withMeta` is the
|
|
231
|
-
* only write API. Register on the inner schema before
|
|
232
|
-
* see the "Registration rule" note in this file's header.
|
|
236
|
+
* only fluent write API. Register on the inner schema before
|
|
237
|
+
* wrapping; see the "Registration rule" note in this file's header.
|
|
233
238
|
*/
|
|
234
239
|
declare function withMeta<S extends z.ZodTypeAny>(schema: S, payload: FieldMetaPayload): S;
|
|
235
240
|
|
package/dist/zod-v3.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.
|
|
2
|
+
import { ag as ValidateOnConfig, F as FormKey, E as OnInvalidSubmitPolicy, X as PersistConfig, y as HistoryConfig, C as CoercionRegistry, G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType, o as FieldMetaPayload } from './shared/attaform.CU3JperC.js';
|
|
3
|
+
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.CU3JperC.js';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CCQkY4Ta.js';
|
|
5
5
|
import 'vue';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -163,11 +163,16 @@ declare function isZodSchemaType<K extends keyof ZodTypeMap>(schema: unknown, ex
|
|
|
163
163
|
/**
|
|
164
164
|
* Field-metadata write/read API for the Zod v3 adapter.
|
|
165
165
|
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
166
|
+
* Storage lives in the shared `field-meta-store` core — every entry
|
|
167
|
+
* (`attaform/zod`, `attaform/zod-v3`, `attaform/zod-v4`) writes to and
|
|
168
|
+
* reads from the same `WeakMap`s, so a payload registered via any
|
|
169
|
+
* entry surfaces at lookup regardless of which adapter actually runs.
|
|
170
|
+
*
|
|
171
|
+
* Zod 3 has no `z.registry()` mechanism, so `fieldMeta` is the
|
|
172
|
+
* shared registry-shaped object exposing `add` / `get` / `has` /
|
|
173
|
+
* `remove`. The public `withMeta(schema, payload)` write API matches
|
|
174
|
+
* `attaform/zod`'s so schema authoring reads identically across the
|
|
175
|
+
* two adapters.
|
|
171
176
|
*
|
|
172
177
|
* **Registration patterns:** both styles work — register on whatever
|
|
173
178
|
* schema reference you assign into the parent's shape, OR on the
|
|
@@ -186,9 +191,9 @@ declare function isZodSchemaType<K extends keyof ZodTypeMap>(schema: unknown, ex
|
|
|
186
191
|
|
|
187
192
|
/**
|
|
188
193
|
* The shared registry every Attaform-aware Zod 3 schema can register
|
|
189
|
-
* field metadata against.
|
|
190
|
-
*
|
|
191
|
-
*
|
|
194
|
+
* field metadata against. Backed by the cross-adapter
|
|
195
|
+
* `fieldMetaStore` — a payload registered here is visible to the v4
|
|
196
|
+
* adapter and the unified `attaform/zod` entry, and vice versa.
|
|
192
197
|
*/
|
|
193
198
|
type FieldMetaRegistryV3 = {
|
|
194
199
|
/**
|
|
@@ -210,7 +215,7 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
210
215
|
* and return a clone of `schema` (chainable, with the new metadata).
|
|
211
216
|
* Cross-version with `attaform/zod`'s `withMeta()`.
|
|
212
217
|
*
|
|
213
|
-
* **Why clone, not mutate.** The
|
|
218
|
+
* **Why clone, not mutate.** The shared store keys metadata on the
|
|
214
219
|
* schema reference. Calling `withMeta` twice on the same instance
|
|
215
220
|
* would overwrite (last-write-wins) — so a sub-schema reused at
|
|
216
221
|
* multiple form paths (e.g. an address schema shared between pickup
|
|
@@ -228,8 +233,8 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
228
233
|
* registers once and surfaces at every path.
|
|
229
234
|
*
|
|
230
235
|
* `schema.register()` does NOT exist on Zod 3 — `withMeta` is the
|
|
231
|
-
* only write API. Register on the inner schema before
|
|
232
|
-
* see the "Registration rule" note in this file's header.
|
|
236
|
+
* only fluent write API. Register on the inner schema before
|
|
237
|
+
* wrapping; see the "Registration rule" note in this file's header.
|
|
233
238
|
*/
|
|
234
239
|
declare function withMeta<S extends z.ZodTypeAny>(schema: S, payload: FieldMetaPayload): S;
|
|
235
240
|
|
package/dist/zod-v3.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { f as fieldMeta, i as isZodSchemaType, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.
|
|
2
|
-
export { A as AttaformErrorCode, i as injectForm, a as isUnset, u as unset } from './shared/attaform.
|
|
1
|
+
export { f as fieldMeta, i as isZodSchemaType, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.UA19EF3J.mjs';
|
|
2
|
+
export { A as AttaformErrorCode, i as injectForm, a as isUnset, u as unset } from './shared/attaform.DyV1O4tI.mjs';
|
|
3
3
|
export { u as useRegister } from './shared/attaform.BfMxsfmE.mjs';
|
|
4
4
|
//# sourceMappingURL=zod-v3.mjs.map
|
package/dist/zod-v4.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const index = require('./shared/attaform.
|
|
4
|
-
const useFormContext = require('./shared/attaform.
|
|
3
|
+
const index = require('./shared/attaform.keLBaHB6.cjs');
|
|
4
|
+
const useFormContext = require('./shared/attaform.fegmBJaq.cjs');
|
|
5
5
|
const plugin = require('./shared/attaform.rIRYSUI1.cjs');
|
|
6
6
|
|
|
7
7
|
|
package/dist/zod-v4.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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,
|
|
3
|
-
export {
|
|
4
|
-
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.
|
|
5
|
-
export { f as fieldMeta, w as withMeta } from './shared/attaform.xIcmqscx.cjs';
|
|
2
|
+
import { F as FormKey, b as AbstractSchema, U as UseFormConfiguration, G as GenericForm, D as DeepPartial, c as DefaultValuesShape, ag as ValidateOnConfig, d as UseFormReturnType, o as FieldMetaPayload } from './shared/attaform.CU3JperC.cjs';
|
|
3
|
+
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.CU3JperC.cjs';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CMRmwGDt.cjs';
|
|
6
5
|
import { a as AttaformError } from './shared/attaform.B7rzpK1U.cjs';
|
|
7
6
|
import 'vue';
|
|
8
7
|
|
|
@@ -100,5 +99,95 @@ declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseForm
|
|
|
100
99
|
schema: Schema;
|
|
101
100
|
} & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Field-metadata write/read API for the Zod v4 adapter.
|
|
104
|
+
*
|
|
105
|
+
* Storage lives in the shared `field-meta-store` core — every entry
|
|
106
|
+
* (`attaform/zod`, `attaform/zod-v3`, `attaform/zod-v4`) writes to and
|
|
107
|
+
* reads from the same `WeakMap`s, so a payload registered via any
|
|
108
|
+
* entry surfaces at lookup regardless of which adapter actually runs.
|
|
109
|
+
*
|
|
110
|
+
* The native chain `schema.register(fieldMeta, payload)` still works
|
|
111
|
+
* — Zod 4's `.register` calls `registry.add(this, payload)` and
|
|
112
|
+
* returns the schema; the shared store satisfies that structurally.
|
|
113
|
+
*
|
|
114
|
+
* **Registration patterns:** both styles work — register on whatever
|
|
115
|
+
* schema reference you assign into the parent's shape, OR on the
|
|
116
|
+
* inner schema before wrapping. The adapter's resolver tries the
|
|
117
|
+
* walker-returned schema first, then falls back to the peeled
|
|
118
|
+
* inner so either ordering hits:
|
|
119
|
+
*
|
|
120
|
+
* // both equivalent — registry hits at lookup time
|
|
121
|
+
* withMeta(z.string(), { label: 'Email' }).optional()
|
|
122
|
+
* withMeta(z.string().optional(), { label: 'Email' })
|
|
123
|
+
* z.string().optional().register(fieldMeta, { label: 'Email' })
|
|
124
|
+
* z.string().register(fieldMeta, { label: 'Email' }).optional()
|
|
125
|
+
*
|
|
126
|
+
* The path walker returns the wrapper at terminal positions
|
|
127
|
+
* (`['email']` against `{ email: z.string().optional() }` resolves
|
|
128
|
+
* to `ZodOptional<ZodString>`) and peels at intermediate descent
|
|
129
|
+
* (`['address', 'street']` peels through `address`'s wrapper to
|
|
130
|
+
* reach the inner object). The two-stage lookup covers both leaf
|
|
131
|
+
* and container registrations symmetrically.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
|
|
135
|
+
/**
|
|
136
|
+
* The shared registry every Attaform-aware Zod 4 schema can register
|
|
137
|
+
* field metadata against. Backed by the cross-adapter
|
|
138
|
+
* `fieldMetaStore` — one module-scoped instance, shared with the v3
|
|
139
|
+
* adapter and the unified `attaform/zod` entry, so a `.register()`
|
|
140
|
+
* chain in one place is read by adapters in another.
|
|
141
|
+
*
|
|
142
|
+
* Consumers extending `FieldMetaPayload` via declaration merging
|
|
143
|
+
* automatically get the richer payload type at every `register` /
|
|
144
|
+
* `add` / `get` call site.
|
|
145
|
+
*
|
|
146
|
+
* **Shared-instance disambiguation.** A single schema instance reused
|
|
147
|
+
* at multiple form paths (e.g. one address schema bound to both
|
|
148
|
+
* `pickup` and `delivery`) can carry distinct metadata per path —
|
|
149
|
+
* even via the canonical `schema.register(fieldMeta, payload)` chain.
|
|
150
|
+
* The shared store keeps a parallel list of every registration; the
|
|
151
|
+
* path-resolver walks the form's schema tree counting per-schema
|
|
152
|
+
* occurrences to pick the right payload for each path. Object
|
|
153
|
+
* literals evaluate left-to-right, so registration order matches
|
|
154
|
+
* tree-walk order, and shared schemas pair their two registrations
|
|
155
|
+
* to the two paths correctly:
|
|
156
|
+
*
|
|
157
|
+
* z.object({
|
|
158
|
+
* pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
|
|
159
|
+
* delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
|
|
160
|
+
* })
|
|
161
|
+
* // form.fields('pickup').label → 'Pickup address'
|
|
162
|
+
* // form.fields('delivery').label → 'Delivery address'
|
|
163
|
+
*
|
|
164
|
+
* Schemas reused via `withMeta()` get a fresh clone per call (see
|
|
165
|
+
* `withMeta` below), so they never share a registry slot in the
|
|
166
|
+
* first place.
|
|
167
|
+
*
|
|
168
|
+
* Cast to `z.$ZodRegistry<FieldMetaPayload>` so that
|
|
169
|
+
* `schema.register(fieldMeta, payload)` chains type-check at the call
|
|
170
|
+
* site — Zod 4's `.register()` only calls `.add(this, payload)`
|
|
171
|
+
* structurally, so the cast is sound at runtime.
|
|
172
|
+
*/
|
|
173
|
+
declare const fieldMeta: ZodFieldMetaRegistry;
|
|
174
|
+
/**
|
|
175
|
+
* Attach `payload` to `schema` in the shared `fieldMeta` registry
|
|
176
|
+
* and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
|
|
177
|
+
* `withMeta()`; user code that uses this helper reads the same on
|
|
178
|
+
* either adapter.
|
|
179
|
+
*
|
|
180
|
+
* Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
|
|
181
|
+
* Prefer the native chain for v4-only code; reach for `withMeta`
|
|
182
|
+
* when authoring schema modules that may need to compile under both
|
|
183
|
+
* adapters.
|
|
184
|
+
*
|
|
185
|
+
* Registers on the schema reference passed in. See the
|
|
186
|
+
* "Registration rule" note in this file's header — register on the
|
|
187
|
+
* inner schema before wrapping with `.optional()` / `.nullable()` /
|
|
188
|
+
* `.default()` / etc.
|
|
189
|
+
*/
|
|
190
|
+
declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
|
|
191
|
+
|
|
192
|
+
export { FieldMetaPayload, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
|
|
104
193
|
export type { ZodKind };
|
package/dist/zod-v4.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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,
|
|
3
|
-
export {
|
|
4
|
-
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.
|
|
5
|
-
export { f as fieldMeta, w as withMeta } from './shared/attaform.BAuJTWuT.mjs';
|
|
2
|
+
import { F as FormKey, b as AbstractSchema, U as UseFormConfiguration, G as GenericForm, D as DeepPartial, c as DefaultValuesShape, ag as ValidateOnConfig, d as UseFormReturnType, o as FieldMetaPayload } from './shared/attaform.CU3JperC.mjs';
|
|
3
|
+
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.CU3JperC.mjs';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CXMOheyZ.mjs';
|
|
6
5
|
import { a as AttaformError } from './shared/attaform.B7rzpK1U.mjs';
|
|
7
6
|
import 'vue';
|
|
8
7
|
|
|
@@ -100,5 +99,95 @@ declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseForm
|
|
|
100
99
|
schema: Schema;
|
|
101
100
|
} & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Field-metadata write/read API for the Zod v4 adapter.
|
|
104
|
+
*
|
|
105
|
+
* Storage lives in the shared `field-meta-store` core — every entry
|
|
106
|
+
* (`attaform/zod`, `attaform/zod-v3`, `attaform/zod-v4`) writes to and
|
|
107
|
+
* reads from the same `WeakMap`s, so a payload registered via any
|
|
108
|
+
* entry surfaces at lookup regardless of which adapter actually runs.
|
|
109
|
+
*
|
|
110
|
+
* The native chain `schema.register(fieldMeta, payload)` still works
|
|
111
|
+
* — Zod 4's `.register` calls `registry.add(this, payload)` and
|
|
112
|
+
* returns the schema; the shared store satisfies that structurally.
|
|
113
|
+
*
|
|
114
|
+
* **Registration patterns:** both styles work — register on whatever
|
|
115
|
+
* schema reference you assign into the parent's shape, OR on the
|
|
116
|
+
* inner schema before wrapping. The adapter's resolver tries the
|
|
117
|
+
* walker-returned schema first, then falls back to the peeled
|
|
118
|
+
* inner so either ordering hits:
|
|
119
|
+
*
|
|
120
|
+
* // both equivalent — registry hits at lookup time
|
|
121
|
+
* withMeta(z.string(), { label: 'Email' }).optional()
|
|
122
|
+
* withMeta(z.string().optional(), { label: 'Email' })
|
|
123
|
+
* z.string().optional().register(fieldMeta, { label: 'Email' })
|
|
124
|
+
* z.string().register(fieldMeta, { label: 'Email' }).optional()
|
|
125
|
+
*
|
|
126
|
+
* The path walker returns the wrapper at terminal positions
|
|
127
|
+
* (`['email']` against `{ email: z.string().optional() }` resolves
|
|
128
|
+
* to `ZodOptional<ZodString>`) and peels at intermediate descent
|
|
129
|
+
* (`['address', 'street']` peels through `address`'s wrapper to
|
|
130
|
+
* reach the inner object). The two-stage lookup covers both leaf
|
|
131
|
+
* and container registrations symmetrically.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
|
|
135
|
+
/**
|
|
136
|
+
* The shared registry every Attaform-aware Zod 4 schema can register
|
|
137
|
+
* field metadata against. Backed by the cross-adapter
|
|
138
|
+
* `fieldMetaStore` — one module-scoped instance, shared with the v3
|
|
139
|
+
* adapter and the unified `attaform/zod` entry, so a `.register()`
|
|
140
|
+
* chain in one place is read by adapters in another.
|
|
141
|
+
*
|
|
142
|
+
* Consumers extending `FieldMetaPayload` via declaration merging
|
|
143
|
+
* automatically get the richer payload type at every `register` /
|
|
144
|
+
* `add` / `get` call site.
|
|
145
|
+
*
|
|
146
|
+
* **Shared-instance disambiguation.** A single schema instance reused
|
|
147
|
+
* at multiple form paths (e.g. one address schema bound to both
|
|
148
|
+
* `pickup` and `delivery`) can carry distinct metadata per path —
|
|
149
|
+
* even via the canonical `schema.register(fieldMeta, payload)` chain.
|
|
150
|
+
* The shared store keeps a parallel list of every registration; the
|
|
151
|
+
* path-resolver walks the form's schema tree counting per-schema
|
|
152
|
+
* occurrences to pick the right payload for each path. Object
|
|
153
|
+
* literals evaluate left-to-right, so registration order matches
|
|
154
|
+
* tree-walk order, and shared schemas pair their two registrations
|
|
155
|
+
* to the two paths correctly:
|
|
156
|
+
*
|
|
157
|
+
* z.object({
|
|
158
|
+
* pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
|
|
159
|
+
* delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
|
|
160
|
+
* })
|
|
161
|
+
* // form.fields('pickup').label → 'Pickup address'
|
|
162
|
+
* // form.fields('delivery').label → 'Delivery address'
|
|
163
|
+
*
|
|
164
|
+
* Schemas reused via `withMeta()` get a fresh clone per call (see
|
|
165
|
+
* `withMeta` below), so they never share a registry slot in the
|
|
166
|
+
* first place.
|
|
167
|
+
*
|
|
168
|
+
* Cast to `z.$ZodRegistry<FieldMetaPayload>` so that
|
|
169
|
+
* `schema.register(fieldMeta, payload)` chains type-check at the call
|
|
170
|
+
* site — Zod 4's `.register()` only calls `.add(this, payload)`
|
|
171
|
+
* structurally, so the cast is sound at runtime.
|
|
172
|
+
*/
|
|
173
|
+
declare const fieldMeta: ZodFieldMetaRegistry;
|
|
174
|
+
/**
|
|
175
|
+
* Attach `payload` to `schema` in the shared `fieldMeta` registry
|
|
176
|
+
* and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
|
|
177
|
+
* `withMeta()`; user code that uses this helper reads the same on
|
|
178
|
+
* either adapter.
|
|
179
|
+
*
|
|
180
|
+
* Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
|
|
181
|
+
* Prefer the native chain for v4-only code; reach for `withMeta`
|
|
182
|
+
* when authoring schema modules that may need to compile under both
|
|
183
|
+
* adapters.
|
|
184
|
+
*
|
|
185
|
+
* Registers on the schema reference passed in. See the
|
|
186
|
+
* "Registration rule" note in this file's header — register on the
|
|
187
|
+
* inner schema before wrapping with `.optional()` / `.nullable()` /
|
|
188
|
+
* `.default()` / etc.
|
|
189
|
+
*/
|
|
190
|
+
declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
|
|
191
|
+
|
|
192
|
+
export { FieldMetaPayload, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
|
|
104
193
|
export type { ZodKind };
|
package/dist/zod-v4.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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,
|
|
3
|
-
export {
|
|
4
|
-
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.
|
|
5
|
-
export { f as fieldMeta, w as withMeta } from './shared/attaform.ls_7jBYc.js';
|
|
2
|
+
import { F as FormKey, b as AbstractSchema, U as UseFormConfiguration, G as GenericForm, D as DeepPartial, c as DefaultValuesShape, ag as ValidateOnConfig, d as UseFormReturnType, o as FieldMetaPayload } from './shared/attaform.CU3JperC.js';
|
|
3
|
+
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.CU3JperC.js';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CCQkY4Ta.js';
|
|
6
5
|
import { a as AttaformError } from './shared/attaform.B7rzpK1U.js';
|
|
7
6
|
import 'vue';
|
|
8
7
|
|
|
@@ -100,5 +99,95 @@ declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseForm
|
|
|
100
99
|
schema: Schema;
|
|
101
100
|
} & ValidateOnConfig): UseFormReturnType<z.output<Schema> extends GenericForm ? z.output<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>;
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Field-metadata write/read API for the Zod v4 adapter.
|
|
104
|
+
*
|
|
105
|
+
* Storage lives in the shared `field-meta-store` core — every entry
|
|
106
|
+
* (`attaform/zod`, `attaform/zod-v3`, `attaform/zod-v4`) writes to and
|
|
107
|
+
* reads from the same `WeakMap`s, so a payload registered via any
|
|
108
|
+
* entry surfaces at lookup regardless of which adapter actually runs.
|
|
109
|
+
*
|
|
110
|
+
* The native chain `schema.register(fieldMeta, payload)` still works
|
|
111
|
+
* — Zod 4's `.register` calls `registry.add(this, payload)` and
|
|
112
|
+
* returns the schema; the shared store satisfies that structurally.
|
|
113
|
+
*
|
|
114
|
+
* **Registration patterns:** both styles work — register on whatever
|
|
115
|
+
* schema reference you assign into the parent's shape, OR on the
|
|
116
|
+
* inner schema before wrapping. The adapter's resolver tries the
|
|
117
|
+
* walker-returned schema first, then falls back to the peeled
|
|
118
|
+
* inner so either ordering hits:
|
|
119
|
+
*
|
|
120
|
+
* // both equivalent — registry hits at lookup time
|
|
121
|
+
* withMeta(z.string(), { label: 'Email' }).optional()
|
|
122
|
+
* withMeta(z.string().optional(), { label: 'Email' })
|
|
123
|
+
* z.string().optional().register(fieldMeta, { label: 'Email' })
|
|
124
|
+
* z.string().register(fieldMeta, { label: 'Email' }).optional()
|
|
125
|
+
*
|
|
126
|
+
* The path walker returns the wrapper at terminal positions
|
|
127
|
+
* (`['email']` against `{ email: z.string().optional() }` resolves
|
|
128
|
+
* to `ZodOptional<ZodString>`) and peels at intermediate descent
|
|
129
|
+
* (`['address', 'street']` peels through `address`'s wrapper to
|
|
130
|
+
* reach the inner object). The two-stage lookup covers both leaf
|
|
131
|
+
* and container registrations symmetrically.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
|
|
135
|
+
/**
|
|
136
|
+
* The shared registry every Attaform-aware Zod 4 schema can register
|
|
137
|
+
* field metadata against. Backed by the cross-adapter
|
|
138
|
+
* `fieldMetaStore` — one module-scoped instance, shared with the v3
|
|
139
|
+
* adapter and the unified `attaform/zod` entry, so a `.register()`
|
|
140
|
+
* chain in one place is read by adapters in another.
|
|
141
|
+
*
|
|
142
|
+
* Consumers extending `FieldMetaPayload` via declaration merging
|
|
143
|
+
* automatically get the richer payload type at every `register` /
|
|
144
|
+
* `add` / `get` call site.
|
|
145
|
+
*
|
|
146
|
+
* **Shared-instance disambiguation.** A single schema instance reused
|
|
147
|
+
* at multiple form paths (e.g. one address schema bound to both
|
|
148
|
+
* `pickup` and `delivery`) can carry distinct metadata per path —
|
|
149
|
+
* even via the canonical `schema.register(fieldMeta, payload)` chain.
|
|
150
|
+
* The shared store keeps a parallel list of every registration; the
|
|
151
|
+
* path-resolver walks the form's schema tree counting per-schema
|
|
152
|
+
* occurrences to pick the right payload for each path. Object
|
|
153
|
+
* literals evaluate left-to-right, so registration order matches
|
|
154
|
+
* tree-walk order, and shared schemas pair their two registrations
|
|
155
|
+
* to the two paths correctly:
|
|
156
|
+
*
|
|
157
|
+
* z.object({
|
|
158
|
+
* pickup: addressSchema.register(fieldMeta, { label: 'Pickup address' }),
|
|
159
|
+
* delivery: addressSchema.register(fieldMeta, { label: 'Delivery address' }),
|
|
160
|
+
* })
|
|
161
|
+
* // form.fields('pickup').label → 'Pickup address'
|
|
162
|
+
* // form.fields('delivery').label → 'Delivery address'
|
|
163
|
+
*
|
|
164
|
+
* Schemas reused via `withMeta()` get a fresh clone per call (see
|
|
165
|
+
* `withMeta` below), so they never share a registry slot in the
|
|
166
|
+
* first place.
|
|
167
|
+
*
|
|
168
|
+
* Cast to `z.$ZodRegistry<FieldMetaPayload>` so that
|
|
169
|
+
* `schema.register(fieldMeta, payload)` chains type-check at the call
|
|
170
|
+
* site — Zod 4's `.register()` only calls `.add(this, payload)`
|
|
171
|
+
* structurally, so the cast is sound at runtime.
|
|
172
|
+
*/
|
|
173
|
+
declare const fieldMeta: ZodFieldMetaRegistry;
|
|
174
|
+
/**
|
|
175
|
+
* Attach `payload` to `schema` in the shared `fieldMeta` registry
|
|
176
|
+
* and return `schema` (chainable). Cross-version with `attaform/zod-v3`'s
|
|
177
|
+
* `withMeta()`; user code that uses this helper reads the same on
|
|
178
|
+
* either adapter.
|
|
179
|
+
*
|
|
180
|
+
* Equivalent to `schema.register(fieldMeta, payload)` on Zod 4.
|
|
181
|
+
* Prefer the native chain for v4-only code; reach for `withMeta`
|
|
182
|
+
* when authoring schema modules that may need to compile under both
|
|
183
|
+
* adapters.
|
|
184
|
+
*
|
|
185
|
+
* Registers on the schema reference passed in. See the
|
|
186
|
+
* "Registration rule" note in this file's header — register on the
|
|
187
|
+
* inner schema before wrapping with `.optional()` / `.nullable()` /
|
|
188
|
+
* `.default()` / etc.
|
|
189
|
+
*/
|
|
190
|
+
declare function withMeta<S extends z.ZodType>(schema: S, payload: FieldMetaPayload): S;
|
|
191
|
+
|
|
192
|
+
export { FieldMetaPayload, UnsupportedSchemaError, assertZodVersion, fieldMeta, kindOf, useForm, withMeta, zodV4Adapter as zodAdapter };
|
|
104
193
|
export type { ZodKind };
|
package/dist/zod-v4.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { U as UnsupportedSchemaError, a as assertZodVersion, f as fieldMeta, k as kindOf, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.
|
|
2
|
-
export { A as AttaformErrorCode, i as injectForm, a as isUnset, u as unset } from './shared/attaform.
|
|
1
|
+
export { U as UnsupportedSchemaError, a as assertZodVersion, f as fieldMeta, k as kindOf, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.g7rfuXdz.mjs';
|
|
2
|
+
export { A as AttaformErrorCode, i as injectForm, a as isUnset, u as unset } from './shared/attaform.DyV1O4tI.mjs';
|
|
3
3
|
export { u as useRegister } from './shared/attaform.BfMxsfmE.mjs';
|
|
4
4
|
//# sourceMappingURL=zod-v4.mjs.map
|
package/dist/zod.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const plugin = require('./shared/attaform.rIRYSUI1.cjs');
|
|
4
|
-
const useForm$1 = require('./shared/attaform.
|
|
5
|
-
const index = require('./shared/attaform.
|
|
6
|
-
const useFormContext = require('./shared/attaform.
|
|
4
|
+
const useForm$1 = require('./shared/attaform.Dd_pWnmn.cjs');
|
|
5
|
+
const index = require('./shared/attaform.keLBaHB6.cjs');
|
|
6
|
+
const useFormContext = require('./shared/attaform.fegmBJaq.cjs');
|
|
7
|
+
const fieldMetaStore = require('./shared/attaform.C8CyvYa_.cjs');
|
|
7
8
|
|
|
8
9
|
function isZodV4SchemaShape(value) {
|
|
9
10
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -23,12 +24,29 @@ function useForm(configuration) {
|
|
|
23
24
|
return useForm$1.useForm(configuration);
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
const fieldMeta = fieldMetaStore.fieldMetaStore;
|
|
28
|
+
function withMeta(schema, payload) {
|
|
29
|
+
const target = schema;
|
|
30
|
+
const existing = fieldMetaStore.getFieldMetaForSchema(target) ?? {};
|
|
31
|
+
const cloned = cloneSchema(schema);
|
|
32
|
+
fieldMetaStore.fieldMetaStore.add(cloned, { ...existing, ...payload });
|
|
33
|
+
return cloned;
|
|
34
|
+
}
|
|
35
|
+
function cloneSchema(schema) {
|
|
36
|
+
const candidate = schema;
|
|
37
|
+
if (typeof candidate.clone === "function") {
|
|
38
|
+
return candidate.clone();
|
|
39
|
+
}
|
|
40
|
+
const Ctor = candidate.constructor;
|
|
41
|
+
return new Ctor(candidate._def);
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
exports.useRegister = plugin.useRegister;
|
|
27
|
-
exports.fieldMeta = index.fieldMeta;
|
|
28
|
-
exports.withMeta = index.withMeta;
|
|
29
45
|
exports.AttaformErrorCode = useFormContext.AttaformErrorCode;
|
|
30
46
|
exports.injectForm = useFormContext.injectForm;
|
|
31
47
|
exports.isUnset = useFormContext.isUnset;
|
|
32
48
|
exports.unset = useFormContext.unset;
|
|
49
|
+
exports.fieldMeta = fieldMeta;
|
|
33
50
|
exports.useForm = useForm;
|
|
51
|
+
exports.withMeta = withMeta;
|
|
34
52
|
//# sourceMappingURL=zod.cjs.map
|
package/dist/zod.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.cjs","sources":["../src/runtime/core/zod-shape.ts","../src/runtime/adapters/unified/use-form.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 * 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 type { z } from 'zod'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DeepPartial, DefaultValuesShape, GenericForm } from '../../types/types-core'\n\n/**\n * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4\n * schemas; the runtime picks the right adapter from the schema's\n * shape.\n *\n * Type inference targets Zod v4 — the recommended major. Consumers\n * still on Zod v3 get correct runtime behavior here, but the strongest\n * TypeScript inference comes from importing `attaform/zod-v3`\n * directly.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * email: z.email(),\n * password: z.string().min(8),\n * }),\n * })\n * ```\n */\nexport function useForm<Schema extends z.ZodObject>(\n configuration: Omit<\n UseFormConfiguration<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<\n DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>\n >\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n> {\n // Foot-gun guard mirrors the typed wrappers'.\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4<Schema>>[0]) as ReturnType<\n typeof useForm<Schema>\n >\n }\n // Anything else (Zod v3 schema, custom AbstractSchema, schema\n // factory) goes through the v3 wrapper, which already accepts both\n // Zod v3 input and AbstractSchema directly via its existing shape\n // branch. Cast through unknown — the unified entry's TS surface\n // tracks v4, but the runtime accepts the broader shape.\n return useFormV3(configuration as never) as unknown as ReturnType<typeof useForm<Schema>>\n}\n"],"names":["InvalidUseFormConfigError","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;;ACUO,SAAS,QACd,aAAA,EAiBA;AAEA,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAIA,gCAAA,EAA0B;AAAA,EACtC;AAEA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOC,cAAU,aAAwD,CAAA;AAAA,EAG3E;AAMA,EAAA,OAAOC,kBAAU,aAAsB,CAAA;AACzC;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"zod.cjs","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 * 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 type { z } from 'zod'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type {\n AbstractSchema,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DeepPartial, DefaultValuesShape, GenericForm } from '../../types/types-core'\n\n/**\n * Create a form bound to a Zod schema. Accepts both Zod v3 and Zod v4\n * schemas; the runtime picks the right adapter from the schema's\n * shape.\n *\n * Type inference targets Zod v4 — the recommended major. Consumers\n * still on Zod v3 get correct runtime behavior here, but the strongest\n * TypeScript inference comes from importing `attaform/zod-v3`\n * directly.\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 */\nexport function useForm<Schema extends z.ZodObject>(\n configuration: Omit<\n UseFormConfiguration<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<\n DefaultValuesShape<z.output<Schema> extends GenericForm ? z.output<Schema> : never>\n >\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n> {\n // Foot-gun guard mirrors the typed wrappers'.\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4<Schema>>[0]) as ReturnType<\n typeof useForm<Schema>\n >\n }\n // Anything else (Zod v3 schema, custom AbstractSchema, schema\n // factory) goes through the v3 wrapper, which already accepts both\n // Zod v3 input and AbstractSchema directly via its existing shape\n // branch. Cast through unknown — the unified entry's TS surface\n // tracks v4, but the runtime accepts the broader shape.\n return useFormV3(configuration as never) as unknown as ReturnType<typeof useForm<Schema>>\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":["InvalidUseFormConfigError","useFormV4","useFormV3","fieldMetaStore","getFieldMetaForSchema"],"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;;ACUO,SAAS,QACd,aAAA,EAiBA;AAEA,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAIA,gCAAA,EAA0B;AAAA,EACtC;AAEA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOC,cAAU,aAAwD,CAAA;AAAA,EAG3E;AAMA,EAAA,OAAOC,kBAAU,aAAsB,CAAA;AACzC;;AC3DO,MAAM,SAAA,GAAYC;AAiBlB,SAAS,QAAA,CAAY,QAAW,OAAA,EAA8B;AACnE,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,QAAA,GAAWC,oCAAA,CAAsB,MAAM,CAAA,IAAK,EAAC;AACnD,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,EAAAD,6BAAA,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;;;;;;;;;;;"}
|