@webiny/api-headless-cms-ddb 0.0.0-mt-2 → 0.0.0-unstable.0156a4c312
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -20
- package/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/definitions/entry.d.ts +6 -6
- package/definitions/entry.js +9 -95
- package/definitions/entry.js.map +1 -0
- package/definitions/group.d.ts +6 -6
- package/definitions/group.js +9 -72
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +6 -6
- package/definitions/model.js +9 -94
- package/definitions/model.js.map +1 -0
- package/definitions/table.d.ts +6 -7
- package/definitions/table.js +8 -30
- package/definitions/table.js.map +1 -0
- package/definitions/types.d.ts +65 -0
- package/definitions/types.js +0 -0
- package/index.d.ts +10 -2
- package/index.js +45 -123
- package/index.js.map +1 -0
- 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 +59 -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 +30 -0
- package/operations/entry/DdbListEntries.js +133 -0
- package/operations/entry/DdbListEntries.js.map +1 -0
- package/operations/entry/DdbMoveEntry.d.ts +16 -0
- package/operations/entry/DdbMoveEntry.js +63 -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 +162 -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 +105 -0
- package/operations/entry/DdbUpdateEntry.js.map +1 -0
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +5 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +42 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +18 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +0 -0
- package/operations/entry/dataLoaders.d.ts +20 -31
- package/operations/entry/dataLoaders.js +91 -296
- package/operations/entry/dataLoaders.js.map +1 -0
- 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/keys.d.ts +46 -2
- package/operations/entry/keys.js +53 -55
- package/operations/entry/keys.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 +30 -34
- package/types.d.ts +12 -76
- package/types.js +8 -15
- package/types.js.map +1 -0
- package/definitions/settings.d.ts +0 -8
- package/definitions/settings.js +0 -62
- package/definitions/system.d.ts +0 -8
- package/definitions/system.js +0 -50
- package/dynamoDb/index.d.ts +0 -2
- package/dynamoDb/index.js +0 -24
- package/dynamoDb/path/plainObject.d.ts +0 -3
- package/dynamoDb/path/plainObject.js +0 -33
- package/dynamoDb/path/ref.d.ts +0 -3
- package/dynamoDb/path/ref.js +0 -27
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -65
- package/dynamoDb/storage/longText.d.ts +0 -7
- package/dynamoDb/storage/longText.js +0 -83
- package/dynamoDb/storage/richText.d.ts +0 -8
- package/dynamoDb/storage/richText.js +0 -110
- package/dynamoDb/transformValue/datetime.d.ts +0 -3
- package/dynamoDb/transformValue/datetime.js +0 -47
- package/operations/entry/index.d.ts +0 -8
- package/operations/entry/index.js +0 -823
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -50
- package/operations/entry/utils.d.ts +0 -31
- package/operations/entry/utils.js +0 -406
- package/operations/group/index.d.ts +0 -8
- package/operations/group/index.js +0 -198
- package/operations/model/index.d.ts +0 -6
- package/operations/model/index.js +0 -161
- package/operations/settings/index.d.ts +0 -6
- package/operations/settings/index.js +0 -141
- package/operations/system/index.d.ts +0 -6
- package/operations/system/index.js +0 -105
package/index.js
CHANGED
|
@@ -1,125 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ENTITIES } from "./types.js";
|
|
2
|
+
import { createGroupEntity } from "./definitions/group.js";
|
|
3
|
+
import { createModelEntity } from "./definitions/model.js";
|
|
4
|
+
import { createEntryEntity } from "./definitions/entry.js";
|
|
5
|
+
import { createTable } from "./definitions/table.js";
|
|
6
|
+
import { createFeature } from "@webiny/feature/api/index.js";
|
|
7
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb";
|
|
8
|
+
import { FilterUtilFeature } from "@webiny/db-dynamodb/feature/FilterUtil/feature.js";
|
|
9
|
+
import { CmsDdbTable } from "./abstractions/CmsDdbTable.js";
|
|
10
|
+
import { CmsDdbGroupEntity } from "./abstractions/CmsDdbGroupEntity.js";
|
|
11
|
+
import { CmsDdbModelEntity } from "./abstractions/CmsDdbModelEntity.js";
|
|
12
|
+
import { CmsDdbEntryEntity } from "./abstractions/CmsDdbEntryEntity.js";
|
|
13
|
+
import { FilterRegistriesFeature } from "@webiny/api-headless-cms-storage";
|
|
14
|
+
import { DdbGroupStorageOpsFeature } from "./operations/group/feature.js";
|
|
15
|
+
import { DdbModelStorageOpsFeature } from "./operations/model/feature.js";
|
|
16
|
+
import { DdbEntryStorageOpsFeature } from "./operations/entry/feature.js";
|
|
17
|
+
const HeadlessCmsDdbFeature = createFeature({
|
|
18
|
+
name: "cms.storageOperations.ddb",
|
|
19
|
+
register: (container)=>{
|
|
20
|
+
FilterUtilFeature.register(container);
|
|
21
|
+
const db = container.resolve(DynamoDBClient);
|
|
22
|
+
const documentClient = db.client;
|
|
23
|
+
const tableInstance = createTable({
|
|
24
|
+
documentClient
|
|
25
|
+
});
|
|
26
|
+
container.registerInstance(CmsDdbTable, tableInstance);
|
|
27
|
+
container.registerInstance(CmsDdbGroupEntity, createGroupEntity({
|
|
28
|
+
entityName: ENTITIES.GROUPS,
|
|
29
|
+
table: tableInstance
|
|
30
|
+
}));
|
|
31
|
+
container.registerInstance(CmsDdbModelEntity, createModelEntity({
|
|
32
|
+
entityName: ENTITIES.MODELS,
|
|
33
|
+
table: tableInstance
|
|
34
|
+
}));
|
|
35
|
+
container.registerInstance(CmsDdbEntryEntity, createEntryEntity({
|
|
36
|
+
entityName: ENTITIES.ENTRIES,
|
|
37
|
+
table: tableInstance
|
|
38
|
+
}));
|
|
39
|
+
FilterRegistriesFeature.register(container);
|
|
40
|
+
DdbGroupStorageOpsFeature.register(container);
|
|
41
|
+
DdbModelStorageOpsFeature.register(container);
|
|
42
|
+
DdbEntryStorageOpsFeature.register(container);
|
|
43
|
+
}
|
|
7
44
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
|
|
11
|
-
|
|
12
|
-
var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
|
|
13
|
-
|
|
14
|
-
var _types = require("./types");
|
|
15
|
-
|
|
16
|
-
var _table = require("./definitions/table");
|
|
17
|
-
|
|
18
|
-
var _settings = require("./definitions/settings");
|
|
19
|
-
|
|
20
|
-
var _system = require("./definitions/system");
|
|
21
|
-
|
|
22
|
-
var _group = require("./definitions/group");
|
|
23
|
-
|
|
24
|
-
var _model = require("./definitions/model");
|
|
25
|
-
|
|
26
|
-
var _entry = require("./definitions/entry");
|
|
27
|
-
|
|
28
|
-
var _plugins = require("@webiny/plugins");
|
|
29
|
-
|
|
30
|
-
var _system2 = require("./operations/system");
|
|
31
|
-
|
|
32
|
-
var _settings2 = require("./operations/settings");
|
|
33
|
-
|
|
34
|
-
var _group2 = require("./operations/group");
|
|
35
|
-
|
|
36
|
-
var _model2 = require("./operations/model");
|
|
37
|
-
|
|
38
|
-
var _entry2 = require("./operations/entry");
|
|
39
|
-
|
|
40
|
-
const createStorageOperations = params => {
|
|
41
|
-
const {
|
|
42
|
-
attributes = {},
|
|
43
|
-
table,
|
|
44
|
-
documentClient,
|
|
45
|
-
plugins: customPlugins,
|
|
46
|
-
modelFieldToGraphQLPlugins
|
|
47
|
-
} = params;
|
|
48
|
-
const tableInstance = (0, _table.createTable)({
|
|
49
|
-
table,
|
|
50
|
-
documentClient
|
|
51
|
-
});
|
|
52
|
-
const entities = {
|
|
53
|
-
settings: (0, _settings.createSettingsEntity)({
|
|
54
|
-
entityName: _types.ENTITIES.SETTINGS,
|
|
55
|
-
table: tableInstance,
|
|
56
|
-
attributes: attributes[_types.ENTITIES.SETTINGS]
|
|
57
|
-
}),
|
|
58
|
-
system: (0, _system.createSystemEntity)({
|
|
59
|
-
entityName: _types.ENTITIES.SYSTEM,
|
|
60
|
-
table: tableInstance,
|
|
61
|
-
attributes: attributes[_types.ENTITIES.SYSTEM]
|
|
62
|
-
}),
|
|
63
|
-
groups: (0, _group.createGroupEntity)({
|
|
64
|
-
entityName: _types.ENTITIES.GROUPS,
|
|
65
|
-
table: tableInstance,
|
|
66
|
-
attributes: attributes[_types.ENTITIES.GROUPS]
|
|
67
|
-
}),
|
|
68
|
-
models: (0, _model.createModelEntity)({
|
|
69
|
-
entityName: _types.ENTITIES.MODELS,
|
|
70
|
-
table: tableInstance,
|
|
71
|
-
attributes: attributes[_types.ENTITIES.MODELS]
|
|
72
|
-
}),
|
|
73
|
-
entries: (0, _entry.createEntryEntity)({
|
|
74
|
-
entityName: _types.ENTITIES.ENTRIES,
|
|
75
|
-
table: tableInstance,
|
|
76
|
-
attributes: attributes[_types.ENTITIES.ENTRIES]
|
|
77
|
-
})
|
|
78
|
-
};
|
|
79
|
-
const plugins = new _plugins.PluginsContainer([
|
|
80
|
-
/**
|
|
81
|
-
* User defined custom plugins.
|
|
82
|
-
*/
|
|
83
|
-
...(customPlugins || []),
|
|
84
|
-
/**
|
|
85
|
-
* Plugins of type CmsModelFieldToGraphQLPlugin.
|
|
86
|
-
*/
|
|
87
|
-
modelFieldToGraphQLPlugins,
|
|
88
|
-
/**
|
|
89
|
-
* DynamoDB filter plugins for the where conditions.
|
|
90
|
-
*/
|
|
91
|
-
(0, _filters.default)(),
|
|
92
|
-
/**
|
|
93
|
-
* Field plugins for DynamoDB.
|
|
94
|
-
*/
|
|
95
|
-
(0, _dynamoDb.default)()]);
|
|
96
|
-
return {
|
|
97
|
-
plugins: [
|
|
98
|
-
/**
|
|
99
|
-
* Field plugins for DynamoDB.
|
|
100
|
-
* We must pass them to the base application.
|
|
101
|
-
*/
|
|
102
|
-
(0, _dynamoDb.default)()],
|
|
103
|
-
getEntities: () => entities,
|
|
104
|
-
getTable: () => tableInstance,
|
|
105
|
-
system: (0, _system2.createSystemStorageOperations)({
|
|
106
|
-
entity: entities.system
|
|
107
|
-
}),
|
|
108
|
-
settings: (0, _settings2.createSettingsStorageOperations)({
|
|
109
|
-
entity: entities.settings
|
|
110
|
-
}),
|
|
111
|
-
groups: (0, _group2.createGroupsStorageOperations)({
|
|
112
|
-
entity: entities.groups,
|
|
113
|
-
plugins
|
|
114
|
-
}),
|
|
115
|
-
models: (0, _model2.createModelsStorageOperations)({
|
|
116
|
-
entity: entities.models
|
|
117
|
-
}),
|
|
118
|
-
entries: (0, _entry2.createEntriesStorageOperations)({
|
|
119
|
-
entity: entities.entries,
|
|
120
|
-
plugins
|
|
121
|
-
})
|
|
122
|
-
};
|
|
123
|
-
};
|
|
45
|
+
export { HeadlessCmsDdbFeature };
|
|
124
46
|
|
|
125
|
-
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { ENTITIES } from \"~/types.js\";\nimport { createGroupEntity } from \"~/definitions/group.js\";\nimport { createModelEntity } from \"~/definitions/model.js\";\nimport { createEntryEntity } from \"~/definitions/entry.js\";\nimport { createTable } from \"~/definitions/table.js\";\nimport { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DynamoDBClient } from \"@webiny/db-dynamodb\";\nimport { FilterUtilFeature } from \"@webiny/db-dynamodb/feature/FilterUtil/feature.js\";\nimport { CmsDdbTable } from \"~/abstractions/CmsDdbTable.js\";\nimport { CmsDdbGroupEntity } from \"~/abstractions/CmsDdbGroupEntity.js\";\nimport { CmsDdbModelEntity } from \"~/abstractions/CmsDdbModelEntity.js\";\nimport { CmsDdbEntryEntity } from \"~/abstractions/CmsDdbEntryEntity.js\";\nimport { FilterRegistriesFeature } from \"@webiny/api-headless-cms-storage\";\nimport { DdbGroupStorageOpsFeature } from \"~/operations/group/feature.js\";\nimport { DdbModelStorageOpsFeature } from \"~/operations/model/feature.js\";\nimport { DdbEntryStorageOpsFeature } from \"~/operations/entry/feature.js\";\n\n/**\n * DynamoDB CMS storage. Register it once, in the root container. Tables and entities are built once\n * per process; the storage operations are transient, and per-request state (the entry DataLoaders,\n * the filter registries) is container scoped, so each request (child) container gets its own.\n * Requires DynamoDBClient to be registered in the container first (via DbFeature).\n */\nexport const HeadlessCmsDdbFeature = createFeature({\n name: \"cms.storageOperations.ddb\",\n register: container => {\n FilterUtilFeature.register(container);\n\n const db = container.resolve(DynamoDBClient);\n const documentClient = db.client;\n\n const tableInstance = createTable({ documentClient });\n\n // Register infrastructure instances (app-scoped)\n container.registerInstance(CmsDdbTable, tableInstance);\n container.registerInstance(\n CmsDdbGroupEntity,\n createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance\n })\n );\n container.registerInstance(\n CmsDdbModelEntity,\n createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance\n })\n );\n container.registerInstance(\n CmsDdbEntryEntity,\n createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance\n })\n );\n\n FilterRegistriesFeature.register(container);\n DdbGroupStorageOpsFeature.register(container);\n DdbModelStorageOpsFeature.register(container);\n DdbEntryStorageOpsFeature.register(container);\n }\n});\n"],"names":["HeadlessCmsDdbFeature","createFeature","container","FilterUtilFeature","db","DynamoDBClient","documentClient","tableInstance","createTable","CmsDdbTable","CmsDdbGroupEntity","createGroupEntity","ENTITIES","CmsDdbModelEntity","createModelEntity","CmsDdbEntryEntity","createEntryEntity","FilterRegistriesFeature","DdbGroupStorageOpsFeature","DdbModelStorageOpsFeature","DdbEntryStorageOpsFeature"],"mappings":";;;;;;;;;;;;;;;;AAuBO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAAUC,CAAAA;QACNC,kBAAkB,QAAQ,CAACD;QAE3B,MAAME,KAAKF,UAAU,OAAO,CAACG;QAC7B,MAAMC,iBAAiBF,GAAG,MAAM;QAEhC,MAAMG,gBAAgBC,YAAY;YAAEF;QAAe;QAGnDJ,UAAU,gBAAgB,CAACO,aAAaF;QACxCL,UAAU,gBAAgB,CACtBQ,mBACAC,kBAAkB;YACd,YAAYC,SAAS,MAAM;YAC3B,OAAOL;QACX;QAEJL,UAAU,gBAAgB,CACtBW,mBACAC,kBAAkB;YACd,YAAYF,SAAS,MAAM;YAC3B,OAAOL;QACX;QAEJL,UAAU,gBAAgB,CACtBa,mBACAC,kBAAkB;YACd,YAAYJ,SAAS,OAAO;YAC5B,OAAOL;QACX;QAGJU,wBAAwB,QAAQ,CAACf;QACjCgB,0BAA0B,QAAQ,CAAChB;QACnCiB,0BAA0B,QAAQ,CAACjB;QACnCkB,0BAA0B,QAAQ,CAAClB;IACvC;AACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsCreateParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { CreateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryStorageOperation.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 DdbCreateEntryImpl implements CreateEntryStorageOperation.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: CmsEntryStorageOperationsCreateParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const DdbCreateEntry: typeof DdbCreateEntryImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryStorageOperation.js").ICreateEntryStorageOperation>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { CreateEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryStorageOperation.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 { convertToStorageEntry } from "./storageEntryUtils.js";
|
|
8
|
+
class DdbCreateEntryImpl {
|
|
9
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
10
|
+
this.entity = entity;
|
|
11
|
+
this.dataLoaders = dataLoaders;
|
|
12
|
+
this.storageModelProvider = storageModelProvider;
|
|
13
|
+
}
|
|
14
|
+
async execute(initialModel, params) {
|
|
15
|
+
const { entry, storageEntry: initialStorageEntry } = params;
|
|
16
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
17
|
+
const isPublished = "published" === entry.status;
|
|
18
|
+
const locked = isPublished ? true : entry.locked;
|
|
19
|
+
const storageEntry = convertToStorageEntry({
|
|
20
|
+
model,
|
|
21
|
+
storageEntry: initialStorageEntry
|
|
22
|
+
});
|
|
23
|
+
const storageEntryRevisionKeys = createEntryRevisionKeys(entry);
|
|
24
|
+
const storageEntryLatestKeys = createEntryLatestKeys(entry);
|
|
25
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
26
|
+
put: [
|
|
27
|
+
{
|
|
28
|
+
...storageEntryRevisionKeys,
|
|
29
|
+
data: {
|
|
30
|
+
...storageEntry,
|
|
31
|
+
locked
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
...storageEntryLatestKeys,
|
|
36
|
+
data: {
|
|
37
|
+
...storageEntry,
|
|
38
|
+
locked
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
if (isPublished) {
|
|
44
|
+
const storageEntryPublishedKeys = createEntryPublishedKeys(storageEntry);
|
|
45
|
+
entityBatch.put({
|
|
46
|
+
...storageEntryPublishedKeys,
|
|
47
|
+
data: {
|
|
48
|
+
...storageEntry,
|
|
49
|
+
locked
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await entityBatch.execute();
|
|
55
|
+
this.dataLoaders.clearAll({
|
|
56
|
+
tenant: entry.tenant
|
|
57
|
+
});
|
|
58
|
+
} catch (ex) {
|
|
59
|
+
throw new error(ex.message || "Could not insert data into the DynamoDB.", ex.code || "CREATE_ENTRY_ERROR", {
|
|
60
|
+
error: ex,
|
|
61
|
+
entry
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return initialStorageEntry;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const DdbCreateEntry = CreateEntryStorageOperation.createImplementation({
|
|
68
|
+
implementation: DdbCreateEntryImpl,
|
|
69
|
+
dependencies: [
|
|
70
|
+
CmsDdbEntryEntity,
|
|
71
|
+
CmsDdbDataLoaders,
|
|
72
|
+
CmsStorageModelProvider
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
export { DdbCreateEntry };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=DdbCreateEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbCreateEntry.js","sources":["../../../src/operations/entry/DdbCreateEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsCreateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { CreateEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryStorageOperation.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 { convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbCreateEntryImpl implements CreateEntryStorageOperation.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: CmsEntryStorageOperationsCreateParams<T>\n ) {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const isPublished = entry.status === \"published\";\n\n const locked = isPublished ? true : entry.locked;\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n\n const storageEntryRevisionKeys = createEntryRevisionKeys(entry);\n const storageEntryLatestKeys = createEntryLatestKeys(entry);\n /**\n * We need to:\n * - create new main entry item\n * - create new or update the latest entry item\n */\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...storageEntryRevisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n },\n {\n ...storageEntryLatestKeys,\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n /**\n * We need to create published entry if\n */\n if (isPublished) {\n const storageEntryPublishedKeys = createEntryPublishedKeys(storageEntry);\n entityBatch.put({\n ...storageEntryPublishedKeys,\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: entry.tenant\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 initialStorageEntry;\n }\n}\n\nexport const DdbCreateEntry = CreateEntryStorageOperation.createImplementation({\n implementation: DdbCreateEntryImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbCreateEntryImpl","entity","dataLoaders","storageModelProvider","initialModel","params","entry","initialStorageEntry","model","isPublished","locked","storageEntry","convertToStorageEntry","storageEntryRevisionKeys","createEntryRevisionKeys","storageEntryLatestKeys","createEntryLatestKeys","entityBatch","storageEntryPublishedKeys","createEntryPublishedKeys","ex","WebinyError","DdbCreateEntry","CreateEntryStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;AAiBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAgD,EAClD;QACE,MAAM,EAAEC,KAAK,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACrD,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAEjD,MAAMK,cAAcH,AAAiB,gBAAjBA,MAAM,MAAM;QAEhC,MAAMI,SAASD,cAAc,OAAOH,MAAM,MAAM;QAEhD,MAAMK,eAAeC,sBAAsB;YACvCJ;YACA,cAAcD;QAClB;QAEA,MAAMM,2BAA2BC,wBAAwBR;QACzD,MAAMS,yBAAyBC,sBAAsBV;QAMrD,MAAMW,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;YAC/C,KAAK;gBACD;oBACI,GAAGJ,wBAAwB;oBAC3B,MAAM;wBACF,GAAGF,YAAY;wBACfD;oBACJ;gBACJ;gBACA;oBACI,GAAGK,sBAAsB;oBACzB,MAAM;wBACF,GAAGJ,YAAY;wBACfD;oBACJ;gBACJ;aACH;QACL;QAKA,IAAID,aAAa;YACb,MAAMS,4BAA4BC,yBAAyBR;YAC3DM,YAAY,GAAG,CAAC;gBACZ,GAAGC,yBAAyB;gBAC5B,MAAM;oBACF,GAAGP,YAAY;oBACfD;gBACJ;YACJ;QACJ;QAEA,IAAI;YACA,MAAMO,YAAY,OAAO;YACzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQX,MAAM,MAAM;YACxB;QACJ,EAAE,OAAOc,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,4CACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPd;YACJ;QAER;QAEA,OAAOC;IACX;AACJ;AAEO,MAAMe,iBAAiBC,4BAA4B,oBAAoB,CAAC;IAC3E,gBAAgBvB;IAChB,cAAc;QAACwB;QAAmBC;QAAmBC;KAAwB;AACjF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsCreateRevisionFromParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { CreateEntryRevisionFromStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryRevisionFromStorageOperation.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 DdbCreateEntryRevisionFromImpl implements CreateEntryRevisionFromStorageOperation.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: CmsEntryStorageOperationsCreateRevisionFromParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const DdbCreateEntryRevisionFrom: typeof DdbCreateEntryRevisionFromImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryRevisionFromStorageOperation.js").ICreateEntryRevisionFromStorageOperation>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import { CreateEntryRevisionFromStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryRevisionFromStorageOperation.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 { convertToStorageEntry } from "./storageEntryUtils.js";
|
|
9
|
+
class DdbCreateEntryRevisionFromImpl {
|
|
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
|
+
const storageEntry = convertToStorageEntry({
|
|
19
|
+
storageEntry: initialStorageEntry,
|
|
20
|
+
model
|
|
21
|
+
});
|
|
22
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
23
|
+
put: [
|
|
24
|
+
{
|
|
25
|
+
...createEntryRevisionKeys(storageEntry),
|
|
26
|
+
data: {
|
|
27
|
+
...storageEntry
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
...createEntryLatestKeys(storageEntry),
|
|
32
|
+
data: {
|
|
33
|
+
...storageEntry
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
const isPublished = "published" === entry.status;
|
|
39
|
+
if (isPublished) {
|
|
40
|
+
entityBatch.put({
|
|
41
|
+
...createEntryPublishedKeys(storageEntry),
|
|
42
|
+
data: {
|
|
43
|
+
...storageEntry
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const [publishedRevisionStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({
|
|
47
|
+
model,
|
|
48
|
+
ids: [
|
|
49
|
+
entry.id
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
if (publishedRevisionStorageEntry) entityBatch.put({
|
|
53
|
+
...createEntryRevisionKeys(publishedRevisionStorageEntry),
|
|
54
|
+
data: {
|
|
55
|
+
...publishedRevisionStorageEntry,
|
|
56
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
await entityBatch.execute();
|
|
62
|
+
this.dataLoaders.clearAll({
|
|
63
|
+
tenant: entry.tenant
|
|
64
|
+
});
|
|
65
|
+
} catch (ex) {
|
|
66
|
+
throw new error(ex.message || "Could not create revision from given entry.", ex.code || "CREATE_REVISION_ERROR", {
|
|
67
|
+
error: ex,
|
|
68
|
+
entry,
|
|
69
|
+
storageEntry
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return initialStorageEntry;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const DdbCreateEntryRevisionFrom = CreateEntryRevisionFromStorageOperation.createImplementation({
|
|
76
|
+
implementation: DdbCreateEntryRevisionFromImpl,
|
|
77
|
+
dependencies: [
|
|
78
|
+
CmsDdbEntryEntity,
|
|
79
|
+
CmsDdbDataLoaders,
|
|
80
|
+
CmsStorageModelProvider
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
export { DdbCreateEntryRevisionFrom };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=DdbCreateEntryRevisionFrom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbCreateEntryRevisionFrom.js","sources":["../../../src/operations/entry/DdbCreateEntryRevisionFrom.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsCreateRevisionFromParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { CONTENT_ENTRY_STATUS } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CreateEntryRevisionFromStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/CreateEntryRevisionFromStorageOperation.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 { convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbCreateEntryRevisionFromImpl implements CreateEntryRevisionFromStorageOperation.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: CmsEntryStorageOperationsCreateRevisionFromParams<T>\n ) {\n const { entry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n\n /**\n * We need to:\n * - create the main entry item\n * - update the latest entry item to the current one\n * - if the entry's status was set to \"published\":\n * - update the published entry item to the current one\n * - unpublish previously published revision (if any)\n */\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...createEntryRevisionKeys(storageEntry),\n data: {\n ...storageEntry\n }\n },\n {\n ...createEntryLatestKeys(storageEntry),\n data: {\n ...storageEntry\n }\n }\n ]\n });\n\n const isPublished = entry.status === \"published\";\n if (isPublished) {\n entityBatch.put({\n ...createEntryPublishedKeys(storageEntry),\n data: {\n ...storageEntry\n }\n });\n\n // Unpublish previously published revision (if any).\n const [publishedRevisionStorageEntry] =\n await this.dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n if (publishedRevisionStorageEntry) {\n entityBatch.put({\n ...createEntryRevisionKeys(publishedRevisionStorageEntry),\n data: {\n ...publishedRevisionStorageEntry,\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 } 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 initialStorageEntry;\n }\n}\n\nexport const DdbCreateEntryRevisionFrom =\n CreateEntryRevisionFromStorageOperation.createImplementation({\n implementation: DdbCreateEntryRevisionFromImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n });\n"],"names":["DdbCreateEntryRevisionFromImpl","entity","dataLoaders","storageModelProvider","initialModel","params","entry","initialStorageEntry","model","storageEntry","convertToStorageEntry","entityBatch","createEntryRevisionKeys","createEntryLatestKeys","isPublished","createEntryPublishedKeys","publishedRevisionStorageEntry","CONTENT_ENTRY_STATUS","ex","WebinyError","DdbCreateEntryRevisionFrom","CreateEntryRevisionFromStorageOperation","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,MAA4D,EAC9D;QACE,MAAM,EAAEC,KAAK,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACrD,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAEjD,MAAMK,eAAeC,sBAAsB;YACvC,cAAcH;YACdC;QACJ;QAUA,MAAMG,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;YAC/C,KAAK;gBACD;oBACI,GAAGC,wBAAwBH,aAAa;oBACxC,MAAM;wBACF,GAAGA,YAAY;oBACnB;gBACJ;gBACA;oBACI,GAAGI,sBAAsBJ,aAAa;oBACtC,MAAM;wBACF,GAAGA,YAAY;oBACnB;gBACJ;aACH;QACL;QAEA,MAAMK,cAAcR,AAAiB,gBAAjBA,MAAM,MAAM;QAChC,IAAIQ,aAAa;YACbH,YAAY,GAAG,CAAC;gBACZ,GAAGI,yBAAyBN,aAAa;gBACzC,MAAM;oBACF,GAAGA,YAAY;gBACnB;YACJ;YAGA,MAAM,CAACO,8BAA8B,GACjC,MAAM,IAAI,CAAC,WAAW,CAAC,6BAA6B,CAAC;gBACjDR;gBACA,KAAK;oBAACF,MAAM,EAAE;iBAAC;YACnB;YAEJ,IAAIU,+BACAL,YAAY,GAAG,CAAC;gBACZ,GAAGC,wBAAwBI,8BAA8B;gBACzD,MAAM;oBACF,GAAGA,6BAA6B;oBAChC,QAAQC,qBAAqB,WAAW;gBAC5C;YACJ;QAER;QAEA,IAAI;YACA,MAAMN,YAAY,OAAO;YACzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQL,MAAM,MAAM;YACxB;QACJ,EAAE,OAAOY,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,+CACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACPZ;gBACAG;YACJ;QAER;QAIA,OAAOF;IACX;AACJ;AAEO,MAAMa,6BACTC,wCAAwC,oBAAoB,CAAC;IACzD,gBAAgBrB;IAChB,cAAc;QAACsB;QAAmBC;QAAmBC;KAAwB;AACjF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CmsModel, CmsEntryStorageOperationsDeleteParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { DeleteEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryStorageOperation.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 DdbDeleteEntryImpl implements DeleteEntryStorageOperation.Interface {
|
|
7
|
+
private entity;
|
|
8
|
+
private dataLoaders;
|
|
9
|
+
private storageModelProvider;
|
|
10
|
+
constructor(entity: CmsDdbEntryEntity.Interface, dataLoaders: CmsDdbDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface);
|
|
11
|
+
execute(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteParams): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare const DdbDeleteEntry: typeof DdbDeleteEntryImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryStorageOperation.js").IDeleteEntryStorageOperation>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { DeleteEntryStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryStorageOperation.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
|
+
class DdbDeleteEntryImpl {
|
|
8
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
9
|
+
this.entity = entity;
|
|
10
|
+
this.dataLoaders = dataLoaders;
|
|
11
|
+
this.storageModelProvider = storageModelProvider;
|
|
12
|
+
}
|
|
13
|
+
async execute(initialModel, params) {
|
|
14
|
+
const { entry } = params;
|
|
15
|
+
const id = entry.id || entry.entryId;
|
|
16
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
17
|
+
const partitionKey = createPartitionKey({
|
|
18
|
+
id,
|
|
19
|
+
tenant: model.tenant
|
|
20
|
+
});
|
|
21
|
+
let records = [];
|
|
22
|
+
try {
|
|
23
|
+
records = await this.entity.queryAll({
|
|
24
|
+
partitionKey,
|
|
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
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
36
|
+
delete: records.map((item)=>({
|
|
37
|
+
PK: item.PK,
|
|
38
|
+
SK: item.SK
|
|
39
|
+
}))
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
await entityBatch.execute();
|
|
43
|
+
this.dataLoaders.clearAll({
|
|
44
|
+
tenant: entry.tenant
|
|
45
|
+
});
|
|
46
|
+
} catch (ex) {
|
|
47
|
+
throw new error(ex.message || "Could not delete the entry.", ex.code || "DELETE_ENTRY_ERROR", {
|
|
48
|
+
error: ex,
|
|
49
|
+
partitionKey,
|
|
50
|
+
id
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const DdbDeleteEntry = DeleteEntryStorageOperation.createImplementation({
|
|
56
|
+
implementation: DdbDeleteEntryImpl,
|
|
57
|
+
dependencies: [
|
|
58
|
+
CmsDdbEntryEntity,
|
|
59
|
+
CmsDdbDataLoaders,
|
|
60
|
+
CmsStorageModelProvider
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
export { DdbDeleteEntry };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=DdbDeleteEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbDeleteEntry.js","sources":["../../../src/operations/entry/DdbDeleteEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryStorageOperationsDeleteParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { DeleteEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryStorageOperation.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\";\n\nclass DdbDeleteEntryImpl implements DeleteEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteParams) {\n const { entry } = params;\n const id = entry.id || entry.entryId;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const partitionKey = createPartitionKey({\n id,\n tenant: model.tenant\n });\n\n let records: Awaited<ReturnType<typeof this.entity.queryAll>> = [];\n try {\n records = await this.entity.queryAll({\n partitionKey,\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\n }\n );\n }\n\n const entityBatch = this.entity.createEntityWriter({\n delete: records.map(item => {\n return {\n PK: item.PK,\n SK: item.SK\n };\n })\n });\n\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: entry.tenant\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,\n id\n }\n );\n }\n }\n}\n\nexport const DdbDeleteEntry = DeleteEntryStorageOperation.createImplementation({\n implementation: DdbDeleteEntryImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbDeleteEntryImpl","entity","dataLoaders","storageModelProvider","initialModel","params","entry","id","model","partitionKey","createPartitionKey","records","ex","WebinyError","entityBatch","item","DdbDeleteEntry","DeleteEntryStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAEC,MAA6C,EAAE;QACjF,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,KAAKD,MAAM,EAAE,IAAIA,MAAM,OAAO;QACpC,MAAME,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAEjD,MAAMK,eAAeC,mBAAmB;YACpCH;YACA,QAAQC,MAAM,MAAM;QACxB;QAEA,IAAIG,UAA4D,EAAE;QAClE,IAAI;YACAA,UAAU,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACjCF;gBACA,SAAS;oBACL,KAAK;gBACT;YACJ;QACJ,EAAE,OAAOG,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,+BACdA,GAAG,IAAI,IAAI,0BACX;gBACI,OAAOA;gBACPL;YACJ;QAER;QAEA,MAAMO,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;YAC/C,QAAQH,QAAQ,GAAG,CAACI,CAAAA,OACT;oBACH,IAAIA,KAAK,EAAE;oBACX,IAAIA,KAAK,EAAE;gBACf;QAER;QAEA,IAAI;YACA,MAAMD,YAAY,OAAO;YACzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQR,MAAM,MAAM;YACxB;QACJ,EAAE,OAAOM,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,+BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPH;gBACAF;YACJ;QAER;IACJ;AACJ;AAEO,MAAMS,iBAAiBC,4BAA4B,oBAAoB,CAAC;IAC3E,gBAAgBjB;IAChB,cAAc;QAACkB;QAAmBC;QAAmBC;KAAwB;AACjF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsDeleteRevisionParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { DeleteEntryRevisionStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryRevisionStorageOperation.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 DdbDeleteEntryRevisionImpl implements DeleteEntryRevisionStorageOperation.Interface {
|
|
7
|
+
private entity;
|
|
8
|
+
private dataLoaders;
|
|
9
|
+
private storageModelProvider;
|
|
10
|
+
constructor(entity: CmsDdbEntryEntity.Interface, dataLoaders: CmsDdbDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface);
|
|
11
|
+
private getPublishedRevisionByEntryId;
|
|
12
|
+
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteRevisionParams<T>): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare const DdbDeleteEntryRevision: typeof DdbDeleteEntryRevisionImpl & {
|
|
15
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryRevisionStorageOperation.js").IDeleteEntryRevisionStorageOperation>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { DeleteEntryRevisionStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryRevisionStorageOperation.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, createRevisionSortKey } from "./keys.js";
|
|
7
|
+
import { convertFromStorageEntry, convertToStorageEntry } from "./storageEntryUtils.js";
|
|
8
|
+
class DdbDeleteEntryRevisionImpl {
|
|
9
|
+
constructor(entity, dataLoaders, storageModelProvider){
|
|
10
|
+
this.entity = entity;
|
|
11
|
+
this.dataLoaders = dataLoaders;
|
|
12
|
+
this.storageModelProvider = storageModelProvider;
|
|
13
|
+
}
|
|
14
|
+
async getPublishedRevisionByEntryId(initialModel, params) {
|
|
15
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
16
|
+
const items = await this.dataLoaders.getPublishedRevisionByEntryId({
|
|
17
|
+
model,
|
|
18
|
+
ids: [
|
|
19
|
+
params.id
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
const item = items.shift() || null;
|
|
23
|
+
if (!item) return null;
|
|
24
|
+
return convertFromStorageEntry({
|
|
25
|
+
storageEntry: item,
|
|
26
|
+
model
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async execute(initialModel, params) {
|
|
30
|
+
const { entry, latestEntry, latestStorageEntry: initialLatestStorageEntry } = params;
|
|
31
|
+
const model = this.storageModelProvider.getModel(initialModel);
|
|
32
|
+
const partitionKey = createPartitionKey({
|
|
33
|
+
id: entry.id,
|
|
34
|
+
tenant: model.tenant
|
|
35
|
+
});
|
|
36
|
+
const entityBatch = this.entity.createEntityWriter({
|
|
37
|
+
delete: [
|
|
38
|
+
{
|
|
39
|
+
PK: partitionKey,
|
|
40
|
+
SK: createRevisionSortKey(entry)
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
const publishedStorageEntry = await this.getPublishedRevisionByEntryId(model, entry);
|
|
45
|
+
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) entityBatch.delete({
|
|
46
|
+
PK: partitionKey,
|
|
47
|
+
SK: createPublishedSortKey()
|
|
48
|
+
});
|
|
49
|
+
if (initialLatestStorageEntry) {
|
|
50
|
+
const latestStorageEntry = convertToStorageEntry({
|
|
51
|
+
storageEntry: initialLatestStorageEntry,
|
|
52
|
+
model
|
|
53
|
+
});
|
|
54
|
+
entityBatch.put({
|
|
55
|
+
...createEntryLatestKeys(latestStorageEntry),
|
|
56
|
+
data: {
|
|
57
|
+
...latestStorageEntry
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
entityBatch.put({
|
|
61
|
+
...createEntryRevisionKeys(latestStorageEntry),
|
|
62
|
+
data: {
|
|
63
|
+
...latestStorageEntry
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await entityBatch.execute();
|
|
69
|
+
this.dataLoaders.clearAll({
|
|
70
|
+
tenant: entry.tenant
|
|
71
|
+
});
|
|
72
|
+
} catch (ex) {
|
|
73
|
+
throw new error(ex.message, ex.code, {
|
|
74
|
+
error: ex,
|
|
75
|
+
entry,
|
|
76
|
+
latestEntry
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const DdbDeleteEntryRevision = DeleteEntryRevisionStorageOperation.createImplementation({
|
|
82
|
+
implementation: DdbDeleteEntryRevisionImpl,
|
|
83
|
+
dependencies: [
|
|
84
|
+
CmsDdbEntryEntity,
|
|
85
|
+
CmsDdbDataLoaders,
|
|
86
|
+
CmsStorageModelProvider
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
export { DdbDeleteEntryRevision };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=DdbDeleteEntryRevision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbDeleteEntryRevision.js","sources":["../../../src/operations/entry/DdbDeleteEntryRevision.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsDeleteRevisionParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { DeleteEntryRevisionStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteEntryRevisionStorageOperation.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 createRevisionSortKey\n} from \"~/operations/entry/keys.js\";\nimport { convertFromStorageEntry, convertToStorageEntry } from \"./storageEntryUtils.js\";\n\nclass DdbDeleteEntryRevisionImpl implements DeleteEntryRevisionStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEntryEntity.Interface,\n private dataLoaders: CmsDdbDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\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: CmsEntryStorageOperationsDeleteRevisionParams<T>\n ) {\n const { entry, latestEntry, latestStorageEntry: initialLatestStorageEntry } = params;\n\n const model = this.storageModelProvider.getModel(initialModel);\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n const entityBatch = this.entity.createEntityWriter({\n delete: [\n {\n PK: partitionKey,\n SK: createRevisionSortKey(entry)\n }\n ]\n });\n\n const publishedStorageEntry = await this.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 entityBatch.delete({\n PK: partitionKey,\n SK: createPublishedSortKey()\n });\n }\n\n if (initialLatestStorageEntry) {\n const latestStorageEntry = convertToStorageEntry({\n storageEntry: initialLatestStorageEntry,\n model\n });\n entityBatch.put({\n ...createEntryLatestKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry\n }\n });\n\n // Do an update on the latest revision. We need to update the latest revision's\n // entry-level meta fields to match the previous revision's entry-level meta fields.\n entityBatch.put({\n ...createEntryRevisionKeys(latestStorageEntry),\n data: {\n ...latestStorageEntry\n }\n });\n }\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, {\n error: ex,\n entry,\n latestEntry\n });\n }\n }\n}\n\nexport const DdbDeleteEntryRevision = DeleteEntryRevisionStorageOperation.createImplementation({\n implementation: DdbDeleteEntryRevisionImpl,\n dependencies: [CmsDdbEntryEntity, CmsDdbDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbDeleteEntryRevisionImpl","entity","dataLoaders","storageModelProvider","initialModel","params","model","items","item","convertFromStorageEntry","entry","latestEntry","initialLatestStorageEntry","partitionKey","createPartitionKey","entityBatch","createRevisionSortKey","publishedStorageEntry","createPublishedSortKey","latestStorageEntry","convertToStorageEntry","createEntryLatestKeys","createEntryRevisionKeys","ex","WebinyError","DdbDeleteEntryRevision","DeleteEntryRevisionStorageOperation","CmsDdbEntryEntity","CmsDdbDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;;AAmBA,MAAMA;IACF,YACYC,MAAmC,EACnCC,WAAwC,EACxCC,oBAAuD,CACjE;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAc,8BACVC,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,KAAK,MAAM;QAC9B,IAAI,CAACC,MACD,OAAO;QAEX,OAAOC,wBAAwB;YAC3B,cAAcD;YACdF;QACJ;IACJ;IAEA,MAAM,QACFF,YAAsB,EACtBC,MAAwD,EAC1D;QACE,MAAM,EAAEK,KAAK,EAAEC,WAAW,EAAE,oBAAoBC,yBAAyB,EAAE,GAAGP;QAE9E,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACF;QAEjD,MAAMS,eAAeC,mBAAmB;YACpC,IAAIJ,MAAM,EAAE;YACZ,QAAQJ,MAAM,MAAM;QACxB;QAEA,MAAMS,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;YAC/C,QAAQ;gBACJ;oBACI,IAAIF;oBACJ,IAAIG,sBAAsBN;gBAC9B;aACH;QACL;QAEA,MAAMO,wBAAwB,MAAM,IAAI,CAAC,6BAA6B,CAACX,OAAOI;QAK9E,IAAIO,yBAAyBP,MAAM,EAAE,KAAKO,sBAAsB,EAAE,EAC9DF,YAAY,MAAM,CAAC;YACf,IAAIF;YACJ,IAAIK;QACR;QAGJ,IAAIN,2BAA2B;YAC3B,MAAMO,qBAAqBC,sBAAsB;gBAC7C,cAAcR;gBACdN;YACJ;YACAS,YAAY,GAAG,CAAC;gBACZ,GAAGM,sBAAsBF,mBAAmB;gBAC5C,MAAM;oBACF,GAAGA,kBAAkB;gBACzB;YACJ;YAIAJ,YAAY,GAAG,CAAC;gBACZ,GAAGO,wBAAwBH,mBAAmB;gBAC9C,MAAM;oBACF,GAAGA,kBAAkB;gBACzB;YACJ;QACJ;QACA,IAAI;YACA,MAAMJ,YAAY,OAAO;YAEzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQL,MAAM,MAAM;YACxB;QACJ,EAAE,OAAOa,IAAI;YACT,MAAM,IAAIC,MAAYD,GAAG,OAAO,EAAEA,GAAG,IAAI,EAAE;gBACvC,OAAOA;gBACPb;gBACAC;YACJ;QACJ;IACJ;AACJ;AAEO,MAAMc,yBAAyBC,oCAAoC,oBAAoB,CAAC;IAC3F,gBAAgB1B;IAChB,cAAc;QAAC2B;QAAmBC;QAAmBC;KAAwB;AACjF"}
|