@webiny/api-headless-cms-ddb-es 5.34.8 → 5.35.0-beta.1
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/configurations.d.ts +1 -1
- package/configurations.js +0 -8
- package/configurations.js.map +1 -1
- package/definitions/entry.js +3 -5
- package/definitions/entry.js.map +1 -1
- package/definitions/entryElasticsearch.js +0 -5
- package/definitions/entryElasticsearch.js.map +1 -1
- package/definitions/group.js +0 -5
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +17 -5
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +0 -5
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +0 -5
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -1
- package/definitions/tableElasticsearch.js +0 -3
- package/definitions/tableElasticsearch.js.map +1 -1
- package/dynamoDb/index.js +0 -5
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/storage/date.js +1 -16
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.js +1 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +0 -24
- package/dynamoDb/storage/richText.js.map +1 -1
- package/elasticsearch/createElasticsearchIndex.js +0 -11
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/deleteElasticsearchIndex.js +0 -7
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
- package/elasticsearch/index.js +0 -5
- package/elasticsearch/index.js.map +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js +4 -21
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js +5 -11
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
- package/elasticsearch/indexing/index.js +0 -9
- package/elasticsearch/indexing/index.js.map +1 -1
- package/elasticsearch/indexing/longTextIndexing.js +2 -14
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
- package/elasticsearch/indexing/numberIndexing.js +0 -9
- package/elasticsearch/indexing/numberIndexing.js.map +1 -1
- package/elasticsearch/indexing/objectIndexing.js +3 -30
- package/elasticsearch/indexing/objectIndexing.js.map +1 -1
- package/elasticsearch/indexing/richTextIndexing.js +0 -5
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
- package/elasticsearch/indices/base.js +0 -3
- package/elasticsearch/indices/base.js.map +1 -1
- package/elasticsearch/indices/index.js +0 -4
- package/elasticsearch/indices/index.js.map +1 -1
- package/elasticsearch/indices/japanese.js +0 -3
- package/elasticsearch/indices/japanese.js.map +1 -1
- package/elasticsearch/search/index.js +0 -4
- package/elasticsearch/search/index.js.map +1 -1
- package/elasticsearch/search/refSearch.js +0 -6
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/elasticsearch/search/timeSearch.js +0 -7
- package/elasticsearch/search/timeSearch.js.map +1 -1
- package/helpers/entryIndexHelpers.js +20 -49
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/index.js +0 -2
- package/helpers/index.js.map +1 -1
- package/index.js +7 -44
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +0 -52
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +1 -3
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
- package/operations/entry/elasticsearch/body.js +2 -26
- package/operations/entry/elasticsearch/body.js.map +1 -1
- package/operations/entry/elasticsearch/fields.d.ts +5 -4
- package/operations/entry/elasticsearch/fields.js +73 -60
- package/operations/entry/elasticsearch/fields.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +1 -10
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/exec.js +9 -52
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/index.js +0 -2
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/path.js +1 -9
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +1 -8
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/index.js +0 -5
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +0 -13
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +0 -10
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/populated.js +0 -7
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/values.js +0 -6
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.js +0 -13
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearchFields.js +0 -6
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.js +5 -19
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
- package/operations/entry/elasticsearch/keyword.js +0 -4
- package/operations/entry/elasticsearch/keyword.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +0 -3
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/operator.js +0 -8
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/queryModifier.js +0 -3
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/search.js +0 -6
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/sortModifier.js +0 -3
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
- package/operations/entry/elasticsearch/sort.js +5 -21
- package/operations/entry/elasticsearch/sort.js.map +1 -1
- package/operations/entry/elasticsearch/transformValueForSearch.js +0 -4
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
- package/operations/entry/elasticsearch/types.d.ts +3 -3
- package/operations/entry/elasticsearch/types.js.map +1 -1
- package/operations/entry/index.js +54 -147
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +0 -9
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/recordType.js +0 -6
- package/operations/entry/recordType.js.map +1 -1
- package/operations/group/index.js +2 -32
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +1 -34
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +0 -24
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +0 -17
- package/operations/system/index.js.map +1 -1
- package/package.json +23 -16
- package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +69 -0
- package/plugins/CmsElasticsearchModelFieldPlugin.js +48 -0
- package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +0 -8
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +0 -10
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -5
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +0 -12
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +0 -8
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +0 -8
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryFilterPlugin.js +0 -7
- package/plugins/CmsEntryFilterPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +11 -25
- package/plugins/index.js.map +1 -1
- package/types.d.ts +1 -1
- package/types.js +0 -5
- package/types.js.map +1 -1
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.prepareEntryToIndex = exports.extractEntriesFromIndex = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
const prepareEntryToIndex = params => {
|
|
15
11
|
const {
|
|
16
12
|
plugins,
|
|
@@ -25,36 +21,32 @@ const prepareEntryToIndex = params => {
|
|
|
25
21
|
} = setupEntriesIndexHelpers({
|
|
26
22
|
plugins
|
|
27
23
|
});
|
|
28
|
-
|
|
29
24
|
function getFieldIndexPlugin(fieldType) {
|
|
30
25
|
return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
function getFieldTypePlugin(fieldType) {
|
|
34
28
|
const pl = fieldTypePlugins[fieldType];
|
|
35
|
-
|
|
36
29
|
if (pl) {
|
|
37
30
|
return pl;
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
throw new _error.default(`Missing field type plugin "${fieldType}". Prepare entry for index.`);
|
|
41
|
-
}
|
|
42
|
-
|
|
33
|
+
}
|
|
43
34
|
|
|
35
|
+
// These objects will contain values processed by field index plugins
|
|
44
36
|
const values = {};
|
|
45
|
-
const rawValues = {};
|
|
37
|
+
const rawValues = {};
|
|
46
38
|
|
|
39
|
+
// We're only interested in current model fields.
|
|
47
40
|
for (const field of model.fields) {
|
|
48
41
|
if (storageEntry.values.hasOwnProperty(field.storageId) === false) {
|
|
49
42
|
continue;
|
|
50
43
|
}
|
|
44
|
+
const targetFieldPlugin = getFieldIndexPlugin(field.type);
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
// TODO: remove this `if` once we convert this plugin to proper plugin class
|
|
54
47
|
if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {
|
|
55
48
|
continue;
|
|
56
49
|
}
|
|
57
|
-
|
|
58
50
|
const {
|
|
59
51
|
value,
|
|
60
52
|
rawValue
|
|
@@ -67,41 +59,34 @@ const prepareEntryToIndex = params => {
|
|
|
67
59
|
getFieldIndexPlugin,
|
|
68
60
|
getFieldTypePlugin
|
|
69
61
|
});
|
|
70
|
-
|
|
71
62
|
if (typeof value !== "undefined") {
|
|
72
63
|
values[field.storageId] = value;
|
|
73
64
|
}
|
|
74
|
-
|
|
75
65
|
if (typeof rawValue !== "undefined") {
|
|
76
66
|
rawValues[field.storageId] = rawValue;
|
|
77
67
|
}
|
|
78
68
|
}
|
|
79
|
-
|
|
80
69
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
81
70
|
values,
|
|
82
71
|
rawValues
|
|
83
72
|
});
|
|
84
73
|
};
|
|
85
|
-
|
|
86
74
|
exports.prepareEntryToIndex = prepareEntryToIndex;
|
|
87
|
-
|
|
88
75
|
const setupEntriesIndexHelpers = ({
|
|
89
76
|
plugins: pluginsContainer
|
|
90
77
|
}) => {
|
|
91
78
|
const plugins = pluginsContainer.byType("cms-model-field-to-elastic-search");
|
|
92
79
|
const fieldIndexPlugins = {};
|
|
93
|
-
|
|
94
80
|
for (const plugin of plugins.reverse()) {
|
|
95
81
|
if (fieldIndexPlugins[plugin.fieldType]) {
|
|
96
82
|
continue;
|
|
97
83
|
}
|
|
98
|
-
|
|
99
84
|
fieldIndexPlugins[plugin.fieldType] = plugin;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === "*"); // CmsModelFieldToGraphQLPlugin plugins
|
|
85
|
+
}
|
|
86
|
+
// we will use this plugin if no targeted plugin found
|
|
87
|
+
const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === "*");
|
|
104
88
|
|
|
89
|
+
// CmsModelFieldToGraphQLPlugin plugins
|
|
105
90
|
const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, plugins), {}, {
|
|
106
91
|
[plugin.fieldType]: plugin
|
|
107
92
|
}), {});
|
|
@@ -111,7 +96,6 @@ const setupEntriesIndexHelpers = ({
|
|
|
111
96
|
fieldTypePlugins
|
|
112
97
|
};
|
|
113
98
|
};
|
|
114
|
-
|
|
115
99
|
const extractEntriesFromIndex = ({
|
|
116
100
|
plugins,
|
|
117
101
|
entries,
|
|
@@ -124,34 +108,27 @@ const extractEntriesFromIndex = ({
|
|
|
124
108
|
} = setupEntriesIndexHelpers({
|
|
125
109
|
plugins
|
|
126
110
|
});
|
|
127
|
-
|
|
128
111
|
function getFieldIndexPlugin(fieldType) {
|
|
129
112
|
return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;
|
|
130
113
|
}
|
|
131
|
-
|
|
132
114
|
function getFieldTypePlugin(fieldType) {
|
|
133
115
|
return fieldTypePlugins[fieldType];
|
|
134
116
|
}
|
|
135
|
-
|
|
136
117
|
const list = [];
|
|
137
|
-
|
|
138
118
|
for (const entry of entries) {
|
|
139
119
|
// This object will contain values processed by field index plugins
|
|
140
|
-
const indexValues = {};
|
|
120
|
+
const indexValues = {};
|
|
141
121
|
|
|
122
|
+
// We only consider fields that are present in the model
|
|
142
123
|
for (const field of model.fields) {
|
|
143
124
|
const fieldTypePlugin = fieldTypePlugins[field.type];
|
|
144
|
-
|
|
145
125
|
if (!fieldTypePlugin) {
|
|
146
126
|
throw new _error.default(`Missing field type plugin "${field.type}". Extract entries from index.`);
|
|
147
127
|
}
|
|
148
|
-
|
|
149
128
|
const targetFieldPlugin = getFieldIndexPlugin(field.type);
|
|
150
|
-
|
|
151
129
|
if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {
|
|
152
130
|
continue;
|
|
153
131
|
}
|
|
154
|
-
|
|
155
132
|
try {
|
|
156
133
|
indexValues[field.storageId] = targetFieldPlugin.fromIndex({
|
|
157
134
|
plugins,
|
|
@@ -160,7 +137,6 @@ const extractEntriesFromIndex = ({
|
|
|
160
137
|
getFieldIndexPlugin,
|
|
161
138
|
getFieldTypePlugin,
|
|
162
139
|
value: entry.values[field.storageId],
|
|
163
|
-
|
|
164
140
|
/**
|
|
165
141
|
* Possibly no rawValues so we must check for the existence of the field.
|
|
166
142
|
*/
|
|
@@ -176,8 +152,6 @@ const extractEntriesFromIndex = ({
|
|
|
176
152
|
/**
|
|
177
153
|
* Let's have a new entry so we do not modify the original one.
|
|
178
154
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
155
|
const newEntry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
182
156
|
values: indexValues
|
|
183
157
|
});
|
|
@@ -185,20 +159,17 @@ const extractEntriesFromIndex = ({
|
|
|
185
159
|
* If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.
|
|
186
160
|
*/
|
|
187
161
|
// @ts-ignore
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
162
|
+
delete newEntry["rawValues"];
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
delete newEntry["TYPE"];
|
|
165
|
+
// @ts-ignore
|
|
166
|
+
delete newEntry["__type"];
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
delete newEntry["latest"];
|
|
169
|
+
// @ts-ignore
|
|
197
170
|
delete newEntry["published"];
|
|
198
171
|
list.push((0, _objectSpread2.default)({}, newEntry));
|
|
199
172
|
}
|
|
200
|
-
|
|
201
173
|
return list;
|
|
202
174
|
};
|
|
203
|
-
|
|
204
175
|
exports.extractEntriesFromIndex = extractEntriesFromIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","hasOwnProperty","storageId","targetFieldPlugin","type","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry[];\n}\n\ninterface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry;\n storageEntry: CmsEntry;\n}\n\nexport const prepareEntryToIndex = (params: PrepareElasticsearchDataParams): CmsIndexEntry => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: Record<string, string> = {};\n const rawValues: Record<string, string> = {};\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n if (storageEntry.values.hasOwnProperty(field.storageId) === false) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[field.storageId],\n value: storageEntry.values[field.storageId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[field.storageId] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[field.storageId] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n } as CmsIndexEntry;\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = ({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams): CmsEntry[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: Record<string, string> = {};\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = fieldTypePlugins[field.type];\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n try {\n indexValues[field.storageId] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[field.storageId],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[field.storageId] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n /**\n * Let's have a new entry so we do not modify the original one.\n */\n const newEntry: CmsEntry = {\n ...entry,\n values: indexValues\n };\n /**\n * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.\n */\n // @ts-ignore\n delete newEntry[\"rawValues\"];\n // @ts-ignore\n delete newEntry[\"TYPE\"];\n // @ts-ignore\n delete newEntry[\"__type\"];\n // @ts-ignore\n delete newEntry[\"latest\"];\n // @ts-ignore\n delete newEntry[\"published\"];\n list.push({ ...newEntry });\n }\n\n return list;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAoBO,MAAMA,mBAAmB,GAAIC,MAAD,IAA2D;EAC1F,MAAM;IAAEC,OAAF;IAAWC,YAAX;IAAyBC,KAAzB;IAAgCC;EAAhC,IAA0CJ,MAAhD;EACA,MAAM;IAAEK,iBAAF;IAAqBC,uBAArB;IAA8CC;EAA9C,IACFC,wBAAwB,CAAC;IAAEP;EAAF,CAAD,CAD5B;;EAGA,SAASQ,mBAAT,CAA6BC,SAA7B,EAAgD;IAC5C,OAAOL,iBAAiB,CAACK,SAAD,CAAjB,IAAgCJ,uBAAvC;EACH;;EAED,SAASK,kBAAT,CAA4BD,SAA5B,EAA+C;IAC3C,MAAME,EAAE,GAAGL,gBAAgB,CAACG,SAAD,CAA3B;;IACA,IAAIE,EAAJ,EAAQ;MACJ,OAAOA,EAAP;IACH;;IACD,MAAM,IAAIC,cAAJ,CAAiB,8BAA6BH,SAAU,6BAAxD,CAAN;EACH,CAfyF,CAiB1F;;;EACA,MAAMI,MAA8B,GAAG,EAAvC;EACA,MAAMC,SAAiC,GAAG,EAA1C,CAnB0F,CAqB1F;;EACA,KAAK,MAAMC,KAAX,IAAoBZ,KAAK,CAACa,MAA1B,EAAkC;IAC9B,IAAIf,YAAY,CAACY,MAAb,CAAoBI,cAApB,CAAmCF,KAAK,CAACG,SAAzC,MAAwD,KAA5D,EAAmE;MAC/D;IACH;;IAED,MAAMC,iBAAiB,GAAGX,mBAAmB,CAACO,KAAK,CAACK,IAAP,CAA7C,CAL8B,CAO9B;;IACA,IAAI,CAACD,iBAAD,IAAsB,CAACA,iBAAiB,CAACE,OAA7C,EAAsD;MAClD;IACH;;IAED,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBJ,iBAAiB,CAACE,OAAlB,CAA0B;MAClDrB,OADkD;MAElDG,KAFkD;MAGlDY,KAHkD;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AAK,CAACG,SAAnB,CANgD;;UAOvD;AACpB;AACA;UACoBK,QAAQ,EAAErB,KAAK,CAACY,SAAN,GAAkBZ,KAAK,CAACY,SAAN,CAAgBC,KAAK,CAACG,SAAtB,CAAlB,GAAqD;QAVR,CAA5B,CAA/B;MAYH,CAbD,CAaE,OAAOkB,EAAP,EAAW;QACT,MAAM,IAAIxB,cAAJ,CACFwB,EAAE,CAACC,OAAH,IAAc,6CADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,wBAFT,EAGF;UACIvB,KADJ;UAEIb;QAFJ,CAHE,CAAN;MAQH;IACJ;IACD;AACR;AACA;;;IACQ,MAAMqC,QAAkB,+DACjBrC,KADiB;MAEpBW,MAAM,EAAEoB;IAFY,EAAxB;IAIA;AACR;AACA;IACQ;;IACA,OAAOM,QAAQ,CAAC,WAAD,CAAf,CApDyB,CAqDzB;;IACA,OAAOA,QAAQ,CAAC,MAAD,CAAf,CAtDyB,CAuDzB;;IACA,OAAOA,QAAQ,CAAC,QAAD,CAAf,CAxDyB,CAyDzB;;IACA,OAAOA,QAAQ,CAAC,QAAD,CAAf,CA1DyB,CA2DzB;;IACA,OAAOA,QAAQ,CAAC,WAAD,CAAf;IACAP,IAAI,CAACQ,IAAL,iCAAeD,QAAf;EACH;;EAED,OAAOP,IAAP;AACH,CAnFM"}
|
|
1
|
+
{"version":3,"names":["prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","hasOwnProperty","storageId","targetFieldPlugin","type","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry[];\n}\n\ninterface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry;\n storageEntry: CmsEntry;\n}\n\nexport const prepareEntryToIndex = (params: PrepareElasticsearchDataParams): CmsIndexEntry => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: Record<string, string> = {};\n const rawValues: Record<string, string> = {};\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n if (storageEntry.values.hasOwnProperty(field.storageId) === false) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[field.storageId],\n value: storageEntry.values[field.storageId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[field.storageId] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[field.storageId] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n } as CmsIndexEntry;\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = ({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams): CmsEntry[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: Record<string, string> = {};\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = fieldTypePlugins[field.type];\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n try {\n indexValues[field.storageId] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[field.storageId],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[field.storageId] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n /**\n * Let's have a new entry so we do not modify the original one.\n */\n const newEntry: CmsEntry = {\n ...entry,\n values: indexValues\n };\n /**\n * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.\n */\n // @ts-ignore\n delete newEntry[\"rawValues\"];\n // @ts-ignore\n delete newEntry[\"TYPE\"];\n // @ts-ignore\n delete newEntry[\"__type\"];\n // @ts-ignore\n delete newEntry[\"latest\"];\n // @ts-ignore\n delete newEntry[\"published\"];\n list.push({ ...newEntry });\n }\n\n return list;\n};\n"],"mappings":";;;;;;;;AAAA;AAoBO,MAAMA,mBAAmB,GAAIC,MAAsC,IAAoB;EAC1F,MAAM;IAAEC,OAAO;IAAEC,YAAY;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EACtD,MAAM;IAAEK,iBAAiB;IAAEC,uBAAuB;IAAEC;EAAiB,CAAC,GAClEC,wBAAwB,CAAC;IAAEP;EAAQ,CAAC,CAAC;EAEzC,SAASQ,mBAAmB,CAACC,SAAiB,EAAE;IAC5C,OAAOL,iBAAiB,CAACK,SAAS,CAAC,IAAIJ,uBAAuB;EAClE;EAEA,SAASK,kBAAkB,CAACD,SAAiB,EAAE;IAC3C,MAAME,EAAE,GAAGL,gBAAgB,CAACG,SAAS,CAAC;IACtC,IAAIE,EAAE,EAAE;MACJ,OAAOA,EAAE;IACb;IACA,MAAM,IAAIC,cAAW,CAAE,8BAA6BH,SAAU,6BAA4B,CAAC;EAC/F;;EAEA;EACA,MAAMI,MAA8B,GAAG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
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _entryIndexHelpers = require("./entryIndexHelpers");
|
|
8
|
-
|
|
9
7
|
Object.keys(_entryIndexHelpers).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _entryIndexHelpers[key]) return;
|
package/helpers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -9,53 +8,29 @@ var _exportNames = {
|
|
|
9
8
|
createStorageOperations: true
|
|
10
9
|
};
|
|
11
10
|
exports.createStorageOperations = void 0;
|
|
12
|
-
|
|
13
11
|
var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
|
|
14
|
-
|
|
15
12
|
var _elasticsearch = _interopRequireDefault(require("./elasticsearch"));
|
|
16
|
-
|
|
17
13
|
var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
|
|
18
|
-
|
|
19
14
|
var _settings = require("./operations/settings");
|
|
20
|
-
|
|
21
15
|
var _system = require("./operations/system");
|
|
22
|
-
|
|
23
16
|
var _model = require("./operations/model");
|
|
24
|
-
|
|
25
17
|
var _entry = require("./operations/entry");
|
|
26
|
-
|
|
27
18
|
var _types = require("./types");
|
|
28
|
-
|
|
29
19
|
var _table = require("./definitions/table");
|
|
30
|
-
|
|
31
20
|
var _tableElasticsearch = require("./definitions/tableElasticsearch");
|
|
32
|
-
|
|
33
21
|
var _group = require("./definitions/group");
|
|
34
|
-
|
|
35
22
|
var _model2 = require("./definitions/model");
|
|
36
|
-
|
|
37
23
|
var _entry2 = require("./definitions/entry");
|
|
38
|
-
|
|
39
24
|
var _entryElasticsearch = require("./definitions/entryElasticsearch");
|
|
40
|
-
|
|
41
25
|
var _system2 = require("./definitions/system");
|
|
42
|
-
|
|
43
26
|
var _settings2 = require("./definitions/settings");
|
|
44
|
-
|
|
45
27
|
var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
|
|
46
|
-
|
|
47
28
|
var _plugins = require("@webiny/plugins");
|
|
48
|
-
|
|
49
29
|
var _group2 = require("./operations/group");
|
|
50
|
-
|
|
51
30
|
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
52
|
-
|
|
53
31
|
var _indices = require("./elasticsearch/indices");
|
|
54
|
-
|
|
55
32
|
var _deleteElasticsearchIndex = require("./elasticsearch/deleteElasticsearchIndex");
|
|
56
|
-
|
|
57
33
|
var _plugins2 = require("./plugins");
|
|
58
|
-
|
|
59
34
|
Object.keys(_plugins2).forEach(function (key) {
|
|
60
35
|
if (key === "default" || key === "__esModule") return;
|
|
61
36
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -67,11 +42,9 @@ Object.keys(_plugins2).forEach(function (key) {
|
|
|
67
42
|
}
|
|
68
43
|
});
|
|
69
44
|
});
|
|
70
|
-
|
|
71
45
|
var _plugins3 = require("./operations/entry/elasticsearch/filtering/plugins");
|
|
72
|
-
|
|
73
46
|
var _CmsEntryFilterPlugin = require("./plugins/CmsEntryFilterPlugin");
|
|
74
|
-
|
|
47
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
75
48
|
const createStorageOperations = params => {
|
|
76
49
|
const {
|
|
77
50
|
attributes,
|
|
@@ -122,18 +95,10 @@ const createStorageOperations = params => {
|
|
|
122
95
|
})
|
|
123
96
|
};
|
|
124
97
|
const plugins = new _plugins.PluginsContainer([
|
|
125
|
-
/**
|
|
126
|
-
* Plugins of type CmsModelFieldToGraphQLPlugin.
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
98
|
/**
|
|
130
99
|
* DynamoDB filter plugins for the where conditions.
|
|
131
100
|
*/
|
|
132
101
|
(0, _filters.default)(),
|
|
133
|
-
/**
|
|
134
|
-
* Elasticsearch operators.
|
|
135
|
-
*/
|
|
136
|
-
(0, _apiElasticsearch.getElasticsearchOperators)(),
|
|
137
102
|
/**
|
|
138
103
|
* Field plugins for DynamoDB.
|
|
139
104
|
*/
|
|
@@ -167,19 +132,18 @@ const createStorageOperations = params => {
|
|
|
167
132
|
/**
|
|
168
133
|
* Pass the plugins to the parent context.
|
|
169
134
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
135
|
context.plugins.register([(0, _dynamoDb.default)()]);
|
|
173
136
|
/**
|
|
174
137
|
* We need to fetch all the plugin types in the list from the main container.
|
|
175
138
|
* This way we do not need to register plugins in the storage plugins contains.
|
|
176
139
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
140
|
+
const types = [
|
|
141
|
+
// Elasticsearch
|
|
142
|
+
_apiElasticsearch.CompressionPlugin.type, _apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type,
|
|
143
|
+
// Headless CMS
|
|
144
|
+
"cms-model-field-to-graphql", _CmsEntryFilterPlugin.CmsEntryFilterPlugin.type, _plugins2.CmsEntryElasticsearchBodyModifierPlugin.type, _plugins2.CmsEntryElasticsearchFullTextSearchPlugin.type, _plugins2.CmsEntryElasticsearchIndexPlugin.type, _plugins2.CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type, _plugins2.CmsEntryElasticsearchQueryModifierPlugin.type, _plugins2.CmsEntryElasticsearchSortModifierPlugin.type, _plugins2.CmsElasticsearchModelFieldPlugin.type, _apiHeadlessCms.StorageOperationsCmsModelPlugin.type];
|
|
180
145
|
for (const type of types) {
|
|
181
|
-
|
|
182
|
-
plugins.register(contextPlugins);
|
|
146
|
+
plugins.mergeByType(context.plugins, type);
|
|
183
147
|
}
|
|
184
148
|
},
|
|
185
149
|
init: async context => {
|
|
@@ -248,5 +212,4 @@ const createStorageOperations = params => {
|
|
|
248
212
|
})
|
|
249
213
|
};
|
|
250
214
|
};
|
|
251
|
-
|
|
252
215
|
exports.createStorageOperations = createStorageOperations;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","dynamoDbValueFilters","getElasticsearchOperators","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","name","beforeInit","context","register","types","CmsEntryFilterPlugin","type","ElasticsearchQueryBuilderOperatorPlugin","CmsEntryElasticsearchBodyModifierPlugin","CmsEntryElasticsearchFullTextSearchPlugin","CmsEntryElasticsearchIndexPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","CmsEntryElasticsearchQueryModifierPlugin","CmsEntryElasticsearchSortModifierPlugin","CmsEntryElasticsearchFieldPlugin","contextPlugins","byType","init","cms","onModelBeforeCreate","subscribe","model","createElasticsearchIndex","onModelBeforeCreateFrom","onModelAfterDelete","deleteElasticsearchIndex","onModelInitialize","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport {\n ElasticsearchQueryBuilderOperatorPlugin,\n getElasticsearchOperators\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport {\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchFullTextSearchPlugin,\n CmsEntryElasticsearchIndexPlugin,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin,\n CmsEntryElasticsearchFieldPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * Plugins of type CmsModelFieldToGraphQLPlugin.\n */\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins(),\n /**\n * Filter plugins used to apply filtering from where conditions to Elasticsearch query.\n */\n createFilterPlugins(),\n /**\n * User defined custom plugins.\n * They are at the end because we can then override existing plugins.\n */\n ...(userPlugins || [])\n ]);\n\n return {\n name: \"dynamodb:elasticsearch\",\n beforeInit: async context => {\n /**\n * Attach the elasticsearch into context if it is not already attached.\n */\n if (!context.elasticsearch) {\n context.elasticsearch = elasticsearch;\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n /**\n * We need to fetch all the plugin types in the list from the main container.\n * This way we do not need to register plugins in the storage plugins contains.\n */\n const types: string[] = [\n \"cms-model-field-to-graphql\",\n CmsEntryFilterPlugin.type,\n ElasticsearchQueryBuilderOperatorPlugin.type,\n CmsEntryElasticsearchBodyModifierPlugin.type,\n CmsEntryElasticsearchFullTextSearchPlugin.type,\n CmsEntryElasticsearchIndexPlugin.type,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type,\n CmsEntryElasticsearchQueryModifierPlugin.type,\n CmsEntryElasticsearchSortModifierPlugin.type,\n CmsEntryElasticsearchFieldPlugin.type\n ];\n for (const type of types) {\n const contextPlugins = context.plugins.byType(type);\n plugins.register(contextPlugins);\n }\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onModelBeforeCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelBeforeCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelAfterDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n\n context.cms.onModelInitialize.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\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AAqB;QAC1D,MAAM,IAAAI,kDAAA,EAAyB;UAC3B5D,aAD2B;UAE3BwD;QAF2B,CAAzB,CAAN;MAIH,CALD;MAOAnB,OAAO,CAACgB,GAAR,CAAYQ,iBAAZ,CAA8BN,SAA9B,CAAwC,OAAO;QAAEC;MAAF,CAAP,KAAqB;QACzD,MAAM,IAAAC,kDAAA,EAAyB;UAC3BzD,aAD2B;UAE3BwD,KAF2B;UAG3BvD;QAH2B,CAAzB,CAAN;MAKH,CAND;IAOH,CAnEE;IAoEH6D,WAAW,EAAE,MAAMvD,QApEhB;IAqEHwD,QAAQ,EAAE,MAAM5D,aArEb;IAsEH6D,UAAU,EAAE,MAAM3D,0BAtEf;IAuEHQ,MAAM,EAAE,IAAAoD,qCAAA,EAA8B;MAClCC,MAAM,EAAE3D,QAAQ,CAACM;IADiB,CAA9B,CAvEL;IA0EHL,QAAQ,EAAE,IAAA2D,yCAAA,EAAgC;MACtCD,MAAM,EAAE3D,QAAQ,CAACC;IADqB,CAAhC,CA1EP;IA6EHQ,MAAM,EAAE,IAAAoD,qCAAA,EAA8B;MAClCF,MAAM,EAAE3D,QAAQ,CAACS,MADiB;MAElCf;IAFkC,CAA9B,CA7EL;IAiFHkB,MAAM,EAAE,IAAAkD,oCAAA,EAA8B;MAClCH,MAAM,EAAE3D,QAAQ,CAACY,MADiB;MAElCnB;IAFkC,CAA9B,CAjFL;IAqFHsB,OAAO,EAAE,IAAAgD,qCAAA,EAA+B;MACpCJ,MAAM,EAAE3D,QAAQ,CAACe,OADmB;MAEpCiD,QAAQ,EAAEhE,QAAQ,CAACkB,SAFiB;MAGpCxB,OAHoC;MAIpCD;IAJoC,CAA/B;EArFN,CAAP;AA4FH,CAnLM"}
|
|
1
|
+
{"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","name","beforeInit","context","register","types","CompressionPlugin","type","ElasticsearchQueryBuilderOperatorPlugin","CmsEntryFilterPlugin","CmsEntryElasticsearchBodyModifierPlugin","CmsEntryElasticsearchFullTextSearchPlugin","CmsEntryElasticsearchIndexPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","CmsEntryElasticsearchQueryModifierPlugin","CmsEntryElasticsearchSortModifierPlugin","CmsElasticsearchModelFieldPlugin","StorageOperationsCmsModelPlugin","mergeByType","init","cms","onModelBeforeCreate","subscribe","model","createElasticsearchIndex","onModelBeforeCreateFrom","onModelAfterDelete","deleteElasticsearchIndex","onModelInitialize","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport {\n CompressionPlugin,\n ElasticsearchQueryBuilderOperatorPlugin\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport {\n CmsElasticsearchModelFieldPlugin,\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchFullTextSearchPlugin,\n CmsEntryElasticsearchIndexPlugin,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin } from \"@webiny/api-headless-cms\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins(),\n /**\n * Filter plugins used to apply filtering from where conditions to Elasticsearch query.\n */\n createFilterPlugins(),\n /**\n * User defined custom plugins.\n * They are at the end because we can then override existing plugins.\n */\n ...(userPlugins || [])\n ]);\n\n return {\n name: \"dynamodb:elasticsearch\",\n beforeInit: async context => {\n /**\n * Attach the elasticsearch into context if it is not already attached.\n */\n if (!context.elasticsearch) {\n context.elasticsearch = elasticsearch;\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n /**\n * We need to fetch all the plugin types in the list from the main container.\n * This way we do not need to register plugins in the storage plugins contains.\n */\n const types: string[] = [\n // Elasticsearch\n CompressionPlugin.type,\n ElasticsearchQueryBuilderOperatorPlugin.type,\n // Headless CMS\n \"cms-model-field-to-graphql\",\n CmsEntryFilterPlugin.type,\n CmsEntryElasticsearchBodyModifierPlugin.type,\n CmsEntryElasticsearchFullTextSearchPlugin.type,\n CmsEntryElasticsearchIndexPlugin.type,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type,\n CmsEntryElasticsearchQueryModifierPlugin.type,\n CmsEntryElasticsearchSortModifierPlugin.type,\n CmsElasticsearchModelFieldPlugin.type,\n StorageOperationsCmsModelPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onModelBeforeCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelBeforeCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelAfterDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n\n context.cms.onModelInitialize.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AAaA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAJA;AACA;AACA;AAIO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IACFC,UAAU;IACVC,KAAK;IACLC,OAAO;IACPC,cAAc;IACdC,aAAa;IACbC,OAAO,EAAEC;EACb,CAAC,GAAGP,MAAM;EAEV,MAAMQ,aAAa,GAAG,IAAAC,kBAAW,EAAC;IAC9BP,KAAK;IACLE;EACJ,CAAC,CAAC;EACF,MAAMM,0BAA0B,GAAG,IAAAC,4CAAwB,EAAC;IACxDT,KAAK,EAAEC,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