@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.
- package/context.js +15 -0
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +5 -0
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +3 -0
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +3 -0
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +40 -1
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +25 -2
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +59 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +83 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.js +146 -55
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.js +2 -0
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.js +2 -0
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.js +2 -0
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.js +2 -0
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +32 -4
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +10 -0
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +5 -0
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/contentModelManagerFactory.js +7 -0
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldModels.js +6 -0
- package/crud/contentModel/createFieldModels.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +2 -0
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/fieldIdValidation.js +5 -0
- package/crud/contentModel/fieldIdValidation.js.map +1 -1
- package/crud/contentModel/idValidation.js +5 -0
- package/crud/contentModel/idValidation.js.map +1 -1
- package/crud/contentModel/models.js +8 -1
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validateLayout.js +8 -0
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.js +8 -0
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.js +60 -8
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel.crud.js +96 -11
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.js +12 -0
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +8 -0
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +5 -0
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup.crud.js +47 -10
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/index.js +16 -0
- package/crud/index.js.map +1 -1
- package/crud/settings.crud.js +12 -0
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +37 -2
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +13 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +53 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +4 -0
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.js +9 -5
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +28 -3
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.js +8 -1
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +9 -1
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +42 -2
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +19 -2
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +18 -2
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +21 -3
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +26 -0
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +17 -2
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +10 -0
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +10 -0
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.js +13 -1
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -0
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +3 -0
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +3 -0
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +6 -0
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +16 -0
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -0
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -0
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +3 -0
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +3 -0
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +8 -0
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +3 -0
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +8 -0
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +3 -0
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +19 -5
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +14 -1
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +12 -0
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +17 -0
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/file.js +8 -0
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +10 -0
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +11 -0
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +10 -0
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +16 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +137 -21
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +51 -17
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +9 -0
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +11 -0
- package/graphqlFields/text.js.map +1 -1
- package/index.js +19 -0
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +16 -0
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +4 -0
- package/modelManager/index.js.map +1 -1
- package/package.json +24 -24
- package/parameters/context.js +4 -0
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +11 -0
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +8 -0
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +8 -1
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +11 -0
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGroupPlugin.js +8 -0
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +5 -0
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.js +38 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +7 -0
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +1 -1
- package/plugins/StorageTransformPlugin.js +9 -0
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.js +10 -0
- package/plugins/index.js.map +1 -1
- package/storage/default.js +3 -0
- package/storage/default.js.map +1 -1
- package/storage/object.js +18 -0
- package/storage/object.js.map +1 -1
- package/types.d.ts +9 -1
- package/types.js +62 -0
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +26 -3
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +3 -0
- package/upgrades/index.js.map +1 -1
- package/utils/access.js +25 -11
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +13 -0
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +32 -9
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +26 -0
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeName.js +8 -0
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +26 -10
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +5 -0
- package/utils/filterAsync.js.map +1 -1
- package/utils/filterModelFields.js +9 -3
- package/utils/filterModelFields.js.map +1 -1
- package/utils/getEntryTitle.js +9 -0
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.js +6 -2
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/ownership.js +8 -0
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +23 -8
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +6 -0
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.js +8 -0
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +11 -0
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +8 -0
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +11 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +7 -0
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +4 -0
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +7 -0
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +7 -0
- package/validators/dateLte.js.map +1 -1
- package/validators/gte.js +8 -0
- package/validators/gte.js.map +1 -1
- package/validators/in.js +8 -0
- package/validators/in.js.map +1 -1
- package/validators/index.js +15 -0
- package/validators/index.js.map +1 -1
- package/validators/lte.js +8 -0
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +8 -0
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +8 -0
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +9 -0
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +2 -0
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +8 -0
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +2 -0
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +2 -0
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +2 -0
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +2 -0
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +2 -0
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +5 -0
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +8 -0
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +8 -0
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +7 -0
- 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":"
|
|
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":"
|
|
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":"
|
|
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":"
|
|
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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,MAAMlC,aAAmC,GAAGC,OAAO,CAACkC,OAAO,CACtDC,MAAM,CAA+B,2BAA2B,CAAC,CACjEC,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,KAAK;IACrB,MAAMjC,IAAI,GAAGiC,MAAM,CAAC5B,SAAS,CAACL,IAAI;IAClC,IAAI,CAACgC,GAAG,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,OAClBC,IADkB,EAElBC,eAFkB,EAGlBC,KAHkB,KAIO;EACzB,IAAI,CAACD,eAAL,EAAsB;IAClB,OAAO,IAAP;EACH;;EAED,MAAM;IAAEE,aAAF;IAAiBC,OAAjB;IAA0BC,KAA1B;IAAiCC,KAAjC;IAAwCC;EAAxC,IAAkDP,IAAxD;;EACA,IAAI;IACA,KAAK,MAAMQ,cAAX,IAA6BP,eAA7B,EAA8C;MAC1C,MAAMQ,IAAI,GAAGD,cAAc,CAACC,IAA5B;MACA,MAAMC,WAAW,GAAGP,aAAa,CAACM,IAAD,CAAjC;;MACA,IAAI,CAACC,WAAD,IAAgBA,WAAW,CAACC,MAAZ,KAAuB,CAA3C,EAA8C;QAC1C,OAAQ,iBAAgBF,IAAK,uBAA7B;MACH;;MACD,KAAK,MAAMG,QAAX,IAAuBF,WAAvB,EAAoC;QAChC,MAAMG,MAAM,GAAG,MAAMD,QAAQ,CAAC;UAC1BV,KAD0B;UAE1BE,OAF0B;UAG1BU,SAAS,EAAEN,cAHe;UAI1BH,KAJ0B;UAK1BC,KAL0B;UAM1BC;QAN0B,CAAD,CAA7B;;QAQA,IAAI,CAACM,MAAL,EAAa;UACT,OAAOL,cAAc,CAACO,OAAtB;QACH;MACJ;IACJ;EACJ,CArBD,CAqBE,OAAOC,EAAP,EAAW;IACT,OAAOA,EAAE,CAACD,OAAV;EACH;;EAED,OAAO,IAAP;AACH,CApCD;;AAsCA,MAAME,uBAAuB,GAAG,CAACZ,KAAD,EAAuBH,KAAvB,KAA6D;EACzF,MAAM;IAAEgB,OAAO,GAAG,KAAZ;IAAmBC,MAAM,EAAEC,gBAAgB,G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AhC;IAEA,OAAO6B,GAAP;EACH,CAVuC,EAUrC,EAVqC,CAA5C;EAYA;AACJ;AACA;AACA;;EACI,MAAMG,aAAa,GAAG,EAAtB;;EACA,KAAK,MAAMvC,KAAX,IAAoBC,KAAK,CAACuC,MAA1B,EAAkC;IAC9B,MAAMZ,KAAK,GAAG,MAAMC,cAAc,CAAC;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
|
-
|
|
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":"
|
|
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":";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