Skip to content

Commit

Permalink
Merge branch 'main' into feat/support-validate-field
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini-ghost committed Feb 18, 2024
2 parents 8c93673 + fdb8d94 commit 10732bb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
],
"devDependencies": {
"@vorms/core": "workspace:*",
"valibot": "^0.11.0",
"yup": "^0.32.11",
"valibot": "^0.28.1",
"yup": "^1.3.3",
"zod": "^3.20.2"
}
}
4 changes: 2 additions & 2 deletions packages/resolvers/valibot/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ObjectSchema } from 'valibot';
import { BaseSchema, BaseSchemaAsync } from 'valibot';

import type { FormErrors, FormValues } from '@vorms/core';

export type Resolver = <T extends ObjectSchema<any, any>>(
export type Resolver = <T extends BaseSchema | BaseSchemaAsync>(
schema: T,
) => <Values extends FormValues = FormValues>(
values: Values,
Expand Down
17 changes: 10 additions & 7 deletions packages/resolvers/valibot/src/valibot.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { toNestError } from '@vorms/resolvers';
import { parseAsync } from 'valibot';
import { parseAsync, ValiError } from 'valibot';

import type { Resolver } from './types';
import type { Issues } from 'valibot';
import type { SchemaIssues } from 'valibot';

const parseErrorSchema = (valibotIssues: Issues) => {
const parseErrorSchema = (valibotIssues: SchemaIssues) => {
const errors: Record<string, string> = {};

while (valibotIssues.length) {
Expand All @@ -29,9 +29,12 @@ export const valibotResolver: Resolver = (schema) => async (values) => {
await parseAsync(schema, values);
return {};
} catch (error: any) {
if (error.name !== 'ValiError') throw error;
return error.issues.length
? toNestError(parseErrorSchema(error.issues))
: {};
if (error instanceof ValiError) {
return error.issues.length
? toNestError(parseErrorSchema(error.issues))
: {};
}

throw error;
}
};
2 changes: 1 addition & 1 deletion packages/resolvers/yup/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Yup from 'yup';

import type { FormErrors, FormValues } from '@vorms/core';
import type Lazy from 'yup/lib/Lazy';
import type { Lazy } from 'yup';

export type Resolver = <T extends Yup.AnyObjectSchema | Lazy<any>>(
schema: T,
Expand Down
37 changes: 33 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10732bb

Please sign in to comment.