@hookform/resolvers 4.1.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/ajv/package.json +1 -1
- package/arktype/dist/arktype.d.ts +8 -20
- package/arktype/dist/arktype.js +1 -1
- package/arktype/dist/arktype.js.map +1 -1
- package/arktype/dist/arktype.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs.map +1 -1
- package/arktype/dist/arktype.module.js +1 -1
- package/arktype/dist/arktype.module.js.map +1 -1
- package/arktype/dist/arktype.umd.js +1 -1
- package/arktype/dist/arktype.umd.js.map +1 -1
- package/arktype/package.json +1 -1
- package/arktype/src/__tests__/Form.tsx +0 -28
- package/arktype/src/__tests__/arktype.ts +56 -0
- package/arktype/src/arktype.ts +58 -22
- package/class-validator/src/__tests__/Form.tsx +0 -26
- package/computed-types/dist/computed-types.d.ts +2 -3
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/package.json +1 -1
- package/computed-types/src/__tests__/Form.tsx +0 -28
- package/computed-types/src/__tests__/computed-types.ts +55 -1
- package/computed-types/src/computed-types.ts +7 -5
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/effect-ts/dist/effect-ts.d.ts +8 -16
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/package.json +1 -1
- package/effect-ts/src/__tests__/effect-ts.ts +61 -0
- package/effect-ts/src/effect-ts.ts +21 -3
- package/fluentvalidation-ts/package.json +1 -1
- package/io-ts/dist/io-ts.d.ts +8 -17
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.modern.mjs.map +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/package.json +1 -1
- package/io-ts/src/__tests__/__fixtures__/data.ts +3 -3
- package/io-ts/src/__tests__/io-ts.ts +54 -0
- package/io-ts/src/io-ts.ts +35 -8
- package/joi/package.json +1 -1
- package/nope/package.json +1 -1
- package/package.json +13 -13
- package/standard-schema/dist/standard-schema.d.ts +6 -23
- package/standard-schema/dist/standard-schema.js +1 -1
- package/standard-schema/dist/standard-schema.js.map +1 -1
- package/standard-schema/dist/standard-schema.mjs +1 -1
- package/standard-schema/dist/standard-schema.modern.mjs +1 -1
- package/standard-schema/dist/standard-schema.modern.mjs.map +1 -1
- package/standard-schema/dist/standard-schema.module.js +1 -1
- package/standard-schema/dist/standard-schema.module.js.map +1 -1
- package/standard-schema/dist/standard-schema.umd.js +1 -1
- package/standard-schema/dist/standard-schema.umd.js.map +1 -1
- package/standard-schema/package.json +1 -1
- package/standard-schema/src/__tests__/Form.tsx +0 -28
- package/standard-schema/src/__tests__/__fixtures__/data.ts +2 -2
- package/standard-schema/src/__tests__/standard-schema.ts +78 -1
- package/standard-schema/src/standard-schema.ts +32 -5
- package/superstruct/dist/superstruct.d.ts +6 -20
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/package.json +1 -1
- package/superstruct/src/__tests__/superstruct.ts +60 -0
- package/superstruct/src/superstruct.ts +20 -4
- package/typanion/dist/typanion.d.ts +8 -16
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/package.json +1 -1
- package/typanion/src/__tests__/Form.tsx +0 -32
- package/typanion/src/__tests__/typanion.ts +49 -0
- package/typanion/src/typanion.ts +22 -4
- package/typebox/dist/typebox.d.ts +3 -3
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/package.json +1 -1
- package/typebox/src/__tests__/Form-native-validation-compiler.tsx +1 -1
- package/typebox/src/__tests__/Form.tsx +0 -28
- package/typebox/src/__tests__/__fixtures__/data.ts +3 -3
- package/typebox/src/__tests__/typebox.ts +98 -0
- package/typebox/src/typebox.ts +7 -14
- package/typeschema/dist/index.d.ts +0 -1
- package/typeschema/dist/typeschema.d.ts +8 -19
- package/typeschema/dist/typeschema.js +1 -1
- package/typeschema/dist/typeschema.js.map +1 -1
- package/typeschema/dist/typeschema.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs.map +1 -1
- package/typeschema/dist/typeschema.module.js +1 -1
- package/typeschema/dist/typeschema.module.js.map +1 -1
- package/typeschema/dist/typeschema.umd.js +1 -1
- package/typeschema/dist/typeschema.umd.js.map +1 -1
- package/typeschema/package.json +1 -1
- package/typeschema/src/__tests__/Form.tsx +2 -4
- package/typeschema/src/__tests__/__fixtures__/data.ts +1 -1
- package/typeschema/src/__tests__/typeschema.ts +77 -0
- package/typeschema/src/index.ts +0 -1
- package/typeschema/src/typeschema.ts +52 -25
- package/valibot/dist/valibot.d.ts +9 -30
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/package.json +1 -1
- package/valibot/src/__tests__/valibot.ts +69 -3
- package/valibot/src/valibot.ts +29 -13
- package/vest/package.json +1 -1
- package/vine/dist/vine.d.ts +10 -24
- package/vine/dist/vine.js.map +1 -1
- package/vine/dist/vine.modern.mjs.map +1 -1
- package/vine/dist/vine.module.js.map +1 -1
- package/vine/dist/vine.umd.js.map +1 -1
- package/vine/package.json +1 -1
- package/vine/src/__tests__/Form.tsx +0 -28
- package/vine/src/__tests__/__fixtures__/data.ts +4 -4
- package/vine/src/__tests__/vine.ts +69 -0
- package/vine/src/vine.ts +26 -4
- package/yup/dist/yup.d.ts +7 -21
- package/yup/dist/yup.js +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.mjs +1 -1
- package/yup/dist/yup.modern.mjs +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/package.json +1 -1
- package/yup/src/__tests__/yup.ts +66 -0
- package/yup/src/yup.ts +30 -8
- package/zod/dist/zod.d.ts +7 -22
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/package.json +1 -1
- package/zod/src/__tests__/Form.tsx +0 -28
- package/zod/src/__tests__/__fixtures__/data.ts +2 -2
- package/zod/src/__tests__/zod.ts +69 -0
- package/zod/src/zod.ts +29 -9
- package/typeschema/dist/types.d.ts +0 -9
- package/typeschema/src/types.ts +0 -18
package/zod/src/zod.ts
CHANGED
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
FieldErrors,
|
|
5
5
|
FieldValues,
|
|
6
6
|
Resolver,
|
|
7
|
+
ResolverError,
|
|
8
|
+
ResolverSuccess,
|
|
7
9
|
appendErrors,
|
|
8
10
|
} from 'react-hook-form';
|
|
9
11
|
import { ZodError, z } from 'zod';
|
|
@@ -61,14 +63,32 @@ function parseErrorSchema(
|
|
|
61
63
|
return errors;
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
export function zodResolver<Input extends FieldValues, Context, Output>(
|
|
67
|
+
schema: z.ZodSchema<Output, any, Input>,
|
|
68
|
+
schemaOptions?: Partial<z.ParseParams>,
|
|
69
|
+
resolverOptions?: {
|
|
70
|
+
mode?: 'async' | 'sync';
|
|
71
|
+
raw?: false;
|
|
72
|
+
},
|
|
73
|
+
): Resolver<Input, Context, Output>;
|
|
74
|
+
|
|
75
|
+
export function zodResolver<Input extends FieldValues, Context, Output>(
|
|
76
|
+
schema: z.ZodSchema<Output, any, Input>,
|
|
77
|
+
schemaOptions: Partial<z.ParseParams> | undefined,
|
|
78
|
+
resolverOptions: {
|
|
79
|
+
mode?: 'async' | 'sync';
|
|
80
|
+
raw: true;
|
|
81
|
+
},
|
|
82
|
+
): Resolver<Input, Context, Input>;
|
|
83
|
+
|
|
64
84
|
/**
|
|
65
85
|
* Creates a resolver function for react-hook-form that validates form data using a Zod schema
|
|
66
|
-
* @param {z.ZodSchema<
|
|
86
|
+
* @param {z.ZodSchema<Input>} schema - The Zod schema used to validate the form data
|
|
67
87
|
* @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing
|
|
68
88
|
* @param {Object} [resolverOptions] - Optional resolver-specific configuration
|
|
69
89
|
* @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation
|
|
70
90
|
* @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data
|
|
71
|
-
* @returns {Resolver<z.
|
|
91
|
+
* @returns {Resolver<z.output<typeof schema>>} A resolver function compatible with react-hook-form
|
|
72
92
|
* @throws {Error} Throws if validation fails with a non-Zod error
|
|
73
93
|
* @example
|
|
74
94
|
* const schema = z.object({
|
|
@@ -80,15 +100,15 @@ function parseErrorSchema(
|
|
|
80
100
|
* resolver: zodResolver(schema)
|
|
81
101
|
* });
|
|
82
102
|
*/
|
|
83
|
-
export function zodResolver<
|
|
84
|
-
schema: z.ZodSchema<
|
|
103
|
+
export function zodResolver<Input extends FieldValues, Context, Output>(
|
|
104
|
+
schema: z.ZodSchema<Output, any, Input>,
|
|
85
105
|
schemaOptions?: Partial<z.ParseParams>,
|
|
86
106
|
resolverOptions: {
|
|
87
107
|
mode?: 'async' | 'sync';
|
|
88
108
|
raw?: boolean;
|
|
89
109
|
} = {},
|
|
90
|
-
): Resolver<
|
|
91
|
-
return async (values, _, options) => {
|
|
110
|
+
): Resolver<Input, Context, Output | Input> {
|
|
111
|
+
return async (values: Input, _, options) => {
|
|
92
112
|
try {
|
|
93
113
|
const data = await schema[
|
|
94
114
|
resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'
|
|
@@ -99,8 +119,8 @@ export function zodResolver<TFieldValues extends FieldValues>(
|
|
|
99
119
|
return {
|
|
100
120
|
errors: {} as FieldErrors,
|
|
101
121
|
values: resolverOptions.raw ? Object.assign({}, values) : data,
|
|
102
|
-
}
|
|
103
|
-
} catch (error
|
|
122
|
+
} satisfies ResolverSuccess<Output | Input>;
|
|
123
|
+
} catch (error) {
|
|
104
124
|
if (isZodError(error)) {
|
|
105
125
|
return {
|
|
106
126
|
values: {},
|
|
@@ -112,7 +132,7 @@ export function zodResolver<TFieldValues extends FieldValues>(
|
|
|
112
132
|
),
|
|
113
133
|
options,
|
|
114
134
|
),
|
|
115
|
-
}
|
|
135
|
+
} satisfies ResolverError<Input>;
|
|
116
136
|
}
|
|
117
137
|
|
|
118
138
|
throw error;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '@typeschema/main';
|
|
2
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
|
-
export type Resolver = <T extends Schema>(schema: T, schemaOptions?: never, factoryOptions?: {
|
|
4
|
-
/**
|
|
5
|
-
* Return the raw input values rather than the parsed values.
|
|
6
|
-
* @default false
|
|
7
|
-
*/
|
|
8
|
-
raw?: boolean;
|
|
9
|
-
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
package/typeschema/src/types.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '@typeschema/main';
|
|
2
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
export type Resolver = <T extends Schema>(
|
|
5
|
-
schema: T,
|
|
6
|
-
schemaOptions?: never,
|
|
7
|
-
factoryOptions?: {
|
|
8
|
-
/**
|
|
9
|
-
* Return the raw input values rather than the parsed values.
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
raw?: boolean;
|
|
13
|
-
},
|
|
14
|
-
) => <TFieldValues extends FieldValues, TContext>(
|
|
15
|
-
values: TFieldValues,
|
|
16
|
-
context: TContext | undefined,
|
|
17
|
-
options: ResolverOptions<TFieldValues>,
|
|
18
|
-
) => Promise<ResolverResult<TFieldValues>>;
|