@@ -5,16 +5,17 @@ import {
55 type ClientValidationAdapter ,
66 type ValidationAdapter
77} from './adapters.js' ;
8- import {
9- validator ,
10- type Json ,
11- type Schema ,
12- type Validate ,
13- type ValidatorOptions
14- } from '@exodus/schemasafe' ;
8+ import type { Json , Schema , Validate , ValidatorOptions } from '@exodus/schemasafe' ;
159import type { FromSchema , JSONSchema } from 'json-schema-to-ts' ;
1610import type { JSONSchema as JSONSchema7 } from '$lib/jsonSchema/index.js' ;
1711
12+ async function modules ( ) {
13+ const { validator } = await import ( /* webpackIgnore: true */ '@exodus/schemasafe' ) ;
14+ return { validator } ;
15+ }
16+
17+ const fetchModule = /* @__PURE__ */ memoize ( modules ) ;
18+
1819/*
1920 * Adapter specificts:
2021 * Type inference problem unless this is applied:
@@ -33,7 +34,9 @@ const defaultOptions = {
3334 allErrors : true
3435} ;
3536
36- function cachedValidator ( currentSchema : JSONSchema7 , config ?: ValidatorOptions ) {
37+ async function cachedValidator ( currentSchema : JSONSchema7 , config ?: ValidatorOptions ) {
38+ const { validator } = await fetchModule ( ) ;
39+
3740 if ( ! cache . has ( currentSchema ) ) {
3841 cache . set (
3942 currentSchema ,
@@ -60,7 +63,7 @@ function _schemasafe<
6063 jsonSchema : schema as JSONSchema7 ,
6164 defaults : options ?. defaults ,
6265 async validate ( data : unknown ) {
63- const validator = cachedValidator ( schema as JSONSchema7 , options ?. config ) ;
66+ const validator = await cachedValidator ( schema as JSONSchema7 , options ?. config ) ;
6467 const isValid = validator ( data as Json ) ;
6568
6669 if ( isValid ) {
@@ -91,7 +94,7 @@ function _schemasafeClient<
9194 return {
9295 superFormValidationLibrary : 'schemasafe' ,
9396 async validate ( data : unknown ) {
94- const validator = cachedValidator ( schema as JSONSchema7 , options ?. config ) ;
97+ const validator = await cachedValidator ( schema as JSONSchema7 , options ?. config ) ;
9598 const isValid = validator ( data as Json ) ;
9699
97100 if ( isValid ) {
0 commit comments