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