@webiny/api-headless-cms-ddb 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.78f581c1d2
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.js +5 -0
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +5 -0
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +5 -0
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +5 -0
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +5 -0
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +3 -0
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.js +7 -0
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/plainObject.js +8 -1
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/date.js +16 -1
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.js +17 -1
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +18 -0
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +8 -1
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.js +21 -1
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +44 -1
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/index.js +89 -6
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +18 -0
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/systemFields.js +2 -0
- package/operations/entry/systemFields.js.map +1 -1
- package/operations/entry/utils.js +114 -0
- package/operations/entry/utils.js.map +1 -1
- package/operations/group/index.js +32 -2
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +25 -0
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +24 -0
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +17 -0
- package/operations/system/index.js.map +1 -1
- package/package.json +12 -12
- package/plugins/CmsEntryFieldFilterPathPlugin.js +14 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/index.js +2 -0
- package/plugins/index.js.map +1 -1
- package/types.js +1 -0
- package/types.js.map +1 -1
|
@@ -1,31 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.createEntriesStorageOperations = void 0;
|
|
9
|
+
|
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
9
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
10
14
|
var _dataLoaders = require("./dataLoaders");
|
|
15
|
+
|
|
11
16
|
var _types = require("@webiny/api-headless-cms/types");
|
|
17
|
+
|
|
12
18
|
var _utils = require("./utils");
|
|
19
|
+
|
|
13
20
|
var _keys = require("./keys");
|
|
21
|
+
|
|
14
22
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
23
|
+
|
|
15
24
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
25
|
+
|
|
16
26
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
27
|
+
|
|
17
28
|
var _cursor = require("@webiny/utils/cursor");
|
|
29
|
+
|
|
18
30
|
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
31
|
+
|
|
19
32
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
33
|
+
|
|
20
34
|
const createType = () => {
|
|
21
35
|
return "cms.entry";
|
|
22
36
|
};
|
|
37
|
+
|
|
23
38
|
const createLatestType = () => {
|
|
24
39
|
return `${createType()}.l`;
|
|
25
40
|
};
|
|
41
|
+
|
|
26
42
|
const createPublishedType = () => {
|
|
27
43
|
return `${createType()}.p`;
|
|
28
44
|
};
|
|
45
|
+
|
|
29
46
|
const convertToStorageEntry = params => {
|
|
30
47
|
const {
|
|
31
48
|
model,
|
|
@@ -39,6 +56,7 @@ const convertToStorageEntry = params => {
|
|
|
39
56
|
values
|
|
40
57
|
});
|
|
41
58
|
};
|
|
59
|
+
|
|
42
60
|
const convertFromStorageEntry = params => {
|
|
43
61
|
const {
|
|
44
62
|
model,
|
|
@@ -52,6 +70,7 @@ const convertFromStorageEntry = params => {
|
|
|
52
70
|
values
|
|
53
71
|
});
|
|
54
72
|
};
|
|
73
|
+
|
|
55
74
|
const createEntriesStorageOperations = params => {
|
|
56
75
|
const {
|
|
57
76
|
entity,
|
|
@@ -64,23 +83,29 @@ const createEntriesStorageOperations = params => {
|
|
|
64
83
|
collection[plugin.fieldType] = plugin;
|
|
65
84
|
return collection;
|
|
66
85
|
}, {});
|
|
86
|
+
|
|
67
87
|
const createStorageTransformCallable = model => {
|
|
68
88
|
return (field, value) => {
|
|
69
89
|
const plugin = storageTransformPlugins[field.type];
|
|
90
|
+
|
|
70
91
|
if (!plugin) {
|
|
71
92
|
return value;
|
|
72
93
|
}
|
|
94
|
+
|
|
73
95
|
return plugin.fromStorage({
|
|
74
96
|
model,
|
|
75
97
|
field,
|
|
76
98
|
value,
|
|
99
|
+
|
|
77
100
|
getStoragePlugin(fieldType) {
|
|
78
101
|
return storageTransformPlugins[fieldType] || storageTransformPlugins["*"];
|
|
79
102
|
},
|
|
103
|
+
|
|
80
104
|
plugins
|
|
81
105
|
});
|
|
82
106
|
};
|
|
83
107
|
};
|
|
108
|
+
|
|
84
109
|
const create = async (model, params) => {
|
|
85
110
|
const {
|
|
86
111
|
entry,
|
|
@@ -102,6 +127,7 @@ const createEntriesStorageOperations = params => {
|
|
|
102
127
|
* - create new main entry item
|
|
103
128
|
* - create new or update latest entry item
|
|
104
129
|
*/
|
|
130
|
+
|
|
105
131
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
106
132
|
locked,
|
|
107
133
|
PK: partitionKey,
|
|
@@ -117,10 +143,10 @@ const createEntriesStorageOperations = params => {
|
|
|
117
143
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
118
144
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
119
145
|
}))];
|
|
120
|
-
|
|
121
146
|
/**
|
|
122
147
|
* We need to create published entry if
|
|
123
148
|
*/
|
|
149
|
+
|
|
124
150
|
if (isPublished) {
|
|
125
151
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
126
152
|
locked,
|
|
@@ -131,6 +157,7 @@ const createEntriesStorageOperations = params => {
|
|
|
131
157
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
132
158
|
})));
|
|
133
159
|
}
|
|
160
|
+
|
|
134
161
|
try {
|
|
135
162
|
await (0, _batchWrite.batchWriteAll)({
|
|
136
163
|
table: entity.table,
|
|
@@ -145,8 +172,10 @@ const createEntriesStorageOperations = params => {
|
|
|
145
172
|
entry
|
|
146
173
|
});
|
|
147
174
|
}
|
|
175
|
+
|
|
148
176
|
return initialStorageEntry;
|
|
149
177
|
};
|
|
178
|
+
|
|
150
179
|
const createRevisionFrom = async (model, params) => {
|
|
151
180
|
const {
|
|
152
181
|
entry,
|
|
@@ -166,6 +195,7 @@ const createEntriesStorageOperations = params => {
|
|
|
166
195
|
* - create the main entry item
|
|
167
196
|
* - update the last entry item to a current one
|
|
168
197
|
*/
|
|
198
|
+
|
|
169
199
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
170
200
|
PK: partitionKey,
|
|
171
201
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
@@ -179,6 +209,7 @@ const createEntriesStorageOperations = params => {
|
|
|
179
209
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
180
210
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
181
211
|
}))];
|
|
212
|
+
|
|
182
213
|
try {
|
|
183
214
|
await (0, _batchWrite.batchWriteAll)({
|
|
184
215
|
table: entity.table,
|
|
@@ -197,8 +228,11 @@ const createEntriesStorageOperations = params => {
|
|
|
197
228
|
/**
|
|
198
229
|
* There are no modifications on the entry created so just return the data.
|
|
199
230
|
*/
|
|
231
|
+
|
|
232
|
+
|
|
200
233
|
return initialStorageEntry;
|
|
201
234
|
};
|
|
235
|
+
|
|
202
236
|
const update = async (model, params) => {
|
|
203
237
|
const {
|
|
204
238
|
entry,
|
|
@@ -221,6 +255,7 @@ const createEntriesStorageOperations = params => {
|
|
|
221
255
|
* - update the current entry
|
|
222
256
|
* - update the latest entry if the current entry is the latest one
|
|
223
257
|
*/
|
|
258
|
+
|
|
224
259
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
225
260
|
locked,
|
|
226
261
|
PK: partitionKey,
|
|
@@ -229,6 +264,7 @@ const createEntriesStorageOperations = params => {
|
|
|
229
264
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
230
265
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
231
266
|
})));
|
|
267
|
+
|
|
232
268
|
if (isPublished) {
|
|
233
269
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
234
270
|
locked,
|
|
@@ -239,11 +275,13 @@ const createEntriesStorageOperations = params => {
|
|
|
239
275
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
240
276
|
})));
|
|
241
277
|
}
|
|
242
|
-
|
|
243
278
|
/**
|
|
244
279
|
* We need the latest entry to update it as well if neccessary.
|
|
245
280
|
*/
|
|
281
|
+
|
|
282
|
+
|
|
246
283
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
284
|
+
|
|
247
285
|
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
248
286
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
249
287
|
locked,
|
|
@@ -254,6 +292,7 @@ const createEntriesStorageOperations = params => {
|
|
|
254
292
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
255
293
|
})));
|
|
256
294
|
}
|
|
295
|
+
|
|
257
296
|
try {
|
|
258
297
|
await (0, _batchWrite.batchWriteAll)({
|
|
259
298
|
table: entity.table,
|
|
@@ -271,6 +310,7 @@ const createEntriesStorageOperations = params => {
|
|
|
271
310
|
});
|
|
272
311
|
}
|
|
273
312
|
};
|
|
313
|
+
|
|
274
314
|
const deleteEntry = async (model, params) => {
|
|
275
315
|
const {
|
|
276
316
|
entry
|
|
@@ -287,6 +327,7 @@ const createEntriesStorageOperations = params => {
|
|
|
287
327
|
}
|
|
288
328
|
};
|
|
289
329
|
let records = [];
|
|
330
|
+
|
|
290
331
|
try {
|
|
291
332
|
records = await (0, _query.queryAll)(queryAllParams);
|
|
292
333
|
} catch (ex) {
|
|
@@ -295,12 +336,14 @@ const createEntriesStorageOperations = params => {
|
|
|
295
336
|
entry
|
|
296
337
|
});
|
|
297
338
|
}
|
|
339
|
+
|
|
298
340
|
const items = records.map(item => {
|
|
299
341
|
return entity.deleteBatch({
|
|
300
342
|
PK: item.PK,
|
|
301
343
|
SK: item.SK
|
|
302
344
|
});
|
|
303
345
|
});
|
|
346
|
+
|
|
304
347
|
try {
|
|
305
348
|
await (0, _batchWrite.batchWriteAll)({
|
|
306
349
|
table: entity.table,
|
|
@@ -317,6 +360,7 @@ const createEntriesStorageOperations = params => {
|
|
|
317
360
|
});
|
|
318
361
|
}
|
|
319
362
|
};
|
|
363
|
+
|
|
320
364
|
const deleteRevision = async (model, params) => {
|
|
321
365
|
const {
|
|
322
366
|
entry,
|
|
@@ -333,16 +377,17 @@ const createEntriesStorageOperations = params => {
|
|
|
333
377
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
334
378
|
})];
|
|
335
379
|
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
336
|
-
|
|
337
380
|
/**
|
|
338
381
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
339
382
|
*/
|
|
383
|
+
|
|
340
384
|
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
341
385
|
items.push(entity.deleteBatch({
|
|
342
386
|
PK: partitionKey,
|
|
343
387
|
SK: (0, _keys.createPublishedSortKey)()
|
|
344
388
|
}));
|
|
345
389
|
}
|
|
390
|
+
|
|
346
391
|
if (initialLatestStorageEntry) {
|
|
347
392
|
const latestStorageEntry = convertToStorageEntry({
|
|
348
393
|
storageEntry: initialLatestStorageEntry,
|
|
@@ -356,6 +401,7 @@ const createEntriesStorageOperations = params => {
|
|
|
356
401
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
357
402
|
})));
|
|
358
403
|
}
|
|
404
|
+
|
|
359
405
|
try {
|
|
360
406
|
await (0, _batchWrite.batchWriteAll)({
|
|
361
407
|
table: entity.table,
|
|
@@ -372,48 +418,58 @@ const createEntriesStorageOperations = params => {
|
|
|
372
418
|
});
|
|
373
419
|
}
|
|
374
420
|
};
|
|
421
|
+
|
|
375
422
|
const getLatestRevisionByEntryId = async (model, params) => {
|
|
376
423
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
377
424
|
model,
|
|
378
425
|
ids: [params.id]
|
|
379
426
|
});
|
|
380
427
|
const item = items.shift() || null;
|
|
428
|
+
|
|
381
429
|
if (!item) {
|
|
382
430
|
return null;
|
|
383
431
|
}
|
|
432
|
+
|
|
384
433
|
return convertFromStorageEntry({
|
|
385
434
|
storageEntry: item,
|
|
386
435
|
model
|
|
387
436
|
});
|
|
388
437
|
};
|
|
438
|
+
|
|
389
439
|
const getPublishedRevisionByEntryId = async (model, params) => {
|
|
390
440
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
391
441
|
model,
|
|
392
442
|
ids: [params.id]
|
|
393
443
|
});
|
|
394
444
|
const item = items.shift() || null;
|
|
445
|
+
|
|
395
446
|
if (!item) {
|
|
396
447
|
return null;
|
|
397
448
|
}
|
|
449
|
+
|
|
398
450
|
return convertFromStorageEntry({
|
|
399
451
|
storageEntry: item,
|
|
400
452
|
model
|
|
401
453
|
});
|
|
402
454
|
};
|
|
455
|
+
|
|
403
456
|
const getRevisionById = async (model, params) => {
|
|
404
457
|
const items = await dataLoaders.getRevisionById({
|
|
405
458
|
model,
|
|
406
459
|
ids: [params.id]
|
|
407
460
|
});
|
|
408
461
|
const item = items.shift() || null;
|
|
462
|
+
|
|
409
463
|
if (!item) {
|
|
410
464
|
return null;
|
|
411
465
|
}
|
|
466
|
+
|
|
412
467
|
return convertFromStorageEntry({
|
|
413
468
|
storageEntry: item,
|
|
414
469
|
model
|
|
415
470
|
});
|
|
416
471
|
};
|
|
472
|
+
|
|
417
473
|
const getRevisions = async (model, params) => {
|
|
418
474
|
const items = await dataLoaders.getAllEntryRevisions({
|
|
419
475
|
model,
|
|
@@ -426,6 +482,7 @@ const createEntriesStorageOperations = params => {
|
|
|
426
482
|
});
|
|
427
483
|
});
|
|
428
484
|
};
|
|
485
|
+
|
|
429
486
|
const getByIds = async (model, params) => {
|
|
430
487
|
const items = await dataLoaders.getRevisionById({
|
|
431
488
|
model,
|
|
@@ -438,6 +495,7 @@ const createEntriesStorageOperations = params => {
|
|
|
438
495
|
});
|
|
439
496
|
});
|
|
440
497
|
};
|
|
498
|
+
|
|
441
499
|
const getLatestByIds = async (model, params) => {
|
|
442
500
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
443
501
|
model,
|
|
@@ -450,6 +508,7 @@ const createEntriesStorageOperations = params => {
|
|
|
450
508
|
});
|
|
451
509
|
});
|
|
452
510
|
};
|
|
511
|
+
|
|
453
512
|
const getPublishedByIds = async (model, params) => {
|
|
454
513
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
455
514
|
model,
|
|
@@ -462,6 +521,7 @@ const createEntriesStorageOperations = params => {
|
|
|
462
521
|
});
|
|
463
522
|
});
|
|
464
523
|
};
|
|
524
|
+
|
|
465
525
|
const getPreviousRevision = async (model, params) => {
|
|
466
526
|
const {
|
|
467
527
|
entryId,
|
|
@@ -476,6 +536,7 @@ const createEntriesStorageOperations = params => {
|
|
|
476
536
|
}),
|
|
477
537
|
options: {
|
|
478
538
|
lt: `REV#${(0, _zeroPad.zeroPad)(version)}`,
|
|
539
|
+
|
|
479
540
|
/**
|
|
480
541
|
* We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
|
|
481
542
|
*/
|
|
@@ -489,12 +550,15 @@ const createEntriesStorageOperations = params => {
|
|
|
489
550
|
reverse: true
|
|
490
551
|
}
|
|
491
552
|
};
|
|
553
|
+
|
|
492
554
|
try {
|
|
493
555
|
const result = await (0, _query.queryOne)(queryParams);
|
|
494
556
|
const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
|
|
557
|
+
|
|
495
558
|
if (!storageEntry) {
|
|
496
559
|
return null;
|
|
497
560
|
}
|
|
561
|
+
|
|
498
562
|
return convertFromStorageEntry({
|
|
499
563
|
storageEntry,
|
|
500
564
|
model
|
|
@@ -508,6 +572,7 @@ const createEntriesStorageOperations = params => {
|
|
|
508
572
|
}));
|
|
509
573
|
}
|
|
510
574
|
};
|
|
575
|
+
|
|
511
576
|
const list = async (model, params) => {
|
|
512
577
|
const {
|
|
513
578
|
limit: initialLimit = 10,
|
|
@@ -528,6 +593,7 @@ const createEntriesStorageOperations = params => {
|
|
|
528
593
|
}
|
|
529
594
|
};
|
|
530
595
|
let records = [];
|
|
596
|
+
|
|
531
597
|
try {
|
|
532
598
|
records = await (0, _query.queryAll)(queryAllParams);
|
|
533
599
|
} catch (ex) {
|
|
@@ -537,6 +603,7 @@ const createEntriesStorageOperations = params => {
|
|
|
537
603
|
options: queryAllParams.options
|
|
538
604
|
});
|
|
539
605
|
}
|
|
606
|
+
|
|
540
607
|
if (records.length === 0) {
|
|
541
608
|
return {
|
|
542
609
|
hasMoreItems: false,
|
|
@@ -545,6 +612,7 @@ const createEntriesStorageOperations = params => {
|
|
|
545
612
|
items: []
|
|
546
613
|
};
|
|
547
614
|
}
|
|
615
|
+
|
|
548
616
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
549
617
|
delete where["published"];
|
|
550
618
|
delete where["latest"];
|
|
@@ -552,6 +620,7 @@ const createEntriesStorageOperations = params => {
|
|
|
552
620
|
* We need a object containing field, transformers and paths.
|
|
553
621
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
554
622
|
*/
|
|
623
|
+
|
|
555
624
|
const modelFields = (0, _utils.buildModelFields)({
|
|
556
625
|
plugins,
|
|
557
626
|
model
|
|
@@ -560,6 +629,7 @@ const createEntriesStorageOperations = params => {
|
|
|
560
629
|
* Filter the read items via the code.
|
|
561
630
|
* It will build the filters out of the where input and transform the values it is using.
|
|
562
631
|
*/
|
|
632
|
+
|
|
563
633
|
const filteredItems = await (0, _utils.filterItems)({
|
|
564
634
|
items: records.map(record => {
|
|
565
635
|
return convertFromStorageEntry({
|
|
@@ -577,11 +647,11 @@ const createEntriesStorageOperations = params => {
|
|
|
577
647
|
}
|
|
578
648
|
});
|
|
579
649
|
const totalCount = filteredItems.length;
|
|
580
|
-
|
|
581
650
|
/**
|
|
582
651
|
* Sorting is also done via the code.
|
|
583
652
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
584
653
|
*/
|
|
654
|
+
|
|
585
655
|
const sortedItems = (0, _utils.sortEntryItems)({
|
|
586
656
|
items: filteredItems,
|
|
587
657
|
sort,
|
|
@@ -595,6 +665,7 @@ const createEntriesStorageOperations = params => {
|
|
|
595
665
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
596
666
|
* Number is simply encoded.
|
|
597
667
|
*/
|
|
668
|
+
|
|
598
669
|
const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(`${start + limit}`) : null;
|
|
599
670
|
return {
|
|
600
671
|
hasMoreItems,
|
|
@@ -603,6 +674,7 @@ const createEntriesStorageOperations = params => {
|
|
|
603
674
|
items: (0, _cleanup.cleanupItems)(entity, slicedItems)
|
|
604
675
|
};
|
|
605
676
|
};
|
|
677
|
+
|
|
606
678
|
const get = async (model, params) => {
|
|
607
679
|
const {
|
|
608
680
|
items
|
|
@@ -611,6 +683,7 @@ const createEntriesStorageOperations = params => {
|
|
|
611
683
|
}));
|
|
612
684
|
return items.shift() || null;
|
|
613
685
|
};
|
|
686
|
+
|
|
614
687
|
const publish = async (model, params) => {
|
|
615
688
|
const {
|
|
616
689
|
entry,
|
|
@@ -621,10 +694,10 @@ const createEntriesStorageOperations = params => {
|
|
|
621
694
|
locale: model.locale,
|
|
622
695
|
tenant: model.tenant
|
|
623
696
|
});
|
|
624
|
-
|
|
625
697
|
/**
|
|
626
698
|
* We need the latest and published entries to see if something needs to be updated along side the publishing one.
|
|
627
699
|
*/
|
|
700
|
+
|
|
628
701
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
629
702
|
const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
630
703
|
const storageEntry = convertToStorageEntry({
|
|
@@ -638,6 +711,7 @@ const createEntriesStorageOperations = params => {
|
|
|
638
711
|
* - latest sort key - if entry updated is actually latest
|
|
639
712
|
* - previous published entry to unpublished status - if any previously published entry
|
|
640
713
|
*/
|
|
714
|
+
|
|
641
715
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
642
716
|
PK: partitionKey,
|
|
643
717
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
@@ -651,6 +725,7 @@ const createEntriesStorageOperations = params => {
|
|
|
651
725
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
652
726
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
653
727
|
}))];
|
|
728
|
+
|
|
654
729
|
if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {
|
|
655
730
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
656
731
|
PK: partitionKey,
|
|
@@ -660,6 +735,7 @@ const createEntriesStorageOperations = params => {
|
|
|
660
735
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
661
736
|
})));
|
|
662
737
|
}
|
|
738
|
+
|
|
663
739
|
if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
|
|
664
740
|
const publishedStorageEntry = convertToStorageEntry({
|
|
665
741
|
storageEntry: initialPublishedStorageEntry,
|
|
@@ -674,6 +750,7 @@ const createEntriesStorageOperations = params => {
|
|
|
674
750
|
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
675
751
|
})));
|
|
676
752
|
}
|
|
753
|
+
|
|
677
754
|
try {
|
|
678
755
|
await (0, _batchWrite.batchWriteAll)({
|
|
679
756
|
table: entity.table,
|
|
@@ -691,6 +768,7 @@ const createEntriesStorageOperations = params => {
|
|
|
691
768
|
});
|
|
692
769
|
}
|
|
693
770
|
};
|
|
771
|
+
|
|
694
772
|
const unpublish = async (model, params) => {
|
|
695
773
|
const {
|
|
696
774
|
entry,
|
|
@@ -711,6 +789,7 @@ const createEntriesStorageOperations = params => {
|
|
|
711
789
|
* - update current entry revision with new data
|
|
712
790
|
* - update latest entry status - if entry being unpublished is latest
|
|
713
791
|
*/
|
|
792
|
+
|
|
714
793
|
const items = [entity.deleteBatch({
|
|
715
794
|
PK: partitionKey,
|
|
716
795
|
SK: (0, _keys.createPublishedSortKey)()
|
|
@@ -721,11 +800,12 @@ const createEntriesStorageOperations = params => {
|
|
|
721
800
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
722
801
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
723
802
|
}))];
|
|
724
|
-
|
|
725
803
|
/**
|
|
726
804
|
* We need the latest entry to see if something needs to be updated along side the unpublishing one.
|
|
727
805
|
*/
|
|
806
|
+
|
|
728
807
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
808
|
+
|
|
729
809
|
if (latestStorageEntry && entry.id === latestStorageEntry.id) {
|
|
730
810
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
731
811
|
PK: partitionKey,
|
|
@@ -735,6 +815,7 @@ const createEntriesStorageOperations = params => {
|
|
|
735
815
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
736
816
|
})));
|
|
737
817
|
}
|
|
818
|
+
|
|
738
819
|
try {
|
|
739
820
|
await (0, _batchWrite.batchWriteAll)({
|
|
740
821
|
table: entity.table,
|
|
@@ -751,6 +832,7 @@ const createEntriesStorageOperations = params => {
|
|
|
751
832
|
});
|
|
752
833
|
}
|
|
753
834
|
};
|
|
835
|
+
|
|
754
836
|
return {
|
|
755
837
|
create,
|
|
756
838
|
createRevisionFrom,
|
|
@@ -771,4 +853,5 @@ const createEntriesStorageOperations = params => {
|
|
|
771
853
|
unpublish
|
|
772
854
|
};
|
|
773
855
|
};
|
|
856
|
+
|
|
774
857
|
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|