@@ -104,9 +104,33 @@ import type {
104
104
} from '../../config/types.js'
105
105
import type { DBIdentifierName } from '../../database/types.js'
106
106
import type { SanitizedGlobalConfig } from '../../globals/config/types.js'
107
- import type { CollectionSlug } from '../../index.js'
107
+ import type {
108
+ ArrayFieldValidation ,
109
+ BlocksFieldValidation ,
110
+ CheckboxFieldValidation ,
111
+ CodeFieldValidation ,
112
+ CollectionSlug ,
113
+ DateFieldValidation ,
114
+ EmailFieldValidation ,
115
+ JSONFieldValidation ,
116
+ PointFieldValidation ,
117
+ RadioFieldValidation ,
118
+ TextareaFieldValidation ,
119
+ } from '../../index.js'
108
120
import type { DocumentPreferences } from '../../preferences/types.js'
109
121
import type { Operation , PayloadRequest , RequestContext , Where } from '../../types/index.js'
122
+ import type {
123
+ NumberFieldManyValidation ,
124
+ NumberFieldSingleValidation ,
125
+ RelationshipFieldManyValidation ,
126
+ RelationshipFieldSingleValidation ,
127
+ SelectFieldManyValidation ,
128
+ SelectFieldSingleValidation ,
129
+ TextFieldManyValidation ,
130
+ TextFieldSingleValidation ,
131
+ UploadFieldManyValidation ,
132
+ UploadFieldSingleValidation ,
133
+ } from '../validations.js'
110
134
111
135
export type FieldHookArgs < TData extends TypeWithID = any , TValue = any , TSiblingData = any > = {
112
136
/** The collection which the field belongs to. If the field belongs to a global, this will be null. */
@@ -335,7 +359,7 @@ export type Validate<
335
359
TSiblingData = any ,
336
360
TFieldConfig extends object = object ,
337
361
> = (
338
- value : TValue ,
362
+ value : null | TValue | undefined ,
339
363
options : ValidateOptions < TData , TSiblingData , TFieldConfig , TValue > ,
340
364
) => Promise < string | true > | string | true
341
365
@@ -452,7 +476,7 @@ export type NumberField = {
452
476
maxRows ?: number
453
477
/** Minimum number of numbers in the numbers array, if `hasMany` is set to true. */
454
478
minRows ?: number
455
- validate ?: Validate < number [ ] , unknown , unknown , NumberField >
479
+ validate ?: NumberFieldManyValidation
456
480
}
457
481
| {
458
482
/** Makes this field an ordered array of numbers instead of just a single number. */
@@ -461,7 +485,7 @@ export type NumberField = {
461
485
maxRows ?: undefined
462
486
/** Minimum number of numbers in the numbers array, if `hasMany` is set to true. */
463
487
minRows ?: undefined
464
- validate ?: Validate < number , unknown , unknown , NumberField >
488
+ validate ?: NumberFieldSingleValidation
465
489
}
466
490
) &
467
491
Omit < FieldBase , 'validate' >
@@ -502,7 +526,7 @@ export type TextField = {
502
526
maxRows ?: number
503
527
/** Minimum number of strings in the strings array, if `hasMany` is set to true. */
504
528
minRows ?: number
505
- validate ?: Validate < string [ ] , unknown , unknown , TextField >
529
+ validate ?: TextFieldManyValidation
506
530
}
507
531
| {
508
532
/** Makes this field an ordered array of strings instead of just a single string. */
@@ -511,7 +535,7 @@ export type TextField = {
511
535
maxRows ?: undefined
512
536
/** Minimum number of strings in the strings array, if `hasMany` is set to true. */
513
537
minRows ?: undefined
514
- validate ?: Validate < string , unknown , unknown , TextField >
538
+ validate ?: TextFieldSingleValidation
515
539
}
516
540
) &
517
541
Omit < FieldBase , 'validate' >
@@ -541,7 +565,7 @@ export type EmailField = {
541
565
placeholder ?: Record < string , string > | string
542
566
} & Admin
543
567
type : 'email'
544
- validate ?: Validate < string , unknown , unknown , EmailField >
568
+ validate ?: EmailFieldValidation
545
569
} & Omit < FieldBase , 'validate' >
546
570
547
571
export type EmailFieldClient = {
@@ -572,7 +596,7 @@ export type TextareaField = {
572
596
maxLength ?: number
573
597
minLength ?: number
574
598
type : 'textarea'
575
- validate ?: Validate < string , unknown , unknown , TextareaField >
599
+ validate ?: TextareaFieldValidation
576
600
} & Omit < FieldBase , 'validate' >
577
601
578
602
export type TextareaFieldClient = {
@@ -598,7 +622,7 @@ export type CheckboxField = {
598
622
} & Admin [ 'components' ]
599
623
} & Admin
600
624
type : 'checkbox'
601
- validate ?: Validate < boolean , unknown , unknown , CheckboxField >
625
+ validate ?: CheckboxFieldValidation
602
626
} & Omit < FieldBase , 'validate' >
603
627
604
628
export type CheckboxFieldClient = {
@@ -625,7 +649,7 @@ export type DateField = {
625
649
placeholder ?: Record < string , string > | string
626
650
} & Admin
627
651
type : 'date'
628
- validate ?: Validate < unknown , unknown , unknown , DateField >
652
+ validate ?: DateFieldValidation
629
653
} & Omit < FieldBase , 'validate' >
630
654
631
655
export type DateFieldClient = {
@@ -861,7 +885,7 @@ type SharedUploadProperties = {
861
885
*/
862
886
min ?: number
863
887
minRows ?: number
864
- validate ?: Validate < unknown [ ] , unknown , unknown , SharedUploadProperties >
888
+ validate ?: UploadFieldManyValidation
865
889
}
866
890
| {
867
891
hasMany ?: false | undefined
@@ -875,7 +899,7 @@ type SharedUploadProperties = {
875
899
*/
876
900
min ?: undefined
877
901
minRows ?: undefined
878
- validate ?: Validate < unknown , unknown , unknown , SharedUploadProperties >
902
+ validate ?: UploadFieldSingleValidation
879
903
}
880
904
) &
881
905
Omit < FieldBase , 'validate' >
@@ -950,7 +974,7 @@ export type CodeField = {
950
974
maxLength ?: number
951
975
minLength ?: number
952
976
type : 'code'
953
- validate ?: Validate < string , unknown , unknown , CodeField >
977
+ validate ?: CodeFieldValidation
954
978
} & Omit < FieldBase , 'admin' | 'validate' >
955
979
956
980
export type CodeFieldClient = {
@@ -983,7 +1007,7 @@ export type JSONField = {
983
1007
uri : string
984
1008
}
985
1009
type : 'json'
986
- validate ?: Validate < Record < string , unknown > , unknown , unknown , JSONField >
1010
+ validate ?: JSONFieldValidation
987
1011
} & Omit < FieldBase , 'admin' | 'validate' >
988
1012
989
1013
export type JSONFieldClient = {
@@ -1024,11 +1048,11 @@ export type SelectField = {
1024
1048
} & (
1025
1049
| {
1026
1050
hasMany : true
1027
- validate ?: Validate < string [ ] , unknown , unknown , SelectField >
1051
+ validate ?: SelectFieldManyValidation
1028
1052
}
1029
1053
| {
1030
1054
hasMany ?: false | undefined
1031
- validate ?: Validate < string , unknown , unknown , SelectField >
1055
+ validate ?: SelectFieldSingleValidation
1032
1056
}
1033
1057
) &
1034
1058
Omit < FieldBase , 'validate' >
@@ -1068,7 +1092,7 @@ type SharedRelationshipProperties = {
1068
1092
*/
1069
1093
min ?: number
1070
1094
minRows ?: number
1071
- validate ?: Validate < any [ ] , unknown , unknown , SharedRelationshipProperties >
1095
+ validate ?: RelationshipFieldManyValidation
1072
1096
}
1073
1097
| {
1074
1098
hasMany ?: false | undefined
@@ -1082,7 +1106,7 @@ type SharedRelationshipProperties = {
1082
1106
*/
1083
1107
min ?: undefined
1084
1108
minRows ?: undefined
1085
- validate ?: Validate < any , unknown , unknown , SharedRelationshipProperties >
1109
+ validate ?: RelationshipFieldSingleValidation
1086
1110
}
1087
1111
) &
1088
1112
Omit < FieldBase , 'validate' >
@@ -1155,11 +1179,11 @@ export function valueIsValueWithRelation(value: unknown): value is ValueWithRela
1155
1179
return value !== null && typeof value === 'object' && 'relationTo' in value && 'value' in value
1156
1180
}
1157
1181
1158
- export type RelationshipValue =
1159
- | ( number | string ) [ ]
1160
- | ( number | string )
1161
- | ValueWithRelation
1162
- | ValueWithRelation [ ]
1182
+ export type RelationshipValue = RelationshipValueMany | RelationshipValueSingle
1183
+
1184
+ export type RelationshipValueMany = ( number | string ) [ ] | ValueWithRelation [ ]
1185
+
1186
+ export type RelationshipValueSingle = number | string | ValueWithRelation
1163
1187
1164
1188
export type RichTextField <
1165
1189
TValue extends object = any ,
@@ -1231,7 +1255,7 @@ export type ArrayField = {
1231
1255
maxRows ?: number
1232
1256
minRows ?: number
1233
1257
type : 'array'
1234
- validate ?: Validate < unknown [ ] , unknown , unknown , ArrayField >
1258
+ validate ?: ArrayFieldValidation
1235
1259
} & Omit < FieldBase , 'validate' >
1236
1260
1237
1261
export type ArrayFieldClient = {
@@ -1266,7 +1290,7 @@ export type RadioField = {
1266
1290
enumName ?: DBIdentifierName
1267
1291
options : Option [ ]
1268
1292
type : 'radio'
1269
- validate ?: Validate < string , unknown , unknown , RadioField >
1293
+ validate ?: RadioFieldValidation
1270
1294
} & Omit < FieldBase , 'validate' >
1271
1295
1272
1296
export type RadioFieldClient = {
@@ -1352,7 +1376,7 @@ export type BlocksField = {
1352
1376
maxRows ?: number
1353
1377
minRows ?: number
1354
1378
type : 'blocks'
1355
- validate ?: Validate < string , unknown , unknown , BlocksField >
1379
+ validate ?: BlocksFieldValidation
1356
1380
} & Omit < FieldBase , 'validate' >
1357
1381
1358
1382
export type BlocksFieldClient = {
@@ -1379,7 +1403,7 @@ export type PointField = {
1379
1403
step ?: number
1380
1404
} & Admin
1381
1405
type : 'point'
1382
- validate ?: Validate < [ number , number ] , unknown , unknown , PointField >
1406
+ validate ?: PointFieldValidation
1383
1407
} & Omit < FieldBase , 'validate' >
1384
1408
1385
1409
export type PointFieldClient = {
0 commit comments