@olane/o-core 0.7.12-alpha.9 → 0.7.12
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 +12 -0
- 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 -0
- package/dist/src/connection/interfaces/connection-send-params.interface.d.ts.map +1 -1
- package/dist/src/connection/interfaces/connection.config.d.ts +21 -0
- package/dist/src/connection/interfaces/connection.config.d.ts.map +1 -1
- package/dist/src/connection/o-connection-manager.d.ts +0 -1
- package/dist/src/connection/o-connection-manager.d.ts.map +1 -1
- package/dist/src/connection/o-connection-manager.js +1 -15
- package/dist/src/connection/o-connection.d.ts +5 -1
- package/dist/src/connection/o-connection.d.ts.map +1 -1
- package/dist/src/connection/o-connection.js +11 -3
- package/dist/src/connection/o-response.d.ts +1 -0
- package/dist/src/connection/o-response.d.ts.map +1 -1
- package/dist/src/connection/o-response.js +8 -0
- package/dist/src/core/defaults/config.js +2 -2
- package/dist/src/core/interfaces/index.d.ts +3 -0
- package/dist/src/core/interfaces/index.d.ts.map +1 -1
- package/dist/src/core/interfaces/index.js +3 -0
- package/dist/src/core/interfaces/use-options.interface.d.ts +10 -0
- package/dist/src/core/interfaces/use-options.interface.d.ts.map +1 -0
- package/dist/src/core/interfaces/use-options.interface.js +1 -0
- package/dist/src/core/interfaces/use-stream-options.interface.d.ts +4 -0
- package/dist/src/core/interfaces/use-stream-options.interface.d.ts.map +1 -0
- package/dist/src/core/interfaces/use-stream-options.interface.js +1 -0
- package/dist/src/core/lib/o-notification.manager.js +2 -2
- package/dist/src/core/o-core.d.ts +34 -2
- package/dist/src/core/o-core.d.ts.map +1 -1
- package/dist/src/core/o-core.js +96 -43
- package/dist/src/error/enums/codes.error.d.ts +2 -1
- package/dist/src/error/enums/codes.error.d.ts.map +1 -1
- package/dist/src/error/enums/codes.error.js +1 -0
- package/dist/src/error/o-error.d.ts.map +1 -1
- package/dist/src/error/o-error.js +8 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/response/index.d.ts +2 -0
- package/dist/src/response/index.d.ts.map +1 -0
- package/dist/src/response/index.js +1 -0
- package/dist/src/response/response-builder.d.ts +140 -0
- package/dist/src/response/response-builder.d.ts.map +1 -0
- package/dist/src/response/response-builder.js +190 -0
- package/dist/src/utils/core.utils.d.ts +19 -4
- package/dist/src/utils/core.utils.d.ts.map +1 -1
- package/dist/src/utils/core.utils.js +51 -19
- package/dist/src/utils/logger.d.ts +2 -0
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/logger.js +7 -2
- package/dist/src/utils/streaming.utils.d.ts +22 -0
- package/dist/src/utils/streaming.utils.d.ts.map +1 -0
- package/dist/src/utils/streaming.utils.js +45 -0
- package/package.json +14 -5
- package/dist/src/router/o-address-resolution.d.ts +0 -12
- package/dist/src/router/o-address-resolution.d.ts.map +0 -1
- package/dist/src/router/o-address-resolution.js +0 -42
|
@@ -1,3 +1,15 @@
|
|
|
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;
|
|
2
14
|
}
|
|
3
15
|
//# 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;IACvC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -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,OAAO,CAAC;KACxB,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;
|
|
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,OAAO,CAAC;KACxB,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -1,7 +1,28 @@
|
|
|
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';
|
|
2
5
|
export interface oConnectionConfig {
|
|
3
6
|
nextHopAddress: oAddress;
|
|
4
7
|
callerAddress?: oAddress;
|
|
5
8
|
address: oAddress;
|
|
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;
|
|
19
|
+
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>;
|
|
6
27
|
}
|
|
7
28
|
//# 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;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,QAAQ,CAAC;IACzB,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;CAC5E"}
|
|
@@ -5,7 +5,6 @@ import { oObject } from '../core/o-object.js';
|
|
|
5
5
|
import { oConnectionConfig } from './interfaces/connection.config.js';
|
|
6
6
|
export declare abstract class oConnectionManager extends oObject {
|
|
7
7
|
readonly config: oConnectionManagerConfig;
|
|
8
|
-
protected cache: Map<string, oConnection>;
|
|
9
8
|
constructor(config: oConnectionManagerConfig);
|
|
10
9
|
/**
|
|
11
10
|
* Connect to a given address
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-connection-manager.d.ts","sourceRoot":"","sources":["../../../src/connection/o-connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,8BAAsB,kBAAmB,SAAQ,OAAO;
|
|
1
|
+
{"version":3,"file":"o-connection-manager.d.ts","sourceRoot":"","sources":["../../../src/connection/o-connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,8BAAsB,kBAAmB,SAAQ,OAAO;IAC1C,QAAQ,CAAC,MAAM,EAAE,wBAAwB;gBAAhC,MAAM,EAAE,wBAAwB;IAIrD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAEjE,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAG3D"}
|
|
@@ -3,25 +3,11 @@ export class oConnectionManager extends oObject {
|
|
|
3
3
|
constructor(config) {
|
|
4
4
|
super();
|
|
5
5
|
this.config = config;
|
|
6
|
-
this.cache = new Map();
|
|
7
6
|
}
|
|
8
7
|
isCached(address) {
|
|
9
|
-
return
|
|
8
|
+
return false;
|
|
10
9
|
}
|
|
11
10
|
getCachedConnection(address) {
|
|
12
|
-
const key = address.toString();
|
|
13
|
-
try {
|
|
14
|
-
const connection = this.cache.get(key);
|
|
15
|
-
if (!connection) {
|
|
16
|
-
throw new Error('Connection not found in cache');
|
|
17
|
-
}
|
|
18
|
-
connection.validate();
|
|
19
|
-
return connection;
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
this.cache.delete(key);
|
|
23
|
-
this.logger.error('Error getting cached connection:', error);
|
|
24
|
-
}
|
|
25
11
|
return null;
|
|
26
12
|
}
|
|
27
13
|
}
|
|
@@ -4,14 +4,18 @@ import { oResponse } from './o-response.js';
|
|
|
4
4
|
import { ConnectionSendParams } from './interfaces/connection-send-params.interface.js';
|
|
5
5
|
import { oObject } from '../core/o-object.js';
|
|
6
6
|
import { oConnectionConfig } from './interfaces/connection.config.js';
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
7
8
|
export declare abstract class oConnection extends oObject {
|
|
8
9
|
protected readonly config: oConnectionConfig;
|
|
9
10
|
readonly id: string;
|
|
10
11
|
readonly address: oAddress;
|
|
11
12
|
readonly nextHopAddress: oAddress;
|
|
12
13
|
readonly callerAddress: oAddress | undefined;
|
|
14
|
+
protected readonly emitter: EventEmitter;
|
|
13
15
|
constructor(config: oConnectionConfig);
|
|
14
|
-
|
|
16
|
+
get abortSignal(): AbortSignal | undefined;
|
|
17
|
+
onChunk(listener: (response: oResponse) => void): void;
|
|
18
|
+
validate(dto?: any): void;
|
|
15
19
|
createRequest(method: string, params: ConnectionSendParams): oRequest;
|
|
16
20
|
abstract transmit(request: oRequest): Promise<oResponse>;
|
|
17
21
|
send(data: ConnectionSendParams): Promise<oResponse>;
|
|
@@ -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;
|
|
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;IAOnC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IANxD,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,OAAO,EAAE,QAAQ,CAAC;IAClC,SAAgB,cAAc,EAAE,QAAQ,CAAC;IACzC,SAAgB,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAsB;gBAE/B,MAAM,EAAE,iBAAiB;IAgBxD,IAAI,WAAW,IAAI,WAAW,GAAG,SAAS,CAEzC;IAED,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI;IAI/C,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI;IAMzB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,QAAQ;IAcrE,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAElD,IAAI,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC;IAMpD,KAAK;CAGZ"}
|
|
@@ -2,10 +2,12 @@ import { oRequest } from './o-request.js';
|
|
|
2
2
|
import { oProtocolMethods } from '@olane/o-protocol';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
import { oObject } from '../core/o-object.js';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
5
6
|
export class oConnection extends oObject {
|
|
6
7
|
constructor(config) {
|
|
7
8
|
super();
|
|
8
9
|
this.config = config;
|
|
10
|
+
this.emitter = new EventEmitter();
|
|
9
11
|
this.id = uuidv4();
|
|
10
12
|
this.address = config.address;
|
|
11
13
|
this.nextHopAddress = config.nextHopAddress;
|
|
@@ -17,7 +19,13 @@ export class oConnection extends oObject {
|
|
|
17
19
|
']:' +
|
|
18
20
|
this.id);
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
get abortSignal() {
|
|
23
|
+
return this.config.abortSignal;
|
|
24
|
+
}
|
|
25
|
+
onChunk(listener) {
|
|
26
|
+
this.emitter.addListener('chunk', listener);
|
|
27
|
+
}
|
|
28
|
+
validate(dto) {
|
|
21
29
|
if (!this.address || !this.nextHopAddress || !this.callerAddress) {
|
|
22
30
|
throw new Error('Connection configuration is invalid');
|
|
23
31
|
}
|
|
@@ -29,6 +37,7 @@ export class oConnection extends oObject {
|
|
|
29
37
|
_connectionId: this.id,
|
|
30
38
|
_requestMethod: method,
|
|
31
39
|
_callerAddress: this.callerAddress?.value,
|
|
40
|
+
_isStreaming: this.config.isStream ?? false,
|
|
32
41
|
...params,
|
|
33
42
|
},
|
|
34
43
|
id: params.id || uuidv4(),
|
|
@@ -37,8 +46,7 @@ export class oConnection extends oObject {
|
|
|
37
46
|
async send(data) {
|
|
38
47
|
// proxy through the router tool
|
|
39
48
|
const request = this.createRequest(oProtocolMethods.ROUTE, data);
|
|
40
|
-
|
|
41
|
-
return result;
|
|
49
|
+
return this.transmit(request);
|
|
42
50
|
}
|
|
43
51
|
async close() {
|
|
44
52
|
this.logger.debug('Closing connection...');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-response.d.ts","sourceRoot":"","sources":["../../../src/connection/o-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,IAAI,QAAQ,EACrB,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,SAAU,YAAW,QAAQ;IACxC,OAAO,EAAE,OAAO,eAAe,CAAC;IAChC,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE;IAM9C,MAAM,IAAI,GAAG;IAQb,QAAQ,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"o-response.d.ts","sourceRoot":"","sources":["../../../src/connection/o-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,IAAI,QAAQ,EACrB,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,SAAU,YAAW,QAAQ;IACxC,OAAO,EAAE,OAAO,eAAe,CAAC;IAChC,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE;IAM9C,MAAM,IAAI,GAAG;IAQb,QAAQ,IAAI,MAAM;IAIlB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,SAAS;CAQtC"}
|
|
@@ -15,4 +15,12 @@ export class oResponse {
|
|
|
15
15
|
toString() {
|
|
16
16
|
return JSON.stringify(this);
|
|
17
17
|
}
|
|
18
|
+
static fromJSON(json) {
|
|
19
|
+
return new oResponse({
|
|
20
|
+
...json.result,
|
|
21
|
+
id: json.id, // Preserve request ID for proper request/response correlation
|
|
22
|
+
_connectionId: json.result?._connectionId,
|
|
23
|
+
_requestMethod: json.result?._requestMethod,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
18
26
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import os from 'os';
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as os from 'os';
|
|
3
3
|
export const DEFAULT_CONFIG_PATH = path.join(os.homedir(), '.olane');
|
|
4
4
|
export const DEFAULT_INSTANCE_PATH = path.join(DEFAULT_CONFIG_PATH, 'os-instances');
|
|
5
5
|
export const DEFAULT_CONFIG_FILE = path.join(DEFAULT_CONFIG_PATH, 'config.json');
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './o-core.config.js';
|
|
2
2
|
export * from './node-type.enum.js';
|
|
3
3
|
export * from './state.enum.js';
|
|
4
|
+
export * from './use-options.interface.js';
|
|
5
|
+
export * from './o-core.interface.js';
|
|
6
|
+
export * from './use-stream-options.interface.js';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { oResponse } from '../../connection/o-response.js';
|
|
2
|
+
export interface UseOptions {
|
|
3
|
+
readTimeoutMs?: number;
|
|
4
|
+
drainTimeoutMs?: number;
|
|
5
|
+
isStream?: boolean;
|
|
6
|
+
onChunk?: (chunk: oResponse) => void;
|
|
7
|
+
noRouting?: boolean;
|
|
8
|
+
abortSignal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=use-options.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/use-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-stream-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/use-stream-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -79,13 +79,13 @@ export class oNotificationManager extends oObject {
|
|
|
79
79
|
if (subscriptionsForType.size === 0) {
|
|
80
80
|
this.subscriptions.delete(subscription.eventType);
|
|
81
81
|
}
|
|
82
|
-
this.logger.
|
|
82
|
+
this.logger.verbose(`Unsubscribed from ${subscription.eventType} with ID ${subscription.id}`);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Emit a notification event
|
|
86
86
|
*/
|
|
87
87
|
emit(event) {
|
|
88
|
-
this.logger.
|
|
88
|
+
this.logger.verbose(`Emitting event: ${event.type}`, event.toJSON());
|
|
89
89
|
const customEvent = new CustomEvent(event.type, {
|
|
90
90
|
detail: event,
|
|
91
91
|
});
|
|
@@ -16,6 +16,9 @@ import { oRouter } from '../router/o-router.js';
|
|
|
16
16
|
import { oRequest } from '../connection/o-request.js';
|
|
17
17
|
import { oNotificationManager } from './lib/o-notification.manager.js';
|
|
18
18
|
import { oNotificationEvent, EventFilter, NotificationHandler, Subscription } from './lib/events/index.js';
|
|
19
|
+
import { oConnectionConfig } from '../connection/index.js';
|
|
20
|
+
import { UseOptions } from './interfaces/use-options.interface.js';
|
|
21
|
+
import { UseStreamOptions } from './interfaces/use-stream-options.interface.js';
|
|
19
22
|
export declare abstract class oCore extends oObject {
|
|
20
23
|
readonly config: oCoreConfig;
|
|
21
24
|
address: oAddress;
|
|
@@ -32,6 +35,20 @@ export declare abstract class oCore extends oObject {
|
|
|
32
35
|
get isLeader(): boolean;
|
|
33
36
|
get leader(): oAddress | null;
|
|
34
37
|
abstract configureTransports(): any[];
|
|
38
|
+
useStream(address: oAddress, data: {
|
|
39
|
+
method?: string;
|
|
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>;
|
|
35
52
|
/**
|
|
36
53
|
* Sends a request to a remote node in the O-Lane network using the specified address and optional data payload.
|
|
37
54
|
*
|
|
@@ -91,8 +108,19 @@ export declare abstract class oCore extends oObject {
|
|
|
91
108
|
[key: string]: any;
|
|
92
109
|
};
|
|
93
110
|
id?: string;
|
|
94
|
-
}): Promise<oResponse>;
|
|
111
|
+
}, options?: UseOptions): Promise<oResponse>;
|
|
95
112
|
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
|
+
/**
|
|
120
|
+
* Helper method to validate node is running
|
|
121
|
+
* @throws Error if node is not running
|
|
122
|
+
*/
|
|
123
|
+
private validateRunning;
|
|
96
124
|
useSelf(data?: {
|
|
97
125
|
method?: string;
|
|
98
126
|
params?: {
|
|
@@ -106,10 +134,13 @@ export declare abstract class oCore extends oObject {
|
|
|
106
134
|
[key: string]: any;
|
|
107
135
|
};
|
|
108
136
|
id?: string;
|
|
137
|
+
}, options?: {
|
|
138
|
+
isStream?: boolean;
|
|
139
|
+
onChunk?: (chunk: oResponse) => void;
|
|
109
140
|
}): Promise<oResponse>;
|
|
110
141
|
addChildNode(node: oCore): void;
|
|
111
142
|
removeChildNode(node: oCore): void;
|
|
112
|
-
abstract connect(
|
|
143
|
+
abstract connect(config: oConnectionConfig): Promise<oConnection>;
|
|
113
144
|
abstract initializeRouter(): void;
|
|
114
145
|
abstract unregister(): Promise<void>;
|
|
115
146
|
abstract register(): Promise<void>;
|
|
@@ -124,6 +155,7 @@ export declare abstract class oCore extends oObject {
|
|
|
124
155
|
protected onNotification(eventType: string, handler: NotificationHandler, filter?: EventFilter): Subscription;
|
|
125
156
|
initialize(): Promise<void>;
|
|
126
157
|
get isRunning(): boolean;
|
|
158
|
+
hookStartFinished(): Promise<void>;
|
|
127
159
|
/**
|
|
128
160
|
* Starts the node by transitioning through initialization and registration phases.
|
|
129
161
|
*
|
|
@@ -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,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,C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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
|
@@ -7,9 +7,8 @@ import { oObject } from './o-object.js';
|
|
|
7
7
|
import { oMetrics } from './lib/o-metrics.js';
|
|
8
8
|
import { oHierarchyManager } from './lib/o-hierarchy.manager.js';
|
|
9
9
|
import { oRequestManager } from './lib/o-request.manager.js';
|
|
10
|
-
import { CoreUtils } from '../utils/core.utils.js';
|
|
11
|
-
import { oErrorCodes } from '../error/index.js';
|
|
12
10
|
import { oRequest } from '../connection/o-request.js';
|
|
11
|
+
import { ResponseBuilder } from '../response/response-builder.js';
|
|
13
12
|
export class oCore extends oObject {
|
|
14
13
|
constructor(config) {
|
|
15
14
|
super((config.name ? `:${config.name}` : '') + ':' + config.address.toString());
|
|
@@ -30,6 +29,21 @@ export class oCore extends oObject {
|
|
|
30
29
|
get leader() {
|
|
31
30
|
return this.isLeader ? this.address : this.config?.leader || null;
|
|
32
31
|
}
|
|
32
|
+
async useStream(address, data, options) {
|
|
33
|
+
return this.use(address, {
|
|
34
|
+
...data,
|
|
35
|
+
params: {
|
|
36
|
+
...data.params,
|
|
37
|
+
_isStreaming: true,
|
|
38
|
+
},
|
|
39
|
+
}, {
|
|
40
|
+
...options,
|
|
41
|
+
isStream: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async useDirect(address, data) {
|
|
45
|
+
return this.use(address, data, { noRouting: true });
|
|
46
|
+
}
|
|
33
47
|
/**
|
|
34
48
|
* Sends a request to a remote node in the O-Lane network using the specified address and optional data payload.
|
|
35
49
|
*
|
|
@@ -83,11 +97,8 @@ export class oCore extends oObject {
|
|
|
83
97
|
* }
|
|
84
98
|
* ```
|
|
85
99
|
*/
|
|
86
|
-
async use(address, data) {
|
|
87
|
-
|
|
88
|
-
this.logger.error('Node is not running', this.state);
|
|
89
|
-
throw new Error('Node is not running');
|
|
90
|
-
}
|
|
100
|
+
async use(address, data, options) {
|
|
101
|
+
this.validateRunning();
|
|
91
102
|
if (!address.validate()) {
|
|
92
103
|
throw new Error('Invalid address');
|
|
93
104
|
}
|
|
@@ -96,28 +107,66 @@ export class oCore extends oObject {
|
|
|
96
107
|
if (address.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
97
108
|
return this.useSelf(data);
|
|
98
109
|
}
|
|
99
|
-
|
|
110
|
+
// if no routing is requested, use the address as is
|
|
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);
|
|
100
117
|
if (nextHopAddress.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
101
118
|
return this.useSelf(data);
|
|
102
119
|
}
|
|
103
|
-
const connection = await this.connect(
|
|
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
|
+
}
|
|
104
134
|
// communicate the payload to the target node
|
|
105
135
|
const response = await connection.send({
|
|
106
136
|
address: targetAddress?.toString() || '',
|
|
107
137
|
payload: data || {},
|
|
108
138
|
id: data?.id,
|
|
109
139
|
});
|
|
140
|
+
// we handle streaming response differently
|
|
141
|
+
if (options?.isStream) {
|
|
142
|
+
return response;
|
|
143
|
+
}
|
|
110
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) {
|
|
111
154
|
if (response.result.error) {
|
|
112
|
-
this.logger.error('response.result.error', JSON.stringify(response.result.error, null, 2));
|
|
113
155
|
throw oError.fromJSON(response.result.error);
|
|
114
156
|
}
|
|
115
|
-
return response;
|
|
116
157
|
}
|
|
117
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Helper method to validate node is running
|
|
160
|
+
* @throws Error if node is not running
|
|
161
|
+
*/
|
|
162
|
+
validateRunning() {
|
|
118
163
|
if (!this.isRunning) {
|
|
164
|
+
this.logger.error('Node is not running', this.state);
|
|
119
165
|
throw new Error('Node is not running');
|
|
120
166
|
}
|
|
167
|
+
}
|
|
168
|
+
async useSelf(data) {
|
|
169
|
+
this.validateRunning();
|
|
121
170
|
// let's call our own tool
|
|
122
171
|
this.logger.debug('Calling ourselves, skipping...', data);
|
|
123
172
|
const request = new oRequest({
|
|
@@ -129,29 +178,19 @@ export class oCore extends oObject {
|
|
|
129
178
|
},
|
|
130
179
|
id: 0,
|
|
131
180
|
});
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
? error
|
|
138
|
-
: new oError(oErrorCodes.UNKNOWN, error.message);
|
|
139
|
-
return {
|
|
140
|
-
error: responseError.toJSON(),
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
if (success) {
|
|
144
|
-
this.metrics.successCount++;
|
|
181
|
+
// Use ResponseBuilder with automatic error handling and metrics tracking
|
|
182
|
+
const responseBuilder = ResponseBuilder.create().withMetrics(this.metrics);
|
|
183
|
+
try {
|
|
184
|
+
const result = await this.execute(request);
|
|
185
|
+
return await responseBuilder.build(request, result, null);
|
|
145
186
|
}
|
|
146
|
-
|
|
147
|
-
this.
|
|
187
|
+
catch (error) {
|
|
188
|
+
this.logger.error('Error executing tool [self]: ', error);
|
|
189
|
+
return await responseBuilder.buildError(request, error);
|
|
148
190
|
}
|
|
149
|
-
return CoreUtils.buildResponse(request, result, result?.error);
|
|
150
191
|
}
|
|
151
|
-
async useChild(childAddress, data) {
|
|
152
|
-
|
|
153
|
-
throw new Error('Node is not running');
|
|
154
|
-
}
|
|
192
|
+
async useChild(childAddress, data, options) {
|
|
193
|
+
this.validateRunning();
|
|
155
194
|
if (!childAddress.transports) {
|
|
156
195
|
const child = this.hierarchyManager.getChild(childAddress);
|
|
157
196
|
if (!child) {
|
|
@@ -162,7 +201,17 @@ export class oCore extends oObject {
|
|
|
162
201
|
childAddress.setTransports(child?.transports || []);
|
|
163
202
|
}
|
|
164
203
|
}
|
|
165
|
-
const connection = await this.connect(
|
|
204
|
+
const connection = await this.connect({
|
|
205
|
+
nextHopAddress: childAddress,
|
|
206
|
+
address: childAddress,
|
|
207
|
+
callerAddress: this.address,
|
|
208
|
+
isStream: options?.isStream,
|
|
209
|
+
});
|
|
210
|
+
if (options?.isStream) {
|
|
211
|
+
connection.onChunk((response) => {
|
|
212
|
+
options.onChunk?.(response);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
166
215
|
// communicate the payload to the target node
|
|
167
216
|
const response = await connection.send({
|
|
168
217
|
address: childAddress?.toString() || '',
|
|
@@ -170,10 +219,7 @@ export class oCore extends oObject {
|
|
|
170
219
|
id: data?.id,
|
|
171
220
|
});
|
|
172
221
|
// if there is an error, throw it to continue to bubble up
|
|
173
|
-
|
|
174
|
-
this.logger.error('response.result.error', JSON.stringify(response.result.error, null, 2));
|
|
175
|
-
throw oError.fromJSON(response.result.error);
|
|
176
|
-
}
|
|
222
|
+
this.handleResponseError(response);
|
|
177
223
|
return response;
|
|
178
224
|
}
|
|
179
225
|
// hierarchy
|
|
@@ -211,6 +257,7 @@ export class oCore extends oObject {
|
|
|
211
257
|
this.state === NodeState.STOPPING ||
|
|
212
258
|
this.state === NodeState.STARTING);
|
|
213
259
|
}
|
|
260
|
+
async hookStartFinished() { }
|
|
214
261
|
/**
|
|
215
262
|
* Starts the node by transitioning through initialization and registration phases.
|
|
216
263
|
*
|
|
@@ -252,6 +299,7 @@ export class oCore extends oObject {
|
|
|
252
299
|
await this.register().catch((error) => {
|
|
253
300
|
this.logger.error('Failed to register node', error);
|
|
254
301
|
});
|
|
302
|
+
await this.hookStartFinished();
|
|
255
303
|
this.state = NodeState.RUNNING;
|
|
256
304
|
// Start optional heartbeat to monitor if enabled
|
|
257
305
|
if (process.env.MONITOR_ENABLED === 'true' &&
|
|
@@ -357,17 +405,22 @@ export class oCore extends oObject {
|
|
|
357
405
|
this.logger.debug(`Starting heartbeat to ${monitorAddress.toString()} every ${interval}ms`);
|
|
358
406
|
this.heartbeatInterval = setInterval(async () => {
|
|
359
407
|
try {
|
|
408
|
+
const metrics = {
|
|
409
|
+
successCount: this.metrics.successCount,
|
|
410
|
+
errorCount: this.metrics.errorCount,
|
|
411
|
+
activeRequests: this.requestManager.activeRequests.length,
|
|
412
|
+
state: this.state,
|
|
413
|
+
};
|
|
414
|
+
// Add stream count if available (oNode instances have this method)
|
|
415
|
+
if (typeof this.getStreamCount === 'function') {
|
|
416
|
+
metrics.streamCount = this.getStreamCount();
|
|
417
|
+
}
|
|
360
418
|
await this.use(monitorAddress, {
|
|
361
419
|
method: 'record_heartbeat',
|
|
362
420
|
params: {
|
|
363
421
|
address: this.address.toString(),
|
|
364
422
|
timestamp: Date.now(),
|
|
365
|
-
metrics
|
|
366
|
-
successCount: this.metrics.successCount,
|
|
367
|
-
errorCount: this.metrics.errorCount,
|
|
368
|
-
activeRequests: this.requestManager.activeRequests.length,
|
|
369
|
-
state: this.state,
|
|
370
|
-
},
|
|
423
|
+
metrics,
|
|
371
424
|
},
|
|
372
425
|
});
|
|
373
426
|
}
|
|
@@ -14,6 +14,7 @@ export declare enum oErrorCodes {
|
|
|
14
14
|
TRANSPORT_NOT_SUPPORTED = 1013,
|
|
15
15
|
FAILED_TO_DIAL_TARGET = 1014,
|
|
16
16
|
INVALID_CAPABILITY = 1015,
|
|
17
|
-
CONNECTION_LIMIT_REACHED = 1016
|
|
17
|
+
CONNECTION_LIMIT_REACHED = 1016,
|
|
18
|
+
TIMEOUT = 1017
|
|
18
19
|
}
|
|
19
20
|
//# 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;
|
|
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;CACf"}
|