diff --git a/.changeset/red-wolves-shout.md b/.changeset/red-wolves-shout.md new file mode 100644 index 00000000..14c15352 --- /dev/null +++ b/.changeset/red-wolves-shout.md @@ -0,0 +1,7 @@ +--- +"@typeschema/all": patch +"@typeschema/main": patch +"@typeschema/valibot": patch +--- + +Update to Valibot 0.31 diff --git a/README.md b/README.md index 9efae736..7e7f4f16 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,16 @@ We value flexibility, which is why there are multiple ways of using TypeSchema: @typeschema/io-ts npm downloads + + effect + GitHub stars + ✅ + ✅ + ✅ + ✅ + @typeschema/effect + npm downloads + valibot GitHub stars @@ -164,16 +174,6 @@ We value flexibility, which is why there are multiple ways of using TypeSchema: @typeschema/typebox npm downloads - - effect - GitHub stars - ✅ - ✅ - ✅ - ✅ - @typeschema/effect - npm downloads - typia GitHub stars diff --git a/packages/all/package.json b/packages/all/package.json index 5cf069c9..d8b2a4ba 100644 --- a/packages/all/package.json +++ b/packages/all/package.json @@ -117,8 +117,8 @@ "superstruct": "^1.0.4", "suretype": "^3.3.1", "@sinclair/typebox": "^0.32.20", - "@gcornut/valibot-json-schema": "^0.0.27", - "valibot": "^0.30.0", + "@gcornut/valibot-json-schema": "^0.31.0", + "valibot": "^0.31.0", "@badrap/valita": "^0.3.8", "@vinejs/vine": "^2.0.0", "@sodaru/yup-to-json-schema": "^2.0.1", diff --git a/packages/all/src/__tests__/valibot.test.ts b/packages/all/src/__tests__/valibot.test.ts index db86201e..9ae0e131 100644 --- a/packages/all/src/__tests__/valibot.test.ts +++ b/packages/all/src/__tests__/valibot.test.ts @@ -6,7 +6,7 @@ import type {Infer, InferIn} from '..'; import {initTRPC} from '@trpc/server'; import {expectTypeOf} from 'expect-type'; -import {email, number, object, string, transform} from 'valibot'; +import {email, isoTimestamp, number, object, pipe, string, transform} from 'valibot'; import {describe, expect, test} from 'vitest'; import {assert, toJSONSchema, validate, wrap} from '..'; @@ -14,11 +14,11 @@ import {assert, toJSONSchema, validate, wrap} from '..'; describe('valibot', () => { const schema = object({ age: number(), - createdAt: transform(string(), value => new Date(value)), - email: string([email()]), + createdAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))), + email: pipe(string(), email()), id: string(), name: string(), - updatedAt: transform(string(), value => new Date(value)), + updatedAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))), }); const data = { diff --git a/packages/main/package.json b/packages/main/package.json index 31994c51..80537702 100644 --- a/packages/main/package.json +++ b/packages/main/package.json @@ -112,8 +112,8 @@ "@typeschema/typebox": "workspace:*", "@sinclair/typebox": "^0.32.20", "@typeschema/valibot": "workspace:*", - "@gcornut/valibot-json-schema": "^0.0.27", - "valibot": "^0.30.0", + "@gcornut/valibot-json-schema": "^0.31.0", + "valibot": "^0.31.0", "@typeschema/valita": "workspace:*", "@badrap/valita": "^0.3.8", "@typeschema/vine": "workspace:*", diff --git a/packages/main/src/__tests__/valibot.test.ts b/packages/main/src/__tests__/valibot.test.ts index db86201e..9ae0e131 100644 --- a/packages/main/src/__tests__/valibot.test.ts +++ b/packages/main/src/__tests__/valibot.test.ts @@ -6,7 +6,7 @@ import type {Infer, InferIn} from '..'; import {initTRPC} from '@trpc/server'; import {expectTypeOf} from 'expect-type'; -import {email, number, object, string, transform} from 'valibot'; +import {email, isoTimestamp, number, object, pipe, string, transform} from 'valibot'; import {describe, expect, test} from 'vitest'; import {assert, toJSONSchema, validate, wrap} from '..'; @@ -14,11 +14,11 @@ import {assert, toJSONSchema, validate, wrap} from '..'; describe('valibot', () => { const schema = object({ age: number(), - createdAt: transform(string(), value => new Date(value)), - email: string([email()]), + createdAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))), + email: pipe(string(), email()), id: string(), name: string(), - updatedAt: transform(string(), value => new Date(value)), + updatedAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))), }); const data = { diff --git a/packages/valibot/README.md b/packages/valibot/README.md index 510a9ee6..d5db78f2 100644 --- a/packages/valibot/README.md +++ b/packages/valibot/README.md @@ -35,8 +35,8 @@ const appRouter = t.router({ Use it directly or through [`@typeschema/main`](https://github.com/decs/typeschema/tree/main/packages/main) ## Dependencies -- [`@gcornut/valibot-json-schema`](https://www.npmjs.com/package/@gcornut/valibot-json-schema): Required for serialization (`^0.0.27`) -- [`valibot`](https://www.npmjs.com/package/valibot): Required for inference and validation (`^0.30.0`) +- [`@gcornut/valibot-json-schema`](https://www.npmjs.com/package/@gcornut/valibot-json-schema): Required for serialization (`^0.31.0`) +- [`valibot`](https://www.npmjs.com/package/valibot): Required for inference and validation (`^0.31.0`) ## API diff --git a/packages/valibot/package.json b/packages/valibot/package.json index fde567c3..745d6d96 100644 --- a/packages/valibot/package.json +++ b/packages/valibot/package.json @@ -59,8 +59,8 @@ }, "//devDependencies": "This field is manually maintained.", "devDependencies": { - "@gcornut/valibot-json-schema": "^0.0.27", - "valibot": "^0.30.0" + "@gcornut/valibot-json-schema": "^0.31.0", + "valibot": "^0.31.0" }, "//peerDependencies": { "//": "This field is manually maintained.", @@ -68,8 +68,8 @@ "valibot": "Required for inference and validation" }, "peerDependencies": { - "@gcornut/valibot-json-schema": "^0.0.27", - "valibot": "^0.30.0" + "@gcornut/valibot-json-schema": "^0.31.0", + "valibot": "^0.31.0" }, "//peerDependenciesMeta": "This field is manually maintained.", "peerDependenciesMeta": { diff --git a/packages/valibot/src/__tests__/valibot.test.ts b/packages/valibot/src/__tests__/valibot.test.ts index 161863f2..1f734ea1 100644 --- a/packages/valibot/src/__tests__/valibot.test.ts +++ b/packages/valibot/src/__tests__/valibot.test.ts @@ -2,7 +2,7 @@ import type {Infer, InferIn} from '..'; import {initTRPC} from '@trpc/server'; import {expectTypeOf} from 'expect-type'; -import {email, number, object, string, transform} from 'valibot'; +import {email, isoTimestamp, number, object, pipe, string, transform} from 'valibot'; import {describe, expect, test} from 'vitest'; import {assert, toJSONSchema, validate, wrap} from '..'; @@ -10,11 +10,11 @@ import {assert, toJSONSchema, validate, wrap} from '..'; describe('valibot', () => { const schema = object({ age: number(), - createdAt: transform(string(), value => new Date(value)), - email: string([email()]), + createdAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))), + email: pipe(string(), email()), id: string(), name: string(), - updatedAt: transform(string(), value => new Date(value)), + updatedAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))), }); const data = { diff --git a/packages/valibot/src/resolver.ts b/packages/valibot/src/resolver.ts index 09395936..fd48e3c4 100644 --- a/packages/valibot/src/resolver.ts +++ b/packages/valibot/src/resolver.ts @@ -1,8 +1,8 @@ import type {IfDefined, Resolver} from '@typeschema/core'; -import type {BaseSchema, BaseSchemaAsync, Input, Output} from 'valibot'; +import type {GenericSchema, GenericSchemaAsync, InferInput, InferOutput} from 'valibot'; export interface AdapterResolver extends Resolver { - base: IfDefined; - input: this['schema'] extends this['base'] ? Input : never; - output: this['schema'] extends this['base'] ? Output : never; + base: IfDefined; + input: this['schema'] extends this['base'] ? InferInput : never; + output: this['schema'] extends this['base'] ? InferOutput : never; } diff --git a/packages/valibot/src/serialization.ts b/packages/valibot/src/serialization.ts index e7443bb6..c07f44b1 100644 --- a/packages/valibot/src/serialization.ts +++ b/packages/valibot/src/serialization.ts @@ -12,5 +12,5 @@ export const serializationAdapter: SerializationAdapter< AdapterResolver > = async schema => { const {toJSONSchema} = await importSerializationModule(); - return toJSONSchema({schema}); + return toJSONSchema({ignoreUnknownValidation: true, schema}); }; diff --git a/packages/valibot/src/validation.ts b/packages/valibot/src/validation.ts index 4ce07aaa..24b5b3ec 100644 --- a/packages/valibot/src/validation.ts +++ b/packages/valibot/src/validation.ts @@ -4,28 +4,27 @@ import type {ValidationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importValidationModule = memoize(async () => { - const {safeParseAsync} = await import('valibot'); - return {safeParseAsync}; + const {getDotPath, safeParseAsync} = await import('valibot'); + return {getDotPath, safeParseAsync}; }); export const validationAdapter: ValidationAdapter< AdapterResolver > = async schema => { - const {safeParseAsync} = await importValidationModule(); + const {getDotPath, safeParseAsync} = await importValidationModule(); return async data => { const result = await safeParseAsync(schema, data); if (result.success) { return { - data: result.output, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data: result.output as any, success: true, }; } return { - issues: result.issues.map(({message, path}) => ({ - message, - path: path?.map(({type, key}) => - type === 'map' || type === 'unknown' ? String(key) : key, - ), + issues: result.issues.map(issue => ({ + message: issue.message, + path: getDotPath(issue)?.split('.'), })), success: false, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 006242d7..0bc9633b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,8 +304,8 @@ importers: specifier: ^0.64.20 version: 0.64.20(effect@2.4.18)(fast-check@3.17.1) '@gcornut/valibot-json-schema': - specifier: ^0.0.27 - version: 0.0.27(@types/json-schema@7.0.15)(esbuild-runner@2.2.2)(esbuild@0.20.2)(valibot@0.30.0) + specifier: ^0.31.0 + version: 0.31.0 '@sinclair/typebox': specifier: ^0.32.20 version: 0.32.20 @@ -364,8 +364,8 @@ importers: specifier: ^6.0.2 version: 6.0.2(typescript@5.4.5) valibot: - specifier: ^0.30.0 - version: 0.30.0 + specifier: ^0.31.0 + version: 0.31.0 yup: specifier: ^1.4.0 version: 1.4.0 @@ -509,8 +509,8 @@ importers: specifier: ^0.64.20 version: 0.64.20(effect@2.4.18)(fast-check@3.17.1) '@gcornut/valibot-json-schema': - specifier: ^0.0.27 - version: 0.0.27(@types/json-schema@7.0.15)(esbuild-runner@2.2.2)(esbuild@0.20.2)(valibot@0.30.0) + specifier: ^0.31.0 + version: 0.31.0 '@sinclair/typebox': specifier: ^0.32.20 version: 0.32.20 @@ -626,8 +626,8 @@ importers: specifier: ^6.0.2 version: 6.0.2(typescript@5.4.5) valibot: - specifier: ^0.30.0 - version: 0.30.0 + specifier: ^0.31.0 + version: 0.31.0 yup: specifier: ^1.4.0 version: 1.4.0 @@ -695,11 +695,11 @@ importers: version: link:../core devDependencies: '@gcornut/valibot-json-schema': - specifier: ^0.0.27 - version: 0.0.27(@types/json-schema@7.0.15)(esbuild-runner@2.2.2)(esbuild@0.20.2)(valibot@0.30.0) + specifier: ^0.31.0 + version: 0.31.0 valibot: - specifier: ^0.30.0 - version: 0.30.0 + specifier: ^0.31.0 + version: 0.31.0 packages/valita: dependencies: @@ -1550,19 +1550,15 @@ packages: resolution: {integrity: sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==} dev: true - /@gcornut/valibot-json-schema@0.0.27(@types/json-schema@7.0.15)(esbuild-runner@2.2.2)(esbuild@0.20.2)(valibot@0.30.0): - resolution: {integrity: sha512-xcMaUStVgQzPrK3d7PuLFbQ+3qSp6LzaLExAm52E3FKmUfjQa7Sw5cDK6Hfu/8WT0yfGsuSCuJ5uT1sosjR9Qg==} + /@gcornut/valibot-json-schema@0.31.0: + resolution: {integrity: sha512-3xGptCurm23e7nuPQkdrE5rEs1FeTPHhAUsBuwwqG4/YeZLwJOoYZv+fmsppUEfo5y9lzUwNQrNqLS/q7HMc7g==} hasBin: true - peerDependencies: - '@types/json-schema': '>= 7.0.14' - esbuild: '>= 0.18.20' - esbuild-runner: '>= 2.2.2' - valibot: '>= 0.21.0' dependencies: + valibot: 0.31.0 + optionalDependencies: '@types/json-schema': 7.0.15 esbuild: 0.20.2 esbuild-runner: 2.2.2(esbuild@0.20.2) - valibot: 0.30.0 dev: true /@gwhitney/detect-indent@7.0.1: @@ -4867,6 +4863,7 @@ packages: /buffer-from@1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} + requiresBuild: true dev: true /buffer@5.7.1: @@ -5997,6 +5994,7 @@ packages: /esbuild-runner@2.2.2(esbuild@0.20.2): resolution: {integrity: sha512-fRFVXcmYVmSmtYm2mL8RlUASt2TDkGh3uRcvHFOKNr/T58VrfVeKD9uT9nlgxk96u0LS0ehS/GY7Da/bXWKkhw==} hasBin: true + requiresBuild: true peerDependencies: esbuild: '*' dependencies: @@ -6004,6 +6002,7 @@ packages: source-map-support: 0.5.21 tslib: 2.4.0 dev: true + optional: true /esbuild@0.19.12: resolution: {integrity: sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==} @@ -9340,6 +9339,9 @@ packages: resolution: {integrity: sha512-W+gxAq7aQ9dJIg/XLKGcRT0cvnStFAQHPaI0pvD0U2l6IVLueUAm3nwN7lkY62zZNmlvNx6jNtE4wlbS+CyqSg==} engines: {node: '>= 12.0.0'} hasBin: true + peerDependenciesMeta: + '@parcel/core': + optional: true dependencies: '@parcel/config-default': 2.12.0(@parcel/core@2.12.0)(typescript@5.4.5) '@parcel/core': 2.12.0 @@ -11216,7 +11218,9 @@ packages: /tslib@2.4.0: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} + requiresBuild: true dev: true + optional: true /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} @@ -11649,8 +11653,8 @@ packages: resolution: {integrity: sha512-k57/5/kMwMjiVP0LUMpa+n4ihSemuXshz1ND4fftKw1bkHZYN/TnHcbjaEie3K7FwAceiOgugLZPjSaNxdygeg==} dev: false - /valibot@0.30.0: - resolution: {integrity: sha512-5POBdbSkM+3nvJ6ZlyQHsggisfRtyT4tVTo1EIIShs6qCdXJnyWU5TJ68vr8iTg5zpOLjXLRiBqNx+9zwZz/rA==} + /valibot@0.31.0: + resolution: {integrity: sha512-bleS8aVFpRGTUgbMoXzsRJhpxJGiZ3MG1nuNSORuDvio+sI1EyT1+lQHg+77Pfnlxz+25Uj5HiwdaklcDcYdiQ==} dev: true /validate-npm-package-license@3.0.4: