oox 0.3.8 → 0.3.10

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/bin/register.js CHANGED
@@ -43,8 +43,9 @@ async function connect(identify, prevError = null) {
43
43
  onConnection(connection);
44
44
  }
45
45
  catch (error) {
46
- if (!prevError)
47
- console.error(chalk.red('[Registry]'), chalk.underline.red(`${url}`), 'error.');
46
+ if (!prevError || String(prevError) !== String(error)) {
47
+ console.error(chalk.red('[Registry]'), chalk.underline.red(`${url}`), String(error));
48
+ }
48
49
  await delay(2000);
49
50
  connect(identify, error);
50
51
  }
package/bin/starter.js CHANGED
@@ -10,8 +10,16 @@ function getEntryInfo(env, entryFilename) {
10
10
  const args = process.argv.slice(2);
11
11
  entryFilename = args.find(arg => !arg.includes('=') && entryMatchRegExp.test(arg));
12
12
  }
13
- if (!entryFilename)
14
- throw new Error('Cannot find entry file: ' + entryFilename);
13
+ if (!entryFilename) {
14
+ if (env.entryInfo && env.entryInfo.path) {
15
+ entryFilename = env.entryInfo.path;
16
+ }
17
+ }
18
+ if (!entryFilename) {
19
+ // 允许无服务入口启动
20
+ return { name: '', path: '', group: '' };
21
+ // throw new Error ( 'Cannot find entry file: ' + entryFilename )
22
+ }
15
23
  const fullPath = path.resolve(entryFilename);
16
24
  const filename = path.basename(fullPath);
17
25
  const fullDirectory = path.dirname(fullPath);
@@ -32,10 +40,10 @@ async function loadEntry(name, entryPath) {
32
40
  export async function configure(env, entryFilename) {
33
41
  // 加载环境变量
34
42
  env = await buildConfig(env);
35
- Object.assign(oox.config, env);
36
43
  // 获取服务入口地址
37
44
  const entryInfo = getEntryInfo(env, entryFilename);
38
45
  oox.config.name = entryInfo.name;
46
+ Object.assign(oox.config, env);
39
47
  oox.config.entryInfo = {
40
48
  path: entryInfo.path.replace(/\\/g, '/'),
41
49
  group: entryInfo.group.replace(/\\/g, '/'),
@@ -52,8 +60,11 @@ export async function configure(env, entryFilename) {
52
60
  }
53
61
  export async function startup() {
54
62
  const { config } = oox;
55
- // 加载服务
56
- await loadEntry(config.name, config.entryInfo.path);
63
+ // 允许无服务入口启动
64
+ if (config.entryInfo.path) {
65
+ // 加载服务
66
+ await loadEntry(config.name, config.entryInfo.path);
67
+ }
57
68
  // 服务启动
58
69
  await oox.serve();
59
70
  // 服务启动完成
@@ -1,5 +1,6 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { getContext } from './context.js';
3
+ import { emit } from './app.js';
3
4
  export class KeepAliveConnectionError extends Error {
4
5
  connection;
5
6
  constructor(message, connection) {
@@ -22,6 +23,12 @@ export class KeepAliveConnection extends EventEmitter {
22
23
  this.data = Object.assign(data, {
23
24
  adapter: adapter.name,
24
25
  });
26
+ this.on('connect', () => {
27
+ emit('keepalive:connect', this);
28
+ });
29
+ this.on('disconnect', () => {
30
+ emit('keepalive:disconnect', this);
31
+ });
25
32
  }
26
33
  /**
27
34
  * 设置连接是否可用,并自动触发enabled或disabled事件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oox",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "OOX Service Engine",
5
5
  "keywords": [
6
6
  "http",
package/types/app.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
+ import { KeepAliveConnection, KeepAliveNativeConnection } from './keepalive-connection.js';
2
3
  import { AppContext } from './context.js';
3
4
  export interface ReturnsBody<T = any> {
4
5
  traceId?: string;
@@ -22,17 +23,23 @@ export declare function on(event: 'call:start', listener: (timestamp: number, ac
22
23
  export declare function on(event: 'call:success', listener: (timestamp: number, action: string, params: any[], context: AppContext, result: ReturnsBody) => void): void;
23
24
  export declare function on(event: 'call:fail', listener: (timestamp: number, action: string, params: any[], context: AppContext, error: Error) => void): void;
24
25
  export declare function on(event: 'log', listener: (timestamp: number, context: AppContext | null, level: string, msgs: any[]) => void): void;
26
+ export declare function on(event: 'keepalive:connect', listener: (conn: KeepAliveConnection<KeepAliveNativeConnection>) => void): void;
27
+ export declare function on(event: 'keepalive:disconnect', listener: (conn: KeepAliveConnection<KeepAliveNativeConnection>) => void): void;
25
28
  export declare function once(event: 'app:configured' | 'app:served' | 'app:stopped', listener: (...args: any[]) => void): void;
26
29
  export declare function once(event: 'call:start', listener: (timestamp: number, action: string, params: any[], context: AppContext) => void): void;
27
30
  export declare function once(event: 'call:success', listener: (timestamp: number, action: string, params: any[], context: AppContext, result: ReturnsBody) => void): void;
28
31
  export declare function once(event: 'call:fail', listener: (timestamp: number, action: string, params: any[], context: AppContext, error: Error) => void): void;
29
32
  export declare function once(event: 'log', listener: (timestamp: number, context: AppContext | null, level: string, msgs: any[]) => void): void;
30
- export declare function off(event: 'app:configured' | 'app:served' | 'app:stopped' | 'call:start' | 'call:success' | 'call:fail' | 'log', listener: (...args: any[]) => void): void;
33
+ export declare function once(event: 'keepalive:connect', listener: (conn: KeepAliveConnection<KeepAliveNativeConnection>) => void): void;
34
+ export declare function once(event: 'keepalive:disconnect', listener: (conn: KeepAliveConnection<KeepAliveNativeConnection>) => void): void;
35
+ export declare function off(event: 'app:configured' | 'app:served' | 'app:stopped' | 'call:start' | 'call:success' | 'call:fail' | 'log' | 'keepalive:connect' | 'keepalive:disconnect', listener: (...args: any[]) => void): void;
31
36
  export declare function emit(event: 'app:configured' | 'app:served' | 'app:stopped'): boolean;
32
37
  export declare function emit(event: 'call:start', timestamp: number, action: string, params: any[], context: AppContext): boolean;
33
38
  export declare function emit(event: 'call:success', timestamp: number, action: string, params: any[], context: AppContext, result: ReturnsBody): boolean;
34
39
  export declare function emit(event: 'call:fail', timestamp: number, action: string, params: any[], context: AppContext, error: Error): boolean;
35
40
  export declare function emit(event: 'log', timestamp: number, context: AppContext | null, level: string, content: any): boolean;
41
+ export declare function emit(event: 'keepalive:connect', conn: KeepAliveConnection<KeepAliveNativeConnection>): boolean;
42
+ export declare function emit(event: 'keepalive:disconnect', conn: KeepAliveConnection<KeepAliveNativeConnection>): boolean;
36
43
  /**
37
44
  * Call an Function on RPC server
38
45
  * @param action