@webiny/api-headless-cms-ddb 0.0.0-unstable.de38392959 → 0.0.0-unstable.e0bfc55d5a
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.
- package/definitions/entry.d.ts +3 -2
- package/definitions/entry.js +42 -0
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +3 -2
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +3 -2
- package/definitions/model.js.map +1 -1
- package/definitions/system.d.ts +3 -2
- package/definitions/system.js.map +1 -1
- package/definitions/table.d.ts +3 -3
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.js +1 -2
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.js +1 -0
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +21 -56
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +1 -2
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +2 -2
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +2 -2
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +2 -2
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +2 -2
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +2 -2
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +2 -2
- package/operations/entry/dataLoader/getRevisionById.js +2 -2
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +3 -3
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +1 -1
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +3 -3
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +4 -4
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +3 -3
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +3 -3
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +3 -3
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +2 -2
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +2 -1
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +6 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +65 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +3 -3
- package/operations/entry/filtering/sort.js +2 -2
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -2
- package/operations/entry/filtering/systemFields.js +6 -0
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +2 -2
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +3 -3
- package/operations/entry/index.js +438 -238
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +3 -3
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +2 -2
- package/operations/model/index.js.map +1 -1
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js.map +1 -1
- package/package.json +19 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +1 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +2 -2
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.js.map +1 -1
- package/types.d.ts +8 -8
- package/types.js +1 -2
- package/types.js.map +1 -1
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -84
- package/dynamoDb/storage/date.js.map +0 -1
|
@@ -9,9 +9,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
9
9
|
var _dataLoaders = require("./dataLoaders");
|
|
10
10
|
var _types = require("@webiny/api-headless-cms/types");
|
|
11
11
|
var _keys = require("./keys");
|
|
12
|
-
var
|
|
13
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
14
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
12
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
15
13
|
var _cursor = require("@webiny/utils/cursor");
|
|
16
14
|
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
17
15
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
@@ -55,7 +53,7 @@ const convertFromStorageEntry = params => {
|
|
|
55
53
|
values
|
|
56
54
|
};
|
|
57
55
|
};
|
|
58
|
-
const MAX_LIST_LIMIT =
|
|
56
|
+
const MAX_LIST_LIMIT = 1000000;
|
|
59
57
|
const createEntriesStorageOperations = params => {
|
|
60
58
|
const {
|
|
61
59
|
entity,
|
|
@@ -76,11 +74,12 @@ const createEntriesStorageOperations = params => {
|
|
|
76
74
|
const dataLoaders = new _dataLoaders.DataLoadersHandler({
|
|
77
75
|
entity
|
|
78
76
|
});
|
|
79
|
-
const storageTransformPlugins = plugins.byType(_apiHeadlessCms.StorageTransformPlugin.type).reduce((collection, plugin) => {
|
|
80
|
-
collection[plugin.fieldType] = plugin;
|
|
81
|
-
return collection;
|
|
82
|
-
}, {});
|
|
83
77
|
const createStorageTransformCallable = model => {
|
|
78
|
+
// Cache StorageTransformPlugin to optimize execution.
|
|
79
|
+
const storageTransformPlugins = plugins.byType(_apiHeadlessCms.StorageTransformPlugin.type).reduce((collection, plugin) => {
|
|
80
|
+
collection[plugin.fieldType] = plugin;
|
|
81
|
+
return collection;
|
|
82
|
+
}, {});
|
|
84
83
|
return (field, value) => {
|
|
85
84
|
const plugin = storageTransformPlugins[field.type];
|
|
86
85
|
if (!plugin) {
|
|
@@ -119,29 +118,32 @@ const createEntriesStorageOperations = params => {
|
|
|
119
118
|
* - create new main entry item
|
|
120
119
|
* - create new or update the latest entry item
|
|
121
120
|
*/
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
121
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
122
|
+
entity,
|
|
123
|
+
put: [{
|
|
124
|
+
...storageEntry,
|
|
125
|
+
locked,
|
|
126
|
+
PK: partitionKey,
|
|
127
|
+
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
128
|
+
TYPE: createType(),
|
|
129
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
130
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
131
|
+
}, {
|
|
132
|
+
...storageEntry,
|
|
133
|
+
locked,
|
|
134
|
+
PK: partitionKey,
|
|
135
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
136
|
+
TYPE: createLatestType(),
|
|
137
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
138
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
139
|
+
}]
|
|
140
|
+
});
|
|
139
141
|
|
|
140
142
|
/**
|
|
141
143
|
* We need to create published entry if
|
|
142
144
|
*/
|
|
143
145
|
if (isPublished) {
|
|
144
|
-
|
|
146
|
+
entityBatch.put({
|
|
145
147
|
...storageEntry,
|
|
146
148
|
locked,
|
|
147
149
|
PK: partitionKey,
|
|
@@ -149,13 +151,10 @@ const createEntriesStorageOperations = params => {
|
|
|
149
151
|
TYPE: createLatestType(),
|
|
150
152
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
151
153
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
152
|
-
})
|
|
154
|
+
});
|
|
153
155
|
}
|
|
154
156
|
try {
|
|
155
|
-
await (
|
|
156
|
-
table: entity.table,
|
|
157
|
-
items
|
|
158
|
-
});
|
|
157
|
+
await entityBatch.execute();
|
|
159
158
|
dataLoaders.clearAll({
|
|
160
159
|
model
|
|
161
160
|
});
|
|
@@ -182,31 +181,63 @@ const createEntriesStorageOperations = params => {
|
|
|
182
181
|
storageEntry: initialStorageEntry,
|
|
183
182
|
model
|
|
184
183
|
});
|
|
184
|
+
|
|
185
185
|
/**
|
|
186
186
|
* We need to:
|
|
187
187
|
* - create the main entry item
|
|
188
|
-
* - update the
|
|
188
|
+
* - update the latest entry item to the current one
|
|
189
|
+
* - if the entry's status was set to "published":
|
|
190
|
+
* - update the published entry item to the current one
|
|
191
|
+
* - unpublish previously published revision (if any)
|
|
189
192
|
*/
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
193
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
194
|
+
entity,
|
|
195
|
+
put: [{
|
|
196
|
+
...storageEntry,
|
|
197
|
+
PK: partitionKey,
|
|
198
|
+
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
199
|
+
TYPE: createType(),
|
|
200
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
201
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
202
|
+
}, {
|
|
203
|
+
...storageEntry,
|
|
204
|
+
PK: partitionKey,
|
|
205
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
206
|
+
TYPE: createLatestType(),
|
|
207
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
208
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
209
|
+
}]
|
|
210
|
+
});
|
|
211
|
+
const isPublished = entry.status === "published";
|
|
212
|
+
if (isPublished) {
|
|
213
|
+
entityBatch.put({
|
|
214
|
+
...storageEntry,
|
|
215
|
+
PK: partitionKey,
|
|
216
|
+
SK: (0, _keys.createPublishedSortKey)(),
|
|
217
|
+
TYPE: createPublishedType(),
|
|
218
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
219
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Unpublish previously published revision (if any).
|
|
223
|
+
const [publishedRevisionStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
|
|
224
|
+
model,
|
|
225
|
+
ids: [entry.id]
|
|
209
226
|
});
|
|
227
|
+
if (publishedRevisionStorageEntry) {
|
|
228
|
+
entityBatch.put({
|
|
229
|
+
...publishedRevisionStorageEntry,
|
|
230
|
+
PK: partitionKey,
|
|
231
|
+
SK: (0, _keys.createRevisionSortKey)(publishedRevisionStorageEntry),
|
|
232
|
+
TYPE: createType(),
|
|
233
|
+
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
|
|
234
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
235
|
+
GSI1_SK: (0, _keys.createGSISortKey)(publishedRevisionStorageEntry)
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
await entityBatch.execute();
|
|
210
241
|
dataLoaders.clearAll({
|
|
211
242
|
model
|
|
212
243
|
});
|
|
@@ -235,7 +266,6 @@ const createEntriesStorageOperations = params => {
|
|
|
235
266
|
});
|
|
236
267
|
const isPublished = entry.status === "published";
|
|
237
268
|
const locked = isPublished ? true : entry.locked;
|
|
238
|
-
const items = [];
|
|
239
269
|
const storageEntry = convertToStorageEntry({
|
|
240
270
|
model,
|
|
241
271
|
storageEntry: initialStorageEntry
|
|
@@ -245,17 +275,21 @@ const createEntriesStorageOperations = params => {
|
|
|
245
275
|
* - update the current entry
|
|
246
276
|
* - update the latest entry if the current entry is the latest one
|
|
247
277
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
278
|
+
|
|
279
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
280
|
+
entity,
|
|
281
|
+
put: [{
|
|
282
|
+
...storageEntry,
|
|
283
|
+
locked,
|
|
284
|
+
PK: partitionKey,
|
|
285
|
+
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
286
|
+
TYPE: createType(),
|
|
287
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
288
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
289
|
+
}]
|
|
290
|
+
});
|
|
257
291
|
if (isPublished) {
|
|
258
|
-
|
|
292
|
+
entityBatch.put({
|
|
259
293
|
...storageEntry,
|
|
260
294
|
locked,
|
|
261
295
|
PK: partitionKey,
|
|
@@ -263,7 +297,7 @@ const createEntriesStorageOperations = params => {
|
|
|
263
297
|
TYPE: createPublishedType(),
|
|
264
298
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
265
299
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
266
|
-
})
|
|
300
|
+
});
|
|
267
301
|
}
|
|
268
302
|
|
|
269
303
|
/**
|
|
@@ -273,7 +307,7 @@ const createEntriesStorageOperations = params => {
|
|
|
273
307
|
if (latestStorageEntry) {
|
|
274
308
|
const updatingLatestRevision = latestStorageEntry.id === entry.id;
|
|
275
309
|
if (updatingLatestRevision) {
|
|
276
|
-
|
|
310
|
+
entityBatch.put({
|
|
277
311
|
...storageEntry,
|
|
278
312
|
locked,
|
|
279
313
|
PK: partitionKey,
|
|
@@ -281,7 +315,7 @@ const createEntriesStorageOperations = params => {
|
|
|
281
315
|
TYPE: createLatestType(),
|
|
282
316
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
283
317
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
284
|
-
})
|
|
318
|
+
});
|
|
285
319
|
} else {
|
|
286
320
|
/**
|
|
287
321
|
* If not updating latest revision, we still want to update the latest revision's
|
|
@@ -294,7 +328,7 @@ const createEntriesStorageOperations = params => {
|
|
|
294
328
|
* - one for the actual revision record
|
|
295
329
|
* - one for the latest record
|
|
296
330
|
*/
|
|
297
|
-
|
|
331
|
+
entityBatch.put({
|
|
298
332
|
...latestStorageEntry,
|
|
299
333
|
...updatedEntryLevelMetaFields,
|
|
300
334
|
PK: partitionKey,
|
|
@@ -302,8 +336,8 @@ const createEntriesStorageOperations = params => {
|
|
|
302
336
|
TYPE: createType(),
|
|
303
337
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
304
338
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
305
|
-
})
|
|
306
|
-
|
|
339
|
+
});
|
|
340
|
+
entityBatch.put({
|
|
307
341
|
...latestStorageEntry,
|
|
308
342
|
...updatedEntryLevelMetaFields,
|
|
309
343
|
PK: partitionKey,
|
|
@@ -311,14 +345,11 @@ const createEntriesStorageOperations = params => {
|
|
|
311
345
|
TYPE: createLatestType(),
|
|
312
346
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
313
347
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
314
|
-
})
|
|
348
|
+
});
|
|
315
349
|
}
|
|
316
350
|
}
|
|
317
351
|
try {
|
|
318
|
-
await (
|
|
319
|
-
table: entity.table,
|
|
320
|
-
items
|
|
321
|
-
});
|
|
352
|
+
await entityBatch.execute();
|
|
322
353
|
dataLoaders.clearAll({
|
|
323
354
|
model
|
|
324
355
|
});
|
|
@@ -352,27 +383,28 @@ const createEntriesStorageOperations = params => {
|
|
|
352
383
|
gte: " "
|
|
353
384
|
}
|
|
354
385
|
};
|
|
355
|
-
const records = await (0,
|
|
386
|
+
const records = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
356
387
|
/**
|
|
357
388
|
* Then create the batch writes for the DynamoDB, with the updated folderId.
|
|
358
389
|
*/
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
...item
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
390
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
391
|
+
entity,
|
|
392
|
+
put: records.map(item => {
|
|
393
|
+
return {
|
|
394
|
+
...item,
|
|
395
|
+
location: {
|
|
396
|
+
...item.location,
|
|
397
|
+
folderId
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
})
|
|
367
401
|
});
|
|
402
|
+
|
|
368
403
|
/**
|
|
369
404
|
* And finally write it...
|
|
370
405
|
*/
|
|
371
406
|
try {
|
|
372
|
-
await (
|
|
373
|
-
table: entity.table,
|
|
374
|
-
items
|
|
375
|
-
});
|
|
407
|
+
await entityBatch.execute();
|
|
376
408
|
} catch (ex) {
|
|
377
409
|
throw _error.default.from(ex, {
|
|
378
410
|
message: "Could not move records to a new folder.",
|
|
@@ -383,6 +415,77 @@ const createEntriesStorageOperations = params => {
|
|
|
383
415
|
});
|
|
384
416
|
}
|
|
385
417
|
};
|
|
418
|
+
const moveToBin = async (initialModel, params) => {
|
|
419
|
+
const {
|
|
420
|
+
entry,
|
|
421
|
+
storageEntry: initialStorageEntry
|
|
422
|
+
} = params;
|
|
423
|
+
const model = getStorageOperationsModel(initialModel);
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* First we need to load all the revisions and published / latest entries.
|
|
427
|
+
*/
|
|
428
|
+
const queryAllParams = {
|
|
429
|
+
entity,
|
|
430
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
431
|
+
id: entry.id,
|
|
432
|
+
locale: model.locale,
|
|
433
|
+
tenant: model.tenant
|
|
434
|
+
}),
|
|
435
|
+
options: {
|
|
436
|
+
gte: " "
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
let records = [];
|
|
440
|
+
try {
|
|
441
|
+
records = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
442
|
+
} catch (ex) {
|
|
443
|
+
throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
444
|
+
error: ex,
|
|
445
|
+
id: entry.id
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (records.length === 0) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const storageEntry = convertToStorageEntry({
|
|
452
|
+
model,
|
|
453
|
+
storageEntry: initialStorageEntry
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Let's pick the `deleted` meta fields from the storage entry.
|
|
458
|
+
*/
|
|
459
|
+
const updatedDeletedMetaFields = (0, _constants.pickEntryMetaFields)(storageEntry, _constants.isDeletedEntryMetaField);
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Then create the batch writes for the DynamoDB, with the updated data.
|
|
463
|
+
*/
|
|
464
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
465
|
+
entity,
|
|
466
|
+
put: records.map(record => {
|
|
467
|
+
return {
|
|
468
|
+
...record,
|
|
469
|
+
...updatedDeletedMetaFields,
|
|
470
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
471
|
+
location: storageEntry.location,
|
|
472
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
473
|
+
};
|
|
474
|
+
})
|
|
475
|
+
});
|
|
476
|
+
/**
|
|
477
|
+
* And finally write it...
|
|
478
|
+
*/
|
|
479
|
+
try {
|
|
480
|
+
await entityBatch.execute();
|
|
481
|
+
} catch (ex) {
|
|
482
|
+
throw new _error.default(ex.message || "Could not move the entry to the bin.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
|
|
483
|
+
error: ex,
|
|
484
|
+
entry,
|
|
485
|
+
storageEntry
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
386
489
|
const deleteEntry = async (initialModel, params) => {
|
|
387
490
|
const {
|
|
388
491
|
entry
|
|
@@ -402,24 +505,24 @@ const createEntriesStorageOperations = params => {
|
|
|
402
505
|
};
|
|
403
506
|
let records = [];
|
|
404
507
|
try {
|
|
405
|
-
records = await (0,
|
|
508
|
+
records = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
406
509
|
} catch (ex) {
|
|
407
510
|
throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
408
511
|
error: ex,
|
|
409
512
|
id
|
|
410
513
|
});
|
|
411
514
|
}
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
515
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
516
|
+
entity,
|
|
517
|
+
delete: records.map(item => {
|
|
518
|
+
return {
|
|
519
|
+
PK: item.PK,
|
|
520
|
+
SK: item.SK
|
|
521
|
+
};
|
|
522
|
+
})
|
|
417
523
|
});
|
|
418
524
|
try {
|
|
419
|
-
await (
|
|
420
|
-
table: entity.table,
|
|
421
|
-
items
|
|
422
|
-
});
|
|
525
|
+
await entityBatch.execute();
|
|
423
526
|
dataLoaders.clearAll({
|
|
424
527
|
model
|
|
425
528
|
});
|
|
@@ -431,6 +534,78 @@ const createEntriesStorageOperations = params => {
|
|
|
431
534
|
});
|
|
432
535
|
}
|
|
433
536
|
};
|
|
537
|
+
const restoreFromBin = async (initialModel, params) => {
|
|
538
|
+
const {
|
|
539
|
+
entry,
|
|
540
|
+
storageEntry: initialStorageEntry
|
|
541
|
+
} = params;
|
|
542
|
+
const model = getStorageOperationsModel(initialModel);
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* First we need to load all the revisions and published / latest entries.
|
|
546
|
+
*/
|
|
547
|
+
const queryAllParams = {
|
|
548
|
+
entity,
|
|
549
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
550
|
+
id: entry.id,
|
|
551
|
+
locale: model.locale,
|
|
552
|
+
tenant: model.tenant
|
|
553
|
+
}),
|
|
554
|
+
options: {
|
|
555
|
+
gte: " "
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
let records = [];
|
|
559
|
+
try {
|
|
560
|
+
records = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
561
|
+
} catch (ex) {
|
|
562
|
+
throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
563
|
+
error: ex,
|
|
564
|
+
id: entry.id
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
if (records.length === 0) {
|
|
568
|
+
return initialStorageEntry;
|
|
569
|
+
}
|
|
570
|
+
const storageEntry = convertToStorageEntry({
|
|
571
|
+
model,
|
|
572
|
+
storageEntry: initialStorageEntry
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Let's pick the `restored` meta fields from the storage entry.
|
|
577
|
+
*/
|
|
578
|
+
const updatedRestoredMetaFields = (0, _constants.pickEntryMetaFields)(storageEntry, _constants.isRestoredEntryMetaField);
|
|
579
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
580
|
+
entity,
|
|
581
|
+
put: records.map(record => {
|
|
582
|
+
return {
|
|
583
|
+
...record,
|
|
584
|
+
...updatedRestoredMetaFields,
|
|
585
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
586
|
+
location: storageEntry.location,
|
|
587
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
588
|
+
};
|
|
589
|
+
})
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* And finally write it...
|
|
594
|
+
*/
|
|
595
|
+
try {
|
|
596
|
+
await entityBatch.execute();
|
|
597
|
+
dataLoaders.clearAll({
|
|
598
|
+
model
|
|
599
|
+
});
|
|
600
|
+
return initialStorageEntry;
|
|
601
|
+
} catch (ex) {
|
|
602
|
+
throw new _error.default(ex.message || "Could not restore the entry from the bin.", ex.code || "RESTORE_ENTRY_ERROR", {
|
|
603
|
+
error: ex,
|
|
604
|
+
entry,
|
|
605
|
+
storageEntry
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
};
|
|
434
609
|
const deleteRevision = async (initialModel, params) => {
|
|
435
610
|
const {
|
|
436
611
|
entry,
|
|
@@ -443,51 +618,51 @@ const createEntriesStorageOperations = params => {
|
|
|
443
618
|
locale: model.locale,
|
|
444
619
|
tenant: model.tenant
|
|
445
620
|
});
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
621
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
622
|
+
entity,
|
|
623
|
+
delete: [{
|
|
624
|
+
PK: partitionKey,
|
|
625
|
+
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
626
|
+
}]
|
|
627
|
+
});
|
|
450
628
|
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
451
629
|
|
|
452
630
|
/**
|
|
453
631
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
454
632
|
*/
|
|
455
633
|
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
456
|
-
|
|
634
|
+
entityBatch.delete({
|
|
457
635
|
PK: partitionKey,
|
|
458
636
|
SK: (0, _keys.createPublishedSortKey)()
|
|
459
|
-
})
|
|
637
|
+
});
|
|
460
638
|
}
|
|
461
639
|
if (initialLatestStorageEntry) {
|
|
462
640
|
const latestStorageEntry = convertToStorageEntry({
|
|
463
641
|
storageEntry: initialLatestStorageEntry,
|
|
464
642
|
model
|
|
465
643
|
});
|
|
466
|
-
|
|
644
|
+
entityBatch.put({
|
|
467
645
|
...latestStorageEntry,
|
|
468
646
|
PK: partitionKey,
|
|
469
647
|
SK: (0, _keys.createLatestSortKey)(),
|
|
470
648
|
TYPE: createLatestType(),
|
|
471
649
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
472
650
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
473
|
-
})
|
|
651
|
+
});
|
|
474
652
|
|
|
475
653
|
// Do an update on the latest revision. We need to update the latest revision's
|
|
476
654
|
// entry-level meta fields to match the previous revision's entry-level meta fields.
|
|
477
|
-
|
|
478
|
-
...
|
|
655
|
+
entityBatch.put({
|
|
656
|
+
...latestStorageEntry,
|
|
479
657
|
PK: partitionKey,
|
|
480
658
|
SK: (0, _keys.createRevisionSortKey)(initialLatestStorageEntry),
|
|
481
659
|
TYPE: createType(),
|
|
482
660
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
483
661
|
GSI1_SK: (0, _keys.createGSISortKey)(initialLatestStorageEntry)
|
|
484
|
-
})
|
|
662
|
+
});
|
|
485
663
|
}
|
|
486
664
|
try {
|
|
487
|
-
|
|
488
|
-
table: entity.table,
|
|
489
|
-
items
|
|
490
|
-
});
|
|
665
|
+
entityBatch.execute();
|
|
491
666
|
dataLoaders.clearAll({
|
|
492
667
|
model
|
|
493
668
|
});
|
|
@@ -514,36 +689,30 @@ const createEntriesStorageOperations = params => {
|
|
|
514
689
|
/**
|
|
515
690
|
* Then we need to construct the queries for all the revisions and entries.
|
|
516
691
|
*/
|
|
517
|
-
|
|
692
|
+
|
|
693
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
694
|
+
entity
|
|
695
|
+
});
|
|
518
696
|
for (const id of entries) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
tenant: model.tenant
|
|
527
|
-
}),
|
|
697
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
698
|
+
id,
|
|
699
|
+
locale: model.locale,
|
|
700
|
+
tenant: model.tenant
|
|
701
|
+
});
|
|
702
|
+
entityBatch.delete({
|
|
703
|
+
PK: partitionKey,
|
|
528
704
|
SK: "L"
|
|
529
|
-
})
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
*/
|
|
533
|
-
items.push(entity.deleteBatch({
|
|
534
|
-
PK: (0, _keys.createPartitionKey)({
|
|
535
|
-
id,
|
|
536
|
-
locale: model.locale,
|
|
537
|
-
tenant: model.tenant
|
|
538
|
-
}),
|
|
705
|
+
});
|
|
706
|
+
entityBatch.delete({
|
|
707
|
+
PK: partitionKey,
|
|
539
708
|
SK: "P"
|
|
540
|
-
})
|
|
709
|
+
});
|
|
541
710
|
}
|
|
542
711
|
/**
|
|
543
712
|
* Exact revisions of all the entries
|
|
544
713
|
*/
|
|
545
714
|
for (const revision of revisions) {
|
|
546
|
-
|
|
715
|
+
entityBatch.delete({
|
|
547
716
|
PK: (0, _keys.createPartitionKey)({
|
|
548
717
|
id: revision.id,
|
|
549
718
|
locale: model.locale,
|
|
@@ -552,12 +721,9 @@ const createEntriesStorageOperations = params => {
|
|
|
552
721
|
SK: (0, _keys.createRevisionSortKey)({
|
|
553
722
|
version: revision.version
|
|
554
723
|
})
|
|
555
|
-
})
|
|
724
|
+
});
|
|
556
725
|
}
|
|
557
|
-
await (
|
|
558
|
-
table: entity.table,
|
|
559
|
-
items
|
|
560
|
-
});
|
|
726
|
+
await entityBatch.execute();
|
|
561
727
|
};
|
|
562
728
|
const getLatestRevisionByEntryId = async (initialModel, params) => {
|
|
563
729
|
const model = getStorageOperationsModel(initialModel);
|
|
@@ -685,8 +851,8 @@ const createEntriesStorageOperations = params => {
|
|
|
685
851
|
}
|
|
686
852
|
};
|
|
687
853
|
try {
|
|
688
|
-
const result = await (0,
|
|
689
|
-
const storageEntry = (0,
|
|
854
|
+
const result = await (0, _dbDynamodb.queryOne)(queryParams);
|
|
855
|
+
const storageEntry = (0, _dbDynamodb.cleanupItem)(entity, result);
|
|
690
856
|
if (!storageEntry) {
|
|
691
857
|
return null;
|
|
692
858
|
}
|
|
@@ -726,7 +892,7 @@ const createEntriesStorageOperations = params => {
|
|
|
726
892
|
};
|
|
727
893
|
let storageEntries = [];
|
|
728
894
|
try {
|
|
729
|
-
storageEntries = await (0,
|
|
895
|
+
storageEntries = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
730
896
|
} catch (ex) {
|
|
731
897
|
throw new _error.default(ex.message, "QUERY_ENTRIES_ERROR", {
|
|
732
898
|
error: ex,
|
|
@@ -806,12 +972,12 @@ const createEntriesStorageOperations = params => {
|
|
|
806
972
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
807
973
|
* Number is simply encoded.
|
|
808
974
|
*/
|
|
809
|
-
const cursor =
|
|
975
|
+
const cursor = (0, _cursor.encodeCursor)(`${start + limit}`);
|
|
810
976
|
return {
|
|
811
977
|
hasMoreItems,
|
|
812
978
|
totalCount,
|
|
813
979
|
cursor,
|
|
814
|
-
items: (0,
|
|
980
|
+
items: (0, _dbDynamodb.cleanupItems)(entity, slicedItems)
|
|
815
981
|
};
|
|
816
982
|
};
|
|
817
983
|
const get = async (initialModel, params) => {
|
|
@@ -840,98 +1006,129 @@ const createEntriesStorageOperations = params => {
|
|
|
840
1006
|
* We need the latest and published entries to see if something needs to be updated alongside the publishing one.
|
|
841
1007
|
*/
|
|
842
1008
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
1009
|
+
if (!initialLatestStorageEntry) {
|
|
1010
|
+
throw new _error.default(`Could not publish entry. Could not load latest ("L") record.`, "PUBLISH_ERROR", {
|
|
1011
|
+
entry
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
843
1014
|
const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
844
1015
|
const storageEntry = convertToStorageEntry({
|
|
845
1016
|
model,
|
|
846
1017
|
storageEntry: initialStorageEntry
|
|
847
1018
|
});
|
|
848
|
-
/**
|
|
849
|
-
* We need to update:
|
|
850
|
-
* - current entry revision sort key
|
|
851
|
-
* - published sort key
|
|
852
|
-
* - the latest sort key - if entry updated is actually latest
|
|
853
|
-
* - previous published entry to unpublished status - if any previously published entry
|
|
854
|
-
*/
|
|
855
|
-
const items = [entity.putBatch({
|
|
856
|
-
...storageEntry,
|
|
857
|
-
PK: partitionKey,
|
|
858
|
-
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
859
|
-
TYPE: createType(),
|
|
860
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
861
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
862
|
-
}), entity.putBatch({
|
|
863
|
-
...storageEntry,
|
|
864
|
-
PK: partitionKey,
|
|
865
|
-
SK: (0, _keys.createPublishedSortKey)(),
|
|
866
|
-
TYPE: createPublishedType(),
|
|
867
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
868
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
869
|
-
})];
|
|
870
|
-
if (initialLatestStorageEntry) {
|
|
871
|
-
const publishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
872
|
-
if (publishingLatestRevision) {
|
|
873
|
-
// We want to update current latest record because of the status (`status: 'published'`) update.
|
|
874
|
-
items.push(entity.putBatch({
|
|
875
|
-
...storageEntry,
|
|
876
|
-
PK: partitionKey,
|
|
877
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
878
|
-
TYPE: createLatestType(),
|
|
879
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
880
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
881
|
-
}));
|
|
882
|
-
} else {
|
|
883
|
-
const latestStorageEntry = convertToStorageEntry({
|
|
884
|
-
storageEntry: initialLatestStorageEntry,
|
|
885
|
-
model
|
|
886
|
-
});
|
|
887
1019
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1020
|
+
// 1. Update REV# and P records with new data.
|
|
1021
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
1022
|
+
entity,
|
|
1023
|
+
put: [{
|
|
1024
|
+
...storageEntry,
|
|
1025
|
+
PK: partitionKey,
|
|
1026
|
+
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
1027
|
+
TYPE: createType(),
|
|
1028
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1029
|
+
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1030
|
+
}, {
|
|
1031
|
+
...storageEntry,
|
|
1032
|
+
PK: partitionKey,
|
|
1033
|
+
SK: (0, _keys.createPublishedSortKey)(),
|
|
1034
|
+
TYPE: createPublishedType(),
|
|
1035
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
1036
|
+
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1037
|
+
}]
|
|
1038
|
+
});
|
|
891
1039
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1040
|
+
// 2. When it comes to the latest record, we need to perform a couple of different
|
|
1041
|
+
// updates, based on whether the entry being published is the latest revision or not.
|
|
1042
|
+
const publishedRevisionId = initialPublishedStorageEntry?.id;
|
|
1043
|
+
const publishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
1044
|
+
if (publishingLatestRevision) {
|
|
1045
|
+
// 2.1 If we're publishing the latest revision, we first need to update the L record.
|
|
1046
|
+
entityBatch.put({
|
|
1047
|
+
...storageEntry,
|
|
1048
|
+
PK: partitionKey,
|
|
1049
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
1050
|
+
TYPE: createLatestType(),
|
|
1051
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1052
|
+
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1053
|
+
});
|
|
1054
|
+
|
|
1055
|
+
// 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.
|
|
1056
|
+
if (publishedRevisionId && publishedRevisionId !== entry.id) {
|
|
1057
|
+
const publishedStorageEntry = convertToStorageEntry({
|
|
1058
|
+
storageEntry: initialPublishedStorageEntry,
|
|
1059
|
+
model
|
|
1060
|
+
});
|
|
1061
|
+
entityBatch.put({
|
|
1062
|
+
...publishedStorageEntry,
|
|
896
1063
|
PK: partitionKey,
|
|
897
|
-
SK: (0, _keys.createRevisionSortKey)(
|
|
1064
|
+
SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
|
|
898
1065
|
TYPE: createType(),
|
|
1066
|
+
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
|
|
899
1067
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
900
|
-
GSI1_SK: (0, _keys.createGSISortKey)(
|
|
901
|
-
})
|
|
902
|
-
|
|
903
|
-
// 2. Update latest record.
|
|
904
|
-
items.push(entity.putBatch({
|
|
905
|
-
...latestStorageEntry,
|
|
906
|
-
...updatedEntryLevelMetaFields,
|
|
907
|
-
PK: partitionKey,
|
|
908
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
909
|
-
TYPE: createLatestType(),
|
|
910
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
911
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
912
|
-
}));
|
|
1068
|
+
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
1069
|
+
});
|
|
913
1070
|
}
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1071
|
+
} else {
|
|
1072
|
+
// 2.3 If the published revision is not the latest one, the situation is a bit
|
|
1073
|
+
// more complex. We first need to update the L and REV# records with the new
|
|
1074
|
+
// values of *only entry-level* meta fields.
|
|
1075
|
+
const updatedEntryLevelMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isEntryLevelEntryMetaField);
|
|
1076
|
+
const latestStorageEntry = convertToStorageEntry({
|
|
1077
|
+
storageEntry: initialLatestStorageEntry,
|
|
918
1078
|
model
|
|
919
1079
|
});
|
|
920
|
-
|
|
921
|
-
|
|
1080
|
+
|
|
1081
|
+
// 2.3.1 Update L record. Apart from updating the entry-level meta fields, we also need
|
|
1082
|
+
// to change the status from "published" to "unpublished" (if the status is set to "published").
|
|
1083
|
+
let latestRevisionStatus = latestStorageEntry.status;
|
|
1084
|
+
if (latestRevisionStatus === _types.CONTENT_ENTRY_STATUS.PUBLISHED) {
|
|
1085
|
+
latestRevisionStatus = _types.CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
1086
|
+
}
|
|
1087
|
+
const latestStorageEntryFields = {
|
|
1088
|
+
...latestStorageEntry,
|
|
1089
|
+
...updatedEntryLevelMetaFields,
|
|
1090
|
+
status: latestRevisionStatus
|
|
1091
|
+
};
|
|
1092
|
+
entityBatch.put({
|
|
1093
|
+
...latestStorageEntryFields,
|
|
922
1094
|
PK: partitionKey,
|
|
923
|
-
SK: (0, _keys.
|
|
1095
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
1096
|
+
TYPE: createLatestType(),
|
|
1097
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1098
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
// 2.3.2 Update REV# record.
|
|
1102
|
+
entityBatch.put({
|
|
1103
|
+
...latestStorageEntryFields,
|
|
1104
|
+
PK: partitionKey,
|
|
1105
|
+
SK: (0, _keys.createRevisionSortKey)(latestStorageEntry),
|
|
924
1106
|
TYPE: createType(),
|
|
925
|
-
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
|
|
926
1107
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
927
|
-
GSI1_SK: (0, _keys.createGSISortKey)(
|
|
928
|
-
})
|
|
1108
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
// 2.3.3 Finally, if we got a published entry, but it wasn't the latest one, we need to take
|
|
1112
|
+
// an extra step and mark it as unpublished.
|
|
1113
|
+
const publishedRevisionDifferentFromLatest = publishedRevisionId && publishedRevisionId !== latestStorageEntry.id;
|
|
1114
|
+
if (publishedRevisionDifferentFromLatest) {
|
|
1115
|
+
const publishedStorageEntry = convertToStorageEntry({
|
|
1116
|
+
storageEntry: initialPublishedStorageEntry,
|
|
1117
|
+
model
|
|
1118
|
+
});
|
|
1119
|
+
entityBatch.put({
|
|
1120
|
+
...publishedStorageEntry,
|
|
1121
|
+
PK: partitionKey,
|
|
1122
|
+
SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
|
|
1123
|
+
TYPE: createType(),
|
|
1124
|
+
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
|
|
1125
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1126
|
+
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
929
1129
|
}
|
|
930
1130
|
try {
|
|
931
|
-
await (
|
|
932
|
-
table: entity.table,
|
|
933
|
-
items
|
|
934
|
-
});
|
|
1131
|
+
await entityBatch.execute();
|
|
935
1132
|
dataLoaders.clearAll({
|
|
936
1133
|
model
|
|
937
1134
|
});
|
|
@@ -965,17 +1162,21 @@ const createEntriesStorageOperations = params => {
|
|
|
965
1162
|
* - update current entry revision with new data
|
|
966
1163
|
* - update the latest entry status - if entry being unpublished is latest
|
|
967
1164
|
*/
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1165
|
+
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
1166
|
+
entity,
|
|
1167
|
+
delete: [{
|
|
1168
|
+
PK: partitionKey,
|
|
1169
|
+
SK: (0, _keys.createPublishedSortKey)()
|
|
1170
|
+
}],
|
|
1171
|
+
put: [{
|
|
1172
|
+
...storageEntry,
|
|
1173
|
+
PK: partitionKey,
|
|
1174
|
+
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
1175
|
+
TYPE: createType(),
|
|
1176
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1177
|
+
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1178
|
+
}]
|
|
1179
|
+
});
|
|
979
1180
|
|
|
980
1181
|
/**
|
|
981
1182
|
* We need the latest entry to see if something needs to be updated alongside the unpublishing one.
|
|
@@ -984,14 +1185,14 @@ const createEntriesStorageOperations = params => {
|
|
|
984
1185
|
if (initialLatestStorageEntry) {
|
|
985
1186
|
const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
986
1187
|
if (unpublishingLatestRevision) {
|
|
987
|
-
|
|
1188
|
+
entityBatch.put({
|
|
988
1189
|
...storageEntry,
|
|
989
1190
|
PK: partitionKey,
|
|
990
1191
|
SK: (0, _keys.createLatestSortKey)(),
|
|
991
1192
|
TYPE: createLatestType(),
|
|
992
1193
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
993
1194
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
994
|
-
})
|
|
1195
|
+
});
|
|
995
1196
|
} else {
|
|
996
1197
|
const latestStorageEntry = convertToStorageEntry({
|
|
997
1198
|
storageEntry: initialLatestStorageEntry,
|
|
@@ -1003,7 +1204,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1003
1204
|
const updatedEntryLevelMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isEntryLevelEntryMetaField);
|
|
1004
1205
|
|
|
1005
1206
|
// 1. Update actual revision record.
|
|
1006
|
-
|
|
1207
|
+
entityBatch.put({
|
|
1007
1208
|
...latestStorageEntry,
|
|
1008
1209
|
...updatedEntryLevelMetaFields,
|
|
1009
1210
|
PK: partitionKey,
|
|
@@ -1011,10 +1212,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1011
1212
|
TYPE: createType(),
|
|
1012
1213
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1013
1214
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1014
|
-
})
|
|
1215
|
+
});
|
|
1015
1216
|
|
|
1016
1217
|
// 2. Update latest record.
|
|
1017
|
-
|
|
1218
|
+
entityBatch.put({
|
|
1018
1219
|
...latestStorageEntry,
|
|
1019
1220
|
...updatedEntryLevelMetaFields,
|
|
1020
1221
|
PK: partitionKey,
|
|
@@ -1022,14 +1223,11 @@ const createEntriesStorageOperations = params => {
|
|
|
1022
1223
|
TYPE: createLatestType(),
|
|
1023
1224
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1024
1225
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1025
|
-
})
|
|
1226
|
+
});
|
|
1026
1227
|
}
|
|
1027
1228
|
}
|
|
1028
1229
|
try {
|
|
1029
|
-
await (
|
|
1030
|
-
table: entity.table,
|
|
1031
|
-
items
|
|
1032
|
-
});
|
|
1230
|
+
await entityBatch.execute();
|
|
1033
1231
|
dataLoaders.clearAll({
|
|
1034
1232
|
model
|
|
1035
1233
|
});
|
|
@@ -1083,6 +1281,8 @@ const createEntriesStorageOperations = params => {
|
|
|
1083
1281
|
update,
|
|
1084
1282
|
move,
|
|
1085
1283
|
delete: deleteEntry,
|
|
1284
|
+
moveToBin,
|
|
1285
|
+
restoreFromBin,
|
|
1086
1286
|
deleteRevision,
|
|
1087
1287
|
deleteMultipleEntries,
|
|
1088
1288
|
getPreviousRevision,
|