@webiny/api-headless-cms-ddb-es 5.17.4 → 5.18.0-beta.3
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 +5 -17
- package/configurations.js +9 -38
- package/definitions/entry.d.ts +6 -11
- package/definitions/entry.js +17 -14
- package/definitions/entryElasticsearch.d.ts +8 -0
- package/definitions/entryElasticsearch.js +46 -0
- package/definitions/group.d.ts +8 -0
- package/definitions/group.js +74 -0
- package/definitions/model.d.ts +7 -6
- package/definitions/model.js +45 -20
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +62 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +50 -0
- package/definitions/table.d.ts +7 -3
- package/definitions/table.js +12 -29
- package/definitions/tableElasticsearch.d.ts +7 -3
- package/definitions/tableElasticsearch.js +12 -29
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +4 -3
- package/dynamoDb/storage/date.d.ts +2 -2
- package/dynamoDb/storage/date.js +17 -17
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +2 -2
- package/dynamoDb/storage/richText.js +69 -67
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +1 -2
- package/elasticsearch/indexing/dateTimeIndexing.js +1 -2
- package/elasticsearch/indexing/defaultFieldIndexing.js +1 -2
- package/elasticsearch/indexing/index.js +4 -3
- package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/longTextIndexing.js +36 -0
- package/elasticsearch/indexing/numberIndexing.js +1 -2
- package/elasticsearch/indexing/objectIndexing.js +32 -27
- package/elasticsearch/indexing/richTextIndexing.js +1 -2
- package/elasticsearch/search/index.js +1 -2
- package/elasticsearch/search/refSearch.js +1 -2
- package/elasticsearch/search/timeSearch.js +1 -2
- package/helpers/createElasticsearchQueryBody.d.ts +5 -4
- package/helpers/createElasticsearchQueryBody.js +89 -44
- package/helpers/entryIndexHelpers.d.ts +14 -12
- package/helpers/entryIndexHelpers.js +63 -58
- package/helpers/fields.d.ts +11 -10
- package/helpers/fields.js +4 -5
- package/helpers/index.js +1 -2
- package/helpers/operatorPluginsList.d.ts +2 -2
- package/helpers/operatorPluginsList.js +3 -4
- package/helpers/searchPluginsList.d.ts +2 -2
- package/helpers/searchPluginsList.js +3 -4
- package/helpers/transformValueForSearch.d.ts +4 -5
- package/helpers/transformValueForSearch.js +3 -6
- package/index.d.ts +2 -2
- package/index.js +154 -12
- package/operations/entry/dataLoaders.d.ts +38 -14
- package/operations/entry/dataLoaders.js +193 -125
- package/operations/entry/elasticsearchFields.d.ts +2 -0
- package/operations/entry/elasticsearchFields.js +32 -0
- package/operations/entry/fields.d.ts +2 -2
- package/operations/entry/fields.js +1 -2
- package/operations/entry/index.d.ts +13 -3
- package/operations/entry/index.js +1148 -15
- package/operations/entry/keys.d.ts +12 -0
- package/operations/entry/keys.js +40 -0
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +202 -0
- package/operations/model/index.d.ts +8 -3
- package/operations/model/index.js +196 -17
- package/operations/settings/index.d.ts +6 -3
- package/operations/settings/index.js +132 -16
- package/operations/system/createElasticsearchTemplate.d.ts +5 -0
- package/operations/system/createElasticsearchTemplate.js +62 -0
- package/operations/system/index.d.ts +6 -3
- package/operations/system/index.js +93 -17
- package/package.json +15 -14
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +9 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +9 -3
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +24 -0
- package/types.d.ts +61 -80
- package/types.js +55 -1
- package/upgrades/index.js +1 -2
- package/upgrades/utils.js +1 -2
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +2 -2
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +1 -2
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +1 -2
- package/upgrades/v5.0.0/entryValueFixer.d.ts +3 -3
- package/upgrades/v5.0.0/entryValueFixer.js +3 -4
- package/upgrades/v5.0.0/fieldFinder.d.ts +4 -4
- package/upgrades/v5.0.0/fieldFinder.js +1 -2
- package/upgrades/v5.0.0/helpers.js +1 -2
- package/upgrades/v5.0.0/index.js +1 -2
- package/upgrades/v5.8.0/index.js +3 -3
- package/configurations.js.map +0 -1
- package/definitions/elasticsearchEntry.d.ts +0 -13
- package/definitions/elasticsearchEntry.js +0 -43
- package/definitions/elasticsearchEntry.js.map +0 -1
- package/definitions/entry.js.map +0 -1
- package/definitions/index.d.ts +0 -17
- package/definitions/index.js +0 -28
- package/definitions/index.js.map +0 -1
- package/definitions/model.js.map +0 -1
- package/definitions/table.js.map +0 -1
- package/definitions/tableElasticsearch.js.map +0 -1
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/storage/date.js.map +0 -1
- package/dynamoDb/storage/richText.js.map +0 -1
- package/elasticsearch/index.js.map +0 -1
- package/elasticsearch/indexing/dateTimeIndexing.js.map +0 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +0 -1
- package/elasticsearch/indexing/index.js.map +0 -1
- package/elasticsearch/indexing/numberIndexing.js.map +0 -1
- package/elasticsearch/indexing/objectIndexing.js.map +0 -1
- package/elasticsearch/indexing/richTextIndexing.js.map +0 -1
- package/elasticsearch/search/index.js.map +0 -1
- package/elasticsearch/search/refSearch.js.map +0 -1
- package/elasticsearch/search/timeSearch.js.map +0 -1
- package/helpers/createElasticsearchQueryBody.js.map +0 -1
- package/helpers/entryIndexHelpers.js.map +0 -1
- package/helpers/fields.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/helpers/operatorPluginsList.js.map +0 -1
- package/helpers/searchPluginsList.js.map +0 -1
- package/helpers/transformValueForSearch.js.map +0 -1
- package/index.js.map +0 -1
- package/operations/entry/CmsContentEntryDynamoElastic.d.ts +0 -54
- package/operations/entry/CmsContentEntryDynamoElastic.js +0 -1128
- package/operations/entry/CmsContentEntryDynamoElastic.js.map +0 -1
- package/operations/entry/dataLoaders.js.map +0 -1
- package/operations/entry/fields.js.map +0 -1
- package/operations/entry/index.js.map +0 -1
- package/operations/model/CmsContentModelDynamoElastic.d.ts +0 -18
- package/operations/model/CmsContentModelDynamoElastic.js +0 -180
- package/operations/model/CmsContentModelDynamoElastic.js.map +0 -1
- package/operations/model/index.js.map +0 -1
- package/operations/modelGroup/CmsContentModelGroupDynamoElastic.d.ts +0 -40
- package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js +0 -193
- package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js.map +0 -1
- package/operations/modelGroup/index.d.ts +0 -3
- package/operations/modelGroup/index.js +0 -26
- package/operations/modelGroup/index.js.map +0 -1
- package/operations/settings/CmsSettingsDynamoElastic.d.ts +0 -14
- package/operations/settings/CmsSettingsDynamoElastic.js +0 -127
- package/operations/settings/CmsSettingsDynamoElastic.js.map +0 -1
- package/operations/settings/index.js.map +0 -1
- package/operations/system/CmsSystemDynamoElastic.d.ts +0 -14
- package/operations/system/CmsSystemDynamoElastic.js +0 -101
- package/operations/system/CmsSystemDynamoElastic.js.map +0 -1
- package/operations/system/CmsSystemInstallationPlugin.d.ts +0 -11
- package/operations/system/CmsSystemInstallationPlugin.js +0 -78
- package/operations/system/CmsSystemInstallationPlugin.js.map +0 -1
- package/operations/system/index.js.map +0 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
- package/types.js.map +0 -1
- package/upgrades/index.js.map +0 -1
- package/upgrades/utils.js.map +0 -1
- package/upgrades/v5.0.0/cleanDatabaseRecord.js.map +0 -1
- package/upgrades/v5.0.0/createOldVersionIndiceName.js.map +0 -1
- package/upgrades/v5.0.0/entryValueFixer.js.map +0 -1
- package/upgrades/v5.0.0/fieldFinder.js.map +0 -1
- package/upgrades/v5.0.0/helpers.js.map +0 -1
- package/upgrades/v5.0.0/index.js.map +0 -1
- package/upgrades/v5.8.0/index.js.map +0 -1
- package/utils.d.ts +0 -3
- package/utils.js +0 -42
- package/utils.js.map +0 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmsEntryListParams, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { SearchBody as esSearchBody } from "@webiny/api-elasticsearch/types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
4
|
interface CreateElasticsearchParams {
|
|
4
|
-
|
|
5
|
-
model:
|
|
6
|
-
args:
|
|
5
|
+
plugins: PluginsContainer;
|
|
6
|
+
model: CmsModel;
|
|
7
|
+
args: CmsEntryListParams;
|
|
7
8
|
parentPath?: string;
|
|
8
9
|
}
|
|
9
10
|
export declare const createElasticsearchQueryBody: (params: CreateElasticsearchParams) => esSearchBody;
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.createElasticsearchQueryBody = void 0;
|
|
9
9
|
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
10
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
13
|
|
|
12
14
|
var _operatorPluginsList = require("./operatorPluginsList");
|
|
@@ -15,8 +17,6 @@ var _transformValueForSearch = require("./transformValueForSearch");
|
|
|
15
17
|
|
|
16
18
|
var _searchPluginsList = require("./searchPluginsList");
|
|
17
19
|
|
|
18
|
-
var _CmsContentEntryDynamoElastic = require("../operations/entry/CmsContentEntryDynamoElastic");
|
|
19
|
-
|
|
20
20
|
var _cursors = require("@webiny/api-elasticsearch/cursors");
|
|
21
21
|
|
|
22
22
|
var _sort = require("@webiny/api-elasticsearch/sort");
|
|
@@ -27,12 +27,23 @@ var _CmsEntryElasticsearchFieldPlugin = require("../plugins/CmsEntryElasticsearc
|
|
|
27
27
|
|
|
28
28
|
var _where = require("@webiny/api-elasticsearch/where");
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
var _entry = require("../operations/entry");
|
|
31
|
+
|
|
32
|
+
var _CmsEntryElasticsearchQueryModifierPlugin = require("../plugins/CmsEntryElasticsearchQueryModifierPlugin");
|
|
33
|
+
|
|
34
|
+
var _CmsEntryElasticsearchSortModifierPlugin = require("../plugins/CmsEntryElasticsearchSortModifierPlugin");
|
|
35
|
+
|
|
36
|
+
var _CmsEntryElasticsearchBodyModifierPlugin = require("../plugins/CmsEntryElasticsearchBodyModifierPlugin");
|
|
37
|
+
|
|
38
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
39
|
+
|
|
40
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
41
|
+
|
|
42
|
+
const specialFields = ["published", "latest", "locale", "tenant"];
|
|
31
43
|
const noKeywordFields = ["date", "number", "boolean"];
|
|
32
44
|
|
|
33
45
|
const createElasticsearchSortParams = args => {
|
|
34
46
|
const {
|
|
35
|
-
context,
|
|
36
47
|
sort,
|
|
37
48
|
modelFields,
|
|
38
49
|
parentPath,
|
|
@@ -52,7 +63,6 @@ const createElasticsearchSortParams = args => {
|
|
|
52
63
|
searchable: modelField.isSearchable,
|
|
53
64
|
field: modelField.field.fieldId,
|
|
54
65
|
path: createFieldPath({
|
|
55
|
-
context,
|
|
56
66
|
parentPath,
|
|
57
67
|
modelField: modelField,
|
|
58
68
|
searchPlugin
|
|
@@ -74,8 +84,7 @@ const createElasticsearchSortParams = args => {
|
|
|
74
84
|
|
|
75
85
|
const createInitialQueryValue = args => {
|
|
76
86
|
const {
|
|
77
|
-
where
|
|
78
|
-
context
|
|
87
|
+
where
|
|
79
88
|
} = args;
|
|
80
89
|
const query = {
|
|
81
90
|
must: [],
|
|
@@ -87,28 +96,38 @@ const createInitialQueryValue = args => {
|
|
|
87
96
|
const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
|
|
88
97
|
|
|
89
98
|
if (sharedIndex) {
|
|
90
|
-
const tenant = context.tenancy.getCurrentTenant();
|
|
91
99
|
query.must.push({
|
|
92
100
|
term: {
|
|
93
|
-
"tenant.keyword": tenant
|
|
101
|
+
"tenant.keyword": where.tenant
|
|
94
102
|
}
|
|
95
103
|
});
|
|
96
104
|
}
|
|
105
|
+
|
|
106
|
+
delete where["tenant"];
|
|
107
|
+
|
|
108
|
+
if (where.locale) {
|
|
109
|
+
query.must.push({
|
|
110
|
+
term: {
|
|
111
|
+
"locale.keyword": where.locale
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
delete where["locale"];
|
|
97
117
|
/**
|
|
98
118
|
* We must transform published and latest where args into something that is understandable by our Elasticsearch
|
|
99
119
|
*/
|
|
100
120
|
|
|
101
|
-
|
|
102
121
|
if (where.published === true) {
|
|
103
122
|
query.must.push({
|
|
104
123
|
term: {
|
|
105
|
-
"__type.keyword":
|
|
124
|
+
"__type.keyword": (0, _entry.createPublishedType)()
|
|
106
125
|
}
|
|
107
126
|
});
|
|
108
127
|
} else if (where.latest === true) {
|
|
109
128
|
query.must.push({
|
|
110
129
|
term: {
|
|
111
|
-
"__type.keyword":
|
|
130
|
+
"__type.keyword": (0, _entry.createLatestType)()
|
|
112
131
|
}
|
|
113
132
|
});
|
|
114
133
|
} // we do not allow not published and not latest
|
|
@@ -129,15 +148,13 @@ const createInitialQueryValue = args => {
|
|
|
129
148
|
const createFieldPath = ({
|
|
130
149
|
modelField,
|
|
131
150
|
searchPlugin,
|
|
132
|
-
context,
|
|
133
151
|
parentPath
|
|
134
152
|
}) => {
|
|
135
153
|
let path;
|
|
136
154
|
|
|
137
155
|
if (searchPlugin && typeof searchPlugin.createPath === "function") {
|
|
138
156
|
path = searchPlugin.createPath({
|
|
139
|
-
field: modelField.field
|
|
140
|
-
context
|
|
157
|
+
field: modelField.field
|
|
141
158
|
});
|
|
142
159
|
} else if (typeof modelField.path === "function") {
|
|
143
160
|
path = modelField.path(modelField.field.fieldId);
|
|
@@ -179,15 +196,20 @@ const hasKeyword = modelField => {
|
|
|
179
196
|
*/
|
|
180
197
|
|
|
181
198
|
|
|
182
|
-
const execElasticsearchBuildQueryPlugins =
|
|
199
|
+
const execElasticsearchBuildQueryPlugins = params => {
|
|
183
200
|
const {
|
|
184
|
-
where,
|
|
201
|
+
where: initialWhere,
|
|
185
202
|
modelFields,
|
|
186
203
|
parentPath,
|
|
187
|
-
|
|
204
|
+
plugins,
|
|
188
205
|
searchPlugins
|
|
189
|
-
} =
|
|
190
|
-
|
|
206
|
+
} = params;
|
|
207
|
+
|
|
208
|
+
const where = _objectSpread({}, initialWhere);
|
|
209
|
+
|
|
210
|
+
const query = createInitialQueryValue(_objectSpread(_objectSpread({}, params), {}, {
|
|
211
|
+
where
|
|
212
|
+
}));
|
|
191
213
|
/**
|
|
192
214
|
* Always remove special fields, as these do not exist in Elasticsearch.
|
|
193
215
|
*/
|
|
@@ -196,11 +218,11 @@ const execElasticsearchBuildQueryPlugins = args => {
|
|
|
196
218
|
delete where[sf];
|
|
197
219
|
}
|
|
198
220
|
|
|
199
|
-
if (
|
|
221
|
+
if (Object.keys(where).length === 0) {
|
|
200
222
|
return query;
|
|
201
223
|
}
|
|
202
224
|
|
|
203
|
-
const operatorPlugins = (0, _operatorPluginsList.operatorPluginsList)(
|
|
225
|
+
const operatorPlugins = (0, _operatorPluginsList.operatorPluginsList)(plugins);
|
|
204
226
|
|
|
205
227
|
for (const key in where) {
|
|
206
228
|
if (where.hasOwnProperty(key) === false) {
|
|
@@ -247,11 +269,9 @@ const execElasticsearchBuildQueryPlugins = args => {
|
|
|
247
269
|
const value = (0, _transformValueForSearch.transformValueForSearch)({
|
|
248
270
|
plugins: searchPlugins,
|
|
249
271
|
field: cmsField,
|
|
250
|
-
value: where[key]
|
|
251
|
-
context
|
|
272
|
+
value: where[key]
|
|
252
273
|
});
|
|
253
274
|
const fieldPath = createFieldPath({
|
|
254
|
-
context,
|
|
255
275
|
searchPlugin: fieldSearchPlugin,
|
|
256
276
|
modelField,
|
|
257
277
|
parentPath: parentPath
|
|
@@ -270,7 +290,7 @@ const execElasticsearchBuildQueryPlugins = args => {
|
|
|
270
290
|
|
|
271
291
|
const createElasticsearchQueryBody = params => {
|
|
272
292
|
const {
|
|
273
|
-
|
|
293
|
+
plugins,
|
|
274
294
|
model,
|
|
275
295
|
args,
|
|
276
296
|
parentPath = null
|
|
@@ -279,29 +299,50 @@ const createElasticsearchQueryBody = params => {
|
|
|
279
299
|
where,
|
|
280
300
|
after,
|
|
281
301
|
limit,
|
|
282
|
-
sort
|
|
302
|
+
sort: initialSort
|
|
283
303
|
} = args;
|
|
284
|
-
const modelFields = (0, _fields.createModelFields)(
|
|
285
|
-
const searchPlugins = (0, _searchPluginsList.searchPluginsList)(
|
|
304
|
+
const modelFields = (0, _fields.createModelFields)(plugins, model);
|
|
305
|
+
const searchPlugins = (0, _searchPluginsList.searchPluginsList)(plugins);
|
|
286
306
|
const query = execElasticsearchBuildQueryPlugins({
|
|
287
307
|
model,
|
|
288
|
-
|
|
308
|
+
plugins,
|
|
289
309
|
where,
|
|
290
310
|
modelFields,
|
|
291
311
|
parentPath,
|
|
292
312
|
searchPlugins
|
|
293
313
|
});
|
|
294
|
-
const queryPlugins =
|
|
314
|
+
const queryPlugins = plugins.byType(_CmsEntryElasticsearchQueryModifierPlugin.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
|
|
315
|
+
return !pl.modelId || pl.modelId === model.modelId;
|
|
316
|
+
});
|
|
295
317
|
|
|
296
318
|
for (const pl of queryPlugins) {
|
|
297
|
-
pl.
|
|
319
|
+
pl.modifyQuery({
|
|
298
320
|
query,
|
|
299
321
|
model,
|
|
300
|
-
|
|
322
|
+
where
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const sort = createElasticsearchSortParams({
|
|
327
|
+
plugins,
|
|
328
|
+
sort: initialSort,
|
|
329
|
+
modelFields,
|
|
330
|
+
parentPath,
|
|
331
|
+
model,
|
|
332
|
+
searchPlugins
|
|
333
|
+
});
|
|
334
|
+
const sortPlugins = plugins.byType(_CmsEntryElasticsearchSortModifierPlugin.CmsEntryElasticsearchSortModifierPlugin.type).filter(pl => {
|
|
335
|
+
return !pl.modelId || pl.modelId === model.modelId;
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
for (const pl of sortPlugins) {
|
|
339
|
+
pl.modifySort({
|
|
340
|
+
sort,
|
|
341
|
+
model
|
|
301
342
|
});
|
|
302
343
|
}
|
|
303
344
|
|
|
304
|
-
|
|
345
|
+
const body = {
|
|
305
346
|
query: {
|
|
306
347
|
bool: {
|
|
307
348
|
must: query.must.length > 0 ? query.must : undefined,
|
|
@@ -310,21 +351,25 @@ const createElasticsearchQueryBody = params => {
|
|
|
310
351
|
filter: query.filter.length > 0 ? query.filter : undefined
|
|
311
352
|
}
|
|
312
353
|
},
|
|
313
|
-
sort
|
|
314
|
-
context,
|
|
315
|
-
sort,
|
|
316
|
-
modelFields,
|
|
317
|
-
parentPath,
|
|
318
|
-
model,
|
|
319
|
-
searchPlugins
|
|
320
|
-
}),
|
|
354
|
+
sort,
|
|
321
355
|
size: limit + 1,
|
|
322
356
|
// eslint-disable-next-line
|
|
323
357
|
search_after: (0, _cursors.decodeCursor)(after),
|
|
324
358
|
// eslint-disable-next-line
|
|
325
359
|
track_total_hits: true
|
|
326
360
|
};
|
|
361
|
+
const bodyPlugins = plugins.byType(_CmsEntryElasticsearchBodyModifierPlugin.CmsEntryElasticsearchBodyModifierPlugin.type).filter(pl => {
|
|
362
|
+
return !pl.modelId || pl.modelId === model.modelId;
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
for (const pl of bodyPlugins) {
|
|
366
|
+
pl.modifyBody({
|
|
367
|
+
body,
|
|
368
|
+
model
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return body;
|
|
327
373
|
};
|
|
328
374
|
|
|
329
|
-
exports.createElasticsearchQueryBody = createElasticsearchQueryBody;
|
|
330
|
-
//# sourceMappingURL=createElasticsearchQueryBody.js.map
|
|
375
|
+
exports.createElasticsearchQueryBody = createElasticsearchQueryBody;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { CmsIndexEntry } from "../types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
interface SetupEntriesIndexHelpersParams {
|
|
5
|
+
plugins: PluginsContainer;
|
|
5
6
|
}
|
|
6
|
-
interface
|
|
7
|
-
model:
|
|
8
|
-
entries:
|
|
7
|
+
interface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {
|
|
8
|
+
model: CmsModel;
|
|
9
|
+
entries: CmsIndexEntry[];
|
|
9
10
|
}
|
|
10
|
-
interface
|
|
11
|
-
model:
|
|
12
|
-
|
|
11
|
+
interface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {
|
|
12
|
+
model: CmsModel;
|
|
13
|
+
entry: CmsEntry;
|
|
14
|
+
storageEntry: CmsEntry;
|
|
13
15
|
}
|
|
14
|
-
export declare const prepareEntryToIndex: (
|
|
15
|
-
export declare const extractEntriesFromIndex: ({
|
|
16
|
+
export declare const prepareEntryToIndex: (params: PrepareElasticsearchDataParams) => CmsIndexEntry;
|
|
17
|
+
export declare const extractEntriesFromIndex: ({ plugins, entries, model }: ExtractEntriesFromIndexParams) => CmsEntry[];
|
|
16
18
|
export {};
|
|
@@ -15,18 +15,19 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
15
15
|
|
|
16
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
17
17
|
|
|
18
|
-
const prepareEntryToIndex =
|
|
18
|
+
const prepareEntryToIndex = params => {
|
|
19
19
|
const {
|
|
20
|
-
|
|
20
|
+
plugins,
|
|
21
21
|
storageEntry,
|
|
22
|
+
entry,
|
|
22
23
|
model
|
|
23
|
-
} =
|
|
24
|
+
} = params;
|
|
24
25
|
const {
|
|
25
26
|
fieldIndexPlugins,
|
|
26
27
|
defaultIndexFieldPlugin,
|
|
27
28
|
fieldTypePlugins
|
|
28
29
|
} = setupEntriesIndexHelpers({
|
|
29
|
-
|
|
30
|
+
plugins
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
function getFieldIndexPlugin(fieldType) {
|
|
@@ -34,7 +35,13 @@ const prepareEntryToIndex = args => {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
function getFieldTypePlugin(fieldType) {
|
|
37
|
-
|
|
38
|
+
const pl = fieldTypePlugins[fieldType];
|
|
39
|
+
|
|
40
|
+
if (pl) {
|
|
41
|
+
return pl;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new _error.default(`Missing field type plugin "${fieldType}". Prepare entry for index.`);
|
|
38
45
|
} // These objects will contain values processed by field index plugins
|
|
39
46
|
|
|
40
47
|
|
|
@@ -46,34 +53,31 @@ const prepareEntryToIndex = args => {
|
|
|
46
53
|
continue;
|
|
47
54
|
}
|
|
48
55
|
|
|
49
|
-
const
|
|
56
|
+
const targetFieldPlugin = getFieldIndexPlugin(field.type); // TODO: remove this `if` once we convert this plugin to proper plugin class
|
|
50
57
|
|
|
51
|
-
if (!
|
|
52
|
-
|
|
58
|
+
if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {
|
|
59
|
+
continue;
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
values[field.fieldId] = value;
|
|
72
|
-
}
|
|
62
|
+
const {
|
|
63
|
+
value,
|
|
64
|
+
rawValue
|
|
65
|
+
} = targetFieldPlugin.toIndex({
|
|
66
|
+
plugins,
|
|
67
|
+
model,
|
|
68
|
+
field,
|
|
69
|
+
rawValue: entry.values[field.fieldId],
|
|
70
|
+
value: storageEntry.values[field.fieldId],
|
|
71
|
+
getFieldIndexPlugin,
|
|
72
|
+
getFieldTypePlugin
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (typeof value !== "undefined") {
|
|
76
|
+
values[field.fieldId] = value;
|
|
77
|
+
}
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
79
|
+
if (typeof rawValue !== "undefined") {
|
|
80
|
+
rawValues[field.fieldId] = rawValue;
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
@@ -86,9 +90,9 @@ const prepareEntryToIndex = args => {
|
|
|
86
90
|
exports.prepareEntryToIndex = prepareEntryToIndex;
|
|
87
91
|
|
|
88
92
|
const setupEntriesIndexHelpers = ({
|
|
89
|
-
|
|
93
|
+
plugins: pluginsContainer
|
|
90
94
|
}) => {
|
|
91
|
-
const plugins =
|
|
95
|
+
const plugins = pluginsContainer.byType("cms-model-field-to-elastic-search");
|
|
92
96
|
const fieldIndexPlugins = {};
|
|
93
97
|
|
|
94
98
|
for (const plugin of plugins.reverse()) {
|
|
@@ -102,7 +106,7 @@ const setupEntriesIndexHelpers = ({
|
|
|
102
106
|
|
|
103
107
|
const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === "*"); // CmsModelFieldToGraphQLPlugin plugins
|
|
104
108
|
|
|
105
|
-
const fieldTypePlugins =
|
|
109
|
+
const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => _objectSpread(_objectSpread({}, plugins), {}, {
|
|
106
110
|
[plugin.fieldType]: plugin
|
|
107
111
|
}), {});
|
|
108
112
|
return {
|
|
@@ -113,7 +117,7 @@ const setupEntriesIndexHelpers = ({
|
|
|
113
117
|
};
|
|
114
118
|
|
|
115
119
|
const extractEntriesFromIndex = ({
|
|
116
|
-
|
|
120
|
+
plugins,
|
|
117
121
|
entries,
|
|
118
122
|
model
|
|
119
123
|
}) => {
|
|
@@ -122,7 +126,7 @@ const extractEntriesFromIndex = ({
|
|
|
122
126
|
defaultIndexFieldPlugin,
|
|
123
127
|
fieldTypePlugins
|
|
124
128
|
} = setupEntriesIndexHelpers({
|
|
125
|
-
|
|
129
|
+
plugins
|
|
126
130
|
});
|
|
127
131
|
|
|
128
132
|
function getFieldIndexPlugin(fieldType) {
|
|
@@ -143,32 +147,34 @@ const extractEntriesFromIndex = ({
|
|
|
143
147
|
const fieldTypePlugin = fieldTypePlugins[field.type];
|
|
144
148
|
|
|
145
149
|
if (!fieldTypePlugin) {
|
|
146
|
-
throw new _error.default(`Missing field type plugin "${field.type}".`);
|
|
150
|
+
throw new _error.default(`Missing field type plugin "${field.type}". Extract entries from index.`);
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
const targetFieldPlugin = getFieldIndexPlugin(field.type);
|
|
150
154
|
|
|
151
|
-
if (targetFieldPlugin
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
155
|
+
if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
indexValues[field.fieldId] = targetFieldPlugin.fromIndex({
|
|
161
|
+
plugins,
|
|
162
|
+
model,
|
|
163
|
+
field,
|
|
164
|
+
getFieldIndexPlugin,
|
|
165
|
+
getFieldTypePlugin,
|
|
166
|
+
value: entry.values[field.fieldId],
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Possibly no rawValues so we must check for the existence of the field.
|
|
170
|
+
*/
|
|
171
|
+
rawValue: entry.rawValues ? entry.rawValues[field.fieldId] : null
|
|
172
|
+
});
|
|
173
|
+
} catch (ex) {
|
|
174
|
+
throw new _error.default(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
|
|
175
|
+
field,
|
|
176
|
+
entry
|
|
177
|
+
});
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
|
|
@@ -180,5 +186,4 @@ const extractEntriesFromIndex = ({
|
|
|
180
186
|
return list;
|
|
181
187
|
};
|
|
182
188
|
|
|
183
|
-
exports.extractEntriesFromIndex = extractEntriesFromIndex;
|
|
184
|
-
//# sourceMappingURL=entryIndexHelpers.js.map
|
|
189
|
+
exports.extractEntriesFromIndex = extractEntriesFromIndex;
|
package/helpers/fields.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
2
3
|
declare type ModelFieldPath = string | ((value: string) => string);
|
|
3
4
|
export interface ModelField {
|
|
4
5
|
unmappedType?: string;
|
|
@@ -7,7 +8,7 @@ export interface ModelField {
|
|
|
7
8
|
isSortable: boolean;
|
|
8
9
|
type: string;
|
|
9
10
|
isSystemField?: boolean;
|
|
10
|
-
field:
|
|
11
|
+
field: CmsModelField;
|
|
11
12
|
path?: ModelFieldPath;
|
|
12
13
|
}
|
|
13
14
|
export declare type ModelFields = Record<string, ModelField>;
|
|
@@ -17,14 +18,14 @@ export declare const systemFields: {
|
|
|
17
18
|
isSystemField: boolean;
|
|
18
19
|
isSearchable: boolean;
|
|
19
20
|
isSortable: boolean;
|
|
20
|
-
field:
|
|
21
|
+
field: CmsModelField;
|
|
21
22
|
};
|
|
22
23
|
entryId: {
|
|
23
24
|
type: string;
|
|
24
25
|
isSystemField: boolean;
|
|
25
26
|
isSearchable: boolean;
|
|
26
27
|
isSortable: boolean;
|
|
27
|
-
field:
|
|
28
|
+
field: CmsModelField;
|
|
28
29
|
};
|
|
29
30
|
savedOn: {
|
|
30
31
|
type: string;
|
|
@@ -33,7 +34,7 @@ export declare const systemFields: {
|
|
|
33
34
|
isSystemField: boolean;
|
|
34
35
|
isSearchable: boolean;
|
|
35
36
|
isSortable: boolean;
|
|
36
|
-
field:
|
|
37
|
+
field: CmsModelField;
|
|
37
38
|
};
|
|
38
39
|
createdOn: {
|
|
39
40
|
type: string;
|
|
@@ -42,7 +43,7 @@ export declare const systemFields: {
|
|
|
42
43
|
isSystemField: boolean;
|
|
43
44
|
isSearchable: boolean;
|
|
44
45
|
isSortable: boolean;
|
|
45
|
-
field:
|
|
46
|
+
field: CmsModelField;
|
|
46
47
|
};
|
|
47
48
|
createdBy: {
|
|
48
49
|
type: string;
|
|
@@ -51,7 +52,7 @@ export declare const systemFields: {
|
|
|
51
52
|
isSearchable: boolean;
|
|
52
53
|
isSortable: boolean;
|
|
53
54
|
path: string;
|
|
54
|
-
field:
|
|
55
|
+
field: CmsModelField;
|
|
55
56
|
};
|
|
56
57
|
ownedBy: {
|
|
57
58
|
type: string;
|
|
@@ -60,7 +61,7 @@ export declare const systemFields: {
|
|
|
60
61
|
isSearchable: boolean;
|
|
61
62
|
isSortable: boolean;
|
|
62
63
|
path: string;
|
|
63
|
-
field:
|
|
64
|
+
field: CmsModelField;
|
|
64
65
|
};
|
|
65
66
|
version: {
|
|
66
67
|
type: string;
|
|
@@ -69,8 +70,8 @@ export declare const systemFields: {
|
|
|
69
70
|
isSystemField: boolean;
|
|
70
71
|
isSearchable: boolean;
|
|
71
72
|
isSortable: boolean;
|
|
72
|
-
field:
|
|
73
|
+
field: CmsModelField;
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
|
-
export declare const createModelFields: (
|
|
76
|
+
export declare const createModelFields: (plugins: PluginsContainer, model: CmsModel) => ModelFields;
|
|
76
77
|
export {};
|
package/helpers/fields.js
CHANGED
|
@@ -117,9 +117,9 @@ const systemFields = {
|
|
|
117
117
|
|
|
118
118
|
exports.systemFields = systemFields;
|
|
119
119
|
|
|
120
|
-
const createModelFields = (
|
|
120
|
+
const createModelFields = (plugins, model) => {
|
|
121
121
|
// collect all unmappedType from elastic plugins
|
|
122
|
-
const unmappedTypes =
|
|
122
|
+
const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
|
|
123
123
|
if (!plugin.unmappedType) {
|
|
124
124
|
return acc;
|
|
125
125
|
}
|
|
@@ -131,7 +131,7 @@ const createModelFields = (context, model) => {
|
|
|
131
131
|
* collect all field types from the plugins
|
|
132
132
|
*/
|
|
133
133
|
|
|
134
|
-
const fieldTypePlugins =
|
|
134
|
+
const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
|
|
135
135
|
const {
|
|
136
136
|
fieldType,
|
|
137
137
|
isSearchable,
|
|
@@ -171,5 +171,4 @@ const createModelFields = (context, model) => {
|
|
|
171
171
|
}, systemFields);
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
exports.createModelFields = createModelFields;
|
|
175
|
-
//# sourceMappingURL=fields.js.map
|
|
174
|
+
exports.createModelFields = createModelFields;
|
package/helpers/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CmsContext } from "@webiny/api-headless-cms/types";
|
|
2
1
|
import { ElasticsearchQueryBuilderOperatorPlugin } from "@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
3
|
interface OperatorPlugins {
|
|
4
4
|
[operator: string]: ElasticsearchQueryBuilderOperatorPlugin;
|
|
5
5
|
}
|
|
6
|
-
export declare const operatorPluginsList: (
|
|
6
|
+
export declare const operatorPluginsList: (plugins: PluginsContainer) => OperatorPlugins;
|
|
7
7
|
export {};
|
|
@@ -11,8 +11,8 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
11
11
|
|
|
12
12
|
var _ElasticsearchQueryBuilderOperatorPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
13
|
|
|
14
|
-
const operatorPluginsList =
|
|
15
|
-
return
|
|
14
|
+
const operatorPluginsList = plugins => {
|
|
15
|
+
return plugins.byType(_ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((plugins, plugin) => {
|
|
16
16
|
const operator = plugin.getOperator();
|
|
17
17
|
|
|
18
18
|
if (plugins[operator]) {
|
|
@@ -27,5 +27,4 @@ const operatorPluginsList = context => {
|
|
|
27
27
|
}, {});
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
exports.operatorPluginsList = operatorPluginsList;
|
|
31
|
-
//# sourceMappingURL=operatorPluginsList.js.map
|
|
30
|
+
exports.operatorPluginsList = operatorPluginsList;
|