@ddd-ts/store-firestore 0.0.0-feat.june-improvements.c0df263

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,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,4BAAmD;IACnG,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,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirestoreStore = void 0;
4
+ class FirestoreStore {
5
+ collectionName;
6
+ firestore;
7
+ serializer;
8
+ converter;
9
+ collection;
10
+ constructor(collectionName, firestore, serializer, converter) {
11
+ this.collectionName = collectionName;
12
+ this.firestore = firestore;
13
+ this.serializer = serializer;
14
+ this.converter = converter;
15
+ if (this.converter) {
16
+ this.collection = this.firestore
17
+ .collection(collectionName)
18
+ .withConverter(this.converter);
19
+ }
20
+ else {
21
+ this.collection = this.firestore.collection(collectionName);
22
+ }
23
+ }
24
+ async executeQuery(query, trx) {
25
+ const result = trx ? await trx.get(query) : await query.get();
26
+ return Promise.all(result.docs.map((doc) => this.serializer.deserialize({ id: doc.id, ...doc.data() })));
27
+ }
28
+ async *streamQuery(query) {
29
+ const stream = query.stream();
30
+ for await (const doc of stream) {
31
+ yield this.serializer.deserialize({ id: doc.id, ...doc.data() });
32
+ }
33
+ }
34
+ async save(model, trx) {
35
+ const serialized = await this.serializer.serialize(model);
36
+ const ref = this.collection.doc(model.id.toString());
37
+ trx ? trx.set(ref, serialized) : await ref.set(serialized);
38
+ }
39
+ async load(id, trx) {
40
+ const ref = this.collection.doc(id.toString());
41
+ const snapshot = trx ? await trx.get(ref) : await ref.get();
42
+ if (!snapshot.exists) {
43
+ return undefined;
44
+ }
45
+ return this.serializer.deserialize({
46
+ id: id.toString(),
47
+ ...snapshot.data(),
48
+ });
49
+ }
50
+ async loadAll() {
51
+ const snapshot = await this.collection.get();
52
+ return Promise.all(snapshot.docs.map((doc) => this.serializer.deserialize({ id: doc.id, ...doc.data() })));
53
+ }
54
+ async delete(id, trx) {
55
+ if (trx) {
56
+ trx.delete(this.collection.doc(id.toString()));
57
+ }
58
+ else {
59
+ await this.collection.doc(id.toString()).delete();
60
+ }
61
+ }
62
+ }
63
+ exports.FirestoreStore = FirestoreStore;
64
+ //# sourceMappingURL=firestore.store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore.store.js","sourceRoot":"","sources":["../src/firestore.store.ts"],"names":[],"mappings":";;;AAUA,MAAa,cAAc;IAMP;IACA;IACA;IAIA;IATlB,UAAU,CAAsB;IAEhC,YACkB,cAAsB,EACtB,SAAoB,EACpB,UAGf,EACe,SAAgD;QANhD,mBAAc,GAAd,cAAc,CAAQ;QACtB,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAGzB;QACe,cAAS,GAAT,SAAS,CAAuC;QAEhE,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS;iBAC7B,UAAU,CAAC,cAAc,CAAC;iBAC1B,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAClC;aAAM;YACL,IAAI,CAA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/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,20 @@
1
+ {
2
+ "name": "@ddd-ts/store-firestore",
3
+ "version": "0.0.0-feat.june-improvements.c0df263",
4
+ "main": "dist/index.js",
5
+ "types": "src/index.ts",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "build": "builder"
9
+ },
10
+ "dependencies": {
11
+ "firebase-admin": "^11.5.0"
12
+ },
13
+ "peerDependencies": {
14
+ "@ddd-ts/model": "*"
15
+ },
16
+ "devDependencies": {
17
+ "@ddd-ts/dev": "*",
18
+ "@ddd-ts/types": "*"
19
+ }
20
+ }