@mavenmachines/event-handler-lib 1.4.5-41 → 1.4.5-42
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mavenmachines/event-handler-lib",
|
|
3
|
-
"version": "1.4.5-
|
|
3
|
+
"version": "1.4.5-42",
|
|
4
4
|
"description": "Helper libraries for creating an Event Handler",
|
|
5
5
|
"module": "./dist/src/index.mjs",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@confluentinc/kafka-javascript": "^1.4.1",
|
|
67
67
|
"@google-cloud/firestore": "^7.8.0",
|
|
68
68
|
"@mavenmachines/directory-service-client": "^1.4.5",
|
|
69
|
-
"@mavenmachines/es-references-store-client": "^1.0.14-
|
|
69
|
+
"@mavenmachines/es-references-store-client": "^1.0.14-2",
|
|
70
70
|
"@mavenmachines/event-sourcing-types": "^1.0.86",
|
|
71
71
|
"@mavenmachines/feature-flags-client": "^1.2.0",
|
|
72
72
|
"@mavenmachines/prometheus-nodejs-client": "^1.0.2",
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { AggregateTypeEnum } from "@mavenmachines/event-sourcing-types";
|
|
2
1
|
import { EsReferencesStoreClient, GetAggregateReferencesRequest } from "@mavenmachines/es-references-store-client";
|
|
3
2
|
import { ProjectionModifierPlugin } from "./projectionModifierPlugin";
|
|
4
3
|
import { EventSourcedProjection, LoggerService, ReferenceIdsType } from "../../exports";
|
|
5
|
-
type FlatReferenceId = {
|
|
6
|
-
entityId: string;
|
|
7
|
-
key: string;
|
|
8
|
-
value: string;
|
|
9
|
-
};
|
|
10
4
|
export declare abstract class SyncReferenceIdsPlugin<ProjectionT extends Record<string, any>> extends ProjectionModifierPlugin<ProjectionT, Record<string, ReferenceIdsType>> {
|
|
11
5
|
protected readonly client: EsReferencesStoreClient;
|
|
12
6
|
constructor(loggerService: LoggerService, client: EsReferencesStoreClient);
|
|
@@ -20,6 +14,4 @@ export declare abstract class SyncReferenceIdsPlugin<ProjectionT extends Record<
|
|
|
20
14
|
rollbackOnCreate(projection: EventSourcedProjection<ProjectionT>, data: Record<string, ReferenceIdsType>): Promise<void>;
|
|
21
15
|
rollbackOnUpdate(projection: EventSourcedProjection<ProjectionT>, data: Record<string, ReferenceIdsType>): Promise<void>;
|
|
22
16
|
rollbackOnDelete(projection: EventSourcedProjection<ProjectionT>, data: Record<string, ReferenceIdsType>): Promise<void>;
|
|
23
|
-
ensureNoConflicts(companyId: number, aggregateType: AggregateTypeEnum, ids: FlatReferenceId[]): Promise<void>;
|
|
24
17
|
}
|
|
25
|
-
export {};
|
|
@@ -11,17 +11,12 @@ 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
16
|
const es_references_store_client_1 = require("@mavenmachines/es-references-store-client");
|
|
20
17
|
const projectionModifierPlugin_1 = require("./projectionModifierPlugin");
|
|
21
18
|
const exports_1 = require("../../exports");
|
|
22
19
|
const inversify_1 = require("inversify");
|
|
23
|
-
const lodash_1 = require("lodash");
|
|
24
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
|
25
20
|
let SyncReferenceIdsPlugin = class SyncReferenceIdsPlugin extends projectionModifierPlugin_1.ProjectionModifierPlugin {
|
|
26
21
|
constructor(loggerService, client) {
|
|
27
22
|
super(loggerService);
|
|
@@ -41,29 +36,26 @@ let SyncReferenceIdsPlugin = class SyncReferenceIdsPlugin extends projectionModi
|
|
|
41
36
|
return Object.fromEntries(results);
|
|
42
37
|
}
|
|
43
38
|
async setReferenceIds(projection, previous, updated) {
|
|
44
|
-
const { added, previousValues, updatedValues, removed } = diffReferenceIds(previous, updated);
|
|
45
39
|
const companyId = projection.companyId;
|
|
46
40
|
const aggregateType = projection.projectionType;
|
|
47
|
-
await this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await bluebird_1.default.map(requests, (request) => this.client.addAggregateReferences(request));
|
|
66
|
-
}
|
|
41
|
+
await this.client.runTransaction(async () => {
|
|
42
|
+
const toRemove = Array.from(findRemovedIds(previous, updated));
|
|
43
|
+
if (toRemove.length) {
|
|
44
|
+
await this.client.deleteAggregateReferences({
|
|
45
|
+
companyId,
|
|
46
|
+
aggregateType,
|
|
47
|
+
referenceIdsList: toRemove,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
for (const [entityId, referenceIds] of Object.entries(updated)) {
|
|
51
|
+
await this.client.addAggregateReferences({
|
|
52
|
+
companyId,
|
|
53
|
+
aggregateType,
|
|
54
|
+
aggregateId: entityId,
|
|
55
|
+
referenceIds,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
67
59
|
return previous;
|
|
68
60
|
}
|
|
69
61
|
async onCreate(projection) {
|
|
@@ -98,19 +90,6 @@ let SyncReferenceIdsPlugin = class SyncReferenceIdsPlugin extends projectionModi
|
|
|
98
90
|
const existingReferenceIds = await this.getExistingReferenceIds(projection);
|
|
99
91
|
this.setReferenceIds(projection, existingReferenceIds, data);
|
|
100
92
|
}
|
|
101
|
-
async ensureNoConflicts(companyId, aggregateType, ids) {
|
|
102
|
-
if (ids.length === 0) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const existing = await this.client.getAggregateReferences({
|
|
106
|
-
companyId,
|
|
107
|
-
aggregateType,
|
|
108
|
-
referenceIds: Object.fromEntries(ids.map(({ key, value }) => [key, value])),
|
|
109
|
-
});
|
|
110
|
-
if (existing.length) {
|
|
111
|
-
throw new Error(`${existing.length} referenceId conflicts: ${JSON.stringify(existing)}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
93
|
};
|
|
115
94
|
exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin;
|
|
116
95
|
exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin = __decorate([
|
|
@@ -120,33 +99,13 @@ exports.SyncReferenceIdsPlugin = SyncReferenceIdsPlugin = __decorate([
|
|
|
120
99
|
__metadata("design:paramtypes", [exports_1.LoggerService,
|
|
121
100
|
es_references_store_client_1.EsReferencesStoreClient])
|
|
122
101
|
], SyncReferenceIdsPlugin);
|
|
123
|
-
function*
|
|
124
|
-
for (const [entityId, referenceIds] of Object.entries(
|
|
102
|
+
function* findRemovedIds(previous, updated) {
|
|
103
|
+
for (const [entityId, referenceIds] of Object.entries(previous)) {
|
|
125
104
|
for (const [key, value] of Object.entries(referenceIds)) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
function diffReferenceIds(previous, updated) {
|
|
131
|
-
const added = [];
|
|
132
|
-
const removed = [];
|
|
133
|
-
const previousValues = [];
|
|
134
|
-
const updatedValues = [];
|
|
135
|
-
for (const { entityId, key, value } of iterateIds(updated)) {
|
|
136
|
-
const existing = previous[entityId]?.[key];
|
|
137
|
-
if (existing === undefined) {
|
|
138
|
-
added.push({ entityId, key, value });
|
|
139
|
-
}
|
|
140
|
-
else if (existing !== value) {
|
|
141
|
-
previousValues.push({ entityId, key, value: existing });
|
|
142
|
-
updatedValues.push({ entityId, key, value });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
for (const { entityId, key, value } of iterateIds(previous)) {
|
|
146
|
-
if (updated[entityId]?.[key] === undefined) {
|
|
147
|
-
removed.push({ entityId, key, value });
|
|
105
|
+
if (updated[entityId]?.[key] === undefined) {
|
|
106
|
+
yield { entityId, key, value };
|
|
107
|
+
}
|
|
148
108
|
}
|
|
149
109
|
}
|
|
150
|
-
return { added, removed, previousValues, updatedValues };
|
|
151
110
|
}
|
|
152
111
|
//# 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":";;;;;;;;;;;;;;;AACA,0FAImD;AACnD,yEAAsE;AACtE,2CAIuB;AACvB,yCAA+C;AAMxC,IAAe,sBAAsB,GAArC,MAAe,sBAEpB,SAAQ,mDAGT;IACC,YACyB,aAA4B,EAEhC,MAA+B;QAElD,KAAK,CAAC,aAAa,CAAC,CAAC;QAFF,WAAM,GAAN,MAAM,CAAyB;IAGpD,CAAC;IAMS,KAAK,CAAC,uBAAuB,CACrC,UAA+C;QAE/C,MAAM,QAAQ,GAAG,IAAI,CAAC,mCAAmC,CAAC,UAAU,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,UAAU,GACd,MAAM,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;YAChD,MAAM,YAAY,GAAqB,MAAM,CAAC,WAAW,CACvD,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAChE,CAAC;YAEF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EAC/C,IAAsC;QAEtC,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAC5E,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;CACF,CAAA;AAnIqB,wDAAsB;iCAAtB,sBAAsB;IAD3C,IAAA,sBAAU,GAAE;IAQR,WAAA,IAAA,kBAAM,EAAC,uBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,kBAAM,EAAC,oDAAuB,CAAC,CAAA;qCADM,uBAAa;QAExB,oDAAuB;GAThC,sBAAsB,CAmI3C;AAED,QAAQ,CAAC,CAAC,cAAc,CACtB,QAA0C,EAC1C,OAAyC;IAEzC,KAAK,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACxD,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mavenmachines/event-handler-lib",
|
|
3
|
-
"version": "1.4.5-
|
|
3
|
+
"version": "1.4.5-42",
|
|
4
4
|
"description": "Helper libraries for creating an Event Handler",
|
|
5
5
|
"module": "./dist/src/index.mjs",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@confluentinc/kafka-javascript": "^1.4.1",
|
|
67
67
|
"@google-cloud/firestore": "^7.8.0",
|
|
68
68
|
"@mavenmachines/directory-service-client": "^1.4.5",
|
|
69
|
-
"@mavenmachines/es-references-store-client": "^1.0.14-
|
|
69
|
+
"@mavenmachines/es-references-store-client": "^1.0.14-2",
|
|
70
70
|
"@mavenmachines/event-sourcing-types": "^1.0.86",
|
|
71
71
|
"@mavenmachines/feature-flags-client": "^1.2.0",
|
|
72
72
|
"@mavenmachines/prometheus-nodejs-client": "^1.0.2",
|