@webiny/api-headless-cms-ddb 0.0.0-mt-3 → 0.0.0-unstable.40876133bb

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