@webiny/api-headless-cms 0.0.0-unstable.611c5af35e → 0.0.0-unstable.615a930a68

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 (277) hide show
  1. package/context.js +15 -0
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/afterDelete.js +5 -0
  4. package/crud/contentEntry/afterDelete.js.map +1 -1
  5. package/crud/contentEntry/beforeCreate.js +3 -0
  6. package/crud/contentEntry/beforeCreate.js.map +1 -1
  7. package/crud/contentEntry/beforeUpdate.js +3 -0
  8. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  9. package/crud/contentEntry/entryDataValidation.js +40 -1
  10. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  11. package/crud/contentEntry/markLockedFields.js +25 -2
  12. package/crud/contentEntry/markLockedFields.js.map +1 -1
  13. package/crud/contentEntry/referenceFieldsMapping.js +59 -5
  14. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  15. package/crud/contentEntry/searchableFields.d.ts +9 -0
  16. package/crud/contentEntry/searchableFields.js +83 -0
  17. package/crud/contentEntry/searchableFields.js.map +1 -0
  18. package/crud/contentEntry.crud.js +146 -55
  19. package/crud/contentEntry.crud.js.map +1 -1
  20. package/crud/contentModel/afterCreate.js +2 -0
  21. package/crud/contentModel/afterCreate.js.map +1 -1
  22. package/crud/contentModel/afterCreateFrom.js +2 -0
  23. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  24. package/crud/contentModel/afterDelete.js +2 -0
  25. package/crud/contentModel/afterDelete.js.map +1 -1
  26. package/crud/contentModel/afterUpdate.js +2 -0
  27. package/crud/contentModel/afterUpdate.js.map +1 -1
  28. package/crud/contentModel/beforeCreate.js +32 -4
  29. package/crud/contentModel/beforeCreate.js.map +1 -1
  30. package/crud/contentModel/beforeDelete.js +10 -0
  31. package/crud/contentModel/beforeDelete.js.map +1 -1
  32. package/crud/contentModel/beforeUpdate.js +5 -0
  33. package/crud/contentModel/beforeUpdate.js.map +1 -1
  34. package/crud/contentModel/contentModelManagerFactory.js +7 -0
  35. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  36. package/crud/contentModel/createFieldModels.js +6 -0
  37. package/crud/contentModel/createFieldModels.js.map +1 -1
  38. package/crud/contentModel/createFieldStorageId.js +2 -0
  39. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  40. package/crud/contentModel/fieldIdValidation.js +5 -0
  41. package/crud/contentModel/fieldIdValidation.js.map +1 -1
  42. package/crud/contentModel/idValidation.js +5 -0
  43. package/crud/contentModel/idValidation.js.map +1 -1
  44. package/crud/contentModel/models.js +8 -1
  45. package/crud/contentModel/models.js.map +1 -1
  46. package/crud/contentModel/systemFields.js.map +1 -1
  47. package/crud/contentModel/validateLayout.js +8 -0
  48. package/crud/contentModel/validateLayout.js.map +1 -1
  49. package/crud/contentModel/validateModel.js +8 -0
  50. package/crud/contentModel/validateModel.js.map +1 -1
  51. package/crud/contentModel/validateModelFields.js +60 -8
  52. package/crud/contentModel/validateModelFields.js.map +1 -1
  53. package/crud/contentModel.crud.js +96 -11
  54. package/crud/contentModel.crud.js.map +1 -1
  55. package/crud/contentModelGroup/beforeCreate.js +12 -0
  56. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  57. package/crud/contentModelGroup/beforeDelete.js +8 -0
  58. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  59. package/crud/contentModelGroup/beforeUpdate.js +5 -0
  60. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  61. package/crud/contentModelGroup.crud.js +47 -10
  62. package/crud/contentModelGroup.crud.js.map +1 -1
  63. package/crud/index.js +16 -0
  64. package/crud/index.js.map +1 -1
  65. package/crud/settings.crud.js +12 -0
  66. package/crud/settings.crud.js.map +1 -1
  67. package/crud/system.crud.js +37 -2
  68. package/crud/system.crud.js.map +1 -1
  69. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +13 -0
  70. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  71. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +53 -0
  72. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  73. package/fieldConverters/index.js +4 -0
  74. package/fieldConverters/index.js.map +1 -1
  75. package/graphql/buildSchemaPlugins.js +9 -5
  76. package/graphql/buildSchemaPlugins.js.map +1 -1
  77. package/graphql/graphQLHandlerFactory.js +28 -3
  78. package/graphql/graphQLHandlerFactory.js.map +1 -1
  79. package/graphql/index.js +8 -1
  80. package/graphql/index.js.map +1 -1
  81. package/graphql/schema/baseContentSchema.js +9 -1
  82. package/graphql/schema/baseContentSchema.js.map +1 -1
  83. package/graphql/schema/contentEntries.js +42 -2
  84. package/graphql/schema/contentEntries.js.map +1 -1
  85. package/graphql/schema/contentModelGroups.js +19 -2
  86. package/graphql/schema/contentModelGroups.js.map +1 -1
  87. package/graphql/schema/contentModels.js +18 -2
  88. package/graphql/schema/contentModels.js.map +1 -1
  89. package/graphql/schema/createFieldResolvers.js +21 -3
  90. package/graphql/schema/createFieldResolvers.js.map +1 -1
  91. package/graphql/schema/createManageResolvers.js +26 -0
  92. package/graphql/schema/createManageResolvers.js.map +1 -1
  93. package/graphql/schema/createManageSDL.js +17 -2
  94. package/graphql/schema/createManageSDL.js.map +1 -1
  95. package/graphql/schema/createPreviewResolvers.js +10 -0
  96. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  97. package/graphql/schema/createReadResolvers.js +10 -0
  98. package/graphql/schema/createReadResolvers.js.map +1 -1
  99. package/graphql/schema/createReadSDL.js +13 -1
  100. package/graphql/schema/createReadSDL.js.map +1 -1
  101. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -0
  102. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  103. package/graphql/schema/resolvers/manage/resolveCreate.js +3 -0
  104. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  105. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +3 -0
  106. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  107. package/graphql/schema/resolvers/manage/resolveDelete.js +6 -0
  108. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  109. package/graphql/schema/resolvers/manage/resolveGet.js +16 -0
  110. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  111. package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -0
  112. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  113. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -0
  114. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  115. package/graphql/schema/resolvers/manage/resolveList.js +3 -0
  116. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  117. package/graphql/schema/resolvers/manage/resolvePublish.js +3 -0
  118. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  119. package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -0
  120. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  121. package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -0
  122. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  123. package/graphql/schema/resolvers/manage/resolveUpdate.js +3 -0
  124. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  125. package/graphql/schema/resolvers/preview/resolveGet.js +8 -0
  126. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  127. package/graphql/schema/resolvers/preview/resolveList.js +3 -0
  128. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  129. package/graphql/schema/resolvers/read/resolveGet.js +8 -0
  130. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  131. package/graphql/schema/resolvers/read/resolveList.js +3 -0
  132. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  133. package/graphql/schema/schemaPlugins.js +19 -5
  134. package/graphql/schema/schemaPlugins.js.map +1 -1
  135. package/graphql/system.js +14 -1
  136. package/graphql/system.js.map +1 -1
  137. package/graphqlFields/boolean.js +12 -0
  138. package/graphqlFields/boolean.js.map +1 -1
  139. package/graphqlFields/datetime.js +17 -0
  140. package/graphqlFields/datetime.js.map +1 -1
  141. package/graphqlFields/file.js +8 -0
  142. package/graphqlFields/file.js.map +1 -1
  143. package/graphqlFields/helpers.js +10 -0
  144. package/graphqlFields/helpers.js.map +1 -1
  145. package/graphqlFields/index.js +11 -0
  146. package/graphqlFields/index.js.map +1 -1
  147. package/graphqlFields/longText.js +10 -0
  148. package/graphqlFields/longText.js.map +1 -1
  149. package/graphqlFields/number.js +16 -0
  150. package/graphqlFields/number.js.map +1 -1
  151. package/graphqlFields/object.js +137 -21
  152. package/graphqlFields/object.js.map +1 -1
  153. package/graphqlFields/ref.js +51 -17
  154. package/graphqlFields/ref.js.map +1 -1
  155. package/graphqlFields/richText.js +9 -0
  156. package/graphqlFields/richText.js.map +1 -1
  157. package/graphqlFields/text.js +11 -0
  158. package/graphqlFields/text.js.map +1 -1
  159. package/index.js +19 -0
  160. package/index.js.map +1 -1
  161. package/modelManager/DefaultCmsModelManager.js +16 -0
  162. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  163. package/modelManager/index.js +4 -0
  164. package/modelManager/index.js.map +1 -1
  165. package/package.json +24 -24
  166. package/parameters/context.js +4 -0
  167. package/parameters/context.js.map +1 -1
  168. package/parameters/header.js +11 -0
  169. package/parameters/header.js.map +1 -1
  170. package/parameters/index.js +8 -0
  171. package/parameters/index.js.map +1 -1
  172. package/parameters/manual.js +8 -1
  173. package/parameters/manual.js.map +1 -1
  174. package/parameters/path.js +11 -0
  175. package/parameters/path.js.map +1 -1
  176. package/plugins/CmsGroupPlugin.js +8 -0
  177. package/plugins/CmsGroupPlugin.js.map +1 -1
  178. package/plugins/CmsModelFieldConverterPlugin.js +5 -0
  179. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  180. package/plugins/CmsModelPlugin.js +38 -2
  181. package/plugins/CmsModelPlugin.js.map +1 -1
  182. package/plugins/CmsParametersPlugin.js +7 -0
  183. package/plugins/CmsParametersPlugin.js.map +1 -1
  184. package/plugins/StorageTransformPlugin.d.ts +1 -1
  185. package/plugins/StorageTransformPlugin.js +9 -0
  186. package/plugins/StorageTransformPlugin.js.map +1 -1
  187. package/plugins/index.js +10 -0
  188. package/plugins/index.js.map +1 -1
  189. package/storage/default.js +3 -0
  190. package/storage/default.js.map +1 -1
  191. package/storage/object.js +18 -0
  192. package/storage/object.js.map +1 -1
  193. package/types.d.ts +9 -1
  194. package/types.js +62 -0
  195. package/types.js.map +1 -1
  196. package/upgrades/5.33.0/index.js +26 -3
  197. package/upgrades/5.33.0/index.js.map +1 -1
  198. package/upgrades/index.js +3 -0
  199. package/upgrades/index.js.map +1 -1
  200. package/utils/access.js +25 -11
  201. package/utils/access.js.map +1 -1
  202. package/utils/converters/Converter.js +13 -0
  203. package/utils/converters/Converter.js.map +1 -1
  204. package/utils/converters/ConverterCollection.js +32 -9
  205. package/utils/converters/ConverterCollection.js.map +1 -1
  206. package/utils/converters/valueKeyStorageConverter.js +26 -0
  207. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  208. package/utils/createTypeName.js +8 -0
  209. package/utils/createTypeName.js.map +1 -1
  210. package/utils/entryStorage.js +26 -10
  211. package/utils/entryStorage.js.map +1 -1
  212. package/utils/filterAsync.js +5 -0
  213. package/utils/filterAsync.js.map +1 -1
  214. package/utils/filterModelFields.js +9 -3
  215. package/utils/filterModelFields.js.map +1 -1
  216. package/utils/getEntryTitle.js +9 -0
  217. package/utils/getEntryTitle.js.map +1 -1
  218. package/utils/getSchemaFromFieldPlugins.js +6 -2
  219. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  220. package/utils/ownership.js +8 -0
  221. package/utils/ownership.js.map +1 -1
  222. package/utils/permissions.js +23 -8
  223. package/utils/permissions.js.map +1 -1
  224. package/utils/pluralizedTypeName.js +6 -0
  225. package/utils/pluralizedTypeName.js.map +1 -1
  226. package/utils/renderFields.js +8 -0
  227. package/utils/renderFields.js.map +1 -1
  228. package/utils/renderGetFilterFields.js +11 -0
  229. package/utils/renderGetFilterFields.js.map +1 -1
  230. package/utils/renderInputFields.js +8 -0
  231. package/utils/renderInputFields.js.map +1 -1
  232. package/utils/renderListFilterFields.js +11 -2
  233. package/utils/renderListFilterFields.js.map +1 -1
  234. package/utils/renderSortEnum.js +7 -0
  235. package/utils/renderSortEnum.js.map +1 -1
  236. package/utils/toSlug.js +4 -0
  237. package/utils/toSlug.js.map +1 -1
  238. package/validators/dateGte.js +7 -0
  239. package/validators/dateGte.js.map +1 -1
  240. package/validators/dateLte.js +7 -0
  241. package/validators/dateLte.js.map +1 -1
  242. package/validators/gte.js +8 -0
  243. package/validators/gte.js.map +1 -1
  244. package/validators/in.js +8 -0
  245. package/validators/in.js.map +1 -1
  246. package/validators/index.js +15 -0
  247. package/validators/index.js.map +1 -1
  248. package/validators/lte.js +8 -0
  249. package/validators/lte.js.map +1 -1
  250. package/validators/maxLength.js +8 -0
  251. package/validators/maxLength.js.map +1 -1
  252. package/validators/minLength.js +8 -0
  253. package/validators/minLength.js.map +1 -1
  254. package/validators/pattern.js +9 -0
  255. package/validators/pattern.js.map +1 -1
  256. package/validators/patternPlugins/email.js +2 -0
  257. package/validators/patternPlugins/email.js.map +1 -1
  258. package/validators/patternPlugins/index.js +8 -0
  259. package/validators/patternPlugins/index.js.map +1 -1
  260. package/validators/patternPlugins/lowerCase.js +2 -0
  261. package/validators/patternPlugins/lowerCase.js.map +1 -1
  262. package/validators/patternPlugins/lowerCaseSpace.js +2 -0
  263. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  264. package/validators/patternPlugins/upperCase.js +2 -0
  265. package/validators/patternPlugins/upperCase.js.map +1 -1
  266. package/validators/patternPlugins/upperCaseSpace.js +2 -0
  267. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  268. package/validators/patternPlugins/url.js +2 -0
  269. package/validators/patternPlugins/url.js.map +1 -1
  270. package/validators/required.js +5 -0
  271. package/validators/required.js.map +1 -1
  272. package/validators/timeGte.js +8 -0
  273. package/validators/timeGte.js.map +1 -1
  274. package/validators/timeLte.js +8 -0
  275. package/validators/timeLte.js.map +1 -1
  276. package/validators/unique.js +7 -0
  277. package/validators/unique.js.map +1 -1
package/context.js CHANGED
@@ -1,37 +1,51 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.createContextPlugin = void 0;
9
+
8
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
9
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
+
10
14
  var _api = require("@webiny/api");
15
+
11
16
  var _CmsParametersPlugin = require("./plugins/CmsParametersPlugin");
17
+
12
18
  const getParameters = async context => {
13
19
  const plugins = context.plugins.byType(_CmsParametersPlugin.CmsParametersPlugin.type);
20
+
14
21
  for (const plugin of plugins) {
15
22
  const result = await plugin.getParameters(context);
23
+
16
24
  if (result !== null) {
17
25
  return result;
18
26
  }
19
27
  }
28
+
20
29
  throw new _error.default("Could not determine locale and/or type of the CMS.", "CMS_LOCALE_AND_TYPE_ERROR");
21
30
  };
31
+
22
32
  const createContextPlugin = () => {
23
33
  return new _api.ContextPlugin(async context => {
24
34
  const {
25
35
  type,
26
36
  locale
27
37
  } = await getParameters(context);
38
+
28
39
  const getLocale = () => {
29
40
  const systemLocale = context.i18n.getLocale(locale);
41
+
30
42
  if (!systemLocale) {
31
43
  throw new _error.default(`There is no locale "${locale}" in the system.`);
32
44
  }
45
+
33
46
  return systemLocale;
34
47
  };
48
+
35
49
  context.cms = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, context.cms || {}), {}, {
36
50
  type,
37
51
  locale,
@@ -42,4 +56,5 @@ const createContextPlugin = () => {
42
56
  });
43
57
  });
44
58
  };
59
+
45
60
  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,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
+ {"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,+DACQd,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"}
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignAfterEntryDelete = void 0;
7
+
7
8
  var _markLockedFields = require("./markLockedFields");
9
+
8
10
  const assignAfterEntryDelete = params => {
9
11
  const {
10
12
  context,
@@ -24,13 +26,16 @@ const assignAfterEntryDelete = params => {
24
26
  },
25
27
  limit: 1
26
28
  });
29
+
27
30
  if (items.length > 0) {
28
31
  return;
29
32
  }
33
+
30
34
  await (0, _markLockedFields.markUnlockedFields)({
31
35
  context,
32
36
  model
33
37
  });
34
38
  });
35
39
  };
40
+
36
41
  exports.assignAfterEntryDelete = assignAfterEntryDelete;
@@ -1 +1 @@
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
+ {"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,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"}
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignBeforeEntryCreate = void 0;
7
+
7
8
  var _markLockedFields = require("./markLockedFields");
9
+
8
10
  const assignBeforeEntryCreate = params => {
9
11
  const {
10
12
  context,
@@ -22,4 +24,5 @@ const assignBeforeEntryCreate = params => {
22
24
  });
23
25
  });
24
26
  };
27
+
25
28
  exports.assignBeforeEntryCreate = assignBeforeEntryCreate;
@@ -1 +1 @@
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
+ {"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,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"}
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assignBeforeEntryUpdate = void 0;
7
+
7
8
  var _markLockedFields = require("./markLockedFields");
9
+
8
10
  const assignBeforeEntryUpdate = params => {
9
11
  const {
10
12
  context,
@@ -22,4 +24,5 @@ const assignBeforeEntryUpdate = params => {
22
24
  });
23
25
  });
24
26
  };
27
+
25
28
  exports.assignBeforeEntryUpdate = assignBeforeEntryUpdate;
@@ -1 +1 @@
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
+ {"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,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,16 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.validateModelEntryData = void 0;
9
+
8
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
9
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
+
10
14
  const validateValue = async (args, fieldValidators, value) => {
11
15
  if (!fieldValidators) {
12
16
  return null;
13
17
  }
18
+
14
19
  const {
15
20
  validatorList,
16
21
  context,
@@ -18,13 +23,16 @@ const validateValue = async (args, fieldValidators, value) => {
18
23
  model,
19
24
  entry
20
25
  } = args;
26
+
21
27
  try {
22
28
  for (const fieldValidator of fieldValidators) {
23
29
  const name = fieldValidator.name;
24
30
  const validations = validatorList[name];
31
+
25
32
  if (!validations || validations.length === 0) {
26
33
  return `There are no "${name}" validators defined.`;
27
34
  }
35
+
28
36
  for (const validate of validations) {
29
37
  const result = await validate({
30
38
  value,
@@ -34,6 +42,7 @@ const validateValue = async (args, fieldValidators, value) => {
34
42
  model,
35
43
  entry
36
44
  });
45
+
37
46
  if (!result) {
38
47
  return fieldValidator.message;
39
48
  }
@@ -42,57 +51,74 @@ const validateValue = async (args, fieldValidators, value) => {
42
51
  } catch (ex) {
43
52
  return ex.message;
44
53
  }
54
+
45
55
  return null;
46
56
  };
57
+
47
58
  const validatePredefinedValue = (field, value) => {
48
59
  const {
49
60
  enabled = false,
50
61
  values: predefinedValues = []
51
62
  } = field.predefinedValues || {};
63
+
52
64
  if (!enabled) {
53
65
  return null;
54
66
  } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {
55
67
  return "Missing predefined values to validate against.";
56
68
  }
69
+
57
70
  for (const predefinedValue of predefinedValues) {
58
71
  if (predefinedValue.value == value) {
59
72
  return null;
60
73
  }
61
74
  }
75
+
62
76
  return "Value sent does not match any of the available predefined values.";
63
77
  };
64
78
  /**
65
79
  * When multiple values is selected we must run validations on the array containing the values
66
80
  * And then on each value in the array
67
81
  */
82
+
83
+
68
84
  const runFieldMultipleValuesValidations = async args => {
69
85
  const {
70
86
  field,
71
87
  data
72
88
  } = args;
73
89
  const values = data[field.fieldId] || [];
90
+
74
91
  if (Array.isArray(values) === false) {
75
92
  return `Value of the field "${field.fieldId}" is not an array.`;
76
93
  }
94
+
77
95
  const valuesError = await validateValue(args, field.listValidation || [], values);
96
+
78
97
  if (valuesError) {
79
98
  return valuesError;
80
99
  }
100
+
81
101
  for (const value of values) {
82
102
  const valueError = await validateValue(args, field.validation || [], value);
103
+
83
104
  if (valueError) {
84
105
  return valueError;
85
106
  }
107
+
86
108
  const predefinedValueError = validatePredefinedValue(field, value);
109
+
87
110
  if (predefinedValueError) {
88
111
  return predefinedValueError;
89
112
  }
90
113
  }
114
+
91
115
  return null;
92
116
  };
93
117
  /**
94
118
  * Runs validation on given value.
95
119
  */
120
+
121
+
96
122
  const runFieldValueValidations = async args => {
97
123
  const {
98
124
  data,
@@ -100,17 +126,22 @@ const runFieldValueValidations = async args => {
100
126
  } = args;
101
127
  const value = data[field.fieldId];
102
128
  const error = await validateValue(args, field.validation || [], value);
129
+
103
130
  if (error) {
104
131
  return error;
105
132
  }
133
+
106
134
  return validatePredefinedValue(field, value);
107
135
  };
136
+
108
137
  const execValidation = async args => {
109
138
  if (args.field.multipleValues) {
110
139
  return await runFieldMultipleValuesValidations(args);
111
140
  }
141
+
112
142
  return await runFieldValueValidations(args);
113
143
  };
144
+
114
145
  const validateModelEntryData = async params => {
115
146
  const {
116
147
  context,
@@ -122,20 +153,24 @@ const validateModelEntryData = async params => {
122
153
  * To later simplify searching for the validations we map them to a name.
123
154
  * @see CmsModelFieldValidatorPlugin.validator.validate
124
155
  */
156
+
125
157
  const validatorList = context.plugins.byType("cms-model-field-validator").reduce((acc, plugin) => {
126
158
  const name = plugin.validator.name;
159
+
127
160
  if (!acc[name]) {
128
161
  acc[name] = [];
129
162
  }
163
+
130
164
  acc[name].push(plugin.validator.validate);
131
165
  return acc;
132
166
  }, {});
133
-
134
167
  /**
135
168
  * Loop through model fields and validate the corresponding data.
136
169
  * Run validation only if the field has validation configured.
137
170
  */
171
+
138
172
  const invalidFields = [];
173
+
139
174
  for (const field of model.fields) {
140
175
  const error = await execValidation({
141
176
  model,
@@ -145,17 +180,21 @@ const validateModelEntryData = async params => {
145
180
  context,
146
181
  entry
147
182
  });
183
+
148
184
  if (!error) {
149
185
  continue;
150
186
  }
187
+
151
188
  invalidFields.push({
152
189
  fieldId: field.fieldId,
153
190
  storageId: field.storageId,
154
191
  error
155
192
  });
156
193
  }
194
+
157
195
  if (invalidFields.length > 0) {
158
196
  throw new _error.default("Validation failed.", "VALIDATION_FAILED", invalidFields);
159
197
  }
160
198
  };
199
+
161
200
  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,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,CAACM,IAAI,CAAC;MACvC,IAAI,CAACC,WAAW,IAAIA,WAAW,CAACC,MAAM,KAAK,CAAC,EAAE;QAC1C,OAAQ,iBAAgBF,IAAK,uBAAsB;MACvD;MACA,KAAK,MAAMG,QAAQ,IAAIF,WAAW,EAAE;QAChC,MAAMG,MAAM,GAAG,MAAMD,QAAQ,CAAC;UAC1BV,KAAK;UACLE,OAAO;UACPU,SAAS,EAAEN,cAAc;UACzBH,KAAK;UACLC,KAAK;UACLC;QACJ,CAAC,CAAC;QACF,IAAI,CAACM,MAAM,EAAE;UACT,OAAOL,cAAc,CAACO,OAAO;QACjC;MACJ;IACJ;EACJ,CAAC,CAAC,OAAOC,EAAE,EAAE;IACT,OAAOA,EAA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AG,CAAChC,IAAI,CAAC,EAAE;MACZgC,GAAG,CAAChC,IAAI,CAAC,GAAG,EAAE;IAClB;IACAgC,GAAG,CAAChC,IAAI,CAAC,CAACkC,IAAI,CAACD,MAAM,CAAC5B,SAAS,CAACF,QAAQ,CAAC;IAEzC,OAAO6B,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAAyB;;EAElC;AACJ;AACA;AACA;EACI,MAAMG,aAAa,GAAG,EAAE;EACxB,KAAK,MAAMvC,KAAK,IAAIC,KAAK,CAACuC,MAAM,EAAE;IAC9B,MAAMZ,KAAK,GAAG,MAAMC,cAAc,CAAC;MAC/B5B,KAAK;MACLH,aAAa;MACbE,KAAK;MACLoB,IAAI,8DACI,CAAAlB,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEY,MAAM,KAAI,CAAC,CAAC,GACpBM,IAAI,CACV;MACDrB,OAAO;MACPG;IACJ,CAAC,CAAC;IACF,IAAI,CAAC0B,KAAK,EAAE;MACR;IACJ;IACAW,aAAa,CAACD,IAAI,CAAC;MACfjB,OAAO,EAAErB,KAAK,CAACqB,OAAO;MACtBoB,SAAS,EAAEzC,KAAK,CAACyC,SAAS;MAC1Bb;IACJ,CAAC,CAAC;EACN;EAEA,IAAIW,aAAa,CAACjC,MAAM,GAAG,CAAC,EAAE;IAC1B,MAAM,IAAIoC,cAAW,CAAC,oBAAoB,EAAE,mBAAmB,EAAEH,aAAa,CAAC;EACnF;AACJ,CAAC;AAAC"}
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,O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AC;MAC/B5B,KAD+B;MAE/BH,aAF+B;MAG/BE,KAH+B;MAI/BoB,IAAI,8DACI,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,13 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.markUnlockedFields = exports.markLockedFields = void 0;
9
+
8
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
9
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
+
10
14
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
15
+
11
16
  const markLockedFields = async params => {
12
17
  const {
13
18
  model,
@@ -16,40 +21,52 @@ const markLockedFields = async params => {
16
21
  /**
17
22
  * If the model is registered via a plugin, we don't need do process anything.
18
23
  */
24
+
19
25
  const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
26
+
20
27
  if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
21
28
  return;
22
29
  }
30
+
23
31
  const cmsLockedFieldPlugins = context.plugins.byType("cms-model-locked-field");
24
32
  const existingLockedFields = model.lockedFields || [];
25
33
  const lockedFields = [];
34
+
26
35
  for (const field of model.fields) {
27
36
  const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.storageId);
37
+
28
38
  if (alreadyLocked) {
29
39
  continue;
30
40
  }
41
+
31
42
  let lockedFieldData = {};
32
43
  const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === field.type);
44
+
33
45
  for (const plugin of lockedFieldPlugins) {
34
46
  if (typeof plugin.getLockedFieldData !== "function") {
35
47
  continue;
36
48
  }
49
+
37
50
  const data = plugin.getLockedFieldData({
38
51
  field
39
52
  });
40
53
  lockedFieldData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, lockedFieldData), data);
41
54
  }
55
+
42
56
  lockedFields.push((0, _objectSpread2.default)({
43
57
  fieldId: field.storageId,
44
58
  multipleValues: !!field.multipleValues,
45
59
  type: field.type
46
60
  }, lockedFieldData));
47
- }
48
- // no need to update anything if no locked fields were added
61
+ } // no need to update anything if no locked fields were added
62
+
63
+
49
64
  if (lockedFields.length === 0) {
50
65
  return;
51
66
  }
67
+
52
68
  const newLockedFields = existingLockedFields.concat(lockedFields);
69
+
53
70
  try {
54
71
  await context.cms.updateModelDirect({
55
72
  original: model,
@@ -62,7 +79,9 @@ const markLockedFields = async params => {
62
79
  throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED", ex);
63
80
  }
64
81
  };
82
+
65
83
  exports.markLockedFields = markLockedFields;
84
+
66
85
  const markUnlockedFields = async params => {
67
86
  const {
68
87
  context,
@@ -71,10 +90,13 @@ const markUnlockedFields = async params => {
71
90
  /**
72
91
  * If the model is registered via a plugin, we don't need do process anything.
73
92
  */
93
+
74
94
  const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
95
+
75
96
  if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
76
97
  return;
77
98
  }
99
+
78
100
  try {
79
101
  await context.cms.updateModelDirect({
80
102
  original: model,
@@ -87,4 +109,5 @@ const markUnlockedFields = async params => {
87
109
  throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED", ex);
88
110
  }
89
111
  };
112
+
90
113
  exports.markUnlockedFields = markUnlockedFields;
@@ -1 +1 @@
1
- {"version":3,"names":["markLockedFields","params","model","context","plugins","byType","CmsModelPlugin","type","find","plugin","contentModel","modelId","cmsLockedFieldPlugins","existingLockedFields","lockedFields","field","fields","alreadyLocked","some","lockedField","fieldId","storageId","lockedFieldData","lockedFieldPlugins","filter","pl","fieldType","getLockedFieldData","data","push","multipleValues","length","newLockedFields","concat","cms","updateModelDirect","original","ex","WebinyError","markUnlockedFields"],"sources":["markLockedFields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsContext, CmsModelLockedFieldPlugin, LockedField } from \"~/types\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\n\ninterface MarkLockedFieldsParams {\n model: CmsModel;\n entry: CmsEntry;\n context: CmsContext;\n}\nexport const markLockedFields = async (params: MarkLockedFieldsParams): Promise<void> => {\n const { model, context } = params;\n /**\n * If the model is registered via a plugin, we don't need do process anything.\n */\n const plugins = context.plugins.byType<CmsModelPlugin>(CmsModelPlugin.type);\n if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {\n return;\n }\n\n const cmsLockedFieldPlugins =\n context.plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n const existingLockedFields = model.lockedFields || [];\n const lockedFields: LockedField[] = [];\n for (const field of model.fields) {\n const alreadyLocked = existingLockedFields.some(\n lockedField => lockedField.fieldId === field.storageId\n );\n if (alreadyLocked) {\n continue;\n }\n\n let lockedFieldData = {};\n\n const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === field.type);\n for (const plugin of lockedFieldPlugins) {\n if (typeof plugin.getLockedFieldData !== \"function\") {\n continue;\n }\n const data = plugin.getLockedFieldData({\n field\n });\n lockedFieldData = { ...lockedFieldData, ...data };\n }\n\n lockedFields.push({\n fieldId: field.storageId,\n multipleValues: !!field.multipleValues,\n type: field.type,\n ...lockedFieldData\n });\n }\n // no need to update anything if no locked fields were added\n if (lockedFields.length === 0) {\n return;\n }\n\n const newLockedFields = existingLockedFields.concat(lockedFields);\n\n try {\n await context.cms.updateModelDirect({\n original: model,\n model: {\n ...model,\n lockedFields: newLockedFields\n }\n });\n model.lockedFields = newLockedFields;\n } catch (ex) {\n throw new WebinyError(\n `Could not update model \"${model.modelId}\" with new locked fields.`,\n \"MODEL_LOCKED_FIELDS_UPDATE_FAILED\",\n ex\n );\n }\n};\n\nexport interface MarkFieldsUnlockedParams {\n context: CmsContext;\n model: CmsModel;\n}\nexport const markUnlockedFields = async (params: MarkFieldsUnlockedParams) => {\n const { context, model } = params;\n /**\n * If the model is registered via a plugin, we don't need do process anything.\n */\n const plugins = context.plugins.byType<CmsModelPlugin>(CmsModelPlugin.type);\n if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {\n return;\n }\n\n try {\n await context.cms.updateModelDirect({\n original: model,\n model: {\n ...model,\n lockedFields: []\n }\n });\n model.lockedFields = [];\n } catch (ex) {\n throw new WebinyError(\n `Could not update model \"${model.modelId}\" with unlocked fields.`,\n \"MODEL_UNLOCKED_FIELDS_UPDATE_FAILED\",\n ex\n );\n }\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AAOO,MAAMA,gBAAgB,GAAG,MAAOC,MAA8B,IAAoB;EACrF,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EACjC;AACJ;AACA;EACI,MAAMG,OAAO,GAAGD,OAAO,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC;EAC3E,IAAIH,OAAO,CAACI,IAAI,CAACC,MAAM,IAAIA,MAAM,CAACC,YAAY,CAACC,OAAO,KAAKT,KAAK,CAACS,OAAO,CAA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DACEA,KAAK;QACRY,YAAY,EAAEkB;MAAe;IAErC,CAAC,CAAC;IACF9B,KAAK,CAACY,YAAY,GAAGkB,eAAe;EACxC,CAAC,CAAC,OAAOK,EAAE,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,2BAA0BpC,KAAK,CAACS,OAAQ,2BAA0B,EACnE,mCAAmC,EACnC0B,EAAE,CACL;EACL;AACJ,CAAC;AAAC;AAMK,MAAME,kBAAkB,GAAG,MAAOtC,MAAgC,IAAK;EAC1E,MAAM;IAAEE,OAAO;IAAED;EAAM,CAAC,GAAGD,MAAM;EACjC;AACJ;AACA;EACI,MAAMG,OAAO,GAAGD,OAAO,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC;EAC3E,IAAIH,OAAO,CAACI,IAAI,CAACC,MAAM,IAAIA,MAAM,CAACC,YAAY,CAACC,OAAO,KAAKT,KAAK,CAACS,OAAO,CAAC,EAAE;IACvE;EACJ;EAEA,IAAI;IACA,MAAMR,OAAO,CAAC+B,GAAG,CAACC,iBAAiB,CAAC;MAChCC,QAAQ,EAAElC,KAAK;MACfA,KAAK,8DACEA,KAAK;QACRY,YAAY,EAAE;MAAE;IAExB,CAAC,CAAC;IACFZ,KAAK,CAACY,YAAY,GAAG,EAAE;EAC3B,CAAC,CAAC,OAAOuB,EAAE,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,2BAA0BpC,KAAK,CAACS,OAAQ,yBAAwB,EACjE,qCAAqC,EACrC0B,EAAE,CACL;EACL;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["markLockedFields","params","model","context","plugins","byType","CmsModelPlugin","type","find","plugin","contentModel","modelId","cmsLockedFieldPlugins","existingLockedFields","lockedFields","field","fields","alreadyLocked","some","lockedField","fieldId","storageId","lockedFieldData","lockedFieldPlugins","filter","pl","fieldType","getLockedFieldData","data","push","multipleValues","length","newLockedFields","concat","cms","updateModelDirect","original","ex","WebinyError","markUnlockedFields"],"sources":["markLockedFields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsContext, CmsModelLockedFieldPlugin, LockedField } from \"~/types\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\n\ninterface MarkLockedFieldsParams {\n model: CmsModel;\n entry: CmsEntry;\n context: CmsContext;\n}\nexport const markLockedFields = async (params: MarkLockedFieldsParams): Promise<void> => {\n const { model, context } = params;\n /**\n * If the model is registered via a plugin, we don't need do process anything.\n */\n const plugins = context.plugins.byType<CmsModelPlugin>(CmsModelPlugin.type);\n if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {\n return;\n }\n\n const cmsLockedFieldPlugins =\n context.plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n const existingLockedFields = model.lockedFields || [];\n const lockedFields: LockedField[] = [];\n for (const field of model.fields) {\n const alreadyLocked = existingLockedFields.some(\n lockedField => lockedField.fieldId === field.storageId\n );\n if (alreadyLocked) {\n continue;\n }\n\n let lockedFieldData = {};\n\n const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === field.type);\n for (const plugin of lockedFieldPlugins) {\n if (typeof plugin.getLockedFieldData !== \"function\") {\n continue;\n }\n const data = plugin.getLockedFieldData({\n field\n });\n lockedFieldData = { ...lockedFieldData, ...data };\n }\n\n lockedFields.push({\n fieldId: field.storageId,\n multipleValues: !!field.multipleValues,\n type: field.type,\n ...lockedFieldData\n });\n }\n // no need to update anything if no locked fields were added\n if (lockedFields.length === 0) {\n return;\n }\n\n const newLockedFields = existingLockedFields.concat(lockedFields);\n\n try {\n await context.cms.updateModelDirect({\n original: model,\n model: {\n ...model,\n lockedFields: newLockedFields\n }\n });\n model.lockedFields = newLockedFields;\n } catch (ex) {\n throw new WebinyError(\n `Could not update model \"${model.modelId}\" with new locked fields.`,\n \"MODEL_LOCKED_FIELDS_UPDATE_FAILED\",\n ex\n );\n }\n};\n\nexport interface MarkFieldsUnlockedParams {\n context: CmsContext;\n model: CmsModel;\n}\nexport const markUnlockedFields = async (params: MarkFieldsUnlockedParams) => {\n const { context, model } = params;\n /**\n * If the model is registered via a plugin, we don't need do process anything.\n */\n const plugins = context.plugins.byType<CmsModelPlugin>(CmsModelPlugin.type);\n if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {\n return;\n }\n\n try {\n await context.cms.updateModelDirect({\n original: model,\n model: {\n ...model,\n lockedFields: []\n }\n });\n model.lockedFields = [];\n } catch (ex) {\n throw new WebinyError(\n `Could not update model \"${model.modelId}\" with unlocked fields.`,\n \"MODEL_UNLOCKED_FIELDS_UPDATE_FAILED\",\n ex\n );\n }\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAOO,MAAMA,gBAAgB,GAAG,MAAOC,MAAP,IAAyD;EACrF,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EACA;AACJ;AACA;;EACI,MAAMG,OAAO,GAAGD,OAAO,CAACC,OAAR,CAAgBC,MAAhB,CAAuCC,8BAAA,CAAeC,IAAtD,CAAhB;;EACA,IAAIH,OAAO,CAACI,IAAR,CAAaC,MAAM,IAAIA,MAAM,CAACC,YAAP,CAAoBC,OAApB,KAAgCT,KAAK,CAACS,OAA7D,CAAJ,EAA2E;IACvE;EACH;;EAED,MAAMC,qBAAqB,GACvBT,OAAO,CAACC,OAAR,CAAgBC,MAAhB,CAAkD,wBAAlD,CADJ;EAGA,MAAMQ,oBAAoB,GAAGX,KAAK,CAACY,YAAN,IAAsB,EAAnD;EACA,MAAMA,YAA2B,GAAG,EAApC;;EACA,KAAK,MAAMC,KAAX,IAAoBb,KAAK,CAACc,MAA1B,EAAkC;IAC9B,MAAMC,aAAa,GAAGJ,oBAAoB,CAACK,IAArB,CAClBC,WAAW,IAAIA,WAAW,CAACC,OAAZ,KAAwBL,KAAK,CAACM,SAD3B,CAAtB;;IAGA,IAAIJ,aAAJ,EAAmB;MACf;IACH;;IAED,IAAIK,eAAe,GAAG,EAAtB;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