@olane/o-core 0.6.13 → 0.7.2
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/README.md +490 -140
- package/dist/src/connection/index.d.ts +8 -0
- package/dist/src/connection/index.d.ts.map +1 -0
- package/dist/src/connection/index.js +7 -0
- package/dist/src/connection/interfaces/connection-manager.config.d.ts +3 -0
- package/dist/src/connection/interfaces/connection-manager.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/connection-send-params.interface.d.ts.map +1 -0
- package/dist/src/connection/interfaces/connection.config.d.ts +7 -0
- package/dist/src/connection/interfaces/connection.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/index.d.ts +5 -0
- package/dist/src/connection/interfaces/index.d.ts.map +1 -0
- package/dist/src/connection/interfaces/index.js +4 -0
- package/dist/src/connection/interfaces/request-state.enum.d.ts +7 -0
- package/dist/src/connection/interfaces/request-state.enum.d.ts.map +1 -0
- package/dist/src/connection/interfaces/request-state.enum.js +7 -0
- package/dist/src/connection/o-connection-manager.d.ts +19 -0
- package/dist/src/connection/o-connection-manager.d.ts.map +1 -0
- package/dist/src/connection/o-connection-manager.js +27 -0
- package/dist/src/connection/o-connection.d.ts +20 -0
- package/dist/src/connection/o-connection.d.ts.map +1 -0
- package/dist/src/connection/o-connection.js +45 -0
- package/dist/src/{core/lib → connection}/o-request.d.ts +5 -1
- package/dist/src/connection/o-request.d.ts.map +1 -0
- package/dist/src/{core/lib → connection}/o-request.js +8 -1
- package/dist/src/connection/o-response.d.ts.map +1 -0
- package/dist/src/core/defaults/config.d.ts +1 -1
- package/dist/src/core/defaults/config.d.ts.map +1 -1
- package/dist/src/core/defaults/config.js +1 -1
- package/dist/src/core/graceful-shutdown.d.ts +1 -1
- package/dist/src/core/graceful-shutdown.d.ts.map +1 -1
- package/dist/src/core/graceful-shutdown.js +1 -1
- package/dist/src/core/index.d.ts +3 -5
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +3 -5
- package/dist/src/core/interfaces/index.d.ts +1 -2
- package/dist/src/core/interfaces/index.d.ts.map +1 -1
- package/dist/src/core/interfaces/index.js +1 -2
- package/dist/src/core/interfaces/{core-config.interface.d.ts → o-core.config.d.ts} +4 -5
- package/dist/src/core/interfaces/o-core.config.d.ts.map +1 -0
- package/dist/src/core/interfaces/o-core.interface.d.ts +18 -0
- package/dist/src/core/interfaces/o-core.interface.d.ts.map +1 -0
- package/dist/src/core/lib/index.d.ts +3 -7
- package/dist/src/core/lib/index.d.ts.map +1 -1
- package/dist/src/core/lib/index.js +3 -7
- package/dist/src/core/lib/o-hierarchy.manager.d.ts +24 -0
- package/dist/src/core/lib/o-hierarchy.manager.d.ts.map +1 -0
- package/dist/src/core/lib/o-hierarchy.manager.js +57 -0
- package/dist/src/core/lib/o-metrics.d.ts +5 -0
- package/dist/src/core/lib/o-metrics.d.ts.map +1 -0
- package/dist/src/core/lib/o-metrics.js +6 -0
- package/dist/src/core/lib/o-request.manager.d.ts +10 -0
- package/dist/src/core/lib/o-request.manager.d.ts.map +1 -0
- package/dist/src/core/lib/o-request.manager.js +18 -0
- package/dist/src/core/o-core.d.ts +190 -0
- package/dist/src/core/o-core.d.ts.map +1 -0
- package/dist/src/core/o-core.js +334 -0
- package/dist/src/core/o-object.d.ts +7 -0
- package/dist/src/core/o-object.d.ts.map +1 -0
- package/dist/src/core/o-object.js +10 -0
- package/dist/src/error/enums/codes.error.d.ts +16 -14
- package/dist/src/error/enums/codes.error.d.ts.map +1 -1
- package/dist/src/error/enums/codes.error.js +18 -16
- package/dist/src/error/index.d.ts +1 -1
- package/dist/src/error/index.d.ts.map +1 -1
- package/dist/src/error/index.js +1 -1
- package/dist/src/error/interfaces/o-error.interface.d.ts +6 -0
- package/dist/src/error/interfaces/o-error.interface.d.ts.map +1 -0
- package/dist/src/error/o-error.d.ts +15 -0
- package/dist/src/error/o-error.d.ts.map +1 -0
- package/dist/src/error/{tool.error.js → o-error.js} +4 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/router/enums/restricted-addresses.enum.d.ts +8 -0
- package/dist/src/router/enums/restricted-addresses.enum.d.ts.map +1 -0
- package/dist/src/router/enums/restricted-addresses.enum.js +13 -0
- package/dist/src/router/index.d.ts +9 -0
- package/dist/src/router/index.d.ts.map +1 -0
- package/dist/src/router/index.js +8 -0
- package/dist/src/router/interfaces/resolve.request.d.ts +10 -0
- package/dist/src/router/interfaces/resolve.request.d.ts.map +1 -0
- package/dist/src/router/interfaces/route.response.d.ts +8 -0
- package/dist/src/router/interfaces/route.response.d.ts.map +1 -0
- package/dist/src/router/o-address-resolution.d.ts +12 -0
- package/dist/src/router/o-address-resolution.d.ts.map +1 -0
- package/dist/src/router/o-address-resolution.js +42 -0
- package/dist/src/router/o-address-resolver.d.ts +14 -0
- package/dist/src/router/o-address-resolver.d.ts.map +1 -0
- package/dist/src/router/o-address-resolver.js +19 -0
- package/dist/src/router/o-address.d.ts +33 -0
- package/dist/src/router/o-address.d.ts.map +1 -0
- package/dist/src/router/o-address.js +101 -0
- package/dist/src/router/o-request.router.d.ts +18 -0
- package/dist/src/router/o-request.router.d.ts.map +1 -0
- package/dist/src/router/o-request.router.js +12 -0
- package/dist/src/router/o-router.d.ts +19 -0
- package/dist/src/router/o-router.d.ts.map +1 -0
- package/dist/src/router/o-router.js +14 -0
- package/dist/src/transports/custom.transport.d.ts +6 -0
- package/dist/src/transports/custom.transport.d.ts.map +1 -0
- package/dist/src/transports/custom.transport.js +10 -0
- package/dist/src/transports/index.d.ts +4 -0
- package/dist/src/transports/index.d.ts.map +1 -0
- package/dist/src/transports/index.js +3 -0
- package/dist/src/transports/interfaces/transport-type.enum.d.ts +5 -0
- package/dist/src/transports/interfaces/transport-type.enum.d.ts.map +1 -0
- package/dist/src/transports/interfaces/transport-type.enum.js +5 -0
- package/dist/src/transports/o-transport.d.ts +10 -0
- package/dist/src/transports/o-transport.d.ts.map +1 -0
- package/dist/src/transports/o-transport.js +16 -0
- package/dist/src/{core/utils → utils}/core.utils.d.ts +4 -3
- package/dist/src/utils/core.utils.d.ts.map +1 -0
- package/dist/src/{core/utils → utils}/core.utils.js +17 -2
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +2 -0
- package/dist/src/{core/utils → utils}/logger.d.ts +1 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/{core/utils → utils}/logger.js +4 -1
- package/dist/test/server/in-process.spec.js +2 -14
- package/package.json +3 -3
- package/dist/src/core/core.node.d.ts +0 -79
- package/dist/src/core/core.node.d.ts.map +0 -1
- package/dist/src/core/core.node.js +0 -304
- package/dist/src/core/interfaces/connection-manager.config.d.ts +0 -7
- package/dist/src/core/interfaces/connection-manager.config.d.ts.map +0 -1
- package/dist/src/core/interfaces/connection-send-params.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/core-config.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/restricted-addresses.enum.d.ts +0 -13
- package/dist/src/core/interfaces/restricted-addresses.enum.d.ts.map +0 -1
- package/dist/src/core/interfaces/restricted-addresses.enum.js +0 -18
- package/dist/src/core/lib/o-address-resolution.d.ts +0 -9
- package/dist/src/core/lib/o-address-resolution.d.ts.map +0 -1
- package/dist/src/core/lib/o-address-resolution.js +0 -24
- package/dist/src/core/lib/o-address-resolver.d.ts +0 -17
- package/dist/src/core/lib/o-address-resolver.d.ts.map +0 -1
- package/dist/src/core/lib/o-address-resolver.js +0 -36
- package/dist/src/core/lib/o-connection-manager.d.ts +0 -22
- package/dist/src/core/lib/o-connection-manager.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection-manager.js +0 -65
- package/dist/src/core/lib/o-connection.d.ts +0 -27
- package/dist/src/core/lib/o-connection.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection.js +0 -84
- package/dist/src/core/lib/o-request.d.ts.map +0 -1
- package/dist/src/core/lib/o-response.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/anything.resolver.d.ts +0 -8
- package/dist/src/core/lib/resolvers/anything.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/anything.resolver.js +0 -15
- package/dist/src/core/lib/resolvers/index.d.ts +0 -5
- package/dist/src/core/lib/resolvers/index.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/index.js +0 -4
- package/dist/src/core/lib/resolvers/method.resolver.d.ts +0 -8
- package/dist/src/core/lib/resolvers/method.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/method.resolver.js +0 -18
- package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts +0 -10
- package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/next-hop.resolver.js +0 -59
- package/dist/src/core/lib/resolvers/storage.resolver.d.ts +0 -6
- package/dist/src/core/lib/resolvers/storage.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/storage.resolver.js +0 -10
- package/dist/src/core/o-address.d.ts +0 -20
- package/dist/src/core/o-address.d.ts.map +0 -1
- package/dist/src/core/o-address.js +0 -47
- package/dist/src/core/utils/core.utils.d.ts.map +0 -1
- package/dist/src/core/utils/index.d.ts +0 -4
- package/dist/src/core/utils/index.d.ts.map +0 -1
- package/dist/src/core/utils/index.js +0 -3
- package/dist/src/core/utils/logger.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.d.ts +0 -16
- package/dist/src/core/utils/network.utils.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.js +0 -35
- package/dist/src/error/tool.error.d.ts +0 -19
- package/dist/src/error/tool.error.d.ts.map +0 -1
- package/dist/src/node/index.d.ts +0 -4
- package/dist/src/node/index.d.ts.map +0 -1
- package/dist/src/node/index.js +0 -3
- package/dist/src/node/interfaces/route.request.d.ts +0 -14
- package/dist/src/node/interfaces/route.request.d.ts.map +0 -1
- package/dist/src/node/lib/local-search.lib.d.ts +0 -6
- package/dist/src/node/lib/local-search.lib.d.ts.map +0 -1
- package/dist/src/node/lib/local-search.lib.js +0 -10
- package/dist/src/node/lib/network-activity.lib.d.ts +0 -12
- package/dist/src/node/lib/network-activity.lib.d.ts.map +0 -1
- package/dist/src/node/lib/network-activity.lib.js +0 -29
- package/dist/src/node/node.d.ts +0 -45
- package/dist/src/node/node.d.ts.map +0 -1
- package/dist/src/node/node.js +0 -359
- package/dist/src/node-virtual/index.d.ts +0 -2
- package/dist/src/node-virtual/index.d.ts.map +0 -1
- package/dist/src/node-virtual/index.js +0 -1
- package/dist/src/node-virtual/virtual.node.d.ts +0 -10
- package/dist/src/node-virtual/virtual.node.d.ts.map +0 -1
- package/dist/src/node-virtual/virtual.node.js +0 -12
- package/dist/src/plan/agent.plan.d.ts +0 -28
- package/dist/src/plan/agent.plan.d.ts.map +0 -1
- package/dist/src/plan/agent.plan.js +0 -187
- package/dist/src/plan/index.d.ts +0 -5
- package/dist/src/plan/index.d.ts.map +0 -1
- package/dist/src/plan/index.js +0 -4
- package/dist/src/plan/interfaces/configure.result.d.ts +0 -6
- package/dist/src/plan/interfaces/configure.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/handshake.result.d.ts +0 -14
- package/dist/src/plan/interfaces/handshake.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-config.interface.d.ts +0 -16
- package/dist/src/plan/interfaces/plan-config.interface.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-result.interface.d.ts +0 -6
- package/dist/src/plan/interfaces/plan-result.interface.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-type.enum.d.ts +0 -8
- package/dist/src/plan/interfaces/plan-type.enum.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-type.enum.js +0 -8
- package/dist/src/plan/interfaces/plan.result.d.ts +0 -15
- package/dist/src/plan/interfaces/plan.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan.result.js +0 -1
- package/dist/src/plan/interfaces/query.config.d.ts +0 -6
- package/dist/src/plan/interfaces/query.config.d.ts.map +0 -1
- package/dist/src/plan/interfaces/query.config.js +0 -1
- package/dist/src/plan/interfaces/task.config.d.ts +0 -10
- package/dist/src/plan/interfaces/task.config.d.ts.map +0 -1
- package/dist/src/plan/interfaces/task.config.js +0 -1
- package/dist/src/plan/o-plan.d.ts +0 -36
- package/dist/src/plan/o-plan.d.ts.map +0 -1
- package/dist/src/plan/o-plan.js +0 -202
- package/dist/src/plan/plan.context.d.ts +0 -10
- package/dist/src/plan/plan.context.d.ts.map +0 -1
- package/dist/src/plan/plan.context.js +0 -28
- package/dist/src/plan/prompts/agent.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/agent.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/agent.prompt.js +0 -112
- package/dist/src/plan/prompts/configure.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/configure.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/configure.prompt.js +0 -40
- package/dist/src/plan/prompts/custom.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/custom.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/custom.prompt.js +0 -80
- package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts +0 -2
- package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts.map +0 -1
- package/dist/src/plan/search/prompts/search-analysis.prompt.js +0 -14
- package/dist/src/plan/search/search.plan.d.ts +0 -21
- package/dist/src/plan/search/search.plan.d.ts.map +0 -1
- package/dist/src/plan/search/search.plan.js +0 -53
- package/dist/src/plan/use/index.d.ts +0 -2
- package/dist/src/plan/use/index.d.ts.map +0 -1
- package/dist/src/plan/use/index.js +0 -1
- package/dist/src/plan/use/use.plan.d.ts +0 -16
- package/dist/src/plan/use/use.plan.d.ts.map +0 -1
- package/dist/src/plan/use/use.plan.js +0 -149
- /package/dist/src/{core → connection}/interfaces/connection-manager.config.js +0 -0
- /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.d.ts +0 -0
- /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.js +0 -0
- /package/dist/src/{core/interfaces/core-config.interface.js → connection/interfaces/connection.config.js} +0 -0
- /package/dist/src/{core/lib → connection}/o-response.d.ts +0 -0
- /package/dist/src/{core/lib → connection}/o-response.js +0 -0
- /package/dist/src/{node/interfaces/route.request.js → core/interfaces/o-core.config.js} +0 -0
- /package/dist/src/{plan/interfaces/configure.result.js → core/interfaces/o-core.interface.js} +0 -0
- /package/dist/src/{plan/interfaces/handshake.result.js → error/interfaces/o-error.interface.js} +0 -0
- /package/dist/src/{plan/interfaces/plan-config.interface.js → router/interfaces/resolve.request.js} +0 -0
- /package/dist/src/{plan/interfaces/plan-result.interface.js → router/interfaces/route.response.js} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { oCoreConfig } from './interfaces/o-core.config.js';
|
|
2
|
+
import { NodeState } from './interfaces/state.enum.js';
|
|
3
|
+
import { oAddress } from '../router/o-address.js';
|
|
4
|
+
import { NodeType } from './interfaces/node-type.enum.js';
|
|
5
|
+
import { oConnectionManager } from '../connection/o-connection-manager.js';
|
|
6
|
+
import { oResponse } from '../connection/o-response.js';
|
|
7
|
+
import { oConnection } from '../connection/o-connection.js';
|
|
8
|
+
import { oMethod } from '@olane/o-protocol';
|
|
9
|
+
import { oDependency } from './o-dependency.js';
|
|
10
|
+
import { oObject } from './o-object.js';
|
|
11
|
+
import { oMetrics } from './lib/o-metrics.js';
|
|
12
|
+
import { oHierarchyManager } from './lib/o-hierarchy.manager.js';
|
|
13
|
+
import { oRequestManager } from './lib/o-request.manager.js';
|
|
14
|
+
import { oTransport } from '../transports/o-transport.js';
|
|
15
|
+
import { oRouter } from '../router/o-router.js';
|
|
16
|
+
import { oRequest } from '../connection/o-request.js';
|
|
17
|
+
export declare abstract class oCore extends oObject {
|
|
18
|
+
readonly config: oCoreConfig;
|
|
19
|
+
address: oAddress;
|
|
20
|
+
state: NodeState;
|
|
21
|
+
errors: Error[];
|
|
22
|
+
connectionManager: oConnectionManager;
|
|
23
|
+
hierarchyManager: oHierarchyManager;
|
|
24
|
+
metrics: oMetrics;
|
|
25
|
+
requestManager: oRequestManager;
|
|
26
|
+
router: oRouter;
|
|
27
|
+
constructor(config: oCoreConfig);
|
|
28
|
+
get isLeader(): boolean;
|
|
29
|
+
get leader(): oAddress | null;
|
|
30
|
+
abstract configureTransports(): any[];
|
|
31
|
+
/**
|
|
32
|
+
* Sends a request to a remote node in the O-Lane network using the specified address and optional data payload.
|
|
33
|
+
*
|
|
34
|
+
* This method handles the complete communication flow:
|
|
35
|
+
* 1. Validates the target address format
|
|
36
|
+
* 2. Resolves the routing path through the network
|
|
37
|
+
* 3. Establishes a connection to the target node
|
|
38
|
+
* 4. Sends the request payload and waits for response
|
|
39
|
+
* 5. Handles errors and throws them as oError instances
|
|
40
|
+
*
|
|
41
|
+
* @param address - The target node address in O-Lane format (must start with 'o://')
|
|
42
|
+
* @param data - Optional request data containing method, parameters, and request ID
|
|
43
|
+
* @param data.method - The method name to invoke on the target node
|
|
44
|
+
* @param data.params - Key-value pairs of parameters to pass to the method
|
|
45
|
+
* @param data.id - Unique identifier for the request (for tracking purposes)
|
|
46
|
+
* @returns Promise that resolves to an oResponse containing the result from the target node
|
|
47
|
+
* @throws {Error} When the address is invalid (doesn't pass validation)
|
|
48
|
+
* @throws {oError} When the target node returns an error response
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Basic usage - call a method on a remote node
|
|
53
|
+
* const response = await node.use(
|
|
54
|
+
* new oAddress('o://calculator/add'),
|
|
55
|
+
* {
|
|
56
|
+
* method: 'add',
|
|
57
|
+
* params: { a: 5, b: 3 },
|
|
58
|
+
* id: 'calc-001'
|
|
59
|
+
* }
|
|
60
|
+
* );
|
|
61
|
+
* console.log(response.result); // { result: 8 }
|
|
62
|
+
*
|
|
63
|
+
* // Minimal usage - just specify the address
|
|
64
|
+
* const response = await node.use(
|
|
65
|
+
* new oAddress('o://status/health')
|
|
66
|
+
* );
|
|
67
|
+
* console.log(response.result); // { status: 'healthy' }
|
|
68
|
+
*
|
|
69
|
+
* // Error handling
|
|
70
|
+
* try {
|
|
71
|
+
* const response = await node.use(
|
|
72
|
+
* new oAddress('o://calculator/divide'),
|
|
73
|
+
* { method: 'divide', params: { a: 10, b: 0 } }
|
|
74
|
+
* );
|
|
75
|
+
* } catch (error) {
|
|
76
|
+
* if (error instanceof oError) {
|
|
77
|
+
* console.error(`Node error ${error.code}: ${error.message}`);
|
|
78
|
+
* } else {
|
|
79
|
+
* console.error('Invalid address or connection error:', error.message);
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
use(address: oAddress, data?: {
|
|
85
|
+
method?: string;
|
|
86
|
+
params?: {
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
};
|
|
89
|
+
id?: string;
|
|
90
|
+
}): Promise<oResponse>;
|
|
91
|
+
abstract execute(request: oRequest): Promise<any>;
|
|
92
|
+
useSelf(data?: {
|
|
93
|
+
method?: string;
|
|
94
|
+
params?: {
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
};
|
|
97
|
+
id?: string;
|
|
98
|
+
}): Promise<oResponse>;
|
|
99
|
+
useChild(childAddress: oAddress, data?: {
|
|
100
|
+
method?: string;
|
|
101
|
+
params?: {
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
};
|
|
104
|
+
id?: string;
|
|
105
|
+
}): Promise<oResponse>;
|
|
106
|
+
addChildNode(node: oCore): void;
|
|
107
|
+
removeChildNode(node: oCore): void;
|
|
108
|
+
abstract connect(nextHopAddress: oAddress, targetAddress: oAddress): Promise<oConnection>;
|
|
109
|
+
abstract initializeRouter(): void;
|
|
110
|
+
abstract unregister(): Promise<void>;
|
|
111
|
+
abstract register(): Promise<void>;
|
|
112
|
+
initialize(): Promise<void>;
|
|
113
|
+
get isRunning(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Starts the node by transitioning through initialization and registration phases.
|
|
116
|
+
*
|
|
117
|
+
* This method performs the following operations in sequence:
|
|
118
|
+
* 1. Validates that the node is in STOPPED state
|
|
119
|
+
* 2. Sets state to STARTING
|
|
120
|
+
* 3. Calls initialize() to set up the node's core components
|
|
121
|
+
* 4. Attempts registration with the network (registration errors are logged but don't fail startup)
|
|
122
|
+
* 5. Sets state to RUNNING on success
|
|
123
|
+
*
|
|
124
|
+
* @throws {Error} If the node is not in STOPPED state or initialization fails
|
|
125
|
+
* @returns {Promise<void>} Resolves when the node is successfully started and running
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const node = new oNode(config);
|
|
130
|
+
* try {
|
|
131
|
+
* await node.start();
|
|
132
|
+
* console.log('Node is now running');
|
|
133
|
+
* } catch (error) {
|
|
134
|
+
* console.error('Failed to start node:', error);
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* - If the node is already running or starting, the method will log a warning and return early
|
|
140
|
+
* - Registration failures are logged but do not prevent the node from starting
|
|
141
|
+
* - On any initialization error, the node state is set to ERROR and teardown() is called
|
|
142
|
+
* - The node must be in STOPPED state before calling this method
|
|
143
|
+
*/
|
|
144
|
+
start(): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Stops the node by performing cleanup and transitioning to a stopped state.
|
|
147
|
+
*
|
|
148
|
+
* This method performs the following operations in sequence:
|
|
149
|
+
* 1. Sets state to STOPPING
|
|
150
|
+
* 2. Calls teardown() to clean up node resources and connections
|
|
151
|
+
* 3. Sets state to STOPPED on successful completion
|
|
152
|
+
*
|
|
153
|
+
* @throws {Error} If teardown operations fail, the node state will be set to ERROR
|
|
154
|
+
* @returns {Promise<void>} Resolves when the node is successfully stopped
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const node = new oNode(config);
|
|
159
|
+
* await node.start();
|
|
160
|
+
*
|
|
161
|
+
* // Later, when shutting down
|
|
162
|
+
* try {
|
|
163
|
+
* await node.stop();
|
|
164
|
+
* console.log('Node stopped successfully');
|
|
165
|
+
* } catch (error) {
|
|
166
|
+
* console.error('Failed to stop node:', error);
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* - This method can be called from any node state
|
|
172
|
+
* - If teardown fails, errors are logged and the node state is set to ERROR
|
|
173
|
+
* - All cleanup operations are performed through the teardown() method
|
|
174
|
+
* - The method will attempt to stop gracefully even if the node is in an error state
|
|
175
|
+
*/
|
|
176
|
+
stop(): Promise<void>;
|
|
177
|
+
teardown(): Promise<void>;
|
|
178
|
+
get dependencies(): oDependency[];
|
|
179
|
+
get methods(): {
|
|
180
|
+
[key: string]: oMethod;
|
|
181
|
+
};
|
|
182
|
+
get description(): string;
|
|
183
|
+
get staticAddress(): oAddress;
|
|
184
|
+
get type(): NodeType;
|
|
185
|
+
get transports(): oTransport[];
|
|
186
|
+
get parent(): oAddress | null;
|
|
187
|
+
get parentTransports(): oTransport[];
|
|
188
|
+
whoami(): Promise<any>;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=o-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-core.d.ts","sourceRoot":"","sources":["../../../src/core/o-core.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { NodeState } from './interfaces/state.enum.js';
|
|
2
|
+
import { oAddress } from '../router/o-address.js';
|
|
3
|
+
import { NodeType } from './interfaces/node-type.enum.js';
|
|
4
|
+
import { oDependency } from './o-dependency.js';
|
|
5
|
+
import { oError } from '../error/o-error.js';
|
|
6
|
+
import { oObject } from './o-object.js';
|
|
7
|
+
import { oMetrics } from './lib/o-metrics.js';
|
|
8
|
+
import { oHierarchyManager } from './lib/o-hierarchy.manager.js';
|
|
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
|
+
import { oRequest } from '../connection/o-request.js';
|
|
13
|
+
export class oCore extends oObject {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
super((config.name ? `:${config.name}` : '') + ':' + config.address.toString());
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.state = NodeState.STOPPED;
|
|
18
|
+
this.errors = [];
|
|
19
|
+
this.metrics = new oMetrics();
|
|
20
|
+
this.requestManager = new oRequestManager();
|
|
21
|
+
this.address = config.address || new oAddress('o://node');
|
|
22
|
+
this.hierarchyManager = new oHierarchyManager({
|
|
23
|
+
leaders: this.config.leader ? [this.config.leader] : [],
|
|
24
|
+
parents: this.config.parent ? [this.config.parent] : [],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
get isLeader() {
|
|
28
|
+
return this.config.type === NodeType.LEADER;
|
|
29
|
+
}
|
|
30
|
+
get leader() {
|
|
31
|
+
return this.isLeader ? this.address : this.config?.leader || null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sends a request to a remote node in the O-Lane network using the specified address and optional data payload.
|
|
35
|
+
*
|
|
36
|
+
* This method handles the complete communication flow:
|
|
37
|
+
* 1. Validates the target address format
|
|
38
|
+
* 2. Resolves the routing path through the network
|
|
39
|
+
* 3. Establishes a connection to the target node
|
|
40
|
+
* 4. Sends the request payload and waits for response
|
|
41
|
+
* 5. Handles errors and throws them as oError instances
|
|
42
|
+
*
|
|
43
|
+
* @param address - The target node address in O-Lane format (must start with 'o://')
|
|
44
|
+
* @param data - Optional request data containing method, parameters, and request ID
|
|
45
|
+
* @param data.method - The method name to invoke on the target node
|
|
46
|
+
* @param data.params - Key-value pairs of parameters to pass to the method
|
|
47
|
+
* @param data.id - Unique identifier for the request (for tracking purposes)
|
|
48
|
+
* @returns Promise that resolves to an oResponse containing the result from the target node
|
|
49
|
+
* @throws {Error} When the address is invalid (doesn't pass validation)
|
|
50
|
+
* @throws {oError} When the target node returns an error response
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // Basic usage - call a method on a remote node
|
|
55
|
+
* const response = await node.use(
|
|
56
|
+
* new oAddress('o://calculator/add'),
|
|
57
|
+
* {
|
|
58
|
+
* method: 'add',
|
|
59
|
+
* params: { a: 5, b: 3 },
|
|
60
|
+
* id: 'calc-001'
|
|
61
|
+
* }
|
|
62
|
+
* );
|
|
63
|
+
* console.log(response.result); // { result: 8 }
|
|
64
|
+
*
|
|
65
|
+
* // Minimal usage - just specify the address
|
|
66
|
+
* const response = await node.use(
|
|
67
|
+
* new oAddress('o://status/health')
|
|
68
|
+
* );
|
|
69
|
+
* console.log(response.result); // { status: 'healthy' }
|
|
70
|
+
*
|
|
71
|
+
* // Error handling
|
|
72
|
+
* try {
|
|
73
|
+
* const response = await node.use(
|
|
74
|
+
* new oAddress('o://calculator/divide'),
|
|
75
|
+
* { method: 'divide', params: { a: 10, b: 0 } }
|
|
76
|
+
* );
|
|
77
|
+
* } catch (error) {
|
|
78
|
+
* if (error instanceof oError) {
|
|
79
|
+
* console.error(`Node error ${error.code}: ${error.message}`);
|
|
80
|
+
* } else {
|
|
81
|
+
* console.error('Invalid address or connection error:', error.message);
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async use(address, data) {
|
|
87
|
+
if (!this.isRunning) {
|
|
88
|
+
throw new Error('Node is not running');
|
|
89
|
+
}
|
|
90
|
+
if (!address.validate()) {
|
|
91
|
+
throw new Error('Invalid address');
|
|
92
|
+
}
|
|
93
|
+
this.logger.debug('Using address: ', address.toString());
|
|
94
|
+
if (address.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
95
|
+
return this.useSelf(data);
|
|
96
|
+
}
|
|
97
|
+
const { nextHopAddress, targetAddress } = await this.router.translate(address, this);
|
|
98
|
+
if (nextHopAddress.toStaticAddress().equals(this.address.toStaticAddress())) {
|
|
99
|
+
return this.useSelf(data);
|
|
100
|
+
}
|
|
101
|
+
const connection = await this.connect(nextHopAddress, targetAddress);
|
|
102
|
+
// communicate the payload to the target node
|
|
103
|
+
const response = await connection.send({
|
|
104
|
+
address: targetAddress?.toString() || '',
|
|
105
|
+
payload: data || {},
|
|
106
|
+
id: data?.id,
|
|
107
|
+
});
|
|
108
|
+
// if there is an error, throw it to continue to bubble up
|
|
109
|
+
if (response.result.error) {
|
|
110
|
+
this.logger.error('response.result.error', JSON.stringify(response.result.error, null, 2));
|
|
111
|
+
throw oError.fromJSON(response.result.error);
|
|
112
|
+
}
|
|
113
|
+
return response;
|
|
114
|
+
}
|
|
115
|
+
async useSelf(data) {
|
|
116
|
+
if (!this.isRunning) {
|
|
117
|
+
throw new Error('Node is not running');
|
|
118
|
+
}
|
|
119
|
+
// let's call our own tool
|
|
120
|
+
this.logger.debug('Calling ourselves, skipping...', data);
|
|
121
|
+
const request = new oRequest({
|
|
122
|
+
method: data?.method,
|
|
123
|
+
params: {
|
|
124
|
+
_connectionId: 0,
|
|
125
|
+
_requestMethod: data?.method,
|
|
126
|
+
...data?.params,
|
|
127
|
+
},
|
|
128
|
+
id: 0,
|
|
129
|
+
});
|
|
130
|
+
let success = true;
|
|
131
|
+
const result = await this.execute(request).catch((error) => {
|
|
132
|
+
this.logger.error('Error executing tool: ', error);
|
|
133
|
+
success = false;
|
|
134
|
+
const responseError = error instanceof oError
|
|
135
|
+
? error
|
|
136
|
+
: new oError(oErrorCodes.UNKNOWN, error.message);
|
|
137
|
+
return {
|
|
138
|
+
error: responseError.toJSON(),
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
if (success) {
|
|
142
|
+
this.metrics.successCount++;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.metrics.errorCount++;
|
|
146
|
+
}
|
|
147
|
+
return CoreUtils.buildResponse(request, result, result?.error);
|
|
148
|
+
}
|
|
149
|
+
async useChild(childAddress, data) {
|
|
150
|
+
if (!this.isRunning) {
|
|
151
|
+
throw new Error('Node is not running');
|
|
152
|
+
}
|
|
153
|
+
if (!childAddress.transports) {
|
|
154
|
+
this.logger.warn('Child address has no transports, this might break!');
|
|
155
|
+
}
|
|
156
|
+
const connection = await this.connect(childAddress, childAddress);
|
|
157
|
+
// communicate the payload to the target node
|
|
158
|
+
const response = await connection.send({
|
|
159
|
+
address: childAddress?.toString() || '',
|
|
160
|
+
payload: data || {},
|
|
161
|
+
id: data?.id,
|
|
162
|
+
});
|
|
163
|
+
// if there is an error, throw it to continue to bubble up
|
|
164
|
+
if (response.result.error) {
|
|
165
|
+
this.logger.error('response.result.error', JSON.stringify(response.result.error, null, 2));
|
|
166
|
+
throw oError.fromJSON(response.result.error);
|
|
167
|
+
}
|
|
168
|
+
return response;
|
|
169
|
+
}
|
|
170
|
+
// hierarchy
|
|
171
|
+
addChildNode(node) {
|
|
172
|
+
this.logger.debug('Adding virtual node: ' + node.address.toString());
|
|
173
|
+
this.hierarchyManager.addChild(node.address);
|
|
174
|
+
}
|
|
175
|
+
removeChildNode(node) {
|
|
176
|
+
this.hierarchyManager.removeChild(node.address);
|
|
177
|
+
}
|
|
178
|
+
// initialize
|
|
179
|
+
async initialize() { }
|
|
180
|
+
get isRunning() {
|
|
181
|
+
return this.state < NodeState.STOPPING;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Starts the node by transitioning through initialization and registration phases.
|
|
185
|
+
*
|
|
186
|
+
* This method performs the following operations in sequence:
|
|
187
|
+
* 1. Validates that the node is in STOPPED state
|
|
188
|
+
* 2. Sets state to STARTING
|
|
189
|
+
* 3. Calls initialize() to set up the node's core components
|
|
190
|
+
* 4. Attempts registration with the network (registration errors are logged but don't fail startup)
|
|
191
|
+
* 5. Sets state to RUNNING on success
|
|
192
|
+
*
|
|
193
|
+
* @throws {Error} If the node is not in STOPPED state or initialization fails
|
|
194
|
+
* @returns {Promise<void>} Resolves when the node is successfully started and running
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const node = new oNode(config);
|
|
199
|
+
* try {
|
|
200
|
+
* await node.start();
|
|
201
|
+
* console.log('Node is now running');
|
|
202
|
+
* } catch (error) {
|
|
203
|
+
* console.error('Failed to start node:', error);
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* - If the node is already running or starting, the method will log a warning and return early
|
|
209
|
+
* - Registration failures are logged but do not prevent the node from starting
|
|
210
|
+
* - On any initialization error, the node state is set to ERROR and teardown() is called
|
|
211
|
+
* - The node must be in STOPPED state before calling this method
|
|
212
|
+
*/
|
|
213
|
+
async start() {
|
|
214
|
+
if (this.state !== NodeState.STOPPED) {
|
|
215
|
+
this.logger.warn('Node is not stopped, skipping start');
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.state = NodeState.STARTING;
|
|
219
|
+
try {
|
|
220
|
+
await this.initialize();
|
|
221
|
+
await this.register().catch((error) => {
|
|
222
|
+
this.logger.error('Failed to register node', error);
|
|
223
|
+
});
|
|
224
|
+
this.state = NodeState.RUNNING;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
this.logger.error('Failed to start node', error);
|
|
228
|
+
this.errors.push(error);
|
|
229
|
+
this.state = NodeState.ERROR;
|
|
230
|
+
await this.teardown();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Stops the node by performing cleanup and transitioning to a stopped state.
|
|
235
|
+
*
|
|
236
|
+
* This method performs the following operations in sequence:
|
|
237
|
+
* 1. Sets state to STOPPING
|
|
238
|
+
* 2. Calls teardown() to clean up node resources and connections
|
|
239
|
+
* 3. Sets state to STOPPED on successful completion
|
|
240
|
+
*
|
|
241
|
+
* @throws {Error} If teardown operations fail, the node state will be set to ERROR
|
|
242
|
+
* @returns {Promise<void>} Resolves when the node is successfully stopped
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const node = new oNode(config);
|
|
247
|
+
* await node.start();
|
|
248
|
+
*
|
|
249
|
+
* // Later, when shutting down
|
|
250
|
+
* try {
|
|
251
|
+
* await node.stop();
|
|
252
|
+
* console.log('Node stopped successfully');
|
|
253
|
+
* } catch (error) {
|
|
254
|
+
* console.error('Failed to stop node:', error);
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* @remarks
|
|
259
|
+
* - This method can be called from any node state
|
|
260
|
+
* - If teardown fails, errors are logged and the node state is set to ERROR
|
|
261
|
+
* - All cleanup operations are performed through the teardown() method
|
|
262
|
+
* - The method will attempt to stop gracefully even if the node is in an error state
|
|
263
|
+
*/
|
|
264
|
+
async stop() {
|
|
265
|
+
this.logger.debug('Stop node called...');
|
|
266
|
+
if (this.state !== NodeState.RUNNING) {
|
|
267
|
+
this.logger.warn('Node is not running, skipping stop');
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this.state = NodeState.STOPPING;
|
|
271
|
+
try {
|
|
272
|
+
await this.teardown();
|
|
273
|
+
this.state = NodeState.STOPPED;
|
|
274
|
+
this.logger.debug('Node stopped!');
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
this.errors.push(error);
|
|
278
|
+
this.state = NodeState.ERROR;
|
|
279
|
+
this.logger.error('Node failed to stop', error);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async teardown() {
|
|
283
|
+
this.logger.debug('Tearing down node...');
|
|
284
|
+
this.state = NodeState.STOPPING;
|
|
285
|
+
for (const child of this.hierarchyManager.children) {
|
|
286
|
+
this.logger.debug('Stopping child: ' + child.toString());
|
|
287
|
+
await this.useChild(child, {
|
|
288
|
+
method: 'stop',
|
|
289
|
+
params: {},
|
|
290
|
+
}).catch((error) => {
|
|
291
|
+
if (error.message === 'No data received') {
|
|
292
|
+
// ignore
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
this.logger.error('Potential error stopping child', error);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
this.logger.debug('Child stopped: ' + child.toString());
|
|
299
|
+
}
|
|
300
|
+
this.hierarchyManager.clear();
|
|
301
|
+
}
|
|
302
|
+
get dependencies() {
|
|
303
|
+
return this.config.dependencies?.map((d) => new oDependency(d)) || [];
|
|
304
|
+
}
|
|
305
|
+
get methods() {
|
|
306
|
+
return this.config.methods || {};
|
|
307
|
+
}
|
|
308
|
+
get description() {
|
|
309
|
+
return this.config.description || '';
|
|
310
|
+
}
|
|
311
|
+
get staticAddress() {
|
|
312
|
+
return this.config.address;
|
|
313
|
+
}
|
|
314
|
+
get type() {
|
|
315
|
+
return this.config.type || NodeType.UNKNOWN;
|
|
316
|
+
}
|
|
317
|
+
get transports() {
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
get parent() {
|
|
321
|
+
return this.config.parent || null;
|
|
322
|
+
}
|
|
323
|
+
get parentTransports() {
|
|
324
|
+
return this.parent?.transports || [];
|
|
325
|
+
}
|
|
326
|
+
async whoami() {
|
|
327
|
+
return {
|
|
328
|
+
address: this.address.toString(),
|
|
329
|
+
type: this.type,
|
|
330
|
+
description: this.description,
|
|
331
|
+
methods: this.methods,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-object.d.ts","sourceRoot":"","sources":["../../../src/core/o-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,qBAAa,OAAO;IACX,MAAM,EAAE,MAAM,CAAC;gBACV,IAAI,CAAC,EAAE,MAAM;IAIzB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAI1B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Logger } from '../utils/logger.js';
|
|
2
|
+
export class oObject {
|
|
3
|
+
constructor(name) {
|
|
4
|
+
this.logger = new Logger(this.constructor.name + (name ? `:${name}` : ''));
|
|
5
|
+
}
|
|
6
|
+
static log(...args) {
|
|
7
|
+
const l = new Logger(this.constructor.name);
|
|
8
|
+
l.debug(...args);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
export declare enum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
export declare enum oErrorCodes {
|
|
2
|
+
UNKNOWN = 1001,
|
|
3
|
+
NOT_FOUND = 1002,
|
|
4
|
+
NOT_IMPLEMENTED = 1003,
|
|
5
|
+
NOT_CONFIGURED = 1004,
|
|
6
|
+
NOT_AUTHORIZED = 1005,
|
|
7
|
+
MISSING_PARAMETERS = 1006,
|
|
8
|
+
INVALID_PARAMETERS = 1007,
|
|
9
|
+
INVALID_RESPONSE = 1008,
|
|
10
|
+
INVALID_REQUEST = 1009,
|
|
11
|
+
INVALID_STATE = 1010,
|
|
12
|
+
INVALID_ACTION = 1011,
|
|
13
|
+
INVALID_CREDENTIALS = 1012,
|
|
14
|
+
TRANSPORT_NOT_SUPPORTED = 1013,
|
|
15
|
+
FAILED_TO_DIAL_TARGET = 1014,
|
|
16
|
+
INVALID_CAPABILITY = 1015
|
|
15
17
|
}
|
|
16
18
|
//# 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,
|
|
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;CAC1B"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
export var
|
|
2
|
-
(function (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
export var oErrorCodes;
|
|
2
|
+
(function (oErrorCodes) {
|
|
3
|
+
oErrorCodes[oErrorCodes["UNKNOWN"] = 1001] = "UNKNOWN";
|
|
4
|
+
oErrorCodes[oErrorCodes["NOT_FOUND"] = 1002] = "NOT_FOUND";
|
|
5
|
+
oErrorCodes[oErrorCodes["NOT_IMPLEMENTED"] = 1003] = "NOT_IMPLEMENTED";
|
|
6
|
+
oErrorCodes[oErrorCodes["NOT_CONFIGURED"] = 1004] = "NOT_CONFIGURED";
|
|
7
|
+
oErrorCodes[oErrorCodes["NOT_AUTHORIZED"] = 1005] = "NOT_AUTHORIZED";
|
|
8
|
+
oErrorCodes[oErrorCodes["MISSING_PARAMETERS"] = 1006] = "MISSING_PARAMETERS";
|
|
9
|
+
oErrorCodes[oErrorCodes["INVALID_PARAMETERS"] = 1007] = "INVALID_PARAMETERS";
|
|
10
|
+
oErrorCodes[oErrorCodes["INVALID_RESPONSE"] = 1008] = "INVALID_RESPONSE";
|
|
11
|
+
oErrorCodes[oErrorCodes["INVALID_REQUEST"] = 1009] = "INVALID_REQUEST";
|
|
12
|
+
oErrorCodes[oErrorCodes["INVALID_STATE"] = 1010] = "INVALID_STATE";
|
|
13
|
+
oErrorCodes[oErrorCodes["INVALID_ACTION"] = 1011] = "INVALID_ACTION";
|
|
14
|
+
oErrorCodes[oErrorCodes["INVALID_CREDENTIALS"] = 1012] = "INVALID_CREDENTIALS";
|
|
15
|
+
oErrorCodes[oErrorCodes["TRANSPORT_NOT_SUPPORTED"] = 1013] = "TRANSPORT_NOT_SUPPORTED";
|
|
16
|
+
oErrorCodes[oErrorCodes["FAILED_TO_DIAL_TARGET"] = 1014] = "FAILED_TO_DIAL_TARGET";
|
|
17
|
+
oErrorCodes[oErrorCodes["INVALID_CAPABILITY"] = 1015] = "INVALID_CAPABILITY";
|
|
18
|
+
})(oErrorCodes || (oErrorCodes = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC"}
|
package/dist/src/error/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './o-error.js';
|
|
2
2
|
export * from './enums/codes.error.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-error.interface.d.ts","sourceRoot":"","sources":["../../../../src/error/interfaces/o-error.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf"}
|