Skip to content

Commit 5f1a622

Browse files
authored
feat: add support for root errors for field array (#621)
* feat: add support for root errors for field array * refactor: rename toNestError to toNestErrors * chore(deps): update * refactor: toNestError to toNestErrors
1 parent a9d319d commit 5f1a622

File tree

25 files changed

+439
-188
lines changed

25 files changed

+439
-188
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"typescript",
66
"typescriptreact"
77
],
8-
"prettier.configPath": "./.prettierrc.js",
8+
"prettier.configPath": "./prettier.config.cjs",
99
"editor.formatOnSave": true,
1010
"editor.codeActionsOnSave": {
1111
"source.fixAll.eslint": true

ajv/src/ajv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
1+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
22
import Ajv, { DefinedError } from 'ajv';
33
import ajvErrors from 'ajv-errors';
44
import { appendErrors, FieldError } from 'react-hook-form';
@@ -76,7 +76,7 @@ export const ajvResolver: Resolver =
7676
? { values, errors: {} }
7777
: {
7878
values: {},
79-
errors: toNestError(
79+
errors: toNestErrors(
8080
parseErrorSchema(
8181
validate.errors as DefinedError[],
8282
!options.shouldUseNativeValidation &&

arktype/src/arktype.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FieldError, FieldErrors } from 'react-hook-form';
2-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
2+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
33
import type { Resolver } from './types';
44
import { Problems } from 'arktype';
55

@@ -28,7 +28,7 @@ export const arktypeResolver: Resolver =
2828
if (result.problems) {
2929
return {
3030
values: {},
31-
errors: toNestError(parseErrorSchema(result.problems), options),
31+
errors: toNestErrors(parseErrorSchema(result.problems), options),
3232
};
3333
}
3434

class-validator/src/class-validator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FieldErrors } from 'react-hook-form';
2-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
2+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
33
import { plainToClass } from 'class-transformer';
44
import { validate, validateSync, ValidationError } from 'class-validator';
55
import type { Resolver } from './types';
@@ -47,7 +47,7 @@ export const classValidatorResolver: Resolver =
4747
if (rawErrors.length) {
4848
return {
4949
values: {},
50-
errors: toNestError(
50+
errors: toNestErrors(
5151
parseErrors(
5252
rawErrors,
5353
!options.shouldUseNativeValidation &&

computed-types/src/computed-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FieldErrors } from 'react-hook-form';
2-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
2+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
33
import type { Resolver } from './types';
44
import type { ValidationError } from 'computed-types';
55

@@ -33,7 +33,7 @@ export const computedTypesResolver: Resolver =
3333
if (isValidationError(error)) {
3434
return {
3535
values: {},
36-
errors: toNestError(parseErrorSchema(error), options),
36+
errors: toNestErrors(parseErrorSchema(error), options),
3737
};
3838
}
3939

io-ts/src/io-ts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Either from 'fp-ts/Either';
22
import { pipe } from 'fp-ts/function';
3-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
3+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
44
import errorsToRecord from './errorsToRecord';
55
import { Resolver } from './types';
66

@@ -13,7 +13,7 @@ export const ioTsResolver: Resolver = (codec) => (values, _context, options) =>
1313
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
1414
),
1515
),
16-
Either.mapLeft((errors) => toNestError(errors, options)),
16+
Either.mapLeft((errors) => toNestErrors(errors, options)),
1717
Either.fold(
1818
(errors) => ({
1919
values: {},

joi/src/joi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { appendErrors, FieldError } from 'react-hook-form';
2-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
2+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
33
import type { ValidationError } from 'joi';
44
import { Resolver } from './types';
55

@@ -61,7 +61,7 @@ export const joiResolver: Resolver =
6161
if (result.error) {
6262
return {
6363
values: {},
64-
errors: toNestError(
64+
errors: toNestErrors(
6565
parseErrorSchema(
6666
result.error,
6767
!options.shouldUseNativeValidation &&

nope/src/nope.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type {FieldError, FieldErrors} from 'react-hook-form';
2-
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
1+
import type { FieldError, FieldErrors } from 'react-hook-form';
2+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
33
import type { ShapeErrors } from 'nope-validator/lib/cjs/types';
44
import type { Resolver } from './types';
55

@@ -37,7 +37,7 @@ export const nopeResolver: Resolver =
3737
| undefined;
3838

3939
if (result) {
40-
return { values: {}, errors: toNestError(parseErrors(result), options) };
40+
return { values: {}, errors: toNestErrors(parseErrors(result), options) };
4141
}
4242

4343
options.shouldUseNativeValidation && validateFieldsNatively({}, options);

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@
209209
"devDependencies": {
210210
"@sinclair/typebox": "^0.31.1",
211211
"@testing-library/dom": "^9.3.1",
212-
"@testing-library/jest-dom": "^6.0.0",
212+
"@testing-library/jest-dom": "^6.0.1",
213213
"@testing-library/react": "^14.0.0",
214214
"@testing-library/user-event": "^14.4.3",
215-
"@types/node": "^20.5.0",
215+
"@types/node": "^20.5.1",
216216
"@types/react": "^18.2.20",
217217
"@typescript-eslint/eslint-plugin": "^6.4.0",
218218
"@typescript-eslint/parser": "^6.4.0",
@@ -251,9 +251,9 @@
251251
"vest": "^4.6.11",
252252
"vite": "^4.4.9",
253253
"vite-tsconfig-paths": "^4.2.0",
254-
"vitest": "^0.34.1",
254+
"vitest": "^0.34.2",
255255
"yup": "^1.2.0",
256-
"zod": "^3.22.1"
256+
"zod": "^3.22.2"
257257
},
258258
"peerDependencies": {
259259
"react-hook-form": "^7.0.0"

0 commit comments

Comments
 (0)