@webiny/api-headless-cms-ddb-es 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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 (303) hide show
  1. package/configurations.d.ts +13 -6
  2. package/configurations.js +18 -12
  3. package/configurations.js.map +1 -1
  4. package/definitions/entry.d.ts +4 -3
  5. package/definitions/entry.js +108 -16
  6. package/definitions/entry.js.map +1 -1
  7. package/definitions/entryElasticsearch.d.ts +4 -3
  8. package/definitions/entryElasticsearch.js +11 -12
  9. package/definitions/entryElasticsearch.js.map +1 -1
  10. package/definitions/group.d.ts +4 -3
  11. package/definitions/group.js +8 -12
  12. package/definitions/group.js.map +1 -1
  13. package/definitions/model.d.ts +4 -3
  14. package/definitions/model.js +30 -12
  15. package/definitions/model.js.map +1 -1
  16. package/definitions/system.d.ts +4 -3
  17. package/definitions/system.js +8 -12
  18. package/definitions/system.js.map +1 -1
  19. package/definitions/table.d.ts +5 -5
  20. package/definitions/table.js +7 -6
  21. package/definitions/table.js.map +1 -1
  22. package/definitions/tableElasticsearch.d.ts +5 -5
  23. package/definitions/tableElasticsearch.js +7 -6
  24. package/definitions/tableElasticsearch.js.map +1 -1
  25. package/dynamoDb/index.d.ts +2 -1
  26. package/dynamoDb/index.js +8 -8
  27. package/dynamoDb/index.js.map +1 -1
  28. package/dynamoDb/storage/longText.d.ts +1 -1
  29. package/dynamoDb/storage/longText.js +13 -18
  30. package/dynamoDb/storage/longText.js.map +1 -1
  31. package/dynamoDb/storage/richText.d.ts +1 -6
  32. package/dynamoDb/storage/richText.js +26 -95
  33. package/dynamoDb/storage/richText.js.map +1 -1
  34. package/elasticsearch/createElasticsearchIndex.d.ts +4 -4
  35. package/elasticsearch/createElasticsearchIndex.js +19 -39
  36. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  37. package/elasticsearch/deleteElasticsearchIndex.d.ts +3 -3
  38. package/elasticsearch/deleteElasticsearchIndex.js +5 -10
  39. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  40. package/elasticsearch/index.js +2 -5
  41. package/elasticsearch/index.js.map +1 -1
  42. package/elasticsearch/indexing/dateTimeIndexing.d.ts +1 -1
  43. package/elasticsearch/indexing/dateTimeIndexing.js +8 -23
  44. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  45. package/elasticsearch/indexing/defaultFieldIndexing.d.ts +1 -1
  46. package/elasticsearch/indexing/defaultFieldIndexing.js +17 -10
  47. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  48. package/elasticsearch/indexing/index.js +4 -10
  49. package/elasticsearch/indexing/index.js.map +1 -1
  50. package/elasticsearch/indexing/jsonIndexing.d.ts +2 -0
  51. package/elasticsearch/indexing/jsonIndexing.js +28 -0
  52. package/elasticsearch/indexing/jsonIndexing.js.map +1 -0
  53. package/elasticsearch/indexing/longTextIndexing.d.ts +5 -1
  54. package/elasticsearch/indexing/longTextIndexing.js +16 -10
  55. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  56. package/elasticsearch/indexing/numberIndexing.d.ts +1 -1
  57. package/elasticsearch/indexing/numberIndexing.js +2 -9
  58. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  59. package/elasticsearch/indexing/objectIndexing.d.ts +1 -1
  60. package/elasticsearch/indexing/objectIndexing.js +23 -45
  61. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  62. package/elasticsearch/indexing/richTextIndexing.d.ts +1 -1
  63. package/elasticsearch/indexing/richTextIndexing.js +2 -5
  64. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  65. package/elasticsearch/indices/base.js +3 -5
  66. package/elasticsearch/indices/base.js.map +1 -1
  67. package/elasticsearch/indices/index.js +2 -4
  68. package/elasticsearch/indices/index.js.map +1 -1
  69. package/elasticsearch/indices/japanese.js +3 -5
  70. package/elasticsearch/indices/japanese.js.map +1 -1
  71. package/elasticsearch/search/index.d.ts +1 -1
  72. package/elasticsearch/search/index.js +4 -5
  73. package/elasticsearch/search/index.js.map +1 -1
  74. package/elasticsearch/search/refSearch.js +6 -8
  75. package/elasticsearch/search/refSearch.js.map +1 -1
  76. package/elasticsearch/search/searchableJson.d.ts +2 -0
  77. package/elasticsearch/search/searchableJson.js +60 -0
  78. package/elasticsearch/search/searchableJson.js.map +1 -0
  79. package/elasticsearch/search/timeSearch.js +3 -9
  80. package/elasticsearch/search/timeSearch.js.map +1 -1
  81. package/helpers/entryIndexHelpers.d.ts +3 -3
  82. package/helpers/entryIndexHelpers.js +51 -65
  83. package/helpers/entryIndexHelpers.js.map +1 -1
  84. package/helpers/fieldIdentifier.d.ts +6 -0
  85. package/helpers/fieldIdentifier.js +43 -0
  86. package/helpers/fieldIdentifier.js.map +1 -0
  87. package/helpers/index.d.ts +1 -1
  88. package/helpers/index.js +11 -13
  89. package/helpers/index.js.map +1 -1
  90. package/index.d.ts +1 -1
  91. package/index.js +50 -93
  92. package/index.js.map +1 -1
  93. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  94. package/operations/entry/dataLoader/DataLoaderCache.js +41 -0
  95. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  96. package/operations/entry/dataLoader/constants.d.ts +1 -0
  97. package/operations/entry/dataLoader/constants.js +10 -0
  98. package/operations/entry/dataLoader/constants.js.map +1 -0
  99. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  100. package/operations/entry/dataLoader/createBatchScheduleFn.js +25 -0
  101. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  102. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  103. package/operations/entry/dataLoader/getAllEntryRevisions.js +45 -0
  104. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  105. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  106. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +52 -0
  107. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  108. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  109. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +52 -0
  110. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  111. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  112. package/operations/entry/dataLoader/getRevisionById.js +62 -0
  113. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  114. package/operations/entry/dataLoader/index.d.ts +8 -0
  115. package/operations/entry/dataLoader/index.js +40 -0
  116. package/operations/entry/dataLoader/index.js.map +1 -0
  117. package/operations/entry/dataLoader/types.d.ts +6 -0
  118. package/operations/entry/dataLoader/types.js +7 -0
  119. package/operations/entry/dataLoader/types.js.map +1 -0
  120. package/operations/entry/dataLoaders.d.ts +16 -37
  121. package/operations/entry/dataLoaders.js +54 -303
  122. package/operations/entry/dataLoaders.js.map +1 -1
  123. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  124. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +34 -0
  125. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  126. package/operations/entry/elasticsearch/body.d.ts +13 -0
  127. package/operations/entry/elasticsearch/body.js +142 -0
  128. package/operations/entry/elasticsearch/body.js.map +1 -0
  129. package/operations/entry/elasticsearch/fields.d.ts +10 -0
  130. package/operations/entry/elasticsearch/fields.js +315 -0
  131. package/operations/entry/elasticsearch/fields.js.map +1 -0
  132. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
  133. package/operations/entry/elasticsearch/filtering/applyFiltering.js +60 -0
  134. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  135. package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
  136. package/operations/entry/elasticsearch/filtering/exec.js +175 -0
  137. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  138. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  139. package/operations/entry/elasticsearch/filtering/index.js +18 -0
  140. package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
  141. package/operations/entry/elasticsearch/filtering/path.d.ts +16 -0
  142. package/operations/entry/elasticsearch/filtering/path.js +48 -0
  143. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  144. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  145. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +30 -0
  146. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  147. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  148. package/operations/entry/elasticsearch/filtering/plugins/index.js +15 -0
  149. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  150. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  151. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +69 -0
  152. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  153. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  154. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +57 -0
  155. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  156. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  157. package/operations/entry/elasticsearch/filtering/populated.js +25 -0
  158. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  159. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  160. package/operations/entry/elasticsearch/filtering/values.js +24 -0
  161. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  162. package/operations/entry/elasticsearch/fullTextSearch.d.ts +12 -0
  163. package/operations/entry/elasticsearch/fullTextSearch.js +91 -0
  164. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  165. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  166. package/operations/entry/elasticsearch/fullTextSearchFields.js +27 -0
  167. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  168. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  169. package/operations/entry/elasticsearch/initialQuery.js +106 -0
  170. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  171. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  172. package/operations/entry/elasticsearch/keyword.js +36 -0
  173. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  174. package/operations/entry/elasticsearch/logIgnoredEsResponseError.d.ts +9 -0
  175. package/operations/entry/elasticsearch/logIgnoredEsResponseError.js +26 -0
  176. package/operations/entry/elasticsearch/logIgnoredEsResponseError.js.map +1 -0
  177. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
  178. package/operations/entry/elasticsearch/plugins/bodyModifier.js +18 -0
  179. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
  180. package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
  181. package/operations/entry/elasticsearch/plugins/operator.js +39 -0
  182. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  183. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
  184. package/operations/entry/elasticsearch/plugins/queryModifier.js +18 -0
  185. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
  186. package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
  187. package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +8 -8
  188. package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
  189. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
  190. package/operations/entry/elasticsearch/plugins/sortModifier.js +18 -0
  191. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
  192. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.d.ts +2 -0
  193. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +13 -0
  194. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -0
  195. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  196. package/operations/entry/elasticsearch/sort.js +89 -0
  197. package/operations/entry/elasticsearch/sort.js.map +1 -0
  198. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
  199. package/operations/entry/elasticsearch/transformValueForSearch.js +32 -0
  200. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  201. package/operations/entry/elasticsearch/types.d.ts +41 -0
  202. package/operations/entry/elasticsearch/types.js +7 -0
  203. package/operations/entry/elasticsearch/types.js.map +1 -0
  204. package/operations/entry/index.d.ts +4 -6
  205. package/operations/entry/index.js +1211 -596
  206. package/operations/entry/index.js.map +1 -1
  207. package/operations/entry/keys.js +2 -9
  208. package/operations/entry/keys.js.map +1 -1
  209. package/operations/entry/recordType.d.ts +3 -0
  210. package/operations/entry/recordType.js +20 -0
  211. package/operations/entry/recordType.js.map +1 -0
  212. package/operations/entry/transformations/convertEntryKeys.d.ts +8 -0
  213. package/operations/entry/transformations/convertEntryKeys.js +38 -0
  214. package/operations/entry/transformations/convertEntryKeys.js.map +1 -0
  215. package/operations/entry/transformations/index.d.ts +29 -0
  216. package/operations/entry/transformations/index.js +127 -0
  217. package/operations/entry/transformations/index.js.map +1 -0
  218. package/operations/entry/transformations/modifyEntryValues.d.ts +58 -0
  219. package/operations/entry/transformations/modifyEntryValues.js +28 -0
  220. package/operations/entry/transformations/modifyEntryValues.js.map +1 -0
  221. package/operations/entry/transformations/transformEntryKeys.d.ts +11 -0
  222. package/operations/entry/transformations/transformEntryKeys.js +27 -0
  223. package/operations/entry/transformations/transformEntryKeys.js.map +1 -0
  224. package/operations/entry/transformations/transformEntryToIndex.d.ts +10 -0
  225. package/operations/entry/transformations/transformEntryToIndex.js +31 -0
  226. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -0
  227. package/operations/group/index.d.ts +3 -3
  228. package/operations/group/index.js +38 -54
  229. package/operations/group/index.js.map +1 -1
  230. package/operations/model/index.d.ts +3 -3
  231. package/operations/model/index.js +26 -47
  232. package/operations/model/index.js.map +1 -1
  233. package/operations/system/index.d.ts +2 -2
  234. package/operations/system/index.js +18 -23
  235. package/operations/system/index.js.map +1 -1
  236. package/operations/system/indexes.d.ts +10 -0
  237. package/operations/system/indexes.js +41 -0
  238. package/operations/system/indexes.js.map +1 -0
  239. package/package.json +37 -34
  240. package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +69 -0
  241. package/plugins/CmsElasticsearchModelFieldPlugin.js +52 -0
  242. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -0
  243. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +4 -2
  244. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +8 -11
  245. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  246. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
  247. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +27 -0
  248. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
  249. package/plugins/CmsEntryElasticsearchIndexPlugin.js +5 -9
  250. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  251. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +3 -1
  252. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +12 -15
  253. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  254. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -2
  255. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +8 -11
  256. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  257. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -2
  258. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +8 -11
  259. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  260. package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +33 -0
  261. package/plugins/CmsEntryElasticsearchValuesModifier.js +50 -0
  262. package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -0
  263. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  264. package/plugins/CmsEntryFilterPlugin.js +22 -0
  265. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  266. package/plugins/index.d.ts +3 -1
  267. package/plugins/index.js +36 -24
  268. package/plugins/index.js.map +1 -1
  269. package/tasks/createIndexTaskPlugin.d.ts +2 -0
  270. package/tasks/createIndexTaskPlugin.js +67 -0
  271. package/tasks/createIndexTaskPlugin.js.map +1 -0
  272. package/types.d.ts +27 -22
  273. package/types.js +5 -10
  274. package/types.js.map +1 -1
  275. package/values/NoValueContainer.d.ts +5 -0
  276. package/values/NoValueContainer.js +20 -0
  277. package/values/NoValueContainer.js.map +1 -0
  278. package/definitions/settings.d.ts +0 -8
  279. package/definitions/settings.js +0 -58
  280. package/definitions/settings.js.map +0 -1
  281. package/dynamoDb/storage/date.d.ts +0 -2
  282. package/dynamoDb/storage/date.js +0 -99
  283. package/dynamoDb/storage/date.js.map +0 -1
  284. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  285. package/helpers/createElasticsearchQueryBody.js +0 -611
  286. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  287. package/helpers/fields.d.ts +0 -19
  288. package/helpers/fields.js +0 -205
  289. package/helpers/fields.js.map +0 -1
  290. package/helpers/searchPluginsList.d.ts +0 -6
  291. package/helpers/searchPluginsList.js.map +0 -1
  292. package/helpers/transformValueForSearch.d.ts +0 -12
  293. package/helpers/transformValueForSearch.js +0 -29
  294. package/helpers/transformValueForSearch.js.map +0 -1
  295. package/operations/entry/elasticsearchFields.d.ts +0 -2
  296. package/operations/entry/elasticsearchFields.js +0 -38
  297. package/operations/entry/elasticsearchFields.js.map +0 -1
  298. package/operations/settings/index.d.ts +0 -6
  299. package/operations/settings/index.js +0 -135
  300. package/operations/settings/index.js.map +0 -1
  301. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
  302. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -24
  303. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
@@ -1,365 +1,116 @@
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
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- var _dataloader = _interopRequireDefault(require("dataloader"));
15
-
16
8
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
- var _query = require("@webiny/db-dynamodb/utils/query");
19
-
20
- var _keys = require("./keys");
21
-
22
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
23
-
9
+ var _DataLoaderCache = require("./dataLoader/DataLoaderCache");
10
+ var _dataLoader = require("./dataLoader");
24
11
  var _utils = require("@webiny/utils");
25
-
26
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
27
-
28
- const getAllEntryRevisions = params => {
29
- const {
30
- entity,
31
- model
32
- } = params;
33
- const {
34
- tenant,
35
- locale
36
- } = model;
37
- return new _dataloader.default(async ids => {
38
- const results = {};
39
-
40
- for (const id of ids) {
41
- const queryAllParams = {
42
- entity,
43
- partitionKey: (0, _keys.createPartitionKey)({
44
- tenant,
45
- locale,
46
- id
47
- }),
48
- options: {
49
- beginsWith: "REV#"
50
- }
51
- };
52
- const items = await (0, _query.queryAll)(queryAllParams);
53
- results[id] = (0, _cleanup.cleanupItems)(entity, items);
54
- }
55
-
56
- return ids.map(id => {
57
- return results[id] || [];
58
- });
59
- });
60
- };
61
-
62
- const getRevisionById = params => {
63
- const {
64
- entity,
65
- model
66
- } = params;
67
- const {
68
- locale,
69
- tenant
70
- } = model;
71
- return new _dataloader.default(async ids => {
72
- const queries = ids.reduce((collection, id) => {
73
- const partitionKey = (0, _keys.createPartitionKey)({
74
- tenant,
75
- locale,
76
- id
77
- });
78
- const {
79
- version
80
- } = (0, _utils.parseIdentifier)(id);
81
-
82
- if (!version) {
83
- return collection;
84
- }
85
-
86
- const sortKey = (0, _keys.createRevisionSortKey)({
87
- version
88
- });
89
- const keys = `${partitionKey}__${sortKey}`;
90
-
91
- if (collection[keys]) {
92
- return collection;
93
- }
94
-
95
- collection[keys] = entity.getBatch({
96
- PK: partitionKey,
97
- SK: sortKey
98
- });
99
- return collection;
100
- /**
101
- * We use any because there is no type for the return type.
102
- */
103
- }, {});
104
- const records = await (0, _batchRead.batchReadAll)({
105
- table: entity.table,
106
- items: Object.values(queries)
107
- });
108
- const items = (0, _cleanup.cleanupItems)(entity, records);
109
- return ids.map(id => {
110
- return items.filter(item => {
111
- return id === item.id;
112
- });
113
- });
114
- });
115
- };
116
-
117
- const getPublishedRevisionByEntryId = params => {
118
- const {
119
- entity,
120
- model
121
- } = params;
122
- const {
123
- locale,
124
- tenant
125
- } = model;
126
- const publishedKey = (0, _keys.createPublishedSortKey)();
127
- return new _dataloader.default(async ids => {
128
- const queries = ids.reduce((collection, id) => {
129
- const partitionKey = (0, _keys.createPartitionKey)({
130
- tenant,
131
- locale,
132
- id
133
- });
134
-
135
- if (collection[partitionKey]) {
136
- return collection;
137
- }
138
-
139
- collection[partitionKey] = entity.getBatch({
140
- PK: partitionKey,
141
- SK: publishedKey
142
- });
143
- return collection;
144
- /**
145
- * We use any because there is no type for the return type.
146
- */
147
- }, {});
148
- const records = await (0, _batchRead.batchReadAll)({
149
- table: entity.table,
150
- items: Object.values(queries)
151
- });
152
- const items = (0, _cleanup.cleanupItems)(entity, records);
153
- return ids.map(id => {
154
- const {
155
- id: entryId
156
- } = (0, _utils.parseIdentifier)(id);
157
- return items.filter(item => {
158
- return entryId === item.entryId;
159
- });
160
- });
161
- });
162
- };
163
-
164
- const getLatestRevisionByEntryId = params => {
165
- const {
166
- entity,
167
- model
168
- } = params;
169
- const {
170
- locale,
171
- tenant
172
- } = model;
173
- const latestKey = (0, _keys.createLatestSortKey)();
174
- return new _dataloader.default(async ids => {
175
- const queries = ids.reduce((collection, id) => {
176
- const partitionKey = (0, _keys.createPartitionKey)({
177
- tenant,
178
- locale,
179
- id
180
- });
181
-
182
- if (collection[partitionKey]) {
183
- return collection;
184
- }
185
-
186
- collection[partitionKey] = entity.getBatch({
187
- PK: partitionKey,
188
- SK: latestKey
189
- });
190
- return collection;
191
- /**
192
- * We use any because there is no type for the return type.
193
- */
194
- }, {});
195
- const records = await (0, _batchRead.batchReadAll)({
196
- table: entity.table,
197
- items: Object.values(queries)
198
- });
199
- const items = (0, _cleanup.cleanupItems)(entity, records);
200
- return ids.map(id => {
201
- const {
202
- id: entryId
203
- } = (0, _utils.parseIdentifier)(id);
204
- return items.filter(item => {
205
- return entryId === item.entryId;
206
- });
207
- });
208
- });
209
- };
210
-
211
- const dataLoaders = {
212
- getAllEntryRevisions,
213
- getRevisionById,
214
- getPublishedRevisionByEntryId,
215
- getLatestRevisionByEntryId
216
- };
217
- const loaderNames = Object.keys(dataLoaders);
218
-
219
12
  class DataLoadersHandler {
13
+ cache = new _DataLoaderCache.DataLoaderCache();
220
14
  constructor(params) {
221
- (0, _defineProperty2.default)(this, "loaders", new Map());
222
- (0, _defineProperty2.default)(this, "entity", void 0);
223
15
  this.entity = params.entity;
224
16
  }
225
-
226
17
  async getAllEntryRevisions(params) {
227
- return await this.loadMany("getAllEntryRevisions", params, params.ids);
228
- }
229
-
230
- clearAllEntryRevisions(params) {
231
- this.clear("getAllEntryRevisions", params);
18
+ const ids = params.ids.map(id => {
19
+ const {
20
+ id: entryId
21
+ } = (0, _utils.parseIdentifier)(id);
22
+ return entryId;
23
+ });
24
+ return await this.loadMany("getAllEntryRevisions", params, ids);
232
25
  }
233
-
234
26
  async getRevisionById(params) {
235
27
  return await this.loadMany("getRevisionById", params, params.ids);
236
28
  }
237
-
238
- clearRevisionById(params) {
239
- this.clear("getRevisionById", params);
240
- }
241
-
242
29
  async getPublishedRevisionByEntryId(params) {
243
- return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
244
- }
245
-
246
- clearPublishedRevisionByEntryId(params) {
247
- this.clear("getPublishedRevisionByEntryId", params);
30
+ const ids = params.ids.map(id => {
31
+ const {
32
+ id: entryId
33
+ } = (0, _utils.parseIdentifier)(id);
34
+ return entryId;
35
+ });
36
+ return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
248
37
  }
249
-
250
38
  async getLatestRevisionByEntryId(params) {
251
- return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
39
+ const ids = params.ids.map(id => {
40
+ const {
41
+ id: entryId
42
+ } = (0, _utils.parseIdentifier)(id);
43
+ return entryId;
44
+ });
45
+ return await this.loadMany("getLatestRevisionByEntryId", params, ids);
252
46
  }
253
47
 
254
- clearLatestRevisionByEntryId(params) {
255
- this.clear("getLatestRevisionByEntryId", params);
256
- }
257
48
  /**
258
49
  * TODO @ts-refactor
259
50
  * Maybe pass on the generics to DataLoader definition?
260
51
  */
261
-
262
-
263
52
  getLoader(name, params) {
264
- if (!dataLoaders[name]) {
265
- throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
266
- name
267
- });
268
- }
269
-
270
53
  const {
271
54
  model
272
55
  } = params;
273
- const {
274
- tenant,
275
- locale
276
- } = model;
277
- const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
278
-
279
- if (!this.loaders.has(loaderKey)) {
280
- this.loaders.set(loaderKey, dataLoaders[name]((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
281
- entity: this.entity
282
- })));
56
+ const cacheParams = {
57
+ tenant: model.tenant,
58
+ locale: model.locale,
59
+ name
60
+ };
61
+ let loader = this.cache.getDataLoader(cacheParams);
62
+ if (loader) {
63
+ return loader;
283
64
  }
284
-
285
- return this.loaders.get(loaderKey);
65
+ const factory = (0, _dataLoader.getDataLoaderFactory)(name);
66
+ loader = factory({
67
+ entity: this.entity,
68
+ tenant: model.tenant,
69
+ locale: model.locale
70
+ });
71
+ this.cache.setDataLoader(cacheParams, loader);
72
+ return loader;
286
73
  }
287
-
288
74
  async loadMany(loader, params, ids) {
289
- let results;
290
-
75
+ let results = [];
291
76
  try {
292
77
  results = await this.getLoader(loader, params).loadMany(ids);
293
-
294
78
  if (Array.isArray(results) === true) {
295
79
  return results.reduce((acc, res) => {
296
80
  if (Array.isArray(res) === false) {
297
81
  if (res && res.message) {
298
- throw new _error.default(res.message, res.code, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, res), {}, {
82
+ throw new _error.default(res.message, res.code, {
83
+ ...res,
299
84
  data: JSON.stringify(res.data || {})
300
- }));
85
+ });
301
86
  }
302
-
303
- 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), {}, {
87
+ throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
88
+ ...params,
304
89
  loader
305
- }));
90
+ });
306
91
  }
307
-
308
92
  acc.push(...res);
309
93
  return acc;
310
94
  }, []);
311
95
  }
312
96
  } catch (ex) {
313
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
314
- error: ex
315
- }, params), {}, {
97
+ throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
98
+ error: ex,
99
+ ...params,
316
100
  loader,
317
101
  ids
318
- }));
102
+ });
319
103
  }
320
-
321
104
  throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
322
105
  loader,
323
106
  ids,
324
107
  results
325
108
  });
326
109
  }
327
-
328
110
  clearAll(params) {
329
- for (const name of loaderNames) {
330
- const loader = this.getLoader(name, params);
331
- loader.clearAll();
332
- }
111
+ this.cache.clearAll(params?.model);
333
112
  }
334
- /**
335
- * Helper to clear the cache for certain data loader.
336
- * If entry is passed then clear target key only.
337
- */
338
-
339
-
340
- clear(name, params) {
341
- const {
342
- entry
343
- } = params;
344
- const loader = this.getLoader(name, params);
345
-
346
- if (!entry) {
347
- loader.clearAll();
348
- return;
349
- }
350
-
351
- loader.clear(entry.id);
352
- const {
353
- tenant,
354
- locale
355
- } = params.model;
356
- loader.clear((0, _keys.createPartitionKey)({
357
- tenant,
358
- locale,
359
- id: entry.id
360
- }));
361
- }
362
-
363
113
  }
114
+ exports.DataLoadersHandler = DataLoadersHandler;
364
115
 
365
- exports.DataLoadersHandler = DataLoadersHandler;
116
+ //# sourceMappingURL=dataLoaders.js.map
@@ -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;EAC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":["_error","_interopRequireDefault","require","_DataLoaderCache","_dataLoader","_utils","DataLoadersHandler","cache","DataLoaderCache","constructor","params","entity","getAllEntryRevisions","ids","map","id","entryId","parseIdentifier","loadMany","getRevisionById","getPublishedRevisionByEntryId","getLatestRevisionByEntryId","getLoader","name","model","cacheParams","tenant","locale","loader","getDataLoader","factory","getDataLoaderFactory","setDataLoader","results","Array","isArray","reduce","acc","res","message","WebinyError","code","data","JSON","stringify","push","ex","error","clearAll","exports"],"sources":["dataLoaders.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport type { CmsModel, CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport type { CacheKeyParams } from \"~/operations/entry/dataLoader/DataLoaderCache\";\nimport { DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport type { DataLoaders } from \"~/operations/entry/dataLoader\";\nimport { getDataLoaderFactory } from \"~/operations/entry/dataLoader\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type {\n DataLoadersHandlerInterface,\n DataLoadersHandlerInterfaceClearAllParams\n} from \"~/types\";\n\ninterface DataLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"locale\" | \"modelId\">;\n ids: readonly string[];\n}\n\ninterface GetLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"locale\" | \"modelId\">;\n}\n\ninterface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\n\nexport interface ClearAllParams {\n model: Pick<CmsModel, \"tenant\" | \"locale\" | \"modelId\">;\n}\n\nexport class DataLoadersHandler implements DataLoadersHandlerInterface {\n private readonly entity: Entity<any>;\n private readonly cache: DataLoaderCache = new DataLoaderCache();\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(params: DataLoaderParams): Promise<CmsStorageEntry[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany(\"getAllEntryRevisions\", params, ids);\n }\n\n public async getRevisionById(params: DataLoaderParams): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, ids);\n }\n\n public async getLatestRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: DataLoaders, params: GetLoaderParams): DataLoader<any, any> {\n const { model } = params;\n const cacheParams: CacheKeyParams = {\n tenant: model.tenant,\n locale: model.locale,\n name\n };\n let loader = this.cache.getDataLoader(cacheParams);\n if (loader) {\n return loader;\n }\n const factory = getDataLoaderFactory(name);\n loader = factory({\n entity: this.entity,\n tenant: model.tenant,\n locale: model.locale\n });\n this.cache.setDataLoader(cacheParams, loader);\n return loader;\n }\n\n private async loadMany(\n loader: DataLoaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry[]> {\n let results: any[] = [];\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?: DataLoadersHandlerInterfaceClearAllParams): void {\n this.cache.clearAll(params?.model);\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,gBAAA,GAAAD,OAAA;AAGA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAuBO,MAAMI,kBAAkB,CAAwC;EAElDC,KAAK,GAAoB,IAAIC,gCAAe,CAAC,CAAC;EAExDC,WAAWA,CAACC,MAAgC,EAAE;IACjD,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;EAEA,MAAaC,oBAAoBA,CAACF,MAAwB,EAA8B;IACpF,MAAMG,GAAG,GAAGH,MAAM,CAACG,GAAG,CAACC,GAAG,CAACC,EAAE,IAAI;MAC7B,MAAM;QAAEA,EAAE,EAAEC;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACF,EAAE,CAAC;MAC3C,OAAOC,OAAO;IAClB,CAAC,CAAC;IACF,OAAO,MAAM,IAAI,CAACE,QAAQ,CAAC,sBAAsB,EAAER,MAAM,EAAEG,GAAG,CAAC;EACnE;EAEA,MAAaM,eAAeA,CAACT,MAAwB,EAA8B;IAC/E,OAAO,MAAM,IAAI,CAACQ,QAAQ,CAAC,iBAAiB,EAAER,MAAM,EAAEA,MAAM,CAACG,GAAG,CAAC;EACrE;EAEA,MAAaO,6BAA6BA,CACtCV,MAAwB,EACE;IAC1B,MAAMG,GAAG,GAAGH,MAAM,CAACG,GAAG,CAACC,GAAG,CAACC,EAAE,IAAI;MAC7B,MAAM;QAAEA,EAAE,EAAEC;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACF,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AQ,CAACtC,MAAM,EAAEc,KAAK,CAAC;EACtC;AACJ;AAACyB,OAAA,CAAA3C,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ import type { 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,34 @@
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;
33
+
34
+ //# sourceMappingURL=assignMinimumShouldMatchToQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["assignMinimumShouldMatchToQuery","query","value","Array","isArray","should","length","minimum_should_match","exports"],"sources":["assignMinimumShouldMatchToQuery.ts"],"sourcesContent":["import type { 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,GAAGA,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;AAACM,OAAA,CAAAR,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { PluginsContainer } from "@webiny/plugins";
2
+ import type { CmsEntryListParams, CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types";
3
+ import type { 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 {};