@webiny/api-headless-cms-ddb 6.4.5 → 6.6.0-alpha.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/abstractions/CmsDdbDataLoaders.d.ts +5 -0
- package/abstractions/CmsDdbDataLoaders.js +5 -0
- package/abstractions/CmsDdbDataLoaders.js.map +1 -0
- package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
- package/abstractions/CmsDdbEntryEntity.js +5 -0
- package/abstractions/CmsDdbEntryEntity.js.map +1 -0
- package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
- package/abstractions/CmsDdbGroupEntity.js +5 -0
- package/abstractions/CmsDdbGroupEntity.js.map +1 -0
- package/abstractions/CmsDdbModelEntity.d.ts +5 -0
- package/abstractions/CmsDdbModelEntity.js +5 -0
- package/abstractions/CmsDdbModelEntity.js.map +1 -0
- package/abstractions/CmsDdbTable.d.ts +5 -0
- package/abstractions/CmsDdbTable.js +5 -0
- package/abstractions/CmsDdbTable.js.map +1 -0
- package/index.d.ts +13 -2
- package/index.js +31 -71
- package/index.js.map +1 -1
- package/operations/entry/DdbCreateEntry.d.ts +16 -0
- package/operations/entry/DdbCreateEntry.js +77 -0
- package/operations/entry/DdbCreateEntry.js.map +1 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
- package/operations/entry/DdbDeleteEntry.d.ts +16 -0
- package/operations/entry/DdbDeleteEntry.js +65 -0
- package/operations/entry/DdbDeleteEntry.js.map +1 -0
- package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
- package/operations/entry/DdbDeleteEntryRevision.js +91 -0
- package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
- package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
- package/operations/entry/DdbDeleteMultipleEntries.js +56 -0
- package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
- package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetEntriesByIds.js +31 -0
- package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetEntry.d.ts +14 -0
- package/operations/entry/DdbGetEntry.js +27 -0
- package/operations/entry/DdbGetEntry.js.map +1 -0
- package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
- package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
- package/operations/entry/DdbGetPreviousRevision.js +53 -0
- package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/DdbGetRevisionById.d.ts +14 -0
- package/operations/entry/DdbGetRevisionById.js +34 -0
- package/operations/entry/DdbGetRevisionById.js.map +1 -0
- package/operations/entry/DdbGetRevisions.d.ts +14 -0
- package/operations/entry/DdbGetRevisions.js +33 -0
- package/operations/entry/DdbGetRevisions.js.map +1 -0
- package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
- package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
- package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
- package/operations/entry/DdbListEntries.d.ts +28 -0
- package/operations/entry/DdbListEntries.js +124 -0
- package/operations/entry/DdbListEntries.js.map +1 -0
- package/operations/entry/DdbMoveEntry.d.ts +14 -0
- package/operations/entry/DdbMoveEntry.js +57 -0
- package/operations/entry/DdbMoveEntry.js.map +1 -0
- package/operations/entry/DdbMoveToBin.d.ts +16 -0
- package/operations/entry/DdbMoveToBin.js +77 -0
- package/operations/entry/DdbMoveToBin.js.map +1 -0
- package/operations/entry/DdbPublishEntry.d.ts +18 -0
- package/operations/entry/DdbPublishEntry.js +161 -0
- package/operations/entry/DdbPublishEntry.js.map +1 -0
- package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
- package/operations/entry/DdbRestoreFromBin.js +78 -0
- package/operations/entry/DdbRestoreFromBin.js.map +1 -0
- package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
- package/operations/entry/DdbUnpublishEntry.js +112 -0
- package/operations/entry/DdbUnpublishEntry.js.map +1 -0
- package/operations/entry/DdbUpdateEntry.d.ts +17 -0
- package/operations/entry/DdbUpdateEntry.js +110 -0
- package/operations/entry/DdbUpdateEntry.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +7 -6
- package/operations/entry/dataLoaders.js +11 -3
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/feature.d.ts +4 -0
- package/operations/entry/feature.js +55 -0
- package/operations/entry/feature.js.map +1 -0
- package/operations/entry/storageEntryUtils.d.ts +8 -0
- package/operations/entry/storageEntryUtils.js +25 -0
- package/operations/entry/storageEntryUtils.js.map +1 -0
- package/operations/group/DdbCreateGroup.d.ts +12 -0
- package/operations/group/DdbCreateGroup.js +35 -0
- package/operations/group/DdbCreateGroup.js.map +1 -0
- package/operations/group/DdbDeleteGroup.d.ts +12 -0
- package/operations/group/DdbDeleteGroup.js +31 -0
- package/operations/group/DdbDeleteGroup.js.map +1 -0
- package/operations/group/DdbGetGroup.d.ts +12 -0
- package/operations/group/DdbGetGroup.js +31 -0
- package/operations/group/DdbGetGroup.js.map +1 -0
- package/operations/group/DdbListGroups.d.ts +14 -0
- package/operations/group/DdbListGroups.js +52 -0
- package/operations/group/DdbListGroups.js.map +1 -0
- package/operations/group/DdbUpdateGroup.d.ts +12 -0
- package/operations/group/DdbUpdateGroup.js +35 -0
- package/operations/group/DdbUpdateGroup.js.map +1 -0
- package/operations/group/feature.d.ts +4 -0
- package/operations/group/feature.js +19 -0
- package/operations/group/feature.js.map +1 -0
- package/operations/group/keys.d.ts +15 -0
- package/operations/group/keys.js +17 -0
- package/operations/group/keys.js.map +1 -0
- package/operations/model/DdbCreateModel.d.ts +12 -0
- package/operations/model/DdbCreateModel.js +37 -0
- package/operations/model/DdbCreateModel.js.map +1 -0
- package/operations/model/DdbDeleteModel.d.ts +12 -0
- package/operations/model/DdbDeleteModel.js +31 -0
- package/operations/model/DdbDeleteModel.js.map +1 -0
- package/operations/model/DdbGetModel.d.ts +12 -0
- package/operations/model/DdbGetModel.js +30 -0
- package/operations/model/DdbGetModel.js.map +1 -0
- package/operations/model/DdbListModels.d.ts +12 -0
- package/operations/model/DdbListModels.js +36 -0
- package/operations/model/DdbListModels.js.map +1 -0
- package/operations/model/DdbUpdateModel.d.ts +12 -0
- package/operations/model/DdbUpdateModel.js +36 -0
- package/operations/model/DdbUpdateModel.js.map +1 -0
- package/operations/model/feature.d.ts +4 -0
- package/operations/model/feature.js +19 -0
- package/operations/model/feature.js.map +1 -0
- package/operations/model/keys.d.ts +15 -0
- package/operations/model/keys.js +16 -0
- package/operations/model/keys.js.map +1 -0
- package/package.json +15 -17
- package/types.d.ts +9 -49
- package/types.js.map +1 -1
- package/dynamoDb/index.d.ts +0 -2
- package/dynamoDb/index.js +0 -11
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/path/locationFolderId.d.ts +0 -2
- package/dynamoDb/path/locationFolderId.js +0 -21
- package/dynamoDb/path/locationFolderId.js.map +0 -1
- package/dynamoDb/path/plainObject.d.ts +0 -2
- package/dynamoDb/path/plainObject.js +0 -16
- package/dynamoDb/path/plainObject.js.map +0 -1
- package/dynamoDb/transformValue/datetime.d.ts +0 -5
- package/dynamoDb/transformValue/datetime.js +0 -29
- package/dynamoDb/transformValue/datetime.js.map +0 -1
- package/operations/entry/filtering/createExpressions.d.ts +0 -27
- package/operations/entry/filtering/createExpressions.js +0 -124
- package/operations/entry/filtering/createExpressions.js.map +0 -1
- package/operations/entry/filtering/createFields.d.ts +0 -16
- package/operations/entry/filtering/createFields.js +0 -93
- package/operations/entry/filtering/createFields.js.map +0 -1
- package/operations/entry/filtering/extractSort.d.ts +0 -17
- package/operations/entry/filtering/extractSort.js +0 -60
- package/operations/entry/filtering/extractSort.js.map +0 -1
- package/operations/entry/filtering/filter.d.ts +0 -16
- package/operations/entry/filtering/filter.js +0 -85
- package/operations/entry/filtering/filter.js.map +0 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
- package/operations/entry/filtering/fullTextSearch.js +0 -25
- package/operations/entry/filtering/fullTextSearch.js.map +0 -1
- package/operations/entry/filtering/getValue.d.ts +0 -5
- package/operations/entry/filtering/getValue.js +0 -37
- package/operations/entry/filtering/getValue.js.map +0 -1
- package/operations/entry/filtering/index.d.ts +0 -2
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/mapPlugins.d.ts +0 -8
- package/operations/entry/filtering/mapPlugins.js +0 -18
- package/operations/entry/filtering/mapPlugins.js.map +0 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -33
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/index.d.ts +0 -1
- package/operations/entry/filtering/plugins/index.js +0 -13
- package/operations/entry/filtering/plugins/index.js.map +0 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -68
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -3
- package/operations/entry/filtering/plugins/refFilterCreate.js +0 -63
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +0 -56
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +0 -1
- package/operations/entry/filtering/sort.d.ts +0 -12
- package/operations/entry/filtering/sort.js +0 -41
- package/operations/entry/filtering/sort.js.map +0 -1
- package/operations/entry/filtering/systemFields.d.ts +0 -2
- package/operations/entry/filtering/systemFields.js +0 -149
- package/operations/entry/filtering/systemFields.js.map +0 -1
- package/operations/entry/filtering/transform.d.ts +0 -6
- package/operations/entry/filtering/transform.js +0 -7
- package/operations/entry/filtering/transform.js.map +0 -1
- package/operations/entry/filtering/types.d.ts +0 -40
- package/operations/entry/filtering/types.js +0 -0
- package/operations/entry/filtering/values.d.ts +0 -2
- package/operations/entry/filtering/values.js +0 -15
- package/operations/entry/filtering/values.js.map +0 -1
- package/operations/entry/filtering/where.d.ts +0 -5
- package/operations/entry/filtering/where.js +0 -22
- package/operations/entry/filtering/where.js.map +0 -1
- package/operations/entry/index.d.ts +0 -9
- package/operations/entry/index.js +0 -943
- package/operations/entry/index.js.map +0 -1
- package/operations/group/index.d.ts +0 -8
- package/operations/group/index.js +0 -121
- package/operations/group/index.js.map +0 -1
- package/operations/model/index.d.ts +0 -7
- package/operations/model/index.js +0 -106
- package/operations/model/index.js.map +0 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -30
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
- package/plugins/CmsEntryFieldFilterPlugin.js +0 -20
- package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
- package/plugins/CmsEntryFieldSortingPlugin.js +0 -20
- package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
- package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -19
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
- package/plugins/index.d.ts +0 -4
- package/plugins/index.js +0 -4
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import { PublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.js";
|
|
4
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
5
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
6
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
|
+
import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys } from "./keys.js";
|
|
8
|
+
import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
9
|
+
import { convertFromStorageEntry, convertToStorageEntry } from "./storageEntryUtils.js";
|
|
10
|
+
class DdbPublishEntryImpl {
|
|
11
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
12
|
+
this.entity = entity;
|
|
13
|
+
this.dataLoaders = dataLoaders;
|
|
14
|
+
this.storageModelProvider = storageModelProvider;
|
|
15
|
+
}
|
|
16
|
+
async getLatestRevisionByEntryId(initialModel, params) {
|
|
17
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
18
|
+
const items = await this.dataLoaders.getLatestRevisionByEntryId({
|
|
19
|
+
model,
|
|
20
|
+
ids: [
|
|
21
|
+
params.id
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
const item = items.shift() || null;
|
|
25
|
+
if (!item) return null;
|
|
26
|
+
return convertFromStorageEntry({
|
|
27
|
+
storageEntry: item,
|
|
28
|
+
model
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async getPublishedRevisionByEntryId(initialModel, params) {
|
|
32
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
33
|
+
const items = await this.dataLoaders.getPublishedRevisionByEntryId({
|
|
34
|
+
model,
|
|
35
|
+
ids: [
|
|
36
|
+
params.id
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
const item = items.shift() || null;
|
|
40
|
+
if (!item) return null;
|
|
41
|
+
return convertFromStorageEntry({
|
|
42
|
+
storageEntry: item,
|
|
43
|
+
model
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async execute(initialModel, params) {
|
|
47
|
+
const { entry, storageEntry: initialStorageEntry } = params;
|
|
48
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
49
|
+
const initialLatestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);
|
|
50
|
+
if (!initialLatestStorageEntry) throw new error('Could not publish entry. Could not load latest ("L") record.', "PUBLISH_ERROR", {
|
|
51
|
+
entry
|
|
52
|
+
});
|
|
53
|
+
const initialPublishedStorageEntry = await this.getPublishedRevisionByEntryId(model, entry);
|
|
54
|
+
const storageEntry = convertToStorageEntry({
|
|
55
|
+
model,
|
|
56
|
+
storageEntry: initialStorageEntry
|
|
57
|
+
});
|
|
58
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
59
|
+
put: [
|
|
60
|
+
{
|
|
61
|
+
...createEntryRevisionKeys(storageEntry),
|
|
62
|
+
data: {
|
|
63
|
+
...storageEntry
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
...createEntryPublishedKeys(storageEntry),
|
|
68
|
+
data: {
|
|
69
|
+
...storageEntry
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
const publishedRevisionId = initialPublishedStorageEntry?.id;
|
|
75
|
+
const publishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
76
|
+
if (publishingLatestRevision) {
|
|
77
|
+
entityBatch.put({
|
|
78
|
+
...createEntryLatestKeys(storageEntry),
|
|
79
|
+
data: {
|
|
80
|
+
...storageEntry
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (publishedRevisionId && publishedRevisionId !== entry.id) {
|
|
84
|
+
const publishedStorageEntry = convertToStorageEntry({
|
|
85
|
+
storageEntry: initialPublishedStorageEntry,
|
|
86
|
+
model
|
|
87
|
+
});
|
|
88
|
+
entityBatch.put({
|
|
89
|
+
...createEntryRevisionKeys(publishedStorageEntry),
|
|
90
|
+
data: {
|
|
91
|
+
...publishedStorageEntry,
|
|
92
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
98
|
+
const latestStorageEntry = convertToStorageEntry({
|
|
99
|
+
storageEntry: initialLatestStorageEntry,
|
|
100
|
+
model
|
|
101
|
+
});
|
|
102
|
+
let latestRevisionStatus = latestStorageEntry.status;
|
|
103
|
+
if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
104
|
+
const latestStorageEntryFields = {
|
|
105
|
+
...latestStorageEntry,
|
|
106
|
+
...updatedEntryLevelMetaFields,
|
|
107
|
+
status: latestRevisionStatus
|
|
108
|
+
};
|
|
109
|
+
entityBatch.put({
|
|
110
|
+
...createEntryLatestKeys(latestStorageEntryFields),
|
|
111
|
+
data: {
|
|
112
|
+
...latestStorageEntryFields
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
entityBatch.put({
|
|
116
|
+
...createEntryRevisionKeys(latestStorageEntryFields),
|
|
117
|
+
data: {
|
|
118
|
+
...latestStorageEntryFields
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const publishedRevisionDifferentFromLatest = publishedRevisionId && publishedRevisionId !== latestStorageEntry.id;
|
|
122
|
+
if (publishedRevisionDifferentFromLatest) {
|
|
123
|
+
const publishedStorageEntry = convertToStorageEntry({
|
|
124
|
+
storageEntry: initialPublishedStorageEntry,
|
|
125
|
+
model
|
|
126
|
+
});
|
|
127
|
+
entityBatch.put({
|
|
128
|
+
...createEntryRevisionKeys(publishedStorageEntry),
|
|
129
|
+
data: {
|
|
130
|
+
...publishedStorageEntry,
|
|
131
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
await entityBatch.execute();
|
|
138
|
+
this.dataLoaders.clearAll({
|
|
139
|
+
tenant: entry.tenant
|
|
140
|
+
});
|
|
141
|
+
return initialStorageEntry;
|
|
142
|
+
} catch (ex) {
|
|
143
|
+
throw new error(ex.message || "Could not execute the publishing batch.", ex.code || "PUBLISH_ERROR", {
|
|
144
|
+
entry,
|
|
145
|
+
latestStorageEntry: initialLatestStorageEntry,
|
|
146
|
+
publishedStorageEntry: initialPublishedStorageEntry
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const DdbPublishEntry = PublishEntryStorageOperation.createImplementation({
|
|
152
|
+
implementation: DdbPublishEntryImpl,
|
|
153
|
+
dependencies: [
|
|
154
|
+
CmsDdbEntryEntity,
|
|
155
|
+
CmsDdbDataLoaders,
|
|
156
|
+
CmsStorageModelProvider
|
|
157
|
+
]
|
|
158
|
+
});
|
|
159
|
+
export { DdbPublishEntry };
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=DdbPublishEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbPublishEntry.js","sources":["../../../src/operations/entry/DdbPublishEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsPublishParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { CONTENT_ENTRY_STATUS } from \"@webiny/api-headless-cms/types/index.js\";\nimport { PublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { CmsDdbDataLoaders } from \"~/abstractions/CmsDdbDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys\n} from \"~/operations/entry/keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { convertFromStorageEntry, convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbPublishEntryImpl implements PublishEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n private async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: { id: string }\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const items = await this.dataLoaders.getLatestRevisionByEntryId<T>({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n }\n\n private async getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: { id: string }\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const items = await this.dataLoaders.getPublishedRevisionByEntryId<T>({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsPublishParams<T>\n ) {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n /**\n * We need the latest and published entries to see if something needs to be updated alongside the publishing one.\n */\n const initialLatestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);\n if (!initialLatestStorageEntry) {\n throw new WebinyError(\n `Could not publish entry. Could not load latest (\"L\") record.`,\n \"PUBLISH_ERROR\",\n { entry }\n );\n }\n\n const initialPublishedStorageEntry = await this.getPublishedRevisionByEntryId(model, entry);\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n\n // 1. Update REV# and P records with new data.\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...createEntryRevisionKeys(storageEntry),\n data: {\n ...storageEntry\n }\n },\n {\n ...createEntryPublishedKeys(storageEntry),\n data: {\n ...storageEntry\n }\n }\n ]\n });\n\n // 2. When it comes to the latest record, we need to perform a couple of different\n // updates, based on whether the entry being published is the latest revision or not.\n const publishedRevisionId = initialPublishedStorageEntry?.id;\n const publishingLatestRevision = entry.id === initialLatestStorageEntry.id;\n\n if (publishingLatestRevision) {\n // 2.1 If we're publishing the latest revision, we first need to update the L record.\n entityBatch.put({\n ...createEntryLatestKeys(storageEntry),\n data: {\n ...storageEntry\n }\n });\n\n // 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.\n if (publishedRevisionId && publishedRevisionId !== entry.id) {\n const publishedStorageEntry = convertToStorageEntry({\n storageEntry: initialPublishedStorageEntry,\n model\n });\n\n entityBatch.put({\n ...createEntryRevisionKeys(publishedStorageEntry),\n data: {\n ...publishedStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\n } else {\n // 2.3 If the published revision is not the latest one, the situation is a bit\n // more complex. We first need to update the L and REV# records with the new\n // values of *only entry-level* meta fields.\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n const latestStorageEntry = convertToStorageEntry({\n storageEntry: initialLatestStorageEntry,\n model\n });\n\n // 2.3.1 Update L record. Apart from updating the entry-level meta fields, we also need\n // to change the status from \"published\" to \"unpublished\" (if the status is set to \"published\").\n let latestRevisionStatus = latestStorageEntry.status;\n if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {\n latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;\n }\n\n const latestStorageEntryFields = {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields,\n status: latestRevisionStatus\n };\n\n entityBatch.put({\n ...createEntryLatestKeys(latestStorageEntryFields),\n data: {\n ...latestStorageEntryFields\n }\n });\n\n // 2.3.2 Update REV# record.\n entityBatch.put({\n ...createEntryRevisionKeys(latestStorageEntryFields),\n data: {\n ...latestStorageEntryFields\n }\n });\n\n // 2.3.3 Finally, if we got a published entry, but it wasn't the latest one, we need to take\n // an extra step and mark it as unpublished.\n const publishedRevisionDifferentFromLatest =\n publishedRevisionId && publishedRevisionId !== latestStorageEntry.id;\n if (publishedRevisionDifferentFromLatest) {\n const publishedStorageEntry = convertToStorageEntry({\n storageEntry: initialPublishedStorageEntry,\n model\n });\n\n entityBatch.put({\n ...createEntryRevisionKeys(publishedStorageEntry),\n data: {\n ...publishedStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\n }\n\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n return initialStorageEntry;\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: initialLatestStorageEntry,\n publishedStorageEntry: initialPublishedStorageEntry\n }\n );\n }\n }\n}\n\nexport const DdbPublishEntry = PublishEntryStorageOperation.createImplementation({\n implementation: DdbPublishEntryImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbPublishEntryImpl","entity","dataLoaders","storageModelProvider","initialModel","params","model","items","item","convertFromStorageEntry","entry","initialStorageEntry","initialLatestStorageEntry","WebinyError","initialPublishedStorageEntry","storageEntry","convertToStorageEntry","entityBatch","createEntryRevisionKeys","createEntryPublishedKeys","publishedRevisionId","publishingLatestRevision","createEntryLatestKeys","publishedStorageEntry","CONTENT_ENTRY_STATUS","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","latestStorageEntry","latestRevisionStatus","latestStorageEntryFields","publishedRevisionDifferentFromLatest","ex","DdbPublishEntry","PublishEntryStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;;;AAsBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAc,2BACVC,YAAsB,EACtBC,MAAsB,EACxB;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAI;YAC/DD;YACA,KAAK;gBAACD,OAAO,EAAE;aAAC;QACpB;QACA,MAAMG,OAAOD,MAAM,KAAK,MAAM;QAC9B,IAAI,CAACC,MACD,OAAO;QAEX,OAAOC,wBAAwB;YAC3B,cAAcD;YACdF;QACJ;IACJ;IAEA,MAAc,8BACVF,YAAsB,EACtBC,MAAsB,EACxB;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,6BAA6B,CAAI;YAClED;YACA,KAAK;gBAACD,OAAO,EAAE;aAAC;QACpB;QACA,MAAMG,OAAOD,MAAM,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+1,16 @@
|
|
|
1
|
+
import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsRestoreFromBinParams, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { RestoreFromBinStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
4
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
5
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
declare class DdbRestoreFromBinImpl implements RestoreFromBinStorageOperation.Interface {
|
|
7
|
+
private entity;
|
|
8
|
+
private dataLoaders;
|
|
9
|
+
private storageModelProvider;
|
|
10
|
+
constructor(entity: CmsDdbEntryEntity.Interface, dataLoaders: CmsDdbDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface);
|
|
11
|
+
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsRestoreFromBinParams<T>): Promise<CmsStorageEntry<T>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const DdbRestoreFromBin: typeof DdbRestoreFromBinImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js").IRestoreFromBinStorageOperation>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { RestoreFromBinStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
4
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
5
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
import { createPartitionKey } from "./keys.js";
|
|
7
|
+
import { isRestoredEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
8
|
+
import { convertToStorageEntry } from "./storageEntryUtils.js";
|
|
9
|
+
class DdbRestoreFromBinImpl {
|
|
10
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
11
|
+
this.entity = entity;
|
|
12
|
+
this.dataLoaders = dataLoaders;
|
|
13
|
+
this.storageModelProvider = storageModelProvider;
|
|
14
|
+
}
|
|
15
|
+
async execute(initialModel, params) {
|
|
16
|
+
const { entry, storageEntry: initialStorageEntry } = params;
|
|
17
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
18
|
+
let records = [];
|
|
19
|
+
try {
|
|
20
|
+
records = await this.entity.queryAll({
|
|
21
|
+
partitionKey: createPartitionKey({
|
|
22
|
+
id: entry.id,
|
|
23
|
+
tenant: model.tenant
|
|
24
|
+
}),
|
|
25
|
+
options: {
|
|
26
|
+
gte: " "
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
} catch (ex) {
|
|
30
|
+
throw new error(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
|
|
31
|
+
error: ex,
|
|
32
|
+
id: entry.id
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (0 === records.length) return initialStorageEntry;
|
|
36
|
+
const storageEntry = convertToStorageEntry({
|
|
37
|
+
model,
|
|
38
|
+
storageEntry: initialStorageEntry
|
|
39
|
+
});
|
|
40
|
+
const updatedRestoredMetaFields = pickEntryMetaFields(storageEntry, isRestoredEntryMetaField);
|
|
41
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
42
|
+
put: records.map((record)=>({
|
|
43
|
+
...record,
|
|
44
|
+
data: {
|
|
45
|
+
...record.data,
|
|
46
|
+
...updatedRestoredMetaFields,
|
|
47
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
48
|
+
location: storageEntry.location,
|
|
49
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
50
|
+
}
|
|
51
|
+
}))
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
await entityBatch.execute();
|
|
55
|
+
this.dataLoaders.clearAll({
|
|
56
|
+
tenant: entry.tenant
|
|
57
|
+
});
|
|
58
|
+
return initialStorageEntry;
|
|
59
|
+
} catch (ex) {
|
|
60
|
+
throw new error(ex.message || "Could not restore the entry from the bin.", ex.code || "RESTORE_ENTRY_ERROR", {
|
|
61
|
+
error: ex,
|
|
62
|
+
entry,
|
|
63
|
+
storageEntry
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const DdbRestoreFromBin = RestoreFromBinStorageOperation.createImplementation({
|
|
69
|
+
implementation: DdbRestoreFromBinImpl,
|
|
70
|
+
dependencies: [
|
|
71
|
+
CmsDdbEntryEntity,
|
|
72
|
+
CmsDdbDataLoaders,
|
|
73
|
+
CmsStorageModelProvider
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
export { DdbRestoreFromBin };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=DdbRestoreFromBin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbRestoreFromBin.js","sources":["../../../src/operations/entry/DdbRestoreFromBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsRestoreFromBinParams,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { RestoreFromBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { CmsDdbDataLoaders } from \"~/abstractions/CmsDdbDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { createPartitionKey } from \"~/operations/entry/keys.js\";\nimport {\n isRestoredEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbRestoreFromBinImpl implements RestoreFromBinStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsRestoreFromBinParams<T>\n ): Promise<CmsStorageEntry<T>> {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n /**\n * First we need to load all the revisions and published / latest entries.\n */\n let records: Awaited<ReturnType<typeof this.entity.queryAll>> = [];\n try {\n records = await this.entity.queryAll({\n partitionKey: createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n }),\n options: {\n gte: \" \"\n }\n });\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 id: entry.id\n }\n );\n }\n if (records.length === 0) {\n return initialStorageEntry;\n }\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n\n /**\n * Let's pick the `restored` meta fields from the storage entry.\n */\n const updatedRestoredMetaFields = pickEntryMetaFields(\n storageEntry,\n isRestoredEntryMetaField\n );\n\n const entityBatch = this.entity.createEntityWriter({\n put: records.map(record => {\n return {\n ...record,\n data: {\n ...record.data,\n ...updatedRestoredMetaFields,\n wbyDeleted: storageEntry.wbyDeleted,\n location: storageEntry.location,\n binOriginalFolderId: storageEntry.binOriginalFolderId\n }\n };\n })\n });\n\n /**\n * And finally write it...\n */\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not restore the entry from the bin.\",\n ex.code || \"RESTORE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n }\n}\n\nexport const DdbRestoreFromBin = RestoreFromBinStorageOperation.createImplementation({\n implementation: DdbRestoreFromBinImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbRestoreFromBinImpl","entity","dataLoaders","storageModelProvider","initialModel","params","entry","initialStorageEntry","model","records","createPartitionKey","ex","WebinyError","storageEntry","convertToStorageEntry","updatedRestoredMetaFields","pickEntryMetaFields","isRestoredEntryMetaField","entityBatch","record","DdbRestoreFromBin","RestoreFromBinStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;;AAkBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAwD,EAC7B;QAC3B,MAAM,EAAEC,KAAK,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACrD,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAKjD,IAAIK,UAA4D,EAAE;QAClE,IAAI;YACAA,UAAU,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACjC,cAAcC,mBAAmB;oBAC7B,IAAIJ,MAAM,EAAE;oBACZ,QAAQE,MAAM,MAAM;gBACxB;gBACA,SAAS;oBACL,KAAK;gBACT;YACJ;QACJ,EAAE,OAAOG,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,+BACdA,GAAG,IAAI,IAAI,0BACX;gBACI,OAAOA;gBACP,IAAIL,MAAM,EAAE;YAChB;QAER;QACA,IAAIG,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAOF;QAGX,MAAMM,eAAeC,sBAAsB;YACvCN;YACA,cAAcD;QAClB;QAKA,MAAMQ,4BAA4BC,oBAC9BH,cACAI;QAGJ,MAAMC,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;YAC/C,KAAKT,QAAQ,GAAG,CAACU,CAAAA,SACN;oBACH,GAAGA,MAAM;oBACT,MAAM;wBACF,GAAGA,OAAO,IAAI;wBACd,GAAGJ,yBAAyB;wBAC5B,YAAYF,aAAa,UAAU;wBACnC,UAAUA,aAAa,QAAQ;wBAC/B,qBAAqBA,aAAa,mBAAmB;oBACzD;gBACJ;QAER;QAKA,IAAI;YACA,MAAMK,YAAY,OAAO;YAEzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQZ,MAAM,MAAM;YACxB;YAEA,OAAOC;QACX,EAAE,OAAOI,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,6CACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACPL;gBACAO;YACJ;QAER;IACJ;AACJ;AAEO,MAAMO,oBAAoBC,+BAA+B,oBAAoB,CAAC;IACjF,gBAAgBrB;IAChB,cAAc;QAACsB;QAAmBC;QAAmBC;KAAwB;AACjF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsUnpublishParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { UnpublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
4
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
5
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
declare class DdbUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {
|
|
7
|
+
private entity;
|
|
8
|
+
private dataLoaders;
|
|
9
|
+
private storageModelProvider;
|
|
10
|
+
constructor(entity: CmsDdbEntryEntity.Interface, dataLoaders: CmsDdbDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface);
|
|
11
|
+
private getLatestRevisionByEntryId;
|
|
12
|
+
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsUnpublishParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const DdbUnpublishEntry: typeof DdbUnpublishEntryImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js").IUnpublishEntryStorageOperation>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { UnpublishEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
4
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
5
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
import { createEntryLatestKeys, createEntryRevisionKeys, createPartitionKey, createPublishedSortKey } from "./keys.js";
|
|
7
|
+
import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
8
|
+
import { convertFromStorageEntry, convertToStorageEntry } from "./storageEntryUtils.js";
|
|
9
|
+
class DdbUnpublishEntryImpl {
|
|
10
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
11
|
+
this.entity = entity;
|
|
12
|
+
this.dataLoaders = dataLoaders;
|
|
13
|
+
this.storageModelProvider = storageModelProvider;
|
|
14
|
+
}
|
|
15
|
+
async getLatestRevisionByEntryId(initialModel, params) {
|
|
16
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
17
|
+
const items = await this.dataLoaders.getLatestRevisionByEntryId({
|
|
18
|
+
model,
|
|
19
|
+
ids: [
|
|
20
|
+
params.id
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
const item = items.shift() || null;
|
|
24
|
+
if (!item) return null;
|
|
25
|
+
return convertFromStorageEntry({
|
|
26
|
+
storageEntry: item,
|
|
27
|
+
model
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async execute(initialModel, params) {
|
|
31
|
+
const { entry, storageEntry: initialStorageEntry } = params;
|
|
32
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
33
|
+
const partitionKey = createPartitionKey({
|
|
34
|
+
id: entry.id,
|
|
35
|
+
tenant: model.tenant
|
|
36
|
+
});
|
|
37
|
+
const storageEntry = convertToStorageEntry({
|
|
38
|
+
storageEntry: initialStorageEntry,
|
|
39
|
+
model
|
|
40
|
+
});
|
|
41
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
42
|
+
delete: [
|
|
43
|
+
{
|
|
44
|
+
PK: partitionKey,
|
|
45
|
+
SK: createPublishedSortKey()
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
put: [
|
|
49
|
+
{
|
|
50
|
+
...createEntryRevisionKeys(storageEntry),
|
|
51
|
+
data: {
|
|
52
|
+
...storageEntry
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
const initialLatestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);
|
|
58
|
+
if (initialLatestStorageEntry) {
|
|
59
|
+
const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;
|
|
60
|
+
if (unpublishingLatestRevision) entityBatch.put({
|
|
61
|
+
...createEntryLatestKeys(storageEntry),
|
|
62
|
+
data: {
|
|
63
|
+
...storageEntry
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
else {
|
|
67
|
+
const latestStorageEntry = convertToStorageEntry({
|
|
68
|
+
storageEntry: initialLatestStorageEntry,
|
|
69
|
+
model
|
|
70
|
+
});
|
|
71
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
72
|
+
entityBatch.put({
|
|
73
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
74
|
+
data: {
|
|
75
|
+
...latestStorageEntry,
|
|
76
|
+
...updatedEntryLevelMetaFields
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
entityBatch.put({
|
|
80
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
81
|
+
data: {
|
|
82
|
+
...latestStorageEntry,
|
|
83
|
+
...updatedEntryLevelMetaFields
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
await entityBatch.execute();
|
|
90
|
+
this.dataLoaders.clearAll({
|
|
91
|
+
tenant: entry.tenant
|
|
92
|
+
});
|
|
93
|
+
return initialStorageEntry;
|
|
94
|
+
} catch (ex) {
|
|
95
|
+
throw new error(ex.message || "Could not execute unpublish batch.", ex.code || "UNPUBLISH_ERROR", {
|
|
96
|
+
entry,
|
|
97
|
+
storageEntry
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const DdbUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({
|
|
103
|
+
implementation: DdbUnpublishEntryImpl,
|
|
104
|
+
dependencies: [
|
|
105
|
+
CmsDdbEntryEntity,
|
|
106
|
+
CmsDdbDataLoaders,
|
|
107
|
+
CmsStorageModelProvider
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
export { DdbUnpublishEntry };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=DdbUnpublishEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbUnpublishEntry.js","sources":["../../../src/operations/entry/DdbUnpublishEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUnpublishParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UnpublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { CmsDdbDataLoaders } from \"~/abstractions/CmsDdbDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n createEntryLatestKeys,\n createEntryRevisionKeys,\n createPartitionKey,\n createPublishedSortKey\n} from \"~/operations/entry/keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { convertFromStorageEntry, convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n private async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: { id: string }\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const items = await this.dataLoaders.getLatestRevisionByEntryId<T>({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUnpublishParams<T>\n ) {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - delete currently published entry\n * - update current entry revision with new data\n * - update the latest entry status - if entry being unpublished is latest\n */\n const entityBatch = this.entity.createEntityWriter({\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ],\n put: [\n {\n ...createEntryRevisionKeys(storageEntry),\n data: {\n ...storageEntry\n }\n }\n ]\n });\n\n /**\n * We need the latest entry to see if something needs to be updated alongside the unpublishing one.\n */\n const initialLatestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);\n\n if (initialLatestStorageEntry) {\n const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;\n if (unpublishingLatestRevision) {\n entityBatch.put({\n ...createEntryLatestKeys(storageEntry),\n data: {\n ...storageEntry\n }\n });\n } else {\n const latestStorageEntry = convertToStorageEntry({\n storageEntry: initialLatestStorageEntry,\n model\n });\n\n // If the unpublished revision is not the latest one, we still need to\n // update the latest record with the new values of entry-level meta fields.\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n // 1. Update actual revision record.\n entityBatch.put({\n ...createEntryRevisionKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n });\n\n // 2. Update latest record.\n entityBatch.put({\n ...createEntryLatestKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n });\n }\n }\n\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n return initialStorageEntry;\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\nexport const DdbUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({\n implementation: DdbUnpublishEntryImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbUnpublishEntryImpl","entity","dataLoaders","storageModelProvider","initialModel","params","model","items","item","convertFromStorageEntry","entry","initialStorageEntry","partitionKey","createPartitionKey","storageEntry","convertToStorageEntry","entityBatch","createPublishedSortKey","createEntryRevisionKeys","initialLatestStorageEntry","unpublishingLatestRevision","createEntryLatestKeys","latestStorageEntry","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","ex","WebinyError","DdbUnpublishEntry","UnpublishEntryStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;;AAsBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAc,2BACVC,YAAsB,EACtBC,MAAsB,EACxB;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAI;YAC/DD;YACA,KAAK;gBAACD,OAAO,EAAE;aAAC;QACpB;QACA,MAAMG,OAAOD,MAAM,KAAK,MAAM;QAC9B,IAAI,CAACC,MACD,OAAO;QAEX,OAAOC,wBAAwB;YAC3B,cAAcD;YACdF;QACJ;IACJ;IAEA,MAAM,QACFF,YAAsB,EACtBC,MAAmD,EACrD;QACE,MAAM,EAAEK,KAAK,EAAE,cAAcC,mBAAmB,EAAE,GAAGN;QACrD,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACF;QAEjD,MAAMQ,eAAeC,mBAAmB;YACpC,IAAIH,MAAM,EAAE;YACZ,QAAQJ,MAAM,MAAM;QACxB;QAEA,MAAMQ,eAAeC,sBAAsB;YACvC,cAAcJ;YACdL;QACJ;QAOA,MAAMU,cAAc,IAAI,CAAC,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
|
|
|
1
|
+
import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsUpdateParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { UpdateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
4
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
5
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
declare class DdbUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {
|
|
7
|
+
private entity;
|
|
8
|
+
private dataLoaders;
|
|
9
|
+
private storageModelProvider;
|
|
10
|
+
constructor(entity: CmsDdbEntryEntity.Interface, dataLoaders: CmsDdbDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface);
|
|
11
|
+
private getLatestRevisionByEntryId;
|
|
12
|
+
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsUpdateParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const DdbUpdateEntry: typeof DdbUpdateEntryImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js").IUpdateEntryStorageOperation>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { UpdateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
4
|
+
import { CmsDdbDataLoaders } from "../../abstractions/CmsDdbDataLoaders.js";
|
|
5
|
+
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys } from "./keys.js";
|
|
7
|
+
import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
8
|
+
import { convertFromStorageEntry, convertToStorageEntry } from "./storageEntryUtils.js";
|
|
9
|
+
class DdbUpdateEntryImpl {
|
|
10
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
11
|
+
this.entity = entity;
|
|
12
|
+
this.dataLoaders = dataLoaders;
|
|
13
|
+
this.storageModelProvider = storageModelProvider;
|
|
14
|
+
}
|
|
15
|
+
async getLatestRevisionByEntryId(initialModel, params) {
|
|
16
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
17
|
+
const items = await this.dataLoaders.getLatestRevisionByEntryId({
|
|
18
|
+
model,
|
|
19
|
+
ids: [
|
|
20
|
+
params.id
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
const item = items.shift() || null;
|
|
24
|
+
if (!item) return null;
|
|
25
|
+
return convertFromStorageEntry({
|
|
26
|
+
storageEntry: item,
|
|
27
|
+
model
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async execute(initialModel, params) {
|
|
31
|
+
const { entry, storageEntry: initialStorageEntry } = params;
|
|
32
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
33
|
+
const isPublished = "published" === entry.status;
|
|
34
|
+
const locked = isPublished ? true : entry.locked;
|
|
35
|
+
const storageEntry = convertToStorageEntry({
|
|
36
|
+
model,
|
|
37
|
+
storageEntry: initialStorageEntry
|
|
38
|
+
});
|
|
39
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
40
|
+
put: [
|
|
41
|
+
{
|
|
42
|
+
...createEntryRevisionKeys(storageEntry),
|
|
43
|
+
data: {
|
|
44
|
+
...storageEntry,
|
|
45
|
+
locked
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
if (isPublished) entityBatch.put({
|
|
51
|
+
...createEntryPublishedKeys(storageEntry),
|
|
52
|
+
data: {
|
|
53
|
+
...storageEntry,
|
|
54
|
+
locked
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const latestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);
|
|
58
|
+
if (latestStorageEntry) {
|
|
59
|
+
const updatingLatestRevision = latestStorageEntry.id === entry.id;
|
|
60
|
+
if (updatingLatestRevision) entityBatch.put({
|
|
61
|
+
...createEntryLatestKeys(storageEntry),
|
|
62
|
+
data: {
|
|
63
|
+
...storageEntry,
|
|
64
|
+
locked
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
else {
|
|
68
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
69
|
+
entityBatch.put({
|
|
70
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
71
|
+
data: {
|
|
72
|
+
...latestStorageEntry,
|
|
73
|
+
...updatedEntryLevelMetaFields
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
entityBatch.put({
|
|
77
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
78
|
+
data: {
|
|
79
|
+
...latestStorageEntry,
|
|
80
|
+
...updatedEntryLevelMetaFields
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await entityBatch.execute();
|
|
87
|
+
this.dataLoaders.clearAll({
|
|
88
|
+
tenant: entry.tenant
|
|
89
|
+
});
|
|
90
|
+
return initialStorageEntry;
|
|
91
|
+
} catch (ex) {
|
|
92
|
+
throw new error(ex.message || "Could not update entry.", ex.code || "UPDATE_ERROR", {
|
|
93
|
+
error: ex,
|
|
94
|
+
entry,
|
|
95
|
+
latestStorageEntry
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const DdbUpdateEntry = UpdateEntryStorageOperation.createImplementation({
|
|
101
|
+
implementation: DdbUpdateEntryImpl,
|
|
102
|
+
dependencies: [
|
|
103
|
+
CmsDdbEntryEntity,
|
|
104
|
+
CmsDdbDataLoaders,
|
|
105
|
+
CmsStorageModelProvider
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
export { DdbUpdateEntry };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=DdbUpdateEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbUpdateEntry.js","sources":["../../../src/operations/entry/DdbUpdateEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UpdateEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { CmsDdbDataLoaders } from \"~/abstractions/CmsDdbDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys\n} from \"~/operations/entry/keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { convertFromStorageEntry, convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n private async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: { id: string }\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const items = await this.dataLoaders.getLatestRevisionByEntryId<T>({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUpdateParams<T>\n ) {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\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\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...createEntryRevisionKeys(storageEntry),\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...createEntryPublishedKeys(storageEntry),\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n /**\n * We need the latest entry to update it as well if necessary.\n */\n const latestStorageEntry = await this.getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry) {\n const updatingLatestRevision = latestStorageEntry.id === entry.id;\n if (updatingLatestRevision) {\n entityBatch.put({\n ...createEntryLatestKeys(storageEntry),\n data: {\n ...storageEntry,\n locked\n }\n });\n } else {\n /**\n * If not updating latest revision, we still want to update the latest revision's\n * entry-level meta fields to match the current revision's entry-level meta fields.\n */\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n /**\n * First we update the regular DynamoDB table. Two updates are needed:\n * - one for the actual revision record\n * - one for the latest record\n */\n entityBatch.put({\n ...createEntryRevisionKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n });\n\n entityBatch.put({\n ...createEntryLatestKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n });\n }\n }\n\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n return initialStorageEntry;\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\nexport const DdbUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: DdbUpdateEntryImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbUpdateEntryImpl","entity","dataLoaders","storageModelProvider","initialModel","params","model","items","item","convertFromStorageEntry","entry","initialStorageEntry","isPublished","locked","storageEntry","convertToStorageEntry","entityBatch","createEntryRevisionKeys","createEntryPublishedKeys","latestStorageEntry","updatingLatestRevision","createEntryLatestKeys","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","ex","WebinyError","DdbUpdateEntry","UpdateEntryStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;;AAqBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAc,2BACVC,YAAsB,EACtBC,MAAsB,EACxB;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAI;YAC/DD;YACA,KAAK;gBAACD,OAAO,EAAE;aAAC;QACpB;QACA,MAAMG,OAAOD,MAAM,KAAK,MAAM;QAC9B,IAAI,CAACC,MACD,OAAO;QAEX,OAAOC,wBAAwB;YAC3B,cAAcD;YACdF;QACJ;IACJ;IAEA,MAAM,QACFF,YAAsB,EACtBC,MAAgD,EAClD;QACE,MAAM,EAAEK,KAAK,EAAE,cAA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QACX,EAAE,OAAOc,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,gBACX;gBACI,OAAOA;gBACPf;gBACAS;YACJ;QAER;IACJ;AACJ;AAEO,MAAMQ,iBAAiBC,4BAA4B,oBAAoB,CAAC;IAC3E,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAmBC;QAAmBC;KAAwB;AACjF"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { CmsEntryValues, CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
-
import type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler
|
|
2
|
+
import type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler } from "../../types.js";
|
|
3
|
+
import { CmsDdbEntryEntity } from "../../abstractions/CmsDdbEntryEntity.js";
|
|
3
4
|
interface DataLoaderParams {
|
|
4
5
|
model: Pick<CmsModel, "tenant" | "modelId">;
|
|
5
6
|
ids: readonly string[];
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
entity: IEntryEntity;
|
|
9
|
-
}
|
|
10
|
-
export declare class DataLoadersHandler implements IDataLoadersHandler {
|
|
8
|
+
declare class DataLoadersHandlerImpl implements IDataLoadersHandler {
|
|
11
9
|
private readonly entity;
|
|
12
10
|
private readonly cache;
|
|
13
|
-
constructor(
|
|
11
|
+
constructor(entity: CmsDdbEntryEntity.Interface);
|
|
14
12
|
getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
15
13
|
getRevisionById<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
16
14
|
getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
@@ -23,4 +21,7 @@ export declare class DataLoadersHandler implements IDataLoadersHandler {
|
|
|
23
21
|
private loadMany;
|
|
24
22
|
clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void;
|
|
25
23
|
}
|
|
24
|
+
export declare const DataLoadersHandler: typeof DataLoadersHandlerImpl & {
|
|
25
|
+
__abstraction: import("@webiny/di").Abstraction<IDataLoadersHandler>;
|
|
26
|
+
};
|
|
26
27
|
export {};
|