oox 0.3.4 → 0.3.5

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/registry.js CHANGED
@@ -1,5 +1,71 @@
1
1
  import { config } from './index.js';
2
2
  import { enabledKeepAliveConnections, keepAliveConnectionAdapters, keepAliveConnections } from './keepalive-connection.js';
3
+ const unsubscribeListeners = new Map();
4
+ const subscribes = new Map();
5
+ let broadcastTimer = null;
6
+ /**
7
+ * 取消订阅连接列表
8
+ * @param connection
9
+ */
10
+ export function unsubscribe(connection) {
11
+ subscribes.delete(connection);
12
+ }
13
+ /**
14
+ * 订阅连接列表
15
+ * @param connection
16
+ * @param query
17
+ * @returns
18
+ */
19
+ export function subscribe(connection, query) {
20
+ if (!config.isRegistry)
21
+ return;
22
+ if (!unsubscribeListeners.has(connection)) {
23
+ const listener = () => {
24
+ unsubscribe(connection);
25
+ };
26
+ unsubscribeListeners.set(connection, listener);
27
+ connection.once('disconnect', listener);
28
+ }
29
+ subscribes.set(connection, query);
30
+ }
31
+ /**
32
+ * 停止广播连接列表
33
+ */
34
+ export function stopBroadcastTimer() {
35
+ if (!broadcastTimer)
36
+ return;
37
+ clearInterval(broadcastTimer);
38
+ broadcastTimer = null;
39
+ }
40
+ /**
41
+ * 开始广播连接列表
42
+ */
43
+ export function startBroadcastTimer() {
44
+ if (!config.isRegistry)
45
+ return;
46
+ if (broadcastTimer)
47
+ clearInterval(broadcastTimer);
48
+ broadcastTimer = setInterval(broadcast, 1000);
49
+ }
50
+ /**
51
+ * 广播连接列表
52
+ */
53
+ export function broadcast() {
54
+ if (!config.isRegistry)
55
+ return;
56
+ for (const [connection, query] of subscribes.entries()) {
57
+ try {
58
+ onSyncConnections(connection, query, returns => {
59
+ if (!returns.success)
60
+ return;
61
+ connection.adapter['registry:notify'](connection, returns.body || []);
62
+ });
63
+ }
64
+ catch (error) {
65
+ console.error(error);
66
+ }
67
+ }
68
+ }
3
69
  /**
4
70
  * 服务器发送连接列表
5
71
  * @param connection
@@ -8,8 +74,16 @@ import { enabledKeepAliveConnections, keepAliveConnectionAdapters, keepAliveConn
8
74
  */
9
75
  export function onSyncConnections(connection, query, callback) {
10
76
  // 检查是否开启服务注册功能
11
- if (!config.isRegistry)
12
- return callback([]);
77
+ if (!config.isRegistry) {
78
+ const returns = {
79
+ success: false,
80
+ error: {
81
+ message: 'Service registration is not enabled',
82
+ }
83
+ };
84
+ callback(returns);
85
+ return;
86
+ }
13
87
  const datas = [];
14
88
  if (query.name) {
15
89
  const names = Array.isArray(query.name) ? query.name : [query.name];
@@ -34,14 +108,24 @@ export function onSyncConnections(connection, query, callback) {
34
108
  }
35
109
  }
36
110
  }
37
- callback(datas);
111
+ const returns = {
112
+ success: true,
113
+ body: datas,
114
+ };
115
+ callback(returns);
38
116
  }
39
117
  /**
40
118
  * 同步连接列表
41
119
  * @param datas 连接参数列表
42
120
  */
43
- export function syncConnections(datas) {
44
- for (const data of datas) {
121
+ export function syncConnections(returns) {
122
+ if (!returns.success) {
123
+ if (returns.error) {
124
+ console.error(new Error(returns.error.message || 'Sync connections failed'));
125
+ }
126
+ return;
127
+ }
128
+ for (const data of returns.body || []) {
45
129
  // 获取适配器
46
130
  const adapter = keepAliveConnectionAdapters.get(data.adapter);
47
131
  if (!adapter)
@@ -56,6 +140,6 @@ export function syncConnections(datas) {
56
140
  if (keepAliveConnections.has(data.name, data.id))
57
141
  continue;
58
142
  // 建立连接
59
- adapter.open(data.url).catch((error) => console.error(error));
143
+ adapter.open(data).catch((error) => console.error(error));
60
144
  }
61
145
  }
@@ -1,22 +1,41 @@
1
1
  import * as oox from '../index.js';
2
2
  export class SampleKeepAliveConnectionAdapter {
3
- name;
4
3
  OOXEvent = {
5
4
  READY: 'oox:ready',
6
5
  ENABLED: 'oox:enabled',
7
6
  DISABLED: 'oox:disabled',
8
- SYNC_CONNECTIONS: 'oox:sync_connections',
7
+ REGISTRY_SYNC_CONNECTIONS: 'oox:registry:sync_connections',
8
+ REGISTRY_SUBSCRIBE: 'oox:registry:subscribe',
9
+ REGISTRY_NOTIFY: 'oox:registry:notify',
9
10
  };
10
11
  nativeEvent = {
11
12
  CONNECT: 'connect',
12
13
  DISCONNECT: 'disconnect',
13
14
  ERROR: 'error',
14
15
  };
16
+ /**
17
+ * 通知连接列表
18
+ */
19
+ ['registry:notify'](connection, datas) {
20
+ connection.nativeConnection.emit(this.OOXEvent.REGISTRY_NOTIFY, datas);
21
+ }
22
+ /**
23
+ * 订阅连接列表
24
+ */
25
+ ['registry:subscribe'](connection, query) {
26
+ connection.nativeConnection.emit(this.OOXEvent.REGISTRY_SUBSCRIBE, query);
27
+ }
15
28
  bindConnectionEvents(connection) {
16
29
  const socket = connection.nativeConnection;
17
30
  socket.on(this.OOXEvent.READY, (params) => {
18
31
  connection.ready(params);
19
- socket.emit(this.OOXEvent.SYNC_CONNECTIONS, oox.registry.syncConnections);
32
+ socket.emit(this.OOXEvent.REGISTRY_SYNC_CONNECTIONS, oox.registry.syncConnections);
33
+ });
34
+ socket.on(this.OOXEvent.REGISTRY_NOTIFY, (datas) => {
35
+ oox.registry.syncConnections({
36
+ success: true,
37
+ body: datas,
38
+ });
20
39
  });
21
40
  socket.on(this.OOXEvent.ENABLED, () => {
22
41
  connection.enabled = true;
@@ -25,23 +44,21 @@ export class SampleKeepAliveConnectionAdapter {
25
44
  connection.enabled = false;
26
45
  });
27
46
  socket.on(this.nativeEvent.DISCONNECT, (reason) => {
28
- connection.emit('disconnect');
29
47
  oox.removeKeepAliveConnection(connection);
30
48
  socket.removeAllListeners();
31
- socket.disconnect();
49
+ connection.emit('disconnect');
32
50
  });
33
51
  socket.on(this.nativeEvent.CONNECT, () => {
34
52
  connection.emit('connect');
35
53
  });
36
54
  socket.on(this.nativeEvent.ERROR, (error) => {
37
- connection.emit('error', error);
38
55
  oox.removeKeepAliveConnection(connection);
39
56
  socket.removeAllListeners();
40
- socket.disconnect();
57
+ connection.emit('error', new oox.KeepAliveConnectionError(error.message, connection));
41
58
  });
42
59
  }
43
- async open(url) {
44
- const connection = this.newConnection(url);
60
+ async open(identify) {
61
+ const connection = this.newConnection(identify);
45
62
  oox.addKeepAliveConnection(connection);
46
63
  this.bindConnectionEvents(connection);
47
64
  this.bindCall(connection);
@@ -89,7 +106,11 @@ export class SampleKeepAliveConnectionAdapter {
89
106
  async rpc(connection, action, params, context) {
90
107
  if (!context)
91
108
  context = oox.getContext();
92
- const { success, error, body } = await this.emit(connection.nativeConnection, 'call', [action, params, context]);
109
+ const miniContext = {
110
+ sourceIP: context.sourceIP,
111
+ traceId: context.traceId,
112
+ };
113
+ const { success, error, body } = await this.emit(connection.nativeConnection, 'call', [action, params, miniContext]);
93
114
  if (success)
94
115
  return body;
95
116
  else if (error)
@@ -102,20 +123,16 @@ export class SampleKeepAliveConnectionAdapter {
102
123
  * @param connection
103
124
  */
104
125
  bindCall(connection) {
105
- const { id, name, host } = connection.data;
106
- const connectionContext = {
107
- sourceIP: '',
108
- ip: host,
109
- caller: name,
110
- callerId: id,
111
- connection
112
- };
126
+ const { id, name, ip } = connection.data;
113
127
  connection.nativeConnection.on('call', async (action, params, context, callback) => {
114
- if ('object' !== typeof context)
115
- context = oox.genContext(connectionContext);
116
- else
117
- context = oox.genContext(Object.assign(context, connectionContext));
118
- this.call(action, params, context, callback);
128
+ const validContext = new oox.Context({
129
+ ...context,
130
+ ip: ip,
131
+ caller: name,
132
+ callerId: id,
133
+ connection
134
+ });
135
+ this.call(action, params, validContext, callback);
119
136
  });
120
137
  }
121
138
  async call(action, params, context, callback) {
package/types/app.d.ts CHANGED
@@ -1,20 +1,20 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  export * as logger from './logger.js';
4
- export interface ReturnsBody {
5
- traceId: string;
4
+ export interface ReturnsBody<T = any> {
5
+ traceId?: string;
6
6
  success: boolean;
7
- body?: any;
7
+ body?: T;
8
8
  error?: {
9
9
  message: string;
10
10
  stack?: string;
11
11
  };
12
12
  }
13
- export declare class Context {
13
+ export declare class AppContext {
14
14
  [x: string]: any;
15
- traceId?: string;
15
+ traceId?: string | undefined;
16
16
  }
17
- export declare const asyncStore: AsyncLocalStorage<Context>;
17
+ export declare const asyncStore: AsyncLocalStorage<AppContext>;
18
18
  export declare const eventHub: EventEmitter<[never]>;
19
19
  /**
20
20
  * the kvMethods is all actions refs [has bind this]
@@ -24,21 +24,21 @@ export declare const sourceKVMethods: Map<string, Function>;
24
24
  export declare function setMethods(methods: any): void;
25
25
  export declare function getMethods(): any;
26
26
  export declare function on(event: 'app:configured' | 'app:served' | 'app:stopped', listener: () => void): void;
27
- export declare function on(event: 'call:start', listener: (timestamp: number, action: string, params: any[], context: Context) => void): void;
28
- export declare function on(event: 'call:success', listener: (timestamp: number, action: string, params: any[], context: Context, result: ReturnsBody) => void): void;
29
- export declare function on(event: 'call:fail', listener: (timestamp: number, action: string, params: any[], context: Context, error: Error) => void): void;
30
- export declare function on(event: 'log', listener: (timestamp: number, context: Context | null, level: string, msgs: any[]) => void): void;
27
+ export declare function on(event: 'call:start', listener: (timestamp: number, action: string, params: any[], context: AppContext) => void): void;
28
+ export declare function on(event: 'call:success', listener: (timestamp: number, action: string, params: any[], context: AppContext, result: ReturnsBody) => void): void;
29
+ export declare function on(event: 'call:fail', listener: (timestamp: number, action: string, params: any[], context: AppContext, error: Error) => void): void;
30
+ export declare function on(event: 'log', listener: (timestamp: number, context: AppContext | null, level: string, msgs: any[]) => void): void;
31
31
  export declare function once(event: 'app:configured' | 'app:served' | 'app:stopped', listener: (...args: any[]) => void): void;
32
- export declare function once(event: 'call:start', listener: (timestamp: number, action: string, params: any[], context: Context) => void): void;
33
- export declare function once(event: 'call:success', listener: (timestamp: number, action: string, params: any[], context: Context, result: ReturnsBody) => void): void;
34
- export declare function once(event: 'call:fail', listener: (timestamp: number, action: string, params: any[], context: Context, error: Error) => void): void;
35
- export declare function once(event: 'log', listener: (timestamp: number, context: Context | null, level: string, msgs: any[]) => void): void;
32
+ export declare function once(event: 'call:start', listener: (timestamp: number, action: string, params: any[], context: AppContext) => void): void;
33
+ export declare function once(event: 'call:success', listener: (timestamp: number, action: string, params: any[], context: AppContext, result: ReturnsBody) => void): void;
34
+ export declare function once(event: 'call:fail', listener: (timestamp: number, action: string, params: any[], context: AppContext, error: Error) => void): void;
35
+ export declare function once(event: 'log', listener: (timestamp: number, context: AppContext | null, level: string, msgs: any[]) => void): void;
36
36
  export declare function off(event: 'app:configured' | 'app:served' | 'app:stopped' | 'call:start' | 'call:success' | 'call:fail' | 'log', listener: (...args: any[]) => void): void;
37
37
  export declare function emit(event: 'app:configured' | 'app:served' | 'app:stopped'): boolean;
38
- export declare function emit(event: 'call:start', timestamp: number, action: string, params: any[], context: Context): boolean;
39
- export declare function emit(event: 'call:success', timestamp: number, action: string, params: any[], context: Context, result: ReturnsBody): boolean;
40
- export declare function emit(event: 'call:fail', timestamp: number, action: string, params: any[], context: Context, error: Error): boolean;
41
- export declare function emit(event: 'log', timestamp: number, context: Context | null, level: string, content: any): boolean;
38
+ export declare function emit(event: 'call:start', timestamp: number, action: string, params: any[], context: AppContext): boolean;
39
+ export declare function emit(event: 'call:success', timestamp: number, action: string, params: any[], context: AppContext, result: ReturnsBody): boolean;
40
+ export declare function emit(event: 'call:fail', timestamp: number, action: string, params: any[], context: AppContext, error: Error): boolean;
41
+ export declare function emit(event: 'log', timestamp: number, context: AppContext | null, level: string, content: any): boolean;
42
42
  /**
43
43
  * Call an Function on RPC server
44
44
  * @param action
@@ -46,5 +46,5 @@ export declare function emit(event: 'log', timestamp: number, context: Context |
46
46
  * @param context
47
47
  * @returns
48
48
  */
49
- export declare function call(action: string, params: any[], context: Context): Promise<ReturnsBody>;
50
- export declare function execute(action: string, params: Array<any>, context: Context): Promise<any>;
49
+ export declare function call(action: string, params: any[] | undefined, context: AppContext): Promise<ReturnsBody>;
50
+ export declare function execute(action: string, params: Array<any>, context: AppContext): Promise<any>;
@@ -1,3 +1,5 @@
1
1
  export declare function buildConfig(mergeEnv?: {
2
2
  [x: string]: any;
3
- }): Promise<any>;
3
+ }): Promise<{
4
+ [x: string]: any;
5
+ }>;
@@ -1 +1,2 @@
1
- export declare function registry(urls: string | string[]): Promise<void>;
1
+ import * as oox from '../index.js';
2
+ export declare function registry(identifies: string[] | oox.KeepAliveConnectionData[]): Promise<void>;
@@ -1,5 +1,4 @@
1
- import * as oox from '../index.js';
2
1
  export declare function configure(env?: {
3
2
  [x: string]: any;
4
- }, entryFilename?: string): Promise<oox.Config>;
3
+ }, entryFilename?: string): Promise<import("../config.js").Config>;
5
4
  export declare function startup(): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import { KeepAliveConnectionData } from "./keepalive-connection.js";
2
+ export interface ConfigAllow {
3
+ untrusted: boolean;
4
+ ip: string[];
5
+ caller: string[];
6
+ }
7
+ interface ConfigInterface {
8
+ id: string;
9
+ name: string;
10
+ group: string;
11
+ ignore: string[];
12
+ entryInfo: {
13
+ path: string;
14
+ group: string;
15
+ };
16
+ host: string;
17
+ port: number;
18
+ origin: string | string[];
19
+ errorStack: boolean;
20
+ isRegistry: boolean;
21
+ registry: string[] | KeepAliveConnectionData[];
22
+ registryToken: string;
23
+ registryAdapter: string;
24
+ token: string;
25
+ allow: ConfigAllow;
26
+ }
27
+ export declare class Config implements ConfigInterface {
28
+ [x: string]: any;
29
+ id: string;
30
+ name: string;
31
+ group: string;
32
+ ignore: string[];
33
+ entryInfo: {
34
+ path: string;
35
+ group: string;
36
+ };
37
+ host: string;
38
+ port: number;
39
+ origin: string | string[];
40
+ errorStack: boolean;
41
+ isRegistry: boolean;
42
+ registry: string[] | KeepAliveConnectionData[];
43
+ registryToken: string;
44
+ registryAdapter: string;
45
+ token: string;
46
+ allow: ConfigAllow;
47
+ }
48
+ type StrictFormatter<T> = {
49
+ [K in keyof T]: (value: any) => T[K];
50
+ };
51
+ export declare const formatters: StrictFormatter<ConfigInterface> & {
52
+ [x: string]: (v: any) => any;
53
+ };
54
+ export {};
package/types/index.d.ts CHANGED
@@ -1,33 +1,21 @@
1
- import * as app from './app.js';
1
+ import { AppContext } from './app.js';
2
2
  import * as registry from './registry.js';
3
+ import { Config } from './config.js';
3
4
  import Module, { ModuleConfig } from './modules/module.js';
4
- import { KeepAliveConnectionReadyParams, KeepAliveConnectionAdapter, KeepAliveConnection, KeepAliveConnectionData, keepAliveConnectionAdapters, keepAliveConnections, enabledKeepAliveConnections } from './keepalive-connection.js';
5
- export declare class Context extends app.Context {
5
+ import { KeepAliveConnection, KeepAliveNativeConnection } from './keepalive-connection.js';
6
+ export interface KeepAliveRPCContext {
7
+ traceId?: string;
8
+ sourceIP?: string;
9
+ }
10
+ export declare class Context extends AppContext {
6
11
  sourceIP: string;
7
12
  ip: string;
8
13
  caller: string;
9
14
  callerId: string;
10
- connection?: KeepAliveConnection<any>;
15
+ connection?: KeepAliveConnection<KeepAliveNativeConnection>;
16
+ constructor(context?: Partial<Context>);
11
17
  toJSON?(): {} & this;
12
18
  }
13
- export declare class Config {
14
- [x: string]: any;
15
- id: `${string}-${string}-${string}-${string}-${string}`;
16
- name: string;
17
- group: string;
18
- ignore: string[];
19
- entryInfo: {
20
- path: string;
21
- group: string;
22
- };
23
- host: string;
24
- port: number;
25
- origin: string | string[];
26
- errorStack: boolean;
27
- isRegistry: boolean;
28
- registry: string[];
29
- registryAdapter: string;
30
- }
31
19
  export declare const config: Config;
32
20
  export declare function setGenTraceIdFunction(fn: () => string): void;
33
21
  /**
@@ -41,16 +29,31 @@ export declare function genContext(context?: Context): Context;
41
29
  export declare function getContext(): Context;
42
30
  export declare function serve(): Promise<void>;
43
31
  export declare function stop(): Promise<void>;
44
- export declare function addKeepAliveConnection(connection: KeepAliveConnection<any>): void;
45
- export declare function removeKeepAliveConnection(connection: KeepAliveConnection<any>): void;
32
+ /**
33
+ * 检查连接是否被允许
34
+ * @param ip 连接主机 IP
35
+ * @param caller 连接服务名称
36
+ * @param token 令牌
37
+ * @returns 是否被允许
38
+ */
39
+ export declare function checkAllow(ip: string, caller: string, token: string): {
40
+ allow: boolean;
41
+ reason?: string;
42
+ };
43
+ /**
44
+ * 添加长连接
45
+ * @throws {KeepAliveConnectionError} 连接已存在
46
+ * @param connection
47
+ */
48
+ export declare function addKeepAliveConnection(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
49
+ export declare function removeKeepAliveConnection(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
46
50
  export declare function removeKeepAliveConnection(name: string, id: string): void;
47
- export declare function setLoadBalancePolicy(policy: (name: string) => KeepAliveConnection<any>): void;
51
+ export declare function setLoadBalancePolicy(policy: (name: string) => KeepAliveConnection<KeepAliveNativeConnection>): void;
48
52
  export declare function rpc(appName: string, action: string, params: any[], context?: Context): Promise<any>;
49
- export declare function rpc(connection: KeepAliveConnection<any>, action: string, params: any[], context?: Context): Promise<any>;
50
- export { KeepAliveConnectionReadyParams, KeepAliveConnectionAdapter, KeepAliveConnection, KeepAliveConnectionData, keepAliveConnectionAdapters, keepAliveConnections, enabledKeepAliveConnections };
51
- export { ReturnsBody } from './app.js';
53
+ export declare function rpc(connection: KeepAliveConnection<KeepAliveNativeConnection>, action: string, params: any[], context?: Context): Promise<any>;
54
+ export * from './app.js';
55
+ export * from './keepalive-connection.js';
52
56
  export { Module, ModuleConfig };
53
57
  export { registry };
54
- export declare const asyncStore: import("async_hooks").AsyncLocalStorage<app.Context>, setMethods: typeof app.setMethods, getMethods: typeof app.getMethods, kvMethods: Map<string, Function>, sourceKVMethods: Map<string, Function>, call: typeof app.call, execute: typeof app.execute, logger: typeof app.logger, on: typeof app.on, once: typeof app.once, off: typeof app.off, emit: typeof app.emit;
55
- import Modules from './modules/index.js';
56
- export declare const modules: Modules;
58
+ import * as modules from './modules/index.js';
59
+ export { modules };
@@ -1,14 +1,33 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { Context } from './index.js';
3
3
  type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
- export interface KeepAliveConnectionAdapter<T> {
4
+ export declare class KeepAliveConnectionError extends Error {
5
+ connection: KeepAliveConnection<KeepAliveNativeConnection>;
6
+ constructor(message: string, connection: KeepAliveConnection<KeepAliveNativeConnection>);
7
+ }
8
+ export interface KeepAliveNativeConnection {
9
+ disconnect(): void;
10
+ }
11
+ export interface KeepAliveSyncConnectionsQuery {
12
+ [x: string]: any;
13
+ name?: string | string[];
14
+ }
15
+ export interface KeepAliveConnectionAdapter<T extends KeepAliveNativeConnection> {
5
16
  /**
6
17
  * 连接适配器名称
7
18
  */
8
19
  name: string;
9
- open(url: string | URL): Promise<KeepAliveConnection<T>>;
20
+ open(identify: string | URL | KeepAliveConnectionData): Promise<KeepAliveConnection<T>>;
10
21
  close(connection: KeepAliveConnection<T>): Promise<void>;
11
22
  rpc(connection: KeepAliveConnection<T>, action: string, params: any[], context: Context): Promise<any>;
23
+ /**
24
+ * 通知连接列表
25
+ */
26
+ ['registry:notify'](connection: KeepAliveConnection<T>, datas: KeepAliveConnectionData[]): void;
27
+ /**
28
+ * 订阅连接列表
29
+ */
30
+ ['registry:subscribe'](connection: KeepAliveConnection<T>, query: KeepAliveSyncConnectionsQuery): void;
12
31
  }
13
32
  export interface KeepAliveConnectionData {
14
33
  /**
@@ -18,7 +37,7 @@ export interface KeepAliveConnectionData {
18
37
  /**
19
38
  * 连接主机地址
20
39
  */
21
- host: string;
40
+ ip: string;
22
41
  /**
23
42
  * 连接服务名称
24
43
  */
@@ -31,21 +50,26 @@ export interface KeepAliveConnectionData {
31
50
  * 目标服务网络唯一ID
32
51
  */
33
52
  id: string;
53
+ /**
54
+ * 验证令牌
55
+ */
56
+ token: string;
34
57
  }
35
58
  export interface KeepAliveConnectionReadyParams {
36
59
  [x: string]: any;
37
60
  id: KeepAliveConnectionData['id'];
38
61
  name: KeepAliveConnectionData['name'];
39
62
  }
40
- export type KeepAliveConnectionEventMap = Record<keyof {
41
- "enabled": any;
42
- "disabled": any;
43
- "connect": any;
44
- "disconnect": any;
45
- 'error': any;
46
- }, any[]>;
47
- export declare class KeepAliveConnection<T> extends EventEmitter<KeepAliveConnectionEventMap> {
63
+ interface KeepAliveConnectionEventMap<T> {
64
+ "enabled": [];
65
+ "disabled": [];
66
+ "connect": [];
67
+ "disconnect": [];
68
+ 'error': [KeepAliveConnectionError];
69
+ }
70
+ export declare class KeepAliveConnection<T extends KeepAliveNativeConnection> extends EventEmitter<KeepAliveConnectionEventMap<KeepAliveConnection<T>>> {
48
71
  #private;
72
+ isRegistry: boolean;
49
73
  data: KeepAliveConnectionData;
50
74
  nativeConnection: T;
51
75
  adapter: KeepAliveConnectionAdapter<T>;
@@ -62,8 +86,9 @@ export declare class KeepAliveConnection<T> extends EventEmitter<KeepAliveConnec
62
86
  * @returns
63
87
  */
64
88
  ready(params: KeepAliveConnectionReadyParams): void;
89
+ disconnect(): void;
65
90
  }
66
- export declare class KeepAliveConnectionStore<T> {
91
+ export declare class KeepAliveConnectionStore<T extends KeepAliveNativeConnection> {
67
92
  #private;
68
93
  entries(): MapIterator<[string, Map<string, KeepAliveConnection<T>>]>;
69
94
  getConnectionsOfService(name: string): Map<string, KeepAliveConnection<T>>;
@@ -73,7 +98,7 @@ export declare class KeepAliveConnectionStore<T> {
73
98
  remove(connection: KeepAliveConnection<T>): void;
74
99
  remove(name: string, id: string): void;
75
100
  }
76
- export declare const keepAliveConnectionAdapters: Map<string, KeepAliveConnectionAdapter<any>>;
77
- export declare const keepAliveConnections: KeepAliveConnectionStore<any>;
78
- export declare const enabledKeepAliveConnections: KeepAliveConnectionStore<any>;
101
+ export declare const keepAliveConnectionAdapters: Map<string, KeepAliveConnectionAdapter<KeepAliveNativeConnection>>;
102
+ export declare const keepAliveConnections: KeepAliveConnectionStore<KeepAliveNativeConnection>;
103
+ export declare const enabledKeepAliveConnections: KeepAliveConnectionStore<KeepAliveNativeConnection>;
79
104
  export {};
@@ -1,8 +1,9 @@
1
1
  import * as http from 'node:http';
2
+ import * as https from 'node:https';
2
3
  import Router, { Middleware } from './router.js';
3
- import * as oox from '../../index.js';
4
4
  import Module, { ModuleConfig } from '../module.js';
5
- export declare class HTTPConfig extends ModuleConfig {
5
+ export declare class HTTPConfig implements ModuleConfig {
6
+ enabled: boolean;
6
7
  port: number;
7
8
  path: string;
8
9
  origin: string | string[];
@@ -16,7 +17,7 @@ export declare class HTTPConfig extends ModuleConfig {
16
17
  export default class HTTPModule extends Module {
17
18
  name: string;
18
19
  config: HTTPConfig;
19
- server: http.Server;
20
+ server: http.Server | https.Server | null;
20
21
  router: Router;
21
22
  getURL(): URL;
22
23
  get(path: string, ...args: any[]): this;
@@ -58,8 +59,4 @@ export default class HTTPModule extends Module {
58
59
  stack?: any;
59
60
  };
60
61
  }): void;
61
- /**
62
- * HTTP RPC
63
- */
64
- rpc(url: string | URL, action: string, params: Array<any>, context?: oox.Context): Promise<any>;
65
62
  }
@@ -1,24 +1,39 @@
1
1
  import Module from './module.js';
2
2
  import HTTP from './http/index.js';
3
3
  import SocketIO from './socketio/index.js';
4
- export default class Modules extends Module {
5
- #private;
6
- /**
7
- * the module unique name
8
- */
9
- name: string;
10
- /**
11
- * all builtin modules
12
- */
13
- builtins: {
14
- http: HTTP;
15
- socketio: SocketIO;
16
- };
17
- constructor();
18
- add(module: Module): this;
19
- get(name: string): Module;
20
- remove(name: string): Promise<void>;
21
- setConfig(config: any): void;
22
- serve(): Promise<void>;
23
- stop(): Promise<void>;
24
- }
4
+ /**
5
+ * FIFO queue for modules starting
6
+ */
7
+ export declare const queue: Module[];
8
+ /**
9
+ * all modules map
10
+ */
11
+ export declare const map: Map<string, Module>;
12
+ /**
13
+ * add module to modules queue
14
+ */
15
+ export declare function add(module: Module): void;
16
+ /**
17
+ * get module by name
18
+ */
19
+ export declare function get(name: string): Module | null;
20
+ export declare function remove(name: string): Promise<void>;
21
+ /**
22
+ * set modules config
23
+ */
24
+ export declare function setConfig(config: any): void;
25
+ /**
26
+ * serve modules
27
+ */
28
+ export declare function serve(): Promise<void>;
29
+ /**
30
+ * stop all modules
31
+ */
32
+ export declare function stop(): Promise<void>;
33
+ /**
34
+ * all builtin modules
35
+ */
36
+ export declare const builtins: {
37
+ http: HTTP;
38
+ socketio: SocketIO;
39
+ };