@olane/o-client-limited 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 (49) hide show
  1. package/dist/src/connection/o-limited-connection.d.ts +12 -21
  2. package/dist/src/connection/o-limited-connection.d.ts.map +1 -1
  3. package/dist/src/connection/o-limited-connection.js +31 -65
  4. package/dist/src/connection/o-limited.stream-manager.d.ts +79 -0
  5. package/dist/src/connection/o-limited.stream-manager.d.ts.map +1 -0
  6. package/dist/src/connection/o-limited.stream-manager.js +234 -0
  7. package/dist/test/bidirectional-communication.spec.d.ts +2 -0
  8. package/dist/test/bidirectional-communication.spec.d.ts.map +1 -0
  9. package/dist/test/bidirectional-communication.spec.js +265 -0
  10. package/dist/test/helpers/index.d.ts +2 -3
  11. package/dist/test/helpers/index.d.ts.map +1 -1
  12. package/dist/test/helpers/index.js +2 -3
  13. package/dist/test/helpers/limited-test-tool.d.ts +41 -0
  14. package/dist/test/helpers/limited-test-tool.d.ts.map +1 -0
  15. package/dist/test/helpers/limited-test-tool.js +98 -0
  16. package/dist/test/helpers/receiver-test-tool.d.ts +34 -0
  17. package/dist/test/helpers/receiver-test-tool.d.ts.map +1 -0
  18. package/dist/test/helpers/receiver-test-tool.js +67 -0
  19. package/dist/test/limited-connection-lifecycle.spec.d.ts +2 -0
  20. package/dist/test/limited-connection-lifecycle.spec.d.ts.map +1 -0
  21. package/dist/test/limited-connection-lifecycle.spec.js +209 -0
  22. package/dist/test/limited-stream-manager.spec.d.ts +2 -0
  23. package/dist/test/limited-stream-manager.spec.d.ts.map +1 -0
  24. package/dist/test/limited-stream-manager.spec.js +222 -0
  25. package/dist/test/reader-stream-recovery.spec.d.ts +2 -0
  26. package/dist/test/reader-stream-recovery.spec.d.ts.map +1 -0
  27. package/dist/test/reader-stream-recovery.spec.js +188 -0
  28. package/package.json +8 -8
  29. package/dist/test/configuration.spec.d.ts +0 -1
  30. package/dist/test/configuration.spec.d.ts.map +0 -1
  31. package/dist/test/configuration.spec.js +0 -335
  32. package/dist/test/error-handling.spec.d.ts +0 -2
  33. package/dist/test/error-handling.spec.d.ts.map +0 -1
  34. package/dist/test/error-handling.spec.js +0 -378
  35. package/dist/test/helpers/mock-p2p-connection.d.ts +0 -38
  36. package/dist/test/helpers/mock-p2p-connection.d.ts.map +0 -1
  37. package/dist/test/helpers/mock-p2p-connection.js +0 -66
  38. package/dist/test/helpers/mock-stream-handler.d.ts +0 -43
  39. package/dist/test/helpers/mock-stream-handler.d.ts.map +0 -1
  40. package/dist/test/helpers/mock-stream-handler.js +0 -71
  41. package/dist/test/helpers/mock-stream.d.ts +0 -46
  42. package/dist/test/helpers/mock-stream.d.ts.map +0 -1
  43. package/dist/test/helpers/mock-stream.js +0 -59
  44. package/dist/test/method.spec.d.ts +0 -1
  45. package/dist/test/method.spec.d.ts.map +0 -1
  46. package/dist/test/method.spec.js +0 -29
  47. package/dist/test/stream-reuse.spec.d.ts +0 -1
  48. package/dist/test/stream-reuse.spec.d.ts.map +0 -1
  49. package/dist/test/stream-reuse.spec.js +0 -267
@@ -1,59 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- /**
3
- * Mock Stream implementation for testing
4
- */
5
- export class MockStream extends EventEmitter {
6
- constructor(id, protocol, options = {}) {
7
- super();
8
- this.abortCallCount = 0;
9
- this.closeCallCount = 0;
10
- this.id = id;
11
- this.protocol = protocol;
12
- this.status = options.status || 'open';
13
- this.writeStatus = options.writeStatus || 'writable';
14
- this.readStatus = options.readStatus || 'readable';
15
- this.remoteReadStatus = options.remoteReadStatus || 'readable';
16
- this.direction = options.direction || 'outbound';
17
- this.timeline = {
18
- open: Date.now(),
19
- };
20
- }
21
- abort(err) {
22
- this.abortCallCount++;
23
- this.status = 'aborted';
24
- this.writeStatus = 'closed';
25
- this.readStatus = 'closed';
26
- this.remoteReadStatus = 'closed';
27
- this.timeline.close = Date.now();
28
- this.emit('abort', err);
29
- }
30
- async close(options) {
31
- this.closeCallCount++;
32
- this.status = 'closed';
33
- this.writeStatus = 'closed';
34
- this.readStatus = 'closed';
35
- this.remoteReadStatus = 'closed';
36
- this.timeline.close = Date.now();
37
- this.emit('close');
38
- }
39
- reset() {
40
- this.status = 'reset';
41
- this.writeStatus = 'closed';
42
- this.readStatus = 'closed';
43
- this.remoteReadStatus = 'closed';
44
- this.timeline.close = Date.now();
45
- this.emit('reset');
46
- }
47
- }
48
- /**
49
- * Create a mock stream with default open/writable/readable state
50
- */
51
- export function createMockStream(id = 'test-stream', protocol = '/test/1.0.0', options) {
52
- return new MockStream(id, protocol, options);
53
- }
54
- /**
55
- * Create multiple mock streams
56
- */
57
- export function createMockStreams(count, protocol = '/test/1.0.0') {
58
- return Array.from({ length: count }, (_, i) => createMockStream(`stream-${i}`, protocol));
59
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=method.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"method.spec.d.ts","sourceRoot":"","sources":["../../test/method.spec.ts"],"names":[],"mappings":""}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- // import { oAddress, NodeState, oRequest } from '@olane/o-core';
3
- // import { oVirtualTool } from '../src/virtual.tool.js';
4
- // import { expect } from 'chai';
5
- // describe('o-tool @methods', () => {
6
- // it('should call the hello_world method', async () => {
7
- // const node = new oVirtualTool({
8
- // address: new oAddress('o://test'),
9
- // leader: null,
10
- // parent: null,
11
- // });
12
- // await node.start();
13
- // expect(node.state).to.equal(NodeState.RUNNING);
14
- // // call the tool
15
- // const req = new oRequest({
16
- // method: 'hello_world',
17
- // id: '123',
18
- // params: {
19
- // _connectionId: '123',
20
- // _requestMethod: 'hello_world',
21
- // },
22
- // });
23
- // const data = await node.callMyTool(req);
24
- // expect(data.message).to.equal('Hello, world!');
25
- // // stop the node
26
- // await node.stop();
27
- // expect(node.state).to.equal(NodeState.STOPPED);
28
- // });
29
- // });
@@ -1 +0,0 @@
1
- //# sourceMappingURL=stream-reuse.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream-reuse.spec.d.ts","sourceRoot":"","sources":["../../test/stream-reuse.spec.ts"],"names":[],"mappings":""}
@@ -1,267 +0,0 @@
1
- "use strict";
2
- // import { describe, it, beforeEach } from 'mocha';
3
- // import { expect } from 'aegir/chai';
4
- // import { oLimitedConnection } from '../src/connection/o-limited-connection.js';
5
- // import { oNodeAddress } from '@olane/o-node';
6
- // import {
7
- // createMockP2PConnection,
8
- // createMockStream,
9
- // createMockStreamHandler,
10
- // MockStream,
11
- // MockP2PConnection,
12
- // MockStreamHandler,
13
- // } from './helpers/index.js';
14
- // describe('oLimitedConnection - Stream Reuse Core Behavior', () => {
15
- // let connection: oLimitedConnection;
16
- // let mockP2PConnection: MockP2PConnection;
17
- // let mockStreamHandler: MockStreamHandler;
18
- // const testProtocol = '/test/1.0.0';
19
- // const testAddress = new oNodeAddress('o://test');
20
- // const nextHopAddress = new oNodeAddress('o://next-hop');
21
- // beforeEach(() => {
22
- // // Create fresh mocks for each test
23
- // mockP2PConnection = createMockP2PConnection('test-conn', 'open');
24
- // mockStreamHandler = createMockStreamHandler();
25
- // // Create connection instance
26
- // connection = new oLimitedConnection({
27
- // nextHopAddress,
28
- // address: testAddress,
29
- // p2pConnection: mockP2PConnection as any,
30
- // callerAddress: testAddress,
31
- // runOnLimitedConnection: true,
32
- // });
33
- // // Inject mock stream handler
34
- // (connection as any).streamHandler = mockStreamHandler;
35
- // (connection as any).nextHopAddress = { protocol: testProtocol };
36
- // });
37
- // describe('Stream Reuse - Core Feature', () => {
38
- // it('should reuse existing open stream for multiple requests', async () => {
39
- // // Create a stream and add it to the connection
40
- // const existingStream = createMockStream('stream-1', testProtocol, {
41
- // status: 'open',
42
- // writeStatus: 'writable',
43
- // remoteReadStatus: 'readable',
44
- // });
45
- // mockP2PConnection.addStream(existingStream);
46
- // // First call should return the existing stream
47
- // const stream1 = await connection.getOrCreateStream();
48
- // expect(stream1).toBe(existingStream);
49
- // expect(mockStreamHandler.getOrCreateStreamCalls.length).toBe(1);
50
- // // Verify reusePolicy was set to 'reuse'
51
- // const config1 = mockStreamHandler.getLastGetOrCreateConfig();
52
- // expect(config1?.reusePolicy).toBe('reuse');
53
- // // Second call should return the same stream (reused)
54
- // const stream2 = await connection.getOrCreateStream();
55
- // expect(stream2).toBe(existingStream);
56
- // expect(stream2).toBe(stream1);
57
- // expect(mockStreamHandler.getOrCreateStreamCalls.length).toBe(2);
58
- // // Verify reusePolicy was still 'reuse'
59
- // const config2 = mockStreamHandler.getLastGetOrCreateConfig();
60
- // expect(config2?.reusePolicy).toBe('reuse');
61
- // });
62
- // it('should NOT close stream after transmission (postTransmit)', async () => {
63
- // const stream = createMockStream('stream-1', testProtocol);
64
- // mockP2PConnection.addStream(stream);
65
- // // Get the stream
66
- // await connection.getOrCreateStream();
67
- // // Simulate transmission complete - call postTransmit
68
- // await connection.postTransmit(stream as any);
69
- // // Verify stream was NOT aborted or closed
70
- // expect((stream as any).abortCallCount).toBe(0);
71
- // expect(stream.closeCallCount).toBe(0);
72
- // expect(stream.status).toBe('open');
73
- // // Verify close was called with reusePolicy: 'reuse'
74
- // expect(mockStreamHandler.closeCalls.length).toBe(1);
75
- // const closeConfig = mockStreamHandler.getLastCloseConfig();
76
- // expect(closeConfig?.reusePolicy).toBe('reuse');
77
- // });
78
- // it('should keep stream open status after postTransmit', async () => {
79
- // const stream = createMockStream('stream-1', testProtocol, {
80
- // status: 'open',
81
- // writeStatus: 'writable',
82
- // remoteReadStatus: 'readable',
83
- // });
84
- // mockP2PConnection.addStream(stream);
85
- // // Call postTransmit
86
- // await connection.postTransmit(stream as any);
87
- // // Stream should remain in usable state
88
- // expect(stream.status).toBe('open');
89
- // expect(stream.writeStatus).toBe('writable');
90
- // expect(stream.remoteReadStatus).toBe('readable');
91
- // });
92
- // });
93
- // describe('Stream Selection Criteria', () => {
94
- // it('should only reuse streams with status=open', async () => {
95
- // // Add a closed stream
96
- // const closedStream = createMockStream('stream-closed', testProtocol, {
97
- // status: 'closed',
98
- // writeStatus: 'closed',
99
- // });
100
- // mockP2PConnection.addStream(closedStream);
101
- // // Add an open stream
102
- // const openStream = createMockStream('stream-open', testProtocol, {
103
- // status: 'open',
104
- // writeStatus: 'writable',
105
- // remoteReadStatus: 'readable',
106
- // });
107
- // mockP2PConnection.addStream(openStream);
108
- // // Should select the open stream, not the closed one
109
- // const stream = await connection.getOrCreateStream();
110
- // expect(stream).toBe(openStream);
111
- // expect(stream).not.toBe(closedStream);
112
- // });
113
- // it('should only reuse streams with writeStatus=writable', async () => {
114
- // // Add a non-writable stream
115
- // const nonWritableStream = createMockStream(
116
- // 'stream-readonly',
117
- // testProtocol,
118
- // {
119
- // status: 'open',
120
- // writeStatus: 'closed',
121
- // remoteReadStatus: 'readable',
122
- // },
123
- // );
124
- // mockP2PConnection.addStream(nonWritableStream);
125
- // // Should create a new stream instead of reusing non-writable
126
- // const stream = await connection.getOrCreateStream();
127
- // expect(stream).not.toBe(nonWritableStream);
128
- // expect(stream.writeStatus).toBe('writable');
129
- // });
130
- // it('should only reuse streams with remoteReadStatus=readable', async () => {
131
- // // Add a stream where remote can't read
132
- // const nonReadableStream = createMockStream(
133
- // 'stream-noread',
134
- // testProtocol,
135
- // {
136
- // status: 'open',
137
- // writeStatus: 'writable',
138
- // remoteReadStatus: 'closed',
139
- // },
140
- // );
141
- // mockP2PConnection.addStream(nonReadableStream);
142
- // // Should create a new stream instead
143
- // const stream = await connection.getOrCreateStream();
144
- // expect(stream).not.toBe(nonReadableStream);
145
- // expect(stream.remoteReadStatus).toBe('readable');
146
- // });
147
- // it('should only reuse streams matching the protocol', async () => {
148
- // // Add a stream with different protocol
149
- // const differentProtocolStream = createMockStream(
150
- // 'stream-other',
151
- // '/other/1.0.0',
152
- // {
153
- // status: 'open',
154
- // writeStatus: 'writable',
155
- // remoteReadStatus: 'readable',
156
- // },
157
- // );
158
- // mockP2PConnection.addStream(differentProtocolStream);
159
- // // Should create a new stream with correct protocol
160
- // const stream = await connection.getOrCreateStream();
161
- // expect(stream).not.toBe(differentProtocolStream);
162
- // expect(stream.protocol).toBe(testProtocol);
163
- // });
164
- // it('should NOT reuse reset streams', async () => {
165
- // const resetStream = createMockStream('stream-reset', testProtocol, {
166
- // status: 'reset',
167
- // });
168
- // mockP2PConnection.addStream(resetStream);
169
- // // Should create a new stream, not reuse reset one
170
- // const stream = await connection.getOrCreateStream();
171
- // expect(stream).not.toBe(resetStream);
172
- // expect(stream.status).toBe('open');
173
- // });
174
- // it('should NOT reuse aborted streams', async () => {
175
- // const abortedStream = createMockStream('stream-aborted', testProtocol, {
176
- // status: 'aborted',
177
- // });
178
- // mockP2PConnection.addStream(abortedStream);
179
- // // Should create a new stream
180
- // const stream = await connection.getOrCreateStream();
181
- // expect(stream).not.toBe(abortedStream);
182
- // expect(stream.status).toBe('open');
183
- // });
184
- // });
185
- // describe('Stream Creation When No Reusable Stream Exists', () => {
186
- // it('should create new stream when no existing streams', async () => {
187
- // // No streams in connection
188
- // expect(mockP2PConnection.streams.length).toBe(0);
189
- // const stream = await connection.getOrCreateStream();
190
- // // Should have created a new stream
191
- // expect(stream).toBeDefined();
192
- // expect(stream.protocol).toBe(testProtocol);
193
- // expect(stream.status).toBe('open');
194
- // expect(mockP2PConnection.streams.length).toBe(1);
195
- // });
196
- // it('should create new stream when existing streams are unusable', async () => {
197
- // // Add only unusable streams
198
- // mockP2PConnection.addStream(
199
- // createMockStream('stream-1', testProtocol, { status: 'closed' }),
200
- // );
201
- // mockP2PConnection.addStream(
202
- // createMockStream('stream-2', testProtocol, {
203
- // status: 'open',
204
- // writeStatus: 'closed',
205
- // }),
206
- // );
207
- // mockP2PConnection.addStream(
208
- // createMockStream('stream-3', '/wrong/1.0.0', {
209
- // status: 'open',
210
- // writeStatus: 'writable',
211
- // }),
212
- // );
213
- // const initialCount = mockP2PConnection.streams.length;
214
- // const stream = await connection.getOrCreateStream();
215
- // // Should have created a new stream
216
- // expect(mockP2PConnection.streams.length).toBe(initialCount + 1);
217
- // expect(stream.protocol).toBe(testProtocol);
218
- // expect(stream.status).toBe('open');
219
- // expect(stream.writeStatus).toBe('writable');
220
- // });
221
- // });
222
- // describe('Configuration - runOnLimitedConnection Flag', () => {
223
- // it('should pass runOnLimitedConnection: true to stream handler', async () => {
224
- // await connection.getOrCreateStream();
225
- // const config = mockStreamHandler.getLastGetOrCreateConfig();
226
- // expect(config?.runOnLimitedConnection).toBe(true);
227
- // });
228
- // it('should pass runOnLimitedConnection: false when disabled', async () => {
229
- // // Create connection with flag disabled
230
- // const disabledConnection = new oLimitedConnection({
231
- // nextHopAddress,
232
- // address: testAddress,
233
- // p2pConnection: createMockP2PConnection('test-conn-2', 'open') as any,
234
- // callerAddress: testAddress,
235
- // runOnLimitedConnection: false,
236
- // });
237
- // (disabledConnection as any).streamHandler = mockStreamHandler;
238
- // (disabledConnection as any).nextHopAddress = { protocol: testProtocol };
239
- // await disabledConnection.getOrCreateStream();
240
- // const config = mockStreamHandler.getLastGetOrCreateConfig();
241
- // expect(config?.runOnLimitedConnection).toBe(false);
242
- // });
243
- // });
244
- // describe('Environment Variables', () => {
245
- // it('should read MAX_OUTBOUND_STREAMS from environment', async () => {
246
- // process.env.MAX_OUTBOUND_STREAMS = '500';
247
- // await connection.getOrCreateStream();
248
- // const config = mockStreamHandler.getLastGetOrCreateConfig();
249
- // expect(config?.maxOutboundStreams).toBe(500);
250
- // delete process.env.MAX_OUTBOUND_STREAMS;
251
- // });
252
- // it('should default to 1000 when MAX_OUTBOUND_STREAMS not set', async () => {
253
- // delete process.env.MAX_OUTBOUND_STREAMS;
254
- // await connection.getOrCreateStream();
255
- // const config = mockStreamHandler.getLastGetOrCreateConfig();
256
- // expect(config?.maxOutboundStreams).toBe(1000);
257
- // });
258
- // it('should handle invalid MAX_OUTBOUND_STREAMS gracefully', async () => {
259
- // process.env.MAX_OUTBOUND_STREAMS = 'invalid';
260
- // await connection.getOrCreateStream();
261
- // const config = mockStreamHandler.getLastGetOrCreateConfig();
262
- // // parseInt('invalid') returns NaN, but we still get a number
263
- // expect(typeof config?.maxOutboundStreams).toBe('number');
264
- // delete process.env.MAX_OUTBOUND_STREAMS;
265
- // });
266
- // });
267
- // });