@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,30 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.DataLoadersHandler = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _dataloader = _interopRequireDefault(require("dataloader"));
15
-
16
11
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
12
  var _query = require("@webiny/db-dynamodb/utils/query");
19
-
20
13
  var _keys = require("./keys");
21
-
22
14
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
23
-
24
15
  var _utils = require("@webiny/utils");
25
-
26
16
  var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
27
-
28
17
  const getAllEntryRevisions = params => {
29
18
  const {
30
19
  entity,
@@ -36,7 +25,6 @@ const getAllEntryRevisions = params => {
36
25
  } = model;
37
26
  return new _dataloader.default(async ids => {
38
27
  const results = {};
39
-
40
28
  for (const id of ids) {
41
29
  const queryAllParams = {
42
30
  entity,
@@ -52,13 +40,11 @@ const getAllEntryRevisions = params => {
52
40
  const items = await (0, _query.queryAll)(queryAllParams);
53
41
  results[id] = (0, _cleanup.cleanupItems)(entity, items);
54
42
  }
55
-
56
43
  return ids.map(id => {
57
44
  return results[id] || [];
58
45
  });
59
46
  });
60
47
  };
61
-
62
48
  const getRevisionById = params => {
63
49
  const {
64
50
  entity,
@@ -78,20 +64,16 @@ const getRevisionById = params => {
78
64
  const {
79
65
  version
80
66
  } = (0, _utils.parseIdentifier)(id);
81
-
82
67
  if (!version) {
83
68
  return collection;
84
69
  }
85
-
86
70
  const sortKey = (0, _keys.createRevisionSortKey)({
87
71
  version
88
72
  });
89
73
  const keys = `${partitionKey}__${sortKey}`;
90
-
91
74
  if (collection[keys]) {
92
75
  return collection;
93
76
  }
94
-
95
77
  collection[keys] = entity.getBatch({
96
78
  PK: partitionKey,
97
79
  SK: sortKey
@@ -113,7 +95,6 @@ const getRevisionById = params => {
113
95
  });
114
96
  });
115
97
  };
116
-
117
98
  const getPublishedRevisionByEntryId = params => {
118
99
  const {
119
100
  entity,
@@ -131,11 +112,9 @@ const getPublishedRevisionByEntryId = params => {
131
112
  locale,
132
113
  id
133
114
  });
134
-
135
115
  if (collection[partitionKey]) {
136
116
  return collection;
137
117
  }
138
-
139
118
  collection[partitionKey] = entity.getBatch({
140
119
  PK: partitionKey,
141
120
  SK: publishedKey
@@ -160,7 +139,6 @@ const getPublishedRevisionByEntryId = params => {
160
139
  });
161
140
  });
162
141
  };
163
-
164
142
  const getLatestRevisionByEntryId = params => {
165
143
  const {
166
144
  entity,
@@ -178,11 +156,9 @@ const getLatestRevisionByEntryId = params => {
178
156
  locale,
179
157
  id
180
158
  });
181
-
182
159
  if (collection[partitionKey]) {
183
160
  return collection;
184
161
  }
185
-
186
162
  collection[partitionKey] = entity.getBatch({
187
163
  PK: partitionKey,
188
164
  SK: latestKey
@@ -207,7 +183,6 @@ const getLatestRevisionByEntryId = params => {
207
183
  });
208
184
  });
209
185
  };
210
-
211
186
  const dataLoaders = {
212
187
  getAllEntryRevisions,
213
188
  getRevisionById,
@@ -215,42 +190,33 @@ const dataLoaders = {
215
190
  getLatestRevisionByEntryId
216
191
  };
217
192
  const loaderNames = Object.keys(dataLoaders);
218
-
219
193
  class DataLoadersHandler {
220
194
  constructor(params) {
221
195
  (0, _defineProperty2.default)(this, "loaders", new Map());
222
196
  (0, _defineProperty2.default)(this, "entity", void 0);
223
197
  this.entity = params.entity;
224
198
  }
225
-
226
199
  async getAllEntryRevisions(params) {
227
200
  return await this.loadMany("getAllEntryRevisions", params, params.ids);
228
201
  }
229
-
230
202
  clearAllEntryRevisions(params) {
231
203
  this.clear("getAllEntryRevisions", params);
232
204
  }
233
-
234
205
  async getRevisionById(params) {
235
206
  return await this.loadMany("getRevisionById", params, params.ids);
236
207
  }
237
-
238
208
  clearRevisionById(params) {
239
209
  this.clear("getRevisionById", params);
240
210
  }
241
-
242
211
  async getPublishedRevisionByEntryId(params) {
243
212
  return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
244
213
  }
245
-
246
214
  clearPublishedRevisionByEntryId(params) {
247
215
  this.clear("getPublishedRevisionByEntryId", params);
248
216
  }
249
-
250
217
  async getLatestRevisionByEntryId(params) {
251
218
  return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
252
219
  }
253
-
254
220
  clearLatestRevisionByEntryId(params) {
255
221
  this.clear("getLatestRevisionByEntryId", params);
256
222
  }
@@ -258,15 +224,12 @@ class DataLoadersHandler {
258
224
  * TODO @ts-refactor
259
225
  * Maybe pass on the generics to DataLoader definition?
260
226
  */
261
-
262
-
263
227
  getLoader(name, params) {
264
228
  if (!dataLoaders[name]) {
265
229
  throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
266
230
  name
267
231
  });
268
232
  }
269
-
270
233
  const {
271
234
  model
272
235
  } = params;
@@ -275,22 +238,17 @@ class DataLoadersHandler {
275
238
  locale
276
239
  } = model;
277
240
  const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
278
-
279
241
  if (!this.loaders.has(loaderKey)) {
280
242
  this.loaders.set(loaderKey, dataLoaders[name]((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
281
243
  entity: this.entity
282
244
  })));
283
245
  }
284
-
285
246
  return this.loaders.get(loaderKey);
286
247
  }
287
-
288
248
  async loadMany(loader, params, ids) {
289
249
  let results;
290
-
291
250
  try {
292
251
  results = await this.getLoader(loader, params).loadMany(ids);
293
-
294
252
  if (Array.isArray(results) === true) {
295
253
  return results.reduce((acc, res) => {
296
254
  if (Array.isArray(res) === false) {
@@ -299,12 +257,10 @@ class DataLoadersHandler {
299
257
  data: JSON.stringify(res.data || {})
300
258
  }));
301
259
  }
302
-
303
260
  throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
304
261
  loader
305
262
  }));
306
263
  }
307
-
308
264
  acc.push(...res);
309
265
  return acc;
310
266
  }, []);
@@ -317,14 +273,12 @@ class DataLoadersHandler {
317
273
  ids
318
274
  }));
319
275
  }
320
-
321
276
  throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
322
277
  loader,
323
278
  ids,
324
279
  results
325
280
  });
326
281
  }
327
-
328
282
  clearAll(params) {
329
283
  for (const name of loaderNames) {
330
284
  const loader = this.getLoader(name, params);
@@ -335,19 +289,15 @@ class DataLoadersHandler {
335
289
  * Helper to clear the cache for certain data loader.
336
290
  * If entry is passed then clear target key only.
337
291
  */
338
-
339
-
340
292
  clear(name, params) {
341
293
  const {
342
294
  entry
343
295
  } = params;
344
296
  const loader = this.getLoader(name, params);
345
-
346
297
  if (!entry) {
347
298
  loader.clearAll();
348
299
  return;
349
300
  }
350
-
351
301
  loader.clear(entry.id);
352
302
  const {
353
303
  tenant,
@@ -359,7 +309,5 @@ class DataLoadersHandler {
359
309
  id: entry.id
360
310
  }));
361
311
  }
362
-
363
312
  }
364
-
365
313
  exports.DataLoadersHandler = DataLoadersHandler;
@@ -1 +1 @@
1
- {"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","clearAllEntryRevisions","clear","clearRevisionById","clearPublishedRevisionByEntryId","clearLatestRevisionByEntryId","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll","entry"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsEntry>(queryAllParams);\n\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (!version) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\nexport interface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public clearAllEntryRevisions(params: ClearLoaderParams): void {\n this.clear(\"getAllEntryRevisions\", params);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public clearRevisionById(params: ClearLoaderParams): void {\n this.clear(\"getRevisionById\", params);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n public clearPublishedRevisionByEntryId(params: ClearLoaderParams): void {\n this.clear(\"getPublishedRevisionByEntryId\", params);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n public clearLatestRevisionByEntryId(params: ClearLoaderParams): void {\n this.clear(\"getLatestRevisionByEntryId\", params);\n }\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n /**\n * Helper to clear the cache for certain data loader.\n * If entry is passed then clear target key only.\n */\n private clear(name: Loaders, params: ClearLoaderParams): void {\n const { entry } = params;\n const loader = this.getLoader(name, params);\n if (!entry) {\n loader.clearAll();\n return;\n }\n loader.clear(entry.id);\n const { tenant, locale } = params.model;\n loader.clear(\n createPartitionKey({\n tenant,\n locale,\n id: entry.id\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAMA;;AACA;;AACA;;AAEA,MAAMA,oBAAoB,GAAIC,MAAD,IAA0B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBF,MAA1B;EACA,MAAM;IAAEG,MAAF;IAAUC;EAAV,IAAqBF,KAA3B;EACA,OAAO,IAAIG,mBAAJ,CAAmC,MAAOC,GAAP,IAAkC;IACxE,MAAMC,OAAmC,GAAG,EAA5C;;IACA,KAAK,MAAMC,EAAX,IAAiBF,GAAjB,EAAsB;MAClB,MAAMG,cAA8B,GAAG;QACnCR,MADmC;QAEnCS,YAAY,EAAE,IAAAC,wBAAA,EAAmB;UAC7BR,MAD6B;UAE7BC,MAF6B;UAG7BI;QAH6B,CAAnB,CAFqB;QAOnCI,OAAO,EAAE;UACLC,UAAU,EAAE;QADP;MAP0B,CAAvC;MAWA,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAA,EAAmBN,cAAnB,CAApB;MAEAF,OAAO,CAACC,EAAD,CAAP,GAAc,IAAAQ,qBAAA,EAAaf,MAAb,EAAqBa,KAArB,CAAd;IACH;;IAED,OAAOR,GAAG,CAACW,GAAJ,CAAQT,EAAE,IAAI;MACjB,OAAOD,OAAO,CAACC,EAAD,CAAP,IAAe,EAAtB;IACH,CAFM,CAAP;EAGH,CAtBM,CAA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AAD,EAAgBxD,MAAhB,EAAiD;IAC1D,MAAM;MAAE8E;IAAF,IAAY9E,MAAlB;IACA,MAAMgE,MAAM,GAAG,KAAKT,SAAL,CAAeC,IAAf,EAAqBxD,MAArB,CAAf;;IACA,IAAI,CAAC8E,KAAL,EAAY;MACRd,MAAM,CAACa,QAAP;MACA;IACH;;IACDb,MAAM,CAACb,KAAP,CAAa2B,KAAK,CAACtE,EAAnB;IACA,MAAM;MAAEL,MAAF;MAAUC;IAAV,IAAqBJ,MAAM,CAACE,KAAlC;IACA8D,MAAM,CAACb,KAAP,CACI,IAAAxC,wBAAA,EAAmB;MACfR,MADe;MAEfC,MAFe;MAGfI,EAAE,EAAEsE,KAAK,CAACtE;IAHK,CAAnB,CADJ;EAOH;;AAlJ2B"}
1
+ {"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","clearAllEntryRevisions","clear","clearRevisionById","clearPublishedRevisionByEntryId","clearLatestRevisionByEntryId","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll","entry"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsEntry>(queryAllParams);\n\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (!version) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\nexport interface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public clearAllEntryRevisions(params: ClearLoaderParams): void {\n this.clear(\"getAllEntryRevisions\", params);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public clearRevisionById(params: ClearLoaderParams): void {\n this.clear(\"getRevisionById\", params);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n public clearPublishedRevisionByEntryId(params: ClearLoaderParams): void {\n this.clear(\"getPublishedRevisionByEntryId\", params);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n public clearLatestRevisionByEntryId(params: ClearLoaderParams): void {\n this.clear(\"getLatestRevisionByEntryId\", params);\n }\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n /**\n * Helper to clear the cache for certain data loader.\n * If entry is passed then clear target key only.\n */\n private clear(name: Loaders, params: ClearLoaderParams): void {\n const { entry } = params;\n const loader = this.getLoader(name, params);\n if (!entry) {\n loader.clearAll();\n return;\n }\n loader.clear(entry.id);\n const { tenant, locale } = params.model;\n loader.clear(\n createPartitionKey({\n tenant,\n locale,\n id: entry.id\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AAGA;AACA;AAMA;AACA;AACA;AAEA,MAAMA,oBAAoB,GAAIC,MAAoB,IAAK;EACnD,MAAM;IAAEC,MAAM;IAAEC;EAAM,CAAC,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,OAAOD,GAAG;QACd,CAAC,EAAE,EAAE,CAAC;MACV;IACJ,CAAC,CAAC,OAAOQ,EAAE,EAAE;MACT,MAAM,IAAIlB,cAAW,CACjBkB,EAAE,CAACN,OAAO,IAAI,oBAAoB,EAClCM,EAAE,CAACL,IAAI,IAAI,mBAAmB;QAE1BM,KAAK,EAAED;MAAE,GACN3E,MAAM;QACTgE,MAAM;QACN1D;MAAG,GAEV;IACL;IACA,MAAM,IAAImD,cAAW,CAChB,2DAA0D,EAC3D,4BAA4B,EAC5B;MACIO,MAAM;MACN1D,GAAG;MACHC;IACJ,CAAC,CACJ;EACL;EAEOsE,QAAQ,CAAC7E,MAAwC,EAAQ;IAC5D,KAAK,MAAMwD,IAAI,IAAIX,WAAW,EAAE;MAC5B,MAAMmB,MAAM,GAAG,IAAI,CAACT,SAAS,CAACC,IAAI,EAAExD,MAAM,CAAC;MAC3CgE,MAAM,CAACa,QAAQ,EAAE;IACrB;EACJ;EACA;AACJ;AACA;AACA;EACY1B,KAAK,CAACK,IAAa,EAAExD,MAAyB,EAAQ;IAC1D,MAAM;MAAE8E;IAAM,CAAC,GAAG9E,MAAM;IACxB,MAAMgE,MAAM,GAAG,IAAI,CAACT,SAAS,CAACC,IAAI,EAAExD,MAAM,CAAC;IAC3C,IAAI,CAAC8E,KAAK,EAAE;MACRd,MAAM,CAACa,QAAQ,EAAE;MACjB;IACJ;IACAb,MAAM,CAACb,KAAK,CAAC2B,KAAK,CAACtE,EAAE,CAAC;IACtB,MAAM;MAAEL,MAAM;MAAEC;IAAO,CAAC,GAAGJ,MAAM,CAACE,KAAK;IACvC8D,MAAM,CAACb,KAAK,CACR,IAAAxC,wBAAkB,EAAC;MACfR,MAAM;MACNC,MAAM;MACNI,EAAE,EAAEsE,KAAK,CAACtE;IACd,CAAC,CAAC,CACL;EACL;AACJ;AAAC"}
@@ -0,0 +1,18 @@
1
+ import { BoolQueryConfig } from "@webiny/api-elasticsearch/types";
2
+ /**
3
+ * This function will assign a minimum_should_match for the query if conditions are met:
4
+ * * should is an array
5
+ * * it is not empty
6
+ * * minimum_should_match is not already set
7
+ *
8
+ *
9
+ * By the default we set it to 1 as we want at least one OR condition to produce results.
10
+ *
11
+ * Users can modify minimum_should_match value via the body or query modification plugins.
12
+ */
13
+ interface Params {
14
+ query: BoolQueryConfig;
15
+ value?: number;
16
+ }
17
+ export declare const assignMinimumShouldMatchToQuery: ({ query, value }: Params) => void;
18
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignMinimumShouldMatchToQuery = void 0;
7
+ /**
8
+ * This function will assign a minimum_should_match for the query if conditions are met:
9
+ * * should is an array
10
+ * * it is not empty
11
+ * * minimum_should_match is not already set
12
+ *
13
+ *
14
+ * By the default we set it to 1 as we want at least one OR condition to produce results.
15
+ *
16
+ * Users can modify minimum_should_match value via the body or query modification plugins.
17
+ */
18
+
19
+ const assignMinimumShouldMatchToQuery = ({
20
+ query,
21
+ value = 1
22
+ }) => {
23
+ if (!Array.isArray(query.should)) {
24
+ return;
25
+ } else if (query.should.length === 0) {
26
+ return;
27
+ } else if (query.minimum_should_match) {
28
+ return;
29
+ }
30
+ query.minimum_should_match = value > 0 ? value : 1;
31
+ };
32
+ exports.assignMinimumShouldMatchToQuery = assignMinimumShouldMatchToQuery;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["assignMinimumShouldMatchToQuery","query","value","Array","isArray","should","length","minimum_should_match"],"sources":["assignMinimumShouldMatchToQuery.ts"],"sourcesContent":["import { BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\n\n/**\n * This function will assign a minimum_should_match for the query if conditions are met:\n * * should is an array\n * * it is not empty\n * * minimum_should_match is not already set\n *\n *\n * By the default we set it to 1 as we want at least one OR condition to produce results.\n *\n * Users can modify minimum_should_match value via the body or query modification plugins.\n */\ninterface Params {\n query: BoolQueryConfig;\n value?: number;\n}\nexport const assignMinimumShouldMatchToQuery = ({ query, value = 1 }: Params): void => {\n if (!Array.isArray(query.should)) {\n return;\n } else if (query.should.length === 0) {\n return;\n } else if (query.minimum_should_match) {\n return;\n }\n query.minimum_should_match = value > 0 ? value : 1;\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKO,MAAMA,+BAA+B,GAAG,CAAC;EAAEC,KAAK;EAAEC,KAAK,GAAG;AAAU,CAAC,KAAW;EACnF,IAAI,CAACC,KAAK,CAACC,OAAO,CAACH,KAAK,CAACI,MAAM,CAAC,EAAE;IAC9B;EACJ,CAAC,MAAM,IAAIJ,KAAK,CAACI,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;IAClC;EACJ,CAAC,MAAM,IAAIL,KAAK,CAACM,oBAAoB,EAAE;IACnC;EACJ;EACAN,KAAK,CAACM,oBAAoB,GAAGL,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAG,CAAC;AACtD,CAAC;AAAC"}
@@ -0,0 +1,13 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { CmsEntryListParams, CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types";
3
+ import { PrimitiveValue, SearchBody } from "@webiny/api-elasticsearch/types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
7
+ params: Omit<CmsEntryListParams, "where" | "after"> & {
8
+ where: CmsEntryListWhere;
9
+ after?: PrimitiveValue[];
10
+ };
11
+ }
12
+ export declare const createElasticsearchBody: ({ plugins, model, params }: Params) => SearchBody;
13
+ export {};
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createElasticsearchBody = void 0;
7
+ var _fields = require("./fields");
8
+ var _fullTextSearchFields = require("./fullTextSearchFields");
9
+ var _initialQuery = require("./initialQuery");
10
+ var _fullTextSearch = require("./fullTextSearch");
11
+ var _queryModifier = require("./plugins/queryModifier");
12
+ var _sortModifier = require("./plugins/sortModifier");
13
+ var _bodyModifier = require("./plugins/bodyModifier");
14
+ var _sort = require("./sort");
15
+ var _filtering = require("./filtering");
16
+ var _assignMinimumShouldMatchToQuery = require("./assignMinimumShouldMatchToQuery");
17
+ const createElasticsearchBody = ({
18
+ plugins,
19
+ model,
20
+ params
21
+ }) => {
22
+ const {
23
+ fields,
24
+ search: term,
25
+ where,
26
+ sort: initialSort,
27
+ after,
28
+ limit
29
+ } = params;
30
+ /**
31
+ * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.
32
+ */
33
+ const modelFields = (0, _fields.createModelFields)({
34
+ plugins,
35
+ fields: model.fields
36
+ });
37
+
38
+ /**
39
+ * We need the query modifier plugins.
40
+ */
41
+ const queryModifierPlugins = (0, _queryModifier.createQueryModifierPluginList)({
42
+ plugins,
43
+ model
44
+ });
45
+ /**
46
+ * We need the sort modifier plugins.
47
+ */
48
+ const sortModifierPlugins = (0, _sortModifier.createSortModifierPluginList)({
49
+ plugins,
50
+ model
51
+ });
52
+ /**
53
+ * We need the body modifier plugins.
54
+ */
55
+ const bodyModifierPlugins = (0, _bodyModifier.createBodyModifierPluginList)({
56
+ plugins,
57
+ model
58
+ });
59
+ /**
60
+ * We need the fields which we can search through via the full text search.
61
+ *
62
+ */
63
+ const fullTextSearchFields = (0, _fullTextSearchFields.createFullTextSearchFields)({
64
+ model,
65
+ term,
66
+ fields
67
+ });
68
+ /**
69
+ * The initial elasticsearch query where we attach some default conditions we always need.
70
+ */
71
+ const query = (0, _initialQuery.createInitialQuery)({
72
+ where,
73
+ model
74
+ });
75
+ /**
76
+ * Apply the full text search, if term is set.
77
+ */
78
+ (0, _fullTextSearch.applyFullTextSearch)({
79
+ model,
80
+ plugins,
81
+ query,
82
+ term,
83
+ fields: fullTextSearchFields
84
+ });
85
+ const execFiltering = (0, _filtering.createExecFiltering)({
86
+ model,
87
+ fields: modelFields,
88
+ plugins
89
+ });
90
+ execFiltering({
91
+ where,
92
+ query
93
+ });
94
+ for (const pl of queryModifierPlugins) {
95
+ pl.modifyQuery({
96
+ query,
97
+ model,
98
+ where
99
+ });
100
+ }
101
+ const sort = (0, _sort.createElasticsearchSort)({
102
+ plugins,
103
+ sort: initialSort,
104
+ modelFields,
105
+ model
106
+ });
107
+ for (const pl of sortModifierPlugins) {
108
+ pl.modifySort({
109
+ sort,
110
+ model
111
+ });
112
+ }
113
+ const boolQuery = {
114
+ must: query.must.length > 0 ? query.must : undefined,
115
+ must_not: query.must_not.length > 0 ? query.must_not : undefined,
116
+ should: query.should.length > 0 ? query.should : undefined,
117
+ filter: query.filter.length > 0 ? query.filter : undefined
118
+ };
119
+ (0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
120
+ query: boolQuery
121
+ });
122
+ const body = {
123
+ query: {
124
+ bool: boolQuery
125
+ },
126
+ sort,
127
+ size: (limit || 0) + 1,
128
+ search_after: after,
129
+ track_total_hits: true
130
+ };
131
+ for (const pl of bodyModifierPlugins) {
132
+ pl.modifyBody({
133
+ body,
134
+ model,
135
+ where
136
+ });
137
+ }
138
+ return body;
139
+ };
140
+ exports.createElasticsearchBody = createElasticsearchBody;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElasticsearchBody","plugins","model","params","fields","search","term","where","sort","initialSort","after","limit","modelFields","createModelFields","queryModifierPlugins","createQueryModifierPluginList","sortModifierPlugins","createSortModifierPluginList","bodyModifierPlugins","createBodyModifierPluginList","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","execFiltering","createExecFiltering","pl","modifyQuery","createElasticsearchSort","modifySort","boolQuery","must","length","undefined","must_not","should","filter","assignMinimumShouldMatchToQuery","body","bool","size","search_after","track_total_hits","modifyBody"],"sources":["body.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListParams, CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createModelFields } from \"./fields\";\nimport { createFullTextSearchFields } from \"./fullTextSearchFields\";\nimport { createInitialQuery } from \"./initialQuery\";\nimport { applyFullTextSearch } from \"./fullTextSearch\";\nimport { createQueryModifierPluginList } from \"./plugins/queryModifier\";\nimport { createSortModifierPluginList } from \"./plugins/sortModifier\";\nimport { createBodyModifierPluginList } from \"./plugins/bodyModifier\";\nimport { createElasticsearchSort } from \"./sort\";\nimport { PrimitiveValue, SearchBody, BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createExecFiltering } from \"./filtering\";\nimport { assignMinimumShouldMatchToQuery } from \"./assignMinimumShouldMatchToQuery\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\nexport const createElasticsearchBody = ({ plugins, model, params }: Params): SearchBody => {\n const { fields, search: term, where, sort: initialSort, after, limit } = params;\n /**\n * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.\n */\n const modelFields = createModelFields({\n plugins,\n fields: model.fields\n });\n\n /**\n * We need the query modifier plugins.\n */\n const queryModifierPlugins = createQueryModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the sort modifier plugins.\n */\n const sortModifierPlugins = createSortModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the body modifier plugins.\n */\n const bodyModifierPlugins = createBodyModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the fields which we can search through via the full text search.\n *\n */\n const fullTextSearchFields = createFullTextSearchFields({\n model,\n term,\n fields\n });\n /**\n * The initial elasticsearch query where we attach some default conditions we always need.\n */\n const query = createInitialQuery({\n where,\n model\n });\n /**\n * Apply the full text search, if term is set.\n */\n applyFullTextSearch({\n model,\n plugins,\n query,\n term,\n fields: fullTextSearchFields\n });\n\n const execFiltering = createExecFiltering({\n model,\n fields: modelFields,\n plugins\n });\n\n execFiltering({\n where,\n query\n });\n\n for (const pl of queryModifierPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n plugins,\n sort: initialSort,\n modelFields,\n model\n });\n\n for (const pl of sortModifierPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const boolQuery: BoolQueryConfig = {\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 assignMinimumShouldMatchToQuery({\n query: boolQuery\n });\n\n const body: SearchBody = {\n query: {\n bool: boolQuery\n },\n sort,\n size: (limit || 0) + 1,\n search_after: after,\n track_total_hits: true\n };\n\n for (const pl of bodyModifierPlugins) {\n pl.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAUO,MAAMA,uBAAuB,GAAG,CAAC;EAAEC,OAAO;EAAEC,KAAK;EAAEC;AAAe,CAAC,KAAiB;EACvF,MAAM;IAAEC,MAAM;IAAEC,MAAM,EAAEC,IAAI;IAAEC,KAAK;IAAEC,IAAI,EAAEC,WAAW;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGR,MAAM;EAC/E;AACJ;AACA;EACI,MAAMS,WAAW,GAAG,IAAAC,yBAAiB,EAAC;IAClCZ,OAAO;IACPG,MAAM,EAAEF,KAAK,CAACE;EAClB,CAAC,CAAC;;EAEF;AACJ;AACA;EACI,MAAMU,oBAAoB,GAAG,IAAAC,4CAA6B,EAAC;IACvDd,OAAO;IACPC;EACJ,CAAC,CAAC;EACF;AACJ;AACA;EACI,MAAMc,mBAAmB,GAAG,IAAAC,0CAA4B,EAAC;IACrDhB,OAAO;IACPC;EACJ,CAAC,CAAC;EACF;AACJ;AACA;EACI,MAAMgB,mBAAmB,GAAG,IAAAC,0CAA4B,EAAC;IACrDlB,OAAO;IACPC;EACJ,CAAC,CAAC;EACF;AACJ;AACA;AACA;EACI,MAAMkB,oBAAoB,GAA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AACe,MAAM,CAACJ,MAAM,GAAG,CAAC,GAAGX,KAAK,CAACe,MAAM,GAAGH;EACrD,CAAC;EAED,IAAAI,gEAA+B,EAAC;IAC5BhB,KAAK,EAAES;EACX,CAAC,CAAC;EAEF,MAAMQ,IAAgB,GAAG;IACrBjB,KAAK,EAAE;MACHkB,IAAI,EAAET;IACV,CAAC;IACDvB,IAAI;IACJiC,IAAI,EAAE,CAAC9B,KAAK,IAAI,CAAC,IAAI,CAAC;IACtB+B,YAAY,EAAEhC,KAAK;IACnBiC,gBAAgB,EAAE;EACtB,CAAC;EAED,KAAK,MAAMhB,EAAE,IAAIT,mBAAmB,EAAE;IAClCS,EAAE,CAACiB,UAAU,CAAC;MACVL,IAAI;MACJrC,KAAK;MACLK;IACJ,CAAC,CAAC;EACN;EAEA,OAAOgC,IAAI;AACf,CAAC;AAAC"}
@@ -0,0 +1,9 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
3
+ import { ModelFields } from "./types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ fields?: CmsModelField[];
7
+ }
8
+ export declare const createModelFields: ({ plugins, fields }: Params) => ModelFields;
9
+ export {};