@naturalcycles/datastore-lib 3.39.3 → 3.39.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.
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'node:stream';
2
- import { Query } from '@google-cloud/datastore';
3
- import { CommonLogger } from '@naturalcycles/js-lib';
2
+ import type { Query } from '@google-cloud/datastore';
3
+ import type { CommonLogger } from '@naturalcycles/js-lib';
4
4
  import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
5
  import type { DatastoreDBStreamOptions } from './datastore.model';
6
6
  export declare class DatastoreStreamReadable<T = any> extends Readable implements ReadableTyped<T> {
@@ -1,9 +1,9 @@
1
- import type { Datastore, Key } from '@google-cloud/datastore';
2
- import { Transaction } from '@google-cloud/datastore';
3
- import { BaseCommonDB, CommonDB, CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions, CommonDBSupport, CommonDBTransactionOptions, DBQuery, DBTransaction, DBTransactionFn, RunQueryResult } from '@naturalcycles/db-lib';
4
- import { CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
5
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
6
- import { DatastoreDBCfg, DatastoreDBOptions, DatastoreDBReadOptions, DatastoreDBSaveOptions, DatastoreDBStreamOptions, DatastorePropertyStats, DatastoreStats } from './datastore.model';
1
+ import type { Datastore, Key, Transaction } from '@google-cloud/datastore';
2
+ import type { CommonDB, CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions, CommonDBSupport, CommonDBTransactionOptions, DBQuery, DBTransaction, DBTransactionFn, RunQueryResult } from '@naturalcycles/db-lib';
3
+ import { BaseCommonDB } from '@naturalcycles/db-lib';
4
+ import type { CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
5
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
6
+ import type { DatastoreDBCfg, DatastoreDBOptions, DatastoreDBReadOptions, DatastoreDBSaveOptions, DatastoreDBStreamOptions, DatastorePropertyStats, DatastoreStats } from './datastore.model';
7
7
  /**
8
8
  * Datastore API:
9
9
  * https://googlecloudplatform.github.io/google-cloud-node/#/docs/datastore/1.0.3/datastore
@@ -21,6 +21,8 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
21
21
  */
22
22
  protected KEY: symbol;
23
23
  ds(): Datastore;
24
+ private getPropertyFilter;
25
+ private getDatastoreLib;
24
26
  ping(): Promise<void>;
25
27
  getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: DatastoreDBReadOptions): Promise<ROW[]>;
26
28
  runQuery<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, opt?: DatastoreDBReadOptions): Promise<RunQueryResult<ROW>>;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DatastoreDBTransaction = exports.DatastoreDB = void 0;
4
- const datastore_1 = require("@google-cloud/datastore");
5
4
  const db_lib_1 = require("@naturalcycles/db-lib");
6
5
  const js_lib_1 = require("@naturalcycles/js-lib");
7
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
@@ -50,9 +49,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
50
49
  ds() {
51
50
  if (!this.cachedDatastore) {
52
51
  (0, js_lib_1._assert)(process.env['APP_ENV'] !== 'test', 'DatastoreDB cannot be used in Test env, please use InMemoryDB');
53
- // Lazy-loading
54
- const datastoreLib = require('@google-cloud/datastore');
55
- const DS = datastoreLib.Datastore;
52
+ const DS = this.getDatastoreLib().Datastore;
56
53
  this.cfg.projectId ||= this.cfg.credentials?.project_id || process.env['GOOGLE_CLOUD_PROJECT'];
57
54
  if (this.cfg.projectId) {
58
55
  this.cfg.logger.log(`DatastoreDB connected to ${(0, nodejs_lib_1.boldWhite)(this.cfg.projectId)}`);
@@ -68,6 +65,13 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
68
65
  }
69
66
  return this.cachedDatastore;
70
67
  }
68
+ getPropertyFilter() {
69
+ return this.getDatastoreLib().PropertyFilter;
70
+ }
71
+ getDatastoreLib() {
72
+ // Lazy-loading
73
+ return require('@google-cloud/datastore');
74
+ }
71
75
  async ping() {
72
76
  await this.getAllStats();
73
77
  }
@@ -138,7 +142,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
138
142
  rows: await this.getByIds(dbQuery.table, ids, opt),
139
143
  };
140
144
  }
141
- const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery, this.ds().createQuery(dbQuery.table));
145
+ const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery, this.ds().createQuery(dbQuery.table), this.getPropertyFilter());
142
146
  const dsOpt = this.getRunQueryOptions(opt);
143
147
  const qr = await this.runDatastoreQuery(q, dsOpt);
144
148
  // Special case when projection query didn't specify 'id'
@@ -148,7 +152,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
148
152
  return qr;
149
153
  }
150
154
  async runQueryCount(dbQuery, opt = {}) {
151
- const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery.select([]), this.ds().createQuery(dbQuery.table));
155
+ const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery.select([]), this.ds().createQuery(dbQuery.table), this.getPropertyFilter());
152
156
  const aq = this.ds().createAggregationQuery(q).count('count');
153
157
  const dsOpt = this.getRunQueryOptions(opt);
154
158
  const [entities] = await this.ds().runAggregationQuery(aq, dsOpt);
@@ -173,7 +177,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
173
177
  : this.ds().runQueryStream(q, dsOpt)).map(chunk => this.mapId(chunk));
174
178
  }
175
179
  streamQuery(dbQuery, opt) {
176
- const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery, this.ds().createQuery(dbQuery.table));
180
+ const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery, this.ds().createQuery(dbQuery.table), this.getPropertyFilter());
177
181
  return this.runQueryStream(q, opt);
178
182
  }
179
183
  // https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/2-structured-data/books/model-datastore.js
@@ -215,7 +219,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
215
219
  const ids = idFilter.op === '==' ? [idFilter.val] : idFilter.val;
216
220
  return await this.deleteByIds(q.table, ids, opt);
217
221
  }
218
- const datastoreQuery = (0, query_util_1.dbQueryToDatastoreQuery)(q.select([]), this.ds().createQuery(q.table));
222
+ const datastoreQuery = (0, query_util_1.dbQueryToDatastoreQuery)(q.select([]), this.ds().createQuery(q.table), this.getPropertyFilter());
219
223
  const dsOpt = this.getRunQueryOptions(opt);
220
224
  const { rows } = await this.runDatastoreQuery(datastoreQuery, dsOpt);
221
225
  return await this.deleteByIds(q.table, rows.map(obj => obj.id), opt);
@@ -256,10 +260,11 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
256
260
  * Returns undefined e.g when Table is non-existing
257
261
  */
258
262
  async getStats(table) {
263
+ const { PropertyFilter } = this.getDatastoreLib();
259
264
  const q = this.ds()
260
265
  .createQuery('__Stat_Kind__')
261
266
  // .filter('kind_name', table)
262
- .filter(new datastore_1.PropertyFilter('kind_name', '=', table))
267
+ .filter(new PropertyFilter('kind_name', '=', table))
263
268
  .limit(1);
264
269
  const [statsArray] = await this.ds().runQuery(q);
265
270
  const [stats] = statsArray;
@@ -273,7 +278,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
273
278
  const q = this.ds()
274
279
  .createQuery('__Stat_PropertyType_PropertyName_Kind__')
275
280
  // .filter('kind_name', table)
276
- .filter(new datastore_1.PropertyFilter('kind_name', '=', table));
281
+ .filter(new (this.getPropertyFilter())('kind_name', '=', table));
277
282
  const [stats] = await this.ds().runQuery(q);
278
283
  return stats;
279
284
  }
@@ -1,6 +1,6 @@
1
1
  import type { DatastoreOptions, Key } from '@google-cloud/datastore';
2
- import { CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib';
3
- import { CommonLogger, NumberOfSeconds, ObjectWithId } from '@naturalcycles/js-lib';
2
+ import type { CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib';
3
+ import type { CommonLogger, NumberOfSeconds, ObjectWithId } from '@naturalcycles/js-lib';
4
4
  export interface DatastorePayload<T = any> {
5
5
  key: Key;
6
6
  data: T;
@@ -1,8 +1,7 @@
1
- import { CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
- import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB';
3
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
1
+ import type { CommonKeyValueDB, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
3
  import { DatastoreDB } from './datastore.db';
5
- import { DatastoreDBCfg } from './datastore.model';
4
+ import type { DatastoreDBCfg } from './datastore.model';
6
5
  export interface DatastoreKeyValueDBCfg extends DatastoreDBCfg {
7
6
  }
8
7
  export declare class DatastoreKeyValueDB implements CommonKeyValueDB {
@@ -1,4 +1,4 @@
1
- import { Query } from '@google-cloud/datastore';
2
- import { DBQuery } from '@naturalcycles/db-lib';
3
- import { ObjectWithId } from '@naturalcycles/js-lib';
4
- export declare function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(dbQuery: Readonly<DBQuery<ROW>>, emptyQuery: Query): Query;
1
+ import type { PropertyFilter, Query } from '@google-cloud/datastore';
2
+ import type { DBQuery } from '@naturalcycles/db-lib';
3
+ import type { ObjectWithId } from '@naturalcycles/js-lib';
4
+ export declare function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(dbQuery: Readonly<DBQuery<ROW>>, emptyQuery: Query, propertyFilterClass: typeof PropertyFilter): Query;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dbQueryToDatastoreQuery = dbQueryToDatastoreQuery;
4
- const datastore_1 = require("@google-cloud/datastore");
5
4
  const FNAME_MAP = {
6
5
  id: '__key__',
7
6
  };
@@ -10,7 +9,7 @@ const OP_MAP = {
10
9
  in: 'IN',
11
10
  'not-in': 'NOT_IN',
12
11
  };
13
- function dbQueryToDatastoreQuery(dbQuery, emptyQuery) {
12
+ function dbQueryToDatastoreQuery(dbQuery, emptyQuery, propertyFilterClass) {
14
13
  let q = emptyQuery;
15
14
  // filter
16
15
  for (const f of dbQuery._filters) {
@@ -24,7 +23,7 @@ function dbQueryToDatastoreQuery(dbQuery, emptyQuery) {
24
23
  let { op, val } = f;
25
24
  if (val === undefined)
26
25
  val = null;
27
- q = q.filter(new datastore_1.PropertyFilter(f.name, OP_MAP[op] || op, val));
26
+ q = q.filter(new propertyFilterClass(f.name, OP_MAP[op] || op, val));
28
27
  }
29
28
  // limit
30
29
  q = q.limit(dbQuery._limitValue || 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.39.3",
3
+ "version": "3.39.4",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky",
@@ -12,14 +12,16 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@google-cloud/datastore": "^9",
15
- "@naturalcycles/db-lib": "^9",
15
+ "@naturalcycles/db-lib": "^10",
16
16
  "@naturalcycles/js-lib": "^14",
17
17
  "@naturalcycles/nodejs-lib": "^13"
18
18
  },
19
19
  "devDependencies": {
20
- "@naturalcycles/dev-lib": "^15",
20
+ "@naturalcycles/dev-lib": "^17",
21
21
  "@types/node": "^22",
22
- "jest": "^29"
22
+ "@vitest/coverage-v8": "^3",
23
+ "tsx": "^4.19.3",
24
+ "vitest": "^3"
23
25
  },
24
26
  "files": [
25
27
  "dist",
@@ -1,7 +1,8 @@
1
1
  import { Readable } from 'node:stream'
2
- import { Query } from '@google-cloud/datastore'
2
+ import type { Query } from '@google-cloud/datastore'
3
3
  import type { RunQueryInfo, RunQueryOptions } from '@google-cloud/datastore/build/src/query'
4
- import { _ms, CommonLogger, pRetry, UnixTimestampMillis } from '@naturalcycles/js-lib'
4
+ import type { CommonLogger, UnixTimestampMillis } from '@naturalcycles/js-lib'
5
+ import { _ms, pRetry } from '@naturalcycles/js-lib'
5
6
  import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
6
7
  import type { DatastoreDBStreamOptions } from './datastore.model'
7
8
 
@@ -1,10 +1,7 @@
1
- import type { Datastore, Key, Query } from '@google-cloud/datastore'
2
- import { PropertyFilter, Transaction } from '@google-cloud/datastore'
3
- import { type RunQueryOptions } from '@google-cloud/datastore/build/src/query'
4
- import {
5
- BaseCommonDB,
1
+ import type { Datastore, Key, PropertyFilter, Query, Transaction } from '@google-cloud/datastore'
2
+ import type { RunQueryOptions } from '@google-cloud/datastore/build/src/query'
3
+ import type {
6
4
  CommonDB,
7
- commonDBFullSupport,
8
5
  CommonDBOptions,
9
6
  CommonDBReadOptions,
10
7
  CommonDBSaveMethod,
@@ -16,13 +13,9 @@ import {
16
13
  DBTransactionFn,
17
14
  RunQueryResult,
18
15
  } from '@naturalcycles/db-lib'
19
- import {
20
- _assert,
21
- _chunk,
22
- _errorDataAppend,
23
- _omit,
16
+ import { BaseCommonDB, commonDBFullSupport } from '@naturalcycles/db-lib'
17
+ import type {
24
18
  CommonLogger,
25
- commonLoggerMinLevel,
26
19
  JsonSchemaAny,
27
20
  JsonSchemaBoolean,
28
21
  JsonSchemaNull,
@@ -31,15 +24,23 @@ import {
31
24
  JsonSchemaRootObject,
32
25
  JsonSchemaString,
33
26
  ObjectWithId,
27
+ PRetryOptions,
28
+ } from '@naturalcycles/js-lib'
29
+ import {
30
+ _assert,
31
+ _chunk,
32
+ _errorDataAppend,
33
+ _omit,
34
+ commonLoggerMinLevel,
34
35
  pMap,
35
36
  pRetry,
36
37
  pRetryFn,
37
- PRetryOptions,
38
38
  pTimeout,
39
39
  TimeoutError,
40
40
  } from '@naturalcycles/js-lib'
41
- import { boldWhite, ReadableTyped } from '@naturalcycles/nodejs-lib'
42
- import {
41
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
42
+ import { boldWhite } from '@naturalcycles/nodejs-lib'
43
+ import type {
43
44
  DatastoreDBCfg,
44
45
  DatastoreDBOptions,
45
46
  DatastoreDBReadOptions,
@@ -48,8 +49,8 @@ import {
48
49
  DatastorePayload,
49
50
  DatastorePropertyStats,
50
51
  DatastoreStats,
51
- DatastoreType,
52
52
  } from './datastore.model'
53
+ import { DatastoreType } from './datastore.model'
53
54
  import { DatastoreStreamReadable } from './DatastoreStreamReadable'
54
55
  import { dbQueryToDatastoreQuery } from './query.util'
55
56
 
@@ -114,9 +115,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
114
115
  'DatastoreDB cannot be used in Test env, please use InMemoryDB',
115
116
  )
116
117
 
117
- // Lazy-loading
118
- const datastoreLib = require('@google-cloud/datastore')
119
- const DS = datastoreLib.Datastore as typeof Datastore
118
+ const DS = this.getDatastoreLib().Datastore as typeof Datastore
120
119
  this.cfg.projectId ||= this.cfg.credentials?.project_id || process.env['GOOGLE_CLOUD_PROJECT']
121
120
 
122
121
  if (this.cfg.projectId) {
@@ -136,6 +135,15 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
136
135
  return this.cachedDatastore
137
136
  }
138
137
 
138
+ private getPropertyFilter(): typeof PropertyFilter {
139
+ return this.getDatastoreLib().PropertyFilter
140
+ }
141
+
142
+ private getDatastoreLib(): any {
143
+ // Lazy-loading
144
+ return require('@google-cloud/datastore')
145
+ }
146
+
139
147
  override async ping(): Promise<void> {
140
148
  await this.getAllStats()
141
149
  }
@@ -231,7 +239,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
231
239
  }
232
240
  }
233
241
 
234
- const q = dbQueryToDatastoreQuery(dbQuery, this.ds().createQuery(dbQuery.table))
242
+ const q = dbQueryToDatastoreQuery(
243
+ dbQuery,
244
+ this.ds().createQuery(dbQuery.table),
245
+ this.getPropertyFilter(),
246
+ )
235
247
  const dsOpt = this.getRunQueryOptions(opt)
236
248
  const qr = await this.runDatastoreQuery<ROW>(q, dsOpt)
237
249
 
@@ -247,7 +259,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
247
259
  dbQuery: DBQuery<ROW>,
248
260
  opt: DatastoreDBReadOptions = {},
249
261
  ): Promise<number> {
250
- const q = dbQueryToDatastoreQuery(dbQuery.select([]), this.ds().createQuery(dbQuery.table))
262
+ const q = dbQueryToDatastoreQuery(
263
+ dbQuery.select([]),
264
+ this.ds().createQuery(dbQuery.table),
265
+ this.getPropertyFilter(),
266
+ )
251
267
  const aq = this.ds().createAggregationQuery(q).count('count')
252
268
  const dsOpt = this.getRunQueryOptions(opt)
253
269
  const [entities] = await this.ds().runAggregationQuery(aq, dsOpt)
@@ -293,7 +309,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
293
309
  dbQuery: DBQuery<ROW>,
294
310
  opt?: DatastoreDBStreamOptions,
295
311
  ): ReadableTyped<ROW> {
296
- const q = dbQueryToDatastoreQuery(dbQuery, this.ds().createQuery(dbQuery.table))
312
+ const q = dbQueryToDatastoreQuery(
313
+ dbQuery,
314
+ this.ds().createQuery(dbQuery.table),
315
+ this.getPropertyFilter(),
316
+ )
297
317
  return this.runQueryStream(q, opt)
298
318
  }
299
319
 
@@ -357,7 +377,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
357
377
  return await this.deleteByIds(q.table, ids, opt)
358
378
  }
359
379
 
360
- const datastoreQuery = dbQueryToDatastoreQuery(q.select([]), this.ds().createQuery(q.table))
380
+ const datastoreQuery = dbQueryToDatastoreQuery(
381
+ q.select([]),
382
+ this.ds().createQuery(q.table),
383
+ this.getPropertyFilter(),
384
+ )
361
385
  const dsOpt = this.getRunQueryOptions(opt)
362
386
  const { rows } = await this.runDatastoreQuery<ROW>(datastoreQuery, dsOpt)
363
387
  return await this.deleteByIds(
@@ -419,6 +443,8 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
419
443
  * Returns undefined e.g when Table is non-existing
420
444
  */
421
445
  async getStats(table: string): Promise<DatastoreStats | undefined> {
446
+ const { PropertyFilter } = this.getDatastoreLib()
447
+
422
448
  const q = this.ds()
423
449
  .createQuery('__Stat_Kind__')
424
450
  // .filter('kind_name', table)
@@ -438,7 +464,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
438
464
  const q = this.ds()
439
465
  .createQuery('__Stat_PropertyType_PropertyName_Kind__')
440
466
  // .filter('kind_name', table)
441
- .filter(new PropertyFilter('kind_name', '=', table))
467
+ .filter(new (this.getPropertyFilter())('kind_name', '=', table))
442
468
  const [stats] = await this.ds().runQuery(q)
443
469
  return stats
444
470
  }
@@ -1,6 +1,10 @@
1
1
  import type { DatastoreOptions, Key } from '@google-cloud/datastore'
2
- import { CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions } from '@naturalcycles/db-lib'
3
- import { CommonLogger, NumberOfSeconds, ObjectWithId } from '@naturalcycles/js-lib'
2
+ import type {
3
+ CommonDBOptions,
4
+ CommonDBReadOptions,
5
+ CommonDBSaveOptions,
6
+ } from '@naturalcycles/db-lib'
7
+ import type { CommonLogger, NumberOfSeconds, ObjectWithId } from '@naturalcycles/js-lib'
4
8
 
5
9
  export interface DatastorePayload<T = any> {
6
10
  key: Key
@@ -1,14 +1,10 @@
1
- import {
2
- CommonKeyValueDB,
3
- commonKeyValueDBFullSupport,
4
- DBQuery,
5
- KeyValueDBTuple,
6
- } from '@naturalcycles/db-lib'
7
- import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
8
- import { AppError, ObjectWithId } from '@naturalcycles/js-lib'
9
- import { ReadableTyped } from '@naturalcycles/nodejs-lib'
1
+ import type { CommonKeyValueDB, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib'
2
+ import { commonKeyValueDBFullSupport, DBQuery } from '@naturalcycles/db-lib'
3
+ import type { ObjectWithId } from '@naturalcycles/js-lib'
4
+ import { AppError } from '@naturalcycles/js-lib'
5
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
10
6
  import { DatastoreDB } from './datastore.db'
11
- import { DatastoreDBCfg } from './datastore.model'
7
+ import type { DatastoreDBCfg } from './datastore.model'
12
8
 
13
9
  interface KVObject {
14
10
  id: string
package/src/query.util.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { PropertyFilter, Query } from '@google-cloud/datastore'
2
- import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
3
- import { ObjectWithId, StringMap } from '@naturalcycles/js-lib'
1
+ import type { PropertyFilter, Query } from '@google-cloud/datastore'
2
+ import type { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
3
+ import type { ObjectWithId, StringMap } from '@naturalcycles/js-lib'
4
4
 
5
5
  const FNAME_MAP: StringMap = {
6
6
  id: '__key__',
@@ -15,6 +15,7 @@ const OP_MAP: Partial<Record<DBQueryFilterOperator, string>> = {
15
15
  export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
16
16
  dbQuery: Readonly<DBQuery<ROW>>,
17
17
  emptyQuery: Query,
18
+ propertyFilterClass: typeof PropertyFilter,
18
19
  ): Query {
19
20
  let q = emptyQuery
20
21
 
@@ -30,7 +31,7 @@ export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
30
31
  // `a == null` will return just that - rows with null values
31
32
  let { op, val } = f
32
33
  if (val === undefined) val = null
33
- q = q.filter(new PropertyFilter(f.name as string, OP_MAP[op] || (op as any), val))
34
+ q = q.filter(new propertyFilterClass(f.name as string, OP_MAP[op] || (op as any), val))
34
35
  }
35
36
 
36
37
  // limit