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