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