@hookform/resolvers 3.7.0 → 3.8.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 +69 -0
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +1 -1
- package/ajv/src/__tests__/ajv.ts +7 -1
- package/ajv/src/ajv.ts +1 -1
- package/ajv/src/types.ts +1 -5
- 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/types.d.ts +1 -1
- package/arktype/package.json +2 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +5 -5
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +1 -1
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +29 -29
- package/arktype/src/__tests__/arktype.ts +1 -1
- package/arktype/src/arktype.ts +2 -2
- package/arktype/src/types.ts +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/types.d.ts +2 -2
- package/class-validator/src/__tests__/Form-native-validation.tsx +2 -2
- package/class-validator/src/__tests__/Form.tsx +2 -2
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +2 -2
- package/class-validator/src/__tests__/class-validator.ts +4 -4
- package/class-validator/src/class-validator.ts +2 -2
- package/class-validator/src/types.ts +2 -2
- 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/dist/types.d.ts +1 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -2
- package/computed-types/src/__tests__/Form.tsx +2 -2
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +6 -6
- package/computed-types/src/__tests__/computed-types.ts +1 -1
- package/computed-types/src/computed-types.ts +2 -2
- package/computed-types/src/types.ts +1 -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/dist/toNestErrors.d.ts +1 -6
- package/dist/validateFieldsNatively.d.ts +1 -1
- 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/src/__tests__/Form-native-validation.tsx +2 -2
- package/effect-ts/src/__tests__/Form.tsx +2 -2
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +2 -2
- package/effect-ts/src/__tests__/effect-ts.ts +1 -1
- package/effect-ts/src/effect-ts.ts +1 -1
- package/io-ts/dist/errorsToRecord.d.ts +0 -1
- 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 +2 -2
- package/io-ts/src/__tests__/Form.tsx +2 -2
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +9 -9
- package/io-ts/src/__tests__/errorsToRecord.ts +29 -19
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/io-ts/src/errorsToRecord.ts +19 -10
- package/io-ts/src/io-ts.ts +1 -1
- package/joi/dist/joi.js +1 -1
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.mjs +1 -1
- package/joi/dist/joi.modern.mjs +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +1 -1
- package/joi/src/__tests__/Form-native-validation.tsx +2 -2
- package/joi/src/__tests__/Form.tsx +2 -2
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +56 -56
- package/joi/src/__tests__/joi.ts +1 -1
- package/joi/src/joi.ts +1 -1
- package/joi/src/types.ts +1 -5
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +1 -1
- package/nope/src/__tests__/Form-native-validation.tsx +2 -2
- package/nope/src/__tests__/Form.tsx +2 -2
- package/nope/src/__tests__/__fixtures__/data.ts +1 -1
- package/nope/src/__tests__/nope.ts +1 -1
- package/nope/src/nope.ts +1 -1
- package/nope/src/types.ts +2 -2
- package/package.json +54 -51
- 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/dist/types.d.ts +1 -1
- package/superstruct/src/__tests__/Form-native-validation.tsx +2 -2
- package/superstruct/src/__tests__/Form.tsx +2 -2
- package/superstruct/src/__tests__/__fixtures__/data.ts +8 -8
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +4 -4
- package/superstruct/src/__tests__/superstruct.ts +1 -1
- package/superstruct/src/superstruct.ts +1 -1
- package/superstruct/src/types.ts +1 -1
- 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/dist/types.d.ts +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +1 -1
- package/typanion/src/__tests__/Form.tsx +1 -1
- package/typanion/src/__tests__/__fixtures__/data.ts +12 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +4 -4
- package/typanion/src/__tests__/typanion.ts +1 -1
- package/typanion/src/typanion.ts +1 -1
- package/typanion/src/types.ts +4 -4
- 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/dist/types.d.ts +3 -2
- package/typebox/src/__tests__/Form-compiler.tsx +57 -0
- package/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +4 -4
- package/typebox/src/__tests__/Form.tsx +3 -3
- package/typebox/src/__tests__/__fixtures__/data.ts +6 -2
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +13 -13
- package/typebox/src/__tests__/typebox-compiler.ts +37 -0
- package/typebox/src/__tests__/typebox.ts +1 -1
- package/typebox/src/typebox.ts +8 -3
- package/typebox/src/types.ts +3 -2
- package/typeschema/dist/index.d.ts +2 -0
- package/typeschema/dist/types.d.ts +9 -0
- package/typeschema/dist/typeschema.d.ts +2 -0
- package/typeschema/dist/typeschema.js +2 -0
- package/typeschema/dist/typeschema.js.map +1 -0
- package/typeschema/dist/typeschema.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs.map +1 -0
- package/typeschema/dist/typeschema.module.js +2 -0
- package/typeschema/dist/typeschema.module.js.map +1 -0
- package/typeschema/dist/typeschema.umd.js +2 -0
- package/typeschema/dist/typeschema.umd.js.map +1 -0
- package/typeschema/package.json +18 -0
- package/typeschema/src/__tests__/Form-native-validation.tsx +82 -0
- package/typeschema/src/__tests__/Form.tsx +53 -0
- package/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
- package/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
- package/typeschema/src/__tests__/typeschema.ts +70 -0
- package/typeschema/src/index.ts +2 -0
- package/typeschema/src/types.ts +18 -0
- package/typeschema/src/typeschema.ts +70 -0
- package/valibot/dist/types.d.ts +1 -1
- 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/src/__tests__/Form-native-validation.tsx +2 -2
- package/valibot/src/__tests__/Form.tsx +1 -1
- package/valibot/src/__tests__/valibot.ts +4 -4
- package/valibot/src/types.ts +1 -1
- package/valibot/src/valibot.ts +12 -6
- package/vest/dist/types.d.ts +2 -2
- 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/__tests__/Form-native-validation.tsx +1 -1
- package/vest/src/__tests__/Form.tsx +1 -1
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +0 -6
- package/vest/src/__tests__/vest.ts +14 -8
- package/vest/src/types.ts +11 -4
- package/vest/src/vest.ts +1 -1
- package/vine/dist/types.d.ts +1 -1
- 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 +9 -5
- package/vine/src/__tests__/Form.tsx +9 -5
- package/vine/src/__tests__/__fixtures__/data.ts +4 -2
- package/vine/src/__tests__/vine.ts +1 -1
- package/vine/src/types.ts +1 -1
- package/vine/src/vine.ts +10 -8
- package/yup/dist/yup.d.ts +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +1 -1
- package/yup/src/__tests__/Form.tsx +1 -1
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +13 -13
- package/yup/src/__tests__/yup.ts +9 -7
- package/yup/src/yup.ts +2 -2
- package/zod/dist/types.d.ts +1 -1
- 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-native-validation.tsx +2 -2
- package/zod/src/__tests__/Form.tsx +1 -1
- package/zod/src/__tests__/zod.ts +1 -1
- package/zod/src/types.ts +1 -1
- package/zod/src/zod.ts +4 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
2
|
+
import type { ValidationIssue } from '@typeschema/core';
|
|
3
|
+
import { validate } from '@typeschema/main';
|
|
4
|
+
import { FieldError, FieldErrors, appendErrors } from 'react-hook-form';
|
|
5
|
+
import type { Resolver } from './types';
|
|
6
|
+
|
|
7
|
+
const parseErrorSchema = (
|
|
8
|
+
typeschemaErrors: ValidationIssue[],
|
|
9
|
+
validateAllFieldCriteria: boolean,
|
|
10
|
+
): FieldErrors => {
|
|
11
|
+
const errors: Record<string, FieldError> = {};
|
|
12
|
+
|
|
13
|
+
for (; typeschemaErrors.length; ) {
|
|
14
|
+
const error = typeschemaErrors[0];
|
|
15
|
+
|
|
16
|
+
if (!error.path) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const _path = error.path.join('.');
|
|
20
|
+
|
|
21
|
+
if (!errors[_path]) {
|
|
22
|
+
errors[_path] = { message: error.message, type: '' };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (validateAllFieldCriteria) {
|
|
26
|
+
const types = errors[_path].types;
|
|
27
|
+
const messages = types && types[''];
|
|
28
|
+
|
|
29
|
+
errors[_path] = appendErrors(
|
|
30
|
+
_path,
|
|
31
|
+
validateAllFieldCriteria,
|
|
32
|
+
errors,
|
|
33
|
+
'',
|
|
34
|
+
messages
|
|
35
|
+
? ([] as string[]).concat(messages as string[], error.message)
|
|
36
|
+
: error.message,
|
|
37
|
+
) as FieldError;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
typeschemaErrors.shift();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return errors;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const typeschemaResolver: Resolver =
|
|
47
|
+
(schema, _, resolverOptions = {}) =>
|
|
48
|
+
async (values, _, options) => {
|
|
49
|
+
const result = await validate(schema, values);
|
|
50
|
+
|
|
51
|
+
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
52
|
+
|
|
53
|
+
if (result.success) {
|
|
54
|
+
return {
|
|
55
|
+
errors: {} as FieldErrors,
|
|
56
|
+
values: resolverOptions.raw ? values : (result.data as any),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
values: {},
|
|
62
|
+
errors: toNestErrors(
|
|
63
|
+
parseErrorSchema(
|
|
64
|
+
result.issues,
|
|
65
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
|
|
66
|
+
),
|
|
67
|
+
options,
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
};
|
package/valibot/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldValues,
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
2
|
import { BaseIssue, BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';
|
|
3
3
|
export type Resolver = <T extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(schema: T, schemaOptions?: Partial<Omit<Config<InferIssue<T>>, 'abortPipeEarly' | 'skipPipe'>>, resolverOptions?: {
|
|
4
4
|
/**
|
package/valibot/dist/valibot.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("react-hook-form"),s=require("valibot");exports.valibotResolver=function(t,o,a){return void 0===a&&(a={}),function(i,u,n){try{var v=!n.shouldUseNativeValidation&&"all"===n.criteriaMode;return Promise.resolve(s.safeParseAsync(t,i,Object.assign({},o,{abortPipeEarly:!v}))).then(function(t){if(t.issues){for(var o={};t.issues.length;){var u=t.issues[0],l=s.getDotPath(u);if(l&&(o[l]||(o[l]={message:u.message,type:u.type}),v)){var c=o[l].types,f=c&&c[u.type];o[l]=r.appendErrors(l,v,o,u.type,f?[].concat(f,u.message):u.message)}t.issues.shift()}return{values:{},errors:e.toNestErrors(o,n)}}return{values:a.raw?i:t.output,errors:{}}})}catch(e){return Promise.reject(e)}}};
|
|
2
2
|
//# sourceMappingURL=valibot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError,
|
|
1
|
+
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, FieldValues, appendErrors } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","Object","assign","abortPipeEarly","then","result","issues","errors","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output","e","reject"],"mappings":"+GAME,SAACA,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eACjCX,EACAG,EACAS,OAAOC,OAAO,GAAIZ,EAAe,CAC/Ba,gBAAiBR,MAEpBS,KAAA,SANKC,GASN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAAMC,EAAqC,CAAA,EAGpCF,EAAOC,OAAOE,QAAU,CAC7B,IAAMC,EAAQJ,EAAOC,OAAO,GAEtBI,EAAOC,EAAUA,WAACF,GAExB,GAAIC,IAEGH,EAAOG,KACVH,EAAOG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDlB,GAA0B,CAC5B,IAAMmB,EAAQP,EAAOG,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCN,EAAOG,GAAQM,eACbN,EACAf,EACAY,EACAE,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFP,EAAOC,OAAOY,OAChB,CAGA,MAAO,CACL1B,OAAQ,CAAA,EACRe,OAAQY,EAAAA,aAAaZ,EAAQb,GAEjC,CAGA,MAAO,CACLF,OAAQD,EAAgB6B,IAAM5B,EAAUa,EAAOgB,OAC/Cd,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAe,GAAAxB,OAAAA,QAAAyB,OAAAD,EAAA,CAAA,CAAA"}
|
package/valibot/dist/valibot.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as
|
|
1
|
+
import{toNestErrors as e}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";import{safeParseAsync as s,getDotPath as t}from"valibot";var o=function(o,a,i){return void 0===i&&(i={}),function(u,n,m){try{var f=!m.shouldUseNativeValidation&&"all"===m.criteriaMode;return Promise.resolve(s(o,u,Object.assign({},a,{abortPipeEarly:!f}))).then(function(s){if(s.issues){for(var o={};s.issues.length;){var a=s.issues[0],n=t(a);if(n&&(o[n]||(o[n]={message:a.message,type:a.type}),f)){var v=o[n].types,c=v&&v[a.type];o[n]=r(n,f,o,a.type,c?[].concat(c,a.message):a.message)}s.issues.shift()}return{values:{},errors:e(o,m)}}return{values:i.raw?u:s.output,errors:{}}})}catch(e){return Promise.reject(e)}}};export{o as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as
|
|
1
|
+
import{toNestErrors as s}from"@hookform/resolvers";import{appendErrors as e}from"react-hook-form";import{safeParseAsync as o,getDotPath as t}from"valibot";const r=(r,a,i={})=>async(m,n,c)=>{const p=!c.shouldUseNativeValidation&&"all"===c.criteriaMode,u=await o(r,m,Object.assign({},a,{abortPipeEarly:!p}));if(u.issues){const o={};for(;u.issues.length;){const s=u.issues[0],r=t(s);if(r&&(o[r]||(o[r]={message:s.message,type:s.type}),p)){const t=o[r].types,a=t&&t[s.type];o[r]=e(r,p,o,s.type,a?[].concat(a,s.message):s.message)}u.issues.shift()}return{values:{},errors:s(o,c)}}return{values:i.raw?m:u.output,errors:{}}};export{r as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError,
|
|
1
|
+
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, FieldValues, appendErrors } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","async","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","result","safeParseAsync","Object","assign","abortPipeEarly","issues","errors","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output"],"mappings":"2JAKa,MAAAA,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAA,IAC1CC,MAAOC,EAAQC,EAAGC,KAEhB,MAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAG1CC,QAAeC,EACnBX,EACAI,EACAQ,OAAOC,OAAO,CAAA,EAAIZ,EAAe,CAC/Ba,gBAAiBP,KAKrB,GAAIG,EAAOK,OAAQ,CAEjB,MAAMC,EAAqC,CAAA,EAG3C,KAAON,EAAOK,OAAOE,QAAU,CAC7B,MAAMC,EAAQR,EAAOK,OAAO,GAEtBI,EAAOC,EAAWF,GAExB,GAAIC,IAEGH,EAAOG,KACVH,EAAOG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDf,GAA0B,CAC5B,MAAMgB,EAAQP,EAAOG,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCN,EAAOG,GAAQM,EACbN,EACAZ,EACAS,EACAE,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFX,EAAOK,OAAOY,OAChB,CAGA,MAAO,CACLvB,OAAQ,CAAA,EACRY,OAAQY,EAAaZ,EAAQV,GAEjC,CAGA,MAAO,CACLF,OAAQF,EAAgB2B,IAAMzB,EAAUM,EAAOoB,OAC/Cd,OAAQ,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as
|
|
1
|
+
import{toNestErrors as e}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";import{safeParseAsync as s,getDotPath as t}from"valibot";var o=function(o,a,i){return void 0===i&&(i={}),function(u,n,m){try{var f=!m.shouldUseNativeValidation&&"all"===m.criteriaMode;return Promise.resolve(s(o,u,Object.assign({},a,{abortPipeEarly:!f}))).then(function(s){if(s.issues){for(var o={};s.issues.length;){var a=s.issues[0],n=t(a);if(n&&(o[n]||(o[n]={message:a.message,type:a.type}),f)){var v=o[n].types,c=v&&v[a.type];o[n]=r(n,f,o,a.type,c?[].concat(c,a.message):a.message)}s.issues.shift()}return{values:{},errors:e(o,m)}}return{values:i.raw?u:s.output,errors:{}}})}catch(e){return Promise.reject(e)}}};export{o as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError,
|
|
1
|
+
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, FieldValues, appendErrors } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","Object","assign","abortPipeEarly","then","result","issues","errors","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output","e","reject"],"mappings":"2JAKa,IAAAA,EACX,SAACC,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EACnBX,EACAG,EACAS,OAAOC,OAAO,GAAIZ,EAAe,CAC/Ba,gBAAiBR,MAEpBS,KAAA,SANKC,GASN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAAMC,EAAqC,CAAA,EAGpCF,EAAOC,OAAOE,QAAU,CAC7B,IAAMC,EAAQJ,EAAOC,OAAO,GAEtBI,EAAOC,EAAWF,GAExB,GAAIC,IAEGH,EAAOG,KACVH,EAAOG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDlB,GAA0B,CAC5B,IAAMmB,EAAQP,EAAOG,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCN,EAAOG,GAAQM,EACbN,EACAf,EACAY,EACAE,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFP,EAAOC,OAAOY,OAChB,CAGA,MAAO,CACL1B,OAAQ,CAAA,EACRe,OAAQY,EAAaZ,EAAQb,GAEjC,CAGA,MAAO,CACLF,OAAQD,EAAgB6B,IAAM5B,EAAUa,EAAOgB,OAC/Cd,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAe,GAAAxB,OAAAA,QAAAyB,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("react-hook-form"),require("valibot")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form","valibot"],o):o((e||self).hookformResolversValibot={},e.hookformResolvers,e.ReactHookForm,e.valibot)}(this,function(e,o,r,s){e.valibotResolver=function(e,t,i){return void 0===i&&(i={}),function(a,n,f){try{var u=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(s.safeParseAsync(e,a,Object.assign({},t,{abortPipeEarly:!u}))).then(function(e){if(e.issues){for(var t={};e.issues.length;){var n=e.issues[0],l=s.getDotPath(n);if(l&&(t[l]||(t[l]={message:n.message,type:n.type}),u)){var c=t[l].types,v=c&&c[n.type];t[l]=r.appendErrors(l,u,t,n.type,v?[].concat(v,n.message):n.message)}e.issues.shift()}return{values:{},errors:o.toNestErrors(t,f)}}return{values:i.raw?a:e.output,errors:{}}})}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=valibot.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError,
|
|
1
|
+
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, FieldValues, appendErrors } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","Object","assign","abortPipeEarly","then","result","issues","errors","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output","e","reject"],"mappings":"ubAME,SAACA,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eACjCX,EACAG,EACAS,OAAOC,OAAO,GAAIZ,EAAe,CAC/Ba,gBAAiBR,MAEpBS,KAAA,SANKC,GASN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAAMC,EAAqC,CAAA,EAGpCF,EAAOC,OAAOE,QAAU,CAC7B,IAAMC,EAAQJ,EAAOC,OAAO,GAEtBI,EAAOC,EAAUA,WAACF,GAExB,GAAIC,IAEGH,EAAOG,KACVH,EAAOG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDlB,GAA0B,CAC5B,IAAMmB,EAAQP,EAAOG,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCN,EAAOG,GAAQM,eACbN,EACAf,EACAY,EACAE,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFP,EAAOC,OAAOY,OAChB,CAGA,MAAO,CACL1B,OAAQ,CAAA,EACRe,OAAQY,EAAAA,aAAaZ,EAAQb,GAEjC,CAGA,MAAO,CACLF,OAAQD,EAAgB6B,IAAM5B,EAAUa,EAAOgB,OAC/Cd,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAe,GAAAxB,OAAAA,QAAAyB,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useForm } from 'react-hook-form';
|
|
3
1
|
import { render, screen } from '@testing-library/react';
|
|
4
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as v from 'valibot';
|
|
6
6
|
import { valibotResolver } from '..';
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as v from 'valibot';
|
|
6
6
|
import { valibotResolver } from '..';
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import * as valibot from 'valibot';
|
|
1
2
|
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
|
|
2
3
|
import { valibotResolver } from '..';
|
|
3
4
|
import {
|
|
4
|
-
schema,
|
|
5
|
-
validData,
|
|
6
5
|
fields,
|
|
7
6
|
invalidData,
|
|
7
|
+
invalidSchemaErrorData,
|
|
8
|
+
schema,
|
|
8
9
|
schemaError,
|
|
10
|
+
validData,
|
|
9
11
|
validSchemaErrorData,
|
|
10
|
-
invalidSchemaErrorData,
|
|
11
12
|
} from './__fixtures__/data';
|
|
12
|
-
import * as valibot from 'valibot';
|
|
13
13
|
|
|
14
14
|
const shouldUseNativeValidation = false;
|
|
15
15
|
describe('valibotResolver', () => {
|
package/valibot/src/types.ts
CHANGED
package/valibot/src/valibot.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toNestErrors } from '@hookform/resolvers';
|
|
2
|
-
import { FieldError,
|
|
2
|
+
import { FieldError, FieldValues, appendErrors } from 'react-hook-form';
|
|
3
3
|
import { getDotPath, safeParseAsync } from 'valibot';
|
|
4
4
|
import type { Resolver } from './types';
|
|
5
5
|
|
|
@@ -11,10 +11,13 @@ export const valibotResolver: Resolver =
|
|
|
11
11
|
!options.shouldUseNativeValidation && options.criteriaMode === 'all';
|
|
12
12
|
|
|
13
13
|
// Parse values with Valibot schema
|
|
14
|
-
const result = await safeParseAsync(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const result = await safeParseAsync(
|
|
15
|
+
schema,
|
|
16
|
+
values,
|
|
17
|
+
Object.assign({}, schemaOptions, {
|
|
18
|
+
abortPipeEarly: !validateAllFieldCriteria,
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
18
21
|
|
|
19
22
|
// If there are issues, return them as errors
|
|
20
23
|
if (result.issues) {
|
|
@@ -22,7 +25,8 @@ export const valibotResolver: Resolver =
|
|
|
22
25
|
const errors: Record<string, FieldError> = {};
|
|
23
26
|
|
|
24
27
|
// Iterate over issues to add them to errors object
|
|
25
|
-
for (
|
|
28
|
+
for (; result.issues.length; ) {
|
|
29
|
+
const issue = result.issues[0];
|
|
26
30
|
// Create dot path from issue
|
|
27
31
|
const path = getDotPath(issue);
|
|
28
32
|
|
|
@@ -50,6 +54,8 @@ export const valibotResolver: Resolver =
|
|
|
50
54
|
) as FieldError;
|
|
51
55
|
}
|
|
52
56
|
}
|
|
57
|
+
|
|
58
|
+
result.issues.shift();
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
// Return resolver result with errors
|
package/vest/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldName, FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
2
|
import * as Vest from 'vest';
|
|
3
|
-
export type ICreateResult<TValues extends FieldValues = FieldValues, TContext = any> = ReturnType<typeof Vest.create<(values: TValues, names?: FieldName<TValues>[], context?: TContext) => void>>;
|
|
3
|
+
export type ICreateResult<TValues extends FieldValues = FieldValues, TContext = any> = ReturnType<typeof Vest.create<any, any, (values: TValues, names?: FieldName<TValues>[], context?: TContext) => void>>;
|
|
4
4
|
export type Resolver = <TValues extends FieldValues, TContext>(schema: ICreateResult<TValues, TContext>, schemaOptions?: never, factoryOptions?: {
|
|
5
5
|
mode?: 'async' | 'sync';
|
|
6
6
|
rawValues?: boolean;
|
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 {
|
|
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,uBAGE,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 {
|
|
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,GAGIQ,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 {
|
|
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,EAEaQ,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 {
|
|
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,iBAGE,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,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as vest from 'vest';
|
|
6
6
|
import { vestResolver } from '..';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as vest from 'vest';
|
|
6
6
|
import { vestResolver } from '..';
|
|
@@ -21,8 +21,6 @@ exports[`vestResolver > should return all the error messages from vestResolver w
|
|
|
21
21
|
"type": "",
|
|
22
22
|
"types": {
|
|
23
23
|
"0": "Password must be at least 5 chars",
|
|
24
|
-
"1": "Password must contain a digit",
|
|
25
|
-
"2": "Password must contain a symbol",
|
|
26
24
|
},
|
|
27
25
|
},
|
|
28
26
|
"username": {
|
|
@@ -33,7 +31,6 @@ exports[`vestResolver > should return all the error messages from vestResolver w
|
|
|
33
31
|
"type": "",
|
|
34
32
|
"types": {
|
|
35
33
|
"0": "Username is required",
|
|
36
|
-
"1": "Must be longer than 3 chars",
|
|
37
34
|
},
|
|
38
35
|
},
|
|
39
36
|
},
|
|
@@ -62,8 +59,6 @@ exports[`vestResolver > should return all the error messages from vestResolver w
|
|
|
62
59
|
"type": "",
|
|
63
60
|
"types": {
|
|
64
61
|
"0": "Password must be at least 5 chars",
|
|
65
|
-
"1": "Password must contain a digit",
|
|
66
|
-
"2": "Password must contain a symbol",
|
|
67
62
|
},
|
|
68
63
|
},
|
|
69
64
|
"username": {
|
|
@@ -74,7 +69,6 @@ exports[`vestResolver > should return all the error messages from vestResolver w
|
|
|
74
69
|
"type": "",
|
|
75
70
|
"types": {
|
|
76
71
|
"0": "Username is required",
|
|
77
|
-
"1": "Must be longer than 3 chars",
|
|
78
72
|
},
|
|
79
73
|
},
|
|
80
74
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { vestResolver } from '..';
|
|
2
2
|
import {
|
|
3
|
+
fields,
|
|
3
4
|
invalidData,
|
|
4
|
-
validationSuite,
|
|
5
5
|
validData,
|
|
6
|
-
|
|
6
|
+
validationSuite,
|
|
7
7
|
} from './__fixtures__/data';
|
|
8
8
|
|
|
9
9
|
const shouldUseNativeValidation = false;
|
|
@@ -72,13 +72,19 @@ describe('vestResolver', () => {
|
|
|
72
72
|
it('should call a suite with values, validated field names and a context as arguments', async () => {
|
|
73
73
|
const suite = vi.fn(validationSuite) as any as typeof validationSuite;
|
|
74
74
|
|
|
75
|
-
await vestResolver(suite)(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
await vestResolver(suite)(
|
|
76
|
+
validData,
|
|
77
|
+
{ some: 'context' },
|
|
78
|
+
{
|
|
79
|
+
fields: { username: fields.username },
|
|
80
|
+
names: ['username'],
|
|
81
|
+
shouldUseNativeValidation,
|
|
82
|
+
},
|
|
83
|
+
);
|
|
80
84
|
|
|
81
85
|
expect(suite).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(suite).toHaveBeenCalledWith(validData, ['username'], {
|
|
86
|
+
expect(suite).toHaveBeenCalledWith(validData, ['username'], {
|
|
87
|
+
some: 'context',
|
|
88
|
+
});
|
|
83
89
|
});
|
|
84
90
|
});
|
package/vest/src/types.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FieldValues,
|
|
3
2
|
FieldName,
|
|
3
|
+
FieldValues,
|
|
4
4
|
ResolverOptions,
|
|
5
5
|
ResolverResult,
|
|
6
6
|
} from 'react-hook-form';
|
|
7
7
|
import * as Vest from 'vest';
|
|
8
8
|
|
|
9
|
-
export type ICreateResult<
|
|
10
|
-
|
|
9
|
+
export type ICreateResult<
|
|
10
|
+
TValues extends FieldValues = FieldValues,
|
|
11
|
+
TContext = any,
|
|
12
|
+
> = ReturnType<
|
|
13
|
+
typeof Vest.create<
|
|
14
|
+
any,
|
|
15
|
+
any,
|
|
16
|
+
(values: TValues, names?: FieldName<TValues>[], context?: TContext) => void
|
|
17
|
+
>
|
|
11
18
|
>;
|
|
12
19
|
|
|
13
20
|
export type Resolver = <TValues extends FieldValues, TContext>(
|
|
14
21
|
schema: ICreateResult<TValues, TContext>,
|
|
15
22
|
schemaOptions?: never,
|
|
16
|
-
factoryOptions?: { mode?: 'async' | 'sync'
|
|
23
|
+
factoryOptions?: { mode?: 'async' | 'sync'; rawValues?: boolean },
|
|
17
24
|
) => (
|
|
18
25
|
values: TValues,
|
|
19
26
|
context: TContext | undefined,
|
package/vest/src/vest.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
2
2
|
import { FieldError } from 'react-hook-form';
|
|
3
3
|
import promisify from 'vest/promisify';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Resolver, VestErrors } from './types';
|
|
5
5
|
|
|
6
6
|
const parseErrorSchema = (
|
|
7
7
|
vestError: VestErrors,
|
package/vine/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
1
|
import { VineValidator } from '@vinejs/vine';
|
|
3
2
|
import { ValidationOptions } from '@vinejs/vine/build/src/types';
|
|
3
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
4
4
|
export type Resolver = <T extends VineValidator<any, any>>(schema: T, schemaOptions?: ValidationOptions<any>, resolverOptions?: {
|
|
5
5
|
raw?: boolean;
|
|
6
6
|
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
package/vine/dist/vine.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("@vinejs/vine"),t=require("react-hook-form"),o=function(e,r){for(var o={};e.length;){var s=e[0],i=s.field;if(i in o||(o[i]={message:s.message,type:s.rule}),r){var n=o[i].types,a=n&&n[s.rule];o[i]=t.appendErrors(i,r,o,s.rule,a?[].concat(a,[s.message]):s.message)}e.shift()}return o};exports.vineResolver=function(t,s,i){return void 0===i&&(i={}),function(n,a,u){try{return Promise.resolve(function(r,o){try{var a=Promise.resolve(t.validate(n,s)).then(function(r){return u.shouldUseNativeValidation&&e.validateFieldsNatively({},u),{errors:{},values:i.raw?n:r}})}catch(e){return o(e)}return a&&a.then?a.then(void 0,o):a}(0,function(t){if(t instanceof r.errors.E_VALIDATION_ERROR)return{values:{},errors:e.toNestErrors(o(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 {
|
|
1
|
+
{"version":3,"file":"vine.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst 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\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n 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 ? 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"],"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","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"4FAKMA,EAAmB,SACvBC,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,EAAuBP,CAAAA,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,uBAGE,SAACa,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEP,GAEzD,CACLQ,OAAQ,GACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,GAU1B,SAAQ1B,GACP,GAAIA,aAAiBwB,EAAMA,OAACG,mBAC1B,MAAO,CACLb,OAAQ,CAAA,EACRU,OAAQI,EAAYA,aAClBjC,EACEK,EAAMO,UACLS,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMhB,CACR,GACF,CAAC,MAAA8B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|