@waku/core 0.0.34-c41b319.0 → 0.0.34-c43cec2.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/bundle/{base_protocol-CCK9RCtH.js → base_protocol-DxFKDXX2.js} +20 -19
- package/bundle/{index-Db7LxDrL.js → index-yLOEQnIE.js} +39 -75
- package/bundle/index.js +133 -1815
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-ANFNAdFD.js → version_0-Che4t3mN.js} +42 -163
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +2 -2
- package/dist/lib/base_protocol.js +2 -2
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +3 -56
- package/dist/lib/connection_manager/connection_manager.js +13 -96
- package/dist/lib/connection_manager/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.d.ts +18 -1
- package/dist/lib/filter/index.js +208 -1
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/health_manager.d.ts +14 -0
- package/dist/lib/health_manager.js +70 -0
- package/dist/lib/health_manager.js.map +1 -0
- package/dist/lib/light_push/index.d.ts +15 -1
- package/dist/lib/light_push/index.js +144 -1
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +3 -1
- package/dist/lib/metadata/index.js +118 -1
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/store/index.d.ts +9 -1
- package/dist/lib/store/index.js +82 -1
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
- package/dist/lib/stream_manager/stream_manager.js +17 -16
- package/dist/lib/stream_manager/stream_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/lib/base_protocol.ts +3 -3
- package/src/lib/connection_manager/connection_manager.ts +20 -114
- package/src/lib/filter/index.ts +315 -1
- package/src/lib/health_manager.ts +90 -0
- package/src/lib/light_push/index.ts +189 -1
- package/src/lib/metadata/index.ts +182 -1
- package/src/lib/store/index.ts +136 -1
- package/src/lib/stream_manager/stream_manager.ts +18 -16
- package/dist/lib/filter/filter.d.ts +0 -18
- package/dist/lib/filter/filter.js +0 -209
- package/dist/lib/filter/filter.js.map +0 -1
- package/dist/lib/light_push/light_push.d.ts +0 -15
- package/dist/lib/light_push/light_push.js +0 -144
- package/dist/lib/light_push/light_push.js.map +0 -1
- package/dist/lib/metadata/metadata.d.ts +0 -3
- package/dist/lib/metadata/metadata.js +0 -119
- package/dist/lib/metadata/metadata.js.map +0 -1
- package/dist/lib/store/store.d.ts +0 -9
- package/dist/lib/store/store.js +0 -83
- package/dist/lib/store/store.js.map +0 -1
- package/src/lib/filter/filter.ts +0 -315
- package/src/lib/light_push/light_push.ts +0 -188
- package/src/lib/metadata/metadata.ts +0 -182
- package/src/lib/store/store.ts +0 -136
package/src/lib/store/store.ts
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
import type { PeerId } from "@libp2p/interface";
|
2
|
-
import {
|
3
|
-
IDecodedMessage,
|
4
|
-
IDecoder,
|
5
|
-
IStoreCore,
|
6
|
-
Libp2p,
|
7
|
-
PubsubTopic,
|
8
|
-
QueryRequestParams
|
9
|
-
} from "@waku/interfaces";
|
10
|
-
import { Logger } from "@waku/utils";
|
11
|
-
import all from "it-all";
|
12
|
-
import * as lp from "it-length-prefixed";
|
13
|
-
import { pipe } from "it-pipe";
|
14
|
-
import { Uint8ArrayList } from "uint8arraylist";
|
15
|
-
|
16
|
-
import { BaseProtocol } from "../base_protocol.js";
|
17
|
-
import { toProtoMessage } from "../to_proto_message.js";
|
18
|
-
|
19
|
-
import {
|
20
|
-
DEFAULT_PAGE_SIZE,
|
21
|
-
MAX_PAGE_SIZE,
|
22
|
-
StoreQueryRequest,
|
23
|
-
StoreQueryResponse
|
24
|
-
} from "./rpc.js";
|
25
|
-
|
26
|
-
const log = new Logger("store");
|
27
|
-
|
28
|
-
export const StoreCodec = "/vac/waku/store-query/3.0.0";
|
29
|
-
|
30
|
-
export class StoreCore extends BaseProtocol implements IStoreCore {
|
31
|
-
public constructor(
|
32
|
-
public readonly pubsubTopics: PubsubTopic[],
|
33
|
-
libp2p: Libp2p
|
34
|
-
) {
|
35
|
-
super(StoreCodec, libp2p.components, pubsubTopics);
|
36
|
-
}
|
37
|
-
|
38
|
-
public async *queryPerPage<T extends IDecodedMessage>(
|
39
|
-
queryOpts: QueryRequestParams,
|
40
|
-
decoders: Map<string, IDecoder<T>>,
|
41
|
-
peerId: PeerId
|
42
|
-
): AsyncGenerator<Promise<T | undefined>[]> {
|
43
|
-
if (
|
44
|
-
queryOpts.contentTopics.toString() !==
|
45
|
-
Array.from(decoders.keys()).toString()
|
46
|
-
) {
|
47
|
-
throw new Error(
|
48
|
-
"Internal error, the decoders should match the query's content topics"
|
49
|
-
);
|
50
|
-
}
|
51
|
-
|
52
|
-
let currentCursor = queryOpts.paginationCursor;
|
53
|
-
while (true) {
|
54
|
-
const storeQueryRequest = StoreQueryRequest.create({
|
55
|
-
...queryOpts,
|
56
|
-
paginationCursor: currentCursor
|
57
|
-
});
|
58
|
-
|
59
|
-
let stream;
|
60
|
-
try {
|
61
|
-
stream = await this.getStream(peerId);
|
62
|
-
} catch (e) {
|
63
|
-
log.error("Failed to get stream", e);
|
64
|
-
break;
|
65
|
-
}
|
66
|
-
|
67
|
-
const res = await pipe(
|
68
|
-
[storeQueryRequest.encode()],
|
69
|
-
lp.encode,
|
70
|
-
stream,
|
71
|
-
lp.decode,
|
72
|
-
async (source) => await all(source)
|
73
|
-
);
|
74
|
-
|
75
|
-
const bytes = new Uint8ArrayList();
|
76
|
-
res.forEach((chunk) => {
|
77
|
-
bytes.append(chunk);
|
78
|
-
});
|
79
|
-
|
80
|
-
const storeQueryResponse = StoreQueryResponse.decode(bytes);
|
81
|
-
|
82
|
-
if (
|
83
|
-
!storeQueryResponse.statusCode ||
|
84
|
-
storeQueryResponse.statusCode >= 300
|
85
|
-
) {
|
86
|
-
const errorMessage = `Store query failed with status code: ${storeQueryResponse.statusCode}, description: ${storeQueryResponse.statusDesc}`;
|
87
|
-
log.error(errorMessage);
|
88
|
-
throw new Error(errorMessage);
|
89
|
-
}
|
90
|
-
|
91
|
-
if (!storeQueryResponse.messages || !storeQueryResponse.messages.length) {
|
92
|
-
log.warn("Stopping pagination due to empty messages in response");
|
93
|
-
break;
|
94
|
-
}
|
95
|
-
|
96
|
-
log.info(
|
97
|
-
`${storeQueryResponse.messages.length} messages retrieved from store`
|
98
|
-
);
|
99
|
-
|
100
|
-
const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
|
101
|
-
if (!protoMsg.message) {
|
102
|
-
return Promise.resolve(undefined);
|
103
|
-
}
|
104
|
-
const contentTopic = protoMsg.message.contentTopic;
|
105
|
-
if (contentTopic) {
|
106
|
-
const decoder = decoders.get(contentTopic);
|
107
|
-
if (decoder) {
|
108
|
-
return decoder.fromProtoObj(
|
109
|
-
protoMsg.pubsubTopic || "",
|
110
|
-
toProtoMessage(protoMsg.message)
|
111
|
-
);
|
112
|
-
}
|
113
|
-
}
|
114
|
-
return Promise.resolve(undefined);
|
115
|
-
});
|
116
|
-
|
117
|
-
yield decodedMessages;
|
118
|
-
|
119
|
-
if (queryOpts.paginationForward) {
|
120
|
-
currentCursor =
|
121
|
-
storeQueryResponse.messages[storeQueryResponse.messages.length - 1]
|
122
|
-
.messageHash;
|
123
|
-
} else {
|
124
|
-
currentCursor = storeQueryResponse.messages[0].messageHash;
|
125
|
-
}
|
126
|
-
|
127
|
-
if (
|
128
|
-
storeQueryResponse.messages.length > MAX_PAGE_SIZE &&
|
129
|
-
storeQueryResponse.messages.length <
|
130
|
-
(queryOpts.paginationLimit || DEFAULT_PAGE_SIZE)
|
131
|
-
) {
|
132
|
-
break;
|
133
|
-
}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|