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