@ddd-ts/event-sourcing-firestore 0.0.0-feat.alpha.045d9c5

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.
@@ -0,0 +1,5 @@
1
+ import { TransactionPerformer } from "@ddd-ts/model";
2
+ export declare class FirebaseTransactionPerformer extends TransactionPerformer {
3
+ constructor(db: FirebaseFirestore.Firestore);
4
+ }
5
+ //# sourceMappingURL=firebase.transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase.transaction.d.ts","sourceRoot":"","sources":["../src/firebase.transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,qBAAa,4BAA6B,SAAQ,oBAAoB;gBACxD,EAAE,EAAE,iBAAiB,CAAC,SAAS;CAG5C"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirebaseTransactionPerformer = void 0;
4
+ const model_1 = require("@ddd-ts/model");
5
+ class FirebaseTransactionPerformer extends model_1.TransactionPerformer {
6
+ constructor(db) {
7
+ super((effect) => db.runTransaction(effect));
8
+ }
9
+ }
10
+ exports.FirebaseTransactionPerformer = FirebaseTransactionPerformer;
11
+ //# sourceMappingURL=firebase.transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase.transaction.js","sourceRoot":"","sources":["../src/firebase.transaction.ts"],"names":[],"mappings":";;;AAAA,yCAAqD;AAErD,MAAa,4BAA6B,SAAQ,4BAAoB;IACpE,YAAY,EAA+B;QACzC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC;CACF;AAJD,oEAIC"}
@@ -0,0 +1,10 @@
1
+ import * as fb from "firebase-admin";
2
+ import { Checkpoint } from "@ddd-ts/event-sourcing";
3
+ export declare class FirestoreCheckpoint extends Checkpoint {
4
+ readonly firestore: fb.firestore.Firestore;
5
+ constructor(firestore: fb.firestore.Firestore);
6
+ clear(): Promise<void>;
7
+ get(name: string): Promise<bigint>;
8
+ set(name: string, revision: bigint, trx?: FirebaseFirestore.Transaction): Promise<void>;
9
+ }
10
+ //# 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;AAE3E,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,iBAAiB,CAAC,WAAW;CAuBtC"}
@@ -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.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;AAE3E,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,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY;QACpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,SAAS;aACpC,UAAU,CAAC,aAAa,CAAC;aACzB,GAAG,CAAC,IAAI,CAAC;aACT,GAAG,EAAE,CAAC;QAET,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACtB,OAAO,CAAC,EAAE,CAAC;SACZ;QACD,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,GAAG,CACP,IAAY,EACZ,QAAgB,EAChB,GAAmC;QAEnC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS;aACvC,UAAU,CAAC,aAAa,CAAC;aACzB,GAAG,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,CAAC;QAE7C,IAAI,UAAU,CAAC,MAAM,EAAE;YACrB,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC5D,IAAI,eAAe,GAAG,QAAQ,EAAE;gBAC9B,MAAM,IAAI,sCAAqB,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;aAClE;SACF;QAED,IAAI,GAAG,EAAE;YACP,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBAC1D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;aAC3B,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,aAAa,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;SACzD;IACH,CAAC;CACF;AArDD,kDAqDC"}
@@ -0,0 +1,24 @@
1
+ import { EsAggregate, Event, Competitor, Constructor, EsChange, EsFact, EventStore, Follower, ProjectedStreamConfiguration } from "@ddd-ts/event-sourcing";
2
+ import * as fb from "firebase-admin";
3
+ export declare class FirestoreEventStore extends EventStore {
4
+ readonly firestore: fb.firestore.Firestore;
5
+ namespace: string;
6
+ constructor(firestore: fb.firestore.Firestore);
7
+ private serialize;
8
+ runningSubscriptions: Set<any>;
9
+ get aggregateCollection(): fb.firestore.CollectionReference<fb.firestore.DocumentData>;
10
+ close(): Promise<void>;
11
+ clear(): Promise<void>;
12
+ appendToAggregateStream(AGGREGATE: Constructor<EsAggregate>, 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
+ //# sourceMappingURL=firestore.event-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore.event-store.d.ts","sourceRoot":"","sources":["../src/firestore.event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,EACL,UAAU,EACV,WAAW,EACX,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,4BAA4B,EAE7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAIrC,qBAAa,mBAAoB,SAAQ,UAAU;aAErB,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS;IAD7D,SAAS,EAAE,MAAM,CAAC;gBACU,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS;IAK7D,OAAO,CAAC,SAAS;IAIjB,oBAAoB,WAAkB;IAEtC,IAAI,mBAAmB,gEAEtB;IAEK,KAAK;IASL,KAAK;IAQL,uBAAuB,CAC3B,SAAS,EAAE,WAAW,CAAC,WAAW,CAAC,EACnC,EAAE,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,EAC1B,OAAO,EAAE,QAAQ,EAAE,EACnB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;IAgCT,mBAAmB,CACxB,SAAS,EAAE,WAAW,CAAC,WAAW,CAAC;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,EACzE,EAAE,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,aAAa,CAAC,MAAM,CAAC;IAqBjB,mBAAmB,CACxB,MAAM,EAAE,4BAA4B,EACpC,IAAI,CAAC,EAAE,MAAM,GACZ,aAAa,CAAC,MAAM,CAAC;IA2BlB,qBAAqB,CACzB,MAAM,EAAE,4BAA4B,EACpC,IAAI,GAAE,MAAW,GAChB,OAAO,CAAC,QAAQ,CAAC;IA4Cd,yBAAyB,CAC7B,SAAS,EAAE,4BAA4B,EACvC,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,UAAU,CAAC;CAGvB"}
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirestoreEventStore = void 0;
4
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
5
+ process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
6
+ let id = 0;
7
+ class FirestoreEventStore extends event_sourcing_1.EventStore {
8
+ firestore;
9
+ namespace;
10
+ constructor(firestore) {
11
+ super();
12
+ this.firestore = firestore;
13
+ this.namespace = Math.random().toString().substring(2, 8);
14
+ }
15
+ serialize(object) {
16
+ return JSON.parse(JSON.stringify(object));
17
+ }
18
+ runningSubscriptions = new Set();
19
+ get aggregateCollection() {
20
+ return this.firestore.collection(this.namespace + "events");
21
+ }
22
+ async close() {
23
+ for (const unsubscribe of this.runningSubscriptions) {
24
+ unsubscribe();
25
+ this.runningSubscriptions.delete(unsubscribe);
26
+ }
27
+ await this.firestore.terminate();
28
+ }
29
+ async clear() {
30
+ for (const unsubscribe of this.runningSubscriptions) {
31
+ unsubscribe();
32
+ this.runningSubscriptions.delete(unsubscribe);
33
+ }
34
+ this.namespace = Math.random().toString().substring(2, 8);
35
+ }
36
+ async appendToAggregateStream(AGGREGATE, id, changes, expectedRevision) {
37
+ await this.firestore.runTransaction(async (trx) => {
38
+ const eventsOccuredAfter = await trx.get(this.aggregateCollection
39
+ .where("aggregateType", "==", AGGREGATE.name)
40
+ .where("aggregateId", "==", id.toString())
41
+ .where("revision", ">", expectedRevision));
42
+ const hasEventAfter = eventsOccuredAfter.docs.length > 0;
43
+ if (hasEventAfter) {
44
+ throw new Error("Concurrency error");
45
+ }
46
+ let revision = expectedRevision + 1n;
47
+ for (const change of changes) {
48
+ trx.create(this.aggregateCollection.doc(change.id), {
49
+ aggregateType: AGGREGATE.name,
50
+ id: change.id,
51
+ aggregateId: id.toString(),
52
+ revision: Number(revision),
53
+ type: change.type,
54
+ payload: this.serialize(change.payload),
55
+ occurredAt: new Date(),
56
+ });
57
+ await new Promise((r) => setTimeout(r, 1)); // ensure occurredAt is unique
58
+ revision++;
59
+ }
60
+ });
61
+ }
62
+ async *readAggregateStream(AGGREGATE, id, from) {
63
+ let query = this.aggregateCollection
64
+ .where("aggregateType", "==", AGGREGATE.name)
65
+ .where("aggregateId", "==", id.toString())
66
+ .orderBy("revision", "asc");
67
+ if (from) {
68
+ query = query.where("revision", ">", from);
69
+ }
70
+ for await (const event of query.stream()) {
71
+ const e = event;
72
+ yield {
73
+ id: e.id,
74
+ revision: BigInt(e.data().revision),
75
+ type: e.data().type,
76
+ payload: e.data().payload,
77
+ };
78
+ }
79
+ }
80
+ async *readProjectedStream(config, from) {
81
+ let query = this.aggregateCollection
82
+ .where("aggregateType", "in", config.map((c) => c.name))
83
+ .orderBy("occurredAt", "asc");
84
+ let revision = 0n;
85
+ if (from) {
86
+ query = query.offset(Number(from));
87
+ revision = from;
88
+ }
89
+ for await (const event of query.stream()) {
90
+ const e = event;
91
+ yield {
92
+ id: e.id,
93
+ revision: revision,
94
+ type: e.data().type,
95
+ payload: e.data().payload,
96
+ };
97
+ revision++;
98
+ }
99
+ }
100
+ async followProjectedStream(config, from = 0n) {
101
+ const i = id++;
102
+ let query = this.aggregateCollection
103
+ .where("aggregateType", "in", config.map((c) => c.name))
104
+ .orderBy("occurredAt", "asc");
105
+ let revision = from;
106
+ query = query.offset(Number(revision));
107
+ const follower = new event_sourcing_1.Queue();
108
+ const unsubscribe = query.onSnapshot((snap) => {
109
+ for (const change of snap.docChanges()) {
110
+ if (change.type !== "added") {
111
+ continue;
112
+ }
113
+ const data = change.doc.data();
114
+ follower.push({
115
+ id: data.id,
116
+ revision: revision,
117
+ type: data.type,
118
+ payload: data.payload,
119
+ });
120
+ revision++;
121
+ }
122
+ });
123
+ const hook = () => follower.close();
124
+ follower.onClose(() => {
125
+ unsubscribe();
126
+ this.runningSubscriptions.delete(hook);
127
+ });
128
+ this.runningSubscriptions.add(hook);
129
+ return follower;
130
+ }
131
+ async competeForProjectedStream(AGGREGATE, competitionName) {
132
+ throw new Error("not implemented");
133
+ }
134
+ }
135
+ exports.FirestoreEventStore = FirestoreEventStore;
136
+ //# 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,2DAWgC;AAGhC,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,gBAAgB,CAAC;AACvD,IAAI,EAAE,GAAG,CAAC,CAAC;AACX,MAAa,mBAAoB,SAAQ,2BAAU;IAErB;IAD5B,SAAS,CAAS;IAClB,YAA4B,SAAiC;QAC3D,KAAK,EAAE,CAAC;QADkB,cAAS,GAAT,SAAS,CAAwB;QAE3D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;IAEO,SAAS,CAAC,MAAc;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC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AAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEpC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAC7B,SAAuC,EACvC,eAAuB;QAEvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AAnLD,kDAmLC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=firestore.event-store.spec.d.ts.map
@@ -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,37 @@
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
+ const tests_1 = require("@ddd-ts/tests");
27
+ const fb = __importStar(require("firebase-admin"));
28
+ const firestore_event_store_1 = require("./firestore.event-store");
29
+ describe("FirestoreEventStore", () => {
30
+ const app = fb.initializeApp({ projectId: "demo-es" });
31
+ const firestore = app.firestore();
32
+ it("should", () => {
33
+ expect(true).toBe(false);
34
+ });
35
+ (0, tests_1.EsAggregateStoreSuite)(new firestore_event_store_1.FirestoreEventStore(firestore));
36
+ });
37
+ //# 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,yCAAsD;AACtD,mDAAqC;AACrC,mEAA8D;AAE9D,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;IAElC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QAChB,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,IAAA,6BAAqB,EAAC,IAAI,2CAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Snapshotter, EsAggregate } from "@ddd-ts/event-sourcing";
2
+ import { Serializer } from "@ddd-ts/model";
3
+ export declare class FirestoreSnapshotter<S extends Serializer<EsAggregate>> extends Snapshotter<S extends Serializer<infer A> ? A : never> {
4
+ private readonly db;
5
+ readonly serializer: S;
6
+ constructor(db: FirebaseFirestore.Firestore, serializer: S);
7
+ load(id: ReturnType<S["getIdFromModel"]>): Promise<any>;
8
+ save(aggregate: S extends Serializer<infer A> ? A : never): Promise<void>;
9
+ }
10
+ //# 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,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,oBAAoB,CAC/B,CAAC,SAAS,UAAU,CAAC,WAAW,CAAC,CACjC,SAAQ,WAAW,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAE5D,OAAO,CAAC,QAAQ,CAAC,EAAE;aACH,UAAU,EAAE,CAAC;gBADZ,EAAE,EAAE,iBAAiB,CAAC,SAAS,EAChC,UAAU,EAAE,CAAC;IAKzB,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAuBvD,IAAI,CACR,SAAS,EAAE,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,GACnD,OAAO,CAAC,IAAI,CAAC;CAWjB"}
@@ -0,0 +1,43 @@
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
+ async load(id) {
14
+ const query = await this.db
15
+ .collection("snapshots")
16
+ .where("aggregateId", "==", id.toString())
17
+ .orderBy("revision", "desc")
18
+ .limit(1)
19
+ .get();
20
+ const document = query.docs[0];
21
+ if (!document || !document.exists) {
22
+ return undefined;
23
+ }
24
+ const snapshot = document.data();
25
+ if (!snapshot) {
26
+ return undefined;
27
+ }
28
+ return this.serializer.deserialize(snapshot.serialized);
29
+ }
30
+ async save(aggregate) {
31
+ const id = this.serializer.getIdFromModel(aggregate);
32
+ await this.db
33
+ .collection("snapshots")
34
+ .doc(id.toString() + "." + aggregate.acknowledgedRevision.toString())
35
+ .set({
36
+ id: id.toString(),
37
+ revision: Number(aggregate.acknowledgedRevision),
38
+ serialized: this.serializer.serialize(aggregate),
39
+ });
40
+ }
41
+ }
42
+ exports.FirestoreSnapshotter = FirestoreSnapshotter;
43
+ //# 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;AAGlE,MAAa,oBAEX,SAAQ,4BAAsD;IAE3C;IACD;IAFlB,YACmB,EAA+B,EAChC,UAAa;QAE7B,KAAK,EAAE,CAAC;QAHS,OAAE,GAAF,EAAE,CAA6B;QAChC,eAAU,GAAV,UAAU,CAAG;IAG/B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAmC;QAC5C,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;YACjC,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEjC,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,IAAI,CACR,SAAoD;QAEpD,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,IAAI,CAAC,EAAE;aACV,UAAU,CAAC,WAAW,CAAC;aACvB,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,SAAS,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC;aACpE,GAAG,CAAC;YACH,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE;YACjB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;YAChD,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC;SACjD,CAAC,CAAC;IACP,CAAC;CACF;AA9CD,oDA8CC"}
@@ -0,0 +1,6 @@
1
+ import { Store } from "@ddd-ts/model";
2
+ import { AbstractConstructor } from "@ddd-ts/event-sourcing/src/es-aggregate-store/event-store";
3
+ export declare function FirestoreStore<Model, Id extends {
4
+ toString(): string;
5
+ }>(collection: string): AbstractConstructor<Store<Model, Id>>;
6
+ //# sourceMappingURL=firestore.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore.store.d.ts","sourceRoot":"","sources":["../src/firestore.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2DAA2D,CAAC;AAEhG,wBAAgB,cAAc,CAAC,KAAK,EAAE,EAAE,SAAS;IAAE,QAAQ,IAAI,MAAM,CAAA;CAAE,EACrE,UAAU,EAAE,MAAM,GACjB,mBAAmB,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAkDvC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirestoreStore = void 0;
4
+ function FirestoreStore(collection) {
5
+ class FirstoreStore {
6
+ firestore;
7
+ serializer;
8
+ _collection;
9
+ constructor(firestore, serializer) {
10
+ this.firestore = firestore;
11
+ this.serializer = serializer;
12
+ this._collection = this.firestore.collection(collection);
13
+ }
14
+ async save(model, trx) {
15
+ const stack = new Error().stack;
16
+ const serialized = this.serializer.serialize(model);
17
+ const ref = this._collection.doc(serialized.id.toString());
18
+ trx ? trx.set(ref, serialized) : await ref.set(serialized);
19
+ }
20
+ async load(id, trx) {
21
+ const ref = this._collection.doc(id.toString());
22
+ const snapshot = trx ? await trx.get(ref) : await ref.get();
23
+ if (!snapshot.exists) {
24
+ return undefined;
25
+ }
26
+ return this.serializer.deserialize(snapshot.data());
27
+ }
28
+ async loadAll() {
29
+ const snapshot = await this._collection.get();
30
+ return snapshot.docs.map((doc) => this.serializer.deserialize(doc.data()));
31
+ }
32
+ async delete(id) {
33
+ await this.firestore.collection(collection).doc(id.toString()).delete();
34
+ }
35
+ }
36
+ return FirstoreStore;
37
+ }
38
+ exports.FirestoreStore = FirestoreStore;
39
+ //# sourceMappingURL=firestore.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore.store.js","sourceRoot":"","sources":["../src/firestore.store.ts"],"names":[],"mappings":";;;AAGA,SAAgB,cAAc,CAC5B,UAAkB;IAElB,MAAe,aAAa;QAIR;QACC;QAJnB,WAAW,CAAwC;QAEnD,YACkB,SAAsC,EACrC,UAA6B;YAD9B,cAAS,GAAT,SAAS,CAA6B;YACrC,eAAU,GAAV,UAAU,CAAmB;YAE9C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC3D,CAAC;QAED,KAAK,CAAC,IAAI,CACR,KAAY,EACZ,GAAmC;YAEnC,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;YAChC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACpD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,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ckpoint } from "./firestore.checkpoint";
2
+ export { FirestoreEventStore } from "./firestore.event-store";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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
+ //# 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,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bank.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bank.spec.d.ts","sourceRoot":"","sources":["../../src/test/bank.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
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
+ const fb = __importStar(require("firebase-admin"));
27
+ const firestore_event_store_1 = require("../firestore.event-store");
28
+ const tests_1 = require("@ddd-ts/tests");
29
+ const firestore_checkpoint_1 = require("../firestore.checkpoint");
30
+ const firebase_transaction_1 = require("../firebase.transaction");
31
+ const firestore_store_1 = require("../firestore.store");
32
+ const firestore_snapshotter_1 = require("../firestore.snapshotter");
33
+ const event_sourcing_1 = require("@ddd-ts/event-sourcing");
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.FirestoreEventStore(firestore);
38
+ const checkpoint = new firestore_checkpoint_1.FirestoreCheckpoint(firestore);
39
+ const transactionPerformer = new firebase_transaction_1.FirebaseTransactionPerformer(es.firestore);
40
+ (0, tests_1.BankSuite)(es, checkpoint, transactionPerformer, (serializer, name) => {
41
+ const Store = class extends (0, firestore_store_1.FirestoreStore)(name) {
42
+ };
43
+ const store = new Store(firestore, serializer);
44
+ return store;
45
+ }, (AGGREGATE, serializer) => {
46
+ const snapshotter = new firestore_snapshotter_1.FirestoreSnapshotter(firestore, serializer);
47
+ const persistor = class extends (0, event_sourcing_1.EsAggregatePersistorWithSnapshots)(AGGREGATE) {
48
+ };
49
+ return new persistor(es, snapshotter);
50
+ });
51
+ });
52
+ //# 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,mDAAqC;AACrC,oEAA+D;AAE/D,yCAA0C;AAC1C,kEAA8D;AAC9D,kEAAuE;AACvE,wDAAoD;AACpD,oEAAgE;AAChE,2DAA2E;AAE3E,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,2CAAmB,CAAC,SAAS,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,IAAI,0CAAmB,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,oBAAoB,GAAG,IAAI,mDAA4B,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IAE5E,IAAA,iBAAS,EACP,EAAE,EACF,UAAU,EACV,oBAAoB,EACpB,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,KAAM,SAAQ,IAAA,gCAAc,EAAC,IAAI,CAAC;SAAG,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE,UAAU,CAAQ,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC,EACD,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE;QACxB,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,WAAW,CAAC,CAAC;IACxC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@ddd-ts/event-sourcing-firestore",
3
+ "version": "0.0.0-feat.alpha.045d9c5",
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
+ "test": "yarn pretest; test-runner; e=$?;yarn posttest; exit $e",
10
+ "posttest": "docker compose -f docker/docker-compose.yml down",
11
+ "build": "builder"
12
+ },
13
+ "dependencies": {
14
+ "@ddd-ts/event-sourcing": "*",
15
+ "@ddd-ts/model": "*",
16
+ "firebase-admin": "^11.5.0"
17
+ },
18
+ "devDependencies": {
19
+ "@ddd-ts/dev": "*",
20
+ "@ddd-ts/tests": "*"
21
+ }
22
+ }