@olane/o-core 0.7.55 → 0.7.56
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/interfaces/connection-manager.config.d.ts +0 -12
- package/dist/src/connection/interfaces/connection-manager.config.d.ts.map +1 -1
- package/dist/src/connection/interfaces/connection-send-params.interface.d.ts +1 -1
- package/dist/src/connection/interfaces/connection-send-params.interface.d.ts.map +1 -1
- package/dist/src/connection/interfaces/connection.config.d.ts +1 -21
- package/dist/src/connection/interfaces/connection.config.d.ts.map +1 -1
- package/dist/src/connection/o-connection.d.ts +2 -3
- package/dist/src/connection/o-connection.d.ts.map +1 -1
- package/dist/src/connection/o-connection.js +6 -9
- package/dist/src/core/interfaces/use-data.config.d.ts +8 -0
- package/dist/src/core/interfaces/use-data.config.d.ts.map +1 -0
- package/dist/src/core/interfaces/use-data.config.js +1 -0
- package/dist/src/core/lib/o-request.manager.d.ts +20 -5
- package/dist/src/core/lib/o-request.manager.d.ts.map +1 -1
- package/dist/src/core/lib/o-request.manager.js +14 -1
- package/dist/src/core/o-core.d.ts +7 -41
- package/dist/src/core/o-core.d.ts.map +1 -1
- package/dist/src/core/o-core.js +13 -78
- package/dist/src/error/enums/codes.error.d.ts +3 -1
- package/dist/src/error/enums/codes.error.d.ts.map +1 -1
- package/dist/src/error/enums/codes.error.js +2 -0
- package/package.json +3 -3
|
@@ -1,15 +1,3 @@
|
|
|
1
1
|
export interface oConnectionManagerConfig {
|
|
2
|
-
/**
|
|
3
|
-
* Default timeout in milliseconds for reading response data from a stream.
|
|
4
|
-
* Can be overridden per connection.
|
|
5
|
-
* Default: 120000 (2 minutes)
|
|
6
|
-
*/
|
|
7
|
-
defaultReadTimeoutMs?: number;
|
|
8
|
-
/**
|
|
9
|
-
* Default timeout in milliseconds for waiting for stream buffer to drain when backpressure occurs.
|
|
10
|
-
* Can be overridden per connection.
|
|
11
|
-
* Default: 30000 (30 seconds)
|
|
12
|
-
*/
|
|
13
|
-
defaultDrainTimeoutMs?: number;
|
|
14
2
|
}
|
|
15
3
|
//# sourceMappingURL=connection-manager.config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/connection-manager.config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;
|
|
1
|
+
{"version":3,"file":"connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/connection-manager.config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-send-params.interface.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/connection-send-params.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"connection-send-params.interface.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/connection-send-params.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { oAddress } from '../../router/o-address.js';
|
|
2
|
-
import type { oRequest } from '../o-request.js';
|
|
3
|
-
import type { Stream } from '@libp2p/interface';
|
|
4
|
-
import type { RunResult } from '@olane/o-tool';
|
|
5
2
|
export interface oConnectionConfig {
|
|
6
3
|
nextHopAddress: oAddress;
|
|
7
4
|
callerAddress?: oAddress;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Timeout in milliseconds for reading response data from a stream.
|
|
11
|
-
* Default: 120000 (2 minutes)
|
|
12
|
-
*/
|
|
13
|
-
readTimeoutMs?: number;
|
|
14
|
-
/**
|
|
15
|
-
* Timeout in milliseconds for waiting for stream buffer to drain when backpressure occurs.
|
|
16
|
-
* Default: 30000 (30 seconds)
|
|
17
|
-
*/
|
|
18
|
-
drainTimeoutMs?: number;
|
|
5
|
+
targetAddress: oAddress;
|
|
19
6
|
isStream?: boolean;
|
|
20
|
-
abortSignal?: AbortSignal;
|
|
21
|
-
/**
|
|
22
|
-
* Optional handler for processing router requests received on outgoing streams
|
|
23
|
-
* This enables bidirectional communication where the client can receive and process
|
|
24
|
-
* router requests while waiting for responses
|
|
25
|
-
*/
|
|
26
|
-
requestHandler?: (request: oRequest, stream: Stream) => Promise<RunResult>;
|
|
27
7
|
}
|
|
28
8
|
//# sourceMappingURL=connection.config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,QAAQ,CAAC;IACzB,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,aAAa,EAAE,QAAQ,CAAC;IAExB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -10,15 +10,14 @@ export declare abstract class oConnection extends oObject {
|
|
|
10
10
|
readonly id: string;
|
|
11
11
|
protected readonly emitter: EventEmitter;
|
|
12
12
|
constructor(config: oConnectionConfig);
|
|
13
|
-
get abortSignal(): AbortSignal | undefined;
|
|
14
13
|
get address(): oAddress;
|
|
15
14
|
get nextHopAddress(): oAddress;
|
|
16
15
|
get callerAddress(): oAddress | undefined;
|
|
17
16
|
onChunk(listener: (response: oResponse) => void): void;
|
|
18
17
|
validate(dto?: any): void;
|
|
19
18
|
createRequest(method: string, params: ConnectionSendParams): oRequest;
|
|
20
|
-
abstract transmit(request: oRequest): Promise<
|
|
21
|
-
send(data: ConnectionSendParams): Promise<
|
|
19
|
+
abstract transmit(request: oRequest, options: any): Promise<any>;
|
|
20
|
+
send(data: ConnectionSendParams, options: any): Promise<any>;
|
|
22
21
|
close(): Promise<void>;
|
|
23
22
|
}
|
|
24
23
|
//# sourceMappingURL=o-connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AAExF,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,8BAAsB,WAAY,SAAQ,OAAO;IAInC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IAHxD,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAsB;gBAE/B,MAAM,EAAE,iBAAiB;IAaxD,IAAI,
|
|
1
|
+
{"version":3,"file":"o-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAA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
16
|
-
']
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
get abortSignal() {
|
|
20
|
-
return this.config.abortSignal;
|
|
15
|
+
config.nextHopAddress.value +
|
|
16
|
+
']' +
|
|
17
|
+
`-->[Target:${config.targetAddress.value}]`);
|
|
21
18
|
}
|
|
22
19
|
get address() {
|
|
23
|
-
return this.config.
|
|
20
|
+
return this.config.targetAddress;
|
|
24
21
|
}
|
|
25
22
|
get nextHopAddress() {
|
|
26
23
|
return this.config.nextHopAddress;
|
|
@@ -49,10 +46,10 @@ export class oConnection extends oObject {
|
|
|
49
46
|
id: params.id || uuidv4(),
|
|
50
47
|
});
|
|
51
48
|
}
|
|
52
|
-
async send(data) {
|
|
49
|
+
async send(data, options) {
|
|
53
50
|
// proxy through the router tool
|
|
54
51
|
const request = this.createRequest(oProtocolMethods.ROUTE, data);
|
|
55
|
-
return this.transmit(request);
|
|
52
|
+
return await this.transmit(request, options);
|
|
56
53
|
}
|
|
57
54
|
async close() {
|
|
58
55
|
this.logger.debug('Closing connection...');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-data.config.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/use-data.config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import { oConnectionManager } from '../../connection/o-connection-manager.js';
|
|
1
2
|
import { oRequest } from '../../connection/o-request.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { oResponse } from '../../connection/o-response.js';
|
|
4
|
+
import { oAddress } from '../../router/o-address.js';
|
|
5
|
+
import { oRouter } from '../../router/o-router.js';
|
|
6
|
+
import { UseDataConfig } from '../interfaces/use-data.config.js';
|
|
7
|
+
import { UseOptions } from '../interfaces/use-options.interface.js';
|
|
8
|
+
import { oObject } from '../o-object.js';
|
|
9
|
+
export declare abstract class oRequestManager extends oObject {
|
|
10
|
+
protected requests: oRequest[];
|
|
11
|
+
abstract connectionManager?: oConnectionManager;
|
|
12
|
+
abstract router?: oRouter;
|
|
13
|
+
abstract send(address: oAddress, data?: UseDataConfig, options?: UseOptions, node?: any): Promise<oResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Helper method to handle response errors
|
|
16
|
+
* @param response The response to check for errors
|
|
17
|
+
* @throws oError if the response contains an error
|
|
18
|
+
*/
|
|
19
|
+
protected handleResponseError(response: oResponse): void;
|
|
20
|
+
protected addRequest(request: oRequest): void;
|
|
21
|
+
protected removeRequest(request: oRequest): void;
|
|
7
22
|
getRequest(id: string): oRequest | undefined;
|
|
8
23
|
get activeRequests(): oRequest[];
|
|
9
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-request.manager.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/o-request.manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"o-request.manager.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/o-request.manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,8BAAsB,eAAgB,SAAQ,OAAO;IACnD,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAM;IACpC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAE1B,QAAQ,CAAC,IAAI,CACX,OAAO,EAAE,QAAQ,EACjB,IAAI,CAAC,EAAE,aAAa,EACpB,OAAO,CAAC,EAAE,UAAU,EACpB,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,SAAS,CAAC;IAErB;;;;OAIG;IACH,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,SAAS,GAAG,IAAI;IAMxD,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI;IAI7C,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI;IAIhD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI5C,IAAI,cAAc,IAAI,QAAQ,EAAE,CAE/B;CACF"}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { RequestState } from '../../connection/interfaces/request-state.enum.js';
|
|
2
|
-
|
|
2
|
+
import { oError } from '../../error/o-error.js';
|
|
3
|
+
import { oObject } from '../o-object.js';
|
|
4
|
+
export class oRequestManager extends oObject {
|
|
3
5
|
constructor() {
|
|
6
|
+
super(...arguments);
|
|
4
7
|
this.requests = [];
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Helper method to handle response errors
|
|
11
|
+
* @param response The response to check for errors
|
|
12
|
+
* @throws oError if the response contains an error
|
|
13
|
+
*/
|
|
14
|
+
handleResponseError(response) {
|
|
15
|
+
if (response.result.error) {
|
|
16
|
+
throw oError.fromJSON(response.result.error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
6
19
|
addRequest(request) {
|
|
7
20
|
this.requests.push(request);
|
|
8
21
|
}
|
|
@@ -4,7 +4,6 @@ import { oAddress } from '../router/o-address.js';
|
|
|
4
4
|
import { NodeType } from './interfaces/node-type.enum.js';
|
|
5
5
|
import { oConnectionManager } from '../connection/o-connection-manager.js';
|
|
6
6
|
import { oResponse } from '../connection/o-response.js';
|
|
7
|
-
import { oConnection } from '../connection/o-connection.js';
|
|
8
7
|
import { oMethod } from '@olane/o-protocol';
|
|
9
8
|
import { oDependency } from './o-dependency.js';
|
|
10
9
|
import { oObject } from './o-object.js';
|
|
@@ -16,9 +15,9 @@ import { oRouter } from '../router/o-router.js';
|
|
|
16
15
|
import { oRequest } from '../connection/o-request.js';
|
|
17
16
|
import { oNotificationManager } from './lib/o-notification.manager.js';
|
|
18
17
|
import { oNotificationEvent, EventFilter, NotificationHandler, Subscription } from './lib/events/index.js';
|
|
19
|
-
import { oConnectionConfig } from '../connection/index.js';
|
|
20
18
|
import { UseOptions } from './interfaces/use-options.interface.js';
|
|
21
19
|
import { UseStreamOptions } from './interfaces/use-stream-options.interface.js';
|
|
20
|
+
import { UseDataConfig } from './interfaces/use-data.config.js';
|
|
22
21
|
export declare abstract class oCore extends oObject {
|
|
23
22
|
readonly config: oCoreConfig;
|
|
24
23
|
address: oAddress;
|
|
@@ -27,7 +26,7 @@ export declare abstract class oCore extends oObject {
|
|
|
27
26
|
connectionManager: oConnectionManager;
|
|
28
27
|
hierarchyManager: oHierarchyManager;
|
|
29
28
|
metrics: oMetrics;
|
|
30
|
-
requestManager
|
|
29
|
+
requestManager?: oRequestManager;
|
|
31
30
|
router: oRouter;
|
|
32
31
|
notificationManager: oNotificationManager;
|
|
33
32
|
private heartbeatInterval?;
|
|
@@ -35,20 +34,8 @@ export declare abstract class oCore extends oObject {
|
|
|
35
34
|
get isLeader(): boolean;
|
|
36
35
|
get leader(): oAddress | null;
|
|
37
36
|
abstract configureTransports(): any[];
|
|
38
|
-
useStream(address: oAddress, data:
|
|
39
|
-
|
|
40
|
-
params?: {
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
};
|
|
43
|
-
id?: string;
|
|
44
|
-
}, options: UseStreamOptions): Promise<oResponse>;
|
|
45
|
-
useDirect(address: oAddress, data?: {
|
|
46
|
-
method?: string;
|
|
47
|
-
params?: {
|
|
48
|
-
[key: string]: any;
|
|
49
|
-
};
|
|
50
|
-
id?: string;
|
|
51
|
-
}): Promise<oResponse>;
|
|
37
|
+
useStream(address: oAddress, data: UseDataConfig, options: UseStreamOptions): Promise<oResponse>;
|
|
38
|
+
useDirect(address: oAddress, data?: UseDataConfig): Promise<oResponse>;
|
|
52
39
|
/**
|
|
53
40
|
* Sends a request to a remote node in the O-Lane network using the specified address and optional data payload.
|
|
54
41
|
*
|
|
@@ -102,20 +89,8 @@ export declare abstract class oCore extends oObject {
|
|
|
102
89
|
* }
|
|
103
90
|
* ```
|
|
104
91
|
*/
|
|
105
|
-
use(address: oAddress, data?:
|
|
106
|
-
method?: string;
|
|
107
|
-
params?: {
|
|
108
|
-
[key: string]: any;
|
|
109
|
-
};
|
|
110
|
-
id?: string;
|
|
111
|
-
}, options?: UseOptions): Promise<oResponse>;
|
|
92
|
+
use(address: oAddress, data?: UseDataConfig, options?: UseOptions): Promise<oResponse>;
|
|
112
93
|
abstract execute(request: oRequest): Promise<any>;
|
|
113
|
-
/**
|
|
114
|
-
* Helper method to handle response errors
|
|
115
|
-
* @param response The response to check for errors
|
|
116
|
-
* @throws oError if the response contains an error
|
|
117
|
-
*/
|
|
118
|
-
private handleResponseError;
|
|
119
94
|
/**
|
|
120
95
|
* Helper method to validate node is running
|
|
121
96
|
* @throws Error if node is not running
|
|
@@ -133,19 +108,9 @@ export declare abstract class oCore extends oObject {
|
|
|
133
108
|
[key: string]: any;
|
|
134
109
|
};
|
|
135
110
|
}): Promise<any>;
|
|
136
|
-
useChild(childAddress: oAddress, data?:
|
|
137
|
-
method?: string;
|
|
138
|
-
params?: {
|
|
139
|
-
[key: string]: any;
|
|
140
|
-
};
|
|
141
|
-
id?: string;
|
|
142
|
-
}, options?: {
|
|
143
|
-
isStream?: boolean;
|
|
144
|
-
onChunk?: (chunk: oResponse) => void;
|
|
145
|
-
}): Promise<oResponse>;
|
|
111
|
+
useChild(childAddress: oAddress, data?: UseDataConfig, options?: UseOptions): Promise<oResponse>;
|
|
146
112
|
addChildNode(node: oCore): void;
|
|
147
113
|
removeChildNode(node: oCore): void;
|
|
148
|
-
abstract connect(config: oConnectionConfig): Promise<oConnection>;
|
|
149
114
|
abstract initializeRouter(): void;
|
|
150
115
|
abstract unregister(): Promise<void>;
|
|
151
116
|
abstract register(): Promise<void>;
|
|
@@ -234,6 +199,7 @@ export declare abstract class oCore extends oObject {
|
|
|
234
199
|
*/
|
|
235
200
|
stop(): Promise<void>;
|
|
236
201
|
teardown(): Promise<void>;
|
|
202
|
+
abstract initRequestManager(): void;
|
|
237
203
|
/**
|
|
238
204
|
* Reset node state to allow restart after stop
|
|
239
205
|
* Called at the end of teardown()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-core.d.ts","sourceRoot":"","sources":["../../../src/core/o-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"o-core.d.ts","sourceRoot":"","sources":["../../../src/core/o-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,SAAS,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AAW,EAAE,CAEhC;IAED;;;OAGG;IACH,OAAO,CAAC,cAAc;IA0CtB,IAAI,OAAO,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAExC;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,aAAa,IAAI,QAAQ,CAE5B;IAED,IAAI,IAAI,IAAI,QAAQ,CAEnB;IAED,IAAI,UAAU,IAAI,UAAU,EAAE,CAE7B;IAED,IAAI,MAAM,IAAI,QAAQ,GAAG,IAAI,CAE5B;IAED,IAAI,gBAAgB,IAAI,UAAU,EAAE,CAEnC;IAEK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;CAQ7B"}
|
package/dist/src/core/o-core.js
CHANGED
|
@@ -2,10 +2,8 @@ import { NodeState } from './interfaces/state.enum.js';
|
|
|
2
2
|
import { oAddress } from '../router/o-address.js';
|
|
3
3
|
import { NodeType } from './interfaces/node-type.enum.js';
|
|
4
4
|
import { oDependency } from './o-dependency.js';
|
|
5
|
-
import { oError } from '../error/o-error.js';
|
|
6
5
|
import { oObject } from './o-object.js';
|
|
7
6
|
import { oMetrics } from './lib/o-metrics.js';
|
|
8
|
-
import { oRequestManager } from './lib/o-request.manager.js';
|
|
9
7
|
import { oRequest } from '../connection/o-request.js';
|
|
10
8
|
import { ResponseBuilder } from '../response/response-builder.js';
|
|
11
9
|
export class oCore extends oObject {
|
|
@@ -15,7 +13,6 @@ export class oCore extends oObject {
|
|
|
15
13
|
this.state = NodeState.STOPPED;
|
|
16
14
|
this.errors = [];
|
|
17
15
|
this.metrics = new oMetrics();
|
|
18
|
-
this.requestManager = new oRequestManager();
|
|
19
16
|
// Validate that initial address is not nested
|
|
20
17
|
// Nested addresses should only be created at runtime during registration
|
|
21
18
|
if (config.address && !config._allowNestedAddress) {
|
|
@@ -99,61 +96,13 @@ export class oCore extends oObject {
|
|
|
99
96
|
*/
|
|
100
97
|
async use(address, data, options) {
|
|
101
98
|
this.validateRunning();
|
|
102
|
-
if (!
|
|
103
|
-
throw new Error('
|
|
99
|
+
if (!this.requestManager) {
|
|
100
|
+
throw new Error('Request manager is not initialized');
|
|
104
101
|
}
|
|
105
|
-
this.
|
|
106
|
-
// check for static match
|
|
107
|
-
if (address.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
102
|
+
if (address?.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
108
103
|
return this.useSelf(data);
|
|
109
104
|
}
|
|
110
|
-
|
|
111
|
-
if (options?.noRouting) {
|
|
112
|
-
this.logger.debug('No routing requested, using address as is', address.toString());
|
|
113
|
-
}
|
|
114
|
-
const { nextHopAddress, targetAddress } = options?.noRouting
|
|
115
|
-
? { nextHopAddress: address, targetAddress: address }
|
|
116
|
-
: await this.router.translate(address, this);
|
|
117
|
-
if (nextHopAddress?.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
118
|
-
return this.useSelf(data);
|
|
119
|
-
}
|
|
120
|
-
const connection = await this.connect({
|
|
121
|
-
nextHopAddress: nextHopAddress,
|
|
122
|
-
address: targetAddress,
|
|
123
|
-
callerAddress: this.address,
|
|
124
|
-
readTimeoutMs: options?.readTimeoutMs,
|
|
125
|
-
drainTimeoutMs: options?.drainTimeoutMs,
|
|
126
|
-
isStream: options?.isStream,
|
|
127
|
-
abortSignal: options?.abortSignal,
|
|
128
|
-
});
|
|
129
|
-
if (options?.isStream) {
|
|
130
|
-
connection.onChunk((response) => {
|
|
131
|
-
options.onChunk?.(response);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
// communicate the payload to the target node
|
|
135
|
-
const response = await connection.send({
|
|
136
|
-
address: targetAddress?.toString() || '',
|
|
137
|
-
payload: data || {},
|
|
138
|
-
id: data?.id,
|
|
139
|
-
});
|
|
140
|
-
// we handle streaming response differently
|
|
141
|
-
if (options?.isStream) {
|
|
142
|
-
return response;
|
|
143
|
-
}
|
|
144
|
-
// if there is an error, throw it to continue to bubble up
|
|
145
|
-
this.handleResponseError(response);
|
|
146
|
-
return response;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Helper method to handle response errors
|
|
150
|
-
* @param response The response to check for errors
|
|
151
|
-
* @throws oError if the response contains an error
|
|
152
|
-
*/
|
|
153
|
-
handleResponseError(response) {
|
|
154
|
-
if (response.result.error) {
|
|
155
|
-
throw oError.fromJSON(response.result.error);
|
|
156
|
-
}
|
|
105
|
+
return this.requestManager.send(address, data, options, this);
|
|
157
106
|
}
|
|
158
107
|
/**
|
|
159
108
|
* Helper method to validate node is running
|
|
@@ -198,6 +147,10 @@ export class oCore extends oObject {
|
|
|
198
147
|
}
|
|
199
148
|
async useChild(childAddress, data, options) {
|
|
200
149
|
this.validateRunning();
|
|
150
|
+
if (!this.requestManager) {
|
|
151
|
+
throw new Error('Request manager is not initialized');
|
|
152
|
+
}
|
|
153
|
+
// extract child address with transports
|
|
201
154
|
if (!childAddress.transports) {
|
|
202
155
|
const child = this.hierarchyManager.getChild(childAddress);
|
|
203
156
|
if (!child) {
|
|
@@ -208,26 +161,7 @@ export class oCore extends oObject {
|
|
|
208
161
|
childAddress.setTransports(child?.transports || []);
|
|
209
162
|
}
|
|
210
163
|
}
|
|
211
|
-
|
|
212
|
-
nextHopAddress: childAddress,
|
|
213
|
-
address: childAddress,
|
|
214
|
-
callerAddress: this.address,
|
|
215
|
-
isStream: options?.isStream,
|
|
216
|
-
});
|
|
217
|
-
if (options?.isStream) {
|
|
218
|
-
connection.onChunk((response) => {
|
|
219
|
-
options.onChunk?.(response);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
// communicate the payload to the target node
|
|
223
|
-
const response = await connection.send({
|
|
224
|
-
address: childAddress?.toString() || '',
|
|
225
|
-
payload: data || {},
|
|
226
|
-
id: data?.id,
|
|
227
|
-
});
|
|
228
|
-
// if there is an error, throw it to continue to bubble up
|
|
229
|
-
this.handleResponseError(response);
|
|
230
|
-
return response;
|
|
164
|
+
return this.requestManager.send(childAddress, data, options, this);
|
|
231
165
|
}
|
|
232
166
|
// hierarchy
|
|
233
167
|
addChildNode(node) {
|
|
@@ -254,7 +188,9 @@ export class oCore extends oObject {
|
|
|
254
188
|
return this.notificationManager.on(eventType, handler, filter);
|
|
255
189
|
}
|
|
256
190
|
// initialize
|
|
257
|
-
async initialize() {
|
|
191
|
+
async initialize() {
|
|
192
|
+
this.initializeRouter();
|
|
193
|
+
}
|
|
258
194
|
get isRunning() {
|
|
259
195
|
return (this.state === NodeState.RUNNING ||
|
|
260
196
|
this.state === NodeState.STOPPING ||
|
|
@@ -404,7 +340,6 @@ export class oCore extends oObject {
|
|
|
404
340
|
// Reset state tracking
|
|
405
341
|
this.errors = [];
|
|
406
342
|
this.metrics = new oMetrics();
|
|
407
|
-
this.requestManager = new oRequestManager();
|
|
408
343
|
// Clear heartbeat
|
|
409
344
|
if (this.heartbeatInterval) {
|
|
410
345
|
clearInterval(this.heartbeatInterval);
|
|
@@ -431,7 +366,7 @@ export class oCore extends oObject {
|
|
|
431
366
|
const metrics = {
|
|
432
367
|
successCount: this.metrics.successCount,
|
|
433
368
|
errorCount: this.metrics.errorCount,
|
|
434
|
-
activeRequests: this.requestManager
|
|
369
|
+
activeRequests: this.requestManager?.activeRequests?.length || 0,
|
|
435
370
|
state: this.state,
|
|
436
371
|
};
|
|
437
372
|
// Add stream count if available (oNode instances have this method)
|
|
@@ -16,6 +16,8 @@ export declare enum oErrorCodes {
|
|
|
16
16
|
INVALID_CAPABILITY = 1015,
|
|
17
17
|
CONNECTION_LIMIT_REACHED = 1016,
|
|
18
18
|
TIMEOUT = 1017,
|
|
19
|
-
INTERNAL_ERROR = 1018
|
|
19
|
+
INTERNAL_ERROR = 1018,
|
|
20
|
+
SEND_FAILED = 1019,
|
|
21
|
+
RECEIVE_FAILED = 1020
|
|
20
22
|
}
|
|
21
23
|
//# sourceMappingURL=codes.error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codes.error.d.ts","sourceRoot":"","sources":["../../../../src/error/enums/codes.error.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,OAAO,OAAO;IACd,SAAS,OAAO;IAChB,eAAe,OAAO;IACtB,cAAc,OAAO;IACrB,cAAc,OAAO;IACrB,kBAAkB,OAAO;IACzB,kBAAkB,OAAO;IACzB,gBAAgB,OAAO;IACvB,eAAe,OAAO;IACtB,aAAa,OAAO;IACpB,cAAc,OAAO;IACrB,mBAAmB,OAAO;IAC1B,uBAAuB,OAAO;IAC9B,qBAAqB,OAAO;IAC5B,kBAAkB,OAAO;IACzB,wBAAwB,OAAO;IAC/B,OAAO,OAAO;IACd,cAAc,OAAO;CACtB"}
|
|
1
|
+
{"version":3,"file":"codes.error.d.ts","sourceRoot":"","sources":["../../../../src/error/enums/codes.error.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,OAAO,OAAO;IACd,SAAS,OAAO;IAChB,eAAe,OAAO;IACtB,cAAc,OAAO;IACrB,cAAc,OAAO;IACrB,kBAAkB,OAAO;IACzB,kBAAkB,OAAO;IACzB,gBAAgB,OAAO;IACvB,eAAe,OAAO;IACtB,aAAa,OAAO;IACpB,cAAc,OAAO;IACrB,mBAAmB,OAAO;IAC1B,uBAAuB,OAAO;IAC9B,qBAAqB,OAAO;IAC5B,kBAAkB,OAAO;IACzB,wBAAwB,OAAO;IAC/B,OAAO,OAAO;IACd,cAAc,OAAO;IACrB,WAAW,OAAO;IAClB,cAAc,OAAO;CACtB"}
|
|
@@ -18,4 +18,6 @@ export var oErrorCodes;
|
|
|
18
18
|
oErrorCodes[oErrorCodes["CONNECTION_LIMIT_REACHED"] = 1016] = "CONNECTION_LIMIT_REACHED";
|
|
19
19
|
oErrorCodes[oErrorCodes["TIMEOUT"] = 1017] = "TIMEOUT";
|
|
20
20
|
oErrorCodes[oErrorCodes["INTERNAL_ERROR"] = 1018] = "INTERNAL_ERROR";
|
|
21
|
+
oErrorCodes[oErrorCodes["SEND_FAILED"] = 1019] = "SEND_FAILED";
|
|
22
|
+
oErrorCodes[oErrorCodes["RECEIVE_FAILED"] = 1020] = "RECEIVE_FAILED";
|
|
21
23
|
})(oErrorCodes || (oErrorCodes = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.56",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"typescript": "^5.8.3"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@olane/o-protocol": "0.7.
|
|
66
|
+
"@olane/o-protocol": "0.7.56",
|
|
67
67
|
"chalk": "^5.4.1",
|
|
68
68
|
"debug": "^4.4.1",
|
|
69
69
|
"dotenv": "^16.5.0",
|
|
70
70
|
"multiformats": "^13.3.7",
|
|
71
71
|
"stream-json": "^1.9.1"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "f1dadd9c39f33d1279345546df8e1bf63481e5e1"
|
|
74
74
|
}
|