@webiny/api-headless-cms-ddb 0.0.0-mt-3 → 0.0.0-unstable.5e7233243f
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.d.ts +2 -1
- package/definitions/entry.js +5 -2
- package/definitions/entry.js.map +1 -0
- package/definitions/group.d.ts +2 -1
- package/definitions/group.js +2 -2
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +2 -1
- package/definitions/model.js +2 -2
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +2 -2
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +2 -2
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +2 -1
- package/definitions/table.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +6 -10
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +2 -3
- package/dynamoDb/path/plainObject.js +28 -21
- package/dynamoDb/path/plainObject.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +2 -3
- package/dynamoDb/storage/date.js +79 -45
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +7 -4
- package/dynamoDb/storage/longText.js +71 -53
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -8
- package/dynamoDb/storage/richText.js +69 -66
- package/dynamoDb/storage/richText.js.map +1 -0
- package/dynamoDb/transformValue/datetime.d.ts +4 -2
- package/dynamoDb/transformValue/datetime.js +31 -26
- package/dynamoDb/transformValue/datetime.js.map +1 -0
- package/index.js +20 -19
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +12 -8
- package/operations/entry/dataLoaders.js +26 -6
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/index.d.ts +2 -2
- package/operations/entry/index.js +264 -103
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.js +11 -0
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/systemFields.js +18 -0
- package/operations/entry/systemFields.js.map +1 -0
- package/operations/entry/utils.d.ts +10 -5
- package/operations/entry/utils.js +373 -95
- package/operations/entry/utils.js.map +1 -0
- package/operations/group/index.d.ts +3 -2
- package/operations/group/index.js +3 -5
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +3 -2
- package/operations/model/index.js +15 -10
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +3 -2
- package/operations/settings/index.js +3 -5
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +3 -2
- package/operations/system/index.js +3 -5
- package/operations/system/index.js.map +1 -0
- package/package.json +23 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/types.d.ts +1 -32
- package/types.js.map +1 -0
- package/dynamoDb/path/ref.d.ts +0 -3
- package/dynamoDb/path/ref.js +0 -27
|
@@ -31,9 +31,9 @@ var _zeroPad = require("@webiny/utils/zeroPad");
|
|
|
31
31
|
|
|
32
32
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
33
33
|
|
|
34
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
35
|
|
|
36
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
37
37
|
|
|
38
38
|
const createType = () => {
|
|
39
39
|
return "cms.entry";
|
|
@@ -47,6 +47,34 @@ const createPublishedType = () => {
|
|
|
47
47
|
return `${createType()}.p`;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
const convertToStorageEntry = params => {
|
|
51
|
+
const {
|
|
52
|
+
model,
|
|
53
|
+
storageEntry
|
|
54
|
+
} = params;
|
|
55
|
+
const values = model.convertValueKeyToStorage({
|
|
56
|
+
fields: model.fields,
|
|
57
|
+
values: storageEntry.values
|
|
58
|
+
});
|
|
59
|
+
return _objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
60
|
+
values
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const convertFromStorageEntry = params => {
|
|
65
|
+
const {
|
|
66
|
+
model,
|
|
67
|
+
storageEntry
|
|
68
|
+
} = params;
|
|
69
|
+
const values = model.convertValueKeyFromStorage({
|
|
70
|
+
fields: model.fields,
|
|
71
|
+
values: storageEntry.values
|
|
72
|
+
});
|
|
73
|
+
return _objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
74
|
+
values
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
50
78
|
const createEntriesStorageOperations = params => {
|
|
51
79
|
const {
|
|
52
80
|
entity,
|
|
@@ -82,12 +110,22 @@ const createEntriesStorageOperations = params => {
|
|
|
82
110
|
};
|
|
83
111
|
};
|
|
84
112
|
|
|
85
|
-
const create = async (model,
|
|
113
|
+
const create = async (model, params) => {
|
|
86
114
|
const {
|
|
87
115
|
entry,
|
|
88
|
-
storageEntry
|
|
89
|
-
} =
|
|
90
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
116
|
+
storageEntry: initialStorageEntry
|
|
117
|
+
} = params;
|
|
118
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
119
|
+
id: entry.id,
|
|
120
|
+
locale: model.locale,
|
|
121
|
+
tenant: model.tenant
|
|
122
|
+
});
|
|
123
|
+
const isPublished = entry.status === "published";
|
|
124
|
+
const locked = isPublished ? true : entry.locked;
|
|
125
|
+
const storageEntry = convertToStorageEntry({
|
|
126
|
+
model,
|
|
127
|
+
storageEntry: initialStorageEntry
|
|
128
|
+
});
|
|
91
129
|
/**
|
|
92
130
|
* We need to:
|
|
93
131
|
* - create new main entry item
|
|
@@ -95,18 +133,34 @@ const createEntriesStorageOperations = params => {
|
|
|
95
133
|
*/
|
|
96
134
|
|
|
97
135
|
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
136
|
+
locked,
|
|
98
137
|
PK: partitionKey,
|
|
99
138
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
100
139
|
TYPE: createType(),
|
|
101
140
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
102
141
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
103
142
|
})), entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
143
|
+
locked,
|
|
104
144
|
PK: partitionKey,
|
|
105
145
|
SK: (0, _keys.createLatestSortKey)(),
|
|
106
146
|
TYPE: createLatestType(),
|
|
107
147
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
108
148
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
109
149
|
}))];
|
|
150
|
+
/**
|
|
151
|
+
* We need to create published entry if
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
if (isPublished) {
|
|
155
|
+
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
156
|
+
locked,
|
|
157
|
+
PK: partitionKey,
|
|
158
|
+
SK: (0, _keys.createPublishedSortKey)(),
|
|
159
|
+
TYPE: createLatestType(),
|
|
160
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
161
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
162
|
+
})));
|
|
163
|
+
}
|
|
110
164
|
|
|
111
165
|
try {
|
|
112
166
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -123,17 +177,23 @@ const createEntriesStorageOperations = params => {
|
|
|
123
177
|
});
|
|
124
178
|
}
|
|
125
179
|
|
|
126
|
-
return
|
|
180
|
+
return initialStorageEntry;
|
|
127
181
|
};
|
|
128
182
|
|
|
129
183
|
const createRevisionFrom = async (model, params) => {
|
|
130
184
|
const {
|
|
131
|
-
originalEntry,
|
|
132
185
|
entry,
|
|
133
|
-
storageEntry
|
|
134
|
-
latestEntry
|
|
186
|
+
storageEntry: initialStorageEntry
|
|
135
187
|
} = params;
|
|
136
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
188
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
189
|
+
id: entry.id,
|
|
190
|
+
locale: model.locale,
|
|
191
|
+
tenant: model.tenant
|
|
192
|
+
});
|
|
193
|
+
const storageEntry = convertToStorageEntry({
|
|
194
|
+
storageEntry: initialStorageEntry,
|
|
195
|
+
model
|
|
196
|
+
});
|
|
137
197
|
/**
|
|
138
198
|
* We need to:
|
|
139
199
|
* - create the main entry item
|
|
@@ -165,8 +225,6 @@ const createEntriesStorageOperations = params => {
|
|
|
165
225
|
} catch (ex) {
|
|
166
226
|
throw new _error.default(ex.message || "Could not create revision from given entry.", ex.code || "CREATE_REVISION_ERROR", {
|
|
167
227
|
error: ex,
|
|
168
|
-
originalEntry,
|
|
169
|
-
latestEntry,
|
|
170
228
|
entry,
|
|
171
229
|
storageEntry
|
|
172
230
|
});
|
|
@@ -176,17 +234,26 @@ const createEntriesStorageOperations = params => {
|
|
|
176
234
|
*/
|
|
177
235
|
|
|
178
236
|
|
|
179
|
-
return
|
|
237
|
+
return initialStorageEntry;
|
|
180
238
|
};
|
|
181
239
|
|
|
182
240
|
const update = async (model, params) => {
|
|
183
241
|
const {
|
|
184
|
-
originalEntry,
|
|
185
242
|
entry,
|
|
186
|
-
storageEntry
|
|
243
|
+
storageEntry: initialStorageEntry
|
|
187
244
|
} = params;
|
|
188
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
245
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
246
|
+
id: entry.id,
|
|
247
|
+
locale: model.locale,
|
|
248
|
+
tenant: model.tenant
|
|
249
|
+
});
|
|
250
|
+
const isPublished = entry.status === "published";
|
|
251
|
+
const locked = isPublished ? true : entry.locked;
|
|
189
252
|
const items = [];
|
|
253
|
+
const storageEntry = convertToStorageEntry({
|
|
254
|
+
model,
|
|
255
|
+
storageEntry: initialStorageEntry
|
|
256
|
+
});
|
|
190
257
|
/**
|
|
191
258
|
* We need to:
|
|
192
259
|
* - update the current entry
|
|
@@ -194,20 +261,34 @@ const createEntriesStorageOperations = params => {
|
|
|
194
261
|
*/
|
|
195
262
|
|
|
196
263
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
264
|
+
locked,
|
|
197
265
|
PK: partitionKey,
|
|
198
266
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
199
267
|
TYPE: createType(),
|
|
200
268
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
201
269
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
202
270
|
})));
|
|
271
|
+
|
|
272
|
+
if (isPublished) {
|
|
273
|
+
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
274
|
+
locked,
|
|
275
|
+
PK: partitionKey,
|
|
276
|
+
SK: (0, _keys.createPublishedSortKey)(),
|
|
277
|
+
TYPE: createPublishedType(),
|
|
278
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
279
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
280
|
+
})));
|
|
281
|
+
}
|
|
203
282
|
/**
|
|
204
283
|
* We need the latest entry to update it as well if neccessary.
|
|
205
284
|
*/
|
|
206
285
|
|
|
286
|
+
|
|
207
287
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
208
288
|
|
|
209
289
|
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
210
290
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
291
|
+
locked,
|
|
211
292
|
PK: partitionKey,
|
|
212
293
|
SK: (0, _keys.createLatestSortKey)(),
|
|
213
294
|
TYPE: createLatestType(),
|
|
@@ -224,11 +305,10 @@ const createEntriesStorageOperations = params => {
|
|
|
224
305
|
dataLoaders.clearAll({
|
|
225
306
|
model
|
|
226
307
|
});
|
|
227
|
-
return
|
|
308
|
+
return initialStorageEntry;
|
|
228
309
|
} catch (ex) {
|
|
229
310
|
throw new _error.default(ex.message || "Could not update entry.", ex.code || "UPDATE_ERROR", {
|
|
230
311
|
error: ex,
|
|
231
|
-
originalEntry,
|
|
232
312
|
entry,
|
|
233
313
|
latestStorageEntry
|
|
234
314
|
});
|
|
@@ -241,7 +321,11 @@ const createEntriesStorageOperations = params => {
|
|
|
241
321
|
} = params;
|
|
242
322
|
const queryAllParams = {
|
|
243
323
|
entity,
|
|
244
|
-
partitionKey: (0, _keys.createPartitionKey)(
|
|
324
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
325
|
+
id: entry.id,
|
|
326
|
+
locale: model.locale,
|
|
327
|
+
tenant: model.tenant
|
|
328
|
+
}),
|
|
245
329
|
options: {
|
|
246
330
|
gte: " "
|
|
247
331
|
}
|
|
@@ -283,34 +367,42 @@ const createEntriesStorageOperations = params => {
|
|
|
283
367
|
|
|
284
368
|
const deleteRevision = async (model, params) => {
|
|
285
369
|
const {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
370
|
+
entry,
|
|
371
|
+
latestEntry,
|
|
372
|
+
latestStorageEntry: initialLatestStorageEntry
|
|
289
373
|
} = params;
|
|
290
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
374
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
375
|
+
id: entry.id,
|
|
376
|
+
locale: model.locale,
|
|
377
|
+
tenant: model.tenant
|
|
378
|
+
});
|
|
291
379
|
const items = [entity.deleteBatch({
|
|
292
380
|
PK: partitionKey,
|
|
293
|
-
SK: (0, _keys.createRevisionSortKey)(
|
|
381
|
+
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
294
382
|
})];
|
|
295
|
-
const publishedStorageEntry = await getPublishedRevisionByEntryId(model,
|
|
383
|
+
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
296
384
|
/**
|
|
297
385
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
298
386
|
*/
|
|
299
387
|
|
|
300
|
-
if (publishedStorageEntry &&
|
|
388
|
+
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
301
389
|
items.push(entity.deleteBatch({
|
|
302
390
|
PK: partitionKey,
|
|
303
391
|
SK: (0, _keys.createPublishedSortKey)()
|
|
304
392
|
}));
|
|
305
393
|
}
|
|
306
394
|
|
|
307
|
-
if (
|
|
308
|
-
|
|
395
|
+
if (initialLatestStorageEntry) {
|
|
396
|
+
const latestStorageEntry = convertToStorageEntry({
|
|
397
|
+
storageEntry: initialLatestStorageEntry,
|
|
398
|
+
model
|
|
399
|
+
});
|
|
400
|
+
items.push(entity.putBatch(_objectSpread(_objectSpread({}, latestStorageEntry), {}, {
|
|
309
401
|
PK: partitionKey,
|
|
310
402
|
SK: (0, _keys.createLatestSortKey)(),
|
|
311
403
|
TYPE: createLatestType(),
|
|
312
404
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
313
|
-
GSI1_SK: (0, _keys.createGSISortKey)(
|
|
405
|
+
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
314
406
|
})));
|
|
315
407
|
}
|
|
316
408
|
|
|
@@ -325,91 +417,116 @@ const createEntriesStorageOperations = params => {
|
|
|
325
417
|
} catch (ex) {
|
|
326
418
|
throw new _error.default(ex.message, ex.code, {
|
|
327
419
|
error: ex,
|
|
328
|
-
|
|
329
|
-
|
|
420
|
+
entry,
|
|
421
|
+
latestEntry
|
|
330
422
|
});
|
|
331
423
|
}
|
|
332
424
|
};
|
|
333
425
|
|
|
334
|
-
const getAllRevisionsByIds = async (model, params) => {
|
|
335
|
-
return await dataLoaders.getAllEntryRevisions({
|
|
336
|
-
model,
|
|
337
|
-
ids: params.ids
|
|
338
|
-
});
|
|
339
|
-
};
|
|
340
|
-
|
|
341
426
|
const getLatestRevisionByEntryId = async (model, params) => {
|
|
342
|
-
const
|
|
427
|
+
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
343
428
|
model,
|
|
344
429
|
ids: [params.id]
|
|
345
430
|
});
|
|
431
|
+
const item = items.shift() || null;
|
|
346
432
|
|
|
347
|
-
if (
|
|
433
|
+
if (!item) {
|
|
348
434
|
return null;
|
|
349
435
|
}
|
|
350
436
|
|
|
351
|
-
return
|
|
437
|
+
return convertFromStorageEntry({
|
|
438
|
+
storageEntry: item,
|
|
439
|
+
model
|
|
440
|
+
});
|
|
352
441
|
};
|
|
353
442
|
|
|
354
443
|
const getPublishedRevisionByEntryId = async (model, params) => {
|
|
355
|
-
const
|
|
444
|
+
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
356
445
|
model,
|
|
357
446
|
ids: [params.id]
|
|
358
447
|
});
|
|
448
|
+
const item = items.shift() || null;
|
|
359
449
|
|
|
360
|
-
if (
|
|
450
|
+
if (!item) {
|
|
361
451
|
return null;
|
|
362
452
|
}
|
|
363
453
|
|
|
364
|
-
return
|
|
454
|
+
return convertFromStorageEntry({
|
|
455
|
+
storageEntry: item,
|
|
456
|
+
model
|
|
457
|
+
});
|
|
365
458
|
};
|
|
366
459
|
|
|
367
460
|
const getRevisionById = async (model, params) => {
|
|
368
|
-
const
|
|
461
|
+
const items = await dataLoaders.getRevisionById({
|
|
369
462
|
model,
|
|
370
463
|
ids: [params.id]
|
|
371
464
|
});
|
|
465
|
+
const item = items.shift() || null;
|
|
372
466
|
|
|
373
|
-
if (
|
|
467
|
+
if (!item) {
|
|
374
468
|
return null;
|
|
375
469
|
}
|
|
376
470
|
|
|
377
|
-
return
|
|
471
|
+
return convertFromStorageEntry({
|
|
472
|
+
storageEntry: item,
|
|
473
|
+
model
|
|
474
|
+
});
|
|
378
475
|
};
|
|
379
476
|
|
|
380
477
|
const getRevisions = async (model, params) => {
|
|
381
|
-
|
|
478
|
+
const items = await dataLoaders.getAllEntryRevisions({
|
|
382
479
|
model,
|
|
383
480
|
ids: [params.id]
|
|
384
481
|
});
|
|
482
|
+
return items.map(item => {
|
|
483
|
+
return convertFromStorageEntry({
|
|
484
|
+
storageEntry: item,
|
|
485
|
+
model
|
|
486
|
+
});
|
|
487
|
+
});
|
|
385
488
|
};
|
|
386
489
|
|
|
387
490
|
const getByIds = async (model, params) => {
|
|
388
|
-
|
|
491
|
+
const items = await dataLoaders.getRevisionById({
|
|
389
492
|
model,
|
|
390
493
|
ids: params.ids
|
|
391
494
|
});
|
|
495
|
+
return items.map(item => {
|
|
496
|
+
return convertFromStorageEntry({
|
|
497
|
+
storageEntry: item,
|
|
498
|
+
model
|
|
499
|
+
});
|
|
500
|
+
});
|
|
392
501
|
};
|
|
393
502
|
|
|
394
503
|
const getLatestByIds = async (model, params) => {
|
|
395
|
-
|
|
504
|
+
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
396
505
|
model,
|
|
397
506
|
ids: params.ids
|
|
398
507
|
});
|
|
508
|
+
return items.map(item => {
|
|
509
|
+
return convertFromStorageEntry({
|
|
510
|
+
storageEntry: item,
|
|
511
|
+
model
|
|
512
|
+
});
|
|
513
|
+
});
|
|
399
514
|
};
|
|
400
515
|
|
|
401
516
|
const getPublishedByIds = async (model, params) => {
|
|
402
|
-
|
|
517
|
+
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
403
518
|
model,
|
|
404
519
|
ids: params.ids
|
|
405
520
|
});
|
|
521
|
+
return items.map(item => {
|
|
522
|
+
return convertFromStorageEntry({
|
|
523
|
+
storageEntry: item,
|
|
524
|
+
model
|
|
525
|
+
});
|
|
526
|
+
});
|
|
406
527
|
};
|
|
407
528
|
|
|
408
529
|
const getPreviousRevision = async (model, params) => {
|
|
409
|
-
const {
|
|
410
|
-
tenant,
|
|
411
|
-
locale
|
|
412
|
-
} = model;
|
|
413
530
|
const {
|
|
414
531
|
entryId,
|
|
415
532
|
version
|
|
@@ -417,8 +534,8 @@ const createEntriesStorageOperations = params => {
|
|
|
417
534
|
const queryParams = {
|
|
418
535
|
entity,
|
|
419
536
|
partitionKey: (0, _keys.createPartitionKey)({
|
|
420
|
-
tenant,
|
|
421
|
-
locale,
|
|
537
|
+
tenant: model.tenant,
|
|
538
|
+
locale: model.locale,
|
|
422
539
|
id: entryId
|
|
423
540
|
}),
|
|
424
541
|
options: {
|
|
@@ -440,7 +557,16 @@ const createEntriesStorageOperations = params => {
|
|
|
440
557
|
|
|
441
558
|
try {
|
|
442
559
|
const result = await (0, _query.queryOne)(queryParams);
|
|
443
|
-
|
|
560
|
+
const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
|
|
561
|
+
|
|
562
|
+
if (!storageEntry) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return convertFromStorageEntry({
|
|
567
|
+
storageEntry,
|
|
568
|
+
model
|
|
569
|
+
});
|
|
444
570
|
} catch (ex) {
|
|
445
571
|
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", _objectSpread(_objectSpread({}, params), {}, {
|
|
446
572
|
error: ex,
|
|
@@ -454,12 +580,14 @@ const createEntriesStorageOperations = params => {
|
|
|
454
580
|
const list = async (model, params) => {
|
|
455
581
|
const {
|
|
456
582
|
limit: initialLimit = 10,
|
|
457
|
-
where:
|
|
583
|
+
where: initialWhere,
|
|
458
584
|
after,
|
|
459
|
-
sort
|
|
585
|
+
sort,
|
|
586
|
+
fields,
|
|
587
|
+
search
|
|
460
588
|
} = params;
|
|
461
|
-
const limit = initialLimit <= 0 || initialLimit >=
|
|
462
|
-
const type =
|
|
589
|
+
const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;
|
|
590
|
+
const type = initialWhere.published ? "P" : "L";
|
|
463
591
|
const queryAllParams = {
|
|
464
592
|
entity,
|
|
465
593
|
partitionKey: (0, _keys.createGSIPartitionKey)(model, type),
|
|
@@ -489,12 +617,10 @@ const createEntriesStorageOperations = params => {
|
|
|
489
617
|
};
|
|
490
618
|
}
|
|
491
619
|
|
|
492
|
-
const where = _objectSpread({},
|
|
620
|
+
const where = _objectSpread({}, initialWhere);
|
|
493
621
|
|
|
494
622
|
delete where["published"];
|
|
495
623
|
delete where["latest"];
|
|
496
|
-
delete where["locale"];
|
|
497
|
-
delete where["tenant"];
|
|
498
624
|
/**
|
|
499
625
|
* We need a object containing field, transformers and paths.
|
|
500
626
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
@@ -510,11 +636,20 @@ const createEntriesStorageOperations = params => {
|
|
|
510
636
|
*/
|
|
511
637
|
|
|
512
638
|
const filteredItems = await (0, _utils.filterItems)({
|
|
513
|
-
items: records
|
|
639
|
+
items: records.map(record => {
|
|
640
|
+
return convertFromStorageEntry({
|
|
641
|
+
storageEntry: record,
|
|
642
|
+
model
|
|
643
|
+
});
|
|
644
|
+
}),
|
|
514
645
|
where,
|
|
515
646
|
plugins,
|
|
516
647
|
fields: modelFields,
|
|
517
|
-
fromStorage: createStorageTransformCallable(model)
|
|
648
|
+
fromStorage: createStorageTransformCallable(model),
|
|
649
|
+
fullTextSearch: {
|
|
650
|
+
term: search,
|
|
651
|
+
fields: fields || []
|
|
652
|
+
}
|
|
518
653
|
});
|
|
519
654
|
const totalCount = filteredItems.length;
|
|
520
655
|
/**
|
|
@@ -527,7 +662,7 @@ const createEntriesStorageOperations = params => {
|
|
|
527
662
|
sort,
|
|
528
663
|
fields: modelFields
|
|
529
664
|
});
|
|
530
|
-
const start = (0, _cursor.decodeCursor)(after) || 0;
|
|
665
|
+
const start = parseInt((0, _cursor.decodeCursor)(after) || "0") || 0;
|
|
531
666
|
const hasMoreItems = totalCount > start + limit;
|
|
532
667
|
const end = limit > totalCount + start + limit ? undefined : start + limit;
|
|
533
668
|
const slicedItems = sortedItems.slice(start, end);
|
|
@@ -536,7 +671,7 @@ const createEntriesStorageOperations = params => {
|
|
|
536
671
|
* Number is simply encoded.
|
|
537
672
|
*/
|
|
538
673
|
|
|
539
|
-
const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(start + limit) : null;
|
|
674
|
+
const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(`${start + limit}`) : null;
|
|
540
675
|
return {
|
|
541
676
|
hasMoreItems,
|
|
542
677
|
totalCount,
|
|
@@ -551,21 +686,23 @@ const createEntriesStorageOperations = params => {
|
|
|
551
686
|
} = await list(model, _objectSpread(_objectSpread({}, params), {}, {
|
|
552
687
|
limit: 1
|
|
553
688
|
}));
|
|
554
|
-
|
|
555
|
-
if (items.length === 0) {
|
|
556
|
-
return null;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
return items.shift();
|
|
689
|
+
return items.shift() || null;
|
|
560
690
|
};
|
|
561
691
|
|
|
562
692
|
const requestChanges = async (model, params) => {
|
|
563
693
|
const {
|
|
564
694
|
entry,
|
|
565
|
-
storageEntry
|
|
566
|
-
originalEntry
|
|
695
|
+
storageEntry: initialStorageEntry
|
|
567
696
|
} = params;
|
|
568
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
697
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
698
|
+
id: entry.id,
|
|
699
|
+
locale: model.locale,
|
|
700
|
+
tenant: model.tenant
|
|
701
|
+
});
|
|
702
|
+
const storageEntry = convertToStorageEntry({
|
|
703
|
+
storageEntry: initialStorageEntry,
|
|
704
|
+
model
|
|
705
|
+
});
|
|
569
706
|
/**
|
|
570
707
|
* We need to:
|
|
571
708
|
* - update the existing entry
|
|
@@ -585,7 +722,7 @@ const createEntriesStorageOperations = params => {
|
|
|
585
722
|
|
|
586
723
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
587
724
|
|
|
588
|
-
if (latestStorageEntry.id === entry.id) {
|
|
725
|
+
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
589
726
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
590
727
|
PK: partitionKey,
|
|
591
728
|
SK: (0, _keys.createLatestSortKey)(),
|
|
@@ -605,8 +742,7 @@ const createEntriesStorageOperations = params => {
|
|
|
605
742
|
});
|
|
606
743
|
} catch (ex) {
|
|
607
744
|
throw new _error.default(ex.message || "Could not execute the request changes batch.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
608
|
-
entry
|
|
609
|
-
originalEntry
|
|
745
|
+
entry
|
|
610
746
|
});
|
|
611
747
|
}
|
|
612
748
|
|
|
@@ -616,10 +752,17 @@ const createEntriesStorageOperations = params => {
|
|
|
616
752
|
const requestReview = async (model, params) => {
|
|
617
753
|
const {
|
|
618
754
|
entry,
|
|
619
|
-
storageEntry
|
|
620
|
-
originalEntry
|
|
755
|
+
storageEntry: initialStorageEntry
|
|
621
756
|
} = params;
|
|
622
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
757
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
758
|
+
id: entry.id,
|
|
759
|
+
locale: model.locale,
|
|
760
|
+
tenant: model.tenant
|
|
761
|
+
});
|
|
762
|
+
const storageEntry = convertToStorageEntry({
|
|
763
|
+
storageEntry: initialStorageEntry,
|
|
764
|
+
model
|
|
765
|
+
});
|
|
623
766
|
/**
|
|
624
767
|
* We need to:
|
|
625
768
|
* - update existing entry
|
|
@@ -639,7 +782,7 @@ const createEntriesStorageOperations = params => {
|
|
|
639
782
|
|
|
640
783
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
641
784
|
|
|
642
|
-
if (latestStorageEntry.id === entry.id) {
|
|
785
|
+
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
643
786
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
644
787
|
PK: partitionKey,
|
|
645
788
|
SK: (0, _keys.createLatestSortKey)(),
|
|
@@ -657,12 +800,11 @@ const createEntriesStorageOperations = params => {
|
|
|
657
800
|
dataLoaders.clearAll({
|
|
658
801
|
model
|
|
659
802
|
});
|
|
660
|
-
return
|
|
803
|
+
return initialStorageEntry;
|
|
661
804
|
} catch (ex) {
|
|
662
805
|
throw new _error.default(ex.message || "Could not execute request review batch.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
663
806
|
entry,
|
|
664
|
-
storageEntry
|
|
665
|
-
originalEntry
|
|
807
|
+
storageEntry
|
|
666
808
|
});
|
|
667
809
|
}
|
|
668
810
|
};
|
|
@@ -670,15 +812,23 @@ const createEntriesStorageOperations = params => {
|
|
|
670
812
|
const publish = async (model, params) => {
|
|
671
813
|
const {
|
|
672
814
|
entry,
|
|
673
|
-
storageEntry
|
|
815
|
+
storageEntry: initialStorageEntry
|
|
674
816
|
} = params;
|
|
675
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
817
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
818
|
+
id: entry.id,
|
|
819
|
+
locale: model.locale,
|
|
820
|
+
tenant: model.tenant
|
|
821
|
+
});
|
|
676
822
|
/**
|
|
677
823
|
* We need the latest and published entries to see if something needs to be updated along side the publishing one.
|
|
678
824
|
*/
|
|
679
825
|
|
|
680
|
-
const
|
|
681
|
-
const
|
|
826
|
+
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
827
|
+
const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
828
|
+
const storageEntry = convertToStorageEntry({
|
|
829
|
+
model,
|
|
830
|
+
storageEntry: initialStorageEntry
|
|
831
|
+
});
|
|
682
832
|
/**
|
|
683
833
|
* We need to update:
|
|
684
834
|
* - current entry revision sort key
|
|
@@ -701,7 +851,7 @@ const createEntriesStorageOperations = params => {
|
|
|
701
851
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
702
852
|
}))];
|
|
703
853
|
|
|
704
|
-
if (entry.id ===
|
|
854
|
+
if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {
|
|
705
855
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
706
856
|
PK: partitionKey,
|
|
707
857
|
SK: (0, _keys.createLatestSortKey)(),
|
|
@@ -711,7 +861,11 @@ const createEntriesStorageOperations = params => {
|
|
|
711
861
|
})));
|
|
712
862
|
}
|
|
713
863
|
|
|
714
|
-
if (
|
|
864
|
+
if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
|
|
865
|
+
const publishedStorageEntry = convertToStorageEntry({
|
|
866
|
+
storageEntry: initialPublishedStorageEntry,
|
|
867
|
+
model
|
|
868
|
+
});
|
|
715
869
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, publishedStorageEntry), {}, {
|
|
716
870
|
PK: partitionKey,
|
|
717
871
|
SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
|
|
@@ -730,12 +884,12 @@ const createEntriesStorageOperations = params => {
|
|
|
730
884
|
dataLoaders.clearAll({
|
|
731
885
|
model
|
|
732
886
|
});
|
|
733
|
-
return
|
|
887
|
+
return initialStorageEntry;
|
|
734
888
|
} catch (ex) {
|
|
735
889
|
throw new _error.default(ex.message || "Could not execute the publishing batch.", ex.code || "PUBLISH_ERROR", {
|
|
736
890
|
entry,
|
|
737
|
-
latestStorageEntry,
|
|
738
|
-
publishedStorageEntry
|
|
891
|
+
latestStorageEntry: initialLatestStorageEntry,
|
|
892
|
+
publishedStorageEntry: initialPublishedStorageEntry
|
|
739
893
|
});
|
|
740
894
|
}
|
|
741
895
|
};
|
|
@@ -743,9 +897,17 @@ const createEntriesStorageOperations = params => {
|
|
|
743
897
|
const unpublish = async (model, params) => {
|
|
744
898
|
const {
|
|
745
899
|
entry,
|
|
746
|
-
storageEntry
|
|
900
|
+
storageEntry: initialStorageEntry
|
|
747
901
|
} = params;
|
|
748
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
902
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
903
|
+
id: entry.id,
|
|
904
|
+
locale: model.locale,
|
|
905
|
+
tenant: model.tenant
|
|
906
|
+
});
|
|
907
|
+
const storageEntry = convertToStorageEntry({
|
|
908
|
+
storageEntry: initialStorageEntry,
|
|
909
|
+
model
|
|
910
|
+
});
|
|
749
911
|
/**
|
|
750
912
|
* We need to:
|
|
751
913
|
* - delete currently published entry
|
|
@@ -769,7 +931,7 @@ const createEntriesStorageOperations = params => {
|
|
|
769
931
|
|
|
770
932
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
771
933
|
|
|
772
|
-
if (entry.id === latestStorageEntry.id) {
|
|
934
|
+
if (latestStorageEntry && entry.id === latestStorageEntry.id) {
|
|
773
935
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
774
936
|
PK: partitionKey,
|
|
775
937
|
SK: (0, _keys.createLatestSortKey)(),
|
|
@@ -787,7 +949,7 @@ const createEntriesStorageOperations = params => {
|
|
|
787
949
|
dataLoaders.clearAll({
|
|
788
950
|
model
|
|
789
951
|
});
|
|
790
|
-
return
|
|
952
|
+
return initialStorageEntry;
|
|
791
953
|
} catch (ex) {
|
|
792
954
|
throw new _error.default(ex.message || "Could not execute unpublish batch.", ex.code || "UNPUBLISH_ERROR", {
|
|
793
955
|
entry,
|
|
@@ -808,7 +970,6 @@ const createEntriesStorageOperations = params => {
|
|
|
808
970
|
getByIds,
|
|
809
971
|
getRevisionById,
|
|
810
972
|
getPublishedRevisionByEntryId,
|
|
811
|
-
getAllRevisionsByIds,
|
|
812
973
|
getLatestRevisionByEntryId,
|
|
813
974
|
get,
|
|
814
975
|
getRevisions,
|