@webiny/api-headless-cms-ddb-es 6.6.0-alpha.12 → 6.6.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/operations/entry/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/types.js.map +1 -1
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { GetRevisionByIdStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionByIdStorageOperation.js";
|
|
2
2
|
import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
3
3
|
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
|
|
5
6
|
class DdbEsGetRevisionByIdImpl {
|
|
6
|
-
constructor(dataLoaders, storageModelProvider){
|
|
7
|
+
constructor(dataLoaders, storageModelProvider, scopeTenant){
|
|
7
8
|
this.dataLoaders = dataLoaders;
|
|
8
9
|
this.storageModelProvider = storageModelProvider;
|
|
10
|
+
this.scopeTenant = scopeTenant;
|
|
9
11
|
}
|
|
10
12
|
async execute(initialModel, params) {
|
|
13
|
+
const tenant = this.scopeTenant.getId();
|
|
11
14
|
const model = this.storageModelProvider.getModel(initialModel);
|
|
12
15
|
const [entry] = await this.dataLoaders.getRevisionById({
|
|
13
|
-
model
|
|
16
|
+
model: {
|
|
17
|
+
tenant,
|
|
18
|
+
modelId: model.modelId
|
|
19
|
+
},
|
|
14
20
|
ids: [
|
|
15
21
|
params.id
|
|
16
22
|
]
|
|
@@ -26,7 +32,8 @@ const DdbEsGetRevisionById = GetRevisionByIdStorageOperation.createImplementatio
|
|
|
26
32
|
implementation: DdbEsGetRevisionByIdImpl,
|
|
27
33
|
dependencies: [
|
|
28
34
|
CmsDdbEsDataLoaders,
|
|
29
|
-
CmsStorageModelProvider
|
|
35
|
+
CmsStorageModelProvider,
|
|
36
|
+
ScopeTenant
|
|
30
37
|
]
|
|
31
38
|
});
|
|
32
39
|
export { DdbEsGetRevisionById };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsGetRevisionById.js","sources":["../../../src/operations/entry/DdbEsGetRevisionById.ts"],"sourcesContent":["import type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsGetRevisionParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetRevisionByIdStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionByIdStorageOperation.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsGetRevisionByIdImpl implements GetRevisionByIdStorageOperation.Interface {\n constructor(\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const [entry] = await this.dataLoaders.getRevisionById<T>({\n model,\n ids: [params.id]\n });\n if (!entry) {\n return null;\n }\n return convertEntryKeysFromStorage<T>({\n model,\n entry\n });\n }\n}\n\nexport const DdbEsGetRevisionById = GetRevisionByIdStorageOperation.createImplementation({\n implementation: DdbEsGetRevisionByIdImpl,\n dependencies: [CmsDdbEsDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbEsGetRevisionByIdImpl","dataLoaders","storageModelProvider","initialModel","params","model","entry","convertEntryKeysFromStorage","DdbEsGetRevisionById","GetRevisionByIdStorageOperation","CmsDdbEsDataLoaders","CmsStorageModelProvider"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsGetRevisionById.js","sources":["../../../src/operations/entry/DdbEsGetRevisionById.ts"],"sourcesContent":["import type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsGetRevisionParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetRevisionByIdStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionByIdStorageOperation.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsGetRevisionByIdImpl implements GetRevisionByIdStorageOperation.Interface {\n constructor(\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) {\n const tenant = this.scopeTenant.getId();\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const [entry] = await this.dataLoaders.getRevisionById<T>({\n model: { tenant, modelId: model.modelId },\n ids: [params.id]\n });\n if (!entry) {\n return null;\n }\n return convertEntryKeysFromStorage<T>({\n model,\n entry\n });\n }\n}\n\nexport const DdbEsGetRevisionById = GetRevisionByIdStorageOperation.createImplementation({\n implementation: DdbEsGetRevisionByIdImpl,\n dependencies: [CmsDdbEsDataLoaders, CmsStorageModelProvider, ScopeTenant]\n});\n"],"names":["DdbEsGetRevisionByIdImpl","dataLoaders","storageModelProvider","scopeTenant","initialModel","params","tenant","model","entry","convertEntryKeysFromStorage","DdbEsGetRevisionById","GetRevisionByIdStorageOperation","CmsDdbEsDataLoaders","CmsStorageModelProvider","ScopeTenant"],"mappings":";;;;;AAWA,MAAMA;IACF,YACYC,WAA0C,EAC1CC,oBAAuD,EACvDC,WAAkC,CAC5C;aAHUF,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAkD,EACpD;QACE,MAAMC,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIH;QAEpD,MAAM,CAACI,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,eAAe,CAAI;YACtD,OAAO;gBAAEF;gBAAQ,SAASC,MAAM,OAAO;YAAC;YACxC,KAAK;gBAACF,OAAO,EAAE;aAAC;QACpB;QACA,IAAI,CAACG,OACD,OAAO;QAEX,OAAOC,4BAA+B;YAClCF;YACAC;QACJ;IACJ;AACJ;AAEO,MAAME,uBAAuBC,gCAAgC,oBAAoB,CAAC;IACrF,gBAAgBX;IAChB,cAAc;QAACY;QAAqBC;QAAyBC;KAAY;AAC7E"}
|
|
@@ -2,10 +2,12 @@ import type { CmsModel, CmsEntryValues, CmsEntryStorageOperationsGetRevisionsPar
|
|
|
2
2
|
import { GetRevisionsStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionsStorageOperation.js";
|
|
3
3
|
import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
4
4
|
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
5
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
5
6
|
declare class DdbEsGetRevisionsImpl implements GetRevisionsStorageOperation.Interface {
|
|
6
7
|
private dataLoaders;
|
|
7
8
|
private storageModelProvider;
|
|
8
|
-
|
|
9
|
+
private scopeTenant;
|
|
10
|
+
constructor(dataLoaders: CmsDdbEsDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface, scopeTenant: ScopeTenant.Interface);
|
|
9
11
|
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsGetRevisionsParams): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>[]>;
|
|
10
12
|
}
|
|
11
13
|
export declare const DdbEsGetRevisions: typeof DdbEsGetRevisionsImpl & {
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { GetRevisionsStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionsStorageOperation.js";
|
|
2
2
|
import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
|
|
3
3
|
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
4
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
4
5
|
import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
|
|
5
6
|
class DdbEsGetRevisionsImpl {
|
|
6
|
-
constructor(dataLoaders, storageModelProvider){
|
|
7
|
+
constructor(dataLoaders, storageModelProvider, scopeTenant){
|
|
7
8
|
this.dataLoaders = dataLoaders;
|
|
8
9
|
this.storageModelProvider = storageModelProvider;
|
|
10
|
+
this.scopeTenant = scopeTenant;
|
|
9
11
|
}
|
|
10
12
|
async execute(initialModel, params) {
|
|
13
|
+
const tenant = this.scopeTenant.getId();
|
|
11
14
|
const model = this.storageModelProvider.getModel(initialModel);
|
|
12
15
|
const entries = await this.dataLoaders.getAllEntryRevisions({
|
|
13
|
-
model
|
|
16
|
+
model: {
|
|
17
|
+
tenant,
|
|
18
|
+
modelId: model.modelId
|
|
19
|
+
},
|
|
14
20
|
ids: [
|
|
15
21
|
params.id
|
|
16
22
|
]
|
|
@@ -25,7 +31,8 @@ const DdbEsGetRevisions = GetRevisionsStorageOperation.createImplementation({
|
|
|
25
31
|
implementation: DdbEsGetRevisionsImpl,
|
|
26
32
|
dependencies: [
|
|
27
33
|
CmsDdbEsDataLoaders,
|
|
28
|
-
CmsStorageModelProvider
|
|
34
|
+
CmsStorageModelProvider,
|
|
35
|
+
ScopeTenant
|
|
29
36
|
]
|
|
30
37
|
});
|
|
31
38
|
export { DdbEsGetRevisions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsGetRevisions.js","sources":["../../../src/operations/entry/DdbEsGetRevisions.ts"],"sourcesContent":["import type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsGetRevisionsParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetRevisionsStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionsStorageOperation.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsGetRevisionsImpl implements GetRevisionsStorageOperation.Interface {\n constructor(\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const entries = await this.dataLoaders.getAllEntryRevisions<T>({\n model,\n ids: [params.id]\n });\n\n return entries.map(entry => {\n return convertEntryKeysFromStorage<T>({\n model,\n entry\n });\n });\n }\n}\n\nexport const DdbEsGetRevisions = GetRevisionsStorageOperation.createImplementation({\n implementation: DdbEsGetRevisionsImpl,\n dependencies: [CmsDdbEsDataLoaders, CmsStorageModelProvider]\n});\n"],"names":["DdbEsGetRevisionsImpl","dataLoaders","storageModelProvider","initialModel","params","model","entries","entry","convertEntryKeysFromStorage","DdbEsGetRevisions","GetRevisionsStorageOperation","CmsDdbEsDataLoaders","CmsStorageModelProvider"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsGetRevisions.js","sources":["../../../src/operations/entry/DdbEsGetRevisions.ts"],"sourcesContent":["import type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsGetRevisionsParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetRevisionsStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetRevisionsStorageOperation.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsGetRevisionsImpl implements GetRevisionsStorageOperation.Interface {\n constructor(\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) {\n const tenant = this.scopeTenant.getId();\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const entries = await this.dataLoaders.getAllEntryRevisions<T>({\n model: { tenant, modelId: model.modelId },\n ids: [params.id]\n });\n\n return entries.map(entry => {\n return convertEntryKeysFromStorage<T>({\n model,\n entry\n });\n });\n }\n}\n\nexport const DdbEsGetRevisions = GetRevisionsStorageOperation.createImplementation({\n implementation: DdbEsGetRevisionsImpl,\n dependencies: [CmsDdbEsDataLoaders, CmsStorageModelProvider, ScopeTenant]\n});\n"],"names":["DdbEsGetRevisionsImpl","dataLoaders","storageModelProvider","scopeTenant","initialModel","params","tenant","model","entries","entry","convertEntryKeysFromStorage","DdbEsGetRevisions","GetRevisionsStorageOperation","CmsDdbEsDataLoaders","CmsStorageModelProvider","ScopeTenant"],"mappings":";;;;;AAWA,MAAMA;IACF,YACYC,WAA0C,EAC1CC,oBAAuD,EACvDC,WAAkC,CAC5C;aAHUF,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAmD,EACrD;QACE,MAAMC,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIH;QAEpD,MAAMI,UAAU,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAI;YAC3D,OAAO;gBAAEF;gBAAQ,SAASC,MAAM,OAAO;YAAC;YACxC,KAAK;gBAACF,OAAO,EAAE;aAAC;QACpB;QAEA,OAAOG,QAAQ,GAAG,CAACC,CAAAA,QACRC,4BAA+B;gBAClCH;gBACAE;YACJ;IAER;AACJ;AAEO,MAAME,oBAAoBC,6BAA6B,oBAAoB,CAAC;IAC/E,gBAAgBZ;IAChB,cAAc;QAACa;QAAqBC;QAAyBC;KAAY;AAC7E"}
|
|
@@ -2,11 +2,13 @@ import type { CmsModel, CmsEntryStorageOperationsGetUniqueFieldValuesParams } fr
|
|
|
2
2
|
import { GetUniqueFieldValuesStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js";
|
|
3
3
|
import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
4
4
|
import { CmsEntryOpenSearchBodyBuilder, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
5
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
5
6
|
declare class DdbEsGetUniqueFieldValuesImpl implements GetUniqueFieldValuesStorageOperation.Interface {
|
|
6
7
|
private bodyBuilder;
|
|
7
8
|
private indexProvider;
|
|
9
|
+
private scopeTenant;
|
|
8
10
|
private elasticsearch;
|
|
9
|
-
constructor(bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface);
|
|
11
|
+
constructor(bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, scopeTenant: ScopeTenant.Interface);
|
|
10
12
|
execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams): Promise<{
|
|
11
13
|
value: string;
|
|
12
14
|
count: number;
|
|
@@ -4,13 +4,16 @@ import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.
|
|
|
4
4
|
import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
|
|
5
5
|
import { shouldIgnoreEsResponseError } from "@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js";
|
|
6
6
|
import { CmsEntryOpenSearchBodyBuilder, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
7
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
7
8
|
class DdbEsGetUniqueFieldValuesImpl {
|
|
8
|
-
constructor(bodyBuilder, openSearchClient, indexProvider){
|
|
9
|
+
constructor(bodyBuilder, openSearchClient, indexProvider, scopeTenant){
|
|
9
10
|
this.bodyBuilder = bodyBuilder;
|
|
10
11
|
this.indexProvider = indexProvider;
|
|
12
|
+
this.scopeTenant = scopeTenant;
|
|
11
13
|
this.elasticsearch = openSearchClient.use();
|
|
12
14
|
}
|
|
13
15
|
async execute(model, params) {
|
|
16
|
+
this.scopeTenant.getId();
|
|
14
17
|
const { where, fieldId } = params;
|
|
15
18
|
const configurations = createConfigurations(this.indexProvider);
|
|
16
19
|
const { index, shared } = await configurations.es({
|
|
@@ -69,7 +72,8 @@ const DdbEsGetUniqueFieldValues = GetUniqueFieldValuesStorageOperation.createImp
|
|
|
69
72
|
dependencies: [
|
|
70
73
|
CmsEntryOpenSearchBodyBuilder,
|
|
71
74
|
OpenSearchClient,
|
|
72
|
-
CmsModelOpenSearchIndexProvider
|
|
75
|
+
CmsModelOpenSearchIndexProvider,
|
|
76
|
+
ScopeTenant
|
|
73
77
|
]
|
|
74
78
|
});
|
|
75
79
|
export { DdbEsGetUniqueFieldValues };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsGetUniqueFieldValues.js","sources":["../../../src/operations/entry/DdbEsGetUniqueFieldValues.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryStorageOperationsGetUniqueFieldValuesParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetUniqueFieldValuesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport type {\n OpenSearchSearchResponse,\n SearchBody as OpenSearchSearchBody\n} from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\n\nclass DdbEsGetUniqueFieldValuesImpl implements GetUniqueFieldValuesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams) {\n const { where, fieldId } = params;\n\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({\n model\n });\n\n const initialBody = this.bodyBuilder.build({\n model,\n shared,\n params: {\n limit: 1,\n where\n }\n });\n\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n throw new WebinyError(\n `Could not find field with given \"fieldId\" value.`,\n \"FIELD_NOT_FOUND\",\n {\n fieldId\n }\n );\n }\n\n const body: OpenSearchSearchBody = {\n ...initialBody,\n /**\n * We do not need any hits returned, we only need the aggregations.\n */\n size: 0,\n aggregations: {\n getUniqueFieldValues: {\n terms: {\n // @ts-expect-error opensearch 3.9 types omit `field` from TermsAggregationFields\n field: `values.${field.storageId}.keyword`,\n size: 1000000\n }\n }\n }\n };\n\n let response: OpenSearchSearchResponse | undefined = undefined;\n\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n } catch (error) {\n if (shouldIgnoreEsResponseError(error)) {\n return [];\n }\n\n throw new WebinyError(\n error.message || \"Error in the Elasticsearch query.\",\n error.code || \"OPENSEARCH_ERROR\",\n {\n error,\n index,\n model,\n body\n }\n );\n }\n\n const aggregations = response.body.aggregations || {};\n const agg = aggregations[\"getUniqueFieldValues\"];\n const buckets = agg && \"buckets\" in agg && Array.isArray(agg.buckets) ? agg.buckets : [];\n return buckets.map((bucket: { key: string; doc_count: number }) => {\n return {\n value: bucket.key,\n count: bucket.doc_count\n };\n });\n }\n}\n\nexport const DdbEsGetUniqueFieldValues = GetUniqueFieldValuesStorageOperation.createImplementation({\n implementation: DdbEsGetUniqueFieldValuesImpl,\n dependencies: [CmsEntryOpenSearchBodyBuilder
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsGetUniqueFieldValues.js","sources":["../../../src/operations/entry/DdbEsGetUniqueFieldValues.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryStorageOperationsGetUniqueFieldValuesParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetUniqueFieldValuesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport type {\n OpenSearchSearchResponse,\n SearchBody as OpenSearchSearchBody\n} from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\nclass DdbEsGetUniqueFieldValuesImpl implements GetUniqueFieldValuesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams) {\n /**\n * The index and the shared index's tenant filter are derived from the model's tenant, which\n * must be the scope's.\n */\n this.scopeTenant.getId();\n const { where, fieldId } = params;\n\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({\n model\n });\n\n const initialBody = this.bodyBuilder.build({\n model,\n shared,\n params: {\n limit: 1,\n where\n }\n });\n\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n throw new WebinyError(\n `Could not find field with given \"fieldId\" value.`,\n \"FIELD_NOT_FOUND\",\n {\n fieldId\n }\n );\n }\n\n const body: OpenSearchSearchBody = {\n ...initialBody,\n /**\n * We do not need any hits returned, we only need the aggregations.\n */\n size: 0,\n aggregations: {\n getUniqueFieldValues: {\n terms: {\n // @ts-expect-error opensearch 3.9 types omit `field` from TermsAggregationFields\n field: `values.${field.storageId}.keyword`,\n size: 1000000\n }\n }\n }\n };\n\n let response: OpenSearchSearchResponse | undefined = undefined;\n\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n } catch (error) {\n if (shouldIgnoreEsResponseError(error)) {\n return [];\n }\n\n throw new WebinyError(\n error.message || \"Error in the Elasticsearch query.\",\n error.code || \"OPENSEARCH_ERROR\",\n {\n error,\n index,\n model,\n body\n }\n );\n }\n\n const aggregations = response.body.aggregations || {};\n const agg = aggregations[\"getUniqueFieldValues\"];\n const buckets = agg && \"buckets\" in agg && Array.isArray(agg.buckets) ? agg.buckets : [];\n return buckets.map((bucket: { key: string; doc_count: number }) => {\n return {\n value: bucket.key,\n count: bucket.doc_count\n };\n });\n }\n}\n\nexport const DdbEsGetUniqueFieldValues = GetUniqueFieldValuesStorageOperation.createImplementation({\n implementation: DdbEsGetUniqueFieldValuesImpl,\n dependencies: [\n CmsEntryOpenSearchBodyBuilder,\n OpenSearchClient,\n CmsModelOpenSearchIndexProvider,\n ScopeTenant\n ]\n});\n"],"names":["DdbEsGetUniqueFieldValuesImpl","bodyBuilder","openSearchClient","indexProvider","scopeTenant","model","params","where","fieldId","configurations","createConfigurations","index","shared","initialBody","field","f","WebinyError","body","response","error","shouldIgnoreEsResponseError","aggregations","agg","buckets","Array","bucket","DdbEsGetUniqueFieldValues","GetUniqueFieldValuesStorageOperation","CmsEntryOpenSearchBodyBuilder","OpenSearchClient","CmsModelOpenSearchIndexProvider","ScopeTenant"],"mappings":";;;;;;;AAoBA,MAAMA;IAGF,YACYC,WAAoD,EAC5DC,gBAA4C,EACpCC,aAAwD,EACxDC,WAAkC,CAC5C;aAJUH,WAAW,GAAXA;aAEAE,aAAa,GAAbA;aACAC,WAAW,GAAXA;QAER,IAAI,CAAC,aAAa,GAAGF,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQG,KAAe,EAAEC,MAA2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AAOA,OAAO,GAAG;gBACjB,OAAOA,OAAO,SAAS;YAC3B;IAER;AACJ;AAEO,MAAMC,4BAA4BC,qCAAqC,oBAAoB,CAAC;IAC/F,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -5,6 +5,7 @@ import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports
|
|
|
5
5
|
import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
6
6
|
import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
7
7
|
import { Debugger } from "@webiny/api-core/features/debugger/index.js";
|
|
8
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
8
9
|
import "~/debuggerNamespaces.js";
|
|
9
10
|
declare class DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interface {
|
|
10
11
|
private storageModelProvider;
|
|
@@ -13,8 +14,9 @@ declare class DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interf
|
|
|
13
14
|
private fieldIndexRegistry;
|
|
14
15
|
private indexProvider;
|
|
15
16
|
private debuggerService;
|
|
17
|
+
private scopeTenant;
|
|
16
18
|
private elasticsearch;
|
|
17
|
-
constructor(storageModelProvider: CmsStorageModelProvider.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, debuggerService: Debugger.Interface);
|
|
19
|
+
constructor(storageModelProvider: CmsStorageModelProvider.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, debuggerService: Debugger.Interface, scopeTenant: ScopeTenant.Interface);
|
|
18
20
|
execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsListParams): Promise<{
|
|
19
21
|
hasMoreItems: boolean;
|
|
20
22
|
totalCount: number;
|
|
@@ -10,19 +10,22 @@ import { extractEntriesFromIndex } from "@webiny/api-headless-cms-utils-os/helpe
|
|
|
10
10
|
import { shouldIgnoreEsResponseError } from "@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js";
|
|
11
11
|
import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
|
|
12
12
|
import { Debugger } from "@webiny/api-core/features/debugger/index.js";
|
|
13
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
13
14
|
import "../../debuggerNamespaces.js";
|
|
14
15
|
import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
|
|
15
16
|
class DdbEsListEntriesImpl {
|
|
16
|
-
constructor(storageModelProvider, bodyBuilder, fieldRegistry, fieldIndexRegistry, openSearchClient, indexProvider, debuggerService){
|
|
17
|
+
constructor(storageModelProvider, bodyBuilder, fieldRegistry, fieldIndexRegistry, openSearchClient, indexProvider, debuggerService, scopeTenant){
|
|
17
18
|
this.storageModelProvider = storageModelProvider;
|
|
18
19
|
this.bodyBuilder = bodyBuilder;
|
|
19
20
|
this.fieldRegistry = fieldRegistry;
|
|
20
21
|
this.fieldIndexRegistry = fieldIndexRegistry;
|
|
21
22
|
this.indexProvider = indexProvider;
|
|
22
23
|
this.debuggerService = debuggerService;
|
|
24
|
+
this.scopeTenant = scopeTenant;
|
|
23
25
|
this.elasticsearch = openSearchClient.use();
|
|
24
26
|
}
|
|
25
27
|
async execute(initialModel, params) {
|
|
28
|
+
this.scopeTenant.getId();
|
|
26
29
|
const model = this.storageModelProvider.getModel(initialModel);
|
|
27
30
|
const limit = createLimit(params.limit, 50);
|
|
28
31
|
const configurations = createConfigurations(this.indexProvider);
|
|
@@ -102,7 +105,8 @@ const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({
|
|
|
102
105
|
CmsEntryOpenSearchFieldIndexRegistry,
|
|
103
106
|
OpenSearchClient,
|
|
104
107
|
CmsModelOpenSearchIndexProvider,
|
|
105
|
-
Debugger
|
|
108
|
+
Debugger,
|
|
109
|
+
ScopeTenant
|
|
106
110
|
]
|
|
107
111
|
});
|
|
108
112
|
export { DdbEsListEntries };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsListEntries.js","sources":["../../../src/operations/entry/DdbEsListEntries.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsListParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ListEntriesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/ListEntriesStorageOperation.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport { createLimit, decodeCursor, encodeCursor } from \"@webiny/api-opensearch\";\nimport type { OpenSearchSearchResponse } from \"@webiny/api-opensearch/types.js\";\nimport { getTotalCount } from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { extractEntriesFromIndex } from \"@webiny/api-headless-cms-utils-os/helpers/index.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport { Debugger } from \"@webiny/api-core/features/debugger/index.js\";\nimport \"~/debuggerNamespaces.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n private fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private debuggerService: Debugger.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsListParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const limit = createLimit(params.limit, 50);\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({\n model\n });\n\n const body = this.bodyBuilder.build({\n model,\n shared,\n params: {\n ...params,\n limit,\n after: decodeCursor(params.after)\n }\n });\n\n let response: OpenSearchSearchResponse;\n const startedAt = Date.now();\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n\n this.debuggerService.log(\"cms.os.list\", () => ({\n index,\n query: body,\n /**\n * Only the response body and status. The full client response also carries\n * `meta.connection.url` (the cluster endpoint) plus request headers.\n */\n body: response.body,\n statusCode: response.statusCode,\n tookMs: Date.now() - startedAt\n }));\n } catch (error) {\n /**\n * Logged before the `index_not_found` check below, which swallows the error and returns\n * an empty result. That silent exit is exactly what is hard to see from the outside.\n */\n this.debuggerService.log(\"cms.os.list\", () => ({\n index,\n query: body,\n error,\n tookMs: Date.now() - startedAt\n }));\n\n /**\n * We will silently ignore the `index_not_found_exception` error and return an empty result set.\n * This is because the index might not exist yet, and we don't want to throw an error.\n */\n if (shouldIgnoreEsResponseError(error)) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n\n throw new WebinyError(error.message, error.code || \"OPENSEARCH_ERROR\", {\n error,\n index,\n body,\n model\n });\n }\n\n const { hits, total } = response.body.hits;\n\n const items = extractEntriesFromIndex<T>({\n fieldRegistry: this.fieldRegistry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n model,\n entries: hits.map(item => {\n return item._source as CmsIndexEntry<T>;\n })\n }).map(item => {\n return convertEntryKeysFromStorage<T>({\n model,\n entry: item\n });\n });\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;\n return {\n hasMoreItems,\n totalCount: getTotalCount(total),\n cursor,\n items\n };\n }\n}\n\nexport const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({\n implementation: DdbEsListEntriesImpl,\n dependencies: [\n CmsStorageModelProvider,\n CmsEntryOpenSearchBodyBuilder,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n OpenSearchClient,\n CmsModelOpenSearchIndexProvider,\n Debugger\n ]\n});\n"],"names":["DdbEsListEntriesImpl","storageModelProvider","bodyBuilder","fieldRegistry","fieldIndexRegistry","openSearchClient","indexProvider","debuggerService","initialModel","params","model","limit","createLimit","configurations","createConfigurations","index","shared","body","decodeCursor","response","startedAt","Date","error","shouldIgnoreEsResponseError","WebinyError","hits","total","items","extractEntriesFromIndex","item","convertEntryKeysFromStorage","hasMoreItems","cursor","encodeCursor","getTotalCount","DdbEsListEntries","ListEntriesStorageOperation","CmsStorageModelProvider","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","OpenSearchClient","CmsModelOpenSearchIndexProvider","Debugger"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsListEntries.js","sources":["../../../src/operations/entry/DdbEsListEntries.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsListParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ListEntriesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/ListEntriesStorageOperation.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport { createLimit, decodeCursor, encodeCursor } from \"@webiny/api-opensearch\";\nimport type { OpenSearchSearchResponse } from \"@webiny/api-opensearch/types.js\";\nimport { getTotalCount } from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { extractEntriesFromIndex } from \"@webiny/api-headless-cms-utils-os/helpers/index.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport { Debugger } from \"@webiny/api-core/features/debugger/index.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport \"~/debuggerNamespaces.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n private fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private debuggerService: Debugger.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsListParams\n ) {\n /**\n * The index and the shared index's tenant filter are derived from the model's tenant, which\n * must be the scope's.\n */\n this.scopeTenant.getId();\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const limit = createLimit(params.limit, 50);\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({\n model\n });\n\n const body = this.bodyBuilder.build({\n model,\n shared,\n params: {\n ...params,\n limit,\n after: decodeCursor(params.after)\n }\n });\n\n let response: OpenSearchSearchResponse;\n const startedAt = Date.now();\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n\n this.debuggerService.log(\"cms.os.list\", () => ({\n index,\n query: body,\n /**\n * Only the response body and status. The full client response also carries\n * `meta.connection.url` (the cluster endpoint) plus request headers.\n */\n body: response.body,\n statusCode: response.statusCode,\n tookMs: Date.now() - startedAt\n }));\n } catch (error) {\n /**\n * Logged before the `index_not_found` check below, which swallows the error and returns\n * an empty result. That silent exit is exactly what is hard to see from the outside.\n */\n this.debuggerService.log(\"cms.os.list\", () => ({\n index,\n query: body,\n error,\n tookMs: Date.now() - startedAt\n }));\n\n /**\n * We will silently ignore the `index_not_found_exception` error and return an empty result set.\n * This is because the index might not exist yet, and we don't want to throw an error.\n */\n if (shouldIgnoreEsResponseError(error)) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n\n throw new WebinyError(error.message, error.code || \"OPENSEARCH_ERROR\", {\n error,\n index,\n body,\n model\n });\n }\n\n const { hits, total } = response.body.hits;\n\n const items = extractEntriesFromIndex<T>({\n fieldRegistry: this.fieldRegistry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n model,\n entries: hits.map(item => {\n return item._source as CmsIndexEntry<T>;\n })\n }).map(item => {\n return convertEntryKeysFromStorage<T>({\n model,\n entry: item\n });\n });\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;\n return {\n hasMoreItems,\n totalCount: getTotalCount(total),\n cursor,\n items\n };\n }\n}\n\nexport const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({\n implementation: DdbEsListEntriesImpl,\n dependencies: [\n CmsStorageModelProvider,\n CmsEntryOpenSearchBodyBuilder,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n OpenSearchClient,\n CmsModelOpenSearchIndexProvider,\n Debugger,\n ScopeTenant\n ]\n});\n"],"names":["DdbEsListEntriesImpl","storageModelProvider","bodyBuilder","fieldRegistry","fieldIndexRegistry","openSearchClient","indexProvider","debuggerService","scopeTenant","initialModel","params","model","limit","createLimit","configurations","createConfigurations","index","shared","body","decodeCursor","response","startedAt","Date","error","shouldIgnoreEsResponseError","WebinyError","hits","total","items","extractEntriesFromIndex","item","convertEntryKeysFromStorage","hasMoreItems","cursor","encodeCursor","getTotalCount","DdbEsListEntries","ListEntriesStorageOperation","CmsStorageModelProvider","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","OpenSearchClient","CmsModelOpenSearchIndexProvider","Debugger","ScopeTenant"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAMA;IAGF,YACYC,oBAAuD,EACvDC,WAAoD,EACpDC,aAAuD,EACvDC,kBAAkE,EAC1EC,gBAA4C,EACpCC,aAAwD,EACxDC,eAAmC,EACnCC,WAAkC,CAC5C;aARUP,oBAAoB,GAApBA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aAEAE,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;QAER,IAAI,CAAC,aAAa,GAAGH,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QACFI,YAAsB,EACtBC,MAA2C,EAC7C;QAKE,IAAI,CAAC,WAAW,CAAC,KAAK;QACtB,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQC,YAAYH,OAAO,KAAK,EAAE;QACxC,MAAMI,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAG,MAAMH,eAAe,EAAE,CAAC;YAC9CH;QACJ;QAEA,MAAMO,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YAChCP;YACAM;YACA,QAAQ;gBACJ,GAAGP,MAAM;gBACTE;gBACA,OAAOO,aAAaT,OAAO,KAAK;YACpC;QACJ;QAEA,IAAIU;QACJ,MAAMC,YAAYC,KAAK,GAAG;QAC1B,IAAI;YACAF,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;gBACvCJ;gBACAE;YACJ;YAEA,IAAI,CAAC,eAAe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15 +3,15 @@ import { MoveEntryStorageOperation } from "@webiny/api-headless-cms/features/sha
|
|
|
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 { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
6
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
7
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
8
8
|
declare class DdbEsMoveEntryImpl implements MoveEntryStorageOperation.Interface {
|
|
9
9
|
private entity;
|
|
10
10
|
private esEntity;
|
|
11
11
|
private dataLoaders;
|
|
12
|
-
private storageModelProvider;
|
|
13
12
|
private compressionHandler;
|
|
14
|
-
|
|
13
|
+
private scopeTenant;
|
|
14
|
+
constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface, compressionHandler: CompressionHandler.Interface, scopeTenant: ScopeTenant.Interface);
|
|
15
15
|
execute(initialModel: CmsModel, id: string, folderId: string): Promise<void>;
|
|
16
16
|
}
|
|
17
17
|
export declare const DdbEsMoveEntry: typeof DdbEsMoveEntryImpl & {
|
|
@@ -3,22 +3,22 @@ import { MoveEntryStorageOperation } from "@webiny/api-headless-cms/features/sha
|
|
|
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 { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
6
|
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
7
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
8
8
|
import { createLatestSortKey, createPartitionKey, createPublishedSortKey } from "./keys.js";
|
|
9
9
|
class DdbEsMoveEntryImpl {
|
|
10
|
-
constructor(entity, esEntity, dataLoaders,
|
|
10
|
+
constructor(entity, esEntity, dataLoaders, compressionHandler, scopeTenant){
|
|
11
11
|
this.entity = entity;
|
|
12
12
|
this.esEntity = esEntity;
|
|
13
13
|
this.dataLoaders = dataLoaders;
|
|
14
|
-
this.storageModelProvider = storageModelProvider;
|
|
15
14
|
this.compressionHandler = compressionHandler;
|
|
15
|
+
this.scopeTenant = scopeTenant;
|
|
16
16
|
}
|
|
17
17
|
async execute(initialModel, id, folderId) {
|
|
18
|
-
const
|
|
18
|
+
const tenant = this.scopeTenant.getId();
|
|
19
19
|
const partitionKey = createPartitionKey({
|
|
20
20
|
id,
|
|
21
|
-
tenant
|
|
21
|
+
tenant
|
|
22
22
|
});
|
|
23
23
|
const queryAllParams = {
|
|
24
24
|
partitionKey,
|
|
@@ -49,7 +49,7 @@ class DdbEsMoveEntryImpl {
|
|
|
49
49
|
try {
|
|
50
50
|
await entityBatch.execute();
|
|
51
51
|
this.dataLoaders.clearAll({
|
|
52
|
-
tenant
|
|
52
|
+
tenant
|
|
53
53
|
});
|
|
54
54
|
} catch (ex) {
|
|
55
55
|
throw new error(ex.message || "Could not move all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_ERROR", {
|
|
@@ -104,8 +104,8 @@ const DdbEsMoveEntry = MoveEntryStorageOperation.createImplementation({
|
|
|
104
104
|
CmsDdbEsEntryEntity,
|
|
105
105
|
CmsDdbEsEntriesEsEntity,
|
|
106
106
|
CmsDdbEsDataLoaders,
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
CompressionHandler,
|
|
108
|
+
ScopeTenant
|
|
109
109
|
]
|
|
110
110
|
});
|
|
111
111
|
export { DdbEsMoveEntry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsMoveEntry.js","sources":["../../../src/operations/entry/DdbEsMoveEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveEntryStorageOperation.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/DdbEsMoveEntry.js","sources":["../../../src/operations/entry/DdbEsMoveEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveEntryStorageOperation.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch-aws\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\n\nclass DdbEsMoveEntryImpl implements MoveEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel, id: string, folderId: string) {\n const tenant = this.scopeTenant.getId();\n\n const partitionKey = createPartitionKey({\n id,\n tenant\n });\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n /**\n * Then update the folderId in each record and prepare it to be stored.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n location: {\n ...record.data.location,\n folderId\n }\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\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 move all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_ERROR\",\n {\n error: ex,\n id\n }\n );\n }\n\n const esEntityReader = this.esEntity.createEntityReader();\n\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n try {\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n put: await Promise.all(\n esItems.map(async item => {\n return {\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n location: {\n ...item.data?.location,\n folderId\n }\n })\n };\n })\n )\n });\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not move entry DynamoDB Elasticsearch records.\",\n ex.code || \"MOVE_ES_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveEntry = MoveEntryStorageOperation.createImplementation({\n implementation: DdbEsMoveEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CompressionHandler,\n ScopeTenant\n ]\n});\n"],"names":["DdbEsMoveEntryImpl","entity","esEntity","dataLoaders","compressionHandler","scopeTenant","initialModel","id","folderId","tenant","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveEntry","MoveEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CompressionHandler","ScopeTenant"],"mappings":";;;;;;;;AAYA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,kBAAgD,EAChDC,WAAkC,CAC5C;aALUJ,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,kBAAkB,GAAlBA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAEC,EAAU,EAAEC,QAAgB,EAAE;QAChE,MAAMC,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QAErC,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;gBACH,GAAGA,MAAM;gBACT,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAACA,OAAO,IAAI;YAC9D;QACJ,GAAE,EAER,MAAM,CAAC,CAACO,OAAiD,CAAC,CAACA;QAE7D,IAAIF,AAAmB,MAAnBA,QAAQ,MAAM,EACd;QAGJ,IAAI;YACA,MAAMG,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;gBAC9D,KAAK,MAAMF,QAAQ,GAAG,CAClBD,QAAQ,GAAG,CAAC,OAAME,OACP;wBACH,GAAGA,IAAI;wBACP,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;4BACzC,GAAGA,KAAK,IAAI;4BACZ,UAAU;gCACN,GAAGA,KAAK,IAAI,EAAE,QAAQ;gCACtBpB;4BACJ;wBACJ;oBACJ;YAGZ;YACA,MAAMqB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wDACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACPZ;YACJ;QAER;IACJ;AACJ;AAEO,MAAMoB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;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 } 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 DdbEsMoveToBinImpl implements MoveToBinStorageOperation.Interface {
|
|
10
11
|
private entity;
|
|
11
12
|
private esEntity;
|
|
@@ -14,7 +15,8 @@ declare class DdbEsMoveToBinImpl implements MoveToBinStorageOperation.Interface
|
|
|
14
15
|
private fieldIndexRegistry;
|
|
15
16
|
private compressionHandler;
|
|
16
17
|
private valuesModifiers;
|
|
17
|
-
|
|
18
|
+
private scopeTenant;
|
|
19
|
+
constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, compressionHandler: CompressionHandler.Interface, valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[], scopeTenant: ScopeTenant.Interface);
|
|
18
20
|
execute(initialModel: CmsModel, params: CmsEntryStorageOperationsMoveToBinParams): Promise<void>;
|
|
19
21
|
}
|
|
20
22
|
export declare const DdbEsMoveToBin: typeof DdbEsMoveToBinImpl & {
|
|
@@ -7,10 +7,11 @@ import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/share
|
|
|
7
7
|
import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier } 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 { createTransformer } from "./transformations/index.js";
|
|
10
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
10
11
|
import { createLatestSortKey, createPartitionKey, createPublishedSortKey } from "./keys.js";
|
|
11
12
|
import { isDeletedEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
12
13
|
class DdbEsMoveToBinImpl {
|
|
13
|
-
constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, valuesModifiers){
|
|
14
|
+
constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, valuesModifiers, scopeTenant){
|
|
14
15
|
this.entity = entity;
|
|
15
16
|
this.esEntity = esEntity;
|
|
16
17
|
this.dataLoaders = dataLoaders;
|
|
@@ -18,9 +19,11 @@ class DdbEsMoveToBinImpl {
|
|
|
18
19
|
this.fieldIndexRegistry = fieldIndexRegistry;
|
|
19
20
|
this.compressionHandler = compressionHandler;
|
|
20
21
|
this.valuesModifiers = valuesModifiers;
|
|
22
|
+
this.scopeTenant = scopeTenant;
|
|
21
23
|
}
|
|
22
24
|
async execute(initialModel, params) {
|
|
23
25
|
const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
|
|
26
|
+
const tenant = this.scopeTenant.getId();
|
|
24
27
|
const model = this.storageModelProvider.getModel(initialModel);
|
|
25
28
|
const transformer = createTransformer({
|
|
26
29
|
valuesModifiers: this.valuesModifiers,
|
|
@@ -33,7 +36,7 @@ class DdbEsMoveToBinImpl {
|
|
|
33
36
|
const { entry, storageEntry } = transformer.transformEntryKeys();
|
|
34
37
|
const partitionKey = createPartitionKey({
|
|
35
38
|
id: entry.id,
|
|
36
|
-
tenant
|
|
39
|
+
tenant
|
|
37
40
|
});
|
|
38
41
|
const queryAllParams = {
|
|
39
42
|
partitionKey,
|
|
@@ -65,7 +68,7 @@ class DdbEsMoveToBinImpl {
|
|
|
65
68
|
try {
|
|
66
69
|
await entityBatch.execute();
|
|
67
70
|
this.dataLoaders.clearAll({
|
|
68
|
-
tenant
|
|
71
|
+
tenant
|
|
69
72
|
});
|
|
70
73
|
} catch (ex) {
|
|
71
74
|
throw new error(ex.message || "Could mark as deleted all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
|
|
@@ -129,7 +132,8 @@ const DdbEsMoveToBin = MoveToBinStorageOperation.createImplementation({
|
|
|
129
132
|
{
|
|
130
133
|
multiple: true
|
|
131
134
|
}
|
|
132
|
-
]
|
|
135
|
+
],
|
|
136
|
+
ScopeTenant
|
|
133
137
|
]
|
|
134
138
|
});
|
|
135
139
|
export { DdbEsMoveToBin };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/DdbEsMoveToBin.js","sources":["../../../src/operations/entry/DdbEsMoveToBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsEntryStorageOperationsMoveToBinParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveToBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.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} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\nimport {\n isDeletedEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch-aws\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\n\nclass DdbEsMoveToBinImpl implements MoveToBinStorageOperation.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 valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsMoveToBinParams\n ): Promise<void> {\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 partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n\n /**\n * Let's pick the `deleted` meta fields from the entry.\n */\n const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);\n\n /**\n * Then update all the records with data received.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n ...updatedEntryMetaFields,\n wbyDeleted: storageEntry.wbyDeleted,\n location: storageEntry.location,\n binOriginalFolderId: storageEntry.binOriginalFolderId\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\n }\n }\n\n /**\n * We write the records back to the primary DynamoDB table.\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 mark as deleted all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n /**\n * We need to get the published and latest records from Elasticsearch.\n */\n const esEntityReader = this.esEntity.createEntityReader();\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n /**\n * We update all ES records with data received.\n */\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n for (const item of esItems) {\n elasticsearchEntityBatch.put({\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n ...updatedEntryMetaFields,\n wbyDeleted: entry.wbyDeleted,\n location: entry.location,\n binOriginalFolderId: entry.binOriginalFolderId\n })\n });\n }\n\n /**\n * We write the records back to the primary DynamoDB Elasticsearch table.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not mark as deleted entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveToBin = MoveToBinStorageOperation.createImplementation({\n implementation: DdbEsMoveToBinImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsMoveToBinImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","updatedEntryMetaFields","pickEntryMetaFields","isDeletedEntryMetaField","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveToBin","MoveToBinStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;AAyBA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,eAA6D,CACvE;aAPUN,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAgD,EACnC;QACb,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,eAAeC,mBAAmB;YACpC,IAAIH,MAAM,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O;QAE9C,MAAME,UACF,OAAMC,QAAQ,GAAG,CACbF,UAAU,GAAG,CAAC,OAAMJ;YAChB,IAAI,CAACA,QACD,OAAO;YAEX,OAAO;gBACH,GAAGA,MAAM;gBACT,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAACA,OAAO,IAAI;YAC9D;QACJ,GAAE,EAER,MAAM,CAAC,CAACO,OAAiD,CAAC,CAACA;QAE7D,IAAIF,AAAmB,MAAnBA,QAAQ,MAAM,EACd;QAMJ,MAAMG,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB;QAEjE,KAAK,MAAMD,QAAQF,QACfG,yBAAyB,GAAG,CAAC;YACzB,GAAGD,IAAI;YACP,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;gBACzC,GAAGA,KAAK,IAAI;gBACZ,GAAGb,sBAAsB;gBACzB,YAAYV,MAAM,UAAU;gBAC5B,UAAUA,MAAM,QAAQ;gBACxB,qBAAqBA,MAAM,mBAAmB;YAClD;QACJ;QAMJ,IAAI;YACA,MAAMwB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IACN,8EACJA,GAAG,IAAI,IAAI,2BACX;gBACI,OAAOA;gBACPjB;gBACAC;YACJ;QAER;IACJ;AACJ;AAEO,MAAMwB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
|
|
1
|
+
{"version":3,"file":"operations/entry/DdbEsMoveToBin.js","sources":["../../../src/operations/entry/DdbEsMoveToBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsEntryStorageOperationsMoveToBinParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveToBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.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} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\nimport {\n isDeletedEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch-aws\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\n\nclass DdbEsMoveToBinImpl implements MoveToBinStorageOperation.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 valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[],\n private scopeTenant: ScopeTenant.Interface\n ) {}\n\n async execute(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsMoveToBinParams\n ): Promise<void> {\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,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant\n });\n\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n\n /**\n * Let's pick the `deleted` meta fields from the entry.\n */\n const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);\n\n /**\n * Then update all the records with data received.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n ...updatedEntryMetaFields,\n wbyDeleted: storageEntry.wbyDeleted,\n location: storageEntry.location,\n binOriginalFolderId: storageEntry.binOriginalFolderId\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\n }\n }\n\n /**\n * We write the records back to the primary DynamoDB table.\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 mark as deleted all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n /**\n * We need to get the published and latest records from Elasticsearch.\n */\n const esEntityReader = this.esEntity.createEntityReader();\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n /**\n * We update all ES records with data received.\n */\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n for (const item of esItems) {\n elasticsearchEntityBatch.put({\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n ...updatedEntryMetaFields,\n wbyDeleted: entry.wbyDeleted,\n location: entry.location,\n binOriginalFolderId: entry.binOriginalFolderId\n })\n });\n }\n\n /**\n * We write the records back to the primary DynamoDB Elasticsearch table.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not mark as deleted entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveToBin = MoveToBinStorageOperation.createImplementation({\n implementation: DdbEsMoveToBinImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }],\n ScopeTenant\n ]\n});\n"],"names":["DdbEsMoveToBinImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","scopeTenant","initialModel","params","initialEntry","initialStorageEntry","tenant","model","transformer","createTransformer","entry","storageEntry","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","updatedEntryMetaFields","pickEntryMetaFields","isDeletedEntryMetaField","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveToBin","MoveToBinStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier","ScopeTenant"],"mappings":";;;;;;;;;;;;AA0BA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,eAA6D,EAC7DC,WAAkC,CAC5C;aARUP,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAgD,EACnC;QACb,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,OAAOH;YACP,cAAcC;YACd,oBAAoB,IAAI,CAAC,kBAAkB;YAC3C,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAM,EAAEK,KAAK,EAAEC,YAAY,EAAE,GAAGH,YAAY,kBAAkB;QAE9D,MAAMI,eAAeC,mBAAmB;YACpC,IAAIH,MAAM,EAAE;YACZJ;QACJ;QAKA,MAAMQ,iBAAwC;YAC1CF;YACA,SAAS;gBACL,KAAK;YACT;QACJ;QA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GAAGA,MAAM;gBACT,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAACA,OAAO,IAAI;YAC9D;QACJ,GAAE,EAER,MAAM,CAAC,CAACO,OAAiD,CAAC,CAACA;QAE7D,IAAIF,AAAmB,MAAnBA,QAAQ,MAAM,EACd;QAMJ,MAAMG,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB;QAEjE,KAAK,MAAMD,QAAQF,QACfG,yBAAyB,GAAG,CAAC;YACzB,GAAGD,IAAI;YACP,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;gBACzC,GAAGA,KAAK,IAAI;gBACZ,GAAGb,sBAAsB;gBACzB,YAAYV,MAAM,UAAU;gBAC5B,UAAUA,MAAM,QAAQ;gBACxB,qBAAqBA,MAAM,mBAAmB;YAClD;QACJ;QAMJ,IAAI;YACA,MAAMwB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IACN,8EACJA,GAAG,IAAI,IAAI,2BACX;gBACI,OAAOA;gBACPjB;gBACAC;YACJ;QAER;IACJ;AACJ;AAEO,MAAMwB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgB3C;IAChB,cAAc;QACV4C;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 DdbEsPublishEntryImpl implements PublishEntryStorageOperation.Interface {
|
|
10
11
|
private entity;
|
|
11
12
|
private esEntity;
|
|
@@ -15,7 +16,8 @@ declare class DdbEsPublishEntryImpl implements PublishEntryStorageOperation.Inte
|
|
|
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: CmsEntryStorageOperationsPublishParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
|
|
20
22
|
}
|
|
21
23
|
export declare const DdbEsPublishEntry: typeof DdbEsPublishEntryImpl & {
|