@hookform/resolvers 2.9.8 → 2.9.10

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.
@@ -60,6 +60,17 @@ export const invalidData = {
60
60
  },
61
61
  };
62
62
 
63
+ export const invalidDataWithUndefined = {
64
+ username: 'jsun969',
65
+ password: undefined,
66
+ deepObject: {
67
+ twoLayersDeep: {
68
+ name: 'deeper',
69
+ },
70
+ data: undefined,
71
+ }
72
+ }
73
+
63
74
  export const fields: Record<InternalFieldName, Field['_f']> = {
64
75
  username: {
65
76
  ref: { name: 'username' },
@@ -54,6 +54,28 @@ Object {
54
54
  }
55
55
  `;
56
56
 
57
+ exports[`ajvResolver should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure 1`] = `
58
+ Object {
59
+ "errors": Object {
60
+ "deepObject": Object {
61
+ "data": Object {
62
+ "message": "must have required property 'data'",
63
+ "ref": undefined,
64
+ "type": "required",
65
+ },
66
+ },
67
+ "password": Object {
68
+ "message": "must have required property 'password'",
69
+ "ref": Object {
70
+ "name": "password",
71
+ },
72
+ "type": "required",
73
+ },
74
+ },
75
+ "values": Object {},
76
+ }
77
+ `;
78
+
57
79
  exports[`ajvResolver should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
58
80
  Object {
59
81
  "errors": Object {
@@ -1,5 +1,5 @@
1
1
  import { ajvResolver } from '..';
2
- import { fields, invalidData, schema, validData } from './__fixtures__/data';
2
+ import { fields, invalidData, invalidDataWithUndefined, schema, validData } from './__fixtures__/data';
3
3
 
4
4
  const shouldUseNativeValidation = false;
5
5
 
@@ -81,4 +81,17 @@ describe('ajvResolver', () => {
81
81
  }),
82
82
  ).toMatchSnapshot();
83
83
  });
84
+
85
+ it('should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure', async () => {
86
+ expect(
87
+ await ajvResolver(schema, undefined, { mode: 'sync' })(
88
+ invalidDataWithUndefined,
89
+ undefined,
90
+ {
91
+ fields,
92
+ shouldUseNativeValidation,
93
+ },
94
+ ),
95
+ ).toMatchSnapshot();
96
+ });
84
97
  });
package/ajv/src/ajv.ts CHANGED
@@ -11,7 +11,7 @@ const parseErrorSchema = (
11
11
  // Ajv will return empty instancePath when require error
12
12
  ajvErrors.forEach((error) => {
13
13
  if (error.keyword === 'required') {
14
- error.instancePath = '/' + error.params.missingProperty;
14
+ error.instancePath += '/' + error.params.missingProperty;
15
15
  }
16
16
  });
17
17
 
@@ -1,6 +1,6 @@
1
1
  import * as t from 'io-ts';
2
2
  import { FieldError, FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
- export declare type Resolver = <T, TFieldValues, TContext>(codec: t.Decoder<FieldValues, T>) => (values: TFieldValues, _context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
3
+ export declare type Resolver = <T, TFieldValues extends FieldValues, TContext>(codec: t.Decoder<FieldValues, T>) => (values: TFieldValues, _context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
4
4
  export declare type ErrorObject = Record<string, FieldError>;
5
5
  export declare type FieldErrorWithPath = FieldError & {
6
6
  path: string;
@@ -6,7 +6,7 @@ import {
6
6
  ResolverResult,
7
7
  } from 'react-hook-form';
8
8
 
9
- export type Resolver = <T, TFieldValues, TContext>(
9
+ export type Resolver = <T, TFieldValues extends FieldValues, TContext>(
10
10
  codec: t.Decoder<FieldValues, T>,
11
11
  ) => (
12
12
  values: TFieldValues,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hookform/resolvers",
3
3
  "amdName": "hookformResolvers",
4
- "version": "2.9.8",
4
+ "version": "2.9.10",
5
5
  "description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types and Typanion",
6
6
  "main": "dist/resolvers.js",
7
7
  "module": "dist/resolvers.module.js",