@naturalcycles/firestore-lib 1.3.0 → 1.4.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.db.d.ts +1 -1
- package/dist/firestore.db.js +9 -4
- package/package.json +1 -1
- package/src/firestore.db.ts +20 -14
package/dist/firestore.db.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
15
15
|
getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], _opt?: FirestoreDBOptions): Promise<ROW[]>;
|
|
16
16
|
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<RunQueryResult<ROW>>;
|
|
17
17
|
runFirestoreQuery<ROW extends ObjectWithId>(q: Query, _opt?: FirestoreDBOptions): Promise<ROW[]>;
|
|
18
|
-
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>,
|
|
18
|
+
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: FirestoreDBOptions): Promise<number>;
|
|
19
19
|
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
|
|
20
20
|
saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: FirestoreDBSaveOptions<ROW>): Promise<void>;
|
|
21
21
|
deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<number>;
|
package/dist/firestore.db.js
CHANGED
|
@@ -52,18 +52,23 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
|
|
|
52
52
|
async runFirestoreQuery(q, _opt) {
|
|
53
53
|
return this.querySnapshotToArray(await q.get());
|
|
54
54
|
}
|
|
55
|
-
async runQueryCount(q,
|
|
56
|
-
const
|
|
57
|
-
|
|
55
|
+
async runQueryCount(q, _opt) {
|
|
56
|
+
const firestoreQuery = (0, query_util_1.dbQueryToFirestoreQuery)(q, this.cfg.firestore.collection(q.table));
|
|
57
|
+
const r = await firestoreQuery.count().get();
|
|
58
|
+
return r.data().count;
|
|
58
59
|
}
|
|
59
60
|
streamQuery(q, _opt) {
|
|
60
61
|
const firestoreQuery = (0, query_util_1.dbQueryToFirestoreQuery)(q, this.cfg.firestore.collection(q.table));
|
|
61
|
-
|
|
62
|
+
const stream = firestoreQuery
|
|
63
|
+
.stream()
|
|
64
|
+
.on('error', err => stream.emit('error', err))
|
|
65
|
+
.pipe((0, nodejs_lib_1.transformMapSimple)(doc => ({
|
|
62
66
|
id: (0, firestore_util_1.unescapeDocId)(doc.id),
|
|
63
67
|
...doc.data(),
|
|
64
68
|
}), {
|
|
65
69
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // because .pipe cannot propagate errors
|
|
66
70
|
}));
|
|
71
|
+
return stream;
|
|
67
72
|
}
|
|
68
73
|
// SAVE
|
|
69
74
|
async saveBatch(table, rows, opt = {}) {
|
package/package.json
CHANGED
package/src/firestore.db.ts
CHANGED
|
@@ -98,10 +98,11 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
98
98
|
|
|
99
99
|
override async runQueryCount<ROW extends ObjectWithId>(
|
|
100
100
|
q: DBQuery<ROW>,
|
|
101
|
-
|
|
101
|
+
_opt?: FirestoreDBOptions,
|
|
102
102
|
): Promise<number> {
|
|
103
|
-
const
|
|
104
|
-
|
|
103
|
+
const firestoreQuery = dbQueryToFirestoreQuery(q, this.cfg.firestore.collection(q.table))
|
|
104
|
+
const r = await firestoreQuery.count().get()
|
|
105
|
+
return r.data().count
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
override streamQuery<ROW extends ObjectWithId>(
|
|
@@ -110,17 +111,22 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
110
111
|
): ReadableTyped<ROW> {
|
|
111
112
|
const firestoreQuery = dbQueryToFirestoreQuery(q, this.cfg.firestore.collection(q.table))
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
const stream: ReadableTyped<ROW> = firestoreQuery
|
|
115
|
+
.stream()
|
|
116
|
+
.on('error', err => stream.emit('error', err))
|
|
117
|
+
.pipe(
|
|
118
|
+
transformMapSimple<QueryDocumentSnapshot<any>, ROW>(
|
|
119
|
+
doc => ({
|
|
120
|
+
id: unescapeDocId(doc.id),
|
|
121
|
+
...doc.data(),
|
|
122
|
+
}),
|
|
123
|
+
{
|
|
124
|
+
errorMode: ErrorMode.SUPPRESS, // because .pipe cannot propagate errors
|
|
125
|
+
},
|
|
126
|
+
),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
return stream
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
// SAVE
|