@webiny/api-headless-cms 0.0.0-unstable.d4f203fa97 → 0.0.0-unstable.d7f521b032

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 (343) hide show
  1. package/context.d.ts +5 -2
  2. package/context.js +53 -19
  3. package/context.js.map +1 -1
  4. package/crud/contentEntry/afterDelete.js +0 -5
  5. package/crud/contentEntry/afterDelete.js.map +1 -1
  6. package/crud/contentEntry/beforeCreate.js +0 -3
  7. package/crud/contentEntry/beforeCreate.js.map +1 -1
  8. package/crud/contentEntry/beforeUpdate.js +0 -3
  9. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  10. package/crud/contentEntry/entryDataValidation.js +1 -40
  11. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  12. package/crud/contentEntry/markLockedFields.js +16 -29
  13. package/crud/contentEntry/markLockedFields.js.map +1 -1
  14. package/crud/contentEntry/referenceFieldsMapping.js +12 -64
  15. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  16. package/crud/contentEntry/searchableFields.d.ts +9 -0
  17. package/crud/contentEntry/searchableFields.js +72 -0
  18. package/crud/contentEntry/searchableFields.js.map +1 -0
  19. package/crud/contentEntry.crud.js +120 -181
  20. package/crud/contentEntry.crud.js.map +1 -1
  21. package/crud/contentModel/afterCreate.js +0 -2
  22. package/crud/contentModel/afterCreate.js.map +1 -1
  23. package/crud/contentModel/afterCreateFrom.js +0 -2
  24. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  25. package/crud/contentModel/afterDelete.js +0 -2
  26. package/crud/contentModel/afterDelete.js.map +1 -1
  27. package/crud/contentModel/afterUpdate.js +0 -2
  28. package/crud/contentModel/afterUpdate.js.map +1 -1
  29. package/crud/contentModel/beforeCreate.d.ts +2 -3
  30. package/crud/contentModel/beforeCreate.js +7 -36
  31. package/crud/contentModel/beforeCreate.js.map +1 -1
  32. package/crud/contentModel/beforeDelete.js +0 -10
  33. package/crud/contentModel/beforeDelete.js.map +1 -1
  34. package/crud/contentModel/beforeUpdate.d.ts +2 -4
  35. package/crud/contentModel/beforeUpdate.js +2 -7
  36. package/crud/contentModel/beforeUpdate.js.map +1 -1
  37. package/crud/contentModel/contentModelManagerFactory.js +0 -7
  38. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  39. package/crud/contentModel/createFieldStorageId.js +4 -3
  40. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  41. package/crud/contentModel/models.js +12 -0
  42. package/crud/contentModel/models.js.map +1 -1
  43. package/crud/contentModel/systemFields.js.map +1 -1
  44. package/crud/contentModel/validateLayout.js +0 -8
  45. package/crud/contentModel/validateLayout.js.map +1 -1
  46. package/crud/contentModel/validateModel.d.ts +3 -4
  47. package/crud/contentModel/validateModel.js +6 -11
  48. package/crud/contentModel/validateModel.js.map +1 -1
  49. package/crud/contentModel/validateModelFields.d.ts +3 -4
  50. package/crud/contentModel/validateModelFields.js +118 -97
  51. package/crud/contentModel/validateModelFields.js.map +1 -1
  52. package/crud/contentModel/validation.d.ts +477 -0
  53. package/crud/contentModel/validation.js +97 -0
  54. package/crud/contentModel/validation.js.map +1 -0
  55. package/crud/contentModel.crud.js +219 -269
  56. package/crud/contentModel.crud.js.map +1 -1
  57. package/crud/contentModelGroup/beforeCreate.js +0 -12
  58. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  59. package/crud/contentModelGroup/beforeDelete.js +0 -8
  60. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  61. package/crud/contentModelGroup/beforeUpdate.js +0 -5
  62. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  63. package/crud/contentModelGroup/validation.d.ts +30 -0
  64. package/crud/contentModelGroup/validation.js +34 -0
  65. package/crud/contentModelGroup/validation.js.map +1 -0
  66. package/crud/contentModelGroup.crud.js +53 -95
  67. package/crud/contentModelGroup.crud.js.map +1 -1
  68. package/crud/settings.crud.js +0 -12
  69. package/crud/settings.crud.js.map +1 -1
  70. package/crud/system.crud.js +2 -37
  71. package/crud/system.crud.js.map +1 -1
  72. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
  73. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  74. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
  75. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
  76. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
  77. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
  78. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  79. package/fieldConverters/index.d.ts +2 -1
  80. package/fieldConverters/index.js +2 -5
  81. package/fieldConverters/index.js.map +1 -1
  82. package/graphql/buildSchemaPlugins.d.ts +8 -3
  83. package/graphql/buildSchemaPlugins.js +6 -14
  84. package/graphql/buildSchemaPlugins.js.map +1 -1
  85. package/graphql/createExecutableSchema.d.ts +7 -0
  86. package/graphql/createExecutableSchema.js +29 -0
  87. package/graphql/createExecutableSchema.js.map +1 -0
  88. package/graphql/generateSchema.d.ts +8 -0
  89. package/graphql/generateSchema.js +31 -0
  90. package/graphql/generateSchema.js.map +1 -0
  91. package/graphql/graphQLHandlerFactory.js +90 -74
  92. package/graphql/graphQLHandlerFactory.js.map +1 -1
  93. package/graphql/index.d.ts +1 -3
  94. package/graphql/index.js +2 -46
  95. package/graphql/index.js.map +1 -1
  96. package/graphql/schema/baseContentSchema.d.ts +6 -2
  97. package/graphql/schema/baseContentSchema.js +9 -13
  98. package/graphql/schema/baseContentSchema.js.map +1 -1
  99. package/graphql/schema/baseSchema.d.ts +3 -0
  100. package/graphql/schema/baseSchema.js +53 -0
  101. package/graphql/schema/baseSchema.js.map +1 -0
  102. package/graphql/schema/contentEntries.d.ts +6 -2
  103. package/graphql/schema/contentEntries.js +39 -65
  104. package/graphql/schema/contentEntries.js.map +1 -1
  105. package/graphql/schema/contentModelGroups.d.ts +6 -2
  106. package/graphql/schema/contentModelGroups.js +9 -22
  107. package/graphql/schema/contentModelGroups.js.map +1 -1
  108. package/graphql/schema/contentModels.d.ts +6 -2
  109. package/graphql/schema/contentModels.js +42 -25
  110. package/graphql/schema/contentModels.js.map +1 -1
  111. package/graphql/schema/createFieldResolvers.d.ts +1 -1
  112. package/graphql/schema/createFieldResolvers.js +20 -27
  113. package/graphql/schema/createFieldResolvers.js.map +1 -1
  114. package/graphql/schema/createManageResolvers.js +0 -26
  115. package/graphql/schema/createManageResolvers.js.map +1 -1
  116. package/graphql/schema/createManageSDL.d.ts +2 -0
  117. package/graphql/schema/createManageSDL.js +8 -19
  118. package/graphql/schema/createManageSDL.js.map +1 -1
  119. package/graphql/schema/createPreviewResolvers.js +0 -10
  120. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  121. package/graphql/schema/createReadResolvers.js +5 -10
  122. package/graphql/schema/createReadResolvers.js.map +1 -1
  123. package/graphql/schema/createReadSDL.d.ts +2 -0
  124. package/graphql/schema/createReadSDL.js +11 -15
  125. package/graphql/schema/createReadSDL.js.map +1 -1
  126. package/graphql/schema/resolvers/commonFieldResolvers.js +0 -2
  127. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  128. package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
  129. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  130. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
  131. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  132. package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
  133. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  134. package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
  135. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  136. package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
  137. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  138. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
  139. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  140. package/graphql/schema/resolvers/manage/resolveList.js +0 -3
  141. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  142. package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
  143. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  144. package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
  145. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  146. package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
  147. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  148. package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
  149. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  150. package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
  151. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  152. package/graphql/schema/resolvers/preview/resolveList.js +0 -3
  153. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  154. package/graphql/schema/resolvers/read/resolveGet.js +0 -8
  155. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  156. package/graphql/schema/resolvers/read/resolveList.js +0 -3
  157. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  158. package/graphql/schema/schemaPlugins.d.ts +8 -3
  159. package/graphql/schema/schemaPlugins.js +63 -65
  160. package/graphql/schema/schemaPlugins.js.map +1 -1
  161. package/graphql/system.js +69 -85
  162. package/graphql/system.js.map +1 -1
  163. package/graphqlFields/boolean.js +0 -12
  164. package/graphqlFields/boolean.js.map +1 -1
  165. package/graphqlFields/datetime.js +0 -17
  166. package/graphqlFields/datetime.js.map +1 -1
  167. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
  168. package/graphqlFields/dynamicZone/dynamicZoneField.js +208 -0
  169. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
  170. package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
  171. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
  172. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
  173. package/graphqlFields/dynamicZone/index.d.ts +2 -0
  174. package/graphqlFields/dynamicZone/index.js +19 -0
  175. package/graphqlFields/dynamicZone/index.js.map +1 -0
  176. package/graphqlFields/file.js +0 -8
  177. package/graphqlFields/file.js.map +1 -1
  178. package/graphqlFields/helpers.js +0 -10
  179. package/graphqlFields/helpers.js.map +1 -1
  180. package/graphqlFields/index.d.ts +1 -1
  181. package/graphqlFields/index.js +2 -12
  182. package/graphqlFields/index.js.map +1 -1
  183. package/graphqlFields/longText.js +0 -10
  184. package/graphqlFields/longText.js.map +1 -1
  185. package/graphqlFields/number.js +0 -12
  186. package/graphqlFields/number.js.map +1 -1
  187. package/graphqlFields/object.js +112 -98
  188. package/graphqlFields/object.js.map +1 -1
  189. package/graphqlFields/ref.js +48 -96
  190. package/graphqlFields/ref.js.map +1 -1
  191. package/graphqlFields/richText.js +0 -9
  192. package/graphqlFields/richText.js.map +1 -1
  193. package/graphqlFields/text.js +0 -11
  194. package/graphqlFields/text.js.map +1 -1
  195. package/index.d.ts +3 -3
  196. package/index.js +3 -26
  197. package/index.js.map +1 -1
  198. package/modelManager/DefaultCmsModelManager.js +0 -16
  199. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  200. package/modelManager/index.js +0 -4
  201. package/modelManager/index.js.map +1 -1
  202. package/package.json +28 -28
  203. package/parameters/context.js +0 -4
  204. package/parameters/context.js.map +1 -1
  205. package/parameters/header.js +0 -11
  206. package/parameters/header.js.map +1 -1
  207. package/parameters/index.js +0 -8
  208. package/parameters/index.js.map +1 -1
  209. package/parameters/manual.js +1 -8
  210. package/parameters/manual.js.map +1 -1
  211. package/parameters/path.js +0 -11
  212. package/parameters/path.js.map +1 -1
  213. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  214. package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
  215. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  216. package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
  217. package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
  218. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
  219. package/plugins/CmsGroupPlugin.js +0 -8
  220. package/plugins/CmsGroupPlugin.js.map +1 -1
  221. package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
  222. package/plugins/CmsModelFieldConverterPlugin.js +0 -5
  223. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  224. package/plugins/CmsModelPlugin.js +2 -38
  225. package/plugins/CmsModelPlugin.js.map +1 -1
  226. package/plugins/CmsParametersPlugin.js +0 -7
  227. package/plugins/CmsParametersPlugin.js.map +1 -1
  228. package/plugins/StorageTransformPlugin.d.ts +11 -11
  229. package/plugins/StorageTransformPlugin.js +0 -9
  230. package/plugins/StorageTransformPlugin.js.map +1 -1
  231. package/plugins/index.d.ts +2 -0
  232. package/plugins/index.js +22 -10
  233. package/plugins/index.js.map +1 -1
  234. package/storage/default.js +0 -3
  235. package/storage/default.js.map +1 -1
  236. package/storage/object.js +4 -20
  237. package/storage/object.js.map +1 -1
  238. package/types.d.ts +235 -57
  239. package/types.js +62 -69
  240. package/types.js.map +1 -1
  241. package/upgrades/5.33.0/index.js +3 -26
  242. package/upgrades/5.33.0/index.js.map +1 -1
  243. package/upgrades/index.js +0 -3
  244. package/upgrades/index.js.map +1 -1
  245. package/utils/access.js +11 -25
  246. package/utils/access.js.map +1 -1
  247. package/utils/converters/Converter.js +0 -13
  248. package/utils/converters/Converter.js.map +1 -1
  249. package/utils/converters/ConverterCollection.js +14 -34
  250. package/utils/converters/ConverterCollection.js.map +1 -1
  251. package/utils/converters/valueKeyStorageConverter.js +0 -26
  252. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  253. package/utils/createTypeFromFields.d.ts +15 -0
  254. package/utils/createTypeFromFields.js +64 -0
  255. package/utils/createTypeFromFields.js.map +1 -0
  256. package/utils/createTypeName.js +2 -9
  257. package/utils/createTypeName.js.map +1 -1
  258. package/utils/entryStorage.js +22 -35
  259. package/utils/entryStorage.js.map +1 -1
  260. package/utils/filterAsync.js +0 -5
  261. package/utils/filterAsync.js.map +1 -1
  262. package/utils/getBaseFieldType.d.ts +4 -0
  263. package/utils/getBaseFieldType.js +10 -0
  264. package/utils/getBaseFieldType.js.map +1 -0
  265. package/utils/getEntryTitle.js +0 -9
  266. package/utils/getEntryTitle.js.map +1 -1
  267. package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
  268. package/utils/getSchemaFromFieldPlugins.js +23 -19
  269. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  270. package/utils/ownership.js +0 -8
  271. package/utils/ownership.js.map +1 -1
  272. package/utils/permissions.js +8 -23
  273. package/utils/permissions.js.map +1 -1
  274. package/utils/pluralizedTypeName.js +0 -6
  275. package/utils/pluralizedTypeName.js.map +1 -1
  276. package/utils/renderFields.js +2 -9
  277. package/utils/renderFields.js.map +1 -1
  278. package/utils/renderGetFilterFields.js +6 -14
  279. package/utils/renderGetFilterFields.js.map +1 -1
  280. package/utils/renderInputFields.js +2 -9
  281. package/utils/renderInputFields.js.map +1 -1
  282. package/utils/renderListFilterFields.js +4 -10
  283. package/utils/renderListFilterFields.js.map +1 -1
  284. package/utils/renderSortEnum.d.ts +7 -4
  285. package/utils/renderSortEnum.js +21 -11
  286. package/utils/renderSortEnum.js.map +1 -1
  287. package/utils/toSlug.js +0 -4
  288. package/utils/toSlug.js.map +1 -1
  289. package/validators/dateGte.js +0 -7
  290. package/validators/dateGte.js.map +1 -1
  291. package/validators/dateLte.js +0 -7
  292. package/validators/dateLte.js.map +1 -1
  293. package/validators/dynamicZone.d.ts +2 -0
  294. package/validators/dynamicZone.js +20 -0
  295. package/validators/dynamicZone.js.map +1 -0
  296. package/validators/gte.js +0 -8
  297. package/validators/gte.js.map +1 -1
  298. package/validators/in.js +0 -8
  299. package/validators/in.js.map +1 -1
  300. package/validators/index.js +2 -16
  301. package/validators/index.js.map +1 -1
  302. package/validators/lte.js +0 -8
  303. package/validators/lte.js.map +1 -1
  304. package/validators/maxLength.js +0 -8
  305. package/validators/maxLength.js.map +1 -1
  306. package/validators/minLength.js +0 -8
  307. package/validators/minLength.js.map +1 -1
  308. package/validators/pattern.js +0 -9
  309. package/validators/pattern.js.map +1 -1
  310. package/validators/patternPlugins/email.js +0 -2
  311. package/validators/patternPlugins/email.js.map +1 -1
  312. package/validators/patternPlugins/index.js +0 -8
  313. package/validators/patternPlugins/index.js.map +1 -1
  314. package/validators/patternPlugins/lowerCase.js +0 -2
  315. package/validators/patternPlugins/lowerCase.js.map +1 -1
  316. package/validators/patternPlugins/lowerCaseSpace.js +0 -2
  317. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  318. package/validators/patternPlugins/upperCase.js +0 -2
  319. package/validators/patternPlugins/upperCase.js.map +1 -1
  320. package/validators/patternPlugins/upperCaseSpace.js +0 -2
  321. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  322. package/validators/patternPlugins/url.js +0 -2
  323. package/validators/patternPlugins/url.js.map +1 -1
  324. package/validators/required.js +0 -5
  325. package/validators/required.js.map +1 -1
  326. package/validators/timeGte.js +0 -8
  327. package/validators/timeGte.js.map +1 -1
  328. package/validators/timeLte.js +0 -8
  329. package/validators/timeLte.js.map +1 -1
  330. package/validators/unique.js +0 -7
  331. package/validators/unique.js.map +1 -1
  332. package/crud/index.d.ts +0 -6
  333. package/crud/index.js +0 -85
  334. package/crud/index.js.map +0 -1
  335. package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
  336. package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
  337. package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  338. package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
  339. package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
  340. package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
  341. package/utils/filterModelFields.d.ts +0 -16
  342. package/utils/filterModelFields.js +0 -77
  343. package/utils/filterModelFields.js.map +0 -1
@@ -1,36 +1,27 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.assignModelBeforeCreate = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
13
-
14
10
  var _pluralize = _interopRequireDefault(require("pluralize"));
15
-
16
11
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
17
-
18
12
  var _validateModel = require("./validateModel");
19
-
20
13
  var _validateLayout = require("./validateLayout");
21
-
22
14
  const disallowedModelIdList = ["contentModel", "contentModels", "contentModelGroup", "contentModelGroups"];
23
15
  /**
24
16
  * This list is to disallow creating models that might interfere with GraphQL schema creation.
25
17
  * Add more if required.
26
18
  */
27
-
28
19
  const disallowedModelIdEndingList = ["Response", "List", "Meta", "Input", "Sorter", "RefType"];
20
+
29
21
  /**
30
22
  * Checks for the uniqueness of provided modelId, against the provided list of models.
31
23
  * It also takes plural / singular forms of the provided modelId into account.
32
24
  */
33
-
34
25
  const checkModelIdUniqueness = (modelIdList, modelId) => {
35
26
  if (modelIdList.includes(modelId) === true) {
36
27
  throw new _error.default(`Content model with modelId "${modelId}" already exists.`, "MODEL_ID_EXISTS", {
@@ -42,23 +33,18 @@ const checkModelIdUniqueness = (modelIdList, modelId) => {
42
33
  * from creating, for example, "event" and "events" models, which would break the GraphQL schema.
43
34
  * 1. First check if user wants to create the "event" model, but the "events" model already exists.
44
35
  */
45
-
46
-
47
36
  const pluralizedModelIdCamelCase = (0, _pluralize.default)(modelId);
48
-
49
37
  if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {
50
38
  throw new _error.default(`Content model with modelId "${modelId}" does not exist, but a model with modelId "${pluralizedModelIdCamelCase}" does.`, "MODEL_ID_PLURAL_ERROR", {
51
39
  modelId,
52
40
  plural: pluralizedModelIdCamelCase
53
41
  });
54
42
  }
43
+
55
44
  /**
56
45
  * 2. Then check if user wants to create the "events" model, but the "event" model already exists.
57
46
  */
58
-
59
-
60
47
  const singularizedModelIdCamelCase = _pluralize.default.singular(modelId);
61
-
62
48
  if (modelIdList.includes(singularizedModelIdCamelCase) === true) {
63
49
  throw new _error.default(`Content model with modelId "${modelId}" does not exist, but a model with modelId "${singularizedModelIdCamelCase}" does.`, "MODEL_ID_SINGULAR_ERROR", {
64
50
  modelId,
@@ -66,47 +52,38 @@ const checkModelIdUniqueness = (modelIdList, modelId) => {
66
52
  });
67
53
  }
68
54
  };
69
-
70
55
  const checkModelIdAllowed = modelId => {
71
56
  if (disallowedModelIdList.includes(modelId) === false) {
72
57
  return;
73
58
  }
74
-
75
59
  throw new _error.default(`Provided model ID "${modelId}" is not allowed.`);
76
60
  };
77
-
78
61
  const checkModelIdEndingAllowed = modelId => {
79
62
  for (const ending of disallowedModelIdEndingList) {
80
63
  const re = new RegExp(`${ending}$`, "i");
81
64
  const matched = modelId.match(re);
82
-
83
65
  if (matched === null) {
84
66
  continue;
85
67
  }
86
-
87
68
  throw new _error.default(`ModelId that ends with "${ending}" is not allowed.`, "MODEL_ID_NOT_ALLOWED", {
88
69
  modelId
89
70
  });
90
71
  }
91
72
  };
92
-
93
73
  const getModelId = model => {
94
74
  const {
95
75
  modelId,
96
76
  name
97
77
  } = model;
98
-
99
78
  if (!!modelId) {
100
79
  return (0, _camelCase.default)(modelId.trim());
101
80
  } else if (name) {
102
81
  return (0, _camelCase.default)(name.trim());
103
82
  }
104
-
105
83
  throw new _error.default(`There is no "modelId" or "name" passed into the create model method.`, "MISSING_MODEL_DATA", {
106
84
  model
107
85
  });
108
86
  };
109
-
110
87
  const createOnModelBeforeCb = ({
111
88
  plugins,
112
89
  storageOperations
@@ -117,13 +94,11 @@ const createOnModelBeforeCb = ({
117
94
  } = params;
118
95
  const modelId = getModelId(model);
119
96
  const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === modelId);
120
-
121
97
  if (modelPlugin) {
122
98
  throw new _error.default(`Cannot create "${model.modelId}" content model because one is already registered via a plugin.`, "CONTENT_MODEL_CREATE_ERROR", {
123
99
  modelId: model.modelId
124
100
  });
125
101
  }
126
-
127
102
  const models = await storageOperations.models.list({
128
103
  where: {
129
104
  tenant: model.tenant,
@@ -131,20 +106,19 @@ const createOnModelBeforeCb = ({
131
106
  }
132
107
  });
133
108
  const modelIdList = models.map(m => m.modelId);
109
+
134
110
  /**
135
111
  * We need to check for:
136
112
  * - is that exact modelId allowed
137
113
  * - is modelId unique
138
114
  * - is model ending allowed
139
115
  */
140
-
141
116
  checkModelIdAllowed(modelId);
142
117
  checkModelIdEndingAllowed(modelId);
143
118
  checkModelIdUniqueness(modelIdList, modelId);
144
119
  model.modelId = modelId;
145
120
  };
146
121
  };
147
-
148
122
  /**
149
123
  * We attach both on before create and createFrom events here.
150
124
  * Callables are identical.
@@ -154,7 +128,7 @@ const assignModelBeforeCreate = params => {
154
128
  onModelBeforeCreate,
155
129
  onModelBeforeCreateFrom,
156
130
  storageOperations,
157
- plugins
131
+ context
158
132
  } = params;
159
133
  onModelBeforeCreate.subscribe(async ({
160
134
  model,
@@ -167,10 +141,9 @@ const assignModelBeforeCreate = params => {
167
141
  /**
168
142
  * then we run the shared create/createFrom methods.
169
143
  */
170
-
171
144
  const cb = createOnModelBeforeCb({
172
145
  storageOperations,
173
- plugins
146
+ plugins: context.plugins
174
147
  });
175
148
  await cb({
176
149
  model,
@@ -179,16 +152,14 @@ const assignModelBeforeCreate = params => {
179
152
  /**
180
153
  * and then we move onto model and fields...
181
154
  */
182
-
183
155
  await (0, _validateModel.validateModel)({
184
156
  model,
185
- plugins
157
+ context
186
158
  });
187
159
  });
188
160
  onModelBeforeCreateFrom.subscribe(createOnModelBeforeCb({
189
161
  storageOperations,
190
- plugins
162
+ plugins: context.plugins
191
163
  }));
192
164
  };
193
-
194
165
  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","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 onModelB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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
+ {"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","context","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 CmsContext\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 context: CmsContext;\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, context } = 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: context.plugins\n });\n await cb({\n model,\n input\n });\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n model,\n context\n });\n });\n\n onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageOperations,\n plugins: context.plugins\n })\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAUA;AACA;AACA;AAEA,MAAMA,qBAA+B,GAAG,CACpC,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACvB;AACD;AACA;AACA;AACA;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAAU,EACV,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,CACZ;;AAED;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAqB,EAAEC,OAAe,KAAK;EACvE,IAAID,WAAW,CAACE,QAAQ,CAACD,OAAO,CAAC,KAAK,IAAI,EAAE;IACxC,MAAM,IAAIE,cAAW,CAChB,+BAA8BF,OAAQ,mBAAkB,EACzD,iBAAiB,EACjB;MACIA;IACJ,CAAC,CACJ;EACL;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAS,EAACJ,OAAO,CAAC;EACrD,IAAID,WAAW,CAACE,QAAQ,CAACE,0BAA0B,CAAC,KAAK,IAAI,EAAE;IAC3D,MAAM,IAAID,cAAW,CAChB,+BAA8BF,OAAQ,+CAA8CG,0BAA2B,SAAQ,EACxH,uBAAuB,EACvB;MACIH,OAAO;MACPK,MAAM,EAAEF;IACZ,CAAC,CACJ;EACL;;EAEA;AACJ;AACA;EACI,MAAMG,4BAA4B,GAAGF,kBAAS,CAACG,QAAQ,CAACP,OAAO,CAAC;EAChE,IAAID,WAAW,CAACE,QAAQ,CAACK,4BAA4B,CAAC,KAAK,IAA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ACA;IACQ,IAAAC,8BAAc,EAAC5B,KAAK,CAAC6B,MAAM,EAAE7B,KAAK,CAAC8B,MAAM,CAAC;IAC1C;AACR;AACA;IACQ,MAAMC,EAAE,GAAG3B,qBAAqB,CAAC;MAC7BE,iBAAiB;MACjBD,OAAO,EAAEoB,OAAO,CAACpB;IACrB,CAAC,CAAC;IACF,MAAM0B,EAAE,CAAC;MACL/B,KAAK;MACL2B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,MAAM,IAAAK,4BAAa,EAAC;MAChBhC,KAAK;MACLyB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFD,uBAAuB,CAACE,SAAS,CAC7BtB,qBAAqB,CAAC;IAClBE,iBAAiB;IACjBD,OAAO,EAAEoB,OAAO,CAACpB;EACrB,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.assignModelBeforeDelete = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
-
14
10
  var _valueKeyStorageConverter = require("../../utils/converters/valueKeyStorageConverter");
15
-
16
11
  const assignModelBeforeDelete = params => {
17
12
  const {
18
13
  onModelBeforeDelete,
@@ -24,15 +19,12 @@ const assignModelBeforeDelete = params => {
24
19
  model
25
20
  } = params;
26
21
  const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
27
-
28
22
  if (modelPlugin) {
29
23
  throw new _error.default("Content models defined via plugins cannot be deleted.", "CONTENT_MODEL_DELETE_ERROR", {
30
24
  modelId: model.modelId
31
25
  });
32
26
  }
33
-
34
27
  let entries = [];
35
-
36
28
  try {
37
29
  const result = await storageOperations.entries.list((0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
38
30
  model,
@@ -50,11 +42,9 @@ const assignModelBeforeDelete = params => {
50
42
  model
51
43
  });
52
44
  }
53
-
54
45
  if (entries.length > 0) {
55
46
  throw new _error.default(`Cannot delete content model "${model.modelId}" because there are existing entries.`, "CONTENT_MODEL_BEFORE_DELETE_HOOK_FAILED");
56
47
  }
57
48
  });
58
49
  };
59
-
60
50
  exports.assignModelBeforeDelete = assignModelBeforeDelete;
@@ -1 +1 @@
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
+ {"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,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC,iBAAiB;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAElEC,mBAAmB,CAACG,SAAS,CAAC,MAAMJ,MAAM,IAAI;IAC1C,MAAM;MAAEK;IAAM,CAAC,GAAGL,MAAM;IAExB,MAAMM,WAAW,GAAGH,OAAO,CACtBI,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKR,KAAK,CAACQ,OAAO,CAAC;IAE9D,IAAIP,WAAW,EAAE;MACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;QACID,OAAO,EAAER,KAAK,CAACQ;MACnB,CAAC,CACJ;IACL;IAEA,IAAIE,OAAO,GAAG,EAAE;IAChB,IAAI;MACA,MAAMC,MAAM,GAAG,MAAMd,iBAAiB,CAACa,OAAO,CAACE,IAAI,CAC/C,IAAAC,uDAA6B,EAAC;QAC1Bb,KAAK;QACLF;MACJ,CAAC,CAAC,EACF;QACIgB,KAAK,EAAE;UACHC,MAAM,EAAE;QACZ,CAAC;QACDC,KAAK,EAAE;MACX,CAAC,CACJ;MACDN,OAAO,GAAGC,MAAM,CAACM,KAAK;IAC1B,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,MAAM,IAAIT,cAAW,CACjB,8DAA8D,EAC9D,eAAe,EACf;QACIU,KAAK,EAAED,EAAE;QACTlB;MACJ,CAAC,CACJ;IACL;IACA,IAAIU,OAAO,CAACU,MAAM,GAAG,CAAC,EAAE;MACpB,MAAM,IAAIX,cAAW,CAChB,gCAA+BT,KAAK,CAACQ,OAAQ,uCAAsC,EACpF,yCAAyC,CAC5C;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1,10 +1,8 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { OnModelBeforeUpdateTopicParams, HeadlessCmsStorageOperations } from "../../types";
3
- import { PluginsContainer } from "@webiny/plugins";
2
+ import { OnModelBeforeUpdateTopicParams, CmsContext } from "../../types";
4
3
  interface AssignBeforeModelUpdateParams {
5
4
  onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;
6
- storageOperations: HeadlessCmsStorageOperations;
7
- plugins: PluginsContainer;
5
+ context: CmsContext;
8
6
  }
9
7
  export declare const assignModelBeforeUpdate: (params: AssignBeforeModelUpdateParams) => void;
10
8
  export {};
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignModelBeforeUpdate = void 0;
7
-
8
7
  var _validateModel = require("./validateModel");
9
-
10
8
  var _validateLayout = require("./validateLayout");
11
-
12
9
  const assignModelBeforeUpdate = params => {
13
10
  const {
14
11
  onModelBeforeUpdate,
15
- plugins
12
+ context
16
13
  } = params;
17
14
  onModelBeforeUpdate.subscribe(async ({
18
15
  model,
@@ -25,13 +22,11 @@ const assignModelBeforeUpdate = params => {
25
22
  /**
26
23
  * then the model and fields...
27
24
  */
28
-
29
25
  await (0, _validateModel.validateModel)({
30
26
  model,
31
27
  original,
32
- plugins
28
+ context
33
29
  });
34
30
  });
35
31
  };
36
-
37
32
  exports.assignModelBeforeUpdate = assignModelBeforeUpdate;
@@ -1 +1 @@
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"}
1
+ {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","original","validateLayout","layout","fields","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, CmsContext } from \"~/types\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n context: CmsContext;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, context } = 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 context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAE/CC,mBAAmB,CAACE,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEC;EAAS,CAAC,KAAK;IACzD;AACR;AACA;IACQ,IAAAC,8BAAc,EAACF,KAAK,CAACG,MAAM,EAAEH,KAAK,CAACI,MAAM,CAAC;IAC1C;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBL,KAAK;MACLC,QAAQ;MACRH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -5,25 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.contentModelManagerFactory = void 0;
7
7
  const defaultName = "content-model-manager-default";
8
-
9
8
  const contentModelManagerFactory = async (context, model) => {
10
9
  const pluginsByType = context.plugins.byType("cms-content-model-manager").reverse();
11
-
12
10
  for (const plugin of pluginsByType) {
13
11
  const target = Array.isArray(plugin.modelId) ? plugin.modelId : [plugin.modelId];
14
-
15
12
  if (target.includes(model.modelId) === true && plugin.name !== defaultName) {
16
13
  return await plugin.create(context, model);
17
14
  }
18
15
  }
19
-
20
16
  const plugin = pluginsByType.find(plugin => plugin.name === defaultName);
21
-
22
17
  if (!plugin) {
23
18
  throw new Error("There is no default plugin to create CmsModelManager");
24
19
  }
25
-
26
20
  return await plugin.create(context, model);
27
21
  };
28
-
29
22
  exports.contentModelManagerFactory = contentModelManagerFactory;
@@ -1 +1 @@
1
- {"version":3,"names":["defaultName","contentModelManagerFactory","context","model","pluginsByType","plugins","byType","reverse","plugin","target","Array","isArray","modelId","includes","name","create","find","Error"],"sources":["contentModelManagerFactory.ts"],"sourcesContent":["import { CmsModel, CmsContext, ModelManagerPlugin, CmsModelManager } from \"~/types\";\n\nconst defaultName = \"content-model-manager-default\";\n\nexport const contentModelManagerFactory = async (\n context: CmsContext,\n model: CmsModel\n): Promise<CmsModelManager> => {\n const pluginsByType = context.plugins\n .byType<ModelManagerPlugin>(\"cms-content-model-manager\")\n .reverse();\n for (const plugin of pluginsByType) {\n const target = Array.isArray(plugin.modelId) ? plugin.modelId : [plugin.modelId];\n if (target.includes(model.modelId) === true && plugin.name !== defaultName) {\n return await plugin.create(context, model);\n }\n }\n const plugin = pluginsByType.find(plugin => plugin.name === defaultName);\n if (!plugin) {\n throw new Error(\"There is no default plugin to create CmsModelManager\");\n }\n return await plugin.create(context, model);\n};\n"],"mappings":";;;;;;AAEA,MAAMA,WAAW,GAAG,+BAApB;;AAEO,MAAMC,0BAA0B,GAAG,OACtCC,OADsC,EAEtCC,KAFsC,KAGX;EAC3B,MAAMC,aAAa,GAAGF,OAAO,CAACG,OAAR,CACjBC,MADiB,CACU,2BADV,EAEjBC,OAFiB,EAAtB;;EAGA,KAAK,MAAMC,MAAX,IAAqBJ,aAArB,EAAoC;IAChC,MAAMK,MAAM,GAAGC,KAAK,CAACC,OAAN,CAAcH,MAAM,CAACI,OAArB,IAAgCJ,MAAM,CAACI,OAAvC,GAAiD,CAACJ,MAAM,CAACI,OAAR,CAAhE;;IACA,IAAIH,MAAM,CAACI,QAAP,CAAgBV,KAAK,CAACS,OAAtB,MAAmC,IAAnC,IAA2CJ,MAAM,CAACM,IAAP,KAAgBd,WAA/D,EAA4E;MACxE,OAAO,MAAMQ,MAAM,CAACO,MAAP,CAAcb,OAAd,EAAuBC,KAAvB,CAAb;IACH;EACJ;;EACD,MAAMK,MAAM,GAAGJ,aAAa,CAACY,IAAd,CAAmBR,MAAM,IAAIA,MAAM,CAACM,IAAP,KAAgBd,WAA7C,CAAf;;EACA,IAAI,CAACQ,MAAL,EAAa;IACT,MAAM,IAAIS,KAAJ,CAAU,sDAAV,CAAN;EACH;;EACD,OAAO,MAAMT,MAAM,CAACO,MAAP,CAAcb,OAAd,EAAuBC,KAAvB,CAAb;AACH,CAlBM"}
1
+ {"version":3,"names":["defaultName","contentModelManagerFactory","context","model","pluginsByType","plugins","byType","reverse","plugin","target","Array","isArray","modelId","includes","name","create","find","Error"],"sources":["contentModelManagerFactory.ts"],"sourcesContent":["import { CmsModel, CmsContext, ModelManagerPlugin, CmsModelManager } from \"~/types\";\n\nconst defaultName = \"content-model-manager-default\";\n\nexport const contentModelManagerFactory = async (\n context: CmsContext,\n model: CmsModel\n): Promise<CmsModelManager> => {\n const pluginsByType = context.plugins\n .byType<ModelManagerPlugin>(\"cms-content-model-manager\")\n .reverse();\n for (const plugin of pluginsByType) {\n const target = Array.isArray(plugin.modelId) ? plugin.modelId : [plugin.modelId];\n if (target.includes(model.modelId) === true && plugin.name !== defaultName) {\n return await plugin.create(context, model);\n }\n }\n const plugin = pluginsByType.find(plugin => plugin.name === defaultName);\n if (!plugin) {\n throw new Error(\"There is no default plugin to create CmsModelManager\");\n }\n return await plugin.create(context, model);\n};\n"],"mappings":";;;;;;AAEA,MAAMA,WAAW,GAAG,+BAA+B;AAE5C,MAAMC,0BAA0B,GAAG,OACtCC,OAAmB,EACnBC,KAAe,KACY;EAC3B,MAAMC,aAAa,GAAGF,OAAO,CAACG,OAAO,CAChCC,MAAM,CAAqB,2BAA2B,CAAC,CACvDC,OAAO,EAAE;EACd,KAAK,MAAMC,MAAM,IAAIJ,aAAa,EAAE;IAChC,MAAMK,MAAM,GAAGC,KAAK,CAACC,OAAO,CAACH,MAAM,CAACI,OAAO,CAAC,GAAGJ,MAAM,CAACI,OAAO,GAAG,CAACJ,MAAM,CAACI,OAAO,CAAC;IAChF,IAAIH,MAAM,CAACI,QAAQ,CAACV,KAAK,CAACS,OAAO,CAAC,KAAK,IAAI,IAAIJ,MAAM,CAACM,IAAI,KAAKd,WAAW,EAAE;MACxE,OAAO,MAAMQ,MAAM,CAACO,MAAM,CAACb,OAAO,EAAEC,KAAK,CAAC;IAC9C;EACJ;EACA,MAAMK,MAAM,GAAGJ,aAAa,CAACY,IAAI,CAACR,MAAM,IAAIA,MAAM,CAACM,IAAI,KAAKd,WAAW,CAAC;EACxE,IAAI,CAACQ,MAAM,EAAE;IACT,MAAM,IAAIS,KAAK,CAAC,sDAAsD,CAAC;EAC3E;EACA,OAAO,MAAMT,MAAM,CAACO,MAAM,CAACb,OAAO,EAAEC,KAAK,CAAC;AAC9C,CAAC;AAAC"}
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createFieldStorageId = void 0;
7
-
7
+ var _getBaseFieldType = require("../../utils/getBaseFieldType");
8
8
  const createFieldStorageId = params => {
9
9
  const {
10
10
  type,
11
11
  id
12
12
  } = params;
13
- return `${type}@${id}`;
13
+ return `${(0, _getBaseFieldType.getBaseFieldType)({
14
+ type
15
+ })}@${id}`;
14
16
  };
15
-
16
17
  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,MAA0C,IAAa;EACxF,MAAM;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGF,MAAM;EAC3B,OAAQ,GAAE,IAAAG,kCAAgB,EAAC;IAAEF;EAAK,CAAC,CAAE,IAAGC,EAAG,EAAC;AAChD,CAAC;AAAC"}
@@ -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;AACA;;AAEA;AACA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAGC,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB,CAA5B;;AACA,MAAMC,WAAW,GAAGF,sBAAA,CAAWC,MAAX,CAAkB,eAAlB,CAApB;;AAEA,MAAME,aAAa,GAAG,IAAAC,kBAAA,EAAW;EAC7BC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP;AADuB,CAAX,GAAtB;AAIO,MAAMQ,sBAAsB,GAAG,IAAAH,kBAAA,EAAW;EAC7CI,EAAE,EAAE,IAAAF,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CADyC;EAE7CU,OAAO,EAAE,IAAAH,cAAA,EAAO;IACZN,UAAU,EAAEU;EADA,CAAP,CAFoC;EAK7CC,KAAK,EAAE,IAAAL,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CALsC;EAM7Ca,QAAQ,EAAE,IAAAN,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CANmC;EAO7CW,eAAe,EAAE,IAAAP,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAP4B;EAQ7CY,IAAI,EAAE,IAAAC,eAAA,IAAU,IAAAT,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAAV,CARuC;EAS7CiB,cAAc,EAAE,IAAAC,eAAA,EAAQ;IAAEC,KAAK,EAAE;EAAT,CAA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N,UAAU,EAAED;EAAd,CAAP,CAJ2C;EAKlDuC,MAAM,EAAE,IAAAhC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP;AAL0C,CAAX,GAApC;;AAQA,MAAMqC,uBAAuB,GAAG,IAAAnC,kBAAA,EAAW;EAC9CC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CADwC;EAE9C+B,WAAW,EAAE,IAAA3B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAFiC;EAG9CgC,KAAK,EAAE,IAAA5B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHuC;EAI9CsC,YAAY,EAAE,IAAAlC,cAAA,GAJgC;EAK9Cc,MAAM,EAAE,IAAAA,cAAA,EAAO;IAAEC,UAAU,EAAEd,sBAAd;IAAsCW,KAAK,EAAE,EAA7C;IAAiDM,IAAI,EAAE,IAAvD;IAA6DW,QAAQ,EAAE;EAAvE,CAAP,CALsC;EAM9CC,MAAM,EAAE,IAAAP,2BAAA,EAAO;IAAEX,KAAK,EAAE,EAAT;IAAaiB,QAAQ,EAAE;EAAvB,CAAP;AANsC,CAAX,GAAhC"}
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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AO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAJ2C;EAKlDwC,MAAM,EAAE,IAAAjC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP;AAL0C,CAAX,GAApC;;AAQA,MAAMsC,uBAAuB,GAAG,IAAApC,kBAAA,EAAW;EAC9CC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CADwC;EAE9CiC,WAAW,EAAE,IAAA7B,cAAA,EAAO;IAAEN,UAAU,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 +1 @@
1
- {"version":3,"names":["fieldSystemFields"],"sources":["systemFields.ts"],"sourcesContent":["export const fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n"],"mappings":";;;;;;AAAO,MAAMA,iBAA2B,GAAG,CACvC,IADuC,EAEvC,SAFuC,EAGvC,WAHuC,EAIvC,OAJuC,EAKvC,UALuC,EAMvC,iBANuC,EAOvC,MAPuC,EAQvC,gBARuC,EASvC,kBATuC,EAUvC,UAVuC,EAWvC,YAXuC,EAYvC,gBAZuC,EAavC,UAbuC,CAApC"}
1
+ {"version":3,"names":["fieldSystemFields"],"sources":["systemFields.ts"],"sourcesContent":["export const fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n"],"mappings":";;;;;;AAAO,MAAMA,iBAA2B,GAAG,CACvC,IAAI,EACJ,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,CACb;AAAC"}
@@ -4,33 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateLayout = void 0;
7
-
8
7
  const validateLayout = (layout, fields = []) => {
9
8
  const flatLayoutIdList = layout.reduce((acc, id) => {
10
9
  return acc.concat(Array.isArray(id) ? id : [id]);
11
10
  }, []);
12
-
13
11
  if (flatLayoutIdList.length !== fields.length) {
14
12
  throw new Error(`There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`);
15
13
  }
16
-
17
14
  for (const field of fields) {
18
15
  if (flatLayoutIdList.includes(field.id)) {
19
16
  continue;
20
17
  }
21
-
22
18
  throw new Error(`Field "${field.id}" is not defined in layout.`);
23
19
  }
24
-
25
20
  for (const id of flatLayoutIdList) {
26
21
  const fieldFound = fields.some(f => f.id === id);
27
-
28
22
  if (fieldFound) {
29
23
  continue;
30
24
  }
31
-
32
25
  throw new Error(`Field id "${id}" is in layout but not in fields.`);
33
26
  }
34
27
  };
35
-
36
28
  exports.validateLayout = validateLayout;
@@ -1 +1 @@
1
- {"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,MAAD,EAA6BC,MAAuB,GAAG,EAAvD,KAAoE;EAC9F,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAP,CAAc,CAACC,GAAD,EAAMC,EAAN,KAAa;IAChD,OAAOD,GAAG,CAACE,MAAJ,CAAWC,KAAK,CAACC,OAAN,CAAcH,EAAd,IAAoBA,EAApB,GAAyB,CAACA,EAAD,CAApC,CAAP;EACH,CAFwB,EAEtB,EAFsB,CAAzB;;EAGA,IAAIH,gBAAgB,CAACO,MAAjB,KAA4BR,MAAM,CAACQ,MAAvC,EAA+C;IAC3C,MAAM,IAAIC,KAAJ,CACD,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAD1E,CAAN;EAGH;;EACD,KAAK,MAAME,KAAX,IAAoBV,MAApB,EAA4B;IACxB,IAAIC,gBAAgB,CAACU,QAAjB,CAA0BD,KAAK,CAACN,EAAhC,CAAJ,EAAyC;MACrC;IACH;;IACD,MAAM,IAAIK,KAAJ,CAAW,UAASC,KAAK,CAACN,EAAG,6BAA7B,CAAN;EACH;;EACD,KAAK,MAAMA,EAAX,IAAiBH,gBAAjB,EAAmC;IAC/B,MAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACV,EAAF,KAASA,EAA1B,CAAnB;;IACA,IAAIQ,UAAJ,EAAgB;MACZ;IACH;;IACD,MAAM,IAAIH,KAAJ,CAAW,aAAYL,EAAG,mCAA1B,CAAN;EACH;AACJ,CAtBM"}
1
+ {"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,MAA0B,EAAEC,MAAuB,GAAG,EAAE,KAAW;EAC9F,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAM,CAAC,CAACC,GAAG,EAAEC,EAAE,KAAK;IAChD,OAAOD,GAAG,CAACE,MAAM,CAACC,KAAK,CAACC,OAAO,CAACH,EAAE,CAAC,GAAGA,EAAE,GAAG,CAACA,EAAE,CAAC,CAAC;EACpD,CAAC,EAAE,EAAE,CAAC;EACN,IAAIH,gBAAgB,CAACO,MAAM,KAAKR,MAAM,CAACQ,MAAM,EAAE;IAC3C,MAAM,IAAIC,KAAK,CACV,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAAwD,CACvI;EACL;EACA,KAAK,MAAME,KAAK,IAAIV,MAAM,EAAE;IACxB,IAAIC,gBAAgB,CAACU,QAAQ,CAACD,KAAK,CAACN,EAAE,CAAC,EAAE;MACrC;IACJ;IACA,MAAM,IAAIK,KAAK,CAAE,UAASC,KAAK,CAACN,EAAG,6BAA4B,CAAC;EACpE;EACA,KAAK,MAAMA,EAAE,IAAIH,gBAAgB,EAAE;IAC/B,MAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACV,EAAE,KAAKA,EAAE,CAAC;IAChD,IAAIQ,UAAU,EAAE;MACZ;IACJ;IACA,MAAM,IAAIH,KAAK,CAAE,aAAYL,EAAG,mCAAkC,CAAC;EACvE;AACJ,CAAC;AAAC"}
@@ -1,9 +1,8 @@
1
- import { CmsModel } from "../../types";
2
- import { PluginsContainer } from "@webiny/plugins";
1
+ import { CmsContext, CmsModel } from "../../types";
3
2
  interface ValidateModelParams {
4
3
  model: CmsModel;
5
4
  original?: CmsModel;
6
- plugins: PluginsContainer;
5
+ context: CmsContext;
7
6
  }
8
- export declare const validateModel: (params: ValidateModelParams) => void;
7
+ export declare const validateModel: (params: ValidateModelParams) => Promise<void>;
9
8
  export {};
@@ -1,32 +1,27 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.validateModel = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
-
14
10
  var _validateModelFields = require("./validateModelFields");
15
-
16
- const validateModel = params => {
11
+ const validateModel = async params => {
17
12
  const {
18
13
  model,
19
- plugins
14
+ context
20
15
  } = params;
16
+ const {
17
+ plugins
18
+ } = context;
21
19
  const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
22
-
23
20
  if (modelPlugin) {
24
21
  throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
25
22
  modelId: model.modelId
26
23
  });
27
24
  }
28
-
29
- (0, _validateModelFields.validateModelFields)(params);
25
+ await (0, _validateModelFields.validateModelFields)(params);
30
26
  };
31
-
32
27
  exports.validateModel = validateModel;