@webiny/api-headless-cms-ddb 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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 +61 -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 +4 -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/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 -3
- package/index.js +62 -92
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +3 -13
- 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 +16 -26
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +27 -33
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +27 -33
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +29 -35
- 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 +4 -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 +16 -24
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +7 -6
- package/operations/entry/filtering/createExpressions.js +29 -35
- 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 +7 -6
- package/operations/entry/filtering/filter.js +22 -27
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +4 -4
- package/operations/entry/filtering/fullTextSearch.js +7 -15
- 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 +10 -18
- 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 +15 -21
- 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 +16 -22
- 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 +14 -17
- 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 +4 -4
- 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 +4 -3
- package/operations/entry/index.js +279 -388
- 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 +4 -5
- package/operations/group/index.js +37 -69
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +36 -59
- package/operations/model/index.js.map +1 -1
- package/package.json +24 -20
- 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 +5 -5
- 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 +20 -20
- 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/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -94
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -61
- package/dynamoDb/storage/richText.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,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 } 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";
|
|
11
|
+
import { StorageTransformRegistry } from "@webiny/api-headless-cms/exports/api/cms/storage.js";
|
|
28
12
|
const convertToStorageEntry = params => {
|
|
29
13
|
const {
|
|
30
14
|
model,
|
|
@@ -54,45 +38,42 @@ const convertFromStorageEntry = params => {
|
|
|
54
38
|
};
|
|
55
39
|
};
|
|
56
40
|
const MAX_LIST_LIMIT = 1000000;
|
|
57
|
-
const createEntriesStorageOperations = params => {
|
|
41
|
+
export const createEntriesStorageOperations = params => {
|
|
58
42
|
const {
|
|
59
43
|
entity,
|
|
44
|
+
container,
|
|
60
45
|
plugins
|
|
61
46
|
} = params;
|
|
47
|
+
const storageTransformRegistry = container.resolve(StorageTransformRegistry);
|
|
62
48
|
let storageOperationsCmsModelPlugin;
|
|
63
49
|
const getStorageOperationsCmsModelPlugin = () => {
|
|
64
50
|
if (storageOperationsCmsModelPlugin) {
|
|
65
51
|
return storageOperationsCmsModelPlugin;
|
|
66
52
|
}
|
|
67
|
-
storageOperationsCmsModelPlugin = plugins.oneByType(
|
|
53
|
+
storageOperationsCmsModelPlugin = plugins.oneByType(StorageOperationsCmsModelPlugin.type);
|
|
68
54
|
return storageOperationsCmsModelPlugin;
|
|
69
55
|
};
|
|
70
56
|
const getStorageOperationsModel = model => {
|
|
71
57
|
const plugin = getStorageOperationsCmsModelPlugin();
|
|
72
58
|
return plugin.getModel(model);
|
|
73
59
|
};
|
|
74
|
-
const dataLoaders = new
|
|
60
|
+
const dataLoaders = new DataLoadersHandler({
|
|
75
61
|
entity
|
|
76
62
|
});
|
|
77
63
|
const createStorageTransformCallable = model => {
|
|
78
|
-
// Cache StorageTransformPlugin to optimize execution.
|
|
79
|
-
const storageTransformPlugins = plugins.byType(_apiHeadlessCms.StorageTransformPlugin.type).reduce((collection, plugin) => {
|
|
80
|
-
collection[plugin.fieldType] = plugin;
|
|
81
|
-
return collection;
|
|
82
|
-
}, {});
|
|
83
64
|
return (field, value) => {
|
|
84
|
-
const
|
|
85
|
-
|
|
65
|
+
const fieldType = getBaseFieldType(field);
|
|
66
|
+
const storageTransform = storageTransformRegistry.get(fieldType);
|
|
67
|
+
if (!storageTransform) {
|
|
86
68
|
return value;
|
|
87
69
|
}
|
|
88
|
-
return
|
|
70
|
+
return storageTransform.fromStorage({
|
|
89
71
|
model,
|
|
90
72
|
field,
|
|
91
73
|
value,
|
|
92
|
-
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
plugins
|
|
74
|
+
getStorageTransform(fieldType) {
|
|
75
|
+
return storageTransformRegistry.get(fieldType) || storageTransformRegistry.get("*");
|
|
76
|
+
}
|
|
96
77
|
});
|
|
97
78
|
};
|
|
98
79
|
};
|
|
@@ -102,40 +83,32 @@ const createEntriesStorageOperations = params => {
|
|
|
102
83
|
storageEntry: initialStorageEntry
|
|
103
84
|
} = params;
|
|
104
85
|
const model = getStorageOperationsModel(initialModel);
|
|
105
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
106
|
-
id: entry.id,
|
|
107
|
-
locale: model.locale,
|
|
108
|
-
tenant: model.tenant
|
|
109
|
-
});
|
|
110
86
|
const isPublished = entry.status === "published";
|
|
111
87
|
const locked = isPublished ? true : entry.locked;
|
|
112
88
|
const storageEntry = convertToStorageEntry({
|
|
113
89
|
model,
|
|
114
90
|
storageEntry: initialStorageEntry
|
|
115
91
|
});
|
|
92
|
+
const storageEntryRevisionKeys = createEntryRevisionKeys(entry);
|
|
93
|
+
const storageEntryLatestKeys = createEntryLatestKeys(entry);
|
|
116
94
|
/**
|
|
117
95
|
* We need to:
|
|
118
96
|
* - create new main entry item
|
|
119
97
|
* - create new or update the latest entry item
|
|
120
98
|
*/
|
|
121
|
-
const entityBatch =
|
|
122
|
-
entity,
|
|
99
|
+
const entityBatch = entity.createEntityWriter({
|
|
123
100
|
put: [{
|
|
124
|
-
...
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
130
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
101
|
+
...storageEntryRevisionKeys,
|
|
102
|
+
data: {
|
|
103
|
+
...storageEntry,
|
|
104
|
+
locked
|
|
105
|
+
}
|
|
131
106
|
}, {
|
|
132
|
-
...
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
138
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
107
|
+
...storageEntryLatestKeys,
|
|
108
|
+
data: {
|
|
109
|
+
...storageEntry,
|
|
110
|
+
locked
|
|
111
|
+
}
|
|
139
112
|
}]
|
|
140
113
|
});
|
|
141
114
|
|
|
@@ -143,14 +116,13 @@ const createEntriesStorageOperations = params => {
|
|
|
143
116
|
* We need to create published entry if
|
|
144
117
|
*/
|
|
145
118
|
if (isPublished) {
|
|
119
|
+
const storageEntryPublishedKeys = createEntryPublishedKeys(storageEntry);
|
|
146
120
|
entityBatch.put({
|
|
147
|
-
...
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
153
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
121
|
+
...storageEntryPublishedKeys,
|
|
122
|
+
data: {
|
|
123
|
+
...storageEntry,
|
|
124
|
+
locked
|
|
125
|
+
}
|
|
154
126
|
});
|
|
155
127
|
}
|
|
156
128
|
try {
|
|
@@ -159,7 +131,7 @@ const createEntriesStorageOperations = params => {
|
|
|
159
131
|
model
|
|
160
132
|
});
|
|
161
133
|
} catch (ex) {
|
|
162
|
-
throw new
|
|
134
|
+
throw new WebinyError(ex.message || "Could not insert data into the DynamoDB.", ex.code || "CREATE_ENTRY_ERROR", {
|
|
163
135
|
error: ex,
|
|
164
136
|
entry
|
|
165
137
|
});
|
|
@@ -172,11 +144,6 @@ const createEntriesStorageOperations = params => {
|
|
|
172
144
|
storageEntry: initialStorageEntry
|
|
173
145
|
} = params;
|
|
174
146
|
const model = getStorageOperationsModel(initialModel);
|
|
175
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
176
|
-
id: entry.id,
|
|
177
|
-
locale: model.locale,
|
|
178
|
-
tenant: model.tenant
|
|
179
|
-
});
|
|
180
147
|
const storageEntry = convertToStorageEntry({
|
|
181
148
|
storageEntry: initialStorageEntry,
|
|
182
149
|
model
|
|
@@ -190,33 +157,26 @@ const createEntriesStorageOperations = params => {
|
|
|
190
157
|
* - update the published entry item to the current one
|
|
191
158
|
* - unpublish previously published revision (if any)
|
|
192
159
|
*/
|
|
193
|
-
const entityBatch =
|
|
194
|
-
entity,
|
|
160
|
+
const entityBatch = entity.createEntityWriter({
|
|
195
161
|
put: [{
|
|
196
|
-
...storageEntry,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
201
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
162
|
+
...createEntryRevisionKeys(storageEntry),
|
|
163
|
+
data: {
|
|
164
|
+
...storageEntry
|
|
165
|
+
}
|
|
202
166
|
}, {
|
|
203
|
-
...storageEntry,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
208
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
167
|
+
...createEntryLatestKeys(storageEntry),
|
|
168
|
+
data: {
|
|
169
|
+
...storageEntry
|
|
170
|
+
}
|
|
209
171
|
}]
|
|
210
172
|
});
|
|
211
173
|
const isPublished = entry.status === "published";
|
|
212
174
|
if (isPublished) {
|
|
213
175
|
entityBatch.put({
|
|
214
|
-
...storageEntry,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
219
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
176
|
+
...createEntryPublishedKeys(storageEntry),
|
|
177
|
+
data: {
|
|
178
|
+
...storageEntry
|
|
179
|
+
}
|
|
220
180
|
});
|
|
221
181
|
|
|
222
182
|
// Unpublish previously published revision (if any).
|
|
@@ -226,13 +186,11 @@ const createEntriesStorageOperations = params => {
|
|
|
226
186
|
});
|
|
227
187
|
if (publishedRevisionStorageEntry) {
|
|
228
188
|
entityBatch.put({
|
|
229
|
-
...publishedRevisionStorageEntry,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
235
|
-
GSI1_SK: (0, _keys.createGSISortKey)(publishedRevisionStorageEntry)
|
|
189
|
+
...createEntryRevisionKeys(publishedRevisionStorageEntry),
|
|
190
|
+
data: {
|
|
191
|
+
...publishedRevisionStorageEntry,
|
|
192
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
193
|
+
}
|
|
236
194
|
});
|
|
237
195
|
}
|
|
238
196
|
}
|
|
@@ -242,7 +200,7 @@ const createEntriesStorageOperations = params => {
|
|
|
242
200
|
model
|
|
243
201
|
});
|
|
244
202
|
} catch (ex) {
|
|
245
|
-
throw new
|
|
203
|
+
throw new WebinyError(ex.message || "Could not create revision from given entry.", ex.code || "CREATE_REVISION_ERROR", {
|
|
246
204
|
error: ex,
|
|
247
205
|
entry,
|
|
248
206
|
storageEntry
|
|
@@ -259,11 +217,6 @@ const createEntriesStorageOperations = params => {
|
|
|
259
217
|
storageEntry: initialStorageEntry
|
|
260
218
|
} = params;
|
|
261
219
|
const model = getStorageOperationsModel(initialModel);
|
|
262
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
263
|
-
id: entry.id,
|
|
264
|
-
locale: model.locale,
|
|
265
|
-
tenant: model.tenant
|
|
266
|
-
});
|
|
267
220
|
const isPublished = entry.status === "published";
|
|
268
221
|
const locked = isPublished ? true : entry.locked;
|
|
269
222
|
const storageEntry = convertToStorageEntry({
|
|
@@ -276,27 +229,22 @@ const createEntriesStorageOperations = params => {
|
|
|
276
229
|
* - update the latest entry if the current entry is the latest one
|
|
277
230
|
*/
|
|
278
231
|
|
|
279
|
-
const entityBatch =
|
|
280
|
-
entity,
|
|
232
|
+
const entityBatch = entity.createEntityWriter({
|
|
281
233
|
put: [{
|
|
282
|
-
...storageEntry,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
288
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
234
|
+
...createEntryRevisionKeys(storageEntry),
|
|
235
|
+
data: {
|
|
236
|
+
...storageEntry,
|
|
237
|
+
locked
|
|
238
|
+
}
|
|
289
239
|
}]
|
|
290
240
|
});
|
|
291
241
|
if (isPublished) {
|
|
292
242
|
entityBatch.put({
|
|
293
|
-
...storageEntry,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
299
|
-
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
243
|
+
...createEntryPublishedKeys(storageEntry),
|
|
244
|
+
data: {
|
|
245
|
+
...storageEntry,
|
|
246
|
+
locked
|
|
247
|
+
}
|
|
300
248
|
});
|
|
301
249
|
}
|
|
302
250
|
|
|
@@ -308,20 +256,18 @@ const createEntriesStorageOperations = params => {
|
|
|
308
256
|
const updatingLatestRevision = latestStorageEntry.id === entry.id;
|
|
309
257
|
if (updatingLatestRevision) {
|
|
310
258
|
entityBatch.put({
|
|
311
|
-
...storageEntry,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
317
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
259
|
+
...createEntryLatestKeys(storageEntry),
|
|
260
|
+
data: {
|
|
261
|
+
...storageEntry,
|
|
262
|
+
locked
|
|
263
|
+
}
|
|
318
264
|
});
|
|
319
265
|
} else {
|
|
320
266
|
/**
|
|
321
267
|
* If not updating latest revision, we still want to update the latest revision's
|
|
322
268
|
* entry-level meta fields to match the current revision's entry-level meta fields.
|
|
323
269
|
*/
|
|
324
|
-
const updatedEntryLevelMetaFields =
|
|
270
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
325
271
|
|
|
326
272
|
/**
|
|
327
273
|
* First we update the regular DynamoDB table. Two updates are needed:
|
|
@@ -329,22 +275,18 @@ const createEntriesStorageOperations = params => {
|
|
|
329
275
|
* - one for the latest record
|
|
330
276
|
*/
|
|
331
277
|
entityBatch.put({
|
|
332
|
-
...latestStorageEntry,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
338
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
278
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
279
|
+
data: {
|
|
280
|
+
...latestStorageEntry,
|
|
281
|
+
...updatedEntryLevelMetaFields
|
|
282
|
+
}
|
|
339
283
|
});
|
|
340
284
|
entityBatch.put({
|
|
341
|
-
...latestStorageEntry,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
347
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
285
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
286
|
+
data: {
|
|
287
|
+
...latestStorageEntry,
|
|
288
|
+
...updatedEntryLevelMetaFields
|
|
289
|
+
}
|
|
348
290
|
});
|
|
349
291
|
}
|
|
350
292
|
}
|
|
@@ -355,7 +297,7 @@ const createEntriesStorageOperations = params => {
|
|
|
355
297
|
});
|
|
356
298
|
return initialStorageEntry;
|
|
357
299
|
} catch (ex) {
|
|
358
|
-
throw new
|
|
300
|
+
throw new WebinyError(ex.message || "Could not update entry.", ex.code || "UPDATE_ERROR", {
|
|
359
301
|
error: ex,
|
|
360
302
|
entry,
|
|
361
303
|
latestStorageEntry
|
|
@@ -372,29 +314,29 @@ const createEntriesStorageOperations = params => {
|
|
|
372
314
|
/**
|
|
373
315
|
* First we need to load all the revisions and published / latest entry.
|
|
374
316
|
*/
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}),
|
|
317
|
+
const partitionKey = createPartitionKey({
|
|
318
|
+
id,
|
|
319
|
+
tenant: model.tenant
|
|
320
|
+
});
|
|
321
|
+
const records = await entity.queryAll({
|
|
322
|
+
partitionKey,
|
|
382
323
|
options: {
|
|
383
324
|
gte: " "
|
|
384
325
|
}
|
|
385
|
-
};
|
|
386
|
-
const records = await (0, _dbDynamodb.queryAll)(queryAllParams);
|
|
326
|
+
});
|
|
387
327
|
/**
|
|
388
328
|
* Then create the batch writes for the DynamoDB, with the updated folderId.
|
|
389
329
|
*/
|
|
390
|
-
const entityBatch =
|
|
391
|
-
entity,
|
|
330
|
+
const entityBatch = entity.createEntityWriter({
|
|
392
331
|
put: records.map(item => {
|
|
393
332
|
return {
|
|
394
333
|
...item,
|
|
395
|
-
|
|
396
|
-
...item.
|
|
397
|
-
|
|
334
|
+
data: {
|
|
335
|
+
...item.data,
|
|
336
|
+
location: {
|
|
337
|
+
...item.data.location,
|
|
338
|
+
folderId
|
|
339
|
+
}
|
|
398
340
|
}
|
|
399
341
|
};
|
|
400
342
|
})
|
|
@@ -406,7 +348,7 @@ const createEntriesStorageOperations = params => {
|
|
|
406
348
|
try {
|
|
407
349
|
await entityBatch.execute();
|
|
408
350
|
} catch (ex) {
|
|
409
|
-
throw
|
|
351
|
+
throw WebinyError.from(ex, {
|
|
410
352
|
message: "Could not move records to a new folder.",
|
|
411
353
|
data: {
|
|
412
354
|
id,
|
|
@@ -425,22 +367,20 @@ const createEntriesStorageOperations = params => {
|
|
|
425
367
|
/**
|
|
426
368
|
* First we need to load all the revisions and published / latest entries.
|
|
427
369
|
*/
|
|
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
|
-
};
|
|
370
|
+
|
|
439
371
|
let records = [];
|
|
440
372
|
try {
|
|
441
|
-
records = await
|
|
373
|
+
records = await entity.queryAll({
|
|
374
|
+
partitionKey: createPartitionKey({
|
|
375
|
+
id: entry.id,
|
|
376
|
+
tenant: model.tenant
|
|
377
|
+
}),
|
|
378
|
+
options: {
|
|
379
|
+
gte: " "
|
|
380
|
+
}
|
|
381
|
+
});
|
|
442
382
|
} catch (ex) {
|
|
443
|
-
throw new
|
|
383
|
+
throw new WebinyError(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
444
384
|
error: ex,
|
|
445
385
|
id: entry.id
|
|
446
386
|
});
|
|
@@ -456,20 +396,22 @@ const createEntriesStorageOperations = params => {
|
|
|
456
396
|
/**
|
|
457
397
|
* Let's pick the `deleted` meta fields from the storage entry.
|
|
458
398
|
*/
|
|
459
|
-
const updatedDeletedMetaFields =
|
|
399
|
+
const updatedDeletedMetaFields = pickEntryMetaFields(storageEntry, isDeletedEntryMetaField);
|
|
460
400
|
|
|
461
401
|
/**
|
|
462
402
|
* Then create the batch writes for the DynamoDB, with the updated data.
|
|
463
403
|
*/
|
|
464
|
-
const entityBatch =
|
|
465
|
-
entity,
|
|
404
|
+
const entityBatch = entity.createEntityWriter({
|
|
466
405
|
put: records.map(record => {
|
|
467
406
|
return {
|
|
468
407
|
...record,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
408
|
+
data: {
|
|
409
|
+
...record.data,
|
|
410
|
+
...updatedDeletedMetaFields,
|
|
411
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
412
|
+
location: storageEntry.location,
|
|
413
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
414
|
+
}
|
|
473
415
|
};
|
|
474
416
|
})
|
|
475
417
|
});
|
|
@@ -478,8 +420,11 @@ const createEntriesStorageOperations = params => {
|
|
|
478
420
|
*/
|
|
479
421
|
try {
|
|
480
422
|
await entityBatch.execute();
|
|
423
|
+
dataLoaders.clearAll({
|
|
424
|
+
model
|
|
425
|
+
});
|
|
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,
|
|
@@ -949,7 +870,8 @@ const createEntriesStorageOperations = params => {
|
|
|
949
870
|
fullTextSearch: {
|
|
950
871
|
term: search,
|
|
951
872
|
fields: fields || []
|
|
952
|
-
}
|
|
873
|
+
},
|
|
874
|
+
container
|
|
953
875
|
});
|
|
954
876
|
const totalCount = filteredItems.length;
|
|
955
877
|
|
|
@@ -957,14 +879,14 @@ const createEntriesStorageOperations = params => {
|
|
|
957
879
|
* Sorting is also done via the code.
|
|
958
880
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
959
881
|
*/
|
|
960
|
-
const sortedItems =
|
|
882
|
+
const sortedItems = sort({
|
|
961
883
|
model,
|
|
962
884
|
plugins,
|
|
963
885
|
items: filteredItems,
|
|
964
886
|
sort: sortBy,
|
|
965
887
|
fields: modelFields
|
|
966
888
|
});
|
|
967
|
-
const start = parseInt(
|
|
889
|
+
const start = parseInt(decodeCursor(after) || "0") || 0;
|
|
968
890
|
const hasMoreItems = totalCount > start + limit;
|
|
969
891
|
const end = limit > totalCount + start + limit ? undefined : start + limit;
|
|
970
892
|
const slicedItems = sortedItems.slice(start, end);
|
|
@@ -972,12 +894,12 @@ const createEntriesStorageOperations = params => {
|
|
|
972
894
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
973
895
|
* Number is simply encoded.
|
|
974
896
|
*/
|
|
975
|
-
const cursor =
|
|
897
|
+
const cursor = encodeCursor(`${start + limit}`);
|
|
976
898
|
return {
|
|
977
899
|
hasMoreItems,
|
|
978
900
|
totalCount,
|
|
979
901
|
cursor,
|
|
980
|
-
items:
|
|
902
|
+
items: slicedItems
|
|
981
903
|
};
|
|
982
904
|
};
|
|
983
905
|
const get = async (initialModel, params) => {
|
|
@@ -996,18 +918,13 @@ const createEntriesStorageOperations = params => {
|
|
|
996
918
|
storageEntry: initialStorageEntry
|
|
997
919
|
} = params;
|
|
998
920
|
const model = getStorageOperationsModel(initialModel);
|
|
999
|
-
const partitionKey = (0, _keys.createPartitionKey)({
|
|
1000
|
-
id: entry.id,
|
|
1001
|
-
locale: model.locale,
|
|
1002
|
-
tenant: model.tenant
|
|
1003
|
-
});
|
|
1004
921
|
|
|
1005
922
|
/**
|
|
1006
923
|
* We need the latest and published entries to see if something needs to be updated alongside the publishing one.
|
|
1007
924
|
*/
|
|
1008
925
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
1009
926
|
if (!initialLatestStorageEntry) {
|
|
1010
|
-
throw new
|
|
927
|
+
throw new WebinyError(`Could not publish entry. Could not load latest ("L") record.`, "PUBLISH_ERROR", {
|
|
1011
928
|
entry
|
|
1012
929
|
});
|
|
1013
930
|
}
|
|
@@ -1018,22 +935,17 @@ const createEntriesStorageOperations = params => {
|
|
|
1018
935
|
});
|
|
1019
936
|
|
|
1020
937
|
// 1. Update REV# and P records with new data.
|
|
1021
|
-
const entityBatch =
|
|
1022
|
-
entity,
|
|
938
|
+
const entityBatch = entity.createEntityWriter({
|
|
1023
939
|
put: [{
|
|
1024
|
-
...storageEntry,
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1029
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
940
|
+
...createEntryRevisionKeys(storageEntry),
|
|
941
|
+
data: {
|
|
942
|
+
...storageEntry
|
|
943
|
+
}
|
|
1030
944
|
}, {
|
|
1031
|
-
...storageEntry,
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
1036
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
945
|
+
...createEntryPublishedKeys(storageEntry),
|
|
946
|
+
data: {
|
|
947
|
+
...storageEntry
|
|
948
|
+
}
|
|
1037
949
|
}]
|
|
1038
950
|
});
|
|
1039
951
|
|
|
@@ -1044,12 +956,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1044
956
|
if (publishingLatestRevision) {
|
|
1045
957
|
// 2.1 If we're publishing the latest revision, we first need to update the L record.
|
|
1046
958
|
entityBatch.put({
|
|
1047
|
-
...storageEntry,
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1052
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
959
|
+
...createEntryLatestKeys(storageEntry),
|
|
960
|
+
data: {
|
|
961
|
+
...storageEntry
|
|
962
|
+
}
|
|
1053
963
|
});
|
|
1054
964
|
|
|
1055
965
|
// 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.
|
|
@@ -1059,20 +969,18 @@ const createEntriesStorageOperations = params => {
|
|
|
1059
969
|
model
|
|
1060
970
|
});
|
|
1061
971
|
entityBatch.put({
|
|
1062
|
-
...publishedStorageEntry,
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1068
|
-
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
972
|
+
...createEntryRevisionKeys(publishedStorageEntry),
|
|
973
|
+
data: {
|
|
974
|
+
...publishedStorageEntry,
|
|
975
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
976
|
+
}
|
|
1069
977
|
});
|
|
1070
978
|
}
|
|
1071
979
|
} else {
|
|
1072
980
|
// 2.3 If the published revision is not the latest one, the situation is a bit
|
|
1073
981
|
// more complex. We first need to update the L and REV# records with the new
|
|
1074
982
|
// values of *only entry-level* meta fields.
|
|
1075
|
-
const updatedEntryLevelMetaFields =
|
|
983
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
1076
984
|
const latestStorageEntry = convertToStorageEntry({
|
|
1077
985
|
storageEntry: initialLatestStorageEntry,
|
|
1078
986
|
model
|
|
@@ -1081,8 +989,8 @@ const createEntriesStorageOperations = params => {
|
|
|
1081
989
|
// 2.3.1 Update L record. Apart from updating the entry-level meta fields, we also need
|
|
1082
990
|
// to change the status from "published" to "unpublished" (if the status is set to "published").
|
|
1083
991
|
let latestRevisionStatus = latestStorageEntry.status;
|
|
1084
|
-
if (latestRevisionStatus ===
|
|
1085
|
-
latestRevisionStatus =
|
|
992
|
+
if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {
|
|
993
|
+
latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
1086
994
|
}
|
|
1087
995
|
const latestStorageEntryFields = {
|
|
1088
996
|
...latestStorageEntry,
|
|
@@ -1090,22 +998,18 @@ const createEntriesStorageOperations = params => {
|
|
|
1090
998
|
status: latestRevisionStatus
|
|
1091
999
|
};
|
|
1092
1000
|
entityBatch.put({
|
|
1093
|
-
...latestStorageEntryFields,
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1098
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1001
|
+
...createEntryLatestKeys(latestStorageEntryFields),
|
|
1002
|
+
data: {
|
|
1003
|
+
...latestStorageEntryFields
|
|
1004
|
+
}
|
|
1099
1005
|
});
|
|
1100
1006
|
|
|
1101
1007
|
// 2.3.2 Update REV# record.
|
|
1102
1008
|
entityBatch.put({
|
|
1103
|
-
...latestStorageEntryFields,
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1108
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1009
|
+
...createEntryRevisionKeys(latestStorageEntryFields),
|
|
1010
|
+
data: {
|
|
1011
|
+
...latestStorageEntryFields
|
|
1012
|
+
}
|
|
1109
1013
|
});
|
|
1110
1014
|
|
|
1111
1015
|
// 2.3.3 Finally, if we got a published entry, but it wasn't the latest one, we need to take
|
|
@@ -1117,13 +1021,11 @@ const createEntriesStorageOperations = params => {
|
|
|
1117
1021
|
model
|
|
1118
1022
|
});
|
|
1119
1023
|
entityBatch.put({
|
|
1120
|
-
...publishedStorageEntry,
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1126
|
-
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
1024
|
+
...createEntryRevisionKeys(publishedStorageEntry),
|
|
1025
|
+
data: {
|
|
1026
|
+
...publishedStorageEntry,
|
|
1027
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
1028
|
+
}
|
|
1127
1029
|
});
|
|
1128
1030
|
}
|
|
1129
1031
|
}
|
|
@@ -1134,7 +1036,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1134
1036
|
});
|
|
1135
1037
|
return initialStorageEntry;
|
|
1136
1038
|
} catch (ex) {
|
|
1137
|
-
throw new
|
|
1039
|
+
throw new WebinyError(ex.message || "Could not execute the publishing batch.", ex.code || "PUBLISH_ERROR", {
|
|
1138
1040
|
entry,
|
|
1139
1041
|
latestStorageEntry: initialLatestStorageEntry,
|
|
1140
1042
|
publishedStorageEntry: initialPublishedStorageEntry
|
|
@@ -1147,9 +1049,8 @@ const createEntriesStorageOperations = params => {
|
|
|
1147
1049
|
storageEntry: initialStorageEntry
|
|
1148
1050
|
} = params;
|
|
1149
1051
|
const model = getStorageOperationsModel(initialModel);
|
|
1150
|
-
const partitionKey =
|
|
1052
|
+
const partitionKey = createPartitionKey({
|
|
1151
1053
|
id: entry.id,
|
|
1152
|
-
locale: model.locale,
|
|
1153
1054
|
tenant: model.tenant
|
|
1154
1055
|
});
|
|
1155
1056
|
const storageEntry = convertToStorageEntry({
|
|
@@ -1162,19 +1063,16 @@ const createEntriesStorageOperations = params => {
|
|
|
1162
1063
|
* - update current entry revision with new data
|
|
1163
1064
|
* - update the latest entry status - if entry being unpublished is latest
|
|
1164
1065
|
*/
|
|
1165
|
-
const entityBatch =
|
|
1166
|
-
entity,
|
|
1066
|
+
const entityBatch = entity.createEntityWriter({
|
|
1167
1067
|
delete: [{
|
|
1168
1068
|
PK: partitionKey,
|
|
1169
|
-
SK:
|
|
1069
|
+
SK: createPublishedSortKey()
|
|
1170
1070
|
}],
|
|
1171
1071
|
put: [{
|
|
1172
|
-
...storageEntry,
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1177
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1072
|
+
...createEntryRevisionKeys(storageEntry),
|
|
1073
|
+
data: {
|
|
1074
|
+
...storageEntry
|
|
1075
|
+
}
|
|
1178
1076
|
}]
|
|
1179
1077
|
});
|
|
1180
1078
|
|
|
@@ -1186,12 +1084,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1186
1084
|
const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
1187
1085
|
if (unpublishingLatestRevision) {
|
|
1188
1086
|
entityBatch.put({
|
|
1189
|
-
...storageEntry,
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1194
|
-
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
1087
|
+
...createEntryLatestKeys(storageEntry),
|
|
1088
|
+
data: {
|
|
1089
|
+
...storageEntry
|
|
1090
|
+
}
|
|
1195
1091
|
});
|
|
1196
1092
|
} else {
|
|
1197
1093
|
const latestStorageEntry = convertToStorageEntry({
|
|
@@ -1201,28 +1097,24 @@ const createEntriesStorageOperations = params => {
|
|
|
1201
1097
|
|
|
1202
1098
|
// If the unpublished revision is not the latest one, we still need to
|
|
1203
1099
|
// update the latest record with the new values of entry-level meta fields.
|
|
1204
|
-
const updatedEntryLevelMetaFields =
|
|
1100
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
1205
1101
|
|
|
1206
1102
|
// 1. Update actual revision record.
|
|
1207
1103
|
entityBatch.put({
|
|
1208
|
-
...latestStorageEntry,
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
1214
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1104
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
1105
|
+
data: {
|
|
1106
|
+
...latestStorageEntry,
|
|
1107
|
+
...updatedEntryLevelMetaFields
|
|
1108
|
+
}
|
|
1215
1109
|
});
|
|
1216
1110
|
|
|
1217
1111
|
// 2. Update latest record.
|
|
1218
1112
|
entityBatch.put({
|
|
1219
|
-
...latestStorageEntry,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
1225
|
-
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
1113
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
1114
|
+
data: {
|
|
1115
|
+
...latestStorageEntry,
|
|
1116
|
+
...updatedEntryLevelMetaFields
|
|
1117
|
+
}
|
|
1226
1118
|
});
|
|
1227
1119
|
}
|
|
1228
1120
|
}
|
|
@@ -1233,7 +1125,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1233
1125
|
});
|
|
1234
1126
|
return initialStorageEntry;
|
|
1235
1127
|
} catch (ex) {
|
|
1236
|
-
throw new
|
|
1128
|
+
throw new WebinyError(ex.message || "Could not execute unpublish batch.", ex.code || "UNPUBLISH_ERROR", {
|
|
1237
1129
|
entry,
|
|
1238
1130
|
storageEntry
|
|
1239
1131
|
});
|
|
@@ -1246,7 +1138,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1246
1138
|
} = params;
|
|
1247
1139
|
const field = model.fields.find(f => f.fieldId === fieldId);
|
|
1248
1140
|
if (!field) {
|
|
1249
|
-
throw new
|
|
1141
|
+
throw new WebinyError(`Could not find field with given "fieldId" value.`, "FIELD_NOT_FOUND", {
|
|
1250
1142
|
fieldId
|
|
1251
1143
|
});
|
|
1252
1144
|
}
|
|
@@ -1301,6 +1193,5 @@ const createEntriesStorageOperations = params => {
|
|
|
1301
1193
|
getUniqueFieldValues
|
|
1302
1194
|
};
|
|
1303
1195
|
};
|
|
1304
|
-
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|
|
1305
1196
|
|
|
1306
1197
|
//# sourceMappingURL=index.js.map
|