ihsm 0.0.14 → 0.0.19
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 +190 -6
- package/lib/cjs/index.d.ts +282 -0
- package/lib/cjs/index.js +331 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/internal/defs.private.d.ts +31 -0
- package/lib/cjs/internal/defs.private.js +3 -0
- package/lib/cjs/internal/defs.private.js.map +1 -0
- package/lib/cjs/internal/dispatch.debug.d.ts +4 -0
- package/lib/cjs/internal/dispatch.debug.js +330 -0
- package/lib/cjs/internal/dispatch.debug.js.map +1 -0
- package/lib/cjs/internal/dispatch.production.d.ts +6 -0
- package/lib/cjs/internal/dispatch.production.js +239 -0
- package/lib/cjs/internal/dispatch.production.js.map +1 -0
- package/lib/cjs/internal/dispatch.trace.d.ts +4 -0
- package/lib/cjs/internal/dispatch.trace.js +410 -0
- package/lib/cjs/internal/dispatch.trace.js.map +1 -0
- package/lib/cjs/internal/hsm.d.ts +54 -0
- package/lib/cjs/internal/hsm.js +182 -0
- package/lib/cjs/internal/hsm.js.map +1 -0
- package/lib/cjs/internal/utils.d.ts +18 -0
- package/lib/cjs/internal/utils.js +51 -0
- package/lib/cjs/internal/utils.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/esm/index.d.ts +282 -0
- package/lib/esm/index.js +314 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/internal/defs.private.d.ts +31 -0
- package/lib/esm/internal/defs.private.js +2 -0
- package/lib/esm/internal/defs.private.js.map +1 -0
- package/lib/esm/internal/dispatch.debug.d.ts +4 -0
- package/lib/esm/internal/dispatch.debug.js +326 -0
- package/lib/esm/internal/dispatch.debug.js.map +1 -0
- package/lib/esm/internal/dispatch.production.d.ts +6 -0
- package/lib/esm/internal/dispatch.production.js +235 -0
- package/lib/esm/internal/dispatch.production.js.map +1 -0
- package/lib/esm/internal/dispatch.trace.d.ts +4 -0
- package/lib/esm/internal/dispatch.trace.js +406 -0
- package/lib/esm/internal/dispatch.trace.js.map +1 -0
- package/lib/esm/internal/hsm.d.ts +54 -0
- package/lib/esm/internal/hsm.js +178 -0
- package/lib/esm/internal/hsm.js.map +1 -0
- package/lib/esm/internal/utils.d.ts +18 -0
- package/lib/esm/internal/utils.js +41 -0
- package/lib/esm/internal/utils.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/package.json +114 -66
- package/lib/index.browser.js +0 -523
- package/lib/index.d.ts +0 -104
- package/lib/index.js +0 -374
- package/tsconfig.json +0 -72
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hsm.js","sourceRoot":"","sources":["../../../src/internal/hsm.ts"],"names":[],"mappings":";;;AAAA,2BAA+K;AAE/K,qDAAwI;AACxI,qDAA8H;AAC9H,+DAA6I;AAC7I,mCAAuC;AAEvC,SAAS,kBAAkB,CAAC,UAAsB;IACjD,QAAQ,UAAU,EAAE,CAAC;QACpB,KAAK,cAAU,CAAC,UAAU;YACzB,OAAO,oCAAwB,CAAC;QACjC,KAAK,cAAU,CAAC,KAAK;YACpB,OAAO,+BAAmB,CAAC;QAC5B,KAAK,cAAU,CAAC,aAAa;YAC5B,OAAO,+BAAsB,CAAC;IAChC,CAAC;AACF,CAAC;AAED,SAAS,2BAA2B,CAAC,UAAsB;IAC1D,QAAQ,UAAU,EAAE,CAAC;QACpB,KAAK,cAAU,CAAC,UAAU;YACzB,OAAO,6CAA6B,CAAC;QACtC,KAAK,cAAU,CAAC,KAAK;YACpB,OAAO,wCAAwB,CAAC;QACjC,KAAK,cAAU,CAAC,aAAa;YAC5B,OAAO,wCAA+B,CAAC;IACzC,CAAC;AACF,CAAC;AAED,gBAAgB;AAChB,kBAAkB;AAClB,MAAa,SAAS;IAEd,QAAQ,CAAgC;IACxC,YAAY,CAAS;IACZ,WAAW,CAAS;IAC7B,WAAW,CAAc;IAEzB,SAAS,CAA8B;IACvC,gBAAgB,GAA+C,IAAI,GAAG,EAAE,CAAC;IAC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,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;IAC/F,CAAC;IAED,IAAI,CAAmC,SAA2C,EAAE,GAAG,YAAiD;QACvI,OAAO,IAAI,OAAO,CAAuC,CAAC,OAA+D,EAAE,MAA8B,EAAE,EAAE;YAC5J,MAAM,WAAW,GAAkF,IAAI,CAAC,wBAA+B,CAAC;YACxI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACJ,CAAC;CAED;AA1LD,8BA0LC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
import { StateClass } from '../';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare function asError(err: unknown): Error;
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare function quoteUnknown(err: unknown): string;
|
|
7
|
+
/** @internal */
|
|
8
|
+
export declare function quoteError(err: Error): string;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export declare function getInitialState<Context, Protocol extends {} | undefined>(State: StateClass<Context, Protocol>): StateClass<Context, Protocol>;
|
|
11
|
+
/** @internal */
|
|
12
|
+
export declare function hasInitialState<Context, Protocol extends {} | undefined>(State: StateClass<Context, Protocol>): boolean;
|
|
13
|
+
/** @internal */
|
|
14
|
+
export declare function getTransitionKey<Context, Protocol extends {} | undefined>(FromState: StateClass<Context, Protocol>, ToState: StateClass<Context, Protocol>): string;
|
|
15
|
+
/** @internal */
|
|
16
|
+
export declare function defineStateName<Context, Protocol extends {} | undefined>(state: StateClass<Context, Protocol>, displayName: string): void;
|
|
17
|
+
/** @internal — prefers an own explicit name registered for minified browser bundles. */
|
|
18
|
+
export declare function getStateName<Context, Protocol extends {} | undefined>(state: StateClass<Context, Protocol>): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asError = asError;
|
|
4
|
+
exports.quoteUnknown = quoteUnknown;
|
|
5
|
+
exports.quoteError = quoteError;
|
|
6
|
+
exports.getInitialState = getInitialState;
|
|
7
|
+
exports.hasInitialState = hasInitialState;
|
|
8
|
+
exports.getTransitionKey = getTransitionKey;
|
|
9
|
+
exports.defineStateName = defineStateName;
|
|
10
|
+
exports.getStateName = getStateName;
|
|
11
|
+
/** @internal */
|
|
12
|
+
function asError(err) {
|
|
13
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
function quoteUnknown(err) {
|
|
17
|
+
return quoteError(asError(err));
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
function quoteError(err) {
|
|
21
|
+
return `${err.name}${err.message ? `: ${err.message}` : ' with no error message'}`;
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
function getInitialState(State) {
|
|
25
|
+
return State._initialState;
|
|
26
|
+
}
|
|
27
|
+
/** @internal */
|
|
28
|
+
function hasInitialState(State) {
|
|
29
|
+
return Object.prototype.hasOwnProperty.call(State, '_initialState');
|
|
30
|
+
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
function getTransitionKey(FromState, ToState) {
|
|
33
|
+
return `${getStateName(FromState)}=>${getStateName(ToState)}`;
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
function defineStateName(state, displayName) {
|
|
37
|
+
Object.defineProperty(state, '_stateName', {
|
|
38
|
+
value: displayName,
|
|
39
|
+
writable: false,
|
|
40
|
+
configurable: false,
|
|
41
|
+
enumerable: false,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** @internal — prefers an own explicit name registered for minified browser bundles. */
|
|
45
|
+
function getStateName(state) {
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(state, '_stateName')) {
|
|
47
|
+
return state._stateName;
|
|
48
|
+
}
|
|
49
|
+
return state.name;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/internal/utils.ts"],"names":[],"mappings":";;AAIA,0BAEC;AAGD,oCAEC;AAGD,gCAEC;AAGD,0CAEC;AAGD,0CAEC;AAGD,4CAEC;AAGD,0CAOC;AAGD,oCAKC;AA9CD,gBAAgB;AAChB,SAAgB,OAAO,CAAC,GAAY;IACnC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,gBAAgB;AAChB,SAAgB,YAAY,CAAC,GAAY;IACxC,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC;AAED,gBAAgB;AAChB,SAAgB,UAAU,CAAC,GAAU;IACpC,OAAO,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,wBAAwB,EAAE,CAAC;AACpF,CAAC;AAED,gBAAgB;AAChB,SAAgB,eAAe,CAA2C,KAAoC;IAC7G,OAAQ,KAAgC,CAAC,aAA8C,CAAC;AACzF,CAAC;AAED,gBAAgB;AAChB,SAAgB,eAAe,CAA2C,KAAoC;IAC7G,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AACrE,CAAC;AAED,gBAAgB;AAChB,SAAgB,gBAAgB,CAA2C,SAAwC,EAAE,OAAsC;IAC1J,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,KAAK,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED,gBAAgB;AAChB,SAAgB,eAAe,CAA2C,KAAoC,EAAE,WAAmB;IAClI,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE;QAC1C,KAAK,EAAE,WAAW;QAClB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,KAAK;KACjB,CAAC,CAAC;AACJ,CAAC;AAED,wFAAwF;AACxF,SAAgB,YAAY,CAA2C,KAAoC;IAC1G,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CAAC;QAC/D,OAAQ,KAA2C,CAAC,UAAU,CAAC;IAChE,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default context and protocol map when a machine is created without explicit typing.
|
|
3
|
+
* @category Factory
|
|
4
|
+
*/
|
|
5
|
+
export type Any = Record<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* Rejects an async {@link Hsm.call} service with an error.
|
|
8
|
+
* @category Event handler
|
|
9
|
+
*/
|
|
10
|
+
export type RejectCallback = (error: Error) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves an async {@link Hsm.call} service with a typed reply.
|
|
13
|
+
* @category Event handler
|
|
14
|
+
*/
|
|
15
|
+
export type ResolveCallback<Reply> = (result: Reply) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Called when event dispatch fails and the runtime does not recover via `onError`.
|
|
18
|
+
* @category Factory
|
|
19
|
+
*/
|
|
20
|
+
export interface DispatchErrorCallback<Context, Protocol extends {} | undefined> {
|
|
21
|
+
(hsm: Base<Context, Protocol>, err: Error): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Trace verbosity for dispatch logging.
|
|
25
|
+
* @category Factory
|
|
26
|
+
*/
|
|
27
|
+
export declare enum TraceLevel {
|
|
28
|
+
PRODUCTION = 0,
|
|
29
|
+
DEBUG = 1,
|
|
30
|
+
VERBOSE_DEBUG = 2
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Receives trace lines from the runtime and from handlers via `this.traceWriter.write`.
|
|
34
|
+
* @category Factory
|
|
35
|
+
*/
|
|
36
|
+
export interface TraceWriter {
|
|
37
|
+
write<Context, Protocol extends {} | undefined>(hsm: Properties<Context, Protocol>, msg: any): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @category State machine
|
|
41
|
+
*/
|
|
42
|
+
export interface Properties<Context, Protocol extends {} | undefined> {
|
|
43
|
+
readonly currentState: StateClass<Context, Protocol>;
|
|
44
|
+
readonly currentStateName: string;
|
|
45
|
+
readonly topState: StateClass<Context, Protocol>;
|
|
46
|
+
readonly topStateName: string;
|
|
47
|
+
readonly ctxTypeName: string;
|
|
48
|
+
readonly traceHeader: string;
|
|
49
|
+
readonly eventName: string;
|
|
50
|
+
readonly eventPayload: any[];
|
|
51
|
+
traceLevel: TraceLevel;
|
|
52
|
+
traceWriter: TraceWriter;
|
|
53
|
+
dispatchErrorCallback: DispatchErrorCallback<Context, Protocol>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @category State machine
|
|
57
|
+
*/
|
|
58
|
+
export interface Base<Context, Protocol extends {} | undefined> extends Properties<Context, Protocol> {
|
|
59
|
+
post<EventName extends keyof Protocol>(eventName: PostedEvent<Protocol, EventName>, ...eventPayload: EventPayload<Protocol, EventName>): void;
|
|
60
|
+
deferredPost<EventName extends keyof Protocol>(millis: number, eventName: PostedEvent<Protocol, EventName>, ...eventPayload: EventPayload<Protocol, EventName>): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @category State machine
|
|
64
|
+
*/
|
|
65
|
+
export interface State<Context, Protocol extends {} | undefined> extends Base<Context, Protocol> {
|
|
66
|
+
readonly ctx: Context;
|
|
67
|
+
transition(nextState: StateClass<Context, Protocol>): void;
|
|
68
|
+
unhandled(): never;
|
|
69
|
+
sleep(millis: number): Promise<void>;
|
|
70
|
+
/** Handler-only: queue an event on the internal high-priority mailbox (before normal `post`). */
|
|
71
|
+
postNow<EventName extends keyof Protocol>(eventName: PostedEvent<Protocol, EventName>, ...eventPayload: EventPayload<Protocol, EventName>): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Actor handle returned by {@link makeHsm} — client API (`post`, `call`, `sync`, `restore`).
|
|
75
|
+
* @category State machine
|
|
76
|
+
*/
|
|
77
|
+
export interface Hsm<Context = Any, Protocol extends {} | undefined = undefined> extends Base<Context, Protocol> {
|
|
78
|
+
readonly ctx: Context;
|
|
79
|
+
sync(): Promise<void>;
|
|
80
|
+
restore(state: StateClass<Context, Protocol>, ctx: Context): void;
|
|
81
|
+
call<EventName extends keyof Protocol>(eventName: ServiceName<Protocol, EventName>, ...eventPayload: ServiceRequest<Protocol, EventName>): Promise<ServiceResponse<Protocol, EventName>>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @category Event handler
|
|
85
|
+
*/
|
|
86
|
+
export type PostedEvent<Protocol extends {} | undefined, EventName extends keyof Protocol> = Protocol extends undefined ? string : EventName extends keyof State<any, any> ? never : EventName;
|
|
87
|
+
/**
|
|
88
|
+
* @category Event handler
|
|
89
|
+
*/
|
|
90
|
+
export type EventPayload<Protocol extends {} | undefined, EventName extends keyof Protocol> = Protocol extends undefined ? any[] : Protocol[EventName] extends (...payload: infer Payload) => Promise<void> | void ? (Payload extends any[] ? Payload : never) : never;
|
|
91
|
+
/**
|
|
92
|
+
* Constructor type for a state class in the machine hierarchy.
|
|
93
|
+
* @category State machine
|
|
94
|
+
*/
|
|
95
|
+
export type StateClass<Context = Any, Protocol extends {} | undefined = undefined> = Function & {
|
|
96
|
+
prototype: TopState<Context, Protocol>;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
*/
|
|
101
|
+
export type ServiceRequest<Protocol, EventName extends keyof Protocol> = Protocol extends undefined ? any[] : Protocol[EventName] extends (resolve: (result: infer Reply) => void, reject: (error: infer Error) => void, ...payload: infer Payload) => Promise<void> | void ? (Payload extends any[] ? Payload : never) : never;
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
export type ServiceResponse<Protocol, EventName extends keyof Protocol> = Protocol extends undefined ? any : Protocol[EventName] extends (resolve: infer Reply, reject: infer Error, ...payload: infer Payload) => Promise<void> | void ? Reply : never;
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
export type ServiceName<Protocol, EventName> = Protocol extends undefined ? string : EventName extends keyof State<any, any> ? never : EventName;
|
|
110
|
+
/**
|
|
111
|
+
* Optional lifecycle hooks implemented by state classes (`onEntry`, `onExit`, …).
|
|
112
|
+
* @category State machine
|
|
113
|
+
*/
|
|
114
|
+
export interface StateEvents<Context, Protocol extends {} | undefined> {
|
|
115
|
+
onExit(): Promise<void> | void;
|
|
116
|
+
onEntry(): Promise<void> | void;
|
|
117
|
+
onError<EventName extends keyof Protocol>(error: RuntimeError<Context, Protocol, EventName>): Promise<void> | void;
|
|
118
|
+
onUnhandled<EventName extends keyof Protocol>(error: UnhandledEventError<Context, Protocol, EventName>): Promise<void> | void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Root of the state class hierarchy; hosts mailbox machinery. Subclass or pass to {@link makeHsm}.
|
|
122
|
+
* @category State machine
|
|
123
|
+
*/
|
|
124
|
+
export declare abstract class TopState<Context = Any, Protocol extends {} | undefined = undefined> implements State<Context, Protocol>, StateEvents<Context, Protocol> {
|
|
125
|
+
readonly ctx: Context;
|
|
126
|
+
readonly hsm: State<Context, Protocol>;
|
|
127
|
+
constructor();
|
|
128
|
+
get eventName(): string;
|
|
129
|
+
get eventPayload(): any[];
|
|
130
|
+
get traceHeader(): string;
|
|
131
|
+
get topState(): StateClass<Context, Protocol>;
|
|
132
|
+
get currentStateName(): string;
|
|
133
|
+
get currentState(): StateClass<Context, Protocol>;
|
|
134
|
+
get ctxTypeName(): string;
|
|
135
|
+
set traceLevel(value: TraceLevel);
|
|
136
|
+
get traceLevel(): TraceLevel;
|
|
137
|
+
get topStateName(): string;
|
|
138
|
+
get traceWriter(): TraceWriter;
|
|
139
|
+
set traceWriter(value: TraceWriter);
|
|
140
|
+
get dispatchErrorCallback(): DispatchErrorCallback<Context, Protocol>;
|
|
141
|
+
set dispatchErrorCallback(value: DispatchErrorCallback<Context, Protocol>);
|
|
142
|
+
transition(nextState: StateClass<Context, Protocol>): void;
|
|
143
|
+
unhandled(): never;
|
|
144
|
+
sleep(millis: number): Promise<void>;
|
|
145
|
+
post<EventName extends keyof Protocol>(eventName: PostedEvent<Protocol, EventName>, ...eventPayload: EventPayload<Protocol, EventName>): void;
|
|
146
|
+
deferredPost<EventName extends keyof Protocol>(millis: number, eventName: PostedEvent<Protocol, EventName>, ...eventPayload: EventPayload<Protocol, EventName>): void;
|
|
147
|
+
postNow<EventName extends keyof Protocol>(eventName: PostedEvent<Protocol, EventName>, ...eventPayload: EventPayload<Protocol, EventName>): void;
|
|
148
|
+
onExit(): Promise<void> | void;
|
|
149
|
+
onEntry(): Promise<void> | void;
|
|
150
|
+
onError<EventName extends keyof Protocol>(error: RuntimeError<Context, Protocol, EventName>): Promise<void> | void;
|
|
151
|
+
onUnhandled<EventName extends keyof Protocol>(error: UnhandledEventError<Context, Protocol, EventName>): Promise<void> | void;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @category Error
|
|
155
|
+
*/
|
|
156
|
+
export declare abstract class HsmError<Context, Protocol extends {} | undefined> extends Error {
|
|
157
|
+
name: string;
|
|
158
|
+
topStateName: string;
|
|
159
|
+
stateName: string;
|
|
160
|
+
context: Context;
|
|
161
|
+
cause?: Error;
|
|
162
|
+
protected constructor(name: string, hsm: State<Context, Protocol>, message: string, cause?: Error);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @category Error
|
|
166
|
+
*/
|
|
167
|
+
export declare abstract class RuntimeError<Context, Protocol extends {} | undefined, EventName extends keyof Protocol> extends HsmError<Context, Protocol> {
|
|
168
|
+
eventName: PostedEvent<Protocol, EventName>;
|
|
169
|
+
eventPayload: EventPayload<Protocol, EventName>;
|
|
170
|
+
protected constructor(errorName: string, hsm: State<Context, Protocol>, message: string, cause?: Error);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* @category Error
|
|
174
|
+
*/
|
|
175
|
+
export declare class TransitionError<Context, Protocol extends {} | undefined, EventName extends keyof Protocol> extends RuntimeError<Context, Protocol, EventName> {
|
|
176
|
+
failedStateName: string;
|
|
177
|
+
failedCallback: 'onExit' | 'onEntry';
|
|
178
|
+
fromStateName: string;
|
|
179
|
+
toStateName: string;
|
|
180
|
+
constructor(hsm: State<Context, Protocol>, cause: Error, failedStateName: string, failedCallback: 'onExit' | 'onEntry', fromStateName: string, toStateName: string);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* @category Error
|
|
184
|
+
*/
|
|
185
|
+
export declare class EventHandlerError<Context, Protocol extends {} | undefined, EventName extends keyof Protocol> extends RuntimeError<Context, Protocol, EventName> {
|
|
186
|
+
constructor(hsm: State<Context, Protocol>, cause: Error);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @category Error
|
|
190
|
+
*/
|
|
191
|
+
export declare class UnhandledEventError<Context, Protocol extends {} | undefined, EventName extends keyof Protocol> extends RuntimeError<Context, Protocol, EventName> {
|
|
192
|
+
constructor(hsm: State<Context, Protocol>);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @category Error
|
|
196
|
+
*/
|
|
197
|
+
export declare class InitialStateError<Context, Protocol extends {} | undefined> extends Error {
|
|
198
|
+
targetStateName: string;
|
|
199
|
+
constructor(targetState: StateClass<Context, Protocol>);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @category Error
|
|
203
|
+
*/
|
|
204
|
+
export declare class FatalError<Context, Protocol extends {} | undefined, EventName extends keyof Protocol> extends RuntimeError<Context, Protocol, EventName> {
|
|
205
|
+
constructor(hsm: State<Context, Protocol>, cause: Error);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @category Error
|
|
209
|
+
*/
|
|
210
|
+
export declare class InitializationError<Context, Protocol extends {} | undefined> extends HsmError<Context, Protocol> {
|
|
211
|
+
failedState: StateClass<Context, Protocol>;
|
|
212
|
+
constructor(hsm: State<Context, Protocol>, failedState: StateClass<Context, Protocol>, cause: Error);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Terminal error state class used when the machine cannot recover.
|
|
216
|
+
* @category State machine
|
|
217
|
+
*/
|
|
218
|
+
export declare class FatalErrorState<Context, Protocol extends {} | undefined> extends TopState<Context, Protocol> {
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Marks `TargetState` as the initial substate of its parent composite state.
|
|
222
|
+
* @category Factory
|
|
223
|
+
*/
|
|
224
|
+
export declare function InitialState<Context, Protocol extends {} | undefined>(TargetState: StateClass<Context, Protocol>): void;
|
|
225
|
+
/**
|
|
226
|
+
* Assigns a stable display name to a state class.
|
|
227
|
+
*
|
|
228
|
+
* Minifiers (and browser production bundles) rewrite class names, so the
|
|
229
|
+
* built-in `Class.name` is unreliable in optimized builds. Registering an
|
|
230
|
+
* explicit name keeps {@link Properties.currentStateName},
|
|
231
|
+
* {@link Properties.topStateName}, trace output, and error messages stable in
|
|
232
|
+
* every environment (Node and minified browsers alike).
|
|
233
|
+
*
|
|
234
|
+
* The name is stored as a non-enumerable, non-inherited own property, so it is
|
|
235
|
+
* never accidentally shared with subclasses through the prototype chain.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* class Door extends TopState {}
|
|
240
|
+
* defineStateName(Door, 'Door');
|
|
241
|
+
* ```
|
|
242
|
+
* @category State machine
|
|
243
|
+
*/
|
|
244
|
+
export declare function defineStateName<Context, Protocol extends {} | undefined>(state: StateClass<Context, Protocol>, name: string): void;
|
|
245
|
+
/**
|
|
246
|
+
* Registers stable display names for every state class found in an exports map,
|
|
247
|
+
* using the export key as the display name.
|
|
248
|
+
*
|
|
249
|
+
* This is the convenient way to make a whole machine module minification-safe:
|
|
250
|
+
* pass the module namespace (or an object literal of the state classes) and
|
|
251
|
+
* each state class gets its export key as its display name. Non state-class
|
|
252
|
+
* values (factory functions, interfaces compiled away, constants) are ignored.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* // machine.ts
|
|
257
|
+
* export class DoorTop extends TopState {}
|
|
258
|
+
* export class Open extends DoorTop {}
|
|
259
|
+
* export class Closed extends DoorTop {}
|
|
260
|
+
* registerStateNames({ DoorTop, Open, Closed });
|
|
261
|
+
* ```
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* // from another module
|
|
265
|
+
* import * as machine from './machine';
|
|
266
|
+
* registerStateNames(machine);
|
|
267
|
+
* ```
|
|
268
|
+
* @category State machine
|
|
269
|
+
*/
|
|
270
|
+
export declare function registerStateNames(exports: Record<string, unknown>): void;
|
|
271
|
+
/**
|
|
272
|
+
* Creates a state machine instance bound to the given context object.
|
|
273
|
+
*
|
|
274
|
+
* @param topState - Root state class
|
|
275
|
+
* @param ctx - Mutable domain context
|
|
276
|
+
* @param initialize - When `true`, walk `@InitialState` chain and run `onEntry` on the path to the initial leaf (default `true`)
|
|
277
|
+
* @param traceLevel - Trace verbosity (default {@link TraceLevel.DEBUG})
|
|
278
|
+
* @param traceWriter - Trace sink (default console logger)
|
|
279
|
+
* @param dispatchErrorCallback - Hook when dispatch throws and is not recovered (default: log and rethrow)
|
|
280
|
+
* @category Factory
|
|
281
|
+
*/
|
|
282
|
+
export declare function makeHsm<Context, Protocol extends undefined | {}>(topState: StateClass<Context, Protocol>, ctx: Context, initialize?: boolean, traceLevel?: TraceLevel, traceWriter?: TraceWriter, dispatchErrorCallback?: DispatchErrorCallback<Context, Protocol>): Hsm<Context, Protocol>;
|