@naturalcycles/datastore-lib 3.37.0 → 3.38.1
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.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { CommonKeyValueDB
|
|
1
|
+
import { CommonKeyValueDB } from '@naturalcycles/db-lib';
|
|
2
|
+
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB';
|
|
3
|
+
import { KeyValueTuple } from '@naturalcycles/js-lib';
|
|
2
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
5
|
import { DatastoreDB } from './datastore.db';
|
|
4
6
|
import { DatastoreDBCfg } from './datastore.model';
|
|
@@ -8,14 +10,18 @@ export declare class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
8
10
|
cfg: DatastoreKeyValueDBCfg;
|
|
9
11
|
constructor(cfg: DatastoreKeyValueDBCfg);
|
|
10
12
|
db: DatastoreDB;
|
|
13
|
+
support: {
|
|
14
|
+
increment: boolean;
|
|
15
|
+
count?: boolean;
|
|
16
|
+
};
|
|
11
17
|
ping(): Promise<void>;
|
|
12
18
|
createTable(): Promise<void>;
|
|
13
|
-
getByIds(table: string, ids: string[]): Promise<
|
|
19
|
+
getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]>;
|
|
14
20
|
deleteByIds(table: string, ids: string[]): Promise<void>;
|
|
15
|
-
saveBatch(table: string, entries:
|
|
21
|
+
saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void>;
|
|
16
22
|
streamIds(table: string, limit?: number): ReadableTyped<string>;
|
|
17
|
-
streamValues(table: string, limit?: number): ReadableTyped<
|
|
18
|
-
streamEntries(table: string, limit?: number): ReadableTyped<
|
|
23
|
+
streamValues<V>(table: string, limit?: number): ReadableTyped<V>;
|
|
24
|
+
streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>>;
|
|
19
25
|
count(table: string): Promise<number>;
|
|
20
|
-
|
|
26
|
+
incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
|
|
21
27
|
}
|
|
@@ -8,6 +8,10 @@ const excludeFromIndexes = ['v'];
|
|
|
8
8
|
class DatastoreKeyValueDB {
|
|
9
9
|
constructor(cfg) {
|
|
10
10
|
this.cfg = cfg;
|
|
11
|
+
this.support = {
|
|
12
|
+
...db_lib_1.commonKeyValueDBFullSupport,
|
|
13
|
+
increment: false,
|
|
14
|
+
};
|
|
11
15
|
this.db = new datastore_db_1.DatastoreDB(cfg);
|
|
12
16
|
}
|
|
13
17
|
async ping() {
|
|
@@ -53,8 +57,8 @@ class DatastoreKeyValueDB {
|
|
|
53
57
|
const q = db_lib_1.DBQuery.create(table);
|
|
54
58
|
return await this.db.runQueryCount(q);
|
|
55
59
|
}
|
|
56
|
-
async
|
|
57
|
-
throw new js_lib_1.AppError('DatastoreKeyValueDB.
|
|
60
|
+
async incrementBatch(_table, _entries) {
|
|
61
|
+
throw new js_lib_1.AppError('DatastoreKeyValueDB.incrementBatch() is not implemented');
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
exports.DatastoreKeyValueDB = DatastoreKeyValueDB;
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -80,7 +80,8 @@ const methodMap: Record<CommonDBSaveMethod, string> = {
|
|
|
80
80
|
export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
81
81
|
override support: CommonDBSupport = {
|
|
82
82
|
...commonDBFullSupport,
|
|
83
|
-
|
|
83
|
+
patchByQuery: false,
|
|
84
|
+
increment: false,
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
constructor(cfg: DatastoreDBCfg = {}) {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { CommonKeyValueDB,
|
|
2
|
-
import {
|
|
1
|
+
import { CommonKeyValueDB, commonKeyValueDBFullSupport, DBQuery } from '@naturalcycles/db-lib'
|
|
2
|
+
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
|
|
3
|
+
import { AppError, KeyValueTuple, ObjectWithId } from '@naturalcycles/js-lib'
|
|
3
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
5
|
import { DatastoreDB } from './datastore.db'
|
|
5
6
|
import { DatastoreDBCfg } from './datastore.model'
|
|
6
7
|
|
|
7
|
-
interface KVObject {
|
|
8
|
+
interface KVObject<V> {
|
|
8
9
|
id: string
|
|
9
|
-
v:
|
|
10
|
+
v: V
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
const excludeFromIndexes: (keyof KVObject)[] = ['v']
|
|
13
|
+
const excludeFromIndexes: (keyof KVObject<any>)[] = ['v']
|
|
13
14
|
|
|
14
15
|
export interface DatastoreKeyValueDBCfg extends DatastoreDBCfg {}
|
|
15
16
|
|
|
@@ -20,22 +21,27 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
20
21
|
|
|
21
22
|
db: DatastoreDB
|
|
22
23
|
|
|
24
|
+
support = {
|
|
25
|
+
...commonKeyValueDBFullSupport,
|
|
26
|
+
increment: false,
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
async ping(): Promise<void> {
|
|
24
30
|
await this.db.ping()
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
async createTable(): Promise<void> {}
|
|
28
34
|
|
|
29
|
-
async getByIds(table: string, ids: string[]): Promise<
|
|
30
|
-
return (await this.db.getByIds<KVObject
|
|
35
|
+
async getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]> {
|
|
36
|
+
return (await this.db.getByIds<KVObject<V>>(table, ids)).map(r => [r.id, r.v])
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
async deleteByIds(table: string, ids: string[]): Promise<void> {
|
|
34
40
|
await this.db.deleteByIds(table, ids)
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
async saveBatch(table: string, entries:
|
|
38
|
-
await this.db.saveBatch<KVObject
|
|
43
|
+
async saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void> {
|
|
44
|
+
await this.db.saveBatch<KVObject<V>>(
|
|
39
45
|
table,
|
|
40
46
|
entries.map(([id, v]) => ({ id, v })),
|
|
41
47
|
{
|
|
@@ -45,7 +51,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
streamIds(table: string, limit?: number): ReadableTyped<string> {
|
|
48
|
-
const q = DBQuery.create<
|
|
54
|
+
const q = DBQuery.create<ObjectWithId>(table)
|
|
49
55
|
.select(['id'])
|
|
50
56
|
.limit(limit || 0)
|
|
51
57
|
|
|
@@ -57,9 +63,9 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
57
63
|
)
|
|
58
64
|
}
|
|
59
65
|
|
|
60
|
-
streamValues(table: string, limit?: number): ReadableTyped<
|
|
66
|
+
streamValues<V>(table: string, limit?: number): ReadableTyped<V> {
|
|
61
67
|
// `select v` doesn't work for some reason
|
|
62
|
-
const q = DBQuery.create<KVObject
|
|
68
|
+
const q = DBQuery.create<KVObject<V>>(table).limit(limit || 0)
|
|
63
69
|
|
|
64
70
|
return (
|
|
65
71
|
this.db
|
|
@@ -69,23 +75,23 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
69
75
|
)
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
streamEntries(table: string, limit?: number): ReadableTyped<
|
|
73
|
-
const q = DBQuery.create<KVObject
|
|
78
|
+
streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>> {
|
|
79
|
+
const q = DBQuery.create<KVObject<V>>(table).limit(limit || 0)
|
|
74
80
|
|
|
75
81
|
return (
|
|
76
82
|
this.db
|
|
77
83
|
.streamQuery(q)
|
|
78
84
|
// .on('error', err => stream.emit('error', err))
|
|
79
|
-
.map(r => [r.id, r.v]
|
|
85
|
+
.map(r => [r.id, r.v])
|
|
80
86
|
)
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
async count(table: string): Promise<number> {
|
|
84
|
-
const q = DBQuery.create<
|
|
90
|
+
const q = DBQuery.create<ObjectWithId>(table)
|
|
85
91
|
return await this.db.runQueryCount(q)
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
async
|
|
89
|
-
throw new AppError('DatastoreKeyValueDB.
|
|
94
|
+
async incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]> {
|
|
95
|
+
throw new AppError('DatastoreKeyValueDB.incrementBatch() is not implemented')
|
|
90
96
|
}
|
|
91
97
|
}
|