@strapi/content-type-builder 5.52.1 → 5.52.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/controllers/validation/schema.js +195 -177
- package/dist/server/controllers/validation/schema.js.map +1 -1
- package/dist/server/controllers/validation/schema.mjs +16 -18
- package/dist/server/controllers/validation/schema.mjs.map +1 -1
- package/dist/server/index.js +0 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +0 -2
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/validation/schema.d.ts +7058 -105175
- package/dist/server/src/controllers/validation/schema.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +0 -1
- package/dist/server/src/index.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var z = require('zod/v4');
|
|
4
4
|
var utils = require('@strapi/utils');
|
|
5
5
|
var fp = require('lodash/fp');
|
|
6
6
|
var builder = require('../../services/builder.js');
|
|
7
7
|
var constants = require('../../services/constants.js');
|
|
8
8
|
var common = require('./common.js');
|
|
9
9
|
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
29
|
+
|
|
10
30
|
const uniqueAttributeName = (attributes, ctx)=>{
|
|
11
31
|
const names = new Set(attributes.map((attribute)=>fp.snakeCase(attribute.name)));
|
|
12
32
|
if (names.size !== attributes.length) {
|
|
13
33
|
ctx.addIssue({
|
|
14
|
-
code:
|
|
34
|
+
code: 'custom',
|
|
15
35
|
message: 'Attributes must have unique names'
|
|
16
36
|
});
|
|
17
37
|
}
|
|
@@ -28,13 +48,13 @@ const verifyUidTargetField = (attributes, ctx)=>{
|
|
|
28
48
|
// NOTE: on update we are setting it to undefined later in the process instead to handle renames
|
|
29
49
|
if (action === 'create') {
|
|
30
50
|
ctx.addIssue({
|
|
31
|
-
code:
|
|
51
|
+
code: 'custom',
|
|
32
52
|
message: 'Target does not exist'
|
|
33
53
|
});
|
|
34
54
|
}
|
|
35
55
|
} else if (!constants.VALID_UID_TARGETS.some((validUIdTarget)=>validUIdTarget === targetAttr.properties?.type)) {
|
|
36
56
|
ctx.addIssue({
|
|
37
|
-
code:
|
|
57
|
+
code: 'custom',
|
|
38
58
|
message: 'Invalid target type'
|
|
39
59
|
});
|
|
40
60
|
}
|
|
@@ -48,7 +68,7 @@ const verifySingularAndPluralNames = (obj, ctx)=>{
|
|
|
48
68
|
}
|
|
49
69
|
if (obj.singularName === obj.pluralName) {
|
|
50
70
|
ctx.addIssue({
|
|
51
|
-
code:
|
|
71
|
+
code: 'custom',
|
|
52
72
|
message: 'Singular and plural names must be different',
|
|
53
73
|
path: [
|
|
54
74
|
'singularName'
|
|
@@ -83,7 +103,7 @@ const verifyDraftAndPublishReservedAttributes = (contentType, ctx)=>{
|
|
|
83
103
|
const reservedAttributeNames = utils.contentTypes.findDraftAndPublishReservedAttributeNames(getEffectiveAttributeNames(contentType));
|
|
84
104
|
if (reservedAttributeNames.length > 0) {
|
|
85
105
|
ctx.addIssue({
|
|
86
|
-
code:
|
|
106
|
+
code: 'custom',
|
|
87
107
|
message: utils.contentTypes.getDraftAndPublishEnableBlockedMessage(reservedAttributeNames),
|
|
88
108
|
path: [
|
|
89
109
|
'draftAndPublish'
|
|
@@ -95,7 +115,7 @@ const maxLengthGreaterThanMinLength = (value, ctx)=>{
|
|
|
95
115
|
if (!fp.isNil(value.maxLength) && !fp.isNil(value.minLength) && fp.isNumber(value.maxLength) && fp.isNumber(value.minLength)) {
|
|
96
116
|
if (value.maxLength < value.minLength) {
|
|
97
117
|
ctx.addIssue({
|
|
98
|
-
code:
|
|
118
|
+
code: 'custom',
|
|
99
119
|
message: 'maxLength must be greater or equal to minLength',
|
|
100
120
|
path: [
|
|
101
121
|
'maxLength'
|
|
@@ -108,7 +128,7 @@ const maxGreaterThanMin = (value, ctx)=>{
|
|
|
108
128
|
if (!fp.isNil(value.max) && !fp.isNil(value.min) && fp.isNumber(value.max) && fp.isNumber(value.min)) {
|
|
109
129
|
if (value.max < value.min) {
|
|
110
130
|
ctx.addIssue({
|
|
111
|
-
code:
|
|
131
|
+
code: 'custom',
|
|
112
132
|
message: 'max must be greater or equal to min',
|
|
113
133
|
path: [
|
|
114
134
|
'max'
|
|
@@ -127,7 +147,7 @@ const checkUserTarget = (value, ctx)=>{
|
|
|
127
147
|
const { target, relation, targetAttribute } = value;
|
|
128
148
|
if (target === constants.coreUids.STRAPI_USER && (!STRAPI_USER_RELATIONS.includes(relation) || !fp.isUndefined(targetAttribute))) {
|
|
129
149
|
ctx.addIssue({
|
|
130
|
-
code:
|
|
150
|
+
code: 'custom',
|
|
131
151
|
path: [
|
|
132
152
|
'relation'
|
|
133
153
|
],
|
|
@@ -138,7 +158,7 @@ const checkUserTarget = (value, ctx)=>{
|
|
|
138
158
|
const uidRefinement = (value, ctx)=>{
|
|
139
159
|
if (!fp.isNil(value.targetField) && !fp.isNil(value.default)) {
|
|
140
160
|
ctx.addIssue({
|
|
141
|
-
code:
|
|
161
|
+
code: 'custom',
|
|
142
162
|
message: 'Cannot define a default UID if the targetField is set',
|
|
143
163
|
path: [
|
|
144
164
|
'default'
|
|
@@ -150,7 +170,7 @@ const enumRefinement = (value, ctx)=>{
|
|
|
150
170
|
if (value.type === 'enumeration' && !fp.isNil(value.default) && !fp.isNil(value.enum)) {
|
|
151
171
|
if (value.default === '' || !value.enum.some((v)=>v === value.default)) {
|
|
152
172
|
ctx.addIssue({
|
|
153
|
-
code:
|
|
173
|
+
code: 'custom',
|
|
154
174
|
message: 'Default value must be one of the enum values',
|
|
155
175
|
path: [
|
|
156
176
|
'default'
|
|
@@ -159,11 +179,11 @@ const enumRefinement = (value, ctx)=>{
|
|
|
159
179
|
}
|
|
160
180
|
}
|
|
161
181
|
};
|
|
162
|
-
const conditionSchema =
|
|
163
|
-
visible:
|
|
182
|
+
const conditionSchema = z__namespace.object({
|
|
183
|
+
visible: z__namespace.record(z__namespace.string(), z__namespace.array(z__namespace.any()))
|
|
164
184
|
});
|
|
165
|
-
const basePropertiesSchema =
|
|
166
|
-
type:
|
|
185
|
+
const basePropertiesSchema = z__namespace.object({
|
|
186
|
+
type: z__namespace.enum([
|
|
167
187
|
'string',
|
|
168
188
|
'text',
|
|
169
189
|
'richtext',
|
|
@@ -188,24 +208,24 @@ const basePropertiesSchema = zod.z.object({
|
|
|
188
208
|
'relation',
|
|
189
209
|
'dynamiczone'
|
|
190
210
|
]),
|
|
191
|
-
configurable:
|
|
192
|
-
private:
|
|
193
|
-
pluginOptions:
|
|
194
|
-
conditions:
|
|
211
|
+
configurable: z__namespace.boolean().nullish(),
|
|
212
|
+
private: z__namespace.boolean().nullish(),
|
|
213
|
+
pluginOptions: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional(),
|
|
214
|
+
conditions: z__namespace.preprocess((val)=>{
|
|
195
215
|
return val;
|
|
196
216
|
}, conditionSchema.optional())
|
|
197
217
|
});
|
|
198
|
-
const maxLengthSchema =
|
|
199
|
-
const minLengthSchema =
|
|
200
|
-
const requiredSchema =
|
|
201
|
-
const uniqueSchema =
|
|
218
|
+
const maxLengthSchema = z__namespace.number().int().positive().optional();
|
|
219
|
+
const minLengthSchema = z__namespace.number().int().positive().optional();
|
|
220
|
+
const requiredSchema = z__namespace.boolean().optional();
|
|
221
|
+
const uniqueSchema = z__namespace.boolean().optional();
|
|
202
222
|
const STRAPI_USER_RELATIONS = [
|
|
203
223
|
'oneToOne',
|
|
204
224
|
'oneToMany'
|
|
205
225
|
];
|
|
206
|
-
const baseRelationSchema =
|
|
207
|
-
type:
|
|
208
|
-
relation:
|
|
226
|
+
const baseRelationSchema = z__namespace.object({
|
|
227
|
+
type: z__namespace.literal('relation'),
|
|
228
|
+
relation: z__namespace.enum([
|
|
209
229
|
'oneToOne',
|
|
210
230
|
'oneToMany',
|
|
211
231
|
'manyToOne',
|
|
@@ -215,57 +235,57 @@ const baseRelationSchema = zod.z.object({
|
|
|
215
235
|
'morphToOne',
|
|
216
236
|
'morphToMany'
|
|
217
237
|
]),
|
|
218
|
-
configurable:
|
|
238
|
+
configurable: z__namespace.boolean().nullish(),
|
|
219
239
|
required: requiredSchema,
|
|
220
|
-
private:
|
|
221
|
-
pluginOptions:
|
|
222
|
-
conditions:
|
|
240
|
+
private: z__namespace.boolean().nullish(),
|
|
241
|
+
pluginOptions: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional(),
|
|
242
|
+
conditions: z__namespace.preprocess((val)=>{
|
|
223
243
|
return val;
|
|
224
244
|
}, conditionSchema.optional())
|
|
225
245
|
});
|
|
226
246
|
const oneToOneSchema = baseRelationSchema.extend({
|
|
227
|
-
relation:
|
|
228
|
-
target:
|
|
229
|
-
targetAttribute:
|
|
247
|
+
relation: z__namespace.literal('oneToOne'),
|
|
248
|
+
target: z__namespace.string(),
|
|
249
|
+
targetAttribute: z__namespace.string().nullish()
|
|
230
250
|
});
|
|
231
251
|
const oneWaySchema = baseRelationSchema.extend({
|
|
232
|
-
relation:
|
|
233
|
-
target:
|
|
252
|
+
relation: z__namespace.literal('oneToOne'),
|
|
253
|
+
target: z__namespace.string()
|
|
234
254
|
});
|
|
235
255
|
const oneToManySchema = baseRelationSchema.extend({
|
|
236
|
-
relation:
|
|
237
|
-
target:
|
|
238
|
-
targetAttribute:
|
|
256
|
+
relation: z__namespace.literal('oneToMany'),
|
|
257
|
+
target: z__namespace.string(),
|
|
258
|
+
targetAttribute: z__namespace.string().nullish()
|
|
239
259
|
});
|
|
240
260
|
const manyWaySchema = baseRelationSchema.extend({
|
|
241
|
-
relation:
|
|
242
|
-
target:
|
|
261
|
+
relation: z__namespace.literal('oneToMany'),
|
|
262
|
+
target: z__namespace.string()
|
|
243
263
|
});
|
|
244
264
|
const manyToOneSchema = baseRelationSchema.extend({
|
|
245
|
-
relation:
|
|
246
|
-
target:
|
|
247
|
-
targetAttribute:
|
|
265
|
+
relation: z__namespace.literal('manyToOne'),
|
|
266
|
+
target: z__namespace.string(),
|
|
267
|
+
targetAttribute: z__namespace.string().nullish()
|
|
248
268
|
});
|
|
249
269
|
const manyToManySchema = baseRelationSchema.extend({
|
|
250
|
-
relation:
|
|
251
|
-
target:
|
|
252
|
-
targetAttribute:
|
|
270
|
+
relation: z__namespace.literal('manyToMany'),
|
|
271
|
+
target: z__namespace.string(),
|
|
272
|
+
targetAttribute: z__namespace.string().nullish()
|
|
253
273
|
});
|
|
254
274
|
const morphOneSchema = baseRelationSchema.extend({
|
|
255
|
-
relation:
|
|
256
|
-
target:
|
|
257
|
-
targetAttribute:
|
|
275
|
+
relation: z__namespace.literal('morphOne'),
|
|
276
|
+
target: z__namespace.string(),
|
|
277
|
+
targetAttribute: z__namespace.string().nullish()
|
|
258
278
|
});
|
|
259
279
|
const morphManySchema = baseRelationSchema.extend({
|
|
260
|
-
relation:
|
|
261
|
-
target:
|
|
262
|
-
targetAttribute:
|
|
280
|
+
relation: z__namespace.literal('morphMany'),
|
|
281
|
+
target: z__namespace.string(),
|
|
282
|
+
targetAttribute: z__namespace.string().nullish()
|
|
263
283
|
});
|
|
264
284
|
const morphToOneSchema = baseRelationSchema.extend({
|
|
265
|
-
relation:
|
|
285
|
+
relation: z__namespace.literal('morphToOne')
|
|
266
286
|
});
|
|
267
287
|
const morphToManySchema = baseRelationSchema.extend({
|
|
268
|
-
relation:
|
|
288
|
+
relation: z__namespace.literal('morphToMany')
|
|
269
289
|
});
|
|
270
290
|
const createRelationSchema = (meta)=>{
|
|
271
291
|
switch(meta.modelType){
|
|
@@ -273,7 +293,7 @@ const createRelationSchema = (meta)=>{
|
|
|
273
293
|
{
|
|
274
294
|
switch(meta.kind){
|
|
275
295
|
case 'singleType':
|
|
276
|
-
return
|
|
296
|
+
return z__namespace.discriminatedUnion('relation', [
|
|
277
297
|
oneToOneSchema,
|
|
278
298
|
oneToManySchema,
|
|
279
299
|
morphOneSchema,
|
|
@@ -282,7 +302,7 @@ const createRelationSchema = (meta)=>{
|
|
|
282
302
|
morphToManySchema
|
|
283
303
|
]);
|
|
284
304
|
case 'collectionType':
|
|
285
|
-
return
|
|
305
|
+
return z__namespace.discriminatedUnion('relation', [
|
|
286
306
|
oneToOneSchema,
|
|
287
307
|
oneToManySchema,
|
|
288
308
|
manyToOneSchema,
|
|
@@ -298,7 +318,7 @@ const createRelationSchema = (meta)=>{
|
|
|
298
318
|
}
|
|
299
319
|
case 'component':
|
|
300
320
|
{
|
|
301
|
-
return
|
|
321
|
+
return z__namespace.discriminatedUnion('relation', [
|
|
302
322
|
oneWaySchema,
|
|
303
323
|
manyWaySchema
|
|
304
324
|
]);
|
|
@@ -308,20 +328,20 @@ const createRelationSchema = (meta)=>{
|
|
|
308
328
|
}
|
|
309
329
|
};
|
|
310
330
|
const richTextSchema = basePropertiesSchema.extend({
|
|
311
|
-
type:
|
|
331
|
+
type: z__namespace.literal('richtext'),
|
|
312
332
|
required: requiredSchema,
|
|
313
333
|
minLength: minLengthSchema,
|
|
314
334
|
maxLength: maxLengthSchema,
|
|
315
|
-
default:
|
|
335
|
+
default: z__namespace.string().optional()
|
|
316
336
|
});
|
|
317
337
|
const blocksSchema = basePropertiesSchema.extend({
|
|
318
|
-
type:
|
|
338
|
+
type: z__namespace.literal('blocks'),
|
|
319
339
|
required: requiredSchema
|
|
320
340
|
});
|
|
321
341
|
const jsonSchema = basePropertiesSchema.extend({
|
|
322
|
-
type:
|
|
342
|
+
type: z__namespace.literal('json'),
|
|
323
343
|
required: requiredSchema,
|
|
324
|
-
default:
|
|
344
|
+
default: z__namespace.unknown().optional().refine((value)=>{
|
|
325
345
|
if (value === undefined) {
|
|
326
346
|
return true;
|
|
327
347
|
}
|
|
@@ -337,13 +357,13 @@ const jsonSchema = basePropertiesSchema.extend({
|
|
|
337
357
|
})
|
|
338
358
|
});
|
|
339
359
|
const enumerationSchema = basePropertiesSchema.extend({
|
|
340
|
-
type:
|
|
360
|
+
type: z__namespace.literal('enumeration'),
|
|
341
361
|
required: requiredSchema,
|
|
342
|
-
default:
|
|
343
|
-
enumName:
|
|
362
|
+
default: z__namespace.string().optional(),
|
|
363
|
+
enumName: z__namespace.string().optional().refine((value)=>{
|
|
344
364
|
return value === '' || common.NAME_REGEX.test(value);
|
|
345
365
|
}, 'Invalid enum name'),
|
|
346
|
-
enum:
|
|
366
|
+
enum: z__namespace.array(z__namespace.string().refine((value)=>{
|
|
347
367
|
return value === '' || !utils.strings.startsWithANumber(value);
|
|
348
368
|
})).min(1).refine((values)=>{
|
|
349
369
|
const filtered = [
|
|
@@ -353,105 +373,105 @@ const enumerationSchema = basePropertiesSchema.extend({
|
|
|
353
373
|
})
|
|
354
374
|
});
|
|
355
375
|
const textSchema = basePropertiesSchema.extend({
|
|
356
|
-
type:
|
|
357
|
-
default:
|
|
376
|
+
type: z__namespace.literal('text'),
|
|
377
|
+
default: z__namespace.string().nullish(),
|
|
358
378
|
minLength: minLengthSchema,
|
|
359
379
|
maxLength: maxLengthSchema,
|
|
360
380
|
required: requiredSchema,
|
|
361
381
|
unique: uniqueSchema,
|
|
362
|
-
regex:
|
|
382
|
+
regex: z__namespace.string().optional().refine((value)=>{
|
|
363
383
|
return value === '' || !!new RegExp(value);
|
|
364
384
|
}, 'Invalid regular expression pattern')
|
|
365
385
|
});
|
|
366
386
|
const stringSchema = textSchema.extend({
|
|
367
|
-
type:
|
|
387
|
+
type: z__namespace.literal('string')
|
|
368
388
|
});
|
|
369
389
|
const passwordSchema = basePropertiesSchema.extend({
|
|
370
|
-
type:
|
|
390
|
+
type: z__namespace.literal('password'),
|
|
371
391
|
required: requiredSchema,
|
|
372
392
|
minLength: minLengthSchema,
|
|
373
393
|
maxLength: maxLengthSchema
|
|
374
394
|
});
|
|
375
395
|
const emailSchema = basePropertiesSchema.extend({
|
|
376
|
-
type:
|
|
396
|
+
type: z__namespace.literal('email'),
|
|
377
397
|
required: requiredSchema,
|
|
378
398
|
minLength: minLengthSchema,
|
|
379
399
|
maxLength: maxLengthSchema,
|
|
380
|
-
default:
|
|
400
|
+
default: z__namespace.string().email().optional(),
|
|
381
401
|
unique: uniqueSchema
|
|
382
402
|
});
|
|
383
403
|
const integerSchema = basePropertiesSchema.extend({
|
|
384
|
-
type:
|
|
404
|
+
type: z__namespace.literal('integer'),
|
|
385
405
|
required: requiredSchema,
|
|
386
|
-
default:
|
|
406
|
+
default: z__namespace.number().int().optional(),
|
|
387
407
|
unique: uniqueSchema,
|
|
388
|
-
min:
|
|
389
|
-
max:
|
|
408
|
+
min: z__namespace.number().int().optional(),
|
|
409
|
+
max: z__namespace.number().int().optional()
|
|
390
410
|
});
|
|
391
411
|
const bigIntegerSchema = basePropertiesSchema.extend({
|
|
392
|
-
type:
|
|
412
|
+
type: z__namespace.literal('biginteger'),
|
|
393
413
|
required: requiredSchema,
|
|
394
414
|
unique: uniqueSchema,
|
|
395
|
-
default:
|
|
396
|
-
min:
|
|
397
|
-
max:
|
|
415
|
+
default: z__namespace.string().regex(/^\d*$/).nullish(),
|
|
416
|
+
min: z__namespace.string().regex(/^\d*$/).nullish(),
|
|
417
|
+
max: z__namespace.string().regex(/^\d*$/).nullish()
|
|
398
418
|
});
|
|
399
419
|
const floatSchema = basePropertiesSchema.extend({
|
|
400
|
-
type:
|
|
420
|
+
type: z__namespace.literal('float'),
|
|
401
421
|
required: requiredSchema,
|
|
402
422
|
unique: uniqueSchema,
|
|
403
|
-
default:
|
|
404
|
-
min:
|
|
405
|
-
max:
|
|
423
|
+
default: z__namespace.number().optional(),
|
|
424
|
+
min: z__namespace.number().optional(),
|
|
425
|
+
max: z__namespace.number().optional()
|
|
406
426
|
});
|
|
407
427
|
const decimalSchema = basePropertiesSchema.extend({
|
|
408
|
-
type:
|
|
428
|
+
type: z__namespace.literal('decimal'),
|
|
409
429
|
required: requiredSchema,
|
|
410
430
|
unique: uniqueSchema,
|
|
411
|
-
default:
|
|
412
|
-
min:
|
|
413
|
-
max:
|
|
431
|
+
default: z__namespace.number().optional(),
|
|
432
|
+
min: z__namespace.number().optional(),
|
|
433
|
+
max: z__namespace.number().optional()
|
|
414
434
|
});
|
|
415
435
|
const timeSchema = basePropertiesSchema.extend({
|
|
416
|
-
type:
|
|
436
|
+
type: z__namespace.literal('time'),
|
|
417
437
|
required: requiredSchema,
|
|
418
438
|
unique: uniqueSchema,
|
|
419
|
-
default:
|
|
439
|
+
default: z__namespace.string().optional()
|
|
420
440
|
});
|
|
421
441
|
const dateSchema = timeSchema.extend({
|
|
422
|
-
type:
|
|
442
|
+
type: z__namespace.literal('date')
|
|
423
443
|
});
|
|
424
444
|
const dateTimeSchema = timeSchema.extend({
|
|
425
|
-
type:
|
|
445
|
+
type: z__namespace.literal('datetime')
|
|
426
446
|
});
|
|
427
447
|
const timeStampSchema = basePropertiesSchema.extend({
|
|
428
|
-
type:
|
|
448
|
+
type: z__namespace.literal('timestamp')
|
|
429
449
|
});
|
|
430
450
|
const booleanSchema = basePropertiesSchema.extend({
|
|
431
|
-
type:
|
|
451
|
+
type: z__namespace.literal('boolean'),
|
|
432
452
|
required: requiredSchema,
|
|
433
|
-
default:
|
|
453
|
+
default: z__namespace.boolean().optional()
|
|
434
454
|
});
|
|
435
455
|
const componentSchema = basePropertiesSchema.extend({
|
|
436
|
-
type:
|
|
437
|
-
component:
|
|
438
|
-
repeatable:
|
|
456
|
+
type: z__namespace.literal('component'),
|
|
457
|
+
component: z__namespace.string(),
|
|
458
|
+
repeatable: z__namespace.boolean().optional(),
|
|
439
459
|
required: requiredSchema,
|
|
440
|
-
min:
|
|
441
|
-
max:
|
|
460
|
+
min: z__namespace.number().optional(),
|
|
461
|
+
max: z__namespace.number().optional()
|
|
442
462
|
});
|
|
443
463
|
const dynamicZoneSchema = basePropertiesSchema.extend({
|
|
444
|
-
type:
|
|
445
|
-
components:
|
|
464
|
+
type: z__namespace.literal('dynamiczone'),
|
|
465
|
+
components: z__namespace.array(z__namespace.string()).nonempty(),
|
|
446
466
|
required: requiredSchema,
|
|
447
|
-
min:
|
|
448
|
-
max:
|
|
467
|
+
min: z__namespace.number().optional(),
|
|
468
|
+
max: z__namespace.number().optional()
|
|
449
469
|
});
|
|
450
470
|
const mediaSchema = basePropertiesSchema.extend({
|
|
451
|
-
type:
|
|
452
|
-
multiple:
|
|
471
|
+
type: z__namespace.literal('media'),
|
|
472
|
+
multiple: z__namespace.boolean().optional(),
|
|
453
473
|
required: requiredSchema,
|
|
454
|
-
allowedTypes:
|
|
474
|
+
allowedTypes: z__namespace.array(z__namespace.enum([
|
|
455
475
|
'images',
|
|
456
476
|
'videos',
|
|
457
477
|
'files',
|
|
@@ -459,30 +479,30 @@ const mediaSchema = basePropertiesSchema.extend({
|
|
|
459
479
|
])).nonempty().optional()
|
|
460
480
|
});
|
|
461
481
|
const uidSchema = basePropertiesSchema.extend({
|
|
462
|
-
type:
|
|
463
|
-
targetField:
|
|
482
|
+
type: z__namespace.literal('uid'),
|
|
483
|
+
targetField: z__namespace.string().nullish(),
|
|
464
484
|
required: requiredSchema,
|
|
465
|
-
default:
|
|
485
|
+
default: z__namespace.string().nullish(),
|
|
466
486
|
minLength: minLengthSchema,
|
|
467
487
|
maxLength: maxLengthSchema,
|
|
468
|
-
options:
|
|
469
|
-
separator:
|
|
470
|
-
lowercase:
|
|
471
|
-
decamelize:
|
|
472
|
-
customReplacements:
|
|
473
|
-
preserveLeadingUnderscore:
|
|
488
|
+
options: z__namespace.object({
|
|
489
|
+
separator: z__namespace.string().optional(),
|
|
490
|
+
lowercase: z__namespace.boolean().optional(),
|
|
491
|
+
decamelize: z__namespace.boolean().optional(),
|
|
492
|
+
customReplacements: z__namespace.array(z__namespace.array(z__namespace.string()).length(2)).optional(),
|
|
493
|
+
preserveLeadingUnderscore: z__namespace.boolean().optional()
|
|
474
494
|
}).optional(),
|
|
475
|
-
regex:
|
|
495
|
+
regex: z__namespace.string().optional().refine((value)=>{
|
|
476
496
|
return value === '' || !!new RegExp(value);
|
|
477
497
|
}, 'Invalid regular expression pattern')
|
|
478
498
|
});
|
|
479
499
|
const customFieldSchema = basePropertiesSchema.extend({
|
|
480
|
-
type:
|
|
481
|
-
customField:
|
|
500
|
+
type: z__namespace.literal('customField'),
|
|
501
|
+
customField: z__namespace.string()
|
|
482
502
|
});
|
|
483
503
|
const attributePropertiesSchema = (meta)=>{
|
|
484
504
|
const relationSchema = createRelationSchema(meta);
|
|
485
|
-
const base =
|
|
505
|
+
const base = z__namespace.union([
|
|
486
506
|
mediaSchema,
|
|
487
507
|
textSchema,
|
|
488
508
|
stringSchema,
|
|
@@ -508,52 +528,52 @@ const attributePropertiesSchema = (meta)=>{
|
|
|
508
528
|
if (meta.modelType === 'component') {
|
|
509
529
|
return base.superRefine(enumRefinement).superRefine(checkUserTarget).superRefine(maxGreaterThanMin).superRefine(maxLengthGreaterThanMinLength);
|
|
510
530
|
}
|
|
511
|
-
return
|
|
531
|
+
return z__namespace.union([
|
|
512
532
|
...base.options,
|
|
513
533
|
uidSchema,
|
|
514
534
|
dynamicZoneSchema
|
|
515
535
|
]).superRefine(enumRefinement).superRefine(checkUserTarget).superRefine(uidRefinement).superRefine(maxGreaterThanMin).superRefine(maxLengthGreaterThanMinLength);
|
|
516
536
|
};
|
|
517
|
-
const createAttributeSchema = (meta)=>
|
|
518
|
-
action:
|
|
519
|
-
name:
|
|
537
|
+
const createAttributeSchema = (meta)=>z__namespace.object({
|
|
538
|
+
action: z__namespace.literal('create'),
|
|
539
|
+
name: z__namespace.string().regex(common.NAME_REGEX).refine((value)=>!builder.isReservedAttributeName(value), 'Attribute name is reserved'),
|
|
520
540
|
properties: attributePropertiesSchema(meta)
|
|
521
541
|
});
|
|
522
|
-
const updateAttributeSchema = (meta)=>
|
|
523
|
-
action:
|
|
524
|
-
name:
|
|
542
|
+
const updateAttributeSchema = (meta)=>z__namespace.object({
|
|
543
|
+
action: z__namespace.literal('update'),
|
|
544
|
+
name: z__namespace.string(),
|
|
525
545
|
properties: attributePropertiesSchema(meta)
|
|
526
546
|
});
|
|
527
|
-
const deleteAttributeSchema =
|
|
528
|
-
action:
|
|
529
|
-
name:
|
|
547
|
+
const deleteAttributeSchema = z__namespace.object({
|
|
548
|
+
action: z__namespace.literal('delete'),
|
|
549
|
+
name: z__namespace.string()
|
|
530
550
|
});
|
|
531
|
-
const contentTypeUIDSchema =
|
|
551
|
+
const contentTypeUIDSchema = z__namespace.custom((value)=>{
|
|
532
552
|
return typeof value === 'string' && value.length > 0;
|
|
533
553
|
});
|
|
534
|
-
const componentUIDSchema =
|
|
554
|
+
const componentUIDSchema = z__namespace.custom((value)=>{
|
|
535
555
|
return typeof value === 'string' && value.length > 0;
|
|
536
556
|
});
|
|
537
|
-
const categorySchema =
|
|
538
|
-
const baseComponentSchema =
|
|
557
|
+
const categorySchema = z__namespace.string().min(1).regex(common.CATEGORY_NAME_REGEX);
|
|
558
|
+
const baseComponentSchema = z__namespace.object({
|
|
539
559
|
uid: componentUIDSchema,
|
|
540
|
-
displayName:
|
|
541
|
-
icon:
|
|
542
|
-
description:
|
|
560
|
+
displayName: z__namespace.string().min(1),
|
|
561
|
+
icon: z__namespace.string().regex(common.ICON_REGEX).optional(),
|
|
562
|
+
description: z__namespace.string().optional(),
|
|
543
563
|
category: categorySchema,
|
|
544
|
-
pluginOptions:
|
|
564
|
+
pluginOptions: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional()
|
|
545
565
|
});
|
|
546
566
|
const createComponentSchema = baseComponentSchema.extend({
|
|
547
|
-
action:
|
|
548
|
-
config:
|
|
549
|
-
attributes:
|
|
567
|
+
action: z__namespace.literal('create'),
|
|
568
|
+
config: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional().default({}),
|
|
569
|
+
attributes: z__namespace.array(createAttributeSchema({
|
|
550
570
|
modelType: 'component'
|
|
551
571
|
})).superRefine(uniqueAttributeName)
|
|
552
572
|
});
|
|
553
573
|
const updateComponentSchema = baseComponentSchema.extend({
|
|
554
|
-
action:
|
|
574
|
+
action: z__namespace.literal('update'),
|
|
555
575
|
category: categorySchema.optional(),
|
|
556
|
-
attributes:
|
|
576
|
+
attributes: z__namespace.array(z__namespace.discriminatedUnion('action', [
|
|
557
577
|
createAttributeSchema({
|
|
558
578
|
modelType: 'component'
|
|
559
579
|
}),
|
|
@@ -563,50 +583,50 @@ const updateComponentSchema = baseComponentSchema.extend({
|
|
|
563
583
|
deleteAttributeSchema
|
|
564
584
|
])).superRefine(uniqueAttributeName)
|
|
565
585
|
});
|
|
566
|
-
const deleteComponentSchema =
|
|
567
|
-
action:
|
|
586
|
+
const deleteComponentSchema = z__namespace.object({
|
|
587
|
+
action: z__namespace.literal('delete'),
|
|
568
588
|
uid: componentUIDSchema
|
|
569
589
|
});
|
|
570
|
-
const baseContentTypeSchema =
|
|
590
|
+
const baseContentTypeSchema = z__namespace.object({
|
|
571
591
|
uid: contentTypeUIDSchema,
|
|
572
|
-
displayName:
|
|
573
|
-
description:
|
|
574
|
-
draftAndPublish:
|
|
575
|
-
options:
|
|
576
|
-
pluginOptions:
|
|
577
|
-
kind:
|
|
592
|
+
displayName: z__namespace.string().min(1),
|
|
593
|
+
description: z__namespace.string().optional(),
|
|
594
|
+
draftAndPublish: z__namespace.boolean(),
|
|
595
|
+
options: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional().default({}),
|
|
596
|
+
pluginOptions: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional().default({}),
|
|
597
|
+
kind: z__namespace.enum([
|
|
578
598
|
constants.typeKinds.SINGLE_TYPE,
|
|
579
599
|
constants.typeKinds.COLLECTION_TYPE
|
|
580
600
|
]).optional()
|
|
581
601
|
});
|
|
582
602
|
const baseCreateContentTypeSchema = baseContentTypeSchema.extend({
|
|
583
|
-
action:
|
|
584
|
-
plugin:
|
|
585
|
-
collectionName:
|
|
586
|
-
singularName:
|
|
587
|
-
pluralName:
|
|
588
|
-
config:
|
|
603
|
+
action: z__namespace.literal('create'),
|
|
604
|
+
plugin: z__namespace.string().min(1).optional(),
|
|
605
|
+
collectionName: z__namespace.string().regex(common.COLLECTION_NAME_REGEX).optional(),
|
|
606
|
+
singularName: z__namespace.string().min(1).regex(common.KEBAB_BASE_REGEX, 'Must be kebab case').refine((value)=>!builder.isReservedModelName(value), 'Model name is reserved'),
|
|
607
|
+
pluralName: z__namespace.string().min(1).regex(common.KEBAB_BASE_REGEX, 'Must be kebab case').refine((value)=>!builder.isReservedModelName(value), 'Model name is reserved'),
|
|
608
|
+
config: z__namespace.record(z__namespace.string(), z__namespace.unknown()).optional()
|
|
589
609
|
});
|
|
590
610
|
const createSingleTypeSchema = baseCreateContentTypeSchema.extend({
|
|
591
|
-
kind:
|
|
592
|
-
attributes:
|
|
611
|
+
kind: z__namespace.literal(constants.typeKinds.SINGLE_TYPE),
|
|
612
|
+
attributes: z__namespace.array(createAttributeSchema({
|
|
593
613
|
modelType: 'contentType',
|
|
594
614
|
kind: 'singleType'
|
|
595
615
|
})).superRefine(uniqueAttributeName).superRefine(verifyUidTargetField)
|
|
596
616
|
});
|
|
597
617
|
const createCollectionTypeSchema = baseCreateContentTypeSchema.extend({
|
|
598
|
-
kind:
|
|
599
|
-
attributes:
|
|
618
|
+
kind: z__namespace.literal(constants.typeKinds.COLLECTION_TYPE),
|
|
619
|
+
attributes: z__namespace.array(createAttributeSchema({
|
|
600
620
|
modelType: 'contentType',
|
|
601
621
|
kind: 'collectionType'
|
|
602
622
|
})).superRefine(uniqueAttributeName).superRefine(verifyUidTargetField)
|
|
603
623
|
});
|
|
604
624
|
const baseUpdateContentTypeSchema = baseContentTypeSchema.extend({
|
|
605
|
-
action:
|
|
625
|
+
action: z__namespace.literal('update')
|
|
606
626
|
});
|
|
607
627
|
const updateSingleTypeSchema = baseUpdateContentTypeSchema.extend({
|
|
608
|
-
kind:
|
|
609
|
-
attributes:
|
|
628
|
+
kind: z__namespace.literal(constants.typeKinds.SINGLE_TYPE).optional(),
|
|
629
|
+
attributes: z__namespace.array(z__namespace.discriminatedUnion('action', [
|
|
610
630
|
createAttributeSchema({
|
|
611
631
|
modelType: 'contentType',
|
|
612
632
|
kind: 'singleType'
|
|
@@ -619,8 +639,8 @@ const updateSingleTypeSchema = baseUpdateContentTypeSchema.extend({
|
|
|
619
639
|
])).superRefine(uniqueAttributeName).superRefine(verifyUidTargetField)
|
|
620
640
|
});
|
|
621
641
|
const updateCollectionTypeSchema = baseUpdateContentTypeSchema.extend({
|
|
622
|
-
kind:
|
|
623
|
-
attributes:
|
|
642
|
+
kind: z__namespace.literal(constants.typeKinds.COLLECTION_TYPE).optional(),
|
|
643
|
+
attributes: z__namespace.array(z__namespace.union([
|
|
624
644
|
createAttributeSchema({
|
|
625
645
|
modelType: 'contentType',
|
|
626
646
|
kind: 'collectionType'
|
|
@@ -632,17 +652,17 @@ const updateCollectionTypeSchema = baseUpdateContentTypeSchema.extend({
|
|
|
632
652
|
deleteAttributeSchema
|
|
633
653
|
])).superRefine(uniqueAttributeName).superRefine(verifyUidTargetField)
|
|
634
654
|
});
|
|
635
|
-
const deleteContentTypeSchema =
|
|
636
|
-
action:
|
|
655
|
+
const deleteContentTypeSchema = z__namespace.object({
|
|
656
|
+
action: z__namespace.literal('delete'),
|
|
637
657
|
uid: contentTypeUIDSchema
|
|
638
658
|
});
|
|
639
|
-
const schemaSchema =
|
|
640
|
-
components:
|
|
659
|
+
const schemaSchema = z__namespace.object({
|
|
660
|
+
components: z__namespace.array(z__namespace.union([
|
|
641
661
|
createComponentSchema,
|
|
642
662
|
updateComponentSchema,
|
|
643
663
|
deleteComponentSchema
|
|
644
664
|
])).optional().default([]),
|
|
645
|
-
contentTypes:
|
|
665
|
+
contentTypes: z__namespace.array(z__namespace.union([
|
|
646
666
|
createSingleTypeSchema,
|
|
647
667
|
createCollectionTypeSchema,
|
|
648
668
|
updateSingleTypeSchema,
|
|
@@ -650,13 +670,11 @@ const schemaSchema = zod.z.object({
|
|
|
650
670
|
deleteContentTypeSchema
|
|
651
671
|
]).superRefine(verifySingularAndPluralNames).superRefine(verifyDraftAndPublishReservedAttributes)).optional().default([])
|
|
652
672
|
});
|
|
653
|
-
const updateSchemaInput =
|
|
673
|
+
const updateSchemaInput = z__namespace.object({
|
|
654
674
|
data: schemaSchema
|
|
655
675
|
}, {
|
|
656
|
-
|
|
657
|
-
required_error: 'Schema is required'
|
|
676
|
+
error: (issue)=>issue.input === undefined ? 'Schema is required' : 'Invalid schema, expected an object with a data property'
|
|
658
677
|
});
|
|
659
|
-
// TODO: Remove cast when content-type-builder migrates to Zod 4
|
|
660
678
|
const validateUpdateSchema = utils.validateZodSchema(updateSchemaInput);
|
|
661
679
|
|
|
662
680
|
exports.maxGreaterThanMin = maxGreaterThanMin;
|