diff --git a/packages/resolvers/package.json b/packages/resolvers/package.json index 960c279..a09db3c 100644 --- a/packages/resolvers/package.json +++ b/packages/resolvers/package.json @@ -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" } } diff --git a/packages/resolvers/valibot/src/types.ts b/packages/resolvers/valibot/src/types.ts index 080f959..1283845 100644 --- a/packages/resolvers/valibot/src/types.ts +++ b/packages/resolvers/valibot/src/types.ts @@ -1,8 +1,8 @@ -import { ObjectSchema } from 'valibot'; +import { BaseSchema, BaseSchemaAsync } from 'valibot'; import type { FormErrors, FormValues } from '@vorms/core'; -export type Resolver = >( +export type Resolver = ( schema: T, ) => ( values: Values, diff --git a/packages/resolvers/valibot/src/valibot.ts b/packages/resolvers/valibot/src/valibot.ts index 7103fe4..4ba7771 100644 --- a/packages/resolvers/valibot/src/valibot.ts +++ b/packages/resolvers/valibot/src/valibot.ts @@ -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 = {}; while (valibotIssues.length) { @@ -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; } }; diff --git a/packages/resolvers/yup/src/types.ts b/packages/resolvers/yup/src/types.ts index 742bbd7..0521c1b 100644 --- a/packages/resolvers/yup/src/types.ts +++ b/packages/resolvers/yup/src/types.ts @@ -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 = >( schema: T, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e351520..b2b9953 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -123,11 +123,11 @@ importers: specifier: workspace:* version: link:../core valibot: - specifier: ^0.11.0 - version: 0.11.0 + specifier: ^0.28.1 + version: 0.28.1 yup: - specifier: ^0.32.11 - version: 0.32.11 + specifier: ^1.3.3 + version: 1.3.3 zod: specifier: ^3.20.2 version: 3.20.2 @@ -358,6 +358,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: regenerator-runtime: 0.13.11 + dev: false /@babel/types@7.21.2: resolution: {integrity: sha512-3wRZSs7jiFaB8AjxiiD+VqN5DTG2iRvJGQ+qYFrs/654lg6kGTQWIOFjlBo5RaXuAZjBmP3+OQH4dmhqiiyYxw==} @@ -1105,6 +1106,7 @@ packages: /@types/lodash@4.14.191: resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==} + dev: false /@types/node@18.16.18: resolution: {integrity: sha512-/aNaQZD0+iSBAGnvvN2Cx92HqE5sZCPZtx2TsK+4nvV23fFe09jVDvpArXr2j9DnYlzuU9WuoykDDc6wqvpNcw==} @@ -3382,6 +3384,7 @@ packages: /lodash-es@4.17.21: resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} + dev: false /lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} @@ -3564,6 +3567,7 @@ packages: /nanoclone@0.2.1: resolution: {integrity: sha512-wynEP02LmIbLpcYw8uBKpcfF6dmg2vcpKqxeH5UcoKEYdExslsdUA4ugFauuaeYdTB76ez6gJW8XAZ6CgkXYxA==} + dev: false /nanoid@3.3.4: resolution: {integrity: sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==} @@ -3890,6 +3894,7 @@ packages: /regenerator-runtime@0.13.11: resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==} + dev: false /regexp.prototype.flags@1.4.3: resolution: {integrity: sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==} @@ -4312,6 +4317,10 @@ packages: engines: {node: '>=4'} dev: true + /tiny-case@1.0.3: + resolution: {integrity: sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==} + dev: true + /tinybench@2.5.0: resolution: {integrity: sha512-kRwSG8Zx4tjF9ZiyH4bhaebu+EDz1BOx9hOigYHlUW4xxI/wKIUQUqo018UlU4ar6ATPBsaMrdbKZ+tmPdohFA==} dev: true @@ -4417,6 +4426,11 @@ packages: engines: {node: '>=10'} dev: true + /type-fest@2.19.0: + resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==} + engines: {node: '>=12.20'} + dev: true + /typed-array-length@1.0.4: resolution: {integrity: sha512-KjZypGq+I/H7HI5HlOoGHkWUUGq+Q0TPhQurLbyrVrvnKTBgzLhIJ7j6J/XTQOi0d1RjyZ0wdas8bKs2p0x3Ng==} dependencies: @@ -4484,6 +4498,11 @@ packages: /valibot@0.11.0: resolution: {integrity: sha512-qF54ZhrrME9jsicNOw16G7+4JIM2hoT5lyybCJqK7AyvU7/q7/kkmf6xaPc+GigF+GAO66ZWB12ZbFV5RyiQIA==} + dev: false + + /valibot@0.28.1: + resolution: {integrity: sha512-zQnjwNJuXk6362Leu0+4eFa/SMwRom3/hEvH6s1EGf3oXIPbo2WFKDra9ymnbVh3clLRvd8hw4sKF5ruI2Lyvw==} + dev: true /vite-node@0.32.2(@types/node@18.16.18): resolution: {integrity: sha512-dTQ1DCLwl2aEseov7cfQ+kDMNJpM1ebpyMMMwWzBvLbis8Nla/6c9WQcqpPssTwS6Rp/+U6KwlIj8Eapw4bLdA==} @@ -4933,6 +4952,16 @@ packages: nanoclone: 0.2.1 property-expr: 2.0.5 toposort: 2.0.2 + dev: false + + /yup@1.3.3: + resolution: {integrity: sha512-v8QwZSsHH2K3/G9WSkp6mZKO+hugKT1EmnMqLNUcfu51HU9MDyhlETT/JgtzprnrnQHPWsjc6MUDMBp/l9fNnw==} + dependencies: + property-expr: 2.0.5 + tiny-case: 1.0.3 + toposort: 2.0.2 + type-fest: 2.19.0 + dev: true /zod@3.20.2: resolution: {integrity: sha512-1MzNQdAvO+54H+EaK5YpyEy0T+Ejo/7YLHS93G3RnYWh5gaotGHwGeN/ZO687qEDU2y4CdStQYXVHIgrUl5UVQ==}