@webiny/api-headless-cms-ddb 0.0.0-unstable.a4637c5ce6 → 0.0.0-unstable.a85ef555b2

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 (287) hide show
  1. package/README.md +6 -20
  2. package/abstractions/CmsDdbDataLoaders.d.ts +5 -0
  3. package/abstractions/CmsDdbDataLoaders.js +5 -0
  4. package/abstractions/CmsDdbDataLoaders.js.map +1 -0
  5. package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
  6. package/abstractions/CmsDdbEntryEntity.js +5 -0
  7. package/abstractions/CmsDdbEntryEntity.js.map +1 -0
  8. package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
  9. package/abstractions/CmsDdbGroupEntity.js +5 -0
  10. package/abstractions/CmsDdbGroupEntity.js.map +1 -0
  11. package/abstractions/CmsDdbModelEntity.d.ts +5 -0
  12. package/abstractions/CmsDdbModelEntity.js +5 -0
  13. package/abstractions/CmsDdbModelEntity.js.map +1 -0
  14. package/abstractions/CmsDdbTable.d.ts +5 -0
  15. package/abstractions/CmsDdbTable.js +5 -0
  16. package/abstractions/CmsDdbTable.js.map +1 -0
  17. package/definitions/entry.d.ts +4 -6
  18. package/definitions/entry.js +8 -185
  19. package/definitions/entry.js.map +1 -1
  20. package/definitions/group.d.ts +4 -6
  21. package/definitions/group.js +8 -63
  22. package/definitions/group.js.map +1 -1
  23. package/definitions/model.d.ts +4 -6
  24. package/definitions/model.js +8 -107
  25. package/definitions/model.js.map +1 -1
  26. package/definitions/table.d.ts +3 -5
  27. package/definitions/table.js +6 -29
  28. package/definitions/table.js.map +1 -1
  29. package/definitions/types.d.ts +65 -0
  30. package/definitions/types.js +0 -0
  31. package/index.d.ts +10 -3
  32. package/index.js +43 -123
  33. package/index.js.map +1 -1
  34. package/operations/entry/DdbCreateEntry.d.ts +16 -0
  35. package/operations/entry/DdbCreateEntry.js +77 -0
  36. package/operations/entry/DdbCreateEntry.js.map +1 -0
  37. package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
  38. package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
  39. package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
  40. package/operations/entry/DdbDeleteEntry.d.ts +16 -0
  41. package/operations/entry/DdbDeleteEntry.js +65 -0
  42. package/operations/entry/DdbDeleteEntry.js.map +1 -0
  43. package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
  44. package/operations/entry/DdbDeleteEntryRevision.js +91 -0
  45. package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
  46. package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
  47. package/operations/entry/DdbDeleteMultipleEntries.js +59 -0
  48. package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
  49. package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
  50. package/operations/entry/DdbGetEntriesByIds.js +31 -0
  51. package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
  52. package/operations/entry/DdbGetEntry.d.ts +14 -0
  53. package/operations/entry/DdbGetEntry.js +27 -0
  54. package/operations/entry/DdbGetEntry.js.map +1 -0
  55. package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
  56. package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
  57. package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
  58. package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
  59. package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
  60. package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
  61. package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
  62. package/operations/entry/DdbGetPreviousRevision.js +53 -0
  63. package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
  64. package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
  65. package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
  66. package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
  67. package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
  68. package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
  69. package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
  70. package/operations/entry/DdbGetRevisionById.d.ts +14 -0
  71. package/operations/entry/DdbGetRevisionById.js +34 -0
  72. package/operations/entry/DdbGetRevisionById.js.map +1 -0
  73. package/operations/entry/DdbGetRevisions.d.ts +14 -0
  74. package/operations/entry/DdbGetRevisions.js +33 -0
  75. package/operations/entry/DdbGetRevisions.js.map +1 -0
  76. package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
  77. package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
  78. package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
  79. package/operations/entry/DdbListEntries.d.ts +30 -0
  80. package/operations/entry/DdbListEntries.js +133 -0
  81. package/operations/entry/DdbListEntries.js.map +1 -0
  82. package/operations/entry/DdbMoveEntry.d.ts +16 -0
  83. package/operations/entry/DdbMoveEntry.js +63 -0
  84. package/operations/entry/DdbMoveEntry.js.map +1 -0
  85. package/operations/entry/DdbMoveToBin.d.ts +16 -0
  86. package/operations/entry/DdbMoveToBin.js +77 -0
  87. package/operations/entry/DdbMoveToBin.js.map +1 -0
  88. package/operations/entry/DdbPublishEntry.d.ts +18 -0
  89. package/operations/entry/DdbPublishEntry.js +162 -0
  90. package/operations/entry/DdbPublishEntry.js.map +1 -0
  91. package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
  92. package/operations/entry/DdbRestoreFromBin.js +78 -0
  93. package/operations/entry/DdbRestoreFromBin.js.map +1 -0
  94. package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
  95. package/operations/entry/DdbUnpublishEntry.js +112 -0
  96. package/operations/entry/DdbUnpublishEntry.js.map +1 -0
  97. package/operations/entry/DdbUpdateEntry.d.ts +17 -0
  98. package/operations/entry/DdbUpdateEntry.js +105 -0
  99. package/operations/entry/DdbUpdateEntry.js.map +1 -0
  100. package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -2
  101. package/operations/entry/dataLoader/DataLoaderCache.js +21 -35
  102. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  103. package/operations/entry/dataLoader/constants.js +2 -7
  104. package/operations/entry/dataLoader/constants.js.map +1 -1
  105. package/operations/entry/dataLoader/createBatchScheduleFn.js +7 -22
  106. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  107. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
  108. package/operations/entry/dataLoader/getAllEntryRevisions.js +20 -41
  109. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  110. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
  111. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +36 -52
  112. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  113. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
  114. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +36 -52
  115. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  116. package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
  117. package/operations/entry/dataLoader/getRevisionById.js +38 -58
  118. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  119. package/operations/entry/dataLoader/index.d.ts +3 -3
  120. package/operations/entry/dataLoader/index.js +13 -35
  121. package/operations/entry/dataLoader/index.js.map +1 -1
  122. package/operations/entry/dataLoader/types.d.ts +4 -4
  123. package/operations/entry/dataLoader/types.js +0 -7
  124. package/operations/entry/dataLoaders.d.ts +13 -13
  125. package/operations/entry/dataLoaders.js +92 -110
  126. package/operations/entry/dataLoaders.js.map +1 -1
  127. package/operations/entry/feature.d.ts +4 -0
  128. package/operations/entry/feature.js +55 -0
  129. package/operations/entry/feature.js.map +1 -0
  130. package/operations/entry/keys.d.ts +46 -2
  131. package/operations/entry/keys.js +52 -49
  132. package/operations/entry/keys.js.map +1 -1
  133. package/operations/entry/storageEntryUtils.d.ts +8 -0
  134. package/operations/entry/storageEntryUtils.js +25 -0
  135. package/operations/entry/storageEntryUtils.js.map +1 -0
  136. package/operations/group/DdbCreateGroup.d.ts +12 -0
  137. package/operations/group/DdbCreateGroup.js +35 -0
  138. package/operations/group/DdbCreateGroup.js.map +1 -0
  139. package/operations/group/DdbDeleteGroup.d.ts +12 -0
  140. package/operations/group/DdbDeleteGroup.js +31 -0
  141. package/operations/group/DdbDeleteGroup.js.map +1 -0
  142. package/operations/group/DdbGetGroup.d.ts +12 -0
  143. package/operations/group/DdbGetGroup.js +31 -0
  144. package/operations/group/DdbGetGroup.js.map +1 -0
  145. package/operations/group/DdbListGroups.d.ts +14 -0
  146. package/operations/group/DdbListGroups.js +52 -0
  147. package/operations/group/DdbListGroups.js.map +1 -0
  148. package/operations/group/DdbUpdateGroup.d.ts +12 -0
  149. package/operations/group/DdbUpdateGroup.js +35 -0
  150. package/operations/group/DdbUpdateGroup.js.map +1 -0
  151. package/operations/group/feature.d.ts +4 -0
  152. package/operations/group/feature.js +19 -0
  153. package/operations/group/feature.js.map +1 -0
  154. package/operations/group/keys.d.ts +15 -0
  155. package/operations/group/keys.js +17 -0
  156. package/operations/group/keys.js.map +1 -0
  157. package/operations/model/DdbCreateModel.d.ts +12 -0
  158. package/operations/model/DdbCreateModel.js +37 -0
  159. package/operations/model/DdbCreateModel.js.map +1 -0
  160. package/operations/model/DdbDeleteModel.d.ts +12 -0
  161. package/operations/model/DdbDeleteModel.js +31 -0
  162. package/operations/model/DdbDeleteModel.js.map +1 -0
  163. package/operations/model/DdbGetModel.d.ts +12 -0
  164. package/operations/model/DdbGetModel.js +30 -0
  165. package/operations/model/DdbGetModel.js.map +1 -0
  166. package/operations/model/DdbListModels.d.ts +12 -0
  167. package/operations/model/DdbListModels.js +36 -0
  168. package/operations/model/DdbListModels.js.map +1 -0
  169. package/operations/model/DdbUpdateModel.d.ts +12 -0
  170. package/operations/model/DdbUpdateModel.js +36 -0
  171. package/operations/model/DdbUpdateModel.js.map +1 -0
  172. package/operations/model/feature.d.ts +4 -0
  173. package/operations/model/feature.js +19 -0
  174. package/operations/model/feature.js.map +1 -0
  175. package/operations/model/keys.d.ts +15 -0
  176. package/operations/model/keys.js +16 -0
  177. package/operations/model/keys.js.map +1 -0
  178. package/package.json +27 -25
  179. package/types.d.ts +11 -51
  180. package/types.js +6 -12
  181. package/types.js.map +1 -1
  182. package/definitions/system.d.ts +0 -10
  183. package/definitions/system.js +0 -42
  184. package/definitions/system.js.map +0 -1
  185. package/dynamoDb/index.d.ts +0 -2
  186. package/dynamoDb/index.js +0 -15
  187. package/dynamoDb/index.js.map +0 -1
  188. package/dynamoDb/path/locationFolderId.d.ts +0 -2
  189. package/dynamoDb/path/locationFolderId.js +0 -43
  190. package/dynamoDb/path/locationFolderId.js.map +0 -1
  191. package/dynamoDb/path/plainObject.d.ts +0 -2
  192. package/dynamoDb/path/plainObject.js +0 -35
  193. package/dynamoDb/path/plainObject.js.map +0 -1
  194. package/dynamoDb/storage/longText.d.ts +0 -10
  195. package/dynamoDb/storage/longText.js +0 -94
  196. package/dynamoDb/storage/longText.js.map +0 -1
  197. package/dynamoDb/storage/richText.d.ts +0 -2
  198. package/dynamoDb/storage/richText.js +0 -61
  199. package/dynamoDb/storage/richText.js.map +0 -1
  200. package/dynamoDb/transformValue/datetime.d.ts +0 -5
  201. package/dynamoDb/transformValue/datetime.js +0 -47
  202. package/dynamoDb/transformValue/datetime.js.map +0 -1
  203. package/operations/entry/dataLoader/types.js.map +0 -1
  204. package/operations/entry/filtering/createExpressions.d.ts +0 -26
  205. package/operations/entry/filtering/createExpressions.js +0 -178
  206. package/operations/entry/filtering/createExpressions.js.map +0 -1
  207. package/operations/entry/filtering/createFields.d.ts +0 -16
  208. package/operations/entry/filtering/createFields.js +0 -108
  209. package/operations/entry/filtering/createFields.js.map +0 -1
  210. package/operations/entry/filtering/extractSort.d.ts +0 -17
  211. package/operations/entry/filtering/extractSort.js +0 -69
  212. package/operations/entry/filtering/extractSort.js.map +0 -1
  213. package/operations/entry/filtering/filter.d.ts +0 -15
  214. package/operations/entry/filtering/filter.js +0 -158
  215. package/operations/entry/filtering/filter.js.map +0 -1
  216. package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
  217. package/operations/entry/filtering/fullTextSearch.js +0 -50
  218. package/operations/entry/filtering/fullTextSearch.js.map +0 -1
  219. package/operations/entry/filtering/getValue.d.ts +0 -5
  220. package/operations/entry/filtering/getValue.js +0 -66
  221. package/operations/entry/filtering/getValue.js.map +0 -1
  222. package/operations/entry/filtering/index.d.ts +0 -2
  223. package/operations/entry/filtering/index.js +0 -21
  224. package/operations/entry/filtering/index.js.map +0 -1
  225. package/operations/entry/filtering/mapPlugins.d.ts +0 -8
  226. package/operations/entry/filtering/mapPlugins.js +0 -33
  227. package/operations/entry/filtering/mapPlugins.js.map +0 -1
  228. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
  229. package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -45
  230. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
  231. package/operations/entry/filtering/plugins/index.d.ts +0 -1
  232. package/operations/entry/filtering/plugins/index.js +0 -16
  233. package/operations/entry/filtering/plugins/index.js.map +0 -1
  234. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
  235. package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -90
  236. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
  237. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -3
  238. package/operations/entry/filtering/plugins/refFilterCreate.js +0 -80
  239. package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
  240. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +0 -2
  241. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +0 -65
  242. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +0 -1
  243. package/operations/entry/filtering/sort.d.ts +0 -12
  244. package/operations/entry/filtering/sort.js +0 -71
  245. package/operations/entry/filtering/sort.js.map +0 -1
  246. package/operations/entry/filtering/systemFields.d.ts +0 -4
  247. package/operations/entry/filtering/systemFields.js +0 -90
  248. package/operations/entry/filtering/systemFields.js.map +0 -1
  249. package/operations/entry/filtering/transform.d.ts +0 -6
  250. package/operations/entry/filtering/transform.js +0 -18
  251. package/operations/entry/filtering/transform.js.map +0 -1
  252. package/operations/entry/filtering/types.d.ts +0 -40
  253. package/operations/entry/filtering/types.js +0 -7
  254. package/operations/entry/filtering/types.js.map +0 -1
  255. package/operations/entry/filtering/values.d.ts +0 -2
  256. package/operations/entry/filtering/values.js +0 -24
  257. package/operations/entry/filtering/values.js.map +0 -1
  258. package/operations/entry/filtering/where.d.ts +0 -5
  259. package/operations/entry/filtering/where.js +0 -35
  260. package/operations/entry/filtering/where.js.map +0 -1
  261. package/operations/entry/index.d.ts +0 -8
  262. package/operations/entry/index.js +0 -1306
  263. package/operations/entry/index.js.map +0 -1
  264. package/operations/group/index.d.ts +0 -9
  265. package/operations/group/index.js +0 -174
  266. package/operations/group/index.js.map +0 -1
  267. package/operations/model/index.d.ts +0 -7
  268. package/operations/model/index.js +0 -150
  269. package/operations/model/index.js.map +0 -1
  270. package/operations/system/index.d.ts +0 -7
  271. package/operations/system/index.js +0 -94
  272. package/operations/system/index.js.map +0 -1
  273. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -23
  274. package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -48
  275. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
  276. package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
  277. package/plugins/CmsEntryFieldFilterPlugin.js +0 -27
  278. package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
  279. package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
  280. package/plugins/CmsEntryFieldSortingPlugin.js +0 -27
  281. package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
  282. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
  283. package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -23
  284. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
  285. package/plugins/index.d.ts +0 -4
  286. package/plugins/index.js +0 -51
  287. package/plugins/index.js.map +0 -1
@@ -0,0 +1,105 @@
1
+ import error from "@webiny/error";
2
+ import { UpdateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js";
3
+ import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
4
+ import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
5
+ import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
6
+ import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys } from "./keys.js";
7
+ import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
8
+ import { convertToStorageEntry } from "./storageEntryUtils.js";
9
+ class DdbUpdateEntryImpl {
10
+ constructor(entity, dataLoaders, storageModelProvider){
11
+ this.entity = entity;
12
+ this.dataLoaders = dataLoaders;
13
+ this.storageModelProvider = storageModelProvider;
14
+ }
15
+ async getLatestRevisionByEntryId(initialModel, params) {
16
+ const model = this.storageModelProvider.getModel(initialModel);
17
+ const items = await this.dataLoaders.getLatestRevisionByEntryId({
18
+ model,
19
+ ids: [
20
+ params.id
21
+ ]
22
+ });
23
+ return items.shift() || null;
24
+ }
25
+ async execute(initialModel, params) {
26
+ const { entry, storageEntry: initialStorageEntry } = params;
27
+ const model = this.storageModelProvider.getModel(initialModel);
28
+ const isPublished = "published" === entry.status;
29
+ const locked = isPublished ? true : entry.locked;
30
+ const storageEntry = convertToStorageEntry({
31
+ model,
32
+ storageEntry: initialStorageEntry
33
+ });
34
+ const entityBatch = this.entity.createEntityWriter({
35
+ put: [
36
+ {
37
+ ...createEntryRevisionKeys(storageEntry),
38
+ data: {
39
+ ...storageEntry,
40
+ locked
41
+ }
42
+ }
43
+ ]
44
+ });
45
+ if (isPublished) entityBatch.put({
46
+ ...createEntryPublishedKeys(storageEntry),
47
+ data: {
48
+ ...storageEntry,
49
+ locked
50
+ }
51
+ });
52
+ const latestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);
53
+ if (latestStorageEntry) {
54
+ const updatingLatestRevision = latestStorageEntry.id === entry.id;
55
+ if (updatingLatestRevision) entityBatch.put({
56
+ ...createEntryLatestKeys(storageEntry),
57
+ data: {
58
+ ...storageEntry,
59
+ locked
60
+ }
61
+ });
62
+ else {
63
+ const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
64
+ entityBatch.put({
65
+ ...createEntryRevisionKeys(latestStorageEntry),
66
+ data: {
67
+ ...latestStorageEntry,
68
+ ...updatedEntryLevelMetaFields
69
+ }
70
+ });
71
+ entityBatch.put({
72
+ ...createEntryLatestKeys(latestStorageEntry),
73
+ data: {
74
+ ...latestStorageEntry,
75
+ ...updatedEntryLevelMetaFields
76
+ }
77
+ });
78
+ }
79
+ }
80
+ try {
81
+ await entityBatch.execute();
82
+ this.dataLoaders.clearAll({
83
+ tenant: entry.tenant
84
+ });
85
+ return initialStorageEntry;
86
+ } catch (ex) {
87
+ throw new error(ex.message || "Could not update entry.", ex.code || "UPDATE_ERROR", {
88
+ error: ex,
89
+ entry,
90
+ latestStorageEntry
91
+ });
92
+ }
93
+ }
94
+ }
95
+ const DdbUpdateEntry = UpdateEntryStorageOperation.createImplementation({
96
+ implementation: DdbUpdateEntryImpl,
97
+ dependencies: [
98
+ CmsDdbEntryEntity,
99
+ CmsDdbDataLoaders,
100
+ CmsStorageModelProvider
101
+ ]
102
+ });
103
+ export { DdbUpdateEntry };
104
+
105
+ //# sourceMappingURL=DdbUpdateEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/DdbUpdateEntry.js","sources":["../../../src/operations/entry/DdbUpdateEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UpdateEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { CmsDdbDataLoaders } from \"~/abstractions/CmsDdbDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys\n} from \"~/operations/entry/keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { convertToStorageEntry } from \"./storageEntryUtils.js\";\n\ninterface IGetLatestRevisionByEntryIdParams {\n id: string;\n}\n\nclass DdbUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n private async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: IGetLatestRevisionByEntryIdParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const items = await this.dataLoaders.getLatestRevisionByEntryId<T>({\n model,\n ids: [params.id]\n });\n return items.shift() || null;\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUpdateParams<T>\n ) {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - update the current entry\n * - update the latest entry if the current entry is the latest one\n */\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...createEntryRevisionKeys(storageEntry),\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...createEntryPublishedKeys(storageEntry),\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n /**\n * We need the latest entry to update it as well if necessary.\n */\n const latestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry) {\n const updatingLatestRevision = latestStorageEntry.id === entry.id;\n if (updatingLatestRevision) {\n entityBatch.put({\n ...createEntryLatestKeys(storageEntry),\n data: {\n ...storageEntry,\n locked\n }\n });\n } else {\n /**\n * If not updating latest revision, we still want to update the latest revision's\n * entry-level meta fields to match the current revision's entry-level meta fields.\n */\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n /**\n * First we update the regular DynamoDB table. Two updates are needed:\n * - one for the actual revision record\n * - one for the latest record\n */\n entityBatch.put({\n ...createEntryRevisionKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n });\n\n entityBatch.put({\n ...createEntryLatestKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n });\n }\n }\n\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry.\",\n ex.code || \"UPDATE_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry\n }\n );\n }\n }\n}\n\nexport const DdbUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: DdbUpdateEntryImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbUpdateEntryImpl","entity","dataLoaders","storageModelProvider","initialModel","params","model","items","entry","initialStorageEntry","isPublished","locked","storageEntry","convertToStorageEntry","entityBatch","createEntryRevisionKeys","createEntryPublishedKeys","latestStorageEntry","updatingLatestRevision","createEntryLatestKeys","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","ex","WebinyError","DdbUpdateEntry","UpdateEntryStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;;AAyBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAc,2BACVC,YAAsB,EACtBC,MAAyC,EAC3C;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAI;YAC/DD;YACA,KAAK;gBAACD,OAAO,EAAE;aAAC;QACpB;QACA,OAAOE,MAAM,KAAK,MAAM;IAC5B;IAEA,MAAM,QACFH,YAAsB,EACtBC,MAAgD,EAClD;QACE,MAAM,EAAEG,KAAK,EAAE,cAAcC,mBAAmB,EAAE,GAAGJ;QACrD,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACF;QAEjD,MAAMM,cAAcF,AAAiB,gBAAjBA,MAAM,MAAM;QAChC,MAAMG,SAASD,cAAc,OAAOF,MAAM,MAAM;QAEhD,MAAMI,eAAeC,sBAAsB;YACvCP;YACA,cAAcG;QAClB;QAOA,MAAMK,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;YAC/C,KAAK;gBACD;oBACI,GAAGC,wBAAwBH,aAAa;oBACxC,MAAM;wBACF,GAAGA,YAAY;wBACfD;oBACJ;gBACJ;aACH;QACL;QAEA,IAAID,aACAI,YAAY,GAAG,CAAC;YACZ,GAAGE,yBAAyBJ,aAAa;YACzC,MAAM;gBACF,GAAGA,YAAY;gBACfD;YACJ;QACJ;QAMJ,MAAMM,qBAAqB,MAAM,IAAI,CAAC,0BAA0B,CAACX,OAAOE;QAExE,IAAIS,oBAAoB;YACpB,MAAMC,yBAAyBD,mBAAmB,EAAE,KAAKT,MAAM,EAAE;YACjE,IAAIU,wBACAJ,YAAY,GAAG,CAAC;gBACZ,GAAGK,sBAAsBP,aAAa;gBACtC,MAAM;oBACF,GAAGA,YAAY;oBACfD;gBACJ;YACJ;iBACG;gBAKH,MAAMS,8BAA8BC,oBAChCb,OACAc;gBAQJR,YAAY,GAAG,CAAC;oBACZ,GAAGC,wBAAwBE,mBAAmB;oBAC9C,MAAM;wBACF,GAAGA,kBAAkB;wBACrB,GAAGG,2BAA2B;oBAClC;gBACJ;gBAEAN,YAAY,GAAG,CAAC;oBACZ,GAAGK,sBAAsBF,mBAAmB;oBAC5C,MAAM;wBACF,GAAGA,kBAAkB;wBACrB,GAAGG,2BAA2B;oBAClC;gBACJ;YACJ;QACJ;QAEA,IAAI;YACA,MAAMN,YAAY,OAAO;YACzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQN,MAAM,MAAM;YACxB;YACA,OAAOC;QACX,EAAE,OAAOc,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,gBACX;gBACI,OAAOA;gBACPf;gBACAS;YACJ;QAER;IACJ;AACJ;AAEO,MAAMQ,iBAAiBC,4BAA4B,oBAAoB,CAAC;IAC3E,gBAAgB1B;IAChB,cAAc;QAAC2B;QAAmBC;QAAmBC;KAAwB;AACjF"}
@@ -2,11 +2,10 @@ import type DataLoader from "dataloader";
2
2
  export interface CacheKeyParams {
3
3
  name: string;
4
4
  tenant: string;
5
- locale: string;
5
+ modelId: string;
6
6
  }
7
7
  export interface ClearAllParams {
8
8
  tenant: string;
9
- locale: string;
10
9
  }
11
10
  export declare class DataLoaderCache {
12
11
  private readonly cache;
@@ -1,41 +1,27 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DataLoaderCache = void 0;
7
1
  class DataLoaderCache {
8
- cache = {};
9
- getDataLoader(params) {
10
- const key = this.createKey(params);
11
- return this.cache[key] || null;
12
- }
13
- setDataLoader(params, dataLoader) {
14
- const key = this.createKey(params);
15
- this.cache[key] = dataLoader;
16
- }
17
- clearAll(params) {
18
- if (!params) {
19
- for (const current in this.cache) {
20
- this.cache[current].clearAll();
21
- }
22
- return;
2
+ getDataLoader(params) {
3
+ const key = this.createKey(params);
4
+ return this.cache[key] || null;
5
+ }
6
+ setDataLoader(params, dataLoader) {
7
+ const key = this.createKey(params);
8
+ this.cache[key] = dataLoader;
9
+ }
10
+ clearAll(params) {
11
+ if (!params) {
12
+ for(const current in this.cache)this.cache[current].clearAll();
13
+ return;
14
+ }
15
+ const key = `${params.tenant}_`;
16
+ for(const current in this.cache)if (false !== current.startsWith(key)) this.cache[current].clearAll();
17
+ }
18
+ createKey(params) {
19
+ return `${params.tenant}_${params.modelId}_${params.name}`;
23
20
  }
24
- const key = this.createKey({
25
- ...params,
26
- name: ""
27
- });
28
- for (const current in this.cache) {
29
- if (current.startsWith(key) === false) {
30
- continue;
31
- }
32
- this.cache[current].clearAll();
21
+ constructor(){
22
+ this.cache = {};
33
23
  }
34
- }
35
- createKey(params) {
36
- return `${params.tenant}_${params.locale}_${params.name}`;
37
- }
38
24
  }
39
- exports.DataLoaderCache = DataLoaderCache;
25
+ export { DataLoaderCache };
40
26
 
41
27
  //# sourceMappingURL=DataLoaderCache.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["DataLoaderCache","cache","getDataLoader","params","key","createKey","setDataLoader","dataLoader","clearAll","current","name","startsWith","tenant","locale","exports"],"sources":["DataLoaderCache.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\n\nexport interface CacheKeyParams {\n name: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ClearAllParams {\n tenant: string;\n locale: string;\n}\n\nexport class DataLoaderCache {\n private readonly cache: Record<string, DataLoader<any, any>> = {};\n\n public getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null {\n const key = this.createKey(params);\n\n return this.cache[key] || null;\n }\n\n public setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void {\n const key = this.createKey(params);\n this.cache[key] = dataLoader;\n }\n\n public clearAll(params?: ClearAllParams): void {\n if (!params) {\n for (const current in this.cache) {\n this.cache[current].clearAll();\n }\n return;\n }\n const key = this.createKey({\n ...params,\n name: \"\"\n });\n for (const current in this.cache) {\n if (current.startsWith(key) === false) {\n continue;\n }\n this.cache[current].clearAll();\n }\n }\n\n private createKey(params: CacheKeyParams): string {\n return `${params.tenant}_${params.locale}_${params.name}`;\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,eAAe,CAAC;EACRC,KAAK,GAAyC,CAAC,CAAC;EAE1DC,aAAaA,CAAmBC,MAAsB,EAA2B;IACpF,MAAMC,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAElC,OAAO,IAAI,CAACF,KAAK,CAACG,GAAG,CAAC,IAAI,IAAI;EAClC;EAEOE,aAAaA,CAACH,MAAsB,EAAEI,UAAgC,EAAQ;IACjF,MAAMH,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAClC,IAAI,CAACF,KAAK,CAACG,GAAG,CAAC,GAAGG,UAAU;EAChC;EAEOC,QAAQA,CAACL,MAAuB,EAAQ;IAC3C,IAAI,CAACA,MAAM,EAAE;MACT,KAAK,MAAMM,OAAO,IAAI,IAAI,CAACR,KAAK,EAAE;QAC9B,IAAI,CAACA,KAAK,CAACQ,OAAO,CAAC,CAACD,QAAQ,CAAC,CAAC;MAClC;MACA;IACJ;IACA,MAAMJ,GAAG,GAAG,IAAI,CAACC,SAAS,CAAC;MACvB,GAAGF,MAAM;MACTO,IAAI,EAAE;IACV,CAAC,CAAC;IACF,KAAK,MAAMD,OAAO,IAAI,IAAI,CAACR,KAAK,EAAE;MAC9B,IAAIQ,OAAO,CAACE,UAAU,CAACP,GAAG,CAAC,KAAK,KAAK,EAAE;QACnC;MACJ;MACA,IAAI,CAACH,KAAK,CAACQ,OAAO,CAAC,CAACD,QAAQ,CAAC,CAAC;IAClC;EACJ;EAEQH,SAASA,CAACF,MAAsB,EAAU;IAC9C,OAAO,GAAGA,MAAM,CAACS,MAAM,IAAIT,MAAM,CAACU,MAAM,IAAIV,MAAM,CAACO,IAAI,EAAE;EAC7D;AACJ;AAACI,OAAA,CAAAd,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/dataLoader/DataLoaderCache.js","sources":["../../../../src/operations/entry/dataLoader/DataLoaderCache.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\n\nexport interface CacheKeyParams {\n name: string;\n tenant: string;\n modelId: string;\n}\n\nexport interface ClearAllParams {\n tenant: string;\n}\n\nexport class DataLoaderCache {\n private readonly cache: Record<string, DataLoader<any, any>> = {};\n\n public getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null {\n const key = this.createKey(params);\n\n return this.cache[key] || null;\n }\n\n public setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void {\n const key = this.createKey(params);\n this.cache[key] = dataLoader;\n }\n\n public clearAll(params?: ClearAllParams): void {\n if (!params) {\n for (const current in this.cache) {\n this.cache[current].clearAll();\n }\n return;\n }\n const key = `${params.tenant}_`;\n for (const current in this.cache) {\n if (current.startsWith(key) === false) {\n continue;\n }\n this.cache[current].clearAll();\n }\n }\n\n private createKey(params: CacheKeyParams): string {\n return `${params.tenant}_${params.modelId}_${params.name}`;\n }\n}\n"],"names":["DataLoaderCache","params","key","dataLoader","current"],"mappings":"AAYO,MAAMA;IAGF,cAAgCC,MAAsB,EAA2B;QACpF,MAAMC,MAAM,IAAI,CAAC,SAAS,CAACD;QAE3B,OAAO,IAAI,CAAC,KAAK,CAACC,IAAI,IAAI;IAC9B;IAEO,cAAcD,MAAsB,EAAEE,UAAgC,EAAQ;QACjF,MAAMD,MAAM,IAAI,CAAC,SAAS,CAACD;QAC3B,IAAI,CAAC,KAAK,CAACC,IAAI,GAAGC;IACtB;IAEO,SAASF,MAAuB,EAAQ;QAC3C,IAAI,CAACA,QAAQ;YACT,IAAK,MAAMG,WAAW,IAAI,CAAC,KAAK,CAC5B,IAAI,CAAC,KAAK,CAACA,QAAQ,CAAC,QAAQ;YAEhC;QACJ;QACA,MAAMF,MAAM,GAAGD,OAAO,MAAM,CAAC,CAAC,CAAC;QAC/B,IAAK,MAAMG,WAAW,IAAI,CAAC,KAAK,CAC5B,IAAIA,AAA4B,UAA5BA,QAAQ,UAAU,CAACF,MAGvB,IAAI,CAAC,KAAK,CAACE,QAAQ,CAAC,QAAQ;IAEpC;IAEQ,UAAUH,MAAsB,EAAU;QAC9C,OAAO,GAAGA,OAAO,MAAM,CAAC,CAAC,EAAEA,OAAO,OAAO,CAAC,CAAC,EAAEA,OAAO,IAAI,EAAE;IAC9D;;aA/BiB,KAAK,GAAyC,CAAC;;AAgCpE"}
@@ -1,10 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = void 0;
7
1
  const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || "0");
8
- const CMS_ENTRY_BATCH_SCHEDULE_WAIT = exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;
2
+ const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;
3
+ export { CMS_ENTRY_BATCH_SCHEDULE_WAIT };
9
4
 
10
5
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["batchScheduleWaitEnv","Number","process","env","WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT","CMS_ENTRY_BATCH_SCHEDULE_WAIT","exports","isNaN"],"sources":["constants.ts"],"sourcesContent":["const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || \"0\");\nexport const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;\n"],"mappings":";;;;;;AAAA,MAAMA,oBAAoB,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,wCAAwC,IAAI,GAAG,CAAC;AACzF,MAAMC,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAGE,KAAK,CAACP,oBAAoB,CAAC,GAAG,CAAC,GAAGA,oBAAoB","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/dataLoader/constants.js","sources":["../../../../src/operations/entry/dataLoader/constants.ts"],"sourcesContent":["const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || \"0\");\nexport const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;\n"],"names":["batchScheduleWaitEnv","Number","process","CMS_ENTRY_BATCH_SCHEDULE_WAIT","isNaN"],"mappings":"AAAA,MAAMA,uBAAuBC,OAAOC,QAAQ,GAAG,CAAC,wCAAwC,IAAI;AACrF,MAAMC,gCAAgCC,MAAMJ,wBAAwB,IAAIA"}
@@ -1,25 +1,10 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createBatchScheduleFn = void 0;
7
- var _constants = require("./constants");
8
- /**
9
- * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
10
- * Intended to be used internally or for a specific user case.
11
- * Not to be documented and exposed to publish as it can slow the data loading a lot.
12
- *
13
- * https://github.com/graphql/dataloader#batch-scheduling
14
- */
15
- const createBatchScheduleFn = () => {
16
- if (_constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {
17
- return undefined;
18
- }
19
- return callback => {
20
- setTimeout(callback, _constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT);
21
- };
1
+ import { CMS_ENTRY_BATCH_SCHEDULE_WAIT } from "./constants.js";
2
+ const createBatchScheduleFn = ()=>{
3
+ if (CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) return;
4
+ return (callback)=>{
5
+ setTimeout(callback, CMS_ENTRY_BATCH_SCHEDULE_WAIT);
6
+ };
22
7
  };
23
- exports.createBatchScheduleFn = createBatchScheduleFn;
8
+ export { createBatchScheduleFn };
24
9
 
25
10
  //# sourceMappingURL=createBatchScheduleFn.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_constants","require","createBatchScheduleFn","CMS_ENTRY_BATCH_SCHEDULE_WAIT","undefined","callback","setTimeout","exports"],"sources":["createBatchScheduleFn.ts"],"sourcesContent":["import { CMS_ENTRY_BATCH_SCHEDULE_WAIT } from \"./constants\";\n\n/**\n * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.\n * Intended to be used internally or for a specific user case.\n * Not to be documented and exposed to publish as it can slow the data loading a lot.\n *\n * https://github.com/graphql/dataloader#batch-scheduling\n */\nexport const createBatchScheduleFn = () => {\n if (CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {\n return undefined;\n }\n return (callback: () => void) => {\n setTimeout(callback, CMS_ENTRY_BATCH_SCHEDULE_WAIT);\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,IAAIC,wCAA6B,IAAI,CAAC,EAAE;IACpC,OAAOC,SAAS;EACpB;EACA,OAAQC,QAAoB,IAAK;IAC7BC,UAAU,CAACD,QAAQ,EAAEF,wCAA6B,CAAC;EACvD,CAAC;AACL,CAAC;AAACI,OAAA,CAAAL,qBAAA,GAAAA,qBAAA","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/dataLoader/createBatchScheduleFn.js","sources":["../../../../src/operations/entry/dataLoader/createBatchScheduleFn.ts"],"sourcesContent":["import { CMS_ENTRY_BATCH_SCHEDULE_WAIT } from \"./constants.js\";\n\n/**\n * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.\n * Intended to be used internally or for a specific user case.\n * Not to be documented and exposed to publish as it can slow the data loading a lot.\n *\n * https://github.com/graphql/dataloader#batch-scheduling\n */\nexport const createBatchScheduleFn = () => {\n if (CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {\n return undefined;\n }\n return (callback: () => void) => {\n setTimeout(callback, CMS_ENTRY_BATCH_SCHEDULE_WAIT);\n };\n};\n"],"names":["createBatchScheduleFn","CMS_ENTRY_BATCH_SCHEDULE_WAIT","callback","setTimeout"],"mappings":";AASO,MAAMA,wBAAwB;IACjC,IAAIC,iCAAiC,GACjC;IAEJ,OAAO,CAACC;QACJC,WAAWD,UAAUD;IACzB;AACJ"}
@@ -1,4 +1,4 @@
1
1
  import DataLoader from "dataloader";
2
- import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
- import type { DataLoaderParams } from "./types";
4
- export declare const createGetAllEntryRevisions: (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 createGetAllEntryRevisions: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
@@ -1,45 +1,24 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGetAllEntryRevisions = void 0;
8
- var _dataloader = _interopRequireDefault(require("dataloader"));
9
- var _query = require("@webiny/db-dynamodb/utils/query");
10
- var _keys = require("../keys");
11
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
12
- var _createBatchScheduleFn = require("./createBatchScheduleFn");
13
- const createGetAllEntryRevisions = params => {
14
- const {
15
- entity,
16
- locale,
17
- tenant
18
- } = params;
19
- return new _dataloader.default(async ids => {
20
- const results = {};
21
- for (const id of ids) {
22
- const queryAllParams = {
23
- entity,
24
- partitionKey: (0, _keys.createPartitionKey)({
25
- tenant,
26
- locale,
27
- id
28
- }),
29
- options: {
30
- beginsWith: "REV#"
31
- }
32
- };
33
- const items = await (0, _query.queryAll)(queryAllParams);
34
- results[id] = (0, _cleanup.cleanupItems)(entity, items);
35
- }
36
- return ids.map(id => {
37
- return results[id] || [];
1
+ import dataloader from "dataloader";
2
+ import { createPartitionKey } from "../keys.js";
3
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
4
+ const createGetAllEntryRevisions = (params)=>{
5
+ const { entity, tenant, modelId } = params;
6
+ return new dataloader(async (ids)=>{
7
+ const results = {};
8
+ for (const id of ids)results[id] = (await entity.queryAllClean({
9
+ partitionKey: createPartitionKey({
10
+ tenant,
11
+ id
12
+ }),
13
+ options: {
14
+ beginsWith: "REV#"
15
+ }
16
+ })).map((result)=>result.data);
17
+ return ids.map((id)=>(results[id] || []).filter((item)=>item.modelId === modelId));
18
+ }, {
19
+ batchScheduleFn: createBatchScheduleFn()
38
20
  });
39
- }, {
40
- batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
41
- });
42
21
  };
43
- exports.createGetAllEntryRevisions = createGetAllEntryRevisions;
22
+ export { createGetAllEntryRevisions };
44
23
 
45
24
  //# sourceMappingURL=getAllEntryRevisions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_dataloader","_interopRequireDefault","require","_query","_keys","_cleanup","_createBatchScheduleFn","createGetAllEntryRevisions","params","entity","locale","tenant","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getAllEntryRevisions.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport type { QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { createPartitionKey } from \"~/operations/entry/keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { DataLoaderParams } from \"./types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetAllEntryRevisions = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\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<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,sBAAA,GAAAJ,OAAA;AAEO,MAAMK,0BAA0B,GAAIC,MAAwB,IAAK;EACpE,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAA0C,GAAG,CAAC,CAAC;IACrD,KAAK,MAAMC,EAAE,IAAIF,GAAG,EAAE;MAClB,MAAMG,cAA8B,GAAG;QACnCP,MAAM;QACNQ,YAAY,EAAE,IAAAC,wBAAkB,EAAC;UAC7BP,MAAM;UACND,MAAM;UACNK;QACJ,CAAC,CAAC;QACFI,OAAO,EAAE;UACLC,UAAU,EAAE;QAChB;MACJ,CAAC;MACD,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAQ,EAAkBN,cAAc,CAAC;MAC7DF,OAAO,CAACC,EAAE,CAAC,GAAG,IAAAQ,qBAAY,EAACd,MAAM,EAAEY,KAAK,CAAC;IAC7C;IAEA,OAAOR,GAAG,CAACW,GAAG,CAACT,EAAE,IAAI;MACjB,OAAOD,OAAO,CAACC,EAAE,CAAC,IAAI,EAAE;IAC5B,CAAC,CAAC;EACN,CAAC,EACD;IACIU,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAApB,0BAAA,GAAAA,0BAAA","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/dataLoader/getAllEntryRevisions.js","sources":["../../../../src/operations/entry/dataLoader/getAllEntryRevisions.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createPartitionKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetAllEntryRevisions = (params: IDataLoaderParams) => {\n const { entity, tenant, modelId } = params;\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const results: Record<string, CmsStorageEntry[]> = {};\n\n for (const id of ids) {\n results[id] = (\n await entity.queryAllClean({\n partitionKey: createPartitionKey({\n tenant,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n })\n ).map(result => {\n return result.data;\n });\n }\n\n return ids.map(id => {\n return (results[id] || []).filter(item => {\n return item.modelId === modelId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"names":["createGetAllEntryRevisions","params","entity","tenant","modelId","DataLoader","ids","results","id","createPartitionKey","result","item","createBatchScheduleFn"],"mappings":";;;AAMO,MAAMA,6BAA6B,CAACC;IACvC,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IACpC,OAAO,IAAII,WACP,OAAMC;QACF,MAAMC,UAA6C,CAAC;QAEpD,KAAK,MAAMC,MAAMF,IACbC,OAAO,CAACC,GAAG,GACP,OAAMN,OAAO,aAAa,CAAC;YACvB,cAAcO,mBAAmB;gBAC7BN;gBACAK;YACJ;YACA,SAAS;gBACL,YAAY;YAChB;QACJ,EAAC,EACH,GAAG,CAACE,CAAAA,SACKA,OAAO,IAAI;QAI1B,OAAOJ,IAAI,GAAG,CAACE,CAAAA,KACHD,AAAAA,CAAAA,OAAO,CAACC,GAAG,IAAI,EAAC,EAAG,MAAM,CAACG,CAAAA,OACvBA,KAAK,OAAO,KAAKP;IAGpC,GACA;QACI,iBAAiBQ;IACrB;AAER"}
@@ -1,4 +1,4 @@
1
1
  import DataLoader from "dataloader";
2
- import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
- import type { DataLoaderParams } from "./types";
4
- export declare const createGetLatestRevisionByEntryId: (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 createGetLatestRevisionByEntryId: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
@@ -1,56 +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 _dbDynamodb = require("@webiny/db-dynamodb");
10
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
- var _createBatchScheduleFn = require("./createBatchScheduleFn");
12
- var _keys = require("../keys");
13
- var _utils = require("@webiny/utils");
14
- const createGetLatestRevisionByEntryId = params => {
15
- const {
16
- entity,
17
- locale,
18
- tenant
19
- } = params;
20
- const latestKey = (0, _keys.createLatestSortKey)();
21
- return new _dataloader.default(async ids => {
22
- const queries = ids.reduce((collection, id) => {
23
- const partitionKey = (0, _keys.createPartitionKey)({
24
- tenant,
25
- locale,
26
- id
27
- });
28
- if (collection[partitionKey]) {
29
- return collection;
30
- }
31
- collection[partitionKey] = entity.getBatch({
32
- PK: partitionKey,
33
- SK: latestKey
34
- });
35
- return collection;
36
- }, {});
37
- const records = await (0, _dbDynamodb.batchReadAll)({
38
- table: entity.table,
39
- items: Object.values(queries)
40
- });
41
- const items = (0, _cleanup.cleanupItems)(entity, records);
42
- return ids.map(id => {
43
- const {
44
- id: entryId
45
- } = (0, _utils.parseIdentifier)(id);
46
- return items.filter(item => {
47
- return entryId === item.entryId;
48
- });
1
+ import dataloader from "dataloader";
2
+ import { cleanupItems } from "@webiny/db-dynamodb/utils/cleanup.js";
3
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
4
+ import { createLatestSortKey, createPartitionKey } from "../keys.js";
5
+ import { parseIdentifier } from "@webiny/utils";
6
+ const createGetLatestRevisionByEntryId = (params)=>{
7
+ const { entity, tenant, modelId } = params;
8
+ const latestKey = createLatestSortKey();
9
+ return new dataloader(async (ids)=>{
10
+ const reader = entity.createEntityReader();
11
+ const keys = new Set();
12
+ for (const id of ids){
13
+ const partitionKey = createPartitionKey({
14
+ tenant,
15
+ id
16
+ });
17
+ if (!keys.has(partitionKey)) {
18
+ keys.add(partitionKey);
19
+ reader.get({
20
+ PK: partitionKey,
21
+ SK: latestKey
22
+ });
23
+ }
24
+ }
25
+ const records = await reader.execute();
26
+ const items = cleanupItems(entity.entity, records).map((item)=>item.data);
27
+ return ids.map((id)=>{
28
+ const { id: entryId } = parseIdentifier(id);
29
+ return items.filter((item)=>{
30
+ if (item.modelId !== modelId) return false;
31
+ return entryId === item.entryId;
32
+ });
33
+ });
34
+ }, {
35
+ batchScheduleFn: createBatchScheduleFn()
49
36
  });
50
- }, {
51
- batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
52
- });
53
37
  };
54
- exports.createGetLatestRevisionByEntryId = createGetLatestRevisionByEntryId;
38
+ export { createGetLatestRevisionByEntryId };
55
39
 
56
40
  //# sourceMappingURL=getLatestRevisionByEntryId.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_dataloader","_interopRequireDefault","require","_dbDynamodb","_cleanup","_createBatchScheduleFn","_keys","_utils","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","parseIdentifier","filter","item","batchScheduleFn","createBatchScheduleFn","exports"],"sources":["getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\nimport { createLatestSortKey, createPartitionKey } from \"~/operations/entry/keys\";\nimport type { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\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, any>>((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 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 const { id: entryId } = parseIdentifier(id);\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,WAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAEO,MAAMM,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,CAAsB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChE,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,EAAE,CAAC,CAAC,CAAC;IAEN,MAAMO,OAAO,GAAG,MAAM,IAAAC,wBAAY,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,CAACb,EAAE,IAAI;MACjB,MAAM;QAAEA,EAAE,EAAEc;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACf,EAAE,CAAC;MAC3C,OAAOS,KAAK,CAACO,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,eAAe,EAAE,IAAAC,4CAAqB,EAAC;EAC3C,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAhC,gCAAA,GAAAA,gCAAA","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/dataLoader/getLatestRevisionByEntryId.js","sources":["../../../../src/operations/entry/dataLoader/getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup.js\";\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\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const createGetLatestRevisionByEntryId = (params: IDataLoaderParams) => {\n const { entity, tenant, modelId } = 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\n reader.get({\n PK: partitionKey,\n SK: latestKey\n });\n }\n\n const records = await reader.execute();\n const items = cleanupItems(entity.entity, records).map(item => {\n return item.data;\n });\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n if (item.modelId !== modelId) {\n return false;\n }\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"names":["createGetLatestRevisionByEntryId","params","entity","tenant","modelId","latestKey","createLatestSortKey","DataLoader","ids","reader","keys","Set","id","partitionKey","createPartitionKey","records","items","cleanupItems","item","entryId","parseIdentifier","createBatchScheduleFn"],"mappings":";;;;;AAQO,MAAMA,mCAAmC,CAACC;IAC7C,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAEpC,MAAMI,YAAYC;IAElB,OAAO,IAAIC,WACP,OAAMC;QACF,MAAMC,SAASP,OAAO,kBAAkB;QAExC,MAAMQ,OAAO,IAAIC;QAEjB,KAAK,MAAMC,MAAMJ,IAAK;YAClB,MAAMK,eAAeC,mBAAmB;gBACpCX;gBACAS;YACJ;YACA,KAAIF,KAAK,GAAG,CAACG;gBAGbH,KAAK,GAAG,CAACG;gBAETJ,OAAO,GAAG,CAAC;oBACP,IAAII;oBACJ,IAAIR;gBACR;;QACJ;QAEA,MAAMU,UAAU,MAAMN,OAAO,OAAO;QACpC,MAAMO,QAAQC,aAAaf,OAAO,MAAM,EAAEa,SAAS,GAAG,CAACG,CAAAA,OAC5CA,KAAK,IAAI;QAGpB,OAAOV,IAAI,GAAG,CAACI,CAAAA;YACX,MAAM,EAAE,IAAIO,OAAO,EAAE,GAAGC,gBAAgBR;YACxC,OAAOI,MAAM,MAAM,CAACE,CAAAA;gBAChB,IAAIA,KAAK,OAAO,KAAKd,SACjB,OAAO;gBAEX,OAAOe,YAAYD,KAAK,OAAO;YACnC;QACJ;IACJ,GACA;QACI,iBAAiBG;IACrB;AAER"}
@@ -1,4 +1,4 @@
1
1
  import DataLoader from "dataloader";
2
- import type { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
- import type { 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,56 +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 _dbDynamodb = require("@webiny/db-dynamodb");
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 createGetPublishedRevisionByEntryId = params => {
15
- const {
16
- entity,
17
- locale,
18
- tenant
19
- } = params;
20
- const publishedKey = (0, _keys.createPublishedSortKey)();
21
- return new _dataloader.default(async ids => {
22
- const queries = ids.reduce((collection, id) => {
23
- const partitionKey = (0, _keys.createPartitionKey)({
24
- tenant,
25
- locale,
26
- id
27
- });
28
- if (collection[partitionKey]) {
29
- return collection;
30
- }
31
- collection[partitionKey] = entity.getBatch({
32
- PK: partitionKey,
33
- SK: publishedKey
34
- });
35
- return collection;
36
- }, {});
37
- const records = await (0, _dbDynamodb.batchReadAll)({
38
- table: entity.table,
39
- items: Object.values(queries)
40
- });
41
- const items = (0, _cleanup.cleanupItems)(entity, records);
42
- return ids.map(id => {
43
- const {
44
- id: entryId
45
- } = (0, _utils.parseIdentifier)(id);
46
- return items.filter(item => {
47
- return entryId === item.entryId;
48
- });
1
+ import dataloader from "dataloader";
2
+ import { cleanupItems } from "@webiny/db-dynamodb/utils/cleanup.js";
3
+ import { createPartitionKey, createPublishedSortKey } from "../keys.js";
4
+ import { parseIdentifier } from "@webiny/utils";
5
+ import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
6
+ const createGetPublishedRevisionByEntryId = (params)=>{
7
+ const { entity, tenant, modelId } = params;
8
+ const publishedKey = createPublishedSortKey();
9
+ return new dataloader(async (ids)=>{
10
+ const reader = entity.createEntityReader();
11
+ const keys = new Set();
12
+ for (const id of ids){
13
+ const partitionKey = createPartitionKey({
14
+ tenant,
15
+ id
16
+ });
17
+ if (!keys.has(partitionKey)) {
18
+ keys.add(partitionKey);
19
+ reader.get({
20
+ PK: partitionKey,
21
+ SK: publishedKey
22
+ });
23
+ }
24
+ }
25
+ const records = await reader.execute();
26
+ const items = cleanupItems(entity.entity, records).map((item)=>item.data);
27
+ return ids.map((id)=>{
28
+ const { id: entryId } = parseIdentifier(id);
29
+ return items.filter((item)=>{
30
+ if (item.modelId !== modelId) return false;
31
+ return entryId === item.entryId;
32
+ });
33
+ });
34
+ }, {
35
+ batchScheduleFn: createBatchScheduleFn()
49
36
  });
50
- }, {
51
- batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
52
- });
53
37
  };
54
- exports.createGetPublishedRevisionByEntryId = createGetPublishedRevisionByEntryId;
38
+ export { createGetPublishedRevisionByEntryId };
55
39
 
56
40
  //# sourceMappingURL=getPublishedRevisionByEntryId.js.map