web-dc-api 0.0.51 → 0.0.52
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/dc.min.js +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +34 -32
- package/dist/index.esm.js +1 -1
- package/lib/implements/keyvalue/client.ts +3 -0
- package/lib/implements/keyvalue/manager.ts +11 -7
- package/lib/interfaces/keyvalue-interface.ts +5 -0
- package/lib/modules/keyvalue-module.ts +5 -2
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { base58btc } from "multiformats/bases/base58";
|
|
|
6
6
|
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
7
7
|
import { Errors } from "../../common/error";
|
|
8
8
|
import { DCContext } from "../../../lib/interfaces/DCContext";
|
|
9
|
+
import { Direction } from "../../common/define";
|
|
9
10
|
|
|
10
11
|
export class KeyValueClient {
|
|
11
12
|
client: Client;
|
|
@@ -303,6 +304,7 @@ export class KeyValueClient {
|
|
|
303
304
|
indexKey:string,
|
|
304
305
|
indexValue:string,
|
|
305
306
|
seekKey:string,
|
|
307
|
+
direction: Direction = Direction.Forward,
|
|
306
308
|
offset: number,
|
|
307
309
|
limit: number,
|
|
308
310
|
vaccount?: string
|
|
@@ -314,6 +316,7 @@ export class KeyValueClient {
|
|
|
314
316
|
message.indexKey = new TextEncoder().encode(indexKey);
|
|
315
317
|
message.indexValue = new TextEncoder().encode(indexValue);
|
|
316
318
|
message.seekKey = new TextEncoder().encode(seekKey);
|
|
319
|
+
message.direction = direction;
|
|
317
320
|
message.offset = offset;
|
|
318
321
|
message.limit = limit;
|
|
319
322
|
if(vaccount){
|
|
@@ -113,6 +113,7 @@ export class KeyValueDB {
|
|
|
113
113
|
indexValue: string,
|
|
114
114
|
limit: number = 1000,
|
|
115
115
|
seekKey: string = "",
|
|
116
|
+
direction: Direction = Direction.Forward,
|
|
116
117
|
offset: number = 0,
|
|
117
118
|
vaccount: string = ""
|
|
118
119
|
): Promise<[string | null, Error | null]> {
|
|
@@ -123,6 +124,7 @@ export class KeyValueDB {
|
|
|
123
124
|
indexKey,
|
|
124
125
|
indexValue,
|
|
125
126
|
seekKey,
|
|
127
|
+
direction,
|
|
126
128
|
offset,
|
|
127
129
|
limit,
|
|
128
130
|
vaccount
|
|
@@ -427,15 +429,15 @@ export class KeyValueManager {
|
|
|
427
429
|
break;
|
|
428
430
|
}
|
|
429
431
|
for (let i = 0; i < resList.length; i++) {
|
|
430
|
-
originAuthList.push(resList[i]);
|
|
431
|
-
const content = resList[i]
|
|
432
|
+
originAuthList.push(resList[i]!);
|
|
433
|
+
const content = resList[i]!.comment;
|
|
432
434
|
const parts = content.split(":");
|
|
433
435
|
if (parts.length < 2) {
|
|
434
436
|
continue;
|
|
435
437
|
}
|
|
436
|
-
const authPubkey = parts[0]
|
|
437
|
-
const permission = parseInt(parts[1]);
|
|
438
|
-
const remark = content.substring(parts[0]
|
|
438
|
+
const authPubkey = parts[0]!;
|
|
439
|
+
const permission = parseInt(parts[1]!);
|
|
440
|
+
const remark = content.substring(parts[0]!.length + 2);
|
|
439
441
|
authList.push({
|
|
440
442
|
pubkey: authPubkey,
|
|
441
443
|
permission: permission,
|
|
@@ -445,8 +447,8 @@ export class KeyValueManager {
|
|
|
445
447
|
if (resList.length < 1000) {
|
|
446
448
|
break;
|
|
447
449
|
}
|
|
448
|
-
seekKey = `${resList[resList.length - 1]
|
|
449
|
-
resList[resList.length - 1]
|
|
450
|
+
seekKey = `${resList[resList.length - 1]!.blockheight}/${
|
|
451
|
+
resList[resList.length - 1]!.commentCid
|
|
450
452
|
}`;
|
|
451
453
|
}
|
|
452
454
|
} catch (error: any) {
|
|
@@ -670,6 +672,7 @@ export class KeyValueManager {
|
|
|
670
672
|
indexKey: string,
|
|
671
673
|
indexValue: string,
|
|
672
674
|
seekKey: string,
|
|
675
|
+
direction: Direction = Direction.Forward,
|
|
673
676
|
offset: number,
|
|
674
677
|
limit: number,
|
|
675
678
|
vaccount?: string
|
|
@@ -712,6 +715,7 @@ export class KeyValueManager {
|
|
|
712
715
|
indexKey,
|
|
713
716
|
indexValue,
|
|
714
717
|
seekKey,
|
|
718
|
+
direction,
|
|
715
719
|
offset,
|
|
716
720
|
limit,
|
|
717
721
|
vaccount
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Direction } from "../common/define";
|
|
1
2
|
import { ThemePermission } from "../common/constants";
|
|
2
3
|
import { ThemeAuthInfo, ThemeComment } from "../common/types/types";
|
|
3
4
|
import { KeyValueStoreType, KeyValueDB } from "../implements/keyvalue/manager";
|
|
@@ -93,6 +94,7 @@ export interface IKeyValueOperations {
|
|
|
93
94
|
* @param key 键名
|
|
94
95
|
* @param limit 返回结果数量限制
|
|
95
96
|
* @param seekKey 查询起始键,用于分页查询
|
|
97
|
+
* @param direction 查询方向
|
|
96
98
|
* @param offset 结果偏移量
|
|
97
99
|
* @param vaccount 可选的虚拟账户
|
|
98
100
|
* @returns [值列表生成的json字符串, 错误信息]
|
|
@@ -102,6 +104,7 @@ export interface IKeyValueOperations {
|
|
|
102
104
|
key: string,
|
|
103
105
|
limit: number,
|
|
104
106
|
seekKey:string,
|
|
107
|
+
direction: Direction,
|
|
105
108
|
offset: number,
|
|
106
109
|
vaccount?: string
|
|
107
110
|
): Promise<[string | null, Error | null]>;
|
|
@@ -129,6 +132,7 @@ export interface IKeyValueOperations {
|
|
|
129
132
|
* @param indexValue 索引值
|
|
130
133
|
* @param seekKey 查询起始键
|
|
131
134
|
* @param offset 结果偏移量
|
|
135
|
+
* @param direction 查询方向 (Forward/Backward)
|
|
132
136
|
* @param limit 返回结果数量限制
|
|
133
137
|
* @param vaccount 可选的虚拟账户
|
|
134
138
|
* @returns [JSON格式查询结果, 错误信息]
|
|
@@ -140,6 +144,7 @@ export interface IKeyValueOperations {
|
|
|
140
144
|
limit: number,
|
|
141
145
|
seekKey: string,
|
|
142
146
|
offset: number,
|
|
147
|
+
direction: Direction,
|
|
143
148
|
vaccount?: string
|
|
144
149
|
): Promise<[string | null, Error | null]>;
|
|
145
150
|
}
|
|
@@ -7,6 +7,7 @@ import { DCModule, CoreModuleName } from "../common/module-system";
|
|
|
7
7
|
import { KeyValueManager, KeyValueStoreType, KeyValueDB } from "../implements/keyvalue/manager";
|
|
8
8
|
import { createLogger } from "../util/logger";
|
|
9
9
|
import { ThemeAuthInfo, ThemeComment } from "../common/types/types";
|
|
10
|
+
import { Direction } from "../common/define";
|
|
10
11
|
const logger = createLogger('KeyValueModule');
|
|
11
12
|
const indexkey_dckv = "indexkey_dckv"; //索引键名,keyvalue设置过程中key本身的索引键
|
|
12
13
|
/**
|
|
@@ -203,6 +204,7 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
|
|
|
203
204
|
key: string,
|
|
204
205
|
limit: number,
|
|
205
206
|
seekKey:string,
|
|
207
|
+
direction: Direction = Direction.Forward,
|
|
206
208
|
offset: number,
|
|
207
209
|
vaccount?: string
|
|
208
210
|
): Promise<[string | null, Error | null]> {
|
|
@@ -212,7 +214,7 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
|
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
try {
|
|
215
|
-
const res = await kvdb.getWithIndex(indexkey_dckv, key, limit,seekKey, offset, vaccount);
|
|
217
|
+
const res = await kvdb.getWithIndex(indexkey_dckv, key, limit,seekKey,direction, offset, vaccount);
|
|
216
218
|
return res;
|
|
217
219
|
} catch (error) {
|
|
218
220
|
logger.error(`getValues失败:`, error);
|
|
@@ -247,6 +249,7 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
|
|
|
247
249
|
limit: number,
|
|
248
250
|
seekKey:string,
|
|
249
251
|
offset: number,
|
|
252
|
+
direction: Direction = Direction.Forward,
|
|
250
253
|
vaccount?: string
|
|
251
254
|
): Promise<[string | null, Error | null]> {
|
|
252
255
|
const err = this.assertInitialized();
|
|
@@ -254,7 +257,7 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
|
|
|
254
257
|
return [null, err];
|
|
255
258
|
}
|
|
256
259
|
try {
|
|
257
|
-
const res = await kvdb.getWithIndex(indexKey, indexValue, limit,seekKey, offset, vaccount);
|
|
260
|
+
const res = await kvdb.getWithIndex(indexKey, indexValue, limit,seekKey, direction,offset, vaccount);
|
|
258
261
|
return res;
|
|
259
262
|
} catch (error) {
|
|
260
263
|
logger.error(`getWithIndex失败:`, error);
|