@statewalker/fsm 0.16.0 → 0.20.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/CHANGELOG.md ADDED
@@ -0,0 +1,59 @@
1
+ # @statewalker/fsm
2
+
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Fix logical bug in transitions loading
8
+
9
+ ## 0.15.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Update rollup and dependencies
14
+ - Updated dependencies
15
+ - @statewalker/tree@0.10.2
16
+
17
+ ## 0.15.1
18
+
19
+ ### Patch Changes
20
+
21
+ - Normalize package.json files
22
+ - Updated dependencies
23
+ - @statewalker/tree@0.10.1
24
+
25
+ ## 0.15.0
26
+
27
+ ### Minor Changes
28
+
29
+ - Migrage the "initAsyncProcess" method from the @statewalker/fsm to @statewalker/fsm-process package and add process utility methods
30
+
31
+ ## 0.14.0
32
+
33
+ ### Minor Changes
34
+
35
+ - Update exports
36
+
37
+ ## 0.13.0
38
+
39
+ ### Minor Changes
40
+
41
+ - Fix exports
42
+
43
+ ## 0.12.0
44
+
45
+ ### Minor Changes
46
+
47
+ - Update version
48
+
49
+ ## 0.11.0
50
+
51
+ ### Minor Changes
52
+
53
+ - Add initialization function for async processes
54
+
55
+ ## 0.10.1
56
+
57
+ ### Patch Changes
58
+
59
+ - Migrate the @statewalker/fsm project from the @statewalker/statewalker monorepo
@@ -0,0 +1,111 @@
1
+ declare class FsmBaseClass {
2
+ handlers: Record<string, Function[]>;
3
+ data: Record<string, unknown>;
4
+ constructor();
5
+ setData<T>(key: string, value: T): this;
6
+ getData<T>(key: string): T | undefined;
7
+ _addHandler(type: string, handler: Function, direct?: boolean): () => void;
8
+ _removeHandler(type: string, handler: Function): void;
9
+ _runHandlerSync(type: string, ...args: unknown[]): any[];
10
+ _runHandler(type: string, ...args: unknown[]): Promise<void>;
11
+ _handleError(error: Error | unknown): Promise<void>;
12
+ }
13
+
14
+ declare const STATE_ANY = "*";
15
+ declare const STATE_INITIAL = "";
16
+ declare const STATE_FINAL = "";
17
+ declare const EVENT_ANY = "*";
18
+ declare const EVENT_EMPTY = "";
19
+ type FsmStateKey = string;
20
+ type FsmEventKey = string;
21
+ type FsmStateConfig = {
22
+ key: FsmStateKey;
23
+ transitions?: [from: FsmStateKey, event: FsmEventKey, to: FsmStateKey][];
24
+ states?: FsmStateConfig[];
25
+ } & Record<string, any>;
26
+
27
+ declare class FsmStateDescriptor {
28
+ transitions: Record<string, Record<string, string>>;
29
+ states: Record<string, FsmStateDescriptor>;
30
+ static build(config: FsmStateConfig): FsmStateDescriptor;
31
+ getTargetStateKey(stateKey: string, eventKey: string): string;
32
+ }
33
+
34
+ type FsmStateDump = Record<string, any> & {
35
+ key: string;
36
+ data: Record<string, unknown>;
37
+ };
38
+ type FsmStateHandler = (state: FsmState, ...args: unknown[]) => void | Promise<void>;
39
+ type FsmStateSyncHandler = (state: FsmState, ...args: unknown[]) => void;
40
+ type FsmStateDumpHandler = (state: FsmState, dump: FsmStateDump) => void | Promise<void>;
41
+ type FsmStateErrorHandler = (state: FsmState, error: any) => void | Promise<void>;
42
+ declare class FsmState extends FsmBaseClass {
43
+ process: FsmProcess;
44
+ key: string;
45
+ parent?: FsmState;
46
+ descriptor?: FsmStateDescriptor;
47
+ constructor(process: FsmProcess, parent: FsmState | undefined, key: string, descriptor?: FsmStateDescriptor);
48
+ onEnter(handler: FsmStateHandler): () => void;
49
+ onExit(handler: FsmStateHandler): () => void;
50
+ onStateError(handler: FsmStateErrorHandler): () => void;
51
+ dump(handler: FsmStateDumpHandler): () => void;
52
+ restore(handler: FsmStateDumpHandler): () => void;
53
+ getData<T>(key: string, recursive?: boolean): T | undefined;
54
+ useData<T>(key: string): (((recursive?: boolean) => T | undefined) | ((value: T) => this))[];
55
+ _handleError(error: Error | unknown): Promise<void>;
56
+ }
57
+
58
+ declare const STATUS_NONE = 0;
59
+ declare const STATUS_FIRST = 1;
60
+ declare const STATUS_NEXT = 2;
61
+ declare const STATUS_LEAF = 4;
62
+ declare const STATUS_LAST = 8;
63
+ declare const STATUS_FINISHED = 16;
64
+ declare const STATUS_ENTER: number;
65
+ declare const STATUS_EXIT: number;
66
+ type FsmProcessHandler = (process: FsmProcess, ...args: any[]) => void | Promise<void>;
67
+ type FsmProcessDump = Record<string, any> & {
68
+ status: number;
69
+ event?: string;
70
+ stack: FsmStateDump[];
71
+ };
72
+ type FsmProcessDumpHandler = (process: FsmProcess, dump: FsmProcessDump) => void | Promise<void>;
73
+ declare class FsmProcess extends FsmBaseClass {
74
+ state?: FsmState;
75
+ event?: string;
76
+ status: number;
77
+ config: FsmStateConfig;
78
+ rootDescriptor: FsmStateDescriptor;
79
+ constructor(config: FsmStateConfig);
80
+ dispatch(event: string, mask?: number): Promise<boolean>;
81
+ dump(...args: unknown[]): Promise<FsmProcessDump>;
82
+ restore(dump: FsmProcessDump, ...args: unknown[]): Promise<this>;
83
+ onStateCreate(handler: FsmStateSyncHandler): () => void;
84
+ onStateError(handler: (state: FsmState, error: any) => void | Promise<void>): () => void;
85
+ _handleStateError(state: FsmState, error: Error | unknown): Promise<void>;
86
+ _newState(parent: FsmState | undefined, key: string, descriptor: FsmStateDescriptor | undefined): FsmState;
87
+ _getSubstate(parent: FsmState | undefined, prevStateKey: string | undefined): FsmState | undefined;
88
+ _newSubstate(parent: FsmState | undefined, toState: string): FsmState;
89
+ _update(): boolean;
90
+ }
91
+
92
+ declare const KEY_HANDLERS = "handlers";
93
+ declare function callStateHandlers(state: FsmState): void;
94
+ declare function addSubstateHandlers(state: FsmState, handlers: Record<string, FsmStateHandler>): void;
95
+
96
+ type Printer = (...args: any[]) => void;
97
+ type PrinterConfig = {
98
+ prefix?: string;
99
+ print?: (...args: any[]) => void;
100
+ lineNumbers?: boolean;
101
+ };
102
+ declare const KEY_PRINTER = "printer";
103
+ declare function preparePrinter(process: FsmProcess, { prefix, print, lineNumbers }: PrinterConfig): Printer;
104
+ declare function setPrinter(state: FsmState, config?: PrinterConfig): void;
105
+ declare function setProcessPrinter(process: FsmProcess, config?: PrinterConfig): void;
106
+ declare function getPrinter(state: FsmState): Printer;
107
+
108
+ declare function setProcessTracer(process: FsmProcess, print?: Printer): () => void;
109
+ declare function setStateTracer(state: FsmState, print?: Printer): void;
110
+
111
+ export { EVENT_ANY, EVENT_EMPTY, type FsmEventKey, FsmProcess, type FsmProcessDump, type FsmProcessDumpHandler, type FsmProcessHandler, FsmState, type FsmStateConfig, FsmStateDescriptor, type FsmStateDump, type FsmStateDumpHandler, type FsmStateErrorHandler, type FsmStateHandler, type FsmStateKey, type FsmStateSyncHandler, KEY_HANDLERS, KEY_PRINTER, type Printer, type PrinterConfig, STATE_ANY, STATE_FINAL, STATE_INITIAL, STATUS_ENTER, STATUS_EXIT, STATUS_FINISHED, STATUS_FIRST, STATUS_LAST, STATUS_LEAF, STATUS_NEXT, STATUS_NONE, addSubstateHandlers, callStateHandlers, getPrinter, preparePrinter, setPrinter, setProcessPrinter, setProcessTracer, setStateTracer };