@ddd-ts/event-sourcing-firestore 0.0.0-alpha2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/firestore.checkpoint.d.ts +11 -0
- package/dist/firestore.checkpoint.d.ts.map +1 -0
- package/dist/firestore.checkpoint.js +49 -0
- package/dist/firestore.checkpoint.js.map +1 -0
- package/dist/firestore.event-store.d.ts +30 -0
- package/dist/firestore.event-store.d.ts.map +1 -0
- package/dist/firestore.event-store.js +143 -0
- package/dist/firestore.event-store.js.map +1 -0
- package/dist/firestore.event-store.spec.d.ts +2 -0
- package/dist/firestore.event-store.spec.d.ts.map +1 -0
- package/dist/firestore.event-store.spec.js +35 -0
- package/dist/firestore.event-store.spec.js.map +1 -0
- package/dist/firestore.snapshotter.d.ts +12 -0
- package/dist/firestore.snapshotter.d.ts.map +1 -0
- package/dist/firestore.snapshotter.js +51 -0
- package/dist/firestore.snapshotter.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/test/bank.spec.d.ts +2 -0
- package/dist/test/bank.spec.d.ts.map +1 -0
- package/dist/test/bank.spec.js +50 -0
- package/dist/test/bank.spec.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as fb from "firebase-admin";
|
|
2
|
+
import { Checkpoint } from "@ddd-ts/event-sourcing";
|
|
3
|
+
import { FirestoreTransaction } from "@ddd-ts/store-firestore";
|
|
4
|
+
export declare class FirestoreCheckpoint extends Checkpoint {
|
|
5
|
+
readonly firestore: fb.firestore.Firestore;
|
|
6
|
+
constructor(firestore: fb.firestore.Firestore);
|
|
7
|
+
clear(): Promise<void>;
|
|
8
|
+
get(name: string): Promise<bigint>;
|
|
9
|
+
set(name: string, revision: bigint, trx?: FirestoreTransaction): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=firestore.checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.checkpoint.d.ts","sourceRoot":"","sources":["../src/firestore.checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,UAAU,EAAyB,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,qBAAa,mBAAoB,SAAQ,UAAU;aACrB,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS;gBAAjC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS;IAIvD,KAAK;IAUL,GAAG,CAAC,IAAI,EAAE,MAAM;IAYhB,GAAG,CACP,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,oBAAoB;CAuB7B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreCheckpoint = void 0;
|
|
4
|
+
const event_sourcing_1 = require("@ddd-ts/event-sourcing");
|
|
5
|
+
class FirestoreCheckpoint extends event_sourcing_1.Checkpoint {
|
|
6
|
+
firestore;
|
|
7
|
+
constructor(firestore) {
|
|
8
|
+
super();
|
|
9
|
+
this.firestore = firestore;
|
|
10
|
+
}
|
|
11
|
+
async clear() {
|
|
12
|
+
const bw = this.firestore.bulkWriter();
|
|
13
|
+
await this.firestore.recursiveDelete(this.firestore.collection("checkpoints"), bw);
|
|
14
|
+
await bw.flush();
|
|
15
|
+
await bw.close();
|
|
16
|
+
}
|
|
17
|
+
async get(name) {
|
|
18
|
+
const checkpoint = await this.firestore
|
|
19
|
+
.collection("checkpoints")
|
|
20
|
+
.doc(name)
|
|
21
|
+
.get();
|
|
22
|
+
if (!checkpoint.exists) {
|
|
23
|
+
return -1n;
|
|
24
|
+
}
|
|
25
|
+
return BigInt(checkpoint.data()?.revision);
|
|
26
|
+
}
|
|
27
|
+
async set(name, revision, trx) {
|
|
28
|
+
const checkpointRef = await this.firestore
|
|
29
|
+
.collection("checkpoints")
|
|
30
|
+
.doc(name);
|
|
31
|
+
const checkpoint = await checkpointRef.get();
|
|
32
|
+
if (checkpoint.exists) {
|
|
33
|
+
const currentRevision = BigInt(checkpoint.data()?.revision);
|
|
34
|
+
if (currentRevision > revision) {
|
|
35
|
+
throw new event_sourcing_1.CheckpointFurtherAway(name, revision, currentRevision);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (trx) {
|
|
39
|
+
trx.transaction.set(this.firestore.collection("checkpoints").doc(name), {
|
|
40
|
+
revision: Number(revision),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
await checkpointRef.set({ revision: Number(revision) });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.FirestoreCheckpoint = FirestoreCheckpoint;
|
|
49
|
+
//# sourceMappingURL=firestore.checkpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.checkpoint.js","sourceRoot":"","sources":["../src/firestore.checkpoint.ts"],"names":[],"mappings":";;;AACA,2DAA2E;AAG3E,MAAa,mBAAoB,SAAQ,2BAAU;IACrB;IAA5B,YAA4B,SAAiC;QAC3D,KAAK,EAAE,CAAC;QADkB,cAAS,GAAT,SAAS,CAAwB;IAE7D,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAClC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,aAAa,CAAC,EACxC,EAAE,CACH,CAAC;QACF,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;IACnB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DAqDC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EsAggregate, Event, Competitor, EsChange, EsFact, EventStore, Follower, ProjectedStreamConfiguration } from "@ddd-ts/event-sourcing";
|
|
2
|
+
import { Constructor } from "@ddd-ts/types";
|
|
3
|
+
import * as fb from "firebase-admin";
|
|
4
|
+
export declare class FirestoreEventStore extends EventStore {
|
|
5
|
+
readonly firestore: fb.firestore.Firestore;
|
|
6
|
+
constructor(firestore: fb.firestore.Firestore);
|
|
7
|
+
clear(): Promise<void>;
|
|
8
|
+
private serialize;
|
|
9
|
+
runningSubscriptions: Set<() => void>;
|
|
10
|
+
get aggregateCollection(): fb.firestore.CollectionReference<fb.firestore.DocumentData>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
appendToAggregateStream(AGGREGATE: Constructor<EsAggregate<any, any>>, id: {
|
|
13
|
+
toString(): string;
|
|
14
|
+
}, changes: EsChange[], expectedRevision: bigint): Promise<void>;
|
|
15
|
+
readAggregateStream(AGGREGATE: Constructor<EsAggregate<{
|
|
16
|
+
toString(): string;
|
|
17
|
+
}, Event[]>, any[]>, id: {
|
|
18
|
+
toString(): string;
|
|
19
|
+
}, from?: bigint): AsyncIterable<EsFact>;
|
|
20
|
+
readProjectedStream(config: ProjectedStreamConfiguration, from?: bigint): AsyncIterable<EsFact>;
|
|
21
|
+
followProjectedStream(config: ProjectedStreamConfiguration, from?: bigint): Promise<Follower>;
|
|
22
|
+
competeForProjectedStream(AGGREGATE: ProjectedStreamConfiguration, competitionName: string): Promise<Competitor>;
|
|
23
|
+
}
|
|
24
|
+
export declare class TestFirestoreEventStore extends FirestoreEventStore {
|
|
25
|
+
namespace: string;
|
|
26
|
+
changeNamespace(): void;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
get aggregateCollection(): fb.firestore.CollectionReference<fb.firestore.DocumentData>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=firestore.event-store.d.ts.map
|
|
@@ -0,0 +1 @@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B,OAAO,CAAC,QAAQ,CAAC;IA0Cd,yBAAyB,CAC7B,SAAS,EAAE,4BAA4B,EACvC,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,UAAU,CAAC;CAGvB;AAED,qBAAa,uBAAwB,SAAQ,mBAAmB;IAC9D,SAAS,SAA4C;IAErD,eAAe;IAIT,KAAK;IAQX,IAAI,mBAAmB,gEAEtB;CACF"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestFirestoreEventStore = exports.FirestoreEventStore = void 0;
|
|
4
|
+
const event_sourcing_1 = require("@ddd-ts/event-sourcing");
|
|
5
|
+
class FirestoreEventStore extends event_sourcing_1.EventStore {
|
|
6
|
+
firestore;
|
|
7
|
+
constructor(firestore) {
|
|
8
|
+
super();
|
|
9
|
+
this.firestore = firestore;
|
|
10
|
+
}
|
|
11
|
+
async clear() {
|
|
12
|
+
throw new Error("Not implemented");
|
|
13
|
+
}
|
|
14
|
+
serialize(object) {
|
|
15
|
+
return JSON.parse(JSON.stringify(object, (_, value) => typeof value === "bigint" ? value.toString() : value));
|
|
16
|
+
}
|
|
17
|
+
runningSubscriptions = new Set();
|
|
18
|
+
get aggregateCollection() {
|
|
19
|
+
return this.firestore.collection("events");
|
|
20
|
+
}
|
|
21
|
+
async close() {
|
|
22
|
+
for (const unsubscribe of this.runningSubscriptions) {
|
|
23
|
+
unsubscribe();
|
|
24
|
+
this.runningSubscriptions.delete(unsubscribe);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async appendToAggregateStream(AGGREGATE, id, changes, expectedRevision) {
|
|
28
|
+
await this.firestore.runTransaction(async (trx) => {
|
|
29
|
+
const eventsOccuredAfter = await trx.get(this.aggregateCollection
|
|
30
|
+
.where("aggregateType", "==", AGGREGATE.name)
|
|
31
|
+
.where("aggregateId", "==", id.toString())
|
|
32
|
+
.where("revision", ">", expectedRevision));
|
|
33
|
+
const hasEventAfter = eventsOccuredAfter.docs.length > 0;
|
|
34
|
+
if (hasEventAfter) {
|
|
35
|
+
throw new Error("Concurrency error");
|
|
36
|
+
}
|
|
37
|
+
let revision = expectedRevision + 1n;
|
|
38
|
+
for (const change of changes) {
|
|
39
|
+
trx.create(this.aggregateCollection.doc(change.id), {
|
|
40
|
+
aggregateType: AGGREGATE.name,
|
|
41
|
+
id: change.id,
|
|
42
|
+
aggregateId: id.toString(),
|
|
43
|
+
revision: Number(revision),
|
|
44
|
+
type: change.type,
|
|
45
|
+
payload: this.serialize(change.payload),
|
|
46
|
+
occurredAt: new Date(),
|
|
47
|
+
});
|
|
48
|
+
await new Promise((r) => setTimeout(r, 1)); // ensure occurredAt is unique
|
|
49
|
+
revision++;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async *readAggregateStream(AGGREGATE, id, from) {
|
|
54
|
+
let query = this.aggregateCollection
|
|
55
|
+
.where("aggregateType", "==", AGGREGATE.name)
|
|
56
|
+
.where("aggregateId", "==", id.toString())
|
|
57
|
+
.orderBy("revision", "asc");
|
|
58
|
+
if (from) {
|
|
59
|
+
query = query.where("revision", ">", from);
|
|
60
|
+
}
|
|
61
|
+
for await (const event of query.stream()) {
|
|
62
|
+
const e = event;
|
|
63
|
+
yield {
|
|
64
|
+
id: e.id,
|
|
65
|
+
revision: BigInt(e.data().revision),
|
|
66
|
+
type: e.data().type,
|
|
67
|
+
payload: e.data().payload,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async *readProjectedStream(config, from) {
|
|
72
|
+
let query = this.aggregateCollection
|
|
73
|
+
.where("aggregateType", "in", config.map((c) => c.name))
|
|
74
|
+
.orderBy("occurredAt", "asc");
|
|
75
|
+
let revision = 0n;
|
|
76
|
+
if (from) {
|
|
77
|
+
query = query.offset(Number(from));
|
|
78
|
+
revision = from;
|
|
79
|
+
}
|
|
80
|
+
for await (const event of query.stream()) {
|
|
81
|
+
const e = event;
|
|
82
|
+
yield {
|
|
83
|
+
id: e.id,
|
|
84
|
+
revision: revision,
|
|
85
|
+
type: e.data().type,
|
|
86
|
+
payload: e.data().payload,
|
|
87
|
+
};
|
|
88
|
+
revision++;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async followProjectedStream(config, from = 0n) {
|
|
92
|
+
let query = this.aggregateCollection
|
|
93
|
+
.where("aggregateType", "in", config.map((c) => c.name))
|
|
94
|
+
.orderBy("occurredAt", "asc");
|
|
95
|
+
let revision = from;
|
|
96
|
+
query = query.offset(Number(revision));
|
|
97
|
+
const follower = new event_sourcing_1.Queue();
|
|
98
|
+
const unsubscribe = query.onSnapshot((snap) => {
|
|
99
|
+
for (const change of snap.docChanges()) {
|
|
100
|
+
if (change.type !== "added") {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const data = change.doc.data();
|
|
104
|
+
follower.push({
|
|
105
|
+
id: data.id,
|
|
106
|
+
revision: revision,
|
|
107
|
+
type: data.type,
|
|
108
|
+
payload: data.payload,
|
|
109
|
+
});
|
|
110
|
+
revision++;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const hook = () => follower.close();
|
|
114
|
+
follower.onClose(() => {
|
|
115
|
+
unsubscribe();
|
|
116
|
+
this.runningSubscriptions.delete(hook);
|
|
117
|
+
});
|
|
118
|
+
this.runningSubscriptions.add(hook);
|
|
119
|
+
return follower;
|
|
120
|
+
}
|
|
121
|
+
async competeForProjectedStream(AGGREGATE, competitionName) {
|
|
122
|
+
throw new Error("not implemented");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.FirestoreEventStore = FirestoreEventStore;
|
|
126
|
+
class TestFirestoreEventStore extends FirestoreEventStore {
|
|
127
|
+
namespace = Math.random().toString().substring(2, 8);
|
|
128
|
+
changeNamespace() {
|
|
129
|
+
this.namespace = Math.random().toString().substring(2, 8);
|
|
130
|
+
}
|
|
131
|
+
async clear() {
|
|
132
|
+
for (const unsubscribe of this.runningSubscriptions) {
|
|
133
|
+
unsubscribe();
|
|
134
|
+
this.runningSubscriptions.delete(unsubscribe);
|
|
135
|
+
}
|
|
136
|
+
this.namespace = Math.random().toString().substring(2, 8);
|
|
137
|
+
}
|
|
138
|
+
get aggregateCollection() {
|
|
139
|
+
return this.firestore.collection(this.namespace + "-events");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.TestFirestoreEventStore = TestFirestoreEventStore;
|
|
143
|
+
//# sourceMappingURL=firestore.event-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.event-store.js","sourceRoot":"","sources":["../src/firestore.event-store.ts"],"names":[],"mappings":";;;AAAA,2DAUgC;AAIhC,MAAa,mBAAoB,SAAQ,2BAAU;IACrB;IAA5B,YAA4B,SAAiC;QAC3D,KAAK,EAAE,CAAC;QADkB,cAAS,GAAT,SAAS,CAAwB;IAE7D,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAEO,SAAS,CAAC,MAAc;QAC9B,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAClC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CACrD,CACF,CAAC;IACJ,CAAC;IAED,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAE7C,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACpD,WAAW,EAAE,CAAC;YACd,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,W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AAC;QAChD,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAC/D,CAAC;CACF;AAlBD,0DAkBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.event-store.spec.d.ts","sourceRoot":"","sources":["../src/firestore.event-store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
|
|
27
|
+
const tests_1 = require("@ddd-ts/tests");
|
|
28
|
+
const fb = __importStar(require("firebase-admin"));
|
|
29
|
+
const firestore_event_store_1 = require("./firestore.event-store");
|
|
30
|
+
describe("FirestoreEventStore", () => {
|
|
31
|
+
const app = fb.initializeApp({ projectId: "demo-es" });
|
|
32
|
+
const firestore = app.firestore();
|
|
33
|
+
(0, tests_1.EsAggregateStoreSuite)(new firestore_event_store_1.TestFirestoreEventStore(firestore));
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=firestore.event-store.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.event-store.spec.js","sourceRoot":"","sources":["../src/firestore.event-store.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,gBAAgB,CAAC;AAEvD,yCAAsD;AACtD,mDAAqC;AACrC,mEAAkE;AAElE,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC;IAClC,IAAA,6BAAqB,EAAC,IAAI,+CAAuB,CAAC,SAAS,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Snapshotter, EsAggregate } from "@ddd-ts/event-sourcing";
|
|
2
|
+
import { Model } from "@ddd-ts/model";
|
|
3
|
+
import { ISerializer } from "@ddd-ts/serialization";
|
|
4
|
+
export declare class FirestoreSnapshotter<S extends ISerializer<EsAggregate<any, any>>> extends Snapshotter<S extends ISerializer<infer A> ? A : never> {
|
|
5
|
+
private readonly db;
|
|
6
|
+
readonly serializer: S;
|
|
7
|
+
constructor(db: FirebaseFirestore.Firestore, serializer: S);
|
|
8
|
+
private getIdFromModel;
|
|
9
|
+
load(id: S extends ISerializer<infer M extends Model> ? M["id"] : never): Promise<any>;
|
|
10
|
+
save(aggregate: S extends ISerializer<infer A> ? A : never): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=firestore.snapshotter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.snapshotter.d.ts","sourceRoot":"","sources":["../src/firestore.snapshotter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,qBAAa,oBAAoB,CAC/B,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAC5C,SAAQ,WAAW,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAE7D,OAAO,CAAC,QAAQ,CAAC,EAAE;aACH,UAAU,EAAE,CAAC;gBADZ,EAAE,EAAE,iBAAiB,CAAC,SAAS,EAChC,UAAU,EAAE,CAAC;IAK/B,OAAO,CAAC,cAAc;IAShB,IAAI,CACR,EAAE,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,GACjE,OAAO,CAAC,GAAG,CAAC;IAuBT,IAAI,CACR,SAAS,EAAE,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,GACpD,OAAO,CAAC,IAAI,CAAC;CAWjB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreSnapshotter = void 0;
|
|
4
|
+
const event_sourcing_1 = require("@ddd-ts/event-sourcing");
|
|
5
|
+
class FirestoreSnapshotter extends event_sourcing_1.Snapshotter {
|
|
6
|
+
db;
|
|
7
|
+
serializer;
|
|
8
|
+
constructor(db, serializer) {
|
|
9
|
+
super();
|
|
10
|
+
this.db = db;
|
|
11
|
+
this.serializer = serializer;
|
|
12
|
+
}
|
|
13
|
+
getIdFromModel(m) {
|
|
14
|
+
if (Object.getOwnPropertyNames(m.id).includes("serialize")) {
|
|
15
|
+
if ("serialize" in m.id) {
|
|
16
|
+
return m.id.serialize();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return m.id.toString();
|
|
20
|
+
}
|
|
21
|
+
async load(id) {
|
|
22
|
+
const query = await this.db
|
|
23
|
+
.collection("snapshots")
|
|
24
|
+
.where("aggregateId", "==", id.toString())
|
|
25
|
+
.orderBy("revision", "desc")
|
|
26
|
+
.limit(1)
|
|
27
|
+
.get();
|
|
28
|
+
const document = query.docs[0];
|
|
29
|
+
if (!document || !document.exists) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const snapshot = document.data();
|
|
33
|
+
if (!snapshot) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return this.serializer.deserialize(snapshot.serialized);
|
|
37
|
+
}
|
|
38
|
+
async save(aggregate) {
|
|
39
|
+
const id = this.getIdFromModel(aggregate);
|
|
40
|
+
await this.db
|
|
41
|
+
.collection("snapshots")
|
|
42
|
+
.doc(`${id.toString()}.${aggregate.acknowledgedRevision.toString()}`)
|
|
43
|
+
.set({
|
|
44
|
+
id: id.toString(),
|
|
45
|
+
revision: Number(aggregate.acknowledgedRevision),
|
|
46
|
+
serialized: await this.serializer.serialize(aggregate),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.FirestoreSnapshotter = FirestoreSnapshotter;
|
|
51
|
+
//# sourceMappingURL=firestore.snapshotter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.snapshotter.js","sourceRoot":"","sources":["../src/firestore.snapshotter.ts"],"names":[],"mappings":";;;AAAA,2DAAkE;AAIlE,MAAa,oBAEX,SAAQ,4BAAuD;IAE5C;IACD;IAFlB,YACmB,EAA+B,EAChC,UAAa;QAE7B,KAAK,EAAE,CAAC;QAHS,OAAE,GAAF,EAAE,CAA6B;QAChC,eAAU,GAAV,UAAU,CAAG;IAG/B,CAAC;IAEO,cAAc,CAAC,CAA6C;QAClE,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3D,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;gBACxB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,EAAkE;QAElE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE;aACxB,UAAU,CAAC,WAAW,CAAC;aACvB,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC;aACzC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC;aAC3B,KAAK,CAAC,CAAC,CAAC;aACR,GAAG,EAAE,CAAC;QAET,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAE/B,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEjC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,IAAI,CACR,SAAqD;QAErD,MAAM,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,IAAI,CAAC,EAAE;aACV,UAAU,CAAC,WAAW,CAAC;aACvB,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,SAAS,CAAC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,CAAC;aACpE,GAAG,CAAC;YACH,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE;YACjB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;YAChD,UAAU,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC;SACvD,CAAC,CAAC;IACP,CAAC;CACF;AAzDD,oDAyDC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreSnapshotter = exports.TestFirestoreEventStore = exports.FirestoreEventStore = exports.FirestoreCheckpoint = void 0;
|
|
4
|
+
var firestore_checkpoint_1 = require("./firestore.checkpoint");
|
|
5
|
+
Object.defineProperty(exports, "FirestoreCheckpoint", { enumerable: true, get: function () { return firestore_checkpoint_1.FirestoreCheckpoint; } });
|
|
6
|
+
var firestore_event_store_1 = require("./firestore.event-store");
|
|
7
|
+
Object.defineProperty(exports, "FirestoreEventStore", { enumerable: true, get: function () { return firestore_event_store_1.FirestoreEventStore; } });
|
|
8
|
+
Object.defineProperty(exports, "TestFirestoreEventStore", { enumerable: true, get: function () { return firestore_event_store_1.TestFirestoreEventStore; } });
|
|
9
|
+
var firestore_snapshotter_1 = require("./firestore.snapshotter");
|
|
10
|
+
Object.defineProperty(exports, "FirestoreSnapshotter", { enumerable: true, get: function () { return firestore_snapshotter_1.FirestoreSnapshotter; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA6D;AAApD,2HAAA,mBAAmB,OAAA;AAC5B,iEAGiC;AAF/B,4HAAA,mBAAmB,OAAA;AACnB,gIAAA,uBAAuB,OAAA;AAEzB,iEAA+D;AAAtD,6HAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bank.spec.d.ts","sourceRoot":"","sources":["../../src/test/bank.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
|
|
27
|
+
const fb = __importStar(require("firebase-admin"));
|
|
28
|
+
const firestore_event_store_1 = require("../firestore.event-store");
|
|
29
|
+
const tests_1 = require("@ddd-ts/tests");
|
|
30
|
+
const firestore_checkpoint_1 = require("../firestore.checkpoint");
|
|
31
|
+
const firestore_snapshotter_1 = require("../firestore.snapshotter");
|
|
32
|
+
const event_sourcing_1 = require("@ddd-ts/event-sourcing");
|
|
33
|
+
const store_firestore_1 = require("@ddd-ts/store-firestore");
|
|
34
|
+
describe("Firestore Bank Test", () => {
|
|
35
|
+
const app = fb.initializeApp({ projectId: "demo-es" });
|
|
36
|
+
const firestore = app.firestore();
|
|
37
|
+
const es = new firestore_event_store_1.TestFirestoreEventStore(firestore);
|
|
38
|
+
const checkpoint = new firestore_checkpoint_1.FirestoreCheckpoint(firestore);
|
|
39
|
+
const transactionPerformer = new store_firestore_1.FirestoreTransactionPerformer(es.firestore);
|
|
40
|
+
(0, tests_1.BankSuite)(es, checkpoint, transactionPerformer, (serializer, name) => {
|
|
41
|
+
const store = new store_firestore_1.FirestoreStore(name, firestore, serializer);
|
|
42
|
+
return store;
|
|
43
|
+
}, (AGGREGATE, serializer, eventsSerializers) => {
|
|
44
|
+
const snapshotter = new firestore_snapshotter_1.FirestoreSnapshotter(firestore, serializer);
|
|
45
|
+
const persistor = class extends (0, event_sourcing_1.EsAggregatePersistorWithSnapshots)(AGGREGATE) {
|
|
46
|
+
};
|
|
47
|
+
return new persistor(es, eventsSerializers, snapshotter);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=bank.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bank.spec.js","sourceRoot":"","sources":["../../src/test/bank.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,gBAAgB,CAAC;AACvD,mDAAqC;AACrC,oEAAmE;AAEnE,yCAA0C;AAC1C,kEAA8D;AAC9D,oEAAgE;AAChE,2DAA2E;AAC3E,6DAGiC;AAGjC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,EAAE,GAAG,IAAI,+CAAuB,CAAC,SAAS,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,IAAI,0CAAmB,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,oBAAoB,GAAG,IAAI,+CAA6B,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAE7E,IAAA,iBAAS,EACP,EAAE,EACF,UAAU,EACV,oBAAoB,EACpB,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,IAAI,gCAAc,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAQ,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,CAAC,EACD,CAAC,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,EAAE;QAC3C,MAAM,WAAW,GAAG,IAAI,4CAAoB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACpE,MAAM,SAAS,GAAG,KAAM,SAAQ,IAAA,kDAAiC,EAC/D,SAAS,CACV;SAAG,CAAC;QACL,OAAO,IAAI,SAAS,CAAC,EAAE,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ddd-ts/event-sourcing-firestore",
|
|
3
|
+
"version": "0.0.0-alpha2.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"pretest": "docker compose -f docker/docker-compose.yml up -d",
|
|
9
|
+
"wait": "sh -c 'until curl --silent localhost:8080; do sleep 1; done;'",
|
|
10
|
+
"test": "jest --config node_modules/@ddd-ts/tools/jest.config.ts",
|
|
11
|
+
"posttest": "docker compose -f docker/docker-compose.yml down",
|
|
12
|
+
"build": "tsc"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ddd-ts/event-sourcing": "0.0.0-alpha2.1",
|
|
16
|
+
"@ddd-ts/model": "0.0.0-alpha2.1",
|
|
17
|
+
"@ddd-ts/serialization": "0.0.0-alpha2.1",
|
|
18
|
+
"firebase-admin": "^11.5.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@ddd-ts/store-firestore": "0.0.0-alpha2.1",
|
|
22
|
+
"@ddd-ts/tests": "0.0.0-alpha2.1",
|
|
23
|
+
"@ddd-ts/tools": "0.0.0-alpha2.1",
|
|
24
|
+
"@ddd-ts/types": "0.0.0-alpha2.1",
|
|
25
|
+
"@types/jest": "^29.5.1"
|
|
26
|
+
}
|
|
27
|
+
}
|