gennet.js 0.2.0 → 0.2.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/README.md +32 -2
- package/dist/index.d.cts +11 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ Client library for [GenNet](https://github.com/cryptagoEU/gennet.js) — interac
|
|
|
15
15
|
- WebSocket & HTTP providers
|
|
16
16
|
- Full TypeScript support (ESM + CJS)
|
|
17
17
|
- Subscriptions (logs, messages, mempool)
|
|
18
|
+
- Auto-reconnect with exponential backoff
|
|
19
|
+
- Connection events (connect, disconnect, error)
|
|
18
20
|
|
|
19
21
|
## Installation
|
|
20
22
|
|
|
@@ -53,12 +55,20 @@ const gennet = new GenNet('ws://localhost:18789');
|
|
|
53
55
|
const gennet = new GenNet('http://localhost:18790');
|
|
54
56
|
```
|
|
55
57
|
|
|
56
|
-
You can also pass a custom provider:
|
|
58
|
+
You can also pass a custom provider with options:
|
|
57
59
|
|
|
58
60
|
```typescript
|
|
59
61
|
import { GenNet, WebSocketProvider } from 'gennet.js';
|
|
60
62
|
|
|
61
|
-
const provider = new WebSocketProvider('ws://localhost:18789'
|
|
63
|
+
const provider = new WebSocketProvider('ws://localhost:18789', {
|
|
64
|
+
timeout: 10_000,
|
|
65
|
+
reconnect: {
|
|
66
|
+
enabled: true, // default: true
|
|
67
|
+
maxRetries: 10, // default: 5
|
|
68
|
+
delay: 2000, // default: 1000ms (doubles each attempt)
|
|
69
|
+
maxDelay: 60_000, // default: 30000ms
|
|
70
|
+
},
|
|
71
|
+
});
|
|
62
72
|
const gennet = new GenNet(provider);
|
|
63
73
|
```
|
|
64
74
|
|
|
@@ -123,6 +133,26 @@ For methods not covered by the namespaces:
|
|
|
123
133
|
const result = await gennet.request('custom_method', { key: 'value' });
|
|
124
134
|
```
|
|
125
135
|
|
|
136
|
+
## Events
|
|
137
|
+
|
|
138
|
+
The WebSocket provider emits connection lifecycle events:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
gennet.on('connect', () => {
|
|
142
|
+
console.log('Connected to GenNet node');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
gennet.on('disconnect', () => {
|
|
146
|
+
console.log('Disconnected — reconnecting...');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
gennet.on('error', (err) => {
|
|
150
|
+
console.error('Connection error:', err.message);
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Auto-reconnect is enabled by default. After a disconnect, the provider reconnects with exponential backoff. Call `gennet.disconnect()` to stop reconnecting.
|
|
155
|
+
|
|
126
156
|
## Error Handling
|
|
127
157
|
|
|
128
158
|
RPC errors throw a typed `RpcError`:
|
package/dist/index.d.cts
CHANGED
|
@@ -39,6 +39,13 @@ interface ModuleInfo {
|
|
|
39
39
|
state: string;
|
|
40
40
|
status?: string;
|
|
41
41
|
}
|
|
42
|
+
interface TransportInfo {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
host?: string;
|
|
45
|
+
port?: number;
|
|
46
|
+
api: string[];
|
|
47
|
+
origins?: string[];
|
|
48
|
+
}
|
|
42
49
|
interface NodeInfo {
|
|
43
50
|
state: GatewayState;
|
|
44
51
|
peerId: string | null;
|
|
@@ -53,6 +60,9 @@ interface NodeInfo {
|
|
|
53
60
|
listenPort: number;
|
|
54
61
|
datadir: string;
|
|
55
62
|
modules: ModuleInfo[];
|
|
63
|
+
ws: TransportInfo;
|
|
64
|
+
http: TransportInfo;
|
|
65
|
+
ipc: boolean;
|
|
56
66
|
}
|
|
57
67
|
interface PeerInfo {
|
|
58
68
|
peerId: string;
|
|
@@ -287,4 +297,4 @@ declare class HttpProvider implements Provider {
|
|
|
287
297
|
}
|
|
288
298
|
|
|
289
299
|
export { Admin, Agent, GenNet, HttpProvider, Mempool, Net, Personal, RpcError, WebSocketProvider };
|
|
290
|
-
export type { AgentResult, GatewayState, IdentityInfo, JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, ModuleInfo, NodeInfo, PeerInfo, Provider, ProviderEvent, ProviderEventListener, ReconnectOptions, Subscription, SubscriptionTopic };
|
|
300
|
+
export type { AgentResult, GatewayState, IdentityInfo, JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, ModuleInfo, NodeInfo, PeerInfo, Provider, ProviderEvent, ProviderEventListener, ReconnectOptions, Subscription, SubscriptionTopic, TransportInfo };
|
package/dist/index.d.mts
CHANGED
|
@@ -39,6 +39,13 @@ interface ModuleInfo {
|
|
|
39
39
|
state: string;
|
|
40
40
|
status?: string;
|
|
41
41
|
}
|
|
42
|
+
interface TransportInfo {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
host?: string;
|
|
45
|
+
port?: number;
|
|
46
|
+
api: string[];
|
|
47
|
+
origins?: string[];
|
|
48
|
+
}
|
|
42
49
|
interface NodeInfo {
|
|
43
50
|
state: GatewayState;
|
|
44
51
|
peerId: string | null;
|
|
@@ -53,6 +60,9 @@ interface NodeInfo {
|
|
|
53
60
|
listenPort: number;
|
|
54
61
|
datadir: string;
|
|
55
62
|
modules: ModuleInfo[];
|
|
63
|
+
ws: TransportInfo;
|
|
64
|
+
http: TransportInfo;
|
|
65
|
+
ipc: boolean;
|
|
56
66
|
}
|
|
57
67
|
interface PeerInfo {
|
|
58
68
|
peerId: string;
|
|
@@ -287,4 +297,4 @@ declare class HttpProvider implements Provider {
|
|
|
287
297
|
}
|
|
288
298
|
|
|
289
299
|
export { Admin, Agent, GenNet, HttpProvider, Mempool, Net, Personal, RpcError, WebSocketProvider };
|
|
290
|
-
export type { AgentResult, GatewayState, IdentityInfo, JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, ModuleInfo, NodeInfo, PeerInfo, Provider, ProviderEvent, ProviderEventListener, ReconnectOptions, Subscription, SubscriptionTopic };
|
|
300
|
+
export type { AgentResult, GatewayState, IdentityInfo, JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, ModuleInfo, NodeInfo, PeerInfo, Provider, ProviderEvent, ProviderEventListener, ReconnectOptions, Subscription, SubscriptionTopic, TransportInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,13 @@ interface ModuleInfo {
|
|
|
39
39
|
state: string;
|
|
40
40
|
status?: string;
|
|
41
41
|
}
|
|
42
|
+
interface TransportInfo {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
host?: string;
|
|
45
|
+
port?: number;
|
|
46
|
+
api: string[];
|
|
47
|
+
origins?: string[];
|
|
48
|
+
}
|
|
42
49
|
interface NodeInfo {
|
|
43
50
|
state: GatewayState;
|
|
44
51
|
peerId: string | null;
|
|
@@ -53,6 +60,9 @@ interface NodeInfo {
|
|
|
53
60
|
listenPort: number;
|
|
54
61
|
datadir: string;
|
|
55
62
|
modules: ModuleInfo[];
|
|
63
|
+
ws: TransportInfo;
|
|
64
|
+
http: TransportInfo;
|
|
65
|
+
ipc: boolean;
|
|
56
66
|
}
|
|
57
67
|
interface PeerInfo {
|
|
58
68
|
peerId: string;
|
|
@@ -287,4 +297,4 @@ declare class HttpProvider implements Provider {
|
|
|
287
297
|
}
|
|
288
298
|
|
|
289
299
|
export { Admin, Agent, GenNet, HttpProvider, Mempool, Net, Personal, RpcError, WebSocketProvider };
|
|
290
|
-
export type { AgentResult, GatewayState, IdentityInfo, JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, ModuleInfo, NodeInfo, PeerInfo, Provider, ProviderEvent, ProviderEventListener, ReconnectOptions, Subscription, SubscriptionTopic };
|
|
300
|
+
export type { AgentResult, GatewayState, IdentityInfo, JsonRpcErrorResponse, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, ModuleInfo, NodeInfo, PeerInfo, Provider, ProviderEvent, ProviderEventListener, ReconnectOptions, Subscription, SubscriptionTopic, TransportInfo };
|