@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 +0,0 @@
1
- {"version":3,"file":"configuration.spec.d.ts","sourceRoot":"","sources":["../../test/configuration.spec.ts"],"names":[],"mappings":""}
@@ -1,335 +0,0 @@
1
- "use strict";
2
- // import { describe, it, beforeEach } from 'mocha';
3
- // import { expect } from 'aegir/chai';
4
- // import sinon from 'sinon';
5
- // import { oLimitedTool } from '../src/o-limited.tool.js';
6
- // import { oLimitedConnectionManager } from '../src/connection/o-limited-connection-manager.js';
7
- // import { oLimitedConnection } from '../src/connection/o-limited-connection.js';
8
- // import { oNodeAddress } from '@olane/o-node';
9
- // import {
10
- // createMockP2PConnection,
11
- // createMockStreamHandler,
12
- // MockStreamHandler,
13
- // } from './helpers/index.js';
14
- // describe('Configuration Propagation', () => {
15
- // const testProtocol = '/test/1.0.0';
16
- // describe('oLimitedConnection - reusePolicy Configuration', () => {
17
- // let connection: oLimitedConnection;
18
- // let mockStreamHandler: MockStreamHandler;
19
- // beforeEach(() => {
20
- // const mockP2PConnection = createMockP2PConnection('test-conn', 'open');
21
- // mockStreamHandler = createMockStreamHandler();
22
- // connection = new oLimitedConnection({
23
- // nextHopAddress: new oNodeAddress('o://next-hop'),
24
- // address: new oNodeAddress('o://test'),
25
- // p2pConnection: mockP2PConnection as any,
26
- // callerAddress: new oNodeAddress('o://test'),
27
- // runOnLimitedConnection: true,
28
- // });
29
- // (connection as any).streamHandler = mockStreamHandler;
30
- // (connection as any).nextHopAddress = { protocol: testProtocol };
31
- // });
32
- // it('should ALWAYS set reusePolicy to "reuse" in getOrCreateStream', async () => {
33
- // await connection.getOrCreateStream();
34
- // const config = mockStreamHandler.getLastGetOrCreateConfig();
35
- // expect(config?.reusePolicy).toBe('reuse');
36
- // });
37
- // it('should ALWAYS set reusePolicy to "reuse" in postTransmit', async () => {
38
- // const stream = await connection.getOrCreateStream();
39
- // await connection.postTransmit(stream);
40
- // const closeConfig = mockStreamHandler.getLastCloseConfig();
41
- // expect(closeConfig?.reusePolicy).toBe('reuse');
42
- // });
43
- // it('should set reusePolicy to "reuse" regardless of runOnLimitedConnection flag', async () => {
44
- // // Test with runOnLimitedConnection: false
45
- // const connectionDisabled = new oLimitedConnection({
46
- // nextHopAddress: new oNodeAddress('o://next-hop'),
47
- // address: new oNodeAddress('o://test'),
48
- // p2pConnection: createMockP2PConnection('test-conn-2', 'open') as any,
49
- // callerAddress: new oNodeAddress('o://test'),
50
- // runOnLimitedConnection: false, // Disabled
51
- // });
52
- // const handler = createMockStreamHandler();
53
- // (connectionDisabled as any).streamHandler = handler;
54
- // (connectionDisabled as any).nextHopAddress = { protocol: testProtocol };
55
- // await connectionDisabled.getOrCreateStream();
56
- // const config = handler.getLastGetOrCreateConfig();
57
- // expect(config?.reusePolicy).toBe('reuse');
58
- // });
59
- // });
60
- // describe('oLimitedConnectionManager - Configuration Flow', () => {
61
- // let manager: oLimitedConnectionManager;
62
- // beforeEach(() => {
63
- // manager = new oLimitedConnectionManager({
64
- // p2pNode: null as any, // Not needed for this test
65
- // defaultReadTimeoutMs: 5000,
66
- // defaultDrainTimeoutMs: 30000,
67
- // runOnLimitedConnection: true,
68
- // });
69
- // });
70
- // it('should create oLimitedConnection instances (not base oNodeConnection)', async () => {
71
- // // Mock the getOrCreateConnection method
72
- // (manager as any).getOrCreateConnection = jest.fn(async () => {
73
- // return createMockP2PConnection('test-conn', 'open') as any;
74
- // });
75
- // const connection = await manager.connect({
76
- // address: new oNodeAddress('o://test'),
77
- // nextHopAddress: new oNodeAddress('o://next-hop'),
78
- // callerAddress: new oNodeAddress('o://caller'),
79
- // });
80
- // expect(connection).toBeInstanceOf(oLimitedConnection);
81
- // });
82
- // it('should pass runOnLimitedConnection flag to connection', async () => {
83
- // (manager as any).getOrCreateConnection = jest.fn(async () => {
84
- // return createMockP2PConnection('test-conn', 'open') as any;
85
- // });
86
- // const connection = await manager.connect({
87
- // address: new oNodeAddress('o://test'),
88
- // nextHopAddress: new oNodeAddress('o://next-hop'),
89
- // callerAddress: new oNodeAddress('o://caller'),
90
- // });
91
- // // Access the private config to verify
92
- // expect((connection as any).config.runOnLimitedConnection).toBe(true);
93
- // });
94
- // it('should pass requestHandler to connection when provided', async () => {
95
- // (manager as any).getOrCreateConnection = jest.fn(async () => {
96
- // return createMockP2PConnection('test-conn', 'open') as any;
97
- // });
98
- // const mockRequestHandler = jest.fn() as any;
99
- // const connection = await manager.connect({
100
- // address: new oNodeAddress('o://test'),
101
- // nextHopAddress: new oNodeAddress('o://next-hop'),
102
- // callerAddress: new oNodeAddress('o://caller'),
103
- // requestHandler: mockRequestHandler,
104
- // });
105
- // // Verify requestHandler was passed through
106
- // expect((connection as any).config.requestHandler).toBe(
107
- // mockRequestHandler,
108
- // );
109
- // });
110
- // it('should handle runOnLimitedConnection: false', async () => {
111
- // const managerDisabled = new oLimitedConnectionManager({
112
- // p2pNode: null as any,
113
- // runOnLimitedConnection: false,
114
- // });
115
- // (managerDisabled as any).getOrCreateConnection = jest.fn(async () => {
116
- // return createMockP2PConnection('test-conn', 'open') as any;
117
- // });
118
- // const connection = await managerDisabled.connect({
119
- // address: new oNodeAddress('o://test'),
120
- // nextHopAddress: new oNodeAddress('o://next-hop'),
121
- // callerAddress: new oNodeAddress('o://caller'),
122
- // });
123
- // expect((connection as any).config.runOnLimitedConnection).toBe(false);
124
- // });
125
- // });
126
- // describe('oLimitedTool - RequestHandler Injection', () => {
127
- // it('should inject requestHandler in connect() method', async () => {
128
- // const tool = new oLimitedTool({
129
- // address: new oNodeAddress('o://test-tool'),
130
- // leader: null,
131
- // parent: null,
132
- // });
133
- // // Mock the super.connect to capture the config
134
- // let capturedConfig: any;
135
- // (tool as any).super_connect = (tool as any).connect;
136
- // const originalConnect = Object.getPrototypeOf(
137
- // Object.getPrototypeOf(tool),
138
- // ).connect;
139
- // Object.getPrototypeOf(Object.getPrototypeOf(tool)).connect = jest.fn(
140
- // async function (config: any) {
141
- // capturedConfig = config;
142
- // return null as any; // Don't actually connect
143
- // },
144
- // );
145
- // try {
146
- // await tool.connect({
147
- // nextHopAddress: new oNodeAddress('o://next-hop'),
148
- // address: new oNodeAddress('o://test'),
149
- // callerAddress: new oNodeAddress('o://caller'),
150
- // } as any);
151
- // // Verify requestHandler was injected
152
- // expect(capturedConfig.requestHandler).toBeDefined();
153
- // expect(typeof capturedConfig.requestHandler).toBe('function');
154
- // } finally {
155
- // // Restore original
156
- // Object.getPrototypeOf(Object.getPrototypeOf(tool)).connect =
157
- // originalConnect;
158
- // }
159
- // });
160
- // it('should bind requestHandler to tool.execute method', async () => {
161
- // const tool = new oLimitedTool({
162
- // address: new oNodeAddress('o://test-tool'),
163
- // leader: null,
164
- // parent: null,
165
- // });
166
- // let capturedConfig: any;
167
- // const originalConnect = Object.getPrototypeOf(
168
- // Object.getPrototypeOf(tool),
169
- // ).connect;
170
- // Object.getPrototypeOf(Object.getPrototypeOf(tool)).connect = jest.fn(
171
- // async function (config: any) {
172
- // capturedConfig = config;
173
- // return null as any;
174
- // },
175
- // );
176
- // try {
177
- // await tool.connect({
178
- // nextHopAddress: new oNodeAddress('o://next-hop'),
179
- // address: new oNodeAddress('o://test'),
180
- // callerAddress: new oNodeAddress('o://caller'),
181
- // } as any);
182
- // // Verify the requestHandler is bound to execute
183
- // // We can't directly test it's the same function, but we can verify it's a bound function
184
- // expect(capturedConfig.requestHandler.name).toBe('bound execute');
185
- // } finally {
186
- // Object.getPrototypeOf(Object.getPrototypeOf(tool)).connect =
187
- // originalConnect;
188
- // }
189
- // });
190
- // it('should preserve other config properties when injecting requestHandler', async () => {
191
- // const tool = new oLimitedTool({
192
- // address: new oNodeAddress('o://test-tool'),
193
- // leader: null,
194
- // parent: null,
195
- // });
196
- // let capturedConfig: any;
197
- // const originalConnect = Object.getPrototypeOf(
198
- // Object.getPrototypeOf(tool),
199
- // ).connect;
200
- // Object.getPrototypeOf(Object.getPrototypeOf(tool)).connect = jest.fn(
201
- // async function (config: any) {
202
- // capturedConfig = config;
203
- // return null as any;
204
- // },
205
- // );
206
- // try {
207
- // const testAddress = new oNodeAddress('o://test');
208
- // const nextHopAddress = new oNodeAddress('o://next-hop');
209
- // const callerAddress = new oNodeAddress('o://caller');
210
- // await tool.connect({
211
- // nextHopAddress,
212
- // address: testAddress,
213
- // callerAddress,
214
- // } as any);
215
- // // Verify original properties preserved
216
- // expect(capturedConfig.nextHopAddress).toBe(nextHopAddress);
217
- // expect(capturedConfig.address).toBe(testAddress);
218
- // expect(capturedConfig.callerAddress).toBe(callerAddress);
219
- // // And requestHandler added
220
- // expect(capturedConfig.requestHandler).toBeDefined();
221
- // } finally {
222
- // Object.getPrototypeOf(Object.getPrototypeOf(tool)).connect =
223
- // originalConnect;
224
- // }
225
- // });
226
- // });
227
- // describe('oLimitedTool - Network Listeners Configuration', () => {
228
- // it('should default to empty listeners array', () => {
229
- // const tool = new oLimitedTool({
230
- // address: new oNodeAddress('o://test-tool'),
231
- // leader: null,
232
- // parent: null,
233
- // });
234
- // const config = (tool as any).config;
235
- // expect(config.network?.listeners).toEqual([]);
236
- // });
237
- // it('should preserve custom listeners if explicitly provided', () => {
238
- // const customListeners = ['/ip4/0.0.0.0/tcp/0'];
239
- // const tool = new oLimitedTool({
240
- // address: new oNodeAddress('o://test-tool'),
241
- // leader: null,
242
- // parent: null,
243
- // network: {
244
- // listeners: customListeners,
245
- // },
246
- // });
247
- // const config = (tool as any).config;
248
- // expect(config.network?.listeners).toEqual(customListeners);
249
- // });
250
- // it('should preserve other network config while setting listeners', () => {
251
- // const tool = new oLimitedTool({
252
- // address: new oNodeAddress('o://test-tool'),
253
- // leader: null,
254
- // parent: null,
255
- // network: {},
256
- // });
257
- // const config = (tool as any).config;
258
- // expect(config.network?.listeners).toEqual([]);
259
- // });
260
- // });
261
- // describe('oLimitedTool - ConnectionManager Initialization', () => {
262
- // it('should use oLimitedConnectionManager instead of base manager', async () => {
263
- // const tool = new oLimitedTool({
264
- // address: new oNodeAddress('o://test-tool'),
265
- // leader: null,
266
- // parent: null,
267
- // runOnLimitedConnection: true,
268
- // });
269
- // // Initialize the connection manager
270
- // await tool.initConnectionManager();
271
- // // Verify it's the correct type
272
- // expect((tool as any).connectionManager).toBeInstanceOf(
273
- // oLimitedConnectionManager,
274
- // );
275
- // });
276
- // it('should pass runOnLimitedConnection flag to manager', async () => {
277
- // const tool = new oLimitedTool({
278
- // address: new oNodeAddress('o://test-tool'),
279
- // leader: null,
280
- // parent: null,
281
- // runOnLimitedConnection: true,
282
- // });
283
- // await tool.initConnectionManager();
284
- // const manager = (tool as any).connectionManager;
285
- // expect((manager as any).config.runOnLimitedConnection).toBe(true);
286
- // });
287
- // it('should pass connection timeouts to manager', async () => {
288
- // const tool = new oLimitedTool({
289
- // address: new oNodeAddress('o://test-tool'),
290
- // leader: null,
291
- // parent: null,
292
- // connectionTimeouts: {
293
- // readTimeoutMs: 10000,
294
- // drainTimeoutMs: 60000,
295
- // },
296
- // });
297
- // await tool.initConnectionManager();
298
- // const manager = (tool as any).connectionManager;
299
- // expect((manager as any).config.defaultReadTimeoutMs).toBe(10000);
300
- // expect((manager as any).config.defaultDrainTimeoutMs).toBe(60000);
301
- // });
302
- // });
303
- // describe('Full Chain - Tool → Manager → Connection → StreamHandler', () => {
304
- // it('should propagate runOnLimitedConnection through entire chain', async () => {
305
- // // This is an integration-style test verifying the full config flow
306
- // const tool = new oLimitedTool({
307
- // address: new oNodeAddress('o://test-tool'),
308
- // leader: null,
309
- // parent: null,
310
- // runOnLimitedConnection: true,
311
- // });
312
- // await tool.initConnectionManager();
313
- // const manager = (tool as any).connectionManager as oLimitedConnectionManager;
314
- // // Mock getOrCreateConnection
315
- // (manager as any).getOrCreateConnection = jest.fn(async () => {
316
- // return createMockP2PConnection('test-conn', 'open') as any;
317
- // });
318
- // const connection = await manager.connect({
319
- // address: new oNodeAddress('o://test'),
320
- // nextHopAddress: new oNodeAddress('o://next-hop'),
321
- // callerAddress: new oNodeAddress('o://caller'),
322
- // });
323
- // // Verify flag propagated to connection
324
- // expect((connection as any).config.runOnLimitedConnection).toBe(true);
325
- // // Mock streamHandler and verify it receives the flag
326
- // const mockStreamHandler = createMockStreamHandler();
327
- // (connection as any).streamHandler = mockStreamHandler;
328
- // (connection as any).nextHopAddress = { protocol: testProtocol };
329
- // await connection.getOrCreateStream();
330
- // const streamConfig = mockStreamHandler.getLastGetOrCreateConfig();
331
- // expect(streamConfig?.runOnLimitedConnection).toBe(true);
332
- // expect(streamConfig?.reusePolicy).toBe('reuse');
333
- // });
334
- // });
335
- // });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=error-handling.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-handling.spec.d.ts","sourceRoot":"","sources":["../../test/error-handling.spec.ts"],"names":[],"mappings":""}