Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for root errors for field array #621

Merged
merged 4 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading
Loading