@olane/o-node 0.7.51 → 0.7.53

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.
Files changed (48) hide show
  1. package/dist/src/connection/index.d.ts +6 -5
  2. package/dist/src/connection/index.d.ts.map +1 -1
  3. package/dist/src/connection/index.js +6 -5
  4. package/dist/src/connection/interfaces/{o-node-connection-stream.config.d.ts → o-node-stream.config.d.ts} +2 -2
  5. package/dist/src/connection/interfaces/o-node-stream.config.d.ts.map +1 -0
  6. package/dist/src/connection/interfaces/stream-init-message.d.ts +29 -0
  7. package/dist/src/connection/interfaces/stream-init-message.d.ts.map +1 -0
  8. package/dist/src/connection/interfaces/stream-init-message.js +8 -0
  9. package/dist/src/connection/interfaces/stream-manager.config.d.ts +8 -0
  10. package/dist/src/connection/interfaces/stream-manager.config.d.ts.map +1 -0
  11. package/dist/src/connection/o-node-connection.d.ts +5 -7
  12. package/dist/src/connection/o-node-connection.d.ts.map +1 -1
  13. package/dist/src/connection/o-node-connection.js +26 -56
  14. package/dist/src/connection/o-node-connection.manager.d.ts +7 -0
  15. package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
  16. package/dist/src/connection/o-node-connection.manager.js +23 -5
  17. package/dist/src/connection/{o-node-connection-stream.d.ts → o-node-stream.d.ts} +6 -6
  18. package/dist/src/connection/o-node-stream.d.ts.map +1 -0
  19. package/dist/src/connection/{o-node-connection-stream.js → o-node-stream.js} +2 -2
  20. package/dist/src/connection/o-node-stream.manager.d.ts +181 -0
  21. package/dist/src/connection/o-node-stream.manager.d.ts.map +1 -0
  22. package/dist/src/connection/o-node-stream.manager.js +526 -0
  23. package/dist/src/connection/stream-manager.events.d.ts +83 -0
  24. package/dist/src/connection/stream-manager.events.d.ts.map +1 -0
  25. package/dist/src/connection/stream-manager.events.js +18 -0
  26. package/dist/src/o-node.tool.d.ts +0 -1
  27. package/dist/src/o-node.tool.d.ts.map +1 -1
  28. package/dist/src/o-node.tool.js +30 -20
  29. package/dist/test/helpers/stream-pool-test-helpers.d.ts +0 -75
  30. package/dist/test/helpers/stream-pool-test-helpers.d.ts.map +1 -1
  31. package/dist/test/helpers/stream-pool-test-helpers.js +262 -229
  32. package/dist/test/parent-child-registration.spec.js +2 -1
  33. package/package.json +7 -7
  34. package/dist/src/connection/interfaces/o-node-connection-stream.config.d.ts.map +0 -1
  35. package/dist/src/connection/interfaces/stream-pool-manager.config.d.ts +0 -41
  36. package/dist/src/connection/interfaces/stream-pool-manager.config.d.ts.map +0 -1
  37. package/dist/src/connection/o-node-connection-stream.d.ts.map +0 -1
  38. package/dist/src/connection/stream-handler.d.ts +0 -102
  39. package/dist/src/connection/stream-handler.d.ts.map +0 -1
  40. package/dist/src/connection/stream-handler.js +0 -357
  41. package/dist/src/connection/stream-pool-manager.d.ts +0 -86
  42. package/dist/src/connection/stream-pool-manager.d.ts.map +0 -1
  43. package/dist/src/connection/stream-pool-manager.events.d.ts +0 -57
  44. package/dist/src/connection/stream-pool-manager.events.d.ts.map +0 -1
  45. package/dist/src/connection/stream-pool-manager.events.js +0 -14
  46. package/dist/src/connection/stream-pool-manager.js +0 -356
  47. /package/dist/src/connection/interfaces/{o-node-connection-stream.config.js → o-node-stream.config.js} +0 -0
  48. /package/dist/src/connection/interfaces/{stream-pool-manager.config.js → stream-manager.config.js} +0 -0
@@ -3,8 +3,8 @@ 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';
5
5
  import { oNodeAddress } from './router/o-node.address.js';
6
- import { StreamHandler } from './connection/stream-handler.js';
7
6
  import { ConnectionUtils } from './utils/connection.utils.js';
7
+ import { StreamManagerEvent } from './connection/stream-manager.events.js';
8
8
  /**
9
9
  * oTool is a mixin that extends the base class and implements the oTool interface
10
10
  * @param Base - The base class to extend
@@ -60,7 +60,6 @@ export class oNodeTool extends oTool(oServerNode) {
60
60
  }
61
61
  async initialize() {
62
62
  await super.initialize();
63
- this.streamHandler = new StreamHandler(this.logger);
64
63
  await this.initializeProtocols();
65
64
  }
66
65
  async handleStreamReuse(stream, connection) {
@@ -70,32 +69,43 @@ export class oNodeTool extends oTool(oServerNode) {
70
69
  if (reuse) {
71
70
  this.logger.debug('Handle stream with reuse = true');
72
71
  // record inbound connection to manager
73
- const remoteAddress = await ConnectionUtils.addressFromConnection({
74
- currentNode: this,
75
- connection: connection,
76
- });
77
- this.connectionManager.answer({
78
- nextHopAddress: remoteAddress,
79
- address: remoteAddress,
80
- callerAddress: this.address,
81
- p2pConnection: connection,
82
- reuse,
83
- // requestHandler: this.execute.bind(this), TODO: do we need this?
72
+ }
73
+ const remoteAddress = await ConnectionUtils.addressFromConnection({
74
+ currentNode: this,
75
+ connection: connection,
76
+ });
77
+ await this.connectionManager.answer({
78
+ nextHopAddress: remoteAddress,
79
+ address: remoteAddress,
80
+ callerAddress: this.address,
81
+ p2pConnection: connection,
82
+ reuse,
83
+ });
84
+ // Get the oNodeConnection for this libp2p connection
85
+ const oConnection = this.connectionManager.getConnectionByP2pConnection(connection);
86
+ if (!oConnection) {
87
+ this.logger.error('No oNodeConnection found for incoming stream', {
88
+ remotePeer: connection.remotePeer.toString(),
89
+ connectionId: connection.id,
84
90
  });
91
+ return;
85
92
  }
86
- // Use StreamHandler for consistent stream handling
87
- // This follows libp2p v3 best practices for length-prefixed streaming
88
- await this.streamHandler.handleIncomingStream(stream, connection, async (request, stream) => {
93
+ // Subscribe to InboundRequest events from the stream manager
94
+ // This follows an event-driven pattern for handling incoming requests
95
+ oConnection.streamManager.on(StreamManagerEvent.InboundRequest, async (data) => {
89
96
  try {
90
- const result = await this.execute(request, stream);
91
- // Return the raw result - StreamHandler will build and send the response
97
+ const result = await this.execute(data.request, data.stream);
98
+ // Return the raw result - StreamManager will build and send the response
92
99
  return result;
93
100
  }
94
101
  catch (error) {
95
- this.logger.error('Error executing tool: ', request.toString(), error, typeof error);
96
- throw error; // StreamHandler will handle error response building
102
+ this.logger.error('Error executing tool: ', data.request.toString(), error, typeof error);
103
+ throw error; // StreamManager will handle error response building
97
104
  }
98
105
  });
106
+ // Use the connection's StreamManager for consistent stream handling
107
+ // This follows libp2p v3 best practices for length-prefixed streaming
108
+ await oConnection.streamManager.handleIncomingStream(stream, connection);
99
109
  }
100
110
  async _tool_identify() {
101
111
  return {
@@ -1,76 +1 @@
1
- import { oNodeConnectionStream } from '../../src/connection/o-node-connection-stream.js';
2
- import { StreamPoolManagerConfig } from '../../src/index.js';
3
- /**
4
- * Create a mock stream for testing
5
- */
6
- export declare function createMockStream(id?: string, options?: {
7
- status?: 'open' | 'closed' | 'reset';
8
- writeStatus?: 'writable' | 'writing' | 'closed';
9
- readStatus?: 'readable' | 'reading' | 'closed';
10
- remoteReadStatus?: 'readable' | 'reading' | 'closed';
11
- }): any;
12
- /**
13
- * Create a mock P2P connection for testing
14
- */
15
- export declare function createMockP2PConnection(id?: string, status?: 'open' | 'closed'): any;
16
- /**
17
- * Create a mock StreamHandler for testing
18
- */
19
- export declare function createMockStreamHandler(): any;
20
- /**
21
- * Create a mock oNodeConnectionStream
22
- */
23
- export declare function createMockConnectionStream(p2pStream?: any, streamType?: 'dedicated-reader' | 'request-response' | 'general'): oNodeConnectionStream;
24
- /**
25
- * Factory for creating StreamPoolManager test config
26
- */
27
- export declare function createStreamPoolManagerConfig(overrides?: Partial<StreamPoolManagerConfig>): StreamPoolManagerConfig;
28
- /**
29
- * Event capture helper for testing event emissions
30
- */
31
- export declare class EventCapture {
32
- private emitter;
33
- private events;
34
- constructor(emitter: any);
35
- /**
36
- * Start capturing events
37
- */
38
- start(eventNames: string[]): void;
39
- /**
40
- * Get all captured events
41
- */
42
- getEvents(): Array<{
43
- type: string;
44
- data: any;
45
- timestamp: number;
46
- }>;
47
- /**
48
- * Get events of specific type
49
- */
50
- getEventsByType(type: string): any[];
51
- /**
52
- * Check if event was emitted
53
- */
54
- hasEvent(type: string): boolean;
55
- /**
56
- * Get count of specific event type
57
- */
58
- getEventCount(type: string): number;
59
- /**
60
- * Wait for specific event
61
- */
62
- waitForEvent(type: string, timeoutMs?: number): Promise<any>;
63
- /**
64
- * Clear captured events
65
- */
66
- clear(): void;
67
- }
68
- /**
69
- * Helper to make a stream invalid
70
- */
71
- export declare function makeStreamInvalid(stream: any): void;
72
- /**
73
- * Helper to wait for condition with timeout
74
- */
75
- export declare function waitFor(condition: () => boolean, timeoutMs?: number, intervalMs?: number): Promise<void>;
76
1
  //# sourceMappingURL=stream-pool-test-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-pool-test-helpers.d.ts","sourceRoot":"","sources":["../../../test/helpers/stream-pool-test-helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kDAAkD,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,GAAE,MAAsB,EAC1B,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrC,WAAW,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IAChD,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC/C,gBAAgB,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;CACjD,GACL,GAAG,CAqBL;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,GAAE,MAA0B,EAC9B,MAAM,GAAE,MAAM,GAAG,QAAiB,GACjC,GAAG,CAoBL;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,GAAG,CAwE7C;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,CAAC,EAAE,GAAG,EACf,UAAU,GAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAqB,GAC1E,qBAAqB,CASvB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,GAAE,OAAO,CAAC,uBAAuB,CAAM,GAC/C,uBAAuB,CAuBzB;AAED;;GAEG;AACH,qBAAa,YAAY;IAGX,OAAO,CAAC,OAAO;IAF3B,OAAO,CAAC,MAAM,CAA6D;gBAEvD,OAAO,EAAE,GAAG;IAEhC;;OAEG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI;IAYjC;;OAEG;IACH,SAAS,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAIlE;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE;IAIpC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/B;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAInC;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAcxE;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,CAGnD;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,OAAO,EACxB,SAAS,GAAE,MAAa,EACxB,UAAU,GAAE,MAAW,GACtB,OAAO,CAAC,IAAI,CAAC,CASf"}
1
+ {"version":3,"file":"stream-pool-test-helpers.d.ts","sourceRoot":"","sources":["../../../test/helpers/stream-pool-test-helpers.ts"],"names":[],"mappings":""}