@webiny/api-headless-cms 0.0.0-unstable.5e7233243f → 0.0.0-unstable.611c5af35e

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 (290) hide show
  1. package/context.js +3 -22
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/afterDelete.d.ts +2 -2
  4. package/crud/contentEntry/afterDelete.js +2 -7
  5. package/crud/contentEntry/afterDelete.js.map +1 -1
  6. package/crud/contentEntry/beforeCreate.d.ts +2 -2
  7. package/crud/contentEntry/beforeCreate.js +2 -5
  8. package/crud/contentEntry/beforeCreate.js.map +1 -1
  9. package/crud/contentEntry/beforeUpdate.d.ts +2 -2
  10. package/crud/contentEntry/beforeUpdate.js +2 -5
  11. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  12. package/crud/contentEntry/entryDataValidation.js +4 -47
  13. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  14. package/crud/contentEntry/markLockedFields.js +8 -35
  15. package/crud/contentEntry/markLockedFields.js.map +1 -1
  16. package/crud/contentEntry/referenceFieldsMapping.js +8 -68
  17. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  18. package/crud/contentEntry.crud.d.ts +0 -2
  19. package/crud/contentEntry.crud.js +201 -361
  20. package/crud/contentEntry.crud.js.map +1 -1
  21. package/crud/contentModel/afterCreate.d.ts +3 -3
  22. package/crud/contentModel/afterCreate.js +5 -7
  23. package/crud/contentModel/afterCreate.js.map +1 -1
  24. package/crud/contentModel/afterCreateFrom.d.ts +3 -3
  25. package/crud/contentModel/afterCreateFrom.js +5 -7
  26. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  27. package/crud/contentModel/afterDelete.d.ts +3 -3
  28. package/crud/contentModel/afterDelete.js +5 -7
  29. package/crud/contentModel/afterDelete.js.map +1 -1
  30. package/crud/contentModel/afterUpdate.d.ts +3 -3
  31. package/crud/contentModel/afterUpdate.js +5 -7
  32. package/crud/contentModel/afterUpdate.js.map +1 -1
  33. package/crud/contentModel/beforeCreate.d.ts +4 -4
  34. package/crud/contentModel/beforeCreate.js +14 -42
  35. package/crud/contentModel/beforeCreate.js.map +1 -1
  36. package/crud/contentModel/beforeDelete.d.ts +3 -3
  37. package/crud/contentModel/beforeDelete.js +6 -16
  38. package/crud/contentModel/beforeDelete.js.map +1 -1
  39. package/crud/contentModel/beforeUpdate.d.ts +3 -3
  40. package/crud/contentModel/beforeUpdate.js +5 -10
  41. package/crud/contentModel/beforeUpdate.js.map +1 -1
  42. package/crud/contentModel/contentModelManagerFactory.js +0 -7
  43. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  44. package/crud/contentModel/createFieldModels.js +0 -6
  45. package/crud/contentModel/createFieldModels.js.map +1 -1
  46. package/crud/contentModel/createFieldStorageId.js +0 -2
  47. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  48. package/crud/contentModel/fieldIdValidation.js +0 -5
  49. package/crud/contentModel/fieldIdValidation.js.map +1 -1
  50. package/crud/contentModel/idValidation.js +0 -5
  51. package/crud/contentModel/idValidation.js.map +1 -1
  52. package/crud/contentModel/models.js +1 -8
  53. package/crud/contentModel/models.js.map +1 -1
  54. package/crud/contentModel/systemFields.js.map +1 -1
  55. package/crud/contentModel/validateLayout.js +0 -8
  56. package/crud/contentModel/validateLayout.js.map +1 -1
  57. package/crud/contentModel/validateModel.js +1 -9
  58. package/crud/contentModel/validateModel.js.map +1 -1
  59. package/crud/contentModel/validateModelFields.js +11 -67
  60. package/crud/contentModel/validateModelFields.js.map +1 -1
  61. package/crud/contentModel.crud.js +84 -145
  62. package/crud/contentModel.crud.js.map +1 -1
  63. package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
  64. package/crud/contentModelGroup/beforeCreate.js +3 -15
  65. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  66. package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
  67. package/crud/contentModelGroup/beforeDelete.js +3 -11
  68. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  69. package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
  70. package/crud/contentModelGroup/beforeUpdate.js +2 -7
  71. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  72. package/crud/contentModelGroup.crud.js +59 -76
  73. package/crud/contentModelGroup.crud.js.map +1 -1
  74. package/crud/index.js +3 -23
  75. package/crud/index.js.map +1 -1
  76. package/crud/settings.crud.js +3 -20
  77. package/crud/settings.crud.js.map +1 -1
  78. package/crud/system.crud.js +61 -84
  79. package/crud/system.crud.js.map +1 -1
  80. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -14
  81. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  82. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +16 -71
  83. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  84. package/fieldConverters/index.js +0 -4
  85. package/fieldConverters/index.js.map +1 -1
  86. package/graphql/buildSchemaPlugins.js +5 -9
  87. package/graphql/buildSchemaPlugins.js.map +1 -1
  88. package/graphql/graphQLHandlerFactory.js +4 -29
  89. package/graphql/graphQLHandlerFactory.js.map +1 -1
  90. package/graphql/index.js +1 -8
  91. package/graphql/index.js.map +1 -1
  92. package/graphql/schema/baseContentSchema.js +6 -18
  93. package/graphql/schema/baseContentSchema.js.map +1 -1
  94. package/graphql/schema/contentEntries.js +3 -43
  95. package/graphql/schema/contentEntries.js.map +1 -1
  96. package/graphql/schema/contentModelGroups.js +2 -19
  97. package/graphql/schema/contentModelGroups.js.map +1 -1
  98. package/graphql/schema/contentModels.js +20 -17
  99. package/graphql/schema/contentModels.js.map +1 -1
  100. package/graphql/schema/createFieldResolvers.js +7 -31
  101. package/graphql/schema/createFieldResolvers.js.map +1 -1
  102. package/graphql/schema/createManageResolvers.js +4 -44
  103. package/graphql/schema/createManageResolvers.js.map +1 -1
  104. package/graphql/schema/createManageSDL.js +4 -21
  105. package/graphql/schema/createManageSDL.js.map +1 -1
  106. package/graphql/schema/createPreviewResolvers.js +3 -17
  107. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  108. package/graphql/schema/createReadResolvers.js +3 -17
  109. package/graphql/schema/createReadResolvers.js.map +1 -1
  110. package/graphql/schema/createReadSDL.js +0 -10
  111. package/graphql/schema/createReadSDL.js.map +1 -1
  112. package/graphql/schema/resolvers/commonFieldResolvers.js +0 -2
  113. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  114. package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
  115. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  116. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
  117. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  118. package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
  119. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  120. package/graphql/schema/resolvers/manage/resolveGet.js +5 -25
  121. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  122. package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
  123. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  124. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
  125. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  126. package/graphql/schema/resolvers/manage/resolveList.js +0 -3
  127. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  128. package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
  129. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  130. package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
  131. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  132. package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
  133. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  134. package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
  135. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  136. package/graphql/schema/resolvers/preview/resolveGet.js +3 -15
  137. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  138. package/graphql/schema/resolvers/preview/resolveList.js +0 -3
  139. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  140. package/graphql/schema/resolvers/read/resolveGet.js +3 -15
  141. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  142. package/graphql/schema/resolvers/read/resolveList.js +0 -3
  143. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  144. package/graphql/schema/schemaPlugins.js +5 -19
  145. package/graphql/schema/schemaPlugins.js.map +1 -1
  146. package/graphql/system.js +1 -14
  147. package/graphql/system.js.map +1 -1
  148. package/graphqlFields/boolean.js +0 -12
  149. package/graphqlFields/boolean.js.map +1 -1
  150. package/graphqlFields/datetime.js +0 -17
  151. package/graphqlFields/datetime.js.map +1 -1
  152. package/graphqlFields/file.js +0 -8
  153. package/graphqlFields/file.js.map +1 -1
  154. package/graphqlFields/helpers.js +0 -10
  155. package/graphqlFields/helpers.js.map +1 -1
  156. package/graphqlFields/index.js +0 -11
  157. package/graphqlFields/index.js.map +1 -1
  158. package/graphqlFields/longText.js +0 -10
  159. package/graphqlFields/longText.js.map +1 -1
  160. package/graphqlFields/number.js +0 -12
  161. package/graphqlFields/number.js.map +1 -1
  162. package/graphqlFields/object.js +7 -37
  163. package/graphqlFields/object.js.map +1 -1
  164. package/graphqlFields/ref.js +21 -59
  165. package/graphqlFields/ref.js.map +1 -1
  166. package/graphqlFields/richText.js +0 -9
  167. package/graphqlFields/richText.js.map +1 -1
  168. package/graphqlFields/text.js +0 -11
  169. package/graphqlFields/text.js.map +1 -1
  170. package/index.js +0 -19
  171. package/index.js.map +1 -1
  172. package/modelManager/DefaultCmsModelManager.d.ts +7 -7
  173. package/modelManager/DefaultCmsModelManager.js +1 -17
  174. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  175. package/modelManager/index.js +0 -4
  176. package/modelManager/index.js.map +1 -1
  177. package/package.json +27 -28
  178. package/parameters/context.js +0 -4
  179. package/parameters/context.js.map +1 -1
  180. package/parameters/header.js +1 -12
  181. package/parameters/header.js.map +1 -1
  182. package/parameters/index.js +0 -8
  183. package/parameters/index.js.map +1 -1
  184. package/parameters/manual.js +7 -15
  185. package/parameters/manual.js.map +1 -1
  186. package/parameters/path.js +1 -12
  187. package/parameters/path.js.map +1 -1
  188. package/plugins/CmsGroupPlugin.js +1 -9
  189. package/plugins/CmsGroupPlugin.js.map +1 -1
  190. package/plugins/CmsModelFieldConverterPlugin.js +1 -6
  191. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  192. package/plugins/CmsModelPlugin.d.ts +6 -2
  193. package/plugins/CmsModelPlugin.js +18 -49
  194. package/plugins/CmsModelPlugin.js.map +1 -1
  195. package/plugins/CmsParametersPlugin.js +1 -8
  196. package/plugins/CmsParametersPlugin.js.map +1 -1
  197. package/plugins/StorageTransformPlugin.js +1 -10
  198. package/plugins/StorageTransformPlugin.js.map +1 -1
  199. package/plugins/index.js +0 -10
  200. package/plugins/index.js.map +1 -1
  201. package/storage/default.js +0 -3
  202. package/storage/default.js.map +1 -1
  203. package/storage/object.js +3 -25
  204. package/storage/object.js.map +1 -1
  205. package/types.d.ts +267 -126
  206. package/types.js +0 -64
  207. package/types.js.map +1 -1
  208. package/upgrades/5.33.0/index.js +8 -35
  209. package/upgrades/5.33.0/index.js.map +1 -1
  210. package/upgrades/index.js +0 -3
  211. package/upgrades/index.js.map +1 -1
  212. package/utils/access.js +11 -25
  213. package/utils/access.js.map +1 -1
  214. package/utils/converters/Converter.js +1 -14
  215. package/utils/converters/Converter.js.map +1 -1
  216. package/utils/converters/ConverterCollection.d.ts +7 -0
  217. package/utils/converters/ConverterCollection.js +31 -30
  218. package/utils/converters/ConverterCollection.js.map +1 -1
  219. package/utils/converters/valueKeyStorageConverter.js +3 -33
  220. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  221. package/utils/createTypeName.js +1 -9
  222. package/utils/createTypeName.js.map +1 -1
  223. package/utils/entryStorage.js +13 -33
  224. package/utils/entryStorage.js.map +1 -1
  225. package/utils/filterAsync.js +0 -5
  226. package/utils/filterAsync.js.map +1 -1
  227. package/utils/filterModelFields.js +8 -18
  228. package/utils/filterModelFields.js.map +1 -1
  229. package/utils/getEntryTitle.js +0 -9
  230. package/utils/getEntryTitle.js.map +1 -1
  231. package/utils/getSchemaFromFieldPlugins.js +2 -6
  232. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  233. package/utils/ownership.js +0 -8
  234. package/utils/ownership.js.map +1 -1
  235. package/utils/permissions.js +7 -26
  236. package/utils/permissions.js.map +1 -1
  237. package/utils/pluralizedTypeName.js +1 -7
  238. package/utils/pluralizedTypeName.js.map +1 -1
  239. package/utils/renderFields.js +0 -8
  240. package/utils/renderFields.js.map +1 -1
  241. package/utils/renderGetFilterFields.js +0 -11
  242. package/utils/renderGetFilterFields.js.map +1 -1
  243. package/utils/renderInputFields.js +0 -8
  244. package/utils/renderInputFields.js.map +1 -1
  245. package/utils/renderListFilterFields.js +7 -8
  246. package/utils/renderListFilterFields.js.map +1 -1
  247. package/utils/renderSortEnum.js +0 -7
  248. package/utils/renderSortEnum.js.map +1 -1
  249. package/utils/toSlug.js +1 -5
  250. package/utils/toSlug.js.map +1 -1
  251. package/validators/dateGte.js +0 -7
  252. package/validators/dateGte.js.map +1 -1
  253. package/validators/dateLte.js +0 -7
  254. package/validators/dateLte.js.map +1 -1
  255. package/validators/gte.js +0 -8
  256. package/validators/gte.js.map +1 -1
  257. package/validators/in.js +0 -8
  258. package/validators/in.js.map +1 -1
  259. package/validators/index.js +0 -15
  260. package/validators/index.js.map +1 -1
  261. package/validators/lte.js +0 -8
  262. package/validators/lte.js.map +1 -1
  263. package/validators/maxLength.js +0 -8
  264. package/validators/maxLength.js.map +1 -1
  265. package/validators/minLength.js +0 -8
  266. package/validators/minLength.js.map +1 -1
  267. package/validators/pattern.js +0 -9
  268. package/validators/pattern.js.map +1 -1
  269. package/validators/patternPlugins/email.js +0 -2
  270. package/validators/patternPlugins/email.js.map +1 -1
  271. package/validators/patternPlugins/index.js +0 -8
  272. package/validators/patternPlugins/index.js.map +1 -1
  273. package/validators/patternPlugins/lowerCase.js +0 -2
  274. package/validators/patternPlugins/lowerCase.js.map +1 -1
  275. package/validators/patternPlugins/lowerCaseSpace.js +0 -2
  276. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  277. package/validators/patternPlugins/upperCase.js +0 -2
  278. package/validators/patternPlugins/upperCase.js.map +1 -1
  279. package/validators/patternPlugins/upperCaseSpace.js +0 -2
  280. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  281. package/validators/patternPlugins/url.js +0 -2
  282. package/validators/patternPlugins/url.js.map +1 -1
  283. package/validators/required.js +0 -5
  284. package/validators/required.js.map +1 -1
  285. package/validators/timeGte.js +0 -8
  286. package/validators/timeGte.js.map +1 -1
  287. package/validators/timeLte.js +0 -8
  288. package/validators/timeLte.js.map +1 -1
  289. package/validators/unique.js +1 -8
  290. package/validators/unique.js.map +1 -1
package/context.js CHANGED
@@ -1,56 +1,38 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createContextPlugin = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _api = require("@webiny/api");
15
-
16
11
  var _CmsParametersPlugin = require("./plugins/CmsParametersPlugin");
17
-
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
-
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
-
22
12
  const getParameters = async context => {
23
13
  const plugins = context.plugins.byType(_CmsParametersPlugin.CmsParametersPlugin.type);
24
-
25
14
  for (const plugin of plugins) {
26
15
  const result = await plugin.getParameters(context);
27
-
28
16
  if (result !== null) {
29
17
  return result;
30
18
  }
31
19
  }
32
-
33
20
  throw new _error.default("Could not determine locale and/or type of the CMS.", "CMS_LOCALE_AND_TYPE_ERROR");
34
21
  };
35
-
36
22
  const createContextPlugin = () => {
37
23
  return new _api.ContextPlugin(async context => {
38
24
  const {
39
25
  type,
40
26
  locale
41
27
  } = await getParameters(context);
42
-
43
28
  const getLocale = () => {
44
29
  const systemLocale = context.i18n.getLocale(locale);
45
-
46
30
  if (!systemLocale) {
47
31
  throw new _error.default(`There is no locale "${locale}" in the system.`);
48
32
  }
49
-
50
33
  return systemLocale;
51
34
  };
52
-
53
- context.cms = _objectSpread(_objectSpread({}, context.cms || {}), {}, {
35
+ context.cms = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, context.cms || {}), {}, {
54
36
  type,
55
37
  locale,
56
38
  getLocale,
@@ -60,5 +42,4 @@ const createContextPlugin = () => {
60
42
  });
61
43
  });
62
44
  };
63
-
64
45
  exports.createContextPlugin = createContextPlugin;
package/context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["getParameters","context","plugins","byType","CmsParametersPlugin","type","plugin","result","WebinyError","createContextPlugin","ContextPlugin","locale","getLocale","systemLocale","i18n","cms","READ","PREVIEW","MANAGE"],"sources":["context.ts"],"sourcesContent":["import { CmsContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { CmsParametersPlugin, CmsParametersPluginResponse } from \"./plugins/CmsParametersPlugin\";\n\nconst getParameters = async (context: CmsContext): Promise<CmsParametersPluginResponse> => {\n const plugins = context.plugins.byType<CmsParametersPlugin>(CmsParametersPlugin.type);\n\n for (const plugin of plugins) {\n const result = await plugin.getParameters(context);\n if (result !== null) {\n return result;\n }\n }\n throw new WebinyError(\n \"Could not determine locale and/or type of the CMS.\",\n \"CMS_LOCALE_AND_TYPE_ERROR\"\n );\n};\n\nexport const createContextPlugin = () => {\n return new ContextPlugin<CmsContext>(async context => {\n const { type, locale } = await getParameters(context);\n\n const getLocale = () => {\n const systemLocale = context.i18n.getLocale(locale);\n if (!systemLocale) {\n throw new WebinyError(`There is no locale \"${locale}\" in the system.`);\n }\n return systemLocale;\n };\n\n context.cms = {\n ...(context.cms || {}),\n type,\n locale,\n getLocale,\n READ: type === \"read\",\n PREVIEW: type === \"preview\",\n MANAGE: type === \"manage\"\n };\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,aAAa,GAAG,MAAOC,OAAP,IAAqE;EACvF,MAAMC,OAAO,GAAGD,OAAO,CAACC,OAAR,CAAgBC,MAAhB,CAA4CC,wCAAA,CAAoBC,IAAhE,CAAhB;;EAEA,KAAK,MAAMC,MAAX,IAAqBJ,OAArB,EAA8B;IAC1B,MAAMK,MAAM,GAAG,MAAMD,MAAM,CAACN,aAAP,CAAqBC,OAArB,CAArB;;IACA,IAAIM,MAAM,KAAK,IAAf,EAAqB;MACjB,OAAOA,MAAP;IACH;EACJ;;EACD,MAAM,IAAIC,cAAJ,CACF,oDADE,EAEF,2BAFE,CAAN;AAIH,CAbD;;AAeO,MAAMC,mBAAmB,GAAG,MAAM;EACrC,OAAO,IAAIC,kBAAJ,CAA8B,MAAMT,OAAN,IAAiB;IAClD,MAAM;MAAEI,IAAF;MAAQM;IAAR,IAAmB,MAAMX,aAAa,CAACC,OAAD,CAA5C;;IAEA,MAAMW,SAAS,GAAG,MAAM;MACpB,MAAMC,YAAY,GAAGZ,OAAO,CAACa,IAAR,CAAaF,SAAb,CAAuBD,MAAvB,CAArB;;MACA,IAAI,CAACE,YAAL,EAAmB;QACf,MAAM,IAAIL,cAAJ,CAAiB,uBAAsBG,MAAO,kBAA9C,CAAN;MACH;;MACD,OAAOE,YAAP;IACH,CAND;;IAQAZ,OAAO,CAACc,GAAR,mCACQd,OAAO,CAACc,GAAR,IAAe,EADvB;MAEIV,IAFJ;MAGIM,MAHJ;MAIIC,SAJJ;MAKII,IAAI,EAAEX,IAAI,KAAK,MALnB;MAMIY,OAAO,EAAEZ,IAAI,KAAK,SANtB;MAOIa,MAAM,EAAEb,IAAI,KAAK;IAPrB;EASH,CApBM,CAAP;AAqBH,CAtBM"}
1
+ {"version":3,"names":["getParameters","context","plugins","byType","CmsParametersPlugin","type","plugin","result","WebinyError","createContextPlugin","ContextPlugin","locale","getLocale","systemLocale","i18n","cms","READ","PREVIEW","MANAGE"],"sources":["context.ts"],"sourcesContent":["import { CmsContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { CmsParametersPlugin, CmsParametersPluginResponse } from \"./plugins/CmsParametersPlugin\";\n\nconst getParameters = async (context: CmsContext): Promise<CmsParametersPluginResponse> => {\n const plugins = context.plugins.byType<CmsParametersPlugin>(CmsParametersPlugin.type);\n\n for (const plugin of plugins) {\n const result = await plugin.getParameters(context);\n if (result !== null) {\n return result;\n }\n }\n throw new WebinyError(\n \"Could not determine locale and/or type of the CMS.\",\n \"CMS_LOCALE_AND_TYPE_ERROR\"\n );\n};\n\nexport const createContextPlugin = () => {\n return new ContextPlugin<CmsContext>(async context => {\n const { type, locale } = await getParameters(context);\n\n const getLocale = () => {\n const systemLocale = context.i18n.getLocale(locale);\n if (!systemLocale) {\n throw new WebinyError(`There is no locale \"${locale}\" in the system.`);\n }\n return systemLocale;\n };\n\n context.cms = {\n ...(context.cms || {}),\n type,\n locale,\n getLocale,\n READ: type === \"read\",\n PREVIEW: type === \"preview\",\n MANAGE: type === \"manage\"\n };\n });\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AAEA,MAAMA,aAAa,GAAG,MAAOC,OAAmB,IAA2C;EACvF,MAAMC,OAAO,GAAGD,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsBC,wCAAmB,CAACC,IAAI,CAAC;EAErF,KAAK,MAAMC,MAAM,IAAIJ,OAAO,EAAE;IAC1B,MAAMK,MAAM,GAAG,MAAMD,MAAM,CAACN,aAAa,CAACC,OAAO,CAAC;IAClD,IAAIM,MAAM,KAAK,IAAI,EAAE;MACjB,OAAOA,MAAM;IACjB;EACJ;EACA,MAAM,IAAIC,cAAW,CACjB,oDAAoD,EACpD,2BAA2B,CAC9B;AACL,CAAC;AAEM,MAAMC,mBAAmB,GAAG,MAAM;EACrC,OAAO,IAAIC,kBAAa,CAAa,MAAMT,OAAO,IAAI;IAClD,MAAM;MAAEI,IAAI;MAAEM;IAAO,CAAC,GAAG,MAAMX,aAAa,CAACC,OAAO,CAAC;IAErD,MAAMW,SAAS,GAAG,MAAM;MACpB,MAAMC,YAAY,GAAGZ,OAAO,CAACa,IAAI,CAACF,SAAS,CAACD,MAAM,CAAC;MACnD,IAAI,CAACE,YAAY,EAAE;QACf,MAAM,IAAIL,cAAW,CAAE,uBAAsBG,MAAO,kBAAiB,CAAC;MAC1E;MACA,OAAOE,YAAY;IACvB,CAAC;IAEDZ,OAAO,CAACc,GAAG,+DACHd,OAAO,CAACc,GAAG,IAAI,CAAC,CAAC;MACrBV,IAAI;MACJM,MAAM;MACNC,SAAS;MACTI,IAAI,EAAEX,IAAI,KAAK,MAAM;MACrBY,OAAO,EAAEZ,IAAI,KAAK,SAAS;MAC3Ba,MAAM,EAAEb,IAAI,KAAK;IAAQ,EAC5B;EACL,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1,8 +1,8 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { AfterEntryDeleteTopicParams, CmsContext } from "../../types";
2
+ import { OnEntryAfterDeleteTopicParams, CmsContext } from "../../types";
3
3
  interface AssignAfterEntryDeleteParams {
4
4
  context: CmsContext;
5
- onAfterEntryDelete: Topic<AfterEntryDeleteTopicParams>;
5
+ onEntryAfterDelete: Topic<OnEntryAfterDeleteTopicParams>;
6
6
  }
7
7
  export declare const assignAfterEntryDelete: (params: AssignAfterEntryDeleteParams) => void;
8
8
  export {};
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignAfterEntryDelete = void 0;
7
-
8
7
  var _markLockedFields = require("./markLockedFields");
9
-
10
8
  const assignAfterEntryDelete = params => {
11
9
  const {
12
10
  context,
13
- onAfterEntryDelete
11
+ onEntryAfterDelete
14
12
  } = params;
15
- onAfterEntryDelete.subscribe(async params => {
13
+ onEntryAfterDelete.subscribe(async params => {
16
14
  const {
17
15
  entry,
18
16
  model
@@ -26,16 +24,13 @@ const assignAfterEntryDelete = params => {
26
24
  },
27
25
  limit: 1
28
26
  });
29
-
30
27
  if (items.length > 0) {
31
28
  return;
32
29
  }
33
-
34
30
  await (0, _markLockedFields.markUnlockedFields)({
35
31
  context,
36
32
  model
37
33
  });
38
34
  });
39
35
  };
40
-
41
36
  exports.assignAfterEntryDelete = assignAfterEntryDelete;
@@ -1 +1 @@
1
- {"version":3,"names":["assignAfterEntryDelete","params","context","onAfterEntryDelete","subscribe","entry","model","items","cms","storageOperations","entries","list","where","entryId_not","entryId","latest","limit","length","markUnlockedFields"],"sources":["afterDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { AfterEntryDeleteTopicParams, CmsContext } from \"~/types\";\nimport { markUnlockedFields } from \"./markLockedFields\";\n\ninterface AssignAfterEntryDeleteParams {\n context: CmsContext;\n onAfterEntryDelete: Topic<AfterEntryDeleteTopicParams>;\n}\nexport const assignAfterEntryDelete = (params: AssignAfterEntryDeleteParams) => {\n const { context, onAfterEntryDelete } = params;\n\n onAfterEntryDelete.subscribe(async params => {\n const { entry, model } = params;\n\n const { items } = await context.cms.storageOperations.entries.list(model, {\n where: {\n entryId_not: entry.entryId,\n latest: true\n },\n limit: 1\n });\n if (items.length > 0) {\n return;\n }\n await markUnlockedFields({\n context,\n model\n });\n });\n};\n"],"mappings":";;;;;;;AAEA;;AAMO,MAAMA,sBAAsB,GAAIC,MAAD,IAA0C;EAC5E,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAkCF,MAAxC;EAEAE,kBAAkB,CAACC,SAAnB,CAA6B,MAAMH,MAAN,IAAgB;IACzC,MAAM;MAAEI,KAAF;MAASC;IAAT,IAAmBL,MAAzB;IAEA,MAAM;MAAEM;IAAF,IAAY,MAAML,OAAO,CAACM,GAAR,CAAYC,iBAAZ,CAA8BC,OAA9B,CAAsCC,IAAtC,CAA2CL,KAA3C,EAAkD;MACtEM,KAAK,EAAE;QACHC,WAAW,EAAER,KAAK,CAACS,OADhB;QAEHC,MAAM,EAAE;MAFL,CAD+D;MAKtEC,KAAK,EAAE;IAL+D,CAAlD,CAAxB;;IAOA,IAAIT,KAAK,CAACU,MAAN,GAAe,CAAnB,EAAsB;MAClB;IACH;;IACD,MAAM,IAAAC,oCAAA,EAAmB;MACrBhB,OADqB;MAErBI;IAFqB,CAAnB,CAAN;EAIH,CAjBD;AAkBH,CArBM"}
1
+ {"version":3,"names":["assignAfterEntryDelete","params","context","onEntryAfterDelete","subscribe","entry","model","items","cms","storageOperations","entries","list","where","entryId_not","entryId","latest","limit","length","markUnlockedFields"],"sources":["afterDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnEntryAfterDeleteTopicParams, CmsContext } from \"~/types\";\nimport { markUnlockedFields } from \"./markLockedFields\";\n\ninterface AssignAfterEntryDeleteParams {\n context: CmsContext;\n onEntryAfterDelete: Topic<OnEntryAfterDeleteTopicParams>;\n}\nexport const assignAfterEntryDelete = (params: AssignAfterEntryDeleteParams) => {\n const { context, onEntryAfterDelete } = params;\n\n onEntryAfterDelete.subscribe(async params => {\n const { entry, model } = params;\n\n const { items } = await context.cms.storageOperations.entries.list(model, {\n where: {\n entryId_not: entry.entryId,\n latest: true\n },\n limit: 1\n });\n if (items.length > 0) {\n return;\n }\n await markUnlockedFields({\n context,\n model\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AAMO,MAAMA,sBAAsB,GAAIC,MAAoC,IAAK;EAC5E,MAAM;IAAEC,OAAO;IAAEC;EAAmB,CAAC,GAAGF,MAAM;EAE9CE,kBAAkB,CAACC,SAAS,CAAC,MAAMH,MAAM,IAAI;IACzC,MAAM;MAAEI,KAAK;MAAEC;IAAM,CAAC,GAAGL,MAAM;IAE/B,MAAM;MAAEM;IAAM,CAAC,GAAG,MAAML,OAAO,CAACM,GAAG,CAACC,iBAAiB,CAACC,OAAO,CAACC,IAAI,CAACL,KAAK,EAAE;MACtEM,KAAK,EAAE;QACHC,WAAW,EAAER,KAAK,CAACS,OAAO;QAC1BC,MAAM,EAAE;MACZ,CAAC;MACDC,KAAK,EAAE;IACX,CAAC,CAAC;IACF,IAAIT,KAAK,CAACU,MAAM,GAAG,CAAC,EAAE;MAClB;IACJ;IACA,MAAM,IAAAC,oCAAkB,EAAC;MACrBhB,OAAO;MACPI;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1,8 +1,8 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { BeforeEntryCreateTopicParams, CmsContext } from "../../types";
2
+ import { OnEntryBeforeCreateTopicParams, CmsContext } from "../../types";
3
3
  interface AssignBeforeEntryCreateParams {
4
4
  context: CmsContext;
5
- onBeforeEntryCreate: Topic<BeforeEntryCreateTopicParams>;
5
+ onEntryBeforeCreate: Topic<OnEntryBeforeCreateTopicParams>;
6
6
  }
7
7
  export declare const assignBeforeEntryCreate: (params: AssignBeforeEntryCreateParams) => void;
8
8
  export {};
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignBeforeEntryCreate = void 0;
7
-
8
7
  var _markLockedFields = require("./markLockedFields");
9
-
10
8
  const assignBeforeEntryCreate = params => {
11
9
  const {
12
10
  context,
13
- onBeforeEntryCreate
11
+ onEntryBeforeCreate
14
12
  } = params;
15
- onBeforeEntryCreate.subscribe(async params => {
13
+ onEntryBeforeCreate.subscribe(async params => {
16
14
  const {
17
15
  entry,
18
16
  model
@@ -24,5 +22,4 @@ const assignBeforeEntryCreate = params => {
24
22
  });
25
23
  });
26
24
  };
27
-
28
25
  exports.assignBeforeEntryCreate = assignBeforeEntryCreate;
@@ -1 +1 @@
1
- {"version":3,"names":["assignBeforeEntryCreate","params","context","onBeforeEntryCreate","subscribe","entry","model","markLockedFields"],"sources":["beforeCreate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { BeforeEntryCreateTopicParams, CmsContext } from \"~/types\";\nimport { markLockedFields } from \"./markLockedFields\";\n\ninterface AssignBeforeEntryCreateParams {\n context: CmsContext;\n onBeforeEntryCreate: Topic<BeforeEntryCreateTopicParams>;\n}\nexport const assignBeforeEntryCreate = (params: AssignBeforeEntryCreateParams) => {\n const { context, onBeforeEntryCreate } = params;\n\n onBeforeEntryCreate.subscribe(async params => {\n const { entry, model } = params;\n\n await markLockedFields({\n model,\n entry,\n context\n });\n });\n};\n"],"mappings":";;;;;;;AAEA;;AAMO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAmCF,MAAzC;EAEAE,mBAAmB,CAACC,SAApB,CAA8B,MAAMH,MAAN,IAAgB;IAC1C,MAAM;MAAEI,KAAF;MAASC;IAAT,IAAmBL,MAAzB;IAEA,MAAM,IAAAM,kCAAA,EAAiB;MACnBD,KADmB;MAEnBD,KAFmB;MAGnBH;IAHmB,CAAjB,CAAN;EAKH,CARD;AASH,CAZM"}
1
+ {"version":3,"names":["assignBeforeEntryCreate","params","context","onEntryBeforeCreate","subscribe","entry","model","markLockedFields"],"sources":["beforeCreate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnEntryBeforeCreateTopicParams, CmsContext } from \"~/types\";\nimport { markLockedFields } from \"./markLockedFields\";\n\ninterface AssignBeforeEntryCreateParams {\n context: CmsContext;\n onEntryBeforeCreate: Topic<OnEntryBeforeCreateTopicParams>;\n}\nexport const assignBeforeEntryCreate = (params: AssignBeforeEntryCreateParams) => {\n const { context, onEntryBeforeCreate } = params;\n\n onEntryBeforeCreate.subscribe(async params => {\n const { entry, model } = params;\n\n await markLockedFields({\n model,\n entry,\n context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AAMO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,OAAO;IAAEC;EAAoB,CAAC,GAAGF,MAAM;EAE/CE,mBAAmB,CAACC,SAAS,CAAC,MAAMH,MAAM,IAAI;IAC1C,MAAM;MAAEI,KAAK;MAAEC;IAAM,CAAC,GAAGL,MAAM;IAE/B,MAAM,IAAAM,kCAAgB,EAAC;MACnBD,KAAK;MACLD,KAAK;MACLH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1,8 +1,8 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { BeforeEntryUpdateTopicParams, CmsContext } from "../../types";
2
+ import { OnEntryBeforeUpdateTopicParams, CmsContext } from "../../types";
3
3
  interface AssignBeforeEntryUpdateParams {
4
4
  context: CmsContext;
5
- onBeforeEntryUpdate: Topic<BeforeEntryUpdateTopicParams>;
5
+ onEntryBeforeUpdate: Topic<OnEntryBeforeUpdateTopicParams>;
6
6
  }
7
7
  export declare const assignBeforeEntryUpdate: (params: AssignBeforeEntryUpdateParams) => void;
8
8
  export {};
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignBeforeEntryUpdate = void 0;
7
-
8
7
  var _markLockedFields = require("./markLockedFields");
9
-
10
8
  const assignBeforeEntryUpdate = params => {
11
9
  const {
12
10
  context,
13
- onBeforeEntryUpdate
11
+ onEntryBeforeUpdate
14
12
  } = params;
15
- onBeforeEntryUpdate.subscribe(async params => {
13
+ onEntryBeforeUpdate.subscribe(async params => {
16
14
  const {
17
15
  entry,
18
16
  model
@@ -24,5 +22,4 @@ const assignBeforeEntryUpdate = params => {
24
22
  });
25
23
  });
26
24
  };
27
-
28
25
  exports.assignBeforeEntryUpdate = assignBeforeEntryUpdate;
@@ -1 +1 @@
1
- {"version":3,"names":["assignBeforeEntryUpdate","params","context","onBeforeEntryUpdate","subscribe","entry","model","markLockedFields"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { BeforeEntryUpdateTopicParams, CmsContext } from \"~/types\";\nimport { markLockedFields } from \"./markLockedFields\";\n\ninterface AssignBeforeEntryUpdateParams {\n context: CmsContext;\n onBeforeEntryUpdate: Topic<BeforeEntryUpdateTopicParams>;\n}\nexport const assignBeforeEntryUpdate = (params: AssignBeforeEntryUpdateParams) => {\n const { context, onBeforeEntryUpdate } = params;\n\n onBeforeEntryUpdate.subscribe(async params => {\n const { entry, model } = params;\n\n await markLockedFields({\n model,\n entry,\n context\n });\n });\n};\n"],"mappings":";;;;;;;AAEA;;AAMO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAmCF,MAAzC;EAEAE,mBAAmB,CAACC,SAApB,CAA8B,MAAMH,MAAN,IAAgB;IAC1C,MAAM;MAAEI,KAAF;MAASC;IAAT,IAAmBL,MAAzB;IAEA,MAAM,IAAAM,kCAAA,EAAiB;MACnBD,KADmB;MAEnBD,KAFmB;MAGnBH;IAHmB,CAAjB,CAAN;EAKH,CARD;AASH,CAZM"}
1
+ {"version":3,"names":["assignBeforeEntryUpdate","params","context","onEntryBeforeUpdate","subscribe","entry","model","markLockedFields"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnEntryBeforeUpdateTopicParams, CmsContext } from \"~/types\";\nimport { markLockedFields } from \"./markLockedFields\";\n\ninterface AssignBeforeEntryUpdateParams {\n context: CmsContext;\n onEntryBeforeUpdate: Topic<OnEntryBeforeUpdateTopicParams>;\n}\nexport const assignBeforeEntryUpdate = (params: AssignBeforeEntryUpdateParams) => {\n const { context, onEntryBeforeUpdate } = params;\n\n onEntryBeforeUpdate.subscribe(async params => {\n const { entry, model } = params;\n\n await markLockedFields({\n model,\n entry,\n context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AAMO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,OAAO;IAAEC;EAAoB,CAAC,GAAGF,MAAM;EAE/CE,mBAAmB,CAACC,SAAS,CAAC,MAAMH,MAAM,IAAI;IAC1C,MAAM;MAAEI,KAAK;MAAEC;IAAM,CAAC,GAAGL,MAAM;IAE/B,MAAM,IAAAM,kCAAgB,EAAC;MACnBD,KAAK;MACLD,KAAK;MACLH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1,25 +1,16 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.validateModelEntryData = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
-
18
10
  const validateValue = async (args, fieldValidators, value) => {
19
11
  if (!fieldValidators) {
20
12
  return null;
21
13
  }
22
-
23
14
  const {
24
15
  validatorList,
25
16
  context,
@@ -27,16 +18,13 @@ const validateValue = async (args, fieldValidators, value) => {
27
18
  model,
28
19
  entry
29
20
  } = args;
30
-
31
21
  try {
32
22
  for (const fieldValidator of fieldValidators) {
33
23
  const name = fieldValidator.name;
34
24
  const validations = validatorList[name];
35
-
36
25
  if (!validations || validations.length === 0) {
37
26
  return `There are no "${name}" validators defined.`;
38
27
  }
39
-
40
28
  for (const validate of validations) {
41
29
  const result = await validate({
42
30
  value,
@@ -46,7 +34,6 @@ const validateValue = async (args, fieldValidators, value) => {
46
34
  model,
47
35
  entry
48
36
  });
49
-
50
37
  if (!result) {
51
38
  return fieldValidator.message;
52
39
  }
@@ -55,74 +42,57 @@ const validateValue = async (args, fieldValidators, value) => {
55
42
  } catch (ex) {
56
43
  return ex.message;
57
44
  }
58
-
59
45
  return null;
60
46
  };
61
-
62
47
  const validatePredefinedValue = (field, value) => {
63
48
  const {
64
49
  enabled = false,
65
50
  values: predefinedValues = []
66
51
  } = field.predefinedValues || {};
67
-
68
52
  if (!enabled) {
69
53
  return null;
70
54
  } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {
71
55
  return "Missing predefined values to validate against.";
72
56
  }
73
-
74
57
  for (const predefinedValue of predefinedValues) {
75
58
  if (predefinedValue.value == value) {
76
59
  return null;
77
60
  }
78
61
  }
79
-
80
62
  return "Value sent does not match any of the available predefined values.";
81
63
  };
82
64
  /**
83
65
  * When multiple values is selected we must run validations on the array containing the values
84
66
  * And then on each value in the array
85
67
  */
86
-
87
-
88
68
  const runFieldMultipleValuesValidations = async args => {
89
69
  const {
90
70
  field,
91
71
  data
92
72
  } = args;
93
73
  const values = data[field.fieldId] || [];
94
-
95
74
  if (Array.isArray(values) === false) {
96
75
  return `Value of the field "${field.fieldId}" is not an array.`;
97
76
  }
98
-
99
77
  const valuesError = await validateValue(args, field.listValidation || [], values);
100
-
101
78
  if (valuesError) {
102
79
  return valuesError;
103
80
  }
104
-
105
81
  for (const value of values) {
106
82
  const valueError = await validateValue(args, field.validation || [], value);
107
-
108
83
  if (valueError) {
109
84
  return valueError;
110
85
  }
111
-
112
86
  const predefinedValueError = validatePredefinedValue(field, value);
113
-
114
87
  if (predefinedValueError) {
115
88
  return predefinedValueError;
116
89
  }
117
90
  }
118
-
119
91
  return null;
120
92
  };
121
93
  /**
122
94
  * Runs validation on given value.
123
95
  */
124
-
125
-
126
96
  const runFieldValueValidations = async args => {
127
97
  const {
128
98
  data,
@@ -130,22 +100,17 @@ const runFieldValueValidations = async args => {
130
100
  } = args;
131
101
  const value = data[field.fieldId];
132
102
  const error = await validateValue(args, field.validation || [], value);
133
-
134
103
  if (error) {
135
104
  return error;
136
105
  }
137
-
138
106
  return validatePredefinedValue(field, value);
139
107
  };
140
-
141
108
  const execValidation = async args => {
142
109
  if (args.field.multipleValues) {
143
110
  return await runFieldMultipleValuesValidations(args);
144
111
  }
145
-
146
112
  return await runFieldValueValidations(args);
147
113
  };
148
-
149
114
  const validateModelEntryData = async params => {
150
115
  const {
151
116
  context,
@@ -157,48 +122,40 @@ const validateModelEntryData = async params => {
157
122
  * To later simplify searching for the validations we map them to a name.
158
123
  * @see CmsModelFieldValidatorPlugin.validator.validate
159
124
  */
160
-
161
125
  const validatorList = context.plugins.byType("cms-model-field-validator").reduce((acc, plugin) => {
162
126
  const name = plugin.validator.name;
163
-
164
127
  if (!acc[name]) {
165
128
  acc[name] = [];
166
129
  }
167
-
168
130
  acc[name].push(plugin.validator.validate);
169
131
  return acc;
170
132
  }, {});
133
+
171
134
  /**
172
135
  * Loop through model fields and validate the corresponding data.
173
136
  * Run validation only if the field has validation configured.
174
137
  */
175
-
176
138
  const invalidFields = [];
177
-
178
139
  for (const field of model.fields) {
179
140
  const error = await execValidation({
180
141
  model,
181
142
  validatorList,
182
143
  field,
183
- data: _objectSpread(_objectSpread({}, (entry === null || entry === void 0 ? void 0 : entry.values) || {}), data),
144
+ data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (entry === null || entry === void 0 ? void 0 : entry.values) || {}), data),
184
145
  context,
185
146
  entry
186
147
  });
187
-
188
148
  if (!error) {
189
149
  continue;
190
150
  }
191
-
192
151
  invalidFields.push({
193
152
  fieldId: field.fieldId,
194
153
  storageId: field.storageId,
195
154
  error
196
155
  });
197
156
  }
198
-
199
157
  if (invalidFields.length > 0) {
200
158
  throw new _error.default("Validation failed.", "VALIDATION_FAILED", invalidFields);
201
159
  }
202
160
  };
203
-
204
161
  exports.validateModelEntryData = validateModelEntryData;
@@ -1 +1 @@
1
- {"version":3,"names":["validateValue","args","fieldValidators","value","validatorList","context","field","model","entry","fieldValidator","name","validations","length","validate","result","validator","message","ex","validatePredefinedValue","enabled","values","predefinedValues","Array","isArray","predefinedValue","runFieldMultipleValuesValidations","data","fieldId","valuesError","listValidation","valueError","validation","predefinedValueError","runFieldValueValidations","error","execValidation","multipleValues","validateModelEntryData","params","plugins","byType","reduce","acc","plugin","push","invalidFields","fields","storageId","WebinyError"],"sources":["entryDataValidation.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelField,\n CmsModelFieldValidation,\n CmsContext,\n CmsModelFieldValidatorPlugin,\n CmsModelFieldValidatorValidateParams,\n CmsEntry\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\n\ntype PluginValidationCallable = (params: CmsModelFieldValidatorValidateParams) => Promise<boolean>;\ntype PluginValidationList = Record<string, PluginValidationCallable[]>;\ntype InputData = Record<string, any>;\n\ninterface ValidateArgs {\n validatorList: PluginValidationList;\n field: CmsModelField;\n model: CmsModel;\n data: InputData;\n context: CmsContext;\n entry?: CmsEntry;\n}\n\ntype PossibleValue = boolean | number | string | null | undefined;\n\nconst validateValue = async (\n args: ValidateArgs,\n fieldValidators: CmsModelFieldValidation[],\n value: PossibleValue | PossibleValue[]\n): Promise<string | null> => {\n if (!fieldValidators) {\n return null;\n }\n\n const { validatorList, context, field, model, entry } = args;\n try {\n for (const fieldValidator of fieldValidators) {\n const name = fieldValidator.name;\n const validations = validatorList[name];\n if (!validations || validations.length === 0) {\n return `There are no \"${name}\" validators defined.`;\n }\n for (const validate of validations) {\n const result = await validate({\n value,\n context,\n validator: fieldValidator,\n field,\n model,\n entry\n });\n if (!result) {\n return fieldValidator.message;\n }\n }\n }\n } catch (ex) {\n return ex.message;\n }\n\n return null;\n};\n\nconst validatePredefinedValue = (field: CmsModelField, value: any | any[]): string | null => {\n const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};\n if (!enabled) {\n return null;\n } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {\n return \"Missing predefined values to validate against.\";\n }\n for (const predefinedValue of predefinedValues) {\n if (predefinedValue.value == value) {\n return null;\n }\n }\n return \"Value sent does not match any of the available predefined values.\";\n};\n/**\n * When multiple values is selected we must run validations on the array containing the values\n * And then on each value in the array\n */\nconst runFieldMultipleValuesValidations = async (args: ValidateArgs): Promise<string | null> => {\n const { field, data } = args;\n const values = data[field.fieldId] || [];\n if (Array.isArray(values) === false) {\n return `Value of the field \"${field.fieldId}\" is not an array.`;\n }\n const valuesError = await validateValue(args, field.listValidation || [], values);\n if (valuesError) {\n return valuesError;\n }\n for (const value of values) {\n const valueError = await validateValue(args, field.validation || [], value);\n if (valueError) {\n return valueError;\n }\n const predefinedValueError = validatePredefinedValue(field, value);\n if (predefinedValueError) {\n return predefinedValueError;\n }\n }\n return null;\n};\n/**\n * Runs validation on given value.\n */\nconst runFieldValueValidations = async (args: ValidateArgs): Promise<string | null> => {\n const { data, field } = args;\n const value = data[field.fieldId];\n const error = await validateValue(args, field.validation || [], value);\n if (error) {\n return error;\n }\n return validatePredefinedValue(field, value);\n};\n\nconst execValidation = async (args: ValidateArgs): Promise<string | null> => {\n if (args.field.multipleValues) {\n return await runFieldMultipleValuesValidations(args);\n }\n return await runFieldValueValidations(args);\n};\n\nexport interface ValidateModelEntryDataParams {\n context: CmsContext;\n model: CmsModel;\n data: InputData;\n entry?: CmsEntry;\n}\nexport const validateModelEntryData = async (params: ValidateModelEntryDataParams) => {\n const { context, model, entry, data } = params;\n /**\n * To later simplify searching for the validations we map them to a name.\n * @see CmsModelFieldValidatorPlugin.validator.validate\n */\n const validatorList: PluginValidationList = context.plugins\n .byType<CmsModelFieldValidatorPlugin>(\"cms-model-field-validator\")\n .reduce((acc, plugin) => {\n const name = plugin.validator.name;\n if (!acc[name]) {\n acc[name] = [];\n }\n acc[name].push(plugin.validator.validate);\n\n return acc;\n }, {} as PluginValidationList);\n\n /**\n * Loop through model fields and validate the corresponding data.\n * Run validation only if the field has validation configured.\n */\n const invalidFields = [];\n for (const field of model.fields) {\n const error = await execValidation({\n model,\n validatorList,\n field,\n data: {\n ...(entry?.values || {}),\n ...data\n },\n context,\n entry\n });\n if (!error) {\n continue;\n }\n invalidFields.push({\n fieldId: field.fieldId,\n storageId: field.storageId,\n error\n });\n }\n\n if (invalidFields.length > 0) {\n throw new WebinyError(\"Validation failed.\", \"VALIDATION_FAILED\", invalidFields);\n }\n};\n"],"mappings":";;;;;;;;;;;AASA;;;;;;AAiBA,MAA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,MAAMC,cAAc,CAAC;MAC/B5B,KAD+B;MAE/BH,aAF+B;MAG/BE,KAH+B;MAI/BoB,IAAI,kCACI,CAAAlB,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEY,MAAP,KAAiB,EADrB,GAEGM,IAFH,CAJ2B;MAQ/BrB,OAR+B;MAS/BG;IAT+B,CAAD,CAAlC;;IAWA,IAAI,CAAC0B,KAAL,EAAY;MACR;IACH;;IACDW,aAAa,CAACD,IAAd,CAAmB;MACfjB,OAAO,EAAErB,KAAK,CAACqB,OADA;MAEfoB,SAAS,EAAEzC,KAAK,CAACyC,SAFF;MAGfb;IAHe,CAAnB;EAKH;;EAED,IAAIW,aAAa,CAACjC,MAAd,GAAuB,CAA3B,EAA8B;IAC1B,MAAM,IAAIoC,cAAJ,CAAgB,oBAAhB,EAAsC,mBAAtC,EAA2DH,aAA3D,CAAN;EACH;AACJ,CAhDM"}
1
+ {"version":3,"names":["validateValue","args","fieldValidators","value","validatorList","context","field","model","entry","fieldValidator","name","validations","length","validate","result","validator","message","ex","validatePredefinedValue","enabled","values","predefinedValues","Array","isArray","predefinedValue","runFieldMultipleValuesValidations","data","fieldId","valuesError","listValidation","valueError","validation","predefinedValueError","runFieldValueValidations","error","execValidation","multipleValues","validateModelEntryData","params","plugins","byType","reduce","acc","plugin","push","invalidFields","fields","storageId","WebinyError"],"sources":["entryDataValidation.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelField,\n CmsModelFieldValidation,\n CmsContext,\n CmsModelFieldValidatorPlugin,\n CmsModelFieldValidatorValidateParams,\n CmsEntry\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\n\ntype PluginValidationCallable = (params: CmsModelFieldValidatorValidateParams) => Promise<boolean>;\ntype PluginValidationList = Record<string, PluginValidationCallable[]>;\ntype InputData = Record<string, any>;\n\ninterface ValidateArgs {\n validatorList: PluginValidationList;\n field: CmsModelField;\n model: CmsModel;\n data: InputData;\n context: CmsContext;\n entry?: CmsEntry;\n}\n\ntype PossibleValue = boolean | number | string | null | undefined;\n\nconst validateValue = async (\n args: ValidateArgs,\n fieldValidators: CmsModelFieldValidation[],\n value: PossibleValue | PossibleValue[]\n): Promise<string | null> => {\n if (!fieldValidators) {\n return null;\n }\n\n const { validatorList, context, field, model, entry } = args;\n try {\n for (const fieldValidator of fieldValidators) {\n const name = fieldValidator.name;\n const validations = validatorList[name];\n if (!validations || validations.length === 0) {\n return `There are no \"${name}\" validators defined.`;\n }\n for (const validate of validations) {\n const result = await validate({\n value,\n context,\n validator: fieldValidator,\n field,\n model,\n entry\n });\n if (!result) {\n return fieldValidator.message;\n }\n }\n }\n } catch (ex) {\n return ex.message;\n }\n\n return null;\n};\n\nconst validatePredefinedValue = (field: CmsModelField, value: any | any[]): string | null => {\n const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};\n if (!enabled) {\n return null;\n } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {\n return \"Missing predefined values to validate against.\";\n }\n for (const predefinedValue of predefinedValues) {\n if (predefinedValue.value == value) {\n return null;\n }\n }\n return \"Value sent does not match any of the available predefined values.\";\n};\n/**\n * When multiple values is selected we must run validations on the array containing the values\n * And then on each value in the array\n */\nconst runFieldMultipleValuesValidations = async (args: ValidateArgs): Promise<string | null> => {\n const { field, data } = args;\n const values = data[field.fieldId] || [];\n if (Array.isArray(values) === false) {\n return `Value of the field \"${field.fieldId}\" is not an array.`;\n }\n const valuesError = await validateValue(args, field.listValidation || [], values);\n if (valuesError) {\n return valuesError;\n }\n for (const value of values) {\n const valueError = await validateValue(args, field.validation || [], value);\n if (valueError) {\n return valueError;\n }\n const predefinedValueError = validatePredefinedValue(field, value);\n if (predefinedValueError) {\n return predefinedValueError;\n }\n }\n return null;\n};\n/**\n * Runs validation on given value.\n */\nconst runFieldValueValidations = async (args: ValidateArgs): Promise<string | null> => {\n const { data, field } = args;\n const value = data[field.fieldId];\n const error = await validateValue(args, field.validation || [], value);\n if (error) {\n return error;\n }\n return validatePredefinedValue(field, value);\n};\n\nconst execValidation = async (args: ValidateArgs): Promise<string | null> => {\n if (args.field.multipleValues) {\n return await runFieldMultipleValuesValidations(args);\n }\n return await runFieldValueValidations(args);\n};\n\nexport interface ValidateModelEntryDataParams {\n context: CmsContext;\n model: CmsModel;\n data: InputData;\n entry?: CmsEntry;\n}\nexport const validateModelEntryData = async (params: ValidateModelEntryDataParams) => {\n const { context, model, entry, data } = params;\n /**\n * To later simplify searching for the validations we map them to a name.\n * @see CmsModelFieldValidatorPlugin.validator.validate\n */\n const validatorList: PluginValidationList = context.plugins\n .byType<CmsModelFieldValidatorPlugin>(\"cms-model-field-validator\")\n .reduce((acc, plugin) => {\n const name = plugin.validator.name;\n if (!acc[name]) {\n acc[name] = [];\n }\n acc[name].push(plugin.validator.validate);\n\n return acc;\n }, {} as PluginValidationList);\n\n /**\n * Loop through model fields and validate the corresponding data.\n * Run validation only if the field has validation configured.\n */\n const invalidFields = [];\n for (const field of model.fields) {\n const error = await execValidation({\n model,\n validatorList,\n field,\n data: {\n ...(entry?.values || {}),\n ...data\n },\n context,\n entry\n });\n if (!error) {\n continue;\n }\n invalidFields.push({\n fieldId: field.fieldId,\n storageId: field.storageId,\n error\n });\n }\n\n if (invalidFields.length > 0) {\n throw new WebinyError(\"Validation failed.\", \"VALIDATION_FAILED\", invalidFields);\n }\n};\n"],"mappings":";;;;;;;;AASA;AAiBA,MAAMA,aAAa,GAAG,OAClBC,IAAkB,EAClBC,eAA0C,EAC1CC,KAAsC,KACb;EACzB,IAAI,CAACD,eAAe,EAAE;IAClB,OAAO,IAAI;EACf;EAEA,MAAM;IAAEE,aAAa;IAAEC,OAAO;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGP,IAAI;EAC5D,IAAI;IACA,KAAK,MAAMQ,cAAc,IAAIP,eAAe,EAAE;MAC1C,MAAMQ,IAAI,GAAGD,cAAc,CAACC,IAAI;MAChC,MAAMC,WAAW,GAAGP,aAAa,CAAC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,MAAM,GAAG,CAAC,EAAE;IAC1B,MAAM,IAAIoC,cAAW,CAAC,oBAAoB,EAAE,mBAAmB,EAAEH,aAAa,CAAC;EACnF;AACJ,CAAC;AAAC"}
@@ -1,22 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.markUnlockedFields = exports.markLockedFields = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
-
20
11
  const markLockedFields = async params => {
21
12
  const {
22
13
  model,
@@ -25,56 +16,44 @@ const markLockedFields = async params => {
25
16
  /**
26
17
  * If the model is registered via a plugin, we don't need do process anything.
27
18
  */
28
-
29
19
  const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
30
-
31
20
  if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
32
21
  return;
33
22
  }
34
-
35
23
  const cmsLockedFieldPlugins = context.plugins.byType("cms-model-locked-field");
36
24
  const existingLockedFields = model.lockedFields || [];
37
25
  const lockedFields = [];
38
-
39
26
  for (const field of model.fields) {
40
27
  const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.storageId);
41
-
42
28
  if (alreadyLocked) {
43
29
  continue;
44
30
  }
45
-
46
31
  let lockedFieldData = {};
47
32
  const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === field.type);
48
-
49
33
  for (const plugin of lockedFieldPlugins) {
50
34
  if (typeof plugin.getLockedFieldData !== "function") {
51
35
  continue;
52
36
  }
53
-
54
37
  const data = plugin.getLockedFieldData({
55
38
  field
56
39
  });
57
- lockedFieldData = _objectSpread(_objectSpread({}, lockedFieldData), data);
40
+ lockedFieldData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, lockedFieldData), data);
58
41
  }
59
-
60
- lockedFields.push(_objectSpread({
42
+ lockedFields.push((0, _objectSpread2.default)({
61
43
  fieldId: field.storageId,
62
44
  multipleValues: !!field.multipleValues,
63
45
  type: field.type
64
46
  }, lockedFieldData));
65
- } // no need to update anything if no locked fields were added
66
-
67
-
47
+ }
48
+ // no need to update anything if no locked fields were added
68
49
  if (lockedFields.length === 0) {
69
50
  return;
70
51
  }
71
-
72
52
  const newLockedFields = existingLockedFields.concat(lockedFields);
73
-
74
53
  try {
75
54
  await context.cms.updateModelDirect({
76
55
  original: model,
77
- model: _objectSpread(_objectSpread({}, model), {}, {
56
+ model: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
78
57
  lockedFields: newLockedFields
79
58
  })
80
59
  });
@@ -83,9 +62,7 @@ const markLockedFields = async params => {
83
62
  throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED", ex);
84
63
  }
85
64
  };
86
-
87
65
  exports.markLockedFields = markLockedFields;
88
-
89
66
  const markUnlockedFields = async params => {
90
67
  const {
91
68
  context,
@@ -94,17 +71,14 @@ const markUnlockedFields = async params => {
94
71
  /**
95
72
  * If the model is registered via a plugin, we don't need do process anything.
96
73
  */
97
-
98
74
  const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
99
-
100
75
  if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
101
76
  return;
102
77
  }
103
-
104
78
  try {
105
79
  await context.cms.updateModelDirect({
106
80
  original: model,
107
- model: _objectSpread(_objectSpread({}, model), {}, {
81
+ model: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
108
82
  lockedFields: []
109
83
  })
110
84
  });
@@ -113,5 +87,4 @@ const markUnlockedFields = async params => {
113
87
  throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED", ex);
114
88
  }
115
89
  };
116
-
117
90
  exports.markUnlockedFields = markUnlockedFields;