@webiny/api-headless-cms 5.17.4 → 5.18.0-beta.3

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 (395) hide show
  1. package/content/contextSetup.js +1 -2
  2. package/content/graphQLHandlerFactory.d.ts +1 -2
  3. package/content/graphQLHandlerFactory.js +12 -4
  4. package/content/plugins/CmsGroupPlugin.d.ts +11 -0
  5. package/content/plugins/{ContentModelGroupPlugin.js → CmsGroupPlugin.js} +4 -5
  6. package/content/plugins/CmsModelPlugin.d.ts +11 -0
  7. package/content/plugins/{ContentModelPlugin.js → CmsModelPlugin.js} +4 -5
  8. package/content/plugins/buildSchemaPlugins.js +1 -2
  9. package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
  10. package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
  11. package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
  12. package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
  13. package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +2 -2
  14. package/content/plugins/crud/contentEntry/entryDataValidation.js +1 -2
  15. package/content/plugins/crud/contentEntry/markLockedFields.d.ts +3 -3
  16. package/content/plugins/crud/contentEntry/markLockedFields.js +10 -7
  17. package/content/plugins/crud/contentEntry.crud.d.ts +12 -4
  18. package/content/plugins/crud/contentEntry.crud.js +807 -757
  19. package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
  20. package/content/plugins/crud/contentModel/afterCreate.js +18 -0
  21. package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
  22. package/content/plugins/crud/contentModel/afterDelete.js +18 -0
  23. package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
  24. package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
  25. package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
  26. package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
  27. package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
  28. package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
  29. package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
  30. package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
  31. package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -2
  32. package/content/plugins/crud/contentModel/contentModelManagerFactory.js +2 -3
  33. package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -2
  34. package/content/plugins/crud/contentModel/createFieldModels.js +2 -3
  35. package/content/plugins/crud/contentModel/idValidation.js +1 -2
  36. package/content/plugins/crud/contentModel/models.js +1 -2
  37. package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -2
  38. package/content/plugins/crud/contentModel/validateLayout.js +1 -2
  39. package/content/plugins/crud/contentModel.crud.d.ts +12 -4
  40. package/content/plugins/crud/contentModel.crud.js +351 -279
  41. package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
  42. package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
  43. package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
  44. package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
  45. package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
  46. package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
  47. package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -4
  48. package/content/plugins/crud/contentModelGroup.crud.js +259 -219
  49. package/content/plugins/crud/index.d.ts +6 -0
  50. package/content/plugins/crud/index.js +96 -0
  51. package/content/plugins/graphqlFields/boolean.js +1 -2
  52. package/content/plugins/graphqlFields/datetime.js +1 -2
  53. package/content/plugins/graphqlFields/file.js +1 -2
  54. package/content/plugins/graphqlFields/index.js +1 -2
  55. package/content/plugins/graphqlFields/longText.js +1 -2
  56. package/content/plugins/graphqlFields/number.js +1 -2
  57. package/content/plugins/graphqlFields/object.js +1 -2
  58. package/content/plugins/graphqlFields/ref.js +22 -11
  59. package/content/plugins/graphqlFields/richText.js +1 -2
  60. package/content/plugins/graphqlFields/text.js +1 -2
  61. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +2 -3
  62. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +1 -2
  63. package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
  64. package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
  65. package/content/plugins/modelManager/index.d.ts +2 -2
  66. package/content/plugins/modelManager/index.js +3 -4
  67. package/content/plugins/schema/baseSchema.js +1 -2
  68. package/content/plugins/schema/contentEntries.js +9 -10
  69. package/content/plugins/schema/contentModelGroups.js +13 -14
  70. package/content/plugins/schema/contentModels.js +9 -10
  71. package/content/plugins/schema/createFieldResolvers.d.ts +2 -2
  72. package/content/plugins/schema/createFieldResolvers.js +14 -20
  73. package/content/plugins/schema/createManageResolvers.d.ts +3 -3
  74. package/content/plugins/schema/createManageResolvers.js +6 -10
  75. package/content/plugins/schema/createManageSDL.d.ts +2 -2
  76. package/content/plugins/schema/createManageSDL.js +5 -6
  77. package/content/plugins/schema/createPreviewResolvers.d.ts +3 -3
  78. package/content/plugins/schema/createPreviewResolvers.js +5 -6
  79. package/content/plugins/schema/createReadResolvers.d.ts +3 -3
  80. package/content/plugins/schema/createReadResolvers.js +5 -6
  81. package/content/plugins/schema/createReadSDL.d.ts +2 -2
  82. package/content/plugins/schema/createReadSDL.js +3 -4
  83. package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +4 -4
  84. package/content/plugins/schema/resolvers/commonFieldResolvers.js +1 -2
  85. package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +1 -1
  86. package/content/plugins/schema/resolvers/manage/resolveCreate.js +3 -4
  87. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +1 -1
  88. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +3 -4
  89. package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +1 -1
  90. package/content/plugins/schema/resolvers/manage/resolveDelete.js +4 -5
  91. package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +1 -1
  92. package/content/plugins/schema/resolvers/manage/resolveGet.js +3 -4
  93. package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +1 -1
  94. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +3 -4
  95. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +1 -1
  96. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +3 -4
  97. package/content/plugins/schema/resolvers/manage/resolveList.d.ts +1 -1
  98. package/content/plugins/schema/resolvers/manage/resolveList.js +3 -4
  99. package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +1 -1
  100. package/content/plugins/schema/resolvers/manage/resolvePublish.js +3 -4
  101. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +1 -1
  102. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +3 -4
  103. package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +1 -1
  104. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +3 -4
  105. package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +1 -1
  106. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +3 -4
  107. package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +1 -1
  108. package/content/plugins/schema/resolvers/manage/resolveUpdate.js +3 -4
  109. package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +1 -1
  110. package/content/plugins/schema/resolvers/preview/resolveGet.js +3 -4
  111. package/content/plugins/schema/resolvers/preview/resolveList.d.ts +1 -1
  112. package/content/plugins/schema/resolvers/preview/resolveList.js +3 -4
  113. package/content/plugins/schema/resolvers/read/resolveGet.d.ts +1 -1
  114. package/content/plugins/schema/resolvers/read/resolveGet.js +3 -4
  115. package/content/plugins/schema/resolvers/read/resolveList.d.ts +1 -1
  116. package/content/plugins/schema/resolvers/read/resolveList.js +3 -4
  117. package/content/plugins/schema/schemaPlugins.js +4 -3
  118. package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
  119. package/content/plugins/storage/StorageTransformPlugin.js +36 -0
  120. package/content/plugins/storage/default.d.ts +2 -2
  121. package/content/plugins/storage/default.js +12 -12
  122. package/content/plugins/storage/object.d.ts +2 -2
  123. package/content/plugins/storage/object.js +28 -29
  124. package/content/plugins/utils/createTypeName.js +1 -2
  125. package/content/plugins/utils/entryStorage.d.ts +5 -5
  126. package/content/plugins/utils/entryStorage.js +21 -14
  127. package/content/plugins/utils/getEntryTitle.d.ts +2 -2
  128. package/content/plugins/utils/getEntryTitle.js +1 -2
  129. package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +2 -2
  130. package/content/plugins/utils/getSchemaFromFieldPlugins.js +1 -2
  131. package/content/plugins/utils/pluralizedTypeName.js +1 -2
  132. package/content/plugins/utils/renderFields.d.ts +2 -2
  133. package/content/plugins/utils/renderFields.js +1 -2
  134. package/content/plugins/utils/renderGetFilterFields.d.ts +2 -2
  135. package/content/plugins/utils/renderGetFilterFields.js +1 -2
  136. package/content/plugins/utils/renderInputFields.d.ts +2 -2
  137. package/content/plugins/utils/renderInputFields.js +1 -2
  138. package/content/plugins/utils/renderListFilterFields.d.ts +2 -2
  139. package/content/plugins/utils/renderListFilterFields.js +1 -2
  140. package/content/plugins/utils/renderSortEnum.d.ts +2 -2
  141. package/content/plugins/utils/renderSortEnum.js +1 -2
  142. package/content/plugins/validators/dateGte.js +1 -2
  143. package/content/plugins/validators/dateLte.js +1 -2
  144. package/content/plugins/validators/gte.js +1 -2
  145. package/content/plugins/validators/in.js +1 -2
  146. package/content/plugins/validators/index.js +1 -2
  147. package/content/plugins/validators/lte.js +1 -2
  148. package/content/plugins/validators/maxLength.js +1 -2
  149. package/content/plugins/validators/minLength.js +1 -2
  150. package/content/plugins/validators/pattern.js +1 -2
  151. package/content/plugins/validators/patternPlugins/email.js +1 -2
  152. package/content/plugins/validators/patternPlugins/index.js +1 -2
  153. package/content/plugins/validators/patternPlugins/lowerCase.js +1 -2
  154. package/content/plugins/validators/patternPlugins/upperCase.js +1 -2
  155. package/content/plugins/validators/patternPlugins/url.js +1 -2
  156. package/content/plugins/validators/required.js +1 -2
  157. package/content/plugins/validators/timeGte.js +1 -2
  158. package/content/plugins/validators/timeLte.js +1 -2
  159. package/index.d.ts +12 -0
  160. package/index.js +66 -0
  161. package/migrateCMSPermissions.d.ts +2 -2
  162. package/migrateCMSPermissions.js +1 -2
  163. package/package.json +23 -21
  164. package/plugins/context.js +1 -2
  165. package/plugins/crud/index.d.ts +6 -2
  166. package/plugins/crud/index.js +69 -6
  167. package/plugins/crud/settings.crud.d.ts +10 -4
  168. package/plugins/crud/settings.crud.js +64 -77
  169. package/plugins/crud/system.crud.d.ts +10 -4
  170. package/plugins/crud/system.crud.js +139 -126
  171. package/plugins/graphql/system.js +5 -6
  172. package/plugins/graphql.d.ts +1 -2
  173. package/plugins/graphql.js +49 -50
  174. package/plugins/upgrades/index.js +1 -2
  175. package/plugins/upgrades/v5.5.0/helpers.js +1 -2
  176. package/plugins/upgrades/v5.5.0/index.js +3 -4
  177. package/transformers.js +1 -2
  178. package/types.d.ts +742 -1232
  179. package/types.js +104 -254
  180. package/utils.d.ts +4 -11
  181. package/utils.js +2 -49
  182. package/content/contextSetup.js.map +0 -1
  183. package/content/graphQLHandlerFactory.js.map +0 -1
  184. package/content/index.d.ts +0 -5
  185. package/content/index.js +0 -37
  186. package/content/index.js.map +0 -1
  187. package/content/plugins/ContentModelGroupPlugin.d.ts +0 -7
  188. package/content/plugins/ContentModelGroupPlugin.js.map +0 -1
  189. package/content/plugins/ContentModelPlugin.d.ts +0 -7
  190. package/content/plugins/ContentModelPlugin.js.map +0 -1
  191. package/content/plugins/buildSchemaPlugins.js.map +0 -1
  192. package/content/plugins/crud/contentEntry/afterCreate.hook.d.ts +0 -2
  193. package/content/plugins/crud/contentEntry/afterCreate.hook.js +0 -15
  194. package/content/plugins/crud/contentEntry/afterCreate.hook.js.map +0 -1
  195. package/content/plugins/crud/contentEntry/afterCreateRevisionFrom.hook.d.ts +0 -2
  196. package/content/plugins/crud/contentEntry/afterCreateRevisionFrom.hook.js +0 -15
  197. package/content/plugins/crud/contentEntry/afterCreateRevisionFrom.hook.js.map +0 -1
  198. package/content/plugins/crud/contentEntry/afterDelete.hook.d.ts +0 -2
  199. package/content/plugins/crud/contentEntry/afterDelete.hook.js +0 -15
  200. package/content/plugins/crud/contentEntry/afterDelete.hook.js.map +0 -1
  201. package/content/plugins/crud/contentEntry/afterDeleteRevision.hook.d.ts +0 -2
  202. package/content/plugins/crud/contentEntry/afterDeleteRevision.hook.js +0 -15
  203. package/content/plugins/crud/contentEntry/afterDeleteRevision.hook.js.map +0 -1
  204. package/content/plugins/crud/contentEntry/afterPublish.hook.d.ts +0 -2
  205. package/content/plugins/crud/contentEntry/afterPublish.hook.js +0 -15
  206. package/content/plugins/crud/contentEntry/afterPublish.hook.js.map +0 -1
  207. package/content/plugins/crud/contentEntry/afterRequestChanges.hook.d.ts +0 -2
  208. package/content/plugins/crud/contentEntry/afterRequestChanges.hook.js +0 -15
  209. package/content/plugins/crud/contentEntry/afterRequestChanges.hook.js.map +0 -1
  210. package/content/plugins/crud/contentEntry/afterRequestReview.hook.d.ts +0 -2
  211. package/content/plugins/crud/contentEntry/afterRequestReview.hook.js +0 -15
  212. package/content/plugins/crud/contentEntry/afterRequestReview.hook.js.map +0 -1
  213. package/content/plugins/crud/contentEntry/afterUnpublish.hook.d.ts +0 -2
  214. package/content/plugins/crud/contentEntry/afterUnpublish.hook.js +0 -15
  215. package/content/plugins/crud/contentEntry/afterUnpublish.hook.js.map +0 -1
  216. package/content/plugins/crud/contentEntry/afterUpdate.hook.d.ts +0 -2
  217. package/content/plugins/crud/contentEntry/afterUpdate.hook.js +0 -15
  218. package/content/plugins/crud/contentEntry/afterUpdate.hook.js.map +0 -1
  219. package/content/plugins/crud/contentEntry/beforeCreate.hook.d.ts +0 -2
  220. package/content/plugins/crud/contentEntry/beforeCreate.hook.js +0 -18
  221. package/content/plugins/crud/contentEntry/beforeCreate.hook.js.map +0 -1
  222. package/content/plugins/crud/contentEntry/beforeCreateRevisionFrom.hook.d.ts +0 -2
  223. package/content/plugins/crud/contentEntry/beforeCreateRevisionFrom.hook.js +0 -15
  224. package/content/plugins/crud/contentEntry/beforeCreateRevisionFrom.hook.js.map +0 -1
  225. package/content/plugins/crud/contentEntry/beforeDelete.hook.d.ts +0 -2
  226. package/content/plugins/crud/contentEntry/beforeDelete.hook.js +0 -15
  227. package/content/plugins/crud/contentEntry/beforeDelete.hook.js.map +0 -1
  228. package/content/plugins/crud/contentEntry/beforeDeleteRevision.hook.d.ts +0 -2
  229. package/content/plugins/crud/contentEntry/beforeDeleteRevision.hook.js +0 -15
  230. package/content/plugins/crud/contentEntry/beforeDeleteRevision.hook.js.map +0 -1
  231. package/content/plugins/crud/contentEntry/beforePublish.hook.d.ts +0 -2
  232. package/content/plugins/crud/contentEntry/beforePublish.hook.js +0 -15
  233. package/content/plugins/crud/contentEntry/beforePublish.hook.js.map +0 -1
  234. package/content/plugins/crud/contentEntry/beforeRequestChanges.hook.d.ts +0 -2
  235. package/content/plugins/crud/contentEntry/beforeRequestChanges.hook.js +0 -15
  236. package/content/plugins/crud/contentEntry/beforeRequestChanges.hook.js.map +0 -1
  237. package/content/plugins/crud/contentEntry/beforeRequestReview.hook.d.ts +0 -2
  238. package/content/plugins/crud/contentEntry/beforeRequestReview.hook.js +0 -15
  239. package/content/plugins/crud/contentEntry/beforeRequestReview.hook.js.map +0 -1
  240. package/content/plugins/crud/contentEntry/beforeUnpublish.hook.d.ts +0 -2
  241. package/content/plugins/crud/contentEntry/beforeUnpublish.hook.js +0 -15
  242. package/content/plugins/crud/contentEntry/beforeUnpublish.hook.js.map +0 -1
  243. package/content/plugins/crud/contentEntry/beforeUpdate.hook.d.ts +0 -2
  244. package/content/plugins/crud/contentEntry/beforeUpdate.hook.js +0 -18
  245. package/content/plugins/crud/contentEntry/beforeUpdate.hook.js.map +0 -1
  246. package/content/plugins/crud/contentEntry/entryDataValidation.js.map +0 -1
  247. package/content/plugins/crud/contentEntry/hooks.d.ts +0 -18
  248. package/content/plugins/crud/contentEntry/hooks.js +0 -240
  249. package/content/plugins/crud/contentEntry/hooks.js.map +0 -1
  250. package/content/plugins/crud/contentEntry/markLockedFields.js.map +0 -1
  251. package/content/plugins/crud/contentEntry/runContentEntryLifecycleHooks.d.ts +0 -4
  252. package/content/plugins/crud/contentEntry/runContentEntryLifecycleHooks.js +0 -24
  253. package/content/plugins/crud/contentEntry/runContentEntryLifecycleHooks.js.map +0 -1
  254. package/content/plugins/crud/contentEntry.crud.js.map +0 -1
  255. package/content/plugins/crud/contentModel/afterCreate.hook.d.ts +0 -7
  256. package/content/plugins/crud/contentModel/afterCreate.hook.js +0 -24
  257. package/content/plugins/crud/contentModel/afterCreate.hook.js.map +0 -1
  258. package/content/plugins/crud/contentModel/afterDelete.hook.d.ts +0 -7
  259. package/content/plugins/crud/contentModel/afterDelete.hook.js +0 -24
  260. package/content/plugins/crud/contentModel/afterDelete.hook.js.map +0 -1
  261. package/content/plugins/crud/contentModel/afterUpdate.hook.d.ts +0 -7
  262. package/content/plugins/crud/contentModel/afterUpdate.hook.js +0 -24
  263. package/content/plugins/crud/contentModel/afterUpdate.hook.js.map +0 -1
  264. package/content/plugins/crud/contentModel/beforeCreate.hook.d.ts +0 -7
  265. package/content/plugins/crud/contentModel/beforeCreate.hook.js +0 -137
  266. package/content/plugins/crud/contentModel/beforeCreate.hook.js.map +0 -1
  267. package/content/plugins/crud/contentModel/beforeDelete.hook.d.ts +0 -7
  268. package/content/plugins/crud/contentModel/beforeDelete.hook.js +0 -58
  269. package/content/plugins/crud/contentModel/beforeDelete.hook.js.map +0 -1
  270. package/content/plugins/crud/contentModel/beforeUpdate.hook.d.ts +0 -7
  271. package/content/plugins/crud/contentModel/beforeUpdate.hook.js +0 -141
  272. package/content/plugins/crud/contentModel/beforeUpdate.hook.js.map +0 -1
  273. package/content/plugins/crud/contentModel/contentModelManagerFactory.js.map +0 -1
  274. package/content/plugins/crud/contentModel/createFieldModels.js.map +0 -1
  275. package/content/plugins/crud/contentModel/hooks.d.ts +0 -6
  276. package/content/plugins/crud/contentModel/hooks.js +0 -84
  277. package/content/plugins/crud/contentModel/hooks.js.map +0 -1
  278. package/content/plugins/crud/contentModel/idValidation.js.map +0 -1
  279. package/content/plugins/crud/contentModel/models.js.map +0 -1
  280. package/content/plugins/crud/contentModel/runContentModelLifecycleHooks.d.ts +0 -2
  281. package/content/plugins/crud/contentModel/runContentModelLifecycleHooks.js +0 -24
  282. package/content/plugins/crud/contentModel/runContentModelLifecycleHooks.js.map +0 -1
  283. package/content/plugins/crud/contentModel/validateLayout.js.map +0 -1
  284. package/content/plugins/crud/contentModel.crud.js.map +0 -1
  285. package/content/plugins/crud/contentModelGroup/afterCreate.hook.d.ts +0 -7
  286. package/content/plugins/crud/contentModelGroup/afterCreate.hook.js +0 -24
  287. package/content/plugins/crud/contentModelGroup/afterCreate.hook.js.map +0 -1
  288. package/content/plugins/crud/contentModelGroup/afterDelete.hook.d.ts +0 -8
  289. package/content/plugins/crud/contentModelGroup/afterDelete.hook.js +0 -22
  290. package/content/plugins/crud/contentModelGroup/afterDelete.hook.js.map +0 -1
  291. package/content/plugins/crud/contentModelGroup/afterUpdate.hook.d.ts +0 -7
  292. package/content/plugins/crud/contentModelGroup/afterUpdate.hook.js +0 -26
  293. package/content/plugins/crud/contentModelGroup/afterUpdate.hook.js.map +0 -1
  294. package/content/plugins/crud/contentModelGroup/beforeCreate.hook.d.ts +0 -7
  295. package/content/plugins/crud/contentModelGroup/beforeCreate.hook.js +0 -87
  296. package/content/plugins/crud/contentModelGroup/beforeCreate.hook.js.map +0 -1
  297. package/content/plugins/crud/contentModelGroup/beforeDelete.hook.d.ts +0 -7
  298. package/content/plugins/crud/contentModelGroup/beforeDelete.hook.js +0 -46
  299. package/content/plugins/crud/contentModelGroup/beforeDelete.hook.js.map +0 -1
  300. package/content/plugins/crud/contentModelGroup/beforeUpdate.hook.d.ts +0 -7
  301. package/content/plugins/crud/contentModelGroup/beforeUpdate.hook.js +0 -35
  302. package/content/plugins/crud/contentModelGroup/beforeUpdate.hook.js.map +0 -1
  303. package/content/plugins/crud/contentModelGroup.crud.js.map +0 -1
  304. package/content/plugins/graphqlFields/boolean.js.map +0 -1
  305. package/content/plugins/graphqlFields/datetime.js.map +0 -1
  306. package/content/plugins/graphqlFields/file.js.map +0 -1
  307. package/content/plugins/graphqlFields/index.js.map +0 -1
  308. package/content/plugins/graphqlFields/longText.js.map +0 -1
  309. package/content/plugins/graphqlFields/number.js.map +0 -1
  310. package/content/plugins/graphqlFields/object.js.map +0 -1
  311. package/content/plugins/graphqlFields/ref.js.map +0 -1
  312. package/content/plugins/graphqlFields/richText.js.map +0 -1
  313. package/content/plugins/graphqlFields/text.js.map +0 -1
  314. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js.map +0 -1
  315. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js.map +0 -1
  316. package/content/plugins/modelManager/DefaultContentModelManager.d.ts +0 -15
  317. package/content/plugins/modelManager/DefaultContentModelManager.js +0 -63
  318. package/content/plugins/modelManager/DefaultContentModelManager.js.map +0 -1
  319. package/content/plugins/modelManager/index.js.map +0 -1
  320. package/content/plugins/schema/baseSchema.js.map +0 -1
  321. package/content/plugins/schema/contentEntries.js.map +0 -1
  322. package/content/plugins/schema/contentModelGroups.js.map +0 -1
  323. package/content/plugins/schema/contentModels.js.map +0 -1
  324. package/content/plugins/schema/createFieldResolvers.js.map +0 -1
  325. package/content/plugins/schema/createManageResolvers.js.map +0 -1
  326. package/content/plugins/schema/createManageSDL.js.map +0 -1
  327. package/content/plugins/schema/createPreviewResolvers.js.map +0 -1
  328. package/content/plugins/schema/createReadResolvers.js.map +0 -1
  329. package/content/plugins/schema/createReadSDL.js.map +0 -1
  330. package/content/plugins/schema/resolvers/commonFieldResolvers.js.map +0 -1
  331. package/content/plugins/schema/resolvers/manage/resolveCreate.js.map +0 -1
  332. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js.map +0 -1
  333. package/content/plugins/schema/resolvers/manage/resolveDelete.js.map +0 -1
  334. package/content/plugins/schema/resolvers/manage/resolveGet.js.map +0 -1
  335. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js.map +0 -1
  336. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js.map +0 -1
  337. package/content/plugins/schema/resolvers/manage/resolveList.js.map +0 -1
  338. package/content/plugins/schema/resolvers/manage/resolvePublish.js.map +0 -1
  339. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  340. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
  341. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js.map +0 -1
  342. package/content/plugins/schema/resolvers/manage/resolveUpdate.js.map +0 -1
  343. package/content/plugins/schema/resolvers/preview/resolveGet.js.map +0 -1
  344. package/content/plugins/schema/resolvers/preview/resolveList.js.map +0 -1
  345. package/content/plugins/schema/resolvers/read/resolveGet.js.map +0 -1
  346. package/content/plugins/schema/resolvers/read/resolveList.js.map +0 -1
  347. package/content/plugins/schema/schemaPlugins.js.map +0 -1
  348. package/content/plugins/storage/default.js.map +0 -1
  349. package/content/plugins/storage/object.js.map +0 -1
  350. package/content/plugins/utils/createTypeName.js.map +0 -1
  351. package/content/plugins/utils/entryStorage.js.map +0 -1
  352. package/content/plugins/utils/getEntryTitle.js.map +0 -1
  353. package/content/plugins/utils/getSchemaFromFieldPlugins.js.map +0 -1
  354. package/content/plugins/utils/pluralizedTypeName.js.map +0 -1
  355. package/content/plugins/utils/renderFields.js.map +0 -1
  356. package/content/plugins/utils/renderGetFilterFields.js.map +0 -1
  357. package/content/plugins/utils/renderInputFields.js.map +0 -1
  358. package/content/plugins/utils/renderListFilterFields.js.map +0 -1
  359. package/content/plugins/utils/renderSortEnum.js.map +0 -1
  360. package/content/plugins/validators/dateGte.js.map +0 -1
  361. package/content/plugins/validators/dateLte.js.map +0 -1
  362. package/content/plugins/validators/gte.js.map +0 -1
  363. package/content/plugins/validators/in.js.map +0 -1
  364. package/content/plugins/validators/index.js.map +0 -1
  365. package/content/plugins/validators/lte.js.map +0 -1
  366. package/content/plugins/validators/maxLength.js.map +0 -1
  367. package/content/plugins/validators/minLength.js.map +0 -1
  368. package/content/plugins/validators/pattern.js.map +0 -1
  369. package/content/plugins/validators/patternPlugins/email.js.map +0 -1
  370. package/content/plugins/validators/patternPlugins/index.js.map +0 -1
  371. package/content/plugins/validators/patternPlugins/lowerCase.js.map +0 -1
  372. package/content/plugins/validators/patternPlugins/upperCase.js.map +0 -1
  373. package/content/plugins/validators/patternPlugins/url.js.map +0 -1
  374. package/content/plugins/validators/required.js.map +0 -1
  375. package/content/plugins/validators/timeGte.js.map +0 -1
  376. package/content/plugins/validators/timeLte.js.map +0 -1
  377. package/migrateCMSPermissions.js.map +0 -1
  378. package/plugins/InstallationPlugin.d.ts +0 -19
  379. package/plugins/InstallationPlugin.js +0 -39
  380. package/plugins/InstallationPlugin.js.map +0 -1
  381. package/plugins/context.js.map +0 -1
  382. package/plugins/crud/index.js.map +0 -1
  383. package/plugins/crud/settings.crud.js.map +0 -1
  384. package/plugins/crud/system.crud.js.map +0 -1
  385. package/plugins/graphql/system.js.map +0 -1
  386. package/plugins/graphql.js.map +0 -1
  387. package/plugins/index.d.ts +0 -2
  388. package/plugins/index.js +0 -25
  389. package/plugins/index.js.map +0 -1
  390. package/plugins/upgrades/index.js.map +0 -1
  391. package/plugins/upgrades/v5.5.0/helpers.js.map +0 -1
  392. package/plugins/upgrades/v5.5.0/index.js.map +0 -1
  393. package/transformers.js.map +0 -1
  394. package/types.js.map +0 -1
  395. package/utils.js.map +0 -1
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = void 0;
8
+ exports.createModelsCrud = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -23,13 +23,25 @@ var _createFieldModels = require("./contentModel/createFieldModels");
23
23
 
24
24
  var _validateLayout = require("./contentModel/validateLayout");
25
25
 
26
- var _hooks = require("./contentModel/hooks");
27
-
28
26
  var _apiSecurity = require("@webiny/api-security");
29
27
 
30
28
  var _error = _interopRequireDefault(require("@webiny/error"));
31
29
 
32
- var _ContentModelPlugin = require("@webiny/api-headless-cms/content/plugins/ContentModelPlugin");
30
+ var _CmsModelPlugin = require("../CmsModelPlugin");
31
+
32
+ var _pubsub = require("@webiny/pubsub");
33
+
34
+ var _beforeCreate = require("./contentModel/beforeCreate");
35
+
36
+ var _beforeUpdate = require("./contentModel/beforeUpdate");
37
+
38
+ var _beforeDelete = require("./contentModel/beforeDelete");
39
+
40
+ var _afterCreate = require("./contentModel/afterCreate");
41
+
42
+ var _afterUpdate = require("./contentModel/afterUpdate");
43
+
44
+ var _afterDelete = require("./contentModel/afterDelete");
33
45
 
34
46
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
47
 
@@ -39,315 +51,375 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
39
51
 
40
52
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
41
53
 
42
- var _default = () => ({
43
- type: "context",
44
- name: "context-content-model-storageOperations",
54
+ const createModelsCrud = params => {
55
+ const {
56
+ getTenant,
57
+ getIdentity,
58
+ getLocale,
59
+ storageOperations,
60
+ context
61
+ } = params;
62
+ const loaders = {
63
+ listModels: new _dataloader.default(async () => {
64
+ const models = await storageOperations.models.list({
65
+ where: {
66
+ tenant: getTenant().id,
67
+ locale: getLocale().code
68
+ }
69
+ });
70
+ return [models.map(model => {
71
+ return _objectSpread(_objectSpread({}, model), {}, {
72
+ tenant: model.tenant || getTenant().id,
73
+ locale: model.locale || getLocale().code
74
+ });
75
+ })];
76
+ })
77
+ };
78
+ const managers = new Map();
79
+
80
+ const updateManager = async (context, model) => {
81
+ const manager = await (0, _contentModelManagerFactory.contentModelManagerFactory)(context, model);
82
+ managers.set(model.modelId, manager);
83
+ return manager;
84
+ };
85
+
86
+ const checkModelPermissions = check => {
87
+ return utils.checkPermissions(context, "cms.contentModel", {
88
+ rwd: check
89
+ });
90
+ };
45
91
 
46
- async apply(context) {
92
+ const getModelsAsPlugins = () => {
93
+ const tenant = getTenant().id;
94
+ const locale = getLocale().code;
95
+ return context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type)
47
96
  /**
48
- * If cms is not defined on the context, do not continue, but log it.
97
+ * We need to filter out models that are not for this tenant or locale.
98
+ * If it does not have tenant or locale define, it is for every locale and tenant
49
99
  */
50
- if (!context.cms) {
51
- return;
52
- }
100
+ .filter(plugin => {
101
+ const {
102
+ tenant: t,
103
+ locale: l
104
+ } = plugin.contentModel;
105
+
106
+ if (t && t !== tenant) {
107
+ return false;
108
+ } else if (l && l !== locale) {
109
+ return false;
110
+ }
53
111
 
54
- const pluginType = "cms-content-model-storage-operations-provider";
55
- const providerPlugins = context.plugins.byType(pluginType);
56
- /**
57
- * Storage operations for the content model.
58
- * Contains logic to save the data into the specific storage.
59
- */
112
+ return true;
113
+ }).map(plugin => {
114
+ return _objectSpread(_objectSpread({}, plugin.contentModel), {}, {
115
+ tenant,
116
+ locale,
117
+ webinyVersion: context.WEBINY_VERSION
118
+ });
119
+ });
120
+ };
60
121
 
61
- const providerPlugin = providerPlugins[providerPlugins.length - 1];
122
+ const modelsGet = async modelId => {
123
+ const pluginModel = getModelsAsPlugins().find(model => model.modelId === modelId);
62
124
 
63
- if (!providerPlugin) {
64
- throw new _error.default(`Missing "${pluginType}" plugin.`, "PLUGIN_NOT_FOUND", {
65
- type: pluginType
66
- });
125
+ if (pluginModel) {
126
+ return pluginModel;
67
127
  }
68
128
 
69
- const storageOperations = await providerPlugin.provide({
70
- context
129
+ const model = await storageOperations.models.get({
130
+ tenant: getTenant().id,
131
+ locale: getLocale().code,
132
+ modelId
71
133
  });
72
- const loaders = {
73
- listModels: new _dataloader.default(async () => {
74
- const models = await storageOperations.list();
75
- return [models];
76
- })
77
- };
78
- const managers = new Map();
79
-
80
- const updateManager = async (context, model) => {
81
- const manager = await (0, _contentModelManagerFactory.contentModelManagerFactory)(context, model);
82
- managers.set(model.modelId, manager);
83
- return manager;
84
- };
85
-
86
- const checkModelPermissions = check => {
87
- return utils.checkPermissions(context, "cms.contentModel", {
88
- rwd: check
89
- });
90
- };
91
134
 
92
- const modelsGet = async modelId => {
93
- const pluginModel = context.plugins.byType(_ContentModelPlugin.ContentModelPlugin.type).find(plugin => plugin.contentModel.modelId === modelId);
135
+ if (!model) {
136
+ throw new _handlerGraphql.NotFoundError(`Content model "${modelId}" was not found!`);
137
+ }
94
138
 
95
- if (pluginModel) {
96
- return pluginModel.contentModel;
139
+ return _objectSpread(_objectSpread({}, model), {}, {
140
+ tenant: model.tenant || getTenant().id,
141
+ locale: model.locale || getLocale().code
142
+ });
143
+ };
144
+
145
+ const modelsList = async () => {
146
+ const databaseModels = await loaders.listModels.load("listModels");
147
+ const pluginsModels = getModelsAsPlugins();
148
+ return databaseModels.concat(pluginsModels);
149
+ };
150
+
151
+ const listOperations = async () => {
152
+ const permission = await checkModelPermissions("r");
153
+ const models = await modelsList();
154
+ return utils.filterAsync(models, async model => {
155
+ if (!utils.validateOwnership(context, permission, model)) {
156
+ return false;
97
157
  }
98
158
 
99
- const databaseModel = await storageOperations.get({
100
- id: modelId
101
- });
102
-
103
- if (!databaseModel) {
104
- throw new _handlerGraphql.NotFoundError(`Content model "${modelId}" was not found!`);
105
- }
159
+ return utils.validateModelAccess(context, model);
160
+ });
161
+ };
162
+
163
+ const get = async modelId => {
164
+ const permission = await checkModelPermissions("r");
165
+ const model = await modelsGet(modelId);
166
+ utils.checkOwnership(context, permission, model);
167
+ await utils.checkModelAccess(context, model);
168
+ return model;
169
+ };
170
+
171
+ const getManager = async modelId => {
172
+ if (managers.has(modelId)) {
173
+ return managers.get(modelId);
174
+ }
106
175
 
107
- return databaseModel;
108
- };
109
-
110
- const modelsList = async () => {
111
- const databaseModels = await loaders.listModels.load("listModels");
112
- const pluginsModels = context.plugins.byType(_ContentModelPlugin.ContentModelPlugin.type).map(plugin => plugin.contentModel);
113
- return [...databaseModels, ...pluginsModels];
114
- };
115
-
116
- const models = {
117
- operations: storageOperations,
118
- noAuth: () => {
119
- return {
120
- get: modelsGet,
121
- list: modelsList
122
- };
123
- },
124
- silentAuth: () => {
125
- return {
126
- list: async () => {
127
- try {
128
- return await models.list();
129
- } catch (ex) {
130
- if (ex instanceof _apiSecurity.NotAuthorizedError) {
131
- return [];
132
- }
133
-
134
- throw ex;
135
- }
136
- }
137
- };
138
- },
139
-
140
- async get(modelId) {
141
- const permission = await checkModelPermissions("r");
142
- const model = await modelsGet(modelId);
143
- utils.checkOwnership(context, permission, model);
144
- await utils.checkModelAccess(context, model);
145
- return model;
146
- },
147
-
148
- async list() {
149
- const permission = await checkModelPermissions("r");
150
- const models = await modelsList();
151
- return utils.filterAsync(models, async model => {
152
- if (!utils.validateOwnership(context, permission, model)) {
153
- return false;
154
- }
176
+ const models = await modelsList();
177
+ const model = models.find(m => m.modelId === modelId);
155
178
 
156
- return utils.validateModelAccess(context, model);
157
- });
158
- },
179
+ if (!model) {
180
+ throw new _handlerGraphql.NotFoundError(`There is no content model "${modelId}".`);
181
+ }
159
182
 
160
- async create(inputData) {
161
- await checkModelPermissions("w");
162
- const createdData = new _models.CreateContentModelModel().populate(inputData);
163
- await createdData.validate();
164
- const input = await createdData.toJSON();
165
- const group = await context.cms.groups.noAuth().get(input.group);
183
+ return await updateManager(context, model);
184
+ };
185
+
186
+ const onBeforeCreate = (0, _pubsub.createTopic)();
187
+ const onAfterCreate = (0, _pubsub.createTopic)();
188
+ const onBeforeUpdate = (0, _pubsub.createTopic)();
189
+ const onAfterUpdate = (0, _pubsub.createTopic)();
190
+ const onBeforeDelete = (0, _pubsub.createTopic)();
191
+ const onAfterDelete = (0, _pubsub.createTopic)();
192
+ /**
193
+ * We need to assign some default behaviors.
194
+ */
195
+
196
+ (0, _beforeCreate.assignBeforeModelCreate)({
197
+ onBeforeCreate,
198
+ plugins: context.plugins,
199
+ storageOperations
200
+ });
201
+ (0, _afterCreate.assignAfterModelCreate)({
202
+ context,
203
+ onAfterCreate
204
+ });
205
+ (0, _beforeUpdate.assignBeforeModelUpdate)({
206
+ onBeforeUpdate,
207
+ plugins: context.plugins,
208
+ storageOperations
209
+ });
210
+ (0, _afterUpdate.assignAfterModelUpdate)({
211
+ context,
212
+ onAfterUpdate
213
+ });
214
+ (0, _beforeDelete.assignBeforeModelDelete)({
215
+ onBeforeDelete,
216
+ plugins: context.plugins,
217
+ storageOperations
218
+ });
219
+ (0, _afterDelete.assignAfterModelDelete)({
220
+ context,
221
+ onAfterDelete
222
+ });
223
+ return {
224
+ onBeforeModelCreate: onBeforeCreate,
225
+ onAfterModelCreate: onAfterCreate,
226
+ onBeforeModelUpdate: onBeforeUpdate,
227
+ onAfterModelUpdate: onAfterUpdate,
228
+ onBeforeModelDelete: onBeforeDelete,
229
+ onAfterModelDelete: onAfterDelete,
230
+ silentAuthModel: () => {
231
+ return {
232
+ list: async () => {
233
+ try {
234
+ return await listOperations();
235
+ } catch (ex) {
236
+ if (ex instanceof _apiSecurity.NotAuthorizedError) {
237
+ return [];
238
+ }
166
239
 
167
- if (!group) {
168
- throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
240
+ throw ex;
241
+ }
169
242
  }
243
+ };
244
+ },
245
+ getModel: get,
246
+ listModels: listOperations,
247
+
248
+ async createModel(inputData) {
249
+ await checkModelPermissions("w");
250
+ const createdData = new _models.CreateContentModelModel().populate(inputData);
251
+ await createdData.validate();
252
+ const input = await createdData.toJSON();
253
+ context.security.disableAuthorization();
254
+ const group = await context.cms.getGroup(input.group);
255
+ context.security.enableAuthorization();
256
+
257
+ if (!group) {
258
+ throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
259
+ }
170
260
 
171
- const identity = context.security.getIdentity();
172
-
173
- const data = _objectSpread(_objectSpread({}, input), {}, {
174
- titleFieldId: "id",
175
- locale: context.cms.getLocale().code,
176
- group: {
177
- id: group.id,
178
- name: group.name
179
- },
180
- createdBy: {
181
- id: identity.id,
182
- displayName: identity.displayName,
183
- type: identity.type
184
- },
185
- createdOn: new Date().toISOString(),
186
- savedOn: new Date().toISOString(),
187
- fields: [],
188
- lockedFields: [],
189
- layout: []
190
- });
261
+ const identity = getIdentity();
262
+
263
+ const model = _objectSpread(_objectSpread({}, input), {}, {
264
+ titleFieldId: "id",
265
+ locale: getLocale().code,
266
+ tenant: getTenant().id,
267
+ group: {
268
+ id: group.id,
269
+ name: group.name
270
+ },
271
+ createdBy: {
272
+ id: identity.id,
273
+ displayName: identity.displayName,
274
+ type: identity.type
275
+ },
276
+ createdOn: new Date().toISOString(),
277
+ savedOn: new Date().toISOString(),
278
+ fields: [],
279
+ lockedFields: [],
280
+ layout: [],
281
+ webinyVersion: context.WEBINY_VERSION
282
+ });
191
283
 
192
- await (0, _hooks.beforeCreateHook)({
193
- context,
194
- storageOperations,
195
- input,
196
- data
197
- });
198
- const model = await storageOperations.create({
199
- input,
200
- data
201
- });
202
- await updateManager(context, model);
203
- await (0, _hooks.afterCreateHook)({
204
- context,
205
- storageOperations,
206
- input,
207
- model
208
- });
209
- return model;
210
- },
211
-
212
- /**
213
- * Method does not check for permissions or ownership.
214
- * @internal
215
- */
216
- async updateModel(model, data) {
217
- const input = data;
218
- await (0, _hooks.beforeUpdateHook)({
219
- context,
220
- storageOperations,
221
- model,
222
- data,
223
- input
224
- });
225
- const resultModel = await storageOperations.update({
226
- data,
227
- model,
228
- input
229
- });
230
- await updateManager(context, resultModel);
231
- await (0, _hooks.afterUpdateHook)({
232
- context,
233
- storageOperations,
234
- model: resultModel,
235
- data,
236
- input
237
- });
238
- return resultModel;
239
- },
284
+ await onBeforeCreate.publish({
285
+ model,
286
+ input
287
+ });
288
+ const createdModel = await storageOperations.models.create({
289
+ input,
290
+ model
291
+ });
292
+ loaders.listModels.clearAll();
293
+ await updateManager(context, model);
294
+ await onAfterCreate.publish({
295
+ input,
296
+ model: createdModel
297
+ });
298
+ return createdModel;
299
+ },
240
300
 
241
- async update(modelId, inputData) {
242
- await checkModelPermissions("w"); // Get a model record; this will also perform ownership validation.
301
+ /**
302
+ * Method does not check for permissions or ownership.
303
+ * @internal
304
+ */
305
+ async updateModelDirect(params) {
306
+ const {
307
+ model: initialModel,
308
+ original
309
+ } = params;
310
+
311
+ const model = _objectSpread(_objectSpread({}, initialModel), {}, {
312
+ tenant: initialModel.tenant || getTenant().id,
313
+ locale: initialModel.locale || getLocale().code,
314
+ webinyVersion: context.WEBINY_VERSION
315
+ });
243
316
 
244
- const model = await context.cms.models.get(modelId);
245
- const updatedData = new _models.UpdateContentModelModel().populate(inputData);
246
- await updatedData.validate();
247
- const input = await updatedData.toJSON({
248
- onlyDirty: true
249
- });
317
+ await onBeforeUpdate.publish({
318
+ input: {},
319
+ original,
320
+ model
321
+ });
322
+ const resultModel = await storageOperations.models.update({
323
+ original,
324
+ model,
325
+ input: {}
326
+ });
327
+ await updateManager(context, resultModel);
328
+ loaders.listModels.clearAll();
329
+ await onAfterUpdate.publish({
330
+ input: {},
331
+ original,
332
+ model: resultModel
333
+ });
334
+ return resultModel;
335
+ },
250
336
 
251
- if (Object.keys(input).length === 0) {
252
- return {};
253
- }
337
+ async updateModel(modelId, inputData) {
338
+ await checkModelPermissions("w"); // Get a model record; this will also perform ownership validation.
254
339
 
255
- if (input.group) {
256
- const group = await context.cms.groups.noAuth().get(input.group);
340
+ const original = await get(modelId);
341
+ const updatedData = new _models.UpdateContentModelModel().populate(inputData);
342
+ await updatedData.validate();
343
+ const input = await updatedData.toJSON({
344
+ onlyDirty: true
345
+ });
257
346
 
258
- if (!group) {
259
- throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
260
- }
347
+ if (Object.keys(input).length === 0) {
348
+ return {};
349
+ }
261
350
 
262
- input.group = {
263
- id: group.id,
264
- name: group.name
265
- };
351
+ if (input.group) {
352
+ context.security.disableAuthorization();
353
+ const group = await context.cms.getGroup(input.group);
354
+ context.security.enableAuthorization();
355
+
356
+ if (!group) {
357
+ throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
266
358
  }
267
359
 
268
- const modelFields = await (0, _createFieldModels.createFieldModels)(model, inputData);
269
- (0, _validateLayout.validateLayout)(input, modelFields);
360
+ input.group = {
361
+ id: group.id,
362
+ name: group.name
363
+ };
364
+ }
270
365
 
271
- const data = _objectSpread(_objectSpread({}, input), {}, {
272
- fields: modelFields,
273
- savedOn: new Date().toISOString()
274
- });
366
+ const modelFields = await (0, _createFieldModels.createFieldModels)(original, inputData);
367
+ (0, _validateLayout.validateLayout)(input, modelFields);
275
368
 
276
- await (0, _hooks.beforeUpdateHook)({
277
- context,
278
- storageOperations,
279
- model,
280
- data,
281
- input
282
- });
283
- const resultModel = await storageOperations.update({
284
- data,
285
- model,
286
- input
287
- });
288
- await updateManager(context, resultModel);
289
- await (0, _hooks.afterUpdateHook)({
290
- context,
291
- storageOperations,
292
- model: resultModel,
293
- data,
294
- input
295
- });
296
- return resultModel;
297
- },
298
-
299
- async delete(modelId) {
300
- await checkModelPermissions("d");
301
- const model = await context.cms.models.get(modelId);
302
- await (0, _hooks.beforeDeleteHook)({
303
- context,
304
- storageOperations,
305
- model
306
- });
307
- const result = await storageOperations.delete({
308
- model
309
- });
369
+ const model = _objectSpread(_objectSpread(_objectSpread({}, original), input), {}, {
370
+ tenant: original.tenant || getTenant().id,
371
+ locale: original.locale || getLocale().code,
372
+ webinyVersion: context.WEBINY_VERSION,
373
+ fields: modelFields,
374
+ savedOn: new Date().toISOString()
375
+ });
310
376
 
311
- if (!result) {
312
- throw new _error.default("Could not delete the content model", "CONTENT_MODEL_DELETE_ERROR", {
313
- modelId: model.modelId
314
- });
315
- }
377
+ await onBeforeUpdate.publish({
378
+ input,
379
+ original,
380
+ model
381
+ });
382
+ const resultModel = await storageOperations.models.update({
383
+ original,
384
+ model,
385
+ input
386
+ });
387
+ await updateManager(context, resultModel);
388
+ await onAfterUpdate.publish({
389
+ original,
390
+ model: resultModel,
391
+ input
392
+ });
393
+ return resultModel;
394
+ },
395
+
396
+ async deleteModel(modelId) {
397
+ await checkModelPermissions("d");
398
+ const model = await get(modelId);
399
+ await onBeforeDelete.publish({
400
+ model
401
+ });
316
402
 
317
- await (0, _hooks.afterDeleteHook)({
318
- context,
319
- storageOperations,
403
+ try {
404
+ await storageOperations.models.delete({
320
405
  model
321
406
  });
322
- managers.delete(model.modelId);
323
- },
324
-
325
- async getManager(modelId) {
326
- if (managers.has(modelId)) {
327
- return managers.get(modelId);
328
- }
329
-
330
- const models = await modelsList();
331
- const model = models.find(m => m.modelId === modelId);
332
-
333
- if (!model) {
334
- throw new _handlerGraphql.NotFoundError(`There is no content model "${modelId}".`);
335
- }
336
-
337
- return await updateManager(context, model);
338
- },
339
-
340
- getManagers: () => managers
341
- };
342
- context.cms = _objectSpread(_objectSpread({}, context.cms || {}), {}, {
343
- models,
344
- getModel: modelId => {
345
- return models.getManager(modelId);
407
+ } catch (ex) {
408
+ throw new _error.default(ex.message || "Could not delete the content model", ex.code || "CONTENT_MODEL_DELETE_ERROR", {
409
+ error: ex,
410
+ modelId: model.modelId
411
+ });
346
412
  }
347
- });
348
- }
349
413
 
350
- });
414
+ await onAfterDelete.publish({
415
+ model
416
+ });
417
+ managers.delete(model.modelId);
418
+ },
419
+
420
+ getModelManager: getManager,
421
+ getManagers: () => managers
422
+ };
423
+ };
351
424
 
352
- exports.default = _default;
353
- //# sourceMappingURL=contentModel.crud.js.map
425
+ exports.createModelsCrud = createModelsCrud;