@webiny/api-headless-cms 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60e968001a

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 (232) hide show
  1. package/context.d.ts +5 -2
  2. package/context.js +63 -8
  3. package/context.js.map +1 -1
  4. package/crud/contentEntry/afterDelete.d.ts +2 -2
  5. package/crud/contentEntry/afterDelete.js +2 -2
  6. package/crud/contentEntry/afterDelete.js.map +1 -1
  7. package/crud/contentEntry/beforeCreate.d.ts +2 -2
  8. package/crud/contentEntry/beforeCreate.js +2 -2
  9. package/crud/contentEntry/beforeCreate.js.map +1 -1
  10. package/crud/contentEntry/beforeUpdate.d.ts +2 -2
  11. package/crud/contentEntry/beforeUpdate.js +2 -2
  12. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  13. package/crud/contentEntry/entryDataValidation.js +3 -7
  14. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  15. package/crud/contentEntry/markLockedFields.js +10 -11
  16. package/crud/contentEntry/markLockedFields.js.map +1 -1
  17. package/crud/contentEntry/referenceFieldsMapping.js +11 -13
  18. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  19. package/crud/contentEntry/searchableFields.d.ts +9 -0
  20. package/crud/contentEntry/searchableFields.js +83 -0
  21. package/crud/contentEntry/searchableFields.js.map +1 -0
  22. package/crud/contentEntry.crud.d.ts +0 -2
  23. package/crud/contentEntry.crud.js +253 -270
  24. package/crud/contentEntry.crud.js.map +1 -1
  25. package/crud/contentModel/afterCreate.d.ts +3 -3
  26. package/crud/contentModel/afterCreate.js +5 -5
  27. package/crud/contentModel/afterCreate.js.map +1 -1
  28. package/crud/contentModel/afterCreateFrom.d.ts +3 -3
  29. package/crud/contentModel/afterCreateFrom.js +5 -5
  30. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  31. package/crud/contentModel/afterDelete.d.ts +3 -3
  32. package/crud/contentModel/afterDelete.js +5 -5
  33. package/crud/contentModel/afterDelete.js.map +1 -1
  34. package/crud/contentModel/afterUpdate.d.ts +3 -3
  35. package/crud/contentModel/afterUpdate.js +5 -5
  36. package/crud/contentModel/afterUpdate.js.map +1 -1
  37. package/crud/contentModel/beforeCreate.d.ts +4 -4
  38. package/crud/contentModel/beforeCreate.js +10 -10
  39. package/crud/contentModel/beforeCreate.js.map +1 -1
  40. package/crud/contentModel/beforeDelete.d.ts +3 -3
  41. package/crud/contentModel/beforeDelete.js +6 -6
  42. package/crud/contentModel/beforeDelete.js.map +1 -1
  43. package/crud/contentModel/beforeUpdate.d.ts +3 -3
  44. package/crud/contentModel/beforeUpdate.js +5 -5
  45. package/crud/contentModel/beforeUpdate.js.map +1 -1
  46. package/crud/contentModel/createFieldStorageId.js +5 -1
  47. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  48. package/crud/contentModel/models.js +12 -0
  49. package/crud/contentModel/models.js.map +1 -1
  50. package/crud/contentModel/validateModel.js +1 -1
  51. package/crud/contentModel/validateModelFields.js +47 -42
  52. package/crud/contentModel/validateModelFields.js.map +1 -1
  53. package/crud/contentModel/validation.d.ts +477 -0
  54. package/crud/contentModel/validation.js +109 -0
  55. package/crud/contentModel/validation.js.map +1 -0
  56. package/crud/contentModel.crud.js +287 -211
  57. package/crud/contentModel.crud.js.map +1 -1
  58. package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
  59. package/crud/contentModelGroup/beforeCreate.js +3 -3
  60. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  61. package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
  62. package/crud/contentModelGroup/beforeDelete.js +3 -3
  63. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  64. package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
  65. package/crud/contentModelGroup/beforeUpdate.js +2 -2
  66. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  67. package/crud/contentModelGroup/validation.d.ts +30 -0
  68. package/crud/contentModelGroup/validation.js +43 -0
  69. package/crud/contentModelGroup/validation.js.map +1 -0
  70. package/crud/contentModelGroup.crud.js +102 -82
  71. package/crud/contentModelGroup.crud.js.map +1 -1
  72. package/crud/settings.crud.js +3 -8
  73. package/crud/settings.crud.js.map +1 -1
  74. package/crud/system.crud.js +63 -51
  75. package/crud/system.crud.js.map +1 -1
  76. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -1
  77. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
  78. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +239 -0
  79. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
  80. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +17 -19
  81. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  82. package/fieldConverters/index.d.ts +2 -1
  83. package/fieldConverters/index.js +3 -1
  84. package/fieldConverters/index.js.map +1 -1
  85. package/graphql/buildSchemaPlugins.d.ts +2 -2
  86. package/graphql/buildSchemaPlugins.js.map +1 -1
  87. package/graphql/graphQLHandlerFactory.js +59 -29
  88. package/graphql/graphQLHandlerFactory.js.map +1 -1
  89. package/graphql/index.d.ts +2 -2
  90. package/graphql/index.js +49 -38
  91. package/graphql/index.js.map +1 -1
  92. package/graphql/schema/baseContentSchema.d.ts +2 -2
  93. package/graphql/schema/baseContentSchema.js +8 -12
  94. package/graphql/schema/baseContentSchema.js.map +1 -1
  95. package/graphql/schema/contentEntries.d.ts +2 -2
  96. package/graphql/schema/contentEntries.js +6 -6
  97. package/graphql/schema/contentEntries.js.map +1 -1
  98. package/graphql/schema/contentModelGroups.d.ts +2 -2
  99. package/graphql/schema/contentModelGroups.js +3 -3
  100. package/graphql/schema/contentModelGroups.js.map +1 -1
  101. package/graphql/schema/contentModels.d.ts +2 -2
  102. package/graphql/schema/contentModels.js +42 -4
  103. package/graphql/schema/contentModels.js.map +1 -1
  104. package/graphql/schema/createFieldResolvers.d.ts +1 -1
  105. package/graphql/schema/createFieldResolvers.js +26 -16
  106. package/graphql/schema/createFieldResolvers.js.map +1 -1
  107. package/graphql/schema/createManageResolvers.js +4 -18
  108. package/graphql/schema/createManageResolvers.js.map +1 -1
  109. package/graphql/schema/createManageSDL.d.ts +2 -0
  110. package/graphql/schema/createManageSDL.js +11 -12
  111. package/graphql/schema/createManageSDL.js.map +1 -1
  112. package/graphql/schema/createPreviewResolvers.js +3 -7
  113. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  114. package/graphql/schema/createReadResolvers.js +8 -7
  115. package/graphql/schema/createReadResolvers.js.map +1 -1
  116. package/graphql/schema/createReadSDL.d.ts +2 -0
  117. package/graphql/schema/createReadSDL.js +11 -5
  118. package/graphql/schema/createReadSDL.js.map +1 -1
  119. package/graphql/schema/resolvers/manage/resolveGet.js +5 -9
  120. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  121. package/graphql/schema/resolvers/preview/resolveGet.js +3 -7
  122. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  123. package/graphql/schema/resolvers/read/resolveGet.js +3 -7
  124. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  125. package/graphql/schema/schemaPlugins.d.ts +2 -2
  126. package/graphql/schema/schemaPlugins.js +11 -8
  127. package/graphql/schema/schemaPlugins.js.map +1 -1
  128. package/graphql/system.js +79 -82
  129. package/graphql/system.js.map +1 -1
  130. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
  131. package/graphqlFields/dynamicZone/dynamicZoneField.js +234 -0
  132. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
  133. package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
  134. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +79 -0
  135. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
  136. package/graphqlFields/dynamicZone/index.d.ts +2 -0
  137. package/graphqlFields/dynamicZone/index.js +21 -0
  138. package/graphqlFields/dynamicZone/index.js.map +1 -0
  139. package/graphqlFields/index.d.ts +1 -1
  140. package/graphqlFields/index.js +3 -1
  141. package/graphqlFields/index.js.map +1 -1
  142. package/graphqlFields/number.js +4 -0
  143. package/graphqlFields/number.js.map +1 -1
  144. package/graphqlFields/object.js +123 -73
  145. package/graphqlFields/object.js.map +1 -1
  146. package/graphqlFields/ref.js +38 -56
  147. package/graphqlFields/ref.js.map +1 -1
  148. package/index.d.ts +3 -3
  149. package/index.js +4 -8
  150. package/index.js.map +1 -1
  151. package/modelManager/DefaultCmsModelManager.d.ts +7 -7
  152. package/modelManager/DefaultCmsModelManager.js +1 -1
  153. package/package.json +30 -31
  154. package/parameters/header.js +1 -1
  155. package/parameters/manual.js +7 -8
  156. package/parameters/manual.js.map +1 -1
  157. package/parameters/path.js +1 -1
  158. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  159. package/plugins/CmsGraphQLSchemaPlugin.js +17 -0
  160. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  161. package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
  162. package/plugins/CmsGraphQLSchemaSorterPlugin.js +38 -0
  163. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
  164. package/plugins/CmsGroupPlugin.js +1 -1
  165. package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
  166. package/plugins/CmsModelFieldConverterPlugin.js +1 -1
  167. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  168. package/plugins/CmsModelPlugin.d.ts +6 -2
  169. package/plugins/CmsModelPlugin.js +18 -13
  170. package/plugins/CmsModelPlugin.js.map +1 -1
  171. package/plugins/CmsParametersPlugin.js +1 -1
  172. package/plugins/StorageTransformPlugin.d.ts +11 -11
  173. package/plugins/StorageTransformPlugin.js +1 -1
  174. package/plugins/StorageTransformPlugin.js.map +1 -1
  175. package/plugins/index.d.ts +2 -0
  176. package/plugins/index.js +26 -0
  177. package/plugins/index.js.map +1 -1
  178. package/storage/object.js +7 -8
  179. package/storage/object.js.map +1 -1
  180. package/types.d.ts +469 -180
  181. package/types.js +55 -9
  182. package/types.js.map +1 -1
  183. package/upgrades/5.33.0/index.js +5 -9
  184. package/upgrades/5.33.0/index.js.map +1 -1
  185. package/utils/converters/Converter.js +1 -1
  186. package/utils/converters/ConverterCollection.d.ts +7 -0
  187. package/utils/converters/ConverterCollection.js +36 -8
  188. package/utils/converters/ConverterCollection.js.map +1 -1
  189. package/utils/converters/valueKeyStorageConverter.js +3 -7
  190. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  191. package/utils/createTypeFromFields.d.ts +15 -0
  192. package/utils/createTypeFromFields.js +75 -0
  193. package/utils/createTypeFromFields.js.map +1 -0
  194. package/utils/createTypeName.js +4 -2
  195. package/utils/createTypeName.js.map +1 -1
  196. package/utils/entryStorage.js +17 -18
  197. package/utils/entryStorage.js.map +1 -1
  198. package/utils/filterModelFields.js +5 -9
  199. package/utils/filterModelFields.js.map +1 -1
  200. package/utils/getBaseFieldType.d.ts +4 -0
  201. package/utils/getBaseFieldType.js +12 -0
  202. package/utils/getBaseFieldType.js.map +1 -0
  203. package/utils/permissions.js +1 -5
  204. package/utils/permissions.js.map +1 -1
  205. package/utils/pluralizedTypeName.js +1 -1
  206. package/utils/renderFields.js +3 -1
  207. package/utils/renderFields.js.map +1 -1
  208. package/utils/renderGetFilterFields.js +8 -3
  209. package/utils/renderGetFilterFields.js.map +1 -1
  210. package/utils/renderInputFields.js +3 -1
  211. package/utils/renderInputFields.js.map +1 -1
  212. package/utils/renderListFilterFields.js +12 -2
  213. package/utils/renderListFilterFields.js.map +1 -1
  214. package/utils/renderSortEnum.d.ts +7 -4
  215. package/utils/renderSortEnum.js +23 -4
  216. package/utils/renderSortEnum.js.map +1 -1
  217. package/utils/toSlug.js +1 -1
  218. package/validators/dynamicZone.d.ts +2 -0
  219. package/validators/dynamicZone.js +24 -0
  220. package/validators/dynamicZone.js.map +1 -0
  221. package/validators/index.js +3 -1
  222. package/validators/index.js.map +1 -1
  223. package/validators/unique.js +1 -1
  224. package/crud/index.d.ts +0 -6
  225. package/crud/index.js +0 -89
  226. package/crud/index.js.map +0 -1
  227. package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
  228. package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
  229. package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  230. package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
  231. package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
  232. package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.assignBeforeModelCreate = void 0;
8
+ exports.assignModelBeforeCreate = void 0;
9
9
 
10
10
  var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
@@ -107,7 +107,7 @@ const getModelId = model => {
107
107
  });
108
108
  };
109
109
 
110
- const createOnBeforeCb = ({
110
+ const createOnModelBeforeCb = ({
111
111
  plugins,
112
112
  storageOperations
113
113
  }) => {
@@ -149,14 +149,14 @@ const createOnBeforeCb = ({
149
149
  * We attach both on before create and createFrom events here.
150
150
  * Callables are identical.
151
151
  */
152
- const assignBeforeModelCreate = params => {
152
+ const assignModelBeforeCreate = params => {
153
153
  const {
154
- onBeforeModelCreate,
155
- onBeforeModelCreateFrom,
154
+ onModelBeforeCreate,
155
+ onModelBeforeCreateFrom,
156
156
  storageOperations,
157
157
  plugins
158
158
  } = params;
159
- onBeforeModelCreate.subscribe(async ({
159
+ onModelBeforeCreate.subscribe(async ({
160
160
  model,
161
161
  input
162
162
  }) => {
@@ -168,7 +168,7 @@ const assignBeforeModelCreate = params => {
168
168
  * then we run the shared create/createFrom methods.
169
169
  */
170
170
 
171
- const cb = createOnBeforeCb({
171
+ const cb = createOnModelBeforeCb({
172
172
  storageOperations,
173
173
  plugins
174
174
  });
@@ -185,10 +185,10 @@ const assignBeforeModelCreate = params => {
185
185
  plugins
186
186
  });
187
187
  });
188
- onBeforeModelCreateFrom.subscribe(createOnBeforeCb({
188
+ onModelBeforeCreateFrom.subscribe(createOnModelBeforeCb({
189
189
  storageOperations,
190
190
  plugins
191
191
  }));
192
192
  };
193
193
 
194
- exports.assignBeforeModelCreate = assignBeforeModelCreate;
194
+ exports.assignModelBeforeCreate = assignModelBeforeCreate;
@@ -1 +1 @@
1
- {"version":3,"names":["disallowedModelIdList","disallowedModelIdEndingList","checkModelIdUniqueness","modelIdList","modelId","includes","WebinyError","pluralizedModelIdCamelCase","pluralize","plural","singularizedModelIdCamelCase","singular","checkModelIdAllowed","checkModelIdEndingAllowed","ending","re","RegExp","matched","match","getModelId","model","name","camelCase","trim","createOnBeforeCb","plugins","storageOperations","params","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","models","list","where","tenant","locale","map","m","assignBeforeModelCreate","onBeforeModelCreate","onBeforeModelCreateFrom","subscribe","input","validateLayout","layout","fields","cb","validateModel"],"sources":["beforeCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport camelCase from \"lodash/camelCase\";\nimport pluralize from \"pluralize\";\nimport {\n BeforeModelCreateFromTopicParams,\n BeforeModelCreateTopicParams,\n CmsModel,\n HeadlessCmsStorageOperations\n} from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\n/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nconst disallowedModelIdEndingList: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\n/**\n * Checks for the uniqueness of provided modelId, against the provided list of models.\n * It also takes plural / singular forms of the provided modelId into account.\n */\nconst checkModelIdUniqueness = (modelIdList: string[], modelId: string) => {\n if (modelIdList.includes(modelId) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n modelId\n }\n );\n }\n /**\n * Additionally, check if the plural form of the received modelId exists too. This prevents users\n * from creating, for example, \"event\" and \"events\" models, which would break the GraphQL schema.\n * 1. First check if user wants to create the \"event\" model, but the \"events\" model already exists.\n */\n const pluralizedModelIdCamelCase = pluralize(modelId);\n if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${pluralizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_PLURAL_ERROR\",\n {\n modelId,\n plural: pluralizedModelIdCamelCase\n }\n );\n }\n\n /**\n * 2. Then check if user wants to create the \"events\" model, but the \"event\" model already exists.\n */\n const singularizedModelIdCamelCase = pluralize.singular(modelId);\n if (modelIdList.includes(singularizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${singularizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_SINGULAR_ERROR\",\n {\n modelId,\n singular: singularizedModelIdCamelCase\n }\n );\n }\n};\n\nconst checkModelIdAllowed = (modelId: string): void => {\n if (disallowedModelIdList.includes(modelId) === false) {\n return;\n }\n throw new WebinyError(`Provided model ID \"${modelId}\" is not allowed.`);\n};\n\nconst checkModelIdEndingAllowed = (modelId: string): void => {\n for (const ending of disallowedModelIdEndingList) {\n const re = new RegExp(`${ending}$`, \"i\");\n const matched = modelId.match(re);\n if (matched === null) {\n continue;\n }\n throw new WebinyError(\n `ModelId that ends with \"${ending}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n modelId\n }\n );\n }\n};\n\nconst getModelId = (model: CmsModel): string => {\n const { modelId, name } = model;\n if (!!modelId) {\n return camelCase(modelId.trim());\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new WebinyError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`,\n \"MISSING_MODEL_DATA\",\n {\n model\n }\n );\n};\n\ninterface CreateOnBeforeCreateCbParams {\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nconst createOnBeforeCb = ({ plugins, storageOperations }: CreateOnBeforeCreateCbParams) => {\n return async (params: BeforeModelCreateTopicParams | BeforeModelCreateFromTopicParams) => {\n const { model } = params;\n\n const modelId = getModelId(model);\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find((item: CmsModelPlugin) => item.contentModel.modelId === modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n `Cannot create \"${model.modelId}\" content model because one is already registered via a plugin.`,\n \"CONTENT_MODEL_CREATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: model.tenant,\n locale: model.locale\n }\n });\n const modelIdList = models.map(m => m.modelId);\n\n /**\n * We need to check for:\n * - is that exact modelId allowed\n * - is modelId unique\n * - is model ending allowed\n */\n checkModelIdAllowed(modelId);\n checkModelIdEndingAllowed(modelId);\n checkModelIdUniqueness(modelIdList, modelId);\n model.modelId = modelId;\n };\n};\n\ninterface AssignBeforeModelCreateParams {\n onBeforeModelCreate: Topic<BeforeModelCreateTopicParams>;\n onBeforeModelCreateFrom: Topic<BeforeModelCreateFromTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\n/**\n * We attach both on before create and createFrom events here.\n * Callables are identical.\n */\nexport const assignBeforeModelCreate = (params: AssignBeforeModelCreateParams) => {\n const { onBeforeModelCreate, onBeforeModelCreateFrom, storageOperations, plugins } = params;\n\n onBeforeModelCreate.subscribe(async ({ model, input }) => {\n /**\n * First the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then we run the shared create/createFrom methods.\n */\n const cb = createOnBeforeCb({\n storageOperations,\n plugins\n });\n await cb({\n model,\n input\n });\n\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n model,\n plugins\n });\n });\n\n onBeforeModelCreateFrom.subscribe(\n createOnBeforeCb({\n storageOperations,\n plugins\n })\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AASA;;AACA;;AACA;;AAEA,MAAMA,qBAA+B,GAAG,CACpC,cADoC,EAEpC,eAFoC,EAGpC,mBAHoC,EAIpC,oBAJoC,CAAxC;AAMA;AACA;AACA;AACA;;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAD0C,EAE1C,MAF0C,EAG1C,MAH0C,EAI1C,OAJ0C,EAK1C,QAL0C,EAM1C,SAN0C,CAA9C;AASA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAD,EAAwBC,OAAxB,KAA4C;EACvE,IAAID,WAAW,CAACE,QAAZ,CAAqBD,OAArB,MAAkC,IAAtC,EAA4C;IACxC,MAAM,IAAIE,cAAJ,CACD,+BAA8BF,OAAQ,mBADrC,EAEF,iBAFE,EAGF;MACIA;IADJ,CAHE,CAAN;EAOH;EACD;AACJ;AACA;AACA;AACA;;;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAA,EAAUJ,OAAV,CAAnC;;EACA,IAAID,WAAW,CAACE,QAAZ,CAAqBE,0BAArB,MAAqD,IAAzD,EAA+D;IAC3D,MAAM,IAAID,cAAJ,CACD,+BAA8BF,OAAQ,+CAA8CG,0BAA2B,SAD9G,EAEF,uBAFE,EAGF;MACIH,OADJ;MAEIK,MAAM,EAAEF;IAFZ,CAHE,CAAN;EAQH;EAED;AACJ;AACA;;;EACI,MAAMG,4BAA4B,GAAGF,kBAAA,CAAUG,QAAV,CAAmBP,OAAnB,CAArC;;EACA,I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ApB,CAA8B,OAAO;IAAEzB,KAAF;IAAS0B;EAAT,CAAP,KAA4B;IACtD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAe3B,KAAK,CAAC4B,MAArB,EAA6B5B,KAAK,CAAC6B,MAAnC;IACA;AACR;AACA;;IACQ,MAAMC,EAAE,GAAG1B,gBAAgB,CAAC;MACxBE,iBADwB;MAExBD;IAFwB,CAAD,CAA3B;IAIA,MAAMyB,EAAE,CAAC;MACL9B,KADK;MAEL0B;IAFK,CAAD,CAAR;IAKA;AACR;AACA;;IACQ,MAAM,IAAAK,4BAAA,EAAc;MAChB/B,KADgB;MAEhBK;IAFgB,CAAd,CAAN;EAIH,CAxBD;EA0BAmB,uBAAuB,CAACC,SAAxB,CACIrB,gBAAgB,CAAC;IACbE,iBADa;IAEbD;EAFa,CAAD,CADpB;AAMH,CAnCM"}
1
+ {"version":3,"names":["disallowedModelIdList","disallowedModelIdEndingList","checkModelIdUniqueness","modelIdList","modelId","includes","WebinyError","pluralizedModelIdCamelCase","pluralize","plural","singularizedModelIdCamelCase","singular","checkModelIdAllowed","checkModelIdEndingAllowed","ending","re","RegExp","matched","match","getModelId","model","name","camelCase","trim","createOnModelBeforeCb","plugins","storageOperations","params","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","models","list","where","tenant","locale","map","m","assignModelBeforeCreate","onModelBeforeCreate","onModelBeforeCreateFrom","subscribe","input","validateLayout","layout","fields","cb","validateModel"],"sources":["beforeCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport camelCase from \"lodash/camelCase\";\nimport pluralize from \"pluralize\";\nimport {\n OnModelBeforeCreateFromTopicParams,\n OnModelBeforeCreateTopicParams,\n CmsModel,\n HeadlessCmsStorageOperations\n} from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\n/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nconst disallowedModelIdEndingList: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\n/**\n * Checks for the uniqueness of provided modelId, against the provided list of models.\n * It also takes plural / singular forms of the provided modelId into account.\n */\nconst checkModelIdUniqueness = (modelIdList: string[], modelId: string) => {\n if (modelIdList.includes(modelId) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n modelId\n }\n );\n }\n /**\n * Additionally, check if the plural form of the received modelId exists too. This prevents users\n * from creating, for example, \"event\" and \"events\" models, which would break the GraphQL schema.\n * 1. First check if user wants to create the \"event\" model, but the \"events\" model already exists.\n */\n const pluralizedModelIdCamelCase = pluralize(modelId);\n if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${pluralizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_PLURAL_ERROR\",\n {\n modelId,\n plural: pluralizedModelIdCamelCase\n }\n );\n }\n\n /**\n * 2. Then check if user wants to create the \"events\" model, but the \"event\" model already exists.\n */\n const singularizedModelIdCamelCase = pluralize.singular(modelId);\n if (modelIdList.includes(singularizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${singularizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_SINGULAR_ERROR\",\n {\n modelId,\n singular: singularizedModelIdCamelCase\n }\n );\n }\n};\n\nconst checkModelIdAllowed = (modelId: string): void => {\n if (disallowedModelIdList.includes(modelId) === false) {\n return;\n }\n throw new WebinyError(`Provided model ID \"${modelId}\" is not allowed.`);\n};\n\nconst checkModelIdEndingAllowed = (modelId: string): void => {\n for (const ending of disallowedModelIdEndingList) {\n const re = new RegExp(`${ending}$`, \"i\");\n const matched = modelId.match(re);\n if (matched === null) {\n continue;\n }\n throw new WebinyError(\n `ModelId that ends with \"${ending}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n modelId\n }\n );\n }\n};\n\nconst getModelId = (model: CmsModel): string => {\n const { modelId, name } = model;\n if (!!modelId) {\n return camelCase(modelId.trim());\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new WebinyError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`,\n \"MISSING_MODEL_DATA\",\n {\n model\n }\n );\n};\n\ninterface CreateOnModelBeforeCreateCbParams {\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nconst createOnModelBeforeCb = ({\n plugins,\n storageOperations\n}: CreateOnModelBeforeCreateCbParams) => {\n return async (params: OnModelBeforeCreateTopicParams | OnModelBeforeCreateFromTopicParams) => {\n const { model } = params;\n\n const modelId = getModelId(model);\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find((item: CmsModelPlugin) => item.contentModel.modelId === modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n `Cannot create \"${model.modelId}\" content model because one is already registered via a plugin.`,\n \"CONTENT_MODEL_CREATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: model.tenant,\n locale: model.locale\n }\n });\n const modelIdList = models.map(m => m.modelId);\n\n /**\n * We need to check for:\n * - is that exact modelId allowed\n * - is modelId unique\n * - is model ending allowed\n */\n checkModelIdAllowed(modelId);\n checkModelIdEndingAllowed(modelId);\n checkModelIdUniqueness(modelIdList, modelId);\n model.modelId = modelId;\n };\n};\n\ninterface AssignBeforeModelCreateParams {\n onModelBeforeCreate: Topic<OnModelBeforeCreateTopicParams>;\n onModelBeforeCreateFrom: Topic<OnModelBeforeCreateFromTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\n/**\n * We attach both on before create and createFrom events here.\n * Callables are identical.\n */\nexport const assignModelBeforeCreate = (params: AssignBeforeModelCreateParams) => {\n const { onModelBeforeCreate, onModelBeforeCreateFrom, storageOperations, plugins } = params;\n\n onModelBeforeCreate.subscribe(async ({ model, input }) => {\n /**\n * First the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then we run the shared create/createFrom methods.\n */\n const cb = createOnModelBeforeCb({\n storageOperations,\n plugins\n });\n await cb({\n model,\n input\n });\n\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n model,\n plugins\n });\n });\n\n onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageOperations,\n plugins\n })\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AASA;;AACA;;AACA;;AAEA,MAAMA,qBAA+B,GAAG,CACpC,cADoC,EAEpC,eAFoC,EAGpC,mBAHoC,EAIpC,oBAJoC,CAAxC;AAMA;AACA;AACA;AACA;;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAD0C,EAE1C,MAF0C,EAG1C,MAH0C,EAI1C,OAJ0C,EAK1C,QAL0C,EAM1C,SAN0C,CAA9C;AASA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAD,EAAwBC,OAAxB,KAA4C;EACvE,IAAID,WAAW,CAACE,QAAZ,CAAqBD,OAArB,MAAkC,IAAtC,EAA4C;IACxC,MAAM,IAAIE,cAAJ,CACD,+BAA8BF,OAAQ,mBADrC,EAEF,iBAFE,EAGF;MACIA;IADJ,CAHE,CAAN;EAOH;EACD;AACJ;AACA;AACA;AACA;;;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAA,EAAUJ,OAAV,CAAnC;;EACA,IAAID,WAAW,CAACE,QAAZ,CAAqBE,0BAArB,MAAqD,IAAzD,EAA+D;IAC3D,MAAM,IAAID,cAAJ,CACD,+BAA8BF,OAAQ,+CAA8CG,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H,CA1CD;;AAmDA;AACA;AACA;AACA;AACO,MAAMsC,uBAAuB,GAAIf,MAAD,IAA2C;EAC9E,MAAM;IAAEgB,mBAAF;IAAuBC,uBAAvB;IAAgDlB,iBAAhD;IAAmED;EAAnE,IAA+EE,MAArF;EAEAgB,mBAAmB,CAACE,SAApB,CAA8B,OAAO;IAAEzB,KAAF;IAAS0B;EAAT,CAAP,KAA4B;IACtD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAe3B,KAAK,CAAC4B,MAArB,EAA6B5B,KAAK,CAAC6B,MAAnC;IACA;AACR;AACA;;IACQ,MAAMC,EAAE,GAAG1B,qBAAqB,CAAC;MAC7BE,iBAD6B;MAE7BD;IAF6B,CAAD,CAAhC;IAIA,MAAMyB,EAAE,CAAC;MACL9B,KADK;MAEL0B;IAFK,CAAD,CAAR;IAKA;AACR;AACA;;IACQ,MAAM,IAAAK,4BAAA,EAAc;MAChB/B,KADgB;MAEhBK;IAFgB,CAAd,CAAN;EAIH,CAxBD;EA0BAmB,uBAAuB,CAACC,SAAxB,CACIrB,qBAAqB,CAAC;IAClBE,iBADkB;IAElBD;EAFkB,CAAD,CADzB;AAMH,CAnCM"}
@@ -1,10 +1,10 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { BeforeModelDeleteTopicParams, HeadlessCmsStorageOperations } from "../../types";
2
+ import { OnModelBeforeDeleteTopicParams, HeadlessCmsStorageOperations } from "../../types";
3
3
  import { PluginsContainer } from "@webiny/plugins";
4
4
  interface AssignBeforeModelDeleteParams {
5
- onBeforeModelDelete: Topic<BeforeModelDeleteTopicParams>;
5
+ onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;
6
6
  storageOperations: HeadlessCmsStorageOperations;
7
7
  plugins: PluginsContainer;
8
8
  }
9
- export declare const assignBeforeModelDelete: (params: AssignBeforeModelDeleteParams) => void;
9
+ export declare const assignModelBeforeDelete: (params: AssignBeforeModelDeleteParams) => void;
10
10
  export {};
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.assignBeforeModelDelete = void 0;
8
+ exports.assignModelBeforeDelete = void 0;
9
9
 
10
10
  var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
@@ -13,13 +13,13 @@ var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
13
 
14
14
  var _valueKeyStorageConverter = require("../../utils/converters/valueKeyStorageConverter");
15
15
 
16
- const assignBeforeModelDelete = params => {
16
+ const assignModelBeforeDelete = params => {
17
17
  const {
18
- onBeforeModelDelete,
18
+ onModelBeforeDelete,
19
19
  storageOperations,
20
20
  plugins
21
21
  } = params;
22
- onBeforeModelDelete.subscribe(async params => {
22
+ onModelBeforeDelete.subscribe(async params => {
23
23
  const {
24
24
  model
25
25
  } = params;
@@ -57,4 +57,4 @@ const assignBeforeModelDelete = params => {
57
57
  });
58
58
  };
59
59
 
60
- exports.assignBeforeModelDelete = assignBeforeModelDelete;
60
+ exports.assignModelBeforeDelete = assignModelBeforeDelete;
@@ -1 +1 @@
1
- {"version":3,"names":["assignBeforeModelDelete","params","onBeforeModelDelete","storageOperations","plugins","subscribe","model","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","entries","result","list","attachCmsModelFieldConverters","where","latest","limit","items","ex","error","length"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { BeforeModelDeleteTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { attachCmsModelFieldConverters } from \"~/utils/converters/valueKeyStorageConverter\";\n\ninterface AssignBeforeModelDeleteParams {\n onBeforeModelDelete: Topic<BeforeModelDeleteTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\nexport const assignBeforeModelDelete = (params: AssignBeforeModelDeleteParams) => {\n const { onBeforeModelDelete, storageOperations, plugins } = params;\n\n onBeforeModelDelete.subscribe(async params => {\n const { model } = 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 deleted.\",\n \"CONTENT_MODEL_DELETE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n let entries = [];\n try {\n const result = await storageOperations.entries.list(\n attachCmsModelFieldConverters({\n model,\n plugins\n }),\n {\n where: {\n latest: true\n },\n limit: 1\n }\n );\n entries = result.items;\n } catch (ex) {\n throw new WebinyError(\n \"Could not retrieve a list of content entries from the model.\",\n \"ENTRIES_ERROR\",\n {\n error: ex,\n model\n }\n );\n }\n if (entries.length > 0) {\n throw new WebinyError(\n `Cannot delete content model \"${model.modelId}\" because there are existing entries.`,\n \"CONTENT_MODEL_BEFORE_DELETE_HOOK_FAILED\"\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAOO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC,iBAAvB;IAA0CC;EAA1C,IAAsDH,MAA5D;EAEAC,mBAAmB,CAACG,SAApB,CAA8B,MAAMJ,MAAN,IAAgB;IAC1C,MAAM;MAAEK;IAAF,IAAYL,MAAlB;IAEA,MAAMM,WAAW,GAAGH,OAAO,CACtBI,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,YAAL,CAAkBC,OAAlB,KAA8BR,KAAK,CAACQ,OAFlC,CAApB;;IAIA,IAAIP,WAAJ,EAAiB;MACb,MAAM,IAAIQ,cAAJ,CACF,uDADE,EAEF,4BAFE,EAGF;QACID,OAAO,EAAER,KAAK,CAACQ;MADnB,CAHE,CAAN;IAOH;;IAED,IAAIE,OAAO,GAAG,EAAd;;IACA,IAAI;MACA,MAAMC,MAAM,GAAG,MAAMd,iBAAiB,CAACa,OAAlB,CAA0BE,IAA1B,CACjB,IAAAC,uDAAA,EAA8B;QAC1Bb,KAD0B;QAE1BF;MAF0B,CAA9B,CADiB,EAKjB;QACIgB,KAAK,EAAE;UACHC,MAAM,EAAE;QADL,CADX;QAIIC,KAAK,EAAE;MAJX,CALiB,CAArB;MAYAN,OAAO,GAAGC,MAAM,CAACM,KAAjB;IACH,CAdD,CAcE,OAAOC,EAAP,EAAW;MACT,MAAM,IAAIT,cAAJ,CACF,8DADE,EAEF,eAFE,EAGF;QACIU,KAAK,EAAED,EADX;QAEIlB;MAFJ,CAHE,CAAN;IAQH;;IACD,IAAIU,OAAO,CAACU,MAAR,GAAiB,CAArB,EAAwB;MACpB,MAAM,IAAIX,cAAJ,CACD,gCAA+BT,KAAK,CAACQ,OAAQ,uCAD5C,EAEF,yCAFE,CAAN;IAIH;EACJ,CAhDD;AAiDH,CApDM"}
1
+ {"version":3,"names":["assignModelBeforeDelete","params","onModelBeforeDelete","storageOperations","plugins","subscribe","model","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","entries","result","list","attachCmsModelFieldConverters","where","latest","limit","items","ex","error","length"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeDeleteTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { attachCmsModelFieldConverters } from \"~/utils/converters/valueKeyStorageConverter\";\n\ninterface AssignBeforeModelDeleteParams {\n onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\nexport const assignModelBeforeDelete = (params: AssignBeforeModelDeleteParams) => {\n const { onModelBeforeDelete, storageOperations, plugins } = params;\n\n onModelBeforeDelete.subscribe(async params => {\n const { model } = 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 deleted.\",\n \"CONTENT_MODEL_DELETE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n let entries = [];\n try {\n const result = await storageOperations.entries.list(\n attachCmsModelFieldConverters({\n model,\n plugins\n }),\n {\n where: {\n latest: true\n },\n limit: 1\n }\n );\n entries = result.items;\n } catch (ex) {\n throw new WebinyError(\n \"Could not retrieve a list of content entries from the model.\",\n \"ENTRIES_ERROR\",\n {\n error: ex,\n model\n }\n );\n }\n if (entries.length > 0) {\n throw new WebinyError(\n `Cannot delete content model \"${model.modelId}\" because there are existing entries.`,\n \"CONTENT_MODEL_BEFORE_DELETE_HOOK_FAILED\"\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAOO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC,iBAAvB;IAA0CC;EAA1C,IAAsDH,MAA5D;EAEAC,mBAAmB,CAACG,SAApB,CAA8B,MAAMJ,MAAN,IAAgB;IAC1C,MAAM;MAAEK;IAAF,IAAYL,MAAlB;IAEA,MAAMM,WAAW,GAAGH,OAAO,CACtBI,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,YAAL,CAAkBC,OAAlB,KAA8BR,KAAK,CAACQ,OAFlC,CAApB;;IAIA,IAAIP,WAAJ,EAAiB;MACb,MAAM,IAAIQ,cAAJ,CACF,uDADE,EAEF,4BAFE,EAGF;QACID,OAAO,EAAER,KAAK,CAACQ;MADnB,CAHE,CAAN;IAOH;;IAED,IAAIE,OAAO,GAAG,EAAd;;IACA,IAAI;MACA,MAAMC,MAAM,GAAG,MAAMd,iBAAiB,CAACa,OAAlB,CAA0BE,IAA1B,CACjB,IAAAC,uDAAA,EAA8B;QAC1Bb,KAD0B;QAE1BF;MAF0B,CAA9B,CADiB,EAKjB;QACIgB,KAAK,EAAE;UACHC,MAAM,EAAE;QADL,CADX;QAIIC,KAAK,EAAE;MAJX,CALiB,CAArB;MAYAN,OAAO,GAAGC,MAAM,CAACM,KAAjB;IACH,CAdD,CAcE,OAAOC,EAAP,EAAW;MACT,MAAM,IAAIT,cAAJ,CACF,8DADE,EAEF,eAFE,EAGF;QACIU,KAAK,EAAED,EADX;QAEIlB;MAFJ,CAHE,CAAN;IAQH;;IACD,IAAIU,OAAO,CAACU,MAAR,GAAiB,CAArB,EAAwB;MACpB,MAAM,IAAIX,cAAJ,CACD,gCAA+BT,KAAK,CAACQ,OAAQ,uCAD5C,EAEF,yCAFE,CAAN;IAIH;EACJ,CAhDD;AAiDH,CApDM"}
@@ -1,10 +1,10 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { BeforeModelUpdateTopicParams, HeadlessCmsStorageOperations } from "../../types";
2
+ import { OnModelBeforeUpdateTopicParams, HeadlessCmsStorageOperations } from "../../types";
3
3
  import { PluginsContainer } from "@webiny/plugins";
4
4
  interface AssignBeforeModelUpdateParams {
5
- onBeforeModelUpdate: Topic<BeforeModelUpdateTopicParams>;
5
+ onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;
6
6
  storageOperations: HeadlessCmsStorageOperations;
7
7
  plugins: PluginsContainer;
8
8
  }
9
- export declare const assignBeforeModelUpdate: (params: AssignBeforeModelUpdateParams) => void;
9
+ export declare const assignModelBeforeUpdate: (params: AssignBeforeModelUpdateParams) => void;
10
10
  export {};
@@ -3,18 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.assignBeforeModelUpdate = void 0;
6
+ exports.assignModelBeforeUpdate = void 0;
7
7
 
8
8
  var _validateModel = require("./validateModel");
9
9
 
10
10
  var _validateLayout = require("./validateLayout");
11
11
 
12
- const assignBeforeModelUpdate = params => {
12
+ const assignModelBeforeUpdate = params => {
13
13
  const {
14
- onBeforeModelUpdate,
14
+ onModelBeforeUpdate,
15
15
  plugins
16
16
  } = params;
17
- onBeforeModelUpdate.subscribe(async ({
17
+ onModelBeforeUpdate.subscribe(async ({
18
18
  model,
19
19
  original
20
20
  }) => {
@@ -34,4 +34,4 @@ const assignBeforeModelUpdate = params => {
34
34
  });
35
35
  };
36
36
 
37
- exports.assignBeforeModelUpdate = assignBeforeModelUpdate;
37
+ exports.assignModelBeforeUpdate = assignModelBeforeUpdate;
@@ -1 +1 @@
1
- {"version":3,"names":["assignBeforeModelUpdate","params","onBeforeModelUpdate","plugins","subscribe","model","original","validateLayout","layout","fields","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { BeforeModelUpdateTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\ninterface AssignBeforeModelUpdateParams {\n onBeforeModelUpdate: Topic<BeforeModelUpdateTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\nexport const assignBeforeModelUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onBeforeModelUpdate, plugins } = params;\n\n onBeforeModelUpdate.subscribe(async ({ model, original }) => {\n /**\n * First we go through the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then the model and fields...\n */\n await validateModel({\n model,\n original,\n plugins\n });\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC;EAAvB,IAAmCF,MAAzC;EAEAC,mBAAmB,CAACE,SAApB,CAA8B,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA+B;IACzD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAeF,KAAK,CAACG,MAArB,EAA6BH,KAAK,CAACI,MAAnC;IACA;AACR;AACA;;IACQ,MAAM,IAAAC,4BAAA,EAAc;MAChBL,KADgB;MAEhBC,QAFgB;MAGhBH;IAHgB,CAAd,CAAN;EAKH,CAbD;AAcH,CAjBM"}
1
+ {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","plugins","subscribe","model","original","validateLayout","layout","fields","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, plugins } = params;\n\n onModelBeforeUpdate.subscribe(async ({ model, original }) => {\n /**\n * First we go through the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then the model and fields...\n */\n await validateModel({\n model,\n original,\n plugins\n });\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC;EAAvB,IAAmCF,MAAzC;EAEAC,mBAAmB,CAACE,SAApB,CAA8B,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA+B;IACzD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAeF,KAAK,CAACG,MAArB,EAA6BH,KAAK,CAACI,MAAnC;IACA;AACR;AACA;;IACQ,MAAM,IAAAC,4BAAA,EAAc;MAChBL,KADgB;MAEhBC,QAFgB;MAGhBH;IAHgB,CAAd,CAAN;EAKH,CAbD;AAcH,CAjBM"}
@@ -5,12 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createFieldStorageId = void 0;
7
7
 
8
+ var _getBaseFieldType = require("../../utils/getBaseFieldType");
9
+
8
10
  const createFieldStorageId = params => {
9
11
  const {
10
12
  type,
11
13
  id
12
14
  } = params;
13
- return `${type}@${id}`;
15
+ return `${(0, _getBaseFieldType.getBaseFieldType)({
16
+ type
17
+ })}@${id}`;
14
18
  };
15
19
 
16
20
  exports.createFieldStorageId = createFieldStorageId;
@@ -1 +1 @@
1
- {"version":3,"names":["createFieldStorageId","params","type","id"],"sources":["createFieldStorageId.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const createFieldStorageId = (params: Pick<CmsModelField, \"id\" | \"type\">): string => {\n const { type, id } = params;\n return `${type}@${id}`;\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,oBAAoB,GAAIC,MAAD,IAAwD;EACxF,MAAM;IAAEC,IAAF;IAAQC;EAAR,IAAeF,MAArB;EACA,OAAQ,GAAEC,IAAK,IAAGC,EAAG,EAArB;AACH,CAHM"}
1
+ {"version":3,"names":["createFieldStorageId","params","type","id","getBaseFieldType"],"sources":["createFieldStorageId.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport const createFieldStorageId = (params: Pick<CmsModelField, \"id\" | \"type\">): string => {\n const { type, id } = params;\n return `${getBaseFieldType({ type })}@${id}`;\n};\n"],"mappings":";;;;;;;AACA;;AAEO,MAAMA,oBAAoB,GAAIC,MAAD,IAAwD;EACxF,MAAM;IAAEC,IAAF;IAAQC;EAAR,IAAeF,MAArB;EACA,OAAQ,GAAE,IAAAG,kCAAA,EAAiB;IAAEF;EAAF,CAAjB,CAA2B,IAAGC,EAAG,EAA3C;AACH,CAHM"}
@@ -50,6 +50,10 @@ const ContentModelFieldModel = (0, _fields.withFields)({
50
50
  type: (0, _fields.setOnce)()((0, _fields.string)({
51
51
  validation: requiredShortString
52
52
  })),
53
+ tags: (0, _commodoFieldsObject.object)({
54
+ value: [],
55
+ required: false
56
+ }),
53
57
  multipleValues: (0, _fields.boolean)({
54
58
  value: false
55
59
  }),
@@ -134,6 +138,10 @@ const CreateContentModelModel = (0, _fields.withFields)({
134
138
  layout: (0, _commodoFieldsObject.object)({
135
139
  value: [],
136
140
  required: true
141
+ }),
142
+ tags: (0, _commodoFieldsObject.object)({
143
+ value: [],
144
+ required: false
137
145
  })
138
146
  })();
139
147
  exports.CreateContentModelModel = CreateContentModelModel;
@@ -175,6 +183,10 @@ const UpdateContentModelModel = (0, _fields.withFields)({
175
183
  layout: (0, _commodoFieldsObject.object)({
176
184
  value: [],
177
185
  required: true
186
+ }),
187
+ tags: (0, _commodoFieldsObject.object)({
188
+ value: [],
189
+ required: false
178
190
  })
179
191
  })();
180
192
  exports.UpdateContentModelModel = UpdateContentModelModel;
@@ -1 +1 @@
1
- {"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","validateFieldId","label","helpText","placeholderText","type","setOnce","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;A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AEE;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"}
1
+ {"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","validateFieldId","label","helpText","placeholderText","type","setOnce","tags","object","value","required","multipleValues","boolean","predefinedValues","fields","instanceOf","enabled","values","list","selected","renderer","message","settings","listValidation","CreateContentModelModel","modelId","description","group","layout","CreateContentModelModelFrom","locale","UpdateContentModelModel","titleFieldId"],"sources":["models.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\n/**\n * Package commodo-fields does not have object.\n */\n// @ts-ignore\nimport { withFields, string, setOnce, boolean, fields } from \"@commodo/fields\";\nimport { validateFieldId } from \"./fieldIdValidation\";\n\nconst requiredShortString = validation.create(\"required,maxLength:255\");\nconst shortString = validation.create(\"maxLength:255\");\n\nconst RendererModel = withFields({\n name: string({ validation: requiredShortString })\n})();\n\nexport const ContentModelFieldModel = withFields({\n id: string({ validation: requiredShortString }),\n fieldId: string({\n validation: validateFieldId\n }),\n label: string({ validation: requiredShortString }),\n helpText: string({ validation: shortString }),\n placeholderText: string({ validation: shortString }),\n type: setOnce()(string({ validation: requiredShortString })),\n tags: object({ value: [], required: false }),\n multipleValues: boolean({ value: false }),\n predefinedValues: fields({\n value: {},\n instanceOf: withFields({\n enabled: boolean(),\n values: fields({\n value: [],\n list: true,\n instanceOf: withFields({\n label: string(),\n value: string(),\n selected: boolean()\n })()\n })\n })()\n }),\n renderer: fields({ instanceOf: RendererModel, validation: shortString }),\n validation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n listValidation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n settings: object({ value: {} })\n /**\n * By the default, field is not deleted.\n */\n // isDeleted: boolean({ value: false })\n})();\n\nexport const CreateContentModelModel = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true }),\n tags: object({ value: [], required: false })\n})();\n\nexport const CreateContentModelModelFrom = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n locale: string({ validation: shortString })\n})();\n\nexport const UpdateContentModelModel = withFields({\n name: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: shortString }),\n titleFieldId: string(),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true }),\n tags: object({ value: [], required: false })\n})();\n"],"mappings":";;;;;;;AAAA;;AAKA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAGC,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB,CAA5B;;AACA,MAAMC,WAAW,GAAGF,sBAAA,CAAWC,MAAX,CAAkB,eAAlB,CAApB;;AAEA,MAAME,aAAa,GAAG,IAAAC,kBAAA,EAAW;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AAU,EAAEE;EAAd,CAAP,CAFiC;EAG9CkC,KAAK,EAAE,IAAA9B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHuC;EAI9CuC,YAAY,EAAE,IAAAnC,cAAA,GAJgC;EAK9CiB,MAAM,EAAE,IAAAA,cAAA,EAAO;IAAEC,UAAU,EAAEjB,sBAAd;IAAsCW,KAAK,EAAE,EAA7C;IAAiDS,IAAI,EAAE,IAAvD;IAA6DR,QAAQ,EAAE;EAAvE,CAAP,CALsC;EAM9CkB,MAAM,EAAE,IAAApB,2BAAA,EAAO;IAAEC,KAAK,EAAE,EAAT;IAAaC,QAAQ,EAAE;EAAvB,CAAP,CANsC;EAO9CH,IAAI,EAAE,IAAAC,2BAAA,EAAO;IAAEC,KAAK,EAAE,EAAT;IAAaC,QAAQ,EAAE;EAAvB,CAAP;AAPwC,CAAX,GAAhC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.validateModelFields = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
13
 
@@ -17,9 +17,9 @@ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
17
17
 
18
18
  var _createFieldStorageId = require("./createFieldStorageId");
19
19
 
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; }
20
+ var _getBaseFieldType = require("../../utils/getBaseFieldType");
21
21
 
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; }
22
+ var _plugins = require("../../plugins");
23
23
 
24
24
  const defaultTitleFieldId = "id";
25
25
  const allowedTitleFieldTypes = ["text", "number"];
@@ -40,7 +40,7 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
40
40
 
41
41
  if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
42
42
  const titleField = fields.find(field => {
43
- return field.type === "text" && !field.multipleValues;
43
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
44
44
  });
45
45
  return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
46
46
  }
@@ -133,6 +133,24 @@ const extractInvalidField = (model, err) => {
133
133
  };
134
134
  };
135
135
 
136
+ const createValidateChildFields = plugins => {
137
+ return ({
138
+ fields,
139
+ originalFields
140
+ }) => {
141
+ if (fields.length === 0) {
142
+ return;
143
+ }
144
+
145
+ validateFields({
146
+ fields,
147
+ originalFields,
148
+ plugins,
149
+ lockedFields: []
150
+ });
151
+ };
152
+ };
153
+
136
154
  const validateFields = params => {
137
155
  const {
138
156
  plugins,
@@ -142,14 +160,14 @@ const validateFields = params => {
142
160
  } = params;
143
161
  const fieldIdList = [];
144
162
  const storageIdList = [];
163
+ const validateChildFields = createValidateChildFields(plugins);
145
164
 
146
165
  for (const field of fields) {
147
- var _field$settings, _originalField$settin;
148
-
149
- const plugin = plugins.find(item => item.fieldType === field.type);
166
+ const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
167
+ const plugin = plugins.find(plugin => plugin.fieldType === baseType);
150
168
 
151
169
  if (!plugin) {
152
- throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
170
+ throw new Error(`Cannot update content model because of the unknown "${baseType}" field.`);
153
171
  }
154
172
 
155
173
  const originalField = originalFields.find(f => f.id === field.id);
@@ -227,31 +245,18 @@ const validateFields = params => {
227
245
 
228
246
  storageIdList.push(field.storageId);
229
247
  /**
230
- * TODO maybe make this part pluginable?
231
- * We need to check the object field child fields.
232
- * It must be recursive.
248
+ * There might be some plugins which allow child fields.
249
+ * We use this method to validate them as well.
233
250
  */
234
251
 
235
- if (field.type !== "object") {
252
+ if (!plugin.validateChildFields) {
236
253
  continue;
237
254
  }
238
255
 
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: []
256
+ plugin.validateChildFields({
257
+ field,
258
+ originalField,
259
+ validate: validateChildFields
255
260
  });
256
261
  }
257
262
  };
@@ -279,6 +284,7 @@ const validateModelFields = params => {
279
284
  */
280
285
 
281
286
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
287
+ const sorterPlugins = plugins.byType(_plugins.CmsGraphQLSchemaSorterPlugin.type);
282
288
  validateFields({
283
289
  fields,
284
290
  originalFields: (original === null || original === void 0 ? void 0 : original.fields) || [],
@@ -292,9 +298,10 @@ const validateModelFields = params => {
292
298
  */
293
299
  const schema = (0, _createManageSDL.createManageSDL)({
294
300
  model,
295
- fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => _objectSpread(_objectSpread({}, acc), {}, {
301
+ fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, acc), {}, {
296
302
  [pl.fieldType]: pl
297
- }), {})
303
+ }), {}),
304
+ sorterPlugins
298
305
  });
299
306
 
300
307
  try {
@@ -319,25 +326,23 @@ const validateModelFields = params => {
319
326
  */
320
327
 
321
328
  if (!existingField) {
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
- // );
329
+ continue;
330
330
  }
331
331
 
332
332
  if (lockedField.multipleValues !== existingField.multipleValues) {
333
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
+ reason: `"multipleValues" changed`,
334
335
  field: existingField
335
336
  });
336
337
  }
337
338
 
338
- if (lockedField.type !== existingField.type) {
339
+ const fieldType = (0, _getBaseFieldType.getBaseFieldType)(existingField);
340
+
341
+ if (lockedField.type !== fieldType) {
339
342
  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
343
+ reason: `"type" changed`,
344
+ lockedFieldType: lockedField.type,
345
+ existingFieldType: fieldType
341
346
  });
342
347
  }
343
348
  /**
@@ -345,7 +350,7 @@ const validateModelFields = params => {
345
350
  */
346
351
 
347
352
 
348
- const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === lockedField.type);
353
+ const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === (0, _getBaseFieldType.getBaseFieldType)(lockedField));
349
354
 
350
355
  for (const plugin of lockedFieldsByType) {
351
356
  if (typeof plugin.checkLockedField !== "function") {