@@ -64,24 +64,24 @@ export type ValueDefinitionBase = z.infer<typeof ValueDefinitionBaseSchema>;
64
64
export const StringValueDefinitionBaseSchema = ValueDefinitionBaseSchema . extend (
65
65
{
66
66
valueType : z . literal ( ValueTypeSchema . Enum . string ) ,
67
- defaultValue : z . string ( ) . optional ( ) ,
67
+ defaultValue : z . string ( ) . nullable ( ) ,
68
68
}
69
69
) ;
70
70
71
71
export const textValueDefinitionSchema = StringValueDefinitionBaseSchema . extend (
72
72
{
73
73
inputType : z . literal ( ValueInputTypeSchema . Enum . text ) ,
74
- min : z . number ( ) . optional ( ) ,
75
- max : z . number ( ) . optional ( ) ,
74
+ min : z . number ( ) . nullable ( ) ,
75
+ max : z . number ( ) . nullable ( ) ,
76
76
}
77
77
) ;
78
78
export type TextValueDefinition = z . infer < typeof textValueDefinitionSchema > ;
79
79
80
80
export const textareaValueDefinitionSchema =
81
81
StringValueDefinitionBaseSchema . extend ( {
82
82
inputType : z . literal ( ValueInputTypeSchema . Enum . textarea ) ,
83
- min : z . number ( ) . optional ( ) ,
84
- max : z . number ( ) . optional ( ) ,
83
+ min : z . number ( ) . nullable ( ) ,
84
+ max : z . number ( ) . nullable ( ) ,
85
85
} ) ;
86
86
export type TextareaValueDefinition = z . infer <
87
87
typeof textareaValueDefinitionSchema
@@ -90,7 +90,7 @@ export type TextareaValueDefinition = z.infer<
90
90
export const emailValueDefinitionSchema =
91
91
StringValueDefinitionBaseSchema . extend ( {
92
92
inputType : z . literal ( ValueInputTypeSchema . Enum . email ) ,
93
- defaultValue : z . string ( ) . email ( ) . optional ( ) ,
93
+ defaultValue : z . string ( ) . email ( ) . nullable ( ) ,
94
94
} ) ;
95
95
export type EmailValueDefinition = z . infer < typeof emailValueDefinitionSchema > ;
96
96
@@ -102,36 +102,36 @@ export type EmailValueDefinition = z.infer<typeof emailValueDefinitionSchema>;
102
102
103
103
export const urlValueDefinitionSchema = StringValueDefinitionBaseSchema . extend ( {
104
104
inputType : z . literal ( ValueInputTypeSchema . Enum . url ) ,
105
- defaultValue : z . string ( ) . url ( ) . optional ( ) ,
105
+ defaultValue : z . string ( ) . url ( ) . nullable ( ) ,
106
106
} ) ;
107
107
export type UrlValueDefinition = z . infer < typeof urlValueDefinitionSchema > ;
108
108
109
109
export const ipValueDefinitionSchema = StringValueDefinitionBaseSchema . extend ( {
110
110
inputType : z . literal ( ValueInputTypeSchema . Enum . ip ) ,
111
- defaultValue : z . string ( ) . ip ( ) . optional ( ) ,
111
+ defaultValue : z . string ( ) . ip ( ) . nullable ( ) ,
112
112
} ) ;
113
113
export type IpValueDefinition = z . infer < typeof ipValueDefinitionSchema > ;
114
114
115
115
export const dateValueDefinitionSchema = StringValueDefinitionBaseSchema . extend (
116
116
{
117
117
inputType : z . literal ( ValueInputTypeSchema . Enum . date ) ,
118
- defaultValue : z . string ( ) . date ( ) . optional ( ) ,
118
+ defaultValue : z . string ( ) . date ( ) . nullable ( ) ,
119
119
}
120
120
) ;
121
121
export type DateValueDefinition = z . infer < typeof dateValueDefinitionSchema > ;
122
122
123
123
export const timeValueDefinitionSchema = StringValueDefinitionBaseSchema . extend (
124
124
{
125
125
inputType : z . literal ( ValueInputTypeSchema . Enum . time ) ,
126
- defaultValue : z . string ( ) . time ( ) . optional ( ) ,
126
+ defaultValue : z . string ( ) . time ( ) . nullable ( ) ,
127
127
}
128
128
) ;
129
129
export type TimeValueDefinition = z . infer < typeof timeValueDefinitionSchema > ;
130
130
131
131
export const datetimeValueDefinitionSchema =
132
132
StringValueDefinitionBaseSchema . extend ( {
133
133
inputType : z . literal ( ValueInputTypeSchema . Enum . datetime ) ,
134
- defaultValue : z . string ( ) . datetime ( ) . optional ( ) ,
134
+ defaultValue : z . string ( ) . datetime ( ) . nullable ( ) ,
135
135
} ) ;
136
136
export type DatetimeValueDefinition = z . infer <
137
137
typeof datetimeValueDefinitionSchema
@@ -166,10 +166,10 @@ export type StringValueDefinition = z.infer<typeof stringValueDefinitionSchema>;
166
166
export const NumberValueDefinitionBaseSchema = ValueDefinitionBaseSchema . extend (
167
167
{
168
168
valueType : z . literal ( ValueTypeSchema . Enum . number ) ,
169
- min : z . number ( ) . optional ( ) ,
170
- max : z . number ( ) . optional ( ) ,
169
+ min : z . number ( ) . nullable ( ) ,
170
+ max : z . number ( ) . nullable ( ) ,
171
171
isUnique : z . literal ( false ) ,
172
- defaultValue : z . number ( ) . optional ( ) ,
172
+ defaultValue : z . number ( ) . nullable ( ) ,
173
173
}
174
174
) ;
175
175
@@ -182,7 +182,7 @@ export type NumberValueDefinition = z.infer<typeof numberValueDefinitionSchema>;
182
182
export const rangeValueDefinitionSchema =
183
183
NumberValueDefinitionBaseSchema . extend ( {
184
184
inputType : z . literal ( ValueInputTypeSchema . Enum . range ) ,
185
- // Overwrite from optional to required because a range needs min, max and default to work and is required, since it always returns a number
185
+ // Overwrite from nullable to required because a range needs min, max and default to work and is required, since it always returns a number
186
186
isRequired : z . literal ( true ) ,
187
187
min : z . number ( ) ,
188
188
max : z . number ( ) ,
@@ -197,7 +197,7 @@ export type RangeValueDefinition = z.infer<typeof rangeValueDefinitionSchema>;
197
197
export const BooleanValueDefinitionBaseSchema =
198
198
ValueDefinitionBaseSchema . extend ( {
199
199
valueType : z . literal ( ValueTypeSchema . Enum . boolean ) ,
200
- // Overwrite from optional to required because a boolean needs a default to work and is required, since it always is either true or false
200
+ // Overwrite from nullable to required because a boolean needs a default to work and is required, since it always is either true or false
201
201
isRequired : z . literal ( true ) ,
202
202
defaultValue : z . boolean ( ) ,
203
203
isUnique : z . literal ( false ) ,
@@ -221,18 +221,18 @@ export const ReferenceValueDefinitionBaseSchema =
221
221
export const assetValueDefinitionSchema =
222
222
ReferenceValueDefinitionBaseSchema . extend ( {
223
223
inputType : z . literal ( ValueInputTypeSchema . Enum . asset ) ,
224
- allowedMimeTypes : z . array ( supportedAssetMimeTypeSchema ) . optional ( ) ,
225
- min : z . number ( ) . optional ( ) ,
226
- max : z . number ( ) . optional ( ) ,
224
+ allowedMimeTypes : z . array ( supportedAssetMimeTypeSchema ) . min ( 1 ) ,
225
+ min : z . number ( ) . nullable ( ) ,
226
+ max : z . number ( ) . nullable ( ) ,
227
227
} ) ;
228
228
export type AssetValueDefinition = z . infer < typeof assetValueDefinitionSchema > ;
229
229
230
230
export const entryValueDefinitionSchema =
231
231
ReferenceValueDefinitionBaseSchema . extend ( {
232
232
inputType : z . literal ( ValueInputTypeSchema . Enum . entry ) ,
233
233
ofCollections : z . array ( uuidSchema ) ,
234
- min : z . number ( ) . optional ( ) ,
235
- max : z . number ( ) . optional ( ) ,
234
+ min : z . number ( ) . nullable ( ) ,
235
+ max : z . number ( ) . nullable ( ) ,
236
236
} ) ;
237
237
export type EntryValueDefinition = z . infer < typeof entryValueDefinitionSchema > ;
238
238
@@ -445,15 +445,15 @@ function getNumberValueContentSchema(
445
445
) {
446
446
let schema = z . number ( ) ;
447
447
448
- if ( 'min' in definition && definition . min ) {
448
+ if ( definition . min ) {
449
449
schema = schema . min ( definition . min ) ;
450
450
}
451
- if ( 'max' in definition && definition . max ) {
451
+ if ( definition . max ) {
452
452
schema = schema . max ( definition . max ) ;
453
453
}
454
454
455
455
if ( definition . isRequired === false ) {
456
- return schema . optional ( ) ;
456
+ return schema . nullable ( ) ;
457
457
}
458
458
459
459
return schema ;
@@ -494,15 +494,12 @@ function getStringValueContentSchema(definition: StringValueDefinition) {
494
494
}
495
495
496
496
if ( definition . isRequired === false ) {
497
- return schema . optional ( ) ;
497
+ return schema . nullable ( ) ;
498
498
}
499
499
500
500
return schema . min ( 1 , 'shared.stringValueRequired' ) ; // @see https://github.com/colinhacks/zod/issues/2466
501
501
}
502
502
503
- /**
504
- * @todo what do we need inside the asset reference (inside the values content), to resolve and validate their schema?
505
- */
506
503
function getReferenceValueContentSchema (
507
504
definition : AssetValueDefinition | EntryValueDefinition // | SharedValueValueDefinition
508
505
) {
0 commit comments