@webiny/api-headless-cms-ddb-es 6.0.0-beta.0 → 6.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/README.md +6 -30
  2. package/configurations.d.ts +4 -5
  3. package/configurations.js +12 -24
  4. package/configurations.js.map +1 -1
  5. package/definitions/entry.d.ts +4 -5
  6. package/definitions/entry.js +5 -174
  7. package/definitions/entry.js.map +1 -1
  8. package/definitions/group.d.ts +6 -6
  9. package/definitions/group.js +5 -58
  10. package/definitions/group.js.map +1 -1
  11. package/definitions/model.d.ts +6 -6
  12. package/definitions/model.js +5 -102
  13. package/definitions/model.js.map +1 -1
  14. package/definitions/types.d.ts +59 -0
  15. package/definitions/types.js +3 -0
  16. package/definitions/types.js.map +1 -0
  17. package/dynamoDb/index.d.ts +2 -2
  18. package/dynamoDb/index.js +5 -14
  19. package/dynamoDb/index.js.map +1 -1
  20. package/dynamoDb/storage/longText.js +11 -18
  21. package/dynamoDb/storage/longText.js.map +1 -1
  22. package/dynamoDb/storage/richText.d.ts +0 -5
  23. package/dynamoDb/storage/richText.js +25 -80
  24. package/dynamoDb/storage/richText.js.map +1 -1
  25. package/elasticsearch/createElasticsearchIndex.d.ts +3 -3
  26. package/elasticsearch/createElasticsearchIndex.js +7 -15
  27. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  28. package/elasticsearch/deleteElasticsearchIndex.d.ts +2 -2
  29. package/elasticsearch/deleteElasticsearchIndex.js +3 -10
  30. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  31. package/elasticsearch/index.d.ts +1 -1
  32. package/elasticsearch/index.js +3 -11
  33. package/elasticsearch/index.js.map +1 -1
  34. package/elasticsearch/indexing/dateTimeIndexing.d.ts +1 -1
  35. package/elasticsearch/indexing/dateTimeIndexing.js +1 -8
  36. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  37. package/elasticsearch/indexing/defaultFieldIndexing.d.ts +1 -1
  38. package/elasticsearch/indexing/defaultFieldIndexing.js +1 -8
  39. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  40. package/elasticsearch/indexing/index.d.ts +1 -1
  41. package/elasticsearch/indexing/index.js +8 -16
  42. package/elasticsearch/indexing/index.js.map +1 -1
  43. package/elasticsearch/indexing/jsonIndexing.d.ts +1 -1
  44. package/elasticsearch/indexing/jsonIndexing.js +1 -8
  45. package/elasticsearch/indexing/jsonIndexing.js.map +1 -1
  46. package/elasticsearch/indexing/longTextIndexing.d.ts +1 -1
  47. package/elasticsearch/indexing/longTextIndexing.js +1 -8
  48. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  49. package/elasticsearch/indexing/numberIndexing.d.ts +1 -1
  50. package/elasticsearch/indexing/numberIndexing.js +1 -8
  51. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  52. package/elasticsearch/indexing/objectIndexing.d.ts +1 -1
  53. package/elasticsearch/indexing/objectIndexing.js +6 -13
  54. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  55. package/elasticsearch/indexing/richTextIndexing.d.ts +1 -1
  56. package/elasticsearch/indexing/richTextIndexing.js +1 -8
  57. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  58. package/elasticsearch/indices/base.d.ts +1 -1
  59. package/elasticsearch/indices/base.js +4 -10
  60. package/elasticsearch/indices/base.js.map +1 -1
  61. package/elasticsearch/indices/index.d.ts +1 -1
  62. package/elasticsearch/indices/index.js +3 -11
  63. package/elasticsearch/indices/index.js.map +1 -1
  64. package/elasticsearch/search/index.d.ts +1 -1
  65. package/elasticsearch/search/index.js +4 -10
  66. package/elasticsearch/search/index.js.map +1 -1
  67. package/elasticsearch/search/refSearch.d.ts +1 -1
  68. package/elasticsearch/search/refSearch.js +3 -10
  69. package/elasticsearch/search/refSearch.js.map +1 -1
  70. package/elasticsearch/search/searchableJson.d.ts +2 -0
  71. package/elasticsearch/search/searchableJson.js +53 -0
  72. package/elasticsearch/search/searchableJson.js.map +1 -0
  73. package/elasticsearch/search/timeSearch.d.ts +1 -1
  74. package/elasticsearch/search/timeSearch.js +3 -10
  75. package/elasticsearch/search/timeSearch.js.map +1 -1
  76. package/helpers/entryIndexHelpers.d.ts +10 -10
  77. package/helpers/entryIndexHelpers.js +32 -26
  78. package/helpers/entryIndexHelpers.js.map +1 -1
  79. package/helpers/fieldIdentifier.d.ts +1 -1
  80. package/helpers/fieldIdentifier.js +2 -10
  81. package/helpers/fieldIdentifier.js.map +1 -1
  82. package/helpers/index.d.ts +2 -2
  83. package/helpers/index.js +2 -27
  84. package/helpers/index.js.map +1 -1
  85. package/index.d.ts +2 -2
  86. package/index.js +108 -134
  87. package/index.js.map +1 -1
  88. package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -3
  89. package/operations/entry/dataLoader/DataLoaderCache.js +2 -9
  90. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  91. package/operations/entry/dataLoader/constants.js +1 -7
  92. package/operations/entry/dataLoader/constants.js.map +1 -1
  93. package/operations/entry/dataLoader/createBatchScheduleFn.js +4 -10
  94. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  95. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
  96. package/operations/entry/dataLoader/getAllEntryRevisions.js +11 -24
  97. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  98. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
  99. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +18 -30
  100. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  101. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
  102. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +18 -30
  103. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  104. package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
  105. package/operations/entry/dataLoader/getRevisionById.js +23 -35
  106. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  107. package/operations/entry/dataLoader/index.d.ts +5 -5
  108. package/operations/entry/dataLoader/index.js +10 -31
  109. package/operations/entry/dataLoader/index.js.map +1 -1
  110. package/operations/entry/dataLoader/types.d.ts +3 -4
  111. package/operations/entry/dataLoader/types.js +1 -5
  112. package/operations/entry/dataLoader/types.js.map +1 -1
  113. package/operations/entry/dataLoaders.d.ts +13 -13
  114. package/operations/entry/dataLoaders.js +15 -25
  115. package/operations/entry/dataLoaders.js.map +1 -1
  116. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +1 -1
  117. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +1 -8
  118. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
  119. package/operations/entry/elasticsearch/body.d.ts +3 -3
  120. package/operations/entry/elasticsearch/body.js +21 -28
  121. package/operations/entry/elasticsearch/body.js.map +1 -1
  122. package/operations/entry/elasticsearch/fields.d.ts +3 -3
  123. package/operations/entry/elasticsearch/fields.js +110 -24
  124. package/operations/entry/elasticsearch/fields.js.map +1 -1
  125. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +2 -2
  126. package/operations/entry/elasticsearch/filtering/applyFiltering.js +10 -17
  127. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  128. package/operations/entry/elasticsearch/filtering/exec.d.ts +7 -6
  129. package/operations/entry/elasticsearch/filtering/exec.js +48 -45
  130. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  131. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -1
  132. package/operations/entry/elasticsearch/filtering/index.js +1 -16
  133. package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
  134. package/operations/entry/elasticsearch/filtering/path.d.ts +2 -1
  135. package/operations/entry/elasticsearch/filtering/path.js +9 -17
  136. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  137. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +1 -1
  138. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +6 -14
  139. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
  140. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -1
  141. package/operations/entry/elasticsearch/filtering/plugins/index.js +5 -12
  142. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -1
  143. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +1 -1
  144. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +7 -15
  145. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -1
  146. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +1 -1
  147. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +15 -16
  148. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -1
  149. package/operations/entry/elasticsearch/filtering/populated.d.ts +1 -1
  150. package/operations/entry/elasticsearch/filtering/populated.js +1 -8
  151. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  152. package/operations/entry/elasticsearch/filtering/values.d.ts +1 -1
  153. package/operations/entry/elasticsearch/filtering/values.js +4 -12
  154. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  155. package/operations/entry/elasticsearch/fullTextSearch.d.ts +3 -3
  156. package/operations/entry/elasticsearch/fullTextSearch.js +6 -12
  157. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  158. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +1 -1
  159. package/operations/entry/elasticsearch/fullTextSearchFields.js +1 -8
  160. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  161. package/operations/entry/elasticsearch/initialQuery.d.ts +2 -2
  162. package/operations/entry/elasticsearch/initialQuery.js +9 -26
  163. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  164. package/operations/entry/elasticsearch/keyword.d.ts +1 -1
  165. package/operations/entry/elasticsearch/keyword.js +4 -9
  166. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  167. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +4 -4
  168. package/operations/entry/elasticsearch/plugins/bodyModifier.js +3 -10
  169. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
  170. package/operations/entry/elasticsearch/plugins/operator.d.ts +2 -3
  171. package/operations/entry/elasticsearch/plugins/operator.js +4 -19
  172. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  173. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +4 -4
  174. package/operations/entry/elasticsearch/plugins/queryModifier.js +3 -10
  175. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
  176. package/operations/entry/elasticsearch/plugins/search.d.ts +2 -2
  177. package/operations/entry/elasticsearch/plugins/search.js +5 -13
  178. package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
  179. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +4 -4
  180. package/operations/entry/elasticsearch/plugins/sortModifier.js +3 -10
  181. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
  182. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.d.ts +2 -0
  183. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +6 -0
  184. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -0
  185. package/operations/entry/elasticsearch/sort.d.ts +4 -4
  186. package/operations/entry/elasticsearch/sort.js +57 -33
  187. package/operations/entry/elasticsearch/sort.js.map +1 -1
  188. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +2 -2
  189. package/operations/entry/elasticsearch/transformValueForSearch.js +4 -9
  190. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  191. package/operations/entry/elasticsearch/types.d.ts +5 -5
  192. package/operations/entry/elasticsearch/types.js +1 -5
  193. package/operations/entry/elasticsearch/types.js.map +1 -1
  194. package/operations/entry/index.d.ts +7 -6
  195. package/operations/entry/index.js +634 -735
  196. package/operations/entry/index.js.map +1 -1
  197. package/operations/entry/keys.d.ts +31 -1
  198. package/operations/entry/keys.js +56 -19
  199. package/operations/entry/keys.js.map +1 -1
  200. package/operations/entry/recordType.js +3 -12
  201. package/operations/entry/recordType.js.map +1 -1
  202. package/operations/entry/transformations/convertEntryKeys.d.ts +6 -6
  203. package/operations/entry/transformations/convertEntryKeys.js +2 -10
  204. package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
  205. package/operations/entry/transformations/index.d.ts +17 -17
  206. package/operations/entry/transformations/index.js +22 -30
  207. package/operations/entry/transformations/index.js.map +1 -1
  208. package/operations/entry/transformations/modifyEntryValues.d.ts +27 -34
  209. package/operations/entry/transformations/modifyEntryValues.js +1 -8
  210. package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
  211. package/operations/entry/transformations/transformEntryKeys.d.ts +8 -8
  212. package/operations/entry/transformations/transformEntryKeys.js +4 -11
  213. package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
  214. package/operations/entry/transformations/transformEntryToIndex.d.ts +7 -7
  215. package/operations/entry/transformations/transformEntryToIndex.js +3 -10
  216. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
  217. package/operations/group/index.d.ts +6 -5
  218. package/operations/group/index.js +39 -73
  219. package/operations/group/index.js.map +1 -1
  220. package/operations/model/index.d.ts +4 -4
  221. package/operations/model/index.js +38 -57
  222. package/operations/model/index.js.map +1 -1
  223. package/package.json +29 -41
  224. package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +1 -1
  225. package/plugins/CmsElasticsearchModelFieldPlugin.js +2 -8
  226. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -1
  227. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +3 -2
  228. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +3 -11
  229. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  230. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +2 -2
  231. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +3 -11
  232. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -1
  233. package/plugins/CmsEntryElasticsearchIndexPlugin.js +2 -9
  234. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  235. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +3 -2
  236. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +3 -11
  237. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  238. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +3 -2
  239. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +3 -11
  240. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  241. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +3 -2
  242. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +3 -11
  243. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  244. package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +12 -12
  245. package/plugins/CmsEntryElasticsearchValuesModifier.js +4 -12
  246. package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -1
  247. package/plugins/CmsEntryFilterPlugin.d.ts +3 -3
  248. package/plugins/CmsEntryFilterPlugin.js +2 -9
  249. package/plugins/CmsEntryFilterPlugin.js.map +1 -1
  250. package/plugins/index.d.ts +8 -8
  251. package/plugins/index.js +8 -93
  252. package/plugins/index.js.map +1 -1
  253. package/tasks/createIndexTaskPlugin.d.ts +2 -2
  254. package/tasks/createIndexTaskPlugin.js +36 -62
  255. package/tasks/createIndexTaskPlugin.js.map +1 -1
  256. package/types.d.ts +28 -33
  257. package/types.js +5 -8
  258. package/types.js.map +1 -1
  259. package/values/NoValueContainer.d.ts +5 -0
  260. package/values/NoValueContainer.js +13 -0
  261. package/values/NoValueContainer.js.map +1 -0
  262. package/definitions/entryElasticsearch.d.ts +0 -8
  263. package/definitions/entryElasticsearch.js +0 -38
  264. package/definitions/entryElasticsearch.js.map +0 -1
  265. package/definitions/system.d.ts +0 -8
  266. package/definitions/system.js +0 -42
  267. package/definitions/system.js.map +0 -1
  268. package/definitions/table.d.ts +0 -8
  269. package/definitions/table.js +0 -25
  270. package/definitions/table.js.map +0 -1
  271. package/definitions/tableElasticsearch.d.ts +0 -8
  272. package/definitions/tableElasticsearch.js +0 -25
  273. package/definitions/tableElasticsearch.js.map +0 -1
  274. package/dynamoDb/storage/date.d.ts +0 -3
  275. package/dynamoDb/storage/date.js +0 -84
  276. package/dynamoDb/storage/date.js.map +0 -1
  277. package/elasticsearch/indices/japanese.d.ts +0 -2
  278. package/elasticsearch/indices/japanese.js +0 -14
  279. package/elasticsearch/indices/japanese.js.map +0 -1
  280. package/operations/system/index.d.ts +0 -6
  281. package/operations/system/index.js +0 -94
  282. package/operations/system/index.js.map +0 -1
  283. package/operations/system/indexes.d.ts +0 -10
  284. package/operations/system/indexes.js +0 -41
  285. package/operations/system/indexes.js.map +0 -1
@@ -1,52 +1,40 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGetLatestRevisionByEntryId = void 0;
8
- var _dataloader = _interopRequireDefault(require("dataloader"));
9
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
10
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
- var _createBatchScheduleFn = require("./createBatchScheduleFn");
12
- var _keys = require("../keys");
13
- const createGetLatestRevisionByEntryId = params => {
1
+ import DataLoader from "dataloader";
2
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
3
+ import { createLatestSortKey, createPartitionKey } from "../keys.js";
4
+ export const createGetLatestRevisionByEntryId = params => {
14
5
  const {
15
6
  entity,
16
- locale,
17
7
  tenant
18
8
  } = params;
19
- const latestKey = (0, _keys.createLatestSortKey)();
20
- return new _dataloader.default(async ids => {
21
- const queries = ids.reduce((collection, id) => {
22
- const partitionKey = (0, _keys.createPartitionKey)({
9
+ const latestKey = createLatestSortKey();
10
+ return new DataLoader(async ids => {
11
+ const reader = entity.createEntityReader();
12
+ const keys = new Set();
13
+ for (const id of ids) {
14
+ const partitionKey = createPartitionKey({
23
15
  tenant,
24
- locale,
25
16
  id
26
17
  });
27
- if (collection[partitionKey]) {
28
- return collection;
18
+ if (keys.has(partitionKey)) {
19
+ continue;
29
20
  }
30
- collection[partitionKey] = entity.getBatch({
21
+ keys.add(partitionKey);
22
+ reader.get({
31
23
  PK: partitionKey,
32
24
  SK: latestKey
33
25
  });
34
- return collection;
35
- }, {});
36
- const records = await (0, _batchRead.batchReadAll)({
37
- table: entity.table,
38
- items: Object.values(queries)
26
+ }
27
+ const items = (await reader.execute()).map(item => {
28
+ return item.data;
39
29
  });
40
- const items = (0, _cleanup.cleanupItems)(entity, records);
41
30
  return ids.map(entryId => {
42
31
  return items.filter(item => {
43
32
  return entryId === item.entryId;
44
33
  });
45
34
  });
46
35
  }, {
47
- batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
36
+ batchScheduleFn: createBatchScheduleFn()
48
37
  });
49
38
  };
50
- exports.createGetLatestRevisionByEntryId = createGetLatestRevisionByEntryId;
51
39
 
52
40
  //# sourceMappingURL=getLatestRevisionByEntryId.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_dataloader","_interopRequireDefault","require","_batchRead","_cleanup","_createBatchScheduleFn","_keys","createGetLatestRevisionByEntryId","params","entity","locale","tenant","latestKey","createLatestSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\nimport { createLatestSortKey, createPartitionKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\n\nexport const createGetLatestRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, ReturnType<typeof entity.getBatch>>>(\n (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 {}\n );\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(entryId => {\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAGO,MAAMK,gCAAgC,GAAIC,MAAwB,IAAK;EAC1E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,SAAS,GAAG,IAAAC,yBAAmB,EAAC,CAAC;EAEvC,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CACtB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChB,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCV,MAAM;QACND,MAAM;QACNS;MACJ,CAAC,CAAC;MACF,IAAID,UAAU,CAACE,YAAY,CAAC,EAAE;QAC1B,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,YAAY,CAAC,GAAGX,MAAM,CAACa,QAAQ,CAAC;QACvCC,EAAE,EAAEH,YAAY;QAChBI,EAAE,EAAEZ;MACR,CAAC,CAAC;MACF,OAAOM,UAAU;IACrB,CAAC,EACD,CAAC,CACL,CAAC;IAED,MAAMO,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAElB,MAAM,CAACkB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACd,OAAO;IAChC,CAAC,CAAC;IACF,MAAMY,KAAK,GAAG,IAAAG,qBAAY,EAACtB,MAAM,EAAEgB,OAAO,CAAC;IAE3C,OAAOV,GAAG,CAACiB,GAAG,CAACC,OAAO,IAAI;MACtB,OAAOL,KAAK,CAACM,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOF,OAAO,KAAKE,IAAI,CAACF,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIG,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAA/B,gCAAA,GAAAA,gCAAA","ignoreList":[]}
1
+ {"version":3,"names":["DataLoader","createBatchScheduleFn","createLatestSortKey","createPartitionKey","createGetLatestRevisionByEntryId","params","entity","tenant","latestKey","ids","reader","createEntityReader","keys","Set","id","partitionKey","has","add","get","PK","SK","items","execute","map","item","data","entryId","filter","batchScheduleFn"],"sources":["getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\nimport { createLatestSortKey, createPartitionKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\n\nexport const createGetLatestRevisionByEntryId = (params: IDataLoaderParams) => {\n const { entity, tenant } = params;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n if (keys.has(partitionKey)) {\n continue;\n }\n keys.add(partitionKey);\n reader.get({\n PK: partitionKey,\n SK: latestKey\n });\n }\n\n const items = (await reader.execute()).map(item => {\n return item.data;\n });\n\n return ids.map(entryId => {\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,YAAY;AAEnC,SAASC,qBAAqB;AAC9B,SAASC,mBAAmB,EAAEC,kBAAkB;AAGhD,OAAO,MAAMC,gCAAgC,GAAIC,MAAyB,IAAK;EAC3E,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEjC,MAAMG,SAAS,GAAGN,mBAAmB,CAAC,CAAC;EAEvC,OAAO,IAAIF,UAAU,CACjB,MAAMS,GAAG,IAAI;IACT,MAAMC,MAAM,GAAGJ,MAAM,CAACK,kBAAkB,CAAC,CAAC;IAE1C,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAS,CAAC;IAE9B,KAAK,MAAMC,EAAE,IAAIL,GAAG,EAAE;MAClB,MAAMM,YAAY,GAAGZ,kBAAkB,CAAC;QACpCI,MAAM;QACNO;MACJ,CAAC,CAAC;MACF,IAAIF,IAAI,CAACI,GAAG,CAACD,YAAY,CAAC,EAAE;QACxB;MACJ;MACAH,IAAI,CAACK,GAAG,CAACF,YAAY,CAAC;MACtBL,MAAM,CAACQ,GAAG,CAAC;QACPC,EAAE,EAAEJ,YAAY;QAChBK,EAAE,EAAEZ;MACR,CAAC,CAAC;IACN;IAEA,MAAMa,KAAK,GAAG,CAAC,MAAMX,MAAM,CAACY,OAAO,CAAC,CAAC,EAAEC,GAAG,CAACC,IAAI,IAAI;MAC/C,OAAOA,IAAI,CAACC,IAAI;IACpB,CAAC,CAAC;IAEF,OAAOhB,GAAG,CAACc,GAAG,CAACG,OAAO,IAAI;MACtB,OAAOL,KAAK,CAACM,MAAM,CAACH,IAAI,IAAI;QACxB,OAAOE,OAAO,KAAKF,IAAI,CAACE,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIE,eAAe,EAAE3B,qBAAqB,CAAC;EAC3C,CACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  import DataLoader from "dataloader";
2
- import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
- import { DataLoaderParams } from "./types";
4
- export declare const createGetPublishedRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
3
+ import type { IDataLoaderParams } from "./types.js";
4
+ export declare const createGetPublishedRevisionByEntryId: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
@@ -1,52 +1,40 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGetPublishedRevisionByEntryId = void 0;
8
- var _dataloader = _interopRequireDefault(require("dataloader"));
9
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
10
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
- var _keys = require("../keys");
12
- var _createBatchScheduleFn = require("./createBatchScheduleFn");
13
- const createGetPublishedRevisionByEntryId = params => {
1
+ import DataLoader from "dataloader";
2
+ import { createPartitionKey, createPublishedSortKey } from "../keys.js";
3
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
4
+ export const createGetPublishedRevisionByEntryId = params => {
14
5
  const {
15
6
  entity,
16
- locale,
17
7
  tenant
18
8
  } = params;
19
- const publishedKey = (0, _keys.createPublishedSortKey)();
20
- return new _dataloader.default(async ids => {
21
- const queries = ids.reduce((collection, id) => {
22
- const partitionKey = (0, _keys.createPartitionKey)({
9
+ const publishedKey = createPublishedSortKey();
10
+ return new DataLoader(async ids => {
11
+ const reader = entity.createEntityReader();
12
+ const keys = new Set();
13
+ for (const id of ids) {
14
+ const partitionKey = createPartitionKey({
23
15
  tenant,
24
- locale,
25
16
  id
26
17
  });
27
- if (collection[partitionKey]) {
28
- return collection;
18
+ if (keys.has(partitionKey)) {
19
+ continue;
29
20
  }
30
- collection[partitionKey] = entity.getBatch({
21
+ keys.add(partitionKey);
22
+ reader.get({
31
23
  PK: partitionKey,
32
24
  SK: publishedKey
33
25
  });
34
- return collection;
35
- }, {});
36
- const records = await (0, _batchRead.batchReadAll)({
37
- table: entity.table,
38
- items: Object.values(queries)
26
+ }
27
+ const items = (await reader.execute()).map(item => {
28
+ return item.data;
39
29
  });
40
- const items = (0, _cleanup.cleanupItems)(entity, records);
41
30
  return ids.map(entryId => {
42
31
  return items.filter(item => {
43
32
  return entryId === item.entryId;
44
33
  });
45
34
  });
46
35
  }, {
47
- batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
36
+ batchScheduleFn: createBatchScheduleFn()
48
37
  });
49
38
  };
50
- exports.createGetPublishedRevisionByEntryId = createGetPublishedRevisionByEntryId;
51
39
 
52
40
  //# sourceMappingURL=getPublishedRevisionByEntryId.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_dataloader","_interopRequireDefault","require","_batchRead","_cleanup","_keys","_createBatchScheduleFn","createGetPublishedRevisionByEntryId","params","entity","locale","tenant","publishedKey","createPublishedSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetPublishedRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, ReturnType<typeof entity.getBatch>>>(\n (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 {}\n );\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(entryId => {\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,sBAAA,GAAAJ,OAAA;AAEO,MAAMK,mCAAmC,GAAIC,MAAwB,IAAK;EAC7E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,YAAY,GAAG,IAAAC,4BAAsB,EAAC,CAAC;EAC7C,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CACtB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChB,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCV,MAAM;QACND,MAAM;QACNS;MACJ,CAAC,CAAC;MACF,IAAID,UAAU,CAACE,YAAY,CAAC,EAAE;QAC1B,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,YAAY,CAAC,GAAGX,MAAM,CAACa,QAAQ,CAAC;QACvCC,EAAE,EAAEH,YAAY;QAChBI,EAAE,EAAEZ;MACR,CAAC,CAAC;MACF,OAAOM,UAAU;IACrB,CAAC,EACD,CAAC,CACL,CAAC;IAED,MAAMO,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAElB,MAAM,CAACkB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACd,OAAO;IAChC,CAAC,CAAC;IACF,MAAMY,KAAK,GAAG,IAAAG,qBAAY,EAACtB,MAAM,EAAEgB,OAAO,CAAC;IAE3C,OAAOV,GAAG,CAACiB,GAAG,CAACC,OAAO,IAAI;MACtB,OAAOL,KAAK,CAACM,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOF,OAAO,KAAKE,IAAI,CAACF,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIG,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAA/B,mCAAA,GAAAA,mCAAA","ignoreList":[]}
1
+ {"version":3,"names":["DataLoader","createPartitionKey","createPublishedSortKey","createBatchScheduleFn","createGetPublishedRevisionByEntryId","params","entity","tenant","publishedKey","ids","reader","createEntityReader","keys","Set","id","partitionKey","has","add","get","PK","SK","items","execute","map","item","data","entryId","filter","batchScheduleFn"],"sources":["getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetPublishedRevisionByEntryId = (params: IDataLoaderParams) => {\n const { entity, tenant } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n if (keys.has(partitionKey)) {\n continue;\n }\n keys.add(partitionKey);\n reader.get({\n PK: partitionKey,\n SK: publishedKey\n });\n }\n\n const items = (await reader.execute()).map(item => {\n return item.data;\n });\n\n return ids.map(entryId => {\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,YAAY;AAEnC,SAASC,kBAAkB,EAAEC,sBAAsB;AAEnD,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,mCAAmC,GAAIC,MAAyB,IAAK;EAC9E,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEjC,MAAMG,YAAY,GAAGN,sBAAsB,CAAC,CAAC;EAC7C,OAAO,IAAIF,UAAU,CACjB,MAAMS,GAAG,IAAI;IACT,MAAMC,MAAM,GAAGJ,MAAM,CAACK,kBAAkB,CAAC,CAAC;IAE1C,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAS,CAAC;IAE9B,KAAK,MAAMC,EAAE,IAAIL,GAAG,EAAE;MAClB,MAAMM,YAAY,GAAGd,kBAAkB,CAAC;QACpCM,MAAM;QACNO;MACJ,CAAC,CAAC;MACF,IAAIF,IAAI,CAACI,GAAG,CAACD,YAAY,CAAC,EAAE;QACxB;MACJ;MACAH,IAAI,CAACK,GAAG,CAACF,YAAY,CAAC;MACtBL,MAAM,CAACQ,GAAG,CAAC;QACPC,EAAE,EAAEJ,YAAY;QAChBK,EAAE,EAAEZ;MACR,CAAC,CAAC;IACN;IAEA,MAAMa,KAAK,GAAG,CAAC,MAAMX,MAAM,CAACY,OAAO,CAAC,CAAC,EAAEC,GAAG,CAACC,IAAI,IAAI;MAC/C,OAAOA,IAAI,CAACC,IAAI;IACpB,CAAC,CAAC;IAEF,OAAOhB,GAAG,CAACc,GAAG,CAACG,OAAO,IAAI;MACtB,OAAOL,KAAK,CAACM,MAAM,CAACH,IAAI,IAAI;QACxB,OAAOE,OAAO,KAAKF,IAAI,CAACE,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIE,eAAe,EAAEzB,qBAAqB,CAAC;EAC3C,CACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  import DataLoader from "dataloader";
2
- import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
- import { DataLoaderParams } from "./types";
4
- export declare const createGetRevisionById: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
2
+ import type { CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
3
+ import type { IDataLoaderParams } from "./types.js";
4
+ export declare const createGetRevisionById: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
@@ -1,62 +1,50 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGetRevisionById = void 0;
8
- var _dataloader = _interopRequireDefault(require("dataloader"));
9
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
10
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
- var _keys = require("../keys");
12
- var _utils = require("@webiny/utils");
13
- var _createBatchScheduleFn = require("./createBatchScheduleFn");
14
- const createGetRevisionById = params => {
1
+ import DataLoader from "dataloader";
2
+ import { createPartitionKey, createRevisionSortKey } from "../keys.js";
3
+ import { parseIdentifier } from "@webiny/utils";
4
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
5
+ export const createGetRevisionById = params => {
15
6
  const {
16
7
  entity,
17
- tenant,
18
- locale
8
+ tenant
19
9
  } = params;
20
- return new _dataloader.default(async ids => {
21
- const queries = ids.reduce((collection, id) => {
22
- const partitionKey = (0, _keys.createPartitionKey)({
10
+ return new DataLoader(async ids => {
11
+ const reader = entity.createEntityReader();
12
+ const keys = new Set();
13
+ for (const id of ids) {
14
+ const partitionKey = createPartitionKey({
23
15
  tenant,
24
- locale,
25
16
  id
26
17
  });
27
18
  const {
28
19
  version
29
- } = (0, _utils.parseIdentifier)(id);
20
+ } = parseIdentifier(id);
30
21
  if (version === null) {
31
- return collection;
22
+ continue;
32
23
  }
33
- const sortKey = (0, _keys.createRevisionSortKey)({
24
+ const sortKey = createRevisionSortKey({
34
25
  version
35
26
  });
36
- const keys = `${partitionKey}__${sortKey}`;
37
- if (collection[keys]) {
38
- return collection;
27
+ const key = `${partitionKey}__${sortKey}`;
28
+ if (keys.has(key)) {
29
+ continue;
39
30
  }
40
- collection[keys] = entity.getBatch({
31
+ keys.add(key);
32
+ reader.get({
41
33
  PK: partitionKey,
42
34
  SK: sortKey
43
35
  });
44
- return collection;
45
- }, {});
46
- const records = await (0, _batchRead.batchReadAll)({
47
- table: entity.table,
48
- items: Object.values(queries)
36
+ }
37
+ const items = (await reader.execute()).map(item => {
38
+ return item.data;
49
39
  });
50
- const items = (0, _cleanup.cleanupItems)(entity, records);
51
40
  return ids.map(id => {
52
41
  return items.filter(item => {
53
42
  return id === item.id;
54
43
  });
55
44
  });
56
45
  }, {
57
- batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
46
+ batchScheduleFn: createBatchScheduleFn()
58
47
  });
59
48
  };
60
- exports.createGetRevisionById = createGetRevisionById;
61
49
 
62
50
  //# sourceMappingURL=getRevisionById.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_dataloader","_interopRequireDefault","require","_batchRead","_cleanup","_keys","_utils","_createBatchScheduleFn","createGetRevisionById","params","entity","tenant","locale","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetRevisionById = (params: DataLoaderParams) => {\n const { entity, tenant, locale } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, ReturnType<typeof entity.getBatch>>>(\n (collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\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 {}\n );\n\n const records = await batchReadAll<CmsStorageEntry>({\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 batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,sBAAA,GAAAL,OAAA;AAEO,MAAMM,qBAAqB,GAAIC,MAAwB,IAAK;EAC/D,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CACtB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChB,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCT,MAAM;QACNC,MAAM;QACNM;MACJ,CAAC,CAAC;MACF,MAAM;QAAEG;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACJ,EAAE,CAAC;MACvC,IAAIG,OAAO,KAAK,IAAI,EAAE;QAClB,OAAOJ,UAAU;MACrB;MACA,MAAMM,OAAO,GAAG,IAAAC,2BAAqB,EAAC;QAClCH;MACJ,CAAC,CAAC;MACF,MAAMI,IAAI,GAAI,GAAEN,YAAa,KAAII,OAAQ,EAAC;MAC1C,IAAIN,UAAU,CAACQ,IAAI,CAAC,EAAE;QAClB,OAAOR,UAAU;MACrB;MAEAA,UAAU,CAACQ,IAAI,CAAC,GAAGf,MAAM,CAACgB,QAAQ,CAAC;QAC/BC,EAAE,EAAER,YAAY;QAChBS,EAAE,EAAEL;MACR,CAAC,CAAC;MAEF,OAAON,UAAU;IACrB,CAAC,EACD,CAAC,CACL,CAAC;IAED,MAAMY,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAErB,MAAM,CAACqB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACnB,OAAO;IAChC,CAAC,CAAC;IACF,MAAMiB,KAAK,GAAG,IAAAG,qBAAY,EAACzB,MAAM,EAAEmB,OAAO,CAAC;IAE3C,OAAOf,GAAG,CAACsB,GAAG,CAAClB,EAAE,IAAI;MACjB,OAAOc,KAAK,CAACK,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOpB,EAAE,KAAKoB,IAAI,CAACpB,EAAE;MACzB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIqB,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAjC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
1
+ {"version":3,"names":["DataLoader","createPartitionKey","createRevisionSortKey","parseIdentifier","createBatchScheduleFn","createGetRevisionById","params","entity","tenant","ids","reader","createEntityReader","keys","Set","id","partitionKey","version","sortKey","key","has","add","get","PK","SK","items","execute","map","item","data","filter","batchScheduleFn"],"sources":["getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetRevisionById = (params: IDataLoaderParams) => {\n const { entity, tenant } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n continue;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const key = `${partitionKey}__${sortKey}`;\n if (keys.has(key)) {\n continue;\n }\n keys.add(key);\n\n reader.get({\n PK: partitionKey,\n SK: sortKey\n });\n }\n\n const items = (await reader.execute()).map(item => {\n return item.data;\n });\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,YAAY;AAEnC,SAASC,kBAAkB,EAAEC,qBAAqB;AAElD,SAASC,eAAe,QAAQ,eAAe;AAC/C,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,qBAAqB,GAAIC,MAAyB,IAAK;EAChE,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEjC,OAAO,IAAIN,UAAU,CACjB,MAAMS,GAAG,IAAI;IACT,MAAMC,MAAM,GAAGH,MAAM,CAACI,kBAAkB,CAAC,CAAC;IAE1C,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAS,CAAC;IAE9B,KAAK,MAAMC,EAAE,IAAIL,GAAG,EAAE;MAClB,MAAMM,YAAY,GAAGd,kBAAkB,CAAC;QACpCO,MAAM;QACNM;MACJ,CAAC,CAAC;MACF,MAAM;QAAEE;MAAQ,CAAC,GAAGb,eAAe,CAACW,EAAE,CAAC;MACvC,IAAIE,OAAO,KAAK,IAAI,EAAE;QAClB;MACJ;MACA,MAAMC,OAAO,GAAGf,qBAAqB,CAAC;QAClCc;MACJ,CAAC,CAAC;MACF,MAAME,GAAG,GAAG,GAAGH,YAAY,KAAKE,OAAO,EAAE;MACzC,IAAIL,IAAI,CAACO,GAAG,CAACD,GAAG,CAAC,EAAE;QACf;MACJ;MACAN,IAAI,CAACQ,GAAG,CAACF,GAAG,CAAC;MAEbR,MAAM,CAACW,GAAG,CAAC;QACPC,EAAE,EAAEP,YAAY;QAChBQ,EAAE,EAAEN;MACR,CAAC,CAAC;IACN;IAEA,MAAMO,KAAK,GAAG,CAAC,MAAMd,MAAM,CAACe,OAAO,CAAC,CAAC,EAAEC,GAAG,CAACC,IAAI,IAAI;MAC/C,OAAOA,IAAI,CAACC,IAAI;IACpB,CAAC,CAAC;IAEF,OAAOnB,GAAG,CAACiB,GAAG,CAACZ,EAAE,IAAI;MACjB,OAAOU,KAAK,CAACK,MAAM,CAACF,IAAI,IAAI;QACxB,OAAOb,EAAE,KAAKa,IAAI,CAACb,EAAE;MACzB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIgB,eAAe,EAAE1B,qBAAqB,CAAC;EAC3C,CACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,8 +1,8 @@
1
- import DataLoader from "dataloader";
2
- import { DataLoaderParams } from "./types";
3
- export * from "./DataLoaderCache";
1
+ import type DataLoader from "dataloader";
2
+ import type { IDataLoaderParams } from "./types.js";
3
+ export * from "./DataLoaderCache.js";
4
4
  interface Callable {
5
- (params: DataLoaderParams): DataLoader<any, any>;
5
+ (params: IDataLoaderParams): DataLoader<any, any>;
6
6
  }
7
- export declare type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
7
+ export type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
8
8
  export declare const getDataLoaderFactory: (name: string) => Callable;
@@ -1,40 +1,19 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- getDataLoaderFactory: true
8
- };
9
- exports.getDataLoaderFactory = void 0;
10
- var _getAllEntryRevisions = require("./getAllEntryRevisions");
11
- var _getLatestRevisionByEntryId = require("./getLatestRevisionByEntryId");
12
- var _getPublishedRevisionByEntryId = require("./getPublishedRevisionByEntryId");
13
- var _getRevisionById = require("./getRevisionById");
14
- var _DataLoaderCache = require("./DataLoaderCache");
15
- Object.keys(_DataLoaderCache).forEach(function (key) {
16
- if (key === "default" || key === "__esModule") return;
17
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
18
- if (key in exports && exports[key] === _DataLoaderCache[key]) return;
19
- Object.defineProperty(exports, key, {
20
- enumerable: true,
21
- get: function () {
22
- return _DataLoaderCache[key];
23
- }
24
- });
25
- });
1
+ import { createGetAllEntryRevisions } from "./getAllEntryRevisions.js";
2
+ import { createGetLatestRevisionByEntryId } from "./getLatestRevisionByEntryId.js";
3
+ import { createGetPublishedRevisionByEntryId } from "./getPublishedRevisionByEntryId.js";
4
+ import { createGetRevisionById } from "./getRevisionById.js";
5
+ export * from "./DataLoaderCache.js";
26
6
  const dataLoaders = {
27
- getAllEntryRevisions: _getAllEntryRevisions.createGetAllEntryRevisions,
28
- getLatestRevisionByEntryId: _getLatestRevisionByEntryId.createGetLatestRevisionByEntryId,
29
- getPublishedRevisionByEntryId: _getPublishedRevisionByEntryId.createGetPublishedRevisionByEntryId,
30
- getRevisionById: _getRevisionById.createGetRevisionById
7
+ getAllEntryRevisions: createGetAllEntryRevisions,
8
+ getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,
9
+ getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,
10
+ getRevisionById: createGetRevisionById
31
11
  };
32
- const getDataLoaderFactory = name => {
12
+ export const getDataLoaderFactory = name => {
33
13
  if (!dataLoaders[name]) {
34
14
  throw new Error(`Missing data loader "${name}".`);
35
15
  }
36
16
  return dataLoaders[name];
37
17
  };
38
- exports.getDataLoaderFactory = getDataLoaderFactory;
39
18
 
40
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_getAllEntryRevisions","require","_getLatestRevisionByEntryId","_getPublishedRevisionByEntryId","_getRevisionById","_DataLoaderCache","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","dataLoaders","getAllEntryRevisions","createGetAllEntryRevisions","getLatestRevisionByEntryId","createGetLatestRevisionByEntryId","getPublishedRevisionByEntryId","createGetPublishedRevisionByEntryId","getRevisionById","createGetRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { DataLoaderParams } from \"./types\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId\";\nimport { createGetRevisionById } from \"./getRevisionById\";\n\nexport * from \"./DataLoaderCache\";\n\ninterface Callable {\n (params: DataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"mappings":";;;;;;;;;AAEA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,2BAAA,GAAAD,OAAA;AACA,IAAAE,8BAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAJ,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAMA,MAAMS,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEC,gDAA0B;EAChDC,0BAA0B,EAAEC,4DAAgC;EAC5DC,6BAA6B,EAAEC,kEAAmC;EAClEC,eAAe,EAAEC;AACrB,CAAC;AAQM,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACV,WAAW,CAACU,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAE,wBAAuBD,IAAK,IAAG,CAAC;EACrD;EACA,OAAOV,WAAW,CAACU,IAAI,CAAC;AAC5B,CAAC;AAACd,OAAA,CAAAa,oBAAA,GAAAA,oBAAA","ignoreList":[]}
1
+ {"version":3,"names":["createGetAllEntryRevisions","createGetLatestRevisionByEntryId","createGetPublishedRevisionByEntryId","createGetRevisionById","dataLoaders","getAllEntryRevisions","getLatestRevisionByEntryId","getPublishedRevisionByEntryId","getRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions.js\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId.js\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId.js\";\nimport { createGetRevisionById } from \"./getRevisionById.js\";\n\nexport * from \"./DataLoaderCache.js\";\n\ninterface Callable {\n (params: IDataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"mappings":"AAEA,SAASA,0BAA0B;AACnC,SAASC,gCAAgC;AACzC,SAASC,mCAAmC;AAC5C,SAASC,qBAAqB;AAE9B;AAMA,MAAMC,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEL,0BAA0B;EAChDM,0BAA0B,EAAEL,gCAAgC;EAC5DM,6BAA6B,EAAEL,mCAAmC;EAClEM,eAAe,EAAEL;AACrB,CAAC;AAQD,OAAO,MAAMM,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACN,WAAW,CAACM,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAC,wBAAwBD,IAAI,IAAI,CAAC;EACrD;EACA,OAAON,WAAW,CAACM,IAAI,CAAC;AAC5B,CAAC","ignoreList":[]}
@@ -1,6 +1,5 @@
1
- import { Entity } from "@webiny/db-dynamodb/toolbox";
2
- export interface DataLoaderParams {
3
- entity: Entity<any>;
1
+ import type { IEntryEntity } from "../../../definitions/types.js";
2
+ export interface IDataLoaderParams {
3
+ entity: IEntryEntity;
4
4
  tenant: string;
5
- locale: string;
6
5
  }
@@ -1,7 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
6
2
 
7
3
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Entity } from \"@webiny/db-dynamodb/toolbox\";\n\nexport interface DataLoaderParams {\n entity: Entity<any>;\n tenant: string;\n locale: string;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntryEntity } from \"~/definitions/types.js\";\n\nexport interface IDataLoaderParams {\n entity: IEntryEntity;\n tenant: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,24 +1,24 @@
1
- import { CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "@webiny/db-dynamodb/toolbox";
3
- import { DataLoadersHandlerInterface, DataLoadersHandlerInterfaceClearAllParams } from "../../types";
1
+ import type { CmsEntryValues, CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler } from "../../types.js";
3
+ import type { IEntryEntity } from "../../definitions/types.js";
4
4
  interface DataLoaderParams {
5
- model: Pick<CmsModel, "tenant" | "locale" | "modelId">;
5
+ model: Pick<CmsModel, "tenant" | "modelId">;
6
6
  ids: readonly string[];
7
7
  }
8
- interface DataLoadersHandlerParams {
9
- entity: Entity<any>;
8
+ interface IDataLoadersHandlerParams {
9
+ entity: IEntryEntity;
10
10
  }
11
11
  export interface ClearAllParams {
12
- model: Pick<CmsModel, "tenant" | "locale" | "modelId">;
12
+ model: Pick<CmsModel, "tenant" | "modelId">;
13
13
  }
14
- export declare class DataLoadersHandler implements DataLoadersHandlerInterface {
14
+ export declare class DataLoadersHandler implements IDataLoadersHandler {
15
15
  private readonly entity;
16
16
  private readonly cache;
17
- constructor(params: DataLoadersHandlerParams);
18
- getAllEntryRevisions(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
19
- getRevisionById(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
20
- getPublishedRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
21
- getLatestRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
17
+ constructor(params: IDataLoadersHandlerParams);
18
+ getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
19
+ getRevisionById<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
20
+ getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
21
+ getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
22
22
  /**
23
23
  * TODO @ts-refactor
24
24
  * Maybe pass on the generics to DataLoader definition?
@@ -1,16 +1,9 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.DataLoadersHandler = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- var _DataLoaderCache = require("./dataLoader/DataLoaderCache");
10
- var _dataLoader = require("./dataLoader");
11
- var _utils = require("@webiny/utils");
12
- class DataLoadersHandler {
13
- cache = new _DataLoaderCache.DataLoaderCache();
1
+ import WebinyError from "@webiny/error";
2
+ import { DataLoaderCache } from "./dataLoader/DataLoaderCache.js";
3
+ import { getDataLoaderFactory } from "./dataLoader/index.js";
4
+ import { parseIdentifier } from "@webiny/utils";
5
+ export class DataLoadersHandler {
6
+ cache = new DataLoaderCache();
14
7
  constructor(params) {
15
8
  this.entity = params.entity;
16
9
  }
@@ -18,7 +11,7 @@ class DataLoadersHandler {
18
11
  const ids = params.ids.map(id => {
19
12
  const {
20
13
  id: entryId
21
- } = (0, _utils.parseIdentifier)(id);
14
+ } = parseIdentifier(id);
22
15
  return entryId;
23
16
  });
24
17
  return await this.loadMany("getAllEntryRevisions", params, ids);
@@ -30,7 +23,7 @@ class DataLoadersHandler {
30
23
  const ids = params.ids.map(id => {
31
24
  const {
32
25
  id: entryId
33
- } = (0, _utils.parseIdentifier)(id);
26
+ } = parseIdentifier(id);
34
27
  return entryId;
35
28
  });
36
29
  return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
@@ -39,7 +32,7 @@ class DataLoadersHandler {
39
32
  const ids = params.ids.map(id => {
40
33
  const {
41
34
  id: entryId
42
- } = (0, _utils.parseIdentifier)(id);
35
+ } = parseIdentifier(id);
43
36
  return entryId;
44
37
  });
45
38
  return await this.loadMany("getLatestRevisionByEntryId", params, ids);
@@ -55,18 +48,16 @@ class DataLoadersHandler {
55
48
  } = params;
56
49
  const cacheParams = {
57
50
  tenant: model.tenant,
58
- locale: model.locale,
59
51
  name
60
52
  };
61
53
  let loader = this.cache.getDataLoader(cacheParams);
62
54
  if (loader) {
63
55
  return loader;
64
56
  }
65
- const factory = (0, _dataLoader.getDataLoaderFactory)(name);
57
+ const factory = getDataLoaderFactory(name);
66
58
  loader = factory({
67
59
  entity: this.entity,
68
- tenant: model.tenant,
69
- locale: model.locale
60
+ tenant: model.tenant
70
61
  });
71
62
  this.cache.setDataLoader(cacheParams, loader);
72
63
  return loader;
@@ -79,12 +70,12 @@ class DataLoadersHandler {
79
70
  return results.reduce((acc, res) => {
80
71
  if (Array.isArray(res) === false) {
81
72
  if (res && res.message) {
82
- throw new _error.default(res.message, res.code, {
73
+ throw new WebinyError(res.message, res.code, {
83
74
  ...res,
84
75
  data: JSON.stringify(res.data || {})
85
76
  });
86
77
  }
87
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
78
+ throw new WebinyError("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
88
79
  ...params,
89
80
  loader
90
81
  });
@@ -94,14 +85,14 @@ class DataLoadersHandler {
94
85
  }, []);
95
86
  }
96
87
  } catch (ex) {
97
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
88
+ throw new WebinyError(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
98
89
  error: ex,
99
90
  ...params,
100
91
  loader,
101
92
  ids
102
93
  });
103
94
  }
104
- throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
95
+ throw new WebinyError(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
105
96
  loader,
106
97
  ids,
107
98
  results
@@ -111,6 +102,5 @@ class DataLoadersHandler {
111
102
  this.cache.clearAll(params?.model);
112
103
  }
113
104
  }
114
- exports.DataLoadersHandler = DataLoadersHandler;
115
105
 
116
106
  //# sourceMappingURL=dataLoaders.js.map