@webiny/api-headless-cms-ddb-es 6.6.0-alpha.12 → 6.6.0-alpha.14
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/feature.d.ts +4 -4
- package/feature.js +4 -60
- package/feature.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/operations/entry/DdbEsCreateEntry.d.ts +3 -1
- package/operations/entry/DdbEsCreateEntry.js +18 -8
- package/operations/entry/DdbEsCreateEntry.js.map +1 -1
- package/operations/entry/DdbEsCreateEntryRevisionFrom.d.ts +3 -1
- package/operations/entry/DdbEsCreateEntryRevisionFrom.js +23 -10
- package/operations/entry/DdbEsCreateEntryRevisionFrom.js.map +1 -1
- package/operations/entry/DdbEsDeleteEntry.d.ts +3 -3
- package/operations/entry/DdbEsDeleteEntry.js +7 -7
- package/operations/entry/DdbEsDeleteEntry.js.map +1 -1
- package/operations/entry/DdbEsDeleteEntryRevision.d.ts +3 -1
- package/operations/entry/DdbEsDeleteEntryRevision.js +27 -11
- package/operations/entry/DdbEsDeleteEntryRevision.js.map +1 -1
- package/operations/entry/DdbEsDeleteMultipleEntries.d.ts +3 -1
- package/operations/entry/DdbEsDeleteMultipleEntries.js +14 -7
- package/operations/entry/DdbEsDeleteMultipleEntries.js.map +1 -1
- package/operations/entry/DdbEsGetEntriesByIds.d.ts +3 -1
- package/operations/entry/DdbEsGetEntriesByIds.js +10 -3
- package/operations/entry/DdbEsGetEntriesByIds.js.map +1 -1
- package/operations/entry/DdbEsGetEntry.d.ts +3 -1
- package/operations/entry/DdbEsGetEntry.js +6 -2
- package/operations/entry/DdbEsGetEntry.js.map +1 -1
- package/operations/entry/DdbEsGetLatestEntriesByIds.d.ts +3 -1
- package/operations/entry/DdbEsGetLatestEntriesByIds.js +10 -3
- package/operations/entry/DdbEsGetLatestEntriesByIds.js.map +1 -1
- package/operations/entry/DdbEsGetLatestRevisionByEntryId.d.ts +3 -1
- package/operations/entry/DdbEsGetLatestRevisionByEntryId.js +10 -3
- package/operations/entry/DdbEsGetLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/DdbEsGetPreviousRevision.d.ts +3 -1
- package/operations/entry/DdbEsGetPreviousRevision.js +6 -3
- package/operations/entry/DdbEsGetPreviousRevision.js.map +1 -1
- package/operations/entry/DdbEsGetPublishedEntriesByIds.d.ts +3 -1
- package/operations/entry/DdbEsGetPublishedEntriesByIds.js +10 -3
- package/operations/entry/DdbEsGetPublishedEntriesByIds.js.map +1 -1
- package/operations/entry/DdbEsGetPublishedRevisionByEntryId.d.ts +3 -1
- package/operations/entry/DdbEsGetPublishedRevisionByEntryId.js +10 -3
- package/operations/entry/DdbEsGetPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/DdbEsGetRevisionById.d.ts +3 -1
- package/operations/entry/DdbEsGetRevisionById.js +10 -3
- package/operations/entry/DdbEsGetRevisionById.js.map +1 -1
- package/operations/entry/DdbEsGetRevisions.d.ts +3 -1
- package/operations/entry/DdbEsGetRevisions.js +10 -3
- package/operations/entry/DdbEsGetRevisions.js.map +1 -1
- package/operations/entry/DdbEsGetUniqueFieldValues.d.ts +3 -1
- package/operations/entry/DdbEsGetUniqueFieldValues.js +6 -2
- package/operations/entry/DdbEsGetUniqueFieldValues.js.map +1 -1
- package/operations/entry/DdbEsListEntries.d.ts +3 -1
- package/operations/entry/DdbEsListEntries.js +6 -2
- package/operations/entry/DdbEsListEntries.js.map +1 -1
- package/operations/entry/DdbEsMoveEntry.d.ts +3 -3
- package/operations/entry/DdbEsMoveEntry.js +8 -8
- package/operations/entry/DdbEsMoveEntry.js.map +1 -1
- package/operations/entry/DdbEsMoveToBin.d.ts +3 -1
- package/operations/entry/DdbEsMoveToBin.js +8 -4
- package/operations/entry/DdbEsMoveToBin.js.map +1 -1
- package/operations/entry/DdbEsPublishEntry.d.ts +3 -1
- package/operations/entry/DdbEsPublishEntry.js +31 -15
- package/operations/entry/DdbEsPublishEntry.js.map +1 -1
- package/operations/entry/DdbEsRestoreFromBin.d.ts +3 -1
- package/operations/entry/DdbEsRestoreFromBin.js +8 -4
- package/operations/entry/DdbEsRestoreFromBin.js.map +1 -1
- package/operations/entry/DdbEsUnpublishEntry.d.ts +3 -1
- package/operations/entry/DdbEsUnpublishEntry.js +22 -9
- package/operations/entry/DdbEsUnpublishEntry.js.map +1 -1
- package/operations/entry/DdbEsUpdateEntry.d.ts +3 -1
- package/operations/entry/DdbEsUpdateEntry.js +27 -11
- package/operations/entry/DdbEsUpdateEntry.js.map +1 -1
- package/operations/entry/keys.d.ts +7 -6
- package/operations/entry/keys.js +6 -6
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/DdbEsCreateGroup.d.ts +3 -1
- package/operations/group/DdbEsCreateGroup.js +14 -4
- package/operations/group/DdbEsCreateGroup.js.map +1 -1
- package/operations/group/DdbEsDeleteGroup.d.ts +3 -1
- package/operations/group/DdbEsDeleteGroup.js +10 -3
- package/operations/group/DdbEsDeleteGroup.js.map +1 -1
- package/operations/group/DdbEsGetGroup.d.ts +3 -1
- package/operations/group/DdbEsGetGroup.js +10 -3
- package/operations/group/DdbEsGetGroup.js.map +1 -1
- package/operations/group/DdbEsListGroups.d.ts +3 -1
- package/operations/group/DdbEsListGroups.js +9 -3
- package/operations/group/DdbEsListGroups.js.map +1 -1
- package/operations/group/DdbEsUpdateGroup.d.ts +3 -1
- package/operations/group/DdbEsUpdateGroup.js +14 -4
- package/operations/group/DdbEsUpdateGroup.js.map +1 -1
- package/operations/model/DdbEsCreateModel.d.ts +3 -1
- package/operations/model/DdbEsCreateModel.js +14 -4
- package/operations/model/DdbEsCreateModel.js.map +1 -1
- package/operations/model/DdbEsDeleteModel.d.ts +3 -1
- package/operations/model/DdbEsDeleteModel.js +10 -3
- package/operations/model/DdbEsDeleteModel.js.map +1 -1
- package/operations/model/DdbEsGetModel.d.ts +3 -1
- package/operations/model/DdbEsGetModel.js +10 -3
- package/operations/model/DdbEsGetModel.js.map +1 -1
- package/operations/model/DdbEsListModels.d.ts +4 -2
- package/operations/model/DdbEsListModels.js +10 -5
- package/operations/model/DdbEsListModels.js.map +1 -1
- package/operations/model/DdbEsUpdateModel.d.ts +3 -1
- package/operations/model/DdbEsUpdateModel.js +14 -4
- package/operations/model/DdbEsUpdateModel.js.map +1 -1
- package/package.json +26 -26
- package/registry/CmsEntitiesDbRegistryDecorator.d.ts +4 -4
- package/registry/CmsEntitiesDbRegistryDecorator.js.map +1 -1
- package/storageFeature.d.ts +12 -0
- package/storageFeature.js +25 -0
- package/storageFeature.js.map +1 -0
- package/tablesFeature.d.ts +8 -0
- package/tablesFeature.js +53 -0
- package/tablesFeature.js.map +1 -0
- package/types.js.map +1 -1
|
@@ -7,10 +7,11 @@ import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/share
|
|
|
7
7
|
import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
8
8
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
9
9
|
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
10
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
10
11
|
import { createTransformer } from "./transformations/index.js";
|
|
11
12
|
import { createEntryLatestKeys, createEntryRevisionKeys, createPartitionKey, createPublishedSortKey } from "./keys.js";
|
|
12
13
|
class DdbEsUnpublishEntryImpl {
|
|
13
|
-
constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers){
|
|
14
|
+
constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers, scopeTenant){
|
|
14
15
|
this.entity = entity;
|
|
15
16
|
this.esEntity = esEntity;
|
|
16
17
|
this.dataLoaders = dataLoaders;
|
|
@@ -19,30 +20,41 @@ class DdbEsUnpublishEntryImpl {
|
|
|
19
20
|
this.compressionHandler = compressionHandler;
|
|
20
21
|
this.indexProvider = indexProvider;
|
|
21
22
|
this.valuesModifiers = valuesModifiers;
|
|
23
|
+
this.scopeTenant = scopeTenant;
|
|
22
24
|
}
|
|
23
25
|
async execute(initialModel, params) {
|
|
24
26
|
const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
|
|
27
|
+
const tenant = this.scopeTenant.getId();
|
|
25
28
|
const model = this.storageModelProvider.getModel(initialModel);
|
|
26
29
|
const transformer = createTransformer({
|
|
27
30
|
valuesModifiers: this.valuesModifiers,
|
|
28
31
|
model,
|
|
29
|
-
entry:
|
|
30
|
-
|
|
32
|
+
entry: {
|
|
33
|
+
...initialEntry,
|
|
34
|
+
tenant
|
|
35
|
+
},
|
|
36
|
+
storageEntry: {
|
|
37
|
+
...initialStorageEntry,
|
|
38
|
+
tenant
|
|
39
|
+
},
|
|
31
40
|
fieldIndexRegistry: this.fieldIndexRegistry,
|
|
32
41
|
compressionHandler: this.compressionHandler
|
|
33
42
|
});
|
|
34
43
|
const { entry, storageEntry } = await transformer.transformEntryKeys();
|
|
35
44
|
const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({
|
|
36
|
-
model
|
|
45
|
+
model: {
|
|
46
|
+
tenant,
|
|
47
|
+
modelId: model.modelId
|
|
48
|
+
},
|
|
37
49
|
ids: [
|
|
38
50
|
entry.id
|
|
39
51
|
]
|
|
40
52
|
});
|
|
41
53
|
const partitionKey = createPartitionKey({
|
|
42
54
|
id: entry.id,
|
|
43
|
-
tenant
|
|
55
|
+
tenant
|
|
44
56
|
});
|
|
45
|
-
const entryRevisionKeys = createEntryRevisionKeys(entry);
|
|
57
|
+
const entryRevisionKeys = createEntryRevisionKeys(entry, tenant);
|
|
46
58
|
const entityBatch = this.entity.createEntityWriter({
|
|
47
59
|
put: [
|
|
48
60
|
{
|
|
@@ -70,7 +82,7 @@ class DdbEsUnpublishEntryImpl {
|
|
|
70
82
|
const { index } = await configurations.es({
|
|
71
83
|
model
|
|
72
84
|
});
|
|
73
|
-
const entryLatestKeys = createEntryLatestKeys(storageEntry);
|
|
85
|
+
const entryLatestKeys = createEntryLatestKeys(storageEntry, tenant);
|
|
74
86
|
entityBatch.put({
|
|
75
87
|
...entryLatestKeys,
|
|
76
88
|
data: storageEntry
|
|
@@ -85,7 +97,7 @@ class DdbEsUnpublishEntryImpl {
|
|
|
85
97
|
try {
|
|
86
98
|
await entityBatch.execute();
|
|
87
99
|
this.dataLoaders.clearAll({
|
|
88
|
-
tenant
|
|
100
|
+
tenant
|
|
89
101
|
});
|
|
90
102
|
} catch (ex) {
|
|
91
103
|
throw new error(ex.message || "Could not store unpublished entry records in DynamoDB table.", ex.code || "UNPUBLISH_ERROR", {
|
|
@@ -119,7 +131,8 @@ const DdbEsUnpublishEntry = UnpublishEntryStorageOperation.createImplementation(
|
|
|
119
131
|
{
|
|
120
132
|
multiple: true
|
|
121
133
|
}
|
|
122
|
-
]
|
|
134
|
+
],
|
|
135
|
+
ScopeTenant
|
|
123
136
|
]
|
|
124
137
|
});
|
|
125
138
|
export { DdbEsUnpublishEntry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsUnpublishEntry.js","sources":["../../../src/operations/entry/DdbEsUnpublishEntry.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 { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport {\n createEntryLatestKeys,\n createEntryRevisionKeys,\n createPartitionKey,\n createPublishedSortKey\n} from \"./keys.js\";\n\nclass DdbEsUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUnpublishParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n const { entry, storageEntry } = await transformer.transformEntryKeys();\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsUnpublishEntry.js","sources":["../../../src/operations/entry/DdbEsUnpublishEntry.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 { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport {\n createEntryLatestKeys,\n createEntryRevisionKeys,\n createPartitionKey,\n createPublishedSortKey\n} from \"./keys.js\";\n\nclass DdbEsUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[],\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUnpublishParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const tenant = this.scopeTenant.getId();\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: { ...initialEntry, tenant },\n storageEntry: { ...initialStorageEntry, tenant },\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n const { entry, storageEntry } = await transformer.transformEntryKeys();\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model: { tenant, modelId: model.modelId },\n ids: [entry.id]\n });\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant\n });\n\n const entryRevisionKeys = createEntryRevisionKeys(entry, tenant);\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...entryRevisionKeys,\n data: storageEntry\n }\n ],\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ]\n });\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ]\n });\n\n /**\n * If we are unpublishing the latest revision, let's also update the latest revision entry's status in both DynamoDB tables.\n */\n if (latestStorageEntry?.id === entry.id) {\n const configurations = createConfigurations(this.indexProvider);\n const { index } = await configurations.es({\n model\n });\n\n const entryLatestKeys = createEntryLatestKeys(storageEntry, tenant);\n entityBatch.put({\n ...entryLatestKeys,\n data: storageEntry\n });\n\n const esLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n index,\n data: esLatestData,\n ...entryLatestKeys\n });\n }\n\n /**\n * Finally, execute regular table batch.\n */\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not store unpublished entry records in DynamoDB table.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n /**\n * And Elasticsearch table batch.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not store unpublished entry records in DynamoDB Elasticsearch table.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({\n implementation: DdbEsUnpublishEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }],\n ScopeTenant\n ]\n});\n"],"names":["DdbEsUnpublishEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","scopeTenant","initialModel","params","initialEntry","initialStorageEntry","tenant","model","transformer","createTransformer","entry","storageEntry","latestStorageEntry","partitionKey","createPartitionKey","entryRevisionKeys","createEntryRevisionKeys","entityBatch","createPublishedSortKey","elasticsearchEntityBatch","configurations","createConfigurations","index","entryLatestKeys","createEntryLatestKeys","esLatestData","ex","WebinyError","DdbEsUnpublishEntry","UnpublishEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier","ScopeTenant"],"mappings":";;;;;;;;;;;;AA2BA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,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elProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
7
|
import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
8
8
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
9
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
9
10
|
declare class DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {
|
|
10
11
|
private entity;
|
|
11
12
|
private esEntity;
|
|
@@ -15,7 +16,8 @@ declare class DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.Interf
|
|
|
15
16
|
private compressionHandler;
|
|
16
17
|
private indexProvider;
|
|
17
18
|
private valuesModifiers;
|
|
18
|
-
|
|
19
|
+
private scopeTenant;
|
|
20
|
+
constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, compressionHandler: CompressionHandler.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[], scopeTenant: ScopeTenant.Interface);
|
|
19
21
|
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsUpdateParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
20
22
|
}
|
|
21
23
|
export declare const DdbEsUpdateEntry: typeof DdbEsUpdateEntryImpl & {
|
|
@@ -7,11 +7,12 @@ import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/share
|
|
|
7
7
|
import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
8
8
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
9
9
|
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
10
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
10
11
|
import { createTransformer } from "./transformations/index.js";
|
|
11
12
|
import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createPartitionKey, createRevisionSortKey } from "./keys.js";
|
|
12
13
|
import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
13
14
|
class DdbEsUpdateEntryImpl {
|
|
14
|
-
constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers){
|
|
15
|
+
constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers, scopeTenant){
|
|
15
16
|
this.entity = entity;
|
|
16
17
|
this.esEntity = esEntity;
|
|
17
18
|
this.dataLoaders = dataLoaders;
|
|
@@ -20,32 +21,46 @@ class DdbEsUpdateEntryImpl {
|
|
|
20
21
|
this.compressionHandler = compressionHandler;
|
|
21
22
|
this.indexProvider = indexProvider;
|
|
22
23
|
this.valuesModifiers = valuesModifiers;
|
|
24
|
+
this.scopeTenant = scopeTenant;
|
|
23
25
|
}
|
|
24
26
|
async execute(initialModel, params) {
|
|
25
27
|
const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
|
|
28
|
+
const tenant = this.scopeTenant.getId();
|
|
26
29
|
const model = this.storageModelProvider.getModel(initialModel);
|
|
27
30
|
const transformer = createTransformer({
|
|
28
31
|
valuesModifiers: this.valuesModifiers,
|
|
29
32
|
model,
|
|
30
|
-
entry:
|
|
31
|
-
|
|
33
|
+
entry: {
|
|
34
|
+
...initialEntry,
|
|
35
|
+
tenant
|
|
36
|
+
},
|
|
37
|
+
storageEntry: {
|
|
38
|
+
...initialStorageEntry,
|
|
39
|
+
tenant
|
|
40
|
+
},
|
|
32
41
|
fieldIndexRegistry: this.fieldIndexRegistry,
|
|
33
42
|
compressionHandler: this.compressionHandler
|
|
34
43
|
});
|
|
35
44
|
const { entry, storageEntry } = transformer.transformEntryKeys();
|
|
36
45
|
const isPublished = "published" === entry.status;
|
|
37
46
|
const locked = isPublished ? true : entry.locked;
|
|
38
|
-
const revisionKeys = createEntryRevisionKeys(entry);
|
|
39
|
-
const latestKeys = createEntryLatestKeys(entry);
|
|
40
|
-
const publishedKeys = createEntryPublishedKeys(entry);
|
|
47
|
+
const revisionKeys = createEntryRevisionKeys(entry, tenant);
|
|
48
|
+
const latestKeys = createEntryLatestKeys(entry, tenant);
|
|
49
|
+
const publishedKeys = createEntryPublishedKeys(entry, tenant);
|
|
41
50
|
const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({
|
|
42
|
-
model
|
|
51
|
+
model: {
|
|
52
|
+
tenant,
|
|
53
|
+
modelId: model.modelId
|
|
54
|
+
},
|
|
43
55
|
ids: [
|
|
44
56
|
entry.id
|
|
45
57
|
]
|
|
46
58
|
});
|
|
47
59
|
const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({
|
|
48
|
-
model
|
|
60
|
+
model: {
|
|
61
|
+
tenant,
|
|
62
|
+
modelId: model.modelId
|
|
63
|
+
},
|
|
49
64
|
ids: [
|
|
50
65
|
entry.id
|
|
51
66
|
]
|
|
@@ -99,7 +114,7 @@ class DdbEsUpdateEntryImpl {
|
|
|
99
114
|
...updatedLatestStorageEntry,
|
|
100
115
|
PK: createPartitionKey({
|
|
101
116
|
id: latestStorageEntry.id,
|
|
102
|
-
tenant
|
|
117
|
+
tenant
|
|
103
118
|
}),
|
|
104
119
|
SK: createRevisionSortKey(latestStorageEntry)
|
|
105
120
|
});
|
|
@@ -132,7 +147,7 @@ class DdbEsUpdateEntryImpl {
|
|
|
132
147
|
try {
|
|
133
148
|
await entityBatch.execute();
|
|
134
149
|
this.dataLoaders.clearAll({
|
|
135
|
-
tenant
|
|
150
|
+
tenant
|
|
136
151
|
});
|
|
137
152
|
} catch (ex) {
|
|
138
153
|
throw new error(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
|
|
@@ -167,7 +182,8 @@ const DdbEsUpdateEntry = UpdateEntryStorageOperation.createImplementation({
|
|
|
167
182
|
{
|
|
168
183
|
multiple: true
|
|
169
184
|
}
|
|
170
|
-
]
|
|
185
|
+
],
|
|
186
|
+
ScopeTenant
|
|
171
187
|
]
|
|
172
188
|
});
|
|
173
189
|
export { DdbEsUpdateEntry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsUpdateEntry.js","sources":["../../../src/operations/entry/DdbEsUpdateEntry.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 { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys,\n createPartitionKey,\n createRevisionSortKey\n} from \"./keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IEntryEntityAttributes } from \"~/definitions/types.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\n\nclass DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUpdateParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...publishedKeys,\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n /**\n * If the latest entry is the one being updated, we need to create a new latest entry records.\n */\n if (latestStorageEntry) {\n const updatingLatestRevision = latestStorageEntry.id === entry.id;\n if (updatingLatestRevision) {\n /**\n * First we update the regular DynamoDB table.\n */\n entityBatch.put({\n ...latestKeys,\n data: storageEntry\n });\n\n /**\n * And then update the Elasticsearch table to propagate changes to the Elasticsearch\n */\n const elasticsearchLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: elasticsearchLatestData\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 const updatedLatestStorageEntry: IEntryEntityAttributes = {\n ...latestKeys,\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\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 ...updatedLatestStorageEntry,\n PK: createPartitionKey({\n id: latestStorageEntry.id,\n tenant: model.tenant\n }),\n SK: createRevisionSortKey(latestStorageEntry)\n });\n\n entityBatch.put({\n ...updatedLatestStorageEntry\n });\n\n /**\n * Update the Elasticsearch table to propagate changes to the Elasticsearch.\n */\n const latestEsEntry = await this.esEntity.getClean(latestKeys);\n\n if (latestEsEntry) {\n const latestEsEntryDataDecompressed = (await this.compressionHandler.decompress(\n latestEsEntry.data\n )) as CmsIndexEntry;\n\n const updatedLatestEntry = await this.compressionHandler.compress({\n ...latestEsEntryDataDecompressed,\n ...updatedEntryLevelMetaFields\n });\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: updatedLatestEntry\n });\n }\n }\n }\n\n if (isPublished && publishedStorageEntry?.id === entry.id) {\n const elasticsearchPublishedData =\n await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: elasticsearchPublishedData\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(\n ex.message || \"Could not update entry DynamoDB records.\",\n ex.code || \"UPDATE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry DynamoDB Elasticsearch records.\",\n ex.code || \"UPDATE_ES_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: DdbEsUpdateEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsUpdateEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","isPublished","locked","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","latestStorageEntry","publishedStorageEntry","entityBatch","elasticsearchEntityBatch","configurations","createConfigurations","esIndex","updatingLatestRevision","elasticsearchLatestData","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","updatedLatestStorageEntry","createPartitionKey","createRevisionSortKey","latestEsEntry","latestEsEntryDataDecompressed","updatedLatestEntry","elasticsearchPublishedData","ex","WebinyError","DdbEsUpdateEntry","UpdateEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,aAAwD,EACxDC,eAA6D,CACvE;aARUP,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAgD,EAClD;QACE,MAAM,EAAE,OAAOC,YAAY,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACnE,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAEjD,MAAMK,cAAcC,kBAAkB;YAClC,iBAAiB,IAAI,CAAC,eAAe;YACrCF;YACA,OAAOF;YACP,cAAcC;YACd,oBAAoB,IAAI,CAAC,kBAAkB;YAC3C,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAM,EAAEI,KAAK,EAAEC,YAAY,EAAE,GAAGH,YAAY,kBAAkB;QAE9D,MAAMI,cAAcF,AAAiB,gBAAjBA,MAAM,MAAM;QAChC,MAAMG,SAASD,cAAc,OAAOF,MAAM,MAAM;QAEhD,MAAMI,eAAeC,wBAAwBL;QAC7C,MAAMM,aAAaC,sBAAsBP;Q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;AAEO,MAAMmC,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBhD;IAChB,cAAc;QACViD;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsUpdateEntry.js","sources":["../../../src/operations/entry/DdbEsUpdateEntry.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 { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys,\n createPartitionKey,\n createRevisionSortKey\n} from \"./keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IEntryEntityAttributes } from \"~/definitions/types.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\n\nclass DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[],\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsUpdateParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const tenant = this.scopeTenant.getId();\n const model = this.storageModelProvider.getModel(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: { ...initialEntry, tenant },\n storageEntry: { ...initialStorageEntry, tenant },\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const revisionKeys = createEntryRevisionKeys(entry, tenant);\n const latestKeys = createEntryLatestKeys(entry, tenant);\n const publishedKeys = createEntryPublishedKeys(entry, tenant);\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model: { tenant, modelId: model.modelId },\n ids: [entry.id]\n });\n\n const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({\n model: { tenant, modelId: model.modelId },\n ids: [entry.id]\n });\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...publishedKeys,\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n /**\n * If the latest entry is the one being updated, we need to create a new latest entry records.\n */\n if (latestStorageEntry) {\n const updatingLatestRevision = latestStorageEntry.id === entry.id;\n if (updatingLatestRevision) {\n /**\n * First we update the regular DynamoDB table.\n */\n entityBatch.put({\n ...latestKeys,\n data: storageEntry\n });\n\n /**\n * And then update the Elasticsearch table to propagate changes to the Elasticsearch\n */\n const elasticsearchLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: elasticsearchLatestData\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 const updatedLatestStorageEntry: IEntryEntityAttributes = {\n ...latestKeys,\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\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 ...updatedLatestStorageEntry,\n PK: createPartitionKey({\n id: latestStorageEntry.id,\n tenant\n }),\n SK: createRevisionSortKey(latestStorageEntry)\n });\n\n entityBatch.put({\n ...updatedLatestStorageEntry\n });\n\n /**\n * Update the Elasticsearch table to propagate changes to the Elasticsearch.\n */\n const latestEsEntry = await this.esEntity.getClean(latestKeys);\n\n if (latestEsEntry) {\n const latestEsEntryDataDecompressed = (await this.compressionHandler.decompress(\n latestEsEntry.data\n )) as CmsIndexEntry;\n\n const updatedLatestEntry = await this.compressionHandler.compress({\n ...latestEsEntryDataDecompressed,\n ...updatedEntryLevelMetaFields\n });\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: updatedLatestEntry\n });\n }\n }\n }\n\n if (isPublished && publishedStorageEntry?.id === entry.id) {\n const elasticsearchPublishedData =\n await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: elasticsearchPublishedData\n });\n }\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry DynamoDB records.\",\n ex.code || \"UPDATE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry DynamoDB Elasticsearch records.\",\n ex.code || \"UPDATE_ES_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: DdbEsUpdateEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }],\n ScopeTenant\n ]\n});\n"],"names":["DdbEsUpdateEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","scopeTenant","initialModel","params","initialEntry","initialStorageEntry","tenant","model","transformer","createTransformer","entry","storageEntry","isPublished","locked","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","latestStorageEntry","publishedStorageEntry","entityBatch","elasticsearchEntityBatch","configurations","createConfigurations","esIndex","updatingLatestRevision","elasticsearchLatestData","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","updatedLatestStorageEntry","createPartitionKey","createRevisionSortKey","latestEsEntry","latestEsEntryDataDecompressed","updatedLatestEntry","elasticsearchPublishedData","ex","WebinyError","DdbEsUpdateEntry","UpdateEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier","ScopeTenant"],"mappings":";;;;;;;;;;;;;AAkCA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,aAAwD,EACxDC,eAA6D,EAC7DC,WAAkC,CAC5C;aATUR,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAgD,EAClD;QACE,MAAM,EAAE,OAAOC,YAAY,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACnE,MAAMG,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACL;QAEjD,MAAMM,cAAcC,kBAAkB;YAClC,iBAAiB,IAAI,CAAC,eAAe;YACrCF;YACA,OAAO;gBAAE,GAAGH,YAAY;gBAAEE;YAAO;YACjC,cAAc;gBAAE,GAAGD,mBAAmB;gBAAEC;YAAO;YAC/C,oBAAoB,IAAI,CAAC,kBAAkB;YAC3C,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAM,EAAEI,KAAK,EAAEC,YAAY,EAAE,GAAGH,YAAY,kBAAkB;QAE9D,MAAMI,cAAcF,AAAiB,gBAAjBA,MAAM,MAAM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,IAAI;YACA,MAAMY,yBAAyB,OAAO;QAC1C,EAAE,OAAOgB,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,0DACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACP7B;YACJ;QAER;QACA,OAAOL;IACX;AACJ;AAEO,MAAMoC,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBlD;IAChB,cAAc;QACVmD;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;QACtDC;KACH;AACL"}
|
|
@@ -11,9 +11,12 @@ export declare const createLatestSortKey: () => string;
|
|
|
11
11
|
export declare const createPublishedSortKey: () => string;
|
|
12
12
|
export interface ICreateEntryPublishedKeysParams {
|
|
13
13
|
id: string;
|
|
14
|
-
tenant: string;
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The tenant is passed separately from the record: it is the storage scope's tenant, never one read
|
|
17
|
+
* off the record.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createEntryPublishedKeys: (params: ICreateEntryPublishedKeysParams, tenant: string) => {
|
|
17
20
|
PK: string;
|
|
18
21
|
SK: string;
|
|
19
22
|
TYPE: string;
|
|
@@ -21,9 +24,8 @@ export declare const createEntryPublishedKeys: (params: ICreateEntryPublishedKey
|
|
|
21
24
|
};
|
|
22
25
|
export interface ICreateEntryLatestKeysParams {
|
|
23
26
|
id: string;
|
|
24
|
-
tenant: string;
|
|
25
27
|
}
|
|
26
|
-
export declare const createEntryLatestKeys: (params: ICreateEntryLatestKeysParams) => {
|
|
28
|
+
export declare const createEntryLatestKeys: (params: ICreateEntryLatestKeysParams, tenant: string) => {
|
|
27
29
|
PK: string;
|
|
28
30
|
SK: string;
|
|
29
31
|
TYPE: string;
|
|
@@ -31,10 +33,9 @@ export declare const createEntryLatestKeys: (params: ICreateEntryLatestKeysParam
|
|
|
31
33
|
};
|
|
32
34
|
export interface ICreateRevisionKeysParams {
|
|
33
35
|
id: string;
|
|
34
|
-
tenant: string;
|
|
35
36
|
version: number;
|
|
36
37
|
}
|
|
37
|
-
export declare const createEntryRevisionKeys: (params: ICreateRevisionKeysParams) => {
|
|
38
|
+
export declare const createEntryRevisionKeys: (params: ICreateRevisionKeysParams, tenant: string) => {
|
|
38
39
|
PK: string;
|
|
39
40
|
SK: string;
|
|
40
41
|
TYPE: string;
|
package/operations/entry/keys.js
CHANGED
|
@@ -7,8 +7,8 @@ const createPartitionKey = (params)=>{
|
|
|
7
7
|
const createRevisionSortKey = (params)=>`REV#${zeroPad(params.version)}`;
|
|
8
8
|
const createLatestSortKey = ()=>"L";
|
|
9
9
|
const createPublishedSortKey = ()=>"P";
|
|
10
|
-
const createEntryPublishedKeys = (params)=>{
|
|
11
|
-
const { id
|
|
10
|
+
const createEntryPublishedKeys = (params, tenant)=>{
|
|
11
|
+
const { id } = params;
|
|
12
12
|
return {
|
|
13
13
|
PK: createPartitionKey({
|
|
14
14
|
id,
|
|
@@ -19,8 +19,8 @@ const createEntryPublishedKeys = (params)=>{
|
|
|
19
19
|
GSI_TENANT: tenant
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
const createEntryLatestKeys = (params)=>{
|
|
23
|
-
const { id
|
|
22
|
+
const createEntryLatestKeys = (params, tenant)=>{
|
|
23
|
+
const { id } = params;
|
|
24
24
|
return {
|
|
25
25
|
PK: createPartitionKey({
|
|
26
26
|
id,
|
|
@@ -31,8 +31,8 @@ const createEntryLatestKeys = (params)=>{
|
|
|
31
31
|
GSI_TENANT: tenant
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
|
-
const createEntryRevisionKeys = (params)=>{
|
|
35
|
-
const { id,
|
|
34
|
+
const createEntryRevisionKeys = (params, tenant)=>{
|
|
35
|
+
const { id, version } = params;
|
|
36
36
|
return {
|
|
37
37
|
PK: createPartitionKey({
|
|
38
38
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/keys.js","sources":["../../../src/operations/entry/keys.ts"],"sourcesContent":["import { parseIdentifier, zeroPad } from \"@webiny/utils\";\n\nexport interface PartitionKeyParams {\n id: string;\n tenant: string;\n}\nexport const createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, id: initialId } = params;\n const { id } = parseIdentifier(initialId);\n return `T#${tenant}#CMS#CME#${id}`;\n};\n\nexport interface SortKeyParams {\n version: number;\n}\nexport const createRevisionSortKey = (params: SortKeyParams): string => {\n return `REV#${zeroPad(params.version)}`;\n};\n\nexport const createLatestSortKey = (): string => {\n return \"L\";\n};\n\nexport const createPublishedSortKey = (): string => {\n return \"P\";\n};\n\nexport interface ICreateEntryPublishedKeysParams {\n id: string;\n
|
|
1
|
+
{"version":3,"file":"operations/entry/keys.js","sources":["../../../src/operations/entry/keys.ts"],"sourcesContent":["import { parseIdentifier, zeroPad } from \"@webiny/utils\";\n\nexport interface PartitionKeyParams {\n id: string;\n tenant: string;\n}\nexport const createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, id: initialId } = params;\n const { id } = parseIdentifier(initialId);\n return `T#${tenant}#CMS#CME#${id}`;\n};\n\nexport interface SortKeyParams {\n version: number;\n}\nexport const createRevisionSortKey = (params: SortKeyParams): string => {\n return `REV#${zeroPad(params.version)}`;\n};\n\nexport const createLatestSortKey = (): string => {\n return \"L\";\n};\n\nexport const createPublishedSortKey = (): string => {\n return \"P\";\n};\n\nexport interface ICreateEntryPublishedKeysParams {\n id: string;\n}\n\n/**\n * The tenant is passed separately from the record: it is the storage scope's tenant, never one read\n * off the record.\n */\nexport const createEntryPublishedKeys = (\n params: ICreateEntryPublishedKeysParams,\n tenant: string\n) => {\n const { id } = params;\n return {\n PK: createPartitionKey({\n id,\n tenant\n }),\n SK: createPublishedSortKey(),\n TYPE: `cms.entry.p`,\n GSI_TENANT: tenant\n };\n};\n\nexport interface ICreateEntryLatestKeysParams {\n id: string;\n}\n\nexport const createEntryLatestKeys = (params: ICreateEntryLatestKeysParams, tenant: string) => {\n const { id } = params;\n return {\n PK: createPartitionKey({\n id,\n tenant\n }),\n SK: createLatestSortKey(),\n TYPE: `cms.entry.l`,\n GSI_TENANT: tenant\n };\n};\n\nexport interface ICreateRevisionKeysParams {\n id: string;\n version: number;\n}\n\nexport const createEntryRevisionKeys = (params: ICreateRevisionKeysParams, tenant: string) => {\n const { id, version } = params;\n return {\n PK: createPartitionKey({\n id,\n tenant\n }),\n SK: createRevisionSortKey({\n version\n }),\n TYPE: `cms.entry`,\n GSI_TENANT: tenant\n };\n};\n"],"names":["createPartitionKey","params","tenant","initialId","id","parseIdentifier","createRevisionSortKey","zeroPad","createLatestSortKey","createPublishedSortKey","createEntryPublishedKeys","createEntryLatestKeys","createEntryRevisionKeys","version"],"mappings":";AAMO,MAAMA,qBAAqB,CAACC;IAC/B,MAAM,EAAEC,MAAM,EAAE,IAAIC,SAAS,EAAE,GAAGF;IAClC,MAAM,EAAEG,EAAE,EAAE,GAAGC,gBAAgBF;IAC/B,OAAO,CAAC,EAAE,EAAED,OAAO,SAAS,EAAEE,IAAI;AACtC;AAKO,MAAME,wBAAwB,CAACL,SAC3B,CAAC,IAAI,EAAEM,QAAQN,OAAO,OAAO,GAAG;AAGpC,MAAMO,sBAAsB,IACxB;AAGJ,MAAMC,yBAAyB,IAC3B;AAWJ,MAAMC,2BAA2B,CACpCT,QACAC;IAEA,MAAM,EAAEE,EAAE,EAAE,GAAGH;IACf,OAAO;QACH,IAAID,mBAAmB;YACnBI;YACAF;QACJ;QACA,IAAIO;QACJ,MAAM;QACN,YAAYP;IAChB;AACJ;AAMO,MAAMS,wBAAwB,CAACV,QAAsCC;IACxE,MAAM,EAAEE,EAAE,EAAE,GAAGH;IACf,OAAO;QACH,IAAID,mBAAmB;YACnBI;YACAF;QACJ;QACA,IAAIM;QACJ,MAAM;QACN,YAAYN;IAChB;AACJ;AAOO,MAAMU,0BAA0B,CAACX,QAAmCC;IACvE,MAAM,EAAEE,EAAE,EAAES,OAAO,EAAE,GAAGZ;IACxB,OAAO;QACH,IAAID,mBAAmB;YACnBI;YACAF;QACJ;QACA,IAAII,sBAAsB;YACtBO;QACJ;QACA,MAAM;QACN,YAAYX;IAChB;AACJ"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { CmsGroupStorageOperationsCreateParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import { CreateGroupStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/group/CreateGroupStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsGroupEntity } from "../../abstractions/CmsDdbEsGroupEntity.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
declare class DdbEsCreateGroupImpl implements CreateGroupStorageOperation.Interface {
|
|
5
6
|
private entity;
|
|
6
|
-
|
|
7
|
+
private scopeTenant;
|
|
8
|
+
constructor(entity: CmsDdbEsGroupEntity.Interface, scopeTenant: ScopeTenant.Interface);
|
|
7
9
|
execute(params: CmsGroupStorageOperationsCreateParams): Promise<void>;
|
|
8
10
|
}
|
|
9
11
|
export declare const DdbEsCreateGroup: typeof DdbEsCreateGroupImpl & {
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import error from "@webiny/error";
|
|
2
2
|
import { CreateGroupStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/group/CreateGroupStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsGroupEntity } from "../../abstractions/CmsDdbEsGroupEntity.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
import { createKeys, createType } from "./keys.js";
|
|
5
6
|
class DdbEsCreateGroupImpl {
|
|
6
|
-
constructor(entity){
|
|
7
|
+
constructor(entity, scopeTenant){
|
|
7
8
|
this.entity = entity;
|
|
9
|
+
this.scopeTenant = scopeTenant;
|
|
8
10
|
}
|
|
9
11
|
async execute(params) {
|
|
10
12
|
const { group } = params;
|
|
11
|
-
const
|
|
13
|
+
const tenant = this.scopeTenant.getId();
|
|
14
|
+
const keys = createKeys({
|
|
15
|
+
tenant,
|
|
16
|
+
id: group.id
|
|
17
|
+
});
|
|
12
18
|
try {
|
|
13
19
|
await this.entity.put({
|
|
14
|
-
data:
|
|
20
|
+
data: {
|
|
21
|
+
...group,
|
|
22
|
+
tenant
|
|
23
|
+
},
|
|
15
24
|
TYPE: createType(),
|
|
16
25
|
...keys
|
|
17
26
|
});
|
|
@@ -27,7 +36,8 @@ class DdbEsCreateGroupImpl {
|
|
|
27
36
|
const DdbEsCreateGroup = CreateGroupStorageOperation.createImplementation({
|
|
28
37
|
implementation: DdbEsCreateGroupImpl,
|
|
29
38
|
dependencies: [
|
|
30
|
-
CmsDdbEsGroupEntity
|
|
39
|
+
CmsDdbEsGroupEntity,
|
|
40
|
+
ScopeTenant
|
|
31
41
|
]
|
|
32
42
|
});
|
|
33
43
|
export { DdbEsCreateGroup };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/group/DdbEsCreateGroup.js","sources":["../../../src/operations/group/DdbEsCreateGroup.ts"],"sourcesContent":["import type { CmsGroupStorageOperationsCreateParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { CreateGroupStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/group/CreateGroupStorageOperation.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { createKeys, createType } from \"./keys.js\";\n\nclass DdbEsCreateGroupImpl implements CreateGroupStorageOperation.Interface {\n constructor(private entity: CmsDdbEsGroupEntity.Interface) {}\n\n async execute(params: CmsGroupStorageOperationsCreateParams) {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await this.entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsCreateGroup = CreateGroupStorageOperation.createImplementation({\n implementation: DdbEsCreateGroupImpl,\n dependencies: [CmsDdbEsGroupEntity]\n});\n"],"names":["DdbEsCreateGroupImpl","entity","params","group","keys","createKeys","createType","ex","WebinyError","DdbEsCreateGroup","CreateGroupStorageOperation","CmsDdbEsGroupEntity"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/group/DdbEsCreateGroup.js","sources":["../../../src/operations/group/DdbEsCreateGroup.ts"],"sourcesContent":["import type { CmsGroupStorageOperationsCreateParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { CreateGroupStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/group/CreateGroupStorageOperation.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createKeys, createType } from \"./keys.js\";\n\nclass DdbEsCreateGroupImpl implements CreateGroupStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsGroupEntity.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute(params: CmsGroupStorageOperationsCreateParams) {\n const { group } = params;\n const tenant = this.scopeTenant.getId();\n const keys = createKeys({ tenant, id: group.id });\n try {\n await this.entity.put({\n data: { ...group, tenant },\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsCreateGroup = CreateGroupStorageOperation.createImplementation({\n implementation: DdbEsCreateGroupImpl,\n dependencies: [CmsDdbEsGroupEntity, ScopeTenant]\n});\n"],"names":["DdbEsCreateGroupImpl","entity","scopeTenant","params","group","tenant","keys","createKeys","createType","ex","WebinyError","DdbEsCreateGroup","CreateGroupStorageOperation","CmsDdbEsGroupEntity","ScopeTenant"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,MAAqC,EACrCC,WAAkC,CAC5C;aAFUD,MAAM,GAANA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,MAAMC,OAAOC,WAAW;YAAEF;YAAQ,IAAID,MAAM,EAAE;QAAC;QAC/C,IAAI;YACA,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;gBAClB,MAAM;oBAAE,GAAGA,KAAK;oBAAEC;gBAAO;gBACzB,MAAMG;gBACN,GAAGF,IAAI;YACX;QACJ,EAAE,OAAOG,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPL;gBACAE;YACJ;QAER;IACJ;AACJ;AAEO,MAAMK,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBZ;IAChB,cAAc;QAACa;QAAqBC;KAAY;AACpD"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { CmsGroupStorageOperationsDeleteParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import { DeleteGroupStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/group/DeleteGroupStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsGroupEntity } from "../../abstractions/CmsDdbEsGroupEntity.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
declare class DdbEsDeleteGroupImpl implements DeleteGroupStorageOperation.Interface {
|
|
5
6
|
private entity;
|
|
6
|
-
|
|
7
|
+
private scopeTenant;
|
|
8
|
+
constructor(entity: CmsDdbEsGroupEntity.Interface, scopeTenant: ScopeTenant.Interface);
|
|
7
9
|
execute(params: CmsGroupStorageOperationsDeleteParams): Promise<void>;
|
|
8
10
|
}
|
|
9
11
|
export declare const DdbEsDeleteGroup: typeof DdbEsDeleteGroupImpl & {
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import error from "@webiny/error";
|
|
2
2
|
import { DeleteGroupStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/group/DeleteGroupStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsGroupEntity } from "../../abstractions/CmsDdbEsGroupEntity.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
import { createKeys } from "./keys.js";
|
|
5
6
|
class DdbEsDeleteGroupImpl {
|
|
6
|
-
constructor(entity){
|
|
7
|
+
constructor(entity, scopeTenant){
|
|
7
8
|
this.entity = entity;
|
|
9
|
+
this.scopeTenant = scopeTenant;
|
|
8
10
|
}
|
|
9
11
|
async execute(params) {
|
|
10
12
|
const { group } = params;
|
|
11
|
-
const
|
|
13
|
+
const tenant = this.scopeTenant.getId();
|
|
14
|
+
const keys = createKeys({
|
|
15
|
+
tenant,
|
|
16
|
+
id: group.id
|
|
17
|
+
});
|
|
12
18
|
try {
|
|
13
19
|
await this.entity.delete(keys);
|
|
14
20
|
} catch (ex) {
|
|
@@ -23,7 +29,8 @@ class DdbEsDeleteGroupImpl {
|
|
|
23
29
|
const DdbEsDeleteGroup = DeleteGroupStorageOperation.createImplementation({
|
|
24
30
|
implementation: DdbEsDeleteGroupImpl,
|
|
25
31
|
dependencies: [
|
|
26
|
-
CmsDdbEsGroupEntity
|
|
32
|
+
CmsDdbEsGroupEntity,
|
|
33
|
+
ScopeTenant
|
|
27
34
|
]
|
|
28
35
|
});
|
|
29
36
|
export { DdbEsDeleteGroup };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/group/DdbEsDeleteGroup.js","sources":["../../../src/operations/group/DdbEsDeleteGroup.ts"],"sourcesContent":["import type { CmsGroupStorageOperationsDeleteParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { DeleteGroupStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/group/DeleteGroupStorageOperation.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { createKeys } from \"./keys.js\";\n\nclass DdbEsDeleteGroupImpl implements DeleteGroupStorageOperation.Interface {\n constructor(private entity: CmsDdbEsGroupEntity.Interface) {}\n\n async execute(params: CmsGroupStorageOperationsDeleteParams) {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsDeleteGroup = DeleteGroupStorageOperation.createImplementation({\n implementation: DdbEsDeleteGroupImpl,\n dependencies: [CmsDdbEsGroupEntity]\n});\n"],"names":["DdbEsDeleteGroupImpl","entity","params","group","keys","createKeys","ex","WebinyError","DdbEsDeleteGroup","DeleteGroupStorageOperation","CmsDdbEsGroupEntity"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/group/DdbEsDeleteGroup.js","sources":["../../../src/operations/group/DdbEsDeleteGroup.ts"],"sourcesContent":["import type { CmsGroupStorageOperationsDeleteParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { DeleteGroupStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/group/DeleteGroupStorageOperation.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createKeys } from \"./keys.js\";\n\nclass DdbEsDeleteGroupImpl implements DeleteGroupStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsGroupEntity.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute(params: CmsGroupStorageOperationsDeleteParams) {\n const { group } = params;\n const tenant = this.scopeTenant.getId();\n const keys = createKeys({ tenant, id: group.id });\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsDeleteGroup = DeleteGroupStorageOperation.createImplementation({\n implementation: DdbEsDeleteGroupImpl,\n dependencies: [CmsDdbEsGroupEntity, ScopeTenant]\n});\n"],"names":["DdbEsDeleteGroupImpl","entity","scopeTenant","params","group","tenant","keys","createKeys","ex","WebinyError","DdbEsDeleteGroup","DeleteGroupStorageOperation","CmsDdbEsGroupEntity","ScopeTenant"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,MAAqC,EACrCC,WAAkC,CAC5C;aAFUD,MAAM,GAANA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,MAAMC,OAAOC,WAAW;YAAEF;YAAQ,IAAID,MAAM,EAAE;QAAC;QAC/C,IAAI;YACA,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAACE;QAC7B,EAAE,OAAOE,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPJ;gBACAE;YACJ;QAER;IACJ;AACJ;AAEO,MAAMI,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBX;IAChB,cAAc;QAACY;QAAqBC;KAAY;AACpD"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { CmsGroupStorageOperationsGetParams } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import { GetGroupStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/group/GetGroupStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsGroupEntity } from "../../abstractions/CmsDdbEsGroupEntity.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
declare class DdbEsGetGroupImpl implements GetGroupStorageOperation.Interface {
|
|
5
6
|
private entity;
|
|
6
|
-
|
|
7
|
+
private scopeTenant;
|
|
8
|
+
constructor(entity: CmsDdbEsGroupEntity.Interface, scopeTenant: ScopeTenant.Interface);
|
|
7
9
|
execute(params: CmsGroupStorageOperationsGetParams): Promise<import("@webiny/api-headless-cms/types/modelGroup.js").CmsGroup | null>;
|
|
8
10
|
}
|
|
9
11
|
export declare const DdbEsGetGroup: typeof DdbEsGetGroupImpl & {
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import error from "@webiny/error";
|
|
2
2
|
import { GetGroupStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/group/GetGroupStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsGroupEntity } from "../../abstractions/CmsDdbEsGroupEntity.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
import { createKeys } from "./keys.js";
|
|
5
6
|
class DdbEsGetGroupImpl {
|
|
6
|
-
constructor(entity){
|
|
7
|
+
constructor(entity, scopeTenant){
|
|
7
8
|
this.entity = entity;
|
|
9
|
+
this.scopeTenant = scopeTenant;
|
|
8
10
|
}
|
|
9
11
|
async execute(params) {
|
|
10
|
-
const
|
|
12
|
+
const tenant = this.scopeTenant.getId();
|
|
13
|
+
const keys = createKeys({
|
|
14
|
+
tenant,
|
|
15
|
+
id: params.id
|
|
16
|
+
});
|
|
11
17
|
try {
|
|
12
18
|
const result = await this.entity.get(keys);
|
|
13
19
|
return result?.data || null;
|
|
@@ -23,7 +29,8 @@ class DdbEsGetGroupImpl {
|
|
|
23
29
|
const DdbEsGetGroup = GetGroupStorageOperation.createImplementation({
|
|
24
30
|
implementation: DdbEsGetGroupImpl,
|
|
25
31
|
dependencies: [
|
|
26
|
-
CmsDdbEsGroupEntity
|
|
32
|
+
CmsDdbEsGroupEntity,
|
|
33
|
+
ScopeTenant
|
|
27
34
|
]
|
|
28
35
|
});
|
|
29
36
|
export { DdbEsGetGroup };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/group/DdbEsGetGroup.js","sources":["../../../src/operations/group/DdbEsGetGroup.ts"],"sourcesContent":["import type { CmsGroupStorageOperationsGetParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { GetGroupStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/group/GetGroupStorageOperation.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { createKeys } from \"./keys.js\";\n\nclass DdbEsGetGroupImpl implements GetGroupStorageOperation.Interface {\n constructor(private entity: CmsDdbEsGroupEntity.Interface) {}\n\n async execute(params: CmsGroupStorageOperationsGetParams) {\n const keys = createKeys(params);\n\n try {\n const result = await this.entity.get(keys);\n\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsGetGroup = GetGroupStorageOperation.createImplementation({\n implementation: DdbEsGetGroupImpl,\n dependencies: [CmsDdbEsGroupEntity]\n});\n"],"names":["DdbEsGetGroupImpl","entity","params","keys","createKeys","result","ex","WebinyError","DdbEsGetGroup","GetGroupStorageOperation","CmsDdbEsGroupEntity"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/group/DdbEsGetGroup.js","sources":["../../../src/operations/group/DdbEsGetGroup.ts"],"sourcesContent":["import type { CmsGroupStorageOperationsGetParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { GetGroupStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/group/GetGroupStorageOperation.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createKeys } from \"./keys.js\";\n\nclass DdbEsGetGroupImpl implements GetGroupStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsGroupEntity.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute(params: CmsGroupStorageOperationsGetParams) {\n const tenant = this.scopeTenant.getId();\n const keys = createKeys({ tenant, id: params.id });\n\n try {\n const result = await this.entity.get(keys);\n\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsGetGroup = GetGroupStorageOperation.createImplementation({\n implementation: DdbEsGetGroupImpl,\n dependencies: [CmsDdbEsGroupEntity, ScopeTenant]\n});\n"],"names":["DdbEsGetGroupImpl","entity","scopeTenant","params","tenant","keys","createKeys","result","ex","WebinyError","DdbEsGetGroup","GetGroupStorageOperation","CmsDdbEsGroupEntity","ScopeTenant"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,MAAqC,EACrCC,WAAkC,CAC5C;aAFUD,MAAM,GAANA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,MAA0C,EAAE;QACtD,MAAMC,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,MAAMC,OAAOC,WAAW;YAAEF;YAAQ,IAAID,OAAO,EAAE;QAAC;QAEhD,IAAI;YACA,MAAMI,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAACF;YAErC,OAAOE,QAAQ,QAAQ;QAC3B,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wBACdA,GAAG,IAAI,IAAI,mBACX;gBACI,OAAOA;gBACP,GAAGL,MAAM;gBACTE;YACJ;QAER;IACJ;AACJ;AAEO,MAAMK,gBAAgBC,yBAAyB,oBAAoB,CAAC;IACvE,gBAAgBX;IAChB,cAAc;QAACY;QAAqBC;KAAY;AACpD"}
|