@naturalcycles/firestore-lib 1.1.11 → 1.1.12
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
CHANGED
|
@@ -12,15 +12,15 @@ export interface FirestoreDBSaveOptions<ROW extends ObjectWithId = AnyObjectWith
|
|
|
12
12
|
export declare class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
13
13
|
cfg: FirestoreDBCfg;
|
|
14
14
|
constructor(cfg: FirestoreDBCfg);
|
|
15
|
-
getByIds<ROW extends ObjectWithId>(table: string, ids:
|
|
16
|
-
getById<ROW extends ObjectWithId>(table: string, id:
|
|
15
|
+
getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: FirestoreDBOptions): Promise<ROW[]>;
|
|
16
|
+
getById<ROW extends ObjectWithId>(table: string, id: ROW['id'], _opt?: FirestoreDBOptions): Promise<ROW | null>;
|
|
17
17
|
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<RunQueryResult<ROW>>;
|
|
18
18
|
runFirestoreQuery<ROW extends ObjectWithId>(q: Query, _opt?: FirestoreDBOptions): Promise<ROW[]>;
|
|
19
19
|
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<number>;
|
|
20
20
|
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
|
|
21
21
|
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], _opt?: FirestoreDBSaveOptions<ROW>): Promise<void>;
|
|
22
22
|
deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<number>;
|
|
23
|
-
deleteByIds(table: string, ids:
|
|
23
|
+
deleteByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], _opt?: FirestoreDBOptions): Promise<number>;
|
|
24
24
|
private querySnapshotToArray;
|
|
25
25
|
commitTransaction(_tx: DBTransaction, _opt?: CommonDBSaveOptions): Promise<void>;
|
|
26
26
|
ping(): Promise<void>;
|
package/dist/firestore.db.js
CHANGED
|
@@ -21,7 +21,7 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
|
|
|
21
21
|
const doc = await this.cfg.firestore.collection(table).doc((0, firestore_util_1.escapeDocId)(id)).get();
|
|
22
22
|
const data = doc.data();
|
|
23
23
|
if (data === undefined)
|
|
24
|
-
return;
|
|
24
|
+
return null;
|
|
25
25
|
return {
|
|
26
26
|
id,
|
|
27
27
|
...data,
|
package/dist/firestore.util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function escapeDocId(docId: string): string;
|
|
1
|
+
export declare function escapeDocId(docId: string | number): string;
|
|
2
2
|
export declare function unescapeDocId(docId: string): string;
|
package/dist/firestore.util.js
CHANGED
|
@@ -4,10 +4,13 @@ exports.unescapeDocId = exports.escapeDocId = void 0;
|
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const SLASH = '_SLASH_';
|
|
6
6
|
function escapeDocId(docId) {
|
|
7
|
+
if (typeof docId === 'number')
|
|
8
|
+
return String(docId);
|
|
7
9
|
return (0, js_lib_1._replaceAll)(docId, '/', SLASH);
|
|
8
10
|
}
|
|
9
11
|
exports.escapeDocId = escapeDocId;
|
|
10
12
|
function unescapeDocId(docId) {
|
|
13
|
+
// if (typeof docId === 'number') return docId
|
|
11
14
|
return (0, js_lib_1._replaceAll)(docId, SLASH, '/');
|
|
12
15
|
}
|
|
13
16
|
exports.unescapeDocId = unescapeDocId;
|
package/package.json
CHANGED
package/src/firestore.db.ts
CHANGED
|
@@ -38,7 +38,7 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
38
38
|
// GET
|
|
39
39
|
override async getByIds<ROW extends ObjectWithId>(
|
|
40
40
|
table: string,
|
|
41
|
-
ids:
|
|
41
|
+
ids: ROW['id'][],
|
|
42
42
|
opt?: FirestoreDBOptions,
|
|
43
43
|
): Promise<ROW[]> {
|
|
44
44
|
// Oj, doesn't look like a very optimal implementation!
|
|
@@ -50,13 +50,13 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
50
50
|
|
|
51
51
|
async getById<ROW extends ObjectWithId>(
|
|
52
52
|
table: string,
|
|
53
|
-
id:
|
|
53
|
+
id: ROW['id'],
|
|
54
54
|
_opt?: FirestoreDBOptions,
|
|
55
|
-
): Promise<ROW |
|
|
55
|
+
): Promise<ROW | null> {
|
|
56
56
|
const doc = await this.cfg.firestore.collection(table).doc(escapeDocId(id)).get()
|
|
57
57
|
|
|
58
58
|
const data = doc.data()
|
|
59
|
-
if (data === undefined) return
|
|
59
|
+
if (data === undefined) return null
|
|
60
60
|
|
|
61
61
|
return {
|
|
62
62
|
id,
|
|
@@ -156,9 +156,9 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
156
156
|
return ids.length
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
override async deleteByIds(
|
|
159
|
+
override async deleteByIds<ROW extends ObjectWithId>(
|
|
160
160
|
table: string,
|
|
161
|
-
ids:
|
|
161
|
+
ids: ROW['id'][],
|
|
162
162
|
_opt?: FirestoreDBOptions,
|
|
163
163
|
): Promise<number> {
|
|
164
164
|
await pMap(_chunk(ids, 500), async chunk => {
|
package/src/firestore.util.ts
CHANGED
|
@@ -2,10 +2,12 @@ import { _replaceAll } from '@naturalcycles/js-lib'
|
|
|
2
2
|
|
|
3
3
|
const SLASH = '_SLASH_'
|
|
4
4
|
|
|
5
|
-
export function escapeDocId(docId: string): string {
|
|
5
|
+
export function escapeDocId(docId: string | number): string {
|
|
6
|
+
if (typeof docId === 'number') return String(docId)
|
|
6
7
|
return _replaceAll(docId, '/', SLASH)
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export function unescapeDocId(docId: string): string {
|
|
11
|
+
// if (typeof docId === 'number') return docId
|
|
10
12
|
return _replaceAll(docId, SLASH, '/')
|
|
11
13
|
}
|