Skip to content

Commit 2051106

Browse files
authored
Merge pull request #58 from matt45400/main
Update to Valibot 0.31
2 parents e607f9c + ac97adb commit 2051106

File tree

13 files changed

+78
-68
lines changed

13 files changed

+78
-68
lines changed

.changeset/red-wolves-shout.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@typeschema/all": patch
3+
"@typeschema/main": patch
4+
"@typeschema/valibot": patch
5+
---
6+
7+
Update to Valibot 0.31

README.md

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/all/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
"superstruct": "^1.0.4",
118118
"suretype": "^3.3.1",
119119
"@sinclair/typebox": "^0.32.20",
120-
"@gcornut/valibot-json-schema": "^0.0.27",
121-
"valibot": "^0.30.0",
120+
"@gcornut/valibot-json-schema": "^0.31.0",
121+
"valibot": "^0.31.0",
122122
"@badrap/valita": "^0.3.8",
123123
"@vinejs/vine": "^2.0.0",
124124
"@sodaru/yup-to-json-schema": "^2.0.1",

packages/all/src/__tests__/valibot.test.ts

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/main/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
"@typeschema/typebox": "workspace:*",
113113
"@sinclair/typebox": "^0.32.20",
114114
"@typeschema/valibot": "workspace:*",
115-
"@gcornut/valibot-json-schema": "^0.0.27",
116-
"valibot": "^0.30.0",
115+
"@gcornut/valibot-json-schema": "^0.31.0",
116+
"valibot": "^0.31.0",
117117
"@typeschema/valita": "workspace:*",
118118
"@badrap/valita": "^0.3.8",
119119
"@typeschema/vine": "workspace:*",

packages/main/src/__tests__/valibot.test.ts

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/valibot/README.md

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/valibot/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@
5959
},
6060
"//devDependencies": "This field is manually maintained.",
6161
"devDependencies": {
62-
"@gcornut/valibot-json-schema": "^0.0.27",
63-
"valibot": "^0.30.0"
62+
"@gcornut/valibot-json-schema": "^0.31.0",
63+
"valibot": "^0.31.0"
6464
},
6565
"//peerDependencies": {
6666
"//": "This field is manually maintained.",
6767
"@gcornut/valibot-json-schema": "Required for serialization",
6868
"valibot": "Required for inference and validation"
6969
},
7070
"peerDependencies": {
71-
"@gcornut/valibot-json-schema": "^0.0.27",
72-
"valibot": "^0.30.0"
71+
"@gcornut/valibot-json-schema": "^0.31.0",
72+
"valibot": "^0.31.0"
7373
},
7474
"//peerDependenciesMeta": "This field is manually maintained.",
7575
"peerDependenciesMeta": {

packages/valibot/src/__tests__/valibot.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import type {Infer, InferIn} from '..';
22

33
import {initTRPC} from '@trpc/server';
44
import {expectTypeOf} from 'expect-type';
5-
import {email, number, object, string, transform} from 'valibot';
5+
import {email, isoTimestamp, number, object, pipe, string, transform} from 'valibot';
66
import {describe, expect, test} from 'vitest';
77

88
import {assert, toJSONSchema, validate, wrap} from '..';
99

1010
describe('valibot', () => {
1111
const schema = object({
1212
age: number(),
13-
createdAt: transform(string(), value => new Date(value)),
14-
email: string([email()]),
13+
createdAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))),
14+
email: pipe(string(), email()),
1515
id: string(),
1616
name: string(),
17-
updatedAt: transform(string(), value => new Date(value)),
17+
updatedAt: pipe(string(), isoTimestamp(), transform((input) => new Date(input))),
1818
});
1919

2020
const data = {

packages/valibot/src/resolver.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {IfDefined, Resolver} from '@typeschema/core';
2-
import type {BaseSchema, BaseSchemaAsync, Input, Output} from 'valibot';
2+
import type {GenericSchema, GenericSchemaAsync, InferInput, InferOutput} from 'valibot';
33

44
export interface AdapterResolver extends Resolver {
5-
base: IfDefined<BaseSchema | BaseSchemaAsync, 'valibot'>;
6-
input: this['schema'] extends this['base'] ? Input<this['schema']> : never;
7-
output: this['schema'] extends this['base'] ? Output<this['schema']> : never;
5+
base: IfDefined<GenericSchema | GenericSchemaAsync, 'valibot'>;
6+
input: this['schema'] extends this['base'] ? InferInput<this['schema']> : never;
7+
output: this['schema'] extends this['base'] ? InferOutput<this['schema']> : never;
88
}

packages/valibot/src/serialization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export const serializationAdapter: SerializationAdapter<
1212
AdapterResolver
1313
> = async schema => {
1414
const {toJSONSchema} = await importSerializationModule();
15-
return toJSONSchema({schema});
15+
return toJSONSchema({ignoreUnknownValidation: true, schema});
1616
};

packages/valibot/src/validation.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@ import type {ValidationAdapter} from '@typeschema/core';
44
import {memoize} from '@typeschema/core';
55

66
const importValidationModule = memoize(async () => {
7-
const {safeParseAsync} = await import('valibot');
8-
return {safeParseAsync};
7+
const {getDotPath, safeParseAsync} = await import('valibot');
8+
return {getDotPath, safeParseAsync};
99
});
1010

1111
export const validationAdapter: ValidationAdapter<
1212
AdapterResolver
1313
> = async schema => {
14-
const {safeParseAsync} = await importValidationModule();
14+
const {getDotPath, safeParseAsync} = await importValidationModule();
1515
return async data => {
1616
const result = await safeParseAsync(schema, data);
1717
if (result.success) {
1818
return {
19-
data: result.output,
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
data: result.output as any,
2021
success: true,
2122
};
2223
}
2324
return {
24-
issues: result.issues.map(({message, path}) => ({
25-
message,
26-
path: path?.map(({type, key}) =>
27-
type === 'map' || type === 'unknown' ? String(key) : key,
28-
),
25+
issues: result.issues.map(issue => ({
26+
message: issue.message,
27+
path: getDotPath(issue)?.split('.'),
2928
})),
3029
success: false,
3130
};

pnpm-lock.yaml

+26-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)