Skip to content

Commit

Permalink
chore: upgrade valibot version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini-ghost committed Feb 17, 2024
1 parent 82e6958 commit cda204b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
],
"devDependencies": {
"@vorms/core": "workspace:*",
"valibot": "^0.11.0",
"valibot": "^0.28.1",
"yup": "^0.32.11",
"zod": "^3.20.2"
}
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;
}
};
9 changes: 7 additions & 2 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 cda204b

Please sign in to comment.