attaform 0.17.0 → 0.17.1

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 (56) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.d.cts +4 -4
  3. package/dist/index.d.mts +4 -4
  4. package/dist/index.d.ts +4 -4
  5. package/dist/index.mjs +2 -2
  6. package/dist/nuxt.d.cts +1 -1
  7. package/dist/nuxt.d.mts +1 -1
  8. package/dist/nuxt.d.ts +1 -1
  9. package/dist/shared/{attaform.ClfCi1i2.d.mts → attaform.B1jvxsOF.d.mts} +1 -1
  10. package/dist/shared/{attaform.BT55rDNN.mjs → attaform.B3ZaPIzS.mjs} +15 -2
  11. package/dist/shared/attaform.B3ZaPIzS.mjs.map +1 -0
  12. package/dist/shared/{attaform.0Wg7UEeX.cjs → attaform.B5qiXQwN.cjs} +10 -2
  13. package/dist/shared/attaform.B5qiXQwN.cjs.map +1 -0
  14. package/dist/shared/{attaform.C6_zOf8x.cjs → attaform.BV40t5y2.cjs} +16 -6
  15. package/dist/shared/attaform.BV40t5y2.cjs.map +1 -0
  16. package/dist/shared/attaform.C0iFnTN0.d.ts +165 -0
  17. package/dist/shared/{attaform.D7lomopc.d.cts → attaform.C6qzEdIM.d.cts} +1 -1
  18. package/dist/shared/attaform.CHorcsIU.d.cts +165 -0
  19. package/dist/shared/{attaform.B0zue7zt.d.ts → attaform.CTwNcpLE.d.ts} +1 -1
  20. package/dist/shared/{attaform.D6Q5ZP8L.mjs → attaform.CVCmBKZX.mjs} +10 -2
  21. package/dist/shared/attaform.CVCmBKZX.mjs.map +1 -0
  22. package/dist/shared/{attaform.BYbsV2Wv.d.mts → attaform.C_5aB6EQ.d.cts} +95 -15
  23. package/dist/shared/{attaform.BYbsV2Wv.d.ts → attaform.C_5aB6EQ.d.mts} +95 -15
  24. package/dist/shared/{attaform.BYbsV2Wv.d.cts → attaform.C_5aB6EQ.d.ts} +95 -15
  25. package/dist/shared/{attaform.BFumZXY2.cjs → attaform.Cer8JO_P.cjs} +15 -2
  26. package/dist/shared/attaform.Cer8JO_P.cjs.map +1 -0
  27. package/dist/shared/{attaform.Cj0pCNVn.mjs → attaform.CpERWz3u.mjs} +16 -6
  28. package/dist/shared/attaform.CpERWz3u.mjs.map +1 -0
  29. package/dist/shared/attaform.CuE-bS1C.d.mts +165 -0
  30. package/dist/zod-v3.cjs +2 -2
  31. package/dist/zod-v3.d.cts +26 -4
  32. package/dist/zod-v3.d.mts +26 -4
  33. package/dist/zod-v3.d.ts +26 -4
  34. package/dist/zod-v3.mjs +2 -2
  35. package/dist/zod-v4.cjs +2 -2
  36. package/dist/zod-v4.d.cts +4 -4
  37. package/dist/zod-v4.d.mts +4 -4
  38. package/dist/zod-v4.d.ts +4 -4
  39. package/dist/zod-v4.mjs +2 -2
  40. package/dist/zod.cjs +3 -3
  41. package/dist/zod.cjs.map +1 -1
  42. package/dist/zod.d.cts +6 -5
  43. package/dist/zod.d.mts +6 -5
  44. package/dist/zod.d.ts +6 -5
  45. package/dist/zod.mjs +3 -3
  46. package/dist/zod.mjs.map +1 -1
  47. package/package.json +4 -4
  48. package/dist/shared/attaform.0Wg7UEeX.cjs.map +0 -1
  49. package/dist/shared/attaform.AOgGyRoI.d.cts +0 -65
  50. package/dist/shared/attaform.BFumZXY2.cjs.map +0 -1
  51. package/dist/shared/attaform.BQ-iGGWd.d.mts +0 -65
  52. package/dist/shared/attaform.BT55rDNN.mjs.map +0 -1
  53. package/dist/shared/attaform.C6_zOf8x.cjs.map +0 -1
  54. package/dist/shared/attaform.CX9v2M8k.d.ts +0 -65
  55. package/dist/shared/attaform.Cj0pCNVn.mjs.map +0 -1
  56. 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.js';
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,4 +1,4 @@
1
- import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.BYbsV2Wv.cjs';
1
+ import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.C_5aB6EQ.cjs';
2
2
  import { Ref } from 'vue';
3
3
 
4
4
  /**
@@ -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.cjs';
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,4 +1,4 @@
1
- import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.BYbsV2Wv.js';
1
+ import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.C_5aB6EQ.js';
2
2
  import { Ref } from 'vue';
3
3
 
4
4
  /**
@@ -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.BT55rDNN.mjs';
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);
@@ -1581,4 +1589,4 @@ function useForm(configuration) {
1581
1589
  }
1582
1590
 
1583
1591
  export { fieldMeta as f, isZodSchemaType as i, useForm as u, withMeta as w, zodAdapter as z };
1584
- //# sourceMappingURL=attaform.D6Q5ZP8L.mjs.map
1592
+ //# sourceMappingURL=attaform.CVCmBKZX.mjs.map