@@ -167,6 +167,7 @@ interface Instruction {
167167 * @default 'sanitize'
168168 **/
169169 sanitize : 'auto' | 'manual' | 'throw'
170+ definitions : Record < string , TAnySchema >
170171}
171172
172173const SANITIZE = {
@@ -225,6 +226,16 @@ const accelerate = (
225226) : string => {
226227 if ( ! schema ) return ''
227228
229+ if (
230+ Kind in schema &&
231+ schema [ Kind ] === 'Import' &&
232+ schema . $ref in schema . $defs
233+ )
234+ return accelerate ( schema . $defs [ schema . $ref ] , property , {
235+ ...instruction ,
236+ definitions : Object . assign ( instruction . definitions , schema . $defs )
237+ } )
238+
228239 let v = ''
229240 const isRoot = property === 'v'
230241
@@ -376,14 +387,14 @@ const accelerate = (
376387 instruction . array ++
377388
378389 if ( schema . items . type === 'string' ) {
379- if ( isRoot ) v += 'return `'
390+ if ( isRoot ) v += 'return `'
380391
381392 if ( nullableCondition )
382393 v += `\${${ nullableCondition } ?"null":${ property } .length?\`[${ joinStringArray ( property ) } ]\`:"[]"}`
383394 else
384395 v += `\${${ property } .length?\`[${ joinStringArray ( property ) } ]\`:"[]"}`
385396
386- if ( isRoot ) v += '`'
397+ if ( isRoot ) v += '`'
387398
388399 break
389400 }
@@ -394,14 +405,14 @@ const accelerate = (
394405 schema . items . type === 'bigint' ||
395406 isInteger ( schema . items )
396407 ) {
397- if ( isRoot ) v += 'return `'
408+ if ( isRoot ) v += 'return `'
398409
399410 if ( nullableCondition )
400411 v += `\${${ nullableCondition } ?'"null"':${ property } .length?\`[$\{${ property } .toString()}]\`:"[]"`
401412 else
402413 v += `\${${ property } .length?\`[$\{${ property } .toString()}]\`:"[]"}`
403414
404- if ( isRoot ) v += '`'
415+ if ( isRoot ) v += '`'
405416
406417 break
407418 }
@@ -427,6 +438,13 @@ const accelerate = (
427438 break
428439
429440 default :
441+ if ( schema . $ref && schema . $ref in instruction . definitions )
442+ return accelerate (
443+ instruction . definitions [ schema . $ref ] ,
444+ property ,
445+ instruction
446+ )
447+
430448 if ( isDateType ( schema ) ) {
431449 if ( isNullable || isUndefinable )
432450 v = `\${${ nullableCondition } ?${ schema . default !== undefined ? `'"${ schema . default } "'` : "'null'" } :typeof ${ property } ==="object"?\`\"\${${ property } .toISOString()}\"\`:${ property } }`
@@ -490,17 +508,17 @@ const accelerate = (
490508export const createAccelerator = < T extends TAnySchema > (
491509 schema : T ,
492510 {
493- sanitize = 'auto'
494- } : {
495- sanitize ?: Instruction [ 'sanitize' ]
496- } = { }
511+ sanitize = 'auto' ,
512+ definitions = { }
513+ } : Partial < Pick < Instruction , 'sanitize' | 'definitions' > > = { }
497514) : ( ( v : T [ 'static' ] ) => string ) => {
498515 const f = accelerate ( schema , 'v' , {
499516 array : 0 ,
500517 optional : 0 ,
501518 properties : [ ] ,
502519 hasString : false ,
503- sanitize
520+ sanitize,
521+ definitions
504522 } )
505523
506524 return Function ( 'v' , f ) as any
0 commit comments