@webiny/api-headless-cms-ddb 0.0.0-unstable.5e7233243f → 0.0.0-unstable.6e5425ee89
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 +3 -12
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +3 -12
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +3 -12
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +3 -12
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +3 -12
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +0 -7
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/plainObject.js +2 -9
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/date.js +2 -17
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.js +2 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +1 -19
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +1 -8
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +22 -25
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +7 -52
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/index.js +28 -238
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +1 -19
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/systemFields.js +6 -2
- package/operations/entry/systemFields.js.map +1 -1
- package/operations/entry/utils.js +3 -121
- package/operations/entry/utils.js.map +1 -1
- package/operations/group/index.js +8 -42
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +4 -33
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +6 -34
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +4 -25
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.js +1 -15
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +16 -0
- package/plugins/index.js.map +1 -0
- package/types.js +0 -1
- package/types.js.map +1 -1
|
@@ -1,52 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createEntriesStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _dataLoaders = require("./dataLoaders");
|
|
15
|
-
|
|
16
11
|
var _types = require("@webiny/api-headless-cms/types");
|
|
17
|
-
|
|
18
12
|
var _utils = require("./utils");
|
|
19
|
-
|
|
20
13
|
var _keys = require("./keys");
|
|
21
|
-
|
|
22
14
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
23
|
-
|
|
24
15
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
25
|
-
|
|
26
16
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
27
|
-
|
|
28
17
|
var _cursor = require("@webiny/utils/cursor");
|
|
29
|
-
|
|
30
18
|
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
31
|
-
|
|
32
19
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
33
|
-
|
|
34
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
-
|
|
36
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
37
|
-
|
|
38
20
|
const createType = () => {
|
|
39
21
|
return "cms.entry";
|
|
40
22
|
};
|
|
41
|
-
|
|
42
23
|
const createLatestType = () => {
|
|
43
24
|
return `${createType()}.l`;
|
|
44
25
|
};
|
|
45
|
-
|
|
46
26
|
const createPublishedType = () => {
|
|
47
27
|
return `${createType()}.p`;
|
|
48
28
|
};
|
|
49
|
-
|
|
50
29
|
const convertToStorageEntry = params => {
|
|
51
30
|
const {
|
|
52
31
|
model,
|
|
@@ -56,11 +35,10 @@ const convertToStorageEntry = params => {
|
|
|
56
35
|
fields: model.fields,
|
|
57
36
|
values: storageEntry.values
|
|
58
37
|
});
|
|
59
|
-
return
|
|
38
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
60
39
|
values
|
|
61
40
|
});
|
|
62
41
|
};
|
|
63
|
-
|
|
64
42
|
const convertFromStorageEntry = params => {
|
|
65
43
|
const {
|
|
66
44
|
model,
|
|
@@ -70,11 +48,10 @@ const convertFromStorageEntry = params => {
|
|
|
70
48
|
fields: model.fields,
|
|
71
49
|
values: storageEntry.values
|
|
72
50
|
});
|
|
73
|
-
return
|
|
51
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
74
52
|
values
|
|
75
53
|
});
|
|
76
54
|
};
|
|
77
|
-
|
|
78
55
|
const createEntriesStorageOperations = params => {
|
|
79
56
|
const {
|
|
80
57
|
entity,
|
|
@@ -87,29 +64,23 @@ const createEntriesStorageOperations = params => {
|
|
|
87
64
|
collection[plugin.fieldType] = plugin;
|
|
88
65
|
return collection;
|
|
89
66
|
}, {});
|
|
90
|
-
|
|
91
67
|
const createStorageTransformCallable = model => {
|
|
92
68
|
return (field, value) => {
|
|
93
69
|
const plugin = storageTransformPlugins[field.type];
|
|
94
|
-
|
|
95
70
|
if (!plugin) {
|
|
96
71
|
return value;
|
|
97
72
|
}
|
|
98
|
-
|
|
99
73
|
return plugin.fromStorage({
|
|
100
74
|
model,
|
|
101
75
|
field,
|
|
102
76
|
value,
|
|
103
|
-
|
|
104
77
|
getStoragePlugin(fieldType) {
|
|
105
78
|
return storageTransformPlugins[fieldType] || storageTransformPlugins["*"];
|
|
106
79
|
},
|
|
107
|
-
|
|
108
80
|
plugins
|
|
109
81
|
});
|
|
110
82
|
};
|
|
111
83
|
};
|
|
112
|
-
|
|
113
84
|
const create = async (model, params) => {
|
|
114
85
|
const {
|
|
115
86
|
entry,
|
|
@@ -131,15 +102,14 @@ const createEntriesStorageOperations = params => {
|
|
|
131
102
|
* - create new main entry item
|
|
132
103
|
* - create new or update latest entry item
|
|
133
104
|
*/
|
|
134
|
-
|
|
135
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
105
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
136
106
|
locked,
|
|
137
107
|
PK: partitionKey,
|
|
138
108
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
139
109
|
TYPE: createType(),
|
|
140
110
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
141
111
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
142
|
-
})), entity.putBatch(
|
|
112
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
143
113
|
locked,
|
|
144
114
|
PK: partitionKey,
|
|
145
115
|
SK: (0, _keys.createLatestSortKey)(),
|
|
@@ -147,12 +117,12 @@ const createEntriesStorageOperations = params => {
|
|
|
147
117
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
148
118
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
149
119
|
}))];
|
|
120
|
+
|
|
150
121
|
/**
|
|
151
122
|
* We need to create published entry if
|
|
152
123
|
*/
|
|
153
|
-
|
|
154
124
|
if (isPublished) {
|
|
155
|
-
items.push(entity.putBatch(
|
|
125
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
156
126
|
locked,
|
|
157
127
|
PK: partitionKey,
|
|
158
128
|
SK: (0, _keys.createPublishedSortKey)(),
|
|
@@ -161,7 +131,6 @@ const createEntriesStorageOperations = params => {
|
|
|
161
131
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
162
132
|
})));
|
|
163
133
|
}
|
|
164
|
-
|
|
165
134
|
try {
|
|
166
135
|
await (0, _batchWrite.batchWriteAll)({
|
|
167
136
|
table: entity.table,
|
|
@@ -176,10 +145,8 @@ const createEntriesStorageOperations = params => {
|
|
|
176
145
|
entry
|
|
177
146
|
});
|
|
178
147
|
}
|
|
179
|
-
|
|
180
148
|
return initialStorageEntry;
|
|
181
149
|
};
|
|
182
|
-
|
|
183
150
|
const createRevisionFrom = async (model, params) => {
|
|
184
151
|
const {
|
|
185
152
|
entry,
|
|
@@ -199,21 +166,19 @@ const createEntriesStorageOperations = params => {
|
|
|
199
166
|
* - create the main entry item
|
|
200
167
|
* - update the last entry item to a current one
|
|
201
168
|
*/
|
|
202
|
-
|
|
203
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
169
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
204
170
|
PK: partitionKey,
|
|
205
171
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
206
172
|
TYPE: createType(),
|
|
207
173
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
208
174
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
209
|
-
})), entity.putBatch(
|
|
175
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
210
176
|
PK: partitionKey,
|
|
211
177
|
SK: (0, _keys.createLatestSortKey)(),
|
|
212
178
|
TYPE: createLatestType(),
|
|
213
179
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
214
180
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
215
181
|
}))];
|
|
216
|
-
|
|
217
182
|
try {
|
|
218
183
|
await (0, _batchWrite.batchWriteAll)({
|
|
219
184
|
table: entity.table,
|
|
@@ -232,11 +197,8 @@ const createEntriesStorageOperations = params => {
|
|
|
232
197
|
/**
|
|
233
198
|
* There are no modifications on the entry created so just return the data.
|
|
234
199
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
200
|
return initialStorageEntry;
|
|
238
201
|
};
|
|
239
|
-
|
|
240
202
|
const update = async (model, params) => {
|
|
241
203
|
const {
|
|
242
204
|
entry,
|
|
@@ -259,8 +221,7 @@ const createEntriesStorageOperations = params => {
|
|
|
259
221
|
* - update the current entry
|
|
260
222
|
* - update the latest entry if the current entry is the latest one
|
|
261
223
|
*/
|
|
262
|
-
|
|
263
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
224
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
264
225
|
locked,
|
|
265
226
|
PK: partitionKey,
|
|
266
227
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
@@ -268,9 +229,8 @@ const createEntriesStorageOperations = params => {
|
|
|
268
229
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
269
230
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
270
231
|
})));
|
|
271
|
-
|
|
272
232
|
if (isPublished) {
|
|
273
|
-
items.push(entity.putBatch(
|
|
233
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
274
234
|
locked,
|
|
275
235
|
PK: partitionKey,
|
|
276
236
|
SK: (0, _keys.createPublishedSortKey)(),
|
|
@@ -279,15 +239,13 @@ const createEntriesStorageOperations = params => {
|
|
|
279
239
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
280
240
|
})));
|
|
281
241
|
}
|
|
242
|
+
|
|
282
243
|
/**
|
|
283
244
|
* We need the latest entry to update it as well if neccessary.
|
|
284
245
|
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
246
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
288
|
-
|
|
289
247
|
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
290
|
-
items.push(entity.putBatch(
|
|
248
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
291
249
|
locked,
|
|
292
250
|
PK: partitionKey,
|
|
293
251
|
SK: (0, _keys.createLatestSortKey)(),
|
|
@@ -296,7 +254,6 @@ const createEntriesStorageOperations = params => {
|
|
|
296
254
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
297
255
|
})));
|
|
298
256
|
}
|
|
299
|
-
|
|
300
257
|
try {
|
|
301
258
|
await (0, _batchWrite.batchWriteAll)({
|
|
302
259
|
table: entity.table,
|
|
@@ -314,7 +271,6 @@ const createEntriesStorageOperations = params => {
|
|
|
314
271
|
});
|
|
315
272
|
}
|
|
316
273
|
};
|
|
317
|
-
|
|
318
274
|
const deleteEntry = async (model, params) => {
|
|
319
275
|
const {
|
|
320
276
|
entry
|
|
@@ -331,7 +287,6 @@ const createEntriesStorageOperations = params => {
|
|
|
331
287
|
}
|
|
332
288
|
};
|
|
333
289
|
let records = [];
|
|
334
|
-
|
|
335
290
|
try {
|
|
336
291
|
records = await (0, _query.queryAll)(queryAllParams);
|
|
337
292
|
} catch (ex) {
|
|
@@ -340,14 +295,12 @@ const createEntriesStorageOperations = params => {
|
|
|
340
295
|
entry
|
|
341
296
|
});
|
|
342
297
|
}
|
|
343
|
-
|
|
344
298
|
const items = records.map(item => {
|
|
345
299
|
return entity.deleteBatch({
|
|
346
300
|
PK: item.PK,
|
|
347
301
|
SK: item.SK
|
|
348
302
|
});
|
|
349
303
|
});
|
|
350
|
-
|
|
351
304
|
try {
|
|
352
305
|
await (0, _batchWrite.batchWriteAll)({
|
|
353
306
|
table: entity.table,
|
|
@@ -364,7 +317,6 @@ const createEntriesStorageOperations = params => {
|
|
|
364
317
|
});
|
|
365
318
|
}
|
|
366
319
|
};
|
|
367
|
-
|
|
368
320
|
const deleteRevision = async (model, params) => {
|
|
369
321
|
const {
|
|
370
322
|
entry,
|
|
@@ -381,23 +333,22 @@ const createEntriesStorageOperations = params => {
|
|
|
381
333
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
382
334
|
})];
|
|
383
335
|
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
336
|
+
|
|
384
337
|
/**
|
|
385
338
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
386
339
|
*/
|
|
387
|
-
|
|
388
340
|
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
389
341
|
items.push(entity.deleteBatch({
|
|
390
342
|
PK: partitionKey,
|
|
391
343
|
SK: (0, _keys.createPublishedSortKey)()
|
|
392
344
|
}));
|
|
393
345
|
}
|
|
394
|
-
|
|
395
346
|
if (initialLatestStorageEntry) {
|
|
396
347
|
const latestStorageEntry = convertToStorageEntry({
|
|
397
348
|
storageEntry: initialLatestStorageEntry,
|
|
398
349
|
model
|
|
399
350
|
});
|
|
400
|
-
items.push(entity.putBatch(
|
|
351
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestStorageEntry), {}, {
|
|
401
352
|
PK: partitionKey,
|
|
402
353
|
SK: (0, _keys.createLatestSortKey)(),
|
|
403
354
|
TYPE: createLatestType(),
|
|
@@ -405,7 +356,6 @@ const createEntriesStorageOperations = params => {
|
|
|
405
356
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
406
357
|
})));
|
|
407
358
|
}
|
|
408
|
-
|
|
409
359
|
try {
|
|
410
360
|
await (0, _batchWrite.batchWriteAll)({
|
|
411
361
|
table: entity.table,
|
|
@@ -422,58 +372,48 @@ const createEntriesStorageOperations = params => {
|
|
|
422
372
|
});
|
|
423
373
|
}
|
|
424
374
|
};
|
|
425
|
-
|
|
426
375
|
const getLatestRevisionByEntryId = async (model, params) => {
|
|
427
376
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
428
377
|
model,
|
|
429
378
|
ids: [params.id]
|
|
430
379
|
});
|
|
431
380
|
const item = items.shift() || null;
|
|
432
|
-
|
|
433
381
|
if (!item) {
|
|
434
382
|
return null;
|
|
435
383
|
}
|
|
436
|
-
|
|
437
384
|
return convertFromStorageEntry({
|
|
438
385
|
storageEntry: item,
|
|
439
386
|
model
|
|
440
387
|
});
|
|
441
388
|
};
|
|
442
|
-
|
|
443
389
|
const getPublishedRevisionByEntryId = async (model, params) => {
|
|
444
390
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
445
391
|
model,
|
|
446
392
|
ids: [params.id]
|
|
447
393
|
});
|
|
448
394
|
const item = items.shift() || null;
|
|
449
|
-
|
|
450
395
|
if (!item) {
|
|
451
396
|
return null;
|
|
452
397
|
}
|
|
453
|
-
|
|
454
398
|
return convertFromStorageEntry({
|
|
455
399
|
storageEntry: item,
|
|
456
400
|
model
|
|
457
401
|
});
|
|
458
402
|
};
|
|
459
|
-
|
|
460
403
|
const getRevisionById = async (model, params) => {
|
|
461
404
|
const items = await dataLoaders.getRevisionById({
|
|
462
405
|
model,
|
|
463
406
|
ids: [params.id]
|
|
464
407
|
});
|
|
465
408
|
const item = items.shift() || null;
|
|
466
|
-
|
|
467
409
|
if (!item) {
|
|
468
410
|
return null;
|
|
469
411
|
}
|
|
470
|
-
|
|
471
412
|
return convertFromStorageEntry({
|
|
472
413
|
storageEntry: item,
|
|
473
414
|
model
|
|
474
415
|
});
|
|
475
416
|
};
|
|
476
|
-
|
|
477
417
|
const getRevisions = async (model, params) => {
|
|
478
418
|
const items = await dataLoaders.getAllEntryRevisions({
|
|
479
419
|
model,
|
|
@@ -486,7 +426,6 @@ const createEntriesStorageOperations = params => {
|
|
|
486
426
|
});
|
|
487
427
|
});
|
|
488
428
|
};
|
|
489
|
-
|
|
490
429
|
const getByIds = async (model, params) => {
|
|
491
430
|
const items = await dataLoaders.getRevisionById({
|
|
492
431
|
model,
|
|
@@ -499,7 +438,6 @@ const createEntriesStorageOperations = params => {
|
|
|
499
438
|
});
|
|
500
439
|
});
|
|
501
440
|
};
|
|
502
|
-
|
|
503
441
|
const getLatestByIds = async (model, params) => {
|
|
504
442
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
505
443
|
model,
|
|
@@ -512,7 +450,6 @@ const createEntriesStorageOperations = params => {
|
|
|
512
450
|
});
|
|
513
451
|
});
|
|
514
452
|
};
|
|
515
|
-
|
|
516
453
|
const getPublishedByIds = async (model, params) => {
|
|
517
454
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
518
455
|
model,
|
|
@@ -525,7 +462,6 @@ const createEntriesStorageOperations = params => {
|
|
|
525
462
|
});
|
|
526
463
|
});
|
|
527
464
|
};
|
|
528
|
-
|
|
529
465
|
const getPreviousRevision = async (model, params) => {
|
|
530
466
|
const {
|
|
531
467
|
entryId,
|
|
@@ -540,7 +476,6 @@ const createEntriesStorageOperations = params => {
|
|
|
540
476
|
}),
|
|
541
477
|
options: {
|
|
542
478
|
lt: `REV#${(0, _zeroPad.zeroPad)(version)}`,
|
|
543
|
-
|
|
544
479
|
/**
|
|
545
480
|
* We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
|
|
546
481
|
*/
|
|
@@ -554,21 +489,18 @@ const createEntriesStorageOperations = params => {
|
|
|
554
489
|
reverse: true
|
|
555
490
|
}
|
|
556
491
|
};
|
|
557
|
-
|
|
558
492
|
try {
|
|
559
493
|
const result = await (0, _query.queryOne)(queryParams);
|
|
560
494
|
const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
|
|
561
|
-
|
|
562
495
|
if (!storageEntry) {
|
|
563
496
|
return null;
|
|
564
497
|
}
|
|
565
|
-
|
|
566
498
|
return convertFromStorageEntry({
|
|
567
499
|
storageEntry,
|
|
568
500
|
model
|
|
569
501
|
});
|
|
570
502
|
} catch (ex) {
|
|
571
|
-
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR",
|
|
503
|
+
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
572
504
|
error: ex,
|
|
573
505
|
partitionKey: queryParams.partitionKey,
|
|
574
506
|
options: queryParams.options,
|
|
@@ -576,7 +508,6 @@ const createEntriesStorageOperations = params => {
|
|
|
576
508
|
}));
|
|
577
509
|
}
|
|
578
510
|
};
|
|
579
|
-
|
|
580
511
|
const list = async (model, params) => {
|
|
581
512
|
const {
|
|
582
513
|
limit: initialLimit = 10,
|
|
@@ -597,7 +528,6 @@ const createEntriesStorageOperations = params => {
|
|
|
597
528
|
}
|
|
598
529
|
};
|
|
599
530
|
let records = [];
|
|
600
|
-
|
|
601
531
|
try {
|
|
602
532
|
records = await (0, _query.queryAll)(queryAllParams);
|
|
603
533
|
} catch (ex) {
|
|
@@ -607,7 +537,6 @@ const createEntriesStorageOperations = params => {
|
|
|
607
537
|
options: queryAllParams.options
|
|
608
538
|
});
|
|
609
539
|
}
|
|
610
|
-
|
|
611
540
|
if (records.length === 0) {
|
|
612
541
|
return {
|
|
613
542
|
hasMoreItems: false,
|
|
@@ -616,16 +545,13 @@ const createEntriesStorageOperations = params => {
|
|
|
616
545
|
items: []
|
|
617
546
|
};
|
|
618
547
|
}
|
|
619
|
-
|
|
620
|
-
const where = _objectSpread({}, initialWhere);
|
|
621
|
-
|
|
548
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
622
549
|
delete where["published"];
|
|
623
550
|
delete where["latest"];
|
|
624
551
|
/**
|
|
625
552
|
* We need a object containing field, transformers and paths.
|
|
626
553
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
627
554
|
*/
|
|
628
|
-
|
|
629
555
|
const modelFields = (0, _utils.buildModelFields)({
|
|
630
556
|
plugins,
|
|
631
557
|
model
|
|
@@ -634,7 +560,6 @@ const createEntriesStorageOperations = params => {
|
|
|
634
560
|
* Filter the read items via the code.
|
|
635
561
|
* It will build the filters out of the where input and transform the values it is using.
|
|
636
562
|
*/
|
|
637
|
-
|
|
638
563
|
const filteredItems = await (0, _utils.filterItems)({
|
|
639
564
|
items: records.map(record => {
|
|
640
565
|
return convertFromStorageEntry({
|
|
@@ -652,11 +577,11 @@ const createEntriesStorageOperations = params => {
|
|
|
652
577
|
}
|
|
653
578
|
});
|
|
654
579
|
const totalCount = filteredItems.length;
|
|
580
|
+
|
|
655
581
|
/**
|
|
656
582
|
* Sorting is also done via the code.
|
|
657
583
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
658
584
|
*/
|
|
659
|
-
|
|
660
585
|
const sortedItems = (0, _utils.sortEntryItems)({
|
|
661
586
|
items: filteredItems,
|
|
662
587
|
sort,
|
|
@@ -670,7 +595,6 @@ const createEntriesStorageOperations = params => {
|
|
|
670
595
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
671
596
|
* Number is simply encoded.
|
|
672
597
|
*/
|
|
673
|
-
|
|
674
598
|
const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(`${start + limit}`) : null;
|
|
675
599
|
return {
|
|
676
600
|
hasMoreItems,
|
|
@@ -679,136 +603,14 @@ const createEntriesStorageOperations = params => {
|
|
|
679
603
|
items: (0, _cleanup.cleanupItems)(entity, slicedItems)
|
|
680
604
|
};
|
|
681
605
|
};
|
|
682
|
-
|
|
683
606
|
const get = async (model, params) => {
|
|
684
607
|
const {
|
|
685
608
|
items
|
|
686
|
-
} = await list(model,
|
|
609
|
+
} = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
687
610
|
limit: 1
|
|
688
611
|
}));
|
|
689
612
|
return items.shift() || null;
|
|
690
613
|
};
|
|
691
|
-
|
|
692
|
-
const requestChanges = async (model, params) => {
|
|
693
|
-
const {
|
|
694
|
-
entry,
|
|
695
|
-
storageEntry: initialStorageEntry
|
|
696
|
-
} = params;
|
|
697
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
698
|
-
id: entry.id,
|
|
699
|
-
locale: model.locale,
|
|
700
|
-
tenant: model.tenant
|
|
701
|
-
});
|
|
702
|
-
const storageEntry = convertToStorageEntry({
|
|
703
|
-
storageEntry: initialStorageEntry,
|
|
704
|
-
model
|
|
705
|
-
});
|
|
706
|
-
/**
|
|
707
|
-
* We need to:
|
|
708
|
-
* - update the existing entry
|
|
709
|
-
* - update latest version - if existing entry is the latest version
|
|
710
|
-
*/
|
|
711
|
-
|
|
712
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
713
|
-
TYPE: createType(),
|
|
714
|
-
PK: partitionKey,
|
|
715
|
-
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
716
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
717
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
718
|
-
}))];
|
|
719
|
-
/**
|
|
720
|
-
* We need the latest entry to see if something needs to be updated along side the request changes one.
|
|
721
|
-
*/
|
|
722
|
-
|
|
723
|
-
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
724
|
-
|
|
725
|
-
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
726
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
727
|
-
PK: partitionKey,
|
|
728
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
729
|
-
TYPE: createLatestType(),
|
|
730
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
731
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
732
|
-
})));
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
try {
|
|
736
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
737
|
-
table: entity.table,
|
|
738
|
-
items
|
|
739
|
-
});
|
|
740
|
-
dataLoaders.clearAll({
|
|
741
|
-
model
|
|
742
|
-
});
|
|
743
|
-
} catch (ex) {
|
|
744
|
-
throw new _error.default(ex.message || "Could not execute the request changes batch.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
745
|
-
entry
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
return entry;
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
const requestReview = async (model, params) => {
|
|
753
|
-
const {
|
|
754
|
-
entry,
|
|
755
|
-
storageEntry: initialStorageEntry
|
|
756
|
-
} = params;
|
|
757
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
758
|
-
id: entry.id,
|
|
759
|
-
locale: model.locale,
|
|
760
|
-
tenant: model.tenant
|
|
761
|
-
});
|
|
762
|
-
const storageEntry = convertToStorageEntry({
|
|
763
|
-
storageEntry: initialStorageEntry,
|
|
764
|
-
model
|
|
765
|
-
});
|
|
766
|
-
/**
|
|
767
|
-
* We need to:
|
|
768
|
-
* - update existing entry
|
|
769
|
-
* - update latest entry - if existing entry is the latest entry
|
|
770
|
-
*/
|
|
771
|
-
|
|
772
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
773
|
-
TYPE: createType(),
|
|
774
|
-
PK: partitionKey,
|
|
775
|
-
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
776
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
777
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
778
|
-
}))];
|
|
779
|
-
/**
|
|
780
|
-
* We need the latest entry to see if something needs to be updated along side the request review one.
|
|
781
|
-
*/
|
|
782
|
-
|
|
783
|
-
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
784
|
-
|
|
785
|
-
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
786
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
787
|
-
PK: partitionKey,
|
|
788
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
789
|
-
TYPE: createLatestType(),
|
|
790
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
791
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
792
|
-
})));
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
try {
|
|
796
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
797
|
-
table: entity.table,
|
|
798
|
-
items
|
|
799
|
-
});
|
|
800
|
-
dataLoaders.clearAll({
|
|
801
|
-
model
|
|
802
|
-
});
|
|
803
|
-
return initialStorageEntry;
|
|
804
|
-
} catch (ex) {
|
|
805
|
-
throw new _error.default(ex.message || "Could not execute request review batch.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
806
|
-
entry,
|
|
807
|
-
storageEntry
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
|
|
812
614
|
const publish = async (model, params) => {
|
|
813
615
|
const {
|
|
814
616
|
entry,
|
|
@@ -819,10 +621,10 @@ const createEntriesStorageOperations = params => {
|
|
|
819
621
|
locale: model.locale,
|
|
820
622
|
tenant: model.tenant
|
|
821
623
|
});
|
|
624
|
+
|
|
822
625
|
/**
|
|
823
626
|
* We need the latest and published entries to see if something needs to be updated along side the publishing one.
|
|
824
627
|
*/
|
|
825
|
-
|
|
826
628
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
827
629
|
const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
828
630
|
const storageEntry = convertToStorageEntry({
|
|
@@ -836,23 +638,21 @@ const createEntriesStorageOperations = params => {
|
|
|
836
638
|
* - latest sort key - if entry updated is actually latest
|
|
837
639
|
* - previous published entry to unpublished status - if any previously published entry
|
|
838
640
|
*/
|
|
839
|
-
|
|
840
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
641
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
841
642
|
PK: partitionKey,
|
|
842
643
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
843
644
|
TYPE: createType(),
|
|
844
645
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
845
646
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
846
|
-
})), entity.putBatch(
|
|
647
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
847
648
|
PK: partitionKey,
|
|
848
649
|
SK: (0, _keys.createPublishedSortKey)(),
|
|
849
650
|
TYPE: createPublishedType(),
|
|
850
651
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
851
652
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
852
653
|
}))];
|
|
853
|
-
|
|
854
654
|
if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {
|
|
855
|
-
items.push(entity.putBatch(
|
|
655
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
856
656
|
PK: partitionKey,
|
|
857
657
|
SK: (0, _keys.createLatestSortKey)(),
|
|
858
658
|
TYPE: createLatestType(),
|
|
@@ -860,13 +660,12 @@ const createEntriesStorageOperations = params => {
|
|
|
860
660
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
861
661
|
})));
|
|
862
662
|
}
|
|
863
|
-
|
|
864
663
|
if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
|
|
865
664
|
const publishedStorageEntry = convertToStorageEntry({
|
|
866
665
|
storageEntry: initialPublishedStorageEntry,
|
|
867
666
|
model
|
|
868
667
|
});
|
|
869
|
-
items.push(entity.putBatch(
|
|
668
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedStorageEntry), {}, {
|
|
870
669
|
PK: partitionKey,
|
|
871
670
|
SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
|
|
872
671
|
TYPE: createType(),
|
|
@@ -875,7 +674,6 @@ const createEntriesStorageOperations = params => {
|
|
|
875
674
|
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
876
675
|
})));
|
|
877
676
|
}
|
|
878
|
-
|
|
879
677
|
try {
|
|
880
678
|
await (0, _batchWrite.batchWriteAll)({
|
|
881
679
|
table: entity.table,
|
|
@@ -893,7 +691,6 @@ const createEntriesStorageOperations = params => {
|
|
|
893
691
|
});
|
|
894
692
|
}
|
|
895
693
|
};
|
|
896
|
-
|
|
897
694
|
const unpublish = async (model, params) => {
|
|
898
695
|
const {
|
|
899
696
|
entry,
|
|
@@ -914,25 +711,23 @@ const createEntriesStorageOperations = params => {
|
|
|
914
711
|
* - update current entry revision with new data
|
|
915
712
|
* - update latest entry status - if entry being unpublished is latest
|
|
916
713
|
*/
|
|
917
|
-
|
|
918
714
|
const items = [entity.deleteBatch({
|
|
919
715
|
PK: partitionKey,
|
|
920
716
|
SK: (0, _keys.createPublishedSortKey)()
|
|
921
|
-
}), entity.putBatch(
|
|
717
|
+
}), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
922
718
|
PK: partitionKey,
|
|
923
719
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
924
720
|
TYPE: createType(),
|
|
925
721
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
926
722
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
927
723
|
}))];
|
|
724
|
+
|
|
928
725
|
/**
|
|
929
726
|
* We need the latest entry to see if something needs to be updated along side the unpublishing one.
|
|
930
727
|
*/
|
|
931
|
-
|
|
932
728
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
933
|
-
|
|
934
729
|
if (latestStorageEntry && entry.id === latestStorageEntry.id) {
|
|
935
|
-
items.push(entity.putBatch(
|
|
730
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
936
731
|
PK: partitionKey,
|
|
937
732
|
SK: (0, _keys.createLatestSortKey)(),
|
|
938
733
|
TYPE: createLatestType(),
|
|
@@ -940,7 +735,6 @@ const createEntriesStorageOperations = params => {
|
|
|
940
735
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
941
736
|
})));
|
|
942
737
|
}
|
|
943
|
-
|
|
944
738
|
try {
|
|
945
739
|
await (0, _batchWrite.batchWriteAll)({
|
|
946
740
|
table: entity.table,
|
|
@@ -957,7 +751,6 @@ const createEntriesStorageOperations = params => {
|
|
|
957
751
|
});
|
|
958
752
|
}
|
|
959
753
|
};
|
|
960
|
-
|
|
961
754
|
return {
|
|
962
755
|
create,
|
|
963
756
|
createRevisionFrom,
|
|
@@ -973,12 +766,9 @@ const createEntriesStorageOperations = params => {
|
|
|
973
766
|
getLatestRevisionByEntryId,
|
|
974
767
|
get,
|
|
975
768
|
getRevisions,
|
|
976
|
-
requestChanges,
|
|
977
|
-
requestReview,
|
|
978
769
|
publish,
|
|
979
770
|
list,
|
|
980
771
|
unpublish
|
|
981
772
|
};
|
|
982
773
|
};
|
|
983
|
-
|
|
984
774
|
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|