@mavenmachines/event-handler-lib 1.4.5-5 → 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>>;
|
|
@@ -11,71 +11,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
15
|
exports.SyncReferenceIdsPlugin = void 0;
|
|
19
|
-
const es_references_store_client_1 = require("@mavenmachines/es-references-store-client");
|
|
20
16
|
const projectionModifierPlugin_1 = require("./projectionModifierPlugin");
|
|
21
17
|
const exports_1 = require("../../exports");
|
|
22
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
|
23
18
|
const inversify_1 = require("inversify");
|
|
24
19
|
let SyncReferenceIdsPlugin = class SyncReferenceIdsPlugin extends projectionModifierPlugin_1.ProjectionModifierPlugin {
|
|
25
|
-
constructor(loggerService
|
|
20
|
+
constructor(loggerService) {
|
|
26
21
|
super(loggerService);
|
|
27
|
-
this.client = client;
|
|
28
22
|
}
|
|
29
23
|
async getExistingReferenceIds(projection) {
|
|
30
|
-
return
|
|
31
|
-
const references = await this.client.getAggregateReferences(req);
|
|
32
|
-
const referenceIds = Object.fromEntries(references.map((ref) => [ref.referenceKey, ref.referenceValue]));
|
|
33
|
-
return [
|
|
34
|
-
`${projection.companyId}_${projection.projectionType}_${projection.entityId}`,
|
|
35
|
-
referenceIds,
|
|
36
|
-
];
|
|
37
|
-
}, { concurrency: 5 }));
|
|
24
|
+
return {};
|
|
38
25
|
}
|
|
39
26
|
async setReferenceIds(projection, previous, updated) {
|
|
40
|
-
const deleteRequests = [];
|
|
41
|
-
for (const [aggregateId, previousRefs] of Object.entries(previous)) {
|
|
42
|
-
const updatedRefs = updated[aggregateId] ?? {};
|
|
43
|
-
const refsToDelete = {};
|
|
44
|
-
for (const [refKey, refValue] of Object.entries(previousRefs)) {
|
|
45
|
-
if (!(refKey in updatedRefs)) {
|
|
46
|
-
refsToDelete[refKey] = refValue;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (Object.keys(refsToDelete).length > 0) {
|
|
50
|
-
deleteRequests.push({
|
|
51
|
-
companyId: projection.companyId,
|
|
52
|
-
aggregateType: projection.projectionType,
|
|
53
|
-
referenceIdsList: [refsToDelete],
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const addRequests = [];
|
|
58
|
-
for (const [aggregateId, updatedRefs] of Object.entries(updated)) {
|
|
59
|
-
const previousRefs = previous[aggregateId] ?? {};
|
|
60
|
-
const refsToAdd = {};
|
|
61
|
-
for (const [refKey, refValue] of Object.entries(updatedRefs)) {
|
|
62
|
-
if (previousRefs[refKey] !== refValue) {
|
|
63
|
-
refsToAdd[refKey] = refValue;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (Object.keys(refsToAdd).length > 0) {
|
|
67
|
-
addRequests.push({
|
|
68
|
-
companyId: projection.companyId,
|
|
69
|
-
aggregateType: projection.projectionType,
|
|
70
|
-
aggregateId: aggregateId,
|
|
71
|
-
referenceIds: refsToAdd,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
await Promise.all([
|
|
76
|
-
bluebird_1.default.map(deleteRequests, req => this.client.deleteAggregateReferences(req), { concurrency: 5 }),
|
|
77
|
-
bluebird_1.default.map(addRequests, req => this.client.addAggregateReferences(req), { concurrency: 5 }),
|
|
78
|
-
]);
|
|
79
27
|
return updated;
|
|
80
28
|
}
|
|
81
29
|
async onCreate(projection) {
|
|
@@ -108,8 +56,6 @@ exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin;
|
|
|
108
56
|
exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin = __decorate([
|
|
109
57
|
(0, inversify_1.injectable)(),
|
|
110
58
|
__param(0, (0, inversify_1.inject)(exports_1.LoggerService)),
|
|
111
|
-
|
|
112
|
-
__metadata("design:paramtypes", [exports_1.LoggerService,
|
|
113
|
-
es_references_store_client_1.EsReferencesStoreClient])
|
|
59
|
+
__metadata("design:paramtypes", [exports_1.LoggerService])
|
|
114
60
|
], SyncReferenceIdsPlugin);
|
|
115
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","source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