@zeeshan60/event-processor 1.0.0
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 +74 -0
- package/dist/TransactionEventHandler.d.ts +11 -0
- package/dist/TransactionEventHandler.d.ts.map +1 -0
- package/dist/TransactionEventHandler.js +21 -0
- package/dist/TransactionEvents.d.ts +91 -0
- package/dist/TransactionEvents.d.ts.map +1 -0
- package/dist/TransactionEvents.js +69 -0
- package/dist/common/Event.d.ts +8 -0
- package/dist/common/Event.d.ts.map +1 -0
- package/dist/common/Event.js +2 -0
- package/dist/common/EventStore.d.ts +5 -0
- package/dist/common/EventStore.d.ts.map +1 -0
- package/dist/common/EventStore.js +6 -0
- package/dist/common/Model.d.ts +8 -0
- package/dist/common/Model.d.ts.map +1 -0
- package/dist/common/Model.js +2 -0
- package/dist/common/ModelStore.d.ts +6 -0
- package/dist/common/ModelStore.d.ts.map +1 -0
- package/dist/common/ModelStore.js +6 -0
- package/dist/common/index.d.ts +5 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/store/InMemoryEventStore.d.ts +10 -0
- package/dist/store/InMemoryEventStore.d.ts.map +1 -0
- package/dist/store/InMemoryEventStore.js +23 -0
- package/dist/store/InMemoryModelStore.d.ts +11 -0
- package/dist/store/InMemoryModelStore.d.ts.map +1 -0
- package/dist/store/InMemoryModelStore.js +30 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Event Processor
|
|
2
|
+
|
|
3
|
+
Shared event sourcing infrastructure for Loan Tracker projects.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the core building blocks for implementing event sourcing patterns across multiple projects in the Loan Tracker monorepo.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Base Interfaces**: `Event` and `Model` interfaces for type-safe event sourcing
|
|
12
|
+
- **Abstract Stores**: `EventStore` and `ModelStore` base classes
|
|
13
|
+
- **In-Memory Implementations**: Ready-to-use in-memory stores for testing
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
This package is used internally within the monorepo. Reference it in your project's `package.json`:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@loan-tracker/event-processor": "file:../event-processor"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Event Sourcing
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Event, Model, InMemoryEventStore, InMemoryModelStore } from '@loan-tracker/event-processor';
|
|
33
|
+
|
|
34
|
+
// Define your event
|
|
35
|
+
class MyEvent implements Event {
|
|
36
|
+
constructor(
|
|
37
|
+
public userId: string,
|
|
38
|
+
public streamId: string,
|
|
39
|
+
public version: number
|
|
40
|
+
) {}
|
|
41
|
+
|
|
42
|
+
apply(existing: Model | null): Model {
|
|
43
|
+
// Your event application logic
|
|
44
|
+
return {
|
|
45
|
+
id: null,
|
|
46
|
+
userId: this.userId,
|
|
47
|
+
streamId: this.streamId,
|
|
48
|
+
version: this.version,
|
|
49
|
+
deleted: false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Use the stores
|
|
55
|
+
const eventStore = new InMemoryEventStore();
|
|
56
|
+
const modelStore = new InMemoryModelStore();
|
|
57
|
+
|
|
58
|
+
// Store and apply events
|
|
59
|
+
await eventStore.addEvent(event);
|
|
60
|
+
const model = event.apply(null);
|
|
61
|
+
await modelStore.save(model);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Architecture
|
|
65
|
+
|
|
66
|
+
- **Event**: Base interface for all events with `apply()` method
|
|
67
|
+
- **Model**: Base interface for all models/aggregates
|
|
68
|
+
- **EventStore**: Abstract class for event persistence
|
|
69
|
+
- **ModelStore**: Abstract class for model/read-model persistence
|
|
70
|
+
|
|
71
|
+
## Projects Using This Package
|
|
72
|
+
|
|
73
|
+
- `money-rabit-backend`: Firebase Functions backend
|
|
74
|
+
- `mobile`: Mobile application
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Event } from './common/Event';
|
|
2
|
+
import { EventStore } from './common/EventStore';
|
|
3
|
+
import { ModelStore } from './common/ModelStore';
|
|
4
|
+
import { TransactionModel } from './TransactionEvents';
|
|
5
|
+
export declare class TransactionEventHandler {
|
|
6
|
+
private eventStore;
|
|
7
|
+
private modelStore;
|
|
8
|
+
constructor(eventStore: EventStore, modelStore: ModelStore);
|
|
9
|
+
handle(event: Event): Promise<TransactionModel>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=TransactionEventHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/TransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,qBAAa,uBAAuB;IAE5B,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;gBADV,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU;IAI5B,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAiBxD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionEventHandler = void 0;
|
|
4
|
+
class TransactionEventHandler {
|
|
5
|
+
constructor(eventStore, modelStore) {
|
|
6
|
+
this.eventStore = eventStore;
|
|
7
|
+
this.modelStore = modelStore;
|
|
8
|
+
}
|
|
9
|
+
async handle(event) {
|
|
10
|
+
// Store the event
|
|
11
|
+
await this.eventStore.addEvent(event);
|
|
12
|
+
// Get existing model if it exists
|
|
13
|
+
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
14
|
+
// Apply the event to create/update the model
|
|
15
|
+
const updatedModel = event.apply(existingModel);
|
|
16
|
+
// Store the updated model
|
|
17
|
+
await this.modelStore.save(updatedModel);
|
|
18
|
+
return updatedModel;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TransactionEventHandler = TransactionEventHandler;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Event } from './common/Event';
|
|
2
|
+
import { Model } from './common/Model';
|
|
3
|
+
export declare enum SplitType {
|
|
4
|
+
EQUAL = "EQUAL",
|
|
5
|
+
EXACT = "EXACT",
|
|
6
|
+
PERCENTAGE = "PERCENTAGE",
|
|
7
|
+
SHARES = "SHARES"
|
|
8
|
+
}
|
|
9
|
+
export declare enum TransactionEventType {
|
|
10
|
+
TRANSACTION_CREATED = "TRANSACTION_CREATED",
|
|
11
|
+
TRANSACTION_UPDATED = "TRANSACTION_UPDATED",
|
|
12
|
+
TRANSACTION_DELETED = "TRANSACTION_DELETED"
|
|
13
|
+
}
|
|
14
|
+
export interface AmountDto {
|
|
15
|
+
value: number;
|
|
16
|
+
currency: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ChangeHistoryBase {
|
|
19
|
+
type: string;
|
|
20
|
+
changedAt: Date;
|
|
21
|
+
changedBy: string;
|
|
22
|
+
}
|
|
23
|
+
export interface DescriptionUpdated extends ChangeHistoryBase {
|
|
24
|
+
type: 'DESCRIPTION_UPDATED';
|
|
25
|
+
oldValue: string;
|
|
26
|
+
newValue: string;
|
|
27
|
+
}
|
|
28
|
+
export interface AmountUpdated extends ChangeHistoryBase {
|
|
29
|
+
type: 'AMOUNT_UPDATED';
|
|
30
|
+
oldValue: number;
|
|
31
|
+
newValue: number;
|
|
32
|
+
}
|
|
33
|
+
export interface CurrencyUpdated extends ChangeHistoryBase {
|
|
34
|
+
type: 'CURRENCY_UPDATED';
|
|
35
|
+
oldValue: string;
|
|
36
|
+
newValue: string;
|
|
37
|
+
}
|
|
38
|
+
export interface SplitTypeUpdated extends ChangeHistoryBase {
|
|
39
|
+
type: 'SPLIT_TYPE_UPDATED';
|
|
40
|
+
oldValue: SplitType;
|
|
41
|
+
newValue: SplitType;
|
|
42
|
+
}
|
|
43
|
+
export interface TransactionDateUpdated extends ChangeHistoryBase {
|
|
44
|
+
type: 'TRANSACTION_DATE_UPDATED';
|
|
45
|
+
oldValue: Date;
|
|
46
|
+
newValue: Date;
|
|
47
|
+
}
|
|
48
|
+
export type ChangeHistoryItem = DescriptionUpdated | AmountUpdated | CurrencyUpdated | SplitTypeUpdated | TransactionDateUpdated;
|
|
49
|
+
export interface ChangeHistory {
|
|
50
|
+
changes: ChangeHistoryItem[];
|
|
51
|
+
}
|
|
52
|
+
export declare namespace ChangeHistory {
|
|
53
|
+
function empty(): ChangeHistory;
|
|
54
|
+
}
|
|
55
|
+
export interface TransactionModel extends Model {
|
|
56
|
+
logicalTransactionId: string;
|
|
57
|
+
recipientUserId: string;
|
|
58
|
+
description: string;
|
|
59
|
+
currency: string;
|
|
60
|
+
splitType: SplitType;
|
|
61
|
+
totalAmount: number;
|
|
62
|
+
amount: AmountDto | null;
|
|
63
|
+
transactionDate: Date;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
updatedAt: Date | null;
|
|
66
|
+
createdBy: string;
|
|
67
|
+
updatedBy: string | null;
|
|
68
|
+
groupId: string | null;
|
|
69
|
+
groupTransactionId: string | null;
|
|
70
|
+
history: ChangeHistory;
|
|
71
|
+
}
|
|
72
|
+
export declare class TransactionCreated implements Event {
|
|
73
|
+
userId: string;
|
|
74
|
+
recipientUserId: string;
|
|
75
|
+
logicalTransactionId: string;
|
|
76
|
+
description: string;
|
|
77
|
+
currency: string;
|
|
78
|
+
splitType: SplitType;
|
|
79
|
+
totalAmount: number;
|
|
80
|
+
amount: AmountDto | null;
|
|
81
|
+
transactionDate: Date;
|
|
82
|
+
groupId: string | null;
|
|
83
|
+
groupTransactionId: string | null;
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
createdBy: string;
|
|
86
|
+
streamId: string;
|
|
87
|
+
version: number;
|
|
88
|
+
constructor(userId: string, recipientUserId: string, logicalTransactionId: string, description: string, currency: string, splitType: SplitType, totalAmount: number, amount: AmountDto | null, transactionDate: Date, groupId: string | null, groupTransactionId: string | null, createdAt: Date, createdBy: string, streamId: string, version: number);
|
|
89
|
+
apply(_existing: Model | null): TransactionModel;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=TransactionEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionEvents.d.ts","sourceRoot":"","sources":["../src/TransactionEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,oBAAY,SAAS;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,MAAM,WAAW;CACpB;AAED,oBAAY,oBAAoB;IAC5B,mBAAmB,wBAAwB;IAC3C,mBAAmB,wBAAwB;IAC3C,mBAAmB,wBAAwB;CAC9C;AAGD,MAAM,WAAW,SAAS;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACpB;AAGD,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAmB,SA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ineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionCreated = exports.ChangeHistory = exports.TransactionEventType = exports.SplitType = void 0;
|
|
4
|
+
// Enums
|
|
5
|
+
var SplitType;
|
|
6
|
+
(function (SplitType) {
|
|
7
|
+
SplitType["EQUAL"] = "EQUAL";
|
|
8
|
+
SplitType["EXACT"] = "EXACT";
|
|
9
|
+
SplitType["PERCENTAGE"] = "PERCENTAGE";
|
|
10
|
+
SplitType["SHARES"] = "SHARES";
|
|
11
|
+
})(SplitType || (exports.SplitType = SplitType = {}));
|
|
12
|
+
var TransactionEventType;
|
|
13
|
+
(function (TransactionEventType) {
|
|
14
|
+
TransactionEventType["TRANSACTION_CREATED"] = "TRANSACTION_CREATED";
|
|
15
|
+
TransactionEventType["TRANSACTION_UPDATED"] = "TRANSACTION_UPDATED";
|
|
16
|
+
TransactionEventType["TRANSACTION_DELETED"] = "TRANSACTION_DELETED";
|
|
17
|
+
})(TransactionEventType || (exports.TransactionEventType = TransactionEventType = {}));
|
|
18
|
+
var ChangeHistory;
|
|
19
|
+
(function (ChangeHistory) {
|
|
20
|
+
function empty() {
|
|
21
|
+
return { changes: [] };
|
|
22
|
+
}
|
|
23
|
+
ChangeHistory.empty = empty;
|
|
24
|
+
})(ChangeHistory || (exports.ChangeHistory = ChangeHistory = {}));
|
|
25
|
+
// Transaction Created Event
|
|
26
|
+
class TransactionCreated {
|
|
27
|
+
constructor(userId, recipientUserId, logicalTransactionId, description, currency, splitType, totalAmount, amount, transactionDate, groupId, groupTransactionId, createdAt, createdBy, streamId, version) {
|
|
28
|
+
this.userId = userId;
|
|
29
|
+
this.recipientUserId = recipientUserId;
|
|
30
|
+
this.logicalTransactionId = logicalTransactionId;
|
|
31
|
+
this.description = description;
|
|
32
|
+
this.currency = currency;
|
|
33
|
+
this.splitType = splitType;
|
|
34
|
+
this.totalAmount = totalAmount;
|
|
35
|
+
this.amount = amount;
|
|
36
|
+
this.transactionDate = transactionDate;
|
|
37
|
+
this.groupId = groupId;
|
|
38
|
+
this.groupTransactionId = groupTransactionId;
|
|
39
|
+
this.createdAt = createdAt;
|
|
40
|
+
this.createdBy = createdBy;
|
|
41
|
+
this.streamId = streamId;
|
|
42
|
+
this.version = version;
|
|
43
|
+
}
|
|
44
|
+
apply(_existing) {
|
|
45
|
+
return {
|
|
46
|
+
id: null,
|
|
47
|
+
streamId: this.streamId,
|
|
48
|
+
logicalTransactionId: this.logicalTransactionId,
|
|
49
|
+
userId: this.userId,
|
|
50
|
+
recipientUserId: this.recipientUserId,
|
|
51
|
+
description: this.description,
|
|
52
|
+
currency: this.currency,
|
|
53
|
+
splitType: this.splitType,
|
|
54
|
+
totalAmount: this.totalAmount,
|
|
55
|
+
amount: this.amount,
|
|
56
|
+
transactionDate: this.transactionDate,
|
|
57
|
+
createdAt: this.createdAt,
|
|
58
|
+
updatedAt: null,
|
|
59
|
+
createdBy: this.createdBy,
|
|
60
|
+
updatedBy: null,
|
|
61
|
+
deleted: false,
|
|
62
|
+
version: this.version,
|
|
63
|
+
groupId: this.groupId,
|
|
64
|
+
groupTransactionId: this.groupTransactionId,
|
|
65
|
+
history: ChangeHistory.empty(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.TransactionCreated = TransactionCreated;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Event.d.ts","sourceRoot":"","sources":["../../src/common/Event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventStore.d.ts","sourceRoot":"","sources":["../../src/common/EventStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,8BAAsB,UAAU;IAC9B,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/common/Model.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelStore.d.ts","sourceRoot":"","sources":["../../src/common/ModelStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,8BAAsB,UAAU;IAC9B,QAAQ,CAAC,gCAAgC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAClF,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelStore = exports.EventStore = void 0;
|
|
4
|
+
var EventStore_1 = require("./EventStore");
|
|
5
|
+
Object.defineProperty(exports, "EventStore", { enumerable: true, get: function () { return EventStore_1.EventStore; } });
|
|
6
|
+
var ModelStore_1 = require("./ModelStore");
|
|
7
|
+
Object.defineProperty(exports, "ModelStore", { enumerable: true, get: function () { return ModelStore_1.ModelStore; } });
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Event } from './common/Event';
|
|
2
|
+
export { Model } from './common/Model';
|
|
3
|
+
export { EventStore } from './common/EventStore';
|
|
4
|
+
export { ModelStore } from './common/ModelStore';
|
|
5
|
+
export { InMemoryEventStore } from './store/InMemoryEventStore';
|
|
6
|
+
export { InMemoryModelStore } from './store/InMemoryModelStore';
|
|
7
|
+
export { TransactionEventHandler } from './TransactionEventHandler';
|
|
8
|
+
export { TransactionCreated, TransactionModel, SplitType, TransactionEventType, AmountDto, ChangeHistory, ChangeHistoryItem, DescriptionUpdated, AmountUpdated, CurrencyUpdated, SplitTypeUpdated, TransactionDateUpdated, } from './TransactionEvents';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChangeHistory = exports.TransactionEventType = exports.SplitType = exports.TransactionCreated = exports.TransactionEventHandler = exports.InMemoryModelStore = exports.InMemoryEventStore = exports.ModelStore = exports.EventStore = void 0;
|
|
4
|
+
// Abstract stores
|
|
5
|
+
var EventStore_1 = require("./common/EventStore");
|
|
6
|
+
Object.defineProperty(exports, "EventStore", { enumerable: true, get: function () { return EventStore_1.EventStore; } });
|
|
7
|
+
var ModelStore_1 = require("./common/ModelStore");
|
|
8
|
+
Object.defineProperty(exports, "ModelStore", { enumerable: true, get: function () { return ModelStore_1.ModelStore; } });
|
|
9
|
+
// In-memory implementations
|
|
10
|
+
var InMemoryEventStore_1 = require("./store/InMemoryEventStore");
|
|
11
|
+
Object.defineProperty(exports, "InMemoryEventStore", { enumerable: true, get: function () { return InMemoryEventStore_1.InMemoryEventStore; } });
|
|
12
|
+
var InMemoryModelStore_1 = require("./store/InMemoryModelStore");
|
|
13
|
+
Object.defineProperty(exports, "InMemoryModelStore", { enumerable: true, get: function () { return InMemoryModelStore_1.InMemoryModelStore; } });
|
|
14
|
+
// Transaction event handler and types
|
|
15
|
+
var TransactionEventHandler_1 = require("./TransactionEventHandler");
|
|
16
|
+
Object.defineProperty(exports, "TransactionEventHandler", { enumerable: true, get: function () { return TransactionEventHandler_1.TransactionEventHandler; } });
|
|
17
|
+
var TransactionEvents_1 = require("./TransactionEvents");
|
|
18
|
+
Object.defineProperty(exports, "TransactionCreated", { enumerable: true, get: function () { return TransactionEvents_1.TransactionCreated; } });
|
|
19
|
+
Object.defineProperty(exports, "SplitType", { enumerable: true, get: function () { return TransactionEvents_1.SplitType; } });
|
|
20
|
+
Object.defineProperty(exports, "TransactionEventType", { enumerable: true, get: function () { return TransactionEvents_1.TransactionEventType; } });
|
|
21
|
+
Object.defineProperty(exports, "ChangeHistory", { enumerable: true, get: function () { return TransactionEvents_1.ChangeHistory; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventStore } from '../common/EventStore';
|
|
2
|
+
import { Event } from '../common/Event';
|
|
3
|
+
export declare class InMemoryEventStore extends EventStore {
|
|
4
|
+
private events;
|
|
5
|
+
addEvent(event: Event): Promise<void>;
|
|
6
|
+
getEvents(): Event[];
|
|
7
|
+
getEventsByStreamId(streamId: string): Event[];
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=InMemoryEventStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryEventStore.d.ts","sourceRoot":"","sources":["../../src/store/InMemoryEventStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,MAAM,CAAe;IAEvB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3C,SAAS,IAAI,KAAK,EAAE;IAIpB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,EAAE;IAI9C,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryEventStore = void 0;
|
|
4
|
+
const EventStore_1 = require("../common/EventStore");
|
|
5
|
+
class InMemoryEventStore extends EventStore_1.EventStore {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.events = [];
|
|
9
|
+
}
|
|
10
|
+
async addEvent(event) {
|
|
11
|
+
this.events.push(event);
|
|
12
|
+
}
|
|
13
|
+
getEvents() {
|
|
14
|
+
return [...this.events];
|
|
15
|
+
}
|
|
16
|
+
getEventsByStreamId(streamId) {
|
|
17
|
+
return this.events.filter((event) => event.streamId === streamId);
|
|
18
|
+
}
|
|
19
|
+
clear() {
|
|
20
|
+
this.events = [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.InMemoryEventStore = InMemoryEventStore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModelStore } from '../common/ModelStore';
|
|
2
|
+
import { Model } from '../common/Model';
|
|
3
|
+
export declare class InMemoryModelStore extends ModelStore {
|
|
4
|
+
private models;
|
|
5
|
+
getByStreamIdWhereDeletedIsFalse(streamId: string): Promise<Model | null>;
|
|
6
|
+
save(model: Model): Promise<void>;
|
|
7
|
+
getAll(): Model[];
|
|
8
|
+
getAllWhereDeletedIsFalse(): Model[];
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=InMemoryModelStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryModelStore.d.ts","sourceRoot":"","sources":["../../src/store/InMemoryModelStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,MAAM,CAAiC;IAEzC,gCAAgC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAQzE,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,MAAM,IAAI,KAAK,EAAE;IAIjB,yBAAyB,IAAI,KAAK,EAAE;IAIpC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryModelStore = void 0;
|
|
4
|
+
const ModelStore_1 = require("../common/ModelStore");
|
|
5
|
+
class InMemoryModelStore extends ModelStore_1.ModelStore {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.models = new Map();
|
|
9
|
+
}
|
|
10
|
+
async getByStreamIdWhereDeletedIsFalse(streamId) {
|
|
11
|
+
const model = this.models.get(streamId);
|
|
12
|
+
if (!model || model.deleted) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return model;
|
|
16
|
+
}
|
|
17
|
+
async save(model) {
|
|
18
|
+
this.models.set(model.streamId, model);
|
|
19
|
+
}
|
|
20
|
+
getAll() {
|
|
21
|
+
return Array.from(this.models.values());
|
|
22
|
+
}
|
|
23
|
+
getAllWhereDeletedIsFalse() {
|
|
24
|
+
return Array.from(this.models.values()).filter((model) => !model.deleted);
|
|
25
|
+
}
|
|
26
|
+
clear() {
|
|
27
|
+
this.models.clear();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.InMemoryModelStore = InMemoryModelStore;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zeeshan60/event-processor",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared event sourcing infrastructure for Loan Tracker projects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"watch": "tsc --watch",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"test:watch": "jest --watch",
|
|
15
|
+
"test:coverage": "jest --coverage",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"event-sourcing",
|
|
20
|
+
"cqrs",
|
|
21
|
+
"event-store",
|
|
22
|
+
"model-store"
|
|
23
|
+
],
|
|
24
|
+
"author": "zeeshan60",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^30.0.0",
|
|
28
|
+
"@types/node": "^20.10.0",
|
|
29
|
+
"jest": "^30.2.0",
|
|
30
|
+
"ts-jest": "^29.4.5",
|
|
31
|
+
"typescript": "^5.3.3"
|
|
32
|
+
}
|
|
33
|
+
}
|