@ddd-ts/event-sourcing-inmemory 0.0.37 → 0.0.39
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/LICENSE +21 -0
- package/dist/in-memory.event-lake.aggregate-store.d.ts +37 -0
- package/dist/in-memory.event-lake.aggregate-store.d.ts.map +1 -0
- package/dist/in-memory.event-lake.aggregate-store.js +43 -0
- package/dist/in-memory.event-lake.aggregate-store.mjs +42 -0
- package/dist/in-memory.event-lake.aggregate-store.spec.d.ts +2 -0
- package/dist/in-memory.event-lake.aggregate-store.spec.d.ts.map +1 -0
- package/dist/in-memory.event-lake.storage-layer.d.ts +10 -0
- package/dist/in-memory.event-lake.storage-layer.d.ts.map +1 -0
- package/dist/in-memory.event-lake.storage-layer.js +54 -0
- package/dist/in-memory.event-lake.storage-layer.mjs +54 -0
- package/dist/in-memory.event-lake.store.d.ts +6 -0
- package/dist/in-memory.event-lake.store.d.ts.map +1 -0
- package/dist/in-memory.event-lake.store.js +12 -0
- package/dist/in-memory.event-lake.store.mjs +12 -0
- package/dist/in-memory.event-lake.store.spec.d.ts +2 -0
- package/dist/in-memory.event-lake.store.spec.d.ts.map +1 -0
- package/dist/in-memory.event-stream.aggregate-store.d.ts +30 -0
- package/dist/in-memory.event-stream.aggregate-store.d.ts.map +1 -0
- package/dist/in-memory.event-stream.aggregate-store.js +36 -0
- package/dist/in-memory.event-stream.aggregate-store.mjs +35 -0
- package/dist/in-memory.event-stream.aggregate-store.spec.d.ts +2 -0
- package/dist/in-memory.event-stream.aggregate-store.spec.d.ts.map +1 -0
- package/dist/in-memory.event-stream.storage-layer.d.ts +11 -0
- package/dist/in-memory.event-stream.storage-layer.d.ts.map +1 -0
- package/dist/in-memory.event-stream.storage-layer.js +42 -0
- package/dist/in-memory.event-stream.storage-layer.mjs +42 -0
- package/dist/in-memory.event-stream.store.d.ts +6 -0
- package/dist/in-memory.event-stream.store.d.ts.map +1 -0
- package/dist/in-memory.event-stream.store.js +12 -0
- package/dist/in-memory.event-stream.store.mjs +12 -0
- package/dist/in-memory.event-stream.store.spec.d.ts +2 -0
- package/dist/in-memory.event-stream.store.spec.d.ts.map +1 -0
- package/dist/in-memory.projected-stream.reader.d.ts +6 -0
- package/dist/in-memory.projected-stream.reader.d.ts.map +1 -0
- package/dist/in-memory.projected-stream.reader.js +13 -0
- package/dist/in-memory.projected-stream.reader.mjs +13 -0
- package/dist/in-memory.projected-stream.reader.spec.d.ts +2 -0
- package/dist/in-memory.projected-stream.reader.spec.d.ts.map +1 -0
- package/dist/in-memory.projected-stream.storage-layer.d.ts +27 -0
- package/dist/in-memory.projected-stream.storage-layer.d.ts.map +1 -0
- package/dist/in-memory.projected-stream.storage-layer.js +99 -0
- package/dist/in-memory.projected-stream.storage-layer.mjs +97 -0
- package/dist/in-memory.snapshotter.d.ts +6 -0
- package/dist/in-memory.snapshotter.d.ts.map +1 -0
- package/dist/in-memory.snapshotter.js +29 -0
- package/dist/in-memory.snapshotter.mjs +29 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.mjs +11 -0
- package/package.json +22 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Aetherall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LakeId, type IEventBus, EventLakeStore, type EventOf, type ISerializer, type IEventSourced, type IIdentifiable, EventSourced, Identifiable } from "@ddd-ts/core";
|
|
2
|
+
import { InMemoryDatabase, InMemoryStore, InMemoryTransaction, InMemoryTransactionPerformer } from "@ddd-ts/store-inmemory";
|
|
3
|
+
import type { HasTrait } from "@ddd-ts/traits";
|
|
4
|
+
export declare const MakeInMemoryEventLakeAggregateStore: <A extends HasTrait<typeof EventSourced> & HasTrait<typeof Identifiable>>(AGGREGATE: A) => abstract new (database: InMemoryDatabase, collection: string, serializer: ISerializer<InstanceType<A>> & ISerializer<EventOf<InstanceType<A>>>, eventBus?: IEventBus) => {
|
|
5
|
+
readonly database: InMemoryDatabase;
|
|
6
|
+
readonly collection: string;
|
|
7
|
+
getLakeId(instance: InstanceType<A>): LakeId;
|
|
8
|
+
transaction: InMemoryTransactionPerformer;
|
|
9
|
+
lakeStore: EventLakeStore<EventOf<InstanceType<A>>>;
|
|
10
|
+
readonly serializer: ISerializer<EventOf<InstanceType<A>>, {}> & ISerializer<InstanceType<A>, {}>;
|
|
11
|
+
readonly eventBus?: IEventBus | undefined;
|
|
12
|
+
readonly $name?: string | undefined;
|
|
13
|
+
save(aggregate: InstanceType<A>, trx?: InMemoryTransaction): Promise<void>;
|
|
14
|
+
filter(predicate: (model: InstanceType<A>) => boolean, trx?: InMemoryTransaction): Promise<InstanceType<A>[]>;
|
|
15
|
+
clear(): void;
|
|
16
|
+
create(model: InstanceType<A>, trx?: InMemoryTransaction): Promise<void>;
|
|
17
|
+
saveAll(models: InstanceType<A>[], trx?: InMemoryTransaction): Promise<void>;
|
|
18
|
+
load(id: InstanceType<A>["id"], trx?: InMemoryTransaction): Promise<InstanceType<A> | undefined>;
|
|
19
|
+
loadAll(trx?: InMemoryTransaction): Promise<InstanceType<A>[]>;
|
|
20
|
+
loadMany(ids: InstanceType<A>["id"][], trx?: InMemoryTransaction): Promise<InstanceType<A>[]>;
|
|
21
|
+
delete(id: InstanceType<A>["id"], trx?: InMemoryTransaction): Promise<void>;
|
|
22
|
+
countAll(): Promise<number>;
|
|
23
|
+
streamAll(): AsyncIterable<InstanceType<A>>;
|
|
24
|
+
};
|
|
25
|
+
export declare abstract class InMemoryEventLakeAggregateStore<A extends IEventSourced & IIdentifiable> extends InMemoryStore<A> {
|
|
26
|
+
readonly database: InMemoryDatabase;
|
|
27
|
+
readonly collection: string;
|
|
28
|
+
readonly serializer: ISerializer<EventOf<A>> & ISerializer<A>;
|
|
29
|
+
readonly eventBus?: IEventBus | undefined;
|
|
30
|
+
readonly $name?: string | undefined;
|
|
31
|
+
transaction: InMemoryTransactionPerformer;
|
|
32
|
+
lakeStore: EventLakeStore<EventOf<A>>;
|
|
33
|
+
constructor(database: InMemoryDatabase, collection: string, serializer: ISerializer<EventOf<A>> & ISerializer<A>, eventBus?: IEventBus | undefined, $name?: string | undefined);
|
|
34
|
+
abstract getLakeId(instance: A): LakeId;
|
|
35
|
+
save(aggregate: A, trx?: InMemoryTransaction): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=in-memory.event-lake.aggregate-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-lake.aggregate-store.d.ts","sourceRoot":"","sources":["../src/in-memory.event-lake.aggregate-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,SAAS,EACd,cAAc,EACd,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAElB,YAAY,EACZ,YAAY,EACb,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,eAAO,MAAM,mCAAmC,GAC9C,CAAC,SAAS,QAAQ,CAAC,OAAO,YAAY,CAAC,GAAG,QAAQ,CAAC,OAAO,YAAY,CAAC,aAE5D,CAAC,6BAMkB,gBAAgB,cACd,MAAM,cACtB,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GACtC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,aAC5B,SAAS;uBAJM,gBAAgB;yBACd,MAAM;wBAQP,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM;iBAS1C,4BAA4B;;;wBAMZ,SAAS;qBACZ,MAAM;2CAcQ,mBAAmB;;;;;;;;;;;CA1B5D,CAAC;AAEF,8BAAsB,+BAA+B,CACnD,CAAC,SAAS,aAAa,GAAG,aAAa,CACvC,SAAQ,aAAa,CAAC,CAAC,CAAC;aAIN,QAAQ,EAAE,gBAAgB;aAC1B,UAAU,EAAE,MAAM;aAClB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;aACpD,QAAQ,CAAC,EAAE,SAAS;aACpB,KAAK,CAAC,EAAE,MAAM;IAPhC,WAAW,EAAE,4BAA4B,CAAC;IAC1C,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEpB,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EACpD,QAAQ,CAAC,EAAE,SAAS,YAAA,EACpB,KAAK,CAAC,EAAE,MAAM,YAAA;IAYhC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,MAAM;IAExB,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,mBAAmB;CAW5D"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_in_memory_event_lake_storage_layer = require('./in-memory.event-lake.storage-layer.js');
|
|
2
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
3
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
4
|
+
|
|
5
|
+
//#region src/in-memory.event-lake.aggregate-store.ts
|
|
6
|
+
const MakeInMemoryEventLakeAggregateStore = (AGGREGATE) => {
|
|
7
|
+
class $InMemoryEventLakeAggregateStore extends InMemoryEventLakeAggregateStore {
|
|
8
|
+
constructor(database, collection, serializer, eventBus) {
|
|
9
|
+
super(database, collection, serializer, eventBus, AGGREGATE.name);
|
|
10
|
+
this.database = database;
|
|
11
|
+
this.collection = collection;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return $InMemoryEventLakeAggregateStore;
|
|
15
|
+
};
|
|
16
|
+
var InMemoryEventLakeAggregateStore = class extends _ddd_ts_store_inmemory.InMemoryStore {
|
|
17
|
+
transaction;
|
|
18
|
+
lakeStore;
|
|
19
|
+
constructor(database, collection, serializer, eventBus, $name) {
|
|
20
|
+
const storageLayer = new require_in_memory_event_lake_storage_layer.InMemoryEventLakeStorageLayer(database);
|
|
21
|
+
super(collection, database, serializer, $name);
|
|
22
|
+
this.database = database;
|
|
23
|
+
this.collection = collection;
|
|
24
|
+
this.serializer = serializer;
|
|
25
|
+
this.eventBus = eventBus;
|
|
26
|
+
this.$name = $name;
|
|
27
|
+
this.lakeStore = new _ddd_ts_core.EventLakeStore(storageLayer, serializer, eventBus);
|
|
28
|
+
this.transaction = new _ddd_ts_store_inmemory.InMemoryTransactionPerformer(database);
|
|
29
|
+
}
|
|
30
|
+
async save(aggregate, trx) {
|
|
31
|
+
const changes = aggregate.changes;
|
|
32
|
+
await this.transaction.performWith(trx, async (trx) => {
|
|
33
|
+
const lakeId = this.getLakeId(aggregate);
|
|
34
|
+
await super.save(aggregate, trx);
|
|
35
|
+
await this.lakeStore.append(lakeId, changes, trx);
|
|
36
|
+
aggregate.clearChanges();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.InMemoryEventLakeAggregateStore = InMemoryEventLakeAggregateStore;
|
|
43
|
+
exports.MakeInMemoryEventLakeAggregateStore = MakeInMemoryEventLakeAggregateStore;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { InMemoryEventLakeStorageLayer } from "./in-memory.event-lake.storage-layer.mjs";
|
|
2
|
+
import { EventLakeStore, LakeId } from "@ddd-ts/core";
|
|
3
|
+
import { InMemoryStore, InMemoryTransactionPerformer } from "@ddd-ts/store-inmemory";
|
|
4
|
+
|
|
5
|
+
//#region src/in-memory.event-lake.aggregate-store.ts
|
|
6
|
+
const MakeInMemoryEventLakeAggregateStore = (AGGREGATE) => {
|
|
7
|
+
class $InMemoryEventLakeAggregateStore extends InMemoryEventLakeAggregateStore {
|
|
8
|
+
constructor(database, collection, serializer, eventBus) {
|
|
9
|
+
super(database, collection, serializer, eventBus, AGGREGATE.name);
|
|
10
|
+
this.database = database;
|
|
11
|
+
this.collection = collection;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return $InMemoryEventLakeAggregateStore;
|
|
15
|
+
};
|
|
16
|
+
var InMemoryEventLakeAggregateStore = class extends InMemoryStore {
|
|
17
|
+
transaction;
|
|
18
|
+
lakeStore;
|
|
19
|
+
constructor(database, collection, serializer, eventBus, $name) {
|
|
20
|
+
const storageLayer = new InMemoryEventLakeStorageLayer(database);
|
|
21
|
+
super(collection, database, serializer, $name);
|
|
22
|
+
this.database = database;
|
|
23
|
+
this.collection = collection;
|
|
24
|
+
this.serializer = serializer;
|
|
25
|
+
this.eventBus = eventBus;
|
|
26
|
+
this.$name = $name;
|
|
27
|
+
this.lakeStore = new EventLakeStore(storageLayer, serializer, eventBus);
|
|
28
|
+
this.transaction = new InMemoryTransactionPerformer(database);
|
|
29
|
+
}
|
|
30
|
+
async save(aggregate, trx) {
|
|
31
|
+
const changes = aggregate.changes;
|
|
32
|
+
await this.transaction.performWith(trx, async (trx) => {
|
|
33
|
+
const lakeId = this.getLakeId(aggregate);
|
|
34
|
+
await super.save(aggregate, trx);
|
|
35
|
+
await this.lakeStore.append(lakeId, changes, trx);
|
|
36
|
+
aggregate.clearChanges();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { InMemoryEventLakeAggregateStore, MakeInMemoryEventLakeAggregateStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-lake.aggregate-store.spec.d.ts","sourceRoot":"","sources":["../src/in-memory.event-lake.aggregate-store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LakeId, type ISerializedChange, type ISerializedFact, type EventLakeStorageLayer, EventId } from "@ddd-ts/core";
|
|
2
|
+
import type { ISerializedSavedChange } from "@ddd-ts/core/dist/interfaces/es-event";
|
|
3
|
+
import { InMemoryDatabase, InMemoryTransaction } from "@ddd-ts/store-inmemory";
|
|
4
|
+
export declare class InMemoryEventLakeStorageLayer implements EventLakeStorageLayer {
|
|
5
|
+
readonly database: InMemoryDatabase;
|
|
6
|
+
constructor(database: InMemoryDatabase);
|
|
7
|
+
append(lakeId: LakeId, changes: ISerializedChange[], trx: InMemoryTransaction): Promise<ISerializedSavedChange[]>;
|
|
8
|
+
read(lakeId: LakeId, startAfter?: EventId, endAt?: EventId): AsyncIterable<ISerializedFact>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=in-memory.event-lake.storage-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-lake.storage-layer.d.ts","sourceRoot":"","sources":["../src/in-memory.event-lake.storage-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,OAAO,EACR,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,qBAAa,6BAA8B,YAAW,qBAAqB;aAC7C,QAAQ,EAAE,gBAAgB;gBAA1B,QAAQ,EAAE,gBAAgB;IAEhD,MAAM,CACV,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,EAAE,EAC5B,GAAG,EAAE,mBAAmB;IA+BnB,IAAI,CACT,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,OAAO,EACpB,KAAK,CAAC,EAAE,OAAO,GACd,aAAa,CAAC,eAAe,CAAC;CA6BlC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
2
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-lake.storage-layer.ts
|
|
5
|
+
var InMemoryEventLakeStorageLayer = class {
|
|
6
|
+
constructor(database) {
|
|
7
|
+
this.database = database;
|
|
8
|
+
}
|
|
9
|
+
async append(lakeId, changes, trx) {
|
|
10
|
+
const result = [];
|
|
11
|
+
let revision = 0;
|
|
12
|
+
for (const change of changes) {
|
|
13
|
+
const ref = `${lakeId.serialize()}/${change.id}`;
|
|
14
|
+
const stored = {
|
|
15
|
+
...change,
|
|
16
|
+
ref,
|
|
17
|
+
revision
|
|
18
|
+
};
|
|
19
|
+
this.database.save(lakeId.serialize(), change.id, stored, trx.transaction);
|
|
20
|
+
result.push({
|
|
21
|
+
...change,
|
|
22
|
+
ref,
|
|
23
|
+
revision,
|
|
24
|
+
occurredAt: void 0
|
|
25
|
+
});
|
|
26
|
+
revision++;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
async *read(lakeId, startAfter, endAt) {
|
|
31
|
+
const facts = this.database.loadAll(lakeId.serialize()).sort((a, b) => a.data.savedAt === b.data.savedAt ? a.data.data.revision - b.data.data.revision : a.data.savedAt < b.data.savedAt ? -1 : 1).map((e) => e.data);
|
|
32
|
+
let started = !startAfter;
|
|
33
|
+
for (const fact of facts) {
|
|
34
|
+
if (startAfter && fact.data.id === startAfter.serialize()) {
|
|
35
|
+
started = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (endAt && fact.data.id === endAt.serialize()) {
|
|
39
|
+
yield {
|
|
40
|
+
...fact.data,
|
|
41
|
+
occurredAt: fact.data.savedAt
|
|
42
|
+
};
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (started) yield {
|
|
46
|
+
...fact.data,
|
|
47
|
+
occurredAt: fact.data.savedAt
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.InMemoryEventLakeStorageLayer = InMemoryEventLakeStorageLayer;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EventId, LakeId } from "@ddd-ts/core";
|
|
2
|
+
import "@ddd-ts/store-inmemory";
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-lake.storage-layer.ts
|
|
5
|
+
var InMemoryEventLakeStorageLayer = class {
|
|
6
|
+
constructor(database) {
|
|
7
|
+
this.database = database;
|
|
8
|
+
}
|
|
9
|
+
async append(lakeId, changes, trx) {
|
|
10
|
+
const result = [];
|
|
11
|
+
let revision = 0;
|
|
12
|
+
for (const change of changes) {
|
|
13
|
+
const ref = `${lakeId.serialize()}/${change.id}`;
|
|
14
|
+
const stored = {
|
|
15
|
+
...change,
|
|
16
|
+
ref,
|
|
17
|
+
revision
|
|
18
|
+
};
|
|
19
|
+
this.database.save(lakeId.serialize(), change.id, stored, trx.transaction);
|
|
20
|
+
result.push({
|
|
21
|
+
...change,
|
|
22
|
+
ref,
|
|
23
|
+
revision,
|
|
24
|
+
occurredAt: void 0
|
|
25
|
+
});
|
|
26
|
+
revision++;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
async *read(lakeId, startAfter, endAt) {
|
|
31
|
+
const facts = this.database.loadAll(lakeId.serialize()).sort((a, b) => a.data.savedAt === b.data.savedAt ? a.data.data.revision - b.data.data.revision : a.data.savedAt < b.data.savedAt ? -1 : 1).map((e) => e.data);
|
|
32
|
+
let started = !startAfter;
|
|
33
|
+
for (const fact of facts) {
|
|
34
|
+
if (startAfter && fact.data.id === startAfter.serialize()) {
|
|
35
|
+
started = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (endAt && fact.data.id === endAt.serialize()) {
|
|
39
|
+
yield {
|
|
40
|
+
...fact.data,
|
|
41
|
+
occurredAt: fact.data.savedAt
|
|
42
|
+
};
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (started) yield {
|
|
46
|
+
...fact.data,
|
|
47
|
+
occurredAt: fact.data.savedAt
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { InMemoryEventLakeStorageLayer };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IEsEvent, EventLakeStore, type ISerializer } from "@ddd-ts/core";
|
|
2
|
+
import type { InMemoryDatabase } from "@ddd-ts/store-inmemory";
|
|
3
|
+
export declare class InMemoryEventLakeStore<Event extends IEsEvent> extends EventLakeStore<Event> {
|
|
4
|
+
constructor(database: InMemoryDatabase, serializer: ISerializer<Event>);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=in-memory.event-lake.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-lake.store.d.ts","sourceRoot":"","sources":["../src/in-memory.event-lake.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,qBAAa,sBAAsB,CACjC,KAAK,SAAS,QAAQ,CACtB,SAAQ,cAAc,CAAC,KAAK,CAAC;gBACjB,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC;CAGvE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_in_memory_event_lake_storage_layer = require('./in-memory.event-lake.storage-layer.js');
|
|
2
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-lake.store.ts
|
|
5
|
+
var InMemoryEventLakeStore = class extends _ddd_ts_core.EventLakeStore {
|
|
6
|
+
constructor(database, serializer) {
|
|
7
|
+
super(new require_in_memory_event_lake_storage_layer.InMemoryEventLakeStorageLayer(database), serializer);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.InMemoryEventLakeStore = InMemoryEventLakeStore;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InMemoryEventLakeStorageLayer } from "./in-memory.event-lake.storage-layer.mjs";
|
|
2
|
+
import { EventLakeStore } from "@ddd-ts/core";
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-lake.store.ts
|
|
5
|
+
var InMemoryEventLakeStore = class extends EventLakeStore {
|
|
6
|
+
constructor(database, serializer) {
|
|
7
|
+
super(new InMemoryEventLakeStorageLayer(database), serializer);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { InMemoryEventLakeStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-lake.store.spec.d.ts","sourceRoot":"","sources":["../src/in-memory.event-lake.store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HasTrait } from "@ddd-ts/traits";
|
|
2
|
+
import { StreamId, type EventsOf, EventSourced, type Identifiable, type IEventBus, EventStreamStore, EventStreamAggregateStore, type EventOf, type ISerializer, type IEventSourced, type IIdentifiable } from "@ddd-ts/core";
|
|
3
|
+
import { InMemoryDatabase } from "@ddd-ts/store-inmemory";
|
|
4
|
+
import { InMemorySnapshotter } from "./in-memory.snapshotter";
|
|
5
|
+
export declare const MakeInMemoryEventStreamAggregateStore: <A extends HasTrait<typeof EventSourced> & HasTrait<typeof Identifiable>>(AGGREGATE: A) => {
|
|
6
|
+
new (database: InMemoryDatabase, serializer: ISerializer<InstanceType<A>> & ISerializer<EventOf<InstanceType<A>>>, eventBus?: IEventBus): {
|
|
7
|
+
loadFirst(event: EventsOf<A>[number]): InstanceType<A>;
|
|
8
|
+
getStreamId(id: InstanceType<A>["id"]): StreamId;
|
|
9
|
+
readonly database: InMemoryDatabase;
|
|
10
|
+
readonly serializer: ISerializer<EventOf<InstanceType<A>>, {}>;
|
|
11
|
+
readonly snapshotter: InMemorySnapshotter<InstanceType<A>>;
|
|
12
|
+
readonly eventBus?: IEventBus | undefined;
|
|
13
|
+
readonly streamStore: EventStreamStore<EventOf<InstanceType<A>>>;
|
|
14
|
+
readonly transaction: import("@ddd-ts/core").TransactionPerformer;
|
|
15
|
+
loadFromSnapshot(snapshot: InstanceType<A>): Promise<InstanceType<A>>;
|
|
16
|
+
loadFromScratch(id: InstanceType<A>["id"]): Promise<InstanceType<A> | undefined>;
|
|
17
|
+
loadForce(id: InstanceType<A>["id"]): Promise<InstanceType<A> | undefined>;
|
|
18
|
+
load(id: InstanceType<A>["id"]): Promise<InstanceType<A> | undefined>;
|
|
19
|
+
saveAll(aggregates: InstanceType<A>[], parentTrx?: import("@ddd-ts/core").Transaction, attempts?: number): Promise<void>;
|
|
20
|
+
save(aggregate: InstanceType<A>, trx?: import("@ddd-ts/core").Transaction, attempts?: number): Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare abstract class InMemoryEventStreamAggregateStore<A extends IEventSourced & IIdentifiable> extends EventStreamAggregateStore<A> {
|
|
24
|
+
readonly database: InMemoryDatabase;
|
|
25
|
+
readonly serializer: ISerializer<EventOf<A>>;
|
|
26
|
+
readonly snapshotter: InMemorySnapshotter<A>;
|
|
27
|
+
readonly eventBus?: IEventBus | undefined;
|
|
28
|
+
constructor(database: InMemoryDatabase, serializer: ISerializer<EventOf<A>>, snapshotter: InMemorySnapshotter<A>, eventBus?: IEventBus | undefined);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=in-memory.event-stream.aggregate-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-stream.aggregate-store.d.ts","sourceRoot":"","sources":["../src/in-memory.event-stream.aggregate-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,QAAQ,EACR,KAAK,QAAQ,EACb,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,gBAAgB,EAChB,yBAAyB,EAEzB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAEjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,eAAO,MAAM,qCAAqC,GAChD,CAAC,SAAS,QAAQ,CAAC,OAAO,YAAY,CAAC,GAAG,QAAQ,CAAC,OAAO,YAAY,CAAC,aAE5D,CAAC;mBAME,gBAAgB,cACd,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GACtC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,aAC5B,SAAS;yBAUL,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;wBAItC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ;2BAUtB,gBAAgB;;;4BAGf,SAAS;;;;;;;;;;CATvC,CAAC;AAEF,8BAAsB,iCAAiC,CACrD,CAAC,SAAS,aAAa,GAAG,aAAa,CACvC,SAAQ,yBAAyB,CAAC,CAAC,CAAC;aAElB,QAAQ,EAAE,gBAAgB;aAC1B,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;aACnC,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC;aACnC,QAAQ,CAAC,EAAE,SAAS;gBAHpB,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACnC,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC,EACnC,QAAQ,CAAC,EAAE,SAAS,YAAA;CAWvC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_in_memory_event_stream_storage_layer = require('./in-memory.event-stream.storage-layer.js');
|
|
2
|
+
const require_in_memory_snapshotter = require('./in-memory.snapshotter.js');
|
|
3
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
4
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
5
|
+
|
|
6
|
+
//#region src/in-memory.event-stream.aggregate-store.ts
|
|
7
|
+
const MakeInMemoryEventStreamAggregateStore = (AGGREGATE) => {
|
|
8
|
+
return class $InMemoryEventStreamAggregateStore extends InMemoryEventStreamAggregateStore {
|
|
9
|
+
constructor(database, serializer, eventBus) {
|
|
10
|
+
const snapshotter = new require_in_memory_snapshotter.InMemorySnapshotter(AGGREGATE.name, database, serializer);
|
|
11
|
+
super(database, serializer, snapshotter, eventBus);
|
|
12
|
+
}
|
|
13
|
+
loadFirst(event) {
|
|
14
|
+
return AGGREGATE.loadFirst(event);
|
|
15
|
+
}
|
|
16
|
+
getStreamId(id) {
|
|
17
|
+
return _ddd_ts_core.StreamId.from(AGGREGATE.name, id.serialize());
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var InMemoryEventStreamAggregateStore = class extends _ddd_ts_core.EventStreamAggregateStore {
|
|
22
|
+
constructor(database, serializer, snapshotter, eventBus) {
|
|
23
|
+
const storageLayer = new require_in_memory_event_stream_storage_layer.InMemoryEventStreamStorageLayer(database);
|
|
24
|
+
const transaction = new _ddd_ts_store_inmemory.InMemoryTransactionPerformer(database);
|
|
25
|
+
const streamStore = new _ddd_ts_core.EventStreamStore(storageLayer, serializer, eventBus);
|
|
26
|
+
super(streamStore, transaction, snapshotter);
|
|
27
|
+
this.database = database;
|
|
28
|
+
this.serializer = serializer;
|
|
29
|
+
this.snapshotter = snapshotter;
|
|
30
|
+
this.eventBus = eventBus;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.InMemoryEventStreamAggregateStore = InMemoryEventStreamAggregateStore;
|
|
36
|
+
exports.MakeInMemoryEventStreamAggregateStore = MakeInMemoryEventStreamAggregateStore;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InMemoryEventStreamStorageLayer } from "./in-memory.event-stream.storage-layer.mjs";
|
|
2
|
+
import { InMemorySnapshotter } from "./in-memory.snapshotter.mjs";
|
|
3
|
+
import { EventStreamAggregateStore, EventStreamStore, StreamId } from "@ddd-ts/core";
|
|
4
|
+
import { InMemoryTransactionPerformer } from "@ddd-ts/store-inmemory";
|
|
5
|
+
|
|
6
|
+
//#region src/in-memory.event-stream.aggregate-store.ts
|
|
7
|
+
const MakeInMemoryEventStreamAggregateStore = (AGGREGATE) => {
|
|
8
|
+
return class $InMemoryEventStreamAggregateStore extends InMemoryEventStreamAggregateStore {
|
|
9
|
+
constructor(database, serializer, eventBus) {
|
|
10
|
+
const snapshotter = new InMemorySnapshotter(AGGREGATE.name, database, serializer);
|
|
11
|
+
super(database, serializer, snapshotter, eventBus);
|
|
12
|
+
}
|
|
13
|
+
loadFirst(event) {
|
|
14
|
+
return AGGREGATE.loadFirst(event);
|
|
15
|
+
}
|
|
16
|
+
getStreamId(id) {
|
|
17
|
+
return StreamId.from(AGGREGATE.name, id.serialize());
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var InMemoryEventStreamAggregateStore = class extends EventStreamAggregateStore {
|
|
22
|
+
constructor(database, serializer, snapshotter, eventBus) {
|
|
23
|
+
const storageLayer = new InMemoryEventStreamStorageLayer(database);
|
|
24
|
+
const transaction = new InMemoryTransactionPerformer(database);
|
|
25
|
+
const streamStore = new EventStreamStore(storageLayer, serializer, eventBus);
|
|
26
|
+
super(streamStore, transaction, snapshotter);
|
|
27
|
+
this.database = database;
|
|
28
|
+
this.serializer = serializer;
|
|
29
|
+
this.snapshotter = snapshotter;
|
|
30
|
+
this.eventBus = eventBus;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { InMemoryEventStreamAggregateStore, MakeInMemoryEventStreamAggregateStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-stream.aggregate-store.spec.d.ts","sourceRoot":"","sources":["../src/in-memory.event-stream.aggregate-store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StreamId, type ISerializedChange, type ISerializedFact, type EventStreamStorageLayer } from "@ddd-ts/core";
|
|
2
|
+
import type { ISerializedSavedChange } from "@ddd-ts/core/dist/interfaces/es-event";
|
|
3
|
+
import { InMemoryDatabase, InMemoryTransaction } from "@ddd-ts/store-inmemory";
|
|
4
|
+
export declare class InMemoryEventStreamStorageLayer implements EventStreamStorageLayer {
|
|
5
|
+
readonly database: InMemoryDatabase;
|
|
6
|
+
constructor(database: InMemoryDatabase);
|
|
7
|
+
isLocalRevisionOutdatedError(error: unknown): boolean;
|
|
8
|
+
append(streamId: StreamId, changes: ISerializedChange[], expectedRevision: number, trx: InMemoryTransaction): Promise<ISerializedSavedChange[]>;
|
|
9
|
+
read(streamId: StreamId, from?: number): AsyncIterable<ISerializedFact>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=in-memory.event-stream.storage-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-stream.storage-layer.d.ts","sourceRoot":"","sources":["../src/in-memory.event-stream.storage-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAE7B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,qBAAa,+BACX,YAAW,uBAAuB;aAEN,QAAQ,EAAE,gBAAgB;gBAA1B,QAAQ,EAAE,gBAAgB;IAEtD,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/C,MAAM,CACV,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,iBAAiB,EAAE,EAC5B,gBAAgB,EAAE,MAAM,EACxB,GAAG,EAAE,mBAAmB;IAkCnB,IAAI,CACT,QAAQ,EAAE,QAAQ,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,aAAa,CAAC,eAAe,CAAC;CAclC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
2
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-stream.storage-layer.ts
|
|
5
|
+
var InMemoryEventStreamStorageLayer = class {
|
|
6
|
+
constructor(database) {
|
|
7
|
+
this.database = database;
|
|
8
|
+
}
|
|
9
|
+
isLocalRevisionOutdatedError(error) {
|
|
10
|
+
return error instanceof _ddd_ts_core.ConcurrencyError;
|
|
11
|
+
}
|
|
12
|
+
async append(streamId, changes, expectedRevision, trx) {
|
|
13
|
+
const result = [];
|
|
14
|
+
let revision = expectedRevision + 1;
|
|
15
|
+
for (const change of changes) {
|
|
16
|
+
const ref = `${streamId.serialize()}/${revision}`;
|
|
17
|
+
const stored = {
|
|
18
|
+
...change,
|
|
19
|
+
ref,
|
|
20
|
+
revision
|
|
21
|
+
};
|
|
22
|
+
this.database.create(streamId.serialize(), `${revision}`, stored, trx.transaction);
|
|
23
|
+
result.push({
|
|
24
|
+
...change,
|
|
25
|
+
ref,
|
|
26
|
+
revision,
|
|
27
|
+
occurredAt: void 0
|
|
28
|
+
});
|
|
29
|
+
revision++;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async *read(streamId, from) {
|
|
34
|
+
yield* this.database.loadAll(streamId.serialize()).sort((a, b) => a.data.data.revision - b.data.data.revision).map((e) => ({
|
|
35
|
+
...e.data.data,
|
|
36
|
+
occurredAt: e.data.savedAt
|
|
37
|
+
})).slice(from !== void 0 ? from : 0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.InMemoryEventStreamStorageLayer = InMemoryEventStreamStorageLayer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ConcurrencyError, StreamId } from "@ddd-ts/core";
|
|
2
|
+
import "@ddd-ts/store-inmemory";
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-stream.storage-layer.ts
|
|
5
|
+
var InMemoryEventStreamStorageLayer = class {
|
|
6
|
+
constructor(database) {
|
|
7
|
+
this.database = database;
|
|
8
|
+
}
|
|
9
|
+
isLocalRevisionOutdatedError(error) {
|
|
10
|
+
return error instanceof ConcurrencyError;
|
|
11
|
+
}
|
|
12
|
+
async append(streamId, changes, expectedRevision, trx) {
|
|
13
|
+
const result = [];
|
|
14
|
+
let revision = expectedRevision + 1;
|
|
15
|
+
for (const change of changes) {
|
|
16
|
+
const ref = `${streamId.serialize()}/${revision}`;
|
|
17
|
+
const stored = {
|
|
18
|
+
...change,
|
|
19
|
+
ref,
|
|
20
|
+
revision
|
|
21
|
+
};
|
|
22
|
+
this.database.create(streamId.serialize(), `${revision}`, stored, trx.transaction);
|
|
23
|
+
result.push({
|
|
24
|
+
...change,
|
|
25
|
+
ref,
|
|
26
|
+
revision,
|
|
27
|
+
occurredAt: void 0
|
|
28
|
+
});
|
|
29
|
+
revision++;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async *read(streamId, from) {
|
|
34
|
+
yield* this.database.loadAll(streamId.serialize()).sort((a, b) => a.data.data.revision - b.data.data.revision).map((e) => ({
|
|
35
|
+
...e.data.data,
|
|
36
|
+
occurredAt: e.data.savedAt
|
|
37
|
+
})).slice(from !== void 0 ? from : 0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { InMemoryEventStreamStorageLayer };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EventStreamStore, type IEsEvent, type ISerializer } from "@ddd-ts/core";
|
|
2
|
+
import type { InMemoryDatabase } from "@ddd-ts/store-inmemory";
|
|
3
|
+
export declare class InMemoryEventStreamStore<Event extends IEsEvent> extends EventStreamStore<Event> {
|
|
4
|
+
constructor(database: InMemoryDatabase, serializer: ISerializer<Event>);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=in-memory.event-stream.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-stream.store.d.ts","sourceRoot":"","sources":["../src/in-memory.event-stream.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,QAAQ,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,qBAAa,wBAAwB,CACnC,KAAK,SAAS,QAAQ,CACtB,SAAQ,gBAAgB,CAAC,KAAK,CAAC;gBACnB,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC;CAGvE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_in_memory_event_stream_storage_layer = require('./in-memory.event-stream.storage-layer.js');
|
|
2
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-stream.store.ts
|
|
5
|
+
var InMemoryEventStreamStore = class extends _ddd_ts_core.EventStreamStore {
|
|
6
|
+
constructor(database, serializer) {
|
|
7
|
+
super(new require_in_memory_event_stream_storage_layer.InMemoryEventStreamStorageLayer(database), serializer);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.InMemoryEventStreamStore = InMemoryEventStreamStore;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InMemoryEventStreamStorageLayer } from "./in-memory.event-stream.storage-layer.mjs";
|
|
2
|
+
import { EventStreamStore } from "@ddd-ts/core";
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.event-stream.store.ts
|
|
5
|
+
var InMemoryEventStreamStore = class extends EventStreamStore {
|
|
6
|
+
constructor(database, serializer) {
|
|
7
|
+
super(new InMemoryEventStreamStorageLayer(database), serializer);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { InMemoryEventStreamStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.event-stream.store.spec.d.ts","sourceRoot":"","sources":["../src/in-memory.event-stream.store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IEsEvent, type ISerializer, ProjectedStreamReader } from "@ddd-ts/core";
|
|
2
|
+
import { InMemoryDatabase } from "@ddd-ts/store-inmemory";
|
|
3
|
+
export declare class InMemoryProjectedStreamReader<Events extends IEsEvent> extends ProjectedStreamReader<Events> {
|
|
4
|
+
constructor(database: InMemoryDatabase, serializer: ISerializer<Events>);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=in-memory.projected-stream.reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.projected-stream.reader.d.ts","sourceRoot":"","sources":["../src/in-memory.projected-stream.reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,qBAAa,6BAA6B,CACxC,MAAM,SAAS,QAAQ,CACvB,SAAQ,qBAAqB,CAAC,MAAM,CAAC;gBACzB,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC;CAGxE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const require_in_memory_projected_stream_storage_layer = require('./in-memory.projected-stream.storage-layer.js');
|
|
2
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
3
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
4
|
+
|
|
5
|
+
//#region src/in-memory.projected-stream.reader.ts
|
|
6
|
+
var InMemoryProjectedStreamReader = class extends _ddd_ts_core.ProjectedStreamReader {
|
|
7
|
+
constructor(database, serializer) {
|
|
8
|
+
super(new require_in_memory_projected_stream_storage_layer.InMemoryProjectedStreamStorageLayer(database), serializer);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.InMemoryProjectedStreamReader = InMemoryProjectedStreamReader;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InMemoryProjectedStreamStorageLayer } from "./in-memory.projected-stream.storage-layer.mjs";
|
|
2
|
+
import { ProjectedStreamReader } from "@ddd-ts/core";
|
|
3
|
+
import "@ddd-ts/store-inmemory";
|
|
4
|
+
|
|
5
|
+
//#region src/in-memory.projected-stream.reader.ts
|
|
6
|
+
var InMemoryProjectedStreamReader = class extends ProjectedStreamReader {
|
|
7
|
+
constructor(database, serializer) {
|
|
8
|
+
super(new InMemoryProjectedStreamStorageLayer(database), serializer);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { InMemoryProjectedStreamReader };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.projected-stream.reader.spec.d.ts","sourceRoot":"","sources":["../src/in-memory.projected-stream.reader.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ISerializedFact, LakeSource, ProjectedStream, type ProjectedStreamStorageLayer, StreamSource, Cursor, type ISerializedSavedChange } from "@ddd-ts/core";
|
|
2
|
+
import { InMemoryDatabase } from "@ddd-ts/store-inmemory";
|
|
3
|
+
export declare class InMemoryStreamSourceFilter {
|
|
4
|
+
private readonly database;
|
|
5
|
+
constructor(database: InMemoryDatabase);
|
|
6
|
+
all(source: StreamSource, shard: string): Generator<{
|
|
7
|
+
savedAt: bigint;
|
|
8
|
+
data: any;
|
|
9
|
+
}, void, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export declare class InMemoryLakeSourceFilter {
|
|
12
|
+
private readonly database;
|
|
13
|
+
constructor(database: InMemoryDatabase);
|
|
14
|
+
all(source: LakeSource, shard: string): Generator<{
|
|
15
|
+
savedAt: bigint;
|
|
16
|
+
data: any;
|
|
17
|
+
}, void, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export declare class InMemoryProjectedStreamStorageLayer implements ProjectedStreamStorageLayer {
|
|
20
|
+
private readonly database;
|
|
21
|
+
constructor(database: InMemoryDatabase);
|
|
22
|
+
getCursor(savedChange: ISerializedSavedChange): Promise<Cursor | undefined>;
|
|
23
|
+
get(cursor: Cursor): Promise<ISerializedFact | undefined>;
|
|
24
|
+
read(projectedStream: ProjectedStream, shard: string, startAfter?: Cursor, endAt?: Cursor): AsyncGenerator<any, void, unknown>;
|
|
25
|
+
slice(projectedStream: ProjectedStream, shard: string, startAfter?: Cursor, endAt?: Cursor, count?: number): Promise<ISerializedFact[]>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=in-memory.projected-stream.storage-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.projected-stream.storage-layer.d.ts","sourceRoot":"","sources":["../src/in-memory.projected-stream.storage-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAEpB,UAAU,EACV,eAAe,EACf,KAAK,2BAA2B,EAChC,YAAY,EACZ,MAAM,EACN,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,qBAAa,0BAA0B;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,gBAAgB;IAEtD,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM;;;;CAezC;AAED,qBAAa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,gBAAgB;IAEtD,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM;;;;CAYvC;AAED,qBAAa,mCACX,YAAW,2BAA2B;IAE1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,gBAAgB;IAEjD,SAAS,CACb,WAAW,EAAE,sBAAsB,GAClC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAexB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAUxD,IAAI,CACT,eAAe,EAAE,eAAe,EAChC,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM;IAmCV,KAAK,CACT,eAAe,EAAE,eAAe,EAChC,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,eAAe,EAAE,CAAC;CAa9B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
2
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
3
|
+
let _ddd_ts_shape = require("@ddd-ts/shape");
|
|
4
|
+
|
|
5
|
+
//#region src/in-memory.projected-stream.storage-layer.ts
|
|
6
|
+
var InMemoryStreamSourceFilter = class {
|
|
7
|
+
constructor(database) {
|
|
8
|
+
this.database = database;
|
|
9
|
+
}
|
|
10
|
+
*all(source, shard) {
|
|
11
|
+
const streams = [...this.database.storage.collections.keys()].filter((it) => it.startsWith(source.aggregateType));
|
|
12
|
+
for (const stream of streams) yield* this.database.loadAll(stream).filter((event) => {
|
|
13
|
+
if (!source.events.includes(event.data.data.name)) return false;
|
|
14
|
+
const payload = event.data.data.payload;
|
|
15
|
+
if (!payload) return false;
|
|
16
|
+
return payload[source.shardKey] === shard;
|
|
17
|
+
}).map((event) => event.data);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var InMemoryLakeSourceFilter = class {
|
|
21
|
+
constructor(database) {
|
|
22
|
+
this.database = database;
|
|
23
|
+
}
|
|
24
|
+
*all(source, shard) {
|
|
25
|
+
const lakeId = _ddd_ts_core.LakeId.from(source.shardType, shard);
|
|
26
|
+
yield* this.database.loadAll(lakeId.serialize()).filter((event) => {
|
|
27
|
+
if (!source.events.includes(event.data.data.name)) return false;
|
|
28
|
+
const payload = event.data.data.payload;
|
|
29
|
+
if (!payload) return false;
|
|
30
|
+
return payload[source.shardKey] === shard;
|
|
31
|
+
}).map((event) => event.data);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var InMemoryProjectedStreamStorageLayer = class {
|
|
35
|
+
constructor(database) {
|
|
36
|
+
this.database = database;
|
|
37
|
+
}
|
|
38
|
+
async getCursor(savedChange) {
|
|
39
|
+
const [collection, id] = savedChange.ref.split("/");
|
|
40
|
+
if (!collection || !id) return void 0;
|
|
41
|
+
const raw = this.database.storage.getCollection(collection).getRaw(id);
|
|
42
|
+
if (!raw) return void 0;
|
|
43
|
+
return new _ddd_ts_core.Cursor({
|
|
44
|
+
ref: savedChange.ref,
|
|
45
|
+
eventId: new _ddd_ts_core.EventId(savedChange.id),
|
|
46
|
+
occurredAt: _ddd_ts_shape.MicrosecondTimestamp.fromMicroseconds(raw.savedAt),
|
|
47
|
+
revision: savedChange.revision
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async get(cursor) {
|
|
51
|
+
const [collection, id] = cursor.ref.split("/");
|
|
52
|
+
if (!collection || !id) return void 0;
|
|
53
|
+
const raw = this.database.storage.getCollection(collection).getRaw(id);
|
|
54
|
+
if (!raw) return void 0;
|
|
55
|
+
return {
|
|
56
|
+
...raw.data,
|
|
57
|
+
occurredAt: raw.savedAt
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async *read(projectedStream, shard, startAfter, endAt) {
|
|
61
|
+
const all = projectedStream.sources.map((source) => {
|
|
62
|
+
if (source instanceof _ddd_ts_core.StreamSource) return new InMemoryStreamSourceFilter(this.database).all(source, shard);
|
|
63
|
+
return new InMemoryLakeSourceFilter(this.database).all(source, shard);
|
|
64
|
+
}).flatMap((source) => [...source]).sort((a, b) => a.savedAt === b.savedAt ? a.data.revision - b.data.revision : a.savedAt > b.savedAt ? 1 : -1);
|
|
65
|
+
let started = !startAfter?.ref;
|
|
66
|
+
for (const fact of all) {
|
|
67
|
+
if (startAfter && fact.data.ref === startAfter.ref) {
|
|
68
|
+
started = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (endAt?.ref && fact.data.ref === endAt.ref) {
|
|
72
|
+
yield {
|
|
73
|
+
...fact.data,
|
|
74
|
+
occurredAt: fact.savedAt
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (started) yield {
|
|
79
|
+
...fact.data,
|
|
80
|
+
occurredAt: fact.savedAt
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async slice(projectedStream, shard, startAfter, endAt, count) {
|
|
85
|
+
const stream = this.read(projectedStream, shard, startAfter, endAt);
|
|
86
|
+
const result = [];
|
|
87
|
+
let limit = count ?? Number.POSITIVE_INFINITY;
|
|
88
|
+
for await (const fact of stream) {
|
|
89
|
+
if (!limit--) break;
|
|
90
|
+
result.push(fact);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
exports.InMemoryLakeSourceFilter = InMemoryLakeSourceFilter;
|
|
98
|
+
exports.InMemoryProjectedStreamStorageLayer = InMemoryProjectedStreamStorageLayer;
|
|
99
|
+
exports.InMemoryStreamSourceFilter = InMemoryStreamSourceFilter;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Cursor, EventId, LakeId, StreamSource } from "@ddd-ts/core";
|
|
2
|
+
import "@ddd-ts/store-inmemory";
|
|
3
|
+
import { MicrosecondTimestamp } from "@ddd-ts/shape";
|
|
4
|
+
|
|
5
|
+
//#region src/in-memory.projected-stream.storage-layer.ts
|
|
6
|
+
var InMemoryStreamSourceFilter = class {
|
|
7
|
+
constructor(database) {
|
|
8
|
+
this.database = database;
|
|
9
|
+
}
|
|
10
|
+
*all(source, shard) {
|
|
11
|
+
const streams = [...this.database.storage.collections.keys()].filter((it) => it.startsWith(source.aggregateType));
|
|
12
|
+
for (const stream of streams) yield* this.database.loadAll(stream).filter((event) => {
|
|
13
|
+
if (!source.events.includes(event.data.data.name)) return false;
|
|
14
|
+
const payload = event.data.data.payload;
|
|
15
|
+
if (!payload) return false;
|
|
16
|
+
return payload[source.shardKey] === shard;
|
|
17
|
+
}).map((event) => event.data);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var InMemoryLakeSourceFilter = class {
|
|
21
|
+
constructor(database) {
|
|
22
|
+
this.database = database;
|
|
23
|
+
}
|
|
24
|
+
*all(source, shard) {
|
|
25
|
+
const lakeId = LakeId.from(source.shardType, shard);
|
|
26
|
+
yield* this.database.loadAll(lakeId.serialize()).filter((event) => {
|
|
27
|
+
if (!source.events.includes(event.data.data.name)) return false;
|
|
28
|
+
const payload = event.data.data.payload;
|
|
29
|
+
if (!payload) return false;
|
|
30
|
+
return payload[source.shardKey] === shard;
|
|
31
|
+
}).map((event) => event.data);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var InMemoryProjectedStreamStorageLayer = class {
|
|
35
|
+
constructor(database) {
|
|
36
|
+
this.database = database;
|
|
37
|
+
}
|
|
38
|
+
async getCursor(savedChange) {
|
|
39
|
+
const [collection, id] = savedChange.ref.split("/");
|
|
40
|
+
if (!collection || !id) return void 0;
|
|
41
|
+
const raw = this.database.storage.getCollection(collection).getRaw(id);
|
|
42
|
+
if (!raw) return void 0;
|
|
43
|
+
return new Cursor({
|
|
44
|
+
ref: savedChange.ref,
|
|
45
|
+
eventId: new EventId(savedChange.id),
|
|
46
|
+
occurredAt: MicrosecondTimestamp.fromMicroseconds(raw.savedAt),
|
|
47
|
+
revision: savedChange.revision
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async get(cursor) {
|
|
51
|
+
const [collection, id] = cursor.ref.split("/");
|
|
52
|
+
if (!collection || !id) return void 0;
|
|
53
|
+
const raw = this.database.storage.getCollection(collection).getRaw(id);
|
|
54
|
+
if (!raw) return void 0;
|
|
55
|
+
return {
|
|
56
|
+
...raw.data,
|
|
57
|
+
occurredAt: raw.savedAt
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async *read(projectedStream, shard, startAfter, endAt) {
|
|
61
|
+
const all = projectedStream.sources.map((source) => {
|
|
62
|
+
if (source instanceof StreamSource) return new InMemoryStreamSourceFilter(this.database).all(source, shard);
|
|
63
|
+
return new InMemoryLakeSourceFilter(this.database).all(source, shard);
|
|
64
|
+
}).flatMap((source) => [...source]).sort((a, b) => a.savedAt === b.savedAt ? a.data.revision - b.data.revision : a.savedAt > b.savedAt ? 1 : -1);
|
|
65
|
+
let started = !startAfter?.ref;
|
|
66
|
+
for (const fact of all) {
|
|
67
|
+
if (startAfter && fact.data.ref === startAfter.ref) {
|
|
68
|
+
started = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (endAt?.ref && fact.data.ref === endAt.ref) {
|
|
72
|
+
yield {
|
|
73
|
+
...fact.data,
|
|
74
|
+
occurredAt: fact.savedAt
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (started) yield {
|
|
79
|
+
...fact.data,
|
|
80
|
+
occurredAt: fact.savedAt
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async slice(projectedStream, shard, startAfter, endAt, count) {
|
|
85
|
+
const stream = this.read(projectedStream, shard, startAfter, endAt);
|
|
86
|
+
const result = [];
|
|
87
|
+
let limit = count ?? Number.POSITIVE_INFINITY;
|
|
88
|
+
for await (const fact of stream) {
|
|
89
|
+
if (!limit--) break;
|
|
90
|
+
result.push(fact);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { InMemoryLakeSourceFilter, InMemoryProjectedStreamStorageLayer, InMemoryStreamSourceFilter };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IEsAggregateStore, type IEventSourced, type IIdentifiable, type ISerializer } from "@ddd-ts/core";
|
|
2
|
+
import { InMemoryDatabase, InMemoryStore } from "@ddd-ts/store-inmemory";
|
|
3
|
+
export declare class InMemorySnapshotter<A extends IEventSourced & IIdentifiable> extends InMemoryStore<A> implements IEsAggregateStore<A> {
|
|
4
|
+
constructor(aggregate: string, db: InMemoryDatabase, serializer: ISerializer<A>);
|
|
5
|
+
}
|
|
6
|
+
//# 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,EACL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAqBzE,qBAAa,mBAAmB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,CACtE,SAAQ,aAAa,CAAC,CAAC,CACvB,YAAW,iBAAiB,CAAC,CAAC,CAAC;gBAG7B,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,gBAAgB,EACpB,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;CAI7B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
let _ddd_ts_core = require("@ddd-ts/core");
|
|
2
|
+
let _ddd_ts_store_inmemory = require("@ddd-ts/store-inmemory");
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.snapshotter.ts
|
|
5
|
+
var SnapshotSerializer = class {
|
|
6
|
+
constructor(serializer) {
|
|
7
|
+
this.serializer = serializer;
|
|
8
|
+
}
|
|
9
|
+
async serialize(instance) {
|
|
10
|
+
return {
|
|
11
|
+
...await this.serializer.serialize(instance),
|
|
12
|
+
revision: instance.acknowledgedRevision
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async deserialize(serialized) {
|
|
16
|
+
const { revision, ...content } = serialized;
|
|
17
|
+
const instance = await this.serializer.deserialize(content);
|
|
18
|
+
instance.acknowledgedRevision = Number(revision);
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var InMemorySnapshotter = class extends _ddd_ts_store_inmemory.InMemoryStore {
|
|
23
|
+
constructor(aggregate, db, serializer) {
|
|
24
|
+
super(`snapshots-${aggregate}`, db, new SnapshotSerializer(serializer));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.InMemorySnapshotter = InMemorySnapshotter;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "@ddd-ts/core";
|
|
2
|
+
import { InMemoryStore } from "@ddd-ts/store-inmemory";
|
|
3
|
+
|
|
4
|
+
//#region src/in-memory.snapshotter.ts
|
|
5
|
+
var SnapshotSerializer = class {
|
|
6
|
+
constructor(serializer) {
|
|
7
|
+
this.serializer = serializer;
|
|
8
|
+
}
|
|
9
|
+
async serialize(instance) {
|
|
10
|
+
return {
|
|
11
|
+
...await this.serializer.serialize(instance),
|
|
12
|
+
revision: instance.acknowledgedRevision
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async deserialize(serialized) {
|
|
16
|
+
const { revision, ...content } = serialized;
|
|
17
|
+
const instance = await this.serializer.deserialize(content);
|
|
18
|
+
instance.acknowledgedRevision = Number(revision);
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var InMemorySnapshotter = class extends InMemoryStore {
|
|
23
|
+
constructor(aggregate, db, serializer) {
|
|
24
|
+
super(`snapshots-${aggregate}`, db, new SnapshotSerializer(serializer));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { InMemorySnapshotter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { InMemoryEventLakeStorageLayer } from "./in-memory.event-lake.storage-layer";
|
|
2
|
+
export { InMemoryEventLakeStore } from "./in-memory.event-lake.store";
|
|
3
|
+
export { InMemoryEventStreamStorageLayer } from "./in-memory.event-stream.storage-layer";
|
|
4
|
+
export { InMemoryEventStreamStore } from "./in-memory.event-stream.store";
|
|
5
|
+
export { InMemoryEventStreamAggregateStore, MakeInMemoryEventStreamAggregateStore, } from "./in-memory.event-stream.aggregate-store";
|
|
6
|
+
export { InMemoryEventLakeAggregateStore, MakeInMemoryEventLakeAggregateStore, } from "./in-memory.event-lake.aggregate-store";
|
|
7
|
+
export { InMemoryProjectedStreamStorageLayer, InMemoryLakeSourceFilter, InMemoryStreamSourceFilter, } from "./in-memory.projected-stream.storage-layer";
|
|
8
|
+
export { InMemoryProjectedStreamReader } from "./in-memory.projected-stream.reader";
|
|
9
|
+
export { InMemorySnapshotter } from "./in-memory.snapshotter";
|
|
10
|
+
//# 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,6BAA6B,EAAE,MAAM,sCAAsC,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,OAAO,EACL,iCAAiC,EACjC,qCAAqC,GACtC,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACL,+BAA+B,EAC/B,mCAAmC,GACpC,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACL,mCAAmC,EACnC,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAEpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_in_memory_event_lake_storage_layer = require('./in-memory.event-lake.storage-layer.js');
|
|
3
|
+
const require_in_memory_event_lake_store = require('./in-memory.event-lake.store.js');
|
|
4
|
+
const require_in_memory_event_stream_storage_layer = require('./in-memory.event-stream.storage-layer.js');
|
|
5
|
+
const require_in_memory_event_stream_store = require('./in-memory.event-stream.store.js');
|
|
6
|
+
const require_in_memory_snapshotter = require('./in-memory.snapshotter.js');
|
|
7
|
+
const require_in_memory_event_stream_aggregate_store = require('./in-memory.event-stream.aggregate-store.js');
|
|
8
|
+
const require_in_memory_event_lake_aggregate_store = require('./in-memory.event-lake.aggregate-store.js');
|
|
9
|
+
const require_in_memory_projected_stream_storage_layer = require('./in-memory.projected-stream.storage-layer.js');
|
|
10
|
+
const require_in_memory_projected_stream_reader = require('./in-memory.projected-stream.reader.js');
|
|
11
|
+
|
|
12
|
+
exports.InMemoryEventLakeAggregateStore = require_in_memory_event_lake_aggregate_store.InMemoryEventLakeAggregateStore;
|
|
13
|
+
exports.InMemoryEventLakeStorageLayer = require_in_memory_event_lake_storage_layer.InMemoryEventLakeStorageLayer;
|
|
14
|
+
exports.InMemoryEventLakeStore = require_in_memory_event_lake_store.InMemoryEventLakeStore;
|
|
15
|
+
exports.InMemoryEventStreamAggregateStore = require_in_memory_event_stream_aggregate_store.InMemoryEventStreamAggregateStore;
|
|
16
|
+
exports.InMemoryEventStreamStorageLayer = require_in_memory_event_stream_storage_layer.InMemoryEventStreamStorageLayer;
|
|
17
|
+
exports.InMemoryEventStreamStore = require_in_memory_event_stream_store.InMemoryEventStreamStore;
|
|
18
|
+
exports.InMemoryLakeSourceFilter = require_in_memory_projected_stream_storage_layer.InMemoryLakeSourceFilter;
|
|
19
|
+
exports.InMemoryProjectedStreamReader = require_in_memory_projected_stream_reader.InMemoryProjectedStreamReader;
|
|
20
|
+
exports.InMemoryProjectedStreamStorageLayer = require_in_memory_projected_stream_storage_layer.InMemoryProjectedStreamStorageLayer;
|
|
21
|
+
exports.InMemorySnapshotter = require_in_memory_snapshotter.InMemorySnapshotter;
|
|
22
|
+
exports.InMemoryStreamSourceFilter = require_in_memory_projected_stream_storage_layer.InMemoryStreamSourceFilter;
|
|
23
|
+
exports.MakeInMemoryEventLakeAggregateStore = require_in_memory_event_lake_aggregate_store.MakeInMemoryEventLakeAggregateStore;
|
|
24
|
+
exports.MakeInMemoryEventStreamAggregateStore = require_in_memory_event_stream_aggregate_store.MakeInMemoryEventStreamAggregateStore;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InMemoryEventLakeStorageLayer } from "./in-memory.event-lake.storage-layer.mjs";
|
|
2
|
+
import { InMemoryEventLakeStore } from "./in-memory.event-lake.store.mjs";
|
|
3
|
+
import { InMemoryEventStreamStorageLayer } from "./in-memory.event-stream.storage-layer.mjs";
|
|
4
|
+
import { InMemoryEventStreamStore } from "./in-memory.event-stream.store.mjs";
|
|
5
|
+
import { InMemorySnapshotter } from "./in-memory.snapshotter.mjs";
|
|
6
|
+
import { InMemoryEventStreamAggregateStore, MakeInMemoryEventStreamAggregateStore } from "./in-memory.event-stream.aggregate-store.mjs";
|
|
7
|
+
import { InMemoryEventLakeAggregateStore, MakeInMemoryEventLakeAggregateStore } from "./in-memory.event-lake.aggregate-store.mjs";
|
|
8
|
+
import { InMemoryLakeSourceFilter, InMemoryProjectedStreamStorageLayer, InMemoryStreamSourceFilter } from "./in-memory.projected-stream.storage-layer.mjs";
|
|
9
|
+
import { InMemoryProjectedStreamReader } from "./in-memory.projected-stream.reader.mjs";
|
|
10
|
+
|
|
11
|
+
export { InMemoryEventLakeAggregateStore, InMemoryEventLakeStorageLayer, InMemoryEventLakeStore, InMemoryEventStreamAggregateStore, InMemoryEventStreamStorageLayer, InMemoryEventStreamStore, InMemoryLakeSourceFilter, InMemoryProjectedStreamReader, InMemoryProjectedStreamStorageLayer, InMemorySnapshotter, InMemoryStreamSourceFilter, MakeInMemoryEventLakeAggregateStore, MakeInMemoryEventStreamAggregateStore };
|
package/package.json
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts/event-sourcing-inmemory",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "git+https://github.com/ddd-ts/monorepo"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
13
12
|
"dependencies": {
|
|
14
|
-
"@ddd-ts/core": "0.0.
|
|
15
|
-
"@ddd-ts/shape": "0.0.
|
|
16
|
-
"@ddd-ts/store-inmemory": "0.0.
|
|
17
|
-
"@ddd-ts/types": "0.0.
|
|
13
|
+
"@ddd-ts/core": "0.0.39",
|
|
14
|
+
"@ddd-ts/shape": "0.0.39",
|
|
15
|
+
"@ddd-ts/store-inmemory": "0.0.39",
|
|
16
|
+
"@ddd-ts/types": "0.0.39"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
|
-
"@ddd-ts/shape": "0.0.
|
|
21
|
-
"@ddd-ts/tests": "0.0.
|
|
22
|
-
"@ddd-ts/tools": "0.0.
|
|
23
|
-
"@ddd-ts/traits": "0.0.
|
|
19
|
+
"@ddd-ts/shape": "0.0.39",
|
|
20
|
+
"@ddd-ts/tests": "0.0.39",
|
|
21
|
+
"@ddd-ts/tools": "0.0.39",
|
|
22
|
+
"@ddd-ts/traits": "0.0.39",
|
|
24
23
|
"@types/jest": "^29.5.1",
|
|
25
24
|
"@types/node": "^20.12.4"
|
|
26
25
|
},
|
|
27
26
|
"exports": {
|
|
28
|
-
".":
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./dist/index.mjs",
|
|
29
|
+
"require": "./dist/index.js"
|
|
30
|
+
},
|
|
29
31
|
"./package.json": "./package.json"
|
|
30
32
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"module": "./dist/index.mjs",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "jest --config node_modules/@ddd-ts/tools/jest.config.js",
|
|
37
|
+
"build": "tsdown --config node_modules/@ddd-ts/tools/tsdown.config.js"
|
|
36
38
|
}
|
|
37
|
-
}
|
|
39
|
+
}
|