@zeeshan60/event-processor 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ActivityEventHandler.d.ts +1 -0
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +14 -1
- package/dist/EventProcessorSDK.d.ts +26 -1
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +75 -1
- package/dist/FriendEventHandler.d.ts +1 -0
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +50 -7
- package/dist/GroupEventHandler.d.ts +1 -0
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +86 -14
- package/dist/GroupTransactionEventHandler.d.ts +1 -0
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +47 -9
- package/dist/ModelChangeEmitter.d.ts +15 -0
- package/dist/ModelChangeEmitter.d.ts.map +1 -0
- package/dist/ModelChangeEmitter.js +31 -0
- package/dist/TransactionEventHandler.d.ts +1 -0
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +20 -2
- package/dist/UserEventHandler.d.ts +1 -0
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +26 -3
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.js +1 -3
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.js +1 -3
- package/dist/__tests__/test-helpers/IMFriendEventStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMFriendEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMFriendEventStore.js +1 -3
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMFriendModelStore.js +1 -3
- package/dist/__tests__/test-helpers/IMGroupEventStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMGroupEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupEventStore.js +1 -3
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupModelStore.js +1 -3
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.js +1 -3
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.js +1 -3
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionEventStore.js +1 -3
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.js +1 -3
- package/dist/__tests__/test-helpers/IMUserEventStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMUserEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserEventStore.js +1 -3
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.js +1 -3
- package/dist/client/controllers/FriendController.d.ts +6 -5
- package/dist/client/controllers/FriendController.d.ts.map +1 -1
- package/dist/client/controllers/FriendController.js +23 -12
- package/dist/client/controllers/UserController.d.ts.map +1 -1
- package/dist/client/controllers/UserController.js +3 -23
- package/dist/client/handlers/UIEventHandler.d.ts +4 -22
- package/dist/client/handlers/UIEventHandler.d.ts.map +1 -1
- package/dist/client/handlers/UIEventHandler.js +59 -40
- package/dist/converters/eventConverter.d.ts.map +1 -1
- package/dist/converters/eventConverter.js +26 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/store/ActivityLogEventStore.d.ts +2 -2
- package/dist/store/ActivityLogEventStore.d.ts.map +1 -1
- package/dist/store/ActivityLogEventStore.js +0 -4
- package/dist/store/ActivityLogModelStore.d.ts +4 -4
- package/dist/store/ActivityLogModelStore.d.ts.map +1 -1
- package/dist/store/ActivityLogModelStore.js +0 -5
- package/dist/store/FriendEventStore.d.ts +2 -2
- package/dist/store/FriendEventStore.d.ts.map +1 -1
- package/dist/store/FriendEventStore.js +0 -4
- package/dist/store/FriendModelStore.d.ts +9 -9
- package/dist/store/FriendModelStore.d.ts.map +1 -1
- package/dist/store/FriendModelStore.js +0 -5
- package/dist/store/GroupEventStore.d.ts +2 -2
- package/dist/store/GroupEventStore.d.ts.map +1 -1
- package/dist/store/GroupEventStore.js +0 -4
- package/dist/store/GroupModelStore.d.ts +6 -6
- package/dist/store/GroupModelStore.d.ts.map +1 -1
- package/dist/store/GroupModelStore.js +0 -5
- package/dist/store/GroupTransactionEventStore.d.ts +2 -2
- package/dist/store/GroupTransactionEventStore.d.ts.map +1 -1
- package/dist/store/GroupTransactionEventStore.js +0 -4
- package/dist/store/GroupTransactionModelStore.d.ts +6 -6
- package/dist/store/GroupTransactionModelStore.d.ts.map +1 -1
- package/dist/store/GroupTransactionModelStore.js +0 -5
- package/dist/store/ModelStore.d.ts +4 -4
- package/dist/store/ModelStore.d.ts.map +1 -1
- package/dist/store/ModelStore.js +0 -4
- package/dist/store/TransactionEventStore.d.ts +2 -2
- package/dist/store/TransactionEventStore.d.ts.map +1 -1
- package/dist/store/TransactionEventStore.js +0 -4
- package/dist/store/TransactionModelStore.d.ts +6 -6
- package/dist/store/TransactionModelStore.d.ts.map +1 -1
- package/dist/store/TransactionModelStore.js +0 -5
- package/dist/store/UserEventStore.d.ts +2 -2
- package/dist/store/UserEventStore.d.ts.map +1 -1
- package/dist/store/UserEventStore.js +0 -4
- package/dist/store/UserModelStore.d.ts +7 -7
- package/dist/store/UserModelStore.d.ts.map +1 -1
- package/dist/store/UserModelStore.js +0 -5
- package/package.json +1 -1
- package/dist/__tests__/e2e/setup/firebaseEmulator.d.ts +0 -3
- package/dist/__tests__/e2e/setup/firebaseEmulator.d.ts.map +0 -1
- package/dist/__tests__/e2e/setup/firebaseEmulator.js +0 -87
- package/dist/__tests__/e2e/setup/firestoreStores.d.ts +0 -28
- package/dist/__tests__/e2e/setup/firestoreStores.d.ts.map +0 -1
- package/dist/__tests__/e2e/setup/firestoreStores.js +0 -276
- package/dist/__tests__/e2e/setup/firestoreTestHelpers.d.ts +0 -15
- package/dist/__tests__/e2e/setup/firestoreTestHelpers.d.ts.map +0 -1
- package/dist/__tests__/e2e/setup/firestoreTestHelpers.js +0 -167
- package/dist/adapters/FirebaseAdminAdapter.d.ts +0 -8
- package/dist/adapters/FirebaseAdminAdapter.d.ts.map +0 -1
- package/dist/adapters/FirebaseAdminAdapter.js +0 -21
- package/dist/adapters/FirebaseClientAdapter.d.ts +0 -8
- package/dist/adapters/FirebaseClientAdapter.d.ts.map +0 -1
- package/dist/adapters/FirebaseClientAdapter.js +0 -22
- package/dist/client/handlers/UIActivityEventHandler.d.ts +0 -12
- package/dist/client/handlers/UIActivityEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIActivityEventHandler.js +0 -14
- package/dist/common/EventBus.d.ts +0 -12
- package/dist/common/EventBus.d.ts.map +0 -1
- package/dist/common/EventBus.js +0 -26
- package/dist/common/EventBusSingleton.d.ts +0 -4
- package/dist/common/EventBusSingleton.d.ts.map +0 -1
- package/dist/common/EventBusSingleton.js +0 -18
- package/dist/config/environment.d.ts +0 -25
- package/dist/config/environment.d.ts.map +0 -1
- package/dist/config/environment.js +0 -77
- package/dist/controllers/UIEventHandler.d.ts +0 -25
- package/dist/controllers/UIEventHandler.d.ts.map +0 -1
- package/dist/controllers/UIEventHandler.js +0 -50
- package/dist/controllers/UserController.d.ts +0 -9
- package/dist/controllers/UserController.d.ts.map +0 -1
- package/dist/controllers/UserController.js +0 -36
|
@@ -7,6 +7,7 @@ export declare class ActivityEventHandler {
|
|
|
7
7
|
private activityLogEventStore;
|
|
8
8
|
private userModelStore;
|
|
9
9
|
constructor(activityLogModelStore: ActivityLogModelStore, activityLogEventStore: ActivityLogEventStore, userModelStore: UserModelStore);
|
|
10
|
+
private shouldSkipSave;
|
|
10
11
|
createActivityLog(event: Event, existingModel: Model | undefined, updatedModel: Model): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=ActivityEventHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityEventHandler.d.ts","sourceRoot":"","sources":["../src/ActivityEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAA+C,MAAM,GAAG,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"ActivityEventHandler.d.ts","sourceRoot":"","sources":["../src/ActivityEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAA+C,MAAM,GAAG,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAGnC,qBAAa,oBAAoB;IAEzB,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,cAAc;gBAFd,qBAAqB,EAAE,qBAAqB,EAC5C,qBAAqB,EAAE,qBAAqB,EAC5C,cAAc,EAAE,cAAc;IAG1C,OAAO,CAAC,cAAc;IAahB,iBAAiB,CACnB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,KAAK,GAAG,SAAS,EAChC,YAAY,EAAE,KAAK,GACpB,OAAO,CAAC,IAAI,CAAC;CAsCnB"}
|
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActivityEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
5
6
|
class ActivityEventHandler {
|
|
6
7
|
constructor(activityLogModelStore, activityLogEventStore, userModelStore) {
|
|
7
8
|
this.activityLogModelStore = activityLogModelStore;
|
|
8
9
|
this.activityLogEventStore = activityLogEventStore;
|
|
9
10
|
this.userModelStore = userModelStore;
|
|
10
11
|
}
|
|
12
|
+
shouldSkipSave(existingModel, updatedModel) {
|
|
13
|
+
if (!existingModel) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return (existingModel.streamId === updatedModel.streamId &&
|
|
17
|
+
existingModel.version === updatedModel.version);
|
|
18
|
+
}
|
|
11
19
|
async createActivityLog(event, existingModel, updatedModel) {
|
|
12
20
|
if (!event.activityLog) {
|
|
13
21
|
return;
|
|
@@ -29,7 +37,12 @@ class ActivityEventHandler {
|
|
|
29
37
|
const activityLogEvent = new _1.ActivityLogCreated(activityLogProps);
|
|
30
38
|
const activityLogModel = activityLogEvent.apply();
|
|
31
39
|
await this.activityLogEventStore.addEvent(activityLogEvent);
|
|
32
|
-
|
|
40
|
+
if (!this.shouldSkipSave(undefined, activityLogModel)) {
|
|
41
|
+
await this.activityLogModelStore.save(activityLogModel);
|
|
42
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
43
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("ActivityLogModel", activityLogModel);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
exports.ActivityEventHandler = ActivityEventHandler;
|
|
@@ -14,8 +14,11 @@ import { UserController } from "./client/controllers/UserController";
|
|
|
14
14
|
import { FriendController } from "./client/controllers/FriendController";
|
|
15
15
|
import { UIEventHandler } from "./client/handlers/UIEventHandler";
|
|
16
16
|
import { FirebaseAdapter } from "./adapters/FirebaseAdapter";
|
|
17
|
-
import
|
|
17
|
+
import { Event, FriendEventHandler, UserEventHandler, TransactionEventHandler, GroupEventHandler, GroupTransactionEventHandler, ActivityEventHandler } from "./events";
|
|
18
|
+
import { Model } from "./common/Model";
|
|
18
19
|
import type { FirestoreEventData } from "./converters/eventConverter";
|
|
20
|
+
import { ModelChange } from "./ModelChangeEmitter";
|
|
21
|
+
import { Observable } from "rxjs";
|
|
19
22
|
export type StoreConfig = {
|
|
20
23
|
firebaseAdapter: FirebaseAdapter;
|
|
21
24
|
userModelStore: UserModelStore;
|
|
@@ -37,6 +40,13 @@ export declare class EventProcessorSDK {
|
|
|
37
40
|
private userControllerInstance;
|
|
38
41
|
private friendControllerInstance;
|
|
39
42
|
private uiEventHandlerInstance;
|
|
43
|
+
private userEventHandlerInstance;
|
|
44
|
+
private friendEventHandlerInstance;
|
|
45
|
+
private transactionEventHandlerInstance;
|
|
46
|
+
private groupEventHandlerInstance;
|
|
47
|
+
private groupTransactionEventHandlerInstance;
|
|
48
|
+
private activityEventHandlerInstance;
|
|
49
|
+
private readonly modelChangeEmitter;
|
|
40
50
|
private constructor();
|
|
41
51
|
static initialize(config: StoreConfig): EventProcessorSDK;
|
|
42
52
|
static getInstance(): EventProcessorSDK;
|
|
@@ -46,13 +56,28 @@ export declare class EventProcessorSDK {
|
|
|
46
56
|
getUserController(): UserController;
|
|
47
57
|
getFriendController(): FriendController;
|
|
48
58
|
getUIEventHandler(): UIEventHandler;
|
|
59
|
+
getUserEventHandler(): UserEventHandler;
|
|
60
|
+
getFriendEventHandler(): FriendEventHandler;
|
|
61
|
+
getTransactionEventHandler(): TransactionEventHandler;
|
|
62
|
+
getGroupEventHandler(): GroupEventHandler;
|
|
63
|
+
getGroupTransactionEventHandler(): GroupTransactionEventHandler;
|
|
64
|
+
getActivityEventHandler(): ActivityEventHandler;
|
|
49
65
|
getFirebaseAdapter(): FirebaseAdapter;
|
|
66
|
+
getModelChangeObservable(): Observable<ModelChange>;
|
|
67
|
+
emitModelChange(modelType: string, model: Model): void;
|
|
50
68
|
}
|
|
51
69
|
export declare function initializeSDK(config: StoreConfig): EventProcessorSDK;
|
|
52
70
|
export declare function getUserController(): UserController;
|
|
53
71
|
export declare function getFriendController(): FriendController;
|
|
54
72
|
export declare function getUIEventHandler(): UIEventHandler;
|
|
73
|
+
export declare function getUserEventHandler(): UserEventHandler;
|
|
74
|
+
export declare function getFriendEventHandler(): FriendEventHandler;
|
|
75
|
+
export declare function getTransactionEventHandler(): TransactionEventHandler;
|
|
76
|
+
export declare function getGroupEventHandler(): GroupEventHandler;
|
|
77
|
+
export declare function getGroupTransactionEventHandler(): GroupTransactionEventHandler;
|
|
78
|
+
export declare function getActivityEventHandler(): ActivityEventHandler;
|
|
55
79
|
export declare function getFirebaseAdapter(): FirebaseAdapter;
|
|
80
|
+
export declare function getModelChangeObservable(): Observable<ModelChange>;
|
|
56
81
|
export declare function eventToFirestore(event: Event): FirestoreEventData;
|
|
57
82
|
export declare function firestoreToEvent(data: FirestoreEventData): Event;
|
|
58
83
|
export declare function isSDKInitialized(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventProcessorSDK.d.ts","sourceRoot":"","sources":["../src/EventProcessorSDK.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAK7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"EventProcessorSDK.d.ts","sourceRoot":"","sources":["../src/EventProcessorSDK.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,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I,UAAU,CAAC,WAAW,CAAC;IAInD,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;CAGzD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,CAEpE;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAElD;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,CAEtD;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAElD;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,CAEtD;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,CAE1D;AAED,wBAAgB,0BAA0B,IAAI,uBAAuB,CAEpE;AAED,wBAAgB,oBAAoB,IAAI,iBAAiB,CAExD;AAED,wBAAgB,+BAA+B,IAAI,4BAA4B,CAE9E;AAED,wBAAgB,uBAAuB,IAAI,oBAAoB,CAE9D;AAED,wBAAgB,kBAAkB,IAAI,eAAe,CAEpD;AAED,wBAAgB,wBAAwB,IAAI,UAAU,CAAC,WAAW,CAAC,CAElE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB,CAGjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,GAAG,KAAK,CAGhE;AAED,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C"}
|
|
@@ -5,7 +5,14 @@ exports.initializeSDK = initializeSDK;
|
|
|
5
5
|
exports.getUserController = getUserController;
|
|
6
6
|
exports.getFriendController = getFriendController;
|
|
7
7
|
exports.getUIEventHandler = getUIEventHandler;
|
|
8
|
+
exports.getUserEventHandler = getUserEventHandler;
|
|
9
|
+
exports.getFriendEventHandler = getFriendEventHandler;
|
|
10
|
+
exports.getTransactionEventHandler = getTransactionEventHandler;
|
|
11
|
+
exports.getGroupEventHandler = getGroupEventHandler;
|
|
12
|
+
exports.getGroupTransactionEventHandler = getGroupTransactionEventHandler;
|
|
13
|
+
exports.getActivityEventHandler = getActivityEventHandler;
|
|
8
14
|
exports.getFirebaseAdapter = getFirebaseAdapter;
|
|
15
|
+
exports.getModelChangeObservable = getModelChangeObservable;
|
|
9
16
|
exports.eventToFirestore = eventToFirestore;
|
|
10
17
|
exports.firestoreToEvent = firestoreToEvent;
|
|
11
18
|
exports.isSDKInitialized = isSDKInitialized;
|
|
@@ -14,9 +21,12 @@ const UserController_1 = require("./client/controllers/UserController");
|
|
|
14
21
|
const FriendController_1 = require("./client/controllers/FriendController");
|
|
15
22
|
const UIEventHandler_1 = require("./client/handlers/UIEventHandler");
|
|
16
23
|
const eventConverter_1 = require("./converters/eventConverter");
|
|
24
|
+
const events_1 = require("./events");
|
|
25
|
+
const ModelChangeEmitter_1 = require("./ModelChangeEmitter");
|
|
17
26
|
class EventProcessorSDK {
|
|
18
27
|
constructor(config) {
|
|
19
28
|
this.storeConfig = config;
|
|
29
|
+
this.modelChangeEmitter = new ModelChangeEmitter_1.ModelChangeEmitter();
|
|
20
30
|
}
|
|
21
31
|
static initialize(config) {
|
|
22
32
|
EventProcessorSDK.instance = new EventProcessorSDK(config);
|
|
@@ -51,13 +61,56 @@ class EventProcessorSDK {
|
|
|
51
61
|
}
|
|
52
62
|
getUIEventHandler() {
|
|
53
63
|
if (!this.uiEventHandlerInstance) {
|
|
54
|
-
this.uiEventHandlerInstance = new UIEventHandler_1.UIEventHandler(
|
|
64
|
+
this.uiEventHandlerInstance = new UIEventHandler_1.UIEventHandler();
|
|
55
65
|
}
|
|
56
66
|
return this.uiEventHandlerInstance;
|
|
57
67
|
}
|
|
68
|
+
getUserEventHandler() {
|
|
69
|
+
if (!this.userEventHandlerInstance) {
|
|
70
|
+
this.userEventHandlerInstance = new events_1.UserEventHandler(this.storeConfig.userModelStore, this.storeConfig.userEventStore, this.getActivityEventHandler());
|
|
71
|
+
}
|
|
72
|
+
return this.userEventHandlerInstance;
|
|
73
|
+
}
|
|
74
|
+
getFriendEventHandler() {
|
|
75
|
+
if (!this.friendEventHandlerInstance) {
|
|
76
|
+
this.friendEventHandlerInstance = new events_1.FriendEventHandler(this.storeConfig.friendModelStore, this.storeConfig.userModelStore, this.storeConfig.friendEventStore, this.storeConfig.userEventStore, this.getActivityEventHandler());
|
|
77
|
+
}
|
|
78
|
+
return this.friendEventHandlerInstance;
|
|
79
|
+
}
|
|
80
|
+
getTransactionEventHandler() {
|
|
81
|
+
if (!this.transactionEventHandlerInstance) {
|
|
82
|
+
this.transactionEventHandlerInstance = new events_1.TransactionEventHandler(this.storeConfig.transactionModelStore, this.storeConfig.transactionEventStore, this.storeConfig.userModelStore, this.getActivityEventHandler());
|
|
83
|
+
}
|
|
84
|
+
return this.transactionEventHandlerInstance;
|
|
85
|
+
}
|
|
86
|
+
getGroupEventHandler() {
|
|
87
|
+
if (!this.groupEventHandlerInstance) {
|
|
88
|
+
this.groupEventHandlerInstance = new events_1.GroupEventHandler(this.storeConfig.groupModelStore, this.storeConfig.friendModelStore, this.storeConfig.userModelStore, this.storeConfig.groupEventStore, this.storeConfig.friendEventStore, this.getActivityEventHandler());
|
|
89
|
+
}
|
|
90
|
+
return this.groupEventHandlerInstance;
|
|
91
|
+
}
|
|
92
|
+
getGroupTransactionEventHandler() {
|
|
93
|
+
if (!this.groupTransactionEventHandlerInstance) {
|
|
94
|
+
this.groupTransactionEventHandlerInstance =
|
|
95
|
+
new events_1.GroupTransactionEventHandler(this.storeConfig.groupTransactionModelStore, this.storeConfig.groupTransactionEventStore, this.storeConfig.groupModelStore, this.storeConfig.transactionEventStore, this.storeConfig.transactionModelStore, this.getActivityEventHandler());
|
|
96
|
+
}
|
|
97
|
+
return this.groupTransactionEventHandlerInstance;
|
|
98
|
+
}
|
|
99
|
+
getActivityEventHandler() {
|
|
100
|
+
if (!this.activityEventHandlerInstance) {
|
|
101
|
+
this.activityEventHandlerInstance = new events_1.ActivityEventHandler(this.storeConfig.activityLogModelStore, this.storeConfig.activityLogEventStore, this.storeConfig.userModelStore);
|
|
102
|
+
}
|
|
103
|
+
return this.activityEventHandlerInstance;
|
|
104
|
+
}
|
|
58
105
|
getFirebaseAdapter() {
|
|
59
106
|
return this.storeConfig.firebaseAdapter;
|
|
60
107
|
}
|
|
108
|
+
getModelChangeObservable() {
|
|
109
|
+
return this.modelChangeEmitter.asObservable();
|
|
110
|
+
}
|
|
111
|
+
emitModelChange(modelType, model) {
|
|
112
|
+
this.modelChangeEmitter.emit(modelType, model);
|
|
113
|
+
}
|
|
61
114
|
}
|
|
62
115
|
exports.EventProcessorSDK = EventProcessorSDK;
|
|
63
116
|
function initializeSDK(config) {
|
|
@@ -72,9 +125,30 @@ function getFriendController() {
|
|
|
72
125
|
function getUIEventHandler() {
|
|
73
126
|
return EventProcessorSDK.getInstance().getUIEventHandler();
|
|
74
127
|
}
|
|
128
|
+
function getUserEventHandler() {
|
|
129
|
+
return EventProcessorSDK.getInstance().getUserEventHandler();
|
|
130
|
+
}
|
|
131
|
+
function getFriendEventHandler() {
|
|
132
|
+
return EventProcessorSDK.getInstance().getFriendEventHandler();
|
|
133
|
+
}
|
|
134
|
+
function getTransactionEventHandler() {
|
|
135
|
+
return EventProcessorSDK.getInstance().getTransactionEventHandler();
|
|
136
|
+
}
|
|
137
|
+
function getGroupEventHandler() {
|
|
138
|
+
return EventProcessorSDK.getInstance().getGroupEventHandler();
|
|
139
|
+
}
|
|
140
|
+
function getGroupTransactionEventHandler() {
|
|
141
|
+
return EventProcessorSDK.getInstance().getGroupTransactionEventHandler();
|
|
142
|
+
}
|
|
143
|
+
function getActivityEventHandler() {
|
|
144
|
+
return EventProcessorSDK.getInstance().getActivityEventHandler();
|
|
145
|
+
}
|
|
75
146
|
function getFirebaseAdapter() {
|
|
76
147
|
return EventProcessorSDK.getInstance().getFirebaseAdapter();
|
|
77
148
|
}
|
|
149
|
+
function getModelChangeObservable() {
|
|
150
|
+
return EventProcessorSDK.getInstance().getModelChangeObservable();
|
|
151
|
+
}
|
|
78
152
|
function eventToFirestore(event) {
|
|
79
153
|
const adapter = getFirebaseAdapter();
|
|
80
154
|
return (0, eventConverter_1.eventToFirestore)(event, adapter);
|
|
@@ -7,6 +7,7 @@ export declare class FriendEventHandler {
|
|
|
7
7
|
private userEventStore;
|
|
8
8
|
private activityEventHandler?;
|
|
9
9
|
constructor(modelStore: FriendModelStore, userModelStore: UserModelStore, friendEventStore: FriendEventStore, userEventStore: UserEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
10
|
+
private shouldSkipSave;
|
|
10
11
|
handleEvent(event: FriendEvent): Promise<void>;
|
|
11
12
|
handleFriendCreated(event: FriendCreated): Promise<void>;
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FriendEventHandler.d.ts","sourceRoot":"","sources":["../src/FriendEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,WAAW,EACX,gBAAgB,EAGhB,gBAAgB,EAGhB,cAAc,EAEd,cAAc,
|
|
1
|
+
{"version":3,"file":"FriendEventHandler.d.ts","sourceRoot":"","sources":["../src/FriendEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,WAAW,EACX,gBAAgB,EAGhB,gBAAgB,EAGhB,cAAc,EAEd,cAAc,EAEjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,qBAAa,kBAAkB;IAEvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,oBAAoB,CAAC;gBAJrB,UAAU,EAAE,gBAAgB,EAC5B,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,cAAc,EAC9B,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAGvD,OAAO,CAAC,cAAc;IAahB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC9C,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CA0LjE"}
|
|
@@ -4,6 +4,7 @@ exports.FriendEventHandler = void 0;
|
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const DomainEvents_1 = require("./common/DomainEvents");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
|
+
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
7
8
|
class FriendEventHandler {
|
|
8
9
|
constructor(modelStore, userModelStore, friendEventStore, userEventStore, activityEventHandler) {
|
|
9
10
|
this.modelStore = modelStore;
|
|
@@ -12,14 +13,29 @@ class FriendEventHandler {
|
|
|
12
13
|
this.userEventStore = userEventStore;
|
|
13
14
|
this.activityEventHandler = activityEventHandler;
|
|
14
15
|
}
|
|
16
|
+
shouldSkipSave(existingModel, updatedModel) {
|
|
17
|
+
if (!existingModel) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return (existingModel.streamId === updatedModel.streamId &&
|
|
21
|
+
existingModel.version === updatedModel.version);
|
|
22
|
+
}
|
|
15
23
|
async handleEvent(event) {
|
|
16
24
|
const eventType = event.constructor.name;
|
|
17
25
|
if (!(0, DomainEvents_1.isValidFriendEventType)(eventType)) {
|
|
18
26
|
throw new Error(`Unknown friend event type: ${eventType}`);
|
|
19
27
|
}
|
|
28
|
+
if (!_1.residence.isClient && eventType === "FriendCreated") {
|
|
29
|
+
return await this.handleFriendCreated(event);
|
|
30
|
+
}
|
|
20
31
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
21
32
|
const updatedModel = event.apply(existingModel);
|
|
22
|
-
|
|
33
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
34
|
+
await this.modelStore.save(updatedModel);
|
|
35
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
36
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", updatedModel);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
23
39
|
if (_1.residence.isClient) {
|
|
24
40
|
await this.friendEventStore.addEvent(event);
|
|
25
41
|
if (this.activityEventHandler) {
|
|
@@ -30,7 +46,12 @@ class FriendEventHandler {
|
|
|
30
46
|
async handleFriendCreated(event) {
|
|
31
47
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
32
48
|
const updatedModel = event.apply(existingModel);
|
|
33
|
-
|
|
49
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
50
|
+
await this.modelStore.save(updatedModel);
|
|
51
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
52
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", updatedModel);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
34
55
|
// Check if friend is already a user (try phone first, then email)
|
|
35
56
|
let friendUser = null;
|
|
36
57
|
if (event.friendPhoneNumber) {
|
|
@@ -54,7 +75,12 @@ class FriendEventHandler {
|
|
|
54
75
|
});
|
|
55
76
|
await this.friendEventStore.addEvent(friendIdAddedEvent);
|
|
56
77
|
const modelWithFriendId = friendIdAddedEvent.apply(updatedModel);
|
|
57
|
-
|
|
78
|
+
if (!this.shouldSkipSave(updatedModel, modelWithFriendId)) {
|
|
79
|
+
await this.modelStore.save(modelWithFriendId);
|
|
80
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
81
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", modelWithFriendId);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
58
84
|
const primaryUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(event.userId);
|
|
59
85
|
if (primaryUser) {
|
|
60
86
|
const reciprocalFriendCreated = new _1.FriendCreated({
|
|
@@ -73,7 +99,12 @@ class FriendEventHandler {
|
|
|
73
99
|
});
|
|
74
100
|
await this.friendEventStore.addEvent(reciprocalFriendCreated);
|
|
75
101
|
const reciprocalModel = reciprocalFriendCreated.apply(undefined);
|
|
76
|
-
|
|
102
|
+
if (!this.shouldSkipSave(undefined, reciprocalModel)) {
|
|
103
|
+
await this.modelStore.save(reciprocalModel);
|
|
104
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
105
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", reciprocalModel);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
77
108
|
if (this.activityEventHandler) {
|
|
78
109
|
await this.activityEventHandler.createActivityLog(reciprocalFriendCreated, undefined, reciprocalModel);
|
|
79
110
|
}
|
|
@@ -96,7 +127,9 @@ class FriendEventHandler {
|
|
|
96
127
|
});
|
|
97
128
|
await this.userEventStore.addEvent(placeholderUserCreated);
|
|
98
129
|
const placeholderUser = placeholderUserCreated.apply(undefined);
|
|
99
|
-
|
|
130
|
+
if (!this.shouldSkipSave(undefined, placeholderUser)) {
|
|
131
|
+
await this.userModelStore.save(placeholderUser);
|
|
132
|
+
}
|
|
100
133
|
// Link primary user to placeholder
|
|
101
134
|
const friendIdAddedEvent = new _1.FriendIdAdded({
|
|
102
135
|
eventId: (0, uuid_1.v4)(),
|
|
@@ -110,7 +143,12 @@ class FriendEventHandler {
|
|
|
110
143
|
});
|
|
111
144
|
await this.friendEventStore.addEvent(friendIdAddedEvent);
|
|
112
145
|
const modelWithPlaceholderId = friendIdAddedEvent.apply(updatedModel);
|
|
113
|
-
|
|
146
|
+
if (!this.shouldSkipSave(updatedModel, modelWithPlaceholderId)) {
|
|
147
|
+
await this.modelStore.save(modelWithPlaceholderId);
|
|
148
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
149
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", modelWithPlaceholderId);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
114
152
|
// Create reciprocal friendship for placeholder user
|
|
115
153
|
const primaryUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(event.userId);
|
|
116
154
|
if (primaryUser) {
|
|
@@ -131,7 +169,12 @@ class FriendEventHandler {
|
|
|
131
169
|
});
|
|
132
170
|
await this.friendEventStore.addEvent(reciprocalFriendCreated);
|
|
133
171
|
const reciprocalModel = reciprocalFriendCreated.apply(undefined);
|
|
134
|
-
|
|
172
|
+
if (!this.shouldSkipSave(undefined, reciprocalModel)) {
|
|
173
|
+
await this.modelStore.save(reciprocalModel);
|
|
174
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
175
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", reciprocalModel);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
135
178
|
if (this.activityEventHandler) {
|
|
136
179
|
await this.activityEventHandler.createActivityLog(reciprocalFriendCreated, undefined, reciprocalModel);
|
|
137
180
|
}
|
|
@@ -13,6 +13,7 @@ export declare class GroupEventHandler {
|
|
|
13
13
|
private friendEventStore;
|
|
14
14
|
private activityEventHandler?;
|
|
15
15
|
constructor(modelStore: GroupModelStore, friendModelStore: FriendModelStore, userModelStore: UserModelStore, groupEventStore: GroupEventStore, friendEventStore: FriendEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
16
|
+
private shouldSkipSave;
|
|
16
17
|
handleEvent(event: GroupEvent): Promise<GroupModel>;
|
|
17
18
|
private ensureBidirectionalFriendship;
|
|
18
19
|
handleGroupCreated(event: GroupCreated): Promise<GroupModel>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,UAAU,EAEV,UAAU,
|
|
1
|
+
{"version":3,"file":"GroupEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupEventHandler.ts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3B,KAAK,EAAE,mBAAmB,GAC3B,OAAO,CAAC,UAAU,CAAC;IA4DhB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;CA0BrE"}
|
|
@@ -4,6 +4,7 @@ exports.GroupEventHandler = void 0;
|
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const DomainEvents_1 = require("./common/DomainEvents");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
|
+
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
7
8
|
class GroupEventHandler {
|
|
8
9
|
constructor(modelStore, friendModelStore, userModelStore, groupEventStore, friendEventStore, activityEventHandler) {
|
|
9
10
|
this.modelStore = modelStore;
|
|
@@ -13,6 +14,13 @@ class GroupEventHandler {
|
|
|
13
14
|
this.friendEventStore = friendEventStore;
|
|
14
15
|
this.activityEventHandler = activityEventHandler;
|
|
15
16
|
}
|
|
17
|
+
shouldSkipSave(existingModel, updatedModel) {
|
|
18
|
+
if (!existingModel) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return (existingModel.streamId === updatedModel.streamId &&
|
|
22
|
+
existingModel.version === updatedModel.version);
|
|
23
|
+
}
|
|
16
24
|
async handleEvent(event) {
|
|
17
25
|
const eventType = event.constructor.name;
|
|
18
26
|
if (!(0, DomainEvents_1.isValidGroupEventType)(eventType)) {
|
|
@@ -61,7 +69,9 @@ class GroupEventHandler {
|
|
|
61
69
|
});
|
|
62
70
|
await this.friendEventStore.addEvent(friendCreatedEvent);
|
|
63
71
|
const friendModel = friendCreatedEvent.apply(undefined);
|
|
64
|
-
|
|
72
|
+
if (!this.shouldSkipSave(undefined, friendModel)) {
|
|
73
|
+
await this.friendModelStore.save(friendModel);
|
|
74
|
+
}
|
|
65
75
|
}
|
|
66
76
|
const existingFriend2to1 = await this.friendModelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId2, userId1);
|
|
67
77
|
if (!existingFriend2to1) {
|
|
@@ -82,13 +92,20 @@ class GroupEventHandler {
|
|
|
82
92
|
});
|
|
83
93
|
await this.friendEventStore.addEvent(friendCreatedEvent);
|
|
84
94
|
const friendModel = friendCreatedEvent.apply(undefined);
|
|
85
|
-
|
|
95
|
+
if (!this.shouldSkipSave(undefined, friendModel)) {
|
|
96
|
+
await this.friendModelStore.save(friendModel);
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
async handleGroupCreated(event) {
|
|
89
101
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
90
102
|
const updatedModel = event.apply(existingModel);
|
|
91
|
-
|
|
103
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
104
|
+
await this.modelStore.save(updatedModel);
|
|
105
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
106
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
92
109
|
const allMemberIds = event.members ?? [];
|
|
93
110
|
const otherMembers = allMemberIds.filter((id) => id !== event.userId);
|
|
94
111
|
for (const memberId of otherMembers) {
|
|
@@ -118,7 +135,12 @@ class GroupEventHandler {
|
|
|
118
135
|
});
|
|
119
136
|
await this.groupEventStore.addEvent(perspectiveGroupCreated);
|
|
120
137
|
const perspectiveModel = perspectiveGroupCreated.apply(undefined);
|
|
121
|
-
|
|
138
|
+
if (!this.shouldSkipSave(undefined, perspectiveModel)) {
|
|
139
|
+
await this.modelStore.save(perspectiveModel);
|
|
140
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
141
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", perspectiveModel);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
122
144
|
}
|
|
123
145
|
if (this.activityEventHandler) {
|
|
124
146
|
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
@@ -128,7 +150,12 @@ class GroupEventHandler {
|
|
|
128
150
|
async handleGroupNameChanged(event) {
|
|
129
151
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
130
152
|
const updatedModel = event.apply(existingModel);
|
|
131
|
-
|
|
153
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
154
|
+
await this.modelStore.save(updatedModel);
|
|
155
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
156
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
132
159
|
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
133
160
|
for (const perspective of allPerspectives) {
|
|
134
161
|
if (perspective.streamId !== event.streamId) {
|
|
@@ -144,7 +171,12 @@ class GroupEventHandler {
|
|
|
144
171
|
});
|
|
145
172
|
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
146
173
|
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
147
|
-
|
|
174
|
+
if (!this.shouldSkipSave(perspective, updatedPerspective)) {
|
|
175
|
+
await this.modelStore.save(updatedPerspective);
|
|
176
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
177
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedPerspective);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
148
180
|
}
|
|
149
181
|
}
|
|
150
182
|
if (this.activityEventHandler) {
|
|
@@ -155,7 +187,12 @@ class GroupEventHandler {
|
|
|
155
187
|
async handleGroupDescriptionChanged(event) {
|
|
156
188
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
157
189
|
const updatedModel = event.apply(existingModel);
|
|
158
|
-
|
|
190
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
191
|
+
await this.modelStore.save(updatedModel);
|
|
192
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
193
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
159
196
|
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
160
197
|
for (const perspective of allPerspectives) {
|
|
161
198
|
if (perspective.streamId !== event.streamId) {
|
|
@@ -171,7 +208,12 @@ class GroupEventHandler {
|
|
|
171
208
|
});
|
|
172
209
|
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
173
210
|
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
174
|
-
|
|
211
|
+
if (!this.shouldSkipSave(perspective, updatedPerspective)) {
|
|
212
|
+
await this.modelStore.save(updatedPerspective);
|
|
213
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
214
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedPerspective);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
175
217
|
}
|
|
176
218
|
}
|
|
177
219
|
if (this.activityEventHandler) {
|
|
@@ -185,7 +227,12 @@ class GroupEventHandler {
|
|
|
185
227
|
throw new Error(`Group model not found for streamId ${event.streamId}`);
|
|
186
228
|
}
|
|
187
229
|
const updatedModel = event.apply(existingModel);
|
|
188
|
-
|
|
230
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
231
|
+
await this.modelStore.save(updatedModel);
|
|
232
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
233
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
189
236
|
const allMemberIds = updatedModel.members ?? [];
|
|
190
237
|
for (const memberId of event.members) {
|
|
191
238
|
const memberUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(memberId);
|
|
@@ -214,7 +261,12 @@ class GroupEventHandler {
|
|
|
214
261
|
});
|
|
215
262
|
await this.groupEventStore.addEvent(perspectiveGroupCreated);
|
|
216
263
|
const perspectiveModel = perspectiveGroupCreated.apply(undefined);
|
|
217
|
-
|
|
264
|
+
if (!this.shouldSkipSave(undefined, perspectiveModel)) {
|
|
265
|
+
await this.modelStore.save(perspectiveModel);
|
|
266
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
267
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", perspectiveModel);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
218
270
|
}
|
|
219
271
|
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
220
272
|
for (const perspective of allPerspectives) {
|
|
@@ -232,7 +284,12 @@ class GroupEventHandler {
|
|
|
232
284
|
});
|
|
233
285
|
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
234
286
|
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
235
|
-
|
|
287
|
+
if (!this.shouldSkipSave(perspective, updatedPerspective)) {
|
|
288
|
+
await this.modelStore.save(updatedPerspective);
|
|
289
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
290
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedPerspective);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
236
293
|
}
|
|
237
294
|
}
|
|
238
295
|
if (this.activityEventHandler) {
|
|
@@ -243,7 +300,12 @@ class GroupEventHandler {
|
|
|
243
300
|
async handleGroupMembersRemoved(event) {
|
|
244
301
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
245
302
|
const updatedModel = event.apply(existingModel);
|
|
246
|
-
|
|
303
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
304
|
+
await this.modelStore.save(updatedModel);
|
|
305
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
306
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
247
309
|
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
248
310
|
for (const perspective of allPerspectives) {
|
|
249
311
|
if (perspective.streamId !== event.streamId) {
|
|
@@ -259,7 +321,12 @@ class GroupEventHandler {
|
|
|
259
321
|
});
|
|
260
322
|
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
261
323
|
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
262
|
-
|
|
324
|
+
if (!this.shouldSkipSave(perspective, updatedPerspective)) {
|
|
325
|
+
await this.modelStore.save(updatedPerspective);
|
|
326
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
327
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedPerspective);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
263
330
|
}
|
|
264
331
|
}
|
|
265
332
|
if (this.activityEventHandler) {
|
|
@@ -270,7 +337,12 @@ class GroupEventHandler {
|
|
|
270
337
|
async handleGroupDeleted(event) {
|
|
271
338
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
272
339
|
const updatedModel = event.apply(existingModel);
|
|
273
|
-
|
|
340
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
341
|
+
await this.modelStore.save(updatedModel);
|
|
342
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
343
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
274
346
|
if (this.activityEventHandler) {
|
|
275
347
|
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
276
348
|
}
|
|
@@ -13,6 +13,7 @@ export declare class GroupTransactionEventHandler {
|
|
|
13
13
|
private transactionModelStore;
|
|
14
14
|
private activityEventHandler?;
|
|
15
15
|
constructor(modelStore: GroupTransactionModelStore, eventStore: GroupTransactionEventStore, groupModelStore: GroupModelStore, transactionEventStore: TransactionEventStore, transactionModelStore: TransactionModelStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
16
|
+
private shouldSkipSave;
|
|
16
17
|
handleEvent(event: GroupTransactionEvent): Promise<GroupTransactionModel>;
|
|
17
18
|
private calculateNetBalances;
|
|
18
19
|
private createFriendTransactions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupTransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupTransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,mCAAmC,EACnC,qBAAqB,EAIrB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"GroupTransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupTransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,mCAAmC,EACnC,qBAAqB,EAIrB,qBAAqB,EAKxB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAM9D,qBAAa,4BAA4B;IAEjC,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,oBAAoB,CAAC;gBALrB,UAAU,EAAE,0BAA0B,EACtC,UAAU,EAAE,0BAA0B,EACtC,eAAe,EAA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