@webiny/api-headless-cms 5.32.0 → 5.33.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.
Files changed (108) hide show
  1. package/crud/contentEntry/entryDataValidation.js +1 -0
  2. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  3. package/crud/contentEntry/markLockedFields.js +2 -2
  4. package/crud/contentEntry/markLockedFields.js.map +1 -1
  5. package/crud/contentEntry.crud.js +170 -60
  6. package/crud/contentEntry.crud.js.map +1 -1
  7. package/crud/contentModel/beforeCreate.js +11 -4
  8. package/crud/contentModel/beforeCreate.js.map +1 -1
  9. package/crud/contentModel/beforeDelete.js +6 -1
  10. package/crud/contentModel/beforeDelete.js.map +1 -1
  11. package/crud/contentModel/beforeUpdate.js +18 -4
  12. package/crud/contentModel/beforeUpdate.js.map +1 -1
  13. package/crud/contentModel/createFieldStorageId.d.ts +2 -0
  14. package/crud/contentModel/createFieldStorageId.js +16 -0
  15. package/crud/contentModel/createFieldStorageId.js.map +1 -0
  16. package/crud/contentModel/fieldIdValidation.d.ts +1 -0
  17. package/crud/contentModel/fieldIdValidation.js +25 -0
  18. package/crud/contentModel/fieldIdValidation.js.map +1 -0
  19. package/crud/contentModel/models.js +9 -8
  20. package/crud/contentModel/models.js.map +1 -1
  21. package/crud/contentModel/systemFields.d.ts +1 -0
  22. package/crud/contentModel/systemFields.js +8 -0
  23. package/crud/contentModel/systemFields.js.map +1 -0
  24. package/crud/contentModel/validateLayout.d.ts +1 -1
  25. package/crud/contentModel/validateLayout.js +1 -2
  26. package/crud/contentModel/validateLayout.js.map +1 -1
  27. package/crud/contentModel/validateModel.d.ts +9 -0
  28. package/crud/contentModel/validateModel.js +32 -0
  29. package/crud/contentModel/validateModel.js.map +1 -0
  30. package/crud/contentModel/validateModelFields.d.ts +3 -2
  31. package/crud/contentModel/validateModelFields.js +200 -38
  32. package/crud/contentModel/validateModelFields.js.map +1 -1
  33. package/crud/contentModel.crud.js +59 -5
  34. package/crud/contentModel.crud.js.map +1 -1
  35. package/crud/contentModelGroup/beforeCreate.js +3 -3
  36. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  37. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.d.ts +7 -0
  38. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +66 -0
  39. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -0
  40. package/fieldConverters/CmsModelObjectFieldConverterPlugin.d.ts +11 -0
  41. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +306 -0
  42. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -0
  43. package/fieldConverters/index.d.ts +3 -0
  44. package/fieldConverters/index.js +16 -0
  45. package/fieldConverters/index.js.map +1 -0
  46. package/graphql/index.d.ts +1 -1
  47. package/graphql/schema/contentModels.js +6 -0
  48. package/graphql/schema/contentModels.js.map +1 -1
  49. package/graphql/schema/createFieldResolvers.js +13 -1
  50. package/graphql/schema/createFieldResolvers.js.map +1 -1
  51. package/graphql/schema/createReadSDL.js +3 -2
  52. package/graphql/schema/createReadSDL.js.map +1 -1
  53. package/graphql/schema/schemaPlugins.js +7 -1
  54. package/graphql/schema/schemaPlugins.js.map +1 -1
  55. package/graphqlFields/datetime.js +6 -1
  56. package/graphqlFields/datetime.js.map +1 -1
  57. package/graphqlFields/helpers.js +1 -1
  58. package/graphqlFields/helpers.js.map +1 -1
  59. package/graphqlFields/object.js +1 -1
  60. package/graphqlFields/object.js.map +1 -1
  61. package/index.d.ts +2 -2
  62. package/index.js +3 -1
  63. package/index.js.map +1 -1
  64. package/package.json +24 -24
  65. package/plugins/CmsGroupPlugin.d.ts +1 -1
  66. package/plugins/CmsGroupPlugin.js.map +1 -1
  67. package/plugins/CmsModelFieldConverterPlugin.d.ts +14 -0
  68. package/plugins/CmsModelFieldConverterPlugin.js +17 -0
  69. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -0
  70. package/plugins/CmsModelPlugin.d.ts +32 -4
  71. package/plugins/CmsModelPlugin.js +160 -1
  72. package/plugins/CmsModelPlugin.js.map +1 -1
  73. package/plugins/index.d.ts +1 -0
  74. package/plugins/index.js +13 -0
  75. package/plugins/index.js.map +1 -1
  76. package/types.d.ts +143 -81
  77. package/types.js +24 -0
  78. package/types.js.map +1 -1
  79. package/upgrades/5.33.0/index.d.ts +3 -0
  80. package/upgrades/5.33.0/index.js +186 -0
  81. package/upgrades/5.33.0/index.js.map +1 -0
  82. package/upgrades/index.d.ts +1 -1
  83. package/upgrades/index.js +3 -1
  84. package/upgrades/index.js.map +1 -1
  85. package/utils/converters/Converter.d.ts +27 -0
  86. package/utils/converters/Converter.js +71 -0
  87. package/utils/converters/Converter.js.map +1 -0
  88. package/utils/converters/ConverterCollection.d.ts +24 -0
  89. package/utils/converters/ConverterCollection.js +115 -0
  90. package/utils/converters/ConverterCollection.js.map +1 -0
  91. package/utils/converters/valueKeyStorageConverter.d.ts +18 -0
  92. package/utils/converters/valueKeyStorageConverter.js +152 -0
  93. package/utils/converters/valueKeyStorageConverter.js.map +1 -0
  94. package/utils/filterModelFields.d.ts +16 -0
  95. package/utils/filterModelFields.js +81 -0
  96. package/utils/filterModelFields.js.map +1 -0
  97. package/utils/getEntryTitle.js +6 -5
  98. package/utils/getEntryTitle.js.map +1 -1
  99. package/utils/ownership.js +4 -2
  100. package/utils/ownership.js.map +1 -1
  101. package/utils/renderGetFilterFields.js +3 -3
  102. package/utils/renderGetFilterFields.js.map +1 -1
  103. package/utils/renderListFilterFields.js +6 -5
  104. package/utils/renderListFilterFields.js.map +1 -1
  105. package/utils/renderSortEnum.js +4 -4
  106. package/utils/renderSortEnum.js.map +1 -1
  107. package/validators/unique.js +1 -0
  108. package/validators/unique.js.map +1 -1
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateFieldId = void 0;
7
+
8
+ var _validation = require("@webiny/validation");
9
+
10
+ var _systemFields = require("./systemFields");
11
+
12
+ const validateFieldId = async input => {
13
+ await _validation.validation.validate(input, "required,maxLength:100");
14
+ const value = String(input || "").trim();
15
+
16
+ if (!value.charAt(0).match(/^[a-zA-Z]/)) {
17
+ throw new Error(`Provided ${value} is not valid - must not start with a number.`);
18
+ } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {
19
+ throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);
20
+ } else if (_systemFields.fieldSystemFields.includes(value)) {
21
+ throw new Error(`Provided ${value} is not valid - "${value}" is an auto-generated field.`);
22
+ }
23
+ };
24
+
25
+ exports.validateFieldId = validateFieldId;
@@ -0,0 +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":";;;;;;;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"}
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -9,13 +7,11 @@ exports.UpdateContentModelModel = exports.CreateContentModelModelFrom = exports.
9
7
 
10
8
  var _validation = require("@webiny/validation");
11
9
 
12
- var _flow = _interopRequireDefault(require("lodash/flow"));
13
-
14
10
  var _commodoFieldsObject = require("commodo-fields-object");
15
11
 
16
12
  var _fields = require("@commodo/fields");
17
13
 
18
- var _idValidation = require("./idValidation");
14
+ var _fieldIdValidation = require("./fieldIdValidation");
19
15
 
20
16
  /**
21
17
  * Package commodo-fields-object does not have types
@@ -39,9 +35,9 @@ const ContentModelFieldModel = (0, _fields.withFields)({
39
35
  id: (0, _fields.string)({
40
36
  validation: requiredShortString
41
37
  }),
42
- fieldId: (0, _flow.default)((0, _fields.onSet)(value => value && value.trim()), (0, _fields.setOnce)())((0, _fields.string)({
43
- validation: _idValidation.validateId
44
- })),
38
+ fieldId: (0, _fields.string)({
39
+ validation: _fieldIdValidation.validateFieldId
40
+ }),
45
41
  label: (0, _fields.string)({
46
42
  validation: requiredShortString
47
43
  }),
@@ -109,6 +105,11 @@ const ContentModelFieldModel = (0, _fields.withFields)({
109
105
  settings: (0, _commodoFieldsObject.object)({
110
106
  value: {}
111
107
  })
108
+ /**
109
+ * By the default, field is not deleted.
110
+ */
111
+ // isDeleted: boolean({ value: false })
112
+
112
113
  })();
113
114
  exports.ContentModelFieldModel = ContentModelFieldModel;
114
115
  const CreateContentModelModel = (0, _fields.withFields)({
@@ -1 +1 @@
1
- {"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","flow","onSet","value","trim","setOnce","validateId","label","helpText","placeholderText","type","multipleValues","boolean","predefinedValues","fields","instanceOf","enabled","values","list","selected","renderer","message","settings","object","listValidation","CreateContentModelModel","modelId","description","group","required","layout","CreateContentModelModelFrom","locale","UpdateContentModelModel","titleFieldId"],"sources":["models.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport flow from \"lodash/flow\";\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, onSet, boolean, fields } from \"@commodo/fields\";\nimport { validateId } from \"./idValidation\";\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: flow(\n onSet((value?: string) => value && value.trim()),\n setOnce()\n )(string({ validation: validateId })),\n label: string({ validation: requiredShortString }),\n helpText: string({ validation: shortString }),\n placeholderText: string({ validation: shortString }),\n type: setOnce()(string({ validation: requiredShortString })),\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\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})();\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})();\n"],"mappings":";;;;;;;;;AAAA;;AACA;;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,IAAAC,aAAA,EACL,IAAAC,aAAA,EAAOC,KAAD,IAAoBA,KAAK,IAAIA,KAAK,CAACC,IAAN,EA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AAP;AANsC,CAAX,GAAhC"}
1
+ {"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","validateFieldId","label","helpText","placeholderText","type","setOnce","multipleValues","boolean","value","predefinedValues","fields","instanceOf","enabled","values","list","selected","renderer","message","settings","object","listValidation","CreateContentModelModel","modelId","description","group","required","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 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})();\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})();\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,IAA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;EAAd,CAAP,CAD4C;EAElDiC,OAAO,EAAE,IAAA1B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAFyC;EAGlD+B,WAAW,EAAE,IAAA3B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHqC;EAIlDgC,KAAK,EAAE,IAAA5B,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAJ2C;EAKlDuC,MAAM,EAAE,IAAAhC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP;AAL0C,CAAX,GAApC;;AAQA,MAAMqC,uBAAuB,GAAG,IAAAnC,kBAAA,EAAW;EAC9CC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CADwC;EAE9C+B,WAAW,EAAE,IAAA3B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAFiC;EAG9CgC,KAAK,EAAE,IAAA5B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHuC;EAI9CsC,YAAY,EAAE,IAAAlC,cAAA,GAJgC;EAK9Cc,MAAM,EAAE,IAAAA,cAAA,EAAO;IAAEC,UAAU,EAAEd,sBAAd;IAAsCW,KAAK,EAAE,EAA7C;IAAiDM,IAAI,EAAE,IAAvD;IAA6DW,QAAQ,EAAE;EAAvE,CAAP,CALsC;EAM9CC,MAAM,EAAE,IAAAP,2BAAA,EAAO;IAAEX,KAAK,EAAE,EAAT;IAAaiB,QAAQ,EAAE;EAAvB,CAAP;AANsC,CAAX,GAAhC"}
@@ -0,0 +1 @@
1
+ export declare const fieldSystemFields: string[];
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fieldSystemFields = void 0;
7
+ const fieldSystemFields = ["id", "fieldId", "storageId", "label", "helpText", "placeholderText", "type", "multipleValues", "predefinedValues", "renderer", "validation", "listValidation", "settings"];
8
+ exports.fieldSystemFields = fieldSystemFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fieldSystemFields"],"sources":["systemFields.ts"],"sourcesContent":["export const fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n"],"mappings":";;;;;;AAAO,MAAMA,iBAA2B,GAAG,CACvC,IADuC,EAEvC,SAFuC,EAGvC,WAHuC,EAIvC,OAJuC,EAKvC,UALuC,EAMvC,iBANuC,EAOvC,MAPuC,EAQvC,gBARuC,EASvC,kBATuC,EAUvC,UAVuC,EAWvC,YAXuC,EAYvC,gBAZuC,EAavC,UAbuC,CAApC"}
@@ -1,2 +1,2 @@
1
1
  import { CmsModelField, CmsModel } from "../../types";
2
- export declare const validateLayout: (model: CmsModel, fields?: CmsModelField[]) => void;
2
+ export declare const validateLayout: (layout: CmsModel["layout"], fields?: CmsModelField[]) => void;
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.validateLayout = void 0;
7
7
 
8
- const validateLayout = (model, fields = []) => {
9
- const layout = model.layout || [];
8
+ const validateLayout = (layout, fields = []) => {
10
9
  const flatLayoutIdList = layout.reduce((acc, id) => {
11
10
  return acc.concat(Array.isArray(id) ? id : [id]);
12
11
  }, []);
@@ -1 +1 @@
1
- {"version":3,"names":["validateLayout","model","fields","layout","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (model: CmsModel, fields: CmsModelField[] = []): void => {\n const layout = model.layout || [];\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,KAAD,EAAkBC,MAAuB,GAAG,EAA5C,KAAyD;EACnF,MAAMC,MAAM,GAAGF,KAAK,CAACE,MAAN,IAAgB,EAA/B;EACA,MAAMC,gBAAgB,GAAGD,MAAM,CAACE,MAAP,CAAc,CAACC,GAAD,EAAMC,EAAN,KAAa;IAChD,OAAOD,GAAG,CAACE,MAAJ,CAAWC,KAAK,CAACC,OAAN,CAAcH,EAAd,IAAoBA,EAApB,GAAyB,CAACA,EAAD,CAApC,CAAP;EACH,CAFwB,EAEtB,EAFsB,CAAzB;;EAGA,IAAIH,gBAAgB,CAACO,MAAjB,KAA4BT,MAAM,CAACS,MAAvC,EAA+C;IAC3C,MAAM,IAAIC,KAAJ,CACD,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBT,MAAM,CAACS,MAAO,yDAD1E,CAAN;EAGH;;EACD,KAAK,MAAME,KAAX,IAAoBX,MAApB,EAA4B;IACxB,IAAIE,gBAAgB,CAACU,QAAjB,CAA0BD,KAAK,CAACN,EAAhC,CAAJ,EAAyC;MACrC;IACH;;IACD,MAAM,IAAIK,KAAJ,CAAW,UAASC,KAAK,CAACN,EAAG,6BAA7B,CAAN;EACH;;EACD,KAAK,MAAMA,EAAX,IAAiBH,gBAAjB,EAAmC;IAC/B,MAAMW,UAAU,GAAGb,MAAM,CAACc,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACV,EAAF,KAASA,EAA1B,CAAnB;;IACA,IAAIQ,UAAJ,EAAgB;MACZ;IACH;;IACD,MAAM,IAAIH,KAAJ,CAAW,aAAYL,EAAG,mCAA1B,CAAN;EACH;AACJ,CAvBM"}
1
+ {"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,MAAD,EAA6BC,MAAuB,GAAG,EAAvD,KAAoE;EAC9F,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAP,CAAc,CAACC,GAAD,EAAMC,EAAN,KAAa;IAChD,OAAOD,GAAG,CAACE,MAAJ,CAAWC,KAAK,CAACC,OAAN,CAAcH,EAAd,IAAoBA,EAApB,GAAyB,CAACA,EAAD,CAApC,CAAP;EACH,CAFwB,EAEtB,EAFsB,CAAzB;;EAGA,IAAIH,gBAAgB,CAACO,MAAjB,KAA4BR,MAAM,CAACQ,MAAvC,EAA+C;IAC3C,MAAM,IAAIC,KAAJ,CACD,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAD1E,CAAN;EAGH;;EACD,KAAK,MAAME,KAAX,IAAoBV,MAApB,EAA4B;IACxB,IAAIC,gBAAgB,CAACU,QAAjB,CAA0BD,KAAK,CAACN,EAAhC,CAAJ,EAAyC;MACrC;IACH;;IACD,MAAM,IAAIK,KAAJ,CAAW,UAASC,KAAK,CAACN,EAAG,6BAA7B,CAAN;EACH;;EACD,KAAK,MAAMA,EAAX,IAAiBH,gBAAjB,EAAmC;IAC/B,MAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACV,EAAF,KAASA,EAA1B,CAAnB;;IACA,IAAIQ,UAAJ,EAAgB;MACZ;IACH;;IACD,MAAM,IAAIH,KAAJ,CAAW,aAAYL,EAAG,mCAA1B,CAAN;EACH;AACJ,CAtBM"}
@@ -0,0 +1,9 @@
1
+ import { CmsModel } from "../../types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ interface ValidateModelParams {
4
+ model: CmsModel;
5
+ original?: CmsModel;
6
+ plugins: PluginsContainer;
7
+ }
8
+ export declare const validateModel: (params: ValidateModelParams) => void;
9
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.validateModel = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
+
14
+ var _validateModelFields = require("./validateModelFields");
15
+
16
+ const validateModel = params => {
17
+ const {
18
+ model,
19
+ plugins
20
+ } = params;
21
+ const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
22
+
23
+ if (modelPlugin) {
24
+ throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
25
+ modelId: model.modelId
26
+ });
27
+ }
28
+
29
+ (0, _validateModelFields.validateModelFields)(params);
30
+ };
31
+
32
+ exports.validateModel = validateModel;
@@ -0,0 +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 { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\n\nexport const validateModel = (params: ValidateModelParams) => {\n const { model, plugins } = params;\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 validateModelFields(params);\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAGA;;AAQO,MAAMA,aAAa,GAAIC,MAAD,IAAiC;EAC1D,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EAEA,MAAMG,WAAW,GAAGD,OAAO,CACtBE,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,YAAL,CAAkBC,OAAlB,KAA8BT,KAAK,CAACS,OAFlC,CAApB;;EAIA,IAAIP,WAAJ,EAAiB;IACb,MAAM,IAAIQ,cAAJ,CACF,uDADE,EAEF,4BAFE,EAGF;MACID,OAAO,EAAET,KAAK,CAACS;IADnB,CAHE,CAAN;EAOH;;EAED,IAAAE,wCAAA,EAAoBZ,MAApB;AACH,CAlBM"}
@@ -1,8 +1,9 @@
1
1
  import { CmsModel } from "../../types";
2
2
  import { PluginsContainer } from "@webiny/plugins";
3
- interface ValidateModelParams {
3
+ interface ValidateModelFieldsParams {
4
4
  model: CmsModel;
5
+ original?: CmsModel;
5
6
  plugins: PluginsContainer;
6
7
  }
7
- export declare const validateModelFields: (params: ValidateModelParams) => Promise<void>;
8
+ export declare const validateModelFields: (params: ValidateModelFieldsParams) => void;
8
9
  export {};
@@ -9,14 +9,14 @@ exports.validateModelFields = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
12
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
-
14
12
  var _error = _interopRequireDefault(require("@webiny/error"));
15
13
 
16
- var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
17
-
18
14
  var _createManageSDL = require("../../graphql/schema/createManageSDL");
19
15
 
16
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
17
+
18
+ var _createFieldStorageId = require("./createFieldStorageId");
19
+
20
20
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
21
 
22
22
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -25,23 +25,36 @@ const defaultTitleFieldId = "id";
25
25
  const allowedTitleFieldTypes = ["text", "number"];
26
26
 
27
27
  const getContentModelTitleFieldId = (fields, titleFieldId) => {
28
- // if there is no title field defined either in input data or existing content model data
29
- // we will take first text field that has no multiple values enabled
30
- // or if initial titleFieldId is the default one also try to find first available text field
28
+ /**
29
+ * If there are no fields defined, we will return the default field
30
+ */
31
+ if (fields.length === 0) {
32
+ return defaultTitleFieldId;
33
+ }
34
+ /**
35
+ * if there is no title field defined either in input data or existing content model data
36
+ * we will take first text field that has no multiple values enabled
37
+ * or if initial titleFieldId is the default one also try to find first available text field
38
+ */
39
+
40
+
31
41
  if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
32
42
  const titleField = fields.find(field => {
33
43
  return field.type === "text" && !field.multipleValues;
34
44
  });
35
- return titleField ? titleField.fieldId : defaultTitleFieldId;
36
- } // check existing titleFieldId for existence in the model
37
- // for correct type
38
- // and that it is not multiple values field
45
+ return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
46
+ }
47
+ /**
48
+ * check existing titleFieldId for existence in the model
49
+ * for correct type
50
+ * and that it is not multiple values field
51
+ */
39
52
 
40
53
 
41
54
  const target = fields.find(f => f.fieldId === titleFieldId);
42
55
 
43
56
  if (!target) {
44
- throw new _error.default(`Field does not exist in the model.`, "VALIDATION_ERROR", {
57
+ throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
45
58
  fieldId: titleFieldId,
46
59
  fields
47
60
  });
@@ -49,6 +62,7 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
49
62
 
50
63
  if (allowedTitleFieldTypes.includes(target.type) === false) {
51
64
  throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
65
+ storageId: target.storageId,
52
66
  fieldId: target.fieldId,
53
67
  type: target.type
54
68
  });
@@ -56,6 +70,7 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
56
70
 
57
71
  if (target.multipleValues) {
58
72
  throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
73
+ storageId: target.storageId,
59
74
  fieldId: target.fieldId,
60
75
  type: target.type
61
76
  });
@@ -67,7 +82,10 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
67
82
  const extractInvalidField = (model, err) => {
68
83
  var _err$source;
69
84
 
70
- const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || ""; // Find the invalid type
85
+ const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
86
+ /**
87
+ * Find the invalid type
88
+ */
71
89
 
72
90
  const {
73
91
  line: lineNumber
@@ -115,41 +133,163 @@ const extractInvalidField = (model, err) => {
115
133
  };
116
134
  };
117
135
 
118
- const validateModelFields = async params => {
136
+ const validateFields = params => {
119
137
  const {
120
- model,
121
- plugins
138
+ plugins,
139
+ fields,
140
+ originalFields,
141
+ lockedFields
122
142
  } = params;
123
- const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
143
+ const fieldIdList = [];
144
+ const storageIdList = [];
145
+
146
+ for (const field of fields) {
147
+ var _field$settings, _originalField$settin;
148
+
149
+ const plugin = plugins.find(item => item.fieldType === field.type);
150
+
151
+ if (!plugin) {
152
+ throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
153
+ }
154
+
155
+ const originalField = originalFields.find(f => f.id === field.id);
156
+ /**
157
+ * Field MUST have an fieldId defined.
158
+ */
159
+
160
+ if (!field.fieldId) {
161
+ throw new _error.default(`Field does not have an "fieldId" defined.`, "MISSING_FIELD_ID", {
162
+ field
163
+ });
164
+ }
165
+ /**
166
+ * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.
167
+ * This is to avoid errors in the already installed systems.
168
+ *
169
+ * Why are we using the @?
170
+ *
171
+ * It is not part of special characters for the query syntax in the Lucene.
172
+ *
173
+ * Relevant links:
174
+ * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html
175
+ * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3
176
+ * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2
177
+ */
178
+
179
+
180
+ const isLocked = lockedFields.some(lockedField => {
181
+ return lockedField.fieldId === field.storageId;
182
+ });
183
+
184
+ if (!field.storageId) {
185
+ /**
186
+ * In case field is locked, we must set the storageId to the fieldId value.
187
+ * 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.
188
+ */
189
+ //
190
+ if (isLocked) {
191
+ field.storageId = field.fieldId;
192
+ }
193
+ /**
194
+ * When having original field, just set the storageId to value from the originalField
195
+ */
196
+ //
197
+ else if (originalField) {
198
+ field.storageId = originalField.storageId;
199
+ }
200
+ /**
201
+ * The last case is when no original field and not locked - so this is a completely new field.
202
+ */
203
+ //
204
+ else {
205
+ field.storageId = (0, _createFieldStorageId.createFieldStorageId)(field);
206
+ }
207
+ }
208
+ /**
209
+ * Check the field's fieldId against existing ones.
210
+ * There cannot be two fields with the same fieldId - outside world identifier.
211
+ */
124
212
 
125
- if (modelPlugin) {
126
- throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
127
- modelId: model.modelId
213
+
214
+ if (fieldIdList.includes(field.fieldId)) {
215
+ throw new _error.default(`Cannot update content model because field "${field.storageId}" has fieldId "${field.fieldId}", which is already used.`);
216
+ }
217
+
218
+ fieldIdList.push(field.fieldId);
219
+ /**
220
+ * Check the field's storageId against the existing ones.
221
+ * There cannot be two fields with the same storageId.
222
+ */
223
+
224
+ if (storageIdList.includes(field.storageId)) {
225
+ throw new _error.default(`Cannot update content model because field "${field.label}" has storageId "${field.storageId}", which is already used.`);
226
+ }
227
+
228
+ storageIdList.push(field.storageId);
229
+ /**
230
+ * TODO maybe make this part pluginable?
231
+ * We need to check the object field child fields.
232
+ * It must be recursive.
233
+ */
234
+
235
+ if (field.type !== "object") {
236
+ continue;
237
+ }
238
+
239
+ const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
240
+ const originalChildFields = (originalField === null || originalField === void 0 ? void 0 : (_originalField$settin = originalField.settings) === null || _originalField$settin === void 0 ? void 0 : _originalField$settin.fields) || [];
241
+ /**
242
+ * No point in going further if there are no child fields.
243
+ * Code will break if child fields were removed but used in the entries.
244
+ */
245
+
246
+ if (childFields.length === 0) {
247
+ continue;
248
+ }
249
+
250
+ validateFields({
251
+ fields: childFields,
252
+ originalFields: originalChildFields,
253
+ plugins,
254
+ lockedFields: []
128
255
  });
129
256
  }
257
+ };
130
258
 
259
+ const validateModelFields = params => {
260
+ const {
261
+ model,
262
+ original,
263
+ plugins
264
+ } = params;
131
265
  const {
132
266
  titleFieldId
133
- } = model; // There should be fields/locked fields in either model or data to be updated.
267
+ } = model;
268
+ /**
269
+ * There should be fields/locked fields in either model or data to be updated.
270
+ */
134
271
 
135
272
  const {
136
273
  fields = [],
137
274
  lockedFields = []
138
- } = model; // Let's inspect the fields of the received content model. We prevent saving of a content model if it
139
- // contains a field for which a "cms-model-field-to-graphql" plugin does not exist on the backend.
275
+ } = model;
276
+ /**
277
+ * Let's inspect the fields of the received content model. We prevent saving of a content model if it
278
+ * contains a field for which a "cms-model-field-to-graphql" plugin does not exist on the backend.
279
+ */
140
280
 
141
281
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
142
-
143
- for (let i = 0; i < fields.length; i++) {
144
- const field = fields[i];
145
-
146
- if (!fieldTypePlugins.find(item => item.fieldType === field.type)) {
147
- throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
148
- }
149
- }
282
+ validateFields({
283
+ fields,
284
+ originalFields: (original === null || original === void 0 ? void 0 : original.fields) || [],
285
+ lockedFields,
286
+ plugins: fieldTypePlugins
287
+ });
150
288
 
151
289
  if (fields.length) {
152
- // Make sure that this model can be safely converted to a GraphQL SDL
290
+ /**
291
+ * Make sure that this model can be safely converted to a GraphQL SDL
292
+ */
153
293
  const schema = (0, _createManageSDL.createManageSDL)({
154
294
  model,
155
295
  fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => _objectSpread(_objectSpread({}, acc), {}, {
@@ -165,22 +305,44 @@ const validateModelFields = async params => {
165
305
  }
166
306
 
167
307
  model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
168
- const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field"); // We must not allow removal or changes in fields that are already in use in content entries.
308
+ const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
309
+ /**
310
+ * We must not allow removal or changes in fields that are already in use in content entries.
311
+ * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.
312
+ */
169
313
 
170
314
  for (const lockedField of lockedFields) {
171
- const existingField = fields.find(item => item.fieldId === lockedField.fieldId);
315
+ const existingField = fields.find(item => item.storageId === lockedField.fieldId);
316
+ /**
317
+ * Starting with 5.33.0 fields can be deleted.
318
+ * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.
319
+ */
172
320
 
173
321
  if (!existingField) {
174
- throw new _error.default(`Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`, "ENTRY_FIELD_USED");
322
+ continue; // throw new WebinyError(
323
+ // `Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`,
324
+ // "ENTRY_FIELD_USED",
325
+ // {
326
+ // lockedField,
327
+ // fields
328
+ // }
329
+ // );
175
330
  }
176
331
 
177
332
  if (lockedField.multipleValues !== existingField.multipleValues) {
178
- throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED");
333
+ throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
334
+ field: existingField
335
+ });
179
336
  }
180
337
 
181
338
  if (lockedField.type !== existingField.type) {
182
- 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");
183
- } // Check `lockedField` invariant for specific field
339
+ 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", {
340
+ field: existingField
341
+ });
342
+ }
343
+ /**
344
+ * Check `lockedField` invariant for specific field
345
+ */
184
346
 
185
347
 
186
348
  const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === lockedField.type);