@olane/o-node 0.7.12-alpha.23 → 0.7.12-alpha.25
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 +0 -14
- package/dist/o-core/src/connection/o-response.d.ts.map +1 -1
- package/dist/o-core/src/connection/o-response.js +0 -27
- package/dist/o-core/src/utils/streaming.utils.d.ts +0 -15
- package/dist/o-core/src/utils/streaming.utils.d.ts.map +1 -1
- package/dist/o-core/src/utils/streaming.utils.js +0 -26
- package/dist/o-node/src/connection/o-node-connection.d.ts +0 -7
- package/dist/o-node/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/o-node/src/connection/o-node-connection.js +15 -81
- package/dist/o-node/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/o-node/src/connection/o-node-connection.manager.js +1 -0
- package/dist/o-node/src/connection/o-stream.request.d.ts +11 -0
- package/dist/o-node/src/connection/o-stream.request.d.ts.map +1 -0
- package/dist/o-node/src/connection/o-stream.request.js +7 -0
- package/dist/o-node/src/index.d.ts +2 -1
- package/dist/o-node/src/index.d.ts.map +1 -1
- package/dist/o-node/src/index.js +2 -1
- package/dist/o-node/src/o-node.d.ts +2 -1
- package/dist/o-node/src/o-node.d.ts.map +1 -1
- package/dist/o-node/src/o-node.js +2 -8
- package/dist/o-node/src/o-node.tool.d.ts.map +1 -1
- package/dist/o-node/src/o-node.tool.js +9 -35
- package/dist/o-node/src/router/o-node.router.d.ts.map +1 -1
- package/dist/o-node/src/router/o-node.router.js +11 -1
- package/dist/o-node/src/utils/index.d.ts +5 -0
- package/dist/o-node/src/utils/index.d.ts.map +1 -0
- package/dist/o-node/src/utils/index.js +4 -0
- package/dist/o-node/src/utils/stream.utils.d.ts +6 -0
- package/dist/o-node/src/utils/stream.utils.d.ts.map +1 -0
- package/dist/o-node/src/utils/stream.utils.js +27 -0
- package/dist/o-node/test/circuit-breaker.test.d.ts.map +1 -0
- package/dist/o-node/{src/utils → test}/circuit-breaker.test.js +1 -1
- package/dist/o-node/test/leader-request-wrapper.test.d.ts.map +1 -0
- package/dist/src/connection/o-node-connection.d.ts +0 -7
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +22 -86
- package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.manager.js +1 -0
- package/dist/src/connection/o-stream.request.d.ts +11 -0
- package/dist/src/connection/o-stream.request.d.ts.map +1 -0
- package/dist/src/connection/o-stream.request.js +7 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/o-node.d.ts +4 -5
- package/dist/src/o-node.d.ts.map +1 -1
- package/dist/src/o-node.js +4 -10
- package/dist/src/o-node.tool.d.ts.map +1 -1
- package/dist/src/o-node.tool.js +12 -50
- package/dist/src/router/o-node.router.d.ts +1 -0
- package/dist/src/router/o-node.router.d.ts.map +1 -1
- package/dist/src/router/o-node.router.js +61 -5
- package/dist/src/streaming/index.d.ts +10 -0
- package/dist/src/streaming/index.d.ts.map +1 -0
- package/dist/src/streaming/index.js +12 -0
- package/dist/src/streaming/libp2p-stream-transport.d.ts +50 -0
- package/dist/src/streaming/libp2p-stream-transport.d.ts.map +1 -0
- package/dist/src/streaming/libp2p-stream-transport.js +137 -0
- package/dist/src/streaming/node-stream-handler.d.ts +65 -0
- package/dist/src/streaming/node-stream-handler.d.ts.map +1 -0
- package/dist/src/streaming/node-stream-handler.js +101 -0
- package/dist/src/streaming/o-node-streaming-client.d.ts +33 -0
- package/dist/src/streaming/o-node-streaming-client.d.ts.map +1 -0
- package/dist/src/streaming/o-node-streaming-client.js +130 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +4 -0
- package/dist/src/utils/stream.utils.d.ts +6 -0
- package/dist/src/utils/stream.utils.d.ts.map +1 -0
- package/dist/src/utils/stream.utils.js +30 -0
- package/dist/test/circuit-breaker.test.d.ts +2 -0
- package/dist/test/circuit-breaker.test.d.ts.map +1 -0
- package/dist/test/circuit-breaker.test.js +262 -0
- package/dist/test/leader-request-wrapper.test.d.ts +1 -0
- package/dist/test/leader-request-wrapper.test.d.ts.map +1 -0
- package/dist/test/leader-request-wrapper.test.js +246 -0
- package/package.json +6 -6
- package/dist/o-node/src/utils/circuit-breaker.test.d.ts.map +0 -1
- package/dist/o-node/src/utils/leader-request-wrapper.test.d.ts.map +0 -1
- package/dist/src/router/resolvers/o-node.child-resolver.d.ts +0 -11
- package/dist/src/router/resolvers/o-node.child-resolver.d.ts.map +0 -1
- package/dist/src/router/resolvers/o-node.child-resolver.js +0 -58
- /package/dist/o-node/{src/utils → test}/circuit-breaker.test.d.ts +0 -0
- /package/dist/o-node/{src/utils → test}/leader-request-wrapper.test.d.ts +0 -0
- /package/dist/o-node/{src/utils → test}/leader-request-wrapper.test.js +0 -0
|
@@ -3,23 +3,9 @@ export declare class oResponse implements Response {
|
|
|
3
3
|
jsonrpc: typeof JSONRPC_VERSION;
|
|
4
4
|
id: RequestId;
|
|
5
5
|
result: Result;
|
|
6
|
-
isStreaming?: boolean;
|
|
7
|
-
streamChunks?: unknown[];
|
|
8
6
|
constructor(config: Result & {
|
|
9
7
|
id: RequestId;
|
|
10
8
|
});
|
|
11
|
-
/**
|
|
12
|
-
* Check if a result is a streaming result
|
|
13
|
-
*/
|
|
14
|
-
private isStreamingResult;
|
|
15
|
-
/**
|
|
16
|
-
* Add a chunk to a streaming response
|
|
17
|
-
*/
|
|
18
|
-
addChunk(chunk: unknown): void;
|
|
19
|
-
/**
|
|
20
|
-
* Get all accumulated chunks for a streaming response
|
|
21
|
-
*/
|
|
22
|
-
getChunks(): unknown[];
|
|
23
9
|
toJSON(): any;
|
|
24
10
|
toString(): string;
|
|
25
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-response.d.ts","sourceRoot":"","sources":["../../../../../o-core/src/connection/o-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,IAAI,QAAQ,EACrB,MAAM,
|
|
1
|
+
{"version":3,"file":"o-response.d.ts","sourceRoot":"","sources":["../../../../../o-core/src/connection/o-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,IAAI,QAAQ,EACrB,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,SAAU,YAAW,QAAQ;IACxC,OAAO,EAAE,OAAO,eAAe,CAAC;IAChC,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE;IAM9C,MAAM,IAAI,GAAG;IAQb,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -4,33 +4,6 @@ export class oResponse {
|
|
|
4
4
|
this.jsonrpc = JSONRPC_VERSION;
|
|
5
5
|
this.id = config.id;
|
|
6
6
|
this.result = config;
|
|
7
|
-
// Check if this is a streaming result
|
|
8
|
-
if (this.isStreamingResult(config)) {
|
|
9
|
-
this.isStreaming = true;
|
|
10
|
-
this.streamChunks = [config._data];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Check if a result is a streaming result
|
|
15
|
-
*/
|
|
16
|
-
isStreamingResult(result) {
|
|
17
|
-
return '_streaming' in result && result._streaming === true;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Add a chunk to a streaming response
|
|
21
|
-
*/
|
|
22
|
-
addChunk(chunk) {
|
|
23
|
-
if (!this.isStreaming) {
|
|
24
|
-
this.isStreaming = true;
|
|
25
|
-
this.streamChunks = [];
|
|
26
|
-
}
|
|
27
|
-
this.streamChunks.push(chunk);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get all accumulated chunks for a streaming response
|
|
31
|
-
*/
|
|
32
|
-
getChunks() {
|
|
33
|
-
return this.streamChunks || [];
|
|
34
7
|
}
|
|
35
8
|
toJSON() {
|
|
36
9
|
return {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { oResponse } from '../connection/o-response.js';
|
|
2
1
|
/**
|
|
3
2
|
* Type guard to check if a value is an AsyncGenerator
|
|
4
3
|
* @param value - The value to check
|
|
@@ -13,14 +12,6 @@ export declare function isAsyncGenerator(value: any): value is AsyncGenerator;
|
|
|
13
12
|
* @returns Promise that resolves when iteration is complete
|
|
14
13
|
*/
|
|
15
14
|
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
15
|
/**
|
|
25
16
|
* Collect all chunks from an AsyncGenerator into an array
|
|
26
17
|
* Useful for testing or converting streaming responses to non-streaming
|
|
@@ -28,10 +19,4 @@ export declare function createStreamingResponse(connectionId: string, requestMet
|
|
|
28
19
|
* @returns Promise resolving to array of all chunks
|
|
29
20
|
*/
|
|
30
21
|
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
22
|
//# sourceMappingURL=streaming.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.utils.d.ts","sourceRoot":"","sources":["../../../../../o-core/src/utils/streaming.utils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"streaming.utils.d.ts","sourceRoot":"","sources":["../../../../../o-core/src/utils/streaming.utils.ts"],"names":[],"mappings":"AAAA;;;;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;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAMd"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { oResponse } from '../connection/o-response.js';
|
|
2
1
|
/**
|
|
3
2
|
* Type guard to check if a value is an AsyncGenerator
|
|
4
3
|
* @param value - The value to check
|
|
@@ -31,22 +30,6 @@ export async function iterateAsyncGenerator(generator, onChunk, onError) {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
}
|
|
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
33
|
/**
|
|
51
34
|
* Collect all chunks from an AsyncGenerator into an array
|
|
52
35
|
* Useful for testing or converting streaming responses to non-streaming
|
|
@@ -60,12 +43,3 @@ export async function collectStreamChunks(generator) {
|
|
|
60
43
|
}
|
|
61
44
|
return chunks;
|
|
62
45
|
}
|
|
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
|
-
}
|
|
@@ -8,13 +8,6 @@ export declare class oNodeConnection extends oConnection {
|
|
|
8
8
|
read(source: Stream): Promise<any>;
|
|
9
9
|
validate(): void;
|
|
10
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
11
|
close(): Promise<void>;
|
|
19
12
|
}
|
|
20
13
|
//# sourceMappingURL=o-node-connection.d.ts.map
|
|
@@ -1 +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,
|
|
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,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEjF,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;IA0E/C,KAAK;CAKZ"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
import { CoreUtils, oConnection, oError, oErrorCodes, oResponse, } from '@olane/o-core';
|
|
5
3
|
export class oNodeConnection extends oConnection {
|
|
6
4
|
constructor(config) {
|
|
7
5
|
super(config);
|
|
@@ -29,6 +27,7 @@ export class oNodeConnection extends oConnection {
|
|
|
29
27
|
maxOutboundStreams: Infinity,
|
|
30
28
|
runOnLimitedConnection: true, // TODO: should this be configurable?
|
|
31
29
|
});
|
|
30
|
+
const isStreamRequest = request.params._isStream;
|
|
32
31
|
if (!stream || (stream.status !== 'open' && stream.status !== 'reset')) {
|
|
33
32
|
throw new oError(oErrorCodes.FAILED_TO_DIAL_TARGET, 'Failed to dial target');
|
|
34
33
|
}
|
|
@@ -38,6 +37,16 @@ export class oNodeConnection extends oConnection {
|
|
|
38
37
|
// Send the data with backpressure handling (libp2p v3 best practice)
|
|
39
38
|
const data = new TextEncoder().encode(request.toString());
|
|
40
39
|
const sent = stream.send(data);
|
|
40
|
+
if (isStreamRequest) {
|
|
41
|
+
stream.addEventListener('message', async (event) => {
|
|
42
|
+
const response = await CoreUtils.processStreamResponse(event);
|
|
43
|
+
this.emitter.emit('chunk', response);
|
|
44
|
+
// marked as the last chunk let's close
|
|
45
|
+
if (response.result._last) {
|
|
46
|
+
await stream.close();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
41
50
|
// If send() returns false, wait for the stream to drain before continuing
|
|
42
51
|
if (!sent) {
|
|
43
52
|
this.logger.debug('Stream buffer full, waiting for drain...');
|
|
@@ -45,6 +54,9 @@ export class oNodeConnection extends oConnection {
|
|
|
45
54
|
signal: AbortSignal.timeout(this.config.drainTimeoutMs ?? 30000),
|
|
46
55
|
}); // Default: 30 second timeout
|
|
47
56
|
}
|
|
57
|
+
if (isStreamRequest) {
|
|
58
|
+
return Promise.resolve(CoreUtils.buildResponse(request, 'request is streaming, this response is not used', null));
|
|
59
|
+
}
|
|
48
60
|
const res = await this.read(stream);
|
|
49
61
|
await stream.close();
|
|
50
62
|
// process the response
|
|
@@ -60,84 +72,6 @@ export class oNodeConnection extends oConnection {
|
|
|
60
72
|
throw error;
|
|
61
73
|
}
|
|
62
74
|
}
|
|
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
75
|
async close() {
|
|
142
76
|
this.logger.debug('Closing connection');
|
|
143
77
|
await this.p2pConnection.close();
|
|
@@ -1 +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;
|
|
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;IA8FlE,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAe3D"}
|
|
@@ -50,6 +50,7 @@ export class oNodeConnectionManager extends oConnectionManager {
|
|
|
50
50
|
callerAddress: callerAddress,
|
|
51
51
|
readTimeoutMs: readTimeoutMs ?? this.defaultReadTimeoutMs,
|
|
52
52
|
drainTimeoutMs: drainTimeoutMs ?? this.defaultDrainTimeoutMs,
|
|
53
|
+
isStream: config.isStream || false,
|
|
53
54
|
});
|
|
54
55
|
if (attempt > 0) {
|
|
55
56
|
this.logger.info(`Successfully connected to ${nextHopAddress.toString()} on retry attempt ${attempt}`);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Request, RequestId } from '@olane/o-protocol';
|
|
2
|
+
import { oRequest } from '@olane/o-core';
|
|
3
|
+
import { Stream } from '@olane/o-config';
|
|
4
|
+
export declare class oStreamRequest extends oRequest {
|
|
5
|
+
stream: Stream;
|
|
6
|
+
constructor(config: Request & {
|
|
7
|
+
id: RequestId;
|
|
8
|
+
stream: Stream;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=o-stream.request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-stream.request.d.ts","sourceRoot":"","sources":["../../../../src/connection/o-stream.request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,MAAM,EAAE,MAAM,CAAC;gBACH,MAAM,EAAE,OAAO,GAAG;QAAE,EAAE,EAAE,SAAS,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAIhE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './o-node.js';
|
|
2
|
-
export * from './utils/
|
|
2
|
+
export * from './utils/index.js';
|
|
3
3
|
export * from './o-node.hierarchy-manager.js';
|
|
4
4
|
export * from './interfaces/o-node.config.js';
|
|
5
5
|
export * from './connection/index.js';
|
|
@@ -7,4 +7,5 @@ export * from './o-node.tool.js';
|
|
|
7
7
|
export * from './nodes/index.js';
|
|
8
8
|
export * from './interfaces/o-node.tool-config.js';
|
|
9
9
|
export * from './router/index.js';
|
|
10
|
+
export * from './connection/o-stream.request.js';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,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;AAClC,cAAc,kCAAkC,CAAC"}
|
package/dist/o-node/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './o-node.js';
|
|
2
|
-
export * from './utils/
|
|
2
|
+
export * from './utils/index.js';
|
|
3
3
|
export * from './o-node.hierarchy-manager.js';
|
|
4
4
|
export * from './interfaces/o-node.config.js';
|
|
5
5
|
export * from './connection/index.js';
|
|
@@ -7,3 +7,4 @@ export * from './o-node.tool.js';
|
|
|
7
7
|
export * from './nodes/index.js';
|
|
8
8
|
export * from './interfaces/o-node.tool-config.js';
|
|
9
9
|
export * from './router/index.js';
|
|
10
|
+
export * from './connection/o-stream.request.js';
|
|
@@ -11,6 +11,7 @@ import { oToolBase } from '@olane/o-tool';
|
|
|
11
11
|
import { oConnectionHeartbeatManager } from './managers/o-connection-heartbeat.manager.js';
|
|
12
12
|
import { oReconnectionManager } from './managers/o-reconnection.manager.js';
|
|
13
13
|
import { LeaderRequestWrapper } from './utils/leader-request-wrapper.js';
|
|
14
|
+
import { oNodeConnectionConfig } from './connection/index.js';
|
|
14
15
|
export declare class oNode extends oToolBase {
|
|
15
16
|
peerId: PeerId;
|
|
16
17
|
p2pNode: Libp2p;
|
|
@@ -45,7 +46,7 @@ export declare class oNode extends oToolBase {
|
|
|
45
46
|
*/
|
|
46
47
|
configure(): Promise<Libp2pConfig>;
|
|
47
48
|
protected createNode(): Promise<Libp2p>;
|
|
48
|
-
connect(
|
|
49
|
+
connect(config: oNodeConnectionConfig): Promise<oNodeConnection>;
|
|
49
50
|
initConnectionManager(): Promise<void>;
|
|
50
51
|
initReconnectionManager(): Promise<void>;
|
|
51
52
|
hookInitializeFinished(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EACN,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAIL,QAAQ,EACR,QAAQ,EAER,oBAAoB,
|
|
1
|
+
{"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../../src/o-node.ts"],"names":[],"mappings":"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"}
|
|
@@ -279,19 +279,13 @@ export class oNode extends oToolBase {
|
|
|
279
279
|
this.p2pNode = await createNode(params);
|
|
280
280
|
return this.p2pNode;
|
|
281
281
|
}
|
|
282
|
-
async connect(
|
|
282
|
+
async connect(config) {
|
|
283
283
|
if (!this.connectionManager) {
|
|
284
284
|
this.logger.error('Connection manager not initialized');
|
|
285
285
|
throw new Error('Node is not ready to connect to other nodes');
|
|
286
286
|
}
|
|
287
287
|
const connection = await this.connectionManager
|
|
288
|
-
.connect(
|
|
289
|
-
address: targetAddress,
|
|
290
|
-
nextHopAddress,
|
|
291
|
-
callerAddress: this.address,
|
|
292
|
-
readTimeoutMs,
|
|
293
|
-
drainTimeoutMs,
|
|
294
|
-
})
|
|
288
|
+
.connect(config)
|
|
295
289
|
.catch((error) => {
|
|
296
290
|
// TODO: we need to handle this better and document
|
|
297
291
|
if (error.message === 'Can not dial self') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,QAAQ,EAGT,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,QAAQ,EAGT,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;;AAIrD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IACzC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAQhC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAoDnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CA2B5D"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { CoreUtils, oError, oErrorCodes, oRequest, ChildJoinedEvent, } from '@olane/o-core';
|
|
2
|
-
import { isAsyncGenerator, processStream } from '../../o-core/src/utils/streaming.utils.js';
|
|
3
2
|
import { oTool } from '@olane/o-tool';
|
|
4
3
|
import { oServerNode } from './nodes/server.node.js';
|
|
5
4
|
import { oNodeTransport } from './router/o-node.transport.js';
|
|
6
5
|
import { oNodeAddress } from './router/o-node.address.js';
|
|
7
|
-
import { Libp2pStreamTransport } from './streaming/libp2p-stream-transport.js';
|
|
8
|
-
import { NodeStreamHandler } from './streaming/node-stream-handler.js';
|
|
9
6
|
/**
|
|
10
7
|
* oTool is a mixin that extends the base class and implements the oTool interface
|
|
11
8
|
* @param Base - The base class to extend
|
|
@@ -36,7 +33,7 @@ export class oNodeTool extends oTool(oServerNode) {
|
|
|
36
33
|
this.logger.warn('Malformed event data');
|
|
37
34
|
return;
|
|
38
35
|
}
|
|
39
|
-
const requestConfig = await
|
|
36
|
+
const requestConfig = await CoreUtils.processStreamRequest(event);
|
|
40
37
|
const request = new oRequest(requestConfig);
|
|
41
38
|
let success = true;
|
|
42
39
|
const result = await this.execute(request, stream).catch((error) => {
|
|
@@ -49,40 +46,17 @@ export class oNodeTool extends oTool(oServerNode) {
|
|
|
49
46
|
error: responseError.toJSON(),
|
|
50
47
|
};
|
|
51
48
|
});
|
|
52
|
-
//
|
|
53
|
-
if (
|
|
54
|
-
this.
|
|
55
|
-
// Create stream transport and handler
|
|
56
|
-
const transport = new Libp2pStreamTransport(stream);
|
|
57
|
-
const streamHandler = new NodeStreamHandler(transport, {
|
|
58
|
-
enableMetrics: true,
|
|
59
|
-
trackSuccessCount: true,
|
|
60
|
-
trackErrorCount: true,
|
|
61
|
-
});
|
|
62
|
-
try {
|
|
63
|
-
// Handle the streaming using the new abstraction
|
|
64
|
-
await streamHandler.handleStream(result, request);
|
|
65
|
-
// Update metrics from the stream handler
|
|
66
|
-
this.metrics.successCount += streamHandler.getSuccessCount();
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
this.logger.error('Error in streaming response: ', error);
|
|
70
|
-
this.metrics.errorCount++;
|
|
71
|
-
}
|
|
49
|
+
// Non-streaming response - original behavior
|
|
50
|
+
if (success) {
|
|
51
|
+
this.metrics.successCount++;
|
|
72
52
|
}
|
|
73
53
|
else {
|
|
74
|
-
|
|
75
|
-
if (success) {
|
|
76
|
-
this.metrics.successCount++;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this.metrics.errorCount++;
|
|
80
|
-
}
|
|
81
|
-
// compose the response & add the expected connection + request fields
|
|
82
|
-
const response = CoreUtils.buildResponse(request, result, result?.error);
|
|
83
|
-
// add the request method to the response
|
|
84
|
-
await CoreUtils.sendResponse(response, stream);
|
|
54
|
+
this.metrics.errorCount++;
|
|
85
55
|
}
|
|
56
|
+
// compose the response & add the expected connection + request fields
|
|
57
|
+
const response = CoreUtils.buildResponse(request, result, result?.error);
|
|
58
|
+
// add the request method to the response
|
|
59
|
+
await CoreUtils.sendResponse(response, stream);
|
|
86
60
|
};
|
|
87
61
|
// Attach listener synchronously before any async operations
|
|
88
62
|
stream.addEventListener('message', messageHandler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.router.d.ts","sourceRoot":"","sources":["../../../../src/router/o-node.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAML,cAAc,EACd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node.router.d.ts","sourceRoot":"","sources":["../../../../src/router/o-node.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAML,cAAc,EACd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,aAAa,CAAqB;;IAO1C;;;;;;;;OAQG;cACa,OAAO,CACrB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,GAAG,CAAC;IA0Bf;;OAEG;YACW,kBAAkB;IAgBhC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAUhC;;OAEG;YACW,eAAe;IAsC7B;;;OAGG;IACG,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC;IAyB3E;;;OAGG;IACH,UAAU,CAAC,qBAAqB,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO;CAGtE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { oAddress, oError, oErrorCodes, oRequest, } from '@olane/o-core';
|
|
1
|
+
import { CoreUtils, oAddress, oError, oErrorCodes, oRequest, } from '@olane/o-core';
|
|
2
2
|
import { oToolRouter } from '@olane/o-tool';
|
|
3
3
|
import { oNodeConnection } from '../connection/o-node-connection.js';
|
|
4
4
|
import { oNodeRoutingPolicy } from './o-node.routing-policy.js';
|
|
@@ -83,6 +83,16 @@ export class oNodeRouter extends oToolRouter {
|
|
|
83
83
|
address: node.address,
|
|
84
84
|
callerAddress: node.address,
|
|
85
85
|
});
|
|
86
|
+
if (request.params._isStream) {
|
|
87
|
+
const routeRequest = request;
|
|
88
|
+
if (!routeRequest.stream) {
|
|
89
|
+
throw new oError(oErrorCodes.INVALID_REQUEST, 'Stream is required');
|
|
90
|
+
}
|
|
91
|
+
nodeConnection.onChunk((response) => {
|
|
92
|
+
CoreUtils.sendStreamResponse(response, routeRequest.stream);
|
|
93
|
+
});
|
|
94
|
+
// allow this to continue as we will tell the transmitter to stream the response and we will intercept via the above listener
|
|
95
|
+
}
|
|
86
96
|
const response = await nodeConnection.transmit(request);
|
|
87
97
|
return response.result.data;
|
|
88
98
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Stream } from '@olane/o-config';
|
|
2
|
+
import { oObject, oRequest } from '@olane/o-core';
|
|
3
|
+
export declare class StreamUtils extends oObject {
|
|
4
|
+
static processGenerator(request: oRequest, generator: AsyncGenerator<any>, stream: Stream): Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=stream.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.utils.d.ts","sourceRoot":"","sources":["../../../../src/utils/stream.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAa,OAAO,EAAE,QAAQ,EAAa,MAAM,eAAe,CAAC;AAExE,qBAAa,WAAY,SAAQ,OAAO;WAClB,gBAAgB,CAClC,OAAO,EAAE,QAAQ,EACjB,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,EAC9B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,GAAG,CAAC;CA8BhB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CoreUtils, oObject, oResponse } from '@olane/o-core';
|
|
2
|
+
export class StreamUtils extends oObject {
|
|
3
|
+
static async processGenerator(request, generator, stream) {
|
|
4
|
+
const utils = new StreamUtils();
|
|
5
|
+
for await (const result of generator) {
|
|
6
|
+
utils.logger.debug('Sending stream response: ', result);
|
|
7
|
+
await CoreUtils.sendStreamResponse(new oResponse({
|
|
8
|
+
id: request.id,
|
|
9
|
+
data: result,
|
|
10
|
+
_last: false,
|
|
11
|
+
_requestMethod: request.method,
|
|
12
|
+
_connectionId: request.params?._connectionId,
|
|
13
|
+
}), stream);
|
|
14
|
+
}
|
|
15
|
+
await CoreUtils.sendStreamResponse(new oResponse({
|
|
16
|
+
id: request.id,
|
|
17
|
+
data: 'Stream completed',
|
|
18
|
+
_last: true,
|
|
19
|
+
_requestMethod: request.method,
|
|
20
|
+
_connectionId: request.params?._connectionId,
|
|
21
|
+
}), stream);
|
|
22
|
+
return Promise.resolve({
|
|
23
|
+
success: true,
|
|
24
|
+
response: 'Stream started',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.test.d.ts","sourceRoot":"","sources":["../../../test/circuit-breaker.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leader-request-wrapper.test.d.ts","sourceRoot":"","sources":["../../../test/leader-request-wrapper.test.ts"],"names":[],"mappings":""}
|
|
@@ -8,13 +8,6 @@ export declare class oNodeConnection extends oConnection {
|
|
|
8
8
|
read(source: Stream): Promise<any>;
|
|
9
9
|
validate(): void;
|
|
10
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
11
|
close(): Promise<void>;
|
|
19
12
|
}
|
|
20
13
|
//# sourceMappingURL=o-node-connection.d.ts.map
|
|
@@ -1 +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,
|
|
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,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,EAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEjF,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;IA6E/C,KAAK;CAKZ"}
|