@naturalcycles/datastore-lib 3.27.1 → 3.27.2

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DatastoreDB = void 0;
4
4
  const node_stream_1 = require("node:stream");
5
+ const datastore_1 = require("@google-cloud/datastore");
5
6
  const db_lib_1 = require("@naturalcycles/db-lib");
6
7
  const js_lib_1 = require("@naturalcycles/js-lib");
7
8
  const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
@@ -246,7 +247,11 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
246
247
  * Returns undefined e.g when Table is non-existing
247
248
  */
248
249
  async getStats(table) {
249
- const q = this.ds().createQuery('__Stat_Kind__').filter('kind_name', table).limit(1);
250
+ const q = this.ds()
251
+ .createQuery('__Stat_Kind__')
252
+ // .filter('kind_name', table)
253
+ .filter(new datastore_1.PropertyFilter('kind_name', '=', table))
254
+ .limit(1);
250
255
  const [statsArray] = await this.ds().runQuery(q);
251
256
  const [stats] = statsArray;
252
257
  return stats;
@@ -258,7 +263,8 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
258
263
  async getTableProperties(table) {
259
264
  const q = this.ds()
260
265
  .createQuery('__Stat_PropertyType_PropertyName_Kind__')
261
- .filter('kind_name', table);
266
+ // .filter('kind_name', table)
267
+ .filter(new datastore_1.PropertyFilter('kind_name', '=', table));
262
268
  const [stats] = await this.ds().runQuery(q);
263
269
  return stats;
264
270
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dbQueryToDatastoreQuery = void 0;
4
+ const datastore_1 = require("@google-cloud/datastore");
4
5
  const FNAME_MAP = {
5
6
  id: '__key__',
6
7
  };
@@ -13,7 +14,10 @@ function dbQueryToDatastoreQuery(dbQuery, emptyQuery) {
13
14
  let q = emptyQuery;
14
15
  // filter
15
16
  // eslint-disable-next-line unicorn/no-array-reduce
16
- q = dbQuery._filters.reduce((q, f) => q.filter(f.name, OP_MAP[f.op] || f.op, f.val), q);
17
+ q = dbQuery._filters.reduce(
18
+ // keeping "previous syntax" commented out
19
+ // (q, f) => q.filter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val),
20
+ (q, f) => q.filter(new datastore_1.PropertyFilter(f.name, OP_MAP[f.op] || f.op, f.val)), q);
17
21
  // limit
18
22
  q = q.limit(dbQuery._limitValue || 0);
19
23
  // order
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.27.1",
3
+ "version": "3.27.2",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -1,4 +1,5 @@
1
1
  import { Transform } from 'node:stream'
2
+ import { PropertyFilter } from '@google-cloud/datastore'
2
3
  import type { Datastore, Key, Query } from '@google-cloud/datastore'
3
4
  import {
4
5
  BaseCommonDB,
@@ -378,7 +379,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
378
379
  * Returns undefined e.g when Table is non-existing
379
380
  */
380
381
  async getStats(table: string): Promise<DatastoreStats | undefined> {
381
- const q = this.ds().createQuery('__Stat_Kind__').filter('kind_name', table).limit(1)
382
+ const q = this.ds()
383
+ .createQuery('__Stat_Kind__')
384
+ // .filter('kind_name', table)
385
+ .filter(new PropertyFilter('kind_name', '=', table))
386
+ .limit(1)
382
387
  const [statsArray] = await this.ds().runQuery(q)
383
388
  const [stats] = statsArray
384
389
  return stats
@@ -392,7 +397,8 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
392
397
  async getTableProperties(table: string): Promise<DatastorePropertyStats[]> {
393
398
  const q = this.ds()
394
399
  .createQuery('__Stat_PropertyType_PropertyName_Kind__')
395
- .filter('kind_name', table)
400
+ // .filter('kind_name', table)
401
+ .filter(new PropertyFilter('kind_name', '=', table))
396
402
  const [stats] = await this.ds().runQuery(q)
397
403
  return stats
398
404
  }
package/src/query.util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Query } from '@google-cloud/datastore'
1
+ import { PropertyFilter, Query } from '@google-cloud/datastore'
2
2
  import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
3
3
  import { ObjectWithId, StringMap } from '@naturalcycles/js-lib'
4
4
 
@@ -21,7 +21,9 @@ export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
21
21
  // filter
22
22
  // eslint-disable-next-line unicorn/no-array-reduce
23
23
  q = dbQuery._filters.reduce(
24
- (q, f) => q.filter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val),
24
+ // keeping "previous syntax" commented out
25
+ // (q, f) => q.filter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val),
26
+ (q, f) => q.filter(new PropertyFilter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val)),
25
27
  q,
26
28
  )
27
29