@webiny/api-headless-cms-ddb 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c59b9cc5b9
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 +17 -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.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.js +1 -19
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.js +1 -18
- package/dynamoDb/storage/longText.js.map +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 +12 -34
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +43 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +9 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +23 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +43 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +57 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +57 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +63 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +38 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +5 -0
- package/operations/entry/dataLoader/types.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +11 -26
- package/operations/entry/dataLoaders.js +43 -249
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.js +2 -39
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.js +0 -18
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.js +0 -10
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.js +1 -36
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.js +0 -12
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +0 -18
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.js +0 -8
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -7
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.js +0 -5
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -21
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +0 -18
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.js +0 -15
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +0 -2
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.js +0 -3
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/values.js +0 -6
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +0 -6
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +1 -1
- package/operations/entry/index.js +147 -121
- 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 +18 -18
- package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -14
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.js +0 -7
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.js +0 -10
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- 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 +1 -0
- package/plugins/index.js +11 -6
- package/plugins/index.js.map +1 -1
- package/types.d.ts +10 -1
- package/types.js +0 -1
- package/types.js.map +1 -1
|
@@ -1,50 +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
12
|
var _keys = require("./keys");
|
|
19
|
-
|
|
20
13
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
21
|
-
|
|
22
14
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
23
|
-
|
|
24
15
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
25
|
-
|
|
26
16
|
var _cursor = require("@webiny/utils/cursor");
|
|
27
|
-
|
|
28
17
|
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
29
|
-
|
|
30
18
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
31
|
-
|
|
32
19
|
var _createFields = require("./filtering/createFields");
|
|
33
|
-
|
|
34
20
|
var _filtering = require("./filtering");
|
|
35
|
-
|
|
36
21
|
const createType = () => {
|
|
37
22
|
return "cms.entry";
|
|
38
23
|
};
|
|
39
|
-
|
|
40
24
|
const createLatestType = () => {
|
|
41
25
|
return `${createType()}.l`;
|
|
42
26
|
};
|
|
43
|
-
|
|
44
27
|
const createPublishedType = () => {
|
|
45
28
|
return `${createType()}.p`;
|
|
46
29
|
};
|
|
47
|
-
|
|
48
30
|
const convertToStorageEntry = params => {
|
|
49
31
|
const {
|
|
50
32
|
model,
|
|
@@ -58,7 +40,6 @@ const convertToStorageEntry = params => {
|
|
|
58
40
|
values
|
|
59
41
|
});
|
|
60
42
|
};
|
|
61
|
-
|
|
62
43
|
const convertFromStorageEntry = params => {
|
|
63
44
|
const {
|
|
64
45
|
model,
|
|
@@ -72,12 +53,24 @@ const convertFromStorageEntry = params => {
|
|
|
72
53
|
values
|
|
73
54
|
});
|
|
74
55
|
};
|
|
75
|
-
|
|
56
|
+
const MAX_LIST_LIMIT = 10000;
|
|
76
57
|
const createEntriesStorageOperations = params => {
|
|
77
58
|
const {
|
|
78
59
|
entity,
|
|
79
60
|
plugins
|
|
80
61
|
} = params;
|
|
62
|
+
let storageOperationsCmsModelPlugin;
|
|
63
|
+
const getStorageOperationsCmsModelPlugin = () => {
|
|
64
|
+
if (storageOperationsCmsModelPlugin) {
|
|
65
|
+
return storageOperationsCmsModelPlugin;
|
|
66
|
+
}
|
|
67
|
+
storageOperationsCmsModelPlugin = plugins.oneByType(_apiHeadlessCms.StorageOperationsCmsModelPlugin.type);
|
|
68
|
+
return storageOperationsCmsModelPlugin;
|
|
69
|
+
};
|
|
70
|
+
const getStorageOperationsModel = model => {
|
|
71
|
+
const plugin = getStorageOperationsCmsModelPlugin();
|
|
72
|
+
return plugin.getModel(model);
|
|
73
|
+
};
|
|
81
74
|
const dataLoaders = new _dataLoaders.DataLoadersHandler({
|
|
82
75
|
entity
|
|
83
76
|
});
|
|
@@ -85,34 +78,29 @@ const createEntriesStorageOperations = params => {
|
|
|
85
78
|
collection[plugin.fieldType] = plugin;
|
|
86
79
|
return collection;
|
|
87
80
|
}, {});
|
|
88
|
-
|
|
89
81
|
const createStorageTransformCallable = model => {
|
|
90
82
|
return (field, value) => {
|
|
91
83
|
const plugin = storageTransformPlugins[field.type];
|
|
92
|
-
|
|
93
84
|
if (!plugin) {
|
|
94
85
|
return value;
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
return plugin.fromStorage({
|
|
98
88
|
model,
|
|
99
89
|
field,
|
|
100
90
|
value,
|
|
101
|
-
|
|
102
91
|
getStoragePlugin(fieldType) {
|
|
103
92
|
return storageTransformPlugins[fieldType] || storageTransformPlugins["*"];
|
|
104
93
|
},
|
|
105
|
-
|
|
106
94
|
plugins
|
|
107
95
|
});
|
|
108
96
|
};
|
|
109
97
|
};
|
|
110
|
-
|
|
111
|
-
const create = async (model, params) => {
|
|
98
|
+
const create = async (initialModel, params) => {
|
|
112
99
|
const {
|
|
113
100
|
entry,
|
|
114
101
|
storageEntry: initialStorageEntry
|
|
115
102
|
} = params;
|
|
103
|
+
const model = getStorageOperationsModel(initialModel);
|
|
116
104
|
const partitionKey = (0, _keys.createPartitionKey)({
|
|
117
105
|
id: entry.id,
|
|
118
106
|
locale: model.locale,
|
|
@@ -127,9 +115,8 @@ const createEntriesStorageOperations = params => {
|
|
|
127
115
|
/**
|
|
128
116
|
* We need to:
|
|
129
117
|
* - create new main entry item
|
|
130
|
-
* - create new or update latest entry item
|
|
118
|
+
* - create new or update the latest entry item
|
|
131
119
|
*/
|
|
132
|
-
|
|
133
120
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
134
121
|
locked,
|
|
135
122
|
PK: partitionKey,
|
|
@@ -145,10 +132,10 @@ const createEntriesStorageOperations = params => {
|
|
|
145
132
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
146
133
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
147
134
|
}))];
|
|
135
|
+
|
|
148
136
|
/**
|
|
149
137
|
* We need to create published entry if
|
|
150
138
|
*/
|
|
151
|
-
|
|
152
139
|
if (isPublished) {
|
|
153
140
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
154
141
|
locked,
|
|
@@ -159,7 +146,6 @@ const createEntriesStorageOperations = params => {
|
|
|
159
146
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
160
147
|
})));
|
|
161
148
|
}
|
|
162
|
-
|
|
163
149
|
try {
|
|
164
150
|
await (0, _batchWrite.batchWriteAll)({
|
|
165
151
|
table: entity.table,
|
|
@@ -174,15 +160,14 @@ const createEntriesStorageOperations = params => {
|
|
|
174
160
|
entry
|
|
175
161
|
});
|
|
176
162
|
}
|
|
177
|
-
|
|
178
163
|
return initialStorageEntry;
|
|
179
164
|
};
|
|
180
|
-
|
|
181
|
-
const createRevisionFrom = async (model, params) => {
|
|
165
|
+
const createRevisionFrom = async (initialModel, params) => {
|
|
182
166
|
const {
|
|
183
167
|
entry,
|
|
184
168
|
storageEntry: initialStorageEntry
|
|
185
169
|
} = params;
|
|
170
|
+
const model = getStorageOperationsModel(initialModel);
|
|
186
171
|
const partitionKey = (0, _keys.createPartitionKey)({
|
|
187
172
|
id: entry.id,
|
|
188
173
|
locale: model.locale,
|
|
@@ -197,7 +182,6 @@ const createEntriesStorageOperations = params => {
|
|
|
197
182
|
* - create the main entry item
|
|
198
183
|
* - update the last entry item to a current one
|
|
199
184
|
*/
|
|
200
|
-
|
|
201
185
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
202
186
|
PK: partitionKey,
|
|
203
187
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
@@ -211,7 +195,6 @@ const createEntriesStorageOperations = params => {
|
|
|
211
195
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
212
196
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
213
197
|
}))];
|
|
214
|
-
|
|
215
198
|
try {
|
|
216
199
|
await (0, _batchWrite.batchWriteAll)({
|
|
217
200
|
table: entity.table,
|
|
@@ -230,16 +213,14 @@ const createEntriesStorageOperations = params => {
|
|
|
230
213
|
/**
|
|
231
214
|
* There are no modifications on the entry created so just return the data.
|
|
232
215
|
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
216
|
return initialStorageEntry;
|
|
236
217
|
};
|
|
237
|
-
|
|
238
|
-
const update = async (model, params) => {
|
|
218
|
+
const update = async (initialModel, params) => {
|
|
239
219
|
const {
|
|
240
220
|
entry,
|
|
241
221
|
storageEntry: initialStorageEntry
|
|
242
222
|
} = params;
|
|
223
|
+
const model = getStorageOperationsModel(initialModel);
|
|
243
224
|
const partitionKey = (0, _keys.createPartitionKey)({
|
|
244
225
|
id: entry.id,
|
|
245
226
|
locale: model.locale,
|
|
@@ -257,7 +238,6 @@ const createEntriesStorageOperations = params => {
|
|
|
257
238
|
* - update the current entry
|
|
258
239
|
* - update the latest entry if the current entry is the latest one
|
|
259
240
|
*/
|
|
260
|
-
|
|
261
241
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
262
242
|
locked,
|
|
263
243
|
PK: partitionKey,
|
|
@@ -266,7 +246,6 @@ const createEntriesStorageOperations = params => {
|
|
|
266
246
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
267
247
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
268
248
|
})));
|
|
269
|
-
|
|
270
249
|
if (isPublished) {
|
|
271
250
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
272
251
|
locked,
|
|
@@ -277,13 +256,11 @@ const createEntriesStorageOperations = params => {
|
|
|
277
256
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
278
257
|
})));
|
|
279
258
|
}
|
|
259
|
+
|
|
280
260
|
/**
|
|
281
|
-
* We need the latest entry to update it as well if
|
|
261
|
+
* We need the latest entry to update it as well if necessary.
|
|
282
262
|
*/
|
|
283
|
-
|
|
284
|
-
|
|
285
263
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
286
|
-
|
|
287
264
|
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
288
265
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
289
266
|
locked,
|
|
@@ -294,7 +271,6 @@ const createEntriesStorageOperations = params => {
|
|
|
294
271
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
295
272
|
})));
|
|
296
273
|
}
|
|
297
|
-
|
|
298
274
|
try {
|
|
299
275
|
await (0, _batchWrite.batchWriteAll)({
|
|
300
276
|
table: entity.table,
|
|
@@ -312,15 +288,16 @@ const createEntriesStorageOperations = params => {
|
|
|
312
288
|
});
|
|
313
289
|
}
|
|
314
290
|
};
|
|
315
|
-
|
|
316
|
-
const deleteEntry = async (model, params) => {
|
|
291
|
+
const deleteEntry = async (initialModel, params) => {
|
|
317
292
|
const {
|
|
318
293
|
entry
|
|
319
294
|
} = params;
|
|
295
|
+
const id = entry.id || entry.entryId;
|
|
296
|
+
const model = getStorageOperationsModel(initialModel);
|
|
320
297
|
const queryAllParams = {
|
|
321
298
|
entity,
|
|
322
299
|
partitionKey: (0, _keys.createPartitionKey)({
|
|
323
|
-
id
|
|
300
|
+
id,
|
|
324
301
|
locale: model.locale,
|
|
325
302
|
tenant: model.tenant
|
|
326
303
|
}),
|
|
@@ -329,23 +306,20 @@ const createEntriesStorageOperations = params => {
|
|
|
329
306
|
}
|
|
330
307
|
};
|
|
331
308
|
let records = [];
|
|
332
|
-
|
|
333
309
|
try {
|
|
334
310
|
records = await (0, _query.queryAll)(queryAllParams);
|
|
335
311
|
} catch (ex) {
|
|
336
312
|
throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
337
313
|
error: ex,
|
|
338
|
-
|
|
314
|
+
id
|
|
339
315
|
});
|
|
340
316
|
}
|
|
341
|
-
|
|
342
317
|
const items = records.map(item => {
|
|
343
318
|
return entity.deleteBatch({
|
|
344
319
|
PK: item.PK,
|
|
345
320
|
SK: item.SK
|
|
346
321
|
});
|
|
347
322
|
});
|
|
348
|
-
|
|
349
323
|
try {
|
|
350
324
|
await (0, _batchWrite.batchWriteAll)({
|
|
351
325
|
table: entity.table,
|
|
@@ -358,17 +332,17 @@ const createEntriesStorageOperations = params => {
|
|
|
358
332
|
throw new _error.default(ex.message || "Could not delete the entry.", ex.code || "DELETE_ENTRY_ERROR", {
|
|
359
333
|
error: ex,
|
|
360
334
|
partitionKey: queryAllParams.partitionKey,
|
|
361
|
-
|
|
335
|
+
id
|
|
362
336
|
});
|
|
363
337
|
}
|
|
364
338
|
};
|
|
365
|
-
|
|
366
|
-
const deleteRevision = async (model, params) => {
|
|
339
|
+
const deleteRevision = async (initialModel, params) => {
|
|
367
340
|
const {
|
|
368
341
|
entry,
|
|
369
342
|
latestEntry,
|
|
370
343
|
latestStorageEntry: initialLatestStorageEntry
|
|
371
344
|
} = params;
|
|
345
|
+
const model = getStorageOperationsModel(initialModel);
|
|
372
346
|
const partitionKey = (0, _keys.createPartitionKey)({
|
|
373
347
|
id: entry.id,
|
|
374
348
|
locale: model.locale,
|
|
@@ -379,17 +353,16 @@ const createEntriesStorageOperations = params => {
|
|
|
379
353
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
380
354
|
})];
|
|
381
355
|
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
356
|
+
|
|
382
357
|
/**
|
|
383
358
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
384
359
|
*/
|
|
385
|
-
|
|
386
360
|
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
387
361
|
items.push(entity.deleteBatch({
|
|
388
362
|
PK: partitionKey,
|
|
389
363
|
SK: (0, _keys.createPublishedSortKey)()
|
|
390
364
|
}));
|
|
391
365
|
}
|
|
392
|
-
|
|
393
366
|
if (initialLatestStorageEntry) {
|
|
394
367
|
const latestStorageEntry = convertToStorageEntry({
|
|
395
368
|
storageEntry: initialLatestStorageEntry,
|
|
@@ -403,7 +376,6 @@ const createEntriesStorageOperations = params => {
|
|
|
403
376
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
404
377
|
})));
|
|
405
378
|
}
|
|
406
|
-
|
|
407
379
|
try {
|
|
408
380
|
await (0, _batchWrite.batchWriteAll)({
|
|
409
381
|
table: entity.table,
|
|
@@ -420,59 +392,113 @@ const createEntriesStorageOperations = params => {
|
|
|
420
392
|
});
|
|
421
393
|
}
|
|
422
394
|
};
|
|
423
|
-
|
|
424
|
-
|
|
395
|
+
const deleteMultipleEntries = async (initialModel, params) => {
|
|
396
|
+
const {
|
|
397
|
+
entries
|
|
398
|
+
} = params;
|
|
399
|
+
const model = getStorageOperationsModel(initialModel);
|
|
400
|
+
/**
|
|
401
|
+
* First we need all the revisions of the entries we want to delete.
|
|
402
|
+
*/
|
|
403
|
+
const revisions = await dataLoaders.getAllEntryRevisions({
|
|
404
|
+
model,
|
|
405
|
+
ids: entries
|
|
406
|
+
});
|
|
407
|
+
/**
|
|
408
|
+
* Then we need to construct the queries for all the revisions and entries.
|
|
409
|
+
*/
|
|
410
|
+
const items = [];
|
|
411
|
+
for (const id of entries) {
|
|
412
|
+
/**
|
|
413
|
+
* Latest item.
|
|
414
|
+
*/
|
|
415
|
+
items.push(entity.deleteBatch({
|
|
416
|
+
PK: (0, _keys.createPartitionKey)({
|
|
417
|
+
id,
|
|
418
|
+
locale: model.locale,
|
|
419
|
+
tenant: model.tenant
|
|
420
|
+
}),
|
|
421
|
+
SK: "L"
|
|
422
|
+
}));
|
|
423
|
+
/**
|
|
424
|
+
* Published item.
|
|
425
|
+
*/
|
|
426
|
+
items.push(entity.deleteBatch({
|
|
427
|
+
PK: (0, _keys.createPartitionKey)({
|
|
428
|
+
id,
|
|
429
|
+
locale: model.locale,
|
|
430
|
+
tenant: model.tenant
|
|
431
|
+
}),
|
|
432
|
+
SK: "P"
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Exact revisions of all the entries
|
|
437
|
+
*/
|
|
438
|
+
for (const revision of revisions) {
|
|
439
|
+
items.push(entity.deleteBatch({
|
|
440
|
+
PK: (0, _keys.createPartitionKey)({
|
|
441
|
+
id: revision.id,
|
|
442
|
+
locale: model.locale,
|
|
443
|
+
tenant: model.tenant
|
|
444
|
+
}),
|
|
445
|
+
SK: (0, _keys.createRevisionSortKey)({
|
|
446
|
+
version: revision.version
|
|
447
|
+
})
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
451
|
+
table: entity.table,
|
|
452
|
+
items
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
const getLatestRevisionByEntryId = async (initialModel, params) => {
|
|
456
|
+
const model = getStorageOperationsModel(initialModel);
|
|
425
457
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
426
458
|
model,
|
|
427
459
|
ids: [params.id]
|
|
428
460
|
});
|
|
429
461
|
const item = items.shift() || null;
|
|
430
|
-
|
|
431
462
|
if (!item) {
|
|
432
463
|
return null;
|
|
433
464
|
}
|
|
434
|
-
|
|
435
465
|
return convertFromStorageEntry({
|
|
436
466
|
storageEntry: item,
|
|
437
467
|
model
|
|
438
468
|
});
|
|
439
469
|
};
|
|
440
|
-
|
|
441
|
-
|
|
470
|
+
const getPublishedRevisionByEntryId = async (initialModel, params) => {
|
|
471
|
+
const model = getStorageOperationsModel(initialModel);
|
|
442
472
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
443
473
|
model,
|
|
444
474
|
ids: [params.id]
|
|
445
475
|
});
|
|
446
476
|
const item = items.shift() || null;
|
|
447
|
-
|
|
448
477
|
if (!item) {
|
|
449
478
|
return null;
|
|
450
479
|
}
|
|
451
|
-
|
|
452
480
|
return convertFromStorageEntry({
|
|
453
481
|
storageEntry: item,
|
|
454
482
|
model
|
|
455
483
|
});
|
|
456
484
|
};
|
|
457
|
-
|
|
458
|
-
|
|
485
|
+
const getRevisionById = async (initialModel, params) => {
|
|
486
|
+
const model = getStorageOperationsModel(initialModel);
|
|
459
487
|
const items = await dataLoaders.getRevisionById({
|
|
460
488
|
model,
|
|
461
489
|
ids: [params.id]
|
|
462
490
|
});
|
|
463
491
|
const item = items.shift() || null;
|
|
464
|
-
|
|
465
492
|
if (!item) {
|
|
466
493
|
return null;
|
|
467
494
|
}
|
|
468
|
-
|
|
469
495
|
return convertFromStorageEntry({
|
|
470
496
|
storageEntry: item,
|
|
471
497
|
model
|
|
472
498
|
});
|
|
473
499
|
};
|
|
474
|
-
|
|
475
|
-
|
|
500
|
+
const getRevisions = async (initialModel, params) => {
|
|
501
|
+
const model = getStorageOperationsModel(initialModel);
|
|
476
502
|
const items = await dataLoaders.getAllEntryRevisions({
|
|
477
503
|
model,
|
|
478
504
|
ids: [params.id]
|
|
@@ -484,8 +510,8 @@ const createEntriesStorageOperations = params => {
|
|
|
484
510
|
});
|
|
485
511
|
});
|
|
486
512
|
};
|
|
487
|
-
|
|
488
|
-
|
|
513
|
+
const getByIds = async (initialModel, params) => {
|
|
514
|
+
const model = getStorageOperationsModel(initialModel);
|
|
489
515
|
const items = await dataLoaders.getRevisionById({
|
|
490
516
|
model,
|
|
491
517
|
ids: params.ids
|
|
@@ -497,8 +523,8 @@ const createEntriesStorageOperations = params => {
|
|
|
497
523
|
});
|
|
498
524
|
});
|
|
499
525
|
};
|
|
500
|
-
|
|
501
|
-
|
|
526
|
+
const getLatestByIds = async (initialModel, params) => {
|
|
527
|
+
const model = getStorageOperationsModel(initialModel);
|
|
502
528
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
503
529
|
model,
|
|
504
530
|
ids: params.ids
|
|
@@ -510,8 +536,8 @@ const createEntriesStorageOperations = params => {
|
|
|
510
536
|
});
|
|
511
537
|
});
|
|
512
538
|
};
|
|
513
|
-
|
|
514
|
-
|
|
539
|
+
const getPublishedByIds = async (initialModel, params) => {
|
|
540
|
+
const model = getStorageOperationsModel(initialModel);
|
|
515
541
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
516
542
|
model,
|
|
517
543
|
ids: params.ids
|
|
@@ -523,8 +549,8 @@ const createEntriesStorageOperations = params => {
|
|
|
523
549
|
});
|
|
524
550
|
});
|
|
525
551
|
};
|
|
526
|
-
|
|
527
|
-
|
|
552
|
+
const getPreviousRevision = async (initialModel, params) => {
|
|
553
|
+
const model = getStorageOperationsModel(initialModel);
|
|
528
554
|
const {
|
|
529
555
|
entryId,
|
|
530
556
|
version
|
|
@@ -538,7 +564,6 @@ const createEntriesStorageOperations = params => {
|
|
|
538
564
|
}),
|
|
539
565
|
options: {
|
|
540
566
|
lt: `REV#${(0, _zeroPad.zeroPad)(version)}`,
|
|
541
|
-
|
|
542
567
|
/**
|
|
543
568
|
* We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
|
|
544
569
|
*/
|
|
@@ -552,15 +577,12 @@ const createEntriesStorageOperations = params => {
|
|
|
552
577
|
reverse: true
|
|
553
578
|
}
|
|
554
579
|
};
|
|
555
|
-
|
|
556
580
|
try {
|
|
557
581
|
const result = await (0, _query.queryOne)(queryParams);
|
|
558
582
|
const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
|
|
559
|
-
|
|
560
583
|
if (!storageEntry) {
|
|
561
584
|
return null;
|
|
562
585
|
}
|
|
563
|
-
|
|
564
586
|
return convertFromStorageEntry({
|
|
565
587
|
storageEntry,
|
|
566
588
|
model
|
|
@@ -574,8 +596,8 @@ const createEntriesStorageOperations = params => {
|
|
|
574
596
|
}));
|
|
575
597
|
}
|
|
576
598
|
};
|
|
577
|
-
|
|
578
|
-
|
|
599
|
+
const list = async (initialModel, params) => {
|
|
600
|
+
const model = getStorageOperationsModel(initialModel);
|
|
579
601
|
const {
|
|
580
602
|
limit: initialLimit = 10,
|
|
581
603
|
where: initialWhere,
|
|
@@ -584,7 +606,7 @@ const createEntriesStorageOperations = params => {
|
|
|
584
606
|
fields,
|
|
585
607
|
search
|
|
586
608
|
} = params;
|
|
587
|
-
const limit = initialLimit <= 0 || initialLimit >=
|
|
609
|
+
const limit = initialLimit <= 0 || initialLimit >= MAX_LIST_LIMIT ? MAX_LIST_LIMIT : initialLimit;
|
|
588
610
|
const type = initialWhere.published ? "P" : "L";
|
|
589
611
|
const queryAllParams = {
|
|
590
612
|
entity,
|
|
@@ -595,7 +617,6 @@ const createEntriesStorageOperations = params => {
|
|
|
595
617
|
}
|
|
596
618
|
};
|
|
597
619
|
let storageEntries = [];
|
|
598
|
-
|
|
599
620
|
try {
|
|
600
621
|
storageEntries = await (0, _query.queryAll)(queryAllParams);
|
|
601
622
|
} catch (ex) {
|
|
@@ -605,7 +626,6 @@ const createEntriesStorageOperations = params => {
|
|
|
605
626
|
options: queryAllParams.options
|
|
606
627
|
});
|
|
607
628
|
}
|
|
608
|
-
|
|
609
629
|
if (storageEntries.length === 0) {
|
|
610
630
|
return {
|
|
611
631
|
hasMoreItems: false,
|
|
@@ -614,7 +634,6 @@ const createEntriesStorageOperations = params => {
|
|
|
614
634
|
items: []
|
|
615
635
|
};
|
|
616
636
|
}
|
|
617
|
-
|
|
618
637
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
619
638
|
delete where["published"];
|
|
620
639
|
delete where["latest"];
|
|
@@ -622,7 +641,6 @@ const createEntriesStorageOperations = params => {
|
|
|
622
641
|
* We need an object containing field, transformers and paths.
|
|
623
642
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
624
643
|
*/
|
|
625
|
-
|
|
626
644
|
const modelFields = (0, _createFields.createFields)({
|
|
627
645
|
plugins,
|
|
628
646
|
fields: model.fields
|
|
@@ -633,24 +651,20 @@ const createEntriesStorageOperations = params => {
|
|
|
633
651
|
*
|
|
634
652
|
* This is always being done, but at least its in parallel.
|
|
635
653
|
*/
|
|
636
|
-
|
|
637
654
|
const records = await Promise.all(storageEntries.map(async storageEntry => {
|
|
638
655
|
const entry = convertFromStorageEntry({
|
|
639
656
|
storageEntry,
|
|
640
657
|
model
|
|
641
658
|
});
|
|
642
|
-
|
|
643
659
|
for (const field of model.fields) {
|
|
644
660
|
entry.values[field.fieldId] = await fromStorage(field, entry.values[field.fieldId]);
|
|
645
661
|
}
|
|
646
|
-
|
|
647
662
|
return entry;
|
|
648
663
|
}));
|
|
649
664
|
/**
|
|
650
665
|
* Filter the read items via the code.
|
|
651
666
|
* It will build the filters out of the where input and transform the values it is using.
|
|
652
667
|
*/
|
|
653
|
-
|
|
654
668
|
const filteredItems = (0, _filtering.filter)({
|
|
655
669
|
items: records,
|
|
656
670
|
where,
|
|
@@ -662,11 +676,11 @@ const createEntriesStorageOperations = params => {
|
|
|
662
676
|
}
|
|
663
677
|
});
|
|
664
678
|
const totalCount = filteredItems.length;
|
|
679
|
+
|
|
665
680
|
/**
|
|
666
681
|
* Sorting is also done via the code.
|
|
667
682
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
668
683
|
*/
|
|
669
|
-
|
|
670
684
|
const sortedItems = (0, _filtering.sort)({
|
|
671
685
|
model,
|
|
672
686
|
plugins,
|
|
@@ -682,7 +696,6 @@ const createEntriesStorageOperations = params => {
|
|
|
682
696
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
683
697
|
* Number is simply encoded.
|
|
684
698
|
*/
|
|
685
|
-
|
|
686
699
|
const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(`${start + limit}`) : null;
|
|
687
700
|
return {
|
|
688
701
|
hasMoreItems,
|
|
@@ -691,8 +704,8 @@ const createEntriesStorageOperations = params => {
|
|
|
691
704
|
items: (0, _cleanup.cleanupItems)(entity, slicedItems)
|
|
692
705
|
};
|
|
693
706
|
};
|
|
694
|
-
|
|
695
|
-
|
|
707
|
+
const get = async (initialModel, params) => {
|
|
708
|
+
const model = getStorageOperationsModel(initialModel);
|
|
696
709
|
const {
|
|
697
710
|
items
|
|
698
711
|
} = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
@@ -700,21 +713,21 @@ const createEntriesStorageOperations = params => {
|
|
|
700
713
|
}));
|
|
701
714
|
return items.shift() || null;
|
|
702
715
|
};
|
|
703
|
-
|
|
704
|
-
const publish = async (model, params) => {
|
|
716
|
+
const publish = async (initialModel, params) => {
|
|
705
717
|
const {
|
|
706
718
|
entry,
|
|
707
719
|
storageEntry: initialStorageEntry
|
|
708
720
|
} = params;
|
|
721
|
+
const model = getStorageOperationsModel(initialModel);
|
|
709
722
|
const partitionKey = (0, _keys.createPartitionKey)({
|
|
710
723
|
id: entry.id,
|
|
711
724
|
locale: model.locale,
|
|
712
725
|
tenant: model.tenant
|
|
713
726
|
});
|
|
727
|
+
|
|
714
728
|
/**
|
|
715
|
-
* We need the latest and published entries to see if something needs to be updated
|
|
729
|
+
* We need the latest and published entries to see if something needs to be updated alongside the publishing one.
|
|
716
730
|
*/
|
|
717
|
-
|
|
718
731
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
719
732
|
const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
720
733
|
const storageEntry = convertToStorageEntry({
|
|
@@ -725,10 +738,9 @@ const createEntriesStorageOperations = params => {
|
|
|
725
738
|
* We need to update:
|
|
726
739
|
* - current entry revision sort key
|
|
727
740
|
* - published sort key
|
|
728
|
-
* - latest sort key - if entry updated is actually latest
|
|
741
|
+
* - the latest sort key - if entry updated is actually latest
|
|
729
742
|
* - previous published entry to unpublished status - if any previously published entry
|
|
730
743
|
*/
|
|
731
|
-
|
|
732
744
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
733
745
|
PK: partitionKey,
|
|
734
746
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
@@ -742,7 +754,6 @@ const createEntriesStorageOperations = params => {
|
|
|
742
754
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
743
755
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
744
756
|
}))];
|
|
745
|
-
|
|
746
757
|
if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {
|
|
747
758
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
748
759
|
PK: partitionKey,
|
|
@@ -752,7 +763,6 @@ const createEntriesStorageOperations = params => {
|
|
|
752
763
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
753
764
|
})));
|
|
754
765
|
}
|
|
755
|
-
|
|
756
766
|
if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
|
|
757
767
|
const publishedStorageEntry = convertToStorageEntry({
|
|
758
768
|
storageEntry: initialPublishedStorageEntry,
|
|
@@ -767,7 +777,6 @@ const createEntriesStorageOperations = params => {
|
|
|
767
777
|
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
768
778
|
})));
|
|
769
779
|
}
|
|
770
|
-
|
|
771
780
|
try {
|
|
772
781
|
await (0, _batchWrite.batchWriteAll)({
|
|
773
782
|
table: entity.table,
|
|
@@ -785,12 +794,12 @@ const createEntriesStorageOperations = params => {
|
|
|
785
794
|
});
|
|
786
795
|
}
|
|
787
796
|
};
|
|
788
|
-
|
|
789
|
-
const unpublish = async (model, params) => {
|
|
797
|
+
const unpublish = async (initialModel, params) => {
|
|
790
798
|
const {
|
|
791
799
|
entry,
|
|
792
800
|
storageEntry: initialStorageEntry
|
|
793
801
|
} = params;
|
|
802
|
+
const model = getStorageOperationsModel(initialModel);
|
|
794
803
|
const partitionKey = (0, _keys.createPartitionKey)({
|
|
795
804
|
id: entry.id,
|
|
796
805
|
locale: model.locale,
|
|
@@ -804,9 +813,8 @@ const createEntriesStorageOperations = params => {
|
|
|
804
813
|
* We need to:
|
|
805
814
|
* - delete currently published entry
|
|
806
815
|
* - update current entry revision with new data
|
|
807
|
-
* - update latest entry status - if entry being unpublished is latest
|
|
816
|
+
* - update the latest entry status - if entry being unpublished is latest
|
|
808
817
|
*/
|
|
809
|
-
|
|
810
818
|
const items = [entity.deleteBatch({
|
|
811
819
|
PK: partitionKey,
|
|
812
820
|
SK: (0, _keys.createPublishedSortKey)()
|
|
@@ -817,12 +825,11 @@ const createEntriesStorageOperations = params => {
|
|
|
817
825
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
818
826
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
819
827
|
}))];
|
|
828
|
+
|
|
820
829
|
/**
|
|
821
|
-
* We need the latest entry to see if something needs to be updated
|
|
830
|
+
* We need the latest entry to see if something needs to be updated alongside the unpublishing one.
|
|
822
831
|
*/
|
|
823
|
-
|
|
824
832
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
825
|
-
|
|
826
833
|
if (latestStorageEntry && entry.id === latestStorageEntry.id) {
|
|
827
834
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
828
835
|
PK: partitionKey,
|
|
@@ -832,7 +839,6 @@ const createEntriesStorageOperations = params => {
|
|
|
832
839
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
833
840
|
})));
|
|
834
841
|
}
|
|
835
|
-
|
|
836
842
|
try {
|
|
837
843
|
await (0, _batchWrite.batchWriteAll)({
|
|
838
844
|
table: entity.table,
|
|
@@ -849,13 +855,32 @@ const createEntriesStorageOperations = params => {
|
|
|
849
855
|
});
|
|
850
856
|
}
|
|
851
857
|
};
|
|
852
|
-
|
|
858
|
+
const getUniqueFieldValues = async (model, params) => {
|
|
859
|
+
const {
|
|
860
|
+
where,
|
|
861
|
+
fieldId
|
|
862
|
+
} = params;
|
|
863
|
+
const field = model.fields.find(f => f.fieldId === fieldId);
|
|
864
|
+
if (!field) {
|
|
865
|
+
throw new _error.default(`Could not find field with given "fieldId" value.`, "FIELD_NOT_FOUND", {
|
|
866
|
+
fieldId
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
const {
|
|
870
|
+
items
|
|
871
|
+
} = await list(model, {
|
|
872
|
+
where,
|
|
873
|
+
limit: MAX_LIST_LIMIT
|
|
874
|
+
});
|
|
875
|
+
return Array.from(new Set(items.map(item => item.values[field.fieldId])));
|
|
876
|
+
};
|
|
853
877
|
return {
|
|
854
878
|
create,
|
|
855
879
|
createRevisionFrom,
|
|
856
880
|
update,
|
|
857
881
|
delete: deleteEntry,
|
|
858
882
|
deleteRevision,
|
|
883
|
+
deleteMultipleEntries,
|
|
859
884
|
getPreviousRevision,
|
|
860
885
|
getPublishedByIds,
|
|
861
886
|
getLatestByIds,
|
|
@@ -867,8 +892,9 @@ const createEntriesStorageOperations = params => {
|
|
|
867
892
|
getRevisions,
|
|
868
893
|
publish,
|
|
869
894
|
list,
|
|
870
|
-
unpublish
|
|
895
|
+
unpublish,
|
|
896
|
+
dataLoaders,
|
|
897
|
+
getUniqueFieldValues
|
|
871
898
|
};
|
|
872
899
|
};
|
|
873
|
-
|
|
874
900
|
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|