@webiny/api-headless-cms-ddb 0.0.0-mt-2 → 0.0.0-unstable.0156a4c312

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 (215) 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 +6 -6
  18. package/definitions/entry.js +9 -95
  19. package/definitions/entry.js.map +1 -0
  20. package/definitions/group.d.ts +6 -6
  21. package/definitions/group.js +9 -72
  22. package/definitions/group.js.map +1 -0
  23. package/definitions/model.d.ts +6 -6
  24. package/definitions/model.js +9 -94
  25. package/definitions/model.js.map +1 -0
  26. package/definitions/table.d.ts +6 -7
  27. package/definitions/table.js +8 -30
  28. package/definitions/table.js.map +1 -0
  29. package/definitions/types.d.ts +65 -0
  30. package/definitions/types.js +0 -0
  31. package/index.d.ts +10 -2
  32. package/index.js +45 -123
  33. package/index.js.map +1 -0
  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 +16 -0
  101. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  102. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  103. package/operations/entry/dataLoader/constants.d.ts +1 -0
  104. package/operations/entry/dataLoader/constants.js +5 -0
  105. package/operations/entry/dataLoader/constants.js.map +1 -0
  106. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  107. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  108. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  109. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  110. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  111. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  112. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  113. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
  114. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  115. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  116. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
  117. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  118. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  119. package/operations/entry/dataLoader/getRevisionById.js +42 -0
  120. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  121. package/operations/entry/dataLoader/index.d.ts +8 -0
  122. package/operations/entry/dataLoader/index.js +18 -0
  123. package/operations/entry/dataLoader/index.js.map +1 -0
  124. package/operations/entry/dataLoader/types.d.ts +6 -0
  125. package/operations/entry/dataLoader/types.js +0 -0
  126. package/operations/entry/dataLoaders.d.ts +20 -31
  127. package/operations/entry/dataLoaders.js +91 -296
  128. package/operations/entry/dataLoaders.js.map +1 -0
  129. package/operations/entry/feature.d.ts +4 -0
  130. package/operations/entry/feature.js +55 -0
  131. package/operations/entry/feature.js.map +1 -0
  132. package/operations/entry/keys.d.ts +46 -2
  133. package/operations/entry/keys.js +53 -55
  134. package/operations/entry/keys.js.map +1 -0
  135. package/operations/entry/storageEntryUtils.d.ts +8 -0
  136. package/operations/entry/storageEntryUtils.js +25 -0
  137. package/operations/entry/storageEntryUtils.js.map +1 -0
  138. package/operations/group/DdbCreateGroup.d.ts +12 -0
  139. package/operations/group/DdbCreateGroup.js +35 -0
  140. package/operations/group/DdbCreateGroup.js.map +1 -0
  141. package/operations/group/DdbDeleteGroup.d.ts +12 -0
  142. package/operations/group/DdbDeleteGroup.js +31 -0
  143. package/operations/group/DdbDeleteGroup.js.map +1 -0
  144. package/operations/group/DdbGetGroup.d.ts +12 -0
  145. package/operations/group/DdbGetGroup.js +31 -0
  146. package/operations/group/DdbGetGroup.js.map +1 -0
  147. package/operations/group/DdbListGroups.d.ts +14 -0
  148. package/operations/group/DdbListGroups.js +52 -0
  149. package/operations/group/DdbListGroups.js.map +1 -0
  150. package/operations/group/DdbUpdateGroup.d.ts +12 -0
  151. package/operations/group/DdbUpdateGroup.js +35 -0
  152. package/operations/group/DdbUpdateGroup.js.map +1 -0
  153. package/operations/group/feature.d.ts +4 -0
  154. package/operations/group/feature.js +19 -0
  155. package/operations/group/feature.js.map +1 -0
  156. package/operations/group/keys.d.ts +15 -0
  157. package/operations/group/keys.js +17 -0
  158. package/operations/group/keys.js.map +1 -0
  159. package/operations/model/DdbCreateModel.d.ts +12 -0
  160. package/operations/model/DdbCreateModel.js +37 -0
  161. package/operations/model/DdbCreateModel.js.map +1 -0
  162. package/operations/model/DdbDeleteModel.d.ts +12 -0
  163. package/operations/model/DdbDeleteModel.js +31 -0
  164. package/operations/model/DdbDeleteModel.js.map +1 -0
  165. package/operations/model/DdbGetModel.d.ts +12 -0
  166. package/operations/model/DdbGetModel.js +30 -0
  167. package/operations/model/DdbGetModel.js.map +1 -0
  168. package/operations/model/DdbListModels.d.ts +12 -0
  169. package/operations/model/DdbListModels.js +36 -0
  170. package/operations/model/DdbListModels.js.map +1 -0
  171. package/operations/model/DdbUpdateModel.d.ts +12 -0
  172. package/operations/model/DdbUpdateModel.js +36 -0
  173. package/operations/model/DdbUpdateModel.js.map +1 -0
  174. package/operations/model/feature.d.ts +4 -0
  175. package/operations/model/feature.js +19 -0
  176. package/operations/model/feature.js.map +1 -0
  177. package/operations/model/keys.d.ts +15 -0
  178. package/operations/model/keys.js +16 -0
  179. package/operations/model/keys.js.map +1 -0
  180. package/package.json +30 -34
  181. package/types.d.ts +12 -76
  182. package/types.js +8 -15
  183. package/types.js.map +1 -0
  184. package/definitions/settings.d.ts +0 -8
  185. package/definitions/settings.js +0 -62
  186. package/definitions/system.d.ts +0 -8
  187. package/definitions/system.js +0 -50
  188. package/dynamoDb/index.d.ts +0 -2
  189. package/dynamoDb/index.js +0 -24
  190. package/dynamoDb/path/plainObject.d.ts +0 -3
  191. package/dynamoDb/path/plainObject.js +0 -33
  192. package/dynamoDb/path/ref.d.ts +0 -3
  193. package/dynamoDb/path/ref.js +0 -27
  194. package/dynamoDb/storage/date.d.ts +0 -3
  195. package/dynamoDb/storage/date.js +0 -65
  196. package/dynamoDb/storage/longText.d.ts +0 -7
  197. package/dynamoDb/storage/longText.js +0 -83
  198. package/dynamoDb/storage/richText.d.ts +0 -8
  199. package/dynamoDb/storage/richText.js +0 -110
  200. package/dynamoDb/transformValue/datetime.d.ts +0 -3
  201. package/dynamoDb/transformValue/datetime.js +0 -47
  202. package/operations/entry/index.d.ts +0 -8
  203. package/operations/entry/index.js +0 -823
  204. package/operations/entry/systemFields.d.ts +0 -2
  205. package/operations/entry/systemFields.js +0 -50
  206. package/operations/entry/utils.d.ts +0 -31
  207. package/operations/entry/utils.js +0 -406
  208. package/operations/group/index.d.ts +0 -8
  209. package/operations/group/index.js +0 -198
  210. package/operations/model/index.d.ts +0 -6
  211. package/operations/model/index.js +0 -161
  212. package/operations/settings/index.d.ts +0 -6
  213. package/operations/settings/index.js +0 -141
  214. package/operations/system/index.d.ts +0 -6
  215. package/operations/system/index.js +0 -105
@@ -1,303 +1,98 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.DataLoadersHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _dataloader = _interopRequireDefault(require("dataloader"));
13
-
14
- var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- var _query = require("@webiny/db-dynamodb/utils/query");
17
-
18
- var _keys = require("./keys");
19
-
20
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
21
-
22
- var _utils = require("@webiny/utils");
23
-
24
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
25
-
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
27
-
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
-
30
- const getAllEntryRevisions = params => {
31
- const {
32
- entity,
33
- model
34
- } = params;
35
- const {
36
- tenant,
37
- locale
38
- } = model;
39
- return new _dataloader.default(async ids => {
40
- const results = [];
41
-
42
- for (const id of ids) {
43
- const queryAllParams = {
44
- entity,
45
- partitionKey: (0, _keys.createPartitionKey)({
46
- tenant,
47
- locale,
48
- id
49
- }),
50
- options: {
51
- beginsWith: "REV#"
52
- }
53
- };
54
- const items = await (0, _query.queryAll)(queryAllParams);
55
- const entries = (0, _cleanup.cleanupItems)(entity, items);
56
- results.push(entries);
1
+ import error from "@webiny/error";
2
+ import { DataLoaderCache } from "./dataLoader/DataLoaderCache.js";
3
+ import { getDataLoaderFactory } from "./dataLoader/index.js";
4
+ import { parseIdentifier } from "@webiny/utils";
5
+ import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
6
+ import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
7
+ class DataLoadersHandlerImpl {
8
+ constructor(entity){
9
+ this.entity = entity;
10
+ this.cache = new DataLoaderCache();
57
11
  }
58
-
59
- return results;
60
- });
61
- };
62
-
63
- const getRevisionById = params => {
64
- const {
65
- entity,
66
- model
67
- } = params;
68
- const {
69
- locale,
70
- tenant
71
- } = model;
72
- return new _dataloader.default(async ids => {
73
- const queries = ids.reduce((collection, id) => {
74
- const partitionKey = (0, _keys.createPartitionKey)({
75
- tenant,
76
- locale,
77
- id
78
- });
79
- const {
80
- version
81
- } = (0, _utils.parseIdentifier)(id);
82
- const sortKey = (0, _keys.createRevisionSortKey)({
83
- version
84
- });
85
- const keys = `${partitionKey}__${sortKey}`;
86
-
87
- if (collection[keys]) {
88
- return collection;
89
- }
90
-
91
- collection[keys] = entity.getBatch({
92
- PK: partitionKey,
93
- SK: sortKey
94
- });
95
- return collection;
96
- }, {});
97
- const records = await (0, _batchRead.batchReadAll)({
98
- table: entity.table,
99
- items: Object.values(queries)
100
- });
101
- const items = (0, _cleanup.cleanupItems)(entity, records);
102
- return ids.map(id => {
103
- return items.filter(item => {
104
- return id === item.id;
105
- });
106
- });
107
- });
108
- };
109
-
110
- const getPublishedRevisionByEntryId = params => {
111
- const {
112
- entity,
113
- model
114
- } = params;
115
- const {
116
- locale,
117
- tenant
118
- } = model;
119
- const publishedKey = (0, _keys.createPublishedSortKey)();
120
- return new _dataloader.default(async ids => {
121
- const queries = ids.reduce((collection, id) => {
122
- const partitionKey = (0, _keys.createPartitionKey)({
123
- tenant,
124
- locale,
125
- id
126
- });
127
-
128
- if (collection[partitionKey]) {
129
- return collection;
130
- }
131
-
132
- collection[partitionKey] = entity.getBatch({
133
- PK: partitionKey,
134
- SK: publishedKey
135
- });
136
- return collection;
137
- }, {});
138
- const records = await (0, _batchRead.batchReadAll)({
139
- table: entity.table,
140
- items: Object.values(queries)
141
- });
142
- const items = (0, _cleanup.cleanupItems)(entity, records);
143
- return ids.map(id => {
144
- const {
145
- id: entryId
146
- } = (0, _utils.parseIdentifier)(id);
147
- return items.filter(item => {
148
- return entryId === item.entryId;
149
- });
150
- });
151
- });
152
- };
153
-
154
- const getLatestRevisionByEntryId = params => {
155
- const {
156
- entity,
157
- model
158
- } = params;
159
- const {
160
- locale,
161
- tenant
162
- } = model;
163
- const latestKey = (0, _keys.createLatestSortKey)();
164
- return new _dataloader.default(async ids => {
165
- const queries = ids.reduce((collection, id) => {
166
- const partitionKey = (0, _keys.createPartitionKey)({
167
- tenant,
168
- locale,
169
- id
170
- });
171
-
172
- if (collection[partitionKey]) {
173
- return collection;
174
- }
175
-
176
- collection[partitionKey] = entity.getBatch({
177
- PK: partitionKey,
178
- SK: latestKey
179
- });
180
- return collection;
181
- }, {});
182
- const records = await (0, _batchRead.batchReadAll)({
183
- table: entity.table,
184
- items: Object.values(queries)
185
- });
186
- const items = (0, _cleanup.cleanupItems)(entity, records);
187
- return ids.map(id => {
188
- const {
189
- id: entryId
190
- } = (0, _utils.parseIdentifier)(id);
191
- return items.filter(item => {
192
- return entryId === item.entryId;
193
- });
194
- });
195
- });
196
- };
197
-
198
- const dataLoaders = {
199
- getAllEntryRevisions,
200
- getRevisionById,
201
- getPublishedRevisionByEntryId,
202
- getLatestRevisionByEntryId
203
- };
204
- const loaderNames = Object.keys(dataLoaders);
205
-
206
- class DataLoadersHandler {
207
- constructor(params) {
208
- (0, _defineProperty2.default)(this, "loaders", new Map());
209
- (0, _defineProperty2.default)(this, "entity", void 0);
210
- this.entity = params.entity;
211
- }
212
-
213
- async getAllEntryRevisions(params) {
214
- return await this.loadMany("getAllEntryRevisions", params, params.ids);
215
- }
216
-
217
- async getRevisionById(params) {
218
- return await this.loadMany("getRevisionById", params, params.ids);
219
- }
220
-
221
- async getPublishedRevisionByEntryId(params) {
222
- return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
223
- }
224
-
225
- async getLatestRevisionByEntryId(params) {
226
- return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
227
- }
228
-
229
- getLoader(name, params) {
230
- if (!dataLoaders[name]) {
231
- throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
232
- name
233
- });
12
+ async getAllEntryRevisions(params) {
13
+ const ids = params.ids.map((id)=>{
14
+ const { id: entryId } = parseIdentifier(id);
15
+ return entryId;
16
+ });
17
+ return await this.loadMany("getAllEntryRevisions", params, ids);
234
18
  }
235
-
236
- const {
237
- model
238
- } = params;
239
- const {
240
- tenant,
241
- locale
242
- } = model;
243
- const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
244
-
245
- if (!this.loaders.has(loaderKey)) {
246
- this.loaders.set(loaderKey, dataLoaders[name](_objectSpread(_objectSpread({}, params), {}, {
247
- entity: this.entity
248
- })));
19
+ async getRevisionById(params) {
20
+ return await this.loadMany("getRevisionById", params, params.ids);
249
21
  }
250
-
251
- return this.loaders.get(loaderKey);
252
- }
253
-
254
- async loadMany(loader, params, ids) {
255
- let results;
256
-
257
- try {
258
- results = await this.getLoader(loader, params).loadMany(ids);
259
-
260
- if (Array.isArray(results) === true) {
261
- return results.reduce((acc, res) => {
262
- if (Array.isArray(res) === false) {
263
- if (res && res.message) {
264
- throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
265
- data: JSON.stringify(res.data || {})
266
- }));
267
- }
268
-
269
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", _objectSpread(_objectSpread({}, params), {}, {
270
- loader
271
- }));
272
- }
273
-
274
- acc.push(...res);
275
- return acc;
276
- }, []);
277
- }
278
- } catch (ex) {
279
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
280
- error: ex
281
- }, params), {}, {
282
- loader,
283
- ids
284
- }));
22
+ async getPublishedRevisionByEntryId(params) {
23
+ const ids = params.ids.map((id)=>{
24
+ const { id: entryId } = parseIdentifier(id);
25
+ return entryId;
26
+ });
27
+ return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
285
28
  }
286
-
287
- throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
288
- loader,
289
- ids,
290
- results
291
- });
292
- }
293
-
294
- clearAll(params) {
295
- for (const name of loaderNames) {
296
- const loader = this.getLoader(name, params);
297
- loader.clearAll();
29
+ async getLatestRevisionByEntryId(params) {
30
+ const ids = params.ids.map((id)=>{
31
+ const { id: entryId } = parseIdentifier(id);
32
+ return entryId;
33
+ });
34
+ return await this.loadMany("getLatestRevisionByEntryId", params, ids);
35
+ }
36
+ getLoader(name, params) {
37
+ const { model } = params;
38
+ const cacheParams = {
39
+ tenant: model.tenant,
40
+ modelId: model.modelId,
41
+ name
42
+ };
43
+ let loader = this.cache.getDataLoader(cacheParams);
44
+ if (loader) return loader;
45
+ const factory = getDataLoaderFactory(name);
46
+ loader = factory({
47
+ entity: this.entity,
48
+ tenant: model.tenant,
49
+ modelId: model.modelId
50
+ });
51
+ this.cache.setDataLoader(cacheParams, loader);
52
+ return loader;
53
+ }
54
+ async loadMany(loader, params, ids) {
55
+ let results = [];
56
+ try {
57
+ results = await this.getLoader(loader, params).loadMany(ids);
58
+ if (true === Array.isArray(results)) return results.reduce((acc, res)=>{
59
+ if (false === Array.isArray(res)) {
60
+ if (res && res.message) throw new error(res.message, res.code, {
61
+ ...res,
62
+ data: JSON.stringify(res.data || {})
63
+ });
64
+ throw new error("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
65
+ ...params,
66
+ loader
67
+ });
68
+ }
69
+ acc.push(...res);
70
+ return acc;
71
+ }, []);
72
+ } catch (ex) {
73
+ throw new error(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
74
+ error: ex,
75
+ ...params,
76
+ loader,
77
+ ids
78
+ });
79
+ }
80
+ throw new error("Data loader did not return array of items or empty array.", "INVALID_DATA_LOADER_RESULT", {
81
+ loader,
82
+ ids,
83
+ results
84
+ });
85
+ }
86
+ clearAll(params) {
87
+ this.cache.clearAll(params);
298
88
  }
299
- }
300
-
301
89
  }
90
+ const DataLoadersHandler = CmsDdbDataLoaders.createImplementation({
91
+ implementation: DataLoadersHandlerImpl,
92
+ dependencies: [
93
+ CmsDdbEntryEntity
94
+ ]
95
+ });
96
+ export { DataLoadersHandler };
302
97
 
303
- exports.DataLoadersHandler = DataLoadersHandler;
98
+ //# sourceMappingURL=dataLoaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/dataLoaders.js","sources":["../../../src/operations/entry/dataLoaders.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport type {\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CacheKeyParams } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport { DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport type { DataLoaders } from \"~/operations/entry/dataLoader/index.js\";\nimport { getDataLoaderFactory } from \"~/operations/entry/dataLoader/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler } from \"~/types.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { CmsDdbDataLoaders } from \"~/abstractions/CmsDdbDataLoaders.js\";\n\ninterface DataLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n ids: readonly string[];\n}\n\ninterface GetLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n}\n\nclass DataLoadersHandlerImpl implements IDataLoadersHandler {\n private readonly cache = new DataLoaderCache();\n\n public constructor(private readonly entity: CmsDdbEntryEntity.Interface) {}\n\n public async getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getAllEntryRevisions\", params, ids);\n }\n\n public async getRevisionById<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n return await this.loadMany<T>(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getPublishedRevisionByEntryId\", params, ids);\n }\n\n public async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getLatestRevisionByEntryId\", params, ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: DataLoaders, params: GetLoaderParams): DataLoader<any, any> {\n const { model } = params;\n const cacheParams: CacheKeyParams = {\n tenant: model.tenant,\n modelId: model.modelId,\n name\n };\n let loader = this.cache.getDataLoader(cacheParams);\n if (loader) {\n return loader;\n }\n const factory = getDataLoaderFactory(name);\n loader = factory({\n entity: this.entity,\n tenant: model.tenant,\n modelId: model.modelId\n });\n this.cache.setDataLoader(cacheParams, loader);\n return loader;\n }\n\n private async loadMany<T extends CmsEntryValues = CmsEntryValues>(\n loader: DataLoaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry<T>[]> {\n let results: any[] = [];\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void {\n this.cache.clearAll(params);\n }\n}\n\nexport const DataLoadersHandler = CmsDdbDataLoaders.createImplementation({\n implementation: DataLoadersHandlerImpl,\n dependencies: [CmsDdbEntryEntity]\n});\n"],"names":["DataLoadersHandlerImpl","entity","DataLoaderCache","params","ids","id","entryId","parseIdentifier","name","model","cacheParams","loader","factory","getDataLoaderFactory","results","Array","acc","res","WebinyError","JSON","ex","DataLoadersHandler","CmsDdbDataLoaders","CmsDdbEntryEntity"],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ export declare const DdbEntryStorageOpsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,55 @@
1
+ import { createFeature } from "@webiny/feature/api/index.js";
2
+ import { DataLoadersHandler } from "./dataLoaders.js";
3
+ import { DdbCreateEntry } from "./DdbCreateEntry.js";
4
+ import { DdbCreateEntryRevisionFrom } from "./DdbCreateEntryRevisionFrom.js";
5
+ import { DdbUpdateEntry } from "./DdbUpdateEntry.js";
6
+ import { DdbMoveEntry } from "./DdbMoveEntry.js";
7
+ import { DdbMoveToBin } from "./DdbMoveToBin.js";
8
+ import { DdbDeleteEntry } from "./DdbDeleteEntry.js";
9
+ import { DdbRestoreFromBin } from "./DdbRestoreFromBin.js";
10
+ import { DdbDeleteEntryRevision } from "./DdbDeleteEntryRevision.js";
11
+ import { DdbDeleteMultipleEntries } from "./DdbDeleteMultipleEntries.js";
12
+ import { DdbGetEntry } from "./DdbGetEntry.js";
13
+ import { DdbListEntries } from "./DdbListEntries.js";
14
+ import { DdbPublishEntry } from "./DdbPublishEntry.js";
15
+ import { DdbUnpublishEntry } from "./DdbUnpublishEntry.js";
16
+ import { DdbGetEntriesByIds } from "./DdbGetEntriesByIds.js";
17
+ import { DdbGetLatestEntriesByIds } from "./DdbGetLatestEntriesByIds.js";
18
+ import { DdbGetPublishedEntriesByIds } from "./DdbGetPublishedEntriesByIds.js";
19
+ import { DdbGetRevisions } from "./DdbGetRevisions.js";
20
+ import { DdbGetRevisionById } from "./DdbGetRevisionById.js";
21
+ import { DdbGetLatestRevisionByEntryId } from "./DdbGetLatestRevisionByEntryId.js";
22
+ import { DdbGetPublishedRevisionByEntryId } from "./DdbGetPublishedRevisionByEntryId.js";
23
+ import { DdbGetPreviousRevision } from "./DdbGetPreviousRevision.js";
24
+ import { DdbGetUniqueFieldValues } from "./DdbGetUniqueFieldValues.js";
25
+ const DdbEntryStorageOpsFeature = createFeature({
26
+ name: "cms.ddb.entryStorageOps",
27
+ register: (container)=>{
28
+ container.register(DataLoadersHandler).inContainerScope();
29
+ container.register(DdbCreateEntry);
30
+ container.register(DdbCreateEntryRevisionFrom);
31
+ container.register(DdbUpdateEntry);
32
+ container.register(DdbMoveEntry);
33
+ container.register(DdbMoveToBin);
34
+ container.register(DdbDeleteEntry);
35
+ container.register(DdbRestoreFromBin);
36
+ container.register(DdbDeleteEntryRevision);
37
+ container.register(DdbDeleteMultipleEntries);
38
+ container.register(DdbGetEntry);
39
+ container.register(DdbListEntries);
40
+ container.register(DdbPublishEntry);
41
+ container.register(DdbUnpublishEntry);
42
+ container.register(DdbGetEntriesByIds);
43
+ container.register(DdbGetLatestEntriesByIds);
44
+ container.register(DdbGetPublishedEntriesByIds);
45
+ container.register(DdbGetRevisions);
46
+ container.register(DdbGetRevisionById);
47
+ container.register(DdbGetLatestRevisionByEntryId);
48
+ container.register(DdbGetPublishedRevisionByEntryId);
49
+ container.register(DdbGetPreviousRevision);
50
+ container.register(DdbGetUniqueFieldValues);
51
+ }
52
+ });
53
+ export { DdbEntryStorageOpsFeature };
54
+
55
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/feature.js","sources":["../../../src/operations/entry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DataLoadersHandler } from \"./dataLoaders.js\";\nimport { DdbCreateEntry } from \"./DdbCreateEntry.js\";\nimport { DdbCreateEntryRevisionFrom } from \"./DdbCreateEntryRevisionFrom.js\";\nimport { DdbUpdateEntry } from \"./DdbUpdateEntry.js\";\nimport { DdbMoveEntry } from \"./DdbMoveEntry.js\";\nimport { DdbMoveToBin } from \"./DdbMoveToBin.js\";\nimport { DdbDeleteEntry } from \"./DdbDeleteEntry.js\";\nimport { DdbRestoreFromBin } from \"./DdbRestoreFromBin.js\";\nimport { DdbDeleteEntryRevision } from \"./DdbDeleteEntryRevision.js\";\nimport { DdbDeleteMultipleEntries } from \"./DdbDeleteMultipleEntries.js\";\nimport { DdbGetEntry } from \"./DdbGetEntry.js\";\nimport { DdbListEntries } from \"./DdbListEntries.js\";\nimport { DdbPublishEntry } from \"./DdbPublishEntry.js\";\nimport { DdbUnpublishEntry } from \"./DdbUnpublishEntry.js\";\nimport { DdbGetEntriesByIds } from \"./DdbGetEntriesByIds.js\";\nimport { DdbGetLatestEntriesByIds } from \"./DdbGetLatestEntriesByIds.js\";\nimport { DdbGetPublishedEntriesByIds } from \"./DdbGetPublishedEntriesByIds.js\";\nimport { DdbGetRevisions } from \"./DdbGetRevisions.js\";\nimport { DdbGetRevisionById } from \"./DdbGetRevisionById.js\";\nimport { DdbGetLatestRevisionByEntryId } from \"./DdbGetLatestRevisionByEntryId.js\";\nimport { DdbGetPublishedRevisionByEntryId } from \"./DdbGetPublishedRevisionByEntryId.js\";\nimport { DdbGetPreviousRevision } from \"./DdbGetPreviousRevision.js\";\nimport { DdbGetUniqueFieldValues } from \"./DdbGetUniqueFieldValues.js\";\n\nexport const DdbEntryStorageOpsFeature = createFeature({\n name: \"cms.ddb.entryStorageOps\",\n register: container => {\n // The DataLoader caches reads, so it must live for one request: container scoped, it is built\n // per request (child) container even though the feature is registered once in the root.\n container.register(DataLoadersHandler).inContainerScope();\n container.register(DdbCreateEntry);\n container.register(DdbCreateEntryRevisionFrom);\n container.register(DdbUpdateEntry);\n container.register(DdbMoveEntry);\n container.register(DdbMoveToBin);\n container.register(DdbDeleteEntry);\n container.register(DdbRestoreFromBin);\n container.register(DdbDeleteEntryRevision);\n container.register(DdbDeleteMultipleEntries);\n container.register(DdbGetEntry);\n container.register(DdbListEntries);\n container.register(DdbPublishEntry);\n container.register(DdbUnpublishEntry);\n container.register(DdbGetEntriesByIds);\n container.register(DdbGetLatestEntriesByIds);\n container.register(DdbGetPublishedEntriesByIds);\n container.register(DdbGetRevisions);\n container.register(DdbGetRevisionById);\n container.register(DdbGetLatestRevisionByEntryId);\n container.register(DdbGetPublishedRevisionByEntryId);\n container.register(DdbGetPreviousRevision);\n container.register(DdbGetUniqueFieldValues);\n }\n});\n"],"names":["DdbEntryStorageOpsFeature","createFeature","container","DataLoadersHandler","DdbCreateEntry","DdbCreateEntryRevisionFrom","DdbUpdateEntry","DdbMoveEntry","DdbMoveToBin","DdbDeleteEntry","DdbRestoreFromBin","DdbDeleteEntryRevision","DdbDeleteMultipleEntries","DdbGetEntry","DdbListEntries","DdbPublishEntry","DdbUnpublishEntry","DdbGetEntriesByIds","DdbGetLatestEntriesByIds","DdbGetPublishedEntriesByIds","DdbGetRevisions","DdbGetRevisionById","DdbGetLatestRevisionByEntryId","DdbGetPublishedRevisionByEntryId","DdbGetPreviousRevision","DdbGetUniqueFieldValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAAUC,CAAAA;QAGNA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QACnBhB,UAAU,QAAQ,CAACiB;QACnBjB,UAAU,QAAQ,CAACkB;QACnBlB,UAAU,QAAQ,CAACmB;QACnBnB,UAAU,QAAQ,CAACoB;QACnBpB,UAAU,QAAQ,CAACqB;QACnBrB,UAAU,QAAQ,CAACsB;QACnBtB,UAAU,QAAQ,CAACuB;IACvB;AACJ"}
@@ -1,6 +1,5 @@
1
1
  interface BasePartitionKeyParams {
2
2
  tenant: string;
3
- locale: string;
4
3
  }
5
4
  export interface PartitionKeyParams extends BasePartitionKeyParams {
6
5
  id: string;
@@ -14,7 +13,6 @@ export declare const createLatestSortKey: () => string;
14
13
  export declare const createPublishedSortKey: () => string;
15
14
  export interface GSIPartitionKeyParams {
16
15
  tenant: string;
17
- locale: string;
18
16
  modelId: string;
19
17
  }
20
18
  export declare const createGSIPartitionKey: (params: GSIPartitionKeyParams, type: "A" | "L" | "P") => string;
@@ -22,4 +20,50 @@ export interface GSISortKeyParams {
22
20
  id: string;
23
21
  }
24
22
  export declare const createGSISortKey: (params: GSISortKeyParams) => string;
23
+ export interface ICreateEntryPublishedKeysParams {
24
+ id: string;
25
+ tenant: string;
26
+ modelId: string;
27
+ expiresAt: number | null;
28
+ }
29
+ export declare const createEntryPublishedKeys: (params: ICreateEntryPublishedKeysParams) => {
30
+ PK: string;
31
+ SK: string;
32
+ GSI1_PK: string;
33
+ GSI1_SK: string;
34
+ TYPE: string;
35
+ GSI_TENANT: string;
36
+ expiresAt: number | null;
37
+ };
38
+ export interface ICreateEntryLatestKeysParams {
39
+ id: string;
40
+ tenant: string;
41
+ modelId: string;
42
+ expiresAt: number | null;
43
+ }
44
+ export declare const createEntryLatestKeys: (params: ICreateEntryLatestKeysParams) => {
45
+ PK: string;
46
+ SK: string;
47
+ GSI1_PK: string;
48
+ GSI1_SK: string;
49
+ TYPE: string;
50
+ GSI_TENANT: string;
51
+ expiresAt: number | null;
52
+ };
53
+ export interface ICreateRevisionKeysParams {
54
+ id: string;
55
+ tenant: string;
56
+ version: number;
57
+ modelId: string;
58
+ expiresAt: number | null;
59
+ }
60
+ export declare const createEntryRevisionKeys: (params: ICreateRevisionKeysParams) => {
61
+ PK: string;
62
+ SK: string;
63
+ GSI1_PK: string;
64
+ GSI1_SK: string;
65
+ TYPE: string;
66
+ GSI_TENANT: string;
67
+ expiresAt: number | null;
68
+ };
25
69
  export {};
@@ -1,62 +1,60 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createRevisionSortKey = exports.createPublishedSortKey = exports.createPartitionKey = exports.createLatestSortKey = exports.createGSISortKey = exports.createGSIPartitionKey = void 0;
7
-
8
- var _utils = require("@webiny/utils");
9
-
10
- const createBasePartitionKey = params => {
11
- const {
12
- tenant,
13
- locale
14
- } = params;
15
- return `T#${tenant}#L#${locale}#CMS#CME`;
1
+ import { parseIdentifier, zeroPad } from "@webiny/utils";
2
+ import error from "@webiny/error";
3
+ const createBasePartitionKey = (params)=>{
4
+ const { tenant } = params;
5
+ if (!tenant) throw new error("Missing tenant variable when creating entry basePartitionKey");
6
+ return `T#${tenant}#CMS#CME`;
16
7
  };
17
-
18
- const createPartitionKey = params => {
19
- const {
20
- id: initialId
21
- } = params;
22
- const {
23
- id
24
- } = (0, _utils.parseIdentifier)(initialId);
25
- return `${createBasePartitionKey(params)}#CME#${id}`;
8
+ const createPartitionKey = (params)=>{
9
+ const { id: initialId } = params;
10
+ const { id } = parseIdentifier(initialId);
11
+ return `${createBasePartitionKey(params)}#${id}`;
26
12
  };
27
-
28
- exports.createPartitionKey = createPartitionKey;
29
-
30
- const createRevisionSortKey = params => {
31
- return `REV#${(0, _utils.zeroPad)(params.version)}`;
13
+ const createRevisionSortKey = (params)=>`REV#${zeroPad(params.version)}`;
14
+ const createLatestSortKey = ()=>"L";
15
+ const createPublishedSortKey = ()=>"P";
16
+ const createGSIPartitionKey = (params, type)=>{
17
+ const { modelId } = params;
18
+ const partitionKey = createBasePartitionKey(params);
19
+ return `${partitionKey}#M#${modelId}#${type}`;
32
20
  };
33
-
34
- exports.createRevisionSortKey = createRevisionSortKey;
35
-
36
- const createLatestSortKey = () => {
37
- return "L";
21
+ const createGSISortKey = (params)=>params.id;
22
+ const createEntryPublishedKeys = (params)=>{
23
+ const { tenant, expiresAt } = params;
24
+ return {
25
+ PK: createPartitionKey(params),
26
+ SK: createPublishedSortKey(),
27
+ GSI1_PK: createGSIPartitionKey(params, "P"),
28
+ GSI1_SK: createGSISortKey(params),
29
+ TYPE: "cms.entry.p",
30
+ GSI_TENANT: tenant,
31
+ expiresAt
32
+ };
38
33
  };
39
-
40
- exports.createLatestSortKey = createLatestSortKey;
41
-
42
- const createPublishedSortKey = () => {
43
- return "P";
34
+ const createEntryLatestKeys = (params)=>{
35
+ const { tenant, expiresAt } = params;
36
+ return {
37
+ PK: createPartitionKey(params),
38
+ SK: createLatestSortKey(),
39
+ GSI1_PK: createGSIPartitionKey(params, "L"),
40
+ GSI1_SK: createGSISortKey(params),
41
+ TYPE: "cms.entry.l",
42
+ GSI_TENANT: tenant,
43
+ expiresAt
44
+ };
44
45
  };
45
-
46
- exports.createPublishedSortKey = createPublishedSortKey;
47
-
48
- const createGSIPartitionKey = (params, type) => {
49
- const {
50
- modelId
51
- } = params;
52
- const partitionKey = createBasePartitionKey(params);
53
- return `${partitionKey}#M#${modelId}#${type}`;
54
- };
55
-
56
- exports.createGSIPartitionKey = createGSIPartitionKey;
57
-
58
- const createGSISortKey = params => {
59
- return params.id;
46
+ const createEntryRevisionKeys = (params)=>{
47
+ const { tenant, expiresAt } = params;
48
+ return {
49
+ PK: createPartitionKey(params),
50
+ SK: createRevisionSortKey(params),
51
+ GSI1_PK: createGSIPartitionKey(params, "A"),
52
+ GSI1_SK: createGSISortKey(params),
53
+ TYPE: "cms.entry",
54
+ GSI_TENANT: tenant,
55
+ expiresAt
56
+ };
60
57
  };
58
+ export { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createGSIPartitionKey, createGSISortKey, createLatestSortKey, createPartitionKey, createPublishedSortKey, createRevisionSortKey };
61
59
 
62
- exports.createGSISortKey = createGSISortKey;
60
+ //# sourceMappingURL=keys.js.map