@zeeshan60/event-processor 1.0.14 → 1.0.16
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 +5 -6
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +16 -8
- package/dist/ActivityLogEvents.d.ts.map +1 -1
- package/dist/BaseEventHandler.d.ts +8 -0
- package/dist/BaseEventHandler.d.ts.map +1 -0
- package/dist/BaseEventHandler.js +13 -0
- package/dist/EventProcessorSDK.d.ts +10 -2
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +21 -5
- package/dist/FriendEventHandler.d.ts +6 -2
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +50 -45
- package/dist/GroupEventHandler.d.ts +5 -8
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +241 -186
- package/dist/GroupEvents.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.d.ts +3 -2
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +11 -10
- package/dist/GroupTransactionEvents.d.ts.map +1 -1
- package/dist/ModelChangeEmitter.d.ts +1 -1
- package/dist/ModelChangeEmitter.d.ts.map +1 -1
- package/dist/TransactionEventHandler.d.ts +5 -5
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +19 -30
- package/dist/TransactionEvents.d.ts.map +1 -1
- package/dist/UserEventHandler.d.ts +4 -3
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +16 -40
- package/dist/UserEvents.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts +8 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts.map +1 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.js +16 -0
- package/dist/__tests__/test-helpers/IMFriendEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMFriendEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +3 -2
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.js +20 -0
- package/dist/__tests__/test-helpers/IMUserEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMUserEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +4 -2
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.js +10 -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 +45 -15
- package/dist/client/controllers/TransactionController.d.ts +18 -0
- package/dist/client/controllers/TransactionController.d.ts.map +1 -0
- package/dist/client/controllers/TransactionController.js +275 -0
- package/dist/client/handlers/UIEventHandler.d.ts +0 -1
- package/dist/client/handlers/UIEventHandler.d.ts.map +1 -1
- package/dist/client/handlers/UIEventHandler.js +4 -62
- 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/DomainEvents.d.ts +0 -70
- package/dist/common/DomainEvents.d.ts.map +1 -1
- package/dist/common/DomainEvents.js +0 -89
- package/dist/contracts/expenses/index.d.ts.map +1 -1
- package/dist/contracts/friends/index.d.ts +1 -9
- package/dist/contracts/friends/index.d.ts.map +1 -1
- package/dist/contracts/groups/index.d.ts.map +1 -1
- package/dist/contracts/transactions/index.d.ts +1 -1
- package/dist/contracts/transactions/index.d.ts.map +1 -1
- package/dist/converters/ActivityLogConverters.d.ts +9 -0
- package/dist/converters/ActivityLogConverters.d.ts.map +1 -0
- package/dist/converters/ActivityLogConverters.js +39 -0
- package/dist/converters/EventConverterCore.d.ts +67 -0
- package/dist/converters/EventConverterCore.d.ts.map +1 -0
- package/dist/converters/EventConverterCore.js +59 -0
- package/dist/converters/FriendConverters.d.ts +33 -0
- package/dist/converters/FriendConverters.d.ts.map +1 -0
- package/dist/converters/FriendConverters.js +142 -0
- package/dist/converters/GroupConverters.d.ts +39 -0
- package/dist/converters/GroupConverters.d.ts.map +1 -0
- package/dist/converters/GroupConverters.js +160 -0
- package/dist/converters/GroupTransactionConverters.d.ts +57 -0
- package/dist/converters/GroupTransactionConverters.d.ts.map +1 -0
- package/dist/converters/GroupTransactionConverters.js +249 -0
- package/dist/converters/TransactionConverters.d.ts +51 -0
- package/dist/converters/TransactionConverters.d.ts.map +1 -0
- package/dist/converters/TransactionConverters.js +234 -0
- package/dist/converters/UserConverters.d.ts +51 -0
- package/dist/converters/UserConverters.d.ts.map +1 -0
- package/dist/converters/UserConverters.js +226 -0
- package/dist/converters/eventConverter.d.ts +10 -15
- package/dist/converters/eventConverter.d.ts.map +1 -1
- package/dist/converters/eventConverter.js +96 -377
- package/dist/environment.d.ts +12 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +50 -0
- package/dist/events.d.ts +2 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +7 -3
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -31
- package/dist/store/ActivityLogModelStore.d.ts.map +1 -1
- package/dist/store/CurrencyStore.d.ts +5 -0
- package/dist/store/CurrencyStore.d.ts.map +1 -0
- package/dist/store/CurrencyStore.js +6 -0
- package/dist/store/FriendModelStore.d.ts.map +1 -1
- package/dist/store/GroupModelStore.d.ts.map +1 -1
- package/dist/store/GroupTransactionModelStore.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 +13 -0
- package/dist/utils/BalanceUtil.d.ts.map +1 -0
- package/dist/utils/BalanceUtil.js +97 -0
- 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,13 +1,12 @@
|
|
|
1
|
-
import { Event, Model } from ".";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { UserModelStore } from ".";
|
|
5
|
-
export declare class ActivityEventHandler {
|
|
1
|
+
import { ActivityLogEvent, ActivityLogEventStore, ActivityLogModelStore, Event, Model, UserModelStore } from ".";
|
|
2
|
+
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
|
+
export declare class ActivityEventHandler extends BaseEventHandler<ActivityLogEvent> {
|
|
6
4
|
private activityLogModelStore;
|
|
7
5
|
private activityLogEventStore;
|
|
8
6
|
private userModelStore;
|
|
9
7
|
constructor(activityLogModelStore: ActivityLogModelStore, activityLogEventStore: ActivityLogEventStore, userModelStore: UserModelStore);
|
|
10
|
-
private shouldSkipSave;
|
|
11
8
|
createActivityLog(event: Event, existingModel: Model | undefined, updatedModel: Model): Promise<void>;
|
|
9
|
+
handleClientEventFromRemoteListener(event: ActivityLogEvent): Promise<void>;
|
|
10
|
+
handleEvent(event: ActivityLogEvent): Promise<any>;
|
|
12
11
|
}
|
|
13
12
|
//# sourceMappingURL=ActivityEventHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityEventHandler.d.ts","sourceRoot":"","sources":["../src/ActivityEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAGtD,qBAAa,oBACT,SAAQ,gBAAgB,CAAC,gBAAgB,CAAC;IAGtC,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,cAAc;gBAFd,qBAAqB,EAAE,qBAAqB,EAC5C,qBAAqB,EAAE,qBAAqB,EAC5C,cAAc,EAAE,cAAc;IAKpC,iBAAiB,CACnB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,KAAK,GAAG,SAAS,EAChC,YAAY,EAAE,KAAK,GACpB,OAAO,CAAC,IAAI,CAAC;IAuCV,mCAAmC,CACrC,KAAK,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC;IAehB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC;CAOrD"}
|
|
@@ -2,20 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActivityEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
6
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
6
|
-
class ActivityEventHandler {
|
|
7
|
+
class ActivityEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
7
8
|
constructor(activityLogModelStore, activityLogEventStore, userModelStore) {
|
|
9
|
+
super();
|
|
8
10
|
this.activityLogModelStore = activityLogModelStore;
|
|
9
11
|
this.activityLogEventStore = activityLogEventStore;
|
|
10
12
|
this.userModelStore = userModelStore;
|
|
11
13
|
}
|
|
12
|
-
shouldSkipSave(existingModel, updatedModel) {
|
|
13
|
-
if (!existingModel) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
17
|
-
existingModel.version === updatedModel.version);
|
|
18
|
-
}
|
|
19
14
|
async createActivityLog(event, existingModel, updatedModel) {
|
|
20
15
|
if (!event.activityLog) {
|
|
21
16
|
return;
|
|
@@ -44,5 +39,18 @@ class ActivityEventHandler {
|
|
|
44
39
|
}
|
|
45
40
|
}
|
|
46
41
|
}
|
|
42
|
+
async handleClientEventFromRemoteListener(event) {
|
|
43
|
+
const existingModel = await this.activityLogModelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
44
|
+
const updatedModel = event.apply(existingModel);
|
|
45
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
46
|
+
await this.activityLogModelStore.save(updatedModel);
|
|
47
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("ActivityLogModel", updatedModel);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
handleEvent(event) {
|
|
51
|
+
const error = new Error("Method not implemented. ActivityEventHandler only support createActivityLog for this");
|
|
52
|
+
console.error("Method not implemented.", event, error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
exports.ActivityEventHandler = ActivityEventHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActivityLogEvents.d.ts","sourceRoot":"","sources":["../src/ActivityLogEvents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ActivityLogEvents.d.ts","sourceRoot":"","sources":["../src/ActivityLogEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,oBAAY,UAAU;IAClB,WAAW,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
+
import { Model } from "./common/Model";
|
|
3
|
+
export declare abstract class BaseEventHandler<T extends Event> {
|
|
4
|
+
abstract handleEvent(event: T): Promise<any>;
|
|
5
|
+
abstract handleClientEventFromRemoteListener(event: T): Promise<void>;
|
|
6
|
+
protected shouldSkipSave(existingModel: Model | undefined, updatedModel: Model): boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=BaseEventHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAEvC,8BAAsB,gBAAgB,CAAC,CAAC,SAAS,KAAK;IAClD,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;IAErE,SAAS,CAAC,cAAc,CACpB,aAAa,EAAE,KAAK,GAAG,SAAS,EAChC,YAAY,EAAE,KAAK,GACpB,OAAO;CASb"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEventHandler = void 0;
|
|
4
|
+
class BaseEventHandler {
|
|
5
|
+
shouldSkipSave(existingModel, updatedModel) {
|
|
6
|
+
if (!existingModel) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return (existingModel.streamId === updatedModel.streamId &&
|
|
10
|
+
existingModel.version >= updatedModel.version);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BaseEventHandler = BaseEventHandler;
|
|
@@ -10,13 +10,15 @@ 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";
|
|
16
|
+
import { TransactionController } from "./client/controllers/TransactionController";
|
|
15
17
|
import { UIEventHandler } from "./client/handlers/UIEventHandler";
|
|
16
18
|
import { FirebaseAdapter } from "./adapters/FirebaseAdapter";
|
|
17
|
-
import { Event, FriendEventHandler, UserEventHandler, TransactionEventHandler, GroupEventHandler, GroupTransactionEventHandler, ActivityEventHandler } from "./events";
|
|
18
|
-
import { Model } from "./common/Model";
|
|
19
19
|
import type { FirestoreEventData } from "./converters/eventConverter";
|
|
20
|
+
import { ActivityEventHandler, Event, FriendEventHandler, GroupEventHandler, GroupTransactionEventHandler, TransactionEventHandler, UserEventHandler } from "./events";
|
|
21
|
+
import { Model } from "./common/Model";
|
|
20
22
|
import { ModelChange } from "./ModelChangeEmitter";
|
|
21
23
|
import { Observable } from "rxjs";
|
|
22
24
|
export type StoreConfig = {
|
|
@@ -33,12 +35,14 @@ export type StoreConfig = {
|
|
|
33
35
|
groupTransactionEventStore: GroupTransactionEventStore;
|
|
34
36
|
activityLogModelStore: ActivityLogModelStore;
|
|
35
37
|
activityLogEventStore: ActivityLogEventStore;
|
|
38
|
+
currencyStore: CurrencyStore;
|
|
36
39
|
};
|
|
37
40
|
export declare class EventProcessorSDK {
|
|
38
41
|
private static instance;
|
|
39
42
|
private readonly storeConfig;
|
|
40
43
|
private userControllerInstance;
|
|
41
44
|
private friendControllerInstance;
|
|
45
|
+
private transactionControllerInstance;
|
|
42
46
|
private uiEventHandlerInstance;
|
|
43
47
|
private userEventHandlerInstance;
|
|
44
48
|
private friendEventHandlerInstance;
|
|
@@ -55,6 +59,7 @@ export declare class EventProcessorSDK {
|
|
|
55
59
|
getStoreConfig(): StoreConfig;
|
|
56
60
|
getUserController(): UserController;
|
|
57
61
|
getFriendController(): FriendController;
|
|
62
|
+
getTransactionController(): TransactionController;
|
|
58
63
|
getUIEventHandler(): UIEventHandler;
|
|
59
64
|
getUserEventHandler(): UserEventHandler;
|
|
60
65
|
getFriendEventHandler(): FriendEventHandler;
|
|
@@ -63,12 +68,14 @@ export declare class EventProcessorSDK {
|
|
|
63
68
|
getGroupTransactionEventHandler(): GroupTransactionEventHandler;
|
|
64
69
|
getActivityEventHandler(): ActivityEventHandler;
|
|
65
70
|
getFirebaseAdapter(): FirebaseAdapter;
|
|
71
|
+
getCurrencyStore(): CurrencyStore;
|
|
66
72
|
getModelChangeObservable(): Observable<ModelChange>;
|
|
67
73
|
emitModelChange(modelType: string, model: Model): void;
|
|
68
74
|
}
|
|
69
75
|
export declare function initializeSDK(config: StoreConfig): EventProcessorSDK;
|
|
70
76
|
export declare function getUserController(): UserController;
|
|
71
77
|
export declare function getFriendController(): FriendController;
|
|
78
|
+
export declare function getTransactionController(): TransactionController;
|
|
72
79
|
export declare function getUIEventHandler(): UIEventHandler;
|
|
73
80
|
export declare function getUserEventHandler(): UserEventHandler;
|
|
74
81
|
export declare function getFriendEventHandler(): FriendEventHandler;
|
|
@@ -77,6 +84,7 @@ export declare function getGroupEventHandler(): GroupEventHandler;
|
|
|
77
84
|
export declare function getGroupTransactionEventHandler(): GroupTransactionEventHandler;
|
|
78
85
|
export declare function getActivityEventHandler(): ActivityEventHandler;
|
|
79
86
|
export declare function getFirebaseAdapter(): FirebaseAdapter;
|
|
87
|
+
export declare function getCurrencyStore(): CurrencyStore;
|
|
80
88
|
export declare function getModelChangeObservable(): Observable<ModelChange>;
|
|
81
89
|
export declare function eventToFirestore(event: Event): FirestoreEventData;
|
|
82
90
|
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,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;
|
|
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,qBAAq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.getUserController = getUserController;
|
|
6
6
|
exports.getFriendController = getFriendController;
|
|
7
|
+
exports.getTransactionController = getTransactionController;
|
|
7
8
|
exports.getUIEventHandler = getUIEventHandler;
|
|
8
9
|
exports.getUserEventHandler = getUserEventHandler;
|
|
9
10
|
exports.getFriendEventHandler = getFriendEventHandler;
|
|
@@ -12,6 +13,7 @@ exports.getGroupEventHandler = getGroupEventHandler;
|
|
|
12
13
|
exports.getGroupTransactionEventHandler = getGroupTransactionEventHandler;
|
|
13
14
|
exports.getActivityEventHandler = getActivityEventHandler;
|
|
14
15
|
exports.getFirebaseAdapter = getFirebaseAdapter;
|
|
16
|
+
exports.getCurrencyStore = getCurrencyStore;
|
|
15
17
|
exports.getModelChangeObservable = getModelChangeObservable;
|
|
16
18
|
exports.eventToFirestore = eventToFirestore;
|
|
17
19
|
exports.firestoreToEvent = firestoreToEvent;
|
|
@@ -19,6 +21,7 @@ exports.isSDKInitialized = isSDKInitialized;
|
|
|
19
21
|
exports.__resetSDKForTesting = __resetSDKForTesting;
|
|
20
22
|
const UserController_1 = require("./client/controllers/UserController");
|
|
21
23
|
const FriendController_1 = require("./client/controllers/FriendController");
|
|
24
|
+
const TransactionController_1 = require("./client/controllers/TransactionController");
|
|
22
25
|
const UIEventHandler_1 = require("./client/handlers/UIEventHandler");
|
|
23
26
|
const eventConverter_1 = require("./converters/eventConverter");
|
|
24
27
|
const events_1 = require("./events");
|
|
@@ -59,6 +62,12 @@ class EventProcessorSDK {
|
|
|
59
62
|
}
|
|
60
63
|
return this.friendControllerInstance;
|
|
61
64
|
}
|
|
65
|
+
getTransactionController() {
|
|
66
|
+
if (!this.transactionControllerInstance) {
|
|
67
|
+
this.transactionControllerInstance = new TransactionController_1.TransactionController();
|
|
68
|
+
}
|
|
69
|
+
return this.transactionControllerInstance;
|
|
70
|
+
}
|
|
62
71
|
getUIEventHandler() {
|
|
63
72
|
if (!this.uiEventHandlerInstance) {
|
|
64
73
|
this.uiEventHandlerInstance = new UIEventHandler_1.UIEventHandler();
|
|
@@ -79,7 +88,7 @@ class EventProcessorSDK {
|
|
|
79
88
|
}
|
|
80
89
|
getTransactionEventHandler() {
|
|
81
90
|
if (!this.transactionEventHandlerInstance) {
|
|
82
|
-
this.transactionEventHandlerInstance = new events_1.TransactionEventHandler(this.storeConfig.transactionModelStore, this.storeConfig.transactionEventStore, this.
|
|
91
|
+
this.transactionEventHandlerInstance = new events_1.TransactionEventHandler(this.storeConfig.transactionModelStore, this.storeConfig.transactionEventStore, this.getActivityEventHandler());
|
|
83
92
|
}
|
|
84
93
|
return this.transactionEventHandlerInstance;
|
|
85
94
|
}
|
|
@@ -105,6 +114,9 @@ class EventProcessorSDK {
|
|
|
105
114
|
getFirebaseAdapter() {
|
|
106
115
|
return this.storeConfig.firebaseAdapter;
|
|
107
116
|
}
|
|
117
|
+
getCurrencyStore() {
|
|
118
|
+
return this.storeConfig.currencyStore;
|
|
119
|
+
}
|
|
108
120
|
getModelChangeObservable() {
|
|
109
121
|
return this.modelChangeEmitter.asObservable();
|
|
110
122
|
}
|
|
@@ -122,6 +134,9 @@ function getUserController() {
|
|
|
122
134
|
function getFriendController() {
|
|
123
135
|
return EventProcessorSDK.getInstance().getFriendController();
|
|
124
136
|
}
|
|
137
|
+
function getTransactionController() {
|
|
138
|
+
return EventProcessorSDK.getInstance().getTransactionController();
|
|
139
|
+
}
|
|
125
140
|
function getUIEventHandler() {
|
|
126
141
|
return EventProcessorSDK.getInstance().getUIEventHandler();
|
|
127
142
|
}
|
|
@@ -146,16 +161,17 @@ function getActivityEventHandler() {
|
|
|
146
161
|
function getFirebaseAdapter() {
|
|
147
162
|
return EventProcessorSDK.getInstance().getFirebaseAdapter();
|
|
148
163
|
}
|
|
164
|
+
function getCurrencyStore() {
|
|
165
|
+
return EventProcessorSDK.getInstance().getCurrencyStore();
|
|
166
|
+
}
|
|
149
167
|
function getModelChangeObservable() {
|
|
150
168
|
return EventProcessorSDK.getInstance().getModelChangeObservable();
|
|
151
169
|
}
|
|
152
170
|
function eventToFirestore(event) {
|
|
153
|
-
|
|
154
|
-
return (0, eventConverter_1.eventToFirestore)(event, adapter);
|
|
171
|
+
return (0, eventConverter_1.eventToFirestore)(event);
|
|
155
172
|
}
|
|
156
173
|
function firestoreToEvent(data) {
|
|
157
|
-
|
|
158
|
-
return (0, eventConverter_1.firestoreToEvent)(data, adapter);
|
|
174
|
+
return (0, eventConverter_1.firestoreToEvent)(data);
|
|
159
175
|
}
|
|
160
176
|
function isSDKInitialized() {
|
|
161
177
|
return EventProcessorSDK.isInitialized();
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { FriendCreated, FriendEvent, FriendEventStore, FriendModelStore, UserEventStore, UserModelStore } from ".";
|
|
2
|
+
import { BaseEventHandler } from "./BaseEventHandler";
|
|
2
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
3
|
-
export declare class FriendEventHandler {
|
|
4
|
+
export declare class FriendEventHandler extends BaseEventHandler<FriendEvent> {
|
|
4
5
|
private modelStore;
|
|
5
6
|
private userModelStore;
|
|
6
7
|
private friendEventStore;
|
|
7
8
|
private userEventStore;
|
|
8
9
|
private activityEventHandler?;
|
|
9
10
|
constructor(modelStore: FriendModelStore, userModelStore: UserModelStore, friendEventStore: FriendEventStore, userEventStore: UserEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
10
|
-
|
|
11
|
+
handleClientEventFromRemoteListener(event: FriendEvent): Promise<void>;
|
|
11
12
|
handleEvent(event: FriendEvent): Promise<void>;
|
|
12
13
|
handleFriendCreated(event: FriendCreated): Promise<void>;
|
|
14
|
+
handleGenericFriendEvent(event: FriendEvent): Promise<void>;
|
|
15
|
+
handleFriendCreatedOnBackend(event: FriendCreated): Promise<void>;
|
|
16
|
+
private handleFriendCreatedServer;
|
|
13
17
|
}
|
|
14
18
|
//# 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,EAIhB,cAAc,EAEd,cAAc,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAI9D,qBAAa,kBAAmB,SAAQ,gBAAgB,CAAC,WAAW,CAAC;IAE7D,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;IAK1C,mCAAmC,CAC5C,KAAK,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC;IAgBV,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BxD,wBAAwB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B3D,4BAA4B,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAYzD,yBAAyB;CA4I1C"}
|
|
@@ -2,56 +2,83 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FriendEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
-
const
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
7
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
8
|
-
class FriendEventHandler {
|
|
8
|
+
class FriendEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
9
9
|
constructor(modelStore, userModelStore, friendEventStore, userEventStore, activityEventHandler) {
|
|
10
|
+
super();
|
|
10
11
|
this.modelStore = modelStore;
|
|
11
12
|
this.userModelStore = userModelStore;
|
|
12
13
|
this.friendEventStore = friendEventStore;
|
|
13
14
|
this.userEventStore = userEventStore;
|
|
14
15
|
this.activityEventHandler = activityEventHandler;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
async handleClientEventFromRemoteListener(event) {
|
|
18
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
19
|
+
const updatedModel = event.apply(existingModel);
|
|
20
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
21
|
+
await this.modelStore.save(updatedModel);
|
|
22
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
23
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", updatedModel);
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
21
|
-
existingModel.version === updatedModel.version);
|
|
22
26
|
}
|
|
23
27
|
async handleEvent(event) {
|
|
24
28
|
const eventType = event.constructor.name;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
switch (eventType) {
|
|
30
|
+
case "FriendCreated":
|
|
31
|
+
return await this.handleFriendCreated(event);
|
|
32
|
+
default:
|
|
33
|
+
return await this.handleGenericFriendEvent(event);
|
|
30
34
|
}
|
|
35
|
+
}
|
|
36
|
+
async handleFriendCreated(event) {
|
|
31
37
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
32
38
|
const updatedModel = event.apply(existingModel);
|
|
33
|
-
if (
|
|
34
|
-
|
|
39
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await this.modelStore.save(updatedModel);
|
|
43
|
+
if (_1.residence.isClient) {
|
|
44
|
+
await this.friendEventStore.addEvent(event);
|
|
35
45
|
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
36
46
|
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", updatedModel);
|
|
37
47
|
}
|
|
48
|
+
if (this.activityEventHandler) {
|
|
49
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await this.handleFriendCreatedServer(event, updatedModel);
|
|
38
54
|
}
|
|
55
|
+
}
|
|
56
|
+
async handleGenericFriendEvent(event) {
|
|
57
|
+
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
58
|
+
const updatedModel = event.apply(existingModel);
|
|
59
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await this.modelStore.save(updatedModel);
|
|
39
63
|
if (_1.residence.isClient) {
|
|
40
64
|
await this.friendEventStore.addEvent(event);
|
|
65
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
66
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", updatedModel);
|
|
67
|
+
}
|
|
41
68
|
if (this.activityEventHandler) {
|
|
42
69
|
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
43
70
|
}
|
|
44
71
|
}
|
|
45
72
|
}
|
|
46
|
-
async
|
|
73
|
+
async handleFriendCreatedOnBackend(event) {
|
|
47
74
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
48
75
|
const updatedModel = event.apply(existingModel);
|
|
49
76
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
50
77
|
await this.modelStore.save(updatedModel);
|
|
51
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
52
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", updatedModel);
|
|
53
|
-
}
|
|
54
78
|
}
|
|
79
|
+
await this.handleFriendCreatedServer(event, updatedModel);
|
|
80
|
+
}
|
|
81
|
+
async handleFriendCreatedServer(event, updatedModel) {
|
|
55
82
|
// Check if friend is already a user (try phone first, then email)
|
|
56
83
|
let friendUser = null;
|
|
57
84
|
if (event.friendPhoneNumber) {
|
|
@@ -75,12 +102,7 @@ class FriendEventHandler {
|
|
|
75
102
|
});
|
|
76
103
|
await this.friendEventStore.addEvent(friendIdAddedEvent);
|
|
77
104
|
const modelWithFriendId = friendIdAddedEvent.apply(updatedModel);
|
|
78
|
-
|
|
79
|
-
await this.modelStore.save(modelWithFriendId);
|
|
80
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
81
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", modelWithFriendId);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
105
|
+
await this.modelStore.save(modelWithFriendId);
|
|
84
106
|
const primaryUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(event.userId);
|
|
85
107
|
if (primaryUser) {
|
|
86
108
|
const reciprocalFriendCreated = new _1.FriendCreated({
|
|
@@ -99,12 +121,7 @@ class FriendEventHandler {
|
|
|
99
121
|
});
|
|
100
122
|
await this.friendEventStore.addEvent(reciprocalFriendCreated);
|
|
101
123
|
const reciprocalModel = reciprocalFriendCreated.apply(undefined);
|
|
102
|
-
|
|
103
|
-
await this.modelStore.save(reciprocalModel);
|
|
104
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
105
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", reciprocalModel);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
124
|
+
await this.modelStore.save(reciprocalModel);
|
|
108
125
|
if (this.activityEventHandler) {
|
|
109
126
|
await this.activityEventHandler.createActivityLog(reciprocalFriendCreated, undefined, reciprocalModel);
|
|
110
127
|
}
|
|
@@ -127,9 +144,7 @@ class FriendEventHandler {
|
|
|
127
144
|
});
|
|
128
145
|
await this.userEventStore.addEvent(placeholderUserCreated);
|
|
129
146
|
const placeholderUser = placeholderUserCreated.apply(undefined);
|
|
130
|
-
|
|
131
|
-
await this.userModelStore.save(placeholderUser);
|
|
132
|
-
}
|
|
147
|
+
await this.userModelStore.save(placeholderUser);
|
|
133
148
|
// Link primary user to placeholder
|
|
134
149
|
const friendIdAddedEvent = new _1.FriendIdAdded({
|
|
135
150
|
eventId: (0, uuid_1.v4)(),
|
|
@@ -143,12 +158,7 @@ class FriendEventHandler {
|
|
|
143
158
|
});
|
|
144
159
|
await this.friendEventStore.addEvent(friendIdAddedEvent);
|
|
145
160
|
const modelWithPlaceholderId = friendIdAddedEvent.apply(updatedModel);
|
|
146
|
-
|
|
147
|
-
await this.modelStore.save(modelWithPlaceholderId);
|
|
148
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
149
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", modelWithPlaceholderId);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
161
|
+
await this.modelStore.save(modelWithPlaceholderId);
|
|
152
162
|
// Create reciprocal friendship for placeholder user
|
|
153
163
|
const primaryUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(event.userId);
|
|
154
164
|
if (primaryUser) {
|
|
@@ -169,12 +179,7 @@ class FriendEventHandler {
|
|
|
169
179
|
});
|
|
170
180
|
await this.friendEventStore.addEvent(reciprocalFriendCreated);
|
|
171
181
|
const reciprocalModel = reciprocalFriendCreated.apply(undefined);
|
|
172
|
-
|
|
173
|
-
await this.modelStore.save(reciprocalModel);
|
|
174
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
175
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("FriendModel", reciprocalModel);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
182
|
+
await this.modelStore.save(reciprocalModel);
|
|
178
183
|
if (this.activityEventHandler) {
|
|
179
184
|
await this.activityEventHandler.createActivityLog(reciprocalFriendCreated, undefined, reciprocalModel);
|
|
180
185
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { GroupCreated,
|
|
2
|
-
import {
|
|
3
|
-
import { FriendModelStore } from ".";
|
|
4
|
-
import { UserModelStore } from ".";
|
|
5
|
-
import { GroupEventStore } from ".";
|
|
6
|
-
import { FriendEventStore } from ".";
|
|
1
|
+
import { FriendEventStore, FriendModelStore, GroupCreated, GroupDeleted, GroupDescriptionChanged, GroupEvent, GroupEventStore, GroupMembersAdded, GroupMembersRemoved, GroupModel, GroupModelStore, GroupNameChanged, UserModelStore } from ".";
|
|
2
|
+
import { BaseEventHandler } from "./BaseEventHandler";
|
|
7
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
8
|
-
export declare class GroupEventHandler {
|
|
4
|
+
export declare class GroupEventHandler extends BaseEventHandler<GroupEvent> {
|
|
9
5
|
private modelStore;
|
|
10
6
|
private friendModelStore;
|
|
11
7
|
private userModelStore;
|
|
@@ -13,7 +9,8 @@ export declare class GroupEventHandler {
|
|
|
13
9
|
private friendEventStore;
|
|
14
10
|
private activityEventHandler?;
|
|
15
11
|
constructor(modelStore: GroupModelStore, friendModelStore: FriendModelStore, userModelStore: UserModelStore, groupEventStore: GroupEventStore, friendEventStore: FriendEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
16
|
-
|
|
12
|
+
handleClientEventFromRemoteListener(event: GroupEvent): Promise<void>;
|
|
13
|
+
currentUserId?: string;
|
|
17
14
|
handleEvent(event: GroupEvent): Promise<GroupModel>;
|
|
18
15
|
private ensureBidirectionalFriendship;
|
|
19
16
|
handleGroupCreated(event: GroupCreated): Promise<GroupModel>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"GroupEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,gBAAgB,EAEhB,cAAc,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAI9D,qBAAa,iBAAkB,SAAQ,gBAAgB,CAAC,UAAU,CAAC;IAE3D,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,oBAAoB,CAAC;gBALrB,UAAU,EAAE,eAAe,EAC3B,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,EAClC,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAK1C,mCAAmC,CAC5C,KAAK,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC;IAgBhB,aAAa,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YAgC3C,6BAA6B;IA2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