attaform 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +2 -2
- 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.ClfCi1i2.d.mts → attaform.B1jvxsOF.d.mts} +1 -1
- package/dist/shared/{attaform.BT55rDNN.mjs → attaform.B3ZaPIzS.mjs} +15 -2
- package/dist/shared/attaform.B3ZaPIzS.mjs.map +1 -0
- package/dist/shared/{attaform.0Wg7UEeX.cjs → attaform.BPRHR3Zs.cjs} +20 -8
- package/dist/shared/attaform.BPRHR3Zs.cjs.map +1 -0
- package/dist/shared/{attaform.C6_zOf8x.cjs → attaform.BV40t5y2.cjs} +16 -6
- package/dist/shared/attaform.BV40t5y2.cjs.map +1 -0
- package/dist/shared/attaform.C0iFnTN0.d.ts +165 -0
- package/dist/shared/attaform.C5MH4lNh.d.mts +53 -0
- package/dist/shared/attaform.C6lbmMUe.d.ts +53 -0
- package/dist/shared/{attaform.D7lomopc.d.cts → attaform.C6qzEdIM.d.cts} +1 -1
- package/dist/shared/attaform.CHorcsIU.d.cts +165 -0
- package/dist/shared/{attaform.B0zue7zt.d.ts → attaform.CTwNcpLE.d.ts} +1 -1
- package/dist/shared/{attaform.BYbsV2Wv.d.mts → attaform.C_5aB6EQ.d.cts} +95 -15
- package/dist/shared/{attaform.BYbsV2Wv.d.ts → attaform.C_5aB6EQ.d.mts} +95 -15
- package/dist/shared/{attaform.BYbsV2Wv.d.cts → attaform.C_5aB6EQ.d.ts} +95 -15
- package/dist/shared/{attaform.BFumZXY2.cjs → attaform.Cer8JO_P.cjs} +15 -2
- package/dist/shared/attaform.Cer8JO_P.cjs.map +1 -0
- package/dist/shared/{attaform.Cj0pCNVn.mjs → attaform.CpERWz3u.mjs} +16 -6
- package/dist/shared/attaform.CpERWz3u.mjs.map +1 -0
- package/dist/shared/attaform.CuE-bS1C.d.mts +165 -0
- package/dist/shared/{attaform.D6Q5ZP8L.mjs → attaform.Drt6fivF.mjs} +20 -8
- package/dist/shared/attaform.Drt6fivF.mjs.map +1 -0
- package/dist/shared/attaform.DtMN-MAm.d.cts +53 -0
- package/dist/zod-v3.cjs +2 -2
- package/dist/zod-v3.d.cts +35 -61
- package/dist/zod-v3.d.mts +35 -61
- package/dist/zod-v3.d.ts +35 -61
- package/dist/zod-v3.mjs +2 -2
- package/dist/zod-v4.cjs +2 -2
- package/dist/zod-v4.d.cts +4 -4
- package/dist/zod-v4.d.mts +4 -4
- package/dist/zod-v4.d.ts +4 -4
- package/dist/zod-v4.mjs +2 -2
- package/dist/zod.cjs +9 -5
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +37 -11
- package/dist/zod.d.mts +37 -11
- package/dist/zod.d.ts +37 -11
- package/dist/zod.mjs +9 -5
- package/dist/zod.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/shared/attaform.0Wg7UEeX.cjs.map +0 -1
- package/dist/shared/attaform.AOgGyRoI.d.cts +0 -65
- package/dist/shared/attaform.BFumZXY2.cjs.map +0 -1
- package/dist/shared/attaform.BQ-iGGWd.d.mts +0 -65
- package/dist/shared/attaform.BT55rDNN.mjs.map +0 -1
- package/dist/shared/attaform.C6_zOf8x.cjs.map +0 -1
- package/dist/shared/attaform.CX9v2M8k.d.ts +0 -65
- package/dist/shared/attaform.Cj0pCNVn.mjs.map +0 -1
- package/dist/shared/attaform.D6Q5ZP8L.mjs.map +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { G as GenericForm, s as FlatPath, B as NestedType, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, ag as ValidateOnConfig, d as UseFormReturnType } from './attaform.C_5aB6EQ.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The shape `form.values.<key>` returns at runtime.
|
|
6
|
+
*
|
|
7
|
+
* Per leaf:
|
|
8
|
+
*
|
|
9
|
+
* 1. `z.preprocess(fn, inner)` — compiles to `ZodPipe<ZodTransform, inner>`.
|
|
10
|
+
* The preprocess fn fires at the write boundary (synthesized into
|
|
11
|
+
* `setValue`), so storage holds whatever `inner` stores. Recurse
|
|
12
|
+
* `StorageShape` on `inner` so a defaulted leaf inside `inner` still
|
|
13
|
+
* reads `T` (not `T | undefined`).
|
|
14
|
+
*
|
|
15
|
+
* 2. `inner.transform(fn)` — compiles to `ZodPipe<inner, ZodTransform>`.
|
|
16
|
+
* Transforms fire at submit / validate, NOT at the write boundary,
|
|
17
|
+
* so storage holds whatever `inner` stores. Recurse `StorageShape`
|
|
18
|
+
* on `inner` for the same reason.
|
|
19
|
+
*
|
|
20
|
+
* A bare top-level `ZodTransform` (no `in` schema) reads
|
|
21
|
+
* `_zod.input` directly — there's no inner to recurse into.
|
|
22
|
+
*
|
|
23
|
+
* 3. Codec / generic pipe — neither side is a transform. Read
|
|
24
|
+
* `_zod.output`. Codecs aren't write-boundary-synthesized, so the
|
|
25
|
+
* post-parse view is the only honest storage type.
|
|
26
|
+
*
|
|
27
|
+
* 4. Everything else (defaults, catch, readonly, optional, primitives,
|
|
28
|
+
* nested objects) — read `_zod.output`. Defaults and catches fire
|
|
29
|
+
* at parse time, so the post-init view is what storage holds.
|
|
30
|
+
* Nested objects delegate to Zod's own recursion on `_zod.output`,
|
|
31
|
+
* which peels nested defaults inside structural containers.
|
|
32
|
+
*
|
|
33
|
+
* Recursion: the alias calls itself on the non-transform side of a
|
|
34
|
+
* pipe so the inner shape gets the same per-key storage treatment as
|
|
35
|
+
* the top level. Without it, an inner `.default(...)` inside a
|
|
36
|
+
* transformed object would peel back to `T | undefined` (the broad
|
|
37
|
+
* input contract). Recursion only fires for pipe leaves — most leaves
|
|
38
|
+
* skip it.
|
|
39
|
+
*
|
|
40
|
+
* Implementation note: direct `_zod` property access mirrors Zod's
|
|
41
|
+
* own `$InferObjectOutput` / `$InferObjectInput`, which read
|
|
42
|
+
* `T[k]['_zod']['output']` / `T[k]['_zod']['input']` directly rather
|
|
43
|
+
* than wrapping in the top-level `output<T>` / `input<T>` conditional.
|
|
44
|
+
* Wrapping per key spawns a fresh conditional instantiation for every
|
|
45
|
+
* key; Volar's web-worker checker collapses that per-key walk to
|
|
46
|
+
* `any` once the schema is non-trivial. Property access has no
|
|
47
|
+
* conditional and resolves cleanly under the same budget.
|
|
48
|
+
*
|
|
49
|
+
* Shape access also goes through `_zod.def.shape` rather than
|
|
50
|
+
* `infer Shape from z.ZodObject<Shape>` — the latter collapses to the
|
|
51
|
+
* `$ZodShape` upper bound in the same worker because of
|
|
52
|
+
* `z.ZodObject`'s `out Shape` covariance markers.
|
|
53
|
+
*/
|
|
54
|
+
type StorageShape<S> = S extends {
|
|
55
|
+
_zod: {
|
|
56
|
+
def: {
|
|
57
|
+
type: 'object';
|
|
58
|
+
shape: infer Shape;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
} ? {
|
|
62
|
+
[K in keyof Shape]-?: StorageLeaf<Shape[K]>;
|
|
63
|
+
} : StorageLeaf<S>;
|
|
64
|
+
type StorageLeaf<L> = L extends {
|
|
65
|
+
_zod: {
|
|
66
|
+
def: {
|
|
67
|
+
type: 'pipe';
|
|
68
|
+
in: infer A;
|
|
69
|
+
out: infer B;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
} ? A extends {
|
|
73
|
+
_zod: {
|
|
74
|
+
def: {
|
|
75
|
+
type: 'transform';
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
} ? StorageShape<B> : B extends {
|
|
79
|
+
_zod: {
|
|
80
|
+
def: {
|
|
81
|
+
type: 'transform';
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
} ? StorageShape<A> : L extends {
|
|
85
|
+
_zod: {
|
|
86
|
+
output: infer Out;
|
|
87
|
+
};
|
|
88
|
+
} ? Out : never : L extends {
|
|
89
|
+
_zod: {
|
|
90
|
+
def: {
|
|
91
|
+
type: 'transform';
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
} ? L extends {
|
|
95
|
+
_zod: {
|
|
96
|
+
input: infer In;
|
|
97
|
+
};
|
|
98
|
+
} ? In : never : L extends {
|
|
99
|
+
_zod: {
|
|
100
|
+
output: infer Out;
|
|
101
|
+
};
|
|
102
|
+
} ? Out : never;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Zod v4 adapter entry point. Re-exports the adapter + the useForm
|
|
106
|
+
* wrapper that threads zod-v4-specific schema types through
|
|
107
|
+
* useAbstractForm.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Type of the value accepted at `Path` for `setValue` / `defaultValues`
|
|
112
|
+
* — the schema's `z.input<Schema>` shape at that path. Matches what
|
|
113
|
+
* `form.values.X` returns at runtime (the honest input view storage
|
|
114
|
+
* holds before transforms run).
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* const schema = z.object({
|
|
118
|
+
* flag: z.string().transform((v) => v.length > 10),
|
|
119
|
+
* })
|
|
120
|
+
* type FlagWriteIn = PathInput<typeof schema, 'flag'> // string
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
type PathInput<Schema extends z.ZodType, Path extends string> = z.input<Schema> extends GenericForm ? Path extends FlatPath<z.input<Schema>> ? NestedType<z.input<Schema>, Path> : never : never;
|
|
124
|
+
/**
|
|
125
|
+
* Type produced at `Path` after the full parse pipeline — the schema's
|
|
126
|
+
* `z.output<Schema>` shape at that path. Matches the `data` payload of
|
|
127
|
+
* `form.process()` and the value handed to `handleSubmit`'s callback.
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* const schema = z.object({
|
|
131
|
+
* flag: z.string().transform((v) => v.length > 10),
|
|
132
|
+
* })
|
|
133
|
+
* type FlagParsedOut = PathOutput<typeof schema, 'flag'> // boolean
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
type PathOutput<Schema extends z.ZodType, Path extends string> = z.output<Schema> extends GenericForm ? Path extends FlatPath<z.output<Schema>> ? NestedType<z.output<Schema>, Path> : never : never;
|
|
137
|
+
/**
|
|
138
|
+
* Create a form bound to a Zod v4 schema.
|
|
139
|
+
*
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { useForm } from 'attaform/zod'
|
|
142
|
+
* import { z } from 'zod'
|
|
143
|
+
*
|
|
144
|
+
* const form = useForm({
|
|
145
|
+
* schema: z.object({
|
|
146
|
+
* email: z.email(),
|
|
147
|
+
* password: z.string().min(8),
|
|
148
|
+
* }),
|
|
149
|
+
* defaultValues: { email: '' },
|
|
150
|
+
* })
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* Returns a form API exposing `register`, `values`, `errors`,
|
|
154
|
+
* `fields`, `setValue`, `handleSubmit`, `meta`, field-array
|
|
155
|
+
* helpers, and more. See `UseFormReturnType` for the full
|
|
156
|
+
* surface.
|
|
157
|
+
*
|
|
158
|
+
* For Zod v3, import from `attaform/zod-v3` instead.
|
|
159
|
+
*/
|
|
160
|
+
declare function useForm<Schema extends z.ZodObject>(configuration: Omit<UseFormConfiguration<z.input<Schema> extends GenericForm ? z.input<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never, AbstractSchema<z.input<Schema> extends GenericForm ? z.input<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never>, DeepPartial<DefaultValuesShape<z.input<Schema> extends GenericForm ? z.input<Schema> : never>>>, 'schema' | 'validateOn' | 'debounceMs'> & {
|
|
161
|
+
schema: Schema;
|
|
162
|
+
} & ValidateOnConfig): UseFormReturnType<z.input<Schema> extends GenericForm ? z.input<Schema> : never, z.output<Schema> extends GenericForm ? z.output<Schema> : never, StorageShape<Schema> extends GenericForm ? StorageShape<Schema> : never>;
|
|
163
|
+
|
|
164
|
+
export { useForm as u };
|
|
165
|
+
export type { PathInput as P, StorageShape as S, PathOutput as a };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { merge, set, isFunction, cloneDeep } from 'lodash-es';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { g as getAtPath, s as slimKindOf, A as AttaformErrorCode, h as humanize, e as useAbstractForm } from './attaform.
|
|
3
|
+
import { g as getAtPath, s as slimKindOf, A as AttaformErrorCode, h as humanize, e as useAbstractForm } from './attaform.B3ZaPIzS.mjs';
|
|
4
4
|
import { c as canonicalizePath } from './attaform.h1sq3BFu.mjs';
|
|
5
5
|
import { f as fieldMetaStore, g as getFieldMetaForSchema } from './attaform.D13GMFgK.mjs';
|
|
6
6
|
import { a as AttaformError, _ as __DEV__, b as InvalidUseFormConfigError } from './attaform.CIEQgJnM.mjs';
|
|
@@ -651,6 +651,14 @@ function zodAdapter(zodSchema) {
|
|
|
651
651
|
const peeled = unwrapStructuralLeafV3(leaf);
|
|
652
652
|
return getDefaultValuesFromZodSchema(peeled, true, _formKey);
|
|
653
653
|
},
|
|
654
|
+
getEmptyValueAtPath(path) {
|
|
655
|
+
if (path.length === 0) {
|
|
656
|
+
return getDefaultValuesFromZodSchema(_zodSchema, false, _formKey);
|
|
657
|
+
}
|
|
658
|
+
const leaf = walkV3ToLeafSchema(_zodSchema, path);
|
|
659
|
+
if (!leaf) return void 0;
|
|
660
|
+
return getDefaultValuesFromZodSchema(leaf, false, _formKey);
|
|
661
|
+
},
|
|
654
662
|
arrayShapeAtPath(path) {
|
|
655
663
|
if (path.length === 0) return void 0;
|
|
656
664
|
const leaf = walkV3ToLeafSchema(_zodSchema, path);
|
|
@@ -1569,16 +1577,20 @@ function useForm(configuration) {
|
|
|
1569
1577
|
const abstractSchema = isZodType(schema) ? zodAdapter(schema) : schema;
|
|
1570
1578
|
return useAbstractForm({
|
|
1571
1579
|
...configuration,
|
|
1572
|
-
//
|
|
1573
|
-
// `TypeWithNullableDynamicKeys<
|
|
1574
|
-
//
|
|
1575
|
-
//
|
|
1576
|
-
//
|
|
1577
|
-
//
|
|
1580
|
+
// `zodAdapter`'s constraint on its third generic is
|
|
1581
|
+
// `GetValueFormType extends TypeWithNullableDynamicKeys<FormSchema>`,
|
|
1582
|
+
// and `Schema` at this implementation overload is only constrained
|
|
1583
|
+
// by `extends z.ZodSchema<unknown>` — too loose for
|
|
1584
|
+
// `z.output<UnwrapZodObject<typeof schema>>` to resolve concretely.
|
|
1585
|
+
// Pass `TypeWithNullableDynamicKeys<typeof schema>` here purely to
|
|
1586
|
+
// satisfy the adapter's constraint at the structural-cast layer.
|
|
1587
|
+
// The PUBLIC signature's `GetValueFormType` default (line 67) is
|
|
1588
|
+
// what consumers see — that's `z.output<UnwrapZodObject<Schema>>`,
|
|
1589
|
+
// matching the docstring promise. Runtime is unaffected either way.
|
|
1578
1590
|
schema: abstractSchema,
|
|
1579
1591
|
defaultValues: configuration.defaultValues
|
|
1580
1592
|
});
|
|
1581
1593
|
}
|
|
1582
1594
|
|
|
1583
1595
|
export { fieldMeta as f, isZodSchemaType as i, useForm as u, withMeta as w, zodAdapter as z };
|
|
1584
|
-
//# sourceMappingURL=attaform.
|
|
1596
|
+
//# sourceMappingURL=attaform.Drt6fivF.mjs.map
|