@mavenmachines/event-handler-lib 1.4.5-6 → 1.4.5-7
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/dist/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { EsReferenceIdsType } from "@mavenmachines/event-sourcing-types";
|
|
2
|
-
import {
|
|
2
|
+
import { GetAggregateReferencesRequest } from "@mavenmachines/es-references-store-client";
|
|
3
3
|
import { ProjectionModifierPlugin } from "./projectionModifierPlugin";
|
|
4
4
|
import { EventSourcedProjection, LoggerService, ReferenceIdsType } from "../../exports";
|
|
5
5
|
export declare abstract class SyncReferenceIdsPlugin<ProjectionT extends Record<string, any>> extends ProjectionModifierPlugin<ProjectionT, Record<string, EsReferenceIdsType>> {
|
|
6
|
-
|
|
7
|
-
constructor(loggerService: LoggerService, client: EsReferencesStoreClient);
|
|
6
|
+
constructor(loggerService: LoggerService);
|
|
8
7
|
abstract createGetAggregateReferenceRequests(projection: EventSourcedProjection<ProjectionT>): GetAggregateReferencesRequest[];
|
|
9
8
|
protected getExistingReferenceIds(projection: EventSourcedProjection<ProjectionT>): Promise<Record<string, ReferenceIdsType>>;
|
|
10
9
|
abstract createReferenceIds(projection: EventSourcedProjection<ProjectionT>): Promise<Record<string, ReferenceIdsType>>;
|
|
@@ -13,64 +13,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SyncReferenceIdsPlugin = void 0;
|
|
16
|
-
const es_references_store_client_1 = require("@mavenmachines/es-references-store-client");
|
|
17
16
|
const projectionModifierPlugin_1 = require("./projectionModifierPlugin");
|
|
18
17
|
const exports_1 = require("../../exports");
|
|
19
18
|
const inversify_1 = require("inversify");
|
|
20
19
|
let SyncReferenceIdsPlugin = class SyncReferenceIdsPlugin extends projectionModifierPlugin_1.ProjectionModifierPlugin {
|
|
21
|
-
constructor(loggerService
|
|
20
|
+
constructor(loggerService) {
|
|
22
21
|
super(loggerService);
|
|
23
|
-
this.client = client;
|
|
24
22
|
}
|
|
25
23
|
async getExistingReferenceIds(projection) {
|
|
26
|
-
|
|
27
|
-
const results = [];
|
|
28
|
-
for (const req of requests) {
|
|
29
|
-
const references = await this.client.getAggregateReferences(req);
|
|
30
|
-
const referenceIds = Object.fromEntries(references.map((ref) => [ref.referenceKey, ref.referenceValue]));
|
|
31
|
-
results.push([
|
|
32
|
-
`${projection.companyId}_${projection.projectionType}_${projection.entityId}`,
|
|
33
|
-
referenceIds,
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
return Object.fromEntries(results);
|
|
24
|
+
return {};
|
|
37
25
|
}
|
|
38
26
|
async setReferenceIds(projection, previous, updated) {
|
|
39
|
-
for (const [aggregateId, previousRefs] of Object.entries(previous)) {
|
|
40
|
-
const updatedRefs = updated[aggregateId] ?? {};
|
|
41
|
-
const refsToDelete = {};
|
|
42
|
-
for (const [refKey, refValue] of Object.entries(previousRefs)) {
|
|
43
|
-
if (!(refKey in updatedRefs)) {
|
|
44
|
-
refsToDelete[refKey] = refValue;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (Object.keys(refsToDelete).length > 0) {
|
|
48
|
-
const deleteRequest = {
|
|
49
|
-
companyId: projection.companyId,
|
|
50
|
-
aggregateType: projection.projectionType,
|
|
51
|
-
referenceIdsList: [refsToDelete],
|
|
52
|
-
};
|
|
53
|
-
await this.client.deleteAggregateReferences(deleteRequest);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
for (const [aggregateId, updatedRefs] of Object.entries(updated)) {
|
|
57
|
-
const previousRefs = previous[aggregateId] ?? {};
|
|
58
|
-
const refsToAdd = {};
|
|
59
|
-
for (const [refKey, refValue] of Object.entries(updatedRefs)) {
|
|
60
|
-
if (previousRefs[refKey] !== refValue) {
|
|
61
|
-
refsToAdd[refKey] = refValue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (Object.keys(refsToAdd).length > 0) {
|
|
65
|
-
const addRequest = {
|
|
66
|
-
companyId: projection.companyId,
|
|
67
|
-
aggregateType: projection.projectionType,
|
|
68
|
-
aggregateId: aggregateId,
|
|
69
|
-
referenceIds: refsToAdd,
|
|
70
|
-
};
|
|
71
|
-
await this.client.addAggregateReferences(addRequest);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
27
|
return updated;
|
|
75
28
|
}
|
|
76
29
|
async onCreate(projection) {
|
|
@@ -103,8 +56,6 @@ exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin;
|
|
|
103
56
|
exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin = __decorate([
|
|
104
57
|
(0, inversify_1.injectable)(),
|
|
105
58
|
__param(0, (0, inversify_1.inject)(exports_1.LoggerService)),
|
|
106
|
-
|
|
107
|
-
__metadata("design:paramtypes", [exports_1.LoggerService,
|
|
108
|
-
es_references_store_client_1.EsReferencesStoreClient])
|
|
59
|
+
__metadata("design:paramtypes", [exports_1.LoggerService])
|
|
109
60
|
], SyncReferenceIdsPlugin);
|
|
110
61
|
//# sourceMappingURL=syncReferencIdsPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncReferencIdsPlugin.js","sourceRoot":"","sources":["../../../../src/helpers/plugins/syncReferencIdsPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"syncReferencIdsPlugin.js","sourceRoot":"","sources":["../../../../src/helpers/plugins/syncReferencIdsPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,yEAAsE;AACtE,2CAIuB;AAEvB,yCAA+C;AAIxC,IAAe,sBAAsB,GAArC,MAAe,sBAEpB,SAAQ,mDAGT;IACC,YACyB,aAA4B;QAInD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAMS,KAAK,CAAC,uBAAuB,CACrC,UAA+C;QAoB/C,O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