@@ -89,6 +89,33 @@ export const mergeObjectIntersection = (schema: TAnySchema): TAnySchema => {
8989 return newSchema
9090}
9191
92+ const isDateType = ( schema : TAnySchema ) : boolean => {
93+ if ( ! schema . anyOf || ( Kind in schema && schema [ Kind ] !== 'Union' ) )
94+ return false
95+
96+ if ( ! schema . anyOf ) return false
97+
98+ let hasDateType = false
99+ let hasStringFormatDate = false
100+ let hasNumberType = false
101+
102+ if ( schema . anyOf )
103+ for ( const type of schema . anyOf ) {
104+ if ( ! hasDateType && type . type === 'Date' ) hasDateType = true
105+
106+ if (
107+ ! hasStringFormatDate &&
108+ type . type === 'string' &&
109+ ( type . format === 'date' || type . format === 'date-time' )
110+ )
111+ hasStringFormatDate = true
112+
113+ if ( ! hasNumberType && type . type === 'number' ) hasNumberType = true
114+ }
115+
116+ return hasDateType
117+ }
118+
92119interface Instruction {
93120 array : number
94121 optional : number
@@ -128,6 +155,8 @@ const accelerate = (
128155
129156 case 'number' :
130157 case 'boolean' :
158+ case 'integer' :
159+ case 'bigint' :
131160 if ( nullableCondition ) v = `\${${ property } ??null}`
132161 else v = `\${${ property } }`
133162 break
@@ -212,7 +241,9 @@ const accelerate = (
212241
213242 if (
214243 schema . items . type === 'number' ||
215- schema . items . type === 'boolean'
244+ schema . items . type === 'boolean' ||
245+ schema . items . type === 'integer' ||
246+ schema . items . type === 'bigint'
216247 ) {
217248 if ( nullableCondition )
218249 v += `\${${ nullableCondition } ?null:${ property } .length?\`[$\{${ property } .join(',')}]\`:"[]"`
@@ -243,6 +274,16 @@ const accelerate = (
243274 break
244275
245276 default :
277+ if ( isDateType ( schema ) ) {
278+ if ( isNullable || isUndefinable )
279+ v = `\${${ nullableCondition } ?null:typeof ${ property } ==="object"?\`\"\${${ property } .toISOString()}\"\`:${ property } }`
280+ else {
281+ v = `\${typeof ${ property } ==="object"?\`\"\${${ property } .toISOString()}\"\`:${ property } }`
282+ }
283+
284+ break
285+ }
286+
246287 v = `$\{JSON.stringify(${ property } )}`
247288
248289 break
0 commit comments