@webiny/api-headless-cms-ddb-es 0.0.0-mt-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/LICENSE +21 -0
- package/README.md +35 -0
- package/configurations.d.ts +12 -0
- package/configurations.js +32 -0
- package/definitions/entry.d.ts +8 -0
- package/definitions/entry.js +91 -0
- 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 +8 -0
- package/definitions/model.js +96 -0
- 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 +8 -0
- package/definitions/table.js +24 -0
- package/definitions/tableElasticsearch.d.ts +8 -0
- package/definitions/tableElasticsearch.js +24 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +18 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +65 -0
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +8 -0
- package/dynamoDb/storage/richText.js +110 -0
- package/elasticsearch/index.d.ts +2 -0
- package/elasticsearch/index.js +16 -0
- package/elasticsearch/indexing/dateTimeIndexing.d.ts +3 -0
- package/elasticsearch/indexing/dateTimeIndexing.js +89 -0
- package/elasticsearch/indexing/defaultFieldIndexing.d.ts +3 -0
- package/elasticsearch/indexing/defaultFieldIndexing.js +47 -0
- package/elasticsearch/indexing/index.d.ts +2 -0
- package/elasticsearch/indexing/index.js +24 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/longTextIndexing.js +36 -0
- package/elasticsearch/indexing/numberIndexing.d.ts +3 -0
- package/elasticsearch/indexing/numberIndexing.js +48 -0
- package/elasticsearch/indexing/objectIndexing.d.ts +3 -0
- package/elasticsearch/indexing/objectIndexing.js +200 -0
- package/elasticsearch/indexing/richTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/richTextIndexing.js +34 -0
- package/elasticsearch/search/index.d.ts +3 -0
- package/elasticsearch/search/index.js +16 -0
- package/elasticsearch/search/refSearch.d.ts +3 -0
- package/elasticsearch/search/refSearch.js +24 -0
- package/elasticsearch/search/timeSearch.d.ts +3 -0
- package/elasticsearch/search/timeSearch.js +25 -0
- package/helpers/createElasticsearchQueryBody.d.ts +11 -0
- package/helpers/createElasticsearchQueryBody.js +375 -0
- package/helpers/entryIndexHelpers.d.ts +18 -0
- package/helpers/entryIndexHelpers.js +189 -0
- package/helpers/fields.d.ts +77 -0
- package/helpers/fields.js +174 -0
- package/helpers/index.d.ts +2 -0
- package/helpers/index.js +31 -0
- package/helpers/operatorPluginsList.d.ts +7 -0
- package/helpers/operatorPluginsList.js +30 -0
- package/helpers/searchPluginsList.d.ts +6 -0
- package/helpers/searchPluginsList.js +26 -0
- package/helpers/transformValueForSearch.d.ts +9 -0
- package/helpers/transformValueForSearch.js +26 -0
- package/index.d.ts +2 -0
- package/index.js +171 -0
- package/operations/entry/dataLoaders.d.ts +47 -0
- package/operations/entry/dataLoaders.js +347 -0
- package/operations/entry/elasticsearchFields.d.ts +2 -0
- package/operations/entry/elasticsearchFields.js +32 -0
- package/operations/entry/fields.d.ts +3 -0
- package/operations/entry/fields.js +60 -0
- package/operations/entry/index.d.ts +13 -0
- package/operations/entry/index.js +1152 -0
- 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 -0
- package/operations/model/index.js +205 -0
- package/operations/settings/index.d.ts +6 -0
- package/operations/settings/index.js +141 -0
- package/operations/system/createElasticsearchTemplate.d.ts +5 -0
- package/operations/system/createElasticsearchTemplate.js +62 -0
- package/operations/system/index.d.ts +6 -0
- package/operations/system/index.js +105 -0
- package/package.json +73 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +12 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +24 -0
- 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 +191 -0
- package/types.js +60 -0
- package/upgrades/index.d.ts +2 -0
- package/upgrades/index.js +16 -0
- package/upgrades/utils.d.ts +1 -0
- package/upgrades/utils.js +16 -0
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +6 -0
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +16 -0
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +2 -0
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +12 -0
- package/upgrades/v5.0.0/entryValueFixer.d.ts +4 -0
- package/upgrades/v5.0.0/entryValueFixer.js +124 -0
- package/upgrades/v5.0.0/fieldFinder.d.ts +6 -0
- package/upgrades/v5.0.0/fieldFinder.js +42 -0
- package/upgrades/v5.0.0/helpers.d.ts +4 -0
- package/upgrades/v5.0.0/helpers.js +57 -0
- package/upgrades/v5.0.0/index.d.ts +4 -0
- package/upgrades/v5.0.0/index.js +232 -0
- package/upgrades/v5.8.0/index.d.ts +4 -0
- package/upgrades/v5.8.0/index.js +426 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
const processToIndex = ({
|
|
9
|
+
fields,
|
|
10
|
+
value: sourceValue,
|
|
11
|
+
rawValue: sourceRawValue,
|
|
12
|
+
getFieldIndexPlugin,
|
|
13
|
+
getFieldTypePlugin,
|
|
14
|
+
plugins,
|
|
15
|
+
model
|
|
16
|
+
}) => {
|
|
17
|
+
const reducer = (values, field) => {
|
|
18
|
+
const plugin = getFieldIndexPlugin(field.type);
|
|
19
|
+
const {
|
|
20
|
+
value,
|
|
21
|
+
rawValue
|
|
22
|
+
} = plugin.toIndex({
|
|
23
|
+
model,
|
|
24
|
+
field,
|
|
25
|
+
value: sourceValue[field.fieldId],
|
|
26
|
+
rawValue: sourceRawValue[field.fieldId],
|
|
27
|
+
getFieldIndexPlugin,
|
|
28
|
+
getFieldTypePlugin,
|
|
29
|
+
plugins
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (value !== undefined) {
|
|
33
|
+
values.value[field.fieldId] = value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (rawValue !== undefined) {
|
|
37
|
+
values.rawValue[field.fieldId] = rawValue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return values;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return fields.reduce(reducer, {
|
|
44
|
+
value: {},
|
|
45
|
+
rawValue: {}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const processFromIndex = ({
|
|
50
|
+
fields,
|
|
51
|
+
value: sourceValue,
|
|
52
|
+
rawValue: sourceRawValue,
|
|
53
|
+
getFieldIndexPlugin,
|
|
54
|
+
getFieldTypePlugin,
|
|
55
|
+
plugins,
|
|
56
|
+
model
|
|
57
|
+
}) => {
|
|
58
|
+
const reducer = (values, field) => {
|
|
59
|
+
const plugin = getFieldIndexPlugin(field.type);
|
|
60
|
+
const value = plugin.fromIndex({
|
|
61
|
+
plugins,
|
|
62
|
+
model,
|
|
63
|
+
field,
|
|
64
|
+
value: sourceValue[field.fieldId],
|
|
65
|
+
rawValue: sourceRawValue[field.fieldId],
|
|
66
|
+
getFieldIndexPlugin,
|
|
67
|
+
getFieldTypePlugin
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (value !== undefined) {
|
|
71
|
+
values[field.fieldId] = value;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return values;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return fields.reduce(reducer, {});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var _default = () => ({
|
|
81
|
+
type: "cms-model-field-to-elastic-search",
|
|
82
|
+
name: "cms-model-field-to-elastic-search-object",
|
|
83
|
+
fieldType: "object",
|
|
84
|
+
|
|
85
|
+
toIndex({
|
|
86
|
+
plugins,
|
|
87
|
+
model,
|
|
88
|
+
field,
|
|
89
|
+
value: initialValue,
|
|
90
|
+
rawValue: initialRawValue,
|
|
91
|
+
getFieldIndexPlugin,
|
|
92
|
+
getFieldTypePlugin
|
|
93
|
+
}) {
|
|
94
|
+
if (!initialValue) {
|
|
95
|
+
return {
|
|
96
|
+
value: null
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const fields = field.settings.fields;
|
|
101
|
+
/**
|
|
102
|
+
* In "object" field, value is either an object or an array of objects.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
if (field.multipleValues) {
|
|
106
|
+
const result = {
|
|
107
|
+
value: [],
|
|
108
|
+
rawValue: []
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
for (const key in initialValue) {
|
|
112
|
+
const {
|
|
113
|
+
value,
|
|
114
|
+
rawValue
|
|
115
|
+
} = processToIndex({
|
|
116
|
+
value: initialValue[key],
|
|
117
|
+
rawValue: initialRawValue[key],
|
|
118
|
+
getFieldIndexPlugin,
|
|
119
|
+
getFieldTypePlugin,
|
|
120
|
+
model,
|
|
121
|
+
plugins,
|
|
122
|
+
fields
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (Object.keys(value).length > 0) {
|
|
126
|
+
result.value.push(value);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (Object.keys(rawValue).length > 0) {
|
|
130
|
+
result.rawValue.push(rawValue);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
value: result.value.length > 0 ? result.value : undefined,
|
|
136
|
+
rawValue: result.rawValue.length > 0 ? result.rawValue : undefined
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return processToIndex({
|
|
141
|
+
value: initialValue,
|
|
142
|
+
rawValue: initialRawValue,
|
|
143
|
+
getFieldIndexPlugin,
|
|
144
|
+
getFieldTypePlugin,
|
|
145
|
+
model,
|
|
146
|
+
plugins,
|
|
147
|
+
fields
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
fromIndex({
|
|
152
|
+
field,
|
|
153
|
+
value,
|
|
154
|
+
rawValue,
|
|
155
|
+
model,
|
|
156
|
+
plugins,
|
|
157
|
+
getFieldIndexPlugin,
|
|
158
|
+
getFieldTypePlugin
|
|
159
|
+
}) {
|
|
160
|
+
if (!value) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const fields = field.settings.fields;
|
|
165
|
+
/**
|
|
166
|
+
* In "object" field, value is either an object or an array of objects.
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
if (field.multipleValues) {
|
|
170
|
+
/**
|
|
171
|
+
* Why this `value || rawValue || []`?
|
|
172
|
+
* It's possible that an object contains all non-indexable fields, or vice-versa, and so
|
|
173
|
+
* we can never be sure which array we can reliably use as a source of values.
|
|
174
|
+
*/
|
|
175
|
+
const source = value || rawValue || [];
|
|
176
|
+
return source.map((_, index) => processFromIndex({
|
|
177
|
+
value: value ? value[index] || {} : {},
|
|
178
|
+
rawValue: rawValue ? rawValue[index] || {} : {},
|
|
179
|
+
getFieldIndexPlugin,
|
|
180
|
+
getFieldTypePlugin,
|
|
181
|
+
model,
|
|
182
|
+
plugins,
|
|
183
|
+
fields
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return processFromIndex({
|
|
188
|
+
value,
|
|
189
|
+
rawValue,
|
|
190
|
+
getFieldIndexPlugin,
|
|
191
|
+
getFieldTypePlugin,
|
|
192
|
+
model,
|
|
193
|
+
plugins,
|
|
194
|
+
fields
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
exports.default = _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _default = () => ({
|
|
9
|
+
type: "cms-model-field-to-elastic-search",
|
|
10
|
+
name: "cms-model-field-to-elastic-search-rich-text",
|
|
11
|
+
fieldType: "rich-text",
|
|
12
|
+
|
|
13
|
+
toIndex({
|
|
14
|
+
value
|
|
15
|
+
}) {
|
|
16
|
+
// TODO: convert rich-text object to a searchable string to offer full-text search at some point
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* We want to store rich-text value as a "rawValue", meaning it wont' be indexed by ES.
|
|
20
|
+
*/
|
|
21
|
+
return {
|
|
22
|
+
rawValue: value
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
fromIndex({
|
|
27
|
+
rawValue
|
|
28
|
+
}) {
|
|
29
|
+
return rawValue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.default = _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _timeSearch = _interopRequireDefault(require("./timeSearch"));
|
|
11
|
+
|
|
12
|
+
var _refSearch = _interopRequireDefault(require("./refSearch"));
|
|
13
|
+
|
|
14
|
+
var _default = () => [(0, _timeSearch.default)(), (0, _refSearch.default)()];
|
|
15
|
+
|
|
16
|
+
exports.default = _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _default = () => ({
|
|
9
|
+
type: "cms-elastic-search-query-builder-value-search",
|
|
10
|
+
name: "cms-elastic-search-query-builder-value-search-ref-field",
|
|
11
|
+
fieldType: "ref",
|
|
12
|
+
transform: ({
|
|
13
|
+
value
|
|
14
|
+
}) => {
|
|
15
|
+
return value;
|
|
16
|
+
},
|
|
17
|
+
createPath: ({
|
|
18
|
+
field
|
|
19
|
+
}) => {
|
|
20
|
+
return `values.${field.fieldId}.entryId`;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
exports.default = _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _default = () => ({
|
|
9
|
+
type: "cms-elastic-search-query-builder-value-search",
|
|
10
|
+
name: "elastic-search-query-builder-value-search-time",
|
|
11
|
+
fieldType: "datetime",
|
|
12
|
+
transform: ({
|
|
13
|
+
field,
|
|
14
|
+
value
|
|
15
|
+
}) => {
|
|
16
|
+
if (field.settings.type !== "time") {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [hours, minutes, seconds = 0] = value.split(":").map(Number);
|
|
21
|
+
return hours * 60 * 60 + minutes * 60 + seconds;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
exports.default = _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CmsEntryListParams, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { SearchBody as esSearchBody } from "@webiny/api-elasticsearch/types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
interface CreateElasticsearchParams {
|
|
5
|
+
plugins: PluginsContainer;
|
|
6
|
+
model: CmsModel;
|
|
7
|
+
args: CmsEntryListParams;
|
|
8
|
+
parentPath?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const createElasticsearchQueryBody: (params: CreateElasticsearchParams) => esSearchBody;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createElasticsearchQueryBody = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _operatorPluginsList = require("./operatorPluginsList");
|
|
15
|
+
|
|
16
|
+
var _transformValueForSearch = require("./transformValueForSearch");
|
|
17
|
+
|
|
18
|
+
var _searchPluginsList = require("./searchPluginsList");
|
|
19
|
+
|
|
20
|
+
var _cursors = require("@webiny/api-elasticsearch/cursors");
|
|
21
|
+
|
|
22
|
+
var _sort = require("@webiny/api-elasticsearch/sort");
|
|
23
|
+
|
|
24
|
+
var _fields = require("./fields");
|
|
25
|
+
|
|
26
|
+
var _CmsEntryElasticsearchFieldPlugin = require("../plugins/CmsEntryElasticsearchFieldPlugin");
|
|
27
|
+
|
|
28
|
+
var _where = require("@webiny/api-elasticsearch/where");
|
|
29
|
+
|
|
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"];
|
|
43
|
+
const noKeywordFields = ["date", "number", "boolean"];
|
|
44
|
+
|
|
45
|
+
const createElasticsearchSortParams = args => {
|
|
46
|
+
const {
|
|
47
|
+
sort,
|
|
48
|
+
modelFields,
|
|
49
|
+
parentPath,
|
|
50
|
+
searchPlugins
|
|
51
|
+
} = args;
|
|
52
|
+
|
|
53
|
+
if (!sort || sort.length === 0) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {
|
|
58
|
+
const searchPlugin = searchPlugins[modelField.type];
|
|
59
|
+
plugins[modelField.field.fieldId] = new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
60
|
+
unmappedType: modelField.unmappedType,
|
|
61
|
+
keyword: hasKeyword(modelField),
|
|
62
|
+
sortable: modelField.isSortable,
|
|
63
|
+
searchable: modelField.isSearchable,
|
|
64
|
+
field: modelField.field.fieldId,
|
|
65
|
+
path: createFieldPath({
|
|
66
|
+
parentPath,
|
|
67
|
+
modelField: modelField,
|
|
68
|
+
searchPlugin
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
return plugins;
|
|
72
|
+
}, {});
|
|
73
|
+
return (0, _sort.createSort)({
|
|
74
|
+
fieldPlugins: sortPlugins,
|
|
75
|
+
sort
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.
|
|
80
|
+
* We allow either published or either latest.
|
|
81
|
+
* Latest is used in the manage API and published in the read API.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const createInitialQueryValue = args => {
|
|
86
|
+
const {
|
|
87
|
+
where
|
|
88
|
+
} = args;
|
|
89
|
+
const query = {
|
|
90
|
+
must: [],
|
|
91
|
+
must_not: [],
|
|
92
|
+
should: [],
|
|
93
|
+
filter: []
|
|
94
|
+
}; // When ES index is shared between tenants, we need to filter records by tenant ID
|
|
95
|
+
|
|
96
|
+
const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
|
|
97
|
+
|
|
98
|
+
if (sharedIndex) {
|
|
99
|
+
query.must.push({
|
|
100
|
+
term: {
|
|
101
|
+
"tenant.keyword": where.tenant
|
|
102
|
+
}
|
|
103
|
+
});
|
|
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"];
|
|
117
|
+
/**
|
|
118
|
+
* We must transform published and latest where args into something that is understandable by our Elasticsearch
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
if (where.published === true) {
|
|
122
|
+
query.must.push({
|
|
123
|
+
term: {
|
|
124
|
+
"__type.keyword": (0, _entry.createPublishedType)()
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
} else if (where.latest === true) {
|
|
128
|
+
query.must.push({
|
|
129
|
+
term: {
|
|
130
|
+
"__type.keyword": (0, _entry.createLatestType)()
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
} // we do not allow not published and not latest
|
|
134
|
+
else if (where.published === false) {
|
|
135
|
+
throw new _error.default(`Cannot call Elasticsearch query with "published" set at false.`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
|
|
136
|
+
where
|
|
137
|
+
});
|
|
138
|
+
} else if (where.latest === false) {
|
|
139
|
+
throw new _error.default(`Cannot call Elasticsearch query with "latest" set at false.`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
|
|
140
|
+
where
|
|
141
|
+
});
|
|
142
|
+
} //
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
return query;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const createFieldPath = ({
|
|
149
|
+
modelField,
|
|
150
|
+
searchPlugin,
|
|
151
|
+
parentPath
|
|
152
|
+
}) => {
|
|
153
|
+
let path;
|
|
154
|
+
|
|
155
|
+
if (searchPlugin && typeof searchPlugin.createPath === "function") {
|
|
156
|
+
path = searchPlugin.createPath({
|
|
157
|
+
field: modelField.field
|
|
158
|
+
});
|
|
159
|
+
} else if (typeof modelField.path === "function") {
|
|
160
|
+
path = modelField.path(modelField.field.fieldId);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!path) {
|
|
164
|
+
path = modelField.path || modelField.field.fieldId || modelField.field.id;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return modelField.isSystemField || !parentPath || path.match(parentPath) ? path : `${parentPath}.${path}`;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const hasKeyword = modelField => {
|
|
171
|
+
/**
|
|
172
|
+
* We defined some field types that MUST have no keyword added to the field path
|
|
173
|
+
*/
|
|
174
|
+
if (noKeywordFields.includes(modelField.type)) {
|
|
175
|
+
return false;
|
|
176
|
+
} else if (modelField.unmappedType) {
|
|
177
|
+
/**
|
|
178
|
+
* If modelField has unmapped type defined, do not add keyword.
|
|
179
|
+
*/
|
|
180
|
+
return false;
|
|
181
|
+
} else if (modelField.keyword === false) {
|
|
182
|
+
/**
|
|
183
|
+
* And if specifically defined that modelField has no keyword, do not add it.
|
|
184
|
+
*/
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* All other fields have keyword added.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
return true;
|
|
193
|
+
};
|
|
194
|
+
/*
|
|
195
|
+
* Iterate through where keys and apply plugins where necessary
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
const execElasticsearchBuildQueryPlugins = params => {
|
|
200
|
+
const {
|
|
201
|
+
where: initialWhere,
|
|
202
|
+
modelFields,
|
|
203
|
+
parentPath,
|
|
204
|
+
plugins,
|
|
205
|
+
searchPlugins
|
|
206
|
+
} = params;
|
|
207
|
+
|
|
208
|
+
const where = _objectSpread({}, initialWhere);
|
|
209
|
+
|
|
210
|
+
const query = createInitialQueryValue(_objectSpread(_objectSpread({}, params), {}, {
|
|
211
|
+
where
|
|
212
|
+
}));
|
|
213
|
+
/**
|
|
214
|
+
* Always remove special fields, as these do not exist in Elasticsearch.
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
for (const sf of specialFields) {
|
|
218
|
+
delete where[sf];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (Object.keys(where).length === 0) {
|
|
222
|
+
return query;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const operatorPlugins = (0, _operatorPluginsList.operatorPluginsList)(plugins);
|
|
226
|
+
|
|
227
|
+
for (const key in where) {
|
|
228
|
+
if (where.hasOwnProperty(key) === false) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* We do not need to go further if value is undefined.
|
|
233
|
+
* There are few hardcoded possibilities when value is undefined, for example, ownedBy.
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
if (where[key] === undefined) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const {
|
|
242
|
+
field,
|
|
243
|
+
operator
|
|
244
|
+
} = (0, _where.parseWhereKey)(key);
|
|
245
|
+
const modelField = modelFields[field];
|
|
246
|
+
|
|
247
|
+
if (!modelField) {
|
|
248
|
+
throw new _error.default(`There is no field "${field}".`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const {
|
|
252
|
+
isSearchable = false,
|
|
253
|
+
field: cmsField
|
|
254
|
+
} = modelField;
|
|
255
|
+
|
|
256
|
+
if (!isSearchable) {
|
|
257
|
+
throw new _error.default(`Field "${field}" is not searchable.`);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const plugin = operatorPlugins[operator];
|
|
261
|
+
|
|
262
|
+
if (!plugin) {
|
|
263
|
+
throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
|
|
264
|
+
operator
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const fieldSearchPlugin = searchPlugins[modelField.type];
|
|
269
|
+
const value = (0, _transformValueForSearch.transformValueForSearch)({
|
|
270
|
+
plugins: searchPlugins,
|
|
271
|
+
field: cmsField,
|
|
272
|
+
value: where[key]
|
|
273
|
+
});
|
|
274
|
+
const fieldPath = createFieldPath({
|
|
275
|
+
searchPlugin: fieldSearchPlugin,
|
|
276
|
+
modelField,
|
|
277
|
+
parentPath: parentPath
|
|
278
|
+
});
|
|
279
|
+
const keyword = hasKeyword(modelField);
|
|
280
|
+
plugin.apply(query, {
|
|
281
|
+
basePath: fieldPath,
|
|
282
|
+
path: keyword ? `${fieldPath}.keyword` : fieldPath,
|
|
283
|
+
value,
|
|
284
|
+
keyword
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return query;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const createElasticsearchQueryBody = params => {
|
|
292
|
+
const {
|
|
293
|
+
plugins,
|
|
294
|
+
model,
|
|
295
|
+
args,
|
|
296
|
+
parentPath = null
|
|
297
|
+
} = params;
|
|
298
|
+
const {
|
|
299
|
+
where,
|
|
300
|
+
after,
|
|
301
|
+
limit,
|
|
302
|
+
sort: initialSort
|
|
303
|
+
} = args;
|
|
304
|
+
const modelFields = (0, _fields.createModelFields)(plugins, model);
|
|
305
|
+
const searchPlugins = (0, _searchPluginsList.searchPluginsList)(plugins);
|
|
306
|
+
const query = execElasticsearchBuildQueryPlugins({
|
|
307
|
+
model,
|
|
308
|
+
plugins,
|
|
309
|
+
where,
|
|
310
|
+
modelFields,
|
|
311
|
+
parentPath,
|
|
312
|
+
searchPlugins
|
|
313
|
+
});
|
|
314
|
+
const queryPlugins = plugins.byType(_CmsEntryElasticsearchQueryModifierPlugin.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
|
|
315
|
+
return !pl.modelId || pl.modelId === model.modelId;
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
for (const pl of queryPlugins) {
|
|
319
|
+
pl.modifyQuery({
|
|
320
|
+
query,
|
|
321
|
+
model,
|
|
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
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const body = {
|
|
346
|
+
query: {
|
|
347
|
+
bool: {
|
|
348
|
+
must: query.must.length > 0 ? query.must : undefined,
|
|
349
|
+
must_not: query.must_not.length > 0 ? query.must_not : undefined,
|
|
350
|
+
should: query.should.length > 0 ? query.should : undefined,
|
|
351
|
+
filter: query.filter.length > 0 ? query.filter : undefined
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
sort,
|
|
355
|
+
size: limit + 1,
|
|
356
|
+
// eslint-disable-next-line
|
|
357
|
+
search_after: (0, _cursors.decodeCursor)(after),
|
|
358
|
+
// eslint-disable-next-line
|
|
359
|
+
track_total_hits: true
|
|
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;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
exports.createElasticsearchQueryBody = createElasticsearchQueryBody;
|