@olane/o-node 0.7.12-alpha.21 → 0.7.12-alpha.23
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/o-core/src/connection/o-response.d.ts +26 -0
- package/dist/o-core/src/connection/o-response.d.ts.map +1 -0
- package/dist/o-core/src/connection/o-response.js +45 -0
- package/dist/o-core/src/error/enums/codes.error.d.ts +20 -0
- package/dist/o-core/src/error/enums/codes.error.d.ts.map +1 -0
- package/dist/o-core/src/error/enums/codes.error.js +20 -0
- package/dist/o-core/src/error/interfaces/o-error.interface.d.ts +6 -0
- package/dist/o-core/src/error/interfaces/o-error.interface.d.ts.map +1 -0
- package/dist/o-core/src/error/interfaces/o-error.interface.js +1 -0
- package/dist/o-core/src/error/o-error.d.ts +15 -0
- package/dist/o-core/src/error/o-error.d.ts.map +1 -0
- package/dist/o-core/src/error/o-error.js +27 -0
- package/dist/o-core/src/streaming/index.d.ts +11 -0
- package/dist/o-core/src/streaming/index.d.ts.map +1 -0
- package/dist/o-core/src/streaming/index.js +14 -0
- package/dist/o-core/src/streaming/protocol-builder.d.ts +62 -0
- package/dist/o-core/src/streaming/protocol-builder.d.ts.map +1 -0
- package/dist/o-core/src/streaming/protocol-builder.js +93 -0
- package/dist/o-core/src/streaming/stream-config.d.ts +36 -0
- package/dist/o-core/src/streaming/stream-config.d.ts.map +1 -0
- package/dist/o-core/src/streaming/stream-config.js +19 -0
- package/dist/o-core/src/streaming/stream-handler.base.d.ts +85 -0
- package/dist/o-core/src/streaming/stream-handler.base.d.ts.map +1 -0
- package/dist/o-core/src/streaming/stream-handler.base.js +112 -0
- package/dist/o-core/src/streaming/stream-transport.interface.d.ts +61 -0
- package/dist/o-core/src/streaming/stream-transport.interface.d.ts.map +1 -0
- package/dist/o-core/src/streaming/stream-transport.interface.js +10 -0
- package/dist/o-core/src/utils/streaming.utils.d.ts +37 -0
- package/dist/o-core/src/utils/streaming.utils.d.ts.map +1 -0
- package/dist/o-core/src/utils/streaming.utils.js +71 -0
- package/dist/o-node/src/connection/index.d.ts +5 -0
- package/dist/o-node/src/connection/index.d.ts.map +1 -0
- package/dist/o-node/src/connection/index.js +4 -0
- package/dist/o-node/src/connection/interfaces/o-node-connection-manager.config.d.ts +6 -0
- package/dist/o-node/src/connection/interfaces/o-node-connection-manager.config.d.ts.map +1 -0
- package/dist/o-node/src/connection/interfaces/o-node-connection-manager.config.js +1 -0
- package/dist/o-node/src/connection/interfaces/o-node-connection.config.d.ts +6 -0
- package/dist/o-node/src/connection/interfaces/o-node-connection.config.d.ts.map +1 -0
- package/dist/o-node/src/connection/interfaces/o-node-connection.config.js +1 -0
- package/dist/o-node/src/connection/o-node-connection.d.ts +20 -0
- package/dist/o-node/src/connection/o-node-connection.d.ts.map +1 -0
- package/dist/o-node/src/connection/o-node-connection.js +146 -0
- package/dist/o-node/src/connection/o-node-connection.manager.d.ts +19 -0
- package/dist/o-node/src/connection/o-node-connection.manager.d.ts.map +1 -0
- package/dist/o-node/src/connection/o-node-connection.manager.js +92 -0
- package/dist/o-node/src/index.d.ts +10 -0
- package/dist/o-node/src/index.d.ts.map +1 -0
- package/dist/o-node/src/index.js +9 -0
- package/dist/o-node/src/interfaces/i-heartbeatable-node.d.ts +49 -0
- package/dist/o-node/src/interfaces/i-heartbeatable-node.d.ts.map +1 -0
- package/dist/o-node/src/interfaces/i-heartbeatable-node.js +1 -0
- package/dist/o-node/src/interfaces/i-reconnectable-node.d.ts +46 -0
- package/dist/o-node/src/interfaces/i-reconnectable-node.d.ts.map +1 -0
- package/dist/o-node/src/interfaces/i-reconnectable-node.js +1 -0
- package/dist/o-node/src/interfaces/o-node.config.d.ts +66 -0
- package/dist/o-node/src/interfaces/o-node.config.d.ts.map +1 -0
- package/dist/o-node/src/interfaces/o-node.config.js +1 -0
- package/dist/o-node/src/interfaces/o-node.tool-config.d.ts +4 -0
- package/dist/o-node/src/interfaces/o-node.tool-config.d.ts.map +1 -0
- package/dist/o-node/src/interfaces/o-node.tool-config.js +1 -0
- package/dist/o-node/src/lib/network-activity.lib.d.ts +1 -0
- package/dist/o-node/src/lib/network-activity.lib.d.ts.map +1 -0
- package/dist/o-node/src/lib/network-activity.lib.js +34 -0
- package/dist/o-node/src/managers/o-connection-heartbeat.manager.d.ts +62 -0
- package/dist/o-node/src/managers/o-connection-heartbeat.manager.d.ts.map +1 -0
- package/dist/o-node/src/managers/o-connection-heartbeat.manager.js +213 -0
- package/dist/o-node/src/managers/o-reconnection.manager.d.ts +51 -0
- package/dist/o-node/src/managers/o-reconnection.manager.d.ts.map +1 -0
- package/dist/o-node/src/managers/o-reconnection.manager.js +266 -0
- package/dist/o-node/src/nodes/client.node.d.ts +7 -0
- package/dist/o-node/src/nodes/client.node.d.ts.map +1 -0
- package/dist/o-node/src/nodes/client.node.js +16 -0
- package/dist/o-node/src/nodes/index.d.ts +4 -0
- package/dist/o-node/src/nodes/index.d.ts.map +1 -0
- package/dist/o-node/src/nodes/index.js +3 -0
- package/dist/o-node/src/nodes/server.node.d.ts +7 -0
- package/dist/o-node/src/nodes/server.node.d.ts.map +1 -0
- package/dist/o-node/src/nodes/server.node.js +20 -0
- package/dist/o-node/src/nodes/websocket.node.d.ts +7 -0
- package/dist/o-node/src/nodes/websocket.node.d.ts.map +1 -0
- package/dist/o-node/src/nodes/websocket.node.js +18 -0
- package/dist/o-node/src/o-node.d.ts +72 -0
- package/dist/o-node/src/o-node.d.ts.map +1 -0
- package/dist/o-node/src/o-node.hierarchy-manager.d.ts +15 -0
- package/dist/o-node/src/o-node.hierarchy-manager.d.ts.map +1 -0
- package/dist/o-node/src/o-node.hierarchy-manager.js +15 -0
- package/dist/o-node/src/o-node.js +420 -0
- package/dist/o-node/src/o-node.notification-manager.d.ts +52 -0
- package/dist/o-node/src/o-node.notification-manager.d.ts.map +1 -0
- package/dist/o-node/src/o-node.notification-manager.js +185 -0
- package/dist/o-node/src/o-node.tool.d.ts +18 -0
- package/dist/o-node/src/o-node.tool.d.ts.map +1 -0
- package/dist/o-node/src/o-node.tool.js +116 -0
- package/dist/o-node/src/router/index.d.ts +6 -0
- package/dist/o-node/src/router/index.d.ts.map +1 -0
- package/dist/o-node/src/router/index.js +5 -0
- package/dist/o-node/src/router/interfaces/o-node-router.config.d.ts +3 -0
- package/dist/o-node/src/router/interfaces/o-node-router.config.d.ts.map +1 -0
- package/dist/o-node/src/router/interfaces/o-node-router.config.js +1 -0
- package/dist/o-node/src/router/interfaces/o-node-router.response.d.ts +8 -0
- package/dist/o-node/src/router/interfaces/o-node-router.response.d.ts.map +1 -0
- package/dist/o-node/src/router/interfaces/o-node-router.response.js +1 -0
- package/dist/o-node/src/router/o-node.address.d.ts +18 -0
- package/dist/o-node/src/router/o-node.address.d.ts.map +1 -0
- package/dist/o-node/src/router/o-node.address.js +29 -0
- package/dist/o-node/src/router/o-node.router.d.ts +45 -0
- package/dist/o-node/src/router/o-node.router.d.ts.map +1 -0
- package/dist/o-node/src/router/o-node.router.js +125 -0
- package/dist/o-node/src/router/o-node.routing-policy.d.ts +30 -0
- package/dist/o-node/src/router/o-node.routing-policy.d.ts.map +1 -0
- package/dist/o-node/src/router/o-node.routing-policy.js +57 -0
- package/dist/o-node/src/router/o-node.transport.d.ts +11 -0
- package/dist/o-node/src/router/o-node.transport.d.ts.map +1 -0
- package/dist/o-node/src/router/o-node.transport.js +18 -0
- package/dist/o-node/src/router/resolvers/index.d.ts +4 -0
- package/dist/o-node/src/router/resolvers/index.d.ts.map +1 -0
- package/dist/o-node/src/router/resolvers/index.js +3 -0
- package/dist/o-node/src/router/resolvers/o-node.leader-resolver-fallback.d.ts +8 -0
- package/dist/o-node/src/router/resolvers/o-node.leader-resolver-fallback.d.ts.map +1 -0
- package/dist/o-node/src/router/resolvers/o-node.leader-resolver-fallback.js +35 -0
- package/dist/o-node/src/router/resolvers/o-node.resolver.d.ts +11 -0
- package/dist/o-node/src/router/resolvers/o-node.resolver.d.ts.map +1 -0
- package/dist/o-node/src/router/resolvers/o-node.resolver.js +41 -0
- package/dist/o-node/src/router/resolvers/o-node.search-resolver.d.ts +170 -0
- package/dist/o-node/src/router/resolvers/o-node.search-resolver.d.ts.map +1 -0
- package/dist/o-node/src/router/resolvers/o-node.search-resolver.js +285 -0
- package/dist/o-node/src/router/route.request.d.ts +14 -0
- package/dist/o-node/src/router/route.request.d.ts.map +1 -0
- package/dist/o-node/src/router/route.request.js +1 -0
- package/dist/o-node/src/streaming/index.d.ts +10 -0
- package/dist/o-node/src/streaming/index.d.ts.map +1 -0
- package/dist/o-node/src/streaming/index.js +12 -0
- package/dist/o-node/src/streaming/libp2p-stream-transport.d.ts +50 -0
- package/dist/o-node/src/streaming/libp2p-stream-transport.d.ts.map +1 -0
- package/dist/o-node/src/streaming/libp2p-stream-transport.js +137 -0
- package/dist/o-node/src/streaming/node-stream-handler.d.ts +65 -0
- package/dist/o-node/src/streaming/node-stream-handler.d.ts.map +1 -0
- package/dist/o-node/src/streaming/node-stream-handler.js +101 -0
- package/dist/o-node/src/utils/circuit-breaker.d.ts +107 -0
- package/dist/o-node/src/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/o-node/src/utils/circuit-breaker.js +175 -0
- package/dist/o-node/src/utils/circuit-breaker.test.d.ts +2 -0
- package/dist/o-node/src/utils/circuit-breaker.test.d.ts.map +1 -0
- package/dist/o-node/src/utils/circuit-breaker.test.js +262 -0
- package/dist/o-node/src/utils/leader-request-wrapper.d.ts +66 -0
- package/dist/o-node/src/utils/leader-request-wrapper.d.ts.map +1 -0
- package/dist/o-node/src/utils/leader-request-wrapper.js +160 -0
- package/dist/o-node/src/utils/leader-request-wrapper.test.d.ts +1 -0
- package/dist/o-node/src/utils/leader-request-wrapper.test.d.ts.map +1 -0
- package/dist/o-node/src/utils/leader-request-wrapper.test.js +246 -0
- package/dist/o-node/src/utils/network.utils.d.ts +20 -0
- package/dist/o-node/src/utils/network.utils.d.ts.map +1 -0
- package/dist/o-node/src/utils/network.utils.js +74 -0
- package/dist/o-node/test/o-node.spec.d.ts +2 -0
- package/dist/o-node/test/o-node.spec.d.ts.map +1 -0
- package/dist/o-node/test/o-node.spec.js +20 -0
- package/dist/o-node/test/search-resolver.spec.d.ts +2 -0
- package/dist/o-node/test/search-resolver.spec.d.ts.map +1 -0
- package/dist/o-node/test/search-resolver.spec.js +693 -0
- package/dist/src/connection/o-node-connection.d.ts +7 -0
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +89 -2
- package/dist/src/connection/o-node-connection.manager.d.ts +2 -0
- package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.manager.js +5 -1
- package/dist/src/interfaces/o-node.config.d.ts +16 -0
- package/dist/src/interfaces/o-node.config.d.ts.map +1 -1
- package/dist/src/o-node.d.ts +1 -1
- package/dist/src/o-node.d.ts.map +1 -1
- package/dist/src/o-node.js +5 -1
- package/dist/src/o-node.tool.d.ts.map +1 -1
- package/dist/src/o-node.tool.js +37 -7
- package/dist/src/router/resolvers/o-node.search-resolver.d.ts.map +1 -1
- package/dist/src/router/resolvers/o-node.search-resolver.js +10 -3
- package/package.json +6 -6
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream status states
|
|
3
|
+
*/
|
|
4
|
+
export declare enum StreamStatus {
|
|
5
|
+
OPEN = "open",
|
|
6
|
+
CLOSING = "closing",
|
|
7
|
+
CLOSED = "closed",
|
|
8
|
+
RESET = "reset"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Transport-agnostic interface for stream operations.
|
|
12
|
+
* Implementations can use libp2p, WebSockets, HTTP/2, or any other streaming transport.
|
|
13
|
+
*/
|
|
14
|
+
export interface IStreamTransport {
|
|
15
|
+
/**
|
|
16
|
+
* Send data through the stream with backpressure handling
|
|
17
|
+
* @param data - The data to send (UTF-8 encoded bytes)
|
|
18
|
+
* @returns Promise that resolves when data is sent (handles backpressure internally)
|
|
19
|
+
*/
|
|
20
|
+
send(data: Uint8Array): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Set up a message handler for incoming data
|
|
23
|
+
* @param handler - Callback function to handle incoming messages
|
|
24
|
+
*/
|
|
25
|
+
onMessage(handler: (data: Uint8Array) => void): void;
|
|
26
|
+
/**
|
|
27
|
+
* Remove the message handler
|
|
28
|
+
*/
|
|
29
|
+
removeMessageHandler(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Close the stream and clean up resources
|
|
32
|
+
* @returns Promise that resolves when stream is closed
|
|
33
|
+
*/
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the current status of the stream
|
|
37
|
+
* @returns The current stream status
|
|
38
|
+
*/
|
|
39
|
+
getStatus(): StreamStatus;
|
|
40
|
+
/**
|
|
41
|
+
* Check if the stream is in a usable state
|
|
42
|
+
* @returns true if stream can send/receive data
|
|
43
|
+
*/
|
|
44
|
+
isOpen(): boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration options for stream transport operations
|
|
48
|
+
*/
|
|
49
|
+
export interface StreamTransportConfig {
|
|
50
|
+
/**
|
|
51
|
+
* Timeout in milliseconds for drain operations when handling backpressure
|
|
52
|
+
* @default 30000 (30 seconds)
|
|
53
|
+
*/
|
|
54
|
+
drainTimeoutMs?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum time in milliseconds to wait for the first message
|
|
57
|
+
* @default 120000 (2 minutes)
|
|
58
|
+
*/
|
|
59
|
+
readTimeoutMs?: number;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=stream-transport.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-transport.interface.d.ts","sourceRoot":"","sources":["../../../../../o-core/src/streaming/stream-transport.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAAC;IAErD;;OAEG;IACH,oBAAoB,IAAI,IAAI,CAAC;IAE7B;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,SAAS,IAAI,YAAY,CAAC;IAE1B;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream status states
|
|
3
|
+
*/
|
|
4
|
+
export var StreamStatus;
|
|
5
|
+
(function (StreamStatus) {
|
|
6
|
+
StreamStatus["OPEN"] = "open";
|
|
7
|
+
StreamStatus["CLOSING"] = "closing";
|
|
8
|
+
StreamStatus["CLOSED"] = "closed";
|
|
9
|
+
StreamStatus["RESET"] = "reset";
|
|
10
|
+
})(StreamStatus || (StreamStatus = {}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { oResponse } from '../connection/o-response.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if a value is an AsyncGenerator
|
|
4
|
+
* @param value - The value to check
|
|
5
|
+
* @returns true if the value is an AsyncGenerator
|
|
6
|
+
*/
|
|
7
|
+
export declare function isAsyncGenerator(value: any): value is AsyncGenerator;
|
|
8
|
+
/**
|
|
9
|
+
* Safely iterate through an AsyncGenerator with error handling
|
|
10
|
+
* @param generator - The AsyncGenerator to iterate
|
|
11
|
+
* @param onChunk - Callback for each chunk
|
|
12
|
+
* @param onError - Optional error handler
|
|
13
|
+
* @returns Promise that resolves when iteration is complete
|
|
14
|
+
*/
|
|
15
|
+
export declare function iterateAsyncGenerator<T>(generator: AsyncGenerator<T>, onChunk: (chunk: T) => Promise<void> | void, onError?: (error: unknown) => void): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Create an oResponse object configured for streaming
|
|
18
|
+
* @param connectionId - The connection ID
|
|
19
|
+
* @param requestMethod - The request method
|
|
20
|
+
* @param requestId - The request ID
|
|
21
|
+
* @returns An oResponse configured for streaming
|
|
22
|
+
*/
|
|
23
|
+
export declare function createStreamingResponse(connectionId: string, requestMethod: string, requestId: string | number): oResponse;
|
|
24
|
+
/**
|
|
25
|
+
* Collect all chunks from an AsyncGenerator into an array
|
|
26
|
+
* Useful for testing or converting streaming responses to non-streaming
|
|
27
|
+
* @param generator - The AsyncGenerator to collect from
|
|
28
|
+
* @returns Promise resolving to array of all chunks
|
|
29
|
+
*/
|
|
30
|
+
export declare function collectStreamChunks<T>(generator: AsyncGenerator<T>): Promise<T[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Process incoming stream data (deserialize from bytes)
|
|
33
|
+
* @param data - The data to process
|
|
34
|
+
* @returns Parsed message object
|
|
35
|
+
*/
|
|
36
|
+
export declare function processStream(data: Uint8Array): any;
|
|
37
|
+
//# sourceMappingURL=streaming.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.utils.d.ts","sourceRoot":"","sources":["../../../../../o-core/src/utils/streaming.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,cAAc,CAMpE;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,EAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAC3C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACjC,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAAG,MAAM,GACzB,SAAS,CAQX;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAMd;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,GAAG,CAGnD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { oResponse } from '../connection/o-response.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if a value is an AsyncGenerator
|
|
4
|
+
* @param value - The value to check
|
|
5
|
+
* @returns true if the value is an AsyncGenerator
|
|
6
|
+
*/
|
|
7
|
+
export function isAsyncGenerator(value) {
|
|
8
|
+
return (value != null &&
|
|
9
|
+
typeof value === 'object' &&
|
|
10
|
+
typeof value[Symbol.asyncIterator] === 'function');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Safely iterate through an AsyncGenerator with error handling
|
|
14
|
+
* @param generator - The AsyncGenerator to iterate
|
|
15
|
+
* @param onChunk - Callback for each chunk
|
|
16
|
+
* @param onError - Optional error handler
|
|
17
|
+
* @returns Promise that resolves when iteration is complete
|
|
18
|
+
*/
|
|
19
|
+
export async function iterateAsyncGenerator(generator, onChunk, onError) {
|
|
20
|
+
try {
|
|
21
|
+
for await (const chunk of generator) {
|
|
22
|
+
await onChunk(chunk);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (onError) {
|
|
27
|
+
onError(error);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create an oResponse object configured for streaming
|
|
36
|
+
* @param connectionId - The connection ID
|
|
37
|
+
* @param requestMethod - The request method
|
|
38
|
+
* @param requestId - The request ID
|
|
39
|
+
* @returns An oResponse configured for streaming
|
|
40
|
+
*/
|
|
41
|
+
export function createStreamingResponse(connectionId, requestMethod, requestId) {
|
|
42
|
+
const response = new oResponse({
|
|
43
|
+
id: requestId,
|
|
44
|
+
_connectionId: connectionId,
|
|
45
|
+
_requestMethod: requestMethod,
|
|
46
|
+
});
|
|
47
|
+
response.isStreaming = true;
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Collect all chunks from an AsyncGenerator into an array
|
|
52
|
+
* Useful for testing or converting streaming responses to non-streaming
|
|
53
|
+
* @param generator - The AsyncGenerator to collect from
|
|
54
|
+
* @returns Promise resolving to array of all chunks
|
|
55
|
+
*/
|
|
56
|
+
export async function collectStreamChunks(generator) {
|
|
57
|
+
const chunks = [];
|
|
58
|
+
for await (const chunk of generator) {
|
|
59
|
+
chunks.push(chunk);
|
|
60
|
+
}
|
|
61
|
+
return chunks;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Process incoming stream data (deserialize from bytes)
|
|
65
|
+
* @param data - The data to process
|
|
66
|
+
* @returns Parsed message object
|
|
67
|
+
*/
|
|
68
|
+
export function processStream(data) {
|
|
69
|
+
const text = new TextDecoder().decode(data);
|
|
70
|
+
return JSON.parse(text);
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { oConnectionManagerConfig } from '@olane/o-core';
|
|
2
|
+
import { Libp2p } from '@olane/o-config';
|
|
3
|
+
export interface oNodeConnectionManagerConfig extends oConnectionManagerConfig {
|
|
4
|
+
p2pNode: Libp2p;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=o-node-connection-manager.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../../src/connection/interfaces/o-node-connection-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-connection.config.d.ts","sourceRoot":"","sources":["../../../../../src/connection/interfaces/o-node-connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,aAAa,EAAE,UAAU,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Connection, Stream } from '@olane/o-config';
|
|
2
|
+
import { oConnection, oRequest, oResponse } from '@olane/o-core';
|
|
3
|
+
import { oNodeConnectionConfig } from './interfaces/o-node-connection.config.js';
|
|
4
|
+
export declare class oNodeConnection extends oConnection {
|
|
5
|
+
protected readonly config: oNodeConnectionConfig;
|
|
6
|
+
p2pConnection: Connection;
|
|
7
|
+
constructor(config: oNodeConnectionConfig);
|
|
8
|
+
read(source: Stream): Promise<any>;
|
|
9
|
+
validate(): void;
|
|
10
|
+
transmit(request: oRequest): Promise<oResponse>;
|
|
11
|
+
/**
|
|
12
|
+
* Transmit a request and receive streaming chunks via callback
|
|
13
|
+
* @param request The request to send
|
|
14
|
+
* @param onChunk Callback function called for each chunk received
|
|
15
|
+
* @returns Promise that resolves when stream is complete
|
|
16
|
+
*/
|
|
17
|
+
transmitStreaming(request: oRequest, onChunk: (chunk: any, sequence: number, isLast: boolean) => void): Promise<void>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=o-node-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../../src/connection/o-node-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAIV,MAAM,EAEP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAIjF,qBAAa,eAAgB,SAAQ,WAAW;IAGlC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IAFrD,aAAa,EAAE,UAAU,CAAC;gBAEF,MAAM,EAAE,qBAAqB;IAKtD,IAAI,CAAC,MAAM,EAAE,MAAM;IAWzB,QAAQ;IAOF,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAmDrD;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAC/D,OAAO,CAAC,IAAI,CAAC;IA+FV,KAAK;CAKZ"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Uint8ArrayList, byteStream, } from '@olane/o-config';
|
|
2
|
+
import { oConnection, oError, oErrorCodes, oResponse, } from '@olane/o-core';
|
|
3
|
+
import { Libp2pStreamTransport } from '../streaming/libp2p-stream-transport.js';
|
|
4
|
+
import { ProtocolBuilder } from '../../../o-core/src/streaming/protocol-builder.js';
|
|
5
|
+
export class oNodeConnection extends oConnection {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.p2pConnection = config.p2pConnection;
|
|
10
|
+
}
|
|
11
|
+
async read(source) {
|
|
12
|
+
const bytes = byteStream(source);
|
|
13
|
+
const output = await bytes.read({
|
|
14
|
+
signal: AbortSignal.timeout(this.config.readTimeoutMs ?? 120000), // Default: 2 min timeout
|
|
15
|
+
});
|
|
16
|
+
const outputObj = output instanceof Uint8ArrayList ? output.subarray() : output;
|
|
17
|
+
const jsonStr = new TextDecoder().decode(outputObj);
|
|
18
|
+
return JSON.parse(jsonStr);
|
|
19
|
+
}
|
|
20
|
+
validate() {
|
|
21
|
+
if (this.config.p2pConnection.status !== 'open') {
|
|
22
|
+
throw new Error('Connection is not valid');
|
|
23
|
+
}
|
|
24
|
+
// do nothing
|
|
25
|
+
}
|
|
26
|
+
async transmit(request) {
|
|
27
|
+
try {
|
|
28
|
+
const stream = await this.p2pConnection.newStream(this.nextHopAddress.protocol, {
|
|
29
|
+
maxOutboundStreams: Infinity,
|
|
30
|
+
runOnLimitedConnection: true, // TODO: should this be configurable?
|
|
31
|
+
});
|
|
32
|
+
if (!stream || (stream.status !== 'open' && stream.status !== 'reset')) {
|
|
33
|
+
throw new oError(oErrorCodes.FAILED_TO_DIAL_TARGET, 'Failed to dial target');
|
|
34
|
+
}
|
|
35
|
+
if (stream.status === 'reset') {
|
|
36
|
+
throw new oError(oErrorCodes.CONNECTION_LIMIT_REACHED, 'Connection limit reached');
|
|
37
|
+
}
|
|
38
|
+
// Send the data with backpressure handling (libp2p v3 best practice)
|
|
39
|
+
const data = new TextEncoder().encode(request.toString());
|
|
40
|
+
const sent = stream.send(data);
|
|
41
|
+
// If send() returns false, wait for the stream to drain before continuing
|
|
42
|
+
if (!sent) {
|
|
43
|
+
this.logger.debug('Stream buffer full, waiting for drain...');
|
|
44
|
+
await stream.onDrain({
|
|
45
|
+
signal: AbortSignal.timeout(this.config.drainTimeoutMs ?? 30000),
|
|
46
|
+
}); // Default: 30 second timeout
|
|
47
|
+
}
|
|
48
|
+
const res = await this.read(stream);
|
|
49
|
+
await stream.close();
|
|
50
|
+
// process the response
|
|
51
|
+
const response = new oResponse({
|
|
52
|
+
...res.result,
|
|
53
|
+
});
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error?.name === 'UnsupportedProtocolError') {
|
|
58
|
+
throw new oError(oErrorCodes.NOT_FOUND, 'Address not found');
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Transmit a request and receive streaming chunks via callback
|
|
65
|
+
* @param request The request to send
|
|
66
|
+
* @param onChunk Callback function called for each chunk received
|
|
67
|
+
* @returns Promise that resolves when stream is complete
|
|
68
|
+
*/
|
|
69
|
+
async transmitStreaming(request, onChunk) {
|
|
70
|
+
try {
|
|
71
|
+
const stream = await this.p2pConnection.newStream(this.nextHopAddress.protocol, {
|
|
72
|
+
maxOutboundStreams: Infinity,
|
|
73
|
+
runOnLimitedConnection: true,
|
|
74
|
+
});
|
|
75
|
+
if (!stream || (stream.status !== 'open' && stream.status !== 'reset')) {
|
|
76
|
+
throw new oError(oErrorCodes.FAILED_TO_DIAL_TARGET, 'Failed to dial target');
|
|
77
|
+
}
|
|
78
|
+
if (stream.status === 'reset') {
|
|
79
|
+
throw new oError(oErrorCodes.CONNECTION_LIMIT_REACHED, 'Connection limit reached');
|
|
80
|
+
}
|
|
81
|
+
// Create transport abstraction
|
|
82
|
+
const transport = new Libp2pStreamTransport(stream, {
|
|
83
|
+
drainTimeoutMs: this.config.drainTimeoutMs ?? 30000,
|
|
84
|
+
readTimeoutMs: this.config.readTimeoutMs ?? 120000,
|
|
85
|
+
});
|
|
86
|
+
// Send the request using the transport
|
|
87
|
+
const data = new TextEncoder().encode(request.toString());
|
|
88
|
+
await transport.send(data);
|
|
89
|
+
// Set up to receive multiple chunks
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
// Set up timeout for receiving first chunk
|
|
92
|
+
const timeout = setTimeout(async () => {
|
|
93
|
+
transport.removeMessageHandler();
|
|
94
|
+
await transport.close();
|
|
95
|
+
reject(new oError(oErrorCodes.TIMEOUT, 'Timeout waiting for streaming response'));
|
|
96
|
+
}, this.config.readTimeoutMs ?? 120000);
|
|
97
|
+
let timeoutCleared = false;
|
|
98
|
+
const messageHandler = async (data) => {
|
|
99
|
+
// Clear timeout on first message
|
|
100
|
+
if (!timeoutCleared) {
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
timeoutCleared = true;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const response = ProtocolBuilder.decodeMessage(data);
|
|
106
|
+
// Try to parse as streaming chunk
|
|
107
|
+
const chunk = ProtocolBuilder.parseStreamChunk(response);
|
|
108
|
+
if (chunk) {
|
|
109
|
+
// Streaming response
|
|
110
|
+
onChunk(chunk.data, chunk.sequence, chunk.isLast);
|
|
111
|
+
if (chunk.isLast) {
|
|
112
|
+
transport.removeMessageHandler();
|
|
113
|
+
await transport.close();
|
|
114
|
+
resolve();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Non-streaming response (fallback for compatibility)
|
|
119
|
+
onChunk(response.result, 1, true);
|
|
120
|
+
transport.removeMessageHandler();
|
|
121
|
+
await transport.close();
|
|
122
|
+
resolve();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
transport.removeMessageHandler();
|
|
127
|
+
await transport.close();
|
|
128
|
+
reject(error);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
transport.onMessage(messageHandler);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error?.name === 'UnsupportedProtocolError') {
|
|
136
|
+
throw new oError(oErrorCodes.NOT_FOUND, 'Address not found');
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async close() {
|
|
142
|
+
this.logger.debug('Closing connection');
|
|
143
|
+
await this.p2pConnection.close();
|
|
144
|
+
this.logger.debug('Connection closed');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { oAddress, oConnectionConfig, oConnectionManager } from '@olane/o-core';
|
|
2
|
+
import { oConnection } from '@olane/o-core';
|
|
3
|
+
import { oNodeConnectionManagerConfig } from './interfaces/o-node-connection-manager.config.js';
|
|
4
|
+
import { oNodeConnection } from './o-node-connection.js';
|
|
5
|
+
export declare class oNodeConnectionManager extends oConnectionManager {
|
|
6
|
+
private p2pNode;
|
|
7
|
+
private defaultReadTimeoutMs?;
|
|
8
|
+
private defaultDrainTimeoutMs?;
|
|
9
|
+
constructor(config: oNodeConnectionManagerConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Connect to a given address with exponential backoff retry
|
|
12
|
+
* @param address - The address to connect to
|
|
13
|
+
* @returns The connection object
|
|
14
|
+
*/
|
|
15
|
+
connect(config: oConnectionConfig): Promise<oNodeConnection>;
|
|
16
|
+
isCached(address: oAddress): boolean;
|
|
17
|
+
getCachedConnection(address: oAddress): oConnection | null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=o-node-connection.manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-connection.manager.d.ts","sourceRoot":"","sources":["../../../../src/connection/o-node-connection.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAEhG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,oBAAoB,CAAC,CAAS;IACtC,OAAO,CAAC,qBAAqB,CAAC,CAAS;gBAE3B,MAAM,EAAE,4BAA4B;IAOhD;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC;IA6FlE,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAe3D"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { oConnectionManager } from '@olane/o-core';
|
|
2
|
+
import { oNodeConnection } from './o-node-connection.js';
|
|
3
|
+
export class oNodeConnectionManager extends oConnectionManager {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
super(config);
|
|
6
|
+
this.p2pNode = config.p2pNode;
|
|
7
|
+
this.defaultReadTimeoutMs = config.defaultReadTimeoutMs;
|
|
8
|
+
this.defaultDrainTimeoutMs = config.defaultDrainTimeoutMs;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Connect to a given address with exponential backoff retry
|
|
12
|
+
* @param address - The address to connect to
|
|
13
|
+
* @returns The connection object
|
|
14
|
+
*/
|
|
15
|
+
async connect(config) {
|
|
16
|
+
const { address, nextHopAddress, callerAddress, readTimeoutMs, drainTimeoutMs, } = config;
|
|
17
|
+
// check if we already have a connection to this address
|
|
18
|
+
// TODO: how can we enable caching of connections & connection lifecycles
|
|
19
|
+
if (this.isCached(nextHopAddress)) {
|
|
20
|
+
const cachedConnection = this.getCachedConnection(nextHopAddress);
|
|
21
|
+
if (cachedConnection &&
|
|
22
|
+
cachedConnection.p2pConnection.status === 'open') {
|
|
23
|
+
this.logger.debug('Using cached connection for address: ' + address.toString());
|
|
24
|
+
return cachedConnection;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// cached item is not valid, remove it
|
|
28
|
+
this.cache.delete(nextHopAddress.toString());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Retry configuration for handling transient connection failures
|
|
32
|
+
const MAX_RETRIES = 3;
|
|
33
|
+
const BASE_DELAY_MS = 1000; // Start with 1 second
|
|
34
|
+
const MAX_DELAY_MS = 10000; // Cap at 10 seconds
|
|
35
|
+
// first time setup connection with retry logic
|
|
36
|
+
let lastError;
|
|
37
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
38
|
+
try {
|
|
39
|
+
if (attempt > 0) {
|
|
40
|
+
// Calculate exponential backoff delay: 1s, 2s, 4s, 8s (capped at MAX_DELAY_MS)
|
|
41
|
+
const delay = Math.min(BASE_DELAY_MS * Math.pow(2, attempt - 1), MAX_DELAY_MS);
|
|
42
|
+
this.logger.debug(`Retry attempt ${attempt}/${MAX_RETRIES} for ${nextHopAddress.toString()} after ${delay}ms delay`);
|
|
43
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
44
|
+
}
|
|
45
|
+
const p2pConnection = await this.p2pNode.dial(nextHopAddress.libp2pTransports.map((ma) => ma.toMultiaddr()));
|
|
46
|
+
const connection = new oNodeConnection({
|
|
47
|
+
nextHopAddress: nextHopAddress,
|
|
48
|
+
address: address,
|
|
49
|
+
p2pConnection: p2pConnection,
|
|
50
|
+
callerAddress: callerAddress,
|
|
51
|
+
readTimeoutMs: readTimeoutMs ?? this.defaultReadTimeoutMs,
|
|
52
|
+
drainTimeoutMs: drainTimeoutMs ?? this.defaultDrainTimeoutMs,
|
|
53
|
+
});
|
|
54
|
+
if (attempt > 0) {
|
|
55
|
+
this.logger.info(`Successfully connected to ${nextHopAddress.toString()} on retry attempt ${attempt}`);
|
|
56
|
+
}
|
|
57
|
+
// this.cache.set(nextHopAddress.toString(), connection);
|
|
58
|
+
return connection;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
lastError = error;
|
|
62
|
+
this.logger.warn(`[${callerAddress?.toString() || 'unknown'}] Connection attempt ${attempt + 1}/${MAX_RETRIES + 1} failed for ${nextHopAddress.toString()}: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
|
+
// Don't retry on the last attempt
|
|
64
|
+
if (attempt === MAX_RETRIES) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// All retries exhausted
|
|
70
|
+
this.logger.error(`[${callerAddress?.toString() || 'unknown'}] Failed to connect after ${MAX_RETRIES + 1} attempts to address! Next hop: ${nextHopAddress} With Address: ${address.toString()}`, lastError);
|
|
71
|
+
throw lastError;
|
|
72
|
+
}
|
|
73
|
+
isCached(address) {
|
|
74
|
+
return this.cache.has(address.toString());
|
|
75
|
+
}
|
|
76
|
+
getCachedConnection(address) {
|
|
77
|
+
const key = address.toString();
|
|
78
|
+
try {
|
|
79
|
+
const connection = this.cache.get(key);
|
|
80
|
+
if (!connection) {
|
|
81
|
+
throw new Error('Connection not found in cache');
|
|
82
|
+
}
|
|
83
|
+
connection.validate();
|
|
84
|
+
return connection;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
this.cache.delete(key);
|
|
88
|
+
this.logger.error('Error getting cached connection:', error);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './o-node.js';
|
|
2
|
+
export * from './utils/network.utils.js';
|
|
3
|
+
export * from './o-node.hierarchy-manager.js';
|
|
4
|
+
export * from './interfaces/o-node.config.js';
|
|
5
|
+
export * from './connection/index.js';
|
|
6
|
+
export * from './o-node.tool.js';
|
|
7
|
+
export * from './nodes/index.js';
|
|
8
|
+
export * from './interfaces/o-node.tool-config.js';
|
|
9
|
+
export * from './router/index.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './o-node.js';
|
|
2
|
+
export * from './utils/network.utils.js';
|
|
3
|
+
export * from './o-node.hierarchy-manager.js';
|
|
4
|
+
export * from './interfaces/o-node.config.js';
|
|
5
|
+
export * from './connection/index.js';
|
|
6
|
+
export * from './o-node.tool.js';
|
|
7
|
+
export * from './nodes/index.js';
|
|
8
|
+
export * from './interfaces/o-node.tool-config.js';
|
|
9
|
+
export * from './router/index.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { oNotificationManager } from '@olane/o-core';
|
|
2
|
+
import { Libp2p } from '@olane/o-config';
|
|
3
|
+
import { oNodeAddress } from '../router/o-node.address.js';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for nodes that support connection heartbeat monitoring.
|
|
6
|
+
* This interface defines the contract that oConnectionHeartbeatManager needs
|
|
7
|
+
* to access live hierarchy state without holding stale references.
|
|
8
|
+
*/
|
|
9
|
+
export interface IHeartbeatableNode {
|
|
10
|
+
/**
|
|
11
|
+
* The node's current address
|
|
12
|
+
*/
|
|
13
|
+
address: oNodeAddress;
|
|
14
|
+
/**
|
|
15
|
+
* The notification manager for emitting heartbeat events
|
|
16
|
+
*/
|
|
17
|
+
notificationManager: oNotificationManager;
|
|
18
|
+
/**
|
|
19
|
+
* The underlying libp2p node for ping operations
|
|
20
|
+
*/
|
|
21
|
+
p2pNode: Libp2p;
|
|
22
|
+
/**
|
|
23
|
+
* The current parent address (with live transport updates)
|
|
24
|
+
* @returns Parent address or null if no parent
|
|
25
|
+
*/
|
|
26
|
+
parent: oNodeAddress | null;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current list of leader addresses
|
|
29
|
+
* @returns Array of leader addresses (empty if this node is the leader)
|
|
30
|
+
*/
|
|
31
|
+
getLeaders(): oNodeAddress[];
|
|
32
|
+
/**
|
|
33
|
+
* Get the current list of parent addresses
|
|
34
|
+
* @returns Array of parent addresses
|
|
35
|
+
*/
|
|
36
|
+
getParents(): oNodeAddress[];
|
|
37
|
+
/**
|
|
38
|
+
* Get the current list of child addresses
|
|
39
|
+
* @returns Array of child addresses
|
|
40
|
+
*/
|
|
41
|
+
getChildren(): oNodeAddress[];
|
|
42
|
+
/**
|
|
43
|
+
* Remove a child from the hierarchy
|
|
44
|
+
* @param childAddress The address of the child to remove
|
|
45
|
+
*/
|
|
46
|
+
removeChild(childAddress: oNodeAddress): void;
|
|
47
|
+
use(param1: any, param2: any): Promise<any>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=i-heartbeatable-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-heartbeatable-node.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/i-heartbeatable-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;OAEG;IACH,mBAAmB,EAAE,oBAAoB,CAAC;IAE1C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE5B;;;OAGG;IACH,UAAU,IAAI,YAAY,EAAE,CAAC;IAE7B;;;OAGG;IACH,UAAU,IAAI,YAAY,EAAE,CAAC;IAE7B;;;OAGG;IACH,WAAW,IAAI,YAAY,EAAE,CAAC;IAE9B;;;OAGG;IACH,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAE9C,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { oAddress, NodeState, oNotificationManager } from '@olane/o-core';
|
|
2
|
+
import { oNodeAddress } from '../router/o-node.address.js';
|
|
3
|
+
import { oNodeConfig } from './o-node.config.js';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for nodes that support reconnection management.
|
|
6
|
+
* This interface defines the contract that oReconnectionManager needs
|
|
7
|
+
* to perform reconnection operations without creating a circular dependency.
|
|
8
|
+
*/
|
|
9
|
+
export interface IReconnectableNode {
|
|
10
|
+
/**
|
|
11
|
+
* The node's configuration
|
|
12
|
+
*/
|
|
13
|
+
config: oNodeConfig;
|
|
14
|
+
/**
|
|
15
|
+
* The node's current address
|
|
16
|
+
*/
|
|
17
|
+
address: oNodeAddress;
|
|
18
|
+
/**
|
|
19
|
+
* The node's current state
|
|
20
|
+
*/
|
|
21
|
+
state: NodeState;
|
|
22
|
+
/**
|
|
23
|
+
* The notification manager for subscribing to events
|
|
24
|
+
*/
|
|
25
|
+
notificationManager: oNotificationManager;
|
|
26
|
+
/**
|
|
27
|
+
* Register with the parent node
|
|
28
|
+
*/
|
|
29
|
+
registerParent(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Register with the leader's global registry
|
|
32
|
+
*/
|
|
33
|
+
register(): Promise<void>;
|
|
34
|
+
useSelf(request?: any): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* Execute a method on another node
|
|
37
|
+
*/
|
|
38
|
+
use(address: oAddress, data?: {
|
|
39
|
+
method?: string;
|
|
40
|
+
params?: {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
};
|
|
43
|
+
id?: string;
|
|
44
|
+
}): Promise<any>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=i-reconnectable-node.d.ts.map
|