@olane/o-node 0.7.12-alpha.24 → 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/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +17 -10
- package/dist/src/o-node.d.ts +2 -4
- package/dist/src/o-node.d.ts.map +1 -1
- package/dist/src/o-node.js +2 -2
- package/dist/src/o-node.tool.d.ts.map +1 -1
- package/dist/src/o-node.tool.js +12 -21
- 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 +52 -6
- package/dist/src/utils/stream.utils.d.ts.map +1 -1
- package/dist/src/utils/stream.utils.js +24 -21
- package/package.json +6 -6
|
@@ -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,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,
|
|
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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Uint8ArrayList, byteStream, } from '@olane/o-config';
|
|
2
|
-
import { CoreUtils, oConnection, oError, oErrorCodes, oResponse, } from '@olane/o-core';
|
|
2
|
+
import { CoreUtils, oConnection, oError, oErrorCodes, oResponse, ResponseBuilder, } from '@olane/o-core';
|
|
3
3
|
export class oNodeConnection extends oConnection {
|
|
4
4
|
constructor(config) {
|
|
5
5
|
super(config);
|
|
@@ -27,7 +27,7 @@ export class oNodeConnection extends oConnection {
|
|
|
27
27
|
maxOutboundStreams: Infinity,
|
|
28
28
|
runOnLimitedConnection: true, // TODO: should this be configurable?
|
|
29
29
|
});
|
|
30
|
-
const isStreamRequest =
|
|
30
|
+
const isStreamRequest = this.config.isStream;
|
|
31
31
|
if (!stream || (stream.status !== 'open' && stream.status !== 'reset')) {
|
|
32
32
|
throw new oError(oErrorCodes.FAILED_TO_DIAL_TARGET, 'Failed to dial target');
|
|
33
33
|
}
|
|
@@ -38,13 +38,19 @@ export class oNodeConnection extends oConnection {
|
|
|
38
38
|
const data = new TextEncoder().encode(request.toString());
|
|
39
39
|
const sent = stream.send(data);
|
|
40
40
|
if (isStreamRequest) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
this.logger.debug('Detected stream request, attaching message listener');
|
|
42
|
+
await new Promise((resolve, reject) => {
|
|
43
|
+
// TODO: add timeout
|
|
44
|
+
stream.addEventListener('message', async (event) => {
|
|
45
|
+
const response = await CoreUtils.processStreamResponse(event);
|
|
46
|
+
this.emitter.emit('chunk', response);
|
|
47
|
+
// marked as the last chunk let's close
|
|
48
|
+
if (response.result._last) {
|
|
49
|
+
this.logger.debug('Last chunk received, closing stream');
|
|
50
|
+
await stream.close();
|
|
51
|
+
resolve(true);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
48
54
|
});
|
|
49
55
|
}
|
|
50
56
|
// If send() returns false, wait for the stream to drain before continuing
|
|
@@ -55,7 +61,8 @@ export class oNodeConnection extends oConnection {
|
|
|
55
61
|
}); // Default: 30 second timeout
|
|
56
62
|
}
|
|
57
63
|
if (isStreamRequest) {
|
|
58
|
-
|
|
64
|
+
const responseBuilder = ResponseBuilder.create();
|
|
65
|
+
return Promise.resolve(await responseBuilder.buildFinalChunk(request));
|
|
59
66
|
}
|
|
60
67
|
const res = await this.read(stream);
|
|
61
68
|
await stream.close();
|
package/dist/src/o-node.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { PeerId } from '@olane/o-config';
|
|
|
3
3
|
import { oNodeHierarchyManager } from './o-node.hierarchy-manager.js';
|
|
4
4
|
import { oNodeConfig } from './interfaces/o-node.config.js';
|
|
5
5
|
import { oNodeTransport } from './router/o-node.transport.js';
|
|
6
|
-
import { oAddress, oRequest, oNotificationManager } from '@olane/o-core';
|
|
6
|
+
import { oAddress, oRequest, oNotificationManager, UseOptions } from '@olane/o-core';
|
|
7
7
|
import { oNodeAddress } from './router/o-node.address.js';
|
|
8
8
|
import { oNodeConnection } from './connection/o-node-connection.js';
|
|
9
9
|
import { oNodeConnectionManager } from './connection/o-node-connection.manager.js';
|
|
@@ -61,9 +61,7 @@ export declare class oNode extends oToolBase {
|
|
|
61
61
|
[key: string]: any;
|
|
62
62
|
};
|
|
63
63
|
id?: string;
|
|
64
|
-
}, options?:
|
|
65
|
-
noRouting?: boolean;
|
|
66
|
-
}): Promise<any>;
|
|
64
|
+
}, options?: UseOptions): Promise<any>;
|
|
67
65
|
teardown(): Promise<void>;
|
|
68
66
|
getLeaders(): oNodeAddress[];
|
|
69
67
|
getParents(): oNodeAddress[];
|
package/dist/src/o-node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL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BhE,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtC,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxC,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAEvC,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBlC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgEjC;;OAEG;IACG,GAAG,CACP,OAAO,EAAE,QAAQ,EACjB,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QAChC,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,EACD,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,GAAG,CAAC;IAST,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B,UAAU,IAAI,YAAY,EAAE;IAI5B,UAAU,IAAI,YAAY,EAAE;IAI5B,WAAW,IAAI,YAAY,EAAE;IAI7B,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;CAG9C"}
|
package/dist/src/o-node.js
CHANGED
|
@@ -123,7 +123,7 @@ export class oNode extends oToolBase {
|
|
|
123
123
|
// if no parent transports, register with the parent to get them
|
|
124
124
|
// TODO: should we remove the transports check to make this more consistent?
|
|
125
125
|
if (this.config.parent) {
|
|
126
|
-
this.logger.debug('Registering node with parent...', this.config.parent);
|
|
126
|
+
this.logger.debug('Registering node with parent...', this.config.parent?.toString);
|
|
127
127
|
await this.use(this.config.parent, {
|
|
128
128
|
method: 'child_register',
|
|
129
129
|
params: {
|
|
@@ -385,7 +385,7 @@ export class oNode extends oToolBase {
|
|
|
385
385
|
*/
|
|
386
386
|
async use(address, data, options) {
|
|
387
387
|
// Wrap leader/registry requests with retry logic
|
|
388
|
-
return this.leaderRequestWrapper.execute(() => super.use(address, data,
|
|
388
|
+
return this.leaderRequestWrapper.execute(() => super.use(address, data, options), address, data?.method);
|
|
389
389
|
}
|
|
390
390
|
async teardown() {
|
|
391
391
|
// Stop heartbeat before parent teardown
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,QAAQ,EAIT,MAAM,eAAe,CAAC;AAEvB,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;IAuCnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CA2B5D"}
|
package/dist/src/o-node.tool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreUtils,
|
|
1
|
+
import { CoreUtils, oRequest, ResponseBuilder, ChildJoinedEvent, } from '@olane/o-core';
|
|
2
2
|
import { oTool } from '@olane/o-tool';
|
|
3
3
|
import { oServerNode } from './nodes/server.node.js';
|
|
4
4
|
import { oNodeTransport } from './router/o-node.transport.js';
|
|
@@ -33,29 +33,20 @@ export class oNodeTool extends oTool(oServerNode) {
|
|
|
33
33
|
this.logger.warn('Malformed event data');
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
const requestConfig = await CoreUtils.
|
|
36
|
+
const requestConfig = await CoreUtils.processStream(event);
|
|
37
37
|
const request = new oRequest(requestConfig);
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
: new oError(oErrorCodes.UNKNOWN, error.message);
|
|
45
|
-
return {
|
|
46
|
-
error: responseError.toJSON(),
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
// Non-streaming response - original behavior
|
|
50
|
-
if (success) {
|
|
51
|
-
this.metrics.successCount++;
|
|
38
|
+
// Use ResponseBuilder with automatic error handling and metrics tracking
|
|
39
|
+
const responseBuilder = ResponseBuilder.create().withMetrics(this.metrics);
|
|
40
|
+
let response;
|
|
41
|
+
try {
|
|
42
|
+
const result = await this.execute(request, stream);
|
|
43
|
+
response = await responseBuilder.build(request, result, null);
|
|
52
44
|
}
|
|
53
|
-
|
|
54
|
-
this.
|
|
45
|
+
catch (error) {
|
|
46
|
+
this.logger.error('Error executing tool: ', request.toString(), error, typeof error);
|
|
47
|
+
response = await responseBuilder.buildError(request, error);
|
|
55
48
|
}
|
|
56
|
-
//
|
|
57
|
-
const response = CoreUtils.buildResponse(request, result, result?.error);
|
|
58
|
-
// add the request method to the response
|
|
49
|
+
// Send the response
|
|
59
50
|
await CoreUtils.sendResponse(response, stream);
|
|
60
51
|
};
|
|
61
52
|
// Attach listener synchronously before any async operations
|
|
@@ -17,6 +17,7 @@ export declare class oNodeRouter extends oToolRouter {
|
|
|
17
17
|
protected forward(address: oNodeAddress, request: oRouterRequest, node: oNode): Promise<any>;
|
|
18
18
|
/**
|
|
19
19
|
* Executes a request locally when routing to self.
|
|
20
|
+
* Now uses ResponseBuilder for consistency with useSelf() behavior.
|
|
20
21
|
*/
|
|
21
22
|
private executeSelfRouting;
|
|
22
23
|
/**
|
|
@@ -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,
|
|
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,EAGd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,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;IA6Bf;;;OAGG;YACW,kBAAkB;IA8DhC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;OAEG;YACW,eAAe;IA0C7B;;;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,7 +1,8 @@
|
|
|
1
|
-
import { CoreUtils, oAddress, oError, oErrorCodes, oRequest, } from '@olane/o-core';
|
|
1
|
+
import { CoreUtils, oAddress, oError, oErrorCodes, oRequest, ResponseBuilder, } 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';
|
|
5
|
+
import { oStreamRequest } from '../connection/o-stream.request.js';
|
|
5
6
|
export class oNodeRouter extends oToolRouter {
|
|
6
7
|
constructor() {
|
|
7
8
|
super();
|
|
@@ -25,6 +26,9 @@ export class oNodeRouter extends oToolRouter {
|
|
|
25
26
|
params: request.params,
|
|
26
27
|
id: request.id,
|
|
27
28
|
});
|
|
29
|
+
if (request.stream) {
|
|
30
|
+
nextHopRequest.stream = request.stream;
|
|
31
|
+
}
|
|
28
32
|
// Handle self-routing: execute locally instead of dialing
|
|
29
33
|
if (this.routingPolicy.isSelfAddress(address, node)) {
|
|
30
34
|
return this.executeSelfRouting(request, node);
|
|
@@ -39,17 +43,55 @@ export class oNodeRouter extends oToolRouter {
|
|
|
39
43
|
}
|
|
40
44
|
/**
|
|
41
45
|
* Executes a request locally when routing to self.
|
|
46
|
+
* Now uses ResponseBuilder for consistency with useSelf() behavior.
|
|
42
47
|
*/
|
|
43
48
|
async executeSelfRouting(request, node) {
|
|
44
49
|
const { payload } = request.params;
|
|
45
50
|
const params = payload.params;
|
|
46
51
|
const localRequest = new oRequest({
|
|
47
52
|
method: payload.method,
|
|
48
|
-
params: {
|
|
53
|
+
params: {
|
|
54
|
+
...params,
|
|
55
|
+
_connectionId: request.params._connectionId,
|
|
56
|
+
_requestMethod: payload.method,
|
|
57
|
+
},
|
|
49
58
|
id: request.id,
|
|
50
59
|
});
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
// Create ResponseBuilder with metrics tracking
|
|
61
|
+
const responseBuilder = ResponseBuilder.create().withMetrics(node.metrics);
|
|
62
|
+
// Handle streaming requests
|
|
63
|
+
const isStream = request.params._isStream;
|
|
64
|
+
if (isStream && request.stream) {
|
|
65
|
+
// For streaming, we need to handle the stream chunks
|
|
66
|
+
try {
|
|
67
|
+
const result = await node.execute(localRequest, request.stream);
|
|
68
|
+
const response = await responseBuilder.build(localRequest, result, null, {
|
|
69
|
+
isStream: true,
|
|
70
|
+
});
|
|
71
|
+
// Return unwrapped data for consistency with dialAndTransmit
|
|
72
|
+
return response.result.data;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
const errorResponse = await responseBuilder.buildError(localRequest, error, {
|
|
76
|
+
isStream: true,
|
|
77
|
+
});
|
|
78
|
+
// For errors, throw to match remote behavior
|
|
79
|
+
throw responseBuilder.normalizeError(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Handle non-streaming requests with error handling
|
|
83
|
+
try {
|
|
84
|
+
const result = await node.execute(localRequest);
|
|
85
|
+
const response = await responseBuilder.build(localRequest, result, null);
|
|
86
|
+
// Return unwrapped data to match dialAndTransmit behavior
|
|
87
|
+
return response.result.data;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// Build error response for metrics tracking
|
|
91
|
+
await responseBuilder.buildError(localRequest, error);
|
|
92
|
+
// Then throw the normalized error
|
|
93
|
+
throw responseBuilder.normalizeError(error);
|
|
94
|
+
}
|
|
53
95
|
}
|
|
54
96
|
/**
|
|
55
97
|
* Checks if the next hop is the final destination address.
|
|
@@ -65,10 +107,11 @@ export class oNodeRouter extends oToolRouter {
|
|
|
65
107
|
unwrapDestinationRequest(request) {
|
|
66
108
|
const { payload } = request.params;
|
|
67
109
|
const params = payload.params;
|
|
68
|
-
return new
|
|
110
|
+
return new oStreamRequest({
|
|
69
111
|
method: payload.method,
|
|
70
112
|
params: { ...params },
|
|
71
113
|
id: request.id,
|
|
114
|
+
stream: request.stream,
|
|
72
115
|
});
|
|
73
116
|
}
|
|
74
117
|
/**
|
|
@@ -76,14 +119,17 @@ export class oNodeRouter extends oToolRouter {
|
|
|
76
119
|
*/
|
|
77
120
|
async dialAndTransmit(address, request, node) {
|
|
78
121
|
try {
|
|
122
|
+
const isStream = request.params._isStream ||
|
|
123
|
+
request.params.payload?.params?._isStream;
|
|
79
124
|
const connection = await node.p2pNode.dial(address.libp2pTransports.map((t) => t.toMultiaddr()));
|
|
80
125
|
const nodeConnection = new oNodeConnection({
|
|
81
126
|
p2pConnection: connection,
|
|
82
127
|
nextHopAddress: address,
|
|
83
128
|
address: node.address,
|
|
84
129
|
callerAddress: node.address,
|
|
130
|
+
isStream: isStream,
|
|
85
131
|
});
|
|
86
|
-
if (
|
|
132
|
+
if (isStream) {
|
|
87
133
|
const routeRequest = request;
|
|
88
134
|
if (!routeRequest.stream) {
|
|
89
135
|
throw new oError(oErrorCodes.INVALID_REQUEST, 'Stream is required');
|
|
@@ -1 +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,
|
|
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,EAEL,OAAO,EACP,QAAQ,EAGT,MAAM,eAAe,CAAC;AAEvB,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;CA6BhB"}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import { CoreUtils, oObject,
|
|
1
|
+
import { CoreUtils, oObject, ResponseBuilder, } from '@olane/o-core';
|
|
2
2
|
export class StreamUtils extends oObject {
|
|
3
3
|
static async processGenerator(request, generator, stream) {
|
|
4
4
|
const utils = new StreamUtils();
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const responseBuilder = ResponseBuilder.create();
|
|
6
|
+
try {
|
|
7
|
+
// Send each chunk from the generator
|
|
8
|
+
for await (const result of generator) {
|
|
9
|
+
const chunkResponse = await responseBuilder.buildChunk(request, result);
|
|
10
|
+
await CoreUtils.sendStreamResponse(chunkResponse, stream);
|
|
11
|
+
}
|
|
12
|
+
// Send final chunk
|
|
13
|
+
const finalResponse = await responseBuilder.buildFinalChunk(request);
|
|
14
|
+
await CoreUtils.sendStreamResponse(finalResponse, stream);
|
|
15
|
+
return Promise.resolve({
|
|
16
|
+
success: true,
|
|
17
|
+
response: 'Stream completed',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
// If error occurs during streaming, send error response
|
|
22
|
+
const errorResponse = await responseBuilder.buildError(request, error, {
|
|
23
|
+
isStream: true,
|
|
24
|
+
isLast: true,
|
|
25
|
+
});
|
|
26
|
+
await CoreUtils.sendStreamResponse(errorResponse, stream);
|
|
27
|
+
throw error;
|
|
14
28
|
}
|
|
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
29
|
}
|
|
27
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-node",
|
|
3
|
-
"version": "0.7.12-alpha.
|
|
3
|
+
"version": "0.7.12-alpha.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"typescript": "5.4.5"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@olane/o-config": "0.7.12-alpha.
|
|
58
|
-
"@olane/o-core": "0.7.12-alpha.
|
|
59
|
-
"@olane/o-protocol": "0.7.12-alpha.
|
|
60
|
-
"@olane/o-tool": "0.7.12-alpha.
|
|
57
|
+
"@olane/o-config": "0.7.12-alpha.25",
|
|
58
|
+
"@olane/o-core": "0.7.12-alpha.25",
|
|
59
|
+
"@olane/o-protocol": "0.7.12-alpha.25",
|
|
60
|
+
"@olane/o-tool": "0.7.12-alpha.25",
|
|
61
61
|
"debug": "^4.4.1",
|
|
62
62
|
"dotenv": "^16.5.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "4d9d078b894c03839e77313a6653840b7c7acc6f"
|
|
65
65
|
}
|