@webiny/api-headless-cms 0.0.0-unstable.40876133bb → 0.0.0-unstable.496cf268ac

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 (371) 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.d.ts +1 -1
  13. package/crud/contentEntry/markLockedFields.js +19 -29
  14. package/crud/contentEntry/markLockedFields.js.map +1 -1
  15. package/crud/contentEntry/referenceFieldsMapping.js +12 -64
  16. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  17. package/crud/contentEntry/searchableFields.d.ts +9 -0
  18. package/crud/contentEntry/searchableFields.js +72 -0
  19. package/crud/contentEntry/searchableFields.js.map +1 -0
  20. package/crud/contentEntry.crud.d.ts +2 -1
  21. package/crud/contentEntry.crud.js +140 -193
  22. package/crud/contentEntry.crud.js.map +1 -1
  23. package/crud/contentModel/afterCreate.js +0 -2
  24. package/crud/contentModel/afterCreate.js.map +1 -1
  25. package/crud/contentModel/afterCreateFrom.js +0 -2
  26. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  27. package/crud/contentModel/afterDelete.js +0 -2
  28. package/crud/contentModel/afterDelete.js.map +1 -1
  29. package/crud/contentModel/afterUpdate.js +0 -2
  30. package/crud/contentModel/afterUpdate.js.map +1 -1
  31. package/crud/contentModel/beforeCreate.d.ts +2 -3
  32. package/crud/contentModel/beforeCreate.js +11 -36
  33. package/crud/contentModel/beforeCreate.js.map +1 -1
  34. package/crud/contentModel/beforeDelete.js +0 -10
  35. package/crud/contentModel/beforeDelete.js.map +1 -1
  36. package/crud/contentModel/beforeUpdate.d.ts +2 -4
  37. package/crud/contentModel/beforeUpdate.js +6 -7
  38. package/crud/contentModel/beforeUpdate.js.map +1 -1
  39. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  40. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  41. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  42. package/crud/contentModel/contentModelManagerFactory.js +0 -7
  43. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  44. package/crud/contentModel/createFieldStorageId.js +4 -3
  45. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  46. package/crud/contentModel/defaultFields.d.ts +5 -0
  47. package/crud/contentModel/defaultFields.js +58 -0
  48. package/crud/contentModel/defaultFields.js.map +1 -0
  49. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  50. package/crud/contentModel/fields/descriptionField.js +42 -0
  51. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  52. package/crud/contentModel/fields/imageField.d.ts +2 -0
  53. package/crud/contentModel/fields/imageField.js +46 -0
  54. package/crud/contentModel/fields/imageField.js.map +1 -0
  55. package/crud/contentModel/fields/titleField.d.ts +2 -0
  56. package/crud/contentModel/fields/titleField.js +58 -0
  57. package/crud/contentModel/fields/titleField.js.map +1 -0
  58. package/crud/contentModel/models.js +12 -0
  59. package/crud/contentModel/models.js.map +1 -1
  60. package/crud/contentModel/validateLayout.js +0 -8
  61. package/crud/contentModel/validateLayout.js.map +1 -1
  62. package/crud/contentModel/validateModel.d.ts +4 -4
  63. package/crud/contentModel/validateModel.js +6 -11
  64. package/crud/contentModel/validateModel.js.map +1 -1
  65. package/crud/contentModel/validateModelFields.d.ts +4 -4
  66. package/crud/contentModel/validateModelFields.js +131 -147
  67. package/crud/contentModel/validateModelFields.js.map +1 -1
  68. package/crud/contentModel/validation.d.ts +519 -0
  69. package/crud/contentModel/validation.js +145 -0
  70. package/crud/contentModel/validation.js.map +1 -0
  71. package/crud/contentModel.crud.js +245 -272
  72. package/crud/contentModel.crud.js.map +1 -1
  73. package/crud/contentModelGroup/beforeCreate.js +0 -12
  74. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  75. package/crud/contentModelGroup/beforeDelete.js +0 -8
  76. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  77. package/crud/contentModelGroup/beforeUpdate.js +0 -5
  78. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  79. package/crud/contentModelGroup/validation.d.ts +30 -0
  80. package/crud/contentModelGroup/validation.js +34 -0
  81. package/crud/contentModelGroup/validation.js.map +1 -0
  82. package/crud/contentModelGroup.crud.js +53 -95
  83. package/crud/contentModelGroup.crud.js.map +1 -1
  84. package/crud/settings.crud.js +0 -12
  85. package/crud/settings.crud.js.map +1 -1
  86. package/crud/system.crud.js +1 -96
  87. package/crud/system.crud.js.map +1 -1
  88. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
  89. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  90. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
  91. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
  92. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
  93. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
  94. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  95. package/fieldConverters/index.d.ts +2 -1
  96. package/fieldConverters/index.js +2 -5
  97. package/fieldConverters/index.js.map +1 -1
  98. package/graphql/buildSchemaPlugins.d.ts +8 -3
  99. package/graphql/buildSchemaPlugins.js +6 -14
  100. package/graphql/buildSchemaPlugins.js.map +1 -1
  101. package/graphql/createExecutableSchema.d.ts +7 -0
  102. package/graphql/createExecutableSchema.js +29 -0
  103. package/graphql/createExecutableSchema.js.map +1 -0
  104. package/graphql/generateSchema.d.ts +8 -0
  105. package/graphql/generateSchema.js +31 -0
  106. package/graphql/generateSchema.js.map +1 -0
  107. package/graphql/graphQLHandlerFactory.js +95 -74
  108. package/graphql/graphQLHandlerFactory.js.map +1 -1
  109. package/graphql/index.d.ts +1 -3
  110. package/graphql/index.js +2 -46
  111. package/graphql/index.js.map +1 -1
  112. package/graphql/schema/baseContentSchema.d.ts +6 -2
  113. package/graphql/schema/baseContentSchema.js +10 -20
  114. package/graphql/schema/baseContentSchema.js.map +1 -1
  115. package/graphql/schema/baseSchema.d.ts +3 -0
  116. package/graphql/schema/baseSchema.js +53 -0
  117. package/graphql/schema/baseSchema.js.map +1 -0
  118. package/graphql/schema/contentEntries.d.ts +6 -2
  119. package/graphql/schema/contentEntries.js +118 -107
  120. package/graphql/schema/contentEntries.js.map +1 -1
  121. package/graphql/schema/contentModelGroups.d.ts +6 -2
  122. package/graphql/schema/contentModelGroups.js +10 -23
  123. package/graphql/schema/contentModelGroups.js.map +1 -1
  124. package/graphql/schema/contentModels.d.ts +6 -2
  125. package/graphql/schema/contentModels.js +62 -26
  126. package/graphql/schema/contentModels.js.map +1 -1
  127. package/graphql/schema/createFieldResolvers.d.ts +1 -1
  128. package/graphql/schema/createFieldResolvers.js +20 -27
  129. package/graphql/schema/createFieldResolvers.js.map +1 -1
  130. package/graphql/schema/createManageResolvers.d.ts +1 -1
  131. package/graphql/schema/createManageResolvers.js +33 -43
  132. package/graphql/schema/createManageResolvers.js.map +1 -1
  133. package/graphql/schema/createManageSDL.d.ts +3 -0
  134. package/graphql/schema/createManageSDL.js +64 -67
  135. package/graphql/schema/createManageSDL.js.map +1 -1
  136. package/graphql/schema/createPreviewResolvers.js +3 -17
  137. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  138. package/graphql/schema/createReadResolvers.js +8 -17
  139. package/graphql/schema/createReadResolvers.js.map +1 -1
  140. package/graphql/schema/createReadSDL.d.ts +3 -0
  141. package/graphql/schema/createReadSDL.js +33 -35
  142. package/graphql/schema/createReadSDL.js.map +1 -1
  143. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  144. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -3
  145. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  146. package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
  147. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  148. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
  149. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  150. package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
  151. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  152. package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
  153. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  154. package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
  155. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  156. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
  157. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  158. package/graphql/schema/resolvers/manage/resolveList.js +0 -3
  159. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  160. package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
  161. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  162. package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
  163. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  164. package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
  165. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  166. package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
  167. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  168. package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
  169. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  170. package/graphql/schema/resolvers/preview/resolveList.js +0 -3
  171. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  172. package/graphql/schema/resolvers/read/resolveGet.js +0 -8
  173. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  174. package/graphql/schema/resolvers/read/resolveList.js +0 -3
  175. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  176. package/graphql/schema/schemaPlugins.d.ts +8 -3
  177. package/graphql/schema/schemaPlugins.js +64 -66
  178. package/graphql/schema/schemaPlugins.js.map +1 -1
  179. package/graphql/system.js +55 -87
  180. package/graphql/system.js.map +1 -1
  181. package/graphqlFields/boolean.js +0 -12
  182. package/graphqlFields/boolean.js.map +1 -1
  183. package/graphqlFields/datetime.js +0 -17
  184. package/graphqlFields/datetime.js.map +1 -1
  185. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
  186. package/graphqlFields/dynamicZone/dynamicZoneField.js +216 -0
  187. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
  188. package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
  189. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
  190. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
  191. package/graphqlFields/dynamicZone/index.d.ts +2 -0
  192. package/graphqlFields/dynamicZone/index.js +19 -0
  193. package/graphqlFields/dynamicZone/index.js.map +1 -0
  194. package/graphqlFields/file.js +0 -8
  195. package/graphqlFields/file.js.map +1 -1
  196. package/graphqlFields/helpers.js +0 -10
  197. package/graphqlFields/helpers.js.map +1 -1
  198. package/graphqlFields/index.d.ts +1 -1
  199. package/graphqlFields/index.js +2 -12
  200. package/graphqlFields/index.js.map +1 -1
  201. package/graphqlFields/longText.js +0 -10
  202. package/graphqlFields/longText.js.map +1 -1
  203. package/graphqlFields/number.js +4 -12
  204. package/graphqlFields/number.js.map +1 -1
  205. package/graphqlFields/object.js +118 -98
  206. package/graphqlFields/object.js.map +1 -1
  207. package/graphqlFields/ref.js +86 -106
  208. package/graphqlFields/ref.js.map +1 -1
  209. package/graphqlFields/richText.js +0 -9
  210. package/graphqlFields/richText.js.map +1 -1
  211. package/graphqlFields/text.js +0 -11
  212. package/graphqlFields/text.js.map +1 -1
  213. package/index.d.ts +3 -3
  214. package/index.js +3 -27
  215. package/index.js.map +1 -1
  216. package/modelManager/DefaultCmsModelManager.js +0 -16
  217. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  218. package/modelManager/index.js +0 -4
  219. package/modelManager/index.js.map +1 -1
  220. package/package.json +27 -28
  221. package/parameters/context.js +0 -4
  222. package/parameters/context.js.map +1 -1
  223. package/parameters/header.js +0 -11
  224. package/parameters/header.js.map +1 -1
  225. package/parameters/index.js +0 -8
  226. package/parameters/index.js.map +1 -1
  227. package/parameters/manual.js +1 -8
  228. package/parameters/manual.js.map +1 -1
  229. package/parameters/path.js +0 -11
  230. package/parameters/path.js.map +1 -1
  231. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  232. package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
  233. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  234. package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
  235. package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
  236. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
  237. package/plugins/CmsGroupPlugin.js +0 -8
  238. package/plugins/CmsGroupPlugin.js.map +1 -1
  239. package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
  240. package/plugins/CmsModelFieldConverterPlugin.js +0 -5
  241. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  242. package/plugins/CmsModelPlugin.d.ts +11 -1
  243. package/plugins/CmsModelPlugin.js +15 -40
  244. package/plugins/CmsModelPlugin.js.map +1 -1
  245. package/plugins/CmsParametersPlugin.js +0 -7
  246. package/plugins/CmsParametersPlugin.js.map +1 -1
  247. package/plugins/StorageTransformPlugin.d.ts +11 -11
  248. package/plugins/StorageTransformPlugin.js +0 -9
  249. package/plugins/StorageTransformPlugin.js.map +1 -1
  250. package/plugins/index.d.ts +2 -0
  251. package/plugins/index.js +22 -10
  252. package/plugins/index.js.map +1 -1
  253. package/storage/default.js +0 -3
  254. package/storage/default.js.map +1 -1
  255. package/storage/object.js +4 -20
  256. package/storage/object.js.map +1 -1
  257. package/types.d.ts +315 -77
  258. package/types.js +63 -70
  259. package/types.js.map +1 -1
  260. package/utils/access.js +11 -25
  261. package/utils/access.js.map +1 -1
  262. package/utils/converters/Converter.js +0 -13
  263. package/utils/converters/Converter.js.map +1 -1
  264. package/utils/converters/ConverterCollection.js +14 -34
  265. package/utils/converters/ConverterCollection.js.map +1 -1
  266. package/utils/converters/valueKeyStorageConverter.js +2 -27
  267. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  268. package/utils/createTypeFromFields.d.ts +16 -0
  269. package/utils/createTypeFromFields.js +67 -0
  270. package/utils/createTypeFromFields.js.map +1 -0
  271. package/utils/createTypeName.js +2 -9
  272. package/utils/createTypeName.js.map +1 -1
  273. package/utils/entryStorage.js +22 -35
  274. package/utils/entryStorage.js.map +1 -1
  275. package/utils/filterAsync.js +0 -5
  276. package/utils/filterAsync.js.map +1 -1
  277. package/utils/getBaseFieldType.d.ts +4 -0
  278. package/utils/getBaseFieldType.js +10 -0
  279. package/utils/getBaseFieldType.js.map +1 -0
  280. package/utils/getEntryDescription.d.ts +2 -0
  281. package/utils/getEntryDescription.js +17 -0
  282. package/utils/getEntryDescription.js.map +1 -0
  283. package/utils/getEntryImage.d.ts +2 -0
  284. package/utils/getEntryImage.js +17 -0
  285. package/utils/getEntryImage.js.map +1 -0
  286. package/utils/getEntryTitle.js +0 -9
  287. package/utils/getEntryTitle.js.map +1 -1
  288. package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
  289. package/utils/getSchemaFromFieldPlugins.js +23 -19
  290. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  291. package/utils/ownership.d.ts +3 -3
  292. package/utils/ownership.js +0 -8
  293. package/utils/ownership.js.map +1 -1
  294. package/utils/permissions.js +8 -23
  295. package/utils/permissions.js.map +1 -1
  296. package/utils/removeNullValues.d.ts +1 -0
  297. package/utils/removeNullValues.js +17 -0
  298. package/utils/removeNullValues.js.map +1 -0
  299. package/utils/removeUndefinedValues.d.ts +1 -0
  300. package/utils/removeUndefinedValues.js +17 -0
  301. package/utils/removeUndefinedValues.js.map +1 -0
  302. package/utils/renderFields.d.ts +2 -1
  303. package/utils/renderFields.js +10 -10
  304. package/utils/renderFields.js.map +1 -1
  305. package/utils/renderGetFilterFields.js +6 -14
  306. package/utils/renderGetFilterFields.js.map +1 -1
  307. package/utils/renderInputFields.d.ts +2 -1
  308. package/utils/renderInputFields.js +6 -9
  309. package/utils/renderInputFields.js.map +1 -1
  310. package/utils/renderListFilterFields.js +4 -10
  311. package/utils/renderListFilterFields.js.map +1 -1
  312. package/utils/renderSortEnum.d.ts +7 -4
  313. package/utils/renderSortEnum.js +21 -11
  314. package/utils/renderSortEnum.js.map +1 -1
  315. package/utils/toSlug.js +0 -4
  316. package/utils/toSlug.js.map +1 -1
  317. package/validators/dateGte.js +0 -7
  318. package/validators/dateGte.js.map +1 -1
  319. package/validators/dateLte.js +0 -7
  320. package/validators/dateLte.js.map +1 -1
  321. package/validators/dynamicZone.d.ts +2 -0
  322. package/validators/dynamicZone.js +20 -0
  323. package/validators/dynamicZone.js.map +1 -0
  324. package/validators/gte.js +0 -8
  325. package/validators/gte.js.map +1 -1
  326. package/validators/in.js +0 -8
  327. package/validators/in.js.map +1 -1
  328. package/validators/index.js +2 -16
  329. package/validators/index.js.map +1 -1
  330. package/validators/lte.js +0 -8
  331. package/validators/lte.js.map +1 -1
  332. package/validators/maxLength.js +0 -8
  333. package/validators/maxLength.js.map +1 -1
  334. package/validators/minLength.js +0 -8
  335. package/validators/minLength.js.map +1 -1
  336. package/validators/pattern.js +0 -9
  337. package/validators/pattern.js.map +1 -1
  338. package/validators/patternPlugins/email.js +0 -2
  339. package/validators/patternPlugins/email.js.map +1 -1
  340. package/validators/patternPlugins/index.js +0 -8
  341. package/validators/patternPlugins/index.js.map +1 -1
  342. package/validators/patternPlugins/lowerCase.js +0 -2
  343. package/validators/patternPlugins/lowerCase.js.map +1 -1
  344. package/validators/patternPlugins/lowerCaseSpace.js +0 -2
  345. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  346. package/validators/patternPlugins/upperCase.js +0 -2
  347. package/validators/patternPlugins/upperCase.js.map +1 -1
  348. package/validators/patternPlugins/upperCaseSpace.js +0 -2
  349. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  350. package/validators/patternPlugins/url.js +0 -2
  351. package/validators/patternPlugins/url.js.map +1 -1
  352. package/validators/required.js +0 -5
  353. package/validators/required.js.map +1 -1
  354. package/validators/timeGte.js +0 -8
  355. package/validators/timeGte.js.map +1 -1
  356. package/validators/timeLte.js +0 -8
  357. package/validators/timeLte.js.map +1 -1
  358. package/validators/unique.js +0 -7
  359. package/validators/unique.js.map +1 -1
  360. package/crud/index.d.ts +0 -6
  361. package/crud/index.js +0 -85
  362. package/crud/index.js.map +0 -1
  363. package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
  364. package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
  365. package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
  366. package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
  367. package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
  368. package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
  369. package/utils/filterModelFields.d.ts +0 -16
  370. package/utils/filterModelFields.js +0 -77
  371. 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,28 +141,29 @@ 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,
177
150
  input
178
151
  });
152
+ context.security.disableAuthorization();
153
+ const models = await context.cms.listModels();
154
+ context.security.enableAuthorization();
179
155
  /**
180
156
  * and then we move onto model and fields...
181
157
  */
182
-
183
158
  await (0, _validateModel.validateModel)({
159
+ models,
184
160
  model,
185
- plugins
161
+ context
186
162
  });
187
163
  });
188
164
  onModelBeforeCreateFrom.subscribe(createOnModelBeforeCb({
189
165
  storageOperations,
190
- plugins
166
+ plugins: context.plugins
191
167
  }));
192
168
  };
193
-
194
169
  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 onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageOperations,\n plugins\n })\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AASA;;AACA;;AACA;;AAEA,MAAMA,qBAA+B,GAAG,CACpC,cADoC,EAEpC,eAFoC,EAGpC,mBAHoC,EAIpC,oBAJoC,CAAxC;AAMA;AACA;AACA;AACA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,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","security","disableAuthorization","cms","listModels","enableAuthorization","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 context.security.disableAuthorization();\n const models = await context.cms.listModels();\n context.security.enableAuthorization();\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n models,\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,IAAI,EAAE;IAC7D,MAAM,IAAIJ,cAAW,CAChB,+BAA8BF,OAAQ,+CAA8CM,4BAA6B,SAAQ,EAC1H,yBAAyB,EACzB;MACIN,OAAO;MACPO,QAAQ,EAAED;IACd,CAA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;MAC7BE,iBAAiB;MACjBD,OAAO,EAAEoB,OAAO,CAACpB;IACrB,CAAC,CAAC;IACF,MAAM0B,EAAE,CAAC;MACL/B,KAAK;MACL2B;IACJ,CAAC,CAAC;IACFF,OAAO,CAACO,QAAQ,CAACC,oBAAoB,EAAE;IACvC,MAAMlB,MAAM,GAAG,MAAMU,OAAO,CAACS,GAAG,CAACC,UAAU,EAAE;IAC7CV,OAAO,CAACO,QAAQ,CAACI,mBAAmB,EAAE;IACtC;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBtB,MAAM;MACNf,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,
@@ -22,16 +19,18 @@ const assignModelBeforeUpdate = params => {
22
19
  * First we go through the layout...
23
20
  */
24
21
  (0, _validateLayout.validateLayout)(model.layout, model.fields);
22
+ context.security.disableAuthorization();
23
+ const models = await context.cms.listModels();
24
+ context.security.enableAuthorization();
25
25
  /**
26
26
  * then the model and fields...
27
27
  */
28
-
29
28
  await (0, _validateModel.validateModel)({
29
+ models,
30
30
  model,
31
31
  original,
32
- plugins
32
+ context
33
33
  });
34
34
  });
35
35
  };
36
-
37
36
  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","security","disableAuthorization","models","cms","listModels","enableAuthorization","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 context.security.disableAuthorization();\n const models = await context.cms.listModels();\n context.security.enableAuthorization();\n /**\n * then the model and fields...\n */\n await validateModel({\n models,\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;IAE1CN,OAAO,CAACO,QAAQ,CAACC,oBAAoB,EAAE;IACvC,MAAMC,MAAM,GAAG,MAAMT,OAAO,CAACU,GAAG,CAACC,UAAU,EAAE;IAC7CX,OAAO,CAACO,QAAQ,CAACK,mBAAmB,EAAE;IACtC;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBJ,MAAM;MACNP,KAAK;MACLC,QAAQ;MACRH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { CmsModel } from "../../../types";
2
+ export declare const ensureSingularApiName: (model: CmsModel) => string;
3
+ export declare const ensurePluralApiName: (model: CmsModel) => string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ensureSingularApiName = exports.ensurePluralApiName = void 0;
8
+ var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
9
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
10
+ var _pluralize = _interopRequireDefault(require("pluralize"));
11
+ const ensureSingularApiName = model => {
12
+ if (!model.singularApiName) {
13
+ return (0, _upperFirst.default)((0, _camelCase.default)(model.modelId));
14
+ }
15
+ return model.singularApiName;
16
+ };
17
+ exports.ensureSingularApiName = ensureSingularApiName;
18
+ const ensurePluralApiName = model => {
19
+ if (!model.pluralApiName) {
20
+ return (0, _pluralize.default)(ensureSingularApiName(model));
21
+ }
22
+ return model.pluralApiName;
23
+ };
24
+ exports.ensurePluralApiName = ensurePluralApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ensureSingularApiName","model","singularApiName","upperFirst","camelCase","modelId","ensurePluralApiName","pluralApiName","pluralize"],"sources":["modelApiName.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { CmsModel } from \"~/types\";\n\nexport const ensureSingularApiName = (model: CmsModel): string => {\n if (!model.singularApiName) {\n return upperFirst(camelCase(model.modelId));\n }\n return model.singularApiName;\n};\n\nexport const ensurePluralApiName = (model: CmsModel): string => {\n if (!model.pluralApiName) {\n return pluralize(ensureSingularApiName(model));\n }\n return model.pluralApiName;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAIC,KAAe,IAAa;EAC9D,IAAI,CAACA,KAAK,CAACC,eAAe,EAAE;IACxB,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACH,KAAK,CAACI,OAAO,CAAC,CAAC;EAC/C;EACA,OAAOJ,KAAK,CAACC,eAAe;AAChC,CAAC;AAAC;AAEK,MAAMI,mBAAmB,GAAIL,KAAe,IAAa;EAC5D,IAAI,CAACA,KAAK,CAACM,aAAa,EAAE;IACtB,OAAO,IAAAC,kBAAS,EAACR,qBAAqB,CAACC,KAAK,CAAC,CAAC;EAClD;EACA,OAAOA,KAAK,CAACM,aAAa;AAC9B,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"}
@@ -0,0 +1,5 @@
1
+ import { CmsModelCreateInput } from "../../types";
2
+ /**
3
+ * We only assign default fields if there are no fields in the model already.
4
+ */
5
+ export declare const assignModelDefaultFields: (model: CmsModelCreateInput) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignModelDefaultFields = void 0;
7
+ var _utils = require("@webiny/utils");
8
+ const createDefaultFields = () => {
9
+ return [{
10
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
11
+ fieldId: "title",
12
+ type: "text",
13
+ label: "Title",
14
+ validation: [{
15
+ name: "required",
16
+ message: "Title is a required field."
17
+ }],
18
+ listValidation: [],
19
+ renderer: {
20
+ name: "text-input"
21
+ }
22
+ }, {
23
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
24
+ fieldId: "description",
25
+ type: "long-text",
26
+ label: "Description",
27
+ validation: [],
28
+ listValidation: [],
29
+ renderer: {
30
+ name: "long-text-text-area"
31
+ }
32
+ }, {
33
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
34
+ fieldId: "image",
35
+ type: "file",
36
+ label: "Image",
37
+ validation: [],
38
+ listValidation: [],
39
+ renderer: {
40
+ name: "file-input"
41
+ },
42
+ settings: {
43
+ imagesOnly: true
44
+ }
45
+ }];
46
+ };
47
+
48
+ /**
49
+ * We only assign default fields if there are no fields in the model already.
50
+ */
51
+ const assignModelDefaultFields = model => {
52
+ if (model.fields && model.fields.length !== 0) {
53
+ return;
54
+ }
55
+ model.fields = createDefaultFields();
56
+ model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];
57
+ };
58
+ exports.assignModelDefaultFields = assignModelDefaultFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createDefaultFields","id","generateAlphaNumericLowerCaseId","fieldId","type","label","validation","name","message","listValidation","renderer","settings","imagesOnly","assignModelDefaultFields","model","fields","length","layout"],"sources":["defaultFields.ts"],"sourcesContent":["import { CmsModelCreateInput, CmsModelFieldInput } from \"~/types\";\nimport { generateAlphaNumericLowerCaseId } from \"@webiny/utils\";\n\nconst createDefaultFields = (): CmsModelFieldInput[] => {\n return [\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"title\",\n type: \"text\",\n label: \"Title\",\n validation: [\n {\n name: \"required\",\n message: \"Title is a required field.\"\n }\n ],\n listValidation: [],\n renderer: {\n name: \"text-input\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"description\",\n type: \"long-text\",\n label: \"Description\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"long-text-text-area\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"image\",\n type: \"file\",\n label: \"Image\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"file-input\"\n },\n settings: {\n imagesOnly: true\n }\n }\n ];\n};\n\n/**\n * We only assign default fields if there are no fields in the model already.\n */\nexport const assignModelDefaultFields = (model: CmsModelCreateInput): void => {\n if (model.fields && model.fields.length !== 0) {\n return;\n }\n\n model.fields = createDefaultFields();\n model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,mBAAmB,GAAG,MAA4B;EACpD,OAAO,CACH;IACIC,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,CACR;MACIC,IAAI,EAAE,UAAU;MAChBC,OAAO,EAAE;IACb,CAAC,CACJ;IACDC,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,aAAa;IACtBC,IAAI,EAAE,WAAW;IACjBC,KAAK,EAAE,aAAa;IACpBC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV,CAAC;IACDI,QAAQ,EAAE;MACNC,UAAU,EAAE;IAChB;EACJ,CAAC,CACJ;AACL,CAAC;;AAED;AACA;AACA;AACO,MAAMC,wBAAwB,GAAIC,KAA0B,IAAW;EAC1E,IAAIA,KAAK,CAACC,MAAM,IAAID,KAAK,CAACC,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;IAC3C;EACJ;EAEAF,KAAK,CAACC,MAAM,GAAGf,mBAAmB,EAAE;EACpCc,KAAK,CAACG,MAAM,GAAG,CAAC,CAACH,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,EAAE,CAACa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,EAAEa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,CAAC;AACnF,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelDescriptionFieldId: (fields: CmsModelField[], descriptionFieldId?: string | null) => string | null | undefined;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelDescriptionFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const getContentModelDescriptionFieldId = (fields, descriptionFieldId) => {
11
+ /**
12
+ * If there are no fields defined, we will just set as null.
13
+ */
14
+ if (fields.length === 0) {
15
+ return null;
16
+ }
17
+ /**
18
+ * If description field is not defined, let us find possible one.
19
+ */
20
+ if (!descriptionFieldId) {
21
+ const descriptionField = fields.find(field => {
22
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text" && !field.multipleValues;
23
+ });
24
+ return (descriptionField === null || descriptionField === void 0 ? void 0 : descriptionField.fieldId) || null;
25
+ }
26
+ const target = fields.find(field => field.fieldId === descriptionFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text");
27
+ if (!target) {
28
+ throw new _error.default(`Field selected for the description field does not exist in the model.`, "VALIDATION_ERROR", {
29
+ fieldId: descriptionFieldId,
30
+ fields
31
+ });
32
+ }
33
+ if (target.multipleValues) {
34
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry description.`, "ENTRY_TITLE_FIELD_TYPE", {
35
+ storageId: target.storageId,
36
+ fieldId: target.fieldId,
37
+ type: target.type
38
+ });
39
+ }
40
+ return target.fieldId;
41
+ };
42
+ exports.getContentModelDescriptionFieldId = getContentModelDescriptionFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getContentModelDescriptionFieldId","fields","descriptionFieldId","length","descriptionField","find","field","getBaseFieldType","multipleValues","fieldId","target","WebinyError","storageId","type"],"sources":["descriptionField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelDescriptionFieldId = (\n fields: CmsModelField[],\n descriptionFieldId?: string | null\n): string | null | undefined => {\n /**\n * If there are no fields defined, we will just set as null.\n */\n if (fields.length === 0) {\n return null;\n }\n /**\n * If description field is not defined, let us find possible one.\n */\n if (!descriptionFieldId) {\n const descriptionField = fields.find(field => {\n return getBaseFieldType(field) === \"long-text\" && !field.multipleValues;\n });\n return descriptionField?.fieldId || null;\n }\n const target = fields.find(\n field => field.fieldId === descriptionFieldId && getBaseFieldType(field) === \"long-text\"\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the description field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: descriptionFieldId,\n fields\n }\n );\n }\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry description.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEO,MAAMA,iCAAiC,GAAG,CAC7CC,MAAuB,EACvBC,kBAAkC,KACN;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,kBAAkB,EAAE;IACrB,MAAME,gBAAgB,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAC1C,OAAO,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,IAAI,CAACA,KAAK,CAACE,cAAc;IAC3E,CAAC,CAAC;IACF,OAAO,CAAAJ,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEK,OAAO,KAAI,IAAI;EAC5C;EACA,MAAMC,MAAM,GAAGT,MAAM,CAACI,IAAI,CACtBC,KAAK,IAAIA,KAAK,CAACG,OAAO,KAAKP,kBAAkB,IAAI,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,CAC3F;EACD,IAAI,CAACI,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,uEAAsE,EACvE,kBAAkB,EAClB;MACIF,OAAO,EAAEP,kBAAkB;MAC3BD;IACJ,CAAC,CACJ;EACL;EACA,IAAIS,MAAM,CAACF,cAAc,EAAE;IACvB,MAAM,IAAIG,cAAW,CAChB,6EAA4E,EAC7E,wBAAwB,EACxB;MACIC,SAAS,EAAEF,MAAM,CAACE,SAAS;MAC3BH,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBI,IAAI,EAAEH,MAAM,CAACG;IACjB,CAAC,CACJ;EACL;EAEA,OAAOH,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelImageFieldId: (fields: CmsModelField[], imageFieldId?: string | null) => string | null | undefined;