@@ -17,30 +17,33 @@ import {
1717 type SetPathItem
1818} from 'valibot' ;
1919import { 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' ;
2421import type { JSONSchema } from '../jsonSchema/index.js' ;
2522
2623type 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
4649async function _validate < T extends SupportedSchemas > (
@@ -66,7 +69,7 @@ async function _validate<T extends SupportedSchemas>(
6669
6770function _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
8386function _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