@naturalcycles/datastore-lib 3.38.1 → 3.38.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.js
CHANGED
|
@@ -206,9 +206,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
206
206
|
*/
|
|
207
207
|
async deleteByIds(table, ids, opt = {}) {
|
|
208
208
|
const keys = ids.map(id => this.key(table, id));
|
|
209
|
-
await (0, js_lib_1.pMap)((0, js_lib_1._chunk)(keys, MAX_ITEMS),
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/return-await
|
|
211
|
-
async (batch) => await (opt.tx?.tx || this.ds()).delete(batch), {
|
|
209
|
+
await (0, js_lib_1.pMap)((0, js_lib_1._chunk)(keys, MAX_ITEMS), async (batch) => await (opt.tx?.tx || this.ds()).delete(batch), {
|
|
212
210
|
concurrency: DATASTORE_RECOMMENDED_CONCURRENCY,
|
|
213
211
|
});
|
|
214
212
|
return ids.length;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CommonKeyValueDB } from '@naturalcycles/db-lib';
|
|
1
|
+
import { CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
|
|
2
2
|
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB';
|
|
3
|
-
import { KeyValueTuple } from '@naturalcycles/js-lib';
|
|
4
3
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
5
4
|
import { DatastoreDB } from './datastore.db';
|
|
6
5
|
import { DatastoreDBCfg } from './datastore.model';
|
|
@@ -16,12 +15,12 @@ export declare class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
16
15
|
};
|
|
17
16
|
ping(): Promise<void>;
|
|
18
17
|
createTable(): Promise<void>;
|
|
19
|
-
getByIds
|
|
18
|
+
getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
|
|
20
19
|
deleteByIds(table: string, ids: string[]): Promise<void>;
|
|
21
|
-
saveBatch
|
|
20
|
+
saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void>;
|
|
22
21
|
streamIds(table: string, limit?: number): ReadableTyped<string>;
|
|
23
|
-
streamValues
|
|
24
|
-
streamEntries
|
|
22
|
+
streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
|
|
23
|
+
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
|
|
25
24
|
count(table: string): Promise<number>;
|
|
26
25
|
incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
|
|
27
26
|
}
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -350,7 +350,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
350
350
|
|
|
351
351
|
await pMap(
|
|
352
352
|
_chunk(keys, MAX_ITEMS),
|
|
353
|
-
|
|
353
|
+
|
|
354
354
|
async batch => await ((opt.tx as DatastoreDBTransaction)?.tx || this.ds()).delete(batch),
|
|
355
355
|
{
|
|
356
356
|
concurrency: DATASTORE_RECOMMENDED_CONCURRENCY,
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CommonKeyValueDB,
|
|
3
|
+
commonKeyValueDBFullSupport,
|
|
4
|
+
DBQuery,
|
|
5
|
+
KeyValueDBTuple,
|
|
6
|
+
} from '@naturalcycles/db-lib'
|
|
2
7
|
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
|
|
3
|
-
import { AppError,
|
|
8
|
+
import { AppError, ObjectWithId } from '@naturalcycles/js-lib'
|
|
4
9
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
5
10
|
import { DatastoreDB } from './datastore.db'
|
|
6
11
|
import { DatastoreDBCfg } from './datastore.model'
|
|
7
12
|
|
|
8
|
-
interface KVObject
|
|
13
|
+
interface KVObject {
|
|
9
14
|
id: string
|
|
10
|
-
v:
|
|
15
|
+
v: Buffer
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
const excludeFromIndexes: (keyof KVObject
|
|
18
|
+
const excludeFromIndexes: (keyof KVObject)[] = ['v']
|
|
14
19
|
|
|
15
20
|
export interface DatastoreKeyValueDBCfg extends DatastoreDBCfg {}
|
|
16
21
|
|
|
@@ -32,16 +37,16 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
32
37
|
|
|
33
38
|
async createTable(): Promise<void> {}
|
|
34
39
|
|
|
35
|
-
async getByIds
|
|
36
|
-
return (await this.db.getByIds<KVObject
|
|
40
|
+
async getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]> {
|
|
41
|
+
return (await this.db.getByIds<KVObject>(table, ids)).map(r => [r.id, r.v])
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
async deleteByIds(table: string, ids: string[]): Promise<void> {
|
|
40
45
|
await this.db.deleteByIds(table, ids)
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
async saveBatch
|
|
44
|
-
await this.db.saveBatch<KVObject
|
|
48
|
+
async saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void> {
|
|
49
|
+
await this.db.saveBatch<KVObject>(
|
|
45
50
|
table,
|
|
46
51
|
entries.map(([id, v]) => ({ id, v })),
|
|
47
52
|
{
|
|
@@ -63,9 +68,9 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
63
68
|
)
|
|
64
69
|
}
|
|
65
70
|
|
|
66
|
-
streamValues
|
|
71
|
+
streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
|
|
67
72
|
// `select v` doesn't work for some reason
|
|
68
|
-
const q = DBQuery.create<KVObject
|
|
73
|
+
const q = DBQuery.create<KVObject>(table).limit(limit || 0)
|
|
69
74
|
|
|
70
75
|
return (
|
|
71
76
|
this.db
|
|
@@ -75,8 +80,8 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
|
|
|
75
80
|
)
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
streamEntries
|
|
79
|
-
const q = DBQuery.create<KVObject
|
|
83
|
+
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
|
|
84
|
+
const q = DBQuery.create<KVObject>(table).limit(limit || 0)
|
|
80
85
|
|
|
81
86
|
return (
|
|
82
87
|
this.db
|