@webiny/api-headless-cms 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.bca7b3e350
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/context.d.ts +5 -2
- package/context.js +53 -4
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +14 -4
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +7 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +72 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.js +99 -42
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +2 -3
- package/crud/contentModel/beforeCreate.js +4 -5
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +2 -4
- package/crud/contentModel/beforeUpdate.js +2 -2
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/createFieldModels.js +6 -0
- package/crud/contentModel/createFieldModels.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +4 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/fieldIdValidation.js +5 -0
- package/crud/contentModel/fieldIdValidation.js.map +1 -1
- package/crud/contentModel/idValidation.js +5 -0
- package/crud/contentModel/idValidation.js.map +1 -1
- package/crud/contentModel/models.js +20 -1
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +3 -4
- package/crud/contentModel/validateModel.js +6 -3
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +3 -4
- package/crud/contentModel/validateModelFields.js +111 -38
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +97 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +212 -177
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +34 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +47 -52
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +2 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +3 -7
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/createExecutableSchema.d.ts +7 -0
- package/graphql/createExecutableSchema.js +29 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/generateSchema.d.ts +8 -0
- package/graphql/generateSchema.js +31 -0
- package/graphql/generateSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +91 -50
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +2 -39
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +8 -4
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +3 -0
- package/graphql/schema/baseSchema.js +53 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +37 -23
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +7 -3
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +40 -7
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +17 -6
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +10 -6
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +5 -0
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +2 -0
- package/graphql/schema/createReadSDL.js +11 -5
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +58 -46
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +69 -72
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +208 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +19 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +2 -1
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/number.js +4 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +112 -68
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +31 -45
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -7
- package/index.js.map +1 -1
- package/package.json +28 -28
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +22 -0
- package/plugins/index.js.map +1 -1
- package/storage/object.js +4 -2
- package/storage/object.js.map +1 -1
- package/types.d.ts +241 -57
- package/types.js +62 -7
- package/types.js.map +1 -1
- package/utils/converters/ConverterCollection.js +5 -2
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +64 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +2 -1
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +14 -11
- package/utils/entryStorage.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +10 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +22 -14
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/renderFields.js +2 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +6 -3
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +2 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +4 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +21 -4
- package/utils/renderSortEnum.js.map +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +20 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/index.js +2 -1
- package/validators/index.js.map +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -69
- package/crud/index.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
- package/utils/filterModelFields.d.ts +0 -16
- package/utils/filterModelFields.js +0 -71
- package/utils/filterModelFields.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFieldStorageId","params","type","id"],"sources":["createFieldStorageId.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const createFieldStorageId = (params: Pick<CmsModelField, \"id\" | \"type\">): string => {\n const { type, id } = params;\n return `${type}@${id}`;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,oBAAoB,GAAIC,MAA0C,IAAa;EACxF,MAAM;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGF,MAAM;EAC3B,OAAQ,
|
|
1
|
+
{"version":3,"names":["createFieldStorageId","params","type","id","getBaseFieldType"],"sources":["createFieldStorageId.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport const createFieldStorageId = (params: Pick<CmsModelField, \"id\" | \"type\">): string => {\n const { type, id } = params;\n return `${getBaseFieldType({ type })}@${id}`;\n};\n"],"mappings":";;;;;;AACA;AAEO,MAAMA,oBAAoB,GAAIC,MAA0C,IAAa;EACxF,MAAM;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGF,MAAM;EAC3B,OAAQ,GAAE,IAAAG,kCAAgB,EAAC;IAAEF;EAAK,CAAC,CAAE,IAAGC,EAAG,EAAC;AAChD,CAAC;AAAC"}
|
|
@@ -4,11 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.validateFieldId = void 0;
|
|
7
|
+
|
|
7
8
|
var _validation = require("@webiny/validation");
|
|
9
|
+
|
|
8
10
|
var _systemFields = require("./systemFields");
|
|
11
|
+
|
|
9
12
|
const validateFieldId = async input => {
|
|
10
13
|
await _validation.validation.validate(input, "required,maxLength:100");
|
|
11
14
|
const value = String(input || "").trim();
|
|
15
|
+
|
|
12
16
|
if (!value.charAt(0).match(/^[a-zA-Z]/)) {
|
|
13
17
|
throw new Error(`Provided ${value} is not valid - must not start with a number.`);
|
|
14
18
|
} else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {
|
|
@@ -17,4 +21,5 @@ const validateFieldId = async input => {
|
|
|
17
21
|
throw new Error(`Provided ${value} is not valid - "${value}" is an auto-generated field.`);
|
|
18
22
|
}
|
|
19
23
|
};
|
|
24
|
+
|
|
20
25
|
exports.validateFieldId = validateFieldId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["validateFieldId","input","validation","validate","value","String","trim","charAt","match","Error","fieldSystemFields","includes"],"sources":["fieldIdValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport { fieldSystemFields } from \"~/crud/contentModel/systemFields\";\n\nexport const validateFieldId = async (input: string): Promise<void> => {\n await validation.validate(input, \"required,maxLength:100\");\n\n const value = String(input || \"\").trim();\n\n if (!value.charAt(0).match(/^[a-zA-Z]/)) {\n throw new Error(`Provided ${value} is not valid - must not start with a number.`);\n } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {\n throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);\n } else if (fieldSystemFields.includes(value)) {\n throw new Error(`Provided ${value} is not valid - \"${value}\" is an auto-generated field.`);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["validateFieldId","input","validation","validate","value","String","trim","charAt","match","Error","fieldSystemFields","includes"],"sources":["fieldIdValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport { fieldSystemFields } from \"~/crud/contentModel/systemFields\";\n\nexport const validateFieldId = async (input: string): Promise<void> => {\n await validation.validate(input, \"required,maxLength:100\");\n\n const value = String(input || \"\").trim();\n\n if (!value.charAt(0).match(/^[a-zA-Z]/)) {\n throw new Error(`Provided ${value} is not valid - must not start with a number.`);\n } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {\n throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);\n } else if (fieldSystemFields.includes(value)) {\n throw new Error(`Provided ${value} is not valid - \"${value}\" is an auto-generated field.`);\n }\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,eAAe,GAAG,MAAOC,KAAP,IAAwC;EACnE,MAAMC,sBAAA,CAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;EAEA,MAAMG,KAAK,GAAGC,MAAM,CAACJ,KAAK,IAAI,EAAV,CAAN,CAAoBK,IAApB,EAAd;;EAEA,IAAI,CAACF,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,WAAtB,CAAL,EAAyC;IACrC,MAAM,IAAIC,KAAJ,CAAW,YAAWL,KAAM,+CAA5B,CAAN;EACH,CAFD,MAEO,IAAIA,KAAK,CAACI,KAAN,CAAY,kBAAZ,MAAoC,IAAxC,EAA8C;IACjD,MAAM,IAAIC,KAAJ,CAAW,YAAWL,KAAM,8CAA5B,CAAN;EACH,CAFM,MAEA,IAAIM,+BAAA,CAAkBC,QAAlB,CAA2BP,KAA3B,CAAJ,EAAuC;IAC1C,MAAM,IAAIK,KAAJ,CAAW,YAAWL,KAAM,oBAAmBA,KAAM,+BAArD,CAAN;EACH;AACJ,CAZM"}
|
|
@@ -4,14 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.validateId = void 0;
|
|
7
|
+
|
|
7
8
|
var _validation = require("@webiny/validation");
|
|
9
|
+
|
|
8
10
|
const validateId = async value => {
|
|
9
11
|
await _validation.validation.validate(value, "required,maxLength:100");
|
|
12
|
+
|
|
10
13
|
if (!value.charAt(0).match(/[a-zA-Z]/)) {
|
|
11
14
|
throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);
|
|
12
15
|
}
|
|
16
|
+
|
|
13
17
|
if (value.trim().toLowerCase() === "id") {
|
|
14
18
|
throw new Error(`Provided ID ${value} is not valid - "id" is an auto-generated field.`);
|
|
15
19
|
}
|
|
16
20
|
};
|
|
21
|
+
|
|
17
22
|
exports.validateId = validateId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["validateId","value","validation","validate","charAt","match","Error","trim","toLowerCase"],"sources":["idValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n\nexport const validateId = async (value: string): Promise<void> => {\n await validation.validate(value, \"required,maxLength:100\");\n if (!value.charAt(0).match(/[a-zA-Z]/)) {\n throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);\n }\n if (value.trim().toLowerCase() === \"id\") {\n throw new Error(`Provided ID ${value} is not valid - \"id\" is an auto-generated field.`);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["validateId","value","validation","validate","charAt","match","Error","trim","toLowerCase"],"sources":["idValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n\nexport const validateId = async (value: string): Promise<void> => {\n await validation.validate(value, \"required,maxLength:100\");\n if (!value.charAt(0).match(/[a-zA-Z]/)) {\n throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);\n }\n if (value.trim().toLowerCase() === \"id\") {\n throw new Error(`Provided ID ${value} is not valid - \"id\" is an auto-generated field.`);\n }\n};\n"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,UAAU,GAAG,MAAOC,KAAP,IAAwC;EAC9D,MAAMC,sBAAA,CAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;;EACA,IAAI,CAACA,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,UAAtB,CAAL,EAAwC;IACpC,MAAM,IAAIC,KAAJ,CAAW,eAAcL,KAAM,+CAA/B,CAAN;EACH;;EACD,IAAIA,KAAK,CAACM,IAAN,GAAaC,WAAb,OAA+B,IAAnC,EAAyC;IACrC,MAAM,IAAIF,KAAJ,CAAW,eAAcL,KAAM,kDAA/B,CAAN;EACH;AACJ,CARM"}
|
|
@@ -4,10 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.UpdateContentModelModel = exports.CreateContentModelModelFrom = exports.CreateContentModelModel = exports.ContentModelFieldModel = void 0;
|
|
7
|
+
|
|
7
8
|
var _validation = require("@webiny/validation");
|
|
9
|
+
|
|
8
10
|
var _commodoFieldsObject = require("commodo-fields-object");
|
|
11
|
+
|
|
9
12
|
var _fields = require("@commodo/fields");
|
|
13
|
+
|
|
10
14
|
var _fieldIdValidation = require("./fieldIdValidation");
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* Package commodo-fields-object does not have types
|
|
13
18
|
*/
|
|
@@ -17,9 +22,10 @@ var _fieldIdValidation = require("./fieldIdValidation");
|
|
|
17
22
|
* Package commodo-fields does not have object.
|
|
18
23
|
*/
|
|
19
24
|
// @ts-ignore
|
|
20
|
-
|
|
21
25
|
const requiredShortString = _validation.validation.create("required,maxLength:255");
|
|
26
|
+
|
|
22
27
|
const shortString = _validation.validation.create("maxLength:255");
|
|
28
|
+
|
|
23
29
|
const RendererModel = (0, _fields.withFields)({
|
|
24
30
|
name: (0, _fields.string)({
|
|
25
31
|
validation: requiredShortString
|
|
@@ -44,6 +50,10 @@ const ContentModelFieldModel = (0, _fields.withFields)({
|
|
|
44
50
|
type: (0, _fields.setOnce)()((0, _fields.string)({
|
|
45
51
|
validation: requiredShortString
|
|
46
52
|
})),
|
|
53
|
+
tags: (0, _commodoFieldsObject.object)({
|
|
54
|
+
value: [],
|
|
55
|
+
required: false
|
|
56
|
+
}),
|
|
47
57
|
multipleValues: (0, _fields.boolean)({
|
|
48
58
|
value: false
|
|
49
59
|
}),
|
|
@@ -103,6 +113,7 @@ const ContentModelFieldModel = (0, _fields.withFields)({
|
|
|
103
113
|
* By the default, field is not deleted.
|
|
104
114
|
*/
|
|
105
115
|
// isDeleted: boolean({ value: false })
|
|
116
|
+
|
|
106
117
|
})();
|
|
107
118
|
exports.ContentModelFieldModel = ContentModelFieldModel;
|
|
108
119
|
const CreateContentModelModel = (0, _fields.withFields)({
|
|
@@ -127,6 +138,10 @@ const CreateContentModelModel = (0, _fields.withFields)({
|
|
|
127
138
|
layout: (0, _commodoFieldsObject.object)({
|
|
128
139
|
value: [],
|
|
129
140
|
required: true
|
|
141
|
+
}),
|
|
142
|
+
tags: (0, _commodoFieldsObject.object)({
|
|
143
|
+
value: [],
|
|
144
|
+
required: false
|
|
130
145
|
})
|
|
131
146
|
})();
|
|
132
147
|
exports.CreateContentModelModel = CreateContentModelModel;
|
|
@@ -168,6 +183,10 @@ const UpdateContentModelModel = (0, _fields.withFields)({
|
|
|
168
183
|
layout: (0, _commodoFieldsObject.object)({
|
|
169
184
|
value: [],
|
|
170
185
|
required: true
|
|
186
|
+
}),
|
|
187
|
+
tags: (0, _commodoFieldsObject.object)({
|
|
188
|
+
value: [],
|
|
189
|
+
required: false
|
|
171
190
|
})
|
|
172
191
|
})();
|
|
173
192
|
exports.UpdateContentModelModel = UpdateContentModelModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","validateFieldId","label","helpText","placeholderText","type","setOnce","
|
|
1
|
+
{"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","validateFieldId","label","helpText","placeholderText","type","setOnce","tags","object","value","required","multipleValues","boolean","predefinedValues","fields","instanceOf","enabled","values","list","selected","renderer","message","settings","listValidation","CreateContentModelModel","modelId","description","group","layout","CreateContentModelModelFrom","locale","UpdateContentModelModel","titleFieldId"],"sources":["models.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\n/**\n * Package commodo-fields does not have object.\n */\n// @ts-ignore\nimport { withFields, string, setOnce, boolean, fields } from \"@commodo/fields\";\nimport { validateFieldId } from \"./fieldIdValidation\";\n\nconst requiredShortString = validation.create(\"required,maxLength:255\");\nconst shortString = validation.create(\"maxLength:255\");\n\nconst RendererModel = withFields({\n name: string({ validation: requiredShortString })\n})();\n\nexport const ContentModelFieldModel = withFields({\n id: string({ validation: requiredShortString }),\n fieldId: string({\n validation: validateFieldId\n }),\n label: string({ validation: requiredShortString }),\n helpText: string({ validation: shortString }),\n placeholderText: string({ validation: shortString }),\n type: setOnce()(string({ validation: requiredShortString })),\n tags: object({ value: [], required: false }),\n multipleValues: boolean({ value: false }),\n predefinedValues: fields({\n value: {},\n instanceOf: withFields({\n enabled: boolean(),\n values: fields({\n value: [],\n list: true,\n instanceOf: withFields({\n label: string(),\n value: string(),\n selected: boolean()\n })()\n })\n })()\n }),\n renderer: fields({ instanceOf: RendererModel, validation: shortString }),\n validation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n listValidation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n settings: object({ value: {} })\n /**\n * By the default, field is not deleted.\n */\n // isDeleted: boolean({ value: false })\n})();\n\nexport const CreateContentModelModel = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true }),\n tags: object({ value: [], required: false })\n})();\n\nexport const CreateContentModelModelFrom = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n locale: string({ validation: shortString })\n})();\n\nexport const UpdateContentModelModel = withFields({\n name: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: shortString }),\n titleFieldId: string(),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true }),\n tags: object({ value: [], required: false })\n})();\n"],"mappings":";;;;;;;AAAA;;AAKA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAGC,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB,CAA5B;;AACA,MAAMC,WAAW,GAAGF,sBAAA,CAAWC,MAAX,CAAkB,eAAlB,CAApB;;AAEA,MAAME,aAAa,GAAG,IAAAC,kBAAA,EAAW;EAC7BC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP;AADuB,CAAX,GAAtB;AAIO,MAAMQ,sBAAsB,GAAG,IAAAH,kBAAA,EAAW;EAC7CI,EAAE,EAAE,IAAAF,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CADyC;EAE7CU,OAAO,EAAE,IAAAH,cAAA,EAAO;IACZN,UAAU,EAAEU;EADA,CAAP,CAFoC;EAK7CC,KAAK,EAAE,IAAAL,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CALsC;EAM7Ca,QAAQ,EAAE,IAAAN,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CANmC;EAO7CW,eAAe,EAAE,IAAAP,cA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K,EAAE,EAAT;IAAaC,QAAQ,EAAE;EAAvB,CAAP;AAPwC,CAAX,GAAhC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CmsModel } from "../../types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
1
|
+
import { CmsContext, CmsModel } from "../../types";
|
|
3
2
|
interface ValidateModelParams {
|
|
4
3
|
model: CmsModel;
|
|
5
4
|
original?: CmsModel;
|
|
6
|
-
|
|
5
|
+
context: CmsContext;
|
|
7
6
|
}
|
|
8
|
-
export declare const validateModel: (params: ValidateModelParams) => void
|
|
7
|
+
export declare const validateModel: (params: ValidateModelParams) => Promise<void>;
|
|
9
8
|
export {};
|
|
@@ -8,17 +8,20 @@ exports.validateModel = void 0;
|
|
|
8
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
9
|
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
10
10
|
var _validateModelFields = require("./validateModelFields");
|
|
11
|
-
const validateModel = params => {
|
|
11
|
+
const validateModel = async params => {
|
|
12
12
|
const {
|
|
13
13
|
model,
|
|
14
|
-
|
|
14
|
+
context
|
|
15
15
|
} = params;
|
|
16
|
+
const {
|
|
17
|
+
plugins
|
|
18
|
+
} = context;
|
|
16
19
|
const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
|
|
17
20
|
if (modelPlugin) {
|
|
18
21
|
throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
|
|
19
22
|
modelId: model.modelId
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
|
-
(0, _validateModelFields.validateModelFields)(params);
|
|
25
|
+
await (0, _validateModelFields.validateModelFields)(params);
|
|
23
26
|
};
|
|
24
27
|
exports.validateModel = validateModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["validateModel","params","model","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsModel } from \"~/types\";\nimport {
|
|
1
|
+
{"version":3,"names":["validateModel","params","model","context","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsContext, CmsModel } from \"~/types\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModel = async (params: ValidateModelParams): Promise<void> => {\n const { model, context } = params;\n\n const { plugins } = context;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n await validateModelFields(params);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AAQO,MAAMA,aAAa,GAAG,MAAOC,MAA2B,IAAoB;EAC/E,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEjC,MAAM;IAAEG;EAAQ,CAAC,GAAGD,OAAO;EAE3B,MAAME,WAAW,GAAGD,OAAO,CACtBE,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKV,KAAK,CAACU,OAAO,CAAC;EAE9D,IAAIP,WAAW,EAAE;IACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;MACID,OAAO,EAAEV,KAAK,CAACU;IACnB,CAAC,CACJ;EACL;EAEA,MAAM,IAAAE,wCAAmB,EAACb,MAAM,CAAC;AACrC,CAAC;AAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CmsModel } from "../../types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
1
|
+
import { CmsContext, CmsModel } from "../../types";
|
|
3
2
|
interface ValidateModelFieldsParams {
|
|
4
3
|
model: CmsModel;
|
|
5
4
|
original?: CmsModel;
|
|
6
|
-
|
|
5
|
+
context: CmsContext;
|
|
7
6
|
}
|
|
8
|
-
export declare const validateModelFields: (params: ValidateModelFieldsParams) => void
|
|
7
|
+
export declare const validateModelFields: (params: ValidateModelFieldsParams) => Promise<void>;
|
|
9
8
|
export {};
|
|
@@ -10,6 +10,12 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
10
10
|
var _createManageSDL = require("../../graphql/schema/createManageSDL");
|
|
11
11
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
12
12
|
var _createFieldStorageId = require("./createFieldStorageId");
|
|
13
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
14
|
+
var _plugins = require("../../plugins");
|
|
15
|
+
var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
|
|
16
|
+
var _createExecutableSchema = require("../../graphql/createExecutableSchema");
|
|
17
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
18
|
+
var _utils = require("@webiny/utils");
|
|
13
19
|
const defaultTitleFieldId = "id";
|
|
14
20
|
const allowedTitleFieldTypes = ["text", "number"];
|
|
15
21
|
const getContentModelTitleFieldId = (fields, titleFieldId) => {
|
|
@@ -26,7 +32,7 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
|
|
|
26
32
|
*/
|
|
27
33
|
if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
|
|
28
34
|
const titleField = fields.find(field => {
|
|
29
|
-
return field
|
|
35
|
+
return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
|
|
30
36
|
});
|
|
31
37
|
return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
|
|
32
38
|
}
|
|
@@ -102,6 +108,22 @@ const extractInvalidField = (model, err) => {
|
|
|
102
108
|
message: [`Model "${model.modelId}" was not saved!`, message].join("\n")
|
|
103
109
|
};
|
|
104
110
|
};
|
|
111
|
+
const createValidateChildFields = plugins => {
|
|
112
|
+
return ({
|
|
113
|
+
fields,
|
|
114
|
+
originalFields
|
|
115
|
+
}) => {
|
|
116
|
+
if (fields.length === 0 && originalFields.length === 0) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
validateFields({
|
|
120
|
+
fields,
|
|
121
|
+
originalFields,
|
|
122
|
+
plugins,
|
|
123
|
+
lockedFields: []
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
};
|
|
105
127
|
const validateFields = params => {
|
|
106
128
|
const {
|
|
107
129
|
plugins,
|
|
@@ -109,14 +131,23 @@ const validateFields = params => {
|
|
|
109
131
|
originalFields,
|
|
110
132
|
lockedFields
|
|
111
133
|
} = params;
|
|
134
|
+
const idList = [];
|
|
112
135
|
const fieldIdList = [];
|
|
113
136
|
const storageIdList = [];
|
|
114
137
|
for (const field of fields) {
|
|
115
|
-
|
|
116
|
-
const plugin = plugins.find(
|
|
138
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
139
|
+
const plugin = plugins.find(plugin => plugin.fieldType === baseType);
|
|
117
140
|
if (!plugin) {
|
|
118
|
-
throw new Error(`Cannot update content model because of the unknown "${
|
|
141
|
+
throw new Error(`Cannot update content model because of the unknown "${baseType}" field.`);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check the field's id against existing ones.
|
|
145
|
+
* There cannot be two fields with the same id.
|
|
146
|
+
*/
|
|
147
|
+
if (idList.includes(field.id)) {
|
|
148
|
+
throw new _error.default(`Cannot update content model because field "${field.storageId || field.fieldId}" has id "${field.id}", which is already used.`);
|
|
119
149
|
}
|
|
150
|
+
idList.push(field.id);
|
|
120
151
|
const originalField = originalFields.find(f => f.id === field.id);
|
|
121
152
|
/**
|
|
122
153
|
* Field MUST have an fieldId defined.
|
|
@@ -140,7 +171,7 @@ const validateFields = params => {
|
|
|
140
171
|
* https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2
|
|
141
172
|
*/
|
|
142
173
|
const isLocked = lockedFields.some(lockedField => {
|
|
143
|
-
return lockedField.fieldId === field.storageId;
|
|
174
|
+
return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;
|
|
144
175
|
});
|
|
145
176
|
if (!field.storageId) {
|
|
146
177
|
/**
|
|
@@ -183,39 +214,66 @@ const validateFields = params => {
|
|
|
183
214
|
}
|
|
184
215
|
storageIdList.push(field.storageId);
|
|
185
216
|
/**
|
|
186
|
-
*
|
|
187
|
-
* We
|
|
188
|
-
* It must be recursive.
|
|
189
|
-
*/
|
|
190
|
-
if (field.type !== "object") {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
|
|
194
|
-
const originalChildFields = (originalField === null || originalField === void 0 ? void 0 : (_originalField$settin = originalField.settings) === null || _originalField$settin === void 0 ? void 0 : _originalField$settin.fields) || [];
|
|
195
|
-
/**
|
|
196
|
-
* No point in going further if there are no child fields.
|
|
197
|
-
* Code will break if child fields were removed but used in the entries.
|
|
217
|
+
* There might be some plugins which allow child fields.
|
|
218
|
+
* We use this method to validate them as well.
|
|
198
219
|
*/
|
|
199
|
-
if (
|
|
220
|
+
if (!plugin.validateChildFields) {
|
|
200
221
|
continue;
|
|
201
222
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
223
|
+
const validateChildFields = createValidateChildFields(plugins);
|
|
224
|
+
plugin.validateChildFields({
|
|
225
|
+
field,
|
|
226
|
+
originalField,
|
|
227
|
+
validate: validateChildFields
|
|
207
228
|
});
|
|
208
229
|
}
|
|
209
230
|
};
|
|
210
|
-
const
|
|
231
|
+
const createGraphQLSchema = async params => {
|
|
232
|
+
const {
|
|
233
|
+
context,
|
|
234
|
+
model
|
|
235
|
+
} = params;
|
|
236
|
+
context.security.disableAuthorization();
|
|
237
|
+
const models = await context.cms.listModels();
|
|
238
|
+
context.security.enableAuthorization();
|
|
239
|
+
const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
|
|
240
|
+
context,
|
|
241
|
+
models: models.concat([model])
|
|
242
|
+
});
|
|
243
|
+
const plugins = context.plugins.byType(_handlerGraphql.GraphQLSchemaPlugin.type).reduce((collection, plugin) => {
|
|
244
|
+
const name = plugin.name || `${plugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
|
|
245
|
+
collection[name] = plugin;
|
|
246
|
+
return collection;
|
|
247
|
+
}, {});
|
|
248
|
+
for (const plugin of modelPlugins) {
|
|
249
|
+
const name = plugin.name || `${plugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
|
|
250
|
+
plugins[name] = plugin;
|
|
251
|
+
}
|
|
252
|
+
return (0, _createExecutableSchema.createExecutableSchema)({
|
|
253
|
+
plugins: Object.values(plugins)
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
const extractErrorObject = error => {
|
|
257
|
+
return ["message", "code", "data", "stack"].reduce((output, key) => {
|
|
258
|
+
if (!error[key]) {
|
|
259
|
+
return output;
|
|
260
|
+
}
|
|
261
|
+
output[key] = error[key];
|
|
262
|
+
return output;
|
|
263
|
+
}, {});
|
|
264
|
+
};
|
|
265
|
+
const validateModelFields = async params => {
|
|
211
266
|
const {
|
|
212
267
|
model,
|
|
213
268
|
original,
|
|
214
|
-
|
|
269
|
+
context
|
|
215
270
|
} = params;
|
|
216
271
|
const {
|
|
217
272
|
titleFieldId
|
|
218
273
|
} = model;
|
|
274
|
+
const {
|
|
275
|
+
plugins
|
|
276
|
+
} = context;
|
|
219
277
|
|
|
220
278
|
/**
|
|
221
279
|
* There should be fields/locked fields in either model or data to be updated.
|
|
@@ -237,6 +295,7 @@ const validateModelFields = params => {
|
|
|
237
295
|
plugins: fieldTypePlugins
|
|
238
296
|
});
|
|
239
297
|
if (fields.length) {
|
|
298
|
+
const sorterPlugins = plugins.byType(_plugins.CmsGraphQLSchemaSorterPlugin.type);
|
|
240
299
|
/**
|
|
241
300
|
* Make sure that this model can be safely converted to a GraphQL SDL
|
|
242
301
|
*/
|
|
@@ -244,13 +303,32 @@ const validateModelFields = params => {
|
|
|
244
303
|
model,
|
|
245
304
|
fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, acc), {}, {
|
|
246
305
|
[pl.fieldType]: pl
|
|
247
|
-
}), {})
|
|
306
|
+
}), {}),
|
|
307
|
+
sorterPlugins
|
|
248
308
|
});
|
|
249
309
|
try {
|
|
250
310
|
(0, _graphqlTag.default)(schema);
|
|
251
311
|
} catch (err) {
|
|
252
312
|
throw new _error.default(extractInvalidField(model, err));
|
|
253
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
*
|
|
316
|
+
*/
|
|
317
|
+
try {
|
|
318
|
+
await createGraphQLSchema({
|
|
319
|
+
context,
|
|
320
|
+
model
|
|
321
|
+
});
|
|
322
|
+
} catch (err) {
|
|
323
|
+
throw new _error.default({
|
|
324
|
+
message: "Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.",
|
|
325
|
+
code: "GRAPHQL_SCHEMA_ERROR",
|
|
326
|
+
data: {
|
|
327
|
+
modelId: model.modelId,
|
|
328
|
+
error: extractErrorObject(err)
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
254
332
|
}
|
|
255
333
|
model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
|
|
256
334
|
const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
|
|
@@ -268,31 +346,26 @@ const validateModelFields = params => {
|
|
|
268
346
|
*/
|
|
269
347
|
if (!existingField) {
|
|
270
348
|
continue;
|
|
271
|
-
// throw new WebinyError(
|
|
272
|
-
// `Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`,
|
|
273
|
-
// "ENTRY_FIELD_USED",
|
|
274
|
-
// {
|
|
275
|
-
// lockedField,
|
|
276
|
-
// fields
|
|
277
|
-
// }
|
|
278
|
-
// );
|
|
279
349
|
}
|
|
280
|
-
|
|
281
350
|
if (lockedField.multipleValues !== existingField.multipleValues) {
|
|
282
351
|
throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
|
|
352
|
+
reason: `"multipleValues" changed`,
|
|
283
353
|
field: existingField
|
|
284
354
|
});
|
|
285
355
|
}
|
|
286
|
-
|
|
356
|
+
const fieldType = (0, _getBaseFieldType.getBaseFieldType)(existingField);
|
|
357
|
+
if (lockedField.type !== fieldType) {
|
|
287
358
|
throw new _error.default(`Cannot change field type for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
|
|
288
|
-
|
|
359
|
+
reason: `"type" changed`,
|
|
360
|
+
lockedFieldType: lockedField.type,
|
|
361
|
+
existingFieldType: fieldType
|
|
289
362
|
});
|
|
290
363
|
}
|
|
291
364
|
|
|
292
365
|
/**
|
|
293
366
|
* Check `lockedField` invariant for specific field
|
|
294
367
|
*/
|
|
295
|
-
const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType ===
|
|
368
|
+
const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === (0, _getBaseFieldType.getBaseFieldType)(lockedField));
|
|
296
369
|
for (const plugin of lockedFieldsByType) {
|
|
297
370
|
if (typeof plugin.checkLockedField !== "function") {
|
|
298
371
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","type","multipleValues","fieldId","target","f","WebinyError","includes","join","storageId","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","validateFields","params","plugins","originalFields","lockedFields","fieldIdList","storageIdList","plugin","item","fieldType","Error","originalField","id","isLocked","some","lockedField","createFieldStorageId","push","label","childFields","settings","originalChildFields","validateModelFields","original","fieldTypePlugins","byType","schema","createManageSDL","reduce","acc","pl","gql","cmsLockedFieldPlugins","existingField","lockedFieldsByType","filter","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport gql from \"graphql-tag\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return field.type === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const fieldIdList: string[] = [];\n\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const plugin = plugins.find(item => item.fieldType === field.type);\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${field.type}\" field.`\n );\n }\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * TODO maybe make this part pluginable?\n * We need to check the object field child fields.\n * It must be recursive.\n */\n if (field.type !== \"object\") {\n continue;\n }\n const childFields = field.settings?.fields || [];\n const originalChildFields = originalField?.settings?.fields || [];\n /**\n * No point in going further if there are no child fields.\n * Code will break if child fields were removed but used in the entries.\n */\n if (childFields.length === 0) {\n continue;\n }\n validateFields({\n fields: childFields,\n originalFields: originalChildFields,\n plugins,\n lockedFields: []\n });\n }\n};\n\ninterface ValidateModelFieldsParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\nexport const validateModelFields = (params: ValidateModelFieldsParams) => {\n const { model, original, plugins } = params;\n const { titleFieldId } = model;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n )\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n // throw new WebinyError(\n // `Cannot remove the field \"${lockedField.fieldId}\" because it's already in use in created content.`,\n // \"ENTRY_FIELD_USED\",\n // {\n // lockedField,\n // fields\n // }\n // );\n }\n\n if (lockedField.multipleValues !== existingField.multipleValues) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n field: existingField\n }\n );\n }\n\n if (lockedField.type !== existingField.type) {\n throw new WebinyError(\n `Cannot change field type for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n field: existingField\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === lockedField.type\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;;AAOA;AACA;AACA;AAEA;AAGA,MAAMA,mBAAmB,GAAG,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;AAEjD,MAAMC,2BAA2B,GAAG,CAACC,MAAuB,EAAEC,YAAqB,KAAa;EAC5F;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOL,mBAAmB;EAC9B;EACA;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACI,YAAY,IAAIA,YAAY,KAAKJ,mBAAmB,EAAE;IACvD,MAAMM,UAAU,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MACpC,OAAOA,KAAK,CAACC,IAAI,KAAK,MAAM,IAAI,CAACD,KAAK,CAACE,cAAc;IACzD,CAAC,CAAC;IAC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AIlB,WAAW,CAACjD,cAAc,KAAKmE,aAAa,CAACnE,cAAc,EAAE;MAC7D,MAAM,IAAII,cAAW,CAChB,2CAA0C6C,WAAW,CAAChD,OAAQ,yDAAwD,EACvH,kBAAkB,EAClB;QACIH,KAAK,EAAEqE;MACX,CAAC,CACJ;IACL;IAEA,IAAIlB,WAAW,CAAClD,IAAI,KAAKoE,aAAa,CAACpE,IAAI,EAAE;MACzC,MAAM,IAAIK,cAAW,CAChB,qCAAoC6C,WAAW,CAAChD,OAAQ,yDAAwD,EACjH,kBAAkB,EAClB;QACIH,KAAK,EAAEqE;MACX,CAAC,CACJ;IACL;;IAEA;AACR;AACA;IACQ,MAAMC,kBAAkB,GAAGF,qBAAqB,CAACG,MAAM,CACnDL,EAAE,IAAIA,EAAE,CAACrB,SAAS,KAAKM,WAAW,CAAClD,IAAI,CAC1C;IACD,KAAK,MAAM0C,MAAM,IAAI2B,kBAAkB,EAAE;MACrC,IAAI,OAAO3B,MAAM,CAAC6B,gBAAgB,KAAK,UAAU,EAAE;QAC/C;MACJ;MACA7B,MAAM,CAAC6B,gBAAgB,CAAC;QACpBrB,WAAW;QACXnD,KAAK,EAAEqE;MACX,CAAC,CAAC;IACN;EACJ;AACJ,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","getBaseFieldType","multipleValues","fieldId","target","f","WebinyError","includes","type","join","storageId","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","createValidateChildFields","plugins","originalFields","validateFields","lockedFields","params","idList","fieldIdList","storageIdList","baseType","plugin","fieldType","Error","id","push","originalField","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","security","disableAuthorization","models","cms","listModels","enableAuthorization","modelPlugins","buildSchemaPlugins","concat","byType","GraphQLSchemaPlugin","reduce","collection","name","generateAlphaNumericId","createExecutableSchema","Object","values","extractErrorObject","error","output","key","validateModelFields","original","fieldTypePlugins","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","acc","pl","gql","cmsLockedFieldPlugins","existingField","item","reason","lockedFieldType","existingFieldType","lockedFieldsByType","filter","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import {\n CmsContext,\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport gql from \"graphql-tag\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\nimport { buildSchemaPlugins } from \"~/graphql/buildSchemaPlugins\";\nimport { createExecutableSchema } from \"~/graphql/createExecutableSchema\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return getBaseFieldType(field) === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\nconst createValidateChildFields = (\n plugins: CmsModelFieldToGraphQLPlugin[]\n): CmsModelFieldToGraphQLPluginValidateChildFieldsValidate => {\n return ({ fields, originalFields }) => {\n if (fields.length === 0 && originalFields.length === 0) {\n return;\n }\n validateFields({\n fields,\n originalFields,\n plugins,\n lockedFields: []\n });\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const idList: string[] = [];\n const fieldIdList: string[] = [];\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const baseType = getBaseFieldType(field);\n const plugin = plugins.find(plugin => plugin.fieldType === baseType);\n\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${baseType}\" field.`\n );\n }\n /**\n * Check the field's id against existing ones.\n * There cannot be two fields with the same id.\n */\n if (idList.includes(field.id)) {\n throw new WebinyError(\n `Cannot update content model because field \"${\n field.storageId || field.fieldId\n }\" has id \"${field.id}\", which is already used.`\n );\n }\n idList.push(field.id);\n\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * There might be some plugins which allow child fields.\n * We use this method to validate them as well.\n */\n if (!plugin.validateChildFields) {\n continue;\n }\n const validateChildFields = createValidateChildFields(plugins);\n plugin.validateChildFields({\n field,\n originalField,\n validate: validateChildFields\n });\n }\n};\ninterface CreateGraphQLSchemaParams {\n context: CmsContext;\n model: CmsModel;\n}\nconst createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {\n const { context, model } = params;\n\n context.security.disableAuthorization();\n const models = await context.cms.listModels();\n context.security.enableAuthorization();\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: models.concat([model])\n });\n\n const plugins = context.plugins\n .byType<GraphQLSchemaPlugin<CmsContext>>(GraphQLSchemaPlugin.type)\n .reduce<Record<string, GraphQLSchemaPlugin<CmsContext>>>((collection, plugin) => {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n collection[name] = plugin;\n return collection;\n }, {});\n for (const plugin of modelPlugins) {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n plugins[name] = plugin;\n }\n\n return createExecutableSchema({\n plugins: Object.values(plugins)\n });\n};\n\nconst extractErrorObject = (error: any) => {\n return [\"message\", \"code\", \"data\", \"stack\"].reduce<Record<string, any>>((output, key) => {\n if (!error[key]) {\n return output;\n }\n output[key] = error[key];\n return output;\n }, {});\n};\n\ninterface ValidateModelFieldsParams {\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\nexport const validateModelFields = async (params: ValidateModelFieldsParams): Promise<void> => {\n const { model, original, context } = params;\n const { titleFieldId } = model;\n const { plugins } = context;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n const sorterPlugins = plugins.byType<CmsGraphQLSchemaSorterPlugin>(\n CmsGraphQLSchemaSorterPlugin.type\n );\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n ),\n sorterPlugins\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n /**\n *\n */\n try {\n await createGraphQLSchema({\n context,\n model\n });\n } catch (err) {\n throw new WebinyError({\n message:\n \"Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.\",\n code: \"GRAPHQL_SCHEMA_ERROR\",\n data: {\n modelId: model.modelId,\n error: extractErrorObject(err)\n }\n });\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n }\n\n if (lockedField.multipleValues !== existingField.multipleValues) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n reason: `\"multipleValues\" changed`,\n field: existingField\n }\n );\n }\n\n const fieldType = getBaseFieldType(existingField);\n if (lockedField.type !== fieldType) {\n throw new WebinyError(\n `Cannot change field type for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n reason: `\"type\" changed`,\n lockedFieldType: lockedField.type,\n existingFieldType: fieldType\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === getBaseFieldType(lockedField)\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;;AASA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;AAEjD,MAAMC,2BAA2B,GAAG,CAACC,MAAuB,EAAEC,YAAqB,KAAa;EAC5F;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOL,mBAAmB;EAC9B;EACA;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACI,YAAY,IAAIA,YAAY,KAAKJ,mBAAmB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