Skip to content

Commit

Permalink
Merge pull request #58 from matt45400/main
Browse files Browse the repository at this point in the history
Update to Valibot 0.31
  • Loading branch information
decs authored Jun 17, 2024
2 parents e607f9c + ac97adb commit 2051106
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 68 deletions.
7 changes: 7 additions & 0 deletions .changeset/red-wolves-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@typeschema/all": patch
"@typeschema/main": patch
"@typeschema/valibot": patch
---

Update to Valibot 0.31
20 changes: 10 additions & 10 deletions README.md

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

4 changes: 2 additions & 2 deletions packages/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/all/src/__tests__/valibot.test.ts

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

4 changes: 2 additions & 2 deletions packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/__tests__/valibot.test.ts

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

4 changes: 2 additions & 2 deletions packages/valibot/README.md

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

8 changes: 4 additions & 4 deletions packages/valibot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@
},
"//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.",
"@gcornut/valibot-json-schema": "Required for serialization",
"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": {
Expand Down
8 changes: 4 additions & 4 deletions packages/valibot/src/__tests__/valibot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ 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 '..';

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 = {
Expand Down
8 changes: 4 additions & 4 deletions packages/valibot/src/resolver.ts
Original file line number Diff line number Diff line change
@@ -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<BaseSchema | BaseSchemaAsync, 'valibot'>;
input: this['schema'] extends this['base'] ? Input<this['schema']> : never;
output: this['schema'] extends this['base'] ? Output<this['schema']> : never;
base: IfDefined<GenericSchema | GenericSchemaAsync, 'valibot'>;
input: this['schema'] extends this['base'] ? InferInput<this['schema']> : never;
output: this['schema'] extends this['base'] ? InferOutput<this['schema']> : never;
}
2 changes: 1 addition & 1 deletion packages/valibot/src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const serializationAdapter: SerializationAdapter<
AdapterResolver
> = async schema => {
const {toJSONSchema} = await importSerializationModule();
return toJSONSchema({schema});
return toJSONSchema({ignoreUnknownValidation: true, schema});
};
17 changes: 8 additions & 9 deletions packages/valibot/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
48 changes: 26 additions & 22 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 2051106

Please sign in to comment.