@webiny/api-headless-cms-ddb-es 5.33.5-beta.0 → 5.34.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.js +1 -1
- package/definitions/entry.js +3 -7
- package/definitions/entry.js.map +1 -1
- package/definitions/entryElasticsearch.js +3 -7
- package/definitions/entryElasticsearch.js.map +1 -1
- package/definitions/group.js +3 -7
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +8 -7
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +1 -1
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +8 -1
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +1 -1
- package/elasticsearch/createElasticsearchIndex.js +1 -1
- package/elasticsearch/index.js +1 -1
- package/elasticsearch/indexing/index.js +1 -1
- package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
- package/elasticsearch/indexing/longTextIndexing.js +20 -4
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
- package/elasticsearch/search/refSearch.js +4 -2
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/helpers/entryIndexHelpers.js +6 -11
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/index.d.ts +0 -1
- package/helpers/index.js +0 -13
- package/helpers/index.js.map +1 -1
- package/index.js +17 -10
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +7 -9
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +34 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
- package/operations/entry/elasticsearch/body.d.ts +13 -0
- package/operations/entry/elasticsearch/body.js +162 -0
- package/operations/entry/elasticsearch/body.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +9 -0
- package/operations/entry/elasticsearch/fields.js +248 -0
- package/operations/entry/elasticsearch/fields.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +66 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
- package/operations/entry/elasticsearch/filtering/exec.js +215 -0
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/index.js +18 -0
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
- package/operations/entry/elasticsearch/filtering/path.js +52 -0
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +35 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js +18 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +78 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +58 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/populated.js +30 -0
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/values.js +28 -0
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +9 -0
- package/operations/entry/elasticsearch/fullTextSearch.js +34 -0
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js +52 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
- package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
- package/operations/entry/elasticsearch/initialQuery.js +117 -0
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
- package/operations/entry/elasticsearch/keyword.d.ts +2 -0
- package/operations/entry/elasticsearch/keyword.js +38 -0
- package/operations/entry/elasticsearch/keyword.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
- package/operations/entry/elasticsearch/plugins/operator.js +45 -0
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
- package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +9 -5
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
- package/operations/entry/elasticsearch/sort.d.ts +12 -0
- package/operations/entry/elasticsearch/sort.js +92 -0
- package/operations/entry/elasticsearch/sort.js.map +1 -0
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
- package/{helpers → operations/entry/elasticsearch}/transformValueForSearch.js +8 -3
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
- package/operations/entry/elasticsearch/types.d.ts +41 -0
- package/operations/entry/elasticsearch/types.js +5 -0
- package/operations/entry/elasticsearch/types.js.map +1 -0
- package/operations/entry/elasticsearchFields.js +3 -0
- package/operations/entry/elasticsearchFields.js.map +1 -1
- package/operations/entry/index.d.ts +0 -2
- package/operations/entry/index.js +100 -310
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/recordType.d.ts +3 -0
- package/operations/entry/recordType.js +24 -0
- package/operations/entry/recordType.js.map +1 -0
- package/operations/group/index.js +7 -12
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +4 -8
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +6 -10
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +4 -8
- package/operations/system/index.js.map +1 -1
- package/package.json +18 -19
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +1 -1
- package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
- package/plugins/CmsEntryFilterPlugin.js +31 -0
- package/plugins/CmsEntryFilterPlugin.js.map +1 -0
- package/helpers/createElasticsearchQueryBody.d.ts +0 -11
- package/helpers/createElasticsearchQueryBody.js +0 -618
- package/helpers/createElasticsearchQueryBody.js.map +0 -1
- package/helpers/fields.d.ts +0 -19
- package/helpers/fields.js +0 -196
- package/helpers/fields.js.map +0 -1
- package/helpers/searchPluginsList.d.ts +0 -6
- package/helpers/searchPluginsList.js.map +0 -1
- package/helpers/transformValueForSearch.d.ts +0 -12
- package/helpers/transformValueForSearch.js.map +0 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createExecFiltering = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _search = require("../plugins/search");
|
|
15
|
+
|
|
16
|
+
var _operator = require("../plugins/operator");
|
|
17
|
+
|
|
18
|
+
var _initialQuery = require("../initialQuery");
|
|
19
|
+
|
|
20
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
21
|
+
|
|
22
|
+
var _values = require("./values");
|
|
23
|
+
|
|
24
|
+
var _populated = require("./populated");
|
|
25
|
+
|
|
26
|
+
var _applyFiltering = require("./applyFiltering");
|
|
27
|
+
|
|
28
|
+
var _CmsEntryFilterPlugin = require("../../../../plugins/CmsEntryFilterPlugin");
|
|
29
|
+
|
|
30
|
+
var _assignMinimumShouldMatchToQuery = require("../assignMinimumShouldMatchToQuery");
|
|
31
|
+
|
|
32
|
+
const createExecFiltering = params => {
|
|
33
|
+
const {
|
|
34
|
+
fields,
|
|
35
|
+
plugins,
|
|
36
|
+
model
|
|
37
|
+
} = params;
|
|
38
|
+
/**
|
|
39
|
+
* We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
const searchPlugins = (0, _search.createSearchPluginList)({
|
|
43
|
+
plugins
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* We need the operator plugins, which we execute on our where conditions.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const operatorPlugins = (0, _operator.createOperatorPluginList)({
|
|
50
|
+
plugins,
|
|
51
|
+
locale: model.locale
|
|
52
|
+
});
|
|
53
|
+
const applyFiltering = (0, _applyFiltering.createApplyFiltering)({
|
|
54
|
+
operatorPlugins,
|
|
55
|
+
searchPlugins
|
|
56
|
+
});
|
|
57
|
+
const filteringPlugins = plugins.byType(_CmsEntryFilterPlugin.CmsEntryFilterPlugin.type).reduce((collection, plugin) => {
|
|
58
|
+
collection[plugin.fieldType] = plugin;
|
|
59
|
+
return collection;
|
|
60
|
+
}, {});
|
|
61
|
+
|
|
62
|
+
const getFilterPlugin = type => {
|
|
63
|
+
const plugin = filteringPlugins[type] || filteringPlugins["*"];
|
|
64
|
+
|
|
65
|
+
if (plugin) {
|
|
66
|
+
return plugin;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new _error.default(`There is no filtering plugin for the given field type "${type}".`, "FILTERING_PLUGIN_ERROR", {
|
|
70
|
+
type
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const execFiltering = params => {
|
|
75
|
+
const {
|
|
76
|
+
where: initialWhere,
|
|
77
|
+
query
|
|
78
|
+
} = params;
|
|
79
|
+
/**
|
|
80
|
+
* No point in continuing if no "where" conditions exist.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
const keys = Object.keys(initialWhere);
|
|
84
|
+
|
|
85
|
+
if (keys.length === 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
90
|
+
|
|
91
|
+
for (const key in where) {
|
|
92
|
+
const value = where[key];
|
|
93
|
+
/**
|
|
94
|
+
* We always skip if no value is defined.
|
|
95
|
+
* Only skip undefined value, null is valid.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
if (value === undefined) {
|
|
99
|
+
continue;
|
|
100
|
+
} //
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* When we are running with AND, the "value" MUST be an array.
|
|
104
|
+
*/
|
|
105
|
+
else if (key === "AND") {
|
|
106
|
+
const childWhereList = (0, _values.getWhereValues)(value, "AND");
|
|
107
|
+
const childQuery = (0, _initialQuery.createBaseQuery)();
|
|
108
|
+
|
|
109
|
+
for (const childWhere of childWhereList) {
|
|
110
|
+
execFiltering({
|
|
111
|
+
query: childQuery,
|
|
112
|
+
where: childWhere
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const childQueryBool = (0, _populated.getPopulated)(childQuery);
|
|
117
|
+
|
|
118
|
+
if (Object.keys(childQueryBool).length === 0) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
query.filter.push({
|
|
123
|
+
bool: childQueryBool
|
|
124
|
+
});
|
|
125
|
+
continue;
|
|
126
|
+
} //
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* When we are running with OR, the "value" must be an array.
|
|
130
|
+
*/
|
|
131
|
+
else if (key === "OR") {
|
|
132
|
+
const childWhereList = (0, _values.getWhereValues)(value, "OR");
|
|
133
|
+
/**
|
|
134
|
+
* Each of the conditions MUST produce it's own should section.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
const should = [];
|
|
138
|
+
|
|
139
|
+
for (const childWhere of childWhereList) {
|
|
140
|
+
const childQuery = (0, _initialQuery.createBaseQuery)();
|
|
141
|
+
execFiltering({
|
|
142
|
+
query: childQuery,
|
|
143
|
+
where: childWhere
|
|
144
|
+
});
|
|
145
|
+
const childQueryBool = (0, _populated.getPopulated)(childQuery);
|
|
146
|
+
|
|
147
|
+
if (Object.keys(childQueryBool).length === 0) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
should.push({
|
|
152
|
+
bool: childQueryBool
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (should.length === 0) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
query.should.push(...should);
|
|
161
|
+
/**
|
|
162
|
+
* If there are any should, minimum to have is 1.
|
|
163
|
+
* Of course, do not override if it's already set.
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
(0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
|
|
167
|
+
query
|
|
168
|
+
});
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const {
|
|
173
|
+
field: whereFieldId,
|
|
174
|
+
operator
|
|
175
|
+
} = (0, _apiElasticsearch.parseWhereKey)(key);
|
|
176
|
+
let fieldId = whereFieldId;
|
|
177
|
+
/**
|
|
178
|
+
* TODO This will be required until the storage operations receive the fieldId instead of field storageId.
|
|
179
|
+
* TODO For this to work without field searching, we need to refactor how the query looks like.
|
|
180
|
+
*
|
|
181
|
+
* Storage operations should NEVER receive an field storageId, only alias - fieldId.
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
|
|
185
|
+
|
|
186
|
+
if (!cmsModelField && !fields[fieldId]) {
|
|
187
|
+
throw new _error.default(`There is no CMS Model Field field "${fieldId}".`);
|
|
188
|
+
} else if (cmsModelField) {
|
|
189
|
+
fieldId = cmsModelField.fieldId;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const field = fields[fieldId];
|
|
193
|
+
|
|
194
|
+
if (!field) {
|
|
195
|
+
throw new _error.default(`There is no field "${fieldId}".`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const filterPlugin = getFilterPlugin(field.type);
|
|
199
|
+
filterPlugin.exec({
|
|
200
|
+
applyFiltering,
|
|
201
|
+
getFilterPlugin,
|
|
202
|
+
key,
|
|
203
|
+
value,
|
|
204
|
+
operator,
|
|
205
|
+
field,
|
|
206
|
+
fields,
|
|
207
|
+
query
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
return execFiltering;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
exports.createExecFiltering = createExecFiltering;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createExecFiltering","params","fields","plugins","model","searchPlugins","createSearchPluginList","operatorPlugins","createOperatorPluginList","locale","applyFiltering","createApplyFiltering","filteringPlugins","byType","CmsEntryFilterPlugin","type","reduce","collection","plugin","fieldType","getFilterPlugin","WebinyError","execFiltering","where","initialWhere","query","keys","Object","length","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","filter","push","bool","should","assignMinimumShouldMatchToQuery","field","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","find","f","filterPlugin","exec"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"~/operations/entry/elasticsearch/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchBoolQueryConfig, Query } from \"@webiny/api-elasticsearch/types\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport { getWhereValues } from \"./values\";\nimport { getPopulated } from \"./populated\";\nimport { createApplyFiltering } from \"./applyFiltering\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n}\nexport interface ExecParams {\n where: CmsEntryListWhere;\n query: ElasticsearchBoolQueryConfig;\n}\nexport interface CreateExecFilteringResponse {\n (params: ExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model } = params;\n\n /**\n * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.\n */\n const searchPlugins = createSearchPluginList({\n plugins\n });\n /**\n * We need the operator plugins, which we execute on our where conditions.\n */\n const operatorPlugins = createOperatorPluginList({\n plugins,\n locale: model.locale\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n searchPlugins\n });\n\n const filteringPlugins = plugins\n .byType<CmsEntryFilterPlugin>(CmsEntryFilterPlugin.type)\n .reduce<Record<string, CmsEntryFilterPlugin>>((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {});\n\n const getFilterPlugin = (type: string) => {\n const plugin = filteringPlugins[type] || filteringPlugins[\"*\"];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filtering plugin for the given field type \"${type}\".`,\n \"FILTERING_PLUGIN_ERROR\",\n {\n type\n }\n );\n };\n\n const execFiltering = (params: ExecParams) => {\n const { where: initialWhere, query } = params;\n /**\n * No point in continuing if no \"where\" conditions exist.\n */\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n for (const key in where) {\n const value = where[key] as unknown as any;\n /**\n * We always skip if no value is defined.\n * Only skip undefined value, null is valid.\n */\n if (value === undefined) {\n continue;\n }\n //\n /**\n * When we are running with AND, the \"value\" MUST be an array.\n */\n else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n\n const childQuery = createBaseQuery();\n\n for (const childWhere of childWhereList) {\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({\n bool: childQueryBool\n });\n\n continue;\n }\n //\n /**\n * When we are running with OR, the \"value\" must be an array.\n */\n else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n /**\n * Each of the conditions MUST produce it's own should section.\n */\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({\n bool: childQueryBool\n });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n /**\n * If there are any should, minimum to have is 1.\n * Of course, do not override if it's already set.\n */\n assignMinimumShouldMatchToQuery({\n query\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n let fieldId: string = whereFieldId;\n\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\n */\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`);\n }\n const filterPlugin = getFilterPlugin(field.type);\n\n filterPlugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAcO,MAAMA,mBAAmB,GA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wHA,OAAOH,aAAP;AACH,CArKM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./exec";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _exec = require("./exec");
|
|
8
|
+
|
|
9
|
+
Object.keys(_exec).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _exec[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _exec[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./exec\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ElasticsearchQuerySearchValuePlugins, ModelField } from "../types";
|
|
2
|
+
interface FieldPathFactoryParams {
|
|
3
|
+
plugins: ElasticsearchQuerySearchValuePlugins;
|
|
4
|
+
}
|
|
5
|
+
interface FieldPathParams {
|
|
6
|
+
field: ModelField;
|
|
7
|
+
key: string;
|
|
8
|
+
value: any;
|
|
9
|
+
keyword: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const createFieldPathFactory: ({ plugins }: FieldPathFactoryParams) => (params: FieldPathParams) => {
|
|
12
|
+
basePath: string;
|
|
13
|
+
path: string;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFieldPathFactory = void 0;
|
|
7
|
+
|
|
8
|
+
const createFieldPathFactory = ({
|
|
9
|
+
plugins
|
|
10
|
+
}) => {
|
|
11
|
+
return params => {
|
|
12
|
+
const {
|
|
13
|
+
field,
|
|
14
|
+
key,
|
|
15
|
+
value,
|
|
16
|
+
keyword
|
|
17
|
+
} = params;
|
|
18
|
+
const plugin = plugins[field.type];
|
|
19
|
+
let fieldPath = null;
|
|
20
|
+
|
|
21
|
+
if (plugin) {
|
|
22
|
+
fieldPath = plugin.createPath({
|
|
23
|
+
field: field.field,
|
|
24
|
+
value,
|
|
25
|
+
key
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!fieldPath) {
|
|
30
|
+
fieldPath = field.field.storageId;
|
|
31
|
+
|
|
32
|
+
if (field.path) {
|
|
33
|
+
fieldPath = typeof field.path === "function" ? field.path(value) : field.path;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = [];
|
|
38
|
+
|
|
39
|
+
if (!field.isSystemField) {
|
|
40
|
+
result.push("values");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
result.push(...field.parents.map(p => p.storageId));
|
|
44
|
+
result.push(fieldPath);
|
|
45
|
+
return {
|
|
46
|
+
basePath: result.join("."),
|
|
47
|
+
path: result.concat(keyword ? ["keyword"] : []).join(".")
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.createFieldPathFactory = createFieldPathFactory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFieldPathFactory","plugins","params","field","key","value","keyword","plugin","type","fieldPath","createPath","storageId","path","result","isSystemField","push","parents","map","p","basePath","join","concat"],"sources":["path.ts"],"sourcesContent":["import {\n ElasticsearchQuerySearchValuePlugins,\n ModelField\n} from \"~/operations/entry/elasticsearch/types\";\n\ninterface FieldPathFactoryParams {\n plugins: ElasticsearchQuerySearchValuePlugins;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ plugins }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword } = params;\n const plugin = plugins[field.type];\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field: field.field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.field.storageId;\n if (field.path) {\n fieldPath = typeof field.path === \"function\" ? field.path(value) : field.path;\n }\n }\n\n const result: string[] = [];\n if (!field.isSystemField) {\n result.push(\"values\");\n }\n result.push(...field.parents.map(p => p.storageId));\n result.push(fieldPath);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"mappings":";;;;;;;AAeO,MAAMA,sBAAsB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAyC;EAC3E,OAAQC,MAAD,IAA6B;IAChC,MAAM;MAAEC,KAAF;MAASC,GAAT;MAAcC,KAAd;MAAqBC;IAArB,IAAiCJ,MAAvC;IACA,MAAMK,MAAM,GAAGN,OAAO,CAACE,KAAK,CAACK,IAAP,CAAtB;IAEA,IAAIC,SAAwB,GAAG,IAA/B;;IACA,IAAIF,MAAJ,EAAY;MACRE,SAAS,GAAGF,MAAM,CAACG,UAAP,CAAkB;QAAEP,KAAK,EAAEA,KAAK,CAACA,KAAf;QAAsBE,KAAtB;QAA6BD;MAA7B,CAAlB,CAAZ;IACH;;IACD,IAAI,CAACK,SAAL,EAAgB;MACZA,SAAS,GAAGN,KAAK,CAACA,KAAN,CAAYQ,SAAxB;;MACA,IAAIR,KAAK,CAACS,IAAV,EAAgB;QACZH,SAAS,GAAG,OAAON,KAAK,CAACS,IAAb,KAAsB,UAAtB,GAAmCT,KAAK,CAACS,IAAN,CAAWP,KAAX,CAAnC,GAAuDF,KAAK,CAACS,IAAzE;MACH;IACJ;;IAED,MAAMC,MAAgB,GAAG,EAAzB;;IACA,IAAI,CAACV,KAAK,CAACW,aAAX,EAA0B;MACtBD,MAAM,CAACE,IAAP,CAAY,QAAZ;IACH;;IACDF,MAAM,CAACE,IAAP,CAAY,GAAGZ,KAAK,CAACa,OAAN,CAAcC,GAAd,CAAkBC,CAAC,IAAIA,CAAC,CAACP,SAAzB,CAAf;IACAE,MAAM,CAACE,IAAP,CAAYN,SAAZ;IAEA,OAAO;MACHU,QAAQ,EAAEN,MAAM,CAACO,IAAP,CAAY,GAAZ,CADP;MAEHR,IAAI,EAAEC,MAAM,CAACQ,MAAP,CAAcf,OAAO,GAAG,CAAC,SAAD,CAAH,GAAiB,EAAtC,EAA0Cc,IAA1C,CAA+C,GAA/C;IAFH,CAAP;EAIH,CA1BD;AA2BH,CA5BM"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createDefaultFilterPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _CmsEntryFilterPlugin = require("../../../../../plugins/CmsEntryFilterPlugin");
|
|
13
|
+
|
|
14
|
+
const createDefaultFilterPlugin = () => {
|
|
15
|
+
const plugin = new _CmsEntryFilterPlugin.CmsEntryFilterPlugin({
|
|
16
|
+
fieldType: _CmsEntryFilterPlugin.CmsEntryFilterPlugin.ALL,
|
|
17
|
+
exec: params => {
|
|
18
|
+
const {
|
|
19
|
+
applyFiltering,
|
|
20
|
+
field
|
|
21
|
+
} = params;
|
|
22
|
+
|
|
23
|
+
if (!params.field.isSearchable) {
|
|
24
|
+
const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(".");
|
|
25
|
+
throw new _error.default(`Field "${identifier}" is not searchable.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
applyFiltering(params);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
plugin.name = `${plugin.type}.default.all`;
|
|
32
|
+
return plugin;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.createDefaultFilterPlugin = createDefaultFilterPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createDefaultFilterPlugin","plugin","CmsEntryFilterPlugin","fieldType","ALL","exec","params","applyFiltering","field","isSearchable","identifier","parents","map","p","fieldId","join","WebinyError","name","type"],"sources":["defaultFilterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\n\nexport const createDefaultFilterPlugin = () => {\n const plugin = new CmsEntryFilterPlugin({\n fieldType: CmsEntryFilterPlugin.ALL,\n exec: params => {\n const { applyFiltering, field } = params;\n if (!params.field.isSearchable) {\n const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(\n \".\"\n );\n throw new WebinyError(`Field \"${identifier}\" is not searchable.`);\n }\n applyFiltering(params);\n }\n });\n\n plugin.name = `${plugin.type}.default.all`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,0CAAJ,CAAyB;IACpCC,SAAS,EAAED,0CAAA,CAAqBE,GADI;IAEpCC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QAAEC,cAAF;QAAkBC;MAAlB,IAA4BF,MAAlC;;MACA,IAAI,CAACA,MAAM,CAACE,KAAP,CAAaC,YAAlB,EAAgC;QAC5B,MAAMC,UAAU,GAAG,CAAC,GAAGF,KAAK,CAACG,OAAN,CAAcC,GAAd,CAAkBC,CAAC,IAAIA,CAAC,CAACC,OAAzB,CAAJ,EAAuCN,KAAK,CAACA,KAAN,CAAYM,OAAnD,EAA4DC,IAA5D,CACf,GADe,CAAnB;QAGA,MAAM,IAAIC,cAAJ,CAAiB,UAASN,UAAW,sBAArC,CAAN;MACH;;MACDH,cAAc,CAACD,MAAD,CAAd;IACH;EAXmC,CAAzB,CAAf;EAcAL,MAAM,CAACgB,IAAP,GAAe,GAAEhB,MAAM,CAACiB,IAAK,cAA7B;EAEA,OAAOjB,MAAP;AACH,CAlBM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createFilterPlugins: () => import("../../../../../plugins/CmsEntryFilterPlugin").CmsEntryFilterPlugin[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFilterPlugins = void 0;
|
|
7
|
+
|
|
8
|
+
var _defaultFilterPlugin = require("./defaultFilterPlugin");
|
|
9
|
+
|
|
10
|
+
var _objectFilterPlugin = require("./objectFilterPlugin");
|
|
11
|
+
|
|
12
|
+
var _refFilterPlugin = require("./refFilterPlugin");
|
|
13
|
+
|
|
14
|
+
const createFilterPlugins = () => {
|
|
15
|
+
return [(0, _defaultFilterPlugin.createDefaultFilterPlugin)(), (0, _objectFilterPlugin.createObjectFilterPlugin)(), (0, _refFilterPlugin.createRefFilterPlugin)()];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.createFilterPlugins = createFilterPlugins;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFilterPlugins","createDefaultFilterPlugin","createObjectFilterPlugin","createRefFilterPlugin"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterPlugin } from \"./defaultFilterPlugin\";\nimport { createObjectFilterPlugin } from \"./objectFilterPlugin\";\nimport { createRefFilterPlugin } from \"./refFilterPlugin\";\n\nexport const createFilterPlugins = () => {\n return [createDefaultFilterPlugin(), createObjectFilterPlugin(), createRefFilterPlugin()];\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEO,MAAMA,mBAAmB,GAAG,MAAM;EACrC,OAAO,CAAC,IAAAC,8CAAA,GAAD,EAA8B,IAAAC,4CAAA,GAA9B,EAA0D,IAAAC,sCAAA,GAA1D,CAAP;AACH,CAFM"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createObjectFilterPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _CmsEntryFilterPlugin = require("../../../../../plugins/CmsEntryFilterPlugin");
|
|
11
|
+
|
|
12
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
const createObjectFilterPlugin = () => {
|
|
17
|
+
const plugin = new _CmsEntryFilterPlugin.CmsEntryFilterPlugin({
|
|
18
|
+
fieldType: "object",
|
|
19
|
+
exec: params => {
|
|
20
|
+
const {
|
|
21
|
+
applyFiltering,
|
|
22
|
+
value: where,
|
|
23
|
+
fields,
|
|
24
|
+
field: parentField,
|
|
25
|
+
getFilterPlugin,
|
|
26
|
+
query
|
|
27
|
+
} = params;
|
|
28
|
+
/**
|
|
29
|
+
* Because this is an object field, we must construct filters based on the value property.
|
|
30
|
+
* Value property is actually a where condition.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
for (const key in where) {
|
|
34
|
+
const value = where[key];
|
|
35
|
+
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
field: whereFieldId,
|
|
42
|
+
operator
|
|
43
|
+
} = (0, _apiElasticsearch.parseWhereKey)(key);
|
|
44
|
+
const identifier = [...parentField.parents.map(p => p.fieldId), parentField.field.fieldId, whereFieldId].join(".");
|
|
45
|
+
const field = fields[identifier];
|
|
46
|
+
|
|
47
|
+
if (!field) {
|
|
48
|
+
throw new _error.default(`There is no field "${identifier}".`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* We need to find the filter plugin for the child field.
|
|
52
|
+
* This will throw error if no plugin can be found.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const plugin = getFilterPlugin(field.type);
|
|
57
|
+
/**
|
|
58
|
+
* Basically this allows us to go into depth as much as we want with the object fields.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
plugin.exec({
|
|
62
|
+
applyFiltering,
|
|
63
|
+
getFilterPlugin,
|
|
64
|
+
key,
|
|
65
|
+
value,
|
|
66
|
+
operator,
|
|
67
|
+
field,
|
|
68
|
+
fields,
|
|
69
|
+
query
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
plugin.name = `${plugin.type}.default.object`;
|
|
75
|
+
return plugin;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.createObjectFilterPlugin = createObjectFilterPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createObjectFilterPlugin","plugin","CmsEntryFilterPlugin","fieldType","exec","params","applyFiltering","value","where","fields","field","parentField","getFilterPlugin","query","key","undefined","whereFieldId","operator","parseWhereKey","identifier","parents","map","p","fieldId","join","WebinyError","type","name"],"sources":["objectFilterPlugin.ts"],"sourcesContent":["import { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport WebinyError from \"@webiny/error\";\n\nexport const createObjectFilterPlugin = () => {\n const plugin = new CmsEntryFilterPlugin({\n fieldType: \"object\",\n exec: params => {\n const {\n applyFiltering,\n value: where,\n fields,\n field: parentField,\n getFilterPlugin,\n query\n } = params;\n /**\n * Because this is an object field, we must construct filters based on the value property.\n * Value property is actually a where condition.\n */\n for (const key in where) {\n const value = where[key];\n if (value === undefined) {\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n const identifier = [\n ...parentField.parents.map(p => p.fieldId),\n parentField.field.fieldId,\n whereFieldId\n ].join(\".\");\n const field = fields[identifier];\n if (!field) {\n throw new WebinyError(`There is no field \"${identifier}\".`);\n }\n /**\n * We need to find the filter plugin for the child field.\n * This will throw error if no plugin can be found.\n */\n const plugin = getFilterPlugin(field.type);\n /**\n * Basically this allows us to go into depth as much as we want with the object fields.\n */\n plugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n }\n });\n\n plugin.name = `${plugin.type}.default.object`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEO,MAAMA,wBAAwB,GAAG,MAAM;EAC1C,MAAMC,MAAM,GAAG,IAAIC,0CAAJ,CAAyB;IACpCC,SAAS,EAAE,QADyB;IAEpCC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QACFC,cADE;QAEFC,KAAK,EAAEC,KAFL;QAGFC,MAHE;QAIFC,KAAK,EAAEC,WAJL;QAKFC,eALE;QAMFC;MANE,IAOFR,MAPJ;MAQA;AACZ;AACA;AACA;;MACY,KAAK,MAAMS,GAAX,IAAkBN,KAAlB,EAAyB;QACrB,MAAMD,KAAK,GAAGC,KAAK,CAACM,GAAD,CAAnB;;QACA,IAAIP,KAAK,KAAKQ,SAAd,EAAyB;UACrB;QACH;;QACD,MAAM;UAAEL,KAAK,EAAEM,YAAT;UAAuBC;QAAvB,IAAoC,IAAAC,+BAAA,EAAcJ,GAAd,CAA1C;QAEA,MAAMK,UAAU,GAAG,CACf,GAAGR,WAAW,CAACS,OAAZ,CAAoBC,GAApB,CAAwBC,CAAC,IAAIA,CAAC,CAACC,OAA/B,CADY,EAEfZ,WAAW,CAACD,KAAZ,CAAkBa,OAFH,EAGfP,YAHe,EAIjBQ,IAJiB,CAIZ,GAJY,CAAnB;QAKA,MAAMd,KAAK,GAAGD,MAAM,CAACU,UAAD,CAApB;;QACA,IAAI,CAACT,KAAL,EAAY;UACR,MAAM,IAAIe,cAAJ,CAAiB,sBAAqBN,UAAW,IAAjD,CAAN;QACH;QACD;AAChB;AACA;AACA;;;QACgB,MAAMlB,MAAM,GAAGW,eAAe,CAACF,KAAK,CAACgB,IAAP,CAA9B;QACA;AAChB;AACA;;QACgBzB,MAAM,CAACG,IAAP,CAAY;UACRE,cADQ;UAERM,eAFQ;UAGRE,GAHQ;UAIRP,KAJQ;UAKRU,QALQ;UAMRP,KANQ;UAORD,MAPQ;UAQRI;QARQ,CAAZ;MAUH;IACJ;EAlDmC,CAAzB,CAAf;EAqDAZ,MAAM,CAAC0B,IAAP,GAAe,GAAE1B,MAAM,CAACyB,IAAK,iBAA7B;EAEA,OAAOzB,MAAP;AACH,CAzDM"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createRefFilterPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _CmsEntryFilterPlugin = require("../../../../../plugins/CmsEntryFilterPlugin");
|
|
13
|
+
|
|
14
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
15
|
+
|
|
16
|
+
const createRefFilterPlugin = () => {
|
|
17
|
+
return new _CmsEntryFilterPlugin.CmsEntryFilterPlugin({
|
|
18
|
+
fieldType: "ref",
|
|
19
|
+
exec: params => {
|
|
20
|
+
const {
|
|
21
|
+
applyFiltering,
|
|
22
|
+
value: values,
|
|
23
|
+
query,
|
|
24
|
+
field
|
|
25
|
+
} = params;
|
|
26
|
+
/**
|
|
27
|
+
* We must have an object when querying in the ref field.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
if (typeof values !== "object") {
|
|
31
|
+
throw new _error.default(`When querying by ref field, value of the field must be an object.`, "OBJECT_REQUIRED", {
|
|
32
|
+
value: values
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (const key in values) {
|
|
37
|
+
const {
|
|
38
|
+
operator
|
|
39
|
+
} = (0, _apiElasticsearch.parseWhereKey)(key);
|
|
40
|
+
const value = values[key];
|
|
41
|
+
|
|
42
|
+
if (value === undefined) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
applyFiltering({
|
|
47
|
+
query,
|
|
48
|
+
field,
|
|
49
|
+
operator,
|
|
50
|
+
key,
|
|
51
|
+
value
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.createRefFilterPlugin = createRefFilterPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createRefFilterPlugin","CmsEntryFilterPlugin","fieldType","exec","params","applyFiltering","value","values","query","field","WebinyError","key","operator","parseWhereKey","undefined"],"sources":["refFilterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\n\nexport const createRefFilterPlugin = () => {\n return new CmsEntryFilterPlugin({\n fieldType: \"ref\",\n exec: params => {\n const { applyFiltering, value: values, query, field } = params;\n /**\n * We must have an object when querying in the ref field.\n */\n if (typeof values !== \"object\") {\n throw new WebinyError(\n `When querying by ref field, value of the field must be an object.`,\n \"OBJECT_REQUIRED\",\n {\n value: values\n }\n );\n }\n\n for (const key in values) {\n const { operator } = parseWhereKey(key);\n const value = values[key];\n if (value === undefined) {\n continue;\n }\n\n applyFiltering({\n query,\n field,\n operator,\n key,\n value\n });\n }\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEO,MAAMA,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAIC,0CAAJ,CAAyB;IAC5BC,SAAS,EAAE,KADiB;IAE5BC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QAAEC,cAAF;QAAkBC,KAAK,EAAEC,MAAzB;QAAiCC,KAAjC;QAAwCC;MAAxC,IAAkDL,MAAxD;MACA;AACZ;AACA;;MACY,IAAI,OAAOG,MAAP,KAAkB,QAAtB,EAAgC;QAC5B,MAAM,IAAIG,cAAJ,CACD,mEADC,EAEF,iBAFE,EAGF;UACIJ,KAAK,EAAEC;QADX,CAHE,CAAN;MAOH;;MAED,KAAK,MAAMI,GAAX,IAAkBJ,MAAlB,EAA0B;QACtB,MAAM;UAAEK;QAAF,IAAe,IAAAC,+BAAA,EAAcF,GAAd,CAArB;QACA,MAAML,KAAK,GAAGC,MAAM,CAACI,GAAD,CAApB;;QACA,IAAIL,KAAK,KAAKQ,SAAd,EAAyB;UACrB;QACH;;QAEDT,cAAc,CAAC;UACXG,KADW;UAEXC,KAFW;UAGXG,QAHW;UAIXD,GAJW;UAKXL;QALW,CAAD,CAAd;MAOH;IACJ;EAhC2B,CAAzB,CAAP;AAkCH,CAnCM"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPopulated = void 0;
|
|
7
|
+
|
|
8
|
+
const getPopulated = query => {
|
|
9
|
+
const result = {};
|
|
10
|
+
let key;
|
|
11
|
+
|
|
12
|
+
for (key in query) {
|
|
13
|
+
const value = query[key];
|
|
14
|
+
|
|
15
|
+
if (value === undefined || Array.isArray(value) && value.length === 0) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* TODO figure out better types.
|
|
20
|
+
*/
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
result[key] = value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.getPopulated = getPopulated;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getPopulated","query","result","key","value","undefined","Array","isArray","length"],"sources":["populated.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\n\nexport const getPopulated = (\n query: ElasticsearchBoolQueryConfig\n): Partial<ElasticsearchBoolQueryConfig> => {\n const result: Partial<ElasticsearchBoolQueryConfig> = {};\n let key: keyof ElasticsearchBoolQueryConfig;\n for (key in query) {\n const value = query[key];\n if (value === undefined || (Array.isArray(value) && value.length === 0)) {\n continue;\n }\n /**\n * TODO figure out better types.\n */\n // @ts-ignore\n result[key] = value;\n }\n return result;\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,YAAY,GACrBC,KADwB,IAEgB;EACxC,MAAMC,MAA6C,GAAG,EAAtD;EACA,IAAIC,GAAJ;;EACA,KAAKA,GAAL,IAAYF,KAAZ,EAAmB;IACf,MAAMG,KAAK,GAAGH,KAAK,CAACE,GAAD,CAAnB;;IACA,IAAIC,KAAK,KAAKC,SAAV,IAAwBC,KAAK,CAACC,OAAN,CAAcH,KAAd,KAAwBA,KAAK,CAACI,MAAN,KAAiB,CAArE,EAAyE;MACrE;IACH;IACD;AACR;AACA;IACQ;;;IACAN,MAAM,CAACC,GAAD,CAAN,GAAcC,KAAd;EACH;;EACD,OAAOF,MAAP;AACH,CAjBM"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getWhereValues = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const getWhereValues = (value, condition) => {
|
|
13
|
+
const values = value;
|
|
14
|
+
|
|
15
|
+
if (!Array.isArray(values)) {
|
|
16
|
+
throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
17
|
+
value
|
|
18
|
+
});
|
|
19
|
+
} else if (values.length === 0) {
|
|
20
|
+
throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
21
|
+
value
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return values;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.getWhereValues = getWhereValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getWhereValues","value","condition","values","Array","isArray","WebinyError","length"],"sources":["values.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getWhereValues = (value: unknown, condition: \"AND\" | \"OR\") => {\n const values = value as CmsEntryListWhere[] | undefined;\n if (!Array.isArray(values)) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is not an array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n } else if (values.length === 0) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is empty array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n }\n return values;\n};\n"],"mappings":";;;;;;;;;AACA;;AAEO,MAAMA,cAAc,GAAG,CAACC,KAAD,EAAiBC,SAAjB,KAA6C;EACvE,MAAMC,MAAM,GAAGF,KAAf;;EACA,IAAI,CAACG,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAL,EAA4B;IACxB,MAAM,IAAIG,cAAJ,CACD,iCAAgCJ,SAAU,wCADzC,EAED,aAAYA,SAAU,YAFrB,EAGF;MACID;IADJ,CAHE,CAAN;EAOH,CARD,MAQO,IAAIE,MAAM,CAACI,MAAP,KAAkB,CAAtB,EAAyB;IAC5B,MAAM,IAAID,cAAJ,CACD,iCAAgCJ,SAAU,uCADzC,EAED,aAAYA,SAAU,YAFrB,EAGF;MACID;IADJ,CAHE,CAAN;EAOH;;EACD,OAAOE,MAAP;AACH,CApBM"}
|