@eventualize/core 2.0.0 → 2.1.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/dist/EvDbStream.test.js +14 -14
- package/dist/EvDbStream.test.js.map +1 -1
- package/dist/adapters/IEvDbStorageAdapter.d.ts +7 -0
- package/dist/adapters/IEvDbStorageAdapter.js +2 -0
- package/dist/adapters/IEvDbStorageAdapter.js.map +1 -0
- package/dist/codegen/generateStreamFactory.d.ts +18 -0
- package/dist/codegen/generateStreamFactory.js +97 -0
- package/dist/codegen/generateStreamFactory.js.map +1 -0
- package/dist/factories/EvDbStreamFactory.d.ts +50 -0
- package/dist/factories/EvDbStreamFactory.js +103 -0
- package/dist/factories/EvDbStreamFactory.js.map +1 -0
- package/dist/factories/EvDbStreamFactoryTypes.d.ts +20 -0
- package/dist/factories/EvDbStreamFactoryTypes.js +2 -0
- package/dist/factories/EvDbStreamFactoryTypes.js.map +1 -0
- package/dist/factories/EvDbViewFactory.d.ts +24 -0
- package/dist/{EvDbViewFactory.js → factories/EvDbViewFactory.js} +4 -4
- package/dist/factories/EvDbViewFactory.js.map +1 -0
- package/dist/factories/EvDbViewFactoryTypes.d.ts +24 -0
- package/dist/factories/EvDbViewFactoryTypes.js +2 -0
- package/dist/factories/EvDbViewFactoryTypes.js.map +1 -0
- package/dist/factories/StreamFactoryBuilder.d.ts +35 -0
- package/dist/factories/StreamFactoryBuilder.js +67 -0
- package/dist/factories/StreamFactoryBuilder.js.map +1 -0
- package/dist/store/EvDbEventStore.d.ts +68 -0
- package/dist/{EvDbEventStore.js → store/EvDbEventStore.js} +3 -94
- package/dist/store/EvDbEventStore.js.map +1 -0
- package/dist/store/EvDbEventStoreBuilder.d.ts +18 -0
- package/dist/store/EvDbEventStoreBuilder.js +44 -0
- package/dist/store/EvDbEventStoreBuilder.js.map +1 -0
- package/dist/store/EvDbEventStoreTypes.d.ts +11 -0
- package/dist/store/EvDbEventStoreTypes.js +2 -0
- package/dist/store/EvDbEventStoreTypes.js.map +1 -0
- package/dist/store/EvDbStream.d.ts +150 -0
- package/dist/store/EvDbStream.js +192 -0
- package/dist/store/EvDbStream.js.map +1 -0
- package/dist/stream/IEvDbStream.d.ts +0 -0
- package/dist/stream/IEvDbStream.js +2 -0
- package/dist/stream/IEvDbStream.js.map +1 -0
- package/dist/view/EvDbView.d.ts +19 -0
- package/dist/view/EvDbView.js +26 -0
- package/dist/view/EvDbView.js.map +1 -0
- package/dist/view/EvDbViewRaw.d.ts +22 -0
- package/dist/view/EvDbViewRaw.js +41 -0
- package/dist/view/EvDbViewRaw.js.map +1 -0
- package/package.json +2 -2
- package/dist/EvDbEventStore.d.ts +0 -123
- package/dist/EvDbEventStore.js.map +0 -1
- package/dist/EvDbStream.d.ts +0 -49
- package/dist/EvDbStream.js +0 -115
- package/dist/EvDbStream.js.map +0 -1
- package/dist/EvDbStreamFactory.d.ts +0 -97
- package/dist/EvDbStreamFactory.js +0 -155
- package/dist/EvDbStreamFactory.js.map +0 -1
- package/dist/EvDbView.d.ts +0 -34
- package/dist/EvDbView.js +0 -64
- package/dist/EvDbView.js.map +0 -1
- package/dist/EvDbViewFactory.d.ts +0 -45
- package/dist/EvDbViewFactory.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Store class - manages stream creation with configured adapters and factories
|
|
3
3
|
*/
|
|
4
|
-
class BaseStore {
|
|
4
|
+
export class BaseStore {
|
|
5
5
|
constructor(storage, streamFactories) {
|
|
6
6
|
this.streamFactories = {};
|
|
7
7
|
this.storage = storage;
|
|
@@ -14,7 +14,7 @@ class BaseStore {
|
|
|
14
14
|
const factory = this.streamFactories[streamType];
|
|
15
15
|
if (!factory) {
|
|
16
16
|
throw new Error(`No stream factory registered for stream type: ${streamType}. ` +
|
|
17
|
-
`Available types: ${Object.keys(this.streamFactories).join(
|
|
17
|
+
`Available types: ${Object.keys(this.streamFactories).join(", ")}`);
|
|
18
18
|
}
|
|
19
19
|
const stream = factory.create(streamId, this.storage.streamAdapter, this.storage.snapshotAdapter);
|
|
20
20
|
return stream;
|
|
@@ -26,7 +26,7 @@ class BaseStore {
|
|
|
26
26
|
const factory = this.streamFactories[streamType];
|
|
27
27
|
if (!factory) {
|
|
28
28
|
throw new Error(`No stream factory registered for stream type: ${streamType}. ` +
|
|
29
|
-
`Available types: ${Object.keys(this.streamFactories).join(
|
|
29
|
+
`Available types: ${Object.keys(this.streamFactories).join(", ")}`);
|
|
30
30
|
}
|
|
31
31
|
return factory.get(streamId, this.storage.streamAdapter, this.storage.snapshotAdapter);
|
|
32
32
|
}
|
|
@@ -42,76 +42,11 @@ class BaseStore {
|
|
|
42
42
|
getStreamTypes() {
|
|
43
43
|
return Object.keys(this.streamFactories);
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Create a builder for configuring the store
|
|
47
|
-
*/
|
|
48
|
-
static builder() {
|
|
49
|
-
return new BaseStoreBuilder();
|
|
50
|
-
}
|
|
51
45
|
async close() {
|
|
52
46
|
await Promise.all([this.storage.snapshotAdapter.close(), this.storage.streamAdapter.close()]);
|
|
53
47
|
return;
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Builder for creating Store instances
|
|
58
|
-
*/
|
|
59
|
-
class BaseStoreBuilder {
|
|
60
|
-
constructor() {
|
|
61
|
-
this.streamFactories = {};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Configure with separate stream and snapshot adapters
|
|
65
|
-
*/
|
|
66
|
-
withAdapters(streamAdapter, snapshotAdapter) {
|
|
67
|
-
this.streamAdapter = streamAdapter;
|
|
68
|
-
this.snapshotAdapter = snapshotAdapter;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Configure with a combined adapter that implements both interfaces
|
|
73
|
-
*/
|
|
74
|
-
withAdapter(adapter) {
|
|
75
|
-
this.streamAdapter = adapter;
|
|
76
|
-
this.snapshotAdapter = adapter;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Register a stream factory
|
|
81
|
-
*/
|
|
82
|
-
withStreamFactory(factory) {
|
|
83
|
-
const streamType = factory.getStreamType();
|
|
84
|
-
if (this.streamFactories[streamType]) {
|
|
85
|
-
throw new Error(`Stream factory for type '${streamType}' is already registered`);
|
|
86
|
-
}
|
|
87
|
-
this.streamFactories[streamType] = factory;
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Register multiple stream factories at once
|
|
92
|
-
*/
|
|
93
|
-
withStreamFactories(factories) {
|
|
94
|
-
factories.forEach(factory => {
|
|
95
|
-
this.withStreamFactory(factory);
|
|
96
|
-
});
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Build the store instance
|
|
101
|
-
*/
|
|
102
|
-
build() {
|
|
103
|
-
if (!this.streamAdapter || !this.snapshotAdapter) {
|
|
104
|
-
throw new Error('Storage adapters must be configured. Use withAdapter() or withAdapters()');
|
|
105
|
-
}
|
|
106
|
-
if (Object.keys(this.streamFactories).length === 0) {
|
|
107
|
-
console.warn('Store created with no stream factories registered');
|
|
108
|
-
}
|
|
109
|
-
return new BaseStore({
|
|
110
|
-
streamAdapter: this.streamAdapter,
|
|
111
|
-
snapshotAdapter: this.snapshotAdapter
|
|
112
|
-
}, this.streamFactories);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
50
|
/**
|
|
116
51
|
* Type-safe store that knows about specific stream types
|
|
117
52
|
*/
|
|
@@ -153,30 +88,4 @@ export class EvDbEventStore {
|
|
|
153
88
|
return this.store;
|
|
154
89
|
}
|
|
155
90
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Type-safe store builder
|
|
158
|
-
*/
|
|
159
|
-
export class EvDbEventStoreBuilder {
|
|
160
|
-
constructor() {
|
|
161
|
-
this.builder = BaseStore.builder();
|
|
162
|
-
}
|
|
163
|
-
withAdapters(streamAdapter, snapshotAdapter) {
|
|
164
|
-
this.builder.withAdapters(streamAdapter, snapshotAdapter);
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
withAdapter(adapter) {
|
|
168
|
-
this.builder.withAdapter(adapter);
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
// Track stream type in generics
|
|
172
|
-
withStreamFactory(factory) {
|
|
173
|
-
this.builder.withStreamFactory(factory);
|
|
174
|
-
// return as the new type that tracks K
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
build() {
|
|
178
|
-
const store = new EvDbEventStore(this.builder.build());
|
|
179
|
-
return store;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
91
|
//# sourceMappingURL=EvDbEventStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvDbEventStore.js","sourceRoot":"","sources":["../../src/store/EvDbEventStore.ts"],"names":[],"mappings":"AAqBA;;GAEG;AACH,MAAM,OAAO,SAAS;IAIpB,YAAmB,OAAsB,EAAE,eAAsC;QAFhE,oBAAe,GAA0B,EAAE,CAAC;QAG3D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,UAAkB,EAAE,QAAgB;QACtD,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAEjD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,iDAAiD,UAAU,IAAI;gBAC7D,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACrE,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAC3B,QAAQ,EACR,IAAI,CAAC,OAAO,CAAC,aAAa,EAC1B,IAAI,CAAC,OAAO,C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C;IACvD,CAAC;IAED;;OAEG;IACI,SAAS,CACd,UAAa,EACb,QAAgB;QAEhB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;QAEhD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,UAAU,GAAG,SAAS,UAAU,EAAgB,CAAC;YAEvD,4BAA4B;YAC3B,IAAY,CAAC,UAAU,CAAC,GAAG,CAAC,QAAgB,EAAE,EAAE;gBAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACvD,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type IEvDbStorageSnapshotAdapter from "@eventualize/types/adapters/IEvDbStorageSnapshotAdapter";
|
|
2
|
+
import type IEvDbStorageStreamAdapter from "@eventualize/types/adapters/IEvDbStorageStreamAdapter";
|
|
3
|
+
import type { EvDbStreamFactory } from "../factories/EvDbStreamFactory.js";
|
|
4
|
+
import type { IEvDbStorageAdapter } from "../adapters/IEvDbStorageAdapter.js";
|
|
5
|
+
import { EvDbEventStore } from "./EvDbEventStore.js";
|
|
6
|
+
import type { StreamCreatorMethods } from "./EvDbEventStoreTypes.js";
|
|
7
|
+
/**
|
|
8
|
+
* Type-safe store builder
|
|
9
|
+
*/
|
|
10
|
+
export declare class EvDbEventStoreBuilder<TStreamTypes extends Record<string, EvDbStreamFactory<any, string>> = {}> {
|
|
11
|
+
private streamAdapter?;
|
|
12
|
+
private snapshotAdapter?;
|
|
13
|
+
private streamFactories;
|
|
14
|
+
withAdapters(streamAdapter: IEvDbStorageStreamAdapter, snapshotAdapter: IEvDbStorageSnapshotAdapter): this;
|
|
15
|
+
withAdapter(adapter: IEvDbStorageAdapter): this;
|
|
16
|
+
withStreamFactory<F extends EvDbStreamFactory<any, string>, K extends F extends EvDbStreamFactory<any, infer ST> ? ST : never>(factory: F): EvDbEventStoreBuilder<TStreamTypes & Record<K, F>>;
|
|
17
|
+
build(): EvDbEventStore<TStreamTypes> & StreamCreatorMethods<TStreamTypes>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BaseStore, EvDbEventStore } from "./EvDbEventStore.js";
|
|
2
|
+
/**
|
|
3
|
+
* Type-safe store builder
|
|
4
|
+
*/
|
|
5
|
+
export class EvDbEventStoreBuilder {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.streamFactories = {};
|
|
8
|
+
}
|
|
9
|
+
withAdapters(streamAdapter, snapshotAdapter) {
|
|
10
|
+
this.streamAdapter = streamAdapter;
|
|
11
|
+
this.snapshotAdapter = snapshotAdapter;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
withAdapter(adapter) {
|
|
15
|
+
this.streamAdapter = adapter;
|
|
16
|
+
this.snapshotAdapter = adapter;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
// Track stream type in generics
|
|
20
|
+
withStreamFactory(factory) {
|
|
21
|
+
const streamType = factory.getStreamType();
|
|
22
|
+
if (this.streamFactories[streamType]) {
|
|
23
|
+
throw new Error(`Stream factory for type '${streamType}' is already registered`);
|
|
24
|
+
}
|
|
25
|
+
this.streamFactories[streamType] = factory;
|
|
26
|
+
// return as the new type that tracks K
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
build() {
|
|
30
|
+
if (!this.streamAdapter || !this.snapshotAdapter) {
|
|
31
|
+
throw new Error("Storage adapters must be configured. Use withAdapter() or withAdapters()");
|
|
32
|
+
}
|
|
33
|
+
if (Object.keys(this.streamFactories).length === 0) {
|
|
34
|
+
console.warn("Store created with no stream factories registered");
|
|
35
|
+
}
|
|
36
|
+
const baseStore = new BaseStore({
|
|
37
|
+
streamAdapter: this.streamAdapter,
|
|
38
|
+
snapshotAdapter: this.snapshotAdapter,
|
|
39
|
+
}, this.streamFactories);
|
|
40
|
+
const store = new EvDbEventStore(baseStore);
|
|
41
|
+
return store;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=EvDbEventStoreBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvDbEventStoreBuilder.js","sourceRoot":"","sources":["../../src/store/EvDbEventStoreBuilder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAUhE;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAAlC;QAKU,oBAAe,GAA0B,EAAE,CAAC;IAkDtD,CAAC;IAhDQ,YAAY,CACjB,aAAwC,EACxC,eAA4C;QAE5C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,WAAW,CAAC,OAA4B;QAC7C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gCAAgC;IACzB,iBAAiB,CAGtB,OAAU;QACV,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,IAAI,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,4BAA4B,UAAU,yBAAyB,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;QAC3C,uCAAuC;QACvC,OAAO,IAAqE,CAAC;IAC/E,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;QAC9F,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,SAAS,CAC7B;YACE,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,EACD,IAAI,CAAC,eAAe,CACrB,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;QAC5C,OAAO,KAA0E,CAAC;IACpF,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type EvDbStream from "./EvDbStream.js";
|
|
2
|
+
import type { EvDbStreamFactory } from "../factories/EvDbStreamFactory.js";
|
|
3
|
+
import type { EvDbEventStore } from "./EvDbEventStore.js";
|
|
4
|
+
/**
|
|
5
|
+
* Helper type to create method signatures for each stream factory
|
|
6
|
+
*/
|
|
7
|
+
export type StreamCreatorMethods<TStreamTypes extends Record<string, EvDbStreamFactory<any, any>>> = {
|
|
8
|
+
[K in keyof TStreamTypes as `create${K & string}`]: (streamId: string) => EvDbStream;
|
|
9
|
+
};
|
|
10
|
+
export type StreamMap = Record<string, any>;
|
|
11
|
+
export type EvDbEventStoreType<TStreams extends StreamMap = StreamMap> = EvDbEventStore<TStreams> & StreamCreatorMethods<TStreams>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvDbEventStoreTypes.js","sourceRoot":"","sources":["../../src/store/EvDbEventStoreTypes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import EvDbEvent from "@eventualize/types/events/EvDbEvent";
|
|
2
|
+
import type EvDbMessage from "@eventualize/types/messages/EvDbMessage";
|
|
3
|
+
import type IEvDbStorageStreamAdapter from "@eventualize/types/adapters/IEvDbStorageStreamAdapter";
|
|
4
|
+
import type IEvDbView from "@eventualize/types/view/IEvDbView";
|
|
5
|
+
import EvDbStreamAddress from "@eventualize/types/stream/EvDbStreamAddress";
|
|
6
|
+
import type IEvDbStreamStore from "@eventualize/types/store/IEvDbStreamStore";
|
|
7
|
+
import type IEvDbStreamStoreData from "@eventualize/types/store/IEvDbStreamStoreData";
|
|
8
|
+
import type IEvDbEventPayload from "@eventualize/types/events/IEvDbEventPayload";
|
|
9
|
+
import StreamStoreAffected from "@eventualize/types/stream/StreamStoreAffected";
|
|
10
|
+
import type IEvDbEventMetadata from "@eventualize/types/events/IEvDbEventMetadata";
|
|
11
|
+
import type { EvDbStreamType } from "@eventualize/types/primitives/EvDbStreamType";
|
|
12
|
+
import type EVDbMessagesProducer from "@eventualize/types/messages/EvDbMessagesProducer";
|
|
13
|
+
import type { EvDbView } from "../view/EvDbView.js";
|
|
14
|
+
type ImmutableIEvDbView = Readonly<EvDbView<unknown>>;
|
|
15
|
+
/**
|
|
16
|
+
* A read-only map of view name to view instance for a stream.
|
|
17
|
+
* Use this type when you need to pass or store the full set of a stream's views
|
|
18
|
+
* without allowing structural mutation.
|
|
19
|
+
*/
|
|
20
|
+
export type ImmutableIEvDbViewMap = Readonly<Record<string, ImmutableIEvDbView>>;
|
|
21
|
+
/**
|
|
22
|
+
* Core event-sourcing stream that coordinates event appending, view projection,
|
|
23
|
+
* outbox message production, and optimistic-concurrency-controlled persistence.
|
|
24
|
+
*
|
|
25
|
+
* Use `EvDbStream` as the base class for all domain streams. It implements
|
|
26
|
+
* `IEvDbStreamStore` (store/query pending events) and `IEvDbStreamStoreData`
|
|
27
|
+
* (access unspecialized events, messages, and views) so consumers can work
|
|
28
|
+
* against those interfaces without coupling to this concrete class.
|
|
29
|
+
*/
|
|
30
|
+
export default class EvDbStream implements IEvDbStreamStore, IEvDbStreamStoreData {
|
|
31
|
+
protected messagesProducer: EVDbMessagesProducer;
|
|
32
|
+
protected _pendingEvents: ReadonlyArray<EvDbEvent>;
|
|
33
|
+
protected _pendingMessages: ReadonlyArray<EvDbMessage>;
|
|
34
|
+
private static readonly ASSEMBLY_NAME;
|
|
35
|
+
private static readonly DEFAULT_CAPTURE_BY;
|
|
36
|
+
private readonly _storageAdapter;
|
|
37
|
+
protected readonly _views: ImmutableIEvDbViewMap;
|
|
38
|
+
/**
|
|
39
|
+
* Returns all views registered on this stream, keyed by view name.
|
|
40
|
+
* Use this when you need to inspect or iterate over every projection without
|
|
41
|
+
* knowing the view names up-front (e.g. generic tooling or serialization).
|
|
42
|
+
*/
|
|
43
|
+
getViews(): ImmutableIEvDbViewMap;
|
|
44
|
+
/**
|
|
45
|
+
* Returns a single view by its name, or `undefined` if not registered.
|
|
46
|
+
* Use this for targeted access to a specific projection when you know the
|
|
47
|
+
* view name at call-site (prefer typed accessors on concrete subclasses when
|
|
48
|
+
* available).
|
|
49
|
+
*/
|
|
50
|
+
getView(viewName: string): Readonly<IEvDbView> | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the full list of pending (not-yet-stored) events as untyped
|
|
53
|
+
* `EvDbEvent` instances.
|
|
54
|
+
* Use this when you need generic/unspecialized access to the pending event
|
|
55
|
+
* list, e.g. for logging, debugging, or framework-level inspection.
|
|
56
|
+
* Strongly-typed subclasses may expose a narrower accessor instead.
|
|
57
|
+
*/
|
|
58
|
+
getEvents(): ReadonlyArray<EvDbEvent>;
|
|
59
|
+
/**
|
|
60
|
+
* The unique address that identifies this stream instance, combining the
|
|
61
|
+
* stream type and stream ID.
|
|
62
|
+
* Use this to correlate events, cursors, and log entries back to a specific
|
|
63
|
+
* stream without holding a reference to the full stream object.
|
|
64
|
+
*/
|
|
65
|
+
streamAddress: EvDbStreamAddress;
|
|
66
|
+
/**
|
|
67
|
+
* The offset of the last event successfully persisted to storage.
|
|
68
|
+
* Use this to determine the persistence watermark of the stream — it is
|
|
69
|
+
* updated after each successful `store()` call and drives OCC conflict
|
|
70
|
+
* detection on the next write.
|
|
71
|
+
*/
|
|
72
|
+
storedOffset: number;
|
|
73
|
+
/**
|
|
74
|
+
* Constructs a new stream instance, wiring together storage, views, and
|
|
75
|
+
* the outbox message producer.
|
|
76
|
+
*
|
|
77
|
+
* You should not call this constructor directly; use the stream factory
|
|
78
|
+
* (e.g. `EvDbStreamFactory`) so that the adapter, views, and producer are
|
|
79
|
+
* configured consistently.
|
|
80
|
+
*
|
|
81
|
+
* @param streamType - Descriptor that categorises the stream (domain + version).
|
|
82
|
+
* @param views - Projection views that fold events into query-ready state.
|
|
83
|
+
* @param storageAdapter - Adapter used to persist events and outbox messages.
|
|
84
|
+
* @param streamId - Instance-level identifier that, together with `streamType`,
|
|
85
|
+
* uniquely addresses this stream.
|
|
86
|
+
* @param lastStoredOffset - Offset of the last event already in storage; used as
|
|
87
|
+
* the starting cursor and for OCC checks.
|
|
88
|
+
* @param messagesProducer - Function invoked after each `appendEvent` to derive
|
|
89
|
+
* outbox messages from the new event and current view states.
|
|
90
|
+
*/
|
|
91
|
+
constructor(streamType: EvDbStreamType, views: ImmutableIEvDbView[], storageAdapter: IEvDbStorageStreamAdapter, streamId: string, lastStoredOffset: number, messagesProducer: EVDbMessagesProducer);
|
|
92
|
+
/**
|
|
93
|
+
* Appends a domain event to the pending list, applies it to all registered
|
|
94
|
+
* views, and invokes the outbox producer to derive any resulting messages.
|
|
95
|
+
*
|
|
96
|
+
* Use this in concrete subclass methods (e.g. `deposited(amount)`) rather than
|
|
97
|
+
* calling storage directly. The event is **not** persisted until `store()` is
|
|
98
|
+
* called, so multiple `appendEvent` calls can be batched into a single atomic
|
|
99
|
+
* write.
|
|
100
|
+
*
|
|
101
|
+
* @param payload - Typed event payload; `payloadType` must match a type
|
|
102
|
+
* registered on this stream's factory.
|
|
103
|
+
* @param capturedBy - Optional label identifying who/what produced this event
|
|
104
|
+
* (defaults to the core assembly identifier).
|
|
105
|
+
* @returns The populated event metadata (cursor, timestamp, capturedBy).
|
|
106
|
+
*/
|
|
107
|
+
protected appendEvent(payload: IEvDbEventPayload, capturedBy?: string | null): IEvDbEventMetadata;
|
|
108
|
+
private getNextCursor;
|
|
109
|
+
/**
|
|
110
|
+
* Manually inserts a message into the pending outbox without going through
|
|
111
|
+
* the domain event flow.
|
|
112
|
+
*
|
|
113
|
+
* Use this when you need to publish a notification or integration event that
|
|
114
|
+
* is not a direct consequence of a domain event — for example, a saga
|
|
115
|
+
* coordination message or a manually triggered notification. For event-driven
|
|
116
|
+
* messages prefer the `messagesProducer` callback passed to the constructor,
|
|
117
|
+
* which fires automatically inside `appendEvent`.
|
|
118
|
+
*/
|
|
119
|
+
appendToOutbox(e: EvDbMessage): void;
|
|
120
|
+
/**
|
|
121
|
+
* Atomically persists all pending events and outbox messages to storage,
|
|
122
|
+
* advances `storedOffset`, potentialy saves view snapshots, and clears the pending
|
|
123
|
+
* buffers.
|
|
124
|
+
*
|
|
125
|
+
* Use this once you have finished building up a unit of work via one or more
|
|
126
|
+
* `appendEvent` / `appendToOutbox` calls. The call is a no-op (returns
|
|
127
|
+
* `StreamStoreAffected.Empty`) when there are no pending events. Throws
|
|
128
|
+
* `OCCException` if another writer has already stored events at or beyond
|
|
129
|
+
* the current `storedOffset` (optimistic concurrency conflict).
|
|
130
|
+
*
|
|
131
|
+
* @returns A `StreamStoreAffected` value describing how many events and
|
|
132
|
+
* outbox messages were written.
|
|
133
|
+
*/
|
|
134
|
+
store(): Promise<StreamStoreAffected>;
|
|
135
|
+
/**
|
|
136
|
+
* The number of events appended since the last successful `store()` call.
|
|
137
|
+
* Use this to guard against accidentally calling `store()` with an empty
|
|
138
|
+
* batch or to implement pre-store validation that requires at least one event.
|
|
139
|
+
*/
|
|
140
|
+
get countOfPendingEvents(): number;
|
|
141
|
+
/**
|
|
142
|
+
* Returns the full list of pending outbox messages (integration events,
|
|
143
|
+
* notifications, saga commands) that have not yet been stored.
|
|
144
|
+
* Use this for generic/unspecialized access — e.g. framework-level
|
|
145
|
+
* inspection, testing, or logging — when you do not need message-type
|
|
146
|
+
* discrimination. Persisted alongside events during `store()`.
|
|
147
|
+
*/
|
|
148
|
+
getMessages(): ReadonlyArray<EvDbMessage>;
|
|
149
|
+
}
|
|
150
|
+
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import EvDbEvent from "@eventualize/types/events/EvDbEvent";
|
|
2
|
+
import EvDbStreamAddress from "@eventualize/types/stream/EvDbStreamAddress";
|
|
3
|
+
import StreamStoreAffected from "@eventualize/types/stream/StreamStoreAffected";
|
|
4
|
+
import EvDbStreamCursor from "@eventualize/types/stream/EvDbStreamCursor";
|
|
5
|
+
import OCCException from "@eventualize/types/primitives/OCCException";
|
|
6
|
+
/**
|
|
7
|
+
* Core event-sourcing stream that coordinates event appending, view projection,
|
|
8
|
+
* outbox message production, and optimistic-concurrency-controlled persistence.
|
|
9
|
+
*
|
|
10
|
+
* Use `EvDbStream` as the base class for all domain streams. It implements
|
|
11
|
+
* `IEvDbStreamStore` (store/query pending events) and `IEvDbStreamStoreData`
|
|
12
|
+
* (access unspecialized events, messages, and views) so consumers can work
|
|
13
|
+
* against those interfaces without coupling to this concrete class.
|
|
14
|
+
*/
|
|
15
|
+
class EvDbStream {
|
|
16
|
+
/**
|
|
17
|
+
* Returns all views registered on this stream, keyed by view name.
|
|
18
|
+
* Use this when you need to inspect or iterate over every projection without
|
|
19
|
+
* knowing the view names up-front (e.g. generic tooling or serialization).
|
|
20
|
+
*/
|
|
21
|
+
getViews() {
|
|
22
|
+
return this._views;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns a single view by its name, or `undefined` if not registered.
|
|
26
|
+
* Use this for targeted access to a specific projection when you know the
|
|
27
|
+
* view name at call-site (prefer typed accessors on concrete subclasses when
|
|
28
|
+
* available).
|
|
29
|
+
*/
|
|
30
|
+
getView(viewName) {
|
|
31
|
+
return this._views[viewName];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the full list of pending (not-yet-stored) events as untyped
|
|
35
|
+
* `EvDbEvent` instances.
|
|
36
|
+
* Use this when you need generic/unspecialized access to the pending event
|
|
37
|
+
* list, e.g. for logging, debugging, or framework-level inspection.
|
|
38
|
+
* Strongly-typed subclasses may expose a narrower accessor instead.
|
|
39
|
+
*/
|
|
40
|
+
getEvents() {
|
|
41
|
+
return this._pendingEvents;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Constructs a new stream instance, wiring together storage, views, and
|
|
45
|
+
* the outbox message producer.
|
|
46
|
+
*
|
|
47
|
+
* You should not call this constructor directly; use the stream factory
|
|
48
|
+
* (e.g. `EvDbStreamFactory`) so that the adapter, views, and producer are
|
|
49
|
+
* configured consistently.
|
|
50
|
+
*
|
|
51
|
+
* @param streamType - Descriptor that categorises the stream (domain + version).
|
|
52
|
+
* @param views - Projection views that fold events into query-ready state.
|
|
53
|
+
* @param storageAdapter - Adapter used to persist events and outbox messages.
|
|
54
|
+
* @param streamId - Instance-level identifier that, together with `streamType`,
|
|
55
|
+
* uniquely addresses this stream.
|
|
56
|
+
* @param lastStoredOffset - Offset of the last event already in storage; used as
|
|
57
|
+
* the starting cursor and for OCC checks.
|
|
58
|
+
* @param messagesProducer - Function invoked after each `appendEvent` to derive
|
|
59
|
+
* outbox messages from the new event and current view states.
|
|
60
|
+
*/
|
|
61
|
+
constructor(streamType, views, storageAdapter, streamId, lastStoredOffset, messagesProducer) {
|
|
62
|
+
this.messagesProducer = messagesProducer;
|
|
63
|
+
this._pendingEvents = [];
|
|
64
|
+
this._pendingMessages = [];
|
|
65
|
+
this._views = views.reduce((acc, view) => {
|
|
66
|
+
const viewName = view.address.viewName;
|
|
67
|
+
acc[viewName] = view;
|
|
68
|
+
return acc;
|
|
69
|
+
}, {});
|
|
70
|
+
this._storageAdapter = storageAdapter;
|
|
71
|
+
this.streamAddress = new EvDbStreamAddress(streamType, streamId);
|
|
72
|
+
this.storedOffset = lastStoredOffset;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Appends a domain event to the pending list, applies it to all registered
|
|
76
|
+
* views, and invokes the outbox producer to derive any resulting messages.
|
|
77
|
+
*
|
|
78
|
+
* Use this in concrete subclass methods (e.g. `deposited(amount)`) rather than
|
|
79
|
+
* calling storage directly. The event is **not** persisted until `store()` is
|
|
80
|
+
* called, so multiple `appendEvent` calls can be batched into a single atomic
|
|
81
|
+
* write.
|
|
82
|
+
*
|
|
83
|
+
* @param payload - Typed event payload; `payloadType` must match a type
|
|
84
|
+
* registered on this stream's factory.
|
|
85
|
+
* @param capturedBy - Optional label identifying who/what produced this event
|
|
86
|
+
* (defaults to the core assembly identifier).
|
|
87
|
+
* @returns The populated event metadata (cursor, timestamp, capturedBy).
|
|
88
|
+
*/
|
|
89
|
+
appendEvent(payload, capturedBy) {
|
|
90
|
+
capturedBy = capturedBy ?? EvDbStream.DEFAULT_CAPTURE_BY;
|
|
91
|
+
// const json = JSON.stringify(payload); // Or use custom serializer
|
|
92
|
+
const cursor = this.getNextCursor(this._pendingEvents);
|
|
93
|
+
const e = new EvDbEvent(payload.payloadType, cursor, payload, new Date(), capturedBy);
|
|
94
|
+
this._pendingEvents = [...this._pendingEvents, e];
|
|
95
|
+
// Apply to views
|
|
96
|
+
for (const view of Object.values(this._views)) {
|
|
97
|
+
view.applyEvent(e);
|
|
98
|
+
}
|
|
99
|
+
// Outbox producer
|
|
100
|
+
const viewsStates = Object.fromEntries(Object.entries(this._views).map(([k, v]) => {
|
|
101
|
+
return [k, v.state];
|
|
102
|
+
}));
|
|
103
|
+
const producedMessages = this.messagesProducer(e, viewsStates);
|
|
104
|
+
this._pendingMessages = [...this._pendingMessages, ...producedMessages];
|
|
105
|
+
return e;
|
|
106
|
+
}
|
|
107
|
+
getNextCursor(events) {
|
|
108
|
+
if (events.length === 0) {
|
|
109
|
+
return new EvDbStreamCursor(this.streamAddress, this.storedOffset + 1);
|
|
110
|
+
}
|
|
111
|
+
const lastEvent = events[events.length - 1];
|
|
112
|
+
const offset = lastEvent.streamCursor.offset;
|
|
113
|
+
return new EvDbStreamCursor(this.streamAddress, offset + 1);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Manually inserts a message into the pending outbox without going through
|
|
117
|
+
* the domain event flow.
|
|
118
|
+
*
|
|
119
|
+
* Use this when you need to publish a notification or integration event that
|
|
120
|
+
* is not a direct consequence of a domain event — for example, a saga
|
|
121
|
+
* coordination message or a manually triggered notification. For event-driven
|
|
122
|
+
* messages prefer the `messagesProducer` callback passed to the constructor,
|
|
123
|
+
* which fires automatically inside `appendEvent`.
|
|
124
|
+
*/
|
|
125
|
+
appendToOutbox(e) {
|
|
126
|
+
this._pendingMessages = [...this._pendingMessages, e];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Atomically persists all pending events and outbox messages to storage,
|
|
130
|
+
* advances `storedOffset`, potentialy saves view snapshots, and clears the pending
|
|
131
|
+
* buffers.
|
|
132
|
+
*
|
|
133
|
+
* Use this once you have finished building up a unit of work via one or more
|
|
134
|
+
* `appendEvent` / `appendToOutbox` calls. The call is a no-op (returns
|
|
135
|
+
* `StreamStoreAffected.Empty`) when there are no pending events. Throws
|
|
136
|
+
* `OCCException` if another writer has already stored events at or beyond
|
|
137
|
+
* the current `storedOffset` (optimistic concurrency conflict).
|
|
138
|
+
*
|
|
139
|
+
* @returns A `StreamStoreAffected` value describing how many events and
|
|
140
|
+
* outbox messages were written.
|
|
141
|
+
*/
|
|
142
|
+
async store() {
|
|
143
|
+
// Telemetry
|
|
144
|
+
// const tags = this.streamAddress.toOtelTags();
|
|
145
|
+
// const duration = EvDbStream._sysMeters.measureStoreEventsDuration(tags);
|
|
146
|
+
// const activity = EvDbStream._trace.startActivity(tags, 'EvDb.Store');
|
|
147
|
+
try {
|
|
148
|
+
if (this._pendingEvents.length === 0) {
|
|
149
|
+
return StreamStoreAffected.Empty;
|
|
150
|
+
}
|
|
151
|
+
const affected = await this._storageAdapter.storeStreamAsync(this._pendingEvents, this._pendingMessages);
|
|
152
|
+
const lastEvent = this._pendingEvents[this._pendingEvents.length - 1];
|
|
153
|
+
this.storedOffset = lastEvent.streamCursor.offset;
|
|
154
|
+
this._pendingEvents = [];
|
|
155
|
+
this._pendingMessages = [];
|
|
156
|
+
const viewSaveTasks = Object.values(this._views).map((v) => v.store());
|
|
157
|
+
await Promise.all(viewSaveTasks);
|
|
158
|
+
return affected;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof OCCException) {
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The number of events appended since the last successful `store()` call.
|
|
169
|
+
* Use this to guard against accidentally calling `store()` with an empty
|
|
170
|
+
* batch or to implement pre-store validation that requires at least one event.
|
|
171
|
+
*/
|
|
172
|
+
get countOfPendingEvents() {
|
|
173
|
+
return this._pendingEvents.length;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Returns the full list of pending outbox messages (integration events,
|
|
177
|
+
* notifications, saga commands) that have not yet been stored.
|
|
178
|
+
* Use this for generic/unspecialized access — e.g. framework-level
|
|
179
|
+
* inspection, testing, or logging — when you do not need message-type
|
|
180
|
+
* discrimination. Persisted alongside events during `store()`.
|
|
181
|
+
*/
|
|
182
|
+
getMessages() {
|
|
183
|
+
return this._pendingMessages;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
EvDbStream.ASSEMBLY_NAME = {
|
|
187
|
+
name: "evdb-core",
|
|
188
|
+
version: "1.0.0",
|
|
189
|
+
};
|
|
190
|
+
EvDbStream.DEFAULT_CAPTURE_BY = `${EvDbStream.ASSEMBLY_NAME.name}-${EvDbStream.ASSEMBLY_NAME.version}`;
|
|
191
|
+
export default EvDbStream;
|
|
192
|
+
//# sourceMappingURL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CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;YACvE,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAEjC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;gBAClC,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,IAAW,oBAAoB;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACI,WAAW;QAChB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;;AAlOuB,wBAAa,GAAG;IACtC,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;CACjB,AAHoC,CAGnC;AAEsB,6BAAkB,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,IAAI,UAAU,CAAC,aAAa,CAAC,OAAO,EAAE,AAAzE,CAA0E;eATjG,UAAU"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEvDbStream.js","sourceRoot":"","sources":["../../src/stream/IEvDbStream.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IEvDbViewStoreGeneric } from "@eventualize/types/view/IEvDbViewStoreGeneric";
|
|
2
|
+
import type EvDbViewAddress from "@eventualize/types/view/EvDbViewAddress";
|
|
3
|
+
import type IEvDbStorageSnapshotAdapter from "@eventualize/types/adapters/IEvDbStorageSnapshotAdapter";
|
|
4
|
+
import { EvDbStoredSnapshotData } from "@eventualize/types/snapshots/EvDbStoredSnapshotData";
|
|
5
|
+
import type { EvDbStoredSnapshotResult } from "@eventualize/types/snapshots/EvDbStoredSnapshotResult";
|
|
6
|
+
import type IEvDbEventMetadata from "@eventualize/types/events/IEvDbEventMetadata";
|
|
7
|
+
import type IEvDbEventPayload from "@eventualize/types/events/IEvDbEventPayload";
|
|
8
|
+
import type EvDbEvent from "@eventualize/types/events/EvDbEvent";
|
|
9
|
+
import { EvDbViewRaw } from "./EvDbViewRaw.js";
|
|
10
|
+
export declare abstract class EvDbView<TState> extends EvDbViewRaw implements IEvDbViewStoreGeneric<TState> {
|
|
11
|
+
readonly defaultState: TState;
|
|
12
|
+
protected getDefaultState(): TState;
|
|
13
|
+
protected _state: TState;
|
|
14
|
+
get state(): TState;
|
|
15
|
+
constructor(address: EvDbViewAddress, storageAdapter: IEvDbStorageSnapshotAdapter, snapshot: EvDbStoredSnapshotResult<TState>, defaultState: TState);
|
|
16
|
+
getSnapshotData(): EvDbStoredSnapshotData;
|
|
17
|
+
abstract handleOnApply(oldState: TState, event: IEvDbEventPayload, metadata: IEvDbEventMetadata): TState;
|
|
18
|
+
protected onApplyEvent(e: EvDbEvent): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EvDbStoredSnapshotData } from "@eventualize/types/snapshots/EvDbStoredSnapshotData";
|
|
2
|
+
import { EvDbViewRaw } from "./EvDbViewRaw.js";
|
|
3
|
+
export class EvDbView extends EvDbViewRaw {
|
|
4
|
+
getDefaultState() {
|
|
5
|
+
return this.defaultState;
|
|
6
|
+
}
|
|
7
|
+
get state() {
|
|
8
|
+
return this._state;
|
|
9
|
+
}
|
|
10
|
+
constructor(address, storageAdapter, snapshot, defaultState) {
|
|
11
|
+
super(storageAdapter, address, snapshot);
|
|
12
|
+
this.defaultState = defaultState;
|
|
13
|
+
this._state = this.getDefaultState();
|
|
14
|
+
if (snapshot.offset === 0)
|
|
15
|
+
this._state = this.getDefaultState();
|
|
16
|
+
else
|
|
17
|
+
this._state = snapshot.state;
|
|
18
|
+
}
|
|
19
|
+
getSnapshotData() {
|
|
20
|
+
return EvDbStoredSnapshotData.fromAddress(this.address, this.memoryOffset, this.storeOffset, this._state);
|
|
21
|
+
}
|
|
22
|
+
onApplyEvent(e) {
|
|
23
|
+
this._state = this.handleOnApply(this._state, e.payload, e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=EvDbView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvDbView.js","sourceRoot":"","sources":["../../src/view/EvDbView.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAC;AAK7F,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAgB,QACpB,SAAQ,WAAW;IAGT,eAAe;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,YACE,OAAwB,EACxB,cAA2C,EAC3C,QAA0C,EAC1B,YAAoB;QAEpC,KAAK,CAAC,cAAc,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAFzB,iBAAY,GAAZ,YAAY,CAAQ;QAT5B,WAAM,GAAW,IAAI,CAAC,eAAe,EAAE,CAAC;QAYhD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;;YAC3D,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC;IACpC,CAAC;IAED,eAAe;QACb,OAAO,sBAAsB,CAAC,WAAW,CACvC,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAM,CACZ,CAAC;IACJ,CAAC;IAQS,YAAY,CAAC,CAAY;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF"}
|