@naturalcycles/db-lib 10.57.0 → 10.59.0
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/adapter/file/inMemory.persistence.plugin.d.ts +1 -0
- package/dist/adapter/file/inMemory.persistence.plugin.js +3 -0
- package/dist/inmemory/inMemory.db.d.ts +1 -0
- package/dist/inmemory/inMemory.db.js +3 -0
- package/dist/inmemory/inMemoryKeyValueDB.d.ts +1 -0
- package/dist/inmemory/inMemoryKeyValueDB.js +3 -0
- package/dist/kv/commonKeyValueDao.d.ts +4 -0
- package/dist/kv/commonKeyValueDao.js +9 -0
- package/package.json +1 -1
- package/src/adapter/file/inMemory.persistence.plugin.ts +4 -0
- package/src/inmemory/inMemory.db.ts +4 -0
- package/src/inmemory/inMemoryKeyValueDB.ts +4 -0
- package/src/kv/commonKeyValueDao.ts +10 -0
|
@@ -7,6 +7,7 @@ import type { FileDBPersistencePlugin } from './file.db.model.js';
|
|
|
7
7
|
export declare class InMemoryPersistencePlugin implements FileDBPersistencePlugin {
|
|
8
8
|
data: StringMap<StringMap<ObjectWithId>>;
|
|
9
9
|
ping(): Promise<void>;
|
|
10
|
+
clear(): void;
|
|
10
11
|
getTables(): Promise<string[]>;
|
|
11
12
|
loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
|
|
12
13
|
saveFiles(ops: DBSaveBatchOperation<any>[]): Promise<void>;
|
|
@@ -13,6 +13,7 @@ export declare class InMemoryKeyValueDB implements CommonKeyValueDB {
|
|
|
13
13
|
};
|
|
14
14
|
data: StringMap<StringMap<any>>;
|
|
15
15
|
ping(): Promise<void>;
|
|
16
|
+
clear(): void;
|
|
16
17
|
createTable(_table: string, _opt?: CommonDBCreateOptions): Promise<void>;
|
|
17
18
|
deleteByIds(table: string, ids: string[]): Promise<void>;
|
|
18
19
|
getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
|
|
@@ -11,6 +11,9 @@ export class InMemoryKeyValueDB {
|
|
|
11
11
|
// data[table][id] => any (can be Buffer, or number)
|
|
12
12
|
data = {};
|
|
13
13
|
async ping() { }
|
|
14
|
+
clear() {
|
|
15
|
+
this.data = {};
|
|
16
|
+
}
|
|
14
17
|
async createTable(_table, _opt) { }
|
|
15
18
|
async deleteByIds(table, ids) {
|
|
16
19
|
this.data[table] ||= {};
|
|
@@ -31,6 +31,10 @@ export interface CommonKeyValueDaoTransformer<V> {
|
|
|
31
31
|
valueToBuffer: (v: V) => Buffer;
|
|
32
32
|
bufferToValue: (buf: Buffer) => V;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Plain JSON, no compression. For small values, where compressing would cost more than it saves.
|
|
36
|
+
*/
|
|
37
|
+
export declare function commonKeyValueDaoJsonTransformer<T = any>(): CommonKeyValueDaoTransformer<T>;
|
|
34
38
|
/**
|
|
35
39
|
* @deprecated use zstd instead, gzip is obsolete
|
|
36
40
|
*/
|
|
@@ -2,6 +2,15 @@ import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
|
|
|
2
2
|
import { consoleLogger } from '@naturalcycles/js-lib/log';
|
|
3
3
|
import { SKIP } from '@naturalcycles/js-lib/types';
|
|
4
4
|
import { zip2 } from '@naturalcycles/nodejs-lib/zip';
|
|
5
|
+
/**
|
|
6
|
+
* Plain JSON, no compression. For small values, where compressing would cost more than it saves.
|
|
7
|
+
*/
|
|
8
|
+
export function commonKeyValueDaoJsonTransformer() {
|
|
9
|
+
return {
|
|
10
|
+
valueToBuffer: v => Buffer.from(JSON.stringify(v)),
|
|
11
|
+
bufferToValue: buf => JSON.parse(buf.toString()),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* @deprecated use zstd instead, gzip is obsolete
|
|
7
16
|
*/
|
package/package.json
CHANGED
|
@@ -18,6 +18,10 @@ export class InMemoryKeyValueDB implements CommonKeyValueDB {
|
|
|
18
18
|
|
|
19
19
|
async ping(): Promise<void> {}
|
|
20
20
|
|
|
21
|
+
clear(): void {
|
|
22
|
+
this.data = {}
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
async createTable(_table: string, _opt?: CommonDBCreateOptions): Promise<void> {}
|
|
22
26
|
|
|
23
27
|
async deleteByIds(table: string, ids: string[]): Promise<void> {
|
|
@@ -50,6 +50,16 @@ export interface CommonKeyValueDaoTransformer<V> {
|
|
|
50
50
|
bufferToValue: (buf: Buffer) => V
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Plain JSON, no compression. For small values, where compressing would cost more than it saves.
|
|
55
|
+
*/
|
|
56
|
+
export function commonKeyValueDaoJsonTransformer<T = any>(): CommonKeyValueDaoTransformer<T> {
|
|
57
|
+
return {
|
|
58
|
+
valueToBuffer: v => Buffer.from(JSON.stringify(v)),
|
|
59
|
+
bufferToValue: buf => JSON.parse(buf.toString()),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
/**
|
|
54
64
|
* @deprecated use zstd instead, gzip is obsolete
|
|
55
65
|
*/
|