@naturalcycles/firestore-lib 2.2.0 → 2.4.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,9 +1,10 @@
1
1
  import { FieldValue } from '@google-cloud/firestore';
2
2
  import { BaseCommonDB, commonDBFullSupport } from '@naturalcycles/db-lib';
3
- import { _chunk, _isTruthy } from '@naturalcycles/js-lib';
4
- import { _assert } from '@naturalcycles/js-lib/error';
5
- import { _filterUndefinedValues, _omit } from '@naturalcycles/js-lib/object';
6
- import { pMap } from '@naturalcycles/js-lib/promise';
3
+ import { _isTruthy } from '@naturalcycles/js-lib';
4
+ import { _chunk } from '@naturalcycles/js-lib/array/array.util.js';
5
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
6
+ import { _filterUndefinedValues, _omit } from '@naturalcycles/js-lib/object/object.util.js';
7
+ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
7
8
  import { _stringMapEntries } from '@naturalcycles/js-lib/types';
8
9
  import { escapeDocId, unescapeDocId } from './firestore.util.js';
9
10
  import { dbQueryToFirestoreQuery } from './query.util.js';
@@ -87,19 +88,19 @@ export class FirestoreDB extends BaseCommonDB {
87
88
  const method = methodMap[opt.saveMethod] || 'set';
88
89
  if (opt.tx) {
89
90
  const { tx } = opt.tx;
90
- rows.forEach(row => {
91
+ for (const row of rows) {
91
92
  _assert(row.id, `firestore-db doesn't support id auto-generation, but empty id was provided in saveBatch`);
92
93
  tx[method](col.doc(escapeDocId(row.id)), _filterUndefinedValues(row));
93
- });
94
+ }
94
95
  return;
95
96
  }
96
97
  // Firestore allows max 500 items in one batch
97
98
  await pMap(_chunk(rows, 500), async (chunk) => {
98
99
  const batch = firestore.batch();
99
- chunk.forEach(row => {
100
+ for (const row of chunk) {
100
101
  _assert(row.id, `firestore-db doesn't support id auto-generation, but empty id was provided in saveBatch`);
101
102
  batch[method](col.doc(escapeDocId(row.id)), _filterUndefinedValues(row));
102
- });
103
+ }
103
104
  await batch.commit();
104
105
  }, { concurrency: 1 });
105
106
  }
@@ -122,16 +123,16 @@ export class FirestoreDB extends BaseCommonDB {
122
123
  const col = firestore.collection(table);
123
124
  if (opt.tx) {
124
125
  const { tx } = opt.tx;
125
- ids.forEach(id => {
126
+ for (const id of ids) {
126
127
  tx.delete(col.doc(escapeDocId(id)));
127
- });
128
+ }
128
129
  return ids.length;
129
130
  }
130
131
  await pMap(_chunk(ids, 500), async (chunk) => {
131
132
  const batch = firestore.batch();
132
- chunk.forEach(id => {
133
+ for (const id of chunk) {
133
134
  batch.delete(col.doc(escapeDocId(id)));
134
- });
135
+ }
135
136
  await batch.commit();
136
137
  });
137
138
  return ids.length;
package/package.json CHANGED
@@ -9,10 +9,10 @@
9
9
  "tslib": "^2"
10
10
  },
11
11
  "devDependencies": {
12
- "@naturalcycles/dev-lib": "*",
13
12
  "@types/node": "^24",
14
13
  "dotenv": "^17",
15
- "firebase-admin": "^13"
14
+ "firebase-admin": "^13",
15
+ "@naturalcycles/dev-lib": "18.4.2"
16
16
  },
17
17
  "exports": {
18
18
  ".": "./dist/index.js"
@@ -38,7 +38,7 @@
38
38
  "engines": {
39
39
  "node": ">=22.12.0"
40
40
  },
41
- "version": "2.2.0",
41
+ "version": "2.4.0",
42
42
  "description": "Firestore implementation of CommonDB interface",
43
43
  "author": "Natural Cycles Team",
44
44
  "license": "MIT",
@@ -20,10 +20,11 @@ import type {
20
20
  RunQueryResult,
21
21
  } from '@naturalcycles/db-lib'
22
22
  import { BaseCommonDB, commonDBFullSupport } from '@naturalcycles/db-lib'
23
- import { _chunk, _isTruthy } from '@naturalcycles/js-lib'
24
- import { _assert } from '@naturalcycles/js-lib/error'
25
- import { _filterUndefinedValues, _omit } from '@naturalcycles/js-lib/object'
26
- import { pMap } from '@naturalcycles/js-lib/promise'
23
+ import { _isTruthy } from '@naturalcycles/js-lib'
24
+ import { _chunk } from '@naturalcycles/js-lib/array/array.util.js'
25
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js'
26
+ import { _filterUndefinedValues, _omit } from '@naturalcycles/js-lib/object/object.util.js'
27
+ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
27
28
  import type { ObjectWithId, StringMap } from '@naturalcycles/js-lib/types'
28
29
  import { _stringMapEntries } from '@naturalcycles/js-lib/types'
29
30
  import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
@@ -158,14 +159,14 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
158
159
  if (opt.tx) {
159
160
  const { tx } = opt.tx as FirestoreDBTransaction
160
161
 
161
- rows.forEach(row => {
162
+ for (const row of rows) {
162
163
  _assert(
163
164
  row.id,
164
165
  `firestore-db doesn't support id auto-generation, but empty id was provided in saveBatch`,
165
166
  )
166
167
 
167
168
  tx[method as 'set' | 'create'](col.doc(escapeDocId(row.id)), _filterUndefinedValues(row))
168
- })
169
+ }
169
170
  return
170
171
  }
171
172
 
@@ -175,7 +176,7 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
175
176
  async chunk => {
176
177
  const batch = firestore.batch()
177
178
 
178
- chunk.forEach(row => {
179
+ for (const row of chunk) {
179
180
  _assert(
180
181
  row.id,
181
182
  `firestore-db doesn't support id auto-generation, but empty id was provided in saveBatch`,
@@ -184,7 +185,7 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
184
185
  col.doc(escapeDocId(row.id)),
185
186
  _filterUndefinedValues(row),
186
187
  )
187
- })
188
+ }
188
189
 
189
190
  await batch.commit()
190
191
  },
@@ -226,18 +227,18 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
226
227
  if (opt.tx) {
227
228
  const { tx } = opt.tx as FirestoreDBTransaction
228
229
 
229
- ids.forEach(id => {
230
+ for (const id of ids) {
230
231
  tx.delete(col.doc(escapeDocId(id)))
231
- })
232
+ }
232
233
  return ids.length
233
234
  }
234
235
 
235
236
  await pMap(_chunk(ids, 500), async chunk => {
236
237
  const batch = firestore.batch()
237
238
 
238
- chunk.forEach(id => {
239
+ for (const id of chunk) {
239
240
  batch.delete(col.doc(escapeDocId(id)))
240
- })
241
+ }
241
242
 
242
243
  await batch.commit()
243
244
  })