@naturalcycles/datastore-lib 3.25.1 → 3.25.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.
- package/dist/datastore.db.d.ts +2 -1
- package/dist/datastore.db.js +6 -0
- package/package.json +1 -1
- package/src/datastore.db.ts +11 -0
- package/src/datastoreKeyValueDB.ts +3 -3
package/dist/datastore.db.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Datastore, Key, Query } from '@google-cloud/datastore';
|
|
2
2
|
import { BaseCommonDB, CommonDB, DBQuery, DBTransaction, RunQueryResult } from '@naturalcycles/db-lib';
|
|
3
|
-
import { ObjectWithId, JsonSchemaRootObject, CommonLogger } from '@naturalcycles/js-lib';
|
|
3
|
+
import { ObjectWithId, JsonSchemaObject, JsonSchemaRootObject, CommonLogger } from '@naturalcycles/js-lib';
|
|
4
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
5
5
|
import { DatastoreDBCfg, DatastoreDBOptions, DatastoreDBSaveOptions, DatastoreDBStreamOptions, DatastorePayload, DatastorePropertyStats, DatastoreStats } from './datastore.model';
|
|
6
6
|
/**
|
|
@@ -55,6 +55,7 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
55
55
|
key(kind: string, id: string | number): Key;
|
|
56
56
|
getDsKey(o: any): Key | undefined;
|
|
57
57
|
getKey(key: Key): string | undefined;
|
|
58
|
+
createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>): Promise<void>;
|
|
58
59
|
getTables(): Promise<string[]>;
|
|
59
60
|
getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
|
|
60
61
|
private getPRetryOptions;
|
package/dist/datastore.db.js
CHANGED
|
@@ -106,6 +106,11 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
106
106
|
return q.kinds[0];
|
|
107
107
|
}
|
|
108
108
|
async runQuery(dbQuery, _opt) {
|
|
109
|
+
if (dbQuery._ids?.length) {
|
|
110
|
+
return {
|
|
111
|
+
rows: await this.getByIds(dbQuery.table, dbQuery._ids),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
109
114
|
const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery, this.ds().createQuery(dbQuery.table));
|
|
110
115
|
const qr = await this.runDatastoreQuery(q);
|
|
111
116
|
// Special case when projection query didn't specify 'id'
|
|
@@ -277,6 +282,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
277
282
|
const id = key.id || key.name;
|
|
278
283
|
return id?.toString();
|
|
279
284
|
}
|
|
285
|
+
async createTable(_table, _schema) { }
|
|
280
286
|
async getTables() {
|
|
281
287
|
const statsArray = await this.getAllStats();
|
|
282
288
|
// Filter out tables starting with `_` by default (internal Datastore tables)
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -176,6 +176,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
176
176
|
dbQuery: DBQuery<ROW>,
|
|
177
177
|
_opt?: DatastoreDBOptions,
|
|
178
178
|
): Promise<RunQueryResult<ROW>> {
|
|
179
|
+
if (dbQuery._ids?.length) {
|
|
180
|
+
return {
|
|
181
|
+
rows: await this.getByIds(dbQuery.table, dbQuery._ids),
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
179
185
|
const q = dbQueryToDatastoreQuery(dbQuery, this.ds().createQuery(dbQuery.table))
|
|
180
186
|
const qr = await this.runDatastoreQuery<ROW>(q)
|
|
181
187
|
|
|
@@ -418,6 +424,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
418
424
|
return id?.toString()
|
|
419
425
|
}
|
|
420
426
|
|
|
427
|
+
override async createTable<ROW extends ObjectWithId>(
|
|
428
|
+
_table: string,
|
|
429
|
+
_schema: JsonSchemaObject<ROW>,
|
|
430
|
+
): Promise<void> {}
|
|
431
|
+
|
|
421
432
|
override async getTables(): Promise<string[]> {
|
|
422
433
|
const statsArray = await this.getAllStats()
|
|
423
434
|
// Filter out tables starting with `_` by default (internal Datastore tables)
|
|
@@ -45,7 +45,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
streamIds(table: string, limit?: number): ReadableTyped<string> {
|
|
48
|
-
const q = DBQuery.create(table)
|
|
48
|
+
const q = DBQuery.create<KVObject>(table)
|
|
49
49
|
.select(['id'])
|
|
50
50
|
.limit(limit || 0)
|
|
51
51
|
|
|
@@ -63,7 +63,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
63
63
|
|
|
64
64
|
streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
|
|
65
65
|
// `select v` doesn't work for some reason
|
|
66
|
-
const q = DBQuery.create(table).limit(limit || 0)
|
|
66
|
+
const q = DBQuery.create<KVObject>(table).limit(limit || 0)
|
|
67
67
|
|
|
68
68
|
const stream: ReadableTyped<string> = this.db
|
|
69
69
|
.streamQuery<KVObject>(q)
|
|
@@ -78,7 +78,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
|
|
81
|
-
const q = DBQuery.create(table).limit(limit || 0)
|
|
81
|
+
const q = DBQuery.create<KVObject>(table).limit(limit || 0)
|
|
82
82
|
|
|
83
83
|
const stream: ReadableTyped<string> = this.db
|
|
84
84
|
.streamQuery<KVObject>(q)
|