@statewalker/fsm 0.37.0 → 0.38.0
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 +215 -70
- package/dist/index.d.ts +353 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +527 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -15
- package/src/core/fsm-base-class.ts +25 -0
- package/src/core/fsm-process.ts +55 -0
- package/src/core/fsm-state-config.ts +27 -0
- package/src/core/fsm-state-descriptor.ts +21 -0
- package/src/core/fsm-state.ts +21 -0
- package/src/core/fsm-transitions.ts +72 -0
- package/src/core/index.ts +1 -0
- package/src/index.ts +2 -2
- package/src/{orchestrator/start-process.ts → start-process.ts} +60 -63
- package/src/{utils → trace}/printer.ts +20 -0
- package/src/{utils → trace}/tracer.ts +11 -0
- package/bin/cli.js +0 -5
- package/dist/bin/node-runner-UJp8T_oP.d.ts +0 -16
- package/dist/bin/node-runner-UJp8T_oP.d.ts.map +0 -1
- package/dist/bin/node-runner.js +0 -40
- package/dist/bin/node-runner.js.map +0 -1
- package/dist/index-vTjnkbGW.d.ts +0 -129
- package/dist/index-vTjnkbGW.d.ts.map +0 -1
- package/dist/launcher-6VUDviTj.d.ts +0 -48
- package/dist/launcher-6VUDviTj.d.ts.map +0 -1
- package/dist/launcher-CASrMAOa.js +0 -443
- package/dist/launcher-CASrMAOa.js.map +0 -1
- package/src/bin/node-runner.ts +0 -57
- package/src/orchestrator/handler-registry.ts +0 -108
- package/src/orchestrator/index.ts +0 -15
- package/src/orchestrator/launcher.ts +0 -73
- /package/src/{utils → trace}/index.ts +0 -0
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type { HandlerRegistry, StageHandler } from "./handler-registry.ts";
|
|
2
|
-
export { createHandlerRegistry, toStageHandlers } from "./handler-registry.ts";
|
|
3
|
-
export type { LauncherConfig, ProcessDef } from "./launcher.ts";
|
|
4
|
-
export { KEY_LAUNCH_PROCESS, launcher } from "./launcher.ts";
|
|
5
|
-
export type { ProcessHandle } from "./start-process.ts";
|
|
6
|
-
export {
|
|
7
|
-
getStateTransitions,
|
|
8
|
-
isStateTransitionEnabled,
|
|
9
|
-
KEY_DISPATCH,
|
|
10
|
-
KEY_EVENT,
|
|
11
|
-
KEY_STATES,
|
|
12
|
-
KEY_TERMINATE,
|
|
13
|
-
startFsmProcess,
|
|
14
|
-
startProcess,
|
|
15
|
-
} from "./start-process.ts";
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { FsmStateConfig } from "../core/fsm-state-config.ts";
|
|
2
|
-
import type { StageHandler } from "./handler-registry.ts";
|
|
3
|
-
import { createHandlerRegistry } from "./handler-registry.ts";
|
|
4
|
-
import { startProcess } from "./start-process.ts";
|
|
5
|
-
|
|
6
|
-
export const KEY_LAUNCH_PROCESS = "fsm:launch";
|
|
7
|
-
|
|
8
|
-
export interface LauncherConfig {
|
|
9
|
-
processes: ProcessDef[];
|
|
10
|
-
start?: string[];
|
|
11
|
-
context?: (parent: Record<string, unknown>) => Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface ProcessDef {
|
|
15
|
-
name: string;
|
|
16
|
-
config: FsmStateConfig;
|
|
17
|
-
handlers?: (StageHandler | Record<string, StageHandler | StageHandler[]>)[];
|
|
18
|
-
start?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function launcher(
|
|
22
|
-
config: LauncherConfig,
|
|
23
|
-
): Promise<() => Promise<void>> {
|
|
24
|
-
const registry = createHandlerRegistry();
|
|
25
|
-
|
|
26
|
-
async function launch(
|
|
27
|
-
processName: string,
|
|
28
|
-
context: Record<string, unknown>,
|
|
29
|
-
startEvent = "start",
|
|
30
|
-
) {
|
|
31
|
-
const cfg = registry.getConfig(processName);
|
|
32
|
-
const load = registry.getLoader(processName);
|
|
33
|
-
return startProcess(context, cfg, load, startEvent);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const rootContext: Record<string, unknown> = {
|
|
37
|
-
[KEY_LAUNCH_PROCESS]: launch,
|
|
38
|
-
};
|
|
39
|
-
const initContext = config.context ?? ((ctx: Record<string, unknown>) => ctx);
|
|
40
|
-
|
|
41
|
-
const startSet = config.start ? new Set(config.start) : undefined;
|
|
42
|
-
|
|
43
|
-
for (const def of config.processes) {
|
|
44
|
-
registry.register(def.name, def.config);
|
|
45
|
-
if (def.handlers?.length) {
|
|
46
|
-
registry.registerHandlers(def.name, ...def.handlers);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const shutdowns: (() => Promise<void>)[] = [];
|
|
51
|
-
const seen = new Set<string>();
|
|
52
|
-
for (const def of config.processes) {
|
|
53
|
-
if (seen.has(def.name)) continue;
|
|
54
|
-
seen.add(def.name);
|
|
55
|
-
|
|
56
|
-
if (def.start === false) continue;
|
|
57
|
-
if (startSet && !startSet.has(def.name)) continue;
|
|
58
|
-
|
|
59
|
-
let context: Record<string, unknown> = {
|
|
60
|
-
parent: rootContext,
|
|
61
|
-
"fsm:name": def.name,
|
|
62
|
-
};
|
|
63
|
-
context = initContext(context) ?? context;
|
|
64
|
-
const handle = await launch(def.name, context);
|
|
65
|
-
shutdowns.push(handle.shutdown);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return async () => {
|
|
69
|
-
for (const shutdown of shutdowns) {
|
|
70
|
-
await shutdown();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
File without changes
|