@webiny/api-headless-cms 0.0.0-unstable.40876133bb → 0.0.0-unstable.60e968001a
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.d.ts +5 -2
- package/context.js +63 -4
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +5 -2
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +9 -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 +65 -40
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +5 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/models.js +12 -0
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/validateModelFields.js +46 -37
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +109 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +227 -175
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +43 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +54 -54
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +239 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +3 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +2 -2
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +58 -28
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +49 -38
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +2 -2
- package/graphql/schema/baseContentSchema.js +3 -3
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.d.ts +2 -2
- package/graphql/schema/contentEntries.js +5 -5
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +2 -2
- package/graphql/schema/contentModelGroups.js +3 -3
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +2 -2
- package/graphql/schema/contentModels.js +26 -7
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +23 -7
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +9 -6
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +5 -0
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +2 -0
- package/graphql/schema/createReadSDL.js +11 -5
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +2 -2
- package/graphql/schema/schemaPlugins.js +11 -8
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +79 -82
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +234 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +79 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +21 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +3 -1
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/number.js +4 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +122 -72
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +34 -48
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -8
- package/index.js.map +1 -1
- package/package.json +26 -26
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +17 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +38 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +26 -0
- package/plugins/index.js.map +1 -1
- package/storage/object.js +5 -2
- package/storage/object.js.map +1 -1
- package/types.d.ts +203 -55
- package/types.js +55 -7
- package/types.js.map +1 -1
- package/utils/converters/ConverterCollection.js +6 -2
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +75 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +3 -1
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +15 -12
- package/utils/entryStorage.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +12 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/renderFields.js +3 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +8 -3
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +3 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +5 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +23 -4
- package/utils/renderSortEnum.js.map +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +24 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/index.js +3 -1
- package/validators/index.js.map +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -85
- package/crud/index.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
package/context.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { CmsContext } from "./types";
|
|
1
|
+
import { CmsContext, HeadlessCmsStorageOperations } from "./types";
|
|
2
2
|
import { ContextPlugin } from "@webiny/api";
|
|
3
|
-
export
|
|
3
|
+
export interface CrudParams {
|
|
4
|
+
storageOperations: HeadlessCmsStorageOperations;
|
|
5
|
+
}
|
|
6
|
+
export declare const createContextPlugin: ({ storageOperations }: CrudParams) => ContextPlugin<CmsContext>;
|
package/context.js
CHANGED
|
@@ -15,6 +15,16 @@ var _api = require("@webiny/api");
|
|
|
15
15
|
|
|
16
16
|
var _CmsParametersPlugin = require("./plugins/CmsParametersPlugin");
|
|
17
17
|
|
|
18
|
+
var _system = require("./crud/system.crud");
|
|
19
|
+
|
|
20
|
+
var _settings = require("./crud/settings.crud");
|
|
21
|
+
|
|
22
|
+
var _contentModelGroup = require("./crud/contentModelGroup.crud");
|
|
23
|
+
|
|
24
|
+
var _contentModel = require("./crud/contentModel.crud");
|
|
25
|
+
|
|
26
|
+
var _contentEntry = require("./crud/contentEntry.crud");
|
|
27
|
+
|
|
18
28
|
const getParameters = async context => {
|
|
19
29
|
const plugins = context.plugins.byType(_CmsParametersPlugin.CmsParametersPlugin.type);
|
|
20
30
|
|
|
@@ -29,7 +39,9 @@ const getParameters = async context => {
|
|
|
29
39
|
throw new _error.default("Could not determine locale and/or type of the CMS.", "CMS_LOCALE_AND_TYPE_ERROR");
|
|
30
40
|
};
|
|
31
41
|
|
|
32
|
-
const createContextPlugin = (
|
|
42
|
+
const createContextPlugin = ({
|
|
43
|
+
storageOperations
|
|
44
|
+
}) => {
|
|
33
45
|
return new _api.ContextPlugin(async context => {
|
|
34
46
|
const {
|
|
35
47
|
type,
|
|
@@ -46,14 +58,61 @@ const createContextPlugin = () => {
|
|
|
46
58
|
return systemLocale;
|
|
47
59
|
};
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
const getIdentity = () => {
|
|
62
|
+
return context.security.getIdentity();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getTenant = () => {
|
|
66
|
+
return context.tenancy.getCurrentTenant();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (storageOperations.beforeInit) {
|
|
70
|
+
await storageOperations.beforeInit(context);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
context.cms = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
50
74
|
type,
|
|
51
75
|
locale,
|
|
52
76
|
getLocale,
|
|
53
77
|
READ: type === "read",
|
|
54
78
|
PREVIEW: type === "preview",
|
|
55
|
-
MANAGE: type === "manage"
|
|
56
|
-
|
|
79
|
+
MANAGE: type === "manage",
|
|
80
|
+
storageOperations
|
|
81
|
+
}, (0, _system.createSystemCrud)({
|
|
82
|
+
context,
|
|
83
|
+
getTenant,
|
|
84
|
+
getLocale,
|
|
85
|
+
getIdentity,
|
|
86
|
+
storageOperations
|
|
87
|
+
})), (0, _settings.createSettingsCrud)({
|
|
88
|
+
context,
|
|
89
|
+
getTenant,
|
|
90
|
+
getLocale,
|
|
91
|
+
storageOperations
|
|
92
|
+
})), (0, _contentModelGroup.createModelGroupsCrud)({
|
|
93
|
+
context,
|
|
94
|
+
getTenant,
|
|
95
|
+
getLocale,
|
|
96
|
+
getIdentity,
|
|
97
|
+
storageOperations
|
|
98
|
+
})), (0, _contentModel.createModelsCrud)({
|
|
99
|
+
context,
|
|
100
|
+
getLocale,
|
|
101
|
+
getTenant,
|
|
102
|
+
getIdentity,
|
|
103
|
+
storageOperations
|
|
104
|
+
})), (0, _contentEntry.createContentEntryCrud)({
|
|
105
|
+
context,
|
|
106
|
+
getIdentity,
|
|
107
|
+
getTenant,
|
|
108
|
+
storageOperations
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
if (!storageOperations.init) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await storageOperations.init(context);
|
|
57
116
|
});
|
|
58
117
|
};
|
|
59
118
|
|
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 \"
|
|
1
|
+
{"version":3,"names":["getParameters","context","plugins","byType","CmsParametersPlugin","type","plugin","result","WebinyError","createContextPlugin","storageOperations","ContextPlugin","locale","getLocale","systemLocale","i18n","getIdentity","security","getTenant","tenancy","getCurrentTenant","beforeInit","cms","READ","PREVIEW","MANAGE","createSystemCrud","createSettingsCrud","createModelGroupsCrud","createModelsCrud","createContentEntryCrud","init"],"sources":["context.ts"],"sourcesContent":["import { CmsContext, HeadlessCmsStorageOperations } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { CmsParametersPlugin, CmsParametersPluginResponse } from \"~/plugins/CmsParametersPlugin\";\nimport { createSystemCrud } from \"~/crud/system.crud\";\nimport { createSettingsCrud } from \"~/crud/settings.crud\";\nimport { createModelGroupsCrud } from \"~/crud/contentModelGroup.crud\";\nimport { createModelsCrud } from \"~/crud/contentModel.crud\";\nimport { createContentEntryCrud } from \"~/crud/contentEntry.crud\";\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 interface CrudParams {\n storageOperations: HeadlessCmsStorageOperations;\n}\n\nexport const createContextPlugin = ({ storageOperations }: CrudParams) => {\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 const getIdentity = () => {\n return context.security.getIdentity();\n };\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n if (storageOperations.beforeInit) {\n await storageOperations.beforeInit(context);\n }\n\n context.cms = {\n type,\n locale,\n getLocale,\n READ: type === \"read\",\n PREVIEW: type === \"preview\",\n MANAGE: type === \"manage\",\n storageOperations,\n ...createSystemCrud({\n context,\n getTenant,\n getLocale,\n getIdentity,\n storageOperations\n }),\n ...createSettingsCrud({\n context,\n getTenant,\n getLocale,\n storageOperations\n }),\n ...createModelGroupsCrud({\n context,\n getTenant,\n getLocale,\n getIdentity,\n storageOperations\n }),\n ...createModelsCrud({\n context,\n getLocale,\n getTenant,\n getIdentity,\n storageOperations\n }),\n ...createContentEntryCrud({\n context,\n getIdentity,\n getTenant,\n storageOperations\n })\n };\n\n if (!storageOperations.init) {\n return;\n }\n await storageOperations.init(context);\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;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;;AAmBO,MAAMC,mBAAmB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuC;EACtE,OAAO,IAAIC,kBAAJ,CAA8B,MAAMV,OAAN,IAAiB;IAClD,MAAM;MAAEI,IAAF;MAAQO;IAAR,IAAmB,MAAMZ,aAAa,CAACC,OAAD,CAA5C;;IAEA,MAAMY,SAAS,GAAG,MAAM;MACpB,MAAMC,YAAY,GAAGb,OAAO,CAACc,IAAR,CAAaF,SAAb,CAAuBD,MAAvB,CAArB;;MACA,IAAI,CAACE,YAAL,EAAmB;QACf,MAAM,IAAIN,cAAJ,CAAiB,uBAAsBI,MAAO,kBAA9C,CAAN;MACH;;MACD,OAAOE,YAAP;IACH,CAND;;IAQA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13,6 +13,8 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
13
13
|
|
|
14
14
|
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
15
15
|
|
|
16
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
17
|
+
|
|
16
18
|
const markLockedFields = async params => {
|
|
17
19
|
const {
|
|
18
20
|
model,
|
|
@@ -33,6 +35,7 @@ const markLockedFields = async params => {
|
|
|
33
35
|
const lockedFields = [];
|
|
34
36
|
|
|
35
37
|
for (const field of model.fields) {
|
|
38
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
36
39
|
const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.storageId);
|
|
37
40
|
|
|
38
41
|
if (alreadyLocked) {
|
|
@@ -40,7 +43,7 @@ const markLockedFields = async params => {
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
let lockedFieldData = {};
|
|
43
|
-
const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType ===
|
|
46
|
+
const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === baseType);
|
|
44
47
|
|
|
45
48
|
for (const plugin of lockedFieldPlugins) {
|
|
46
49
|
if (typeof plugin.getLockedFieldData !== "function") {
|
|
@@ -56,7 +59,7 @@ const markLockedFields = async params => {
|
|
|
56
59
|
lockedFields.push((0, _objectSpread2.default)({
|
|
57
60
|
fieldId: field.storageId,
|
|
58
61
|
multipleValues: !!field.multipleValues,
|
|
59
|
-
type:
|
|
62
|
+
type: baseType
|
|
60
63
|
}, lockedFieldData));
|
|
61
64
|
} // no need to update anything if no locked fields were added
|
|
62
65
|
|
|
@@ -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 ===
|
|
1
|
+
{"version":3,"names":["markLockedFields","params","model","context","plugins","byType","CmsModelPlugin","type","find","plugin","contentModel","modelId","cmsLockedFieldPlugins","existingLockedFields","lockedFields","field","fields","baseType","getBaseFieldType","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\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\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 baseType = getBaseFieldType(field);\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 === baseType);\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: baseType,\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;;AACA;;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,QAAQ,GAAG,IAAAC,kCAAA,EAAiBH,KAAjB,CAAjB;IACA,MAAMI,aAAa,GAAGN,oBAAoB,CAACO,IAArB,CAClBC,WAAW,IAAIA,WAAW,CAACC,OAAZ,KAAwBP,KAAK,CAACQ,SAD3B,CAAtB;;IAGA,IAAIJ,aAAJ,EAAmB;MACf;IACH;;IAED,IAAIK,eAAe,GAAG,EAAtB;IAEA,MAA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AhB,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,IAAI;IACA,MAAMR,OAAO,CAACiC,GAAR,CAAYC,iBAAZ,CAA8B;MAChCC,QAAQ,EAAEpC,KADsB;MAEhCA,KAAK,8DACEA,KADF;QAEDY,YAAY,EAAE;MAFb;IAF2B,CAA9B,CAAN;IAOAZ,KAAK,CAACY,YAAN,GAAqB,EAArB;EACH,CATD,CASE,OAAOyB,EAAP,EAAW;IACT,MAAM,IAAIC,cAAJ,CACD,2BAA0BtC,KAAK,CAACS,OAAQ,yBADvC,EAEF,qCAFE,EAGF4B,EAHE,CAAN;EAKH;AACJ,CA1BM"}
|
|
@@ -15,6 +15,8 @@ var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
|
15
15
|
|
|
16
16
|
var _utils = require("@webiny/utils");
|
|
17
17
|
|
|
18
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
19
|
+
|
|
18
20
|
const buildReferenceFieldPaths = params => {
|
|
19
21
|
const {
|
|
20
22
|
fields,
|
|
@@ -23,13 +25,15 @@ const buildReferenceFieldPaths = params => {
|
|
|
23
25
|
} = params;
|
|
24
26
|
const parentPaths = [...initialParentPaths];
|
|
25
27
|
const isMultipleValues = Array.isArray(input);
|
|
26
|
-
return fields.filter(field => ["object", "ref"].includes(
|
|
28
|
+
return fields.filter(field => ["object", "ref"].includes((0, _getBaseFieldType.getBaseFieldType)(field))).reduce((collection, field) => {
|
|
27
29
|
var _field$settings2;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* First we check the ref field
|
|
31
33
|
*/
|
|
32
|
-
|
|
34
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
35
|
+
|
|
36
|
+
if (baseType === "ref") {
|
|
33
37
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
34
38
|
|
|
35
39
|
if (field.multipleValues) {
|
|
@@ -193,7 +197,7 @@ const referenceFieldsMapping = async params => {
|
|
|
193
197
|
const models = (await context.cms.listModels()).filter(model => {
|
|
194
198
|
const entries = referencesByModel[model.modelId];
|
|
195
199
|
|
|
196
|
-
if (Array.isArray(entries)
|
|
200
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
197
201
|
return false;
|
|
198
202
|
}
|
|
199
203
|
|
|
@@ -236,7 +240,7 @@ const referenceFieldsMapping = async params => {
|
|
|
236
240
|
for (const id of entries) {
|
|
237
241
|
if (records[id]) {
|
|
238
242
|
continue;
|
|
239
|
-
} else if (validateEntries
|
|
243
|
+
} else if (validateEntries) {
|
|
240
244
|
throw new _error.default(`Missing referenced entry with id "${id}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
|
|
241
245
|
id,
|
|
242
246
|
model: modelId
|
|
@@ -263,7 +267,7 @@ const referenceFieldsMapping = async params => {
|
|
|
263
267
|
const paths = pathsByReferenceId[id];
|
|
264
268
|
|
|
265
269
|
if (!entry) {
|
|
266
|
-
if (validateEntries
|
|
270
|
+
if (validateEntries) {
|
|
267
271
|
throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
|
|
268
272
|
id,
|
|
269
273
|
paths
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["buildReferenceFieldPaths","params","fields","parentPaths","initialParentPaths","input","isMultipleValues","Array","isArray","filter","field","includes","type","reduce","collection","parentPathsValue","length","join","multipleValues","inputValue","dotProp","get","fieldId","key","path","push","objFieldPath","objFieldInputValue","result","settings","concat","results","getReferenceFieldValue","ref","id","modelId","entryId","trim","referenceFieldsMapping","context","model","validateEntries","output","referenceFieldPaths","referencesByModel","pathsByReferenceId","Object","keys","models","cms","listModels","entries","promises","map","getEntriesByIds","Promise","all","records","entry","WebinyError","parseIdentifier","paths","set"],"sources":["referenceFieldsMapping.ts"],"sourcesContent":["import { CmsContext, CmsModel, CmsModelField } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport dotProp from \"dot-prop\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\ninterface CmsRefEntry {\n id: string;\n entryId: string;\n modelId: string;\n}\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface Params {\n context: CmsContext;\n model: CmsModel;\n input: Record<string, ReferenceObject | ReferenceObject[]>;\n validateEntries?: boolean;\n}\n\ninterface BuildReferenceFieldPaths {\n fields: CmsModelField[];\n parentPaths: string[];\n input: Record<string, any>;\n}\n\nconst buildReferenceFieldPaths = (params: BuildReferenceFieldPaths): string[] => {\n const { fields, parentPaths: initialParentPaths, input } = params;\n\n const parentPaths = [...initialParentPaths];\n\n const isMultipleValues = Array.isArray(input);\n\n return fields\n .filter(field => [\"object\", \"ref\"].includes(field.type))\n .reduce((collection, field) => {\n /**\n * First we check the ref field\n */\n if (field.type === \"ref\") {\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n if (field.multipleValues) {\n const inputValue = dotProp.get(input, `${field.fieldId}`, []);\n if (Array.isArray(inputValue) === false) {\n return collection;\n }\n for (const key in inputValue) {\n const path = `${parentPathsValue}${field.fieldId}.${key}`;\n collection.push(path);\n }\n return collection;\n }\n\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n collection.push(`${parentPathsValue}${field.fieldId}`);\n\n return collection;\n }\n /**\n * Then we move onto the object field\n */\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n /**\n * This is if received input is array. We need to map key with fieldId at this point.\n */\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n const objFieldPath = `${field.fieldId}`;\n const objFieldInputValue = dotProp.get(input, objFieldPath, []);\n\n /**\n * If field is multiple values one, we need to go through the input and use the existing keys.\n */\n if (field.multipleValues) {\n if (Array.isArray(objFieldInputValue) === false) {\n return collection;\n }\n for (const key in objFieldInputValue) {\n const result = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue[key],\n parentPaths: parentPaths.concat([field.fieldId, key])\n });\n collection.push(...result);\n }\n\n return collection;\n }\n\n /**\n * Single value reference field.\n */\n const results = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue,\n parentPaths: parentPaths.concat([field.fieldId])\n });\n\n return collection.concat(results);\n }, [] as string[]);\n};\n\nconst getReferenceFieldValue = (ref: any): { id: string | null; modelId: string | null } => {\n if (!ref) {\n return {\n id: null,\n modelId: null\n };\n }\n return {\n id: (ref.id || ref.entryId || \"\").trim() || null,\n modelId: (ref.modelId || \"\").trim() || null\n };\n};\n\nexport const referenceFieldsMapping = async (params: Params): Promise<Record<string, any>> => {\n const { context, model, input, validateEntries = false } = params;\n\n let output: Record<string, any> = {\n ...input\n };\n\n const referenceFieldPaths = buildReferenceFieldPaths({\n fields: model.fields,\n input,\n parentPaths: []\n });\n if (referenceFieldPaths.length === 0) {\n return output;\n }\n\n const referencesByModel: Record<string, string[]> = {};\n const pathsByReferenceId: Record<string, string[]> = {};\n\n for (const path of referenceFieldPaths) {\n const ref = dotProp.get(output, path) as ReferenceObject | any;\n\n const { id, modelId } = getReferenceFieldValue(ref);\n\n if (!id || !modelId) {\n continue;\n }\n if (!referencesByModel[modelId]) {\n referencesByModel[modelId] = [];\n }\n referencesByModel[modelId].push(id);\n if (!pathsByReferenceId[id]) {\n pathsByReferenceId[id] = [];\n }\n pathsByReferenceId[id].push(path);\n }\n\n /**\n * Again, no point in going further.\n */\n if (Object.keys(referencesByModel).length === 0) {\n return output;\n }\n /**\n * Load all models and use only those that are used in reference.\n */\n const models = (await context.cms.listModels()).filter(model => {\n const entries = referencesByModel[model.modelId];\n if (Array.isArray(entries) === false || entries.length === 0) {\n return false;\n }\n return true;\n });\n /**\n * Check for any model existence, just in case.\n */\n if (models.length === 0) {\n return output;\n }\n\n /**\n * Load all the entries by their ID\n */\n const promises = models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);\n });\n\n const results = await Promise.all(promises);\n\n const records: Record<string, CmsRefEntry> = results.reduce((collection, entries) => {\n for (const entry of entries) {\n collection[entry.id] = {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId\n };\n }\n return collection;\n }, {} as Record<string, CmsRefEntry>);\n /**\n * Verify that all referenced entries actually exist.\n */\n for (const modelId in referencesByModel) {\n const entries = referencesByModel[modelId];\n for (const id of entries) {\n if (records[id]) {\n continue;\n } else if (validateEntries === true) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n const { id: entryId } = parseIdentifier(id);\n records[id] = {\n id,\n entryId,\n modelId\n };\n }\n }\n\n /**\n * In the end, assign the entryId, id and model values to the output.\n */\n for (const id in pathsByReferenceId) {\n const entry = records[id];\n const paths = pathsByReferenceId[id];\n if (!entry) {\n if (validateEntries === true) {\n throw new WebinyError(\"Missing entry in records.\", \"ENTRY_ERROR\", {\n id,\n paths\n });\n }\n continue;\n }\n for (const path of paths) {\n output = dotProp.set(output, path, {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId\n });\n }\n }\n\n return output;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AA0BA,MAAMA,wBAAwB,GAAIC,MAAD,IAAgD;EAC7E,MAAM;IAAEC,MAAF;IAAUC,WAAW,EAAEC,kBAAvB;IAA2CC;EAA3C,IAAqDJ,MAA3D;EAEA,MAAME,WAAW,GAAG,CAAC,GAAGC,kBAAJ,CAApB;EAEA,MAAME,gBAAgB,GAAGC,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAzB;EAEA,OAAOH,MAAM,CACRO,M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D,CAArB;IACA,MAAM2B,KAAK,GAAGhB,kBAAkB,CAACX,EAAD,CAAhC;;IACA,IAAI,CAACwB,KAAL,EAAY;MACR,IAAIjB,eAAe,KAAK,IAAxB,EAA8B;QAC1B,MAAM,IAAIkB,cAAJ,CAAgB,2BAAhB,EAA6C,aAA7C,EAA4D;UAC9DzB,EAD8D;UAE9D2B;QAF8D,CAA5D,CAAN;MAIH;;MACD;IACH;;IACD,KAAK,MAAMrC,IAAX,IAAmBqC,KAAnB,EAA0B;MACtBnB,MAAM,GAAGtB,gBAAA,CAAQ0C,GAAR,CAAYpB,MAAZ,EAAoBlB,IAApB,EAA0B;QAC/BU,EAAE,EAAEwB,KAAK,CAACxB,EADqB;QAE/BE,OAAO,EAAEsB,KAAK,CAACtB,OAFgB;QAG/BD,OAAO,EAAEuB,KAAK,CAACvB;MAHgB,CAA1B,CAAT;IAKH;EACJ;;EAED,OAAOO,MAAP;AACH,CAnIM"}
|
|
1
|
+
{"version":3,"names":["buildReferenceFieldPaths","params","fields","parentPaths","initialParentPaths","input","isMultipleValues","Array","isArray","filter","field","includes","getBaseFieldType","reduce","collection","baseType","parentPathsValue","length","join","multipleValues","inputValue","dotProp","get","fieldId","key","path","push","objFieldPath","objFieldInputValue","result","settings","concat","results","getReferenceFieldValue","ref","id","modelId","entryId","trim","referenceFieldsMapping","context","model","validateEntries","output","referenceFieldPaths","referencesByModel","pathsByReferenceId","Object","keys","models","cms","listModels","entries","promises","map","getEntriesByIds","Promise","all","records","entry","WebinyError","parseIdentifier","paths","set"],"sources":["referenceFieldsMapping.ts"],"sourcesContent":["import { CmsContext, CmsModel, CmsModelField } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport dotProp from \"dot-prop\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface CmsRefEntry {\n id: string;\n entryId: string;\n modelId: string;\n}\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface Params {\n context: CmsContext;\n model: CmsModel;\n input: Record<string, ReferenceObject | ReferenceObject[]>;\n validateEntries?: boolean;\n}\n\ninterface BuildReferenceFieldPaths {\n fields: CmsModelField[];\n parentPaths: string[];\n input: Record<string, any>;\n}\n\nconst buildReferenceFieldPaths = (params: BuildReferenceFieldPaths): string[] => {\n const { fields, parentPaths: initialParentPaths, input } = params;\n\n const parentPaths = [...initialParentPaths];\n\n const isMultipleValues = Array.isArray(input);\n\n return fields\n .filter(field => [\"object\", \"ref\"].includes(getBaseFieldType(field)))\n .reduce((collection, field) => {\n /**\n * First we check the ref field\n */\n const baseType = getBaseFieldType(field);\n if (baseType === \"ref\") {\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n if (field.multipleValues) {\n const inputValue = dotProp.get(input, `${field.fieldId}`, []);\n if (Array.isArray(inputValue) === false) {\n return collection;\n }\n for (const key in inputValue) {\n const path = `${parentPathsValue}${field.fieldId}.${key}`;\n collection.push(path);\n }\n return collection;\n }\n\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n collection.push(`${parentPathsValue}${field.fieldId}`);\n\n return collection;\n }\n /**\n * Then we move onto the object field\n */\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n /**\n * This is if received input is array. We need to map key with fieldId at this point.\n */\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n const objFieldPath = `${field.fieldId}`;\n const objFieldInputValue = dotProp.get(input, objFieldPath, []);\n\n /**\n * If field is multiple values one, we need to go through the input and use the existing keys.\n */\n if (field.multipleValues) {\n if (Array.isArray(objFieldInputValue) === false) {\n return collection;\n }\n for (const key in objFieldInputValue) {\n const result = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue[key],\n parentPaths: parentPaths.concat([field.fieldId, key])\n });\n collection.push(...result);\n }\n\n return collection;\n }\n\n /**\n * Single value reference field.\n */\n const results = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue,\n parentPaths: parentPaths.concat([field.fieldId])\n });\n\n return collection.concat(results);\n }, [] as string[]);\n};\n\nconst getReferenceFieldValue = (ref: any): { id: string | null; modelId: string | null } => {\n if (!ref) {\n return {\n id: null,\n modelId: null\n };\n }\n return {\n id: (ref.id || ref.entryId || \"\").trim() || null,\n modelId: (ref.modelId || \"\").trim() || null\n };\n};\n\nexport const referenceFieldsMapping = async (params: Params): Promise<Record<string, any>> => {\n const { context, model, input, validateEntries = false } = params;\n\n let output: Record<string, any> = {\n ...input\n };\n\n const referenceFieldPaths = buildReferenceFieldPaths({\n fields: model.fields,\n input,\n parentPaths: []\n });\n if (referenceFieldPaths.length === 0) {\n return output;\n }\n\n const referencesByModel: Record<string, string[]> = {};\n const pathsByReferenceId: Record<string, string[]> = {};\n\n for (const path of referenceFieldPaths) {\n const ref = dotProp.get(output, path) as ReferenceObject | any;\n\n const { id, modelId } = getReferenceFieldValue(ref);\n\n if (!id || !modelId) {\n continue;\n }\n if (!referencesByModel[modelId]) {\n referencesByModel[modelId] = [];\n }\n referencesByModel[modelId].push(id);\n if (!pathsByReferenceId[id]) {\n pathsByReferenceId[id] = [];\n }\n pathsByReferenceId[id].push(path);\n }\n\n /**\n * Again, no point in going further.\n */\n if (Object.keys(referencesByModel).length === 0) {\n return output;\n }\n /**\n * Load all models and use only those that are used in reference.\n */\n const models = (await context.cms.listModels()).filter(model => {\n const entries = referencesByModel[model.modelId];\n if (!Array.isArray(entries) || entries.length === 0) {\n return false;\n }\n return true;\n });\n /**\n * Check for any model existence, just in case.\n */\n if (models.length === 0) {\n return output;\n }\n\n /**\n * Load all the entries by their ID\n */\n const promises = models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);\n });\n\n const results = await Promise.all(promises);\n\n const records: Record<string, CmsRefEntry> = results.reduce((collection, entries) => {\n for (const entry of entries) {\n collection[entry.id] = {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId\n };\n }\n return collection;\n }, {} as Record<string, CmsRefEntry>);\n /**\n * Verify that all referenced entries actually exist.\n */\n for (const modelId in referencesByModel) {\n const entries = referencesByModel[modelId];\n for (const id of entries) {\n if (records[id]) {\n continue;\n } else if (validateEntries) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n const { id: entryId } = parseIdentifier(id);\n records[id] = {\n id,\n entryId,\n modelId\n };\n }\n }\n\n /**\n * In the end, assign the entryId, id and model values to the output.\n */\n for (const id in pathsByReferenceId) {\n const entry = records[id];\n const paths = pathsByReferenceId[id];\n if (!entry) {\n if (validateEntries) {\n throw new WebinyError(\"Missing entry in records.\", \"ENTRY_ERROR\", {\n id,\n paths\n });\n }\n continue;\n }\n for (const path of paths) {\n output = dotProp.set(output, path, {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId\n });\n }\n }\n\n return output;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;AA0BA,MAAMA,wBAAwB,GAAIC,MAAD,IAAgD;EAC7E,MAAM;IAAEC,MAAF;IAAUC,WAAW,EAAEC,kBAAvB;IAA2CC;EAA3C,IAAqDJ,MAA3D;EAEA,MAAME,WAAW,GAAG,CAAC,GAAGC,kBAAJ,CAApB;EAEA,MAAME,gBAAgB,GAAGC,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAzB;EAEA,OAAOH,MAAM,CACRO,MADE,CACKC,KAAK,IAAI,CAAC,QAAD,EAAW,KAAX,EAAkBC,QAAlB,CAA2B,IAAAC,kCAAA,EAAiBF,KAAjB,CAA3B,CADd,EAEFG,MAFE,CAEK,CAACC,UAAD,EAAaJ,KAAb,KAAuB;IAAA;;IAC3B;AACZ;AACA;IACY,MAAMK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CAAgB,2BAAhB,EAA6C,aAA7C,EAA4D;UAC9DzB,EAD8D;UAE9D2B;QAF8D,CAA5D,CAAN;MAIH;;MACD;IACH;;IACD,KAAK,MAAMrC,IAAX,IAAmBqC,KAAnB,EAA0B;MACtBnB,MAAM,GAAGtB,gBAAA,CAAQ0C,GAAR,CAAYpB,MAAZ,EAAoBlB,IAApB,EAA0B;QAC/BU,EAAE,EAAEwB,KAAK,CAACxB,EADqB;QAE/BE,OAAO,EAAEsB,KAAK,CAACtB,OAFgB;QAG/BD,OAAO,EAAEuB,KAAK,CAACvB;MAHgB,CAA1B,CAAT;IAKH;EACJ;;EAED,OAAOO,MAAP;AACH,CAnIM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CmsModelField } from "../../types";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
interface Params {
|
|
4
|
+
input: string[];
|
|
5
|
+
fields: CmsModelField[];
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
}
|
|
8
|
+
export declare const getSearchableFields: (params: Params) => string[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSearchableFields = void 0;
|
|
7
|
+
|
|
8
|
+
const buildSearchableFieldList = params => {
|
|
9
|
+
const {
|
|
10
|
+
input,
|
|
11
|
+
plugins,
|
|
12
|
+
fields,
|
|
13
|
+
parents
|
|
14
|
+
} = params;
|
|
15
|
+
return fields.reduce((result, field) => {
|
|
16
|
+
var _field$settings;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* We need to check if the field is full text searchable, and for that we need a plugin for the field type.
|
|
20
|
+
*/
|
|
21
|
+
const plugin = plugins[field.type];
|
|
22
|
+
|
|
23
|
+
if (!plugin) {
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* There is a possibility that searchable fields exist in nested object field, so check that as well.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
|
|
32
|
+
|
|
33
|
+
if (childFields.length > 0) {
|
|
34
|
+
/**
|
|
35
|
+
* So we build a list of searchable child fields and push it into the main result set.
|
|
36
|
+
*/
|
|
37
|
+
const childResults = buildSearchableFieldList({
|
|
38
|
+
fields: childFields,
|
|
39
|
+
parents: [...parents, field.fieldId],
|
|
40
|
+
plugins,
|
|
41
|
+
input
|
|
42
|
+
});
|
|
43
|
+
result.push(...childResults);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* If not searchable, continue further.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if (!plugin.fullTextSearch) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Combine all parent paths with the current one and push it.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const path = [...parents, field.fieldId].join(".");
|
|
60
|
+
result.push(path);
|
|
61
|
+
return result;
|
|
62
|
+
}, []);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getSearchableFields = params => {
|
|
66
|
+
const {
|
|
67
|
+
plugins,
|
|
68
|
+
input,
|
|
69
|
+
fields
|
|
70
|
+
} = params;
|
|
71
|
+
const fieldPluginMap = plugins.byType("cms-model-field-to-graphql").reduce((collection, field) => {
|
|
72
|
+
collection[field.fieldType] = field;
|
|
73
|
+
return collection;
|
|
74
|
+
}, {});
|
|
75
|
+
return buildSearchableFieldList({
|
|
76
|
+
fields,
|
|
77
|
+
input,
|
|
78
|
+
plugins: fieldPluginMap,
|
|
79
|
+
parents: []
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.getSearchableFields = getSearchableFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["buildSearchableFieldList","params","input","plugins","fields","parents","reduce","result","field","plugin","type","childFields","settings","length","childResults","fieldId","push","fullTextSearch","path","join","getSearchableFields","fieldPluginMap","byType","collection","fieldType"],"sources":["searchableFields.ts"],"sourcesContent":["import { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface BuildParams {\n input: string[];\n fields: CmsModelField[];\n plugins: Record<string, CmsModelFieldToGraphQLPlugin>;\n parents: string[];\n}\nconst buildSearchableFieldList = (params: BuildParams): string[] => {\n const { input, plugins, fields, parents } = params;\n return fields.reduce<string[]>((result, field) => {\n /**\n * We need to check if the field is full text searchable, and for that we need a plugin for the field type.\n */\n const plugin = plugins[field.type];\n if (!plugin) {\n return result;\n }\n /**\n * There is a possibility that searchable fields exist in nested object field, so check that as well.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * So we build a list of searchable child fields and push it into the main result set.\n */\n const childResults = buildSearchableFieldList({\n fields: childFields,\n parents: [...parents, field.fieldId],\n plugins,\n input\n });\n\n result.push(...childResults);\n return result;\n }\n /**\n * If not searchable, continue further.\n */\n if (!plugin.fullTextSearch) {\n return result;\n }\n\n /**\n * Combine all parent paths with the current one and push it.\n */\n const path = [...parents, field.fieldId].join(\".\");\n result.push(path);\n\n return result;\n }, []);\n};\n\ninterface Params {\n input: string[];\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\nexport const getSearchableFields = (params: Params): string[] => {\n const { plugins, input, fields } = params;\n const fieldPluginMap = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((collection, field) => {\n collection[field.fieldType] = field;\n return collection;\n }, {} as Record<string, CmsModelFieldToGraphQLPlugin>);\n\n return buildSearchableFieldList({\n fields,\n input,\n plugins: fieldPluginMap,\n parents: []\n });\n};\n"],"mappings":";;;;;;;AASA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mB,MADkB,CACmB,4BADnB,EAElBhB,MAFkB,CAEX,CAACiB,UAAD,EAAaf,KAAb,KAAuB;IAC3Be,UAAU,CAACf,KAAK,CAACgB,SAAP,CAAV,GAA8BhB,KAA9B;IACA,OAAOe,UAAP;EACH,CALkB,EAKhB,EALgB,CAAvB;EAOA,OAAOvB,wBAAwB,CAAC;IAC5BI,MAD4B;IAE5BF,KAF4B;IAG5BC,OAAO,EAAEkB,cAHmB;IAI5BhB,OAAO,EAAE;EAJmB,CAAD,CAA/B;AAMH,CAfM"}
|
|
@@ -41,6 +41,8 @@ var _entryStorage = require("../utils/entryStorage");
|
|
|
41
41
|
|
|
42
42
|
var _valueKeyStorageConverter = require("../utils/converters/valueKeyStorageConverter");
|
|
43
43
|
|
|
44
|
+
var _searchableFields = require("./contentEntry/searchableFields");
|
|
45
|
+
|
|
44
46
|
/**
|
|
45
47
|
* Package mdbid does not have types.
|
|
46
48
|
*/
|
|
@@ -217,35 +219,6 @@ const increaseEntryIdVersion = id => {
|
|
|
217
219
|
};
|
|
218
220
|
};
|
|
219
221
|
|
|
220
|
-
const getSearchableFields = params => {
|
|
221
|
-
const {
|
|
222
|
-
plugins,
|
|
223
|
-
model,
|
|
224
|
-
fields
|
|
225
|
-
} = params;
|
|
226
|
-
const fieldPluginMap = plugins.byType("cms-model-field-to-graphql").reduce((collection, field) => {
|
|
227
|
-
collection[field.fieldType] = field;
|
|
228
|
-
return collection;
|
|
229
|
-
}, {});
|
|
230
|
-
return model.fields.filter(field => {
|
|
231
|
-
if (!field.fieldId) {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const plugin = fieldPluginMap[field.type];
|
|
236
|
-
|
|
237
|
-
if (!plugin) {
|
|
238
|
-
return false;
|
|
239
|
-
} else if (!plugin.fullTextSearch) {
|
|
240
|
-
return false;
|
|
241
|
-
} else if (!fields || fields.length === 0) {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return fields.includes(field.fieldId);
|
|
246
|
-
}).map(field => field.fieldId);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
222
|
const allowedEntryStatus = ["draft", "published", "unpublished"];
|
|
250
223
|
|
|
251
224
|
const transformEntryStatus = status => {
|
|
@@ -261,27 +234,45 @@ const createContentEntryCrud = params => {
|
|
|
261
234
|
} = params;
|
|
262
235
|
const {
|
|
263
236
|
plugins
|
|
264
|
-
} = context;
|
|
237
|
+
} = context;
|
|
238
|
+
/**
|
|
239
|
+
* Create
|
|
240
|
+
*/
|
|
265
241
|
|
|
266
242
|
const onEntryBeforeCreate = (0, _pubsub.createTopic)("cms.onEntryBeforeCreate");
|
|
267
243
|
const onEntryAfterCreate = (0, _pubsub.createTopic)("cms.onEntryAfterCreate");
|
|
268
|
-
const onEntryCreateError = (0, _pubsub.createTopic)("cms.onEntryCreateError");
|
|
244
|
+
const onEntryCreateError = (0, _pubsub.createTopic)("cms.onEntryCreateError");
|
|
245
|
+
/**
|
|
246
|
+
* Create new revision
|
|
247
|
+
*/
|
|
269
248
|
|
|
270
249
|
const onEntryBeforeCreateRevision = (0, _pubsub.createTopic)("cms.onEntryBeforeCreateRevision");
|
|
271
250
|
const onEntryRevisionAfterCreate = (0, _pubsub.createTopic)("cms.onEntryRevisionAfterCreate");
|
|
272
|
-
const onEntryCreateRevisionError = (0, _pubsub.createTopic)("cms.onEntryCreateRevisionError");
|
|
251
|
+
const onEntryCreateRevisionError = (0, _pubsub.createTopic)("cms.onEntryCreateRevisionError");
|
|
252
|
+
/**
|
|
253
|
+
* Update
|
|
254
|
+
*/
|
|
273
255
|
|
|
274
256
|
const onEntryBeforeUpdate = (0, _pubsub.createTopic)("cms.onEntryBeforeUpdate");
|
|
275
257
|
const onEntryAfterUpdate = (0, _pubsub.createTopic)("cms.onEntryAfterUpdate");
|
|
276
|
-
const onEntryUpdateError = (0, _pubsub.createTopic)("cms.onEntryUpdateError");
|
|
258
|
+
const onEntryUpdateError = (0, _pubsub.createTopic)("cms.onEntryUpdateError");
|
|
259
|
+
/**
|
|
260
|
+
* Publish
|
|
261
|
+
*/
|
|
277
262
|
|
|
278
263
|
const onEntryBeforePublish = (0, _pubsub.createTopic)("cms.onEntryBeforePublish");
|
|
279
264
|
const onEntryAfterPublish = (0, _pubsub.createTopic)("cms.onEntryAfterPublic");
|
|
280
|
-
const onEntryPublishError = (0, _pubsub.createTopic)("cms.onEntryPublishError");
|
|
265
|
+
const onEntryPublishError = (0, _pubsub.createTopic)("cms.onEntryPublishError");
|
|
266
|
+
/**
|
|
267
|
+
* Unpublish
|
|
268
|
+
*/
|
|
281
269
|
|
|
282
270
|
const onEntryBeforeUnpublish = (0, _pubsub.createTopic)("cms.onEntryBeforeUnpublish");
|
|
283
271
|
const onEntryAfterUnpublish = (0, _pubsub.createTopic)("cms.onEntryAfterUnpublish");
|
|
284
|
-
const onEntryUnpublishError = (0, _pubsub.createTopic)("cms.onEntryUnpublishError");
|
|
272
|
+
const onEntryUnpublishError = (0, _pubsub.createTopic)("cms.onEntryUnpublishError");
|
|
273
|
+
/**
|
|
274
|
+
* Delete
|
|
275
|
+
*/
|
|
285
276
|
|
|
286
277
|
const onEntryBeforeDelete = (0, _pubsub.createTopic)("cms.onEntryBeforeDelete");
|
|
287
278
|
const onEntryAfterDelete = (0, _pubsub.createTopic)("cms.onEntryAfterDelete");
|
|
@@ -391,25 +382,51 @@ const createContentEntryCrud = params => {
|
|
|
391
382
|
|
|
392
383
|
/**
|
|
393
384
|
* Released in 5.34.0
|
|
385
|
+
*
|
|
386
|
+
* Create
|
|
394
387
|
*/
|
|
395
388
|
onEntryBeforeCreate,
|
|
396
389
|
onEntryAfterCreate,
|
|
397
390
|
onEntryCreateError,
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Create revision
|
|
394
|
+
*/
|
|
398
395
|
onEntryRevisionBeforeCreate: onEntryBeforeCreateRevision,
|
|
399
396
|
onEntryRevisionAfterCreate,
|
|
400
397
|
onEntryRevisionCreateError: onEntryCreateRevisionError,
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Update
|
|
401
|
+
*/
|
|
401
402
|
onEntryBeforeUpdate,
|
|
402
403
|
onEntryAfterUpdate,
|
|
403
404
|
onEntryUpdateError,
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Delete whole entry
|
|
408
|
+
*/
|
|
404
409
|
onEntryBeforeDelete,
|
|
405
410
|
onEntryAfterDelete,
|
|
406
411
|
onEntryDeleteError,
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Delete entry revision
|
|
415
|
+
*/
|
|
407
416
|
onEntryRevisionBeforeDelete,
|
|
408
417
|
onEntryRevisionAfterDelete,
|
|
409
418
|
onEntryRevisionDeleteError,
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Publish
|
|
422
|
+
*/
|
|
410
423
|
onEntryBeforePublish,
|
|
411
424
|
onEntryAfterPublish,
|
|
412
425
|
onEntryPublishError,
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Unpublish
|
|
429
|
+
*/
|
|
413
430
|
onEntryBeforeUnpublish,
|
|
414
431
|
onEntryAfterUnpublish,
|
|
415
432
|
onEntryUnpublishError,
|
|
@@ -464,7 +481,7 @@ const createContentEntryCrud = params => {
|
|
|
464
481
|
},
|
|
465
482
|
|
|
466
483
|
/**
|
|
467
|
-
* Get latest revisions by entry IDs.
|
|
484
|
+
* Get the latest revisions by entry IDs.
|
|
468
485
|
*/
|
|
469
486
|
async getLatestEntriesByIds(initialModel, ids) {
|
|
470
487
|
const permission = await checkEntryPermissions({
|
|
@@ -540,8 +557,10 @@ const createContentEntryCrud = params => {
|
|
|
540
557
|
plugins
|
|
541
558
|
});
|
|
542
559
|
const {
|
|
543
|
-
where: initialWhere
|
|
560
|
+
where: initialWhere,
|
|
561
|
+
limit: initialLimit
|
|
544
562
|
} = params;
|
|
563
|
+
const limit = initialLimit && initialLimit > 0 ? initialLimit : 50;
|
|
545
564
|
/**
|
|
546
565
|
* We always assign tenant and locale because we do not allow one model to have content through multiple tenants.
|
|
547
566
|
*/
|
|
@@ -573,10 +592,10 @@ const createContentEntryCrud = params => {
|
|
|
573
592
|
});
|
|
574
593
|
}
|
|
575
594
|
|
|
576
|
-
const fields = getSearchableFields({
|
|
577
|
-
model,
|
|
595
|
+
const fields = (0, _searchableFields.getSearchableFields)({
|
|
596
|
+
fields: model.fields,
|
|
578
597
|
plugins: context.plugins,
|
|
579
|
-
|
|
598
|
+
input: params.fields || []
|
|
580
599
|
});
|
|
581
600
|
|
|
582
601
|
try {
|
|
@@ -590,6 +609,7 @@ const createContentEntryCrud = params => {
|
|
|
590
609
|
cursor,
|
|
591
610
|
items
|
|
592
611
|
} = await storageOperations.entries.list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
612
|
+
limit,
|
|
593
613
|
where,
|
|
594
614
|
fields
|
|
595
615
|
}));
|
|
@@ -826,6 +846,7 @@ const createContentEntryCrud = params => {
|
|
|
826
846
|
} catch (ex) {
|
|
827
847
|
await onEntryCreateRevisionError.publish({
|
|
828
848
|
entry,
|
|
849
|
+
original: originalEntry,
|
|
829
850
|
model,
|
|
830
851
|
input,
|
|
831
852
|
error: ex
|
|
@@ -939,6 +960,10 @@ const createContentEntryCrud = params => {
|
|
|
939
960
|
}
|
|
940
961
|
},
|
|
941
962
|
|
|
963
|
+
/**
|
|
964
|
+
* Method used internally. Not documented and should not be used in users systems.
|
|
965
|
+
* @internal
|
|
966
|
+
*/
|
|
942
967
|
async republishEntry(initialModel, id) {
|
|
943
968
|
await checkEntryPermissions({
|
|
944
969
|
rwd: "w"
|