@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.5e7233243f

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 (152) hide show
  1. package/configurations.d.ts +2 -2
  2. package/configurations.js +18 -7
  3. package/configurations.js.map +1 -0
  4. package/definitions/entry.d.ts +2 -2
  5. package/definitions/entry.js +5 -2
  6. package/definitions/entry.js.map +1 -0
  7. package/definitions/entryElasticsearch.d.ts +2 -2
  8. package/definitions/entryElasticsearch.js +2 -2
  9. package/definitions/entryElasticsearch.js.map +1 -0
  10. package/definitions/group.d.ts +2 -2
  11. package/definitions/group.js +2 -2
  12. package/definitions/group.js.map +1 -0
  13. package/definitions/model.d.ts +2 -2
  14. package/definitions/model.js +2 -2
  15. package/definitions/model.js.map +1 -0
  16. package/definitions/settings.d.ts +2 -2
  17. package/definitions/settings.js +2 -2
  18. package/definitions/settings.js.map +1 -0
  19. package/definitions/system.d.ts +2 -2
  20. package/definitions/system.js +2 -2
  21. package/definitions/system.js.map +1 -0
  22. package/definitions/table.d.ts +2 -2
  23. package/definitions/table.js.map +1 -0
  24. package/definitions/tableElasticsearch.d.ts +2 -2
  25. package/definitions/tableElasticsearch.js.map +1 -0
  26. package/dynamoDb/index.d.ts +1 -1
  27. package/dynamoDb/index.js +4 -6
  28. package/dynamoDb/index.js.map +1 -0
  29. package/dynamoDb/storage/date.d.ts +2 -3
  30. package/dynamoDb/storage/date.js +79 -45
  31. package/dynamoDb/storage/date.js.map +1 -0
  32. package/dynamoDb/storage/longText.d.ts +7 -4
  33. package/dynamoDb/storage/longText.js +71 -53
  34. package/dynamoDb/storage/longText.js.map +1 -0
  35. package/dynamoDb/storage/richText.d.ts +2 -3
  36. package/dynamoDb/storage/richText.js +84 -66
  37. package/dynamoDb/storage/richText.js.map +1 -0
  38. package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
  39. package/elasticsearch/createElasticsearchIndex.js +60 -0
  40. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  41. package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
  42. package/elasticsearch/deleteElasticsearchIndex.js +43 -0
  43. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
  44. package/elasticsearch/index.d.ts +1 -1
  45. package/elasticsearch/index.js.map +1 -0
  46. package/elasticsearch/indexing/dateTimeIndexing.js +15 -1
  47. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
  48. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
  49. package/elasticsearch/indexing/index.js.map +1 -0
  50. package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
  51. package/elasticsearch/indexing/numberIndexing.js.map +1 -0
  52. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  53. package/elasticsearch/indexing/objectIndexing.js +32 -9
  54. package/elasticsearch/indexing/objectIndexing.js.map +1 -0
  55. package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
  56. package/elasticsearch/indices/base.d.ts +2 -0
  57. package/elasticsearch/indices/base.js +23 -0
  58. package/elasticsearch/indices/base.js.map +1 -0
  59. package/elasticsearch/indices/index.d.ts +1 -0
  60. package/elasticsearch/indices/index.js +16 -0
  61. package/elasticsearch/indices/index.js.map +1 -0
  62. package/elasticsearch/indices/japanese.d.ts +2 -0
  63. package/elasticsearch/indices/japanese.js +24 -0
  64. package/elasticsearch/indices/japanese.js.map +1 -0
  65. package/elasticsearch/search/index.d.ts +2 -2
  66. package/elasticsearch/search/index.js +3 -5
  67. package/elasticsearch/search/index.js.map +1 -0
  68. package/elasticsearch/search/refSearch.d.ts +2 -3
  69. package/elasticsearch/search/refSearch.js +25 -16
  70. package/elasticsearch/search/refSearch.js.map +1 -0
  71. package/elasticsearch/search/timeSearch.d.ts +2 -3
  72. package/elasticsearch/search/timeSearch.js +22 -14
  73. package/elasticsearch/search/timeSearch.js.map +1 -0
  74. package/helpers/createElasticsearchQueryBody.js +312 -67
  75. package/helpers/createElasticsearchQueryBody.js.map +1 -0
  76. package/helpers/entryIndexHelpers.js +32 -12
  77. package/helpers/entryIndexHelpers.js.map +1 -0
  78. package/helpers/fields.d.ts +4 -62
  79. package/helpers/fields.js +27 -5
  80. package/helpers/fields.js.map +1 -0
  81. package/helpers/index.js.map +1 -0
  82. package/helpers/searchPluginsList.d.ts +2 -2
  83. package/helpers/searchPluginsList.js.map +1 -0
  84. package/helpers/transformValueForSearch.d.ts +5 -2
  85. package/helpers/transformValueForSearch.js +3 -0
  86. package/helpers/transformValueForSearch.js.map +1 -0
  87. package/index.js +61 -23
  88. package/index.js.map +1 -0
  89. package/operations/entry/dataLoaders.d.ts +6 -2
  90. package/operations/entry/dataLoaders.js +26 -6
  91. package/operations/entry/dataLoaders.js.map +1 -0
  92. package/operations/entry/elasticsearchFields.js +3 -0
  93. package/operations/entry/elasticsearchFields.js.map +1 -0
  94. package/operations/entry/index.d.ts +2 -2
  95. package/operations/entry/index.js +475 -162
  96. package/operations/entry/index.js.map +1 -0
  97. package/operations/entry/keys.js.map +1 -0
  98. package/operations/group/index.d.ts +2 -2
  99. package/operations/group/index.js +3 -5
  100. package/operations/group/index.js.map +1 -0
  101. package/operations/model/index.d.ts +2 -2
  102. package/operations/model/index.js +38 -35
  103. package/operations/model/index.js.map +1 -0
  104. package/operations/settings/index.d.ts +2 -2
  105. package/operations/settings/index.js +3 -5
  106. package/operations/settings/index.js.map +1 -0
  107. package/operations/system/index.d.ts +2 -2
  108. package/operations/system/index.js +3 -5
  109. package/operations/system/index.js.map +1 -0
  110. package/package.json +25 -29
  111. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +2 -2
  112. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
  113. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
  114. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
  115. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
  116. package/plugins/CmsEntryElasticsearchIndexPlugin.js +17 -0
  117. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
  118. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
  119. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +43 -0
  120. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
  121. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +2 -2
  122. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
  123. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +2 -2
  124. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
  125. package/types.d.ts +2 -32
  126. package/types.js +0 -13
  127. package/types.js.map +1 -0
  128. package/upgrades/index.d.ts +1 -1
  129. package/upgrades/index.js +1 -7
  130. package/upgrades/index.js.map +1 -0
  131. package/helpers/operatorPluginsList.d.ts +0 -7
  132. package/helpers/operatorPluginsList.js +0 -30
  133. package/operations/entry/fields.d.ts +0 -3
  134. package/operations/entry/fields.js +0 -60
  135. package/operations/system/createElasticsearchTemplate.d.ts +0 -5
  136. package/operations/system/createElasticsearchTemplate.js +0 -62
  137. package/upgrades/utils.d.ts +0 -1
  138. package/upgrades/utils.js +0 -16
  139. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
  140. package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
  141. package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
  142. package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
  143. package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
  144. package/upgrades/v5.0.0/entryValueFixer.js +0 -124
  145. package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
  146. package/upgrades/v5.0.0/fieldFinder.js +0 -42
  147. package/upgrades/v5.0.0/helpers.d.ts +0 -4
  148. package/upgrades/v5.0.0/helpers.js +0 -57
  149. package/upgrades/v5.0.0/index.d.ts +0 -4
  150. package/upgrades/v5.0.0/index.js +0 -232
  151. package/upgrades/v5.8.0/index.d.ts +0 -4
  152. package/upgrades/v5.8.0/index.js +0 -426
@@ -11,8 +11,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
 
12
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
13
 
14
- var _operatorPluginsList = require("./operatorPluginsList");
15
-
16
14
  var _transformValueForSearch = require("./transformValueForSearch");
17
15
 
18
16
  var _searchPluginsList = require("./searchPluginsList");
@@ -35,12 +33,16 @@ var _CmsEntryElasticsearchSortModifierPlugin = require("../plugins/CmsEntryElast
35
33
 
36
34
  var _CmsEntryElasticsearchBodyModifierPlugin = require("../plugins/CmsEntryElasticsearchBodyModifierPlugin");
37
35
 
38
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
36
+ var _operators = require("@webiny/api-elasticsearch/operators");
37
+
38
+ var _normalize = require("@webiny/api-elasticsearch/normalize");
39
+
40
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
41
 
40
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
42
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
41
43
 
42
- const specialFields = ["published", "latest", "locale", "tenant"];
43
- const noKeywordFields = ["date", "number", "boolean"];
44
+ const specialFields = ["published", "latest"];
45
+ const noKeywordFields = ["date", "datetime", "number", "boolean"];
44
46
 
45
47
  const createElasticsearchSortParams = args => {
46
48
  const {
@@ -51,28 +53,60 @@ const createElasticsearchSortParams = args => {
51
53
  } = args;
52
54
 
53
55
  if (!sort || sort.length === 0) {
54
- return undefined;
56
+ return [];
55
57
  }
56
58
 
59
+ const fieldIdToStorageIdIdMap = {};
57
60
  const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {
58
61
  const searchPlugin = searchPlugins[modelField.type];
59
- plugins[modelField.field.fieldId] = new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
62
+ const {
63
+ fieldId,
64
+ storageId
65
+ } = modelField.field;
66
+ fieldIdToStorageIdIdMap[fieldId] = fieldId;
67
+ /**
68
+ * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.
69
+ */
70
+
71
+ plugins[fieldId] = new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
60
72
  unmappedType: modelField.unmappedType,
61
73
  keyword: hasKeyword(modelField),
62
74
  sortable: modelField.isSortable,
63
75
  searchable: modelField.isSearchable,
64
- field: modelField.field.fieldId,
76
+ field: fieldId,
65
77
  path: createFieldPath({
78
+ key: storageId,
66
79
  parentPath,
67
- modelField: modelField,
80
+ modelField,
68
81
  searchPlugin
69
82
  })
70
83
  });
71
84
  return plugins;
72
85
  }, {});
86
+ const transformedSort = sort.map(value => {
87
+ const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);
88
+
89
+ if (!matched) {
90
+ return null;
91
+ }
92
+
93
+ const [, fieldId, order] = matched;
94
+
95
+ if (fieldIdToStorageIdIdMap[fieldId]) {
96
+ return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;
97
+ }
98
+
99
+ return value;
100
+ }).filter(Boolean);
73
101
  return (0, _sort.createSort)({
74
102
  fieldPlugins: sortPlugins,
75
- sort
103
+ sort: transformedSort
104
+ });
105
+ };
106
+
107
+ const findFieldByFieldId = (model, fieldId) => {
108
+ return model.fields.find(field => {
109
+ return field.fieldId === fieldId;
76
110
  });
77
111
  };
78
112
  /**
@@ -82,10 +116,17 @@ const createElasticsearchSortParams = args => {
82
116
  */
83
117
 
84
118
 
85
- const createInitialQueryValue = args => {
119
+ const createInitialQueryValue = params => {
86
120
  const {
87
- where
88
- } = args;
121
+ model,
122
+ where: initialWhere
123
+ } = params;
124
+ /**
125
+ * Cast as partial so we can remove unnecessary keys.
126
+ */
127
+
128
+ const where = _objectSpread({}, initialWhere);
129
+
89
130
  const query = {
90
131
  must: [],
91
132
  must_not: [],
@@ -98,22 +139,16 @@ const createInitialQueryValue = args => {
98
139
  if (sharedIndex) {
99
140
  query.must.push({
100
141
  term: {
101
- "tenant.keyword": where.tenant
142
+ "tenant.keyword": model.tenant
102
143
  }
103
144
  });
104
145
  }
105
146
 
106
- delete where["tenant"];
107
-
108
- if (where.locale) {
109
- query.must.push({
110
- term: {
111
- "locale.keyword": where.locale
112
- }
113
- });
114
- }
115
-
116
- delete where["locale"];
147
+ query.must.push({
148
+ term: {
149
+ "locale.keyword": model.locale
150
+ }
151
+ });
117
152
  /**
118
153
  * We must transform published and latest where args into something that is understandable by our Elasticsearch
119
154
  */
@@ -131,12 +166,8 @@ const createInitialQueryValue = args => {
131
166
  }
132
167
  });
133
168
  } // we do not allow not published and not latest
134
- else if (where.published === false) {
135
- throw new _error.default(`Cannot call Elasticsearch query with "published" set at false.`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
136
- where
137
- });
138
- } else if (where.latest === false) {
139
- throw new _error.default(`Cannot call Elasticsearch query with "latest" set at false.`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
169
+ else {
170
+ throw new _error.default(`Cannot call Elasticsearch query when not setting "published" or "latest".`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
140
171
  where
141
172
  });
142
173
  } //
@@ -148,20 +179,26 @@ const createInitialQueryValue = args => {
148
179
  const createFieldPath = ({
149
180
  modelField,
150
181
  searchPlugin,
151
- parentPath
182
+ parentPath,
183
+ key
152
184
  }) => {
153
- let path;
185
+ let path = null;
154
186
 
155
187
  if (searchPlugin && typeof searchPlugin.createPath === "function") {
156
188
  path = searchPlugin.createPath({
157
- field: modelField.field
189
+ field: modelField.field,
190
+ value: null,
191
+ key
158
192
  });
159
193
  } else if (typeof modelField.path === "function") {
160
- path = modelField.path(modelField.field.fieldId);
194
+ path = modelField.path(modelField.field.storageId);
161
195
  }
162
196
 
163
197
  if (!path) {
164
- path = modelField.path || modelField.field.fieldId || modelField.field.id;
198
+ /**
199
+ * We know that modelFieldPath is a string or undefined at this point.
200
+ */
201
+ path = modelField.path || modelField.field.storageId || modelField.field.id;
165
202
  }
166
203
 
167
204
  return modelField.isSystemField || !parentPath || path.match(parentPath) ? path : `${parentPath}.${path}`;
@@ -191,6 +228,149 @@ const hasKeyword = modelField => {
191
228
 
192
229
  return true;
193
230
  };
231
+
232
+ /**
233
+ * A list of typeof strings that are 100% not ref field filtering.
234
+ * We also need to check for array and date.
235
+ */
236
+ const nonRefFieldTypes = ["string", "number", "undefined", "symbol", "bigint", "function", "boolean"];
237
+
238
+ const isRefFieldFiltering = params => {
239
+ const {
240
+ key,
241
+ value,
242
+ field
243
+ } = params;
244
+ const typeOf = typeof value;
245
+
246
+ if (!value || nonRefFieldTypes.includes(typeOf) || Array.isArray(value) || value instanceof Date || !!value.toISOString) {
247
+ return false;
248
+ } else if (typeOf === "object" && field.type === "ref") {
249
+ return true;
250
+ }
251
+
252
+ throw new _error.default("Could not determine if the search value is ref field search.", "REF_FIELD_SEARCH_ERROR", {
253
+ value,
254
+ field,
255
+ key
256
+ });
257
+ };
258
+
259
+ const fieldPathFactory = params => {
260
+ const {
261
+ plugin,
262
+ modelField,
263
+ value,
264
+ parentPath,
265
+ keyword,
266
+ key
267
+ } = params;
268
+ const field = modelField.field;
269
+ let fieldPath = null;
270
+
271
+ if (plugin) {
272
+ fieldPath = plugin.createPath({
273
+ field,
274
+ value,
275
+ key
276
+ });
277
+ }
278
+
279
+ if (!fieldPath) {
280
+ fieldPath = field.storageId;
281
+
282
+ if (modelField.path) {
283
+ fieldPath = typeof modelField.path === "function" ? modelField.path(value) : modelField.path;
284
+ }
285
+ }
286
+
287
+ const keywordValue = keyword ? ".keyword" : "";
288
+
289
+ if (!parentPath) {
290
+ return `${fieldPath}${keywordValue}`;
291
+ }
292
+
293
+ return `${parentPath}.${fieldPath}${keywordValue}`;
294
+ };
295
+
296
+ const applyFiltering = params => {
297
+ const {
298
+ query,
299
+ modelField,
300
+ operator,
301
+ key,
302
+ value: initialValue,
303
+ operatorPlugins,
304
+ searchPlugins,
305
+ parentPath
306
+ } = params;
307
+ const plugin = operatorPlugins[operator];
308
+
309
+ if (!plugin) {
310
+ throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
311
+ operator
312
+ });
313
+ }
314
+
315
+ const fieldSearchPlugin = searchPlugins[modelField.type];
316
+ const value = (0, _transformValueForSearch.transformValueForSearch)({
317
+ plugins: searchPlugins,
318
+ field: modelField.field,
319
+ value: initialValue
320
+ });
321
+ const keyword = hasKeyword(modelField);
322
+ plugin.apply(query, {
323
+ basePath: fieldPathFactory({
324
+ plugin: fieldSearchPlugin,
325
+ modelField,
326
+ parentPath: modelField.isSystemField ? null : parentPath,
327
+ value,
328
+ key
329
+ }),
330
+ path: fieldPathFactory({
331
+ plugin: fieldSearchPlugin,
332
+ modelField,
333
+ value,
334
+ parentPath: modelField.isSystemField ? null : parentPath,
335
+ keyword,
336
+ key
337
+ }),
338
+ value,
339
+ keyword
340
+ });
341
+ };
342
+
343
+ const applyFullTextSearch = params => {
344
+ const {
345
+ query,
346
+ modelFields,
347
+ term,
348
+ fields
349
+ } = params;
350
+
351
+ if (!term || term.length === 0 || fields.length === 0) {
352
+ return;
353
+ }
354
+
355
+ const fieldPaths = fields.reduce((collection, field) => {
356
+ const modelField = modelFields[field.fieldId];
357
+
358
+ if (!modelField) {
359
+ return collection;
360
+ }
361
+
362
+ collection.push(`values.${field.storageId}`);
363
+ return collection;
364
+ }, []);
365
+ query.must.push({
366
+ query_string: {
367
+ allow_leading_wildcard: true,
368
+ fields: fieldPaths,
369
+ query: (0, _normalize.normalizeValue)(term),
370
+ default_operator: "or"
371
+ }
372
+ });
373
+ };
194
374
  /*
195
375
  * Iterate through where keys and apply plugins where necessary
196
376
  */
@@ -198,11 +378,13 @@ const hasKeyword = modelField => {
198
378
 
199
379
  const execElasticsearchBuildQueryPlugins = params => {
200
380
  const {
381
+ model,
201
382
  where: initialWhere,
202
383
  modelFields,
203
384
  parentPath,
204
385
  plugins,
205
- searchPlugins
386
+ searchPlugins,
387
+ fullTextSearch
206
388
  } = params;
207
389
 
208
390
  const where = _objectSpread({}, initialWhere);
@@ -210,6 +392,16 @@ const execElasticsearchBuildQueryPlugins = params => {
210
392
  const query = createInitialQueryValue(_objectSpread(_objectSpread({}, params), {}, {
211
393
  where
212
394
  }));
395
+ /**
396
+ * Add full text search for requested fields.
397
+ */
398
+
399
+ applyFullTextSearch({
400
+ query,
401
+ modelFields,
402
+ term: fullTextSearch.term,
403
+ fields: fullTextSearch.fields
404
+ });
213
405
  /**
214
406
  * Always remove special fields, as these do not exist in Elasticsearch.
215
407
  */
@@ -222,7 +414,7 @@ const execElasticsearchBuildQueryPlugins = params => {
222
414
  return query;
223
415
  }
224
416
 
225
- const operatorPlugins = (0, _operatorPluginsList.operatorPluginsList)(plugins);
417
+ const operatorPlugins = (0, _operators.getElasticsearchOperatorPluginsByLocale)(plugins, model.locale);
226
418
 
227
419
  for (const key in where) {
228
420
  if (where.hasOwnProperty(key) === false) {
@@ -232,9 +424,12 @@ const execElasticsearchBuildQueryPlugins = params => {
232
424
  * We do not need to go further if value is undefined.
233
425
  * There are few hardcoded possibilities when value is undefined, for example, ownedBy.
234
426
  */
427
+ // TODO figure out how to have type.
235
428
 
236
429
 
237
- if (where[key] === undefined) {
430
+ const value = where[key];
431
+
432
+ if (value === undefined) {
238
433
  continue;
239
434
  }
240
435
 
@@ -242,10 +437,26 @@ const execElasticsearchBuildQueryPlugins = params => {
242
437
  field,
243
438
  operator
244
439
  } = (0, _where.parseWhereKey)(key);
245
- const modelField = modelFields[field];
440
+ /**
441
+ * TODO This will be required until the storage operations receive the fieldId instead of field storageId.
442
+ * TODO For this to work without field searching, we need to refactor how the query looks like.
443
+ *
444
+ * Storage operations should NEVER receive an field storageId, only alias - fieldId.
445
+ */
446
+
447
+ let fieldId = field;
448
+ const cmsModelField = findFieldByFieldId(model, fieldId);
449
+
450
+ if (!cmsModelField && !modelFields[fieldId]) {
451
+ throw new _error.default(`There is no CMS Model Field field "${fieldId}".`);
452
+ } else if (cmsModelField) {
453
+ fieldId = cmsModelField.fieldId;
454
+ }
455
+
456
+ const modelField = modelFields[fieldId];
246
457
 
247
458
  if (!modelField) {
248
- throw new _error.default(`There is no field "${field}".`);
459
+ throw new _error.default(`There is no field "${fieldId}".`);
249
460
  }
250
461
 
251
462
  const {
@@ -254,34 +465,50 @@ const execElasticsearchBuildQueryPlugins = params => {
254
465
  } = modelField;
255
466
 
256
467
  if (!isSearchable) {
257
- throw new _error.default(`Field "${field}" is not searchable.`);
468
+ throw new _error.default(`Field "${fieldId}" is not searchable.`);
258
469
  }
470
+ /**
471
+ * There is a possibility that value is an object.
472
+ * In that case, check if field is ref field and continue a bit differently.
473
+ */
259
474
 
260
- const plugin = operatorPlugins[operator];
261
475
 
262
- if (!plugin) {
263
- throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
264
- operator
265
- });
476
+ if (isRefFieldFiltering({
477
+ key,
478
+ value,
479
+ field: cmsField
480
+ })) {
481
+ /**
482
+ * We we need to go through each key in where[key] to determine the filters.
483
+ */
484
+ for (const whereKey in value) {
485
+ const {
486
+ operator
487
+ } = (0, _where.parseWhereKey)(whereKey);
488
+ applyFiltering({
489
+ query,
490
+ modelField,
491
+ operator,
492
+ key: whereKey,
493
+ value: value[whereKey],
494
+ searchPlugins,
495
+ operatorPlugins,
496
+ parentPath
497
+ });
498
+ }
499
+
500
+ continue;
266
501
  }
267
502
 
268
- const fieldSearchPlugin = searchPlugins[modelField.type];
269
- const value = (0, _transformValueForSearch.transformValueForSearch)({
270
- plugins: searchPlugins,
271
- field: cmsField,
272
- value: where[key]
273
- });
274
- const fieldPath = createFieldPath({
275
- searchPlugin: fieldSearchPlugin,
503
+ applyFiltering({
504
+ query,
276
505
  modelField,
277
- parentPath: parentPath
278
- });
279
- const keyword = hasKeyword(modelField);
280
- plugin.apply(query, {
281
- basePath: fieldPath,
282
- path: keyword ? `${fieldPath}.keyword` : fieldPath,
506
+ operator,
507
+ key,
283
508
  value,
284
- keyword
509
+ searchPlugins,
510
+ operatorPlugins,
511
+ parentPath
285
512
  });
286
513
  }
287
514
 
@@ -296,20 +523,38 @@ const createElasticsearchQueryBody = params => {
296
523
  parentPath = null
297
524
  } = params;
298
525
  const {
299
- where,
526
+ where = {},
300
527
  after,
301
528
  limit,
302
- sort: initialSort
529
+ sort: initialSort,
530
+ search,
531
+ fields = []
303
532
  } = args;
304
533
  const modelFields = (0, _fields.createModelFields)(plugins, model);
305
534
  const searchPlugins = (0, _searchPluginsList.searchPluginsList)(plugins);
535
+ const fullTextSearchFields = [];
536
+
537
+ for (const fieldId of fields) {
538
+ const field = model.fields.find(f => f.fieldId === fieldId);
539
+
540
+ if (!field) {
541
+ continue;
542
+ }
543
+
544
+ fullTextSearchFields.push(field);
545
+ }
546
+
306
547
  const query = execElasticsearchBuildQueryPlugins({
307
548
  model,
308
549
  plugins,
309
550
  where,
310
551
  modelFields,
311
552
  parentPath,
312
- searchPlugins
553
+ searchPlugins,
554
+ fullTextSearch: {
555
+ term: search,
556
+ fields: fullTextSearchFields
557
+ }
313
558
  });
314
559
  const queryPlugins = plugins.byType(_CmsEntryElasticsearchQueryModifierPlugin.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
315
560
  return !pl.modelId || pl.modelId === model.modelId;
@@ -352,7 +597,7 @@ const createElasticsearchQueryBody = params => {
352
597
  }
353
598
  },
354
599
  sort,
355
- size: limit + 1,
600
+ size: (limit || 0) + 1,
356
601
  // eslint-disable-next-line
357
602
  search_after: (0, _cursors.decodeCursor)(after),
358
603
  // eslint-disable-next-line
@@ -0,0 +1 @@
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 { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createModelFields, ModelField, ModelFields } from \"./fields\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins/CmsEntryElasticsearchFieldPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch/where\";\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\";\nimport { getElasticsearchOperatorPluginsByLocale } from \"@webiny/api-elasticsearch/operators\";\nimport { normalizeValue } from \"@webiny/api-elasticsearch/normalize\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\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 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 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 });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAaA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;;;AAgCA,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,uBA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