@ddd-ts/store-firestore 0.0.0-feat.kraaft.1445e26

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,6 @@
1
+ import { Firestore } from "firebase-admin/firestore";
2
+ import { TransactionPerformer } from "@ddd-ts/model";
3
+ export declare class FirebaseTransactionPerformer extends TransactionPerformer {
4
+ constructor(db: Firestore);
5
+ }
6
+ //# 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,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,qBAAa,4BAA6B,SAAQ,oBAAoB;gBACxD,EAAE,EAAE,SAAS;CAG1B"}
@@ -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":";;;AACA,yCAAqD;AAErD,MAAa,4BAA6B,SAAQ,4BAAoB;IACpE,YAAY,EAAa;QACvB,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC;CACF;AAJD,oEAIC"}
@@ -0,0 +1,17 @@
1
+ import { Serializer, Store } from "@ddd-ts/model";
2
+ import { CollectionReference, Firestore, FirestoreDataConverter, DocumentData, Transaction } from "firebase-admin/firestore";
3
+ export declare class FirestoreStore<Model, Id extends {
4
+ toString(): string;
5
+ }> implements Store<Model, Id> {
6
+ readonly collection: string;
7
+ readonly firestore: Firestore;
8
+ readonly serializer: Serializer<Model>;
9
+ readonly converter?: FirestoreDataConverter<DocumentData> | undefined;
10
+ _collection: CollectionReference;
11
+ constructor(collection: string, firestore: Firestore, serializer: Serializer<Model>, converter?: FirestoreDataConverter<DocumentData> | undefined);
12
+ save(model: Model, trx?: Transaction): Promise<void>;
13
+ load(id: Id, trx?: Transaction): Promise<Model | undefined>;
14
+ loadAll(): Promise<Model[]>;
15
+ delete(id: Id): Promise<void>;
16
+ }
17
+ //# 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,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,sBAAsB,EACtB,YAAY,EACZ,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAElC,qBAAa,cAAc,CAAC,KAAK,EAAE,EAAE,SAAS;IAAE,QAAQ,IAAI,MAAM,CAAA;CAAE,CAClE,YAAW,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;aAKT,UAAU,EAAE,MAAM;aAClB,SAAS,EAAE,SAAS;aACpB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;aAC7B,SAAS,CAAC;IAN5B,WAAW,EAAE,mBAAmB,CAAC;gBAGf,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,EAC7B,SAAS,CAAC,kDAAsC;IAW5D,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IASpD,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAY3D,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAO3B,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirestoreStore = void 0;
4
+ class FirestoreStore {
5
+ collection;
6
+ firestore;
7
+ serializer;
8
+ converter;
9
+ _collection;
10
+ constructor(collection, firestore, serializer, converter) {
11
+ this.collection = collection;
12
+ this.firestore = firestore;
13
+ this.serializer = serializer;
14
+ this.converter = converter;
15
+ if (this.converter) {
16
+ this._collection = this.firestore
17
+ .collection(collection)
18
+ .withConverter(this.converter);
19
+ }
20
+ else {
21
+ this._collection = this.firestore.collection(collection);
22
+ }
23
+ }
24
+ async save(model, trx) {
25
+ const serialized = await this.serializer.serialize(model);
26
+ const ref = this._collection.doc(this.serializer.getIdFromModel(model).toString());
27
+ trx ? trx.set(ref, serialized) : await ref.set(serialized);
28
+ }
29
+ async load(id, trx) {
30
+ const ref = this._collection.doc(id.toString());
31
+ const snapshot = trx ? await trx.get(ref) : await ref.get();
32
+ if (!snapshot.exists) {
33
+ return undefined;
34
+ }
35
+ return this.serializer.deserialize(snapshot.data());
36
+ }
37
+ async loadAll() {
38
+ const snapshot = await this._collection.get();
39
+ return Promise.all(snapshot.docs.map((doc) => this.serializer.deserialize(doc.data())));
40
+ }
41
+ async delete(id) {
42
+ await this._collection.doc(id.toString()).delete();
43
+ }
44
+ }
45
+ exports.FirestoreStore = FirestoreStore;
46
+ //# sourceMappingURL=firestore.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore.store.js","sourceRoot":"","sources":["../src/firestore.store.ts"],"names":[],"mappings":";;;AASA,MAAa,cAAc;IAMP;IACA;IACA;IACA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QAAQ,CAAC,MAAM,EAAE;YACpB,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAS,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;QAC9C,OAAO,OAAO,CAAC,GAAG,CAChB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAS,CAAC,CAAC,CAC3E,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAM;QACjB,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IACrD,CAAC;CACF;AAnDD,wCAmDC"}
@@ -0,0 +1,3 @@
1
+ export { FirestoreStore } from "./firestore.store";
2
+ export { FirebaseTransactionPerformer } from "./firebase.transaction";
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,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirebaseTransactionPerformer = exports.FirestoreStore = void 0;
4
+ var firestore_store_1 = require("./firestore.store");
5
+ Object.defineProperty(exports, "FirestoreStore", { enumerable: true, get: function () { return firestore_store_1.FirestoreStore; } });
6
+ var firebase_transaction_1 = require("./firebase.transaction");
7
+ Object.defineProperty(exports, "FirebaseTransactionPerformer", { enumerable: true, get: function () { return firebase_transaction_1.FirebaseTransactionPerformer; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,+DAAsE;AAA7D,oIAAA,4BAA4B,OAAA"}
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@ddd-ts/store-firestore",
3
+ "version": "0.0.0-feat.kraaft.1445e26",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "build": "builder"
9
+ },
10
+ "dependencies": {
11
+ "@ddd-ts/model": "*",
12
+ "firebase-admin": "^11.5.0"
13
+ },
14
+ "devDependencies": {
15
+ "@ddd-ts/dev": "*",
16
+ "@ddd-ts/types": "*"
17
+ }
18
+ }