Skip to content

Commit c2a51f6

Browse files
committed
Migrated Valibot adapter to use its own JSON Schema.
1 parent 6e32a35 commit c2a51f6

File tree

4 files changed

+43
-92
lines changed

4 files changed

+43
-92
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Migrated Valibot adapter to use the official `@valibot/to-json-schema` package. [#668](https://github.com/ciscoheat/sveltekit-superforms/pull/668)
13+
814
## [2.28.1] - 2025-10-19
915

1016
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
"optionalDependencies": {
171171
"@exodus/schemasafe": "^1.3.0",
172172
"@finom/zod-to-json-schema": "^3.24.11",
173-
"@gcornut/valibot-json-schema": "^0.42.0",
173+
"@valibot/to-json-schema": "^1.0.0",
174174
"@typeschema/class-validator": "^0.3.0",
175175
"@vinejs/vine": "^3.0.1",
176176
"arktype": "^2.1.22",

pnpm-lock.yaml

Lines changed: 14 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/adapters/valibot.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,33 @@ import {
1717
type SetPathItem
1818
} from 'valibot';
1919
import { memoize } from '$lib/memoize.js';
20-
import {
21-
type ToJSONSchemaOptions,
22-
toJSONSchema as valibotToJSON
23-
} from '@gcornut/valibot-json-schema';
20+
import { type ConversionConfig, toJsonSchema } from '@valibot/to-json-schema';
2421
import type { JSONSchema } from '../jsonSchema/index.js';
2522

2623
type SupportedSchemas = GenericSchema | GenericSchemaAsync;
2724

28-
const defaultOptions = {
29-
strictObjectTypes: true,
30-
dateStrategy: 'integer' as const,
31-
bigintStrategy: 'integer' as const,
32-
ignoreUnknownValidation: true,
33-
customSchemaConversion: {
34-
custom: () => ({}),
35-
instance: () => ({}),
36-
file: () => ({}),
37-
blob: () => ({})
25+
const defaultOptions: ConversionConfig = {
26+
ignoreActions: ['transform', 'mime_type', 'max_size', 'min_size', 'starts_with'],
27+
overrideSchema: (context) => {
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
const type = (context.valibotSchema as any).type;
30+
if (type === 'date') {
31+
return { type: 'integer', format: 'unix-time' };
32+
}
33+
if (type === 'bigint') {
34+
return { type: 'string', format: 'bigint' };
35+
}
36+
if (type === 'file' || type === 'blob' || type === 'instance' || type === 'custom') {
37+
return {};
38+
}
3839
}
39-
} satisfies ToJSONSchemaOptions;
40+
};
4041

4142
/* @__NO_SIDE_EFFECTS__ */
42-
export const valibotToJSONSchema = (options: ToJSONSchemaOptions) => {
43-
return valibotToJSON({ ...defaultOptions, ...options }) as JSONSchema;
43+
export const valibotToJSONSchema = (options: ConversionConfig & { schema: SupportedSchemas }) => {
44+
const { schema, ...rest } = options;
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46+
return toJsonSchema(schema as any, { ...defaultOptions, ...rest }) as JSONSchema;
4447
};
4548

4649
async function _validate<T extends SupportedSchemas>(
@@ -66,7 +69,7 @@ async function _validate<T extends SupportedSchemas>(
6669

6770
function _valibot<T extends SupportedSchemas>(
6871
schema: T,
69-
options: Omit<ToJSONSchemaOptions, 'schema'> &
72+
options: Omit<ConversionConfig, 'schema'> &
7073
AdapterOptions<Infer<T, 'valibot'>> & {
7174
config?: Config<GenericIssue<unknown>>;
7275
} = {}
@@ -82,7 +85,7 @@ function _valibot<T extends SupportedSchemas>(
8285

8386
function _valibotClient<T extends SupportedSchemas>(
8487
schema: T,
85-
options: Omit<ToJSONSchemaOptions, 'schema'> &
88+
options: Omit<ConversionConfig, 'schema'> &
8689
AdapterOptions<Infer<T, 'valibot'>> & {
8790
config?: Config<GenericIssue<unknown>>;
8891
} = {}

0 commit comments

Comments
 (0)