@webiny/api-headless-cms-ddb-es 5.34.8-beta.1 → 5.35.0-beta.0
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,30 +1,26 @@
|
|
|
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.createModelFields = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
10
|
+
var _plugins = require("../../../plugins");
|
|
14
11
|
const createSystemField = field => {
|
|
15
12
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
16
13
|
id: field.fieldId,
|
|
17
14
|
label: field.fieldId
|
|
18
15
|
});
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
const createSystemFields = () => {
|
|
22
18
|
return {
|
|
23
19
|
id: {
|
|
24
20
|
type: "text",
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
systemField: true,
|
|
22
|
+
searchable: true,
|
|
23
|
+
sortable: true,
|
|
28
24
|
field: createSystemField({
|
|
29
25
|
storageId: "id",
|
|
30
26
|
fieldId: "id",
|
|
@@ -34,9 +30,9 @@ const createSystemFields = () => {
|
|
|
34
30
|
},
|
|
35
31
|
entryId: {
|
|
36
32
|
type: "text",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
systemField: true,
|
|
34
|
+
searchable: true,
|
|
35
|
+
sortable: true,
|
|
40
36
|
field: createSystemField({
|
|
41
37
|
storageId: "entryId",
|
|
42
38
|
fieldId: "entryId",
|
|
@@ -48,9 +44,9 @@ const createSystemFields = () => {
|
|
|
48
44
|
type: "date",
|
|
49
45
|
unmappedType: "date",
|
|
50
46
|
keyword: false,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
systemField: true,
|
|
48
|
+
searchable: true,
|
|
49
|
+
sortable: true,
|
|
54
50
|
field: createSystemField({
|
|
55
51
|
storageId: "savedOn",
|
|
56
52
|
fieldId: "savedOn",
|
|
@@ -65,9 +61,9 @@ const createSystemFields = () => {
|
|
|
65
61
|
type: "date",
|
|
66
62
|
unmappedType: "date",
|
|
67
63
|
keyword: false,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
systemField: true,
|
|
65
|
+
searchable: true,
|
|
66
|
+
sortable: true,
|
|
71
67
|
field: createSystemField({
|
|
72
68
|
storageId: "createdOn",
|
|
73
69
|
fieldId: "createdOn",
|
|
@@ -81,9 +77,9 @@ const createSystemFields = () => {
|
|
|
81
77
|
createdBy: {
|
|
82
78
|
type: "text",
|
|
83
79
|
unmappedType: undefined,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
systemField: true,
|
|
81
|
+
searchable: true,
|
|
82
|
+
sortable: false,
|
|
87
83
|
path: "createdBy.id",
|
|
88
84
|
field: createSystemField({
|
|
89
85
|
storageId: "createdBy",
|
|
@@ -95,9 +91,9 @@ const createSystemFields = () => {
|
|
|
95
91
|
ownedBy: {
|
|
96
92
|
type: "text",
|
|
97
93
|
unmappedType: undefined,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
systemField: true,
|
|
95
|
+
searchable: true,
|
|
96
|
+
sortable: false,
|
|
101
97
|
path: "ownedBy.id",
|
|
102
98
|
field: createSystemField({
|
|
103
99
|
storageId: "ownedBy",
|
|
@@ -110,9 +106,9 @@ const createSystemFields = () => {
|
|
|
110
106
|
type: "number",
|
|
111
107
|
unmappedType: undefined,
|
|
112
108
|
keyword: false,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
systemField: true,
|
|
110
|
+
searchable: true,
|
|
111
|
+
sortable: true,
|
|
116
112
|
field: createSystemField({
|
|
117
113
|
storageId: "version",
|
|
118
114
|
fieldId: "version",
|
|
@@ -124,9 +120,9 @@ const createSystemFields = () => {
|
|
|
124
120
|
type: "string",
|
|
125
121
|
unmappedType: undefined,
|
|
126
122
|
keyword: false,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
systemField: true,
|
|
124
|
+
searchable: true,
|
|
125
|
+
sortable: false,
|
|
130
126
|
field: createSystemField({
|
|
131
127
|
storageId: "status",
|
|
132
128
|
fieldId: "status",
|
|
@@ -136,7 +132,38 @@ const createSystemFields = () => {
|
|
|
136
132
|
}
|
|
137
133
|
};
|
|
138
134
|
};
|
|
139
|
-
|
|
135
|
+
const buildCustomFields = params => {
|
|
136
|
+
const {
|
|
137
|
+
fields,
|
|
138
|
+
fieldTypePlugins
|
|
139
|
+
} = params;
|
|
140
|
+
return fields.reduce((collection, field) => {
|
|
141
|
+
const typePlugin = fieldTypePlugins[field.fieldType];
|
|
142
|
+
if (!typePlugin) {
|
|
143
|
+
return collection;
|
|
144
|
+
}
|
|
145
|
+
let unmappedType = undefined;
|
|
146
|
+
if (typePlugin.unmappedType) {
|
|
147
|
+
unmappedType = typePlugin.unmappedType(field);
|
|
148
|
+
}
|
|
149
|
+
collection[field.fieldId] = {
|
|
150
|
+
type: field.fieldType,
|
|
151
|
+
field: createSystemField({
|
|
152
|
+
storageId: field.fieldId,
|
|
153
|
+
fieldId: field.fieldId,
|
|
154
|
+
type: field.fieldType
|
|
155
|
+
}),
|
|
156
|
+
unmappedType,
|
|
157
|
+
fullTextSearch: field.searchable ? typePlugin.fullTextSearch : false,
|
|
158
|
+
searchable: field.searchable || typePlugin.searchable,
|
|
159
|
+
sortable: field.sortable || typePlugin.sortable,
|
|
160
|
+
systemField: false,
|
|
161
|
+
path: field.path,
|
|
162
|
+
parents: []
|
|
163
|
+
};
|
|
164
|
+
return collection;
|
|
165
|
+
}, {});
|
|
166
|
+
};
|
|
140
167
|
const buildFieldsList = params => {
|
|
141
168
|
const {
|
|
142
169
|
plugins,
|
|
@@ -145,25 +172,20 @@ const buildFieldsList = params => {
|
|
|
145
172
|
} = params;
|
|
146
173
|
return fields.reduce((result, field) => {
|
|
147
174
|
var _field$settings;
|
|
148
|
-
|
|
149
175
|
const plugin = plugins[field.type];
|
|
150
|
-
|
|
151
176
|
if (!plugin) {
|
|
152
177
|
throw new _error.default(`There is no plugin for field type "${field.type}".`);
|
|
153
178
|
}
|
|
154
|
-
|
|
155
179
|
const {
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
searchable,
|
|
181
|
+
sortable,
|
|
158
182
|
unmappedType,
|
|
159
183
|
fullTextSearch
|
|
160
184
|
} = plugin;
|
|
161
185
|
/**
|
|
162
186
|
* If a field has child fields, go through them and add them to a result.
|
|
163
187
|
*/
|
|
164
|
-
|
|
165
188
|
const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
|
|
166
|
-
|
|
167
189
|
if (childFields.length > 0) {
|
|
168
190
|
/**
|
|
169
191
|
* Let's build all the child fields
|
|
@@ -177,72 +199,63 @@ const buildFieldsList = params => {
|
|
|
177
199
|
type: field.type
|
|
178
200
|
}]
|
|
179
201
|
});
|
|
180
|
-
/**
|
|
181
|
-
*
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
202
|
Object.assign(result, childResult);
|
|
185
203
|
}
|
|
186
|
-
|
|
187
204
|
const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(".");
|
|
188
205
|
result[identifier] = {
|
|
189
206
|
type: field.type,
|
|
190
207
|
parents,
|
|
191
|
-
|
|
192
|
-
|
|
208
|
+
searchable,
|
|
209
|
+
sortable,
|
|
193
210
|
fullTextSearch,
|
|
194
211
|
unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
|
|
195
|
-
|
|
212
|
+
systemField: false,
|
|
196
213
|
field
|
|
197
214
|
};
|
|
198
215
|
return result;
|
|
199
216
|
}, {});
|
|
200
217
|
};
|
|
201
|
-
|
|
202
218
|
const createModelFields = ({
|
|
203
219
|
plugins,
|
|
204
|
-
|
|
220
|
+
model
|
|
205
221
|
}) => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
222
|
+
const fields = model.fields;
|
|
223
|
+
const fieldDefinitionPlugins = plugins.byType(_plugins.CmsElasticsearchModelFieldPlugin.type).filter(plugin => {
|
|
224
|
+
return plugin.canBeApplied(model.modelId);
|
|
225
|
+
});
|
|
209
226
|
/**
|
|
210
227
|
* Collect all unmappedType from elastic plugins.
|
|
211
228
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
229
|
const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
|
|
215
230
|
if (!plugin.unmappedType) {
|
|
216
231
|
return acc;
|
|
217
232
|
}
|
|
218
|
-
|
|
219
233
|
acc[plugin.fieldType] = plugin.unmappedType;
|
|
220
234
|
return acc;
|
|
221
235
|
}, {});
|
|
222
236
|
/**
|
|
223
237
|
* Collect all field types from the plugins.
|
|
224
238
|
*/
|
|
225
|
-
|
|
226
239
|
const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
|
|
227
240
|
const {
|
|
228
241
|
fieldType,
|
|
229
|
-
isSearchable,
|
|
230
|
-
isSortable,
|
|
231
242
|
fullTextSearch
|
|
232
243
|
} = plugin;
|
|
233
244
|
types[fieldType] = {
|
|
234
245
|
unmappedType: unmappedTypes[fieldType],
|
|
235
|
-
isSearchable,
|
|
236
|
-
isSortable,
|
|
246
|
+
searchable: plugin.isSearchable,
|
|
247
|
+
sortable: plugin.isSortable,
|
|
237
248
|
fullTextSearch
|
|
238
249
|
};
|
|
239
250
|
return types;
|
|
240
251
|
}, {});
|
|
241
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()),
|
|
252
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()), buildCustomFields({
|
|
253
|
+
fields: fieldDefinitionPlugins,
|
|
254
|
+
fieldTypePlugins
|
|
255
|
+
})), buildFieldsList({
|
|
242
256
|
fields,
|
|
243
257
|
plugins: fieldTypePlugins,
|
|
244
258
|
parents: []
|
|
245
259
|
}));
|
|
246
260
|
};
|
|
247
|
-
|
|
248
261
|
exports.createModelFields = createModelFields;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","isSystemField","isSearchable","isSortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildFieldsList","params","plugins","fields","reduce","result","plugin","WebinyError","fullTextSearch","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","unmappedTypes","byType","acc","fieldType","fieldTypePlugins","types"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: CmsModelField) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: CmsModelField) => string | undefined;\n isSearchable: boolean;\n isSortable: boolean;\n fullTextSearch?: boolean;\n}\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { isSearchable, isSortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n /**\n *\n */\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n isSearchable,\n isSortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n isSystemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n fields?: CmsModelField[];\n}\nexport const createModelFields = ({ plugins, fields }: Params) => {\n if (!fields || fields.length === 0) {\n return createSystemFields();\n }\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, isSearchable, isSortable, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n isSearchable,\n isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: []\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAQA,MAAMA,iBAAiB,GAAIC,KAAD,IAAgD;EACtE,mEACOA,KADP;IAEIC,EAAE,EAAED,KAAK,CAACE,OAFd;IAGIC,KAAK,EAAEH,KAAK,CAACE;EAHjB;AAKH,CAND;;AAQA,MAAME,kBAAkB,GAAG,MAAmB;EAC1C,OAAO;IACHH,EAAE,EAAE;MACAI,IAAI,EAAE,MADN;MAEAC,aAAa,EAAE,IAFf;MAGAC,YAAY,EAAE,IAHd;MAIAC,UAAU,EAAE,IAJZ;MAKAR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,IADU;QAErBP,OAAO,EAAE,IAFY;QAGrBG,IAAI,EAAE;MAHe,CAAD,CALxB;MAUAK,OAAO,EAAE;IAVT,CADD;IAaHC,OAAO,EAAE;MACLN,IAAI,EAAE,MADD;MAELC,aAAa,EAAE,IAFV;MAGLC,YAAY,EAAE,IAHT;MAILC,UAAU,EAAE,IAJP;MAKLR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,SADU;QAErBP,OAAO,EAAE,SAFY;QAGrBG,IAAI,EAAE;MAHe,CAAD,CALnB;MAULK,OAAO,EAAE;IAVJ,CAbN;IAyBHE,OAAO,EAAE;MACLP,IAAI,EAAE,MADD;MAELQ,YAAY,EAAE,MAFT;MAGLC,OAAO,EAAE,KAHJ;MAILR,aAAa,EAAE,IAJV;MAKLC,YAAY,EAAE,IALT;MAMLC,UAAU,EAAE,IANP;MAOLR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,SADU;QAErBP,OAAO,EAAE,SAFY;QAGrBG,IAAI,E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AAP;IACH;;IACDA,GAAG,CAACf,MAAM,CAACgB,SAAR,CAAH,GAAwBhB,MAAM,CAAChB,YAA/B;IACA,OAAO+B,GAAP;EACH,CARiB,EAQf,EARe,CAAtB;EASA;AACJ;AACA;;EACI,MAAME,gBAAgB,GAAGrB,OAAO,CAC3BkB,MADoB,CACiB,4BADjB,EAEpBhB,MAFoB,CAEK,CAACoB,KAAD,EAAQlB,MAAR,KAAmB;IACzC,MAAM;MAAEgB,SAAF;MAAatC,YAAb;MAA2BC,UAA3B;MAAuCuB;IAAvC,IAA0DF,MAAhE;IACAkB,KAAK,CAACF,SAAD,CAAL,GAAmB;MACfhC,YAAY,EAAE6B,aAAa,CAACG,SAAD,CADZ;MAEftC,YAFe;MAGfC,UAHe;MAIfuB;IAJe,CAAnB;IAMA,OAAOgB,KAAP;EACH,CAXoB,EAWlB,EAXkB,CAAzB;EAaA,mEACO3C,kBAAkB,EADzB,GAEOmB,eAAe,CAAC;IACfG,MADe;IAEfD,OAAO,EAAEqB,gBAFM;IAGfpC,OAAO,EAAE;EAHM,CAAD,CAFtB;AAQH,CAxCM"}
|
|
1
|
+
{"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","systemField","searchable","sortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildCustomFields","params","fields","fieldTypePlugins","reduce","collection","typePlugin","fieldType","fullTextSearch","buildFieldsList","plugins","result","plugin","WebinyError","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","model","fieldDefinitionPlugins","byType","CmsElasticsearchModelFieldPlugin","filter","canBeApplied","modelId","unmappedTypes","acc","types","isSearchable","isSortable"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\nimport { CmsElasticsearchModelFieldPlugin } from \"~/plugins\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n searchable: boolean;\n sortable: boolean;\n fullTextSearch?: boolean;\n}\n\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildCustomFieldsParams {\n fields: CmsElasticsearchModelFieldPlugin[];\n fieldTypePlugins: FieldTypePlugins;\n}\n\nconst buildCustomFields = (params: BuildCustomFieldsParams) => {\n const { fields, fieldTypePlugins } = params;\n\n return fields.reduce<ModelFields>((collection, field) => {\n const typePlugin = fieldTypePlugins[field.fieldType];\n if (!typePlugin) {\n return collection;\n }\n let unmappedType: string | undefined = undefined;\n if (typePlugin.unmappedType) {\n unmappedType = typePlugin.unmappedType(field);\n }\n\n collection[field.fieldId] = {\n type: field.fieldType,\n field: createSystemField({\n storageId: field.fieldId,\n fieldId: field.fieldId,\n type: field.fieldType\n }),\n unmappedType,\n fullTextSearch: field.searchable ? typePlugin.fullTextSearch : false,\n searchable: field.searchable || typePlugin.searchable,\n sortable: field.sortable || typePlugin.sortable,\n systemField: false,\n path: field.path,\n parents: []\n };\n\n return collection;\n }, {});\n};\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\n\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { searchable, sortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n searchable,\n sortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n systemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n}\n\nexport const createModelFields = ({ plugins, model }: Params) => {\n const fields = model.fields;\n const fieldDefinitionPlugins = plugins\n .byType<CmsElasticsearchModelFieldPlugin>(CmsElasticsearchModelFieldPlugin.type)\n .filter(plugin => {\n return plugin.canBeApplied(model.modelId);\n });\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n searchable: plugin.isSearchable,\n sortable: plugin.isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildCustomFields({\n fields: fieldDefinitionPlugins,\n fieldTypePlugins\n }),\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AK,EAAErB,MAAM,KAAK;IACzC,MAAM;MAAEL,SAAS;MAAEC;IAAe,CAAC,GAAGI,MAAM;IAC5CqB,KAAK,CAAC1B,SAAS,CAAC,GAAG;MACfjB,YAAY,EAAEyC,aAAa,CAACxB,SAAS,CAAC;MACtCvB,UAAU,EAAE4B,MAAM,CAACsB,YAAY;MAC/BjD,QAAQ,EAAE2B,MAAM,CAACuB,UAAU;MAC3B3B;IACJ,CAAC;IACD,OAAOyB,KAAK;EAChB,CAAC,EAAE,CAAC,CAAC,CAAC;EAEV,+FACOpD,kBAAkB,EAAE,GACpBmB,iBAAiB,CAAC;IACjBE,MAAM,EAAEuB,sBAAsB;IAC9BtB;EACJ,CAAC,CAAC,GACCM,eAAe,CAAC;IACfP,MAAM;IACNQ,OAAO,EAAEP,gBAAgB;IACzBhB,OAAO,EAAE;EACb,CAAC,CAAC;AAEV,CAAC;AAAC"}
|
|
@@ -1,20 +1,14 @@
|
|
|
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.createApplyFiltering = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
var _transformValueForSearch = require("../transformValueForSearch");
|
|
13
|
-
|
|
14
10
|
var _keyword = require("../keyword");
|
|
15
|
-
|
|
16
11
|
var _path = require("./path");
|
|
17
|
-
|
|
18
12
|
const createApplyFiltering = ({
|
|
19
13
|
operatorPlugins,
|
|
20
14
|
searchPlugins
|
|
@@ -31,13 +25,11 @@ const createApplyFiltering = ({
|
|
|
31
25
|
field
|
|
32
26
|
} = params;
|
|
33
27
|
const plugin = operatorPlugins[operator];
|
|
34
|
-
|
|
35
28
|
if (!plugin) {
|
|
36
|
-
throw new _error.default("
|
|
29
|
+
throw new _error.default(`Elasticsearch operator "${operator}" plugin missing.`, "PLUGIN_MISSING", {
|
|
37
30
|
operator
|
|
38
31
|
});
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
const value = (0, _transformValueForSearch.transformValueForSearch)({
|
|
42
34
|
plugins: searchPlugins,
|
|
43
35
|
field: field.field,
|
|
@@ -62,5 +54,4 @@ const createApplyFiltering = ({
|
|
|
62
54
|
});
|
|
63
55
|
};
|
|
64
56
|
};
|
|
65
|
-
|
|
66
57
|
exports.createApplyFiltering = createApplyFiltering;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createApplyFiltering","operatorPlugins","searchPlugins","createFieldPath","createFieldPathFactory","plugins","params","key","value","initialValue","query","operator","field","plugin","WebinyError","transformValueForSearch","keyword","hasKeyword","basePath","path","apply","name","fieldId"],"sources":["applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport {\n ElasticsearchQueryBuilderOperatorPlugins,\n ElasticsearchQuerySearchValuePlugins\n} from \"~/operations/entry/elasticsearch/types\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\nimport { ApplyFilteringCb } from \"~/plugins/CmsEntryFilterPlugin\";\n\ninterface CreateParams {\n operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;\n searchPlugins: ElasticsearchQuerySearchValuePlugins;\n}\n\nexport const createApplyFiltering = ({\n operatorPlugins,\n searchPlugins\n}: CreateParams): ApplyFilteringCb => {\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n return params => {\n const { key, value: initialValue, query, operator, field } = params;\n\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"
|
|
1
|
+
{"version":3,"names":["createApplyFiltering","operatorPlugins","searchPlugins","createFieldPath","createFieldPathFactory","plugins","params","key","value","initialValue","query","operator","field","plugin","WebinyError","transformValueForSearch","keyword","hasKeyword","basePath","path","apply","name","fieldId"],"sources":["applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport {\n ElasticsearchQueryBuilderOperatorPlugins,\n ElasticsearchQuerySearchValuePlugins\n} from \"~/operations/entry/elasticsearch/types\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\nimport { ApplyFilteringCb } from \"~/plugins/CmsEntryFilterPlugin\";\n\ninterface CreateParams {\n operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;\n searchPlugins: ElasticsearchQuerySearchValuePlugins;\n}\n\nexport const createApplyFiltering = ({\n operatorPlugins,\n searchPlugins\n}: CreateParams): ApplyFilteringCb => {\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n return params => {\n const { key, value: initialValue, query, operator, field } = params;\n\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\n `Elasticsearch operator \"${operator}\" plugin missing.`,\n \"PLUGIN_MISSING\",\n {\n operator\n }\n );\n }\n\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: field.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(field);\n\n const { basePath, path } = createFieldPath({\n field,\n value,\n key,\n keyword\n });\n\n plugin.apply(query, {\n name: field.field.fieldId,\n basePath,\n path,\n value,\n keyword\n });\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAKA;AAQO,MAAMA,oBAAoB,GAAG,CAAC;EACjCC,eAAe;EACfC;AACU,CAAC,KAAuB;EAClC,MAAMC,eAAe,GAAG,IAAAC,4BAAsB,EAAC;IAC3CC,OAAO,EAAEH;EACb,CAAC,CAAC;EAEF,OAAOI,MAAM,IAAI;IACb,MAAM;MAAEC,GAAG;MAAEC,KAAK,EAAEC,YAAY;MAAEC,KAAK;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGN,MAAM;IAEnE,MAAMO,MAAM,GAAGZ,eAAe,CAACU,QAAQ,CAAC;IACxC,IAAI,CAACE,MAAM,EAAE;MACT,MAAM,IAAIC,cAAW,CAChB,2BAA0BH,QAAS,mBAAkB,EACtD,gBAAgB,EAChB;QACIA;MACJ,CAAC,CACJ;IACL;IAEA,MAAMH,KAAK,GAAG,IAAAO,gDAAuB,EAAC;MAClCV,OAAO,EAAEH,aAAa;MACtBU,KAAK,EAAEA,KAAK,CAACA,KAAK;MAClBJ,KAAK,EAAEC;IACX,CAAC,CAAC;IAEF,MAAMO,OAAO,GAAG,IAAAC,mBAAU,EAACL,KAAK,CAAC;IAEjC,MAAM;MAAEM,QAAQ;MAAEC;IAAK,CAAC,GAAGhB,eAAe,CAAC;MACvCS,KAAK;MACLJ,KAAK;MACLD,GAAG;MACHS;IACJ,CAAC,CAAC;IAEFH,MAAM,CAACO,KAAK,CAACV,KAAK,EAAE;MAChBW,IAAI,EAAET,KAAK,CAACA,KAAK,CAACU,OAAO;MACzBJ,QAAQ;MACRC,IAAI;MACJX,KAAK;MACLQ;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -1,51 +1,37 @@
|
|
|
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.createExecFiltering = 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
|
var _search = require("../plugins/search");
|
|
15
|
-
|
|
16
11
|
var _operator = require("../plugins/operator");
|
|
17
|
-
|
|
18
12
|
var _initialQuery = require("../initialQuery");
|
|
19
|
-
|
|
20
13
|
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
21
|
-
|
|
22
14
|
var _values = require("./values");
|
|
23
|
-
|
|
24
15
|
var _populated = require("./populated");
|
|
25
|
-
|
|
26
16
|
var _applyFiltering = require("./applyFiltering");
|
|
27
|
-
|
|
28
17
|
var _CmsEntryFilterPlugin = require("../../../../plugins/CmsEntryFilterPlugin");
|
|
29
|
-
|
|
30
18
|
var _assignMinimumShouldMatchToQuery = require("../assignMinimumShouldMatchToQuery");
|
|
31
|
-
|
|
32
19
|
const createExecFiltering = params => {
|
|
33
20
|
const {
|
|
34
21
|
fields,
|
|
35
22
|
plugins,
|
|
36
23
|
model
|
|
37
24
|
} = params;
|
|
25
|
+
|
|
38
26
|
/**
|
|
39
27
|
* We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.
|
|
40
28
|
*/
|
|
41
|
-
|
|
42
29
|
const searchPlugins = (0, _search.createSearchPluginList)({
|
|
43
30
|
plugins
|
|
44
31
|
});
|
|
45
32
|
/**
|
|
46
33
|
* We need the operator plugins, which we execute on our where conditions.
|
|
47
34
|
*/
|
|
48
|
-
|
|
49
35
|
const operatorPlugins = (0, _operator.createOperatorPluginList)({
|
|
50
36
|
plugins,
|
|
51
37
|
locale: model.locale
|
|
@@ -58,19 +44,15 @@ const createExecFiltering = params => {
|
|
|
58
44
|
collection[plugin.fieldType] = plugin;
|
|
59
45
|
return collection;
|
|
60
46
|
}, {});
|
|
61
|
-
|
|
62
47
|
const getFilterPlugin = type => {
|
|
63
48
|
const plugin = filteringPlugins[type] || filteringPlugins["*"];
|
|
64
|
-
|
|
65
49
|
if (plugin) {
|
|
66
50
|
return plugin;
|
|
67
51
|
}
|
|
68
|
-
|
|
69
52
|
throw new _error.default(`There is no filtering plugin for the given field type "${type}".`, "FILTERING_PLUGIN_ERROR", {
|
|
70
53
|
type
|
|
71
54
|
});
|
|
72
55
|
};
|
|
73
|
-
|
|
74
56
|
const execFiltering = params => {
|
|
75
57
|
const {
|
|
76
58
|
where: initialWhere,
|
|
@@ -79,63 +61,50 @@ const createExecFiltering = params => {
|
|
|
79
61
|
/**
|
|
80
62
|
* No point in continuing if no "where" conditions exist.
|
|
81
63
|
*/
|
|
82
|
-
|
|
83
64
|
const keys = Object.keys(initialWhere);
|
|
84
|
-
|
|
85
65
|
if (keys.length === 0) {
|
|
86
66
|
return;
|
|
87
67
|
}
|
|
88
|
-
|
|
89
68
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
90
|
-
|
|
91
69
|
for (const key in where) {
|
|
92
70
|
const value = where[key];
|
|
93
71
|
/**
|
|
94
72
|
* We always skip if no value is defined.
|
|
95
73
|
* Only skip undefined value, null is valid.
|
|
96
74
|
*/
|
|
97
|
-
|
|
98
75
|
if (value === undefined) {
|
|
99
76
|
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
77
|
+
}
|
|
78
|
+
//
|
|
102
79
|
/**
|
|
103
80
|
* When we are running with AND, the "value" MUST be an array.
|
|
104
|
-
*/
|
|
105
|
-
else if (key === "AND") {
|
|
81
|
+
*/else if (key === "AND") {
|
|
106
82
|
const childWhereList = (0, _values.getWhereValues)(value, "AND");
|
|
107
83
|
const childQuery = (0, _initialQuery.createBaseQuery)();
|
|
108
|
-
|
|
109
84
|
for (const childWhere of childWhereList) {
|
|
110
85
|
execFiltering({
|
|
111
86
|
query: childQuery,
|
|
112
87
|
where: childWhere
|
|
113
88
|
});
|
|
114
89
|
}
|
|
115
|
-
|
|
116
90
|
const childQueryBool = (0, _populated.getPopulated)(childQuery);
|
|
117
|
-
|
|
118
91
|
if (Object.keys(childQueryBool).length === 0) {
|
|
119
92
|
continue;
|
|
120
93
|
}
|
|
121
|
-
|
|
122
94
|
query.filter.push({
|
|
123
95
|
bool: childQueryBool
|
|
124
96
|
});
|
|
125
97
|
continue;
|
|
126
|
-
}
|
|
127
|
-
|
|
98
|
+
}
|
|
99
|
+
//
|
|
128
100
|
/**
|
|
129
101
|
* When we are running with OR, the "value" must be an array.
|
|
130
|
-
*/
|
|
131
|
-
else if (key === "OR") {
|
|
102
|
+
*/else if (key === "OR") {
|
|
132
103
|
const childWhereList = (0, _values.getWhereValues)(value, "OR");
|
|
133
104
|
/**
|
|
134
105
|
* Each of the conditions MUST produce it's own should section.
|
|
135
106
|
*/
|
|
136
|
-
|
|
137
107
|
const should = [];
|
|
138
|
-
|
|
139
108
|
for (const childWhere of childWhereList) {
|
|
140
109
|
const childQuery = (0, _initialQuery.createBaseQuery)();
|
|
141
110
|
execFiltering({
|
|
@@ -143,58 +112,48 @@ const createExecFiltering = params => {
|
|
|
143
112
|
where: childWhere
|
|
144
113
|
});
|
|
145
114
|
const childQueryBool = (0, _populated.getPopulated)(childQuery);
|
|
146
|
-
|
|
147
115
|
if (Object.keys(childQueryBool).length === 0) {
|
|
148
116
|
continue;
|
|
149
117
|
}
|
|
150
|
-
|
|
151
118
|
should.push({
|
|
152
119
|
bool: childQueryBool
|
|
153
120
|
});
|
|
154
121
|
}
|
|
155
|
-
|
|
156
122
|
if (should.length === 0) {
|
|
157
123
|
continue;
|
|
158
124
|
}
|
|
159
|
-
|
|
160
125
|
query.should.push(...should);
|
|
161
126
|
/**
|
|
162
127
|
* If there are any should, minimum to have is 1.
|
|
163
128
|
* Of course, do not override if it's already set.
|
|
164
129
|
*/
|
|
165
|
-
|
|
166
130
|
(0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
|
|
167
131
|
query
|
|
168
132
|
});
|
|
169
133
|
continue;
|
|
170
134
|
}
|
|
171
|
-
|
|
172
135
|
const {
|
|
173
136
|
field: whereFieldId,
|
|
174
137
|
operator
|
|
175
138
|
} = (0, _apiElasticsearch.parseWhereKey)(key);
|
|
176
139
|
let fieldId = whereFieldId;
|
|
140
|
+
|
|
177
141
|
/**
|
|
178
142
|
* TODO This will be required until the storage operations receive the fieldId instead of field storageId.
|
|
179
143
|
* TODO For this to work without field searching, we need to refactor how the query looks like.
|
|
180
144
|
*
|
|
181
145
|
* Storage operations should NEVER receive an field storageId, only alias - fieldId.
|
|
182
146
|
*/
|
|
183
|
-
|
|
184
147
|
const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
|
|
185
|
-
|
|
186
148
|
if (!cmsModelField && !fields[fieldId]) {
|
|
187
|
-
throw new _error.default(`There is no CMS Model Field
|
|
149
|
+
throw new _error.default(`There is no CMS Model Field "${fieldId}".`);
|
|
188
150
|
} else if (cmsModelField) {
|
|
189
151
|
fieldId = cmsModelField.fieldId;
|
|
190
152
|
}
|
|
191
|
-
|
|
192
153
|
const field = fields[fieldId];
|
|
193
|
-
|
|
194
154
|
if (!field) {
|
|
195
155
|
throw new _error.default(`There is no field "${fieldId}".`);
|
|
196
156
|
}
|
|
197
|
-
|
|
198
157
|
const filterPlugin = getFilterPlugin(field.type);
|
|
199
158
|
filterPlugin.exec({
|
|
200
159
|
applyFiltering,
|
|
@@ -208,8 +167,6 @@ const createExecFiltering = params => {
|
|
|
208
167
|
});
|
|
209
168
|
}
|
|
210
169
|
};
|
|
211
|
-
|
|
212
170
|
return execFiltering;
|
|
213
171
|
};
|
|
214
|
-
|
|
215
172
|
exports.createExecFiltering = createExecFiltering;
|