@webiny/api-headless-cms 5.20.0-beta.0 → 5.21.0-beta.0
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/content/graphQLHandlerFactory.js +5 -2
- package/content/plugins/crud/contentEntry/afterDelete.d.ts +1 -1
- package/content/plugins/crud/contentEntry/afterDelete.js +2 -2
- package/content/plugins/crud/contentEntry/beforeCreate.d.ts +1 -1
- package/content/plugins/crud/contentEntry/beforeCreate.js +2 -2
- package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +1 -1
- package/content/plugins/crud/contentEntry/beforeUpdate.js +2 -2
- package/content/plugins/crud/contentEntry.crud.js +72 -68
- package/content/plugins/crud/contentModel/afterCreate.d.ts +1 -1
- package/content/plugins/crud/contentModel/afterCreate.js +2 -2
- package/content/plugins/crud/contentModel/afterDelete.d.ts +1 -1
- package/content/plugins/crud/contentModel/afterDelete.js +2 -2
- package/content/plugins/crud/contentModel/afterUpdate.d.ts +1 -1
- package/content/plugins/crud/contentModel/afterUpdate.js +2 -2
- package/content/plugins/crud/contentModel/beforeCreate.d.ts +2 -2
- package/content/plugins/crud/contentModel/beforeCreate.js +4 -4
- package/content/plugins/crud/contentModel/beforeDelete.d.ts +1 -1
- package/content/plugins/crud/contentModel/beforeDelete.js +2 -2
- package/content/plugins/crud/contentModel/beforeUpdate.d.ts +1 -1
- package/content/plugins/crud/contentModel/beforeUpdate.js +2 -2
- package/content/plugins/crud/contentModel/models.d.ts +1 -0
- package/content/plugins/crud/contentModel/models.js +19 -1
- package/content/plugins/crud/contentModel.crud.js +86 -80
- package/content/plugins/graphqlFields/boolean.js +4 -2
- package/content/plugins/graphqlFields/datetime.js +4 -1
- package/content/plugins/graphqlFields/file.js +5 -2
- package/content/plugins/graphqlFields/longText.js +4 -2
- package/content/plugins/graphqlFields/number.js +4 -2
- package/content/plugins/graphqlFields/object.js +3 -1
- package/content/plugins/graphqlFields/ref.js +4 -2
- package/content/plugins/graphqlFields/requiredField.d.ts +2 -0
- package/content/plugins/graphqlFields/requiredField.js +24 -0
- package/content/plugins/graphqlFields/richText.js +5 -2
- package/content/plugins/graphqlFields/text.js +4 -2
- package/content/plugins/schema/contentModelGroups.js +6 -2
- package/content/plugins/schema/contentModels.js +1 -0
- package/content/plugins/storage/object.js +5 -0
- package/package.json +23 -23
- package/plugins/crud/system.crud.js +11 -3
- package/types.d.ts +64 -32
- package/types.js +22 -0
|
@@ -23,8 +23,6 @@ var _createFieldModels = require("./contentModel/createFieldModels");
|
|
|
23
23
|
|
|
24
24
|
var _validateLayout = require("./contentModel/validateLayout");
|
|
25
25
|
|
|
26
|
-
var _apiSecurity = require("@webiny/api-security");
|
|
27
|
-
|
|
28
26
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
29
27
|
|
|
30
28
|
var _CmsModelPlugin = require("../CmsModelPlugin");
|
|
@@ -148,7 +146,7 @@ const createModelsCrud = params => {
|
|
|
148
146
|
return databaseModels.concat(pluginsModels);
|
|
149
147
|
};
|
|
150
148
|
|
|
151
|
-
const
|
|
149
|
+
const listModels = async () => {
|
|
152
150
|
const permission = await checkModelPermissions("r");
|
|
153
151
|
const models = await modelsList();
|
|
154
152
|
return utils.filterAsync(models, async model => {
|
|
@@ -160,7 +158,7 @@ const createModelsCrud = params => {
|
|
|
160
158
|
});
|
|
161
159
|
};
|
|
162
160
|
|
|
163
|
-
const
|
|
161
|
+
const getModel = async modelId => {
|
|
164
162
|
const permission = await checkModelPermissions("r");
|
|
165
163
|
const model = await modelsGet(modelId);
|
|
166
164
|
utils.checkOwnership(context, permission, model);
|
|
@@ -168,7 +166,9 @@ const createModelsCrud = params => {
|
|
|
168
166
|
return model;
|
|
169
167
|
};
|
|
170
168
|
|
|
171
|
-
const
|
|
169
|
+
const getModelManager = async target => {
|
|
170
|
+
const modelId = typeof target === "string" ? target : target.modelId;
|
|
171
|
+
|
|
172
172
|
if (managers.has(modelId)) {
|
|
173
173
|
return managers.get(modelId);
|
|
174
174
|
}
|
|
@@ -183,72 +183,57 @@ const createModelsCrud = params => {
|
|
|
183
183
|
return await updateManager(context, model);
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
186
|
+
const onBeforeModelCreate = (0, _pubsub.createTopic)();
|
|
187
|
+
const onAfterModelCreate = (0, _pubsub.createTopic)();
|
|
188
|
+
const onBeforeModelCreateFrom = (0, _pubsub.createTopic)();
|
|
189
|
+
const onAfterModelCreateFrom = (0, _pubsub.createTopic)();
|
|
190
|
+
const onBeforeModelUpdate = (0, _pubsub.createTopic)();
|
|
191
|
+
const onAfterModelUpdate = (0, _pubsub.createTopic)();
|
|
192
|
+
const onBeforeModelDelete = (0, _pubsub.createTopic)();
|
|
193
|
+
const onAfterModelDelete = (0, _pubsub.createTopic)();
|
|
194
194
|
/**
|
|
195
195
|
* We need to assign some default behaviors.
|
|
196
196
|
*/
|
|
197
197
|
|
|
198
198
|
(0, _beforeCreate.assignBeforeModelCreate)({
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
onBeforeModelCreate,
|
|
200
|
+
onBeforeModelCreateFrom,
|
|
201
201
|
plugins: context.plugins,
|
|
202
202
|
storageOperations
|
|
203
203
|
});
|
|
204
204
|
(0, _afterCreate.assignAfterModelCreate)({
|
|
205
205
|
context,
|
|
206
|
-
|
|
206
|
+
onAfterModelCreate
|
|
207
207
|
});
|
|
208
208
|
(0, _beforeUpdate.assignBeforeModelUpdate)({
|
|
209
|
-
|
|
209
|
+
onBeforeModelUpdate,
|
|
210
210
|
plugins: context.plugins,
|
|
211
211
|
storageOperations
|
|
212
212
|
});
|
|
213
213
|
(0, _afterUpdate.assignAfterModelUpdate)({
|
|
214
214
|
context,
|
|
215
|
-
|
|
215
|
+
onAfterModelUpdate
|
|
216
216
|
});
|
|
217
217
|
(0, _beforeDelete.assignBeforeModelDelete)({
|
|
218
|
-
|
|
218
|
+
onBeforeModelDelete,
|
|
219
219
|
plugins: context.plugins,
|
|
220
220
|
storageOperations
|
|
221
221
|
});
|
|
222
222
|
(0, _afterDelete.assignAfterModelDelete)({
|
|
223
223
|
context,
|
|
224
|
-
|
|
224
|
+
onAfterModelDelete
|
|
225
225
|
});
|
|
226
226
|
return {
|
|
227
|
-
onBeforeModelCreate
|
|
228
|
-
onAfterModelCreate
|
|
229
|
-
onBeforeModelCreateFrom
|
|
230
|
-
onAfterModelCreateFrom
|
|
231
|
-
onBeforeModelUpdate
|
|
232
|
-
onAfterModelUpdate
|
|
233
|
-
onBeforeModelDelete
|
|
234
|
-
onAfterModelDelete
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
list: async () => {
|
|
238
|
-
try {
|
|
239
|
-
return await listOperations();
|
|
240
|
-
} catch (ex) {
|
|
241
|
-
if (ex instanceof _apiSecurity.NotAuthorizedError) {
|
|
242
|
-
return [];
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
throw ex;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
},
|
|
250
|
-
getModel: get,
|
|
251
|
-
listModels: listOperations,
|
|
227
|
+
onBeforeModelCreate,
|
|
228
|
+
onAfterModelCreate,
|
|
229
|
+
onBeforeModelCreateFrom,
|
|
230
|
+
onAfterModelCreateFrom,
|
|
231
|
+
onBeforeModelUpdate,
|
|
232
|
+
onAfterModelUpdate,
|
|
233
|
+
onBeforeModelDelete,
|
|
234
|
+
onAfterModelDelete,
|
|
235
|
+
getModel,
|
|
236
|
+
listModels,
|
|
252
237
|
|
|
253
238
|
async createModel(inputData) {
|
|
254
239
|
await checkModelPermissions("w");
|
|
@@ -264,8 +249,10 @@ const createModelsCrud = params => {
|
|
|
264
249
|
}
|
|
265
250
|
|
|
266
251
|
const identity = getIdentity();
|
|
267
|
-
|
|
268
|
-
|
|
252
|
+
const model = {
|
|
253
|
+
name: input.name,
|
|
254
|
+
description: input.description,
|
|
255
|
+
modelId: input.modelId,
|
|
269
256
|
titleFieldId: "id",
|
|
270
257
|
locale: getLocale().code,
|
|
271
258
|
tenant: getTenant().id,
|
|
@@ -284,11 +271,10 @@ const createModelsCrud = params => {
|
|
|
284
271
|
lockedFields: [],
|
|
285
272
|
layout: [],
|
|
286
273
|
webinyVersion: context.WEBINY_VERSION
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
model
|
|
291
|
-
input
|
|
274
|
+
};
|
|
275
|
+
await onBeforeModelCreate.publish({
|
|
276
|
+
input,
|
|
277
|
+
model
|
|
292
278
|
});
|
|
293
279
|
const createdModel = await storageOperations.models.create({
|
|
294
280
|
input,
|
|
@@ -296,7 +282,7 @@ const createModelsCrud = params => {
|
|
|
296
282
|
});
|
|
297
283
|
loaders.listModels.clearAll();
|
|
298
284
|
await updateManager(context, model);
|
|
299
|
-
await
|
|
285
|
+
await onAfterModelCreate.publish({
|
|
300
286
|
input,
|
|
301
287
|
model: createdModel
|
|
302
288
|
});
|
|
@@ -319,7 +305,7 @@ const createModelsCrud = params => {
|
|
|
319
305
|
webinyVersion: context.WEBINY_VERSION
|
|
320
306
|
});
|
|
321
307
|
|
|
322
|
-
await
|
|
308
|
+
await onBeforeModelUpdate.publish({
|
|
323
309
|
input: {},
|
|
324
310
|
original,
|
|
325
311
|
model
|
|
@@ -331,7 +317,7 @@ const createModelsCrud = params => {
|
|
|
331
317
|
});
|
|
332
318
|
await updateManager(context, resultModel);
|
|
333
319
|
loaders.listModels.clearAll();
|
|
334
|
-
await
|
|
320
|
+
await onAfterModelUpdate.publish({
|
|
335
321
|
input: {},
|
|
336
322
|
original,
|
|
337
323
|
model: resultModel
|
|
@@ -345,18 +331,31 @@ const createModelsCrud = params => {
|
|
|
345
331
|
* Get a model record; this will also perform ownership validation.
|
|
346
332
|
*/
|
|
347
333
|
|
|
348
|
-
const original = await
|
|
349
|
-
const createdData = new _models.
|
|
334
|
+
const original = await getModel(modelId);
|
|
335
|
+
const createdData = new _models.CreateContentModelModelFrom().populate({
|
|
350
336
|
name: data.name,
|
|
351
337
|
modelId: data.modelId,
|
|
352
338
|
description: data.description || original.description,
|
|
353
|
-
group: data.group
|
|
339
|
+
group: data.group,
|
|
340
|
+
locale: data.locale
|
|
354
341
|
});
|
|
355
342
|
await createdData.validate();
|
|
356
343
|
const input = await createdData.toJSON();
|
|
357
|
-
context.
|
|
358
|
-
|
|
359
|
-
|
|
344
|
+
const locale = await context.i18n.getLocale(input.locale || original.locale);
|
|
345
|
+
|
|
346
|
+
if (!locale) {
|
|
347
|
+
throw new _handlerGraphql.NotFoundError(`There is no locale "${input.locale}".`);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Use storage operations directly because we cannot get group from different locale via context methods.
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
const group = await context.cms.storageOperations.groups.get({
|
|
355
|
+
id: input.group,
|
|
356
|
+
tenant: original.tenant,
|
|
357
|
+
locale: locale.code
|
|
358
|
+
});
|
|
360
359
|
|
|
361
360
|
if (!group) {
|
|
362
361
|
throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
|
|
@@ -365,6 +364,7 @@ const createModelsCrud = params => {
|
|
|
365
364
|
const identity = getIdentity();
|
|
366
365
|
|
|
367
366
|
const model = _objectSpread(_objectSpread({}, original), {}, {
|
|
367
|
+
locale: locale.code,
|
|
368
368
|
group: {
|
|
369
369
|
id: group.id,
|
|
370
370
|
name: group.name
|
|
@@ -383,10 +383,10 @@ const createModelsCrud = params => {
|
|
|
383
383
|
webinyVersion: context.WEBINY_VERSION
|
|
384
384
|
});
|
|
385
385
|
|
|
386
|
-
await
|
|
386
|
+
await onBeforeModelCreateFrom.publish({
|
|
387
|
+
input,
|
|
387
388
|
model,
|
|
388
|
-
original
|
|
389
|
-
input
|
|
389
|
+
original
|
|
390
390
|
});
|
|
391
391
|
const createdModel = await storageOperations.models.create({
|
|
392
392
|
input,
|
|
@@ -394,7 +394,7 @@ const createModelsCrud = params => {
|
|
|
394
394
|
});
|
|
395
395
|
loaders.listModels.clearAll();
|
|
396
396
|
await updateManager(context, model);
|
|
397
|
-
await
|
|
397
|
+
await onAfterModelCreateFrom.publish({
|
|
398
398
|
input,
|
|
399
399
|
original,
|
|
400
400
|
model: createdModel
|
|
@@ -405,7 +405,7 @@ const createModelsCrud = params => {
|
|
|
405
405
|
async updateModel(modelId, inputData) {
|
|
406
406
|
await checkModelPermissions("w"); // Get a model record; this will also perform ownership validation.
|
|
407
407
|
|
|
408
|
-
const original = await
|
|
408
|
+
const original = await getModel(modelId);
|
|
409
409
|
const updatedData = new _models.UpdateContentModelModel().populate(inputData);
|
|
410
410
|
await updatedData.validate();
|
|
411
411
|
const input = await updatedData.toJSON({
|
|
@@ -416,25 +416,30 @@ const createModelsCrud = params => {
|
|
|
416
416
|
return {};
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
let group = {
|
|
420
|
+
id: original.group.id,
|
|
421
|
+
name: original.group.name
|
|
422
|
+
};
|
|
423
|
+
|
|
419
424
|
if (input.group) {
|
|
420
425
|
context.security.disableAuthorization();
|
|
421
|
-
const
|
|
426
|
+
const groupData = await context.cms.getGroup(input.group);
|
|
422
427
|
context.security.enableAuthorization();
|
|
423
428
|
|
|
424
|
-
if (!
|
|
429
|
+
if (!groupData) {
|
|
425
430
|
throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
|
|
426
431
|
}
|
|
427
432
|
|
|
428
|
-
|
|
429
|
-
id:
|
|
430
|
-
name:
|
|
433
|
+
group = {
|
|
434
|
+
id: groupData.id,
|
|
435
|
+
name: groupData.name
|
|
431
436
|
};
|
|
432
437
|
}
|
|
433
438
|
|
|
434
439
|
const modelFields = await (0, _createFieldModels.createFieldModels)(original, inputData);
|
|
435
|
-
(0, _validateLayout.validateLayout)(input, modelFields);
|
|
436
440
|
|
|
437
441
|
const model = _objectSpread(_objectSpread(_objectSpread({}, original), input), {}, {
|
|
442
|
+
group,
|
|
438
443
|
tenant: original.tenant || getTenant().id,
|
|
439
444
|
locale: original.locale || getLocale().code,
|
|
440
445
|
webinyVersion: context.WEBINY_VERSION,
|
|
@@ -442,7 +447,8 @@ const createModelsCrud = params => {
|
|
|
442
447
|
savedOn: new Date().toISOString()
|
|
443
448
|
});
|
|
444
449
|
|
|
445
|
-
|
|
450
|
+
(0, _validateLayout.validateLayout)(model, modelFields);
|
|
451
|
+
await onBeforeModelUpdate.publish({
|
|
446
452
|
input,
|
|
447
453
|
original,
|
|
448
454
|
model
|
|
@@ -453,18 +459,18 @@ const createModelsCrud = params => {
|
|
|
453
459
|
input
|
|
454
460
|
});
|
|
455
461
|
await updateManager(context, resultModel);
|
|
456
|
-
await
|
|
462
|
+
await onAfterModelUpdate.publish({
|
|
463
|
+
input,
|
|
457
464
|
original,
|
|
458
|
-
model: resultModel
|
|
459
|
-
input
|
|
465
|
+
model: resultModel
|
|
460
466
|
});
|
|
461
467
|
return resultModel;
|
|
462
468
|
},
|
|
463
469
|
|
|
464
470
|
async deleteModel(modelId) {
|
|
465
471
|
await checkModelPermissions("d");
|
|
466
|
-
const model = await
|
|
467
|
-
await
|
|
472
|
+
const model = await getModel(modelId);
|
|
473
|
+
await onBeforeModelDelete.publish({
|
|
468
474
|
model
|
|
469
475
|
});
|
|
470
476
|
|
|
@@ -479,13 +485,13 @@ const createModelsCrud = params => {
|
|
|
479
485
|
});
|
|
480
486
|
}
|
|
481
487
|
|
|
482
|
-
await
|
|
488
|
+
await onAfterModelDelete.publish({
|
|
483
489
|
model
|
|
484
490
|
});
|
|
485
491
|
managers.delete(model.modelId);
|
|
486
492
|
},
|
|
487
493
|
|
|
488
|
-
getModelManager
|
|
494
|
+
getModelManager,
|
|
489
495
|
getManagers: () => managers
|
|
490
496
|
};
|
|
491
497
|
};
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
8
10
|
const createListFilters = ({
|
|
9
11
|
field
|
|
10
12
|
}) => {
|
|
@@ -57,10 +59,10 @@ const plugin = {
|
|
|
57
59
|
field
|
|
58
60
|
}) {
|
|
59
61
|
if (field.multipleValues) {
|
|
60
|
-
return field.fieldId + ": [Boolean]";
|
|
62
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [Boolean]", field);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
return field.fieldId + ": Boolean";
|
|
65
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": Boolean", field);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
}
|
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
7
10
|
const fieldGraphQLTypes = {
|
|
8
11
|
time: "Time",
|
|
9
12
|
dateTimeWithoutTimezone: "DateTime",
|
|
@@ -74,7 +77,7 @@ const plugin = {
|
|
|
74
77
|
createInputField({
|
|
75
78
|
field
|
|
76
79
|
}) {
|
|
77
|
-
return `${field.fieldId}: ${getFieldGraphQLType(field)}
|
|
80
|
+
return (0, _requiredField.attachRequiredFieldValue)(`${field.fieldId}: ${getFieldGraphQLType(field)}`, field);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
}
|
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
7
10
|
const plugin = {
|
|
8
11
|
name: "cms-model-field-to-graphql-file",
|
|
9
12
|
type: "cms-model-field-to-graphql",
|
|
@@ -37,10 +40,10 @@ const plugin = {
|
|
|
37
40
|
field
|
|
38
41
|
}) {
|
|
39
42
|
if (field.multipleValues) {
|
|
40
|
-
return field.fieldId + ": [String]";
|
|
43
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [String]", field);
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
return field.fieldId + ": String";
|
|
46
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": String", field);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
8
10
|
const createListFilters = ({
|
|
9
11
|
field
|
|
10
12
|
}) => {
|
|
@@ -50,10 +52,10 @@ const plugin = {
|
|
|
50
52
|
field
|
|
51
53
|
}) {
|
|
52
54
|
if (field.multipleValues) {
|
|
53
|
-
return field.fieldId + ": [String]";
|
|
55
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [String]", field);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
return field.fieldId + ": String";
|
|
58
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": String", field);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
8
10
|
const createListFilters = ({
|
|
9
11
|
field
|
|
10
12
|
}) => {
|
|
@@ -63,10 +65,10 @@ const plugin = {
|
|
|
63
65
|
field
|
|
64
66
|
}) {
|
|
65
67
|
if (field.multipleValues) {
|
|
66
|
-
return field.fieldId + ": [Number]";
|
|
68
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [Number]", field);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
return field.fieldId + ": Number";
|
|
71
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": Number", field);
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
}
|
|
@@ -15,6 +15,8 @@ var _renderInputFields = require("../utils/renderInputFields");
|
|
|
15
15
|
|
|
16
16
|
var _createTypeName = require("../utils/createTypeName");
|
|
17
17
|
|
|
18
|
+
var _requiredField = require("./requiredField");
|
|
19
|
+
|
|
18
20
|
const typeFromField = ({
|
|
19
21
|
typeOfType,
|
|
20
22
|
model,
|
|
@@ -182,7 +184,7 @@ const plugin = {
|
|
|
182
184
|
typeDefs
|
|
183
185
|
} = result;
|
|
184
186
|
return {
|
|
185
|
-
fields: `${field.fieldId}: ${field.multipleValues ? `[${fieldType}!]` : fieldType}`,
|
|
187
|
+
fields: (0, _requiredField.attachRequiredFieldValue)(`${field.fieldId}: ${field.multipleValues ? `[${fieldType}!]` : fieldType}`, field),
|
|
186
188
|
typeDefs
|
|
187
189
|
};
|
|
188
190
|
},
|
|
@@ -13,6 +13,8 @@ var _createTypeName = require("../utils/createTypeName");
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@webiny/utils");
|
|
15
15
|
|
|
16
|
+
var _requiredField = require("./requiredField");
|
|
17
|
+
|
|
16
18
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
17
19
|
|
|
18
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -228,10 +230,10 @@ const plugin = {
|
|
|
228
230
|
field
|
|
229
231
|
}) {
|
|
230
232
|
if (field.multipleValues) {
|
|
231
|
-
return field.fieldId + ": [RefFieldInput!]";
|
|
233
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [RefFieldInput!]", field);
|
|
232
234
|
}
|
|
233
235
|
|
|
234
|
-
return field.fieldId + ": RefFieldInput";
|
|
236
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": RefFieldInput", field);
|
|
235
237
|
},
|
|
236
238
|
|
|
237
239
|
createListFilters
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.attachRequiredFieldValue = void 0;
|
|
7
|
+
|
|
8
|
+
const attachRequiredFieldValue = (def, field) => {
|
|
9
|
+
if (!field.validation || field.validation.length === 0) {
|
|
10
|
+
return def;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const isRequired = field.validation.some(validation => {
|
|
14
|
+
return validation.name === "required";
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (!isRequired) {
|
|
18
|
+
return def;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return `${def}!`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.attachRequiredFieldValue = attachRequiredFieldValue;
|
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
7
10
|
const plugin = {
|
|
8
11
|
name: "cms-model-field-to-graphql-rich-text",
|
|
9
12
|
type: "cms-model-field-to-graphql",
|
|
@@ -43,10 +46,10 @@ const plugin = {
|
|
|
43
46
|
field
|
|
44
47
|
}) {
|
|
45
48
|
if (field.multipleValues) {
|
|
46
|
-
return field.fieldId + ": [JSON]";
|
|
49
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [JSON]", field);
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
return field.fieldId + ": JSON";
|
|
52
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": JSON", field);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _requiredField = require("./requiredField");
|
|
9
|
+
|
|
8
10
|
const createListFilters = ({
|
|
9
11
|
field
|
|
10
12
|
}) => {
|
|
@@ -60,10 +62,10 @@ const plugin = {
|
|
|
60
62
|
field
|
|
61
63
|
}) {
|
|
62
64
|
if (field.multipleValues) {
|
|
63
|
-
return field.fieldId + ": [String]";
|
|
65
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": [String]", field);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
return field.fieldId + ": String";
|
|
68
|
+
return (0, _requiredField.attachRequiredFieldValue)(field.fieldId + ": String", field);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
}
|
|
@@ -62,11 +62,15 @@ const plugin = context => {
|
|
|
62
62
|
resolvers = {
|
|
63
63
|
CmsContentModelGroup: {
|
|
64
64
|
contentModels: async (group, _, context) => {
|
|
65
|
-
|
|
65
|
+
context.security.disableAuthorization();
|
|
66
|
+
const models = await context.cms.listModels();
|
|
67
|
+
context.security.enableAuthorization();
|
|
66
68
|
return models.filter(m => m.group.id === group.id);
|
|
67
69
|
},
|
|
68
70
|
totalContentModels: async (group, _, context) => {
|
|
69
|
-
|
|
71
|
+
context.security.disableAuthorization();
|
|
72
|
+
const models = await context.cms.listModels();
|
|
73
|
+
context.security.enableAuthorization();
|
|
70
74
|
return models.filter(m => m.group === group.id).length;
|
|
71
75
|
},
|
|
72
76
|
plugin: async (group, _, context) => {
|
|
@@ -29,6 +29,11 @@ const processValue = async ({
|
|
|
29
29
|
}) => {
|
|
30
30
|
return await (0, _pReduce.default)(fields, async (values, field) => {
|
|
31
31
|
const plugin = getStoragePlugin(field.type);
|
|
32
|
+
|
|
33
|
+
if (!plugin) {
|
|
34
|
+
throw new Error(`Missing storage plugin for field type "${field.type}".`);
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
const value = await plugin[operation]({
|
|
33
38
|
plugins,
|
|
34
39
|
model,
|