@webiny/api-headless-cms 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97

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 (296) hide show
  1. package/context.d.ts +5 -2
  2. package/context.js +61 -8
  3. package/context.js.map +1 -1
  4. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  5. package/crud/contentEntry/markLockedFields.js +17 -4
  6. package/crud/contentEntry/markLockedFields.js.map +1 -1
  7. package/crud/contentEntry/referenceFieldsMapping.js +40 -9
  8. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  9. package/crud/contentEntry/searchableFields.d.ts +9 -0
  10. package/crud/contentEntry/searchableFields.js +72 -0
  11. package/crud/contentEntry/searchableFields.js.map +1 -0
  12. package/crud/contentEntry.crud.d.ts +8 -5
  13. package/crud/contentEntry.crud.js +1081 -841
  14. package/crud/contentEntry.crud.js.map +1 -1
  15. package/crud/contentModel/beforeCreate.d.ts +2 -3
  16. package/crud/contentModel/beforeCreate.js +43 -81
  17. package/crud/contentModel/beforeCreate.js.map +1 -1
  18. package/crud/contentModel/beforeDelete.d.ts +1 -1
  19. package/crud/contentModel/beforeDelete.js +1 -5
  20. package/crud/contentModel/beforeDelete.js.map +1 -1
  21. package/crud/contentModel/beforeUpdate.d.ts +2 -4
  22. package/crud/contentModel/beforeUpdate.js +33 -5
  23. package/crud/contentModel/beforeUpdate.js.map +1 -1
  24. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  25. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  26. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  27. package/crud/contentModel/createFieldStorageId.js +4 -1
  28. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  29. package/crud/contentModel/defaultFields.d.ts +5 -0
  30. package/crud/contentModel/defaultFields.js +58 -0
  31. package/crud/contentModel/defaultFields.js.map +1 -0
  32. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  33. package/crud/contentModel/fields/descriptionField.js +42 -0
  34. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  35. package/crud/contentModel/fields/imageField.d.ts +2 -0
  36. package/crud/contentModel/fields/imageField.js +46 -0
  37. package/crud/contentModel/fields/imageField.js.map +1 -0
  38. package/crud/contentModel/fields/titleField.d.ts +2 -0
  39. package/crud/contentModel/fields/titleField.js +58 -0
  40. package/crud/contentModel/fields/titleField.js.map +1 -0
  41. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  42. package/crud/contentModel/validate/endingAllowed.js +26 -0
  43. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  44. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  45. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  46. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  47. package/crud/contentModel/validate/modelId.d.ts +11 -0
  48. package/crud/contentModel/validate/modelId.js +36 -0
  49. package/crud/contentModel/validate/modelId.js.map +1 -0
  50. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  51. package/crud/contentModel/validate/pluralApiName.js +24 -0
  52. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  53. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  54. package/crud/contentModel/validate/singularApiName.js +24 -0
  55. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  56. package/crud/contentModel/validateModel.d.ts +4 -4
  57. package/crud/contentModel/validateModel.js +6 -3
  58. package/crud/contentModel/validateModel.js.map +1 -1
  59. package/crud/contentModel/validateModelFields.d.ts +4 -4
  60. package/crud/contentModel/validateModelFields.js +123 -88
  61. package/crud/contentModel/validateModelFields.js.map +1 -1
  62. package/crud/contentModel/validation.d.ts +551 -0
  63. package/crud/contentModel/validation.js +145 -0
  64. package/crud/contentModel/validation.js.map +1 -0
  65. package/crud/contentModel.crud.js +369 -273
  66. package/crud/contentModel.crud.js.map +1 -1
  67. package/crud/contentModelGroup/validation.d.ts +30 -0
  68. package/crud/contentModelGroup/validation.js +34 -0
  69. package/crud/contentModelGroup/validation.js.map +1 -0
  70. package/crud/contentModelGroup.crud.js +189 -172
  71. package/crud/contentModelGroup.crud.js.map +1 -1
  72. package/crud/settings.crud.d.ts +1 -1
  73. package/crud/settings.crud.js +5 -10
  74. package/crud/settings.crud.js.map +1 -1
  75. package/crud/system.crud.js +0 -60
  76. package/crud/system.crud.js.map +1 -1
  77. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
  78. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
  79. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
  80. package/fieldConverters/index.d.ts +2 -1
  81. package/fieldConverters/index.js +2 -1
  82. package/fieldConverters/index.js.map +1 -1
  83. package/graphql/buildSchemaPlugins.d.ts +8 -3
  84. package/graphql/buildSchemaPlugins.js +3 -7
  85. package/graphql/buildSchemaPlugins.js.map +1 -1
  86. package/graphql/checkEndpointAccess.d.ts +2 -0
  87. package/graphql/checkEndpointAccess.js +18 -0
  88. package/graphql/checkEndpointAccess.js.map +1 -0
  89. package/graphql/createExecutableSchema.d.ts +6 -0
  90. package/graphql/createExecutableSchema.js +29 -0
  91. package/graphql/createExecutableSchema.js.map +1 -0
  92. package/graphql/createRequestBody.d.ts +2 -0
  93. package/graphql/createRequestBody.js +14 -0
  94. package/graphql/createRequestBody.js.map +1 -0
  95. package/graphql/formatErrorPayload.d.ts +1 -0
  96. package/graphql/formatErrorPayload.js +25 -0
  97. package/graphql/formatErrorPayload.js.map +1 -0
  98. package/graphql/generateSchema.d.ts +8 -0
  99. package/graphql/generateSchema.js +31 -0
  100. package/graphql/generateSchema.js.map +1 -0
  101. package/graphql/getSchema.d.ts +17 -0
  102. package/graphql/getSchema.js +102 -0
  103. package/graphql/getSchema.js.map +1 -0
  104. package/graphql/graphQLHandlerFactory.js +6 -104
  105. package/graphql/graphQLHandlerFactory.js.map +1 -1
  106. package/graphql/handleRequest.d.ts +11 -0
  107. package/graphql/handleRequest.js +81 -0
  108. package/graphql/handleRequest.js.map +1 -0
  109. package/graphql/index.d.ts +1 -3
  110. package/graphql/index.js +2 -39
  111. package/graphql/index.js.map +1 -1
  112. package/graphql/schema/baseContentSchema.d.ts +6 -2
  113. package/graphql/schema/baseContentSchema.js +9 -11
  114. package/graphql/schema/baseContentSchema.js.map +1 -1
  115. package/graphql/schema/baseSchema.d.ts +3 -0
  116. package/graphql/schema/baseSchema.js +68 -0
  117. package/graphql/schema/baseSchema.js.map +1 -0
  118. package/graphql/schema/contentEntries.d.ts +6 -2
  119. package/graphql/schema/contentEntries.js +116 -65
  120. package/graphql/schema/contentEntries.js.map +1 -1
  121. package/graphql/schema/contentModelGroups.d.ts +6 -2
  122. package/graphql/schema/contentModelGroups.js +14 -10
  123. package/graphql/schema/contentModelGroups.js.map +1 -1
  124. package/graphql/schema/contentModels.d.ts +6 -2
  125. package/graphql/schema/contentModels.js +60 -8
  126. package/graphql/schema/contentModels.js.map +1 -1
  127. package/graphql/schema/createFieldResolvers.d.ts +2 -2
  128. package/graphql/schema/createFieldResolvers.js +18 -13
  129. package/graphql/schema/createFieldResolvers.js.map +1 -1
  130. package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
  131. package/graphql/schema/createFieldTypePluginRecords.js +13 -0
  132. package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
  133. package/graphql/schema/createManageResolvers.d.ts +1 -1
  134. package/graphql/schema/createManageResolvers.js +37 -17
  135. package/graphql/schema/createManageResolvers.js.map +1 -1
  136. package/graphql/schema/createManageSDL.d.ts +3 -0
  137. package/graphql/schema/createManageSDL.js +81 -63
  138. package/graphql/schema/createManageSDL.js.map +1 -1
  139. package/graphql/schema/createPreviewResolvers.js +3 -7
  140. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  141. package/graphql/schema/createReadResolvers.js +8 -7
  142. package/graphql/schema/createReadResolvers.js.map +1 -1
  143. package/graphql/schema/createReadSDL.d.ts +3 -0
  144. package/graphql/schema/createReadSDL.js +47 -36
  145. package/graphql/schema/createReadSDL.js.map +1 -1
  146. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  147. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
  148. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  149. package/graphql/schema/resolvers/manage/resolveDelete.d.ts +2 -1
  150. package/graphql/schema/resolvers/manage/resolveDelete.js +13 -3
  151. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  152. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
  153. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +20 -0
  154. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
  155. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.d.ts +4 -0
  156. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +18 -0
  157. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
  158. package/graphql/schema/schemaPlugins.d.ts +8 -3
  159. package/graphql/schema/schemaPlugins.js +55 -52
  160. package/graphql/schema/schemaPlugins.js.map +1 -1
  161. package/graphql/system.js +55 -74
  162. package/graphql/system.js.map +1 -1
  163. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
  164. package/graphqlFields/dynamicZone/dynamicZoneField.js +243 -0
  165. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
  166. package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
  167. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
  168. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
  169. package/graphqlFields/dynamicZone/index.d.ts +2 -0
  170. package/graphqlFields/dynamicZone/index.js +19 -0
  171. package/graphqlFields/dynamicZone/index.js.map +1 -0
  172. package/graphqlFields/index.d.ts +1 -1
  173. package/graphqlFields/index.js +2 -1
  174. package/graphqlFields/index.js.map +1 -1
  175. package/graphqlFields/number.js +4 -0
  176. package/graphqlFields/number.js.map +1 -1
  177. package/graphqlFields/object.js +131 -68
  178. package/graphqlFields/object.js.map +1 -1
  179. package/graphqlFields/ref.js +70 -56
  180. package/graphqlFields/ref.js.map +1 -1
  181. package/index.d.ts +5 -3
  182. package/index.js +27 -8
  183. package/index.js.map +1 -1
  184. package/package.json +40 -41
  185. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  186. package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
  187. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  188. package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
  189. package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
  190. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
  191. package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
  192. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  193. package/plugins/CmsModelPlugin.d.ts +21 -3
  194. package/plugins/CmsModelPlugin.js +28 -2
  195. package/plugins/CmsModelPlugin.js.map +1 -1
  196. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  197. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  198. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  199. package/plugins/StorageTransformPlugin.d.ts +11 -11
  200. package/plugins/StorageTransformPlugin.js.map +1 -1
  201. package/plugins/index.d.ts +3 -0
  202. package/plugins/index.js +33 -0
  203. package/plugins/index.js.map +1 -1
  204. package/storage/object.js +4 -2
  205. package/storage/object.js.map +1 -1
  206. package/types.d.ts +436 -149
  207. package/types.js +74 -8
  208. package/types.js.map +1 -1
  209. package/utils/converters/ConverterCollection.js +5 -2
  210. package/utils/converters/ConverterCollection.js.map +1 -1
  211. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  212. package/utils/converters/valueKeyStorageConverter.js +26 -20
  213. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  214. package/utils/createTypeFromFields.d.ts +16 -0
  215. package/utils/createTypeFromFields.js +66 -0
  216. package/utils/createTypeFromFields.js.map +1 -0
  217. package/utils/createTypeName.d.ts +0 -2
  218. package/utils/createTypeName.js +4 -11
  219. package/utils/createTypeName.js.map +1 -1
  220. package/utils/entryStorage.js +14 -11
  221. package/utils/entryStorage.js.map +1 -1
  222. package/utils/getBaseFieldType.d.ts +2 -0
  223. package/utils/getBaseFieldType.js +10 -0
  224. package/utils/getBaseFieldType.js.map +1 -0
  225. package/utils/getEntryDescription.d.ts +2 -0
  226. package/utils/getEntryDescription.js +17 -0
  227. package/utils/getEntryDescription.js.map +1 -0
  228. package/utils/getEntryImage.d.ts +2 -0
  229. package/utils/getEntryImage.js +17 -0
  230. package/utils/getEntryImage.js.map +1 -0
  231. package/utils/getEntryTitle.d.ts +1 -1
  232. package/utils/getEntryTitle.js.map +1 -1
  233. package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
  234. package/utils/getSchemaFromFieldPlugins.js +22 -14
  235. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  236. package/utils/incrementEntryIdVersion.d.ts +5 -0
  237. package/utils/incrementEntryIdVersion.js +29 -0
  238. package/utils/incrementEntryIdVersion.js.map +1 -0
  239. package/utils/ownership.d.ts +3 -3
  240. package/utils/ownership.js.map +1 -1
  241. package/utils/renderFields.d.ts +4 -2
  242. package/utils/renderFields.js +12 -3
  243. package/utils/renderFields.js.map +1 -1
  244. package/utils/renderGetFilterFields.d.ts +2 -2
  245. package/utils/renderGetFilterFields.js +9 -19
  246. package/utils/renderGetFilterFields.js.map +1 -1
  247. package/utils/renderInputFields.d.ts +4 -2
  248. package/utils/renderInputFields.js +19 -6
  249. package/utils/renderInputFields.js.map +1 -1
  250. package/utils/renderListFilterFields.d.ts +2 -1
  251. package/utils/renderListFilterFields.js +12 -21
  252. package/utils/renderListFilterFields.js.map +1 -1
  253. package/utils/renderSortEnum.d.ts +9 -5
  254. package/utils/renderSortEnum.js +23 -5
  255. package/utils/renderSortEnum.js.map +1 -1
  256. package/validators/dynamicZone.d.ts +2 -0
  257. package/validators/dynamicZone.js +20 -0
  258. package/validators/dynamicZone.js.map +1 -0
  259. package/validators/index.js +2 -1
  260. package/validators/index.js.map +1 -1
  261. package/crud/contentModel/createFieldModels.d.ts +0 -2
  262. package/crud/contentModel/createFieldModels.js +0 -20
  263. package/crud/contentModel/createFieldModels.js.map +0 -1
  264. package/crud/contentModel/fieldIdValidation.d.ts +0 -1
  265. package/crud/contentModel/fieldIdValidation.js +0 -20
  266. package/crud/contentModel/fieldIdValidation.js.map +0 -1
  267. package/crud/contentModel/idValidation.d.ts +0 -1
  268. package/crud/contentModel/idValidation.js +0 -17
  269. package/crud/contentModel/idValidation.js.map +0 -1
  270. package/crud/contentModel/models.d.ts +0 -4
  271. package/crud/contentModel/models.js +0 -173
  272. package/crud/contentModel/models.js.map +0 -1
  273. package/crud/contentModel/systemFields.d.ts +0 -1
  274. package/crud/contentModel/systemFields.js +0 -8
  275. package/crud/contentModel/systemFields.js.map +0 -1
  276. package/crud/index.d.ts +0 -6
  277. package/crud/index.js +0 -69
  278. package/crud/index.js.map +0 -1
  279. package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
  280. package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
  281. package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  282. package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
  283. package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
  284. package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
  285. package/upgrades/5.33.0/index.d.ts +0 -3
  286. package/upgrades/5.33.0/index.js +0 -159
  287. package/upgrades/5.33.0/index.js.map +0 -1
  288. package/upgrades/index.d.ts +0 -1
  289. package/upgrades/index.js +0 -9
  290. package/upgrades/index.js.map +0 -1
  291. package/utils/filterModelFields.d.ts +0 -16
  292. package/utils/filterModelFields.js +0 -71
  293. package/utils/filterModelFields.js.map +0 -1
  294. package/utils/pluralizedTypeName.d.ts +0 -1
  295. package/utils/pluralizedTypeName.js +0 -20
  296. package/utils/pluralizedTypeName.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.validateModelIdAllowed = exports.validateExistingModelId = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const disallowedModelIdList = ["contentModel", "contentModels", "contentModelGroup", "contentModelGroups"];
10
+ const isModelIdAllowed = modelId => {
11
+ return disallowedModelIdList.includes(modelId) === false;
12
+ };
13
+ const validateModelIdAllowed = params => {
14
+ const {
15
+ model
16
+ } = params;
17
+ if (isModelIdAllowed(model.modelId)) {
18
+ return;
19
+ }
20
+ throw new _error.default(`Provided model ID "${model.modelId}" is not allowed.`, "MODEL_ID_NOT_ALLOWED", {
21
+ input: model.modelId
22
+ });
23
+ };
24
+ exports.validateModelIdAllowed = validateModelIdAllowed;
25
+ const validateExistingModelId = params => {
26
+ const {
27
+ existingModel,
28
+ model
29
+ } = params;
30
+ if (existingModel.modelId === model.modelId) {
31
+ throw new _error.default(`Content model with modelId "${model.modelId}" already exists.`, "MODEL_ID_EXISTS", {
32
+ input: existingModel.modelId
33
+ });
34
+ }
35
+ };
36
+ exports.validateExistingModelId = validateExistingModelId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["disallowedModelIdList","isModelIdAllowed","modelId","includes","validateModelIdAllowed","params","model","WebinyError","input","validateExistingModelId","existingModel"],"sources":["modelId.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\nconst isModelIdAllowed = (modelId: string): boolean => {\n return disallowedModelIdList.includes(modelId) === false;\n};\n\ninterface ModelIdAllowedParams {\n model: Pick<CmsModel, \"modelId\">;\n}\n\nexport const validateModelIdAllowed = (params: ModelIdAllowedParams) => {\n const { model } = params;\n if (isModelIdAllowed(model.modelId)) {\n return;\n }\n throw new WebinyError(\n `Provided model ID \"${model.modelId}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n input: model.modelId\n }\n );\n};\n\ninterface Params {\n existingModel: Pick<CmsModel, \"modelId\">;\n model: Pick<CmsModel, \"modelId\">;\n}\n\nexport const validateExistingModelId = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.modelId === model.modelId) {\n throw new WebinyError(\n `Content model with modelId \"${model.modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n input: existingModel.modelId\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAGA,MAAMA,qBAA+B,GAAG,CACpC,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACvB;AACD,MAAMC,gBAAgB,GAAIC,OAAe,IAAc;EACnD,OAAOF,qBAAqB,CAACG,QAAQ,CAACD,OAAO,CAAC,KAAK,KAAK;AAC5D,CAAC;AAMM,MAAME,sBAAsB,GAAIC,MAA4B,IAAK;EACpE,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAIJ,gBAAgB,CAACK,KAAK,CAACJ,OAAO,CAAC,EAAE;IACjC;EACJ;EACA,MAAM,IAAIK,cAAW,CAChB,sBAAqBD,KAAK,CAACJ,OAAQ,mBAAkB,EACtD,sBAAsB,EACtB;IACIM,KAAK,EAAEF,KAAK,CAACJ;EACjB,CAAC,CACJ;AACL,CAAC;AAAC;AAOK,MAAMO,uBAAuB,GAAIJ,MAAc,IAAW;EAC7D,MAAM;IAAEK,aAAa;IAAEJ;EAAM,CAAC,GAAGD,MAAM;EAEvC,IAAIK,aAAa,CAACR,OAAO,KAAKI,KAAK,CAACJ,OAAO,EAAE;IACzC,MAAM,IAAIK,cAAW,CAChB,+BAA8BD,KAAK,CAACJ,OAAQ,mBAAkB,EAC/D,iBAAiB,EACjB;MACIM,KAAK,EAAEE,aAAa,CAACR;IACzB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -0,0 +1,7 @@
1
+ import { CmsModel } from "../../../types";
2
+ interface Params {
3
+ existingModel: Pick<CmsModel, "singularApiName" | "pluralApiName">;
4
+ model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
5
+ }
6
+ export declare const validatePluralApiName: (params: Params) => void;
7
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.validatePluralApiName = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const validatePluralApiName = params => {
10
+ const {
11
+ existingModel,
12
+ model
13
+ } = params;
14
+ if (existingModel.singularApiName === model.pluralApiName) {
15
+ throw new _error.default(`Content model with singularApiName "${model.pluralApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
16
+ input: model.pluralApiName
17
+ });
18
+ } else if (existingModel.pluralApiName === model.pluralApiName) {
19
+ throw new _error.default(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
20
+ input: model.pluralApiName
21
+ });
22
+ }
23
+ };
24
+ exports.validatePluralApiName = validatePluralApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validatePluralApiName","params","existingModel","model","singularApiName","pluralApiName","WebinyError","input"],"sources":["pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAQO,MAAMA,qBAAqB,GAAIC,MAAc,IAAW;EAC3D,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,IAAIC,aAAa,CAACE,eAAe,KAAKD,KAAK,CAACE,aAAa,EAAE;IACvD,MAAM,IAAIC,cAAW,CAChB,uCAAsCH,KAAK,CAACE,aAAc,mBAAkB,EAC7E,gCAAgC,EAChC;MACIE,KAAK,EAAEJ,KAAK,CAACE;IACjB,CAAC,CACJ;EACL,CAAC,MAAM,IAAIH,aAAa,CAACG,aAAa,KAAKF,KAAK,CAACE,aAAa,EAAE;IAC5D,MAAM,IAAIC,cAAW,CAChB,qCAAoCH,KAAK,CAACE,aAAc,mBAAkB,EAC3E,8BAA8B,EAC9B;MACIE,KAAK,EAAEJ,KAAK,CAACE;IACjB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -0,0 +1,7 @@
1
+ import { CmsModel } from "../../../types";
2
+ interface Params {
3
+ existingModel: Pick<CmsModel, "singularApiName" | "pluralApiName">;
4
+ model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
5
+ }
6
+ export declare const validateSingularApiName: (params: Params) => void;
7
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.validateSingularApiName = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const validateSingularApiName = params => {
10
+ const {
11
+ existingModel,
12
+ model
13
+ } = params;
14
+ if (existingModel.singularApiName === model.singularApiName) {
15
+ throw new _error.default(`Content model with singularApiName "${model.singularApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
16
+ input: model.singularApiName
17
+ });
18
+ } else if (existingModel.pluralApiName === model.singularApiName) {
19
+ throw new _error.default(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
20
+ input: model.singularApiName
21
+ });
22
+ }
23
+ };
24
+ exports.validateSingularApiName = validateSingularApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateSingularApiName","params","existingModel","model","singularApiName","WebinyError","input","pluralApiName"],"sources":["singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAQO,MAAMA,uBAAuB,GAAIC,MAAc,IAAW;EAC7D,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,IAAIC,aAAa,CAACE,eAAe,KAAKD,KAAK,CAACC,eAAe,EAAE;IACzD,MAAM,IAAIC,cAAW,CAChB,uCAAsCF,KAAK,CAACC,eAAgB,mBAAkB,EAC/E,gCAAgC,EAChC;MACIE,KAAK,EAAEH,KAAK,CAACC;IACjB,CAAC,CACJ;EACL,CAAC,MAAM,IAAIF,aAAa,CAACK,aAAa,KAAKJ,KAAK,CAACC,eAAe,EAAE;IAC9D,MAAM,IAAIC,cAAW,CAChB,qCAAoCF,KAAK,CAACC,eAAgB,mBAAkB,EAC7E,8BAA8B,EAC9B;MACIE,KAAK,EAAEH,KAAK,CAACC;IACjB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -1,9 +1,9 @@
1
- import { CmsModel } from "../../types";
2
- import { PluginsContainer } from "@webiny/plugins";
1
+ import { CmsContext, CmsModel } from "../../types";
3
2
  interface ValidateModelParams {
3
+ models: CmsModel[];
4
4
  model: CmsModel;
5
5
  original?: CmsModel;
6
- plugins: PluginsContainer;
6
+ context: CmsContext;
7
7
  }
8
- export declare const validateModel: (params: ValidateModelParams) => void;
8
+ export declare const validateModel: (params: ValidateModelParams) => Promise<void>;
9
9
  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
- plugins
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 { 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,MAA2B,IAAK;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEjC,MAAMG,WAAW,GAAGD,OAAO,CACtBE,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKT,KAAK,CAACS,OAAO,CAAC;EAE9D,IAAIP,WAAW,EAAE;IACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;MACID,OAAO,EAAET,KAAK,CAACS;IACnB,CAAC,CACJ;EACL;EAEA,IAAAE,wCAAmB,EAACZ,MAAM,CAAC;AAC/B,CAAC;AAAC"}
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 models: CmsModel[];\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;AASO,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,9 @@
1
- import { CmsModel } from "../../types";
2
- import { PluginsContainer } from "@webiny/plugins";
1
+ import { CmsModel, CmsContext } from "../../types";
3
2
  interface ValidateModelFieldsParams {
3
+ models: CmsModel[];
4
4
  model: CmsModel;
5
5
  original?: CmsModel;
6
- plugins: PluginsContainer;
6
+ context: CmsContext;
7
7
  }
8
- export declare const validateModelFields: (params: ValidateModelFieldsParams) => void;
8
+ export declare const validateModelFields: (params: ValidateModelFieldsParams) => Promise<void>;
9
9
  export {};
@@ -6,58 +6,18 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.validateModelFields = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
10
  var _error = _interopRequireDefault(require("@webiny/error"));
10
11
  var _createManageSDL = require("../../graphql/schema/createManageSDL");
11
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
12
12
  var _createFieldStorageId = require("./createFieldStorageId");
13
- const defaultTitleFieldId = "id";
14
- const allowedTitleFieldTypes = ["text", "number"];
15
- const getContentModelTitleFieldId = (fields, titleFieldId) => {
16
- /**
17
- * If there are no fields defined, we will return the default field
18
- */
19
- if (fields.length === 0) {
20
- return defaultTitleFieldId;
21
- }
22
- /**
23
- * if there is no title field defined either in input data or existing content model data
24
- * we will take first text field that has no multiple values enabled
25
- * or if initial titleFieldId is the default one also try to find first available text field
26
- */
27
- if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
28
- const titleField = fields.find(field => {
29
- return field.type === "text" && !field.multipleValues;
30
- });
31
- return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
32
- }
33
- /**
34
- * check existing titleFieldId for existence in the model
35
- * for correct type
36
- * and that it is not multiple values field
37
- */
38
- const target = fields.find(f => f.fieldId === titleFieldId);
39
- if (!target) {
40
- throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
41
- fieldId: titleFieldId,
42
- fields
43
- });
44
- }
45
- if (allowedTitleFieldTypes.includes(target.type) === false) {
46
- throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
47
- storageId: target.storageId,
48
- fieldId: target.fieldId,
49
- type: target.type
50
- });
51
- }
52
- if (target.multipleValues) {
53
- throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
54
- storageId: target.storageId,
55
- fieldId: target.fieldId,
56
- type: target.type
57
- });
58
- }
59
- return target.fieldId;
60
- };
13
+ var _getBaseFieldType = require("../../utils/getBaseFieldType");
14
+ var _titleField = require("./fields/titleField");
15
+ var _descriptionField = require("./fields/descriptionField");
16
+ var _imageField = require("./fields/imageField");
17
+ var _plugins = require("../../plugins");
18
+ var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
19
+ var _createExecutableSchema = require("../../graphql/createExecutableSchema");
20
+ var _utils = require("@webiny/utils");
61
21
  const extractInvalidField = (model, err) => {
62
22
  var _err$source;
63
23
  const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
@@ -102,6 +62,22 @@ const extractInvalidField = (model, err) => {
102
62
  message: [`Model "${model.modelId}" was not saved!`, message].join("\n")
103
63
  };
104
64
  };
65
+ const createValidateChildFields = plugins => {
66
+ return ({
67
+ fields,
68
+ originalFields
69
+ }) => {
70
+ if (fields.length === 0 && originalFields.length === 0) {
71
+ return;
72
+ }
73
+ validateFields({
74
+ fields,
75
+ originalFields,
76
+ plugins,
77
+ lockedFields: []
78
+ });
79
+ };
80
+ };
105
81
  const validateFields = params => {
106
82
  const {
107
83
  plugins,
@@ -109,14 +85,23 @@ const validateFields = params => {
109
85
  originalFields,
110
86
  lockedFields
111
87
  } = params;
88
+ const idList = [];
112
89
  const fieldIdList = [];
113
90
  const storageIdList = [];
114
91
  for (const field of fields) {
115
- var _field$settings, _originalField$settin;
116
- const plugin = plugins.find(item => item.fieldType === field.type);
92
+ const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
93
+ const plugin = plugins.find(plugin => plugin.fieldType === baseType);
117
94
  if (!plugin) {
118
- throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
95
+ throw new Error(`Cannot update content model because of the unknown "${baseType}" field.`);
119
96
  }
97
+ /**
98
+ * Check the field's id against existing ones.
99
+ * There cannot be two fields with the same id.
100
+ */
101
+ if (idList.includes(field.id)) {
102
+ throw new _error.default(`Cannot update content model because field "${field.storageId || field.fieldId}" has id "${field.id}", which is already used.`);
103
+ }
104
+ idList.push(field.id);
120
105
  const originalField = originalFields.find(f => f.id === field.id);
121
106
  /**
122
107
  * Field MUST have an fieldId defined.
@@ -140,7 +125,7 @@ const validateFields = params => {
140
125
  * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2
141
126
  */
142
127
  const isLocked = lockedFields.some(lockedField => {
143
- return lockedField.fieldId === field.storageId;
128
+ return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;
144
129
  });
145
130
  if (!field.storageId) {
146
131
  /**
@@ -183,39 +168,71 @@ const validateFields = params => {
183
168
  }
184
169
  storageIdList.push(field.storageId);
185
170
  /**
186
- * TODO maybe make this part pluginable?
187
- * We need to check the object field child fields.
188
- * It must be recursive.
171
+ * There might be some plugins which allow child fields.
172
+ * We use this method to validate them as well.
189
173
  */
190
- if (field.type !== "object") {
174
+ if (!plugin.validateChildFields) {
191
175
  continue;
192
176
  }
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.
198
- */
199
- if (childFields.length === 0) {
200
- continue;
201
- }
202
- validateFields({
203
- fields: childFields,
204
- originalFields: originalChildFields,
205
- plugins,
206
- lockedFields: []
177
+ const validateChildFields = createValidateChildFields(plugins);
178
+ plugin.validateChildFields({
179
+ field,
180
+ originalField,
181
+ validate: validateChildFields
207
182
  });
208
183
  }
209
184
  };
210
- const validateModelFields = params => {
185
+ const createGraphQLSchema = async params => {
211
186
  const {
187
+ context,
188
+ model
189
+ } = params;
190
+ const models = await context.security.withoutAuthorization(async () => {
191
+ return (await context.cms.listModels()).filter(model => {
192
+ return model.isPrivate !== true;
193
+ });
194
+ });
195
+ const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
196
+ context,
197
+ models: models.concat([model])
198
+ });
199
+ const plugins = context.plugins.byType(_plugins.CmsGraphQLSchemaPlugin.type).reduce((collection, plugin) => {
200
+ const name = plugin.name || `${_plugins.CmsGraphQLSchemaPlugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
201
+ collection[name] = plugin;
202
+ return collection;
203
+ }, {});
204
+ for (const plugin of modelPlugins) {
205
+ const name = plugin.name || `${plugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
206
+ plugins[name] = plugin;
207
+ }
208
+ return (0, _createExecutableSchema.createExecutableSchema)({
209
+ plugins: Object.values(plugins)
210
+ });
211
+ };
212
+ const extractErrorObject = error => {
213
+ return ["message", "code", "data", "stack"].reduce((output, key) => {
214
+ if (!error[key]) {
215
+ return output;
216
+ }
217
+ output[key] = error[key];
218
+ return output;
219
+ }, {});
220
+ };
221
+ const validateModelFields = async params => {
222
+ const {
223
+ models,
212
224
  model,
213
225
  original,
214
- plugins
226
+ context
215
227
  } = params;
216
228
  const {
217
- titleFieldId
229
+ titleFieldId,
230
+ descriptionFieldId,
231
+ imageFieldId
218
232
  } = model;
233
+ const {
234
+ plugins
235
+ } = context;
219
236
 
220
237
  /**
221
238
  * There should be fields/locked fields in either model or data to be updated.
@@ -237,22 +254,45 @@ const validateModelFields = params => {
237
254
  plugins: fieldTypePlugins
238
255
  });
239
256
  if (fields.length) {
257
+ const sorterPlugins = plugins.byType(_plugins.CmsGraphQLSchemaSorterPlugin.type);
240
258
  /**
241
259
  * Make sure that this model can be safely converted to a GraphQL SDL
242
260
  */
243
261
  const schema = (0, _createManageSDL.createManageSDL)({
262
+ models,
244
263
  model,
245
264
  fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, acc), {}, {
246
265
  [pl.fieldType]: pl
247
- }), {})
266
+ }), {}),
267
+ sorterPlugins
248
268
  });
249
269
  try {
250
270
  (0, _graphqlTag.default)(schema);
251
271
  } catch (err) {
252
272
  throw new _error.default(extractInvalidField(model, err));
253
273
  }
274
+ /**
275
+ *
276
+ */
277
+ try {
278
+ await createGraphQLSchema({
279
+ context,
280
+ model
281
+ });
282
+ } catch (err) {
283
+ throw new _error.default({
284
+ message: "Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.",
285
+ code: "GRAPHQL_SCHEMA_ERROR",
286
+ data: {
287
+ modelId: model.modelId,
288
+ error: extractErrorObject(err)
289
+ }
290
+ });
291
+ }
254
292
  }
255
- model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
293
+ model.titleFieldId = (0, _titleField.getContentModelTitleFieldId)(fields, titleFieldId);
294
+ model.descriptionFieldId = (0, _descriptionField.getContentModelDescriptionFieldId)(fields, descriptionFieldId);
295
+ model.imageFieldId = (0, _imageField.getContentModelImageFieldId)(fields, imageFieldId);
256
296
  const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
257
297
 
258
298
  /**
@@ -268,31 +308,26 @@ const validateModelFields = params => {
268
308
  */
269
309
  if (!existingField) {
270
310
  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
311
  }
280
-
281
312
  if (lockedField.multipleValues !== existingField.multipleValues) {
282
313
  throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
314
+ reason: `"multipleValues" changed`,
283
315
  field: existingField
284
316
  });
285
317
  }
286
- if (lockedField.type !== existingField.type) {
318
+ const fieldType = (0, _getBaseFieldType.getBaseFieldType)(existingField);
319
+ if (lockedField.type !== fieldType) {
287
320
  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
- field: existingField
321
+ reason: `"type" changed`,
322
+ lockedFieldType: lockedField.type,
323
+ existingFieldType: fieldType
289
324
  });
290
325
  }
291
326
 
292
327
  /**
293
328
  * Check `lockedField` invariant for specific field
294
329
  */
295
- const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === lockedField.type);
330
+ const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === (0, _getBaseFieldType.getBaseFieldType)(lockedField));
296
331
  for (const plugin of lockedFieldsByType) {
297
332
  if (typeof plugin.checkLockedField !== "function") {
298
333
  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 }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BrB,WAAW;QACXnD,KAAK,EAAEqE;MACX,CAAC,CAAC;IACN;EACJ;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","includes","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","join","createValidateChildFields","plugins","fields","originalFields","length","validateFields","lockedFields","params","idList","fieldIdList","storageIdList","field","baseType","getBaseFieldType","plugin","find","fieldType","Error","id","WebinyError","storageId","fieldId","push","originalField","f","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","models","security","withoutAuthorization","cms","listModels","filter","isPrivate","modelPlugins","buildSchemaPlugins","concat","byType","CmsGraphQLSchemaPlugin","type","reduce","collection","name","generateAlphaNumericId","createExecutableSchema","Object","values","extractErrorObject","error","output","key","validateModelFields","original","titleFieldId","descriptionFieldId","imageFieldId","fieldTypePlugins","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","acc","pl","gql","getContentModelTitleFieldId","getContentModelDescriptionFieldId","getContentModelImageFieldId","cmsLockedFieldPlugins","existingField","item","multipleValues","reason","lockedFieldType","existingFieldType","lockedFieldsByType","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsModel,\n CmsContext,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { getContentModelTitleFieldId } from \"./fields/titleField\";\nimport { getContentModelDescriptionFieldId } from \"./fields/descriptionField\";\nimport { getContentModelImageFieldId } from \"./fields/imageField\";\nimport { CmsGraphQLSchemaPlugin, CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\nimport { buildSchemaPlugins } from \"~/graphql/buildSchemaPlugins\";\nimport { createExecutableSchema } from \"~/graphql/createExecutableSchema\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\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}\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};\n\ninterface CreateGraphQLSchemaParams {\n context: CmsContext;\n model: CmsModel;\n}\n\nconst createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {\n const { context, model } = params;\n\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter((model): model is CmsModel => {\n return model.isPrivate !== true;\n });\n });\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: models.concat([model])\n });\n\n const plugins = context.plugins\n .byType<CmsGraphQLSchemaPlugin>(CmsGraphQLSchemaPlugin.type)\n .reduce<Record<string, CmsGraphQLSchemaPlugin>>((collection, plugin) => {\n const name =\n plugin.name || `${CmsGraphQLSchemaPlugin.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 models: CmsModel[];\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModelFields = async (params: ValidateModelFieldsParams): Promise<void> => {\n const { models, model, original, context } = params;\n const { titleFieldId, descriptionFieldId, imageFieldId } = 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 models,\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 model.descriptionFieldId = getContentModelDescriptionFieldId(fields, descriptionFieldId);\n model.imageFieldId = getContentModelImageFieldId(fields, imageFieldId);\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":";;;;;;;;AAAA;AACA;AAUA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,CAACC,KAAe,EAAEC,GAAiB,KAAK;EAAA;EAChE,MAAMC,GAAG,GAAG,gBAAAD,GAAG,CAACE,MAAM,gDAAV,YAAYC,IAAI,KAAI,EAAE;;EAElC;AACJ;AACA;EACI,MAAM;IAAEC,IAAI,EAAEC;EAAW,CAAC,GAAGL,GAAG,CAACM,SAAS,GACpCN,GAAG,CAACM,SAAS,CAAC,CAAC,CAAC,GAChB;IACIF,IAAI,EAAE;EACV,CAAC;EACP,MAAMG,QAAQ,GAAGN,GAAG,CAACO,KAAK,CAAC,IAAI,CAAC;EAChC,IAAIC,OAAO;EACX,IAAIC,OAAO;EACX,KAAK,IAAIC,CAAC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