Skip to content

Commit

Permalink
feat: add support for root errors for field array (#621)
Browse files Browse the repository at this point in the history
* feat: add support for root errors for field array

* refactor: rename toNestError to toNestErrors

* chore(deps): update

* refactor: toNestError to toNestErrors
  • Loading branch information
jorisre committed Aug 20, 2023
1 parent a9d319d commit 5f1a622
Show file tree
Hide file tree
Showing 25 changed files with 439 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Expand Up @@ -5,7 +5,7 @@
"typescript",
"typescriptreact"
],
"prettier.configPath": "./.prettierrc.js",
"prettier.configPath": "./prettier.config.cjs",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
Expand Down
4 changes: 2 additions & 2 deletions ajv/src/ajv.ts
@@ -1,4 +1,4 @@
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import Ajv, { DefinedError } from 'ajv';
import ajvErrors from 'ajv-errors';
import { appendErrors, FieldError } from 'react-hook-form';
Expand Down Expand Up @@ -76,7 +76,7 @@ export const ajvResolver: Resolver =
? { values, errors: {} }
: {
values: {},
errors: toNestError(
errors: toNestErrors(
parseErrorSchema(
validate.errors as DefinedError[],
!options.shouldUseNativeValidation &&
Expand Down
4 changes: 2 additions & 2 deletions arktype/src/arktype.ts
@@ -1,5 +1,5 @@
import { FieldError, FieldErrors } from 'react-hook-form';
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { Resolver } from './types';
import { Problems } from 'arktype';

Expand Down Expand Up @@ -28,7 +28,7 @@ export const arktypeResolver: Resolver =
if (result.problems) {
return {
values: {},
errors: toNestError(parseErrorSchema(result.problems), options),
errors: toNestErrors(parseErrorSchema(result.problems), options),
};
}

Expand Down
4 changes: 2 additions & 2 deletions class-validator/src/class-validator.ts
@@ -1,5 +1,5 @@
import { FieldErrors } from 'react-hook-form';
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { plainToClass } from 'class-transformer';
import { validate, validateSync, ValidationError } from 'class-validator';
import type { Resolver } from './types';
Expand Down Expand Up @@ -47,7 +47,7 @@ export const classValidatorResolver: Resolver =
if (rawErrors.length) {
return {
values: {},
errors: toNestError(
errors: toNestErrors(
parseErrors(
rawErrors,
!options.shouldUseNativeValidation &&
Expand Down
4 changes: 2 additions & 2 deletions computed-types/src/computed-types.ts
@@ -1,5 +1,5 @@
import type { FieldErrors } from 'react-hook-form';
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { Resolver } from './types';
import type { ValidationError } from 'computed-types';

Expand Down Expand Up @@ -33,7 +33,7 @@ export const computedTypesResolver: Resolver =
if (isValidationError(error)) {
return {
values: {},
errors: toNestError(parseErrorSchema(error), options),
errors: toNestErrors(parseErrorSchema(error), options),
};
}

Expand Down
4 changes: 2 additions & 2 deletions io-ts/src/io-ts.ts
@@ -1,6 +1,6 @@
import * as Either from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import errorsToRecord from './errorsToRecord';
import { Resolver } from './types';

Expand All @@ -13,7 +13,7 @@ export const ioTsResolver: Resolver = (codec) => (values, _context, options) =>
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
),
),
Either.mapLeft((errors) => toNestError(errors, options)),
Either.mapLeft((errors) => toNestErrors(errors, options)),
Either.fold(
(errors) => ({
values: {},
Expand Down
4 changes: 2 additions & 2 deletions joi/src/joi.ts
@@ -1,5 +1,5 @@
import { appendErrors, FieldError } from 'react-hook-form';
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { ValidationError } from 'joi';
import { Resolver } from './types';

Expand Down Expand Up @@ -61,7 +61,7 @@ export const joiResolver: Resolver =
if (result.error) {
return {
values: {},
errors: toNestError(
errors: toNestErrors(
parseErrorSchema(
result.error,
!options.shouldUseNativeValidation &&
Expand Down
6 changes: 3 additions & 3 deletions nope/src/nope.ts
@@ -1,5 +1,5 @@
import type {FieldError, FieldErrors} from 'react-hook-form';
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
import type { FieldError, FieldErrors } from 'react-hook-form';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { ShapeErrors } from 'nope-validator/lib/cjs/types';
import type { Resolver } from './types';

Expand Down Expand Up @@ -37,7 +37,7 @@ export const nopeResolver: Resolver =
| undefined;

if (result) {
return { values: {}, errors: toNestError(parseErrors(result), options) };
return { values: {}, errors: toNestErrors(parseErrors(result), options) };
}

options.shouldUseNativeValidation && validateFieldsNatively({}, options);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -209,10 +209,10 @@
"devDependencies": {
"@sinclair/typebox": "^0.31.1",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/jest-dom": "^6.0.1",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/node": "^20.5.0",
"@types/node": "^20.5.1",
"@types/react": "^18.2.20",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
Expand Down Expand Up @@ -251,9 +251,9 @@
"vest": "^4.6.11",
"vite": "^4.4.9",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.34.1",
"vitest": "^0.34.2",
"yup": "^1.2.0",
"zod": "^3.22.1"
"zod": "^3.22.2"
},
"peerDependencies": {
"react-hook-form": "^7.0.0"
Expand Down

0 comments on commit 5f1a622

Please sign in to comment.