@naturalcycles/firestore-lib 2.14.2 → 2.14.4
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.js +5 -5
- package/dist/firestoreShardedReadable.d.ts +1 -1
- package/dist/firestoreStreamReadable.d.ts +1 -1
- package/dist/firestoreStreamReadable.js +4 -2
- package/dist/query.util.d.ts +1 -1
- package/dist/query.util.js +1 -4
- package/package.json +3 -2
- package/src/firestore.db.ts +2 -1
- package/src/firestoreShardedReadable.ts +4 -2
- package/src/firestoreStreamReadable.ts +8 -8
- package/src/query.util.ts +2 -1
package/dist/firestore.db.js
CHANGED
|
@@ -128,7 +128,7 @@ export class FirestoreDB extends BaseCommonDB {
|
|
|
128
128
|
}
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
|
-
await pMap(_chunk(rows, MAX_ITEMS), async
|
|
131
|
+
await pMap(_chunk(rows, MAX_ITEMS), async chunk => {
|
|
132
132
|
// .batch is called "Atomic batch writer"
|
|
133
133
|
// Executes multiple writes in a single atomic transaction-like commit — all succeed or all fail.
|
|
134
134
|
// If any write in the batch fails (e.g., permission error, missing doc), the whole batch fails.
|
|
@@ -163,7 +163,7 @@ export class FirestoreDB extends BaseCommonDB {
|
|
|
163
163
|
tableRows.push([table, row]);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
await pMap(_chunk(tableRows, MAX_ITEMS), async
|
|
166
|
+
await pMap(_chunk(tableRows, MAX_ITEMS), async chunk => {
|
|
167
167
|
const batch = firestore.batch();
|
|
168
168
|
for (const [table, row] of chunk) {
|
|
169
169
|
_assert(row.id, `firestore-db doesn't support id auto-generation, but empty id was provided in multiSaveBatch`);
|
|
@@ -207,7 +207,7 @@ export class FirestoreDB extends BaseCommonDB {
|
|
|
207
207
|
}
|
|
208
208
|
return ids.length;
|
|
209
209
|
}
|
|
210
|
-
await pMap(_chunk(ids, MAX_ITEMS), async
|
|
210
|
+
await pMap(_chunk(ids, MAX_ITEMS), async chunk => {
|
|
211
211
|
const batch = firestore.batch();
|
|
212
212
|
for (const id of chunk) {
|
|
213
213
|
batch.delete(col.doc(escapeDocId(id)));
|
|
@@ -230,7 +230,7 @@ export class FirestoreDB extends BaseCommonDB {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
233
|
-
await pMap(_chunk(refs, MAX_ITEMS), async
|
|
233
|
+
await pMap(_chunk(refs, MAX_ITEMS), async chunk => {
|
|
234
234
|
const batch = firestore.batch();
|
|
235
235
|
for (const ref of chunk) {
|
|
236
236
|
batch.delete(ref);
|
|
@@ -249,7 +249,7 @@ export class FirestoreDB extends BaseCommonDB {
|
|
|
249
249
|
async runInTransaction(fn, opt = {}) {
|
|
250
250
|
const { readOnly } = opt;
|
|
251
251
|
try {
|
|
252
|
-
await this.cfg.firestore.runTransaction(async
|
|
252
|
+
await this.cfg.firestore.runTransaction(async firestoreTx => {
|
|
253
253
|
const tx = new FirestoreDBTransaction(this, firestoreTx);
|
|
254
254
|
await fn(tx);
|
|
255
255
|
}, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import {
|
|
2
|
+
import type { Query } from '@google-cloud/firestore';
|
|
3
3
|
import type { DBQuery } from '@naturalcycles/db-lib';
|
|
4
4
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types';
|
|
5
5
|
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import {
|
|
2
|
+
import type { Query } from '@google-cloud/firestore';
|
|
3
3
|
import type { DBQuery } from '@naturalcycles/db-lib';
|
|
4
4
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types';
|
|
5
5
|
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import { FieldPath
|
|
2
|
+
import { FieldPath } from '@google-cloud/firestore';
|
|
3
3
|
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
|
|
4
4
|
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
5
|
+
import { TimeoutError } from '@naturalcycles/js-lib/error/error.util.js';
|
|
5
6
|
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
|
|
6
7
|
import { pRetry } from '@naturalcycles/js-lib/promise/pRetry.js';
|
|
7
8
|
import { unescapeDocId } from './firestore.util.js';
|
|
@@ -137,7 +138,8 @@ export class FirestoreStreamReadable extends Readable {
|
|
|
137
138
|
return await q.get();
|
|
138
139
|
}, {
|
|
139
140
|
name: `FirestoreStreamReadable.query(${table})`,
|
|
140
|
-
predicate: err =>
|
|
141
|
+
predicate: err => err instanceof TimeoutError ||
|
|
142
|
+
RETRY_ON.some(s => err?.message?.toLowerCase()?.includes(s)),
|
|
141
143
|
maxAttempts: 5,
|
|
142
144
|
delay: 5000,
|
|
143
145
|
delayMultiplier: 2,
|
package/dist/query.util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Query } from '@google-cloud/firestore';
|
|
2
2
|
import type { DBQuery } from '@naturalcycles/db-lib';
|
|
3
3
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types';
|
|
4
4
|
export declare function dbQueryToFirestoreQuery<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, emptyQuery: Query): Query;
|
package/dist/query.util.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { FieldPath } from '@google-cloud/firestore';
|
|
2
2
|
// Map DBQueryFilterOp to WhereFilterOp
|
|
3
3
|
// Currently it's fully aligned!
|
|
4
|
-
const OP_MAP = {
|
|
5
|
-
// '=': '==',
|
|
6
|
-
// in: 'array-contains',
|
|
7
|
-
};
|
|
4
|
+
const OP_MAP = {};
|
|
8
5
|
export function dbQueryToFirestoreQuery(dbQuery, emptyQuery) {
|
|
9
6
|
let q = emptyQuery;
|
|
10
7
|
// filter
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@naturalcycles/firestore-lib",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@google-cloud/firestore": "^
|
|
5
|
+
"@google-cloud/firestore": "^7",
|
|
6
6
|
"@naturalcycles/db-lib": "^10",
|
|
7
7
|
"@naturalcycles/js-lib": "^15",
|
|
8
8
|
"@naturalcycles/nodejs-lib": "^15",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/node": "^25",
|
|
13
|
+
"@typescript/native-preview": "7.0.0-dev.20260201.1",
|
|
13
14
|
"dotenv": "^17",
|
|
14
15
|
"firebase-admin": "^13",
|
|
15
16
|
"@naturalcycles/dev-lib": "18.4.2"
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"engines": {
|
|
39
40
|
"node": ">=24.10.0"
|
|
40
41
|
},
|
|
41
|
-
"version": "2.14.
|
|
42
|
+
"version": "2.14.4",
|
|
42
43
|
"description": "Firestore implementation of CommonDB interface",
|
|
43
44
|
"author": "Natural Cycles Team",
|
|
44
45
|
"license": "MIT",
|
package/src/firestore.db.ts
CHANGED
|
@@ -30,7 +30,8 @@ import { _filterUndefinedValues, _omit } from '@naturalcycles/js-lib/object/obje
|
|
|
30
30
|
import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
|
|
31
31
|
import type { ObjectWithId, PositiveInteger, StringMap } from '@naturalcycles/js-lib/types'
|
|
32
32
|
import { _stringMapEntries } from '@naturalcycles/js-lib/types'
|
|
33
|
-
import { Pipeline
|
|
33
|
+
import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
|
|
34
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
34
35
|
import { escapeDocId, unescapeDocId } from './firestore.util.js'
|
|
35
36
|
import { FirestoreShardedReadable } from './firestoreShardedReadable.js'
|
|
36
37
|
import { FirestoreStreamReadable } from './firestoreStreamReadable.js'
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import { FieldPath
|
|
2
|
+
import { FieldPath } from '@google-cloud/firestore'
|
|
3
|
+
import type { Query, QuerySnapshot } from '@google-cloud/firestore'
|
|
3
4
|
import type { DBQuery } from '@naturalcycles/db-lib'
|
|
4
5
|
import { localTime } from '@naturalcycles/js-lib/datetime'
|
|
5
6
|
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
6
|
-
import {
|
|
7
|
+
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
|
|
8
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
7
9
|
import { pRetry } from '@naturalcycles/js-lib/promise/pRetry.js'
|
|
8
10
|
import type {
|
|
9
11
|
ObjectWithId,
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type Query,
|
|
5
|
-
type QueryDocumentSnapshot,
|
|
6
|
-
type QuerySnapshot,
|
|
7
|
-
} from '@google-cloud/firestore'
|
|
2
|
+
import { FieldPath } from '@google-cloud/firestore'
|
|
3
|
+
import type { Query, QueryDocumentSnapshot, QuerySnapshot } from '@google-cloud/firestore'
|
|
8
4
|
import type { DBQuery } from '@naturalcycles/db-lib'
|
|
9
5
|
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
|
|
10
6
|
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
11
|
-
import {
|
|
7
|
+
import { TimeoutError } from '@naturalcycles/js-lib/error/error.util.js'
|
|
8
|
+
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
|
|
9
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
12
10
|
import { pRetry } from '@naturalcycles/js-lib/promise/pRetry.js'
|
|
13
11
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types'
|
|
14
12
|
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
@@ -182,7 +180,9 @@ export class FirestoreStreamReadable<T extends ObjectWithId = any>
|
|
|
182
180
|
},
|
|
183
181
|
{
|
|
184
182
|
name: `FirestoreStreamReadable.query(${table})`,
|
|
185
|
-
predicate: err =>
|
|
183
|
+
predicate: err =>
|
|
184
|
+
err instanceof TimeoutError ||
|
|
185
|
+
RETRY_ON.some(s => err?.message?.toLowerCase()?.includes(s)),
|
|
186
186
|
maxAttempts: 5,
|
|
187
187
|
delay: 5000,
|
|
188
188
|
delayMultiplier: 2,
|
package/src/query.util.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FieldPath
|
|
1
|
+
import { FieldPath } from '@google-cloud/firestore'
|
|
2
|
+
import type { Query, WhereFilterOp } from '@google-cloud/firestore'
|
|
2
3
|
import type { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
|
|
3
4
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types'
|
|
4
5
|
|