@@ -15,9 +15,12 @@ import {
1515 toJSONSchema as valibotToJSON
1616} from '@gcornut/valibot-json-schema' ;
1717import type { JSONSchema } from '../jsonSchema/index.js' ;
18+ import type { Prettify } from '$lib/utils.js' ;
1819
1920type SupportedSchemas = BaseSchema | BaseSchemaAsync ;
2021
22+ type SchemaConfig = NonNullable < Parameters < typeof safeParseAsync > [ 2 ] > ;
23+
2124const defaultOptions = {
2225 strictObjectTypes : true ,
2326 dateStrategy : 'integer' as const ,
@@ -32,9 +35,10 @@ export const valibotToJSONSchema = (options: ToJSONSchemaOptions) => {
3235
3336async function validate < T extends SupportedSchemas > (
3437 schema : T ,
35- data : unknown
38+ data : unknown ,
39+ config ?: SchemaConfig
3640) : Promise < ValidationResult < Infer < T > > > {
37- const result = await safeParseAsync ( schema , data ) ;
41+ const result = await safeParseAsync ( schema , data , config ) ;
3842 if ( result . success ) {
3943 return {
4044 data : result . output as Infer < T > ,
@@ -52,11 +56,16 @@ async function validate<T extends SupportedSchemas>(
5256
5357function _valibot < T extends SupportedSchemas > (
5458 schema : T ,
55- options : Omit < ToJSONSchemaOptions , 'schema' > | AdapterOptions < T > = { }
59+ options : Prettify <
60+ Omit < ToJSONSchemaOptions , 'schema' > &
61+ AdapterOptions < T > & {
62+ config ?: SchemaConfig ;
63+ }
64+ > = { }
5665) : ValidationAdapter < Infer < T > , InferIn < T > > {
5766 return createAdapter ( {
5867 superFormValidationLibrary : 'valibot' ,
59- validate : async ( data ) => validate ( schema , data ) ,
68+ validate : async ( data ) => validate ( schema , data , options ?. config ) ,
6069 jsonSchema : createJsonSchema (
6170 options ,
6271 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments