@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
package/feature.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DynamoDB+OpenSearch CMS storage
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* DynamoDB+OpenSearch CMS storage in one container: the tables and entities, and the storage. A
|
|
3
|
+
* composition registers the two apart: the tables and entities once, in the root
|
|
4
|
+
* (`HeadlessCmsDdbEsTablesFeature`), and the storage in each tenant scope on this storage
|
|
5
|
+
* (`HeadlessCmsDdbEsStorageFeature`).
|
|
6
6
|
*/
|
|
7
7
|
export declare const HeadlessCmsDdbEsFeature: {
|
|
8
8
|
name: string;
|
package/feature.js
CHANGED
|
@@ -1,67 +1,11 @@
|
|
|
1
|
-
import { DynamoDBClient, createTable } from "@webiny/db-dynamodb";
|
|
2
|
-
import { ENTITIES } from "./types.js";
|
|
3
1
|
import { createFeature } from "@webiny/feature/api/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { createEntryEntity } from "./definitions/entry.js";
|
|
7
|
-
import { createOpenSearchEntity, createOpenSearchTable } from "@webiny/api-opensearch-aws";
|
|
8
|
-
import { FilterUtilFeature } from "@webiny/db-dynamodb/feature/FilterUtil/feature.js";
|
|
9
|
-
import { CmsDdbEsTable } from "./abstractions/CmsDdbEsTable.js";
|
|
10
|
-
import { CmsDdbEsOsTable } from "./abstractions/CmsDdbEsOsTable.js";
|
|
11
|
-
import { CmsDdbEsGroupEntity } from "./abstractions/CmsDdbEsGroupEntity.js";
|
|
12
|
-
import { CmsDdbEsModelEntity } from "./abstractions/CmsDdbEsModelEntity.js";
|
|
13
|
-
import { CmsDdbEsEntryEntity } from "./abstractions/CmsDdbEsEntryEntity.js";
|
|
14
|
-
import { CmsDdbEsEntriesEsEntity } from "./abstractions/CmsDdbEsEntriesEsEntity.js";
|
|
15
|
-
import { CmsEntryOpenSearchUtilsFeature } from "@webiny/api-headless-cms-utils-os";
|
|
16
|
-
import { FilterRegistriesFeature } from "@webiny/api-headless-cms-storage";
|
|
17
|
-
import { CreateElasticsearchIndexTask } from "./tasks/CreateElasticsearchIndexTask.js";
|
|
18
|
-
import { CmsEntitiesDbRegistryDecorator } from "./registry/CmsEntitiesDbRegistryDecorator.js";
|
|
19
|
-
import { DdbEsGroupStorageOpsFeature } from "./operations/group/feature.js";
|
|
20
|
-
import { DdbEsModelStorageOpsFeature } from "./operations/model/feature.js";
|
|
21
|
-
import { DdbEsEntryStorageOpsFeature } from "./operations/entry/feature.js";
|
|
2
|
+
import { HeadlessCmsDdbEsTablesFeature } from "./tablesFeature.js";
|
|
3
|
+
import { HeadlessCmsDdbEsStorageFeature } from "./storageFeature.js";
|
|
22
4
|
const HeadlessCmsDdbEsFeature = createFeature({
|
|
23
5
|
name: "cms.storageOperations.openSearch",
|
|
24
6
|
register: (container)=>{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const documentClient = db.client;
|
|
28
|
-
const tableInstance = createTable({
|
|
29
|
-
name: process.env.DB_TABLE,
|
|
30
|
-
documentClient
|
|
31
|
-
});
|
|
32
|
-
const tableElasticsearchInstance = createOpenSearchTable({
|
|
33
|
-
name: process.env.DB_TABLE_OPENSEARCH,
|
|
34
|
-
documentClient
|
|
35
|
-
});
|
|
36
|
-
const groupEntity = createGroupEntity({
|
|
37
|
-
entityName: ENTITIES.GROUPS,
|
|
38
|
-
table: tableInstance
|
|
39
|
-
});
|
|
40
|
-
const modelEntity = createModelEntity({
|
|
41
|
-
entityName: ENTITIES.MODELS,
|
|
42
|
-
table: tableInstance
|
|
43
|
-
});
|
|
44
|
-
const entryEntity = createEntryEntity({
|
|
45
|
-
entityName: ENTITIES.ENTRIES,
|
|
46
|
-
table: tableInstance
|
|
47
|
-
});
|
|
48
|
-
const entriesEsEntity = createOpenSearchEntity({
|
|
49
|
-
entityName: ENTITIES.ENTRIES_ES,
|
|
50
|
-
table: tableElasticsearchInstance
|
|
51
|
-
});
|
|
52
|
-
container.registerInstance(CmsDdbEsTable, tableInstance);
|
|
53
|
-
container.registerInstance(CmsDdbEsOsTable, tableElasticsearchInstance);
|
|
54
|
-
container.registerInstance(CmsDdbEsGroupEntity, groupEntity);
|
|
55
|
-
container.registerInstance(CmsDdbEsModelEntity, modelEntity);
|
|
56
|
-
container.registerInstance(CmsDdbEsEntryEntity, entryEntity);
|
|
57
|
-
container.registerInstance(CmsDdbEsEntriesEsEntity, entriesEsEntity);
|
|
58
|
-
CmsEntryOpenSearchUtilsFeature.register(container);
|
|
59
|
-
FilterRegistriesFeature.register(container);
|
|
60
|
-
container.register(CreateElasticsearchIndexTask);
|
|
61
|
-
container.registerDecorator(CmsEntitiesDbRegistryDecorator);
|
|
62
|
-
DdbEsGroupStorageOpsFeature.register(container);
|
|
63
|
-
DdbEsModelStorageOpsFeature.register(container);
|
|
64
|
-
DdbEsEntryStorageOpsFeature.register(container);
|
|
7
|
+
HeadlessCmsDdbEsTablesFeature.register(container);
|
|
8
|
+
HeadlessCmsDdbEsStorageFeature.register(container);
|
|
65
9
|
}
|
|
66
10
|
});
|
|
67
11
|
export { HeadlessCmsDdbEsFeature };
|
package/feature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.js","sources":["../src/feature.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"feature.js","sources":["../src/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { HeadlessCmsDdbEsTablesFeature } from \"./tablesFeature.js\";\nimport { HeadlessCmsDdbEsStorageFeature } from \"./storageFeature.js\";\n\n/**\n * DynamoDB+OpenSearch CMS storage in one container: the tables and entities, and the storage. A\n * composition registers the two apart: the tables and entities once, in the root\n * (`HeadlessCmsDdbEsTablesFeature`), and the storage in each tenant scope on this storage\n * (`HeadlessCmsDdbEsStorageFeature`).\n */\nexport const HeadlessCmsDdbEsFeature = createFeature({\n name: \"cms.storageOperations.openSearch\",\n register: container => {\n HeadlessCmsDdbEsTablesFeature.register(container);\n HeadlessCmsDdbEsStorageFeature.register(container);\n }\n});\n"],"names":["HeadlessCmsDdbEsFeature","createFeature","container","HeadlessCmsDdbEsTablesFeature","HeadlessCmsDdbEsStorageFeature"],"mappings":";;;AAUO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAAUC,CAAAA;QACNC,8BAA8B,QAAQ,CAACD;QACvCE,+BAA+B,QAAQ,CAACF;IAC5C;AACJ"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
|
6
6
|
import { CmsStorageModelProvider } 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 DdbEsCreateEntryImpl implements CreateEntryStorageOperation.Interface {
|
|
10
11
|
private entity;
|
|
11
12
|
private esEntity;
|
|
@@ -15,7 +16,8 @@ declare class DdbEsCreateEntryImpl implements CreateEntryStorageOperation.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: CmsEntryStorageOperationsCreateParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
20
22
|
}
|
|
21
23
|
export declare const DdbEsCreateEntry: typeof DdbEsCreateEntryImpl & {
|
|
@@ -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, createEntryPublishedKeys, createEntryRevisionKeys } from "./keys.js";
|
|
12
13
|
class DdbEsCreateEntryImpl {
|
|
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,9 +20,11 @@ class DdbEsCreateEntryImpl {
|
|
|
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 isPublished = "published" === initialEntry.status;
|
|
27
30
|
const locked = isPublished ? true : initialEntry.locked;
|
|
@@ -30,8 +33,14 @@ class DdbEsCreateEntryImpl {
|
|
|
30
33
|
const transformer = createTransformer({
|
|
31
34
|
fieldIndexRegistry: this.fieldIndexRegistry,
|
|
32
35
|
model,
|
|
33
|
-
entry:
|
|
34
|
-
|
|
36
|
+
entry: {
|
|
37
|
+
...initialEntry,
|
|
38
|
+
tenant
|
|
39
|
+
},
|
|
40
|
+
storageEntry: {
|
|
41
|
+
...initialStorageEntry,
|
|
42
|
+
tenant
|
|
43
|
+
},
|
|
35
44
|
compressionHandler: this.compressionHandler,
|
|
36
45
|
valuesModifiers: this.valuesModifiers
|
|
37
46
|
});
|
|
@@ -41,9 +50,9 @@ class DdbEsCreateEntryImpl {
|
|
|
41
50
|
const { index: esIndex } = await configurations.es({
|
|
42
51
|
model
|
|
43
52
|
});
|
|
44
|
-
const revisionKeys = createEntryRevisionKeys(entry);
|
|
45
|
-
const latestKeys = createEntryLatestKeys(entry);
|
|
46
|
-
const publishedKeys = createEntryPublishedKeys(entry);
|
|
53
|
+
const revisionKeys = createEntryRevisionKeys(entry, tenant);
|
|
54
|
+
const latestKeys = createEntryLatestKeys(entry, tenant);
|
|
55
|
+
const publishedKeys = createEntryPublishedKeys(entry, tenant);
|
|
47
56
|
const entityBatch = this.entity.createEntityWriter({
|
|
48
57
|
put: [
|
|
49
58
|
{
|
|
@@ -72,7 +81,7 @@ class DdbEsCreateEntryImpl {
|
|
|
72
81
|
try {
|
|
73
82
|
await entityBatch.execute();
|
|
74
83
|
this.dataLoaders.clearAll({
|
|
75
|
-
tenant
|
|
84
|
+
tenant
|
|
76
85
|
});
|
|
77
86
|
} catch (ex) {
|
|
78
87
|
throw new error(ex.message || "Could not insert entry data into the DynamoDB table.", ex.code || "CREATE_ENTRY_ERROR", {
|
|
@@ -126,7 +135,8 @@ const DdbEsCreateEntry = CreateEntryStorageOperation.createImplementation({
|
|
|
126
135
|
{
|
|
127
136
|
multiple: true
|
|
128
137
|
}
|
|
129
|
-
]
|
|
138
|
+
],
|
|
139
|
+
ScopeTenant
|
|
130
140
|
]
|
|
131
141
|
});
|
|
132
142
|
export { DdbEsCreateEntry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsCreateEntry.js","sources":["../../../src/operations/entry/DdbEsCreateEntry.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 { 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} from \"./keys.js\";\n\nclass DdbEsCreateEntryImpl implements CreateEntryStorageOperation.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: CmsEntryStorageOperationsCreateParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const isPublished = initialEntry.status === \"published\";\n const locked = isPublished ? true : initialEntry.locked;\n\n initialEntry.locked = locked;\n initialStorageEntry.locked = locked;\n\n const transformer = createTransformer<T>({\n fieldIndexRegistry: this.fieldIndexRegistry,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n compressionHandler: this.compressionHandler,\n valuesModifiers: this.valuesModifiers\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const esEntry = transformer.transformToIndex();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n },\n {\n ...latestKeys,\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 try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsCreateEntry.js","sources":["../../../src/operations/entry/DdbEsCreateEntry.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 { 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} from \"./keys.js\";\n\nclass DdbEsCreateEntryImpl implements CreateEntryStorageOperation.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: CmsEntryStorageOperationsCreateParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const tenant = this.scopeTenant.getId();\n\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const isPublished = initialEntry.status === \"published\";\n const locked = isPublished ? true : initialEntry.locked;\n\n initialEntry.locked = locked;\n initialStorageEntry.locked = locked;\n\n const transformer = createTransformer<T>({\n fieldIndexRegistry: this.fieldIndexRegistry,\n model,\n /**\n * Copies with the scope's tenant: the caller's objects are left as they are, the stored\n * and indexed records carry the scope's tenant.\n */\n entry: { ...initialEntry, tenant },\n storageEntry: { ...initialStorageEntry, tenant },\n compressionHandler: this.compressionHandler,\n valuesModifiers: this.valuesModifiers\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const esEntry = transformer.transformToIndex();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n const revisionKeys = createEntryRevisionKeys(entry, tenant);\n const latestKeys = createEntryLatestKeys(entry, tenant);\n const publishedKeys = createEntryPublishedKeys(entry, tenant);\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n },\n {\n ...latestKeys,\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 try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert entry data into the DynamoDB table.\",\n ex.code || \"CREATE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n const esLatestData = await transformer.getElasticsearchLatestEntryData();\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n put: [\n {\n ...latestKeys,\n index: esIndex,\n data: esLatestData\n }\n ]\n });\n\n if (isPublished) {\n const esPublishedData = await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: esPublishedData\n });\n }\n\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert entry data into the Elasticsearch DynamoDB table.\",\n ex.code || \"CREATE_ES_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n esEntry\n }\n );\n }\n\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsCreateEntry = CreateEntryStorageOperation.createImplementation({\n implementation: DdbEsCreateEntryImpl,\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":["DdbEsCreateEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","scopeTenant","initialModel","params","initialEntry","initialStorageEntry","tenant","model","isPublished","locked","transformer","createTransformer","entry","storageEntry","esEntry","configurations","createConfigurations","esIndex","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","entityBatch","ex","WebinyError","esLatestData","elasticsearchEntityBatch","esPublishedData","DdbEsCreateEntry","CreateEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier","ScopeTenant"],"mappings":";;;;;;;;;;;;AA0BA,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;QAErC,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIL;QAEpD,MAAMM,cAAcJ,AAAwB,gBAAxBA,aAAa,MAAM;QACvC,MAAMK,SAASD,cAAc,OAAOJ,aAAa,MAAM;QAEvDA,aAAa,MAAM,GAAGK;QACtBJ,oBAAoB,MAAM,GAAGI;QAE7B,MAAMC,cAAcC,kBAAqB;YACrC,oBAAoB,IAAI,CAAC,kBAAkB;YAC3CJ;YAKA,OAAO;gBAAE,GAAGH,YAAY;gBAAEE;YAAO;YACjC,cAAc;gBAAE,GAAGD,mBAAmB;gBAAEC;YAAO;YAC/C,oBAAoB,IAAI,CAAC,kBAAkB;YAC3C,iBAAiB,IAAI,CAAC,eAAe;QACzC;QAEA,MAAM,EAAEM,KAAK,EAAEC,YAAY,EAAE,GAAGH,YAAY,kBAAk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,yBAAyB,OAAO;QAC1C,EAAE,OAAOH,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,sEACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACPb;gBACAE;YACJ;QAER;QAEA,OAAOT;IACX;AACJ;AAEO,MAAMyB,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBvC;IAChB,cAAc;QACVwC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;QACtDC;KACH;AACL"}
|
|
@@ -6,6 +6,7 @@ import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
|
6
6
|
import { CmsStorageModelProvider } 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 DdbEsCreateEntryRevisionFromImpl implements CreateEntryRevisionFromStorageOperation.Interface {
|
|
10
11
|
private entity;
|
|
11
12
|
private esEntity;
|
|
@@ -15,7 +16,8 @@ declare class DdbEsCreateEntryRevisionFromImpl implements CreateEntryRevisionFro
|
|
|
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: CmsEntryStorageOperationsCreateRevisionFromParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
20
22
|
}
|
|
21
23
|
export declare const DdbEsCreateEntryRevisionFrom: typeof DdbEsCreateEntryRevisionFromImpl & {
|
|
@@ -8,10 +8,11 @@ import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/share
|
|
|
8
8
|
import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
9
9
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
10
10
|
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
11
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
11
12
|
import { createTransformer } from "./transformations/index.js";
|
|
12
13
|
import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys } from "./keys.js";
|
|
13
14
|
class DdbEsCreateEntryRevisionFromImpl {
|
|
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,22 +21,30 @@ class DdbEsCreateEntryRevisionFromImpl {
|
|
|
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
|
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
|
valuesModifiers: this.valuesModifiers
|
|
34
43
|
});
|
|
35
44
|
const { entry, storageEntry } = transformer.transformEntryKeys();
|
|
36
|
-
const revisionKeys = createEntryRevisionKeys(entry);
|
|
37
|
-
const latestKeys = createEntryLatestKeys(entry);
|
|
38
|
-
const publishedKeys = createEntryPublishedKeys(entry);
|
|
45
|
+
const revisionKeys = createEntryRevisionKeys(entry, tenant);
|
|
46
|
+
const latestKeys = createEntryLatestKeys(entry, tenant);
|
|
47
|
+
const publishedKeys = createEntryPublishedKeys(entry, tenant);
|
|
39
48
|
const isPublished = "published" === entry.status;
|
|
40
49
|
const esLatestData = await transformer.getElasticsearchLatestEntryData();
|
|
41
50
|
const entityBatch = this.entity.createEntityWriter({
|
|
@@ -56,13 +65,16 @@ class DdbEsCreateEntryRevisionFromImpl {
|
|
|
56
65
|
data: storageEntry
|
|
57
66
|
});
|
|
58
67
|
const [publishedRevisionStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({
|
|
59
|
-
model
|
|
68
|
+
model: {
|
|
69
|
+
tenant,
|
|
70
|
+
modelId: model.modelId
|
|
71
|
+
},
|
|
60
72
|
ids: [
|
|
61
73
|
entry.id
|
|
62
74
|
]
|
|
63
75
|
});
|
|
64
76
|
if (publishedRevisionStorageEntry) {
|
|
65
|
-
const publishedRevisionKey = createEntryRevisionKeys(publishedRevisionStorageEntry);
|
|
77
|
+
const publishedRevisionKey = createEntryRevisionKeys(publishedRevisionStorageEntry, tenant);
|
|
66
78
|
entityBatch.put({
|
|
67
79
|
...publishedRevisionKey,
|
|
68
80
|
data: {
|
|
@@ -75,7 +87,7 @@ class DdbEsCreateEntryRevisionFromImpl {
|
|
|
75
87
|
try {
|
|
76
88
|
await entityBatch.execute();
|
|
77
89
|
this.dataLoaders.clearAll({
|
|
78
|
-
tenant
|
|
90
|
+
tenant
|
|
79
91
|
});
|
|
80
92
|
} catch (ex) {
|
|
81
93
|
throw new error(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
@@ -131,7 +143,8 @@ const DdbEsCreateEntryRevisionFrom = CreateEntryRevisionFromStorageOperation.cre
|
|
|
131
143
|
{
|
|
132
144
|
multiple: true
|
|
133
145
|
}
|
|
134
|
-
]
|
|
146
|
+
],
|
|
147
|
+
ScopeTenant
|
|
135
148
|
]
|
|
136
149
|
});
|
|
137
150
|
export { DdbEsCreateEntryRevisionFrom };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsCreateEntryRevisionFrom.js","sources":["../../../src/operations/entry/DdbEsCreateEntryRevisionFrom.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 { 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} from \"./keys.js\";\n\nclass DdbEsCreateEntryRevisionFromImpl\n implements CreateEntryRevisionFromStorageOperation.Interface\n{\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: CmsEntryStorageOperationsCreateRevisionFromParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const transformer = createTransformer<T>({\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler,\n valuesModifiers: this.valuesModifiers\n });\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n // We'll need this flag below.\n const isPublished = entry.status === \"published\";\n\n const esLatestData = await transformer.getElasticsearchLatestEntryData();\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: storageEntry\n },\n {\n ...latestKeys,\n data: storageEntry\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...publishedKeys,\n data: storageEntry\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 const publishedRevisionKey = createEntryRevisionKeys(publishedRevisionStorageEntry);\n entityBatch.put({\n ...publishedRevisionKey,\n data: {\n ...publishedRevisionStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\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(\n ex.message || \"Could not create revision from given entry in the DynamoDB table.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n put: [\n {\n ...latestKeys,\n index: esIndex,\n data: esLatestData\n }\n ]\n });\n\n if (isPublished) {\n const esPublishedData = await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: esPublishedData\n });\n }\n\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update latest entry in the DynamoDB Elasticsearch table.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry\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 DdbEsCreateEntryRevisionFrom =\n CreateEntryRevisionFromStorageOperation.createImplementation({\n implementation: DdbEsCreateEntryRevisionFromImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n });\n"],"names":["DdbEsCreateEntryRevisionFromImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","isPublished","esLatestData","entityBatch","publishedRevisionStorageEntry","publishedRevisionKey","CONTENT_ENTRY_STATUS","ex","WebinyError","configurations","createConfigurations","esIndex","elasticsearchEntityBatch","esPublishedData","DdbEsCreateEntryRevisionFrom","CreateEntryRevisionFromStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;;AA0BA,MAAMA;IAGF,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,MAA4D,EAC9D;QACE,MAAM,EA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xB;QACJ,EAAE,OAAOc,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,qEACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACPd;gBACAC;YACJ;QAER;QAEA,MAAMe,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAE,OAAOC,OAAO,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YAC/CnB;QACJ;QAEA,MAAMsB,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YAC9D,KAAK;gBACD;oBACI,GAAGf,UAAU;oBACb,OAAOc;oBACP,MAAMT;gBACV;aACH;QACL;QAEA,IAAID,aAAa;YACb,MAAMY,kBAAkB,MAAMtB,YAAY,kCAAkC;YAC5EqB,yBAAyB,GAAG,CAAC;gBACzB,GAAGb,aAAa;gBAChB,OAAOY;gBACP,MAAME;YACV;QACJ;QAEA,IAAI;YACA,MAAMD,yBAAyB,OAAO;QAC1C,EAAE,OAAOL,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,sEACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACPd;YACJ;QAER;QAIA,OAAOJ;IACX;AACJ;AAEO,MAAMyB,+BACTC,wCAAwC,oBAAoB,CAAC;IACzD,gBAAgBtC;IAChB,cAAc;QACVuC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsCreateEntryRevisionFrom.js","sources":["../../../src/operations/entry/DdbEsCreateEntryRevisionFrom.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 { 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} from \"./keys.js\";\n\nclass DdbEsCreateEntryRevisionFromImpl\n implements CreateEntryRevisionFromStorageOperation.Interface\n{\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: CmsEntryStorageOperationsCreateRevisionFromParams<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<T>({\n model,\n entry: { ...initialEntry, tenant },\n storageEntry: { ...initialStorageEntry, tenant },\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler,\n valuesModifiers: this.valuesModifiers\n });\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const revisionKeys = createEntryRevisionKeys(entry, tenant);\n const latestKeys = createEntryLatestKeys(entry, tenant);\n const publishedKeys = createEntryPublishedKeys(entry, tenant);\n\n // We'll need this flag below.\n const isPublished = entry.status === \"published\";\n\n const esLatestData = await transformer.getElasticsearchLatestEntryData();\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: storageEntry\n },\n {\n ...latestKeys,\n data: storageEntry\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...publishedKeys,\n data: storageEntry\n });\n\n // Unpublish previously published revision (if any).\n const [publishedRevisionStorageEntry] =\n await this.dataLoaders.getPublishedRevisionByEntryId({\n model: { tenant, modelId: model.modelId },\n ids: [entry.id]\n });\n\n if (publishedRevisionStorageEntry) {\n const publishedRevisionKey = createEntryRevisionKeys(\n publishedRevisionStorageEntry,\n tenant\n );\n entityBatch.put({\n ...publishedRevisionKey,\n data: {\n ...publishedRevisionStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\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 create revision from given entry in the DynamoDB table.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n put: [\n {\n ...latestKeys,\n index: esIndex,\n data: esLatestData\n }\n ]\n });\n\n if (isPublished) {\n const esPublishedData = await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: esPublishedData\n });\n }\n\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update latest entry in the DynamoDB Elasticsearch table.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry\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 DdbEsCreateEntryRevisionFrom =\n CreateEntryRevisionFromStorageOperation.createImplementation({\n implementation: DdbEsCreateEntryRevisionFromImpl,\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":["DdbEsCreateEntryRevisionFromImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","scopeTenant","initialModel","params","initialEntry","initialStorageEntry","tenant","model","transformer","createTransformer","entry","storageEntry","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","isPublished","esLatestData","entityBatch","publishedRevisionStorageEntry","publishedRevisionKey","CONTENT_ENTRY_STATUS","ex","WebinyError","configurations","createConfigurations","esIndex","elasticsearchEntityBatch","esPublishedData","DdbEsCreateEntryRevisionFrom","CreateEntryRevisionFromStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier","ScopeTenant"],"mappings":";;;;;;;;;;;;;AA2BA,MAAMA;IAGF,YACYC,MAAqC,E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EACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACPd;YACJ;QAER;QAIA,OAAOL;IACX;AACJ;AAEO,MAAM0B,+BACTC,wCAAwC,oBAAoB,CAAC;IACzD,gBAAgBxC;IAChB,cAAc;QACVyC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;QACtDC;KACH;AACL"}
|
|
@@ -3,13 +3,13 @@ import { DeleteEntryStorageOperation } from "@webiny/api-headless-cms/features/s
|
|
|
3
3
|
import { CmsDdbEsEntryEntity } from "../../abstractions/CmsDdbEsEntryEntity.js";
|
|
4
4
|
import { CmsDdbEsEntriesEsEntity } from "../../abstractions/CmsDdbEsEntriesEsEntity.js";
|
|
5
5
|
import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
7
7
|
declare class DdbEsDeleteEntryImpl implements DeleteEntryStorageOperation.Interface {
|
|
8
8
|
private entity;
|
|
9
9
|
private esEntity;
|
|
10
10
|
private dataLoaders;
|
|
11
|
-
private
|
|
12
|
-
constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface,
|
|
11
|
+
private scopeTenant;
|
|
12
|
+
constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface, scopeTenant: ScopeTenant.Interface);
|
|
13
13
|
execute(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteParams): Promise<void>;
|
|
14
14
|
}
|
|
15
15
|
export declare const DdbEsDeleteEntry: typeof DdbEsDeleteEntryImpl & {
|
|
@@ -3,22 +3,22 @@ import { DeleteEntryStorageOperation } from "@webiny/api-headless-cms/features/s
|
|
|
3
3
|
import { CmsDdbEsEntryEntity } from "../../abstractions/CmsDdbEsEntryEntity.js";
|
|
4
4
|
import { CmsDdbEsEntriesEsEntity } from "../../abstractions/CmsDdbEsEntriesEsEntity.js";
|
|
5
5
|
import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
7
7
|
import { createPartitionKey } from "./keys.js";
|
|
8
8
|
class DdbEsDeleteEntryImpl {
|
|
9
|
-
constructor(entity, esEntity, dataLoaders,
|
|
9
|
+
constructor(entity, esEntity, dataLoaders, scopeTenant){
|
|
10
10
|
this.entity = entity;
|
|
11
11
|
this.esEntity = esEntity;
|
|
12
12
|
this.dataLoaders = dataLoaders;
|
|
13
|
-
this.
|
|
13
|
+
this.scopeTenant = scopeTenant;
|
|
14
14
|
}
|
|
15
15
|
async execute(initialModel, params) {
|
|
16
16
|
const { entry } = params;
|
|
17
|
+
const tenant = this.scopeTenant.getId();
|
|
17
18
|
const id = entry.id || entry.entryId;
|
|
18
|
-
const model = this.storageModelProvider.getModel(initialModel);
|
|
19
19
|
const partitionKey = createPartitionKey({
|
|
20
20
|
id,
|
|
21
|
-
tenant
|
|
21
|
+
tenant
|
|
22
22
|
});
|
|
23
23
|
const items = await this.entity.queryAll({
|
|
24
24
|
partitionKey,
|
|
@@ -47,7 +47,7 @@ class DdbEsDeleteEntryImpl {
|
|
|
47
47
|
try {
|
|
48
48
|
await entityBatch.execute();
|
|
49
49
|
this.dataLoaders.clearAll({
|
|
50
|
-
tenant
|
|
50
|
+
tenant
|
|
51
51
|
});
|
|
52
52
|
} catch (ex) {
|
|
53
53
|
throw new error(ex.message || "Could not destroy entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
|
|
@@ -71,7 +71,7 @@ const DdbEsDeleteEntry = DeleteEntryStorageOperation.createImplementation({
|
|
|
71
71
|
CmsDdbEsEntryEntity,
|
|
72
72
|
CmsDdbEsEntriesEsEntity,
|
|
73
73
|
CmsDdbEsDataLoaders,
|
|
74
|
-
|
|
74
|
+
ScopeTenant
|
|
75
75
|
]
|
|
76
76
|
});
|
|
77
77
|
export { DdbEsDeleteEntry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsDeleteEntry.js","sources":["../../../src/operations/entry/DdbEsDeleteEntry.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 { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsDeleteEntry.js","sources":["../../../src/operations/entry/DdbEsDeleteEntry.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 { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createPartitionKey } from \"./keys.js\";\n\nclass DdbEsDeleteEntryImpl implements DeleteEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteParams) {\n const { entry } = params;\n const tenant = this.scopeTenant.getId();\n const id = entry.id || entry.entryId;\n const partitionKey = createPartitionKey({\n id,\n tenant\n });\n\n const items = await this.entity.queryAll({\n partitionKey,\n options: {\n gte: \" \"\n }\n });\n\n const esItems = await this.esEntity.queryAll({\n partitionKey,\n options: {\n gte: \" \"\n }\n });\n\n const entityBatch = this.entity.createEntityWriter({\n delete: items.map(item => {\n return {\n PK: item.PK,\n SK: item.SK\n };\n })\n });\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n delete: esItems.map(item => {\n return {\n PK: item.PK,\n SK: item.SK\n };\n })\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 destroy entry records from DynamoDB table.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n id\n }\n );\n }\n\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not destroy entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n id\n }\n );\n }\n }\n}\n\nexport const DdbEsDeleteEntry = DeleteEntryStorageOperation.createImplementation({\n implementation: DdbEsDeleteEntryImpl,\n dependencies: [CmsDdbEsEntryEntity, CmsDdbEsEntriesEsEntity, CmsDdbEsDataLoaders, ScopeTenant]\n});\n"],"names":["DdbEsDeleteEntryImpl","entity","esEntity","dataLoaders","scopeTenant","initialModel","params","entry","tenant","id","partitionKey","createPartitionKey","items","esItems","entityBatch","item","elasticsearchEntityBatch","ex","WebinyError","DdbEsDeleteEntry","DeleteEntryStorageOperation","CmsDdbEsEntryEnt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QAEA,IAAI;YACA,MAAMO,yBAAyB,OAAO;QAC1C,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,sEACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPR;YACJ;QAER;IACJ;AACJ;AAEO,MAAMU,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBpB;IAChB,cAAc;QAACqB;QAAqBC;QAAyBC;QAAqBC;KAAY;AAClG"}
|
|
@@ -6,6 +6,7 @@ import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
|
6
6
|
import { CmsStorageModelProvider } 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 DdbEsDeleteEntryRevisionImpl implements DeleteEntryRevisionStorageOperation.Interface {
|
|
10
11
|
private entity;
|
|
11
12
|
private esEntity;
|
|
@@ -15,7 +16,8 @@ declare class DdbEsDeleteEntryRevisionImpl implements DeleteEntryRevisionStorage
|
|
|
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: CmsEntryStorageOperationsDeleteRevisionParams<T>): Promise<void>;
|
|
20
22
|
}
|
|
21
23
|
export declare const DdbEsDeleteEntryRevision: typeof DdbEsDeleteEntryRevisionImpl & {
|