@naturalcycles/firestore-lib 1.6.1 → 1.7.0

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.
@@ -1,5 +1,5 @@
1
1
  import { Firestore, Query, Transaction } from '@google-cloud/firestore';
2
- import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBSupport, DBQuery, DBTransaction, DBTransactionFn, RunQueryResult } from '@naturalcycles/db-lib';
2
+ import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBSupport, CommonDBTransactionOptions, DBQuery, DBTransaction, DBTransactionFn, RunQueryResult } from '@naturalcycles/db-lib';
3
3
  import { ObjectWithId, AnyObjectWithId } from '@naturalcycles/js-lib';
4
4
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
5
  export interface FirestoreDBCfg {
@@ -25,7 +25,7 @@ export declare class FirestoreDB extends BaseCommonDB implements CommonDB {
25
25
  deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<number>;
26
26
  deleteByIds(table: string, ids: string[], opt?: FirestoreDBOptions): Promise<number>;
27
27
  private querySnapshotToArray;
28
- runInTransaction(fn: DBTransactionFn): Promise<void>;
28
+ runInTransaction(fn: DBTransactionFn, opt?: CommonDBTransactionOptions): Promise<void>;
29
29
  ping(): Promise<void>;
30
30
  getTables(): Promise<string[]>;
31
31
  }
@@ -149,11 +149,14 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
149
149
  });
150
150
  return rows;
151
151
  }
152
- async runInTransaction(fn) {
152
+ async runInTransaction(fn, opt = {}) {
153
+ const { readOnly } = opt;
153
154
  try {
154
155
  await this.cfg.firestore.runTransaction(async (firestoreTx) => {
155
156
  const tx = new FirestoreDBTransaction(this, firestoreTx);
156
157
  await fn(tx);
158
+ }, {
159
+ readOnly,
157
160
  });
158
161
  }
159
162
  catch (err) {
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "engines": {
38
38
  "node": ">=18.12.0"
39
39
  },
40
- "version": "1.6.1",
40
+ "version": "1.7.0",
41
41
  "description": "Firestore implementation of CommonDB interface",
42
42
  "author": "Natural Cycles Team",
43
43
  "license": "MIT"
@@ -14,6 +14,7 @@ import {
14
14
  CommonDBSaveOptions,
15
15
  CommonDBStreamOptions,
16
16
  CommonDBSupport,
17
+ CommonDBTransactionOptions,
17
18
  DBQuery,
18
19
  DBTransaction,
19
20
  DBTransactionFn,
@@ -272,12 +273,22 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
272
273
  return rows
273
274
  }
274
275
 
275
- override async runInTransaction(fn: DBTransactionFn): Promise<void> {
276
+ override async runInTransaction(
277
+ fn: DBTransactionFn,
278
+ opt: CommonDBTransactionOptions = {},
279
+ ): Promise<void> {
280
+ const { readOnly } = opt
281
+
276
282
  try {
277
- await this.cfg.firestore.runTransaction(async firestoreTx => {
278
- const tx = new FirestoreDBTransaction(this, firestoreTx)
279
- await fn(tx)
280
- })
283
+ await this.cfg.firestore.runTransaction(
284
+ async firestoreTx => {
285
+ const tx = new FirestoreDBTransaction(this, firestoreTx)
286
+ await fn(tx)
287
+ },
288
+ {
289
+ readOnly,
290
+ },
291
+ )
281
292
  } catch (err) {
282
293
  if (err instanceof RollbackError) {
283
294
  // RollbackError should be handled gracefully (not re-throw)