-
Notifications
You must be signed in to change notification settings - Fork 7
/
kvstore.ts
53 lines (47 loc) · 1.38 KB
/
kvstore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { TFClient } from "../clients/tf-grid/client";
import { GridClientConfig } from "../config";
import { expose } from "../helpers/expose";
import { validateInput } from "../helpers/validator";
import { KVStoreBatchRemoveModel, KVStoreGetModel, KVStoreRemoveModel, KVStoreSetModel } from "./models";
import { checkBalance } from "./utils";
class KVStore {
client: TFClient;
constructor(config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
}
@expose
@validateInput
@checkBalance
async set(options: KVStoreSetModel) {
return (await this.client.kvStore.set(options)).apply();
}
@expose
@validateInput
async get(options: KVStoreGetModel) {
return await this.client.kvStore.get(options);
}
@expose
@validateInput
async list() {
return await this.client.kvStore.list();
}
@expose
@validateInput
@checkBalance
async remove(options: KVStoreRemoveModel) {
return (await this.client.kvStore.delete(options)).apply();
}
@expose
@validateInput
@checkBalance
async removeAll(): Promise<string[]> {
return this.client.kvStore.deleteAll();
}
@expose
@validateInput
@checkBalance
async batchRemove(options: KVStoreBatchRemoveModel): Promise<string[]> {
return await this.client.kvStore.batchRemove(options);
}
}
export { KVStore as kvstore };