@hookform/resolvers 3.10.0 → 4.1.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 +108 -6
- package/ajv/dist/ajv.d.ts +20 -0
- package/ajv/dist/ajv.js +1 -1
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.mjs +1 -1
- package/ajv/dist/ajv.modern.mjs +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +8 -0
- package/ajv/src/__tests__/__fixtures__/data-errors.ts +216 -0
- package/ajv/src/__tests__/__snapshots__/ajv-errors.ts.snap +462 -0
- package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +6 -6
- package/ajv/src/__tests__/ajv-errors.ts +227 -0
- package/ajv/src/ajv.ts +47 -14
- package/ajv/src/types.ts +8 -0
- package/arktype/dist/arktype.d.ts +20 -2
- 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/dist/index.d.ts +0 -1
- package/arktype/package.json +1 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +3 -3
- package/arktype/src/__tests__/Form.tsx +34 -8
- package/arktype/src/__tests__/__fixtures__/data.ts +2 -2
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +22 -415
- package/arktype/src/arktype.ts +46 -15
- package/arktype/src/index.ts +0 -1
- package/class-validator/dist/class-validator.d.ts +29 -2
- package/class-validator/dist/class-validator.js +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/index.d.ts +0 -1
- package/class-validator/src/__tests__/Form.tsx +26 -0
- package/class-validator/src/__tests__/__fixtures__/data.ts +1 -1
- package/class-validator/src/__tests__/class-validator.ts +22 -11
- package/class-validator/src/class-validator.ts +47 -13
- package/class-validator/src/index.ts +0 -1
- package/computed-types/dist/computed-types.d.ts +18 -2
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js +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/dist/index.d.ts +0 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -4
- package/computed-types/src/__tests__/Form.tsx +30 -6
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/computed-types.ts +2 -0
- package/computed-types/src/computed-types.ts +24 -7
- package/computed-types/src/index.ts +0 -1
- 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 +19 -2
- package/effect-ts/dist/effect-ts.js +1 -1
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/dist/index.d.ts +0 -1
- package/effect-ts/src/__tests__/Form.tsx +30 -4
- package/effect-ts/src/__tests__/__fixtures__/data.ts +1 -1
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +35 -1
- package/effect-ts/src/__tests__/effect-ts.ts +61 -0
- package/effect-ts/src/effect-ts.ts +60 -13
- package/effect-ts/src/index.ts +0 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.d.ts +21 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js.map +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.mjs +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs.map +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js.map +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js.map +1 -1
- package/fluentvalidation-ts/src/fluentvalidation-ts.ts +24 -3
- package/io-ts/dist/errorsToRecord.d.ts +5 -1
- package/io-ts/dist/index.d.ts +0 -1
- package/io-ts/dist/io-ts.d.ts +19 -2
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs.map +1 -1
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/src/__tests__/Form-native-validation.tsx +4 -11
- package/io-ts/src/__tests__/Form.tsx +30 -6
- package/io-ts/src/__tests__/__fixtures__/data.ts +2 -19
- package/io-ts/src/errorsToRecord.ts +4 -1
- package/io-ts/src/index.ts +0 -1
- package/io-ts/src/io-ts.ts +47 -25
- package/joi/dist/joi.d.ts +17 -0
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/src/joi.ts +17 -0
- package/nope/dist/nope.d.ts +17 -0
- package/nope/dist/nope.js +1 -1
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.mjs +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/src/nope.ts +17 -0
- package/package.json +49 -34
- package/standard-schema/dist/index.d.ts +1 -0
- package/standard-schema/dist/standard-schema.d.ts +25 -0
- package/standard-schema/dist/standard-schema.js +2 -0
- package/standard-schema/dist/standard-schema.js.map +1 -0
- package/standard-schema/dist/standard-schema.mjs +2 -0
- package/standard-schema/dist/standard-schema.modern.mjs +2 -0
- package/standard-schema/dist/standard-schema.modern.mjs.map +1 -0
- package/standard-schema/dist/standard-schema.module.js +2 -0
- package/standard-schema/dist/standard-schema.module.js.map +1 -0
- package/standard-schema/dist/standard-schema.umd.js +2 -0
- package/standard-schema/dist/standard-schema.umd.js.map +1 -0
- package/standard-schema/package.json +18 -0
- package/standard-schema/src/__tests__/Form-native-validation.tsx +82 -0
- package/standard-schema/src/__tests__/Form.tsx +82 -0
- package/standard-schema/src/__tests__/__fixtures__/data.ts +88 -0
- package/standard-schema/src/__tests__/__snapshots__/standard-schema.ts.snap +250 -0
- package/standard-schema/src/__tests__/standard-schema.ts +56 -0
- package/standard-schema/src/index.ts +1 -0
- package/standard-schema/src/standard-schema.ts +88 -0
- package/superstruct/dist/index.d.ts +0 -1
- package/superstruct/dist/superstruct.d.ts +22 -2
- package/superstruct/dist/superstruct.js +1 -1
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/src/__tests__/Form.tsx +26 -0
- package/superstruct/src/__tests__/__fixtures__/data.ts +1 -1
- package/superstruct/src/index.ts +0 -1
- package/superstruct/src/superstruct.ts +32 -10
- package/typanion/dist/index.d.ts +0 -1
- package/typanion/dist/typanion.d.ts +18 -2
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.mjs +1 -1
- package/typanion/dist/typanion.modern.mjs +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +6 -14
- package/typanion/src/__tests__/Form.tsx +32 -8
- package/typanion/src/__tests__/__fixtures__/data.ts +9 -9
- package/typanion/src/__tests__/typanion.ts +3 -3
- package/typanion/src/index.ts +0 -1
- package/typanion/src/typanion.ts +32 -9
- package/typebox/dist/index.d.ts +0 -1
- package/typebox/dist/typebox.d.ts +20 -2
- package/typebox/dist/typebox.js +1 -1
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/src/__tests__/Form-compiler.tsx +4 -8
- package/typebox/src/__tests__/Form.tsx +32 -6
- package/typebox/src/__tests__/__fixtures__/data.ts +1 -1
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +21 -21
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +21 -21
- package/typebox/src/index.ts +0 -1
- package/typebox/src/typebox.ts +33 -7
- package/typeschema/dist/typeschema.d.ts +17 -0
- 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/src/typeschema.ts +20 -1
- package/valibot/dist/index.d.ts +0 -1
- package/valibot/dist/valibot.d.ts +31 -2
- package/valibot/dist/valibot.js +1 -1
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/package.json +1 -1
- package/valibot/src/__tests__/Form.tsx +26 -0
- package/valibot/src/__tests__/__fixtures__/data.ts +7 -3
- package/valibot/src/__tests__/valibot.ts +1 -1
- package/valibot/src/index.ts +0 -1
- package/valibot/src/valibot.ts +55 -6
- package/vest/dist/vest.d.ts +18 -0
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -1
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/vest.ts +18 -0
- package/vine/dist/index.d.ts +0 -1
- package/vine/dist/vine.d.ts +25 -2
- package/vine/dist/vine.js +1 -1
- package/vine/dist/vine.js.map +1 -1
- package/vine/dist/vine.mjs +1 -1
- package/vine/dist/vine.modern.mjs +1 -1
- package/vine/dist/vine.modern.mjs.map +1 -1
- package/vine/dist/vine.module.js +1 -1
- package/vine/dist/vine.module.js.map +1 -1
- package/vine/dist/vine.umd.js +1 -1
- package/vine/dist/vine.umd.js.map +1 -1
- package/vine/src/__tests__/Form-native-validation.tsx +2 -4
- package/vine/src/__tests__/Form.tsx +30 -6
- package/vine/src/__tests__/__fixtures__/data.ts +1 -1
- package/vine/src/index.ts +0 -1
- package/vine/src/vine.ts +38 -10
- package/yup/dist/yup.d.ts +18 -7
- 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/src/yup.ts +22 -11
- package/zod/dist/index.d.ts +0 -1
- package/zod/dist/zod.d.ts +25 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form.tsx +30 -6
- package/zod/src/__tests__/__fixtures__/data.ts +3 -3
- package/zod/src/index.ts +0 -1
- package/zod/src/zod.ts +40 -9
- package/arktype/dist/types.d.ts +0 -9
- package/arktype/src/types.ts +0 -18
- package/class-validator/dist/types.d.ts +0 -12
- package/class-validator/src/types.ts +0 -16
- package/computed-types/dist/types.d.ts +0 -2
- package/computed-types/src/types.ts +0 -13
- package/effect-ts/dist/types.d.ts +0 -4
- package/effect-ts/src/types.ts +0 -12
- package/io-ts/dist/types.d.ts +0 -7
- package/io-ts/src/types.ts +0 -18
- package/superstruct/dist/types.d.ts +0 -11
- package/superstruct/src/types.ts +0 -20
- package/typanion/dist/types.d.ts +0 -9
- package/typanion/src/types.ts +0 -20
- package/typebox/dist/types.d.ts +0 -4
- package/typebox/src/types.ts +0 -11
- package/valibot/dist/types.d.ts +0 -13
- package/valibot/src/types.ts +0 -34
- package/vine/dist/types.d.ts +0 -6
- package/vine/src/types.ts +0 -13
- package/zod/dist/types.d.ts +0 -13
- package/zod/src/types.ts +0 -22
package/valibot/src/valibot.ts
CHANGED
|
@@ -1,11 +1,57 @@
|
|
|
1
1
|
import { toNestErrors } from '@hookform/resolvers';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
FieldError,
|
|
4
|
+
FieldValues,
|
|
5
|
+
Resolver,
|
|
6
|
+
appendErrors,
|
|
7
|
+
} from 'react-hook-form';
|
|
3
8
|
import { getDotPath, safeParseAsync } from 'valibot';
|
|
4
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
BaseSchema,
|
|
11
|
+
BaseSchemaAsync,
|
|
12
|
+
Config,
|
|
13
|
+
InferIssue,
|
|
14
|
+
InferOutput,
|
|
15
|
+
} from 'valibot';
|
|
5
16
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Creates a resolver for react-hook-form using Valibot schema validation
|
|
19
|
+
* @param {BaseSchema<TFieldValues, TFieldValues, any> | BaseSchemaAsync<TFieldValues, TFieldValues, any>} schema - The Valibot schema to validate against
|
|
20
|
+
* @param {Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>>} [schemaOptions] - Optional Valibot validation options
|
|
21
|
+
* @param {Object} resolverOptions - Additional resolver configuration
|
|
22
|
+
* @param {('sync' | 'async')} [resolverOptions.mode] - Validation mode
|
|
23
|
+
* @param {boolean} [resolverOptions.raw] - If true, returns raw values rather than validated results
|
|
24
|
+
* @returns {Resolver<InferOutput<typeof schema>>} A resolver function compatible with react-hook-form
|
|
25
|
+
* @example
|
|
26
|
+
* const schema = valibot.object({
|
|
27
|
+
* name: valibot.string().minLength(2),
|
|
28
|
+
* age: valibot.number().min(18)
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* useForm({
|
|
32
|
+
* resolver: valibotResolver(schema)
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
export function valibotResolver<TFieldValues extends FieldValues>(
|
|
36
|
+
schema:
|
|
37
|
+
| BaseSchema<TFieldValues, TFieldValues, any>
|
|
38
|
+
| BaseSchemaAsync<TFieldValues, TFieldValues, any>,
|
|
39
|
+
schemaOptions?: Partial<
|
|
40
|
+
Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>
|
|
41
|
+
>,
|
|
42
|
+
resolverOptions: {
|
|
43
|
+
/**
|
|
44
|
+
* @default async
|
|
45
|
+
*/
|
|
46
|
+
mode?: 'sync' | 'async';
|
|
47
|
+
/**
|
|
48
|
+
* Return the raw input values rather than the parsed values.
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
raw?: boolean;
|
|
52
|
+
} = {},
|
|
53
|
+
): Resolver<InferOutput<typeof schema>> {
|
|
54
|
+
return async (values, _, options) => {
|
|
9
55
|
// Check if we should validate all field criteria
|
|
10
56
|
const validateAllFieldCriteria =
|
|
11
57
|
!options.shouldUseNativeValidation && options.criteriaMode === 'all';
|
|
@@ -67,7 +113,10 @@ export const valibotResolver: Resolver =
|
|
|
67
113
|
|
|
68
114
|
// Otherwise, return resolver result with values
|
|
69
115
|
return {
|
|
70
|
-
values: resolverOptions.raw
|
|
116
|
+
values: resolverOptions.raw
|
|
117
|
+
? Object.assign({}, values)
|
|
118
|
+
: (result.output as FieldValues),
|
|
71
119
|
errors: {},
|
|
72
120
|
};
|
|
73
121
|
};
|
|
122
|
+
}
|
package/vest/dist/vest.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
import type { Resolver } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a resolver for react-hook-form using Vest validation
|
|
4
|
+
* @param {Function} schema - The Vest validation schema
|
|
5
|
+
* @param {Object} _ - Unused parameter
|
|
6
|
+
* @param {Object} resolverOptions - Additional resolver configuration
|
|
7
|
+
* @param {string} [resolverOptions.mode='async'] - Validation mode
|
|
8
|
+
* @returns {Resolver} A resolver function compatible with react-hook-form
|
|
9
|
+
* @example
|
|
10
|
+
* const schema = vest.create((data) => {
|
|
11
|
+
* if (!data.name) {
|
|
12
|
+
* return 'Name is required';
|
|
13
|
+
* }
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* useForm({
|
|
17
|
+
* resolver: vestResolver(schema)
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
2
20
|
export declare const vestResolver: Resolver;
|
package/vest/dist/vest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","context","options","_temp2","result","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","names","promisify","then","e","reject"],"mappings":"6JAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAE,EAC7C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,
|
|
1
|
+
{"version":3,"file":"vest.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\n/**\n * Creates a resolver for react-hook-form using Vest validation\n * @param {Function} schema - The Vest validation schema\n * @param {Object} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = vest.create((data) => {\n * if (!data.name) {\n * return 'Name is required';\n * }\n * });\n *\n * useForm({\n * resolver: vestResolver(schema)\n * });\n */\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","context","options","_temp2","result","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","names","promisify","then","e","reject"],"mappings":"6JAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAE,EAC7C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,uBAqBE,SAACQ,EAAQC,EAAGC,GACLC,YADKD,IAAAA,IAAAA,EAAkB,CAAE,GACzBC,SAAAA,EAAQC,EAASC,GAAW,IAAA,IAAAC,EAAA,SAC3BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAE,EACVX,OAAQiB,EAAYA,aAClBpB,EACEkB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,CAAA,GAAK,EApBG,OAAAsB,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,EAAQE,EAAQY,MAAOb,IAAQU,QAAAC,QAChCG,EAAS,QAAClB,EAAVkB,CAAkBf,EAAQE,EAAQY,MAAOb,IAAQe,KAAAb,GAmB/D,CAAC,MAAAc,GAAAN,OAAAA,QAAAO,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.modern.mjs","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","async","values","context","options","result","mode","names","promisify","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively"],"mappings":"6GAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,GAC3C,IAAK,MAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,CAACC,EAAKJ,EAASK,KAAWD,EAAIC,GAASL,IAAYI,EACnD,CAAA,IAIN,OAAON,
|
|
1
|
+
{"version":3,"file":"vest.modern.mjs","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\n/**\n * Creates a resolver for react-hook-form using Vest validation\n * @param {Function} schema - The Vest validation schema\n * @param {Object} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = vest.create((data) => {\n * if (!data.name) {\n * return 'Name is required';\n * }\n * });\n *\n * useForm({\n * resolver: vestResolver(schema)\n * });\n */\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","async","values","context","options","result","mode","names","promisify","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively"],"mappings":"6GAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,GAC3C,IAAK,MAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,CAACC,EAAKJ,EAASK,KAAWD,EAAIC,GAASL,IAAYI,EACnD,CAAA,IAIN,OAAON,GAqBIQ,EACXA,CAACC,EAAQC,EAAGC,EAAkB,KAC9BC,MAAOC,EAAQC,EAASC,KACtB,MAAMC,EACqB,SAAzBL,EAAgBM,KACZR,EAAOI,EAAQE,EAAQG,MAAOJ,SACxBK,EAAUV,EAAVU,CAAkBN,EAAQE,EAAQG,MAAOJ,GAErD,OAAIE,EAAOI,YACF,CACLP,OAAQ,CAAE,EACVb,OAAQqB,EACNxB,EACEmB,EAAOM,aACNP,EAAQQ,2BACkB,QAAzBR,EAAQS,cAEZT,KAKNA,EAAQQ,2BAA6BE,EAAuB,GAAIV,GAEzD,CAAEF,SAAQb,OAAQ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.module.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","values","context","options","_temp2","result","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","names","promisify","then","e","reject"],"mappings":"6GAKA,IAAMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAE,EAC7C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,
|
|
1
|
+
{"version":3,"file":"vest.module.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\n/**\n * Creates a resolver for react-hook-form using Vest validation\n * @param {Function} schema - The Vest validation schema\n * @param {Object} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = vest.create((data) => {\n * if (!data.name) {\n * return 'Name is required';\n * }\n * });\n *\n * useForm({\n * resolver: vestResolver(schema)\n * });\n */\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","values","context","options","_temp2","result","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","names","promisify","then","e","reject"],"mappings":"6GAKA,IAAMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAE,EAC7C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,EAoBaQ,EACX,SAACC,EAAQC,EAAGC,GACLC,YADKD,IAAAA,IAAAA,EAAkB,CAAE,GACzBC,SAAAA,EAAQC,EAASC,GAAW,IAAA,IAAAC,EAAA,SAC3BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAE,EACVZ,OAAQkB,EACNrB,EACEmB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQZ,OAAQ,CAAA,GAAK,EApBG,OAAAuB,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,EAAQE,EAAQY,MAAOb,IAAQU,QAAAC,QAChCG,EAAUlB,EAAVkB,CAAkBf,EAAQE,EAAQY,MAAOb,IAAQe,KAAAb,GAmB/D,CAAC,MAAAc,GAAAN,OAAAA,QAAAO,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.umd.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","context","options","_temp2","result","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","names","promisify","then","e","reject"],"mappings":"mdAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAE,EAC7C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,
|
|
1
|
+
{"version":3,"file":"vest.umd.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { Resolver, VestErrors } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\n/**\n * Creates a resolver for react-hook-form using Vest validation\n * @param {Function} schema - The Vest validation schema\n * @param {Object} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = vest.create((data) => {\n * if (!data.name) {\n * return 'Name is required';\n * }\n * });\n *\n * useForm({\n * resolver: vestResolver(schema)\n * });\n */\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values, options.names, context)\n : await promisify(schema)(values, options.names, context);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","context","options","_temp2","result","hasErrors","toNestErrors","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","names","promisify","then","e","reject"],"mappings":"mdAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAE,EAC7C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,iBAqBE,SAACQ,EAAQC,EAAGC,GACLC,YADKD,IAAAA,IAAAA,EAAkB,CAAE,GACzBC,SAAAA,EAAQC,EAASC,GAAW,IAAA,IAAAC,EAAA,SAC3BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAE,EACVX,OAAQiB,EAAYA,aAClBpB,EACEkB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,CAAA,GAAK,EApBG,OAAAsB,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,EAAQE,EAAQY,MAAOb,IAAQU,QAAAC,QAChCG,EAAS,QAAClB,EAAVkB,CAAkBf,EAAQE,EAAQY,MAAOb,IAAQe,KAAAb,GAmB/D,CAAC,MAAAc,GAAAN,OAAAA,QAAAO,OAAAD,EAAA,CAAA,CAAA"}
|
package/vest/src/vest.ts
CHANGED
|
@@ -23,6 +23,24 @@ const parseErrorSchema = (
|
|
|
23
23
|
return errors;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Creates a resolver for react-hook-form using Vest validation
|
|
28
|
+
* @param {Function} schema - The Vest validation schema
|
|
29
|
+
* @param {Object} _ - Unused parameter
|
|
30
|
+
* @param {Object} resolverOptions - Additional resolver configuration
|
|
31
|
+
* @param {string} [resolverOptions.mode='async'] - Validation mode
|
|
32
|
+
* @returns {Resolver} A resolver function compatible with react-hook-form
|
|
33
|
+
* @example
|
|
34
|
+
* const schema = vest.create((data) => {
|
|
35
|
+
* if (!data.name) {
|
|
36
|
+
* return 'Name is required';
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* useForm({
|
|
41
|
+
* resolver: vestResolver(schema)
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
26
44
|
export const vestResolver: Resolver =
|
|
27
45
|
(schema, _, resolverOptions = {}) =>
|
|
28
46
|
async (values, context, options) => {
|
package/vine/dist/index.d.ts
CHANGED
package/vine/dist/vine.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { VineValidator } from '@vinejs/vine';
|
|
2
|
+
import { Infer, ValidationOptions } from '@vinejs/vine/build/src/types';
|
|
3
|
+
import { Resolver } from 'react-hook-form';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a resolver for react-hook-form using VineJS schema validation
|
|
6
|
+
* @param {T} schema - The VineJS schema to validate against
|
|
7
|
+
* @param {ValidationOptions<any>} [schemaOptions] - Optional VineJS validation options
|
|
8
|
+
* @param {Object} [resolverOptions] - Optional resolver configuration
|
|
9
|
+
* @param {boolean} [resolverOptions.raw=false] - If true, returns raw values instead of validated results
|
|
10
|
+
* @returns {Resolver<Infer<typeof schema>>} A resolver function compatible with react-hook-form
|
|
11
|
+
* @example
|
|
12
|
+
* const schema = vine.compile(
|
|
13
|
+
* vine.object({
|
|
14
|
+
* name: vine.string().minLength(2),
|
|
15
|
+
* age: vine.number().min(18)
|
|
16
|
+
* })
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* useForm({
|
|
20
|
+
* resolver: vineResolver(schema)
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
export declare function vineResolver<T extends VineValidator<any, any>>(schema: T, schemaOptions?: ValidationOptions<any>, resolverOptions?: {
|
|
24
|
+
raw?: boolean;
|
|
25
|
+
}): Resolver<Infer<typeof schema>>;
|
package/vine/dist/vine.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("@hookform/resolvers"),r=require("@vinejs/vine"),t=require("react-hook-form")
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("@vinejs/vine"),t=require("react-hook-form");function s(e,r){for(var s={};e.length;){var o=e[0],i=o.field;if(i in s||(s[i]={message:o.message,type:o.rule}),r){var n=s[i].types,a=n&&n[o.rule];s[i]=t.appendErrors(i,r,s,o.rule,a?[].concat(a,[o.message]):o.message)}e.shift()}return s}exports.vineResolver=function(t,o,i){return void 0===i&&(i={}),function(n,a,u){try{return Promise.resolve(function(r,s){try{var a=Promise.resolve(t.validate(n,o)).then(function(r){return u.shouldUseNativeValidation&&e.validateFieldsNatively({},u),{errors:{},values:i.raw?Object.assign({},n):r}})}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(t){if(t instanceof r.errors.E_VALIDATION_ERROR)return{values:{},errors:e.toNestErrors(s(t.messages,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw t}))}catch(e){return Promise.reject(e)}}};
|
|
2
2
|
//# sourceMappingURL=vine.js.map
|
package/vine/dist/vine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport {
|
|
1
|
+
{"version":3,"file":"vine.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, VineValidator, errors } from '@vinejs/vine';\nimport { Infer, ValidationOptions } from '@vinejs/vine/build/src/types';\nimport {\n FieldError,\n FieldErrors,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n}\n\n/**\n * Creates a resolver for react-hook-form using VineJS schema validation\n * @param {T} schema - The VineJS schema to validate against\n * @param {ValidationOptions<any>} [schemaOptions] - Optional VineJS validation options\n * @param {Object} [resolverOptions] - Optional resolver configuration\n * @param {boolean} [resolverOptions.raw=false] - If true, returns raw values instead of validated results\n * @returns {Resolver<Infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = vine.compile(\n * vine.object({\n * name: vine.string().minLength(2),\n * age: vine.number().min(18)\n * })\n * );\n *\n * useForm({\n * resolver: vineResolver(schema)\n * });\n */\nexport function vineResolver<T extends VineValidator<any, any>>(\n schema: T,\n schemaOptions?: ValidationOptions<any>,\n resolverOptions: { raw?: boolean } = {},\n): Resolver<Infer<typeof schema>> {\n return async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? Object.assign({}, values) : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n}\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","Object","assign","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"4FAUA,SAASA,EACPC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAA,EAE1CF,EAAWG,QAAU,CAC1B,IAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,IAAQS,EAAUR,EAAaG,GAAvBK,MACFC,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,eACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAQ,GAAAE,OAAQF,GAAuBP,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,sBAqBM,SACJa,EACAC,EACAC,GAEA,gBAFAA,IAAAA,EAAqC,CAAA,YAEvBC,EAAQC,EAAGC,OAAWC,OAAAA,QAAAC,gCAC9BD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAEzD,CACLQ,OAAQ,CAAiB,EACzBV,OAAQD,EAAgBY,IAAMC,OAAOC,OAAO,GAAIb,GAAUO,EAC1D,4DAT8BO,CAAA,EAUzB5B,SAAAA,GACP,GAAIA,aAAiBwB,EAAMA,OAACK,mBAC1B,MAAO,CACLf,OAAQ,CAAA,EACRU,OAAQM,EAAYA,aAClBnC,EACEK,EAAMO,UACLS,EAAQM,2BACkB,QAAzBN,EAAQe,cAEZf,IAKN,MAAMhB,CACR,GACF,CAAC,MAAAgC,GAAAf,OAAAA,QAAAgB,OAAAD,EACH,CAAA,CAAA"}
|
package/vine/dist/vine.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as t}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as t}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";function n(e,r){for(var t={};e.length;){var n=e[0],i=n.field;if(i in t||(t[i]={message:n.message,type:n.rule}),r){var s=t[i].types,a=s&&s[n.rule];t[i]=o(i,r,t,n.rule,a?[].concat(a,[n.message]):n.message)}e.shift()}return t}function i(o,i,s){return void 0===s&&(s={}),function(a,u,c){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(o.validate(a,i)).then(function(r){return c.shouldUseNativeValidation&&e({},c),{errors:{},values:s.raw?Object.assign({},a):r}})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){if(e instanceof t.E_VALIDATION_ERROR)return{values:{},errors:r(n(e.messages,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw e}))}catch(e){return Promise.reject(e)}}}export{i as vineResolver};
|
|
2
2
|
//# sourceMappingURL=vine.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as s}from"@vinejs/vine";import{appendErrors as
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as s}from"@vinejs/vine";import{appendErrors as t}from"react-hook-form";function o(e,r){const s={};for(;e.length;){const o=e[0],a=o.field;if(a in s||(s[a]={message:o.message,type:o.rule}),r){const{types:e}=s[a],i=e&&e[o.rule];s[a]=t(a,r,s,o.rule,i?[...i,o.message]:o.message)}e.shift()}return s}function a(t,a,i={}){return async(n,l,c)=>{try{const r=await t.validate(n,a);return c.shouldUseNativeValidation&&e({},c),{errors:{},values:i.raw?Object.assign({},n):r}}catch(e){if(e instanceof s.E_VALIDATION_ERROR)return{values:{},errors:r(o(e.messages,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw e}}}export{a as vineResolver};
|
|
2
2
|
//# sourceMappingURL=vine.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.modern.mjs","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport {
|
|
1
|
+
{"version":3,"file":"vine.modern.mjs","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, VineValidator, errors } from '@vinejs/vine';\nimport { Infer, ValidationOptions } from '@vinejs/vine/build/src/types';\nimport {\n FieldError,\n FieldErrors,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n}\n\n/**\n * Creates a resolver for react-hook-form using VineJS schema validation\n * @param {T} schema - The VineJS schema to validate against\n * @param {ValidationOptions<any>} [schemaOptions] - Optional VineJS validation options\n * @param {Object} [resolverOptions] - Optional resolver configuration\n * @param {boolean} [resolverOptions.raw=false] - If true, returns raw values instead of validated results\n * @returns {Resolver<Infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = vine.compile(\n * vine.object({\n * name: vine.string().minLength(2),\n * age: vine.number().min(18)\n * })\n * );\n *\n * useForm({\n * resolver: vineResolver(schema)\n * });\n */\nexport function vineResolver<T extends VineValidator<any, any>>(\n schema: T,\n schemaOptions?: ValidationOptions<any>,\n resolverOptions: { raw?: boolean } = {},\n): Resolver<Infer<typeof schema>> {\n return async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? Object.assign({}, values) : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n}\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","shift","vineResolver","schema","schemaOptions","resolverOptions","values","_","options","data","validate","shouldUseNativeValidation","validateFieldsNatively","errors","raw","Object","assign","E_VALIDATION_ERROR","toNestErrors","criteriaMode"],"mappings":"oKAUA,SAASA,EACPC,EACAC,GAEA,MAAMC,EAA2C,CAAA,EAEjD,KAAOF,EAAWG,QAAU,CAC1B,MAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,MAAMS,MAAEA,GAAUR,EAAaG,GACzBM,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,EACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAW,IAAKA,EAAuBP,EAAMG,SAAWH,EAAMG,QAElE,CAEAP,EAAWa,OACb,CAEA,OAAOX,CACT,CAqBM,SAAUY,EACdC,EACAC,EACAC,EAAqC,CAAA,GAErC,OAAcC,MAAAA,EAAQC,EAAGC,KACvB,IACE,MAAMC,QAAaN,EAAOO,SAASJ,EAAQF,GAI3C,OAFAI,EAAQG,2BAA6BC,EAAuB,CAAA,EAAIJ,GAEzD,CACLK,OAAQ,CAAiB,EACzBP,OAAQD,EAAgBS,IAAMC,OAAOC,OAAO,CAAA,EAAIV,GAAUG,EAE9D,CAAE,MAAOjB,GACP,GAAIA,aAAiBqB,EAAOI,mBAC1B,MAAO,CACLX,OAAQ,CAAA,EACRO,OAAQK,EACN/B,EACEK,EAAMO,UACLS,EAAQG,2BACkB,QAAzBH,EAAQW,cAEZX,IAKN,MAAMhB,CACR,EAEJ"}
|
package/vine/dist/vine.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as t}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as t}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";function n(e,r){for(var t={};e.length;){var n=e[0],i=n.field;if(i in t||(t[i]={message:n.message,type:n.rule}),r){var s=t[i].types,a=s&&s[n.rule];t[i]=o(i,r,t,n.rule,a?[].concat(a,[n.message]):n.message)}e.shift()}return t}function i(o,i,s){return void 0===s&&(s={}),function(a,u,c){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(o.validate(a,i)).then(function(r){return c.shouldUseNativeValidation&&e({},c),{errors:{},values:s.raw?Object.assign({},a):r}})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){if(e instanceof t.E_VALIDATION_ERROR)return{values:{},errors:r(n(e.messages,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw e}))}catch(e){return Promise.reject(e)}}}export{i as vineResolver};
|
|
2
2
|
//# sourceMappingURL=vine.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.module.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport {
|
|
1
|
+
{"version":3,"file":"vine.module.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, VineValidator, errors } from '@vinejs/vine';\nimport { Infer, ValidationOptions } from '@vinejs/vine/build/src/types';\nimport {\n FieldError,\n FieldErrors,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n}\n\n/**\n * Creates a resolver for react-hook-form using VineJS schema validation\n * @param {T} schema - The VineJS schema to validate against\n * @param {ValidationOptions<any>} [schemaOptions] - Optional VineJS validation options\n * @param {Object} [resolverOptions] - Optional resolver configuration\n * @param {boolean} [resolverOptions.raw=false] - If true, returns raw values instead of validated results\n * @returns {Resolver<Infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = vine.compile(\n * vine.object({\n * name: vine.string().minLength(2),\n * age: vine.number().min(18)\n * })\n * );\n *\n * useForm({\n * resolver: vineResolver(schema)\n * });\n */\nexport function vineResolver<T extends VineValidator<any, any>>(\n schema: T,\n schemaOptions?: ValidationOptions<any>,\n resolverOptions: { raw?: boolean } = {},\n): Resolver<Infer<typeof schema>> {\n return async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? Object.assign({}, values) : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n}\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","concat","shift","vineResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","Object","assign","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"oKAUA,SAASA,EACPC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAA,EAE1CF,EAAWG,QAAU,CAC1B,IAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,IAAQS,EAAUR,EAAaG,GAAvBK,MACFC,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,EACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAQ,GAAAE,OAAQF,GAAuBP,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,CAqBM,SAAUa,EACdC,EACAC,EACAC,GAEA,gBAFAA,IAAAA,EAAqC,CAAA,YAEvBC,EAAQC,EAAGC,OAAWC,OAAAA,QAAAC,gCAC9BD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAuB,GAAIP,GAEzD,CACLQ,OAAQ,CAAiB,EACzBV,OAAQD,EAAgBY,IAAMC,OAAOC,OAAO,GAAIb,GAAUO,EAC1D,4DAT8BO,CAAA,EAUzB7B,SAAAA,GACP,GAAIA,aAAiByB,EAAOK,mBAC1B,MAAO,CACLf,OAAQ,CAAA,EACRU,OAAQM,EACNpC,EACEK,EAAMO,UACLU,EAAQM,2BACkB,QAAzBN,EAAQe,cAEZf,IAKN,MAAMjB,CACR,GACF,CAAC,MAAAiC,GAAAf,OAAAA,QAAAgB,OAAAD,EACH,CAAA,CAAA"}
|
package/vine/dist/vine.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("@vinejs/vine"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","@vinejs/vine","react-hook-form"],r):r((e||self).hookformResolversVine={},e.hookformResolvers,e.vine,e.ReactHookForm)}(this,function(e,r,o,t){
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("@vinejs/vine"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","@vinejs/vine","react-hook-form"],r):r((e||self).hookformResolversVine={},e.hookformResolvers,e.vine,e.ReactHookForm)}(this,function(e,r,o,t){function n(e,r){for(var o={};e.length;){var n=e[0],s=n.field;if(s in o||(o[s]={message:n.message,type:n.rule}),r){var i=o[s].types,a=i&&i[n.rule];o[s]=t.appendErrors(s,r,o,n.rule,a?[].concat(a,[n.message]):n.message)}e.shift()}return o}e.vineResolver=function(e,t,s){return void 0===s&&(s={}),function(i,a,f){try{return Promise.resolve(function(o,n){try{var a=Promise.resolve(e.validate(i,t)).then(function(e){return f.shouldUseNativeValidation&&r.validateFieldsNatively({},f),{errors:{},values:s.raw?Object.assign({},i):e}})}catch(e){return n(e)}return a&&a.then?a.then(void 0,n):a}(0,function(e){if(e instanceof o.errors.E_VALIDATION_ERROR)return{values:{},errors:r.toNestErrors(n(e.messages,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=vine.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.umd.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport {
|
|
1
|
+
{"version":3,"file":"vine.umd.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, VineValidator, errors } from '@vinejs/vine';\nimport { Infer, ValidationOptions } from '@vinejs/vine/build/src/types';\nimport {\n FieldError,\n FieldErrors,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n}\n\n/**\n * Creates a resolver for react-hook-form using VineJS schema validation\n * @param {T} schema - The VineJS schema to validate against\n * @param {ValidationOptions<any>} [schemaOptions] - Optional VineJS validation options\n * @param {Object} [resolverOptions] - Optional resolver configuration\n * @param {boolean} [resolverOptions.raw=false] - If true, returns raw values instead of validated results\n * @returns {Resolver<Infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = vine.compile(\n * vine.object({\n * name: vine.string().minLength(2),\n * age: vine.number().min(18)\n * })\n * );\n *\n * useForm({\n * resolver: vineResolver(schema)\n * });\n */\nexport function vineResolver<T extends VineValidator<any, any>>(\n schema: T,\n schemaOptions?: ValidationOptions<any>,\n resolverOptions: { raw?: boolean } = {},\n): Resolver<Infer<typeof schema>> {\n return async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? Object.assign({}, values) : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n}\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","Object","assign","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"yaAUA,SAASA,EACPC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAA,EAE1CF,EAAWG,QAAU,CAC1B,IAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,IAAQS,EAAUR,EAAaG,GAAvBK,MACFC,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,eACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAQ,GAAAE,OAAQF,GAAuBP,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,gBAqBM,SACJa,EACAC,EACAC,GAEA,gBAFAA,IAAAA,EAAqC,CAAA,YAEvBC,EAAQC,EAAGC,OAAWC,OAAAA,QAAAC,gCAC9BD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAEzD,CACLQ,OAAQ,CAAiB,EACzBV,OAAQD,EAAgBY,IAAMC,OAAOC,OAAO,GAAIb,GAAUO,EAC1D,4DAT8BO,CAAA,EAUzB5B,SAAAA,GACP,GAAIA,aAAiBwB,EAAMA,OAACK,mBAC1B,MAAO,CACLf,OAAQ,CAAA,EACRU,OAAQM,EAAYA,aAClBnC,EACEK,EAAMO,UACLS,EAAQM,2BACkB,QAAzBN,EAAQe,cAEZf,IAKN,MAAMhB,CACR,GACF,CAAC,MAAAgC,GAAAf,OAAAA,QAAAgB,OAAAD,EACH,CAAA,CAAA"}
|
|
@@ -13,14 +13,12 @@ const schema = vine.compile(
|
|
|
13
13
|
}),
|
|
14
14
|
);
|
|
15
15
|
|
|
16
|
-
type FormData = Infer<typeof schema> & { unusedProperty: string };
|
|
17
|
-
|
|
18
16
|
interface Props {
|
|
19
|
-
onSubmit: (data:
|
|
17
|
+
onSubmit: (data: Infer<typeof schema>) => void;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
function TestComponent({ onSubmit }: Props) {
|
|
23
|
-
const { register, handleSubmit } = useForm
|
|
21
|
+
const { register, handleSubmit } = useForm({
|
|
24
22
|
resolver: vineResolver(schema),
|
|
25
23
|
shouldUseNativeValidation: true,
|
|
26
24
|
});
|
|
@@ -15,16 +15,14 @@ const schema = vine.compile(
|
|
|
15
15
|
|
|
16
16
|
type FormData = Infer<typeof schema> & { unusedProperty: string };
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
onSubmit
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function TestComponent({ onSubmit }: Props) {
|
|
18
|
+
function TestComponent({
|
|
19
|
+
onSubmit,
|
|
20
|
+
}: { onSubmit: (data: Infer<typeof schema>) => void }) {
|
|
23
21
|
const {
|
|
24
22
|
register,
|
|
25
23
|
handleSubmit,
|
|
26
24
|
formState: { errors },
|
|
27
|
-
} = useForm
|
|
25
|
+
} = useForm({
|
|
28
26
|
resolver: vineResolver(schema), // Useful to check TypeScript regressions
|
|
29
27
|
});
|
|
30
28
|
|
|
@@ -57,3 +55,29 @@ test("form's validation with Vine and TypeScript's integration", async () => {
|
|
|
57
55
|
).toBeInTheDocument();
|
|
58
56
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
59
57
|
});
|
|
58
|
+
|
|
59
|
+
export function TestComponentManualType({
|
|
60
|
+
onSubmit,
|
|
61
|
+
}: {
|
|
62
|
+
onSubmit: (data: FormData) => void;
|
|
63
|
+
}) {
|
|
64
|
+
const {
|
|
65
|
+
register,
|
|
66
|
+
handleSubmit,
|
|
67
|
+
formState: { errors },
|
|
68
|
+
} = useForm<Infer<typeof schema>, undefined, FormData>({
|
|
69
|
+
resolver: vineResolver(schema), // Useful to check TypeScript regressions
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
74
|
+
<input {...register('username')} />
|
|
75
|
+
{errors.username && <span role="alert">{errors.username.message}</span>}
|
|
76
|
+
|
|
77
|
+
<input {...register('password')} />
|
|
78
|
+
{errors.password && <span role="alert">{errors.password.message}</span>}
|
|
79
|
+
|
|
80
|
+
<button type="submit">submit</button>
|
|
81
|
+
</form>
|
|
82
|
+
);
|
|
83
|
+
}
|
package/vine/src/index.ts
CHANGED
package/vine/src/vine.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
2
|
-
import { SimpleErrorReporter, errors } from '@vinejs/vine';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import { SimpleErrorReporter, VineValidator, errors } from '@vinejs/vine';
|
|
3
|
+
import { Infer, ValidationOptions } from '@vinejs/vine/build/src/types';
|
|
4
|
+
import {
|
|
5
|
+
FieldError,
|
|
6
|
+
FieldErrors,
|
|
7
|
+
Resolver,
|
|
8
|
+
appendErrors,
|
|
9
|
+
} from 'react-hook-form';
|
|
5
10
|
|
|
6
|
-
|
|
11
|
+
function parseErrorSchema(
|
|
7
12
|
vineErrors: SimpleErrorReporter['errors'],
|
|
8
13
|
validateAllFieldCriteria: boolean,
|
|
9
|
-
)
|
|
14
|
+
) {
|
|
10
15
|
const schemaErrors: Record<string, FieldError> = {};
|
|
11
16
|
|
|
12
17
|
for (; vineErrors.length; ) {
|
|
@@ -34,11 +39,33 @@ const parseErrorSchema = (
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
return schemaErrors;
|
|
37
|
-
}
|
|
42
|
+
}
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Creates a resolver for react-hook-form using VineJS schema validation
|
|
46
|
+
* @param {T} schema - The VineJS schema to validate against
|
|
47
|
+
* @param {ValidationOptions<any>} [schemaOptions] - Optional VineJS validation options
|
|
48
|
+
* @param {Object} [resolverOptions] - Optional resolver configuration
|
|
49
|
+
* @param {boolean} [resolverOptions.raw=false] - If true, returns raw values instead of validated results
|
|
50
|
+
* @returns {Resolver<Infer<typeof schema>>} A resolver function compatible with react-hook-form
|
|
51
|
+
* @example
|
|
52
|
+
* const schema = vine.compile(
|
|
53
|
+
* vine.object({
|
|
54
|
+
* name: vine.string().minLength(2),
|
|
55
|
+
* age: vine.number().min(18)
|
|
56
|
+
* })
|
|
57
|
+
* );
|
|
58
|
+
*
|
|
59
|
+
* useForm({
|
|
60
|
+
* resolver: vineResolver(schema)
|
|
61
|
+
* });
|
|
62
|
+
*/
|
|
63
|
+
export function vineResolver<T extends VineValidator<any, any>>(
|
|
64
|
+
schema: T,
|
|
65
|
+
schemaOptions?: ValidationOptions<any>,
|
|
66
|
+
resolverOptions: { raw?: boolean } = {},
|
|
67
|
+
): Resolver<Infer<typeof schema>> {
|
|
68
|
+
return async (values, _, options) => {
|
|
42
69
|
try {
|
|
43
70
|
const data = await schema.validate(values, schemaOptions);
|
|
44
71
|
|
|
@@ -46,7 +73,7 @@ export const vineResolver: Resolver =
|
|
|
46
73
|
|
|
47
74
|
return {
|
|
48
75
|
errors: {} as FieldErrors,
|
|
49
|
-
values: resolverOptions.raw ? values : data,
|
|
76
|
+
values: resolverOptions.raw ? Object.assign({}, values) : data,
|
|
50
77
|
};
|
|
51
78
|
} catch (error: any) {
|
|
52
79
|
if (error instanceof errors.E_VALIDATION_ERROR) {
|
|
@@ -66,3 +93,4 @@ export const vineResolver: Resolver =
|
|
|
66
93
|
throw error;
|
|
67
94
|
}
|
|
68
95
|
};
|
|
96
|
+
}
|
package/yup/dist/yup.d.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { FieldValues, Resolver } from 'react-hook-form';
|
|
2
2
|
import * as Yup from 'yup';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a resolver for react-hook-form using Yup schema validation
|
|
5
|
+
* @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema
|
|
6
|
+
* @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync
|
|
7
|
+
* @param {Object} resolverOptions - Additional resolver configuration
|
|
8
|
+
* @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode
|
|
9
|
+
* @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results
|
|
10
|
+
* @returns {Resolver<Yup.InferType<typeof schema>>} A resolver function compatible with react-hook-form
|
|
11
|
+
* @example
|
|
12
|
+
* const schema = Yup.object({
|
|
13
|
+
* name: Yup.string().required(),
|
|
14
|
+
* age: Yup.number().required(),
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* useForm({
|
|
18
|
+
* resolver: yupResolver(schema)
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
3
21
|
export declare function yupResolver<TFieldValues extends FieldValues>(schema: Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>, schemaOptions?: Parameters<(typeof schema)['validate']>[1], resolverOptions?: {
|
|
4
|
-
/**
|
|
5
|
-
* @default async
|
|
6
|
-
*/
|
|
7
22
|
mode?: 'async' | 'sync';
|
|
8
|
-
/**
|
|
9
|
-
* Return the raw input values rather than the parsed values.
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
23
|
raw?: boolean;
|
|
13
24
|
}): Resolver<Yup.InferType<typeof schema>>;
|
package/yup/dist/yup.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("@hookform/resolvers"),t=require("react-hook-form");exports.yupResolver=function(r,o,n){return void 0===o&&(o={}),void 0===n&&(n={}),function(s,a,i){try{return Promise.resolve(function(t,u){try{var c=(o.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(r["sync"===n.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},o,{context:a}))).then(function(t){return i.shouldUseNativeValidation&&e.validateFieldsNatively({},i),{values:n.raw?s:t,errors:{}}}))}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(r){if(!r.inner)throw r;return{values:{},errors:e.toNestErrors((o=r,n=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(o.inner||[]).reduce(function(e,r){if(e[r.path]||(e[r.path]={message:r.message,type:r.type}),n){var o=e[r.path].types,s=o&&o[r.type];e[r.path]=t.appendErrors(r.path,n,e,r.type,s?[].concat(s,r.message):r.message)}return e},{})),i)};var o,n}))}catch(e){return Promise.reject(e)}}};
|
|
1
|
+
var e=require("@hookform/resolvers"),t=require("react-hook-form");exports.yupResolver=function(r,o,n){return void 0===o&&(o={}),void 0===n&&(n={}),function(s,a,i){try{return Promise.resolve(function(t,u){try{var c=(o.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(r["sync"===n.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},o,{context:a}))).then(function(t){return i.shouldUseNativeValidation&&e.validateFieldsNatively({},i),{values:n.raw?Object.assign({},s):t,errors:{}}}))}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(r){if(!r.inner)throw r;return{values:{},errors:e.toNestErrors((o=r,n=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(o.inner||[]).reduce(function(e,r){if(e[r.path]||(e[r.path]={message:r.message,type:r.type}),n){var o=e[r.path].types,s=o&&o[r.type];e[r.path]=t.appendErrors(r.path,n,e,r.type,s?[].concat(s,r.message):r.message)}return e},{})),i)};var o,n}))}catch(e){return Promise.reject(e)}}};
|
|
2
2
|
//# sourceMappingURL=yup.js.map
|
package/yup/dist/yup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\
|
|
1
|
+
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nfunction parseErrorSchema(\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n {},\n );\n}\n\n/**\n * Creates a resolver for react-hook-form using Yup schema validation\n * @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema\n * @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results\n * @returns {Resolver<Yup.InferType<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Yup.object({\n * name: Yup.string().required(),\n * age: Yup.number().required(),\n * });\n *\n * useForm({\n * resolver: yupResolver(schema)\n * });\n */\nexport function yupResolver<TFieldValues extends FieldValues>(\n schema:\n | Yup.ObjectSchema<TFieldValues>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<Yup.InferType<typeof schema>> {\n return async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","context","options","Promise","resolve","process","env","NODE_ENV","console","warn","mode","Object","assign","abortEarly","then","result","shouldUseNativeValidation","validateFieldsNatively","raw","errors","_catch","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","reject"],"mappings":"sFA8DM,SACJA,EAGAC,EACAC,GAKA,YAN4D,IAA5DD,IAAAA,EAA4D,CAAA,YAC5DC,IAAAA,EAGI,CAAE,GAEN,SAAcC,EAAQC,EAASC,GAAO,WAAIC,QAAAC,iCAElCN,EAAcG,SAAoC,gBAAzBI,QAAQC,IAAIC,UAEvCC,QAAQC,KACN,iGAEHN,QAAAC,QAEoBP,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDV,EACAW,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEG,QAAAA,MACvDa,KALKC,SAAAA,GASN,OAFAb,EAAQc,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMP,OAAOC,OAAO,CAAA,EAAIZ,GAAUe,EAC1DI,OAAQ,CAAA,EACR,6DArBoCC,YAsB/BC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,CAAE,EACVmB,OAAQI,EAAAA,cAvFdC,EAyFUH,EAxFVI,GAyFWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cAxFZF,EAAMF,OAAS,IAAIK,OACzB,SAACC,EAAUJ,GAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,IAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EAAYA,aAClCV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACA,CAAA,IAmEM1B,IA9FV,IACEsB,EACAC,CA+FE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
|