@webiny/api-headless-cms-ddb-es 0.0.0-unstable.40876133bb → 0.0.0-unstable.496cf268ac

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.
Files changed (204) hide show
  1. package/configurations.js +0 -8
  2. package/configurations.js.map +1 -1
  3. package/definitions/entry.js +3 -5
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/entryElasticsearch.js +0 -5
  6. package/definitions/entryElasticsearch.js.map +1 -1
  7. package/definitions/group.js +0 -5
  8. package/definitions/group.js.map +1 -1
  9. package/definitions/model.js +22 -5
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/settings.js +0 -5
  12. package/definitions/settings.js.map +1 -1
  13. package/definitions/system.js +0 -5
  14. package/definitions/system.js.map +1 -1
  15. package/definitions/table.js +0 -3
  16. package/definitions/table.js.map +1 -1
  17. package/definitions/tableElasticsearch.js +0 -3
  18. package/definitions/tableElasticsearch.js.map +1 -1
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +0 -5
  21. package/dynamoDb/index.js.map +1 -1
  22. package/dynamoDb/storage/date.d.ts +2 -1
  23. package/dynamoDb/storage/date.js +4 -17
  24. package/dynamoDb/storage/date.js.map +1 -1
  25. package/dynamoDb/storage/longText.d.ts +1 -1
  26. package/dynamoDb/storage/longText.js +10 -18
  27. package/dynamoDb/storage/longText.js.map +1 -1
  28. package/dynamoDb/storage/richText.d.ts +1 -1
  29. package/dynamoDb/storage/richText.js +12 -30
  30. package/dynamoDb/storage/richText.js.map +1 -1
  31. package/elasticsearch/createElasticsearchIndex.js +0 -11
  32. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  33. package/elasticsearch/deleteElasticsearchIndex.js +0 -7
  34. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  35. package/elasticsearch/index.js +0 -5
  36. package/elasticsearch/index.js.map +1 -1
  37. package/elasticsearch/indexing/dateTimeIndexing.js +4 -21
  38. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  39. package/elasticsearch/indexing/defaultFieldIndexing.js +15 -10
  40. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  41. package/elasticsearch/indexing/index.js +0 -9
  42. package/elasticsearch/indexing/index.js.map +1 -1
  43. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  44. package/elasticsearch/indexing/longTextIndexing.js +19 -9
  45. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  46. package/elasticsearch/indexing/numberIndexing.js +0 -9
  47. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  48. package/elasticsearch/indexing/objectIndexing.js +3 -30
  49. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  50. package/elasticsearch/indexing/richTextIndexing.js +0 -5
  51. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  52. package/elasticsearch/indices/base.js +0 -3
  53. package/elasticsearch/indices/base.js.map +1 -1
  54. package/elasticsearch/indices/index.js +0 -4
  55. package/elasticsearch/indices/index.js.map +1 -1
  56. package/elasticsearch/indices/japanese.js +0 -3
  57. package/elasticsearch/indices/japanese.js.map +1 -1
  58. package/elasticsearch/search/index.js +0 -4
  59. package/elasticsearch/search/index.js.map +1 -1
  60. package/elasticsearch/search/refSearch.js +4 -8
  61. package/elasticsearch/search/refSearch.js.map +1 -1
  62. package/elasticsearch/search/timeSearch.js +0 -7
  63. package/elasticsearch/search/timeSearch.js.map +1 -1
  64. package/helpers/entryIndexHelpers.js +20 -49
  65. package/helpers/entryIndexHelpers.js.map +1 -1
  66. package/helpers/index.d.ts +0 -1
  67. package/helpers/index.js +0 -15
  68. package/helpers/index.js.map +1 -1
  69. package/index.js +19 -73
  70. package/index.js.map +1 -1
  71. package/operations/entry/dataLoaders.js +0 -52
  72. package/operations/entry/dataLoaders.js.map +1 -1
  73. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  74. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +32 -0
  75. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  76. package/operations/entry/elasticsearch/body.d.ts +13 -0
  77. package/operations/entry/elasticsearch/body.js +140 -0
  78. package/operations/entry/elasticsearch/body.js.map +1 -0
  79. package/operations/entry/elasticsearch/fields.d.ts +9 -0
  80. package/operations/entry/elasticsearch/fields.js +229 -0
  81. package/operations/entry/elasticsearch/fields.js.map +1 -0
  82. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
  83. package/operations/entry/elasticsearch/filtering/applyFiltering.js +57 -0
  84. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  85. package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
  86. package/operations/entry/elasticsearch/filtering/exec.js +172 -0
  87. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  88. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  89. package/operations/entry/elasticsearch/filtering/index.js +16 -0
  90. package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
  91. package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
  92. package/operations/entry/elasticsearch/filtering/path.js +44 -0
  93. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  94. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  95. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +28 -0
  96. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  97. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  98. package/operations/entry/elasticsearch/filtering/plugins/index.js +13 -0
  99. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  100. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  101. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +65 -0
  102. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  103. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  104. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +48 -0
  105. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  106. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  107. package/operations/entry/elasticsearch/filtering/populated.js +23 -0
  108. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  109. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  110. package/operations/entry/elasticsearch/filtering/values.js +22 -0
  111. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  112. package/operations/entry/elasticsearch/fullTextSearch.d.ts +12 -0
  113. package/operations/entry/elasticsearch/fullTextSearch.js +89 -0
  114. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  115. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  116. package/operations/entry/elasticsearch/fullTextSearchFields.js +25 -0
  117. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  118. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  119. package/operations/entry/elasticsearch/initialQuery.js +103 -0
  120. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  121. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  122. package/operations/entry/elasticsearch/keyword.js +34 -0
  123. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  124. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
  125. package/operations/entry/elasticsearch/plugins/bodyModifier.js +16 -0
  126. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
  127. package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
  128. package/operations/entry/elasticsearch/plugins/operator.js +37 -0
  129. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  130. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
  131. package/operations/entry/elasticsearch/plugins/queryModifier.js +16 -0
  132. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
  133. package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
  134. package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +7 -9
  135. package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
  136. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
  137. package/operations/entry/elasticsearch/plugins/sortModifier.js +16 -0
  138. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
  139. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  140. package/operations/entry/elasticsearch/sort.js +82 -0
  141. package/operations/entry/elasticsearch/sort.js.map +1 -0
  142. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
  143. package/{helpers → operations/entry/elasticsearch}/transformValueForSearch.js +7 -6
  144. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  145. package/operations/entry/elasticsearch/types.d.ts +41 -0
  146. package/operations/entry/elasticsearch/types.js +5 -0
  147. package/operations/entry/elasticsearch/types.js.map +1 -0
  148. package/operations/entry/index.d.ts +0 -2
  149. package/operations/entry/index.js +72 -210
  150. package/operations/entry/index.js.map +1 -1
  151. package/operations/entry/keys.js +0 -9
  152. package/operations/entry/keys.js.map +1 -1
  153. package/operations/entry/recordType.d.ts +3 -0
  154. package/operations/entry/recordType.js +18 -0
  155. package/operations/entry/recordType.js.map +1 -0
  156. package/operations/group/index.js +2 -32
  157. package/operations/group/index.js.map +1 -1
  158. package/operations/model/index.js +1 -34
  159. package/operations/model/index.js.map +1 -1
  160. package/operations/settings/index.js +0 -24
  161. package/operations/settings/index.js.map +1 -1
  162. package/operations/system/index.js +0 -17
  163. package/operations/system/index.js.map +1 -1
  164. package/package.json +16 -16
  165. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +1 -0
  166. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +6 -8
  167. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  168. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -6
  169. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -1
  170. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
  171. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
  172. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
  173. package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -5
  174. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  175. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +1 -0
  176. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +6 -12
  177. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  178. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +1 -0
  179. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +6 -8
  180. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  181. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +1 -0
  182. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +6 -8
  183. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  184. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  185. package/plugins/CmsEntryFilterPlugin.js +24 -0
  186. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  187. package/plugins/index.d.ts +1 -0
  188. package/plugins/index.js +11 -12
  189. package/plugins/index.js.map +1 -1
  190. package/types.js +0 -5
  191. package/types.js.map +1 -1
  192. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  193. package/helpers/createElasticsearchQueryBody.js +0 -611
  194. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  195. package/helpers/fields.d.ts +0 -19
  196. package/helpers/fields.js +0 -205
  197. package/helpers/fields.js.map +0 -1
  198. package/helpers/searchPluginsList.d.ts +0 -6
  199. package/helpers/searchPluginsList.js.map +0 -1
  200. package/helpers/transformValueForSearch.d.ts +0 -12
  201. package/helpers/transformValueForSearch.js.map +0 -1
  202. package/operations/entry/elasticsearchFields.d.ts +0 -2
  203. package/operations/entry/elasticsearchFields.js +0 -38
  204. package/operations/entry/elasticsearchFields.js.map +0 -1
@@ -1,611 +0,0 @@
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.createElasticsearchQueryBody = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- var _transformValueForSearch = require("./transformValueForSearch");
15
-
16
- var _searchPluginsList = require("./searchPluginsList");
17
-
18
- var _apiElasticsearch = require("@webiny/api-elasticsearch");
19
-
20
- var _fields = require("./fields");
21
-
22
- var _CmsEntryElasticsearchFieldPlugin = require("../plugins/CmsEntryElasticsearchFieldPlugin");
23
-
24
- var _entry = require("../operations/entry");
25
-
26
- var _CmsEntryElasticsearchQueryModifierPlugin = require("../plugins/CmsEntryElasticsearchQueryModifierPlugin");
27
-
28
- var _CmsEntryElasticsearchSortModifierPlugin = require("../plugins/CmsEntryElasticsearchSortModifierPlugin");
29
-
30
- var _CmsEntryElasticsearchBodyModifierPlugin = require("../plugins/CmsEntryElasticsearchBodyModifierPlugin");
31
-
32
- const specialFields = ["published", "latest"];
33
- const noKeywordFields = ["date", "datetime", "number", "boolean"];
34
-
35
- const createElasticsearchSortParams = args => {
36
- const {
37
- sort,
38
- modelFields,
39
- parentPath,
40
- searchPlugins
41
- } = args;
42
-
43
- if (!sort || sort.length === 0) {
44
- return [];
45
- }
46
-
47
- const fieldIdToStorageIdIdMap = {};
48
- const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {
49
- const searchPlugin = searchPlugins[modelField.type];
50
- const {
51
- fieldId,
52
- storageId
53
- } = modelField.field;
54
- fieldIdToStorageIdIdMap[fieldId] = fieldId;
55
- /**
56
- * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.
57
- */
58
-
59
- plugins[fieldId] = new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
60
- unmappedType: modelField.unmappedType,
61
- keyword: hasKeyword(modelField),
62
- sortable: modelField.isSortable,
63
- searchable: modelField.isSearchable,
64
- field: fieldId,
65
- path: createFieldPath({
66
- key: storageId,
67
- parentPath,
68
- modelField,
69
- searchPlugin
70
- })
71
- });
72
- return plugins;
73
- }, {});
74
- const transformedSort = sort.map(value => {
75
- const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);
76
-
77
- if (!matched) {
78
- return null;
79
- }
80
-
81
- const [, fieldId, order] = matched;
82
-
83
- if (fieldIdToStorageIdIdMap[fieldId]) {
84
- return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;
85
- }
86
-
87
- return value;
88
- }).filter(Boolean);
89
- return (0, _apiElasticsearch.createSort)({
90
- fieldPlugins: sortPlugins,
91
- sort: transformedSort
92
- });
93
- };
94
-
95
- const findFieldByFieldId = (model, fieldId) => {
96
- return model.fields.find(field => {
97
- return field.fieldId === fieldId;
98
- });
99
- };
100
- /**
101
- * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.
102
- * We allow either published or either latest.
103
- * Latest is used in the manage API and published in the read API.
104
- */
105
-
106
-
107
- const createInitialQueryValue = params => {
108
- const {
109
- model,
110
- where: initialWhere
111
- } = params;
112
- /**
113
- * Cast as partial so we can remove unnecessary keys.
114
- */
115
-
116
- const where = (0, _objectSpread2.default)({}, initialWhere);
117
- const query = {
118
- must: [],
119
- must_not: [],
120
- should: [],
121
- filter: []
122
- }; // When ES index is shared between tenants, we need to filter records by tenant ID
123
-
124
- const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
125
-
126
- if (sharedIndex) {
127
- query.must.push({
128
- term: {
129
- "tenant.keyword": model.tenant
130
- }
131
- });
132
- }
133
-
134
- query.must.push({
135
- term: {
136
- "locale.keyword": model.locale
137
- }
138
- });
139
- /**
140
- * We must transform published and latest where args into something that is understandable by our Elasticsearch
141
- */
142
-
143
- if (where.published === true) {
144
- query.must.push({
145
- term: {
146
- "__type.keyword": (0, _entry.createPublishedType)()
147
- }
148
- });
149
- } else if (where.latest === true) {
150
- query.must.push({
151
- term: {
152
- "__type.keyword": (0, _entry.createLatestType)()
153
- }
154
- });
155
- } // we do not allow not published and not latest
156
- else {
157
- throw new _error.default(`Cannot call Elasticsearch query when not setting "published" or "latest".`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
158
- where
159
- });
160
- } //
161
-
162
-
163
- return query;
164
- };
165
-
166
- const createFieldPath = ({
167
- modelField,
168
- searchPlugin,
169
- parentPath,
170
- key
171
- }) => {
172
- let path = null;
173
-
174
- if (searchPlugin && typeof searchPlugin.createPath === "function") {
175
- path = searchPlugin.createPath({
176
- field: modelField.field,
177
- value: null,
178
- key
179
- });
180
- } else if (typeof modelField.path === "function") {
181
- path = modelField.path(modelField.field.storageId);
182
- }
183
-
184
- if (!path) {
185
- /**
186
- * We know that modelFieldPath is a string or undefined at this point.
187
- */
188
- path = modelField.path || modelField.field.storageId || modelField.field.id;
189
- }
190
-
191
- return modelField.isSystemField || !parentPath || path.match(parentPath) ? path : `${parentPath}.${path}`;
192
- };
193
-
194
- const hasKeyword = modelField => {
195
- /**
196
- * We defined some field types that MUST have no keyword added to the field path
197
- */
198
- if (noKeywordFields.includes(modelField.type)) {
199
- return false;
200
- } else if (modelField.unmappedType) {
201
- /**
202
- * If modelField has unmapped type defined, do not add keyword.
203
- */
204
- return false;
205
- } else if (modelField.keyword === false) {
206
- /**
207
- * And if specifically defined that modelField has no keyword, do not add it.
208
- */
209
- return false;
210
- }
211
- /**
212
- * All other fields have keyword added.
213
- */
214
-
215
-
216
- return true;
217
- };
218
-
219
- /**
220
- * A list of typeof strings that are 100% not ref field filtering.
221
- * We also need to check for array and date.
222
- */
223
- const nonRefFieldTypes = ["string", "number", "undefined", "symbol", "bigint", "function", "boolean"];
224
-
225
- const isRefFieldFiltering = params => {
226
- const {
227
- key,
228
- value,
229
- field
230
- } = params;
231
- const typeOf = typeof value;
232
-
233
- if (!value || nonRefFieldTypes.includes(typeOf) || Array.isArray(value) || value instanceof Date || !!value.toISOString) {
234
- return false;
235
- } else if (typeOf === "object" && field.type === "ref") {
236
- return true;
237
- }
238
-
239
- throw new _error.default("Could not determine if the search value is ref field search.", "REF_FIELD_SEARCH_ERROR", {
240
- value,
241
- field,
242
- key
243
- });
244
- };
245
-
246
- const fieldPathFactory = params => {
247
- const {
248
- plugin,
249
- modelField,
250
- value,
251
- parentPath,
252
- keyword,
253
- key
254
- } = params;
255
- const field = modelField.field;
256
- let fieldPath = null;
257
-
258
- if (plugin) {
259
- fieldPath = plugin.createPath({
260
- field,
261
- value,
262
- key
263
- });
264
- }
265
-
266
- if (!fieldPath) {
267
- fieldPath = field.storageId;
268
-
269
- if (modelField.path) {
270
- fieldPath = typeof modelField.path === "function" ? modelField.path(value) : modelField.path;
271
- }
272
- }
273
-
274
- const keywordValue = keyword ? ".keyword" : "";
275
-
276
- if (!parentPath) {
277
- return `${fieldPath}${keywordValue}`;
278
- }
279
-
280
- return `${parentPath}.${fieldPath}${keywordValue}`;
281
- };
282
-
283
- const applyFiltering = params => {
284
- const {
285
- query,
286
- modelField,
287
- operator,
288
- key,
289
- value: initialValue,
290
- operatorPlugins,
291
- searchPlugins,
292
- parentPath
293
- } = params;
294
- const plugin = operatorPlugins[operator];
295
-
296
- if (!plugin) {
297
- throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
298
- operator
299
- });
300
- }
301
-
302
- const fieldSearchPlugin = searchPlugins[modelField.type];
303
- const value = (0, _transformValueForSearch.transformValueForSearch)({
304
- plugins: searchPlugins,
305
- field: modelField.field,
306
- value: initialValue
307
- });
308
- const keyword = hasKeyword(modelField);
309
- plugin.apply(query, {
310
- basePath: fieldPathFactory({
311
- plugin: fieldSearchPlugin,
312
- modelField,
313
- parentPath: modelField.isSystemField ? null : parentPath,
314
- value,
315
- key
316
- }),
317
- path: fieldPathFactory({
318
- plugin: fieldSearchPlugin,
319
- modelField,
320
- value,
321
- parentPath: modelField.isSystemField ? null : parentPath,
322
- keyword,
323
- key
324
- }),
325
- value,
326
- keyword
327
- });
328
- };
329
-
330
- const applyFullTextSearch = params => {
331
- const {
332
- query,
333
- modelFields,
334
- term,
335
- fields
336
- } = params;
337
-
338
- if (!term || term.length === 0 || fields.length === 0) {
339
- return;
340
- }
341
-
342
- const fieldPaths = fields.reduce((collection, field) => {
343
- const modelField = modelFields[field.fieldId];
344
-
345
- if (!modelField) {
346
- return collection;
347
- }
348
-
349
- collection.push(`values.${field.storageId}`);
350
- return collection;
351
- }, []);
352
- query.must.push({
353
- query_string: {
354
- allow_leading_wildcard: true,
355
- fields: fieldPaths,
356
- query: (0, _apiElasticsearch.normalizeValue)(term),
357
- default_operator: "or"
358
- }
359
- });
360
- };
361
- /*
362
- * Iterate through where keys and apply plugins where necessary
363
- */
364
-
365
-
366
- const execElasticsearchBuildQueryPlugins = params => {
367
- const {
368
- model,
369
- where: initialWhere,
370
- modelFields,
371
- parentPath,
372
- plugins,
373
- searchPlugins,
374
- fullTextSearch
375
- } = params;
376
- const where = (0, _objectSpread2.default)({}, initialWhere);
377
- const query = createInitialQueryValue((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
378
- where
379
- }));
380
- /**
381
- * Add full text search for requested fields.
382
- */
383
-
384
- applyFullTextSearch({
385
- query,
386
- modelFields,
387
- term: fullTextSearch.term,
388
- fields: fullTextSearch.fields
389
- });
390
- /**
391
- * Always remove special fields, as these do not exist in Elasticsearch.
392
- */
393
-
394
- for (const sf of specialFields) {
395
- delete where[sf];
396
- }
397
-
398
- if (Object.keys(where).length === 0) {
399
- return query;
400
- }
401
-
402
- const operatorPlugins = (0, _apiElasticsearch.getElasticsearchOperatorPluginsByLocale)(plugins, model.locale);
403
-
404
- for (const key in where) {
405
- if (where.hasOwnProperty(key) === false) {
406
- continue;
407
- }
408
- /**
409
- * We do not need to go further if value is undefined.
410
- * There are few hardcoded possibilities when value is undefined, for example, ownedBy.
411
- */
412
- // TODO figure out how to have type.
413
-
414
-
415
- const value = where[key];
416
-
417
- if (value === undefined) {
418
- continue;
419
- }
420
-
421
- const {
422
- field,
423
- operator
424
- } = (0, _apiElasticsearch.parseWhereKey)(key);
425
- /**
426
- * TODO This will be required until the storage operations receive the fieldId instead of field storageId.
427
- * TODO For this to work without field searching, we need to refactor how the query looks like.
428
- *
429
- * Storage operations should NEVER receive an field storageId, only alias - fieldId.
430
- */
431
-
432
- let fieldId = field;
433
- const cmsModelField = findFieldByFieldId(model, fieldId);
434
-
435
- if (!cmsModelField && !modelFields[fieldId]) {
436
- throw new _error.default(`There is no CMS Model Field field "${fieldId}".`);
437
- } else if (cmsModelField) {
438
- fieldId = cmsModelField.fieldId;
439
- }
440
-
441
- const modelField = modelFields[fieldId];
442
-
443
- if (!modelField) {
444
- throw new _error.default(`There is no field "${fieldId}".`);
445
- }
446
-
447
- const {
448
- isSearchable = false,
449
- field: cmsField
450
- } = modelField;
451
-
452
- if (!isSearchable) {
453
- throw new _error.default(`Field "${fieldId}" is not searchable.`);
454
- }
455
- /**
456
- * There is a possibility that value is an object.
457
- * In that case, check if field is ref field and continue a bit differently.
458
- */
459
-
460
-
461
- if (isRefFieldFiltering({
462
- key,
463
- value,
464
- field: cmsField
465
- })) {
466
- /**
467
- * We we need to go through each key in where[key] to determine the filters.
468
- */
469
- for (const whereKey in value) {
470
- const {
471
- operator
472
- } = (0, _apiElasticsearch.parseWhereKey)(whereKey);
473
- applyFiltering({
474
- query,
475
- modelField,
476
- operator,
477
- key: whereKey,
478
- value: value[whereKey],
479
- searchPlugins,
480
- operatorPlugins,
481
- parentPath
482
- });
483
- }
484
-
485
- continue;
486
- }
487
-
488
- applyFiltering({
489
- query,
490
- modelField,
491
- operator,
492
- key,
493
- value,
494
- searchPlugins,
495
- operatorPlugins,
496
- parentPath
497
- });
498
- }
499
-
500
- return query;
501
- };
502
-
503
- const createElasticsearchQueryBody = params => {
504
- const {
505
- plugins,
506
- model,
507
- args,
508
- parentPath = null
509
- } = params;
510
- const {
511
- where = {},
512
- after,
513
- limit,
514
- sort: initialSort,
515
- search,
516
- fields = []
517
- } = args;
518
- const modelFields = (0, _fields.createModelFields)(plugins, model);
519
- const searchPlugins = (0, _searchPluginsList.searchPluginsList)(plugins);
520
- const fullTextSearchFields = [];
521
- /**
522
- * No point in going through fields if there is no search performed.
523
- */
524
-
525
- if (!!search) {
526
- for (const fieldId of fields) {
527
- const field = model.fields.find(f => f.fieldId === fieldId);
528
-
529
- if (!field) {
530
- continue;
531
- }
532
-
533
- fullTextSearchFields.push(field);
534
- }
535
- }
536
-
537
- const query = execElasticsearchBuildQueryPlugins({
538
- model,
539
- plugins,
540
- where,
541
- modelFields,
542
- parentPath,
543
- searchPlugins,
544
- fullTextSearch: {
545
- term: search,
546
- fields: fullTextSearchFields
547
- }
548
- });
549
- const queryPlugins = plugins.byType(_CmsEntryElasticsearchQueryModifierPlugin.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
550
- return !pl.modelId || pl.modelId === model.modelId;
551
- });
552
-
553
- for (const pl of queryPlugins) {
554
- pl.modifyQuery({
555
- query,
556
- model,
557
- where
558
- });
559
- }
560
-
561
- const sort = createElasticsearchSortParams({
562
- plugins,
563
- sort: initialSort,
564
- modelFields,
565
- parentPath,
566
- model,
567
- searchPlugins
568
- });
569
- const sortPlugins = plugins.byType(_CmsEntryElasticsearchSortModifierPlugin.CmsEntryElasticsearchSortModifierPlugin.type).filter(pl => {
570
- return !pl.modelId || pl.modelId === model.modelId;
571
- });
572
-
573
- for (const pl of sortPlugins) {
574
- pl.modifySort({
575
- sort,
576
- model
577
- });
578
- }
579
-
580
- const body = {
581
- query: {
582
- bool: {
583
- must: query.must.length > 0 ? query.must : undefined,
584
- must_not: query.must_not.length > 0 ? query.must_not : undefined,
585
- should: query.should.length > 0 ? query.should : undefined,
586
- filter: query.filter.length > 0 ? query.filter : undefined
587
- }
588
- },
589
- sort,
590
- size: (limit || 0) + 1,
591
- // eslint-disable-next-line
592
- search_after: (0, _apiElasticsearch.decodeCursor)(after),
593
- // eslint-disable-next-line
594
- track_total_hits: true
595
- };
596
- const bodyPlugins = plugins.byType(_CmsEntryElasticsearchBodyModifierPlugin.CmsEntryElasticsearchBodyModifierPlugin.type).filter(pl => {
597
- return !pl.modelId || pl.modelId === model.modelId;
598
- });
599
-
600
- for (const pl of bodyPlugins) {
601
- pl.modifyBody({
602
- body,
603
- model,
604
- where
605
- });
606
- }
607
-
608
- return body;
609
- };
610
-
611
- exports.createElasticsearchQueryBody = createElasticsearchQueryBody;
@@ -1 +0,0 @@
1
- {"version":3,"names":["specialFields","noKeywordFields","createElasticsearchSortParams","args","sort","modelFields","parentPath","searchPlugins","length","fieldIdToStorageIdIdMap","sortPlugins","Object","values","reduce","plugins","modelField","searchPlugin","type","fieldId","storageId","field","CmsEntryElasticsearchFieldPlugin","unmappedType","keyword","hasKeyword","sortable","isSortable","searchable","isSearchable","path","createFieldPath","key","transformedSort","map","value","matched","match","order","filter","Boolean","createSort","fieldPlugins","findFieldByFieldId","model","fields","find","createInitialQueryValue","params","where","initialWhere","query","must","must_not","should","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","push","term","tenant","locale","published","createPublishedType","latest","createLatestType","WebinyError","createPath","id","isSystemField","includes","nonRefFieldTypes","isRefFieldFiltering","typeOf","Array","isArray","Date","toISOString","fieldPathFactory","plugin","fieldPath","keywordValue","applyFiltering","operator","initialValue","operatorPlugins","fieldSearchPlugin","transformValueForSearch","apply","basePath","applyFullTextSearch","fieldPaths","collection","query_string","allow_leading_wildcard","normalizeValue","default_operator","execElasticsearchBuildQueryPlugins","fullTextSearch","sf","keys","getElasticsearchOperatorPluginsByLocale","hasOwnProperty","undefined","parseWhereKey","cmsModelField","cmsField","whereKey","createElasticsearchQueryBody","after","limit","initialSort","search","createModelFields","searchPluginsList","fullTextSearchFields","f","queryPlugins","byType","CmsEntryElasticsearchQueryModifierPlugin","pl","modelId","modifyQuery","CmsEntryElasticsearchSortModifierPlugin","modifySort","body","bool","size","search_after","decodeCursor","track_total_hits","bodyPlugins","CmsEntryElasticsearchBodyModifierPlugin","modifyBody"],"sources":["createElasticsearchQueryBody.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"./transformValueForSearch\";\nimport { searchPluginsList } from \"./searchPluginsList\";\nimport {\n CmsEntryListParams,\n CmsEntryListSort,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport {\n SearchBody as esSearchBody,\n Sort as esSort,\n ElasticsearchBoolQueryConfig\n} from \"@webiny/api-elasticsearch/types\";\nimport {\n decodeCursor,\n createSort,\n parseWhereKey,\n ElasticsearchQueryBuilderOperatorPlugin,\n normalizeValue,\n getElasticsearchOperatorPluginsByLocale\n} from \"@webiny/api-elasticsearch\";\nimport { createModelFields, ModelField, ModelFields } from \"./fields\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins/CmsEntryElasticsearchFieldPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createLatestType, createPublishedType } from \"~/operations/entry\";\nimport { CmsEntryElasticsearchQueryModifierPlugin } from \"~/plugins/CmsEntryElasticsearchQueryModifierPlugin\";\nimport { CmsEntryElasticsearchSortModifierPlugin } from \"~/plugins/CmsEntryElasticsearchSortModifierPlugin\";\nimport { CmsEntryElasticsearchBodyModifierPlugin } from \"~/plugins/CmsEntryElasticsearchBodyModifierPlugin\";\nimport {\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CreatePathCallableParams\n} from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin\";\n\ninterface CreateElasticsearchParams {\n plugins: PluginsContainer;\n model: CmsModel;\n args: CmsEntryListParams;\n parentPath?: string;\n}\n\ninterface CreateElasticsearchSortParams {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n parentPath?: string | null;\n model: CmsModel;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n}\n\ninterface CreateElasticsearchQueryArgs {\n model: CmsModel;\n plugins: PluginsContainer;\n where: CmsEntryListWhere;\n modelFields: ModelFields;\n parentPath?: string | null;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n fullTextSearch: {\n term?: string;\n fields: CmsModelField[];\n };\n}\n\nconst specialFields: (keyof Partial<CmsEntryListWhere>)[] = [\"published\", \"latest\"];\nconst noKeywordFields = [\"date\", \"datetime\", \"number\", \"boolean\"];\n\nconst createElasticsearchSortParams = (args: CreateElasticsearchSortParams): esSort => {\n const { sort, modelFields, parentPath, searchPlugins } = args;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const fieldIdToStorageIdIdMap: Record<string, string> = {};\n\n const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {\n const searchPlugin = searchPlugins[modelField.type];\n\n const { fieldId, storageId } = modelField.field;\n\n fieldIdToStorageIdIdMap[fieldId] = fieldId;\n /**\n * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.\n */\n plugins[fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: modelField.unmappedType,\n keyword: hasKeyword(modelField),\n sortable: modelField.isSortable,\n searchable: modelField.isSearchable,\n field: fieldId,\n path: createFieldPath({\n key: storageId,\n parentPath,\n modelField,\n searchPlugin\n })\n });\n return plugins;\n }, {} as Record<string, CmsEntryElasticsearchFieldPlugin>);\n\n const transformedSort = sort\n .map(value => {\n const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (!matched) {\n return null;\n }\n const [, fieldId, order] = matched;\n if (fieldIdToStorageIdIdMap[fieldId]) {\n return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;\n }\n\n return value;\n })\n .filter(Boolean) as string[];\n return createSort({\n fieldPlugins: sortPlugins,\n sort: transformedSort\n });\n};\n\nconst findFieldByFieldId = (model: CmsModel, fieldId: string): CmsModelField | undefined => {\n return model.fields.find(field => {\n return field.fieldId === fieldId;\n });\n};\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { model, where: initialWhere } = params;\n /**\n * Cast as partial so we can remove unnecessary keys.\n */\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n // When ES index is shared between tenants, we need to filter records by tenant ID\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n query.must.push({ term: { \"tenant.keyword\": model.tenant } });\n }\n\n query.must.push({\n term: {\n \"locale.keyword\": model.locale\n }\n });\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createPublishedType()\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createLatestType()\n }\n });\n }\n // we do not allow not published and not latest\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n //\n return query;\n};\n\ninterface CreateFieldPathParams {\n modelField: ModelField;\n key: string;\n searchPlugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n parentPath?: string | null;\n}\nconst createFieldPath = ({\n modelField,\n searchPlugin,\n parentPath,\n key\n}: CreateFieldPathParams): string => {\n let path: string | null = null;\n if (searchPlugin && typeof searchPlugin.createPath === \"function\") {\n path = searchPlugin.createPath({\n field: modelField.field,\n value: null,\n key\n });\n } else if (typeof modelField.path === \"function\") {\n path = modelField.path(modelField.field.storageId);\n }\n if (!path) {\n /**\n * We know that modelFieldPath is a string or undefined at this point.\n */\n path = (modelField.path as string) || modelField.field.storageId || modelField.field.id;\n }\n return modelField.isSystemField || !parentPath || path.match(parentPath)\n ? path\n : `${parentPath}.${path}`;\n};\n\nconst hasKeyword = (modelField: ModelField): boolean => {\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(modelField.type)) {\n return false;\n } else if (modelField.unmappedType) {\n /**\n * If modelField has unmapped type defined, do not add keyword.\n */\n return false;\n } else if (modelField.keyword === false) {\n /**\n * And if specifically defined that modelField has no keyword, do not add it.\n */\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n\ninterface IsRefFieldFilteringParams {\n key: string;\n value: any;\n field: CmsModelField;\n}\n\n/**\n * A list of typeof strings that are 100% not ref field filtering.\n * We also need to check for array and date.\n */\nconst nonRefFieldTypes: string[] = [\n \"string\",\n \"number\",\n \"undefined\",\n \"symbol\",\n \"bigint\",\n \"function\",\n \"boolean\"\n];\nconst isRefFieldFiltering = (params: IsRefFieldFilteringParams): boolean => {\n const { key, value, field } = params;\n const typeOf = typeof value;\n if (\n !value ||\n nonRefFieldTypes.includes(typeOf) ||\n Array.isArray(value) ||\n value instanceof Date ||\n !!value.toISOString\n ) {\n return false;\n } else if (typeOf === \"object\" && field.type === \"ref\") {\n return true;\n }\n throw new WebinyError(\n \"Could not determine if the search value is ref field search.\",\n \"REF_FIELD_SEARCH_ERROR\",\n {\n value,\n field,\n key\n }\n );\n};\n\ninterface FieldPathFactoryParams extends Omit<CreatePathCallableParams, \"field\"> {\n plugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n modelField: ModelField;\n key: string;\n parentPath?: string | null;\n keyword?: boolean;\n}\nconst fieldPathFactory = (params: FieldPathFactoryParams): string => {\n const { plugin, modelField, value, parentPath, keyword, key } = params;\n\n const field = modelField.field;\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.storageId;\n if (modelField.path) {\n fieldPath =\n typeof modelField.path === \"function\" ? modelField.path(value) : modelField.path;\n }\n }\n\n const keywordValue = keyword ? \".keyword\" : \"\";\n if (!parentPath) {\n return `${fieldPath}${keywordValue}`;\n }\n return `${parentPath}.${fieldPath}${keywordValue}`;\n};\n\ninterface ApplyFilteringParams {\n query: ElasticsearchBoolQueryConfig;\n modelField: ModelField;\n operator: string;\n key: string;\n value: any;\n operatorPlugins: Record<string, ElasticsearchQueryBuilderOperatorPlugin>;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n parentPath?: string | null;\n}\nconst applyFiltering = (params: ApplyFilteringParams) => {\n const {\n query,\n modelField,\n operator,\n key,\n value: initialValue,\n operatorPlugins,\n searchPlugins,\n parentPath\n } = params;\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n const fieldSearchPlugin = searchPlugins[modelField.type];\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: modelField.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(modelField);\n plugin.apply(query, {\n basePath: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n parentPath: modelField.isSystemField ? null : parentPath,\n value,\n key\n }),\n path: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n value,\n parentPath: modelField.isSystemField ? null : parentPath,\n keyword,\n key\n }),\n value,\n keyword\n });\n};\n\ninterface ApplyFullTextSearchParams {\n query: ElasticsearchBoolQueryConfig;\n modelFields: ModelFields;\n term?: string;\n fields: CmsModelField[];\n}\nconst applyFullTextSearch = (params: ApplyFullTextSearchParams): void => {\n const { query, modelFields, term, fields } = params;\n if (!term || term.length === 0 || fields.length === 0) {\n return;\n }\n\n const fieldPaths = fields.reduce((collection, field) => {\n const modelField = modelFields[field.fieldId];\n if (!modelField) {\n return collection;\n }\n\n collection.push(`values.${field.storageId}`);\n\n return collection;\n }, [] as string[]);\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: fieldPaths,\n query: normalizeValue(term),\n default_operator: \"or\"\n }\n });\n};\n\n/*\n * Iterate through where keys and apply plugins where necessary\n */\nconst execElasticsearchBuildQueryPlugins = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const {\n model,\n where: initialWhere,\n modelFields,\n parentPath,\n plugins,\n searchPlugins,\n fullTextSearch\n } = params;\n\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n const query = createInitialQueryValue({\n ...params,\n where\n });\n\n /**\n * Add full text search for requested fields.\n */\n applyFullTextSearch({\n query,\n modelFields,\n term: fullTextSearch.term,\n fields: fullTextSearch.fields\n });\n\n /**\n * Always remove special fields, as these do not exist in Elasticsearch.\n */\n for (const sf of specialFields) {\n delete where[sf];\n }\n\n if (Object.keys(where).length === 0) {\n return query;\n }\n\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, model.locale);\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n /**\n * We do not need to go further if value is undefined.\n * There are few hardcoded possibilities when value is undefined, for example, ownedBy.\n */\n // TODO figure out how to have type.\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\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\n let fieldId = field;\n const cmsModelField = findFieldByFieldId(model, fieldId);\n if (!cmsModelField && !modelFields[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 modelField = modelFields[fieldId];\n\n if (!modelField) {\n throw new WebinyError(`There is no field \"${fieldId}\".`);\n }\n const { isSearchable = false, field: cmsField } = modelField;\n if (!isSearchable) {\n throw new WebinyError(`Field \"${fieldId}\" is not searchable.`);\n }\n /**\n * There is a possibility that value is an object.\n * In that case, check if field is ref field and continue a bit differently.\n */\n if (isRefFieldFiltering({ key, value, field: cmsField })) {\n /**\n * We we need to go through each key in where[key] to determine the filters.\n */\n for (const whereKey in value) {\n const { operator } = parseWhereKey(whereKey);\n applyFiltering({\n query,\n modelField,\n operator,\n key: whereKey,\n value: value[whereKey],\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n continue;\n }\n applyFiltering({\n query,\n modelField,\n operator,\n key,\n value,\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (params: CreateElasticsearchParams): esSearchBody => {\n const { plugins, model, args, parentPath = null } = params;\n const { where = {}, after, limit, sort: initialSort, search, fields = [] } = args;\n\n const modelFields = createModelFields(plugins, model);\n const searchPlugins = searchPluginsList(plugins);\n\n const fullTextSearchFields: CmsModelField[] = [];\n /**\n * No point in going through fields if there is no search performed.\n */\n if (!!search) {\n for (const fieldId of fields) {\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n continue;\n }\n fullTextSearchFields.push(field);\n }\n }\n\n const query = execElasticsearchBuildQueryPlugins({\n model,\n plugins,\n where,\n modelFields,\n parentPath,\n searchPlugins,\n fullTextSearch: {\n term: search,\n fields: fullTextSearchFields\n }\n });\n\n const queryPlugins = plugins\n .byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of queryPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSortParams({\n plugins,\n sort: initialSort,\n modelFields,\n parentPath,\n model,\n searchPlugins\n });\n\n const sortPlugins = plugins\n .byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of sortPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const body: esSearchBody = {\n query: {\n bool: {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n }\n },\n sort,\n size: (limit || 0) + 1,\n // eslint-disable-next-line\n search_after: decodeCursor(after) as any,\n // eslint-disable-next-line\n track_total_hits: true\n };\n\n const bodyPlugins = plugins\n .byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of bodyPlugins) {\n pl.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAaA;;AAQA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAmCA,MAAMA,aAAmD,GAAG,CAAC,WAAD,EAAc,QAAd,CAA5D;AACA,MAAMC,eAAe,GAAG,CAAC,MAAD,EAAS,UAAT,EAAqB,QAArB,EAA+B,SAA/B,CAAxB;;AAEA,MAAMC,6BAA6B,GAAIC,IAAD,IAAiD;EACnF,MAAM;IAAEC,IAAF;IAAQC,WAAR;IAAqBC,UAArB;IAAiCC;EAAjC,IAAmDJ,IAAzD;;EAEA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACI,MAAL,KAAgB,CAA7B,EAAgC;IAC5B,OAAO,EAAP;EACH;;EAED,MAAMC,uBAA+C,GAAG,EAAxD;EAEA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAP,CAAcP,WAAd,EAA2BQ,MAA3B,CAAkC,CAACC,OAAD,EAAUC,UAAV,KAAyB;IAC3E,MAAMC,YAAY,GAAGT,aAA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