@webiny/api-headless-cms-ddb 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.f6dc066313
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/README.md +6 -20
- package/definitions/entry.d.ts +4 -6
- package/definitions/entry.js +5 -180
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -6
- package/definitions/group.js +5 -58
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -6
- package/definitions/model.js +5 -102
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +3 -5
- package/definitions/table.js +6 -28
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +60 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +6 -13
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +1 -1
- package/dynamoDb/path/locationFolderId.js +5 -14
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +5 -14
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.js +10 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +10 -19
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +5 -12
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +38 -73
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +0 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +2 -9
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +1 -7
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +4 -10
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
- package/operations/entry/dataLoader/getAllEntryRevisions.js +11 -24
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +22 -32
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +22 -32
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +24 -34
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +3 -3
- package/operations/entry/dataLoader/index.js +10 -31
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +3 -4
- package/operations/entry/dataLoader/types.js +1 -5
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +11 -12
- package/operations/entry/dataLoaders.js +15 -25
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +3 -3
- package/operations/entry/filtering/createExpressions.js +27 -30
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +2 -2
- package/operations/entry/filtering/createFields.js +20 -22
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +5 -5
- package/operations/entry/filtering/extractSort.js +38 -23
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +5 -5
- package/operations/entry/filtering/filter.js +13 -21
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
- package/operations/entry/filtering/fullTextSearch.js +5 -13
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +1 -8
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.d.ts +2 -2
- package/operations/entry/filtering/index.js +2 -19
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +1 -1
- package/operations/entry/filtering/mapPlugins.js +3 -11
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +6 -14
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +6 -13
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +13 -19
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +12 -18
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +7 -15
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.d.ts +5 -5
- package/operations/entry/filtering/sort.js +15 -19
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +70 -29
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +1 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +3 -3
- package/operations/entry/filtering/types.js +1 -5
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js +4 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +1 -8
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +2 -3
- package/operations/entry/index.js +267 -377
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +40 -2
- package/operations/entry/keys.js +53 -30
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +3 -3
- package/operations/group/index.js +35 -64
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +36 -58
- package/operations/model/index.js.map +1 -1
- package/package.json +16 -18
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +4 -12
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +3 -3
- package/plugins/CmsEntryFieldFilterPlugin.js +2 -8
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js +3 -11
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +2 -9
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +4 -4
- package/plugins/index.js +4 -49
- package/plugins/index.js.map +1 -1
- package/types.d.ts +17 -19
- package/types.js +1 -8
- package/types.js.map +1 -1
- package/definitions/system.d.ts +0 -10
- package/definitions/system.js +0 -42
- package/definitions/system.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -94
- package/operations/system/index.js.map +0 -1
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _keys = require("./keys");
|
|
12
|
-
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
13
|
-
var _cursor = require("@webiny/utils/cursor");
|
|
14
|
-
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
15
|
-
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
16
|
-
var _createFields = require("./filtering/createFields");
|
|
17
|
-
var _filtering = require("./filtering");
|
|
18
|
-
var _constants = require("@webiny/api-headless-cms/constants");
|
|
19
|
-
const createType = () => {
|
|
20
|
-
return "cms.entry";
|
|
21
|
-
};
|
|
22
|
-
const createLatestType = () => {
|
|
23
|
-
return `${createType()}.l`;
|
|
24
|
-
};
|
|
25
|
-
const createPublishedType = () => {
|
|
26
|
-
return `${createType()}.p`;
|
|
27
|
-
};
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { DataLoadersHandler } from "./dataLoaders.js";
|
|
3
|
+
import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createGSIPartitionKey, createPartitionKey, createPublishedSortKey, createRevisionSortKey } from "./keys.js";
|
|
5
|
+
import { decodeCursor, encodeCursor } from "@webiny/utils";
|
|
6
|
+
import { StorageOperationsCmsModelPlugin, StorageTransformPlugin } from "@webiny/api-headless-cms";
|
|
7
|
+
import { createFields } from "./filtering/createFields.js";
|
|
8
|
+
import { filter, sort } from "./filtering/index.js";
|
|
9
|
+
import { isDeletedEntryMetaField, isEntryLevelEntryMetaField, isRestoredEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
10
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
28
11
|
const convertToStorageEntry = params => {
|
|
29
12
|
const {
|
|
30
13
|
model,
|
|
@@ -54,7 +37,7 @@ const convertFromStorageEntry = params => {
|
|
|
54
37
|
};
|
|
55
38
|
};
|
|
56
39
|
const MAX_LIST_LIMIT = 1000000;
|
|
57
|
-
const createEntriesStorageOperations = params => {
|
|
40
|
+
export const createEntriesStorageOperations = params => {
|
|
58
41
|
const {
|
|
59
42
|
entity,
|
|
60
43
|
plugins
|
|
@@ -64,24 +47,25 @@ const createEntriesStorageOperations = params => {
|
|
|
64
47
|
if (storageOperationsCmsModelPlugin) {
|
|
65
48
|
return storageOperationsCmsModelPlugin;
|
|
66
49
|
}
|
|
67
|
-
storageOperationsCmsModelPlugin = plugins.oneByType(
|
|
50
|
+
storageOperationsCmsModelPlugin = plugins.oneByType(StorageOperationsCmsModelPlugin.type);
|
|
68
51
|
return storageOperationsCmsModelPlugin;
|
|
69
52
|
};
|
|
70
53
|
const getStorageOperationsModel = model => {
|
|
71
54
|
const plugin = getStorageOperationsCmsModelPlugin();
|
|
72
55
|
return plugin.getModel(model);
|
|
73
56
|
};
|
|
74
|
-
const dataLoaders = new
|
|
57
|
+
const dataLoaders = new DataLoadersHandler({
|
|
75
58
|
entity
|
|
76
59
|
});
|
|
77
60
|
const createStorageTransformCallable = model => {
|
|
78
61
|
// Cache StorageTransformPlugin to optimize execution.
|
|
79
|
-
const storageTransformPlugins = plugins.byType(
|
|
62
|
+
const storageTransformPlugins = plugins.byType(StorageTransformPlugin.type).reduce((collection, plugin) => {
|
|
80
63
|
collection[plugin.fieldType] = plugin;
|
|
81
64
|
return collection;
|
|
82
65
|
}, {});
|
|
83
66
|
return (field, value) => {
|
|
84
|
-
const
|
|
67
|
+
const fieldType = getBaseFieldType(field);
|
|
68
|
+
const plugin = storageTransformPlugins[fieldType];
|
|
85
69
|
if (!plugin) {
|
|
86
70
|
return value;
|
|
87
71
|
}
|
|
@@ -102,40 +86,32 @@ const createEntriesStorageOperations = params => {
|
|
|
102
86
|
storageEntry: initialStorageEntry
|
|
103
87
|
} = params;
|
|
104
88
|
const model = getStorageOperationsModel(initialModel);
|
|
105
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
106
|
-
id: entry.id,
|
|
107
|
-
locale: model.locale,
|
|
108
|
-
tenant: model.tenant
|
|
109
|
-
});
|
|
110
89
|
const isPublished = entry.status === "published";
|
|
111
90
|
const locked = isPublished ? true : entry.locked;
|
|
112
91
|
const storageEntry = convertToStorageEntry({
|
|
113
92
|
model,
|
|
114
93
|
storageEntry: initialStorageEntry
|
|
115
94
|
});
|
|
95
|
+
const storageEntryRevisionKeys = createEntryRevisionKeys(entry);
|
|
96
|
+
const storageEntryLatestKeys = createEntryLatestKeys(entry);
|
|
116
97
|
/**
|
|
117
98
|
* We need to:
|
|
118
99
|
* - create new main entry item
|
|
119
100
|
* - create new or update the latest entry item
|
|
120
101
|
*/
|
|
121
|
-
const entityBatch =
|
|
122
|
-
entity,
|
|
102
|
+
const entityBatch = entity.createEntityWriter({
|
|
123
103
|
put: [{
|
|
124
|
-
...
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
130
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
104
|
+
...storageEntryRevisionKeys,
|
|
105
|
+
data: {
|
|
106
|
+
...storageEntry,
|
|
107
|
+
locked
|
|
108
|
+
}
|
|
131
109
|
}, {
|
|
132
|
-
...
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
138
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
110
|
+
...storageEntryLatestKeys,
|
|
111
|
+
data: {
|
|
112
|
+
...storageEntry,
|
|
113
|
+
locked
|
|
114
|
+
}
|
|
139
115
|
}]
|
|
140
116
|
});
|
|
141
117
|
|
|
@@ -143,14 +119,13 @@ const createEntriesStorageOperations = params => {
|
|
|
143
119
|
* We need to create published entry if
|
|
144
120
|
*/
|
|
145
121
|
if (isPublished) {
|
|
122
|
+
const storageEntryPublishedKeys = createEntryPublishedKeys(storageEntry);
|
|
146
123
|
entityBatch.put({
|
|
147
|
-
...
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
153
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
124
|
+
...storageEntryPublishedKeys,
|
|
125
|
+
data: {
|
|
126
|
+
...storageEntry,
|
|
127
|
+
locked
|
|
128
|
+
}
|
|
154
129
|
});
|
|
155
130
|
}
|
|
156
131
|
try {
|
|
@@ -159,7 +134,7 @@ const createEntriesStorageOperations = params => {
|
|
|
159
134
|
model
|
|
160
135
|
});
|
|
161
136
|
} catch (ex) {
|
|
162
|
-
throw new
|
|
137
|
+
throw new WebinyError(ex.message || "Could not insert data into the DynamoDB.", ex.code || "CREATE_ENTRY_ERROR", {
|
|
163
138
|
error: ex,
|
|
164
139
|
entry
|
|
165
140
|
});
|
|
@@ -172,11 +147,6 @@ const createEntriesStorageOperations = params => {
|
|
|
172
147
|
storageEntry: initialStorageEntry
|
|
173
148
|
} = params;
|
|
174
149
|
const model = getStorageOperationsModel(initialModel);
|
|
175
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
176
|
-
id: entry.id,
|
|
177
|
-
locale: model.locale,
|
|
178
|
-
tenant: model.tenant
|
|
179
|
-
});
|
|
180
150
|
const storageEntry = convertToStorageEntry({
|
|
181
151
|
storageEntry: initialStorageEntry,
|
|
182
152
|
model
|
|
@@ -190,33 +160,26 @@ const createEntriesStorageOperations = params => {
|
|
|
190
160
|
* - update the published entry item to the current one
|
|
191
161
|
* - unpublish previously published revision (if any)
|
|
192
162
|
*/
|
|
193
|
-
const entityBatch =
|
|
194
|
-
entity,
|
|
163
|
+
const entityBatch = entity.createEntityWriter({
|
|
195
164
|
put: [{
|
|
196
|
-
...storageEntry,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
201
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
165
|
+
...createEntryRevisionKeys(storageEntry),
|
|
166
|
+
data: {
|
|
167
|
+
...storageEntry
|
|
168
|
+
}
|
|
202
169
|
}, {
|
|
203
|
-
...storageEntry,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
208
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
170
|
+
...createEntryLatestKeys(storageEntry),
|
|
171
|
+
data: {
|
|
172
|
+
...storageEntry
|
|
173
|
+
}
|
|
209
174
|
}]
|
|
210
175
|
});
|
|
211
176
|
const isPublished = entry.status === "published";
|
|
212
177
|
if (isPublished) {
|
|
213
178
|
entityBatch.put({
|
|
214
|
-
...storageEntry,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
219
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
179
|
+
...createEntryPublishedKeys(storageEntry),
|
|
180
|
+
data: {
|
|
181
|
+
...storageEntry
|
|
182
|
+
}
|
|
220
183
|
});
|
|
221
184
|
|
|
222
185
|
// Unpublish previously published revision (if any).
|
|
@@ -226,13 +189,11 @@ const createEntriesStorageOperations = params => {
|
|
|
226
189
|
});
|
|
227
190
|
if (publishedRevisionStorageEntry) {
|
|
228
191
|
entityBatch.put({
|
|
229
|
-
...publishedRevisionStorageEntry,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
235
|
-
GSI1_SK: (0, _keys.createGSISortKey)(publishedRevisionStorageEntry)
|
|
192
|
+
...createEntryRevisionKeys(publishedRevisionStorageEntry),
|
|
193
|
+
data: {
|
|
194
|
+
...publishedRevisionStorageEntry,
|
|
195
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
196
|
+
}
|
|
236
197
|
});
|
|
237
198
|
}
|
|
238
199
|
}
|
|
@@ -242,7 +203,7 @@ const createEntriesStorageOperations = params => {
|
|
|
242
203
|
model
|
|
243
204
|
});
|
|
244
205
|
} catch (ex) {
|
|
245
|
-
throw new
|
|
206
|
+
throw new WebinyError(ex.message || "Could not create revision from given entry.", ex.code || "CREATE_REVISION_ERROR", {
|
|
246
207
|
error: ex,
|
|
247
208
|
entry,
|
|
248
209
|
storageEntry
|
|
@@ -259,11 +220,6 @@ const createEntriesStorageOperations = params => {
|
|
|
259
220
|
storageEntry: initialStorageEntry
|
|
260
221
|
} = params;
|
|
261
222
|
const model = getStorageOperationsModel(initialModel);
|
|
262
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
263
|
-
id: entry.id,
|
|
264
|
-
locale: model.locale,
|
|
265
|
-
tenant: model.tenant
|
|
266
|
-
});
|
|
267
223
|
const isPublished = entry.status === "published";
|
|
268
224
|
const locked = isPublished ? true : entry.locked;
|
|
269
225
|
const storageEntry = convertToStorageEntry({
|
|
@@ -276,27 +232,22 @@ const createEntriesStorageOperations = params => {
|
|
|
276
232
|
* - update the latest entry if the current entry is the latest one
|
|
277
233
|
*/
|
|
278
234
|
|
|
279
|
-
const entityBatch =
|
|
280
|
-
entity,
|
|
235
|
+
const entityBatch = entity.createEntityWriter({
|
|
281
236
|
put: [{
|
|
282
|
-
...storageEntry,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
288
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
237
|
+
...createEntryRevisionKeys(storageEntry),
|
|
238
|
+
data: {
|
|
239
|
+
...storageEntry,
|
|
240
|
+
locked
|
|
241
|
+
}
|
|
289
242
|
}]
|
|
290
243
|
});
|
|
291
244
|
if (isPublished) {
|
|
292
245
|
entityBatch.put({
|
|
293
|
-
...storageEntry,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
299
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
246
|
+
...createEntryPublishedKeys(storageEntry),
|
|
247
|
+
data: {
|
|
248
|
+
...storageEntry,
|
|
249
|
+
locked
|
|
250
|
+
}
|
|
300
251
|
});
|
|
301
252
|
}
|
|
302
253
|
|
|
@@ -308,20 +259,18 @@ const createEntriesStorageOperations = params => {
|
|
|
308
259
|
const updatingLatestRevision = latestStorageEntry.id === entry.id;
|
|
309
260
|
if (updatingLatestRevision) {
|
|
310
261
|
entityBatch.put({
|
|
311
|
-
...storageEntry,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
317
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
262
|
+
...createEntryLatestKeys(storageEntry),
|
|
263
|
+
data: {
|
|
264
|
+
...storageEntry,
|
|
265
|
+
locked
|
|
266
|
+
}
|
|
318
267
|
});
|
|
319
268
|
} else {
|
|
320
269
|
/**
|
|
321
270
|
* If not updating latest revision, we still want to update the latest revision's
|
|
322
271
|
* entry-level meta fields to match the current revision's entry-level meta fields.
|
|
323
272
|
*/
|
|
324
|
-
const updatedEntryLevelMetaFields =
|
|
273
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
325
274
|
|
|
326
275
|
/**
|
|
327
276
|
* First we update the regular DynamoDB table. Two updates are needed:
|
|
@@ -329,22 +278,18 @@ const createEntriesStorageOperations = params => {
|
|
|
329
278
|
* - one for the latest record
|
|
330
279
|
*/
|
|
331
280
|
entityBatch.put({
|
|
332
|
-
...latestStorageEntry,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
338
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
281
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
282
|
+
data: {
|
|
283
|
+
...latestStorageEntry,
|
|
284
|
+
...updatedEntryLevelMetaFields
|
|
285
|
+
}
|
|
339
286
|
});
|
|
340
287
|
entityBatch.put({
|
|
341
|
-
...latestStorageEntry,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
347
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
288
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
289
|
+
data: {
|
|
290
|
+
...latestStorageEntry,
|
|
291
|
+
...updatedEntryLevelMetaFields
|
|
292
|
+
}
|
|
348
293
|
});
|
|
349
294
|
}
|
|
350
295
|
}
|
|
@@ -355,7 +300,7 @@ const createEntriesStorageOperations = params => {
|
|
|
355
300
|
});
|
|
356
301
|
return initialStorageEntry;
|
|
357
302
|
} catch (ex) {
|
|
358
|
-
throw new
|
|
303
|
+
throw new WebinyError(ex.message || "Could not update entry.", ex.code || "UPDATE_ERROR", {
|
|
359
304
|
error: ex,
|
|
360
305
|
entry,
|
|
361
306
|
latestStorageEntry
|
|
@@ -372,29 +317,29 @@ const createEntriesStorageOperations = params => {
|
|
|
372
317
|
/**
|
|
373
318
|
* First we need to load all the revisions and published / latest entry.
|
|
374
319
|
*/
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}),
|
|
320
|
+
const partitionKey = createPartitionKey({
|
|
321
|
+
id,
|
|
322
|
+
tenant: model.tenant
|
|
323
|
+
});
|
|
324
|
+
const records = await entity.queryAll({
|
|
325
|
+
partitionKey,
|
|
382
326
|
options: {
|
|
383
327
|
gte: " "
|
|
384
328
|
}
|
|
385
|
-
};
|
|
386
|
-
const records = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
329
|
+
});
|
|
387
330
|
/**
|
|
388
331
|
* Then create the batch writes for the DynamoDB, with the updated folderId.
|
|
389
332
|
*/
|
|
390
|
-
const entityBatch =
|
|
391
|
-
entity,
|
|
333
|
+
const entityBatch = entity.createEntityWriter({
|
|
392
334
|
put: records.map(item => {
|
|
393
335
|
return {
|
|
394
336
|
...item,
|
|
395
|
-
|
|
396
|
-
...item.
|
|
397
|
-
|
|
337
|
+
data: {
|
|
338
|
+
...item.data,
|
|
339
|
+
location: {
|
|
340
|
+
...item.data.location,
|
|
341
|
+
folderId
|
|
342
|
+
}
|
|
398
343
|
}
|
|
399
344
|
};
|
|
400
345
|
})
|
|
@@ -406,7 +351,7 @@ const createEntriesStorageOperations = params => {
|
|
|
406
351
|
try {
|
|
407
352
|
await entityBatch.execute();
|
|
408
353
|
} catch (ex) {
|
|
409
|
-
throw
|
|
354
|
+
throw WebinyError.from(ex, {
|
|
410
355
|
message: "Could not move records to a new folder.",
|
|
411
356
|
data: {
|
|
412
357
|
id,
|
|
@@ -425,22 +370,20 @@ const createEntriesStorageOperations = params => {
|
|
|
425
370
|
/**
|
|
426
371
|
* First we need to load all the revisions and published / latest entries.
|
|
427
372
|
*/
|
|
428
|
-
|
|
429
|
-
entity,
|
|
430
|
-
partitionKey: (0, _keys.createPartitionKey)({
|
|
431
|
-
id: entry.id,
|
|
432
|
-
locale: model.locale,
|
|
433
|
-
tenant: model.tenant
|
|
434
|
-
}),
|
|
435
|
-
options: {
|
|
436
|
-
gte: " "
|
|
437
|
-
}
|
|
438
|
-
};
|
|
373
|
+
|
|
439
374
|
let records = [];
|
|
440
375
|
try {
|
|
441
|
-
records = await
|
|
376
|
+
records = await entity.queryAll({
|
|
377
|
+
partitionKey: createPartitionKey({
|
|
378
|
+
id: entry.id,
|
|
379
|
+
tenant: model.tenant
|
|
380
|
+
}),
|
|
381
|
+
options: {
|
|
382
|
+
gte: " "
|
|
383
|
+
}
|
|
384
|
+
});
|
|
442
385
|
} catch (ex) {
|
|
443
|
-
throw new
|
|
386
|
+
throw new WebinyError(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
444
387
|
error: ex,
|
|
445
388
|
id: entry.id
|
|
446
389
|
});
|
|
@@ -456,20 +399,22 @@ const createEntriesStorageOperations = params => {
|
|
|
456
399
|
/**
|
|
457
400
|
* Let's pick the `deleted` meta fields from the storage entry.
|
|
458
401
|
*/
|
|
459
|
-
const updatedDeletedMetaFields =
|
|
402
|
+
const updatedDeletedMetaFields = pickEntryMetaFields(storageEntry, isDeletedEntryMetaField);
|
|
460
403
|
|
|
461
404
|
/**
|
|
462
405
|
* Then create the batch writes for the DynamoDB, with the updated data.
|
|
463
406
|
*/
|
|
464
|
-
const entityBatch =
|
|
465
|
-
entity,
|
|
407
|
+
const entityBatch = entity.createEntityWriter({
|
|
466
408
|
put: records.map(record => {
|
|
467
409
|
return {
|
|
468
410
|
...record,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
411
|
+
data: {
|
|
412
|
+
...record.data,
|
|
413
|
+
...updatedDeletedMetaFields,
|
|
414
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
415
|
+
location: storageEntry.location,
|
|
416
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
417
|
+
}
|
|
473
418
|
};
|
|
474
419
|
})
|
|
475
420
|
});
|
|
@@ -479,7 +424,7 @@ const createEntriesStorageOperations = params => {
|
|
|
479
424
|
try {
|
|
480
425
|
await entityBatch.execute();
|
|
481
426
|
} catch (ex) {
|
|
482
|
-
throw new
|
|
427
|
+
throw new WebinyError(ex.message || "Could not move the entry to the bin.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
|
|
483
428
|
error: ex,
|
|
484
429
|
entry,
|
|
485
430
|
storageEntry
|
|
@@ -492,28 +437,25 @@ const createEntriesStorageOperations = params => {
|
|
|
492
437
|
} = params;
|
|
493
438
|
const id = entry.id || entry.entryId;
|
|
494
439
|
const model = getStorageOperationsModel(initialModel);
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
locale: model.locale,
|
|
500
|
-
tenant: model.tenant
|
|
501
|
-
}),
|
|
502
|
-
options: {
|
|
503
|
-
gte: " "
|
|
504
|
-
}
|
|
505
|
-
};
|
|
440
|
+
const partitionKey = createPartitionKey({
|
|
441
|
+
id,
|
|
442
|
+
tenant: model.tenant
|
|
443
|
+
});
|
|
506
444
|
let records = [];
|
|
507
445
|
try {
|
|
508
|
-
records = await
|
|
446
|
+
records = await entity.queryAll({
|
|
447
|
+
partitionKey,
|
|
448
|
+
options: {
|
|
449
|
+
gte: " "
|
|
450
|
+
}
|
|
451
|
+
});
|
|
509
452
|
} catch (ex) {
|
|
510
|
-
throw new
|
|
453
|
+
throw new WebinyError(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
511
454
|
error: ex,
|
|
512
455
|
id
|
|
513
456
|
});
|
|
514
457
|
}
|
|
515
|
-
const entityBatch =
|
|
516
|
-
entity,
|
|
458
|
+
const entityBatch = entity.createEntityWriter({
|
|
517
459
|
delete: records.map(item => {
|
|
518
460
|
return {
|
|
519
461
|
PK: item.PK,
|
|
@@ -527,9 +469,9 @@ const createEntriesStorageOperations = params => {
|
|
|
527
469
|
model
|
|
528
470
|
});
|
|
529
471
|
} catch (ex) {
|
|
530
|
-
throw new
|
|
472
|
+
throw new WebinyError(ex.message || "Could not delete the entry.", ex.code || "DELETE_ENTRY_ERROR", {
|
|
531
473
|
error: ex,
|
|
532
|
-
partitionKey
|
|
474
|
+
partitionKey,
|
|
533
475
|
id
|
|
534
476
|
});
|
|
535
477
|
}
|
|
@@ -544,22 +486,19 @@ const createEntriesStorageOperations = params => {
|
|
|
544
486
|
/**
|
|
545
487
|
* First we need to load all the revisions and published / latest entries.
|
|
546
488
|
*/
|
|
547
|
-
const queryAllParams = {
|
|
548
|
-
entity,
|
|
549
|
-
partitionKey: (0, _keys.createPartitionKey)({
|
|
550
|
-
id: entry.id,
|
|
551
|
-
locale: model.locale,
|
|
552
|
-
tenant: model.tenant
|
|
553
|
-
}),
|
|
554
|
-
options: {
|
|
555
|
-
gte: " "
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
489
|
let records = [];
|
|
559
490
|
try {
|
|
560
|
-
records = await
|
|
491
|
+
records = await entity.queryAll({
|
|
492
|
+
partitionKey: createPartitionKey({
|
|
493
|
+
id: entry.id,
|
|
494
|
+
tenant: model.tenant
|
|
495
|
+
}),
|
|
496
|
+
options: {
|
|
497
|
+
gte: " "
|
|
498
|
+
}
|
|
499
|
+
});
|
|
561
500
|
} catch (ex) {
|
|
562
|
-
throw new
|
|
501
|
+
throw new WebinyError(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
563
502
|
error: ex,
|
|
564
503
|
id: entry.id
|
|
565
504
|
});
|
|
@@ -575,16 +514,18 @@ const createEntriesStorageOperations = params => {
|
|
|
575
514
|
/**
|
|
576
515
|
* Let's pick the `restored` meta fields from the storage entry.
|
|
577
516
|
*/
|
|
578
|
-
const updatedRestoredMetaFields =
|
|
579
|
-
const entityBatch =
|
|
580
|
-
entity,
|
|
517
|
+
const updatedRestoredMetaFields = pickEntryMetaFields(storageEntry, isRestoredEntryMetaField);
|
|
518
|
+
const entityBatch = entity.createEntityWriter({
|
|
581
519
|
put: records.map(record => {
|
|
582
520
|
return {
|
|
583
521
|
...record,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
522
|
+
data: {
|
|
523
|
+
...record.data,
|
|
524
|
+
...updatedRestoredMetaFields,
|
|
525
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
526
|
+
location: storageEntry.location,
|
|
527
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
528
|
+
}
|
|
588
529
|
};
|
|
589
530
|
})
|
|
590
531
|
});
|
|
@@ -599,7 +540,7 @@ const createEntriesStorageOperations = params => {
|
|
|
599
540
|
});
|
|
600
541
|
return initialStorageEntry;
|
|
601
542
|
} catch (ex) {
|
|
602
|
-
throw new
|
|
543
|
+
throw new WebinyError(ex.message || "Could not restore the entry from the bin.", ex.code || "RESTORE_ENTRY_ERROR", {
|
|
603
544
|
error: ex,
|
|
604
545
|
entry,
|
|
605
546
|
storageEntry
|
|
@@ -613,16 +554,14 @@ const createEntriesStorageOperations = params => {
|
|
|
613
554
|
latestStorageEntry: initialLatestStorageEntry
|
|
614
555
|
} = params;
|
|
615
556
|
const model = getStorageOperationsModel(initialModel);
|
|
616
|
-
const partitionKey =
|
|
557
|
+
const partitionKey = createPartitionKey({
|
|
617
558
|
id: entry.id,
|
|
618
|
-
locale: model.locale,
|
|
619
559
|
tenant: model.tenant
|
|
620
560
|
});
|
|
621
|
-
const entityBatch =
|
|
622
|
-
entity,
|
|
561
|
+
const entityBatch = entity.createEntityWriter({
|
|
623
562
|
delete: [{
|
|
624
563
|
PK: partitionKey,
|
|
625
|
-
SK:
|
|
564
|
+
SK: createRevisionSortKey(entry)
|
|
626
565
|
}]
|
|
627
566
|
});
|
|
628
567
|
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
@@ -633,7 +572,7 @@ const createEntriesStorageOperations = params => {
|
|
|
633
572
|
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
634
573
|
entityBatch.delete({
|
|
635
574
|
PK: partitionKey,
|
|
636
|
-
SK:
|
|
575
|
+
SK: createPublishedSortKey()
|
|
637
576
|
});
|
|
638
577
|
}
|
|
639
578
|
if (initialLatestStorageEntry) {
|
|
@@ -642,32 +581,28 @@ const createEntriesStorageOperations = params => {
|
|
|
642
581
|
model
|
|
643
582
|
});
|
|
644
583
|
entityBatch.put({
|
|
645
|
-
...latestStorageEntry,
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
650
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
584
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
585
|
+
data: {
|
|
586
|
+
...latestStorageEntry
|
|
587
|
+
}
|
|
651
588
|
});
|
|
652
589
|
|
|
653
590
|
// Do an update on the latest revision. We need to update the latest revision's
|
|
654
591
|
// entry-level meta fields to match the previous revision's entry-level meta fields.
|
|
655
592
|
entityBatch.put({
|
|
656
|
-
...latestStorageEntry,
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
661
|
-
GSI1_SK: (0, _keys.createGSISortKey)(initialLatestStorageEntry)
|
|
593
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
594
|
+
data: {
|
|
595
|
+
...latestStorageEntry
|
|
596
|
+
}
|
|
662
597
|
});
|
|
663
598
|
}
|
|
664
599
|
try {
|
|
665
|
-
entityBatch.execute();
|
|
600
|
+
await entityBatch.execute();
|
|
666
601
|
dataLoaders.clearAll({
|
|
667
602
|
model
|
|
668
603
|
});
|
|
669
604
|
} catch (ex) {
|
|
670
|
-
throw new
|
|
605
|
+
throw new WebinyError(ex.message, ex.code, {
|
|
671
606
|
error: ex,
|
|
672
607
|
entry,
|
|
673
608
|
latestEntry
|
|
@@ -690,13 +625,10 @@ const createEntriesStorageOperations = params => {
|
|
|
690
625
|
* Then we need to construct the queries for all the revisions and entries.
|
|
691
626
|
*/
|
|
692
627
|
|
|
693
|
-
const entityBatch = (
|
|
694
|
-
entity
|
|
695
|
-
});
|
|
628
|
+
const entityBatch = entity.createEntityWriter();
|
|
696
629
|
for (const id of entries) {
|
|
697
|
-
const partitionKey =
|
|
630
|
+
const partitionKey = createPartitionKey({
|
|
698
631
|
id,
|
|
699
|
-
locale: model.locale,
|
|
700
632
|
tenant: model.tenant
|
|
701
633
|
});
|
|
702
634
|
entityBatch.delete({
|
|
@@ -713,12 +645,11 @@ const createEntriesStorageOperations = params => {
|
|
|
713
645
|
*/
|
|
714
646
|
for (const revision of revisions) {
|
|
715
647
|
entityBatch.delete({
|
|
716
|
-
PK:
|
|
648
|
+
PK: createPartitionKey({
|
|
717
649
|
id: revision.id,
|
|
718
|
-
locale: model.locale,
|
|
719
650
|
tenant: model.tenant
|
|
720
651
|
}),
|
|
721
|
-
SK:
|
|
652
|
+
SK: createRevisionSortKey({
|
|
722
653
|
version: revision.version
|
|
723
654
|
})
|
|
724
655
|
});
|
|
@@ -828,44 +759,34 @@ const createEntriesStorageOperations = params => {
|
|
|
828
759
|
entryId,
|
|
829
760
|
version
|
|
830
761
|
} = params;
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
}),
|
|
762
|
+
const partitionKey = createPartitionKey({
|
|
763
|
+
tenant: model.tenant,
|
|
764
|
+
id: entryId
|
|
765
|
+
});
|
|
766
|
+
const unfilteredRevisions = await entity.queryAll({
|
|
767
|
+
partitionKey,
|
|
838
768
|
options: {
|
|
839
|
-
|
|
840
|
-
/**
|
|
841
|
-
* We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
|
|
842
|
-
*/
|
|
843
|
-
filters: [{
|
|
844
|
-
attr: "TYPE",
|
|
845
|
-
eq: createType()
|
|
846
|
-
}, {
|
|
847
|
-
attr: "version",
|
|
848
|
-
lt: version
|
|
849
|
-
}],
|
|
769
|
+
beginsWith: `REV#`,
|
|
850
770
|
reverse: true
|
|
851
771
|
}
|
|
852
|
-
};
|
|
772
|
+
});
|
|
773
|
+
const filteredRevisions = unfilteredRevisions.filter(item => {
|
|
774
|
+
return item.data.version < version;
|
|
775
|
+
});
|
|
776
|
+
const storageEntry = filteredRevisions[0];
|
|
777
|
+
if (!storageEntry) {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
853
780
|
try {
|
|
854
|
-
const result = await (0, _dbDynamodb.queryOne)(queryParams);
|
|
855
|
-
const storageEntry = (0, _dbDynamodb.cleanupItem)(entity, result);
|
|
856
|
-
if (!storageEntry) {
|
|
857
|
-
return null;
|
|
858
|
-
}
|
|
859
781
|
return convertFromStorageEntry({
|
|
860
|
-
storageEntry,
|
|
782
|
+
storageEntry: storageEntry.data,
|
|
861
783
|
model
|
|
862
784
|
});
|
|
863
785
|
} catch (ex) {
|
|
864
|
-
throw new
|
|
786
|
+
throw new WebinyError(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", {
|
|
865
787
|
...params,
|
|
866
788
|
error: ex,
|
|
867
|
-
partitionKey
|
|
868
|
-
options: queryParams.options,
|
|
789
|
+
partitionKey,
|
|
869
790
|
model
|
|
870
791
|
});
|
|
871
792
|
}
|
|
@@ -882,22 +803,22 @@ const createEntriesStorageOperations = params => {
|
|
|
882
803
|
} = params;
|
|
883
804
|
const limit = initialLimit <= 0 || initialLimit >= MAX_LIST_LIMIT ? MAX_LIST_LIMIT : initialLimit;
|
|
884
805
|
const type = initialWhere.published ? "P" : "L";
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
index: "GSI1",
|
|
890
|
-
gte: " "
|
|
891
|
-
}
|
|
806
|
+
const partitionKey = createGSIPartitionKey(model, type);
|
|
807
|
+
const options = {
|
|
808
|
+
index: "GSI1",
|
|
809
|
+
gte: " "
|
|
892
810
|
};
|
|
893
811
|
let storageEntries = [];
|
|
894
812
|
try {
|
|
895
|
-
storageEntries = await
|
|
813
|
+
storageEntries = await entity.queryAll({
|
|
814
|
+
partitionKey,
|
|
815
|
+
options
|
|
816
|
+
});
|
|
896
817
|
} catch (ex) {
|
|
897
|
-
throw new
|
|
818
|
+
throw new WebinyError(ex.message, "QUERY_ENTRIES_ERROR", {
|
|
898
819
|
error: ex,
|
|
899
|
-
partitionKey
|
|
900
|
-
options
|
|
820
|
+
partitionKey,
|
|
821
|
+
options
|
|
901
822
|
});
|
|
902
823
|
}
|
|
903
824
|
if (storageEntries.length === 0) {
|
|
@@ -917,7 +838,7 @@ const createEntriesStorageOperations = params => {
|
|
|
917
838
|
* We need an object containing field, transformers and paths.
|
|
918
839
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
919
840
|
*/
|
|
920
|
-
const modelFields =
|
|
841
|
+
const modelFields = createFields({
|
|
921
842
|
plugins,
|
|
922
843
|
fields: model.fields
|
|
923
844
|
});
|
|
@@ -929,7 +850,7 @@ const createEntriesStorageOperations = params => {
|
|
|
929
850
|
*/
|
|
930
851
|
const records = await Promise.all(storageEntries.map(async storageEntry => {
|
|
931
852
|
const entry = convertFromStorageEntry({
|
|
932
|
-
storageEntry,
|
|
853
|
+
storageEntry: storageEntry.data,
|
|
933
854
|
model
|
|
934
855
|
});
|
|
935
856
|
for (const field of model.fields) {
|
|
@@ -941,7 +862,7 @@ const createEntriesStorageOperations = params => {
|
|
|
941
862
|
* Filter the read items via the code.
|
|
942
863
|
* It will build the filters out of the where input and transform the values it is using.
|
|
943
864
|
*/
|
|
944
|
-
const filteredItems =
|
|
865
|
+
const filteredItems = filter({
|
|
945
866
|
items: records,
|
|
946
867
|
where,
|
|
947
868
|
plugins,
|
|
@@ -957,14 +878,14 @@ const createEntriesStorageOperations = params => {
|
|
|
957
878
|
* Sorting is also done via the code.
|
|
958
879
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
959
880
|
*/
|
|
960
|
-
const sortedItems =
|
|
881
|
+
const sortedItems = sort({
|
|
961
882
|
model,
|
|
962
883
|
plugins,
|
|
963
884
|
items: filteredItems,
|
|
964
885
|
sort: sortBy,
|
|
965
886
|
fields: modelFields
|
|
966
887
|
});
|
|
967
|
-
const start = parseInt(
|
|
888
|
+
const start = parseInt(decodeCursor(after) || "0") || 0;
|
|
968
889
|
const hasMoreItems = totalCount > start + limit;
|
|
969
890
|
const end = limit > totalCount + start + limit ? undefined : start + limit;
|
|
970
891
|
const slicedItems = sortedItems.slice(start, end);
|
|
@@ -972,12 +893,12 @@ const createEntriesStorageOperations = params => {
|
|
|
972
893
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
973
894
|
* Number is simply encoded.
|
|
974
895
|
*/
|
|
975
|
-
const cursor =
|
|
896
|
+
const cursor = encodeCursor(`${start + limit}`);
|
|
976
897
|
return {
|
|
977
898
|
hasMoreItems,
|
|
978
899
|
totalCount,
|
|
979
900
|
cursor,
|
|
980
|
-
items:
|
|
901
|
+
items: slicedItems
|
|
981
902
|
};
|
|
982
903
|
};
|
|
983
904
|
const get = async (initialModel, params) => {
|
|
@@ -996,18 +917,13 @@ const createEntriesStorageOperations = params => {
|
|
|
996
917
|
storageEntry: initialStorageEntry
|
|
997
918
|
} = params;
|
|
998
919
|
const model = getStorageOperationsModel(initialModel);
|
|
999
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
1000
|
-
id: entry.id,
|
|
1001
|
-
locale: model.locale,
|
|
1002
|
-
tenant: model.tenant
|
|
1003
|
-
});
|
|
1004
920
|
|
|
1005
921
|
/**
|
|
1006
922
|
* We need the latest and published entries to see if something needs to be updated alongside the publishing one.
|
|
1007
923
|
*/
|
|
1008
924
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
1009
925
|
if (!initialLatestStorageEntry) {
|
|
1010
|
-
throw new
|
|
926
|
+
throw new WebinyError(`Could not publish entry. Could not load latest ("L") record.`, "PUBLISH_ERROR", {
|
|
1011
927
|
entry
|
|
1012
928
|
});
|
|
1013
929
|
}
|
|
@@ -1018,22 +934,17 @@ const createEntriesStorageOperations = params => {
|
|
|
1018
934
|
});
|
|
1019
935
|
|
|
1020
936
|
// 1. Update REV# and P records with new data.
|
|
1021
|
-
const entityBatch =
|
|
1022
|
-
entity,
|
|
937
|
+
const entityBatch = entity.createEntityWriter({
|
|
1023
938
|
put: [{
|
|
1024
|
-
...storageEntry,
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1029
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
939
|
+
...createEntryRevisionKeys(storageEntry),
|
|
940
|
+
data: {
|
|
941
|
+
...storageEntry
|
|
942
|
+
}
|
|
1030
943
|
}, {
|
|
1031
|
-
...storageEntry,
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
1036
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
944
|
+
...createEntryPublishedKeys(storageEntry),
|
|
945
|
+
data: {
|
|
946
|
+
...storageEntry
|
|
947
|
+
}
|
|
1037
948
|
}]
|
|
1038
949
|
});
|
|
1039
950
|
|
|
@@ -1044,12 +955,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1044
955
|
if (publishingLatestRevision) {
|
|
1045
956
|
// 2.1 If we're publishing the latest revision, we first need to update the L record.
|
|
1046
957
|
entityBatch.put({
|
|
1047
|
-
...storageEntry,
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1052
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
958
|
+
...createEntryLatestKeys(storageEntry),
|
|
959
|
+
data: {
|
|
960
|
+
...storageEntry
|
|
961
|
+
}
|
|
1053
962
|
});
|
|
1054
963
|
|
|
1055
964
|
// 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.
|
|
@@ -1059,20 +968,18 @@ const createEntriesStorageOperations = params => {
|
|
|
1059
968
|
model
|
|
1060
969
|
});
|
|
1061
970
|
entityBatch.put({
|
|
1062
|
-
...publishedStorageEntry,
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1068
|
-
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
971
|
+
...createEntryRevisionKeys(publishedStorageEntry),
|
|
972
|
+
data: {
|
|
973
|
+
...publishedStorageEntry,
|
|
974
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
975
|
+
}
|
|
1069
976
|
});
|
|
1070
977
|
}
|
|
1071
978
|
} else {
|
|
1072
979
|
// 2.3 If the published revision is not the latest one, the situation is a bit
|
|
1073
980
|
// more complex. We first need to update the L and REV# records with the new
|
|
1074
981
|
// values of *only entry-level* meta fields.
|
|
1075
|
-
const updatedEntryLevelMetaFields =
|
|
982
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
1076
983
|
const latestStorageEntry = convertToStorageEntry({
|
|
1077
984
|
storageEntry: initialLatestStorageEntry,
|
|
1078
985
|
model
|
|
@@ -1081,8 +988,8 @@ const createEntriesStorageOperations = params => {
|
|
|
1081
988
|
// 2.3.1 Update L record. Apart from updating the entry-level meta fields, we also need
|
|
1082
989
|
// to change the status from "published" to "unpublished" (if the status is set to "published").
|
|
1083
990
|
let latestRevisionStatus = latestStorageEntry.status;
|
|
1084
|
-
if (latestRevisionStatus ===
|
|
1085
|
-
latestRevisionStatus =
|
|
991
|
+
if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {
|
|
992
|
+
latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
1086
993
|
}
|
|
1087
994
|
const latestStorageEntryFields = {
|
|
1088
995
|
...latestStorageEntry,
|
|
@@ -1090,22 +997,18 @@ const createEntriesStorageOperations = params => {
|
|
|
1090
997
|
status: latestRevisionStatus
|
|
1091
998
|
};
|
|
1092
999
|
entityBatch.put({
|
|
1093
|
-
...latestStorageEntryFields,
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1098
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1000
|
+
...createEntryLatestKeys(latestStorageEntryFields),
|
|
1001
|
+
data: {
|
|
1002
|
+
...latestStorageEntryFields
|
|
1003
|
+
}
|
|
1099
1004
|
});
|
|
1100
1005
|
|
|
1101
1006
|
// 2.3.2 Update REV# record.
|
|
1102
1007
|
entityBatch.put({
|
|
1103
|
-
...latestStorageEntryFields,
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1108
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1008
|
+
...createEntryRevisionKeys(latestStorageEntryFields),
|
|
1009
|
+
data: {
|
|
1010
|
+
...latestStorageEntryFields
|
|
1011
|
+
}
|
|
1109
1012
|
});
|
|
1110
1013
|
|
|
1111
1014
|
// 2.3.3 Finally, if we got a published entry, but it wasn't the latest one, we need to take
|
|
@@ -1117,13 +1020,11 @@ const createEntriesStorageOperations = params => {
|
|
|
1117
1020
|
model
|
|
1118
1021
|
});
|
|
1119
1022
|
entityBatch.put({
|
|
1120
|
-
...publishedStorageEntry,
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1126
|
-
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
1023
|
+
...createEntryRevisionKeys(publishedStorageEntry),
|
|
1024
|
+
data: {
|
|
1025
|
+
...publishedStorageEntry,
|
|
1026
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
1027
|
+
}
|
|
1127
1028
|
});
|
|
1128
1029
|
}
|
|
1129
1030
|
}
|
|
@@ -1134,7 +1035,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1134
1035
|
});
|
|
1135
1036
|
return initialStorageEntry;
|
|
1136
1037
|
} catch (ex) {
|
|
1137
|
-
throw new
|
|
1038
|
+
throw new WebinyError(ex.message || "Could not execute the publishing batch.", ex.code || "PUBLISH_ERROR", {
|
|
1138
1039
|
entry,
|
|
1139
1040
|
latestStorageEntry: initialLatestStorageEntry,
|
|
1140
1041
|
publishedStorageEntry: initialPublishedStorageEntry
|
|
@@ -1147,9 +1048,8 @@ const createEntriesStorageOperations = params => {
|
|
|
1147
1048
|
storageEntry: initialStorageEntry
|
|
1148
1049
|
} = params;
|
|
1149
1050
|
const model = getStorageOperationsModel(initialModel);
|
|
1150
|
-
const partitionKey =
|
|
1051
|
+
const partitionKey = createPartitionKey({
|
|
1151
1052
|
id: entry.id,
|
|
1152
|
-
locale: model.locale,
|
|
1153
1053
|
tenant: model.tenant
|
|
1154
1054
|
});
|
|
1155
1055
|
const storageEntry = convertToStorageEntry({
|
|
@@ -1162,19 +1062,16 @@ const createEntriesStorageOperations = params => {
|
|
|
1162
1062
|
* - update current entry revision with new data
|
|
1163
1063
|
* - update the latest entry status - if entry being unpublished is latest
|
|
1164
1064
|
*/
|
|
1165
|
-
const entityBatch =
|
|
1166
|
-
entity,
|
|
1065
|
+
const entityBatch = entity.createEntityWriter({
|
|
1167
1066
|
delete: [{
|
|
1168
1067
|
PK: partitionKey,
|
|
1169
|
-
SK:
|
|
1068
|
+
SK: createPublishedSortKey()
|
|
1170
1069
|
}],
|
|
1171
1070
|
put: [{
|
|
1172
|
-
...storageEntry,
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1177
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1071
|
+
...createEntryRevisionKeys(storageEntry),
|
|
1072
|
+
data: {
|
|
1073
|
+
...storageEntry
|
|
1074
|
+
}
|
|
1178
1075
|
}]
|
|
1179
1076
|
});
|
|
1180
1077
|
|
|
@@ -1186,12 +1083,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1186
1083
|
const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
1187
1084
|
if (unpublishingLatestRevision) {
|
|
1188
1085
|
entityBatch.put({
|
|
1189
|
-
...storageEntry,
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1194
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1086
|
+
...createEntryLatestKeys(storageEntry),
|
|
1087
|
+
data: {
|
|
1088
|
+
...storageEntry
|
|
1089
|
+
}
|
|
1195
1090
|
});
|
|
1196
1091
|
} else {
|
|
1197
1092
|
const latestStorageEntry = convertToStorageEntry({
|
|
@@ -1201,28 +1096,24 @@ const createEntriesStorageOperations = params => {
|
|
|
1201
1096
|
|
|
1202
1097
|
// If the unpublished revision is not the latest one, we still need to
|
|
1203
1098
|
// update the latest record with the new values of entry-level meta fields.
|
|
1204
|
-
const updatedEntryLevelMetaFields =
|
|
1099
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
1205
1100
|
|
|
1206
1101
|
// 1. Update actual revision record.
|
|
1207
1102
|
entityBatch.put({
|
|
1208
|
-
...latestStorageEntry,
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1214
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1103
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
1104
|
+
data: {
|
|
1105
|
+
...latestStorageEntry,
|
|
1106
|
+
...updatedEntryLevelMetaFields
|
|
1107
|
+
}
|
|
1215
1108
|
});
|
|
1216
1109
|
|
|
1217
1110
|
// 2. Update latest record.
|
|
1218
1111
|
entityBatch.put({
|
|
1219
|
-
...latestStorageEntry,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1225
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1112
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
1113
|
+
data: {
|
|
1114
|
+
...latestStorageEntry,
|
|
1115
|
+
...updatedEntryLevelMetaFields
|
|
1116
|
+
}
|
|
1226
1117
|
});
|
|
1227
1118
|
}
|
|
1228
1119
|
}
|
|
@@ -1233,7 +1124,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1233
1124
|
});
|
|
1234
1125
|
return initialStorageEntry;
|
|
1235
1126
|
} catch (ex) {
|
|
1236
|
-
throw new
|
|
1127
|
+
throw new WebinyError(ex.message || "Could not execute unpublish batch.", ex.code || "UNPUBLISH_ERROR", {
|
|
1237
1128
|
entry,
|
|
1238
1129
|
storageEntry
|
|
1239
1130
|
});
|
|
@@ -1246,7 +1137,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1246
1137
|
} = params;
|
|
1247
1138
|
const field = model.fields.find(f => f.fieldId === fieldId);
|
|
1248
1139
|
if (!field) {
|
|
1249
|
-
throw new
|
|
1140
|
+
throw new WebinyError(`Could not find field with given "fieldId" value.`, "FIELD_NOT_FOUND", {
|
|
1250
1141
|
fieldId
|
|
1251
1142
|
});
|
|
1252
1143
|
}
|
|
@@ -1301,6 +1192,5 @@ const createEntriesStorageOperations = params => {
|
|
|
1301
1192
|
getUniqueFieldValues
|
|
1302
1193
|
};
|
|
1303
1194
|
};
|
|
1304
|
-
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|
|
1305
1195
|
|
|
1306
1196
|
//# sourceMappingURL=index.js.map
|