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