attaform 0.17.1 → 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/shared/{attaform.B5qiXQwN.cjs → attaform.BPRHR3Zs.cjs} +11 -7
- package/dist/shared/{attaform.CVCmBKZX.mjs.map → attaform.BPRHR3Zs.cjs.map} +1 -1
- package/dist/shared/attaform.C5MH4lNh.d.mts +53 -0
- package/dist/shared/attaform.C6lbmMUe.d.ts +53 -0
- package/dist/shared/{attaform.CVCmBKZX.mjs → attaform.Drt6fivF.mjs} +11 -7
- package/dist/shared/{attaform.B5qiXQwN.cjs.map → attaform.Drt6fivF.mjs.map} +1 -1
- package/dist/shared/attaform.DtMN-MAm.d.cts +53 -0
- package/dist/zod-v3.cjs +1 -1
- package/dist/zod-v3.d.cts +33 -81
- package/dist/zod-v3.d.mts +33 -81
- package/dist/zod-v3.d.ts +33 -81
- package/dist/zod-v3.mjs +1 -1
- package/dist/zod.cjs +7 -3
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +32 -7
- package/dist/zod.d.mts +32 -7
- package/dist/zod.d.ts +32 -7
- package/dist/zod.mjs +7 -3
- package/dist/zod.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ag as ValidateOnConfig, F as FormKey, E as OnInvalidSubmitPolicy, X as PersistConfig, y as HistoryConfig, C as CoercionRegistry } from './attaform.C_5aB6EQ.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
6
|
+
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
7
|
+
* Zod's own recursion peels nested defaults inside structural
|
|
8
|
+
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
9
|
+
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
10
|
+
* pre-transform input — transforms only run at submission /
|
|
11
|
+
* validation, not at the write boundary.
|
|
12
|
+
*
|
|
13
|
+
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
14
|
+
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
15
|
+
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
16
|
+
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
17
|
+
* the preprocess input (commonly `unknown`); reach for the
|
|
18
|
+
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
19
|
+
* Transforms preserve their pre-transform input shape, which matches
|
|
20
|
+
* storage.
|
|
21
|
+
*/
|
|
22
|
+
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
23
|
+
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
24
|
+
} : z.input<S>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Configuration object for the Zod v3 `useForm` overload. Same
|
|
28
|
+
* shape as the schema-agnostic `UseFormConfiguration`, but with
|
|
29
|
+
* `schema` constrained to a `z.ZodObject` (or wrapped form).
|
|
30
|
+
*/
|
|
31
|
+
type UseFormConfigurationWithZod<Schema extends z.ZodType<unknown>, DefaultValues> = ValidateOnConfig & {
|
|
32
|
+
/** A Zod v3 `ZodObject` schema (or one wrapped in `.optional()` / `.nullable()` / `.default()` / `.refine()`). */
|
|
33
|
+
schema: Schema extends z.ZodType<unknown> ? UnwrapZodObject<Schema> extends z.ZodObject<z.ZodRawShape> ? Schema : never : never;
|
|
34
|
+
key?: FormKey;
|
|
35
|
+
defaultValues?: DefaultValues;
|
|
36
|
+
strict?: boolean;
|
|
37
|
+
onInvalidSubmit?: OnInvalidSubmitPolicy;
|
|
38
|
+
persist?: PersistConfig;
|
|
39
|
+
history?: HistoryConfig;
|
|
40
|
+
rememberVariants?: boolean;
|
|
41
|
+
coerce?: boolean | CoercionRegistry;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
45
|
+
* `.transform()` wrappers off a Zod v3 schema to reach the inner
|
|
46
|
+
* `ZodObject`. Returns `never` if no `ZodObject` is found.
|
|
47
|
+
*
|
|
48
|
+
* Used internally by the v3 `useForm` overload to verify the
|
|
49
|
+
* supplied schema bottoms out at a `ZodObject`.
|
|
50
|
+
*/
|
|
51
|
+
type UnwrapZodObject<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : never;
|
|
52
|
+
|
|
53
|
+
export type { StorageShape as S, UnwrapZodObject as U, UseFormConfigurationWithZod as a };
|
package/dist/zod-v3.cjs
CHANGED
package/dist/zod-v3.d.cts
CHANGED
|
@@ -1,86 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType, F as FormKey, ar as SchemaFactoryOptions, o as FieldMetaPayload } from './shared/attaform.C_5aB6EQ.cjs';
|
|
3
3
|
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.C_5aB6EQ.cjs';
|
|
4
|
+
import { U as UnwrapZodObject, a as UseFormConfigurationWithZod, S as StorageShape } from './shared/attaform.DtMN-MAm.cjs';
|
|
4
5
|
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.C6qzEdIM.cjs';
|
|
5
6
|
import 'vue';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
9
|
-
* when writing a custom adapter that needs to read internals
|
|
10
|
-
* directly. Most consumers should never reach for this.
|
|
11
|
-
*/
|
|
12
|
-
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
13
|
-
_def: {
|
|
14
|
-
typeName: string;
|
|
15
|
-
innerType: z.ZodTypeAny;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
20
|
-
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
21
|
-
* reflect the runtime reality that those slots may be missing.
|
|
22
|
-
*
|
|
23
|
-
* Used internally by the v3 adapter as the read-side type for
|
|
24
|
-
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
25
|
-
*/
|
|
26
|
-
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
27
|
-
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
28
|
-
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
29
|
-
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
30
|
-
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
31
|
-
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
32
|
-
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
33
|
-
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Configuration object for the Zod v3 `useForm` overload. Same
|
|
37
|
-
* shape as the schema-agnostic `UseFormConfiguration`, but with
|
|
38
|
-
* `schema` constrained to a `z.ZodObject` (or wrapped form).
|
|
39
|
-
*/
|
|
40
|
-
type UseFormConfigurationWithZod<Schema extends z.ZodType<unknown>, DefaultValues> = ValidateOnConfig & {
|
|
41
|
-
/** A Zod v3 `ZodObject` schema (or one wrapped in `.optional()` / `.nullable()` / `.default()` / `.refine()`). */
|
|
42
|
-
schema: Schema extends z.ZodType<unknown> ? UnwrapZodObject<Schema> extends z.ZodObject<z.ZodRawShape> ? Schema : never : never;
|
|
43
|
-
key?: FormKey;
|
|
44
|
-
defaultValues?: DefaultValues;
|
|
45
|
-
strict?: boolean;
|
|
46
|
-
onInvalidSubmit?: OnInvalidSubmitPolicy;
|
|
47
|
-
persist?: PersistConfig;
|
|
48
|
-
history?: HistoryConfig;
|
|
49
|
-
rememberVariants?: boolean;
|
|
50
|
-
coerce?: boolean | CoercionRegistry;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
54
|
-
* `.transform()` wrappers off a Zod v3 schema to reach the inner
|
|
55
|
-
* `ZodObject`. Returns `never` if no `ZodObject` is found.
|
|
56
|
-
*
|
|
57
|
-
* Used internally by the v3 `useForm` overload to verify the
|
|
58
|
-
* supplied schema bottoms out at a `ZodObject`.
|
|
59
|
-
*/
|
|
60
|
-
type UnwrapZodObject<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : never;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
64
|
-
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
65
|
-
* Zod's own recursion peels nested defaults inside structural
|
|
66
|
-
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
67
|
-
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
68
|
-
* pre-transform input — transforms only run at submission /
|
|
69
|
-
* validation, not at the write boundary.
|
|
70
|
-
*
|
|
71
|
-
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
72
|
-
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
73
|
-
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
74
|
-
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
75
|
-
* the preprocess input (commonly `unknown`); reach for the
|
|
76
|
-
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
77
|
-
* Transforms preserve their pre-transform input shape, which matches
|
|
78
|
-
* storage.
|
|
79
|
-
*/
|
|
80
|
-
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
81
|
-
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
82
|
-
} : z.input<S>;
|
|
83
|
-
|
|
84
8
|
/**
|
|
85
9
|
* Create a form bound to a custom `AbstractSchema` adapter.
|
|
86
10
|
*
|
|
@@ -119,7 +43,35 @@ declare function useForm<Form extends GenericForm, GetValueFormType extends Gene
|
|
|
119
43
|
*
|
|
120
44
|
* For Zod v4, import from `attaform/zod` instead.
|
|
121
45
|
*/
|
|
122
|
-
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm =
|
|
46
|
+
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm = z.output<UnwrapZodObject<Schema>> extends GenericForm ? z.output<UnwrapZodObject<Schema>> : never>(configuration: UseFormConfigurationWithZod<Schema, DeepPartial<DefaultValuesShape<z.input<UnwrapZodObject<Schema>>>>>): UseFormReturnType<z.input<UnwrapZodObject<Schema>>, GetValueFormType, StorageShape<UnwrapZodObject<Schema>> extends GenericForm ? StorageShape<UnwrapZodObject<Schema>> : never>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
50
|
+
* when writing a custom adapter that needs to read internals
|
|
51
|
+
* directly. Most consumers should never reach for this.
|
|
52
|
+
*/
|
|
53
|
+
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
54
|
+
_def: {
|
|
55
|
+
typeName: string;
|
|
56
|
+
innerType: z.ZodTypeAny;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
61
|
+
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
62
|
+
* reflect the runtime reality that those slots may be missing.
|
|
63
|
+
*
|
|
64
|
+
* Used internally by the v3 adapter as the read-side type for
|
|
65
|
+
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
66
|
+
*/
|
|
67
|
+
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
68
|
+
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
69
|
+
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
70
|
+
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
71
|
+
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
72
|
+
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
73
|
+
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
74
|
+
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
123
75
|
|
|
124
76
|
/**
|
|
125
77
|
* Wrap a Zod v3 `ZodObject` schema in an `AbstractSchema` factory.
|
|
@@ -260,5 +212,5 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
260
212
|
*/
|
|
261
213
|
declare function withMeta<S extends z.ZodTypeAny>(schema: S, payload: FieldMetaPayload): S;
|
|
262
214
|
|
|
263
|
-
export { FieldMetaPayload, fieldMeta, isZodSchemaType, useForm, withMeta, zodAdapter };
|
|
264
|
-
export type { TypeWithNullableDynamicKeys,
|
|
215
|
+
export { FieldMetaPayload, UnwrapZodObject, UseFormConfigurationWithZod, fieldMeta, isZodSchemaType, useForm, withMeta, zodAdapter };
|
|
216
|
+
export type { TypeWithNullableDynamicKeys, ZodTypeWithInnerType };
|
package/dist/zod-v3.d.mts
CHANGED
|
@@ -1,86 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType, F as FormKey, ar as SchemaFactoryOptions, o as FieldMetaPayload } from './shared/attaform.C_5aB6EQ.mjs';
|
|
3
3
|
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.C_5aB6EQ.mjs';
|
|
4
|
+
import { U as UnwrapZodObject, a as UseFormConfigurationWithZod, S as StorageShape } from './shared/attaform.C5MH4lNh.mjs';
|
|
4
5
|
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.B1jvxsOF.mjs';
|
|
5
6
|
import 'vue';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
9
|
-
* when writing a custom adapter that needs to read internals
|
|
10
|
-
* directly. Most consumers should never reach for this.
|
|
11
|
-
*/
|
|
12
|
-
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
13
|
-
_def: {
|
|
14
|
-
typeName: string;
|
|
15
|
-
innerType: z.ZodTypeAny;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
20
|
-
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
21
|
-
* reflect the runtime reality that those slots may be missing.
|
|
22
|
-
*
|
|
23
|
-
* Used internally by the v3 adapter as the read-side type for
|
|
24
|
-
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
25
|
-
*/
|
|
26
|
-
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
27
|
-
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
28
|
-
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
29
|
-
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
30
|
-
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
31
|
-
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
32
|
-
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
33
|
-
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Configuration object for the Zod v3 `useForm` overload. Same
|
|
37
|
-
* shape as the schema-agnostic `UseFormConfiguration`, but with
|
|
38
|
-
* `schema` constrained to a `z.ZodObject` (or wrapped form).
|
|
39
|
-
*/
|
|
40
|
-
type UseFormConfigurationWithZod<Schema extends z.ZodType<unknown>, DefaultValues> = ValidateOnConfig & {
|
|
41
|
-
/** A Zod v3 `ZodObject` schema (or one wrapped in `.optional()` / `.nullable()` / `.default()` / `.refine()`). */
|
|
42
|
-
schema: Schema extends z.ZodType<unknown> ? UnwrapZodObject<Schema> extends z.ZodObject<z.ZodRawShape> ? Schema : never : never;
|
|
43
|
-
key?: FormKey;
|
|
44
|
-
defaultValues?: DefaultValues;
|
|
45
|
-
strict?: boolean;
|
|
46
|
-
onInvalidSubmit?: OnInvalidSubmitPolicy;
|
|
47
|
-
persist?: PersistConfig;
|
|
48
|
-
history?: HistoryConfig;
|
|
49
|
-
rememberVariants?: boolean;
|
|
50
|
-
coerce?: boolean | CoercionRegistry;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
54
|
-
* `.transform()` wrappers off a Zod v3 schema to reach the inner
|
|
55
|
-
* `ZodObject`. Returns `never` if no `ZodObject` is found.
|
|
56
|
-
*
|
|
57
|
-
* Used internally by the v3 `useForm` overload to verify the
|
|
58
|
-
* supplied schema bottoms out at a `ZodObject`.
|
|
59
|
-
*/
|
|
60
|
-
type UnwrapZodObject<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : never;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
64
|
-
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
65
|
-
* Zod's own recursion peels nested defaults inside structural
|
|
66
|
-
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
67
|
-
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
68
|
-
* pre-transform input — transforms only run at submission /
|
|
69
|
-
* validation, not at the write boundary.
|
|
70
|
-
*
|
|
71
|
-
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
72
|
-
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
73
|
-
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
74
|
-
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
75
|
-
* the preprocess input (commonly `unknown`); reach for the
|
|
76
|
-
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
77
|
-
* Transforms preserve their pre-transform input shape, which matches
|
|
78
|
-
* storage.
|
|
79
|
-
*/
|
|
80
|
-
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
81
|
-
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
82
|
-
} : z.input<S>;
|
|
83
|
-
|
|
84
8
|
/**
|
|
85
9
|
* Create a form bound to a custom `AbstractSchema` adapter.
|
|
86
10
|
*
|
|
@@ -119,7 +43,35 @@ declare function useForm<Form extends GenericForm, GetValueFormType extends Gene
|
|
|
119
43
|
*
|
|
120
44
|
* For Zod v4, import from `attaform/zod` instead.
|
|
121
45
|
*/
|
|
122
|
-
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm =
|
|
46
|
+
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm = z.output<UnwrapZodObject<Schema>> extends GenericForm ? z.output<UnwrapZodObject<Schema>> : never>(configuration: UseFormConfigurationWithZod<Schema, DeepPartial<DefaultValuesShape<z.input<UnwrapZodObject<Schema>>>>>): UseFormReturnType<z.input<UnwrapZodObject<Schema>>, GetValueFormType, StorageShape<UnwrapZodObject<Schema>> extends GenericForm ? StorageShape<UnwrapZodObject<Schema>> : never>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
50
|
+
* when writing a custom adapter that needs to read internals
|
|
51
|
+
* directly. Most consumers should never reach for this.
|
|
52
|
+
*/
|
|
53
|
+
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
54
|
+
_def: {
|
|
55
|
+
typeName: string;
|
|
56
|
+
innerType: z.ZodTypeAny;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
61
|
+
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
62
|
+
* reflect the runtime reality that those slots may be missing.
|
|
63
|
+
*
|
|
64
|
+
* Used internally by the v3 adapter as the read-side type for
|
|
65
|
+
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
66
|
+
*/
|
|
67
|
+
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
68
|
+
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
69
|
+
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
70
|
+
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
71
|
+
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
72
|
+
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
73
|
+
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
74
|
+
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
123
75
|
|
|
124
76
|
/**
|
|
125
77
|
* Wrap a Zod v3 `ZodObject` schema in an `AbstractSchema` factory.
|
|
@@ -260,5 +212,5 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
260
212
|
*/
|
|
261
213
|
declare function withMeta<S extends z.ZodTypeAny>(schema: S, payload: FieldMetaPayload): S;
|
|
262
214
|
|
|
263
|
-
export { FieldMetaPayload, fieldMeta, isZodSchemaType, useForm, withMeta, zodAdapter };
|
|
264
|
-
export type { TypeWithNullableDynamicKeys,
|
|
215
|
+
export { FieldMetaPayload, UnwrapZodObject, UseFormConfigurationWithZod, fieldMeta, isZodSchemaType, useForm, withMeta, zodAdapter };
|
|
216
|
+
export type { TypeWithNullableDynamicKeys, ZodTypeWithInnerType };
|
package/dist/zod-v3.d.ts
CHANGED
|
@@ -1,86 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType, F as FormKey, ar as SchemaFactoryOptions, o as FieldMetaPayload } from './shared/attaform.C_5aB6EQ.js';
|
|
3
3
|
export { ae as Unset, ao as isUnset, aq as unset } from './shared/attaform.C_5aB6EQ.js';
|
|
4
|
+
import { U as UnwrapZodObject, a as UseFormConfigurationWithZod, S as StorageShape } from './shared/attaform.C6lbmMUe.js';
|
|
4
5
|
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.CTwNcpLE.js';
|
|
5
6
|
import 'vue';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
9
|
-
* when writing a custom adapter that needs to read internals
|
|
10
|
-
* directly. Most consumers should never reach for this.
|
|
11
|
-
*/
|
|
12
|
-
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
13
|
-
_def: {
|
|
14
|
-
typeName: string;
|
|
15
|
-
innerType: z.ZodTypeAny;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
20
|
-
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
21
|
-
* reflect the runtime reality that those slots may be missing.
|
|
22
|
-
*
|
|
23
|
-
* Used internally by the v3 adapter as the read-side type for
|
|
24
|
-
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
25
|
-
*/
|
|
26
|
-
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
27
|
-
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
28
|
-
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
29
|
-
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
30
|
-
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
31
|
-
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
32
|
-
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
33
|
-
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Configuration object for the Zod v3 `useForm` overload. Same
|
|
37
|
-
* shape as the schema-agnostic `UseFormConfiguration`, but with
|
|
38
|
-
* `schema` constrained to a `z.ZodObject` (or wrapped form).
|
|
39
|
-
*/
|
|
40
|
-
type UseFormConfigurationWithZod<Schema extends z.ZodType<unknown>, DefaultValues> = ValidateOnConfig & {
|
|
41
|
-
/** A Zod v3 `ZodObject` schema (or one wrapped in `.optional()` / `.nullable()` / `.default()` / `.refine()`). */
|
|
42
|
-
schema: Schema extends z.ZodType<unknown> ? UnwrapZodObject<Schema> extends z.ZodObject<z.ZodRawShape> ? Schema : never : never;
|
|
43
|
-
key?: FormKey;
|
|
44
|
-
defaultValues?: DefaultValues;
|
|
45
|
-
strict?: boolean;
|
|
46
|
-
onInvalidSubmit?: OnInvalidSubmitPolicy;
|
|
47
|
-
persist?: PersistConfig;
|
|
48
|
-
history?: HistoryConfig;
|
|
49
|
-
rememberVariants?: boolean;
|
|
50
|
-
coerce?: boolean | CoercionRegistry;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
54
|
-
* `.transform()` wrappers off a Zod v3 schema to reach the inner
|
|
55
|
-
* `ZodObject`. Returns `never` if no `ZodObject` is found.
|
|
56
|
-
*
|
|
57
|
-
* Used internally by the v3 `useForm` overload to verify the
|
|
58
|
-
* supplied schema bottoms out at a `ZodObject`.
|
|
59
|
-
*/
|
|
60
|
-
type UnwrapZodObject<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : never;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* v3 mirror of the Zod v4 `StorageShape`. Per top-level key, default
|
|
64
|
-
* to `z.output<Shape[K]>` (the post-init view — defaults have fired,
|
|
65
|
-
* Zod's own recursion peels nested defaults inside structural
|
|
66
|
-
* containers); fall back to `z.input<Shape[K]>` for transform / pipe
|
|
67
|
-
* carriers (`ZodEffects`, `ZodPipeline`) where storage holds the
|
|
68
|
-
* pre-transform input — transforms only run at submission /
|
|
69
|
-
* validation, not at the write boundary.
|
|
70
|
-
*
|
|
71
|
-
* v3 quirk: `ZodEffects` covers BOTH `.transform()` and
|
|
72
|
-
* `z.preprocess()` at the TS level — v3 doesn't carry a separate
|
|
73
|
-
* preprocess class the way v4 does. Deferring to `z.input` for
|
|
74
|
-
* `ZodEffects` means a top-level `z.preprocess(fn, T)` leaf reads as
|
|
75
|
-
* the preprocess input (commonly `unknown`); reach for the
|
|
76
|
-
* `AbstractSchema` escape hatch if a stronger type is needed.
|
|
77
|
-
* Transforms preserve their pre-transform input shape, which matches
|
|
78
|
-
* storage.
|
|
79
|
-
*/
|
|
80
|
-
type StorageShape<S extends z.ZodTypeAny> = S extends z.ZodObject<infer Shape> ? {
|
|
81
|
-
[K in keyof Shape]-?: Shape[K] extends z.ZodEffects<z.ZodTypeAny> | z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny> ? z.input<Shape[K]> : z.output<Shape[K]>;
|
|
82
|
-
} : z.input<S>;
|
|
83
|
-
|
|
84
8
|
/**
|
|
85
9
|
* Create a form bound to a custom `AbstractSchema` adapter.
|
|
86
10
|
*
|
|
@@ -119,7 +43,35 @@ declare function useForm<Form extends GenericForm, GetValueFormType extends Gene
|
|
|
119
43
|
*
|
|
120
44
|
* For Zod v4, import from `attaform/zod` instead.
|
|
121
45
|
*/
|
|
122
|
-
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm =
|
|
46
|
+
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm = z.output<UnwrapZodObject<Schema>> extends GenericForm ? z.output<UnwrapZodObject<Schema>> : never>(configuration: UseFormConfigurationWithZod<Schema, DeepPartial<DefaultValuesShape<z.input<UnwrapZodObject<Schema>>>>>): UseFormReturnType<z.input<UnwrapZodObject<Schema>>, GetValueFormType, StorageShape<UnwrapZodObject<Schema>> extends GenericForm ? StorageShape<UnwrapZodObject<Schema>> : never>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
50
|
+
* when writing a custom adapter that needs to read internals
|
|
51
|
+
* directly. Most consumers should never reach for this.
|
|
52
|
+
*/
|
|
53
|
+
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
54
|
+
_def: {
|
|
55
|
+
typeName: string;
|
|
56
|
+
innerType: z.ZodTypeAny;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
61
|
+
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
62
|
+
* reflect the runtime reality that those slots may be missing.
|
|
63
|
+
*
|
|
64
|
+
* Used internally by the v3 adapter as the read-side type for
|
|
65
|
+
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
66
|
+
*/
|
|
67
|
+
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
68
|
+
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
69
|
+
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
70
|
+
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
71
|
+
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
72
|
+
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
73
|
+
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
74
|
+
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
123
75
|
|
|
124
76
|
/**
|
|
125
77
|
* Wrap a Zod v3 `ZodObject` schema in an `AbstractSchema` factory.
|
|
@@ -260,5 +212,5 @@ declare const fieldMeta: FieldMetaRegistryV3;
|
|
|
260
212
|
*/
|
|
261
213
|
declare function withMeta<S extends z.ZodTypeAny>(schema: S, payload: FieldMetaPayload): S;
|
|
262
214
|
|
|
263
|
-
export { FieldMetaPayload, fieldMeta, isZodSchemaType, useForm, withMeta, zodAdapter };
|
|
264
|
-
export type { TypeWithNullableDynamicKeys,
|
|
215
|
+
export { FieldMetaPayload, UnwrapZodObject, UseFormConfigurationWithZod, fieldMeta, isZodSchemaType, useForm, withMeta, zodAdapter };
|
|
216
|
+
export type { TypeWithNullableDynamicKeys, ZodTypeWithInnerType };
|
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.
|
|
1
|
+
export { f as fieldMeta, i as isZodSchemaType, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.Drt6fivF.mjs';
|
|
2
2
|
export { A as AttaformErrorCode, i as injectForm, a as isUnset, u as unset } from './shared/attaform.B3ZaPIzS.mjs';
|
|
3
3
|
export { u as useRegister } from './shared/attaform.CIEQgJnM.mjs';
|
|
4
4
|
//# sourceMappingURL=zod-v3.mjs.map
|
package/dist/zod.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const plugin = require('./shared/attaform.Dee2rU1P.cjs');
|
|
4
|
-
const useForm$1 = require('./shared/attaform.
|
|
4
|
+
const useForm$1 = require('./shared/attaform.BPRHR3Zs.cjs');
|
|
5
5
|
const index = require('./shared/attaform.BV40t5y2.cjs');
|
|
6
6
|
const useFormContext = require('./shared/attaform.Cer8JO_P.cjs');
|
|
7
7
|
const fieldMetaStore = require('./shared/attaform.C8CyvYa_.cjs');
|
|
@@ -19,9 +19,13 @@ function useForm(configuration) {
|
|
|
19
19
|
}
|
|
20
20
|
const { schema } = configuration;
|
|
21
21
|
if (isZodV4SchemaShape(schema)) {
|
|
22
|
-
return index.useForm(
|
|
22
|
+
return index.useForm(
|
|
23
|
+
configuration
|
|
24
|
+
);
|
|
23
25
|
}
|
|
24
|
-
return useForm$1.useForm(
|
|
26
|
+
return useForm$1.useForm(
|
|
27
|
+
configuration
|
|
28
|
+
);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
const fieldMeta = fieldMetaStore.fieldMetaStore;
|
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","../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 { StorageShape } from '../zod-v4/types-storage-shape'\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.input<Schema> extends GenericForm ? z.input<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n AbstractSchema<\n z.input<Schema> extends GenericForm ? z.input<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never\n >,\n DeepPartial<DefaultValuesShape<z.input<Schema> extends GenericForm ? z.input<Schema> : never>>\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<\n z.input<Schema> extends GenericForm ? z.input<Schema> : never,\n z.output<Schema> extends GenericForm ? z.output<Schema> : never,\n StorageShape<Schema> extends GenericForm ? StorageShape<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;;ACWO,SAAS,QACd,aAAA,EAgBA;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;;;;;;;;;;;"}
|
|
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 * Type-level dispatch happens through a single signature with a\n * union constraint — `Schema extends z.ZodObject |\n * zV3.ZodObject<zV3.ZodRawShape>`. The configuration parameter and\n * return type both dispatch conditionally on whether `Schema` is a\n * v4 or v3 object. The two majors don't structurally satisfy each\n * other's `ZodObject` constraints (v4 has `loose` / `safeExtend` /\n * `def` / `type` members v3 lacks), so neither alone is enough — the\n * union accepts both, and the conditional return type routes through\n * the matching adapter's `StorageShape` / `z.input` / `z.output`.\n *\n * A single signature (rather than overloads) keeps `typeof\n * useForm<X>` instantiation expressions in test code unambiguous:\n * TypeScript's overload-resolution rules for these expressions are\n * brittle when multiple overloads partially match, so we collapse to\n * one signature.\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 type { z as zV3 } from 'zod-v3'\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 { StorageShape as StorageShapeV4 } from '../zod-v4/types-storage-shape'\nimport type { StorageShape as StorageShapeV3 } from '../zod-v3/types-storage-shape'\nimport type { UnwrapZodObject } from '../zod-v3/types-zod-adapter'\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// Per-major projections. Each dispatches a single Schema to the\n// matching adapter's input / output / storage-shape slot. The\n// trailing `never` arms catch the \"other major\" case so an isolated\n// instantiation stays well-formed; the union constraint on the\n// public signature guarantees one arm always fires.\n// ───────────────────────────────────────────────────────────────────\n\ntype FormInput<Schema> = Schema extends z.ZodObject\n ? z.input<Schema> extends GenericForm\n ? z.input<Schema>\n : never\n : Schema extends zV3.ZodObject<zV3.ZodRawShape>\n ? zV3.input<UnwrapZodObject<Schema>> extends GenericForm\n ? zV3.input<UnwrapZodObject<Schema>>\n : never\n : never\n\ntype FormOutput<Schema> = Schema extends z.ZodObject\n ? z.output<Schema> extends GenericForm\n ? z.output<Schema>\n : never\n : Schema extends zV3.ZodObject<zV3.ZodRawShape>\n ? zV3.output<UnwrapZodObject<Schema>> extends GenericForm\n ? zV3.output<UnwrapZodObject<Schema>>\n : never\n : never\n\ntype FormStorageShape<Schema> = Schema extends z.ZodObject\n ? StorageShapeV4<Schema> extends GenericForm\n ? StorageShapeV4<Schema>\n : never\n : Schema extends zV3.ZodObject<zV3.ZodRawShape>\n ? StorageShapeV3<UnwrapZodObject<Schema>> extends GenericForm\n ? StorageShapeV3<UnwrapZodObject<Schema>>\n : never\n : never\n\n// Single unified configuration shape. The outer structure is\n// non-conditional (so TS can resolve it for any Schema satisfying\n// the union constraint, including generic `F extends z.ZodObject`\n// helpers in test code); only the field-level types dispatch on\n// Schema kind via `FormInput` / `FormOutput`. The runtime cast\n// passes the configuration through unchanged — each adapter's own\n// signature absorbs the residual structural drift.\ntype UnifiedConfiguration<Schema> = Omit<\n UseFormConfiguration<\n FormInput<Schema>,\n FormOutput<Schema>,\n AbstractSchema<FormInput<Schema>, FormOutput<Schema>>,\n DeepPartial<DefaultValuesShape<FormInput<Schema>>>\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n> & { schema: Schema } & ValidateOnConfig\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 works transparently for both Zod v3 and Zod v4\n * schemas — the adapter is selected from the schema's shape at both\n * runtime and type-check time. `form.values`, `form.fields`,\n * `register`, and the `handleSubmit` callback data type all resolve\n * against the matching adapter's storage shape; consumers don't need\n * to reach for `attaform/zod-v3` or `attaform/zod-v4` to get full\n * inference. Those subpath entries remain as lean-bundle escape\n * hatches for non-Vite tooling, not correctness escape hatches.\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 | zV3.ZodObject<zV3.ZodRawShape>>(\n configuration: UnifiedConfiguration<Schema>\n): UseFormReturnType<FormInput<Schema>, FormOutput<Schema>, FormStorageShape<Schema>> {\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(\n configuration as Parameters<typeof useFormV4>[0]\n ) as unknown as UseFormReturnType<\n FormInput<Schema>,\n FormOutput<Schema>,\n FormStorageShape<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.\n return useFormV3(\n configuration as Parameters<typeof useFormV3>[0]\n ) as unknown as UseFormReturnType<FormInput<Schema>, FormOutput<Schema>, FormStorageShape<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;;ACyFO,SAAS,QACd,aAAA,EACoF;AAEpF,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,aAAA;AAAA,MACL;AAAA,KACF;AAAA,EAKF;AAKA,EAAA,OAAOC,iBAAA;AAAA,IACL;AAAA,GACF;AACF;;AC/HO,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;;;;;;;;;;;"}
|