alemonjs 2.1.82 → 2.1.83-alpha.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/lib/{app → application}/define-children.js +2 -1
- package/lib/{app → application/format}/message-api.d.ts +2 -2
- package/lib/{app → application/format}/message-api.js +12 -4
- package/lib/{app → application/format}/message-format-old.d.ts +1 -1
- package/lib/{app → application/format}/message-format.d.ts +1 -2
- package/lib/{app → application/format}/message-format.js +0 -2
- package/lib/{app/hook-use → application/hooks}/announce.js +4 -3
- package/lib/{app/hook-use → application/hooks}/channel.js +4 -3
- package/lib/{app/hook-use → application/hooks}/client.d.ts +1 -1
- package/lib/{app/hook-use → application/hooks}/client.js +4 -11
- package/lib/{app/hook-use → application/hooks}/common.d.ts +7 -7
- package/lib/{app/hook-use → application/hooks}/common.js +9 -8
- package/lib/{app/hook-use → application/hooks}/event.js +1 -1
- package/lib/{app/hook-use → application/hooks}/guild.js +4 -3
- package/lib/{app/hook-use → application/hooks}/history.js +4 -3
- package/lib/{app/hook-use → application/hooks}/me.js +12 -7
- package/lib/{app/hook-use → application/hooks}/media.d.ts +3 -3
- package/lib/{app/hook-use → application/hooks}/media.js +4 -3
- package/lib/{app/hook-use → application/hooks}/member.js +4 -3
- package/lib/{app/hook-use → application/hooks}/mention.js +4 -3
- package/lib/{app/hook-use → application/hooks}/message.js +6 -5
- package/lib/{app/hook-use → application/hooks}/permission.js +4 -3
- package/lib/{app/hook-use → application/hooks}/reaction.js +4 -3
- package/lib/{app/hook-use → application/hooks}/request.js +12 -7
- package/lib/{app/hook-use → application/hooks}/role.js +4 -3
- package/lib/{app/hook-use → application/hooks}/subscribe.js +6 -4
- package/lib/{app/hook-use → application/hooks}/user.js +12 -7
- package/lib/application/index.d.ts +12 -0
- package/lib/application/index.js +32 -0
- package/lib/{app → application}/router/dsl.d.ts +1 -1
- package/lib/{app → application}/router/dsl.js +13 -9
- package/lib/{cbp → application/runtime/cbp}/connects/client.d.ts +1 -1
- package/lib/{cbp → application/runtime/cbp}/connects/client.js +43 -50
- package/lib/application/runtime/cbp/index.d.ts +3 -0
- package/lib/application/runtime/cbp/index.js +3 -0
- package/lib/application/runtime/cbp/processor/actions.d.ts +3 -0
- package/lib/application/runtime/cbp/processor/actions.js +58 -0
- package/lib/application/runtime/cbp/processor/api.d.ts +3 -0
- package/lib/application/runtime/cbp/processor/api.js +58 -0
- package/lib/application/runtime/cbp/processor/request-registry.d.ts +8 -0
- package/lib/application/runtime/cbp/processor/request-registry.js +6 -0
- package/lib/application/runtime/client-runtime.d.ts +1 -0
- package/lib/application/runtime/client-runtime.js +95 -0
- package/lib/application/runtime/event-error.d.ts +2 -0
- package/lib/application/runtime/event-error.js +20 -0
- package/lib/{app → application/runtime}/event-group.d.ts +1 -1
- package/lib/{app → application/runtime}/event-middleware.d.ts +1 -1
- package/lib/{app → application/runtime}/event-middleware.js +1 -1
- package/lib/application/runtime/event-processor-callHandler.d.ts +5 -0
- package/lib/{app → application/runtime}/event-processor-callHandler.js +26 -3
- package/lib/{app → application/runtime}/event-processor-cycle.d.ts +1 -1
- package/lib/{app → application/runtime}/event-processor-cycleFiles.d.ts +5 -2
- package/lib/{app → application/runtime}/event-processor-cycleFiles.js +23 -8
- package/lib/application/runtime/event-processor-cycleRoute.d.ts +5 -0
- package/lib/{app → application/runtime}/event-processor-cycleRoute.js +25 -4
- package/lib/{app → application/runtime}/event-processor-event.d.ts +1 -1
- package/lib/{app → application/runtime}/event-processor-event.js +2 -2
- package/lib/{app → application/runtime}/event-processor-middleware.d.ts +1 -1
- package/lib/{app → application/runtime}/event-processor-middleware.js +2 -2
- package/lib/{app → application/runtime}/event-processor-subscribe.d.ts +1 -1
- package/lib/{app → application/runtime}/event-processor-subscribe.js +40 -5
- package/lib/{app → application/runtime}/event-processor.d.ts +1 -1
- package/lib/{app → application/runtime}/event-processor.js +10 -4
- package/lib/{app → application/runtime}/event-response.d.ts +1 -1
- package/lib/{app → application/runtime}/event-utils.d.ts +1 -1
- package/lib/{app → application/runtime}/event-utils.js +2 -2
- package/lib/{app → application/runtime}/hook-event-context.d.ts +8 -4
- package/lib/{app → application/runtime}/hook-event-context.js +26 -7
- package/lib/application/runtime/http/index.d.ts +4 -0
- package/lib/application/runtime/http/index.js +4 -0
- package/lib/{server → application/runtime/http}/routers/hello.html.js +1 -1
- package/lib/{server → application/runtime/http}/routers/middleware.js +1 -2
- package/lib/{server → application/runtime/http}/routers/router.js +121 -20
- package/lib/{server → application/runtime/http}/routers/utils.d.ts +1 -1
- package/lib/{server → application/runtime/http}/routers/utils.js +6 -6
- package/lib/{server/main.js → application/runtime/http-server.js} +2 -6
- package/lib/application/runtime/lifecycle-callbacks.d.ts +14 -0
- package/lib/application/runtime/lifecycle-callbacks.js +94 -0
- package/lib/{app/load_modules → application/runtime/load-modules}/load.js +2 -2
- package/lib/{app/load_modules → application/runtime/load-modules}/loadChild.js +16 -13
- package/lib/{app → application/runtime}/schedule-store.d.ts +1 -1
- package/lib/{app → application/runtime}/schedule-store.js +1 -1
- package/lib/{app → application/runtime}/store.d.ts +14 -17
- package/lib/{app → application/runtime}/store.js +38 -107
- package/lib/application/schedule.d.ts +17 -0
- package/lib/{app/api → application}/schedule.js +1 -1
- package/lib/client.d.ts +1 -1
- package/lib/client.js +1 -113
- package/lib/common/cbp/constants.d.ts +11 -0
- package/lib/common/cbp/constants.js +13 -0
- package/lib/{cbp/connects/connect.js → common/cbp/heartbeat.js} +3 -6
- package/lib/common/cbp/normalize.d.ts +16 -0
- package/lib/common/cbp/normalize.js +324 -0
- package/lib/common/cbp/runtime.d.ts +2 -0
- package/lib/common/cbp/runtime.js +10 -0
- package/lib/common/cbp/typings.d.ts +159 -0
- package/lib/{cbp/connects/base.js → common/cbp/ws-connector.js} +7 -9
- package/lib/{core → common}/config.d.ts +5 -5
- package/lib/{core → common}/config.js +5 -4
- package/lib/common/identity.d.ts +11 -0
- package/lib/common/identity.js +34 -0
- package/lib/common/index.d.ts +15 -0
- package/lib/common/index.js +14 -0
- package/lib/common/logger.d.ts +6 -0
- package/lib/common/logger.js +99 -0
- package/lib/common/result.d.ts +7 -0
- package/lib/common/result.js +19 -0
- package/lib/{core → common}/utils.d.ts +3 -18
- package/lib/{core → common}/utils.js +6 -49
- package/lib/{core → common}/variable.js +1 -1
- package/lib/core/cbp/index.d.ts +1 -0
- package/lib/core/cbp/index.js +1 -0
- package/lib/core/cbp/processor/config.d.ts +8 -0
- package/lib/core/cbp/processor/config.js +29 -0
- package/lib/{cbp → core/cbp}/routers/hello.html.js +1 -1
- package/lib/{cbp → core/cbp}/server/main.js +37 -33
- package/lib/{cbp → core/cbp}/server/testone.d.ts +1 -1
- package/lib/{cbp → core/cbp}/server/testone.js +8 -2
- package/lib/core/index.d.ts +1 -3
- package/lib/core/index.js +1 -3
- package/lib/core/process/index.d.ts +3 -0
- package/lib/{process → core/process}/index.js +0 -1
- package/lib/{process → core/process}/ipc-bridge.js +6 -1
- package/lib/{process → core/process}/module.js +13 -4
- package/lib/{process → core/process}/platform.js +12 -3
- package/lib/core/start.d.ts +2 -0
- package/lib/core/start.js +76 -0
- package/lib/global.d.ts +4 -3
- package/lib/index.d.ts +5 -4
- package/lib/index.js +9 -54
- package/lib/main.d.ts +1 -2
- package/lib/main.js +1 -76
- package/lib/{cbp/connects/platform.d.ts → platform/cbp-platform.d.ts} +2 -2
- package/lib/{cbp/connects/platform.js → platform/cbp-platform.js} +52 -75
- package/lib/{app → platform}/define-platform.js +2 -0
- package/lib/platform/event-value.d.ts +7 -0
- package/lib/platform/event-value.js +5 -0
- package/lib/platform/index.d.ts +5 -0
- package/lib/platform/index.js +5 -0
- package/lib/types/actions.d.ts +20 -1
- package/lib/types/apis.d.ts +2 -1
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/cycle/index.d.ts +50 -0
- package/lib/types/event/index.d.ts +2 -1
- package/lib/types/subscribe/index.d.ts +2 -1
- package/package.json +22 -1
- package/lib/app/api/schedule.d.ts +0 -17
- package/lib/app/event-processor-callHandler.d.ts +0 -1
- package/lib/app/event-processor-cycleRoute.d.ts +0 -2
- package/lib/app/index.d.ts +0 -25
- package/lib/app/index.js +0 -47
- package/lib/cbp/index.d.ts +0 -3
- package/lib/cbp/index.js +0 -3
- package/lib/cbp/processor/actions.d.ts +0 -3
- package/lib/cbp/processor/actions.js +0 -48
- package/lib/cbp/processor/api.d.ts +0 -3
- package/lib/cbp/processor/api.js +0 -48
- package/lib/cbp/processor/config.d.ts +0 -29
- package/lib/cbp/processor/config.js +0 -52
- package/lib/cbp/typings.d.ts +0 -20
- package/lib/process/index.d.ts +0 -4
- /package/lib/{app → application}/define-children.d.ts +0 -0
- /package/lib/{app → application}/define-middleware.d.ts +0 -0
- /package/lib/{app → application}/define-middleware.js +0 -0
- /package/lib/{app → application}/define-response.d.ts +0 -0
- /package/lib/{app → application}/define-response.js +0 -0
- /package/lib/{app → application}/define-router.d.ts +0 -0
- /package/lib/{app → application}/define-router.js +0 -0
- /package/lib/{app → application}/expose.d.ts +0 -0
- /package/lib/{app → application}/expose.js +0 -0
- /package/lib/{app → application/format}/message-format-old.js +0 -0
- /package/lib/{app/hook-use → application/hooks}/announce.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/channel.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/event.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/guild.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/history.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/index.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/index.js +0 -0
- /package/lib/{app/hook-use → application/hooks}/me.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/member.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/mention.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/message.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/permission.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/reaction.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/request.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/role.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/route.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/route.js +0 -0
- /package/lib/{app/hook-use → application/hooks}/subscribe.d.ts +0 -0
- /package/lib/{app/hook-use → application/hooks}/user.d.ts +0 -0
- /package/lib/{app → application}/router/fallback.d.ts +0 -0
- /package/lib/{app → application}/router/fallback.js +0 -0
- /package/lib/{app → application}/router/main.d.ts +0 -0
- /package/lib/{app → application}/router/main.js +0 -0
- /package/lib/{app → application}/router/parser.d.ts +0 -0
- /package/lib/{app → application}/router/parser.js +0 -0
- /package/lib/{app → application}/router/types.d.ts +0 -0
- /package/lib/{app → application}/router/types.js +0 -0
- /package/lib/{app → application}/router/validator.d.ts +0 -0
- /package/lib/{app → application}/router/validator.js +0 -0
- /package/lib/{cbp → application/runtime/cbp}/processor/transport.d.ts +0 -0
- /package/lib/{cbp → application/runtime/cbp}/processor/transport.js +0 -0
- /package/lib/{app → application/runtime}/event-group.js +0 -0
- /package/lib/{app → application/runtime}/event-processor-cycle.js +0 -0
- /package/lib/{app → application/runtime}/event-response.js +0 -0
- /package/lib/{cbp → application/runtime/http}/routers/hello.html.d.ts +0 -0
- /package/lib/{server → application/runtime/http}/routers/middleware.d.ts +0 -0
- /package/lib/{cbp → application/runtime/http}/routers/router.d.ts +0 -0
- /package/lib/{server/main.d.ts → application/runtime/http-server.d.ts} +0 -0
- /package/lib/{app/load_modules → application/runtime/load-modules}/index.d.ts +0 -0
- /package/lib/{app/load_modules → application/runtime/load-modules}/index.js +0 -0
- /package/lib/{app/load_modules → application/runtime/load-modules}/load.d.ts +0 -0
- /package/lib/{app/load_modules → application/runtime/load-modules}/loadChild.d.ts +0 -0
- /package/lib/{app/config.d.ts → application/runtime/subscribe-status.d.ts} +0 -0
- /package/lib/{app/config.js → application/runtime/subscribe-status.js} +0 -0
- /package/lib/{app → common}/SinglyLinkedList.d.ts +0 -0
- /package/lib/{app → common}/SinglyLinkedList.js +0 -0
- /package/lib/{cbp/connects/connect.d.ts → common/cbp/heartbeat.d.ts} +0 -0
- /package/lib/{cbp → common/cbp}/typings.js +0 -0
- /package/lib/{cbp/connects/base.d.ts → common/cbp/ws-connector.d.ts} +0 -0
- /package/lib/{process → common}/direct-channel.d.ts +0 -0
- /package/lib/{process → common}/direct-channel.js +0 -0
- /package/lib/{core → common}/react.d.ts +0 -0
- /package/lib/{core → common}/react.js +0 -0
- /package/lib/{core → common}/variable.d.ts +0 -0
- /package/lib/{server → core/cbp}/routers/hello.html.d.ts +0 -0
- /package/lib/{server → core/cbp}/routers/router.d.ts +0 -0
- /package/lib/{cbp → core/cbp}/routers/router.js +0 -0
- /package/lib/{cbp → core/cbp}/server/main.d.ts +0 -0
- /package/lib/{process → core/process}/ipc-bridge.d.ts +0 -0
- /package/lib/{process → core/process}/module.d.ts +0 -0
- /package/lib/{process → core/process}/platform.d.ts +0 -0
- /package/lib/{app → platform}/define-platform.d.ts +0 -0
- /package/lib/{app → platform}/event-format.d.ts +0 -0
- /package/lib/{app → platform}/event-format.js +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { showErrorModule } from '../../common/utils.js';
|
|
2
|
+
|
|
3
|
+
const swallowLifecycleError = (error) => {
|
|
4
|
+
showErrorModule(error instanceof Error ? error : new Error(typeof error === 'string' ? error : 'Unknown lifecycle error'));
|
|
5
|
+
};
|
|
6
|
+
const getChildrenApps = () => {
|
|
7
|
+
return Object.values(global.alemonjsCore?.storeChildrenApp ?? {});
|
|
8
|
+
};
|
|
9
|
+
const getChildrenApp = (name) => {
|
|
10
|
+
return global.alemonjsCore?.storeChildrenApp?.[name] ?? null;
|
|
11
|
+
};
|
|
12
|
+
const dispatchEventStart = async (context) => {
|
|
13
|
+
const apps = getChildrenApps();
|
|
14
|
+
for (const app of apps) {
|
|
15
|
+
try {
|
|
16
|
+
await app.cycle?.onEventStart?.(context);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
swallowLifecycleError(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const dispatchEventFinished = async (context) => {
|
|
24
|
+
const apps = getChildrenApps();
|
|
25
|
+
for (const app of apps) {
|
|
26
|
+
try {
|
|
27
|
+
await app.cycle?.onEventFinished?.(context);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
swallowLifecycleError(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const dispatchHttpError = async (context) => {
|
|
35
|
+
const app = getChildrenApp(context.appName);
|
|
36
|
+
const handler = app?.cycle?.onHttpError;
|
|
37
|
+
if (!handler) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const result = await handler(context);
|
|
42
|
+
return result === 'handled';
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
swallowLifecycleError(error);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const dispatchRuntimeStatusChange = async (context) => {
|
|
50
|
+
const app = getChildrenApp(context.appName);
|
|
51
|
+
const handler = app?.cycle?.onRuntimeStatusChange;
|
|
52
|
+
if (!handler) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await handler(context);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
swallowLifecycleError(error);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const dispatchAppReady = async (appName, store) => {
|
|
63
|
+
const app = getChildrenApp(appName);
|
|
64
|
+
const handler = app?.cycle?.onReady;
|
|
65
|
+
if (!handler) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await handler(store);
|
|
69
|
+
};
|
|
70
|
+
const dispatchAppDispose = async (appName, error) => {
|
|
71
|
+
const app = getChildrenApp(appName);
|
|
72
|
+
if (!app?.cycle) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
if (app.cycle.onDispose) {
|
|
77
|
+
await app.cycle.onDispose(error);
|
|
78
|
+
}
|
|
79
|
+
if (app.cycle.unMounted) {
|
|
80
|
+
await app.cycle.unMounted(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (disposeError) {
|
|
84
|
+
swallowLifecycleError(disposeError);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const dispatchDisposeAllApps = async (error) => {
|
|
88
|
+
const apps = getChildrenApps();
|
|
89
|
+
for (const app of apps) {
|
|
90
|
+
await dispatchAppDispose(app.name, error);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { dispatchAppDispose, dispatchAppReady, dispatchDisposeAllApps, dispatchEventFinished, dispatchEventStart, dispatchHttpError, dispatchRuntimeStatusChange };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getConfig } from '
|
|
1
|
+
import { getConfig } from '../../../common/config.js';
|
|
2
2
|
import { loadChildren, loadChildrenFile } from './loadChild.js';
|
|
3
3
|
import { join, dirname } from 'path';
|
|
4
4
|
import { existsSync } from 'fs';
|
|
5
|
-
import { ResultCode } from '
|
|
5
|
+
import { ResultCode } from '../../../common/variable.js';
|
|
6
6
|
import { registerRuntimeApp } from '../store.js';
|
|
7
7
|
|
|
8
8
|
const loadApps = () => {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { dirname, join } from 'path';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import { showErrorModule, getRecursiveDirFiles, createEventName } from '
|
|
3
|
+
import { showErrorModule, getRecursiveDirFiles, createEventName } from '../../../common/utils.js';
|
|
4
4
|
import { registerRuntimeApp, updateRuntimeAppStatus, ChildrenApp, clearRuntimeAppKoaRouters, setRuntimeAppKoaRouters, updateRuntimeAppCapabilities } from '../store.js';
|
|
5
|
-
import { registerExpose } from '
|
|
6
|
-
import { ResultCode, fileSuffixMiddleware } from '
|
|
5
|
+
import { registerExpose } from '../../expose.js';
|
|
6
|
+
import { ResultCode, fileSuffixMiddleware } from '../../../common/variable.js';
|
|
7
7
|
import { registerAppDir, scheduleCancelByApp, unregisterAppDir } from '../schedule-store.js';
|
|
8
8
|
import module$1 from 'module';
|
|
9
|
+
import { dispatchRuntimeStatusChange, dispatchAppDispose, dispatchAppReady } from '../lifecycle-callbacks.js';
|
|
9
10
|
|
|
10
11
|
const initRequire = () => { };
|
|
11
12
|
initRequire.resolve = () => '';
|
|
@@ -89,21 +90,19 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
89
90
|
app = await moduleApp.default.callback();
|
|
90
91
|
}
|
|
91
92
|
App.pushCycle(app);
|
|
93
|
+
await dispatchRuntimeStatusChange({
|
|
94
|
+
appName,
|
|
95
|
+
previousStatus: 'discovered',
|
|
96
|
+
status: 'loading'
|
|
97
|
+
});
|
|
92
98
|
const unMounted = async (e) => {
|
|
93
99
|
showErrorModule(e);
|
|
94
100
|
clearRuntimeAppKoaRouters(appName);
|
|
95
101
|
updateRuntimeAppStatus(appName, 'failed', e);
|
|
96
102
|
scheduleCancelByApp(appName);
|
|
97
103
|
unregisterAppDir(appName);
|
|
104
|
+
await dispatchAppDispose(appName, e);
|
|
98
105
|
App.un();
|
|
99
|
-
try {
|
|
100
|
-
if (app?.unMounted) {
|
|
101
|
-
await app.unMounted(e);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (e) {
|
|
105
|
-
showErrorModule(e);
|
|
106
|
-
}
|
|
107
106
|
};
|
|
108
107
|
try {
|
|
109
108
|
if (app?.onCreated) {
|
|
@@ -133,10 +132,12 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
133
132
|
expose: hasExposeCapability
|
|
134
133
|
});
|
|
135
134
|
App.on();
|
|
135
|
+
const emptyStore = { response: [], responseMiddleware: {}, middleware: [] };
|
|
136
136
|
try {
|
|
137
137
|
if (app?.onMounted) {
|
|
138
|
-
await app.onMounted(
|
|
138
|
+
await app.onMounted(emptyStore);
|
|
139
139
|
}
|
|
140
|
+
await dispatchAppReady(appName, emptyStore);
|
|
140
141
|
updateRuntimeAppStatus(appName, 'ready');
|
|
141
142
|
}
|
|
142
143
|
catch (e) {
|
|
@@ -202,10 +203,12 @@ const loadChildren = async (mainPath, appName) => {
|
|
|
202
203
|
event: resData.length > 0 || Object.keys(resAndMwData).length > 0 || mwData.length > 0
|
|
203
204
|
});
|
|
204
205
|
App.on();
|
|
206
|
+
const mountedStore = { response: resData, responseMiddleware: resAndMwData, middleware: mwData };
|
|
205
207
|
try {
|
|
206
208
|
if (app?.onMounted) {
|
|
207
|
-
await app.onMounted(
|
|
209
|
+
await app.onMounted(mountedStore);
|
|
208
210
|
}
|
|
211
|
+
await dispatchAppReady(appName, mountedStore);
|
|
209
212
|
updateRuntimeAppStatus(appName, 'ready');
|
|
210
213
|
}
|
|
211
214
|
catch (e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScheduleId, ScheduleItem, ScheduleStatus, ScheduleCallback, CronExpression } from '
|
|
1
|
+
import { ScheduleId, ScheduleItem, ScheduleStatus, ScheduleCallback, CronExpression } from '../../types/schedule';
|
|
2
2
|
export declare const registerAppDir: (appName: string, mainDir: string) => void;
|
|
3
3
|
export declare const unregisterAppDir: (appName: string) => void;
|
|
4
4
|
export declare const scheduleInterval: (callback: ScheduleCallback, ms: number, appName?: string) => ScheduleId;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { SinglyLinkedList } from '
|
|
2
|
-
import { childrenCallbackRes, ChildrenCycle, EventCycleEnum, EventKeys, FileTreeNode, StoreMiddlewareItem, StoreResponseItem, SubscribeValue } from '
|
|
1
|
+
import { SinglyLinkedList } from '../../common/SinglyLinkedList.js';
|
|
2
|
+
import { childrenCallbackRes, ChildrenCycle, EventCycleEnum, EventKeys, FileTreeNode, StoreMiddlewareItem, StoreResponseItem, SubscribeValue } from '../../types';
|
|
3
3
|
import type KoaRouter from 'koa-router';
|
|
4
|
+
export { Logger, logger } from '../../common/logger.js';
|
|
4
5
|
export type RuntimeAppStatus = 'discovered' | 'loading' | 'ready' | 'failed' | 'disposed';
|
|
5
6
|
export type RuntimeAppCapability = {
|
|
6
7
|
event: boolean;
|
|
@@ -26,19 +27,14 @@ export type RuntimeAppRecord = {
|
|
|
26
27
|
createdAt: number;
|
|
27
28
|
updatedAt: number;
|
|
28
29
|
};
|
|
29
|
-
export declare class Logger {
|
|
30
|
-
#private;
|
|
31
|
-
constructor();
|
|
32
|
-
get value(): any;
|
|
33
|
-
}
|
|
34
30
|
export declare class Core {
|
|
35
31
|
constructor();
|
|
36
32
|
get value(): {
|
|
37
|
-
storeState: import("../
|
|
38
|
-
storeStateSubscribe: import("../
|
|
39
|
-
storeSubscribeList: import("../
|
|
33
|
+
storeState: import("../index.js").ResponseState;
|
|
34
|
+
storeStateSubscribe: import("../index.js").StateSubscribeMap;
|
|
35
|
+
storeSubscribeList: import("../index.js").SubscribeKeysMap;
|
|
40
36
|
storeChildrenApp: {
|
|
41
|
-
[key: string]: import("../
|
|
37
|
+
[key: string]: import("../index.js").StoreChildrenApp;
|
|
42
38
|
};
|
|
43
39
|
runtimeApps?: {
|
|
44
40
|
[key: string]: RuntimeAppRecord;
|
|
@@ -185,17 +181,18 @@ export declare class ChildrenApp {
|
|
|
185
181
|
pushCycle(data: ChildrenCycle): void;
|
|
186
182
|
on(): void;
|
|
187
183
|
un(): void;
|
|
188
|
-
get value(): import("../
|
|
184
|
+
get value(): import("../index.js").StoreChildrenApp;
|
|
189
185
|
}
|
|
186
|
+
export declare const getChildrenApp: (name: string) => import("../index.js").StoreChildrenApp;
|
|
187
|
+
export declare const listChildrenApps: () => import("../index.js").StoreChildrenApp[];
|
|
190
188
|
export declare const ProcessorEventAutoClearMap: Map<any, any>;
|
|
191
189
|
export declare const ProcessorEventUserAutoClearMap: Map<any, any>;
|
|
192
|
-
export declare const logger: any;
|
|
193
190
|
export declare const core: {
|
|
194
|
-
storeState: import("../
|
|
195
|
-
storeStateSubscribe: import("../
|
|
196
|
-
storeSubscribeList: import("../
|
|
191
|
+
storeState: import("../index.js").ResponseState;
|
|
192
|
+
storeStateSubscribe: import("../index.js").StateSubscribeMap;
|
|
193
|
+
storeSubscribeList: import("../index.js").SubscribeKeysMap;
|
|
197
194
|
storeChildrenApp: {
|
|
198
|
-
[key: string]: import("../
|
|
195
|
+
[key: string]: import("../index.js").StoreChildrenApp;
|
|
199
196
|
};
|
|
200
197
|
runtimeApps?: {
|
|
201
198
|
[key: string]: RuntimeAppRecord;
|
|
@@ -1,101 +1,8 @@
|
|
|
1
|
-
import { SinglyLinkedList } from '
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { SinglyLinkedList } from '../../common/SinglyLinkedList.js';
|
|
2
|
+
import { disposeExpose } from '../expose.js';
|
|
3
|
+
import { dispatchRuntimeStatusChange } from './lifecycle-callbacks.js';
|
|
4
|
+
export { Logger, logger } from '../../common/logger.js';
|
|
5
5
|
|
|
6
|
-
const createLogger = () => {
|
|
7
|
-
if (process.env.BROWSER_ENV === 'browser') {
|
|
8
|
-
return {
|
|
9
|
-
trace: console.trace.bind(console),
|
|
10
|
-
debug: console.debug.bind(console),
|
|
11
|
-
info: console.info.bind(console),
|
|
12
|
-
mark: console.info.bind(console),
|
|
13
|
-
warn: console.warn.bind(console),
|
|
14
|
-
error: console.error.bind(console),
|
|
15
|
-
fatal: console.error.bind(console)
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const logDir = process.env?.LOG_PATH ?? `./logs/${process.env.LOG_NAME ?? ''}`;
|
|
19
|
-
mkdirSync(logDir, { recursive: true });
|
|
20
|
-
const level = process.env.NODE_ENV === 'development' ? 'trace' : 'info';
|
|
21
|
-
const hideTime = process.env.LOGGER_TIME === 'false' ? true : false;
|
|
22
|
-
const hideLevel = process.env.LOGGER_LEVEL === 'false' ? true : false;
|
|
23
|
-
let pattern = '';
|
|
24
|
-
if (hideTime && hideLevel) {
|
|
25
|
-
pattern = '%m';
|
|
26
|
-
}
|
|
27
|
-
else if (hideTime && !hideLevel) {
|
|
28
|
-
pattern = '[%p] %m';
|
|
29
|
-
}
|
|
30
|
-
else if (!hideTime && hideLevel) {
|
|
31
|
-
pattern = '[%d{yyyy-MM-dd hh:mm:ss}] %m';
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
pattern = '[%d{yyyy-MM-dd hh:mm:ss}][%p] %m';
|
|
35
|
-
}
|
|
36
|
-
log4js.configure({
|
|
37
|
-
appenders: {
|
|
38
|
-
console: {
|
|
39
|
-
type: 'console',
|
|
40
|
-
layout: {
|
|
41
|
-
type: 'pattern',
|
|
42
|
-
pattern: pattern
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
command: {
|
|
46
|
-
type: 'dateFile',
|
|
47
|
-
filename: `${logDir}/command`,
|
|
48
|
-
pattern: 'yyyy-MM-dd.log',
|
|
49
|
-
numBackups: 15,
|
|
50
|
-
alwaysIncludePattern: true,
|
|
51
|
-
layout: {
|
|
52
|
-
type: 'pattern',
|
|
53
|
-
pattern: pattern
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
error: {
|
|
57
|
-
type: 'dateFile',
|
|
58
|
-
filename: `${logDir}/error`,
|
|
59
|
-
pattern: 'yyyy-MM-dd.log',
|
|
60
|
-
numBackups: 15,
|
|
61
|
-
alwaysIncludePattern: true,
|
|
62
|
-
layout: {
|
|
63
|
-
type: 'pattern',
|
|
64
|
-
pattern: pattern
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
categories: {
|
|
69
|
-
default: { appenders: ['console'], level: level },
|
|
70
|
-
command: { appenders: ['console', 'command'], level: 'info' },
|
|
71
|
-
error: { appenders: ['console', 'command', 'error'], level: 'warn' }
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
const defaultLogger = log4js.getLogger('default');
|
|
75
|
-
const commandLogger = log4js.getLogger('command');
|
|
76
|
-
const errorLogger = log4js.getLogger('error');
|
|
77
|
-
return {
|
|
78
|
-
trace: defaultLogger.trace.bind(defaultLogger),
|
|
79
|
-
debug: defaultLogger.debug.bind(defaultLogger),
|
|
80
|
-
info: commandLogger.info.bind(commandLogger),
|
|
81
|
-
mark: commandLogger.mark.bind(commandLogger),
|
|
82
|
-
warn: errorLogger.warn.bind(errorLogger),
|
|
83
|
-
error: errorLogger.error.bind(errorLogger),
|
|
84
|
-
fatal: errorLogger.fatal.bind(errorLogger)
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
class Logger {
|
|
88
|
-
#logger = null;
|
|
89
|
-
constructor() {
|
|
90
|
-
this.#logger = createLogger();
|
|
91
|
-
if (!global.logger) {
|
|
92
|
-
global.logger = this.#logger;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
get value() {
|
|
96
|
-
return this.#logger;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
6
|
class Core {
|
|
100
7
|
constructor() {
|
|
101
8
|
if (!global.alemonjsCore) {
|
|
@@ -200,7 +107,7 @@ const registerRuntimeApp = (record) => {
|
|
|
200
107
|
createdAt: current?.createdAt ?? now,
|
|
201
108
|
updatedAt: now
|
|
202
109
|
};
|
|
203
|
-
if (
|
|
110
|
+
if (current?.status !== record.status) {
|
|
204
111
|
logRuntimeAppStatus(record.status === 'failed' ? 'warn' : 'debug', runtimeApps[record.name]);
|
|
205
112
|
}
|
|
206
113
|
return runtimeApps[record.name];
|
|
@@ -212,6 +119,7 @@ const updateRuntimeAppStatus = (name, status, error) => {
|
|
|
212
119
|
return;
|
|
213
120
|
}
|
|
214
121
|
const normalizedError = normalizeRuntimeAppError(error);
|
|
122
|
+
const previousStatus = current.status;
|
|
215
123
|
if (current.status === status && sameRuntimeAppError(current.error, normalizedError)) {
|
|
216
124
|
return current;
|
|
217
125
|
}
|
|
@@ -220,6 +128,17 @@ const updateRuntimeAppStatus = (name, status, error) => {
|
|
|
220
128
|
current.error = normalizedError;
|
|
221
129
|
const level = status === 'failed' ? 'warn' : status === 'disposed' ? 'info' : 'debug';
|
|
222
130
|
logRuntimeAppStatus(level, current);
|
|
131
|
+
void dispatchRuntimeStatusChange({
|
|
132
|
+
appName: name,
|
|
133
|
+
previousStatus,
|
|
134
|
+
status,
|
|
135
|
+
error: normalizedError
|
|
136
|
+
? {
|
|
137
|
+
message: normalizedError.message,
|
|
138
|
+
time: normalizedError.time
|
|
139
|
+
}
|
|
140
|
+
: undefined
|
|
141
|
+
});
|
|
223
142
|
return current;
|
|
224
143
|
};
|
|
225
144
|
const updateRuntimeAppCapabilities = (name, capabilities) => {
|
|
@@ -242,7 +161,7 @@ const updateRuntimeAppCapabilities = (name, capabilities) => {
|
|
|
242
161
|
const setRuntimeAppKoaRouters = (name, koaRouters) => {
|
|
243
162
|
const koaRouterStore = getRuntimeAppKoaRouterStore();
|
|
244
163
|
if (!koaRouters) {
|
|
245
|
-
|
|
164
|
+
Reflect.deleteProperty(koaRouterStore, name);
|
|
246
165
|
return [];
|
|
247
166
|
}
|
|
248
167
|
const normalizedRouters = (Array.isArray(koaRouters) ? koaRouters : [koaRouters]).filter(Boolean);
|
|
@@ -254,7 +173,7 @@ const getRuntimeAppKoaRouters = (name) => {
|
|
|
254
173
|
};
|
|
255
174
|
const clearRuntimeAppKoaRouters = (name) => {
|
|
256
175
|
const koaRouterStore = getRuntimeAppKoaRouterStore();
|
|
257
|
-
|
|
176
|
+
Reflect.deleteProperty(koaRouterStore, name);
|
|
258
177
|
};
|
|
259
178
|
const listRuntimeAppKoaRouters = () => {
|
|
260
179
|
return Object.entries(getRuntimeAppKoaRouterStore())
|
|
@@ -408,6 +327,13 @@ function mergeFileTree(target, source) {
|
|
|
408
327
|
}
|
|
409
328
|
}
|
|
410
329
|
}
|
|
330
|
+
const attachRouteAppName = (appName, routes = []) => {
|
|
331
|
+
return routes.map(route => ({
|
|
332
|
+
...route,
|
|
333
|
+
appName,
|
|
334
|
+
children: route.children ? attachRouteAppName(appName, route.children) : route.children
|
|
335
|
+
}));
|
|
336
|
+
};
|
|
411
337
|
class MiddlewareTree {
|
|
412
338
|
#cache = null;
|
|
413
339
|
#cacheVersion = -1;
|
|
@@ -456,10 +382,10 @@ class ResponseRouter {
|
|
|
456
382
|
return [];
|
|
457
383
|
}
|
|
458
384
|
if (alemonjsCore.storeChildrenApp[key].register?.responseRouter) {
|
|
459
|
-
return alemonjsCore.storeChildrenApp[key].register?.responseRouter?.current ?? [];
|
|
385
|
+
return attachRouteAppName(key, alemonjsCore.storeChildrenApp[key].register?.responseRouter?.current ?? []);
|
|
460
386
|
}
|
|
461
387
|
if (alemonjsCore.storeChildrenApp[key].register?.response) {
|
|
462
|
-
return alemonjsCore.storeChildrenApp[key].register?.response?.current ?? [];
|
|
388
|
+
return attachRouteAppName(key, alemonjsCore.storeChildrenApp[key].register?.response?.current ?? []);
|
|
463
389
|
}
|
|
464
390
|
return [];
|
|
465
391
|
});
|
|
@@ -480,10 +406,10 @@ class MiddlewareRouter {
|
|
|
480
406
|
return [];
|
|
481
407
|
}
|
|
482
408
|
if (alemonjsCore.storeChildrenApp[key].register?.middlewareRouter) {
|
|
483
|
-
return alemonjsCore.storeChildrenApp[key].register?.middlewareRouter?.current ?? [];
|
|
409
|
+
return attachRouteAppName(key, alemonjsCore.storeChildrenApp[key].register?.middlewareRouter?.current ?? []);
|
|
484
410
|
}
|
|
485
411
|
if (alemonjsCore.storeChildrenApp[key].register?.middleware) {
|
|
486
|
-
return alemonjsCore.storeChildrenApp[key].register?.middleware?.current ?? [];
|
|
412
|
+
return attachRouteAppName(key, alemonjsCore.storeChildrenApp[key].register?.middleware?.current ?? []);
|
|
487
413
|
}
|
|
488
414
|
return [];
|
|
489
415
|
});
|
|
@@ -622,7 +548,7 @@ class ChildrenApp {
|
|
|
622
548
|
}
|
|
623
549
|
un() {
|
|
624
550
|
disposeExpose(this.#name);
|
|
625
|
-
|
|
551
|
+
Reflect.deleteProperty(alemonjsCore.storeChildrenApp, this.#name);
|
|
626
552
|
bumpStoreVersion();
|
|
627
553
|
}
|
|
628
554
|
get value() {
|
|
@@ -632,9 +558,14 @@ class ChildrenApp {
|
|
|
632
558
|
return alemonjsCore.storeChildrenApp[this.#name];
|
|
633
559
|
}
|
|
634
560
|
}
|
|
561
|
+
const getChildrenApp = (name) => {
|
|
562
|
+
return alemonjsCore.storeChildrenApp[name] ?? null;
|
|
563
|
+
};
|
|
564
|
+
const listChildrenApps = () => {
|
|
565
|
+
return Object.values(alemonjsCore.storeChildrenApp);
|
|
566
|
+
};
|
|
635
567
|
const ProcessorEventAutoClearMap = new Map();
|
|
636
568
|
const ProcessorEventUserAutoClearMap = new Map();
|
|
637
|
-
const logger = new Logger().value;
|
|
638
569
|
const core = new Core().value;
|
|
639
570
|
['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
|
|
640
571
|
process?.on?.(sig, () => {
|
|
@@ -645,4 +576,4 @@ process?.on?.('exit', code => {
|
|
|
645
576
|
logger.info?.(`[alemonjs][exit] 进程退出,code=${code}`);
|
|
646
577
|
});
|
|
647
578
|
|
|
648
|
-
export { ChildrenApp, Core,
|
|
579
|
+
export { ChildrenApp, Core, Middleware, MiddlewareRouter, MiddlewareTree, ProcessorEventAutoClearMap, ProcessorEventUserAutoClearMap, Response, ResponseMiddleware, ResponseRouter, ResponseTree, State, StateSubscribe, SubscribeList, bumpStoreVersion, clearRuntimeAppKoaRouters, core, disposeAllRuntimeApps, disposeRuntimeApp, getChildrenApp, getRuntimeApp, getRuntimeAppKoaRouters, getSubscribeList, hasRuntimeAppCapability, listChildrenApps, listRuntimeAppKoaRouters, listRuntimeApps, registerRuntimeApp, setRuntimeAppKoaRouters, toRuntimeAppSnapshot, updateRuntimeAppCapabilities, updateRuntimeAppStatus };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ScheduleCallback, CronExpression } from '../types/schedule';
|
|
2
|
+
export declare const setInterval: (callback: ScheduleCallback, ms: number) => string;
|
|
3
|
+
export declare const setTimeout: (callback: ScheduleCallback, ms: number) => string;
|
|
4
|
+
export declare const setCron: (expression: CronExpression, callback: ScheduleCallback) => string;
|
|
5
|
+
export declare const clearInterval: (id: import("./index.js").ScheduleId) => boolean;
|
|
6
|
+
export declare const clearTimeout: (id: import("./index.js").ScheduleId) => boolean;
|
|
7
|
+
export declare const pauseSchedule: (id: import("./index.js").ScheduleId) => boolean;
|
|
8
|
+
export declare const resumeSchedule: (id: import("./index.js").ScheduleId) => boolean;
|
|
9
|
+
export declare const listSchedule: (appName?: string) => Array<{
|
|
10
|
+
id: import("./index.js").ScheduleId;
|
|
11
|
+
type: import("./index.js").ScheduleItem["type"];
|
|
12
|
+
status: import("./index.js").ScheduleStatus;
|
|
13
|
+
ms?: number;
|
|
14
|
+
cron?: string;
|
|
15
|
+
appName?: string;
|
|
16
|
+
createdAt: number;
|
|
17
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { scheduleCancel, scheduleList, schedulePause, scheduleResume, scheduleCron, scheduleInterval, scheduleTimeout } from '
|
|
1
|
+
import { scheduleCancel, scheduleList, schedulePause, scheduleResume, scheduleCron, scheduleInterval, scheduleTimeout } from './runtime/schedule-store.js';
|
|
2
2
|
|
|
3
3
|
const setInterval = (callback, ms) => scheduleInterval(callback, ms);
|
|
4
4
|
const setTimeout = (callback, ms) => scheduleTimeout(callback, ms);
|
package/lib/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import './application/runtime/client-runtime.js';
|
package/lib/client.js
CHANGED
|
@@ -1,113 +1 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import { defaultPort } from './core/variable.js';
|
|
3
|
-
import 'fs';
|
|
4
|
-
import 'path';
|
|
5
|
-
import 'yaml';
|
|
6
|
-
import './core/utils.js';
|
|
7
|
-
import { cbpClient } from './cbp/connects/client.js';
|
|
8
|
-
import 'flatted';
|
|
9
|
-
import 'ws';
|
|
10
|
-
import './cbp/processor/config.js';
|
|
11
|
-
import 'net';
|
|
12
|
-
import 'v8';
|
|
13
|
-
import 'os';
|
|
14
|
-
import 'koa';
|
|
15
|
-
import '@koa/cors';
|
|
16
|
-
import './cbp/routers/router.js';
|
|
17
|
-
import 'lodash';
|
|
18
|
-
import 'fs/promises';
|
|
19
|
-
import { disposeAllRuntimeApps } from './app/store.js';
|
|
20
|
-
import { loadModels } from './app/load_modules/load.js';
|
|
21
|
-
import './app/load_modules/loadChild.js';
|
|
22
|
-
import './app/define-children.js';
|
|
23
|
-
import './app/define-response.js';
|
|
24
|
-
import './app/define-middleware.js';
|
|
25
|
-
import './app/event-group.js';
|
|
26
|
-
import './app/event-middleware.js';
|
|
27
|
-
import './app/event-processor.js';
|
|
28
|
-
import './app/event-response.js';
|
|
29
|
-
import './app/hook-event-context.js';
|
|
30
|
-
import './app/message-format-old.js';
|
|
31
|
-
import { scheduleCancelByApp, unregisterAppDir } from './app/schedule-store.js';
|
|
32
|
-
import './app/event-utils.js';
|
|
33
|
-
import './app/message-api.js';
|
|
34
|
-
import './process/platform.js';
|
|
35
|
-
import './process/module.js';
|
|
36
|
-
import { createServer } from './server/main.js';
|
|
37
|
-
|
|
38
|
-
global.__client_loaded = true;
|
|
39
|
-
let runtimeDisposed = false;
|
|
40
|
-
const disposeRuntime = () => {
|
|
41
|
-
if (runtimeDisposed) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
runtimeDisposed = true;
|
|
45
|
-
const apps = disposeAllRuntimeApps();
|
|
46
|
-
apps.forEach(app => {
|
|
47
|
-
scheduleCancelByApp(app.name);
|
|
48
|
-
unregisterAppDir(app.name);
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const mainServer = () => {
|
|
52
|
-
const port = process.env.serverPort;
|
|
53
|
-
if (!port) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
createServer(port, () => {
|
|
57
|
-
const httpURL = `http://127.0.0.1:${port}`;
|
|
58
|
-
logger.info(`应用服务器: ${httpURL}`);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
const main = () => {
|
|
62
|
-
const login = process.env.login ?? '';
|
|
63
|
-
const platform = process.env.platform ?? '';
|
|
64
|
-
const url = process.env.url ?? '';
|
|
65
|
-
const port = process.env.port ?? defaultPort;
|
|
66
|
-
const isFullReceive = process.env.is_full_receive === 'true' || process.env.is_full_receive === '1';
|
|
67
|
-
if (!login && !platform && url) {
|
|
68
|
-
logger.info(`[Connecting to CBP server at ${url}]`);
|
|
69
|
-
cbpClient(url);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const httpURL = `http://127.0.0.1:${port}`;
|
|
73
|
-
cbpClient(httpURL, { isFullReceive });
|
|
74
|
-
}
|
|
75
|
-
loadModels();
|
|
76
|
-
};
|
|
77
|
-
const mainProcess = () => {
|
|
78
|
-
process.on('unhandledRejection', (reason) => {
|
|
79
|
-
logger.error('[alemonjs][unhandledRejection] 未捕获的 Promise 拒绝:', reason);
|
|
80
|
-
});
|
|
81
|
-
process.on('uncaughtException', (error) => {
|
|
82
|
-
logger.error('[alemonjs][uncaughtException] 未捕获的异常:', error);
|
|
83
|
-
});
|
|
84
|
-
['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
|
|
85
|
-
process?.on?.(sig, () => {
|
|
86
|
-
logger.info?.(`[alemonjs][${sig}] 收到信号,正在关闭...`);
|
|
87
|
-
disposeRuntime();
|
|
88
|
-
setImmediate(() => process.exit(0));
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
process?.on?.('exit', code => {
|
|
92
|
-
disposeRuntime();
|
|
93
|
-
logger.info?.(`[alemonjs][exit] 进程退出,code=${code}`);
|
|
94
|
-
});
|
|
95
|
-
process.on('message', msg => {
|
|
96
|
-
try {
|
|
97
|
-
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
98
|
-
if (data?.type === 'start') {
|
|
99
|
-
main();
|
|
100
|
-
mainServer();
|
|
101
|
-
}
|
|
102
|
-
else if (data?.type === 'stop') {
|
|
103
|
-
disposeRuntime();
|
|
104
|
-
process.exit(0);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch { }
|
|
108
|
-
});
|
|
109
|
-
if (process.send) {
|
|
110
|
-
process.send({ type: 'ready' });
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
mainProcess();
|
|
1
|
+
import './application/runtime/client-runtime.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const USER_AGENT_HEADER = "user-agent";
|
|
2
|
+
export declare const USER_AGENT_HEADER_VALUE_MAP: {
|
|
3
|
+
readonly platform: "platform";
|
|
4
|
+
readonly client: "client";
|
|
5
|
+
readonly testone: "testone";
|
|
6
|
+
};
|
|
7
|
+
export declare const DEVICE_ID_HEADER = "x-device-id";
|
|
8
|
+
export declare const FULL_RECEIVE_HEADER = "x-full-receive";
|
|
9
|
+
export declare const timeoutTime: number;
|
|
10
|
+
export declare const reconnectInterval: number;
|
|
11
|
+
export declare const HEARTBEAT_INTERVAL: number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const USER_AGENT_HEADER = 'user-agent';
|
|
2
|
+
const USER_AGENT_HEADER_VALUE_MAP = {
|
|
3
|
+
platform: 'platform',
|
|
4
|
+
client: 'client',
|
|
5
|
+
testone: 'testone'
|
|
6
|
+
};
|
|
7
|
+
const DEVICE_ID_HEADER = 'x-device-id';
|
|
8
|
+
const FULL_RECEIVE_HEADER = 'x-full-receive';
|
|
9
|
+
const timeoutTime = 1000 * 60 * 3;
|
|
10
|
+
const reconnectInterval = 1000 * 6;
|
|
11
|
+
const HEARTBEAT_INTERVAL = 1000 * 18;
|
|
12
|
+
|
|
13
|
+
export { DEVICE_ID_HEADER, FULL_RECEIVE_HEADER, HEARTBEAT_INTERVAL, USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, reconnectInterval, timeoutTime };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '
|
|
3
|
-
import '
|
|
4
|
-
import 'yaml';
|
|
5
|
-
import '../../core/utils.js';
|
|
6
|
-
import { HEARTBEAT_INTERVAL } from '../processor/config.js';
|
|
1
|
+
import { logger } from '../logger.js';
|
|
2
|
+
import { ResultCode } from '../variable.js';
|
|
3
|
+
import { HEARTBEAT_INTERVAL } from './constants.js';
|
|
7
4
|
|
|
8
5
|
const useHeartbeat = ({ ping, isConnected, terminate }) => {
|
|
9
6
|
let heartbeatTimer = null;
|