@naturalcycles/firestore-lib 2.21.0 → 2.22.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,6 +1,6 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import { FieldPath } from '@google-cloud/firestore';
3
- import { localTime } from '@naturalcycles/js-lib/datetime';
3
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime';
4
4
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
5
5
  import { _assert } from '@naturalcycles/js-lib/error/assert.js';
6
6
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
@@ -76,7 +76,7 @@ export class FirestoreShardedReadable extends Readable {
76
76
  return;
77
77
  const { logger, table } = this;
78
78
  if (this.lastQueryDoneByShard[shard]) {
79
- this.totalWait += Date.now() - this.lastQueryDoneByShard[shard];
79
+ this.totalWait += nowUnixMillis() - this.lastQueryDoneByShard[shard];
80
80
  }
81
81
  this.queryIsRunningByShard[shard] = true;
82
82
  const limit = this.opt.batchSize;
@@ -107,7 +107,7 @@ export class FirestoreShardedReadable extends Readable {
107
107
  logger.debug(`${table} got ${rows.length} rows, ${this.rowsRetrieved} rowsRetrieved, totalWait: ${_ms(this.totalWait)}`);
108
108
  this.cursorByShard[shard] = lastDocId;
109
109
  this.queryIsRunningByShard[shard] = false; // ready to take more _reads
110
- this.lastQueryDoneByShard[shard] = localTime.nowUnixMillis();
110
+ this.lastQueryDoneByShard[shard] = nowUnixMillis();
111
111
  for (const row of rows) {
112
112
  this.push(row);
113
113
  }
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import { FieldPath } from '@google-cloud/firestore';
3
- import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
3
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/localTime.js';
4
4
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
5
5
  import { TimeoutError } from '@naturalcycles/js-lib/error/error.util.js';
6
6
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
@@ -89,9 +89,9 @@ export class FirestoreStreamReadable extends Readable {
89
89
  // rowsRetrieved: this.rowsRetrieved,
90
90
  // paused: this.paused,
91
91
  // })
92
- const started = localTime.nowUnixMillis();
92
+ const started = nowUnixMillis();
93
93
  const qs = await this.runQuery(q);
94
- const queryTook = Date.now() - started;
94
+ const queryTook = nowUnixMillis() - started;
95
95
  if (!qs) {
96
96
  // error already emitted in runQuery
97
97
  return;
@@ -1,11 +1,12 @@
1
1
  import { FieldPath, Timestamp } from '@google-cloud/firestore';
2
2
  import { _round } from '@naturalcycles/js-lib';
3
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/localTime.js';
3
4
  export function readAtToReadTime(opt) {
4
5
  if (!opt.readAt)
5
6
  return;
6
7
  // Same logic as Datastore: round to whole minutes, guard against future
7
8
  let readTimeMs = _round(opt.readAt, 60) * 1000;
8
- if (readTimeMs >= Date.now() - 1000) {
9
+ if (readTimeMs >= nowUnixMillis() - 1000) {
9
10
  readTimeMs -= 60_000;
10
11
  }
11
12
  return Timestamp.fromMillis(readTimeMs);
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "tslib": "^2"
10
10
  },
11
11
  "devDependencies": {
12
- "@naturalcycles/dev-lib": "20.68.0",
12
+ "@naturalcycles/dev-lib": "20.71.0",
13
13
  "@types/node": "^26",
14
14
  "typescript": "^7",
15
15
  "firebase-admin": "^14"
@@ -38,7 +38,7 @@
38
38
  "engines": {
39
39
  "node": ">=26.12.1"
40
40
  },
41
- "version": "2.21.0",
41
+ "version": "2.22.0",
42
42
  "description": "Firestore implementation of CommonDB interface",
43
43
  "author": "Natural Cycles Team",
44
44
  "license": "MIT",
@@ -2,7 +2,7 @@ import { Readable } from 'node:stream'
2
2
  import { FieldPath } from '@google-cloud/firestore'
3
3
  import type { Query, QuerySnapshot } from '@google-cloud/firestore'
4
4
  import type { DBQuery } from '@naturalcycles/db-lib'
5
- import { localTime } from '@naturalcycles/js-lib/datetime'
5
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime'
6
6
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
7
7
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
8
8
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
@@ -107,7 +107,7 @@ export class FirestoreShardedReadable<T extends ObjectWithId = any>
107
107
  const { logger, table } = this
108
108
 
109
109
  if (this.lastQueryDoneByShard[shard]) {
110
- this.totalWait += Date.now() - this.lastQueryDoneByShard[shard]
110
+ this.totalWait += nowUnixMillis() - this.lastQueryDoneByShard[shard]
111
111
  }
112
112
 
113
113
  this.queryIsRunningByShard[shard] = true
@@ -151,7 +151,7 @@ export class FirestoreShardedReadable<T extends ObjectWithId = any>
151
151
 
152
152
  this.cursorByShard[shard] = lastDocId
153
153
  this.queryIsRunningByShard[shard] = false // ready to take more _reads
154
- this.lastQueryDoneByShard[shard] = localTime.nowUnixMillis()
154
+ this.lastQueryDoneByShard[shard] = nowUnixMillis()
155
155
 
156
156
  for (const row of rows) {
157
157
  this.push(row)
@@ -7,7 +7,7 @@ import type {
7
7
  Timestamp,
8
8
  } from '@google-cloud/firestore'
9
9
  import type { DBQuery } from '@naturalcycles/db-lib'
10
- import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
10
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/localTime.js'
11
11
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
12
12
  import { TimeoutError } from '@naturalcycles/js-lib/error/error.util.js'
13
13
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
@@ -125,9 +125,9 @@ export class FirestoreStreamReadable<T extends ObjectWithId = any>
125
125
  // paused: this.paused,
126
126
  // })
127
127
 
128
- const started = localTime.nowUnixMillis()
128
+ const started = nowUnixMillis()
129
129
  const qs = await this.runQuery(q)
130
- const queryTook = Date.now() - started
130
+ const queryTook = nowUnixMillis() - started
131
131
  if (!qs) {
132
132
  // error already emitted in runQuery
133
133
  return
package/src/query.util.ts CHANGED
@@ -2,6 +2,7 @@ import { FieldPath, Timestamp } from '@google-cloud/firestore'
2
2
  import type { Query, WhereFilterOp } from '@google-cloud/firestore'
3
3
  import type { CommonDBReadOptions, DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
4
4
  import { _round } from '@naturalcycles/js-lib'
5
+ import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/localTime.js'
5
6
  import type { ObjectWithId } from '@naturalcycles/js-lib/types'
6
7
 
7
8
  export function readAtToReadTime(opt: CommonDBReadOptions): Timestamp | undefined {
@@ -9,7 +10,7 @@ export function readAtToReadTime(opt: CommonDBReadOptions): Timestamp | undefine
9
10
 
10
11
  // Same logic as Datastore: round to whole minutes, guard against future
11
12
  let readTimeMs = _round(opt.readAt, 60) * 1000
12
- if (readTimeMs >= Date.now() - 1000) {
13
+ if (readTimeMs >= nowUnixMillis() - 1000) {
13
14
  readTimeMs -= 60_000
14
15
  }
15
16