@ddd-ts/event-sourcing-inmemory 0.0.0-0.1

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.
Files changed (33) hide show
  1. package/dist/event-store/in-memory.event-store.d.ts +34 -0
  2. package/dist/event-store/in-memory.event-store.d.ts.map +1 -0
  3. package/dist/event-store/in-memory.event-store.js +99 -0
  4. package/dist/event-store/in-memory.event-store.js.map +1 -0
  5. package/dist/event-store/in-memory.event-store.spec.d.ts +2 -0
  6. package/dist/event-store/in-memory.event-store.spec.d.ts.map +1 -0
  7. package/dist/event-store/in-memory.event-store.spec.js +8 -0
  8. package/dist/event-store/in-memory.event-store.spec.js.map +1 -0
  9. package/dist/event-store/projected-stream.d.ts +26 -0
  10. package/dist/event-store/projected-stream.d.ts.map +1 -0
  11. package/dist/event-store/projected-stream.js +61 -0
  12. package/dist/event-store/projected-stream.js.map +1 -0
  13. package/dist/event-store/stream.d.ts +13 -0
  14. package/dist/event-store/stream.d.ts.map +1 -0
  15. package/dist/event-store/stream.js +34 -0
  16. package/dist/event-store/stream.js.map +1 -0
  17. package/dist/in-memory.checkpoint.d.ts +11 -0
  18. package/dist/in-memory.checkpoint.d.ts.map +1 -0
  19. package/dist/in-memory.checkpoint.js +31 -0
  20. package/dist/in-memory.checkpoint.js.map +1 -0
  21. package/dist/in-memory.snapshotter.d.ts +13 -0
  22. package/dist/in-memory.snapshotter.d.ts.map +1 -0
  23. package/dist/in-memory.snapshotter.js +38 -0
  24. package/dist/in-memory.snapshotter.js.map +1 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +10 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/test/bank.spec.d.ts +2 -0
  30. package/dist/test/bank.spec.d.ts.map +1 -0
  31. package/dist/test/bank.spec.js +23 -0
  32. package/dist/test/bank.spec.js.map +1 -0
  33. package/package.json +24 -0
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ import { EsAggregate, EsChange, EventStore, ProjectedStreamConfiguration } from "@ddd-ts/event-sourcing";
3
+ import { Constructor } from "@ddd-ts/types";
4
+ export declare class InMemoryEventStore extends EventStore {
5
+ private streams;
6
+ private projectedStreams;
7
+ private newStreamSubscribers;
8
+ close(): Promise<void>;
9
+ clear(): Promise<void>;
10
+ appendToAggregateStream<A extends EsAggregate<any, any>>(AGGREGATE: Constructor<A>, accountId: A extends EsAggregate<infer Id, any> ? Id : never, changes: EsChange[], expectedRevision: bigint): Promise<void>;
11
+ readAggregateStream<A extends EsAggregate<any, any>>(AGGREGATE: Constructor<A>, accountId: A extends EsAggregate<infer Id, any> ? Id : never, from?: bigint): AsyncGenerator<{
12
+ id: string;
13
+ type: string;
14
+ payload: import("@ddd-ts/event-sourcing").Serializable;
15
+ revision: bigint;
16
+ }, void, unknown>;
17
+ private getProjectedStream;
18
+ readProjectedStream(config: ProjectedStreamConfiguration, from?: bigint): AsyncGenerator<{
19
+ id: string;
20
+ type: string;
21
+ payload: import("@ddd-ts/event-sourcing").Serializable;
22
+ revision: bigint;
23
+ }, void, unknown>;
24
+ followProjectedStream(config: ProjectedStreamConfiguration, from?: bigint): Promise<import("@ddd-ts/event-sourcing").Queue<import("@ddd-ts/event-sourcing").EsFact>>;
25
+ competeForProjectedStream(config: ProjectedStreamConfiguration, competition: string): Promise<AsyncIterableIterator<{
26
+ fact: import("@ddd-ts/event-sourcing").EsFact;
27
+ retry: () => NodeJS.Immediate;
28
+ succeed: () => void;
29
+ skip: () => void;
30
+ }> & {
31
+ close: () => Promise<void>;
32
+ }>;
33
+ }
34
+ //# sourceMappingURL=in-memory.event-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.event-store.d.ts","sourceRoot":"","sources":["../../src/event-store/in-memory.event-store.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,gBAAgB,CAAsC;IAE9D,OAAO,CAAC,oBAAoB,CAAuC;IAE7D,KAAK;IAIL,KAAK;IAQL,uBAAuB,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAC3D,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,EACzB,SAAS,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAC5D,OAAO,EAAE,QAAQ,EAAE,EACnB,gBAAgB,EAAE,MAAM;IAwBnB,mBAAmB,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EACxD,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,EACzB,SAAS,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAC5D,IAAI,SAAK;;;;;;IAcX,OAAO,CAAC,kBAAkB;IAiDnB,mBAAmB,CAAC,MAAM,EAAE,4BAA4B,EAAE,IAAI,SAAK;;;;;;IAMpE,qBAAqB,CAAC,MAAM,EAAE,4BAA4B,EAAE,IAAI,SAAK;IAMrE,yBAAyB,CAC7B,MAAM,EAAE,4BAA4B,EACpC,WAAW,EAAE,MAAM;;;;;;;;CAMtB"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryEventStore = void 0;
4
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
5
+ const projected_stream_1 = require("./projected-stream");
6
+ const stream_1 = require("./stream");
7
+ class InMemoryEventStore extends event_sourcing_1.EventStore {
8
+ streams = new Map();
9
+ projectedStreams = new Map();
10
+ newStreamSubscribers = new Set();
11
+ async close() {
12
+ this.clear();
13
+ }
14
+ async clear() {
15
+ this.streams.clear();
16
+ for (const [key, value] of this.projectedStreams) {
17
+ value.onCloseCallbacks.forEach((callback) => callback());
18
+ }
19
+ this.projectedStreams.clear();
20
+ }
21
+ async appendToAggregateStream(AGGREGATE, accountId, changes, expectedRevision) {
22
+ const streamName = `${AGGREGATE.name}-${accountId.toString()}`;
23
+ if (!this.streams.has(streamName)) {
24
+ const stream = new stream_1.Stream();
25
+ this.streams.set(streamName, stream);
26
+ this.newStreamSubscribers.forEach((subscriber) => subscriber(stream));
27
+ }
28
+ const stream = this.streams.get(streamName);
29
+ const currentRevision = stream.facts.length - 1;
30
+ if (currentRevision !== Number(expectedRevision)) {
31
+ throw new Error(`Expected revision ${expectedRevision} but got ${currentRevision}`);
32
+ }
33
+ for (const change of changes) {
34
+ stream.append(change);
35
+ }
36
+ }
37
+ async *readAggregateStream(AGGREGATE, accountId, from = 0n) {
38
+ const streamName = `${AGGREGATE.name}-${accountId.toString()}`;
39
+ const stream = this.streams.get(streamName);
40
+ if (!stream) {
41
+ return;
42
+ }
43
+ for await (const { occuredAt, ...fact } of stream.readRaw(from)) {
44
+ yield fact;
45
+ }
46
+ }
47
+ getProjectedStream(config) {
48
+ const streamName = config
49
+ .map((a) => a.name)
50
+ .sort()
51
+ .join("+");
52
+ if (this.projectedStreams.has(streamName)) {
53
+ return this.projectedStreams.get(streamName);
54
+ }
55
+ const streams = [...this.streams.keys()];
56
+ const correspondingStreams = streams
57
+ .filter((name) => config.some((a) => a.name === name.split("-")[0]))
58
+ .map((name) => this.streams.get(name));
59
+ const orderedFacts = correspondingStreams
60
+ .map((stream) => stream.facts)
61
+ .flat()
62
+ .sort((a, b) => a.occuredAt.getTime() - b.occuredAt.getTime());
63
+ const projectedStream = new projected_stream_1.ProjectedStream();
64
+ for (const fact of orderedFacts) {
65
+ projectedStream.append(fact);
66
+ }
67
+ for (const stream of correspondingStreams) {
68
+ const unsubscribe = stream.subscribe((fact) => {
69
+ projectedStream.append(fact);
70
+ projectedStream.onClose(unsubscribe);
71
+ });
72
+ // here we need to unsubscribe
73
+ }
74
+ this.newStreamSubscribers.add((stream) => {
75
+ // handle non corresponding streams
76
+ const unsubscribe = stream.subscribe((fact) => {
77
+ projectedStream.append(fact);
78
+ });
79
+ projectedStream.onClose(unsubscribe);
80
+ // here we need to unsubscribe
81
+ });
82
+ this.projectedStreams.set(streamName, projectedStream);
83
+ return projectedStream;
84
+ }
85
+ async *readProjectedStream(config, from = 0n) {
86
+ const projectedStream = this.getProjectedStream(config);
87
+ yield* projectedStream.read(from);
88
+ }
89
+ async followProjectedStream(config, from = 0n) {
90
+ const projectedStream = this.getProjectedStream(config);
91
+ return projectedStream.follow(from);
92
+ }
93
+ async competeForProjectedStream(config, competition) {
94
+ const projectedStream = this.getProjectedStream(config);
95
+ return projectedStream.compete(competition);
96
+ }
97
+ }
98
+ exports.InMemoryEventStore = InMemoryEventStore;
99
+ //# sourceMappingURL=in-memory.event-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.event-store.js","sourceRoot":"","sources":["../../src/event-store/in-memory.event-store.ts"],"names":[],"mappings":";;;AAAA,2DAKgC;AAEhC,yDAAqD;AACrD,qCAAkC;AAElC,MAAa,kBAAmB,SAAQ,2BAAU;IACxC,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IACpC,gBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEtD,oBAAoB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEnE,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjD,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,Q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C,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAExD,OAAO,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,yBAAyB,CAC7B,MAAoC,EACpC,WAAmB;QAEnB,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAExD,OAAO,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;CACF;AApID,gDAoIC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=in-memory.event-store.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.event-store.spec.d.ts","sourceRoot":"","sources":["../../src/event-store/in-memory.event-store.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tests_1 = require("@ddd-ts/tests");
4
+ const in_memory_event_store_1 = require("./in-memory.event-store");
5
+ describe("InMemoryEventStore", () => {
6
+ (0, tests_1.EsAggregateStoreSuite)(new in_memory_event_store_1.InMemoryEventStore());
7
+ });
8
+ //# sourceMappingURL=in-memory.event-store.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.event-store.spec.js","sourceRoot":"","sources":["../../src/event-store/in-memory.event-store.spec.ts"],"names":[],"mappings":";;AAAA,yCAAsD;AACtD,mEAA6D;AAE7D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAA,6BAAqB,EAAC,IAAI,0CAAkB,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ import { EsFact, Queue } from "@ddd-ts/event-sourcing";
3
+ import { Stream } from "./stream";
4
+ export declare class ProjectedStream extends Stream {
5
+ followers: Set<Queue<EsFact>>;
6
+ competitions: Map<string, Queue<EsFact>>;
7
+ onCloseCallbacks: any[];
8
+ read(from?: bigint): AsyncGenerator<{
9
+ id: string;
10
+ type: string;
11
+ payload: import("@ddd-ts/event-sourcing").Serializable;
12
+ revision: bigint;
13
+ }, void, unknown>;
14
+ onClose(callback: any): void;
15
+ follow(from?: bigint): Promise<Queue<EsFact>>;
16
+ private getCompetition;
17
+ compete(competitionName: string): Promise<AsyncIterableIterator<{
18
+ fact: EsFact;
19
+ retry: () => NodeJS.Immediate;
20
+ succeed: () => void;
21
+ skip: () => void;
22
+ }> & {
23
+ close: () => Promise<void>;
24
+ }>;
25
+ }
26
+ //# sourceMappingURL=projected-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projected-stream.d.ts","sourceRoot":"","sources":["../../src/event-store/projected-stream.ts"],"names":[],"mappings":";AAAA,OAAO,EAAa,MAAM,EAAO,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,eAAgB,SAAQ,MAAM;IACzC,SAAS,qBAA4B;IACrC,YAAY,6BAAoC;IAEhD,gBAAgB,EAAE,GAAG,EAAE,CAAM;IAEtB,IAAI,CAAC,IAAI,SAAK;;;;;;IAOrB,OAAO,CAAC,QAAQ,EAAE,GAAG;IAIf,MAAM,CAAC,IAAI,SAAK;IAmBtB,OAAO,CAAC,cAAc;IAahB,OAAO,CAAC,eAAe,EAAE,MAAM;;;;;;;;CAiBtC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectedStream = void 0;
4
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
5
+ const stream_1 = require("./stream");
6
+ class ProjectedStream extends stream_1.Stream {
7
+ followers = new Set();
8
+ competitions = new Map();
9
+ onCloseCallbacks = [];
10
+ async *read(from = 0n) {
11
+ for await (const datedFact of super.readRaw(from)) {
12
+ const { occuredAt, ...fact } = datedFact;
13
+ yield fact;
14
+ }
15
+ }
16
+ onClose(callback) {
17
+ this.onCloseCallbacks.push(callback);
18
+ }
19
+ async follow(from = 0n) {
20
+ const follower = new event_sourcing_1.Queue();
21
+ this.followers.add(follower);
22
+ for await (const fact of this.read(from)) {
23
+ follower.push(fact);
24
+ }
25
+ const unsubscribe = this.subscribe((datedFact) => {
26
+ const { occuredAt, ...fact } = datedFact;
27
+ if (fact.revision >= from) {
28
+ follower.push(fact);
29
+ }
30
+ });
31
+ follower.onClose(unsubscribe);
32
+ return follower;
33
+ }
34
+ getCompetition(competitionName) {
35
+ if (!this.competitions.has(competitionName)) {
36
+ const competition = new event_sourcing_1.Queue();
37
+ const unsubscribe = this.subscribe((datedFact) => {
38
+ const { occuredAt, ...fact } = datedFact;
39
+ competition.push(fact);
40
+ });
41
+ competition.onClose(unsubscribe);
42
+ this.competitions.set(competitionName, competition);
43
+ }
44
+ return this.competitions.get(competitionName);
45
+ }
46
+ async compete(competitionName) {
47
+ const competition = this.getCompetition(competitionName);
48
+ return (0, event_sourcing_1.closeable)((0, event_sourcing_1.map)(competition[Symbol.asyncIterator](), (fact) => ({
49
+ fact,
50
+ retry: () => setImmediate(() => competition.push(fact)),
51
+ succeed: () => { },
52
+ skip: () => { },
53
+ })), async () => {
54
+ // competition.close();
55
+ // this.competitions.delete(competitionName);
56
+ // console.log("closing competitor");
57
+ });
58
+ }
59
+ }
60
+ exports.ProjectedStream = ProjectedStream;
61
+ //# sourceMappingURL=projected-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projected-stream.js","sourceRoot":"","sources":["../../src/event-store/projected-stream.ts"],"names":[],"mappings":";;;AAAA,2DAAuE;AACvE,qCAAkC;AAElC,MAAa,eAAgB,SAAQ,eAAM;IACzC,SAAS,GAAG,IAAI,GAAG,EAAiB,CAAC;IACrC,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEhD,gBAAgB,GAAU,EAAE,CAAC;IAE7B,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE;QACnB,IAAI,KA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AAI,EAAE,GAAG,SAAS,CAAC;gBACzC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC;YACH,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACjC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,CAAE,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,eAAuB;QACnC,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QAEzD,OAAO,IAAA,0BAAS,EACd,IAAA,oBAAG,EAAC,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAClD,IAAI;YACJ,KAAK,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvD,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;SACf,CAAC,CAAC,EACH,KAAK,IAAI,EAAE;YACT,uBAAuB;YACvB,6CAA6C;YAC7C,qCAAqC;QACvC,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAlED,0CAkEC"}
@@ -0,0 +1,13 @@
1
+ import { EsFact, EsEvent } from "@ddd-ts/event-sourcing";
2
+ type DatedFact = EsFact & {
3
+ occuredAt: Date;
4
+ };
5
+ export declare class Stream {
6
+ facts: DatedFact[];
7
+ subscribers: Set<(fact: DatedFact) => void>;
8
+ append(change: EsEvent): void;
9
+ subscribe(subscriber: (fact: DatedFact) => void): () => void;
10
+ readRaw(from?: bigint): Generator<DatedFact, void, unknown>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/event-store/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEzD,KAAK,SAAS,GAAG,MAAM,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAE9C,qBAAa,MAAM;IACjB,KAAK,EAAE,SAAS,EAAE,CAAM;IAExB,WAAW,aAAkB,SAAS,KAAK,IAAI,EAAI;IAEnD,MAAM,CAAC,MAAM,EAAE,OAAO;IAetB,SAAS,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI;IAO9C,OAAO,CAAC,IAAI,SAAK;CAMnB"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stream = void 0;
4
+ class Stream {
5
+ facts = [];
6
+ subscribers = new Set();
7
+ append(change) {
8
+ const revision = BigInt(this.facts.length);
9
+ const occuredAt = new Date();
10
+ const datedFact = {
11
+ ...change,
12
+ revision,
13
+ occuredAt,
14
+ };
15
+ this.facts.push(datedFact);
16
+ for (const subscriber of this.subscribers) {
17
+ subscriber(datedFact);
18
+ }
19
+ }
20
+ subscribe(subscriber) {
21
+ this.subscribers.add(subscriber);
22
+ return () => {
23
+ this.subscribers.delete(subscriber);
24
+ };
25
+ }
26
+ *readRaw(from = 0n) {
27
+ const revision = Number(from);
28
+ for (let i = revision; i < this.facts.length; i++) {
29
+ yield this.facts[i];
30
+ }
31
+ }
32
+ }
33
+ exports.Stream = Stream;
34
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/event-store/stream.ts"],"names":[],"mappings":";;;AAIA,MAAa,MAAM;IACjB,KAAK,GAAgB,EAAE,CAAC;IAExB,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;IAEnD,MAAM,CAAC,MAAe;QACpB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAG;YAChB,GAAG,MAAM;YACT,QAAQ;YACR,SAAS;SACV,CAAC;QAEF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,UAAU,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,SAAS,CAAC,UAAqC;QAC7C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC,CAAC;IACJ,CAAC;IAED,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE;QAChB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,KAAK,IAAI,CAAC,GAAG,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClD,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AAjCD,wBAiCC"}
@@ -0,0 +1,11 @@
1
+ import { Checkpoint } from "@ddd-ts/event-sourcing";
2
+ import { InMemoryDatabase, InMemoryTransaction } from "@ddd-ts/store-inmemory";
3
+ export declare class InMemoryCheckpoint extends Checkpoint {
4
+ private readonly inMemoryDatabase;
5
+ projections: Map<string, bigint>;
6
+ constructor(inMemoryDatabase: InMemoryDatabase);
7
+ get(name: string, trx?: InMemoryTransaction): Promise<bigint>;
8
+ set(name: string, revision: bigint, trx?: InMemoryTransaction): Promise<void>;
9
+ clear(): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=in-memory.checkpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.checkpoint.d.ts","sourceRoot":"","sources":["../src/in-memory.checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyB,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,qBAAa,kBAAmB,SAAQ,UAAU;IAGpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAF7C,WAAW,sBAA6B;gBAEX,gBAAgB,EAAE,gBAAgB;IAIzD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,mBAAmB;IAQ3C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,mBAAmB;IAS7D,KAAK;CAGZ"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryCheckpoint = void 0;
4
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
5
+ class InMemoryCheckpoint extends event_sourcing_1.Checkpoint {
6
+ inMemoryDatabase;
7
+ projections = new Map();
8
+ constructor(inMemoryDatabase) {
9
+ super();
10
+ this.inMemoryDatabase = inMemoryDatabase;
11
+ }
12
+ async get(name, trx) {
13
+ const checkpoint = this.inMemoryDatabase.load("checkpoint", name, trx?.transaction);
14
+ if (typeof checkpoint === "bigint") {
15
+ return checkpoint;
16
+ }
17
+ return -1n;
18
+ }
19
+ async set(name, revision, trx) {
20
+ const current = await this.get(name);
21
+ if (revision < current) {
22
+ throw new event_sourcing_1.CheckpointFurtherAway(name, revision, current);
23
+ }
24
+ this.inMemoryDatabase.save("checkpoint", name, revision, trx?.transaction);
25
+ }
26
+ async clear() {
27
+ this.inMemoryDatabase.clear("checkpoint");
28
+ }
29
+ }
30
+ exports.InMemoryCheckpoint = InMemoryCheckpoint;
31
+ //# sourceMappingURL=in-memory.checkpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.checkpoint.js","sourceRoot":"","sources":["../src/in-memory.checkpoint.ts"],"names":[],"mappings":";;;AAAA,2DAA2E;AAG3E,MAAa,kBAAmB,SAAQ,2BAAU;IAGnB;IAF7B,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAExC,YAA6B,gBAAkC;QAC7D,KAAK,EAAE,CAAC;QADmB,qBAAgB,GAAhB,gBAAgB,CAAkB;IAE/D,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,GAAyB;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QACpF,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;IACb,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAE,GAAyB;QACjE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,QAAQ,GAAG,OAAO,EAAE,CAAC;YACvB,MAAM,IAAI,sCAAqB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;CACF;AA3BD,gDA2BC"}
@@ -0,0 +1,13 @@
1
+ import { Snapshotter, EsAggregate } from "@ddd-ts/event-sourcing";
2
+ import { Model } from "@ddd-ts/model";
3
+ import { ISerializer } from "@ddd-ts/serialization";
4
+ import { InMemoryDatabase } from "@ddd-ts/store-inmemory";
5
+ export declare class InMemorySnapshotter<S extends ISerializer<EsAggregate<any, any>>> extends Snapshotter<S extends ISerializer<infer A> ? A : never> {
6
+ private readonly db;
7
+ readonly serializer: S;
8
+ constructor(db: InMemoryDatabase, serializer: S);
9
+ private getIdFromModel;
10
+ load(id: S extends ISerializer<infer T extends Model> ? T['id'] : never): Promise<any>;
11
+ save(aggregate: S extends ISerializer<infer A extends Model> ? A : never): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=in-memory.snapshotter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.snapshotter.d.ts","sourceRoot":"","sources":["../src/in-memory.snapshotter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,qBAAa,mBAAmB,CAC9B,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAC5C,SAAQ,WAAW,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAE7D,OAAO,CAAC,QAAQ,CAAC,EAAE;aACH,UAAU,EAAE,CAAC;gBADZ,EAAE,EAAE,gBAAgB,EACrB,UAAU,EAAE,CAAC;IAK/B,OAAO,CAAC,cAAc;IAShB,IAAI,CAAC,EAAE,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC;IAUtF,IAAI,CACR,SAAS,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,GAClE,OAAO,CAAC,IAAI,CAAC;CAQjB"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemorySnapshotter = void 0;
4
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
5
+ class InMemorySnapshotter extends event_sourcing_1.Snapshotter {
6
+ db;
7
+ serializer;
8
+ constructor(db, serializer) {
9
+ super();
10
+ this.db = db;
11
+ this.serializer = serializer;
12
+ }
13
+ getIdFromModel(model) {
14
+ if (Object.getOwnPropertyNames(model.id).includes('serialize')) {
15
+ if ('serialize' in model.id) {
16
+ return model.id.serialize();
17
+ }
18
+ }
19
+ return model.id.toString();
20
+ }
21
+ async load(id) {
22
+ const snapshot = await this.db.loadLatestSnapshot(id.toString());
23
+ if (!snapshot) {
24
+ return undefined;
25
+ }
26
+ return this.serializer.deserialize(snapshot.serialized);
27
+ }
28
+ async save(aggregate) {
29
+ const id = this.getIdFromModel(aggregate);
30
+ this.db.save("snapshots", id.toString(), {
31
+ id: id.toString(),
32
+ revision: Number(aggregate.acknowledgedRevision),
33
+ serialized: await this.serializer.serialize(aggregate),
34
+ });
35
+ }
36
+ }
37
+ exports.InMemorySnapshotter = InMemorySnapshotter;
38
+ //# sourceMappingURL=in-memory.snapshotter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.snapshotter.js","sourceRoot":"","sources":["../src/in-memory.snapshotter.ts"],"names":[],"mappings":";;;AAAA,2DAAkE;AAKlE,MAAa,mBAEX,SAAQ,4BAAuD;IAE5C;IACD;IAFlB,YACmB,EAAoB,EACrB,UAAa;QAE7B,KAAK,EAAE,CAAC;QAHS,OAAE,GAAF,EAAE,CAAkB;QACrB,eAAU,GAAV,UAAU,CAAG;IAG/B,CAAC;IAEO,cAAc,CAAC,KAA+D;QACpF,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/D,IAAI,WAAW,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;gBAC5B,OAAO,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAA;YAC7B,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAkE;QAC3E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEjE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,IAAI,CACR,SAAmE;QAEnE,MAAM,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE;YACvC,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE;YACjB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;YAChD,UAAU,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC;SACvD,CAAC,CAAC;IACL,CAAC;CACF;AAvCD,kDAuCC"}
@@ -0,0 +1,4 @@
1
+ export { InMemorySnapshotter } from "./in-memory.snapshotter";
2
+ export { InMemoryEventStore } from "./event-store/in-memory.event-store";
3
+ export { InMemoryCheckpoint } from "./in-memory.checkpoint";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryCheckpoint = exports.InMemoryEventStore = exports.InMemorySnapshotter = void 0;
4
+ var in_memory_snapshotter_1 = require("./in-memory.snapshotter");
5
+ Object.defineProperty(exports, "InMemorySnapshotter", { enumerable: true, get: function () { return in_memory_snapshotter_1.InMemorySnapshotter; } });
6
+ var in_memory_event_store_1 = require("./event-store/in-memory.event-store");
7
+ Object.defineProperty(exports, "InMemoryEventStore", { enumerable: true, get: function () { return in_memory_event_store_1.InMemoryEventStore; } });
8
+ var in_memory_checkpoint_1 = require("./in-memory.checkpoint");
9
+ Object.defineProperty(exports, "InMemoryCheckpoint", { enumerable: true, get: function () { return in_memory_checkpoint_1.InMemoryCheckpoint; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAE5B,6EAAyE;AAAhE,2HAAA,kBAAkB,OAAA;AAC3B,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bank.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bank.spec.d.ts","sourceRoot":"","sources":["../../src/test/bank.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
4
+ const store_inmemory_1 = require("@ddd-ts/store-inmemory");
5
+ const tests_1 = require("@ddd-ts/tests");
6
+ const __1 = require("..");
7
+ const in_memory_snapshotter_1 = require("../in-memory.snapshotter");
8
+ describe("EventSourcingInMemory", () => {
9
+ const es = new __1.InMemoryEventStore();
10
+ const database = new store_inmemory_1.InMemoryDatabase();
11
+ const checkpoint = new __1.InMemoryCheckpoint(database);
12
+ const transaction = new store_inmemory_1.InMemoryTransactionPerformer(database);
13
+ (0, tests_1.BankSuite)(es, checkpoint, transaction, (serializer, name) => {
14
+ const store = new store_inmemory_1.InMemoryStore(name, database, serializer);
15
+ return store;
16
+ }, (AGGREGATE, serializer, eventSerializers) => {
17
+ const persistor = class extends (0, event_sourcing_1.EsAggregatePersistorWithSnapshots)(AGGREGATE) {
18
+ };
19
+ const snapshotter = new in_memory_snapshotter_1.InMemorySnapshotter(database, serializer);
20
+ return new persistor(es, eventSerializers, snapshotter);
21
+ });
22
+ });
23
+ //# sourceMappingURL=bank.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bank.spec.js","sourceRoot":"","sources":["../../src/test/bank.spec.ts"],"names":[],"mappings":";;AAAA,2DAA2E;AAC3E,2DAIgC;AAChC,yCAA0C;AAC1C,0BAA4D;AAC5D,oEAA+D;AAE/D,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,MAAM,EAAE,GAAG,IAAI,sBAAkB,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,iCAAgB,EAAE,CAAC;IACxC,MAAM,UAAU,GAAG,IAAI,sBAAkB,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,WAAW,GAAG,IAAI,6CAA4B,CAAC,QAAQ,CAAC,CAAC;IAE/D,IAAA,iBAAS,EACP,EAAE,EACF,UAAU,EACV,WAAW,EACX,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,IAAI,8BAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAQ,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC,EACD,CAAC,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,EAAE;QAC1C,MAAM,SAAS,GAAG,KAAM,SAAQ,IAAA,kDAAiC,EAC/D,SAAS,CACV;SAAG,CAAC;QACL,MAAM,WAAW,GAAG,IAAI,2CAAmB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAClE,OAAO,IAAI,SAAS,CAAC,EAAE,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@ddd-ts/event-sourcing-inmemory",
3
+ "version": "0.0.0-0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "test": "jest --config node_modules/@ddd-ts/tools/jest.config.ts",
9
+ "build": "tsc"
10
+ },
11
+ "dependencies": {
12
+ "@ddd-ts/event-sourcing": "0.0.0-0.1",
13
+ "@ddd-ts/model": "0.0.0-0.1",
14
+ "@ddd-ts/serialization": "0.0.0-0.1",
15
+ "@ddd-ts/store-inmemory": "0.0.0-0.1"
16
+ },
17
+ "devDependencies": {
18
+ "@ddd-ts/tests": "0.0.0-0.1",
19
+ "@ddd-ts/tools": "0.0.0-0.1",
20
+ "@ddd-ts/types": "0.0.0-0.1",
21
+ "@types/jest": "^29.5.1",
22
+ "@types/node": "^20.12.4"
23
+ }
24
+ }