@@ -103,25 +103,27 @@ function computeValuesBasedOnCollectionSchema(collection: CollectionInfo, data:
103
103
104
104
sortedKeys . forEach ( ( key ) => {
105
105
const value = ( properties ) [ key ]
106
- // const underlyingType = getUnderlyingType(value as ZodType<unknown, ZodOptionalDef>)
107
- const underlyingType = ( value as JsonSchema7ObjectType ) . type
108
-
106
+ const type = collection . fields [ key ]
109
107
const defaultValue = value . default !== undefined ? value . default : 'NULL'
110
108
const valueToInsert = typeof data [ key ] !== 'undefined' ? data [ key ] : defaultValue
111
109
112
110
fields . push ( key )
113
- if ( collection . fields [ key ] === 'json' ) {
111
+
112
+ if ( type === 'json' ) {
114
113
values . push ( `'${ JSON . stringify ( valueToInsert ) . replace ( / ' / g, '\'\'' ) } '` )
115
114
}
116
- else if ( [ 'string' , 'enum' ] . includes ( underlyingType ) ) {
117
- values . push ( `'${ String ( valueToInsert ) . replace ( / \n / g, '\\n' ) . replace ( / ' / g, '\'\'' ) } '` )
115
+ else if ( type === 'string' ) {
116
+ // @ts -expect-error format does exist
117
+ if ( [ 'data' , 'datetime' ] . includes ( value . format ) ) {
118
+ values . push ( valueToInsert !== 'NULL' ? `'${ new Date ( valueToInsert ) . toISOString ( ) } '` : defaultValue )
119
+ }
120
+ else {
121
+ values . push ( `'${ String ( valueToInsert ) . replace ( / \n / g, '\\n' ) . replace ( / ' / g, '\'\'' ) } '` )
122
+ }
123
+ }
124
+ else if ( type === 'boolean' ) {
125
+ values . push ( valueToInsert !== 'NULL' ? ! ! valueToInsert : valueToInsert )
118
126
}
119
- // else if (['Date'].includes(underlyingType)) {
120
- // values.push(valueToInsert !== 'NULL' ? `'${new Date(valueToInsert as string).toISOString()}'` : defaultValue)
121
- // }
122
- // else if (underlyingType.constructor.name === 'ZodBoolean') {
123
- // values.push(valueToInsert !== 'NULL' ? !!valueToInsert : valueToInsert)
124
- // }
125
127
else {
126
128
values . push ( valueToInsert )
127
129
}
0 commit comments