@zeeshan60/event-processor 1.0.15 → 1.0.17
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/README.md +29 -22
- package/dist/ActivityEventHandler.d.ts +7 -4
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +24 -13
- package/dist/ActivityLogEvents.d.ts.map +1 -1
- package/dist/ActivityLogEvents.js +1 -0
- package/dist/BaseEventHandler.d.ts +12 -3
- package/dist/BaseEventHandler.d.ts.map +1 -1
- package/dist/BaseEventHandler.js +15 -0
- package/dist/EventProcessorSDK.d.ts +8 -0
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +20 -6
- package/dist/FriendEventHandler.d.ts +8 -3
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +65 -39
- package/dist/GroupEventHandler.d.ts +6 -3
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +254 -189
- package/dist/GroupTransactionEventHandler.d.ts +5 -8
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +26 -298
- package/dist/TransactionEventHandler.d.ts +5 -3
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +26 -13
- package/dist/TransactionEvents.d.ts +10 -9
- package/dist/TransactionEvents.d.ts.map +1 -1
- package/dist/TransactionEvents.js +10 -12
- package/dist/UserEventHandler.d.ts +5 -3
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +27 -14
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.js +3 -0
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.js +10 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts +9 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts.map +1 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.js +19 -0
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMFriendModelStore.js +7 -0
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupModelStore.js +7 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.js +18 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.js +7 -0
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionEventStore.js +6 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +3 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.js +27 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +4 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.js +17 -0
- package/dist/client/controllers/FriendController.d.ts +4 -0
- package/dist/client/controllers/FriendController.d.ts.map +1 -1
- package/dist/client/controllers/FriendController.js +81 -15
- package/dist/client/controllers/TransactionController.d.ts +13 -2
- package/dist/client/controllers/TransactionController.d.ts.map +1 -1
- package/dist/client/controllers/TransactionController.js +150 -16
- package/dist/client/handlers/UIEventHandler.d.ts +3 -0
- package/dist/client/handlers/UIEventHandler.d.ts.map +1 -1
- package/dist/client/handlers/UIEventHandler.js +36 -0
- package/dist/common/CurrencyRate.d.ts +7 -0
- package/dist/common/CurrencyRate.d.ts.map +1 -0
- package/dist/common/CurrencyRate.js +2 -0
- package/dist/common/Model.d.ts +1 -0
- package/dist/common/Model.d.ts.map +1 -1
- package/dist/contracts/friends/index.d.ts +2 -9
- package/dist/contracts/friends/index.d.ts.map +1 -1
- package/dist/contracts/groups/index.d.ts +1 -1
- package/dist/contracts/groups/index.d.ts.map +1 -1
- package/dist/contracts/transactions/index.d.ts +33 -23
- package/dist/contracts/transactions/index.d.ts.map +1 -1
- package/dist/contracts/transactions/index.js +14 -11
- package/dist/converters/ActivityLogConverters.d.ts.map +1 -1
- package/dist/converters/ActivityLogConverters.js +3 -1
- package/dist/events.d.ts +2 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +7 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/store/CurrencyStore.d.ts +6 -0
- package/dist/store/CurrencyStore.d.ts.map +1 -0
- package/dist/store/CurrencyStore.js +6 -0
- package/dist/store/ModelStore.d.ts +1 -0
- package/dist/store/ModelStore.d.ts.map +1 -1
- package/dist/store/TransactionModelStore.d.ts +2 -0
- package/dist/store/TransactionModelStore.d.ts.map +1 -1
- package/dist/store/UserModelStore.d.ts +1 -0
- package/dist/store/UserModelStore.d.ts.map +1 -1
- package/dist/utils/BalanceUtil.d.ts +17 -0
- package/dist/utils/BalanceUtil.d.ts.map +1 -0
- package/dist/utils/BalanceUtil.js +105 -0
- package/dist/utils/splitTypeUtils.d.ts.map +1 -1
- package/dist/utils/splitTypeUtils.js +21 -21
- package/package.json +1 -1
- package/dist/client/handlers/UIFriendEventHandler.d.ts +0 -16
- package/dist/client/handlers/UIFriendEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIFriendEventHandler.js +0 -27
- package/dist/client/handlers/UIGroupEventHandler.d.ts +0 -18
- package/dist/client/handlers/UIGroupEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIGroupEventHandler.js +0 -28
- package/dist/client/handlers/UIGroupTransactionEventHandler.d.ts +0 -18
- package/dist/client/handlers/UIGroupTransactionEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIGroupTransactionEventHandler.js +0 -28
- package/dist/client/handlers/UITransactionEventHandler.d.ts +0 -14
- package/dist/client/handlers/UITransactionEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UITransactionEventHandler.js +0 -26
- package/dist/client/handlers/UIUserEventHandler.d.ts +0 -12
- package/dist/client/handlers/UIUserEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIUserEventHandler.js +0 -29
- package/dist/utils/userPathUtils.d.ts +0 -6
- package/dist/utils/userPathUtils.d.ts.map +0 -1
- package/dist/utils/userPathUtils.js +0 -16
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ This package provides the core building blocks for implementing event sourcing p
|
|
|
11
11
|
- **Base Interfaces**: `Event` and `Model` interfaces for type-safe event sourcing
|
|
12
12
|
- **Abstract Stores**: `EventStore` and `ModelStore` base classes
|
|
13
13
|
- **In-Memory Implementations**: Ready-to-use in-memory stores for testing
|
|
14
|
-
- **
|
|
14
|
+
- **Runtime Context Detection**: `residence.isClient` flag to differentiate between client and server behavior
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
@@ -103,40 +103,48 @@ const model = event.apply(null);
|
|
|
103
103
|
await modelStore.save(model);
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
##
|
|
106
|
+
## Runtime Context Configuration
|
|
107
107
|
|
|
108
|
-
The event-processor package
|
|
108
|
+
The event-processor package uses the `residence.isClient` flag to differentiate between client and server execution contexts. This enables environment-specific behavior.
|
|
109
109
|
|
|
110
110
|
### Quick Start
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
import {
|
|
113
|
+
import { residence } from '@zeeshan60/event-processor';
|
|
114
114
|
|
|
115
|
-
//
|
|
116
|
-
//
|
|
115
|
+
// Client (Mobile App): No configuration needed - defaults to true
|
|
116
|
+
// The residence.isClient flag is true by default
|
|
117
117
|
|
|
118
|
-
//
|
|
119
|
-
|
|
118
|
+
// Google Cloud Functions: Set explicitly to false
|
|
119
|
+
residence.isClient = false;
|
|
120
120
|
|
|
121
|
-
// Check the
|
|
122
|
-
if (
|
|
121
|
+
// Check the runtime context
|
|
122
|
+
if (residence.isClient) {
|
|
123
|
+
console.log('Running in client application');
|
|
124
|
+
} else {
|
|
123
125
|
console.log('Running in Google Cloud Functions');
|
|
124
126
|
}
|
|
127
|
+
```
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
### Usage Pattern
|
|
130
|
+
|
|
131
|
+
**Client (Mobile App):**
|
|
132
|
+
```typescript
|
|
133
|
+
// No setup needed - residence.isClient defaults to true
|
|
134
|
+
// Client creates events, applies to local models
|
|
129
135
|
```
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
**Google Cloud Functions:**
|
|
138
|
+
```typescript
|
|
139
|
+
import { residence } from '@zeeshan60/event-processor';
|
|
140
|
+
|
|
141
|
+
// Set at function initialization
|
|
142
|
+
residence.isClient = false;
|
|
132
143
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- `isUnknown()`: Returns `true` if environment is not configured
|
|
136
|
-
- `setEventProcessorSource(source)`: Set the environment programmatically
|
|
137
|
-
- `getEventProcessorSource()`: Get the current environment
|
|
144
|
+
// Server processes events, creates mirror events for other users
|
|
145
|
+
```
|
|
138
146
|
|
|
139
|
-
For detailed
|
|
147
|
+
For detailed context-specific behavior, see [DUAL_CONTEXT_FLOW.md](./DUAL_CONTEXT_FLOW.md).
|
|
140
148
|
|
|
141
149
|
## Documentation
|
|
142
150
|
|
|
@@ -145,7 +153,6 @@ For detailed environment configuration, see [ENVIRONMENT_CONFIG.md](./ENVIRONMEN
|
|
|
145
153
|
- **[SDK_USAGE.md](./SDK_USAGE.md)** - 📦 Complete SDK initialization guide with examples and best practices
|
|
146
154
|
- **[DUAL_CONTEXT_FLOW.md](./DUAL_CONTEXT_FLOW.md)** - 🎯 **START HERE!** Comprehensive guide explaining how the package operates in client vs Google Cloud Functions contexts, complete with diagrams and examples
|
|
147
155
|
- **[QUICK_REFERENCE.md](./QUICK_REFERENCE.md)** - Quick reference cheat sheet for common patterns, troubleshooting, and best practices
|
|
148
|
-
- **[ENVIRONMENT_CONFIG.md](./ENVIRONMENT_CONFIG.md)** - Environment configuration details
|
|
149
156
|
|
|
150
157
|
### Why Dual-Context Matters
|
|
151
158
|
|
|
@@ -167,7 +174,7 @@ Understanding when to create events vs when to process them is critical to avoid
|
|
|
167
174
|
- **Model**: Base interface for all models/aggregates
|
|
168
175
|
- **EventStore**: Abstract class for event persistence
|
|
169
176
|
- **ModelStore**: Abstract class for model/read-model persistence
|
|
170
|
-
- **
|
|
177
|
+
- **residence**: Runtime context object with `isClient` flag for client vs server detection
|
|
171
178
|
|
|
172
179
|
### Event Handlers
|
|
173
180
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { ActivityLogEvent, ActivityLogEventStore, ActivityLogModelStore,
|
|
2
|
-
|
|
1
|
+
import { ActivityLogEvent, ActivityLogEventStore, ActivityLogModelStore, Event, Model, UserModelStore } from ".";
|
|
2
|
+
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
|
+
import { ModelChangeEmitter } from "./ModelChangeEmitter";
|
|
4
|
+
export declare class ActivityEventHandler extends BaseEventHandler<ActivityLogEvent> {
|
|
3
5
|
private activityLogModelStore;
|
|
4
6
|
private activityLogEventStore;
|
|
5
7
|
private userModelStore;
|
|
6
|
-
constructor(activityLogModelStore: ActivityLogModelStore, activityLogEventStore: ActivityLogEventStore, userModelStore: UserModelStore);
|
|
7
|
-
|
|
8
|
+
constructor(activityLogModelStore: ActivityLogModelStore, activityLogEventStore: ActivityLogEventStore, userModelStore: UserModelStore, isClient: boolean, modelChangeEmitter?: ModelChangeEmitter);
|
|
9
|
+
getModelStore(): ActivityLogModelStore;
|
|
8
10
|
createActivityLog(event: Event, existingModel: Model | undefined, updatedModel: Model): Promise<void>;
|
|
9
11
|
handleClientEventFromRemoteListener(event: ActivityLogEvent): Promise<void>;
|
|
12
|
+
handleClientEventsFromRemoteListenerBulk(events: ActivityLogEvent[]): Promise<void>;
|
|
10
13
|
handleEvent(event: ActivityLogEvent): Promise<any>;
|
|
11
14
|
}
|
|
12
15
|
//# sourceMappingURL=ActivityEventHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityEventHandler.d.ts","sourceRoot":"","sources":["../src/ActivityEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,gBAAgB,EAChB,qBAAqB,EAErB,qBAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"ActivityEventHandler.d.ts","sourceRoot":"","sources":["../src/ActivityEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,gBAAgB,EAChB,qBAAqB,EAErB,qBAAqB,EACrB,KAAK,EACL,KAAK,EACL,cAAc,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,oBAAqB,SAAQ,gBAAgB,CAAC,gBAAgB,CAAC;IAEpE,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,cAAc;gBAFd,qBAAqB,EAAE,qBAAqB,EAC5C,qBAAqB,EAAE,qBAAqB,EAC5C,cAAc,EAAE,cAAc,EACtC,QAAQ,EAAE,OAAO,EACjB,kBAAkB,CAAC,EAAE,kBAAkB;IAKpC,aAAa,IAAI,qBAAqB;IAIvC,iBAAiB,CACnB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,KAAK,GAAG,SAAS,EAChC,YAAY,EAAE,KAAK,GACpB,OAAO,CAAC,IAAI,CAAC;IAkCV,mCAAmC,CACrC,KAAK,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC;IAYH,wCAAwC,CACjD,MAAM,EAAE,gBAAgB,EAAE,GAC3B,OAAO,CAAC,IAAI,CAAC;IAsBhB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC;CAOrD"}
|
|
@@ -2,19 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActivityEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
-
const
|
|
6
|
-
class ActivityEventHandler {
|
|
7
|
-
constructor(activityLogModelStore, activityLogEventStore, userModelStore) {
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
6
|
+
class ActivityEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
7
|
+
constructor(activityLogModelStore, activityLogEventStore, userModelStore, isClient, modelChangeEmitter) {
|
|
8
|
+
super(isClient, modelChangeEmitter);
|
|
8
9
|
this.activityLogModelStore = activityLogModelStore;
|
|
9
10
|
this.activityLogEventStore = activityLogEventStore;
|
|
10
11
|
this.userModelStore = userModelStore;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
17
|
-
existingModel.version === updatedModel.version);
|
|
13
|
+
getModelStore() {
|
|
14
|
+
return this.activityLogModelStore;
|
|
18
15
|
}
|
|
19
16
|
async createActivityLog(event, existingModel, updatedModel) {
|
|
20
17
|
if (!event.activityLog) {
|
|
@@ -39,9 +36,7 @@ class ActivityEventHandler {
|
|
|
39
36
|
await this.activityLogEventStore.addEvent(activityLogEvent);
|
|
40
37
|
if (!this.shouldSkipSave(undefined, activityLogModel)) {
|
|
41
38
|
await this.activityLogModelStore.save(activityLogModel);
|
|
42
|
-
|
|
43
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("ActivityLogModel", activityLogModel);
|
|
44
|
-
}
|
|
39
|
+
this.modelChangeEmitter?.emit("ActivityLogModel", activityLogModel);
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
async handleClientEventFromRemoteListener(event) {
|
|
@@ -49,7 +44,23 @@ class ActivityEventHandler {
|
|
|
49
44
|
const updatedModel = event.apply(existingModel);
|
|
50
45
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
51
46
|
await this.activityLogModelStore.save(updatedModel);
|
|
52
|
-
|
|
47
|
+
this.modelChangeEmitter?.emit("ActivityLogModel", updatedModel);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async handleClientEventsFromRemoteListenerBulk(events) {
|
|
51
|
+
const updatedModels = [];
|
|
52
|
+
for (const event of events) {
|
|
53
|
+
const existingModel = await this.activityLogModelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
54
|
+
const updatedModel = event.apply(existingModel);
|
|
55
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
56
|
+
await this.activityLogModelStore.save(updatedModel);
|
|
57
|
+
updatedModels.push(updatedModel);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (this.modelChangeEmitter && updatedModels.length > 0) {
|
|
61
|
+
for (const model of updatedModels) {
|
|
62
|
+
this.modelChangeEmitter.emit("ActivityLogModel", model);
|
|
63
|
+
}
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
handleEvent(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityLogEvents.d.ts","sourceRoot":"","sources":["../src/ActivityLogEvents.ts"],"names":[],"mappings":"AAAA,O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C;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;gBAEpB,KAAK,EAAE,uBAAuB;IAe1C,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,gBAAgB;CAc7C"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { Event } from "./common/Event";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { Model } from "./common/Model";
|
|
3
|
+
import { ModelChangeEmitter } from "./ModelChangeEmitter";
|
|
4
|
+
import { ModelStore } from "./store/ModelStore";
|
|
5
|
+
export declare abstract class BaseEventHandler<T extends Event> {
|
|
6
|
+
protected readonly isClient: boolean;
|
|
7
|
+
protected readonly modelChangeEmitter?: ModelChangeEmitter;
|
|
8
|
+
constructor(isClient: boolean, modelChangeEmitter?: ModelChangeEmitter);
|
|
9
|
+
abstract handleEvent(event: T): Promise<any>;
|
|
10
|
+
abstract handleClientEventFromRemoteListener(event: T): Promise<void>;
|
|
11
|
+
abstract handleClientEventsFromRemoteListenerBulk(events: T[]): Promise<void>;
|
|
12
|
+
abstract getModelStore(): ModelStore;
|
|
13
|
+
protected shouldSkipSave(existingModel: Model | undefined, updatedModel: Model): boolean;
|
|
5
14
|
}
|
|
6
15
|
//# sourceMappingURL=BaseEventHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseEventHandler.d.ts","sourceRoot":"","sources":["../src/BaseEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseEventHandler.d.ts","sourceRoot":"","sources":["../src/BaseEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,8BAAsB,gBAAgB,CAAC,CAAC,SAAS,KAAK;IAClD,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IACrC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;gBAE/C,QAAQ,EAAE,OAAO,EAAE,kBAAkB,CAAC,EAAE,kBAAkB;IAKtE,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAC5C,QAAQ,CAAC,mCAAmC,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IACrE,QAAQ,CAAC,wCAAwC,CAC7C,MAAM,EAAE,CAAC,EAAE,GACZ,OAAO,CAAC,IAAI,CAAC;IAChB,QAAQ,CAAC,aAAa,IAAI,UAAU;IAEpC,SAAS,CAAC,cAAc,CACpB,aAAa,EAAE,KAAK,GAAG,SAAS,EAChC,YAAY,EAAE,KAAK,GACpB,OAAO;CASb"}
|
package/dist/BaseEventHandler.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEventHandler = void 0;
|
|
4
|
+
class BaseEventHandler {
|
|
5
|
+
constructor(isClient, modelChangeEmitter) {
|
|
6
|
+
this.isClient = isClient;
|
|
7
|
+
this.modelChangeEmitter = modelChangeEmitter;
|
|
8
|
+
}
|
|
9
|
+
shouldSkipSave(existingModel, updatedModel) {
|
|
10
|
+
if (!existingModel) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return (existingModel.streamId === updatedModel.streamId &&
|
|
14
|
+
existingModel.version >= updatedModel.version);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.BaseEventHandler = BaseEventHandler;
|
|
@@ -10,6 +10,7 @@ import { GroupTransactionModelStore } from "./store/GroupTransactionModelStore";
|
|
|
10
10
|
import { GroupTransactionEventStore } from "./store/GroupTransactionEventStore";
|
|
11
11
|
import { ActivityLogModelStore } from "./store/ActivityLogModelStore";
|
|
12
12
|
import { ActivityLogEventStore } from "./store/ActivityLogEventStore";
|
|
13
|
+
import { CurrencyStore } from "./store/CurrencyStore";
|
|
13
14
|
import { UserController } from "./client/controllers/UserController";
|
|
14
15
|
import { FriendController } from "./client/controllers/FriendController";
|
|
15
16
|
import { TransactionController } from "./client/controllers/TransactionController";
|
|
@@ -34,10 +35,13 @@ export type StoreConfig = {
|
|
|
34
35
|
groupTransactionEventStore: GroupTransactionEventStore;
|
|
35
36
|
activityLogModelStore: ActivityLogModelStore;
|
|
36
37
|
activityLogEventStore: ActivityLogEventStore;
|
|
38
|
+
currencyStore: CurrencyStore;
|
|
39
|
+
isClient?: boolean;
|
|
37
40
|
};
|
|
38
41
|
export declare class EventProcessorSDK {
|
|
39
42
|
private static instance;
|
|
40
43
|
private readonly storeConfig;
|
|
44
|
+
private _isClient;
|
|
41
45
|
private userControllerInstance;
|
|
42
46
|
private friendControllerInstance;
|
|
43
47
|
private transactionControllerInstance;
|
|
@@ -53,6 +57,8 @@ export declare class EventProcessorSDK {
|
|
|
53
57
|
static initialize(config: StoreConfig): EventProcessorSDK;
|
|
54
58
|
static getInstance(): EventProcessorSDK;
|
|
55
59
|
static isInitialized(): boolean;
|
|
60
|
+
isClient(): boolean;
|
|
61
|
+
setIsClient(isClient: boolean): void;
|
|
56
62
|
static __resetForTesting(): void;
|
|
57
63
|
getStoreConfig(): StoreConfig;
|
|
58
64
|
getUserController(): UserController;
|
|
@@ -66,6 +72,7 @@ export declare class EventProcessorSDK {
|
|
|
66
72
|
getGroupTransactionEventHandler(): GroupTransactionEventHandler;
|
|
67
73
|
getActivityEventHandler(): ActivityEventHandler;
|
|
68
74
|
getFirebaseAdapter(): FirebaseAdapter;
|
|
75
|
+
getCurrencyStore(): CurrencyStore;
|
|
69
76
|
getModelChangeObservable(): Observable<ModelChange>;
|
|
70
77
|
emitModelChange(modelType: string, model: Model): void;
|
|
71
78
|
}
|
|
@@ -81,6 +88,7 @@ export declare function getGroupEventHandler(): GroupEventHandler;
|
|
|
81
88
|
export declare function getGroupTransactionEventHandler(): GroupTransactionEventHandler;
|
|
82
89
|
export declare function getActivityEventHandler(): ActivityEventHandler;
|
|
83
90
|
export declare function getFirebaseAdapter(): FirebaseAdapter;
|
|
91
|
+
export declare function getCurrencyStore(): CurrencyStore;
|
|
84
92
|
export declare function getModelChangeObservable(): Observable<ModelChange>;
|
|
85
93
|
export declare function eventToFirestore(event: Event): FirestoreEventData;
|
|
86
94
|
export declare function firestoreToEvent(data: FirestoreEventData): Event;
|
|
@@ -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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WAAW,CAAC,CAElE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB,CAEjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,GAAG,KAAK,CAEhE;AAED,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C"}
|
|
@@ -13,6 +13,7 @@ exports.getGroupEventHandler = getGroupEventHandler;
|
|
|
13
13
|
exports.getGroupTransactionEventHandler = getGroupTransactionEventHandler;
|
|
14
14
|
exports.getActivityEventHandler = getActivityEventHandler;
|
|
15
15
|
exports.getFirebaseAdapter = getFirebaseAdapter;
|
|
16
|
+
exports.getCurrencyStore = getCurrencyStore;
|
|
16
17
|
exports.getModelChangeObservable = getModelChangeObservable;
|
|
17
18
|
exports.eventToFirestore = eventToFirestore;
|
|
18
19
|
exports.firestoreToEvent = firestoreToEvent;
|
|
@@ -29,6 +30,7 @@ class EventProcessorSDK {
|
|
|
29
30
|
constructor(config) {
|
|
30
31
|
this.storeConfig = config;
|
|
31
32
|
this.modelChangeEmitter = new ModelChangeEmitter_1.ModelChangeEmitter();
|
|
33
|
+
this._isClient = config.isClient !== undefined ? config.isClient : true;
|
|
32
34
|
}
|
|
33
35
|
static initialize(config) {
|
|
34
36
|
EventProcessorSDK.instance = new EventProcessorSDK(config);
|
|
@@ -43,6 +45,12 @@ class EventProcessorSDK {
|
|
|
43
45
|
static isInitialized() {
|
|
44
46
|
return EventProcessorSDK.instance !== undefined;
|
|
45
47
|
}
|
|
48
|
+
isClient() {
|
|
49
|
+
return this._isClient;
|
|
50
|
+
}
|
|
51
|
+
setIsClient(isClient) {
|
|
52
|
+
this._isClient = isClient;
|
|
53
|
+
}
|
|
46
54
|
static __resetForTesting() {
|
|
47
55
|
EventProcessorSDK.instance = undefined;
|
|
48
56
|
}
|
|
@@ -75,44 +83,47 @@ class EventProcessorSDK {
|
|
|
75
83
|
}
|
|
76
84
|
getUserEventHandler() {
|
|
77
85
|
if (!this.userEventHandlerInstance) {
|
|
78
|
-
this.userEventHandlerInstance = new events_1.UserEventHandler(this.storeConfig.userModelStore, this.storeConfig.userEventStore, this.getActivityEventHandler());
|
|
86
|
+
this.userEventHandlerInstance = new events_1.UserEventHandler(this.storeConfig.userModelStore, this.storeConfig.userEventStore, this._isClient, this.modelChangeEmitter, this.getActivityEventHandler());
|
|
79
87
|
}
|
|
80
88
|
return this.userEventHandlerInstance;
|
|
81
89
|
}
|
|
82
90
|
getFriendEventHandler() {
|
|
83
91
|
if (!this.friendEventHandlerInstance) {
|
|
84
|
-
this.friendEventHandlerInstance = new events_1.FriendEventHandler(this.storeConfig.friendModelStore, this.storeConfig.userModelStore, this.storeConfig.friendEventStore, this.storeConfig.userEventStore, this.getActivityEventHandler());
|
|
92
|
+
this.friendEventHandlerInstance = new events_1.FriendEventHandler(this.storeConfig.friendModelStore, this.storeConfig.userModelStore, this.storeConfig.friendEventStore, this.storeConfig.userEventStore, this._isClient, this.modelChangeEmitter, this.getActivityEventHandler());
|
|
85
93
|
}
|
|
86
94
|
return this.friendEventHandlerInstance;
|
|
87
95
|
}
|
|
88
96
|
getTransactionEventHandler() {
|
|
89
97
|
if (!this.transactionEventHandlerInstance) {
|
|
90
|
-
this.transactionEventHandlerInstance = new events_1.TransactionEventHandler(this.storeConfig.transactionModelStore, this.storeConfig.transactionEventStore, this.getActivityEventHandler());
|
|
98
|
+
this.transactionEventHandlerInstance = new events_1.TransactionEventHandler(this.storeConfig.transactionModelStore, this.storeConfig.transactionEventStore, this._isClient, this.modelChangeEmitter, this.getActivityEventHandler());
|
|
91
99
|
}
|
|
92
100
|
return this.transactionEventHandlerInstance;
|
|
93
101
|
}
|
|
94
102
|
getGroupEventHandler() {
|
|
95
103
|
if (!this.groupEventHandlerInstance) {
|
|
96
|
-
this.groupEventHandlerInstance = new events_1.GroupEventHandler(this.storeConfig.groupModelStore, this.storeConfig.friendModelStore, this.storeConfig.userModelStore, this.storeConfig.groupEventStore, this.storeConfig.friendEventStore, this.getActivityEventHandler());
|
|
104
|
+
this.groupEventHandlerInstance = new events_1.GroupEventHandler(this.storeConfig.groupModelStore, this.storeConfig.friendModelStore, this.storeConfig.userModelStore, this.storeConfig.groupEventStore, this.storeConfig.friendEventStore, this._isClient, this.modelChangeEmitter, this.getActivityEventHandler());
|
|
97
105
|
}
|
|
98
106
|
return this.groupEventHandlerInstance;
|
|
99
107
|
}
|
|
100
108
|
getGroupTransactionEventHandler() {
|
|
101
109
|
if (!this.groupTransactionEventHandlerInstance) {
|
|
102
110
|
this.groupTransactionEventHandlerInstance =
|
|
103
|
-
new events_1.GroupTransactionEventHandler(this.storeConfig.groupTransactionModelStore, this.storeConfig.groupTransactionEventStore, this.storeConfig.groupModelStore, this.storeConfig.transactionEventStore, this.storeConfig.transactionModelStore, this.getActivityEventHandler());
|
|
111
|
+
new events_1.GroupTransactionEventHandler(this.storeConfig.groupTransactionModelStore, this.storeConfig.groupTransactionEventStore, this.storeConfig.groupModelStore, this.storeConfig.transactionEventStore, this.storeConfig.transactionModelStore, this._isClient, this.modelChangeEmitter, this.getActivityEventHandler());
|
|
104
112
|
}
|
|
105
113
|
return this.groupTransactionEventHandlerInstance;
|
|
106
114
|
}
|
|
107
115
|
getActivityEventHandler() {
|
|
108
116
|
if (!this.activityEventHandlerInstance) {
|
|
109
|
-
this.activityEventHandlerInstance = new events_1.ActivityEventHandler(this.storeConfig.activityLogModelStore, this.storeConfig.activityLogEventStore, this.storeConfig.userModelStore);
|
|
117
|
+
this.activityEventHandlerInstance = new events_1.ActivityEventHandler(this.storeConfig.activityLogModelStore, this.storeConfig.activityLogEventStore, this.storeConfig.userModelStore, this._isClient, this.modelChangeEmitter);
|
|
110
118
|
}
|
|
111
119
|
return this.activityEventHandlerInstance;
|
|
112
120
|
}
|
|
113
121
|
getFirebaseAdapter() {
|
|
114
122
|
return this.storeConfig.firebaseAdapter;
|
|
115
123
|
}
|
|
124
|
+
getCurrencyStore() {
|
|
125
|
+
return this.storeConfig.currencyStore;
|
|
126
|
+
}
|
|
116
127
|
getModelChangeObservable() {
|
|
117
128
|
return this.modelChangeEmitter.asObservable();
|
|
118
129
|
}
|
|
@@ -157,6 +168,9 @@ function getActivityEventHandler() {
|
|
|
157
168
|
function getFirebaseAdapter() {
|
|
158
169
|
return EventProcessorSDK.getInstance().getFirebaseAdapter();
|
|
159
170
|
}
|
|
171
|
+
function getCurrencyStore() {
|
|
172
|
+
return EventProcessorSDK.getInstance().getCurrencyStore();
|
|
173
|
+
}
|
|
160
174
|
function getModelChangeObservable() {
|
|
161
175
|
return EventProcessorSDK.getInstance().getModelChangeObservable();
|
|
162
176
|
}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { FriendCreated, FriendEvent, FriendEventStore, FriendModelStore, UserEventStore, UserModelStore } from ".";
|
|
2
2
|
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
4
|
-
|
|
4
|
+
import { ModelChangeEmitter } from "./ModelChangeEmitter";
|
|
5
|
+
export declare class FriendEventHandler extends BaseEventHandler<FriendEvent> {
|
|
5
6
|
private modelStore;
|
|
6
7
|
private userModelStore;
|
|
7
8
|
private friendEventStore;
|
|
8
9
|
private userEventStore;
|
|
9
10
|
private activityEventHandler?;
|
|
10
|
-
constructor(modelStore: FriendModelStore, userModelStore: UserModelStore, friendEventStore: FriendEventStore, userEventStore: UserEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
11
|
-
|
|
11
|
+
constructor(modelStore: FriendModelStore, userModelStore: UserModelStore, friendEventStore: FriendEventStore, userEventStore: UserEventStore, isClient: boolean, modelChangeEmitter?: ModelChangeEmitter, activityEventHandler?: ActivityEventHandler | undefined);
|
|
12
|
+
getModelStore(): FriendModelStore;
|
|
12
13
|
handleClientEventFromRemoteListener(event: FriendEvent): Promise<void>;
|
|
14
|
+
handleClientEventsFromRemoteListenerBulk(events: FriendEvent[]): Promise<void>;
|
|
13
15
|
handleEvent(event: FriendEvent): Promise<void>;
|
|
16
|
+
handleFriendCreated(event: FriendCreated): Promise<void>;
|
|
17
|
+
handleGenericFriendEvent(event: FriendEvent): Promise<void>;
|
|
14
18
|
handleFriendCreatedOnBackend(event: FriendCreated): Promise<void>;
|
|
19
|
+
private handleFriendCreatedServer;
|
|
15
20
|
}
|
|
16
21
|
//# sourceMappingURL=FriendEventHandler.d.ts.map
|
|
@@ -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,
|
|
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,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,kBAAmB,SAAQ,gBAAgB,CAAC,WAAW,CAAC;IAE7D,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,cAAc;IAGtB,OAAO,CAAC,oBAAoB,CAAC;gBANrB,UAAU,EAAE,gBAAgB,EAC5B,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,cAAc,EACtC,QAAQ,EAAE,OAAO,EACjB,kBAAkB,CAAC,EAAE,kBAAkB,EAC/B,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAKhD,aAAa,IAAI,gBAAgB;IAI3B,mCAAmC,CAC5C,KAAK,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC;IAWH,wCAAwC,CACjD,MAAM,EAAE,WAAW,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC;IAqBV,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BxD,wBAAwB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3D,4BAA4B,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAYzD,yBAAyB;CA4I1C"}
|
|
@@ -2,50 +2,83 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
6
|
const uuid_1 = require("uuid");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
class FriendEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
8
|
+
constructor(modelStore, userModelStore, friendEventStore, userEventStore, isClient, modelChangeEmitter, activityEventHandler) {
|
|
9
|
+
super(isClient, modelChangeEmitter);
|
|
9
10
|
this.modelStore = modelStore;
|
|
10
11
|
this.userModelStore = userModelStore;
|
|
11
12
|
this.friendEventStore = friendEventStore;
|
|
12
13
|
this.userEventStore = userEventStore;
|
|
13
14
|
this.activityEventHandler = activityEventHandler;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
20
|
-
existingModel.version === updatedModel.version);
|
|
16
|
+
getModelStore() {
|
|
17
|
+
return this.modelStore;
|
|
21
18
|
}
|
|
22
19
|
async handleClientEventFromRemoteListener(event) {
|
|
23
|
-
const existingModel = await this.modelStore.
|
|
20
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
24
21
|
const updatedModel = event.apply(existingModel);
|
|
25
22
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
26
23
|
await this.modelStore.save(updatedModel);
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
this.modelChangeEmitter?.emit("FriendModel", updatedModel);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async handleClientEventsFromRemoteListenerBulk(events) {
|
|
28
|
+
const updatedModels = [];
|
|
29
|
+
for (const event of events) {
|
|
30
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
31
|
+
const updatedModel = event.apply(existingModel);
|
|
32
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
33
|
+
await this.modelStore.save(updatedModel);
|
|
34
|
+
updatedModels.push(updatedModel);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (this.modelChangeEmitter && updatedModels.length > 0) {
|
|
38
|
+
for (const model of updatedModels) {
|
|
39
|
+
this.modelChangeEmitter.emit("FriendModel", model);
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
43
|
async handleEvent(event) {
|
|
33
44
|
const eventType = event.constructor.name;
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
switch (eventType) {
|
|
46
|
+
case "FriendCreated":
|
|
47
|
+
return await this.handleFriendCreated(event);
|
|
48
|
+
default:
|
|
49
|
+
return await this.handleGenericFriendEvent(event);
|
|
36
50
|
}
|
|
51
|
+
}
|
|
52
|
+
async handleFriendCreated(event) {
|
|
37
53
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
38
54
|
const updatedModel = event.apply(existingModel);
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
await this.modelStore.save(updatedModel);
|
|
59
|
+
if (this.isClient) {
|
|
60
|
+
await this.friendEventStore.addEvent(event);
|
|
61
|
+
this.modelChangeEmitter?.emit("FriendModel", updatedModel);
|
|
62
|
+
if (this.activityEventHandler) {
|
|
63
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
await this.handleFriendCreatedServer(event, updatedModel);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async handleGenericFriendEvent(event) {
|
|
71
|
+
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
72
|
+
const updatedModel = event.apply(existingModel);
|
|
73
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
await this.modelStore.save(updatedModel);
|
|
77
|
+
if (this.isClient) {
|
|
78
|
+
await this.friendEventStore.addEvent(event);
|
|
79
|
+
this.modelChangeEmitter?.emit("FriendModel", updatedModel);
|
|
80
|
+
if (this.activityEventHandler) {
|
|
81
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
49
82
|
}
|
|
50
83
|
}
|
|
51
84
|
}
|
|
@@ -55,6 +88,9 @@ class FriendEventHandler {
|
|
|
55
88
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
56
89
|
await this.modelStore.save(updatedModel);
|
|
57
90
|
}
|
|
91
|
+
await this.handleFriendCreatedServer(event, updatedModel);
|
|
92
|
+
}
|
|
93
|
+
async handleFriendCreatedServer(event, updatedModel) {
|
|
58
94
|
// Check if friend is already a user (try phone first, then email)
|
|
59
95
|
let friendUser = null;
|
|
60
96
|
if (event.friendPhoneNumber) {
|
|
@@ -78,9 +114,7 @@ class FriendEventHandler {
|
|
|
78
114
|
});
|
|
79
115
|
await this.friendEventStore.addEvent(friendIdAddedEvent);
|
|
80
116
|
const modelWithFriendId = friendIdAddedEvent.apply(updatedModel);
|
|
81
|
-
|
|
82
|
-
await this.modelStore.save(modelWithFriendId);
|
|
83
|
-
}
|
|
117
|
+
await this.modelStore.save(modelWithFriendId);
|
|
84
118
|
const primaryUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(event.userId);
|
|
85
119
|
if (primaryUser) {
|
|
86
120
|
const reciprocalFriendCreated = new _1.FriendCreated({
|
|
@@ -99,9 +133,7 @@ class FriendEventHandler {
|
|
|
99
133
|
});
|
|
100
134
|
await this.friendEventStore.addEvent(reciprocalFriendCreated);
|
|
101
135
|
const reciprocalModel = reciprocalFriendCreated.apply(undefined);
|
|
102
|
-
|
|
103
|
-
await this.modelStore.save(reciprocalModel);
|
|
104
|
-
}
|
|
136
|
+
await this.modelStore.save(reciprocalModel);
|
|
105
137
|
if (this.activityEventHandler) {
|
|
106
138
|
await this.activityEventHandler.createActivityLog(reciprocalFriendCreated, undefined, reciprocalModel);
|
|
107
139
|
}
|
|
@@ -124,9 +156,7 @@ class FriendEventHandler {
|
|
|
124
156
|
});
|
|
125
157
|
await this.userEventStore.addEvent(placeholderUserCreated);
|
|
126
158
|
const placeholderUser = placeholderUserCreated.apply(undefined);
|
|
127
|
-
|
|
128
|
-
await this.userModelStore.save(placeholderUser);
|
|
129
|
-
}
|
|
159
|
+
await this.userModelStore.save(placeholderUser);
|
|
130
160
|
// Link primary user to placeholder
|
|
131
161
|
const friendIdAddedEvent = new _1.FriendIdAdded({
|
|
132
162
|
eventId: (0, uuid_1.v4)(),
|
|
@@ -140,9 +170,7 @@ class FriendEventHandler {
|
|
|
140
170
|
});
|
|
141
171
|
await this.friendEventStore.addEvent(friendIdAddedEvent);
|
|
142
172
|
const modelWithPlaceholderId = friendIdAddedEvent.apply(updatedModel);
|
|
143
|
-
|
|
144
|
-
await this.modelStore.save(modelWithPlaceholderId);
|
|
145
|
-
}
|
|
173
|
+
await this.modelStore.save(modelWithPlaceholderId);
|
|
146
174
|
// Create reciprocal friendship for placeholder user
|
|
147
175
|
const primaryUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(event.userId);
|
|
148
176
|
if (primaryUser) {
|
|
@@ -163,9 +191,7 @@ class FriendEventHandler {
|
|
|
163
191
|
});
|
|
164
192
|
await this.friendEventStore.addEvent(reciprocalFriendCreated);
|
|
165
193
|
const reciprocalModel = reciprocalFriendCreated.apply(undefined);
|
|
166
|
-
|
|
167
|
-
await this.modelStore.save(reciprocalModel);
|
|
168
|
-
}
|
|
194
|
+
await this.modelStore.save(reciprocalModel);
|
|
169
195
|
if (this.activityEventHandler) {
|
|
170
196
|
await this.activityEventHandler.createActivityLog(reciprocalFriendCreated, undefined, reciprocalModel);
|
|
171
197
|
}
|