@webiny/api-headless-cms-ddb 5.26.0-beta.1 → 5.26.1-beta.0
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/operations/entry/index.js +82 -18
- package/operations/entry/index.js.map +1 -1
- package/package.json +10 -10
|
@@ -87,7 +87,13 @@ const createEntriesStorageOperations = params => {
|
|
|
87
87
|
entry,
|
|
88
88
|
storageEntry
|
|
89
89
|
} = args;
|
|
90
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
90
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
91
|
+
id: entry.id,
|
|
92
|
+
locale: model.locale,
|
|
93
|
+
tenant: model.tenant
|
|
94
|
+
});
|
|
95
|
+
const isPublished = entry.status === "published";
|
|
96
|
+
const locked = isPublished ? true : entry.locked;
|
|
91
97
|
/**
|
|
92
98
|
* We need to:
|
|
93
99
|
* - create new main entry item
|
|
@@ -95,18 +101,34 @@ const createEntriesStorageOperations = params => {
|
|
|
95
101
|
*/
|
|
96
102
|
|
|
97
103
|
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
104
|
+
locked,
|
|
98
105
|
PK: partitionKey,
|
|
99
106
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
100
107
|
TYPE: createType(),
|
|
101
108
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
102
109
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
103
110
|
})), entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
111
|
+
locked,
|
|
104
112
|
PK: partitionKey,
|
|
105
113
|
SK: (0, _keys.createLatestSortKey)(),
|
|
106
114
|
TYPE: createLatestType(),
|
|
107
115
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
108
116
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
109
117
|
}))];
|
|
118
|
+
/**
|
|
119
|
+
* We need to create published entry if
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
if (isPublished) {
|
|
123
|
+
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
124
|
+
locked,
|
|
125
|
+
PK: partitionKey,
|
|
126
|
+
SK: (0, _keys.createPublishedSortKey)(),
|
|
127
|
+
TYPE: createLatestType(),
|
|
128
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
129
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
130
|
+
})));
|
|
131
|
+
}
|
|
110
132
|
|
|
111
133
|
try {
|
|
112
134
|
await (0, _batchWrite.batchWriteAll)({
|
|
@@ -129,10 +151,13 @@ const createEntriesStorageOperations = params => {
|
|
|
129
151
|
const createRevisionFrom = async (model, params) => {
|
|
130
152
|
const {
|
|
131
153
|
entry,
|
|
132
|
-
storageEntry
|
|
133
|
-
latestEntry
|
|
154
|
+
storageEntry
|
|
134
155
|
} = params;
|
|
135
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
156
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
157
|
+
id: entry.id,
|
|
158
|
+
locale: model.locale,
|
|
159
|
+
tenant: model.tenant
|
|
160
|
+
});
|
|
136
161
|
/**
|
|
137
162
|
* We need to:
|
|
138
163
|
* - create the main entry item
|
|
@@ -164,7 +189,6 @@ const createEntriesStorageOperations = params => {
|
|
|
164
189
|
} catch (ex) {
|
|
165
190
|
throw new _error.default(ex.message || "Could not create revision from given entry.", ex.code || "CREATE_REVISION_ERROR", {
|
|
166
191
|
error: ex,
|
|
167
|
-
latestEntry,
|
|
168
192
|
entry,
|
|
169
193
|
storageEntry
|
|
170
194
|
});
|
|
@@ -182,7 +206,13 @@ const createEntriesStorageOperations = params => {
|
|
|
182
206
|
entry,
|
|
183
207
|
storageEntry
|
|
184
208
|
} = params;
|
|
185
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
209
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
210
|
+
id: entry.id,
|
|
211
|
+
locale: model.locale,
|
|
212
|
+
tenant: model.tenant
|
|
213
|
+
});
|
|
214
|
+
const isPublished = entry.status === "published";
|
|
215
|
+
const locked = isPublished ? true : entry.locked;
|
|
186
216
|
const items = [];
|
|
187
217
|
/**
|
|
188
218
|
* We need to:
|
|
@@ -191,20 +221,34 @@ const createEntriesStorageOperations = params => {
|
|
|
191
221
|
*/
|
|
192
222
|
|
|
193
223
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
224
|
+
locked,
|
|
194
225
|
PK: partitionKey,
|
|
195
226
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
196
227
|
TYPE: createType(),
|
|
197
228
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
198
229
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
199
230
|
})));
|
|
231
|
+
|
|
232
|
+
if (isPublished) {
|
|
233
|
+
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
234
|
+
locked,
|
|
235
|
+
PK: partitionKey,
|
|
236
|
+
SK: (0, _keys.createPublishedSortKey)(),
|
|
237
|
+
TYPE: createPublishedType(),
|
|
238
|
+
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
239
|
+
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
240
|
+
})));
|
|
241
|
+
}
|
|
200
242
|
/**
|
|
201
243
|
* We need the latest entry to update it as well if neccessary.
|
|
202
244
|
*/
|
|
203
245
|
|
|
246
|
+
|
|
204
247
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
205
248
|
|
|
206
249
|
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
207
250
|
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
251
|
+
locked,
|
|
208
252
|
PK: partitionKey,
|
|
209
253
|
SK: (0, _keys.createLatestSortKey)(),
|
|
210
254
|
TYPE: createLatestType(),
|
|
@@ -237,7 +281,11 @@ const createEntriesStorageOperations = params => {
|
|
|
237
281
|
} = params;
|
|
238
282
|
const queryAllParams = {
|
|
239
283
|
entity,
|
|
240
|
-
partitionKey: (0, _keys.createPartitionKey)(
|
|
284
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
285
|
+
id: entry.id,
|
|
286
|
+
locale: model.locale,
|
|
287
|
+
tenant: model.tenant
|
|
288
|
+
}),
|
|
241
289
|
options: {
|
|
242
290
|
gte: " "
|
|
243
291
|
}
|
|
@@ -283,7 +331,11 @@ const createEntriesStorageOperations = params => {
|
|
|
283
331
|
latestEntry,
|
|
284
332
|
latestStorageEntry
|
|
285
333
|
} = params;
|
|
286
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
334
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
335
|
+
id: entry.id,
|
|
336
|
+
locale: model.locale,
|
|
337
|
+
tenant: model.tenant
|
|
338
|
+
});
|
|
287
339
|
const items = [entity.deleteBatch({
|
|
288
340
|
PK: partitionKey,
|
|
289
341
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
@@ -380,10 +432,6 @@ const createEntriesStorageOperations = params => {
|
|
|
380
432
|
};
|
|
381
433
|
|
|
382
434
|
const getPreviousRevision = async (model, params) => {
|
|
383
|
-
const {
|
|
384
|
-
tenant,
|
|
385
|
-
locale
|
|
386
|
-
} = model;
|
|
387
435
|
const {
|
|
388
436
|
entryId,
|
|
389
437
|
version
|
|
@@ -391,8 +439,8 @@ const createEntriesStorageOperations = params => {
|
|
|
391
439
|
const queryParams = {
|
|
392
440
|
entity,
|
|
393
441
|
partitionKey: (0, _keys.createPartitionKey)({
|
|
394
|
-
tenant,
|
|
395
|
-
locale,
|
|
442
|
+
tenant: model.tenant,
|
|
443
|
+
locale: model.locale,
|
|
396
444
|
id: entryId
|
|
397
445
|
}),
|
|
398
446
|
options: {
|
|
@@ -537,7 +585,11 @@ const createEntriesStorageOperations = params => {
|
|
|
537
585
|
entry,
|
|
538
586
|
storageEntry
|
|
539
587
|
} = params;
|
|
540
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
588
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
589
|
+
id: entry.id,
|
|
590
|
+
locale: model.locale,
|
|
591
|
+
tenant: model.tenant
|
|
592
|
+
});
|
|
541
593
|
/**
|
|
542
594
|
* We need to:
|
|
543
595
|
* - update the existing entry
|
|
@@ -589,7 +641,11 @@ const createEntriesStorageOperations = params => {
|
|
|
589
641
|
entry,
|
|
590
642
|
storageEntry
|
|
591
643
|
} = params;
|
|
592
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
644
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
645
|
+
id: entry.id,
|
|
646
|
+
locale: model.locale,
|
|
647
|
+
tenant: model.tenant
|
|
648
|
+
});
|
|
593
649
|
/**
|
|
594
650
|
* We need to:
|
|
595
651
|
* - update existing entry
|
|
@@ -641,7 +697,11 @@ const createEntriesStorageOperations = params => {
|
|
|
641
697
|
entry,
|
|
642
698
|
storageEntry
|
|
643
699
|
} = params;
|
|
644
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
700
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
701
|
+
id: entry.id,
|
|
702
|
+
locale: model.locale,
|
|
703
|
+
tenant: model.tenant
|
|
704
|
+
});
|
|
645
705
|
/**
|
|
646
706
|
* We need the latest and published entries to see if something needs to be updated along side the publishing one.
|
|
647
707
|
*/
|
|
@@ -714,7 +774,11 @@ const createEntriesStorageOperations = params => {
|
|
|
714
774
|
entry,
|
|
715
775
|
storageEntry
|
|
716
776
|
} = params;
|
|
717
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
777
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
778
|
+
id: entry.id,
|
|
779
|
+
locale: model.locale,
|
|
780
|
+
tenant: model.tenant
|
|
781
|
+
});
|
|
718
782
|
/**
|
|
719
783
|
* We need to:
|
|
720
784
|
* - delete currently published entry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["createType","createLatestType","createPublishedType","createEntriesStorageOperations","params","entity","plugins","dataLoaders","DataLoadersHandler","storageTransformPlugins","byType","StorageTransformPlugin","type","reduce","collection","plugin","fieldType","createStorageTransformCallable","model","field","value","fromStorage","getStoragePlugin","create","args","entry","storageEntry","partitionKey","items","putBatch","PK","SK","TYPE","GSI1_PK","GSI1_SK","table","clearAll","ex","WebinyError","message","code","error","createRevisionFrom","latestEntry","update","push","latestStorageEntry","getLatestRevisionByEntryId","id","deleteEntry","queryAllParams","options","gte","records","map","item","deleteBatch","deleteRevision","publishedStorageEntry","getPublishedRevisionByEntryId","result","ids","shift","getRevisionById","getRevisions","getAllEntryRevisions","getByIds","getLatestByIds","getPublishedByIds","getPreviousRevision","tenant","locale","entryId","version","queryParams","lt","filters","attr","eq","reverse","list","limit","initialLimit","where","initialWhere","after","sort","fields","search","published","index","length","hasMoreItems","totalCount","cursor","modelFields","filteredItems","fullTextSearch","term","sortedItems","start","parseInt","end","undefined","slicedItems","slice","get","requestChanges","requestReview","publish","status","CONTENT_ENTRY_STATUS","UNPUBLISHED","unpublish","delete"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AA0BA;;AACA;;AAQA;;AACA;;AAMA;;AAEA;;AACA;;AACA;;;;;;AAEA,MAAMA,UAAU,GAAG,MAAc;AAC7B,SAAO,WAAP;AACH,CAFD;;AAGA,MAAMC,gBAAgB,GAAG,MAAc;AACnC,SAAQ,GAAED,UAAU,EAAG,IAAvB;AACH,CAFD;;AAGA,MAAME,mBAAmB,GAAG,MAAc;AACtC,SAAQ,GAAEF,UAAU,EAAG,IAAvB;AACH,CAFD;;AAQO,MAAMG,8BAA8B,GACvCC,MAD0C,IAEd;AAC5B,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAA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iBT,KAAjB;AANb,SADJ;AAUH;;AAED,QAAI;AACA,YAAM,+BAAc;AAChBU,QAAAA,KAAK,EAAE9B,MAAM,CAAC8B,KADE;AAEhBP,QAAAA;AAFgB,OAAd,CAAN;AAIArB,MAAAA,WAAW,CAAC6B,QAAZ,CAAqB;AACjBlB,QAAAA;AADiB,OAArB;AAGA,aAAOQ,YAAP;AACH,KATD,CASE,OAAOW,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,oCADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,iBAFT,EAGF;AACIf,QAAAA,KADJ;AAEIC,QAAAA;AAFJ,OAHE,CAAN;AAQH;AACJ,GA9DD;;AAgEA,SAAO;AACHH,IAAAA,MADG;AAEHmB,IAAAA,kBAFG;AAGHE,IAAAA,MAHG;AAIHsE,IAAAA,MAAM,EAAEjE,WAJL;AAKHQ,IAAAA,cALG;AAMHY,IAAAA,mBANG;AAOHD,IAAAA,iBAPG;AAQHD,IAAAA,cARG;AASHD,IAAAA,QATG;AAUHH,IAAAA,eAVG;AAWHJ,IAAAA,6BAXG;AAYHZ,IAAAA,0BAZG;AAaH2D,IAAAA,GAbG;AAcH1C,IAAAA,YAdG;AAeH2C,IAAAA,cAfG;AAgBHC,IAAAA,aAhBG;AAiBHC,IAAAA,OAjBG;AAkBH7B,IAAAA,IAlBG;AAmBHiC,IAAAA;AAnBG,GAAP;AAqBH,CAzzBM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DataLoadersHandler } from \"./dataLoaders\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryStorageOperations,\n CmsEntryStorageOperationsCreateParams,\n CmsEntryStorageOperationsCreateRevisionFromParams,\n CmsEntryStorageOperationsDeleteParams,\n CmsEntryStorageOperationsDeleteRevisionParams,\n CmsEntryStorageOperationsGetByIdsParams,\n CmsEntryStorageOperationsGetLatestByIdsParams,\n CmsEntryStorageOperationsGetLatestRevisionParams,\n CmsEntryStorageOperationsGetParams,\n CmsEntryStorageOperationsGetPreviousRevisionParams,\n CmsEntryStorageOperationsGetPublishedByIdsParams,\n CmsEntryStorageOperationsGetRevisionParams,\n CmsEntryStorageOperationsGetRevisionsParams,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsPublishParams,\n CmsEntryStorageOperationsRequestChangesParams,\n CmsEntryStorageOperationsRequestReviewParams,\n CmsEntryStorageOperationsUnpublishParams,\n CmsEntryStorageOperationsUpdateParams,\n CmsModel,\n CONTENT_ENTRY_STATUS\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { filterItems, buildModelFields, sortEntryItems, FilterItemFromStorage } from \"./utils\";\nimport {\n createGSIPartitionKey,\n createGSISortKey,\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"~/operations/entry/keys\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport {\n queryAll,\n QueryAllParams,\n queryOne,\n QueryOneParams\n} from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { decodeCursor, encodeCursor } from \"@webiny/utils/cursor\";\nimport { zeroPad } from \"@webiny/utils/zeroPad\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst createType = (): string => {\n return \"cms.entry\";\n};\nconst createLatestType = (): string => {\n return `${createType()}.l`;\n};\nconst createPublishedType = (): string => {\n return `${createType()}.p`;\n};\n\nexport interface CreateEntriesStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createEntriesStorageOperations = (\n params: CreateEntriesStorageOperationsParams\n): CmsEntryStorageOperations => {\n const { entity, plugins } = params;\n\n const dataLoaders = new DataLoadersHandler({\n entity\n });\n\n const storageTransformPlugins = plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n .reduce((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n const createStorageTransformCallable = (model: CmsModel): FilterItemFromStorage => {\n return (field, value) => {\n const plugin: StorageTransformPlugin = storageTransformPlugins[field.type];\n if (!plugin) {\n return value;\n }\n return plugin.fromStorage({\n model,\n field,\n value,\n getStoragePlugin(fieldType: string): StorageTransformPlugin {\n return storageTransformPlugins[fieldType] || storageTransformPlugins[\"*\"];\n },\n plugins\n });\n };\n };\n\n const create = async (model: CmsModel, args: CmsEntryStorageOperationsCreateParams) => {\n const { entry, storageEntry } = args;\n\n const partitionKey = createPartitionKey(entry);\n /**\n * We need to:\n * - create new main entry item\n * - create new or update latest entry item\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert data into the DynamoDB.\",\n ex.code || \"CREATE_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n\n return storageEntry;\n };\n\n const createRevisionFrom = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsCreateRevisionFromParams\n ) => {\n const { entry, storageEntry, latestEntry } = params;\n\n const partitionKey = createPartitionKey(entry);\n /**\n * We need to:\n * - create the main entry item\n * - update the last entry item to a current one\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create revision from given entry.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n latestEntry,\n entry,\n storageEntry\n }\n );\n }\n /**\n * There are no modifications on the entry created so just return the data.\n */\n return storageEntry;\n };\n\n const update = async (model: CmsModel, params: CmsEntryStorageOperationsUpdateParams) => {\n const { entry, storageEntry } = params;\n const partitionKey = createPartitionKey(entry);\n\n const items = [];\n /**\n * We need to:\n * - update the current entry\n * - update the latest entry if the current entry is the latest one\n */\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n\n /**\n * We need the latest entry to update it as well if neccessary.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return storageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry.\",\n ex.code || \"UPDATE_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry\n }\n );\n }\n };\n\n const deleteEntry = async (model: CmsModel, params: CmsEntryStorageOperationsDeleteParams) => {\n const { entry } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(entry),\n options: {\n gte: \" \"\n }\n };\n\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all records.\",\n ex.code || \"LOAD_ALL_RECORDS_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n const items = records.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the entry.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n entry\n }\n );\n }\n };\n\n const deleteRevision = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsDeleteRevisionParams\n ) => {\n const { entry, latestEntry, latestStorageEntry } = params;\n const partitionKey = createPartitionKey(entry);\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createRevisionSortKey(entry)\n })\n ];\n\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n /**\n * If revision we are deleting is the published one as well, we need to delete those records as well.\n */\n if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n if (latestStorageEntry) {\n items.push(\n entity.putBatch({\n ...latestStorageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(latestStorageEntry)\n })\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, {\n error: ex,\n entry,\n latestEntry\n });\n }\n };\n\n const getLatestRevisionByEntryId = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const result = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [params.id]\n });\n return result.shift() || null;\n };\n const getPublishedRevisionByEntryId = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const result = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [params.id]\n });\n return result.shift() || null;\n };\n\n const getRevisionById = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) => {\n const result = await dataLoaders.getRevisionById({\n model,\n ids: [params.id]\n });\n return result.shift() || null;\n };\n\n const getRevisions = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) => {\n return await dataLoaders.getAllEntryRevisions({\n model,\n ids: [params.id]\n });\n };\n\n const getByIds = async (model: CmsModel, params: CmsEntryStorageOperationsGetByIdsParams) => {\n return dataLoaders.getRevisionById({\n model,\n ids: params.ids\n });\n };\n\n const getLatestByIds = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestByIdsParams\n ) => {\n return dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: params.ids\n });\n };\n\n const getPublishedByIds = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetPublishedByIdsParams\n ) => {\n return dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: params.ids\n });\n };\n\n const getPreviousRevision = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) => {\n const { tenant, locale } = model;\n const { entryId, version } = params;\n const queryParams: QueryOneParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id: entryId\n }),\n options: {\n lt: `REV#${zeroPad(version)}`,\n /**\n * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.\n */\n filters: [\n {\n attr: \"TYPE\",\n eq: createType()\n },\n {\n attr: \"version\",\n lt: version\n }\n ],\n reverse: true\n }\n };\n\n try {\n const result = await queryOne<CmsEntry>(queryParams);\n\n return cleanupItem(entity, result);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey: queryParams.partitionKey,\n options: queryParams.options,\n model\n }\n );\n }\n };\n\n const list = async (model: CmsModel, params: CmsEntryStorageOperationsListParams) => {\n const {\n limit: initialLimit = 10,\n where: initialWhere,\n after,\n sort,\n fields,\n search\n } = params;\n const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;\n\n const type = initialWhere.published ? \"P\" : \"L\";\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createGSIPartitionKey(model, type),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(ex.message, \"QUERY_ENTRIES_ERROR\", {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n });\n }\n if (records.length === 0) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n delete where[\"published\"];\n delete where[\"latest\"];\n /**\n * We need a object containing field, transformers and paths.\n * Just build it here and pass on into other methods that require it to avoid mapping multiple times.\n */\n const modelFields = buildModelFields({\n plugins,\n model\n });\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredItems = await filterItems({\n items: records,\n where,\n plugins,\n fields: modelFields,\n fromStorage: createStorageTransformCallable(model),\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const totalCount = filteredItems.length;\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedItems = sortEntryItems({\n items: filteredItems,\n sort,\n fields: modelFields\n });\n\n const start = parseInt(decodeCursor(after) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const slicedItems = sortedItems.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = totalCount > start + limit ? encodeCursor(`${start + limit}`) : null;\n return {\n hasMoreItems,\n totalCount,\n cursor,\n items: cleanupItems(entity, slicedItems)\n };\n };\n\n const get = async (model: CmsModel, params: CmsEntryStorageOperationsGetParams) => {\n const { items } = await list(model, {\n ...params,\n limit: 1\n });\n return items.shift() || null;\n };\n\n const requestChanges = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsRequestChangesParams\n ) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey(entry);\n\n /**\n * We need to:\n * - update the existing entry\n * - update latest version - if existing entry is the latest version\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n TYPE: createType(),\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the request changes one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the request changes batch.\",\n ex.code || \"REQUEST_CHANGES_ERROR\",\n {\n entry\n }\n );\n }\n return entry;\n };\n\n const requestReview = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsRequestReviewParams\n ) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey(entry);\n /**\n * We need to:\n * - update existing entry\n * - update latest entry - if existing entry is the latest entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n TYPE: createType(),\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the request review one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return entry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute request review batch.\",\n ex.code || \"REQUEST_REVIEW_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n const publish = async (model: CmsModel, params: CmsEntryStorageOperationsPublishParams) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey(entry);\n\n /**\n * We need the latest and published entries to see if something needs to be updated along side the publishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n /**\n * We need to update:\n * - current entry revision sort key\n * - published sort key\n * - latest sort key - if entry updated is actually latest\n * - previous published entry to unpublished status - if any previously published entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n if (publishedStorageEntry && publishedStorageEntry.id !== entry.id) {\n items.push(\n entity.putBatch({\n ...publishedStorageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(publishedStorageEntry),\n TYPE: createType(),\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED,\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(publishedStorageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return entry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the publishing batch.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n entry,\n latestStorageEntry,\n publishedStorageEntry\n }\n );\n }\n };\n\n const unpublish = async (model: CmsModel, params: CmsEntryStorageOperationsUnpublishParams) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey(entry);\n /**\n * We need to:\n * - delete currently published entry\n * - update current entry revision with new data\n * - update latest entry status - if entry being unpublished is latest\n */\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the unpublishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return storageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute unpublish batch.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n return {\n create,\n createRevisionFrom,\n update,\n delete: deleteEntry,\n deleteRevision,\n getPreviousRevision,\n getPublishedByIds,\n getLatestByIds,\n getByIds,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId,\n get,\n getRevisions,\n requestChanges,\n requestReview,\n publish,\n list,\n unpublish\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["createType","createLatestType","createPublishedType","createEntriesStorageOperations","params","entity","plugins","dataLoaders","DataLoadersHandler","storageTransformPlugins","byType","StorageTransformPlugin","type","reduce","collection","plugin","fieldType","createStorageTransformCallable","model","field","value","fromStorage","getStoragePlugin","create","args","entry","storageEntry","partitionKey","id","locale","tenant","isPublished","status","locked","items","putBatch","PK","SK","TYPE","GSI1_PK","GSI1_SK","push","table","clearAll","ex","WebinyError","message","code","error","createRevisionFrom","update","latestStorageEntry","getLatestRevisionByEntryId","deleteEntry","queryAllParams","options","gte","records","map","item","deleteBatch","deleteRevision","latestEntry","publishedStorageEntry","getPublishedRevisionByEntryId","result","ids","shift","getRevisionById","getRevisions","getAllEntryRevisions","getByIds","getLatestByIds","getPublishedByIds","getPreviousRevision","entryId","version","queryParams","lt","filters","attr","eq","reverse","list","limit","initialLimit","where","initialWhere","after","sort","fields","search","published","index","length","hasMoreItems","totalCount","cursor","modelFields","filteredItems","fullTextSearch","term","sortedItems","start","parseInt","end","undefined","slicedItems","slice","get","requestChanges","requestReview","publish","CONTENT_ENTRY_STATUS","UNPUBLISHED","unpublish","delete"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AA0BA;;AACA;;AAQA;;AACA;;AAMA;;AAEA;;A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AET,YAFR;AAGIU,QAAAA,EAAE,EAAE,gCAHR;AAIIC,QAAAA,IAAI,EAAErC,gBAAgB,EAJ1B;AAKIsC,QAAAA,OAAO,EAAE,iCAAsBrB,KAAtB,EAA6B,GAA7B,CALb;AAMIsB,QAAAA,OAAO,EAAE,4BAAiBf,KAAjB;AANb,SADJ;AAUH;;AAED,QAAI;AACA,YAAM,+BAAc;AAChBiB,QAAAA,KAAK,EAAErC,MAAM,CAACqC,KADE;AAEhBR,QAAAA;AAFgB,OAAd,CAAN;AAIA3B,MAAAA,WAAW,CAACoC,QAAZ,CAAqB;AACjBzB,QAAAA;AADiB,OAArB;AAGA,aAAOQ,YAAP;AACH,KATD,CASE,OAAOkB,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,oCADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,iBAFT,EAGF;AACItB,QAAAA,KADJ;AAEIC,QAAAA;AAFJ,OAHE,CAAN;AAQH;AACJ,GAlED;;AAoEA,SAAO;AACHH,IAAAA,MADG;AAEH0B,IAAAA,kBAFG;AAGHC,IAAAA,MAHG;AAIHkE,IAAAA,MAAM,EAAE/D,WAJL;AAKHQ,IAAAA,cALG;AAMHa,IAAAA,mBANG;AAOHD,IAAAA,iBAPG;AAQHD,IAAAA,cARG;AASHD,IAAAA,QATG;AAUHH,IAAAA,eAVG;AAWHJ,IAAAA,6BAXG;AAYHZ,IAAAA,0BAZG;AAaHyD,IAAAA,GAbG;AAcHxC,IAAAA,YAdG;AAeHyC,IAAAA,cAfG;AAgBHC,IAAAA,aAhBG;AAiBHC,IAAAA,OAjBG;AAkBH7B,IAAAA,IAlBG;AAmBHgC,IAAAA;AAnBG,GAAP;AAqBH,CAr4BM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DataLoadersHandler } from \"./dataLoaders\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryStorageOperations,\n CmsEntryStorageOperationsCreateParams,\n CmsEntryStorageOperationsCreateRevisionFromParams,\n CmsEntryStorageOperationsDeleteParams,\n CmsEntryStorageOperationsDeleteRevisionParams,\n CmsEntryStorageOperationsGetByIdsParams,\n CmsEntryStorageOperationsGetLatestByIdsParams,\n CmsEntryStorageOperationsGetLatestRevisionParams,\n CmsEntryStorageOperationsGetParams,\n CmsEntryStorageOperationsGetPreviousRevisionParams,\n CmsEntryStorageOperationsGetPublishedByIdsParams,\n CmsEntryStorageOperationsGetRevisionParams,\n CmsEntryStorageOperationsGetRevisionsParams,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsPublishParams,\n CmsEntryStorageOperationsRequestChangesParams,\n CmsEntryStorageOperationsRequestReviewParams,\n CmsEntryStorageOperationsUnpublishParams,\n CmsEntryStorageOperationsUpdateParams,\n CmsModel,\n CONTENT_ENTRY_STATUS\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { filterItems, buildModelFields, sortEntryItems, FilterItemFromStorage } from \"./utils\";\nimport {\n createGSIPartitionKey,\n createGSISortKey,\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"~/operations/entry/keys\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport {\n queryAll,\n QueryAllParams,\n queryOne,\n QueryOneParams\n} from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { decodeCursor, encodeCursor } from \"@webiny/utils/cursor\";\nimport { zeroPad } from \"@webiny/utils/zeroPad\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst createType = (): string => {\n return \"cms.entry\";\n};\nconst createLatestType = (): string => {\n return `${createType()}.l`;\n};\nconst createPublishedType = (): string => {\n return `${createType()}.p`;\n};\n\nexport interface CreateEntriesStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createEntriesStorageOperations = (\n params: CreateEntriesStorageOperationsParams\n): CmsEntryStorageOperations => {\n const { entity, plugins } = params;\n\n const dataLoaders = new DataLoadersHandler({\n entity\n });\n\n const storageTransformPlugins = plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n .reduce((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n const createStorageTransformCallable = (model: CmsModel): FilterItemFromStorage => {\n return (field, value) => {\n const plugin: StorageTransformPlugin = storageTransformPlugins[field.type];\n if (!plugin) {\n return value;\n }\n return plugin.fromStorage({\n model,\n field,\n value,\n getStoragePlugin(fieldType: string): StorageTransformPlugin {\n return storageTransformPlugins[fieldType] || storageTransformPlugins[\"*\"];\n },\n plugins\n });\n };\n };\n\n const create = async (model: CmsModel, args: CmsEntryStorageOperationsCreateParams) => {\n const { entry, storageEntry } = args;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n\n const locked = isPublished ? true : entry.locked;\n /**\n * We need to:\n * - create new main entry item\n * - create new or update latest entry item\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n\n /**\n * We need to create published entry if\n */\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert data into the DynamoDB.\",\n ex.code || \"CREATE_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n\n return storageEntry;\n };\n\n const createRevisionFrom = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsCreateRevisionFromParams\n ) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n /**\n * We need to:\n * - create the main entry item\n * - update the last entry item to a current one\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create revision from given entry.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n /**\n * There are no modifications on the entry created so just return the data.\n */\n return storageEntry;\n };\n\n const update = async (model: CmsModel, params: CmsEntryStorageOperationsUpdateParams) => {\n const { entry, storageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const items = [];\n /**\n * We need to:\n * - update the current entry\n * - update the latest entry if the current entry is the latest one\n */\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n /**\n * We need the latest entry to update it as well if neccessary.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return storageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry.\",\n ex.code || \"UPDATE_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry\n }\n );\n }\n };\n\n const deleteEntry = async (model: CmsModel, params: CmsEntryStorageOperationsDeleteParams) => {\n const { entry } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n }),\n options: {\n gte: \" \"\n }\n };\n\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all records.\",\n ex.code || \"LOAD_ALL_RECORDS_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n const items = records.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the entry.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n entry\n }\n );\n }\n };\n\n const deleteRevision = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsDeleteRevisionParams\n ) => {\n const { entry, latestEntry, latestStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createRevisionSortKey(entry)\n })\n ];\n\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n /**\n * If revision we are deleting is the published one as well, we need to delete those records as well.\n */\n if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n if (latestStorageEntry) {\n items.push(\n entity.putBatch({\n ...latestStorageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(latestStorageEntry)\n })\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, {\n error: ex,\n entry,\n latestEntry\n });\n }\n };\n\n const getLatestRevisionByEntryId = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const result = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [params.id]\n });\n return result.shift() || null;\n };\n const getPublishedRevisionByEntryId = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const result = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [params.id]\n });\n return result.shift() || null;\n };\n\n const getRevisionById = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) => {\n const result = await dataLoaders.getRevisionById({\n model,\n ids: [params.id]\n });\n return result.shift() || null;\n };\n\n const getRevisions = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) => {\n return await dataLoaders.getAllEntryRevisions({\n model,\n ids: [params.id]\n });\n };\n\n const getByIds = async (model: CmsModel, params: CmsEntryStorageOperationsGetByIdsParams) => {\n return dataLoaders.getRevisionById({\n model,\n ids: params.ids\n });\n };\n\n const getLatestByIds = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestByIdsParams\n ) => {\n return dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: params.ids\n });\n };\n\n const getPublishedByIds = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetPublishedByIdsParams\n ) => {\n return dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: params.ids\n });\n };\n\n const getPreviousRevision = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) => {\n const { entryId, version } = params;\n const queryParams: QueryOneParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant: model.tenant,\n locale: model.locale,\n id: entryId\n }),\n options: {\n lt: `REV#${zeroPad(version)}`,\n /**\n * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.\n */\n filters: [\n {\n attr: \"TYPE\",\n eq: createType()\n },\n {\n attr: \"version\",\n lt: version\n }\n ],\n reverse: true\n }\n };\n\n try {\n const result = await queryOne<CmsEntry>(queryParams);\n\n return cleanupItem(entity, result);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey: queryParams.partitionKey,\n options: queryParams.options,\n model\n }\n );\n }\n };\n\n const list = async (model: CmsModel, params: CmsEntryStorageOperationsListParams) => {\n const {\n limit: initialLimit = 10,\n where: initialWhere,\n after,\n sort,\n fields,\n search\n } = params;\n const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;\n\n const type = initialWhere.published ? \"P\" : \"L\";\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createGSIPartitionKey(model, type),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(ex.message, \"QUERY_ENTRIES_ERROR\", {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n });\n }\n if (records.length === 0) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n delete where[\"published\"];\n delete where[\"latest\"];\n /**\n * We need a object containing field, transformers and paths.\n * Just build it here and pass on into other methods that require it to avoid mapping multiple times.\n */\n const modelFields = buildModelFields({\n plugins,\n model\n });\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredItems = await filterItems({\n items: records,\n where,\n plugins,\n fields: modelFields,\n fromStorage: createStorageTransformCallable(model),\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const totalCount = filteredItems.length;\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedItems = sortEntryItems({\n items: filteredItems,\n sort,\n fields: modelFields\n });\n\n const start = parseInt(decodeCursor(after) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const slicedItems = sortedItems.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = totalCount > start + limit ? encodeCursor(`${start + limit}`) : null;\n return {\n hasMoreItems,\n totalCount,\n cursor,\n items: cleanupItems(entity, slicedItems)\n };\n };\n\n const get = async (model: CmsModel, params: CmsEntryStorageOperationsGetParams) => {\n const { items } = await list(model, {\n ...params,\n limit: 1\n });\n return items.shift() || null;\n };\n\n const requestChanges = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsRequestChangesParams\n ) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n /**\n * We need to:\n * - update the existing entry\n * - update latest version - if existing entry is the latest version\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n TYPE: createType(),\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the request changes one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the request changes batch.\",\n ex.code || \"REQUEST_CHANGES_ERROR\",\n {\n entry\n }\n );\n }\n return entry;\n };\n\n const requestReview = async (\n model: CmsModel,\n params: CmsEntryStorageOperationsRequestReviewParams\n ) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n /**\n * We need to:\n * - update existing entry\n * - update latest entry - if existing entry is the latest entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n TYPE: createType(),\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the request review one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return entry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute request review batch.\",\n ex.code || \"REQUEST_REVIEW_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n const publish = async (model: CmsModel, params: CmsEntryStorageOperationsPublishParams) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n /**\n * We need the latest and published entries to see if something needs to be updated along side the publishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n /**\n * We need to update:\n * - current entry revision sort key\n * - published sort key\n * - latest sort key - if entry updated is actually latest\n * - previous published entry to unpublished status - if any previously published entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n if (publishedStorageEntry && publishedStorageEntry.id !== entry.id) {\n items.push(\n entity.putBatch({\n ...publishedStorageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(publishedStorageEntry),\n TYPE: createType(),\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED,\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(publishedStorageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return entry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the publishing batch.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n entry,\n latestStorageEntry,\n publishedStorageEntry\n }\n );\n }\n };\n\n const unpublish = async (model: CmsModel, params: CmsEntryStorageOperationsUnpublishParams) => {\n const { entry, storageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n /**\n * We need to:\n * - delete currently published entry\n * - update current entry revision with new data\n * - update latest entry status - if entry being unpublished is latest\n */\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the unpublishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return storageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute unpublish batch.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n return {\n create,\n createRevisionFrom,\n update,\n delete: deleteEntry,\n deleteRevision,\n getPreviousRevision,\n getPublishedByIds,\n getLatestByIds,\n getByIds,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId,\n get,\n getRevisions,\n requestChanges,\n requestReview,\n publish,\n list,\n unpublish\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-ddb",
|
|
3
|
-
"version": "5.26.
|
|
3
|
+
"version": "5.26.1-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-headless-cms",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "7.16.7",
|
|
25
|
-
"@webiny/api-headless-cms": "5.26.
|
|
26
|
-
"@webiny/db-dynamodb": "5.26.
|
|
27
|
-
"@webiny/error": "5.26.
|
|
28
|
-
"@webiny/handler-db": "5.26.
|
|
29
|
-
"@webiny/utils": "5.26.
|
|
25
|
+
"@webiny/api-headless-cms": "5.26.1-beta.0",
|
|
26
|
+
"@webiny/db-dynamodb": "5.26.1-beta.0",
|
|
27
|
+
"@webiny/error": "5.26.1-beta.0",
|
|
28
|
+
"@webiny/handler-db": "5.26.1-beta.0",
|
|
29
|
+
"@webiny/utils": "5.26.1-beta.0",
|
|
30
30
|
"aws-sdk": "2.1066.0",
|
|
31
31
|
"dataloader": "2.0.0",
|
|
32
32
|
"dot-prop": "5.3.0",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@babel/preset-env": "^7.16.4",
|
|
41
41
|
"@babel/preset-flow": "^7.16.0",
|
|
42
42
|
"@types/jsonpack": "^1.1.0",
|
|
43
|
-
"@webiny/cli": "^5.26.
|
|
44
|
-
"@webiny/plugins": "^5.26.
|
|
45
|
-
"@webiny/project-utils": "^5.26.
|
|
43
|
+
"@webiny/cli": "^5.26.1-beta.0",
|
|
44
|
+
"@webiny/plugins": "^5.26.1-beta.0",
|
|
45
|
+
"@webiny/project-utils": "^5.26.1-beta.0",
|
|
46
46
|
"jest": "^26.6.3",
|
|
47
47
|
"jest-dynalite": "^3.2.0",
|
|
48
48
|
"jest-environment-node": "^26.6.2",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"build": "yarn webiny run build",
|
|
58
58
|
"watch": "yarn webiny run watch"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "d85df0d292bfd4ee2422cbb59de18ee8899df076"
|
|
61
61
|
}
|