@webiny/api-headless-cms-ddb 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd
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 +2 -2
- package/definitions/entry.js +64 -15
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +2 -2
- package/definitions/group.js +9 -8
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +2 -2
- package/definitions/model.js +9 -8
- package/definitions/model.js.map +1 -1
- package/definitions/system.d.ts +2 -2
- package/definitions/system.js +9 -8
- package/definitions/system.js.map +1 -1
- package/definitions/table.d.ts +4 -4
- package/definitions/table.js +8 -4
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.js +3 -1
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.js +4 -2
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.js +3 -1
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/date.js +3 -1
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.js +3 -1
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +4 -3
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +3 -1
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.js +3 -11
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.js +7 -9
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +3 -1
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +3 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js +3 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +3 -4
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +3 -4
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +3 -4
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.js +3 -1
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +1 -1
- package/operations/entry/dataLoader/types.js +3 -1
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +1 -1
- package/operations/entry/dataLoaders.js +15 -14
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.js +3 -1
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.js +12 -9
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.js +3 -1
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.js +24 -9
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.js +3 -1
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +6 -3
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +3 -1
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.js +3 -1
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +3 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.js +3 -1
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +3 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +3 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.js +3 -1
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +28 -32
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.js +3 -1
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.js +3 -1
- package/operations/entry/filtering/values.js +3 -1
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +3 -1
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +1 -1
- package/operations/entry/index.js +248 -60
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +3 -1
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +1 -1
- package/operations/group/index.js +33 -21
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +1 -1
- package/operations/model/index.js +26 -13
- package/operations/model/index.js.map +1 -1
- package/operations/system/index.d.ts +1 -1
- package/operations/system/index.js +19 -7
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.js +8 -3
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.js +9 -6
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.js +4 -5
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +3 -4
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.js +3 -1
- package/plugins/index.js.map +1 -1
- package/types.d.ts +8 -10
- package/types.js +6 -5
- package/types.js.map +1 -1
- package/definitions/settings.d.ts +0 -9
- package/definitions/settings.js +0 -53
- package/definitions/settings.js.map +0 -1
- package/operations/settings/index.d.ts +0 -7
- package/operations/settings/index.js +0 -111
- package/operations/settings/index.js.map +0 -1
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.createEntriesStorageOperations = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
9
|
var _dataLoaders = require("./dataLoaders");
|
|
11
10
|
var _types = require("@webiny/api-headless-cms/types");
|
|
@@ -18,6 +17,7 @@ var _zeroPad = require("@webiny/utils/zeroPad");
|
|
|
18
17
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
19
18
|
var _createFields = require("./filtering/createFields");
|
|
20
19
|
var _filtering = require("./filtering");
|
|
20
|
+
var _constants = require("@webiny/api-headless-cms/constants");
|
|
21
21
|
const createType = () => {
|
|
22
22
|
return "cms.entry";
|
|
23
23
|
};
|
|
@@ -36,9 +36,10 @@ const convertToStorageEntry = params => {
|
|
|
36
36
|
fields: model.fields,
|
|
37
37
|
values: storageEntry.values
|
|
38
38
|
});
|
|
39
|
-
return
|
|
39
|
+
return {
|
|
40
|
+
...storageEntry,
|
|
40
41
|
values
|
|
41
|
-
}
|
|
42
|
+
};
|
|
42
43
|
};
|
|
43
44
|
const convertFromStorageEntry = params => {
|
|
44
45
|
const {
|
|
@@ -49,9 +50,10 @@ const convertFromStorageEntry = params => {
|
|
|
49
50
|
fields: model.fields,
|
|
50
51
|
values: storageEntry.values
|
|
51
52
|
});
|
|
52
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
...storageEntry,
|
|
53
55
|
values
|
|
54
|
-
}
|
|
56
|
+
};
|
|
55
57
|
};
|
|
56
58
|
const MAX_LIST_LIMIT = 10000;
|
|
57
59
|
const createEntriesStorageOperations = params => {
|
|
@@ -117,34 +119,37 @@ const createEntriesStorageOperations = params => {
|
|
|
117
119
|
* - create new main entry item
|
|
118
120
|
* - create new or update the latest entry item
|
|
119
121
|
*/
|
|
120
|
-
const items = [entity.putBatch(
|
|
122
|
+
const items = [entity.putBatch({
|
|
123
|
+
...storageEntry,
|
|
121
124
|
locked,
|
|
122
125
|
PK: partitionKey,
|
|
123
126
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
124
127
|
TYPE: createType(),
|
|
125
128
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
126
129
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
127
|
-
})
|
|
130
|
+
}), entity.putBatch({
|
|
131
|
+
...storageEntry,
|
|
128
132
|
locked,
|
|
129
133
|
PK: partitionKey,
|
|
130
134
|
SK: (0, _keys.createLatestSortKey)(),
|
|
131
135
|
TYPE: createLatestType(),
|
|
132
136
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
133
137
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
134
|
-
})
|
|
138
|
+
})];
|
|
135
139
|
|
|
136
140
|
/**
|
|
137
141
|
* We need to create published entry if
|
|
138
142
|
*/
|
|
139
143
|
if (isPublished) {
|
|
140
|
-
items.push(entity.putBatch(
|
|
144
|
+
items.push(entity.putBatch({
|
|
145
|
+
...storageEntry,
|
|
141
146
|
locked,
|
|
142
147
|
PK: partitionKey,
|
|
143
148
|
SK: (0, _keys.createPublishedSortKey)(),
|
|
144
149
|
TYPE: createLatestType(),
|
|
145
150
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
146
151
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
147
|
-
}))
|
|
152
|
+
}));
|
|
148
153
|
}
|
|
149
154
|
try {
|
|
150
155
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -182,19 +187,21 @@ const createEntriesStorageOperations = params => {
|
|
|
182
187
|
* - create the main entry item
|
|
183
188
|
* - update the last entry item to a current one
|
|
184
189
|
*/
|
|
185
|
-
const items = [entity.putBatch(
|
|
190
|
+
const items = [entity.putBatch({
|
|
191
|
+
...storageEntry,
|
|
186
192
|
PK: partitionKey,
|
|
187
193
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
188
194
|
TYPE: createType(),
|
|
189
195
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
190
196
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
191
|
-
})
|
|
197
|
+
}), entity.putBatch({
|
|
198
|
+
...storageEntry,
|
|
192
199
|
PK: partitionKey,
|
|
193
200
|
SK: (0, _keys.createLatestSortKey)(),
|
|
194
201
|
TYPE: createLatestType(),
|
|
195
202
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
196
203
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
197
|
-
})
|
|
204
|
+
})];
|
|
198
205
|
try {
|
|
199
206
|
await (0, _batchWrite.batchWriteAll)({
|
|
200
207
|
table: entity.table,
|
|
@@ -238,38 +245,74 @@ const createEntriesStorageOperations = params => {
|
|
|
238
245
|
* - update the current entry
|
|
239
246
|
* - update the latest entry if the current entry is the latest one
|
|
240
247
|
*/
|
|
241
|
-
items.push(entity.putBatch(
|
|
248
|
+
items.push(entity.putBatch({
|
|
249
|
+
...storageEntry,
|
|
242
250
|
locked,
|
|
243
251
|
PK: partitionKey,
|
|
244
252
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
245
253
|
TYPE: createType(),
|
|
246
254
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
247
255
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
248
|
-
}))
|
|
256
|
+
}));
|
|
249
257
|
if (isPublished) {
|
|
250
|
-
items.push(entity.putBatch(
|
|
258
|
+
items.push(entity.putBatch({
|
|
259
|
+
...storageEntry,
|
|
251
260
|
locked,
|
|
252
261
|
PK: partitionKey,
|
|
253
262
|
SK: (0, _keys.createPublishedSortKey)(),
|
|
254
263
|
TYPE: createPublishedType(),
|
|
255
264
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
256
265
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
257
|
-
}))
|
|
266
|
+
}));
|
|
258
267
|
}
|
|
259
268
|
|
|
260
269
|
/**
|
|
261
270
|
* We need the latest entry to update it as well if necessary.
|
|
262
271
|
*/
|
|
263
272
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
264
|
-
if (latestStorageEntry
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
+
if (latestStorageEntry) {
|
|
274
|
+
const updatingLatestRevision = latestStorageEntry.id === entry.id;
|
|
275
|
+
if (updatingLatestRevision) {
|
|
276
|
+
items.push(entity.putBatch({
|
|
277
|
+
...storageEntry,
|
|
278
|
+
locked,
|
|
279
|
+
PK: partitionKey,
|
|
280
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
281
|
+
TYPE: createLatestType(),
|
|
282
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
283
|
+
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
284
|
+
}));
|
|
285
|
+
} else {
|
|
286
|
+
/**
|
|
287
|
+
* If not updating latest revision, we still want to update the latest revision's
|
|
288
|
+
* entry-level meta fields to match the current revision's entry-level meta fields.
|
|
289
|
+
*/
|
|
290
|
+
const updatedEntryLevelMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isEntryLevelEntryMetaField);
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* First we update the regular DynamoDB table. Two updates are needed:
|
|
294
|
+
* - one for the actual revision record
|
|
295
|
+
* - one for the latest record
|
|
296
|
+
*/
|
|
297
|
+
items.push(entity.putBatch({
|
|
298
|
+
...latestStorageEntry,
|
|
299
|
+
...updatedEntryLevelMetaFields,
|
|
300
|
+
PK: partitionKey,
|
|
301
|
+
SK: (0, _keys.createRevisionSortKey)(latestStorageEntry),
|
|
302
|
+
TYPE: createType(),
|
|
303
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
304
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
305
|
+
}));
|
|
306
|
+
items.push(entity.putBatch({
|
|
307
|
+
...latestStorageEntry,
|
|
308
|
+
...updatedEntryLevelMetaFields,
|
|
309
|
+
PK: partitionKey,
|
|
310
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
311
|
+
TYPE: createLatestType(),
|
|
312
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
313
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
273
316
|
}
|
|
274
317
|
try {
|
|
275
318
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -288,6 +331,58 @@ const createEntriesStorageOperations = params => {
|
|
|
288
331
|
});
|
|
289
332
|
}
|
|
290
333
|
};
|
|
334
|
+
const move = async (initialModel, id, folderId) => {
|
|
335
|
+
/**
|
|
336
|
+
* We need to:
|
|
337
|
+
* - load all the revisions of the entry, including published and latest
|
|
338
|
+
* - update all the revisions (published and latest ) of the entry with new folderId
|
|
339
|
+
*/
|
|
340
|
+
const model = getStorageOperationsModel(initialModel);
|
|
341
|
+
/**
|
|
342
|
+
* First we need to load all the revisions and published / latest entry.
|
|
343
|
+
*/
|
|
344
|
+
const queryAllParams = {
|
|
345
|
+
entity,
|
|
346
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
347
|
+
id,
|
|
348
|
+
locale: model.locale,
|
|
349
|
+
tenant: model.tenant
|
|
350
|
+
}),
|
|
351
|
+
options: {
|
|
352
|
+
gte: " "
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const records = await (0, _query.queryAll)(queryAllParams);
|
|
356
|
+
/**
|
|
357
|
+
* Then create the batch writes for the DynamoDB, with the updated folderId.
|
|
358
|
+
*/
|
|
359
|
+
const items = records.map(item => {
|
|
360
|
+
return entity.putBatch({
|
|
361
|
+
...item,
|
|
362
|
+
location: {
|
|
363
|
+
...item.location,
|
|
364
|
+
folderId
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
/**
|
|
369
|
+
* And finally write it...
|
|
370
|
+
*/
|
|
371
|
+
try {
|
|
372
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
373
|
+
table: entity.table,
|
|
374
|
+
items
|
|
375
|
+
});
|
|
376
|
+
} catch (ex) {
|
|
377
|
+
throw _error.default.from(ex, {
|
|
378
|
+
message: "Could not move records to a new folder.",
|
|
379
|
+
data: {
|
|
380
|
+
id,
|
|
381
|
+
folderId
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
};
|
|
291
386
|
const deleteEntry = async (initialModel, params) => {
|
|
292
387
|
const {
|
|
293
388
|
entry
|
|
@@ -368,13 +463,25 @@ const createEntriesStorageOperations = params => {
|
|
|
368
463
|
storageEntry: initialLatestStorageEntry,
|
|
369
464
|
model
|
|
370
465
|
});
|
|
371
|
-
items.push(entity.putBatch(
|
|
466
|
+
items.push(entity.putBatch({
|
|
467
|
+
...latestStorageEntry,
|
|
372
468
|
PK: partitionKey,
|
|
373
469
|
SK: (0, _keys.createLatestSortKey)(),
|
|
374
470
|
TYPE: createLatestType(),
|
|
375
471
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
376
472
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
377
|
-
}))
|
|
473
|
+
}));
|
|
474
|
+
|
|
475
|
+
// Do an update on the latest revision. We need to update the latest revision's
|
|
476
|
+
// entry-level meta fields to match the previous revision's entry-level meta fields.
|
|
477
|
+
items.push(entity.putBatch({
|
|
478
|
+
...initialLatestStorageEntry,
|
|
479
|
+
PK: partitionKey,
|
|
480
|
+
SK: (0, _keys.createRevisionSortKey)(initialLatestStorageEntry),
|
|
481
|
+
TYPE: createType(),
|
|
482
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
483
|
+
GSI1_SK: (0, _keys.createGSISortKey)(initialLatestStorageEntry)
|
|
484
|
+
}));
|
|
378
485
|
}
|
|
379
486
|
try {
|
|
380
487
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -588,12 +695,13 @@ const createEntriesStorageOperations = params => {
|
|
|
588
695
|
model
|
|
589
696
|
});
|
|
590
697
|
} catch (ex) {
|
|
591
|
-
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR",
|
|
698
|
+
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", {
|
|
699
|
+
...params,
|
|
592
700
|
error: ex,
|
|
593
701
|
partitionKey: queryParams.partitionKey,
|
|
594
702
|
options: queryParams.options,
|
|
595
703
|
model
|
|
596
|
-
})
|
|
704
|
+
});
|
|
597
705
|
}
|
|
598
706
|
};
|
|
599
707
|
const list = async (initialModel, params) => {
|
|
@@ -634,7 +742,9 @@ const createEntriesStorageOperations = params => {
|
|
|
634
742
|
items: []
|
|
635
743
|
};
|
|
636
744
|
}
|
|
637
|
-
const where =
|
|
745
|
+
const where = {
|
|
746
|
+
...initialWhere
|
|
747
|
+
};
|
|
638
748
|
delete where["published"];
|
|
639
749
|
delete where["latest"];
|
|
640
750
|
/**
|
|
@@ -708,9 +818,10 @@ const createEntriesStorageOperations = params => {
|
|
|
708
818
|
const model = getStorageOperationsModel(initialModel);
|
|
709
819
|
const {
|
|
710
820
|
items
|
|
711
|
-
} = await list(model,
|
|
821
|
+
} = await list(model, {
|
|
822
|
+
...params,
|
|
712
823
|
limit: 1
|
|
713
|
-
})
|
|
824
|
+
});
|
|
714
825
|
return items.shift() || null;
|
|
715
826
|
};
|
|
716
827
|
const publish = async (initialModel, params) => {
|
|
@@ -741,41 +852,80 @@ const createEntriesStorageOperations = params => {
|
|
|
741
852
|
* - the latest sort key - if entry updated is actually latest
|
|
742
853
|
* - previous published entry to unpublished status - if any previously published entry
|
|
743
854
|
*/
|
|
744
|
-
const items = [entity.putBatch(
|
|
855
|
+
const items = [entity.putBatch({
|
|
856
|
+
...storageEntry,
|
|
745
857
|
PK: partitionKey,
|
|
746
858
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
747
859
|
TYPE: createType(),
|
|
748
860
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
749
861
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
750
|
-
})
|
|
862
|
+
}), entity.putBatch({
|
|
863
|
+
...storageEntry,
|
|
751
864
|
PK: partitionKey,
|
|
752
865
|
SK: (0, _keys.createPublishedSortKey)(),
|
|
753
866
|
TYPE: createPublishedType(),
|
|
754
867
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
755
868
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
756
|
-
})
|
|
757
|
-
if (initialLatestStorageEntry
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
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
|
+
|
|
888
|
+
// If the published revision is not the latest one, we still need to
|
|
889
|
+
// update the latest record with the new values of entry-level meta fields.
|
|
890
|
+
const updatedEntryLevelMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isEntryLevelEntryMetaField);
|
|
891
|
+
|
|
892
|
+
// 1. Update actual revision record.
|
|
893
|
+
items.push(entity.putBatch({
|
|
894
|
+
...latestStorageEntry,
|
|
895
|
+
...updatedEntryLevelMetaFields,
|
|
896
|
+
PK: partitionKey,
|
|
897
|
+
SK: (0, _keys.createRevisionSortKey)(latestStorageEntry),
|
|
898
|
+
TYPE: createType(),
|
|
899
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
900
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
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
|
+
}));
|
|
913
|
+
}
|
|
765
914
|
}
|
|
766
915
|
if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
|
|
767
916
|
const publishedStorageEntry = convertToStorageEntry({
|
|
768
917
|
storageEntry: initialPublishedStorageEntry,
|
|
769
918
|
model
|
|
770
919
|
});
|
|
771
|
-
items.push(entity.putBatch(
|
|
920
|
+
items.push(entity.putBatch({
|
|
921
|
+
...publishedStorageEntry,
|
|
772
922
|
PK: partitionKey,
|
|
773
923
|
SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
|
|
774
924
|
TYPE: createType(),
|
|
775
925
|
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
|
|
776
926
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
777
927
|
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
778
|
-
}))
|
|
928
|
+
}));
|
|
779
929
|
}
|
|
780
930
|
try {
|
|
781
931
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -818,26 +968,62 @@ const createEntriesStorageOperations = params => {
|
|
|
818
968
|
const items = [entity.deleteBatch({
|
|
819
969
|
PK: partitionKey,
|
|
820
970
|
SK: (0, _keys.createPublishedSortKey)()
|
|
821
|
-
}), entity.putBatch(
|
|
971
|
+
}), entity.putBatch({
|
|
972
|
+
...storageEntry,
|
|
822
973
|
PK: partitionKey,
|
|
823
974
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
824
975
|
TYPE: createType(),
|
|
825
976
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
826
977
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
827
|
-
})
|
|
978
|
+
})];
|
|
828
979
|
|
|
829
980
|
/**
|
|
830
981
|
* We need the latest entry to see if something needs to be updated alongside the unpublishing one.
|
|
831
982
|
*/
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
983
|
+
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
984
|
+
if (initialLatestStorageEntry) {
|
|
985
|
+
const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
986
|
+
if (unpublishingLatestRevision) {
|
|
987
|
+
items.push(entity.putBatch({
|
|
988
|
+
...storageEntry,
|
|
989
|
+
PK: partitionKey,
|
|
990
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
991
|
+
TYPE: createLatestType(),
|
|
992
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
993
|
+
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
994
|
+
}));
|
|
995
|
+
} else {
|
|
996
|
+
const latestStorageEntry = convertToStorageEntry({
|
|
997
|
+
storageEntry: initialLatestStorageEntry,
|
|
998
|
+
model
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
// If the unpublished revision is not the latest one, we still need to
|
|
1002
|
+
// update the latest record with the new values of entry-level meta fields.
|
|
1003
|
+
const updatedEntryLevelMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isEntryLevelEntryMetaField);
|
|
1004
|
+
|
|
1005
|
+
// 1. Update actual revision record.
|
|
1006
|
+
items.push(entity.putBatch({
|
|
1007
|
+
...latestStorageEntry,
|
|
1008
|
+
...updatedEntryLevelMetaFields,
|
|
1009
|
+
PK: partitionKey,
|
|
1010
|
+
SK: (0, _keys.createRevisionSortKey)(latestStorageEntry),
|
|
1011
|
+
TYPE: createType(),
|
|
1012
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1013
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1014
|
+
}));
|
|
1015
|
+
|
|
1016
|
+
// 2. Update latest record.
|
|
1017
|
+
items.push(entity.putBatch({
|
|
1018
|
+
...latestStorageEntry,
|
|
1019
|
+
...updatedEntryLevelMetaFields,
|
|
1020
|
+
PK: partitionKey,
|
|
1021
|
+
SK: (0, _keys.createLatestSortKey)(),
|
|
1022
|
+
TYPE: createLatestType(),
|
|
1023
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1024
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1025
|
+
}));
|
|
1026
|
+
}
|
|
841
1027
|
}
|
|
842
1028
|
try {
|
|
843
1029
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -883,10 +1069,9 @@ const createEntriesStorageOperations = params => {
|
|
|
883
1069
|
continue;
|
|
884
1070
|
}
|
|
885
1071
|
for (const value of values) {
|
|
886
|
-
var _result$value;
|
|
887
1072
|
result[value] = {
|
|
888
1073
|
value,
|
|
889
|
-
count: (
|
|
1074
|
+
count: (result[value]?.count || 0) + 1
|
|
890
1075
|
};
|
|
891
1076
|
}
|
|
892
1077
|
}
|
|
@@ -896,6 +1081,7 @@ const createEntriesStorageOperations = params => {
|
|
|
896
1081
|
create,
|
|
897
1082
|
createRevisionFrom,
|
|
898
1083
|
update,
|
|
1084
|
+
move,
|
|
899
1085
|
delete: deleteEntry,
|
|
900
1086
|
deleteRevision,
|
|
901
1087
|
deleteMultipleEntries,
|
|
@@ -915,4 +1101,6 @@ const createEntriesStorageOperations = params => {
|
|
|
915
1101
|
getUniqueFieldValues
|
|
916
1102
|
};
|
|
917
1103
|
};
|
|
918
|
-
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|
|
1104
|
+
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|
|
1105
|
+
|
|
1106
|
+
//# sourceMappingURL=index.js.map
|