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.
Files changed (50) hide show
  1. package/README.md +190 -6
  2. package/lib/cjs/index.d.ts +282 -0
  3. package/lib/cjs/index.js +331 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/cjs/internal/defs.private.d.ts +31 -0
  6. package/lib/cjs/internal/defs.private.js +3 -0
  7. package/lib/cjs/internal/defs.private.js.map +1 -0
  8. package/lib/cjs/internal/dispatch.debug.d.ts +4 -0
  9. package/lib/cjs/internal/dispatch.debug.js +330 -0
  10. package/lib/cjs/internal/dispatch.debug.js.map +1 -0
  11. package/lib/cjs/internal/dispatch.production.d.ts +6 -0
  12. package/lib/cjs/internal/dispatch.production.js +239 -0
  13. package/lib/cjs/internal/dispatch.production.js.map +1 -0
  14. package/lib/cjs/internal/dispatch.trace.d.ts +4 -0
  15. package/lib/cjs/internal/dispatch.trace.js +410 -0
  16. package/lib/cjs/internal/dispatch.trace.js.map +1 -0
  17. package/lib/cjs/internal/hsm.d.ts +54 -0
  18. package/lib/cjs/internal/hsm.js +182 -0
  19. package/lib/cjs/internal/hsm.js.map +1 -0
  20. package/lib/cjs/internal/utils.d.ts +18 -0
  21. package/lib/cjs/internal/utils.js +51 -0
  22. package/lib/cjs/internal/utils.js.map +1 -0
  23. package/lib/cjs/package.json +3 -0
  24. package/lib/esm/index.d.ts +282 -0
  25. package/lib/esm/index.js +314 -0
  26. package/lib/esm/index.js.map +1 -0
  27. package/lib/esm/internal/defs.private.d.ts +31 -0
  28. package/lib/esm/internal/defs.private.js +2 -0
  29. package/lib/esm/internal/defs.private.js.map +1 -0
  30. package/lib/esm/internal/dispatch.debug.d.ts +4 -0
  31. package/lib/esm/internal/dispatch.debug.js +326 -0
  32. package/lib/esm/internal/dispatch.debug.js.map +1 -0
  33. package/lib/esm/internal/dispatch.production.d.ts +6 -0
  34. package/lib/esm/internal/dispatch.production.js +235 -0
  35. package/lib/esm/internal/dispatch.production.js.map +1 -0
  36. package/lib/esm/internal/dispatch.trace.d.ts +4 -0
  37. package/lib/esm/internal/dispatch.trace.js +406 -0
  38. package/lib/esm/internal/dispatch.trace.js.map +1 -0
  39. package/lib/esm/internal/hsm.d.ts +54 -0
  40. package/lib/esm/internal/hsm.js +178 -0
  41. package/lib/esm/internal/hsm.js.map +1 -0
  42. package/lib/esm/internal/utils.d.ts +18 -0
  43. package/lib/esm/internal/utils.js +41 -0
  44. package/lib/esm/internal/utils.js.map +1 -0
  45. package/lib/esm/package.json +3 -0
  46. package/package.json +114 -66
  47. package/lib/index.browser.js +0 -523
  48. package/lib/index.d.ts +0 -104
  49. package/lib/index.js +0 -374
  50. package/tsconfig.json +0 -72
@@ -0,0 +1,314 @@
1
+ import { HsmObject } from './internal/hsm.js';
2
+ import { hasInitialState, quoteError, defineStateName as defineStateNameInternal, getStateName } from './internal/utils.js';
3
+ // export type DispatchErrorCallback<Context, Protocol extends {} | undefined> = (hsm: Hsm<Context, Protocol>, traceWriter: TraceWriter, err: Error) => void;
4
+ /**
5
+ * Trace verbosity for dispatch logging.
6
+ * @category Factory
7
+ */
8
+ export var TraceLevel;
9
+ (function (TraceLevel) {
10
+ TraceLevel[TraceLevel["PRODUCTION"] = 0] = "PRODUCTION";
11
+ TraceLevel[TraceLevel["DEBUG"] = 1] = "DEBUG";
12
+ TraceLevel[TraceLevel["VERBOSE_DEBUG"] = 2] = "VERBOSE_DEBUG";
13
+ })(TraceLevel || (TraceLevel = {}));
14
+ /**
15
+ * Root of the state class hierarchy; hosts mailbox machinery. Subclass or pass to {@link makeHsm}.
16
+ * @category State machine
17
+ */
18
+ export class TopState {
19
+ ctx;
20
+ hsm;
21
+ constructor() {
22
+ throw new Error('Fatal error: States cannot be instantiated');
23
+ }
24
+ get eventName() {
25
+ return this.hsm.eventName;
26
+ }
27
+ get eventPayload() {
28
+ return this.hsm.eventPayload;
29
+ }
30
+ get traceHeader() {
31
+ return this.hsm.traceHeader;
32
+ }
33
+ get topState() {
34
+ return this.hsm.topState;
35
+ }
36
+ get currentStateName() {
37
+ return this.hsm.currentStateName;
38
+ }
39
+ get currentState() {
40
+ return this.hsm.currentState;
41
+ }
42
+ get ctxTypeName() {
43
+ return this.hsm.ctxTypeName;
44
+ }
45
+ set traceLevel(value) {
46
+ this.hsm.traceLevel = value;
47
+ }
48
+ get traceLevel() {
49
+ return this.hsm.traceLevel;
50
+ }
51
+ get topStateName() {
52
+ return this.hsm.topStateName;
53
+ }
54
+ get traceWriter() {
55
+ return this.hsm.traceWriter;
56
+ }
57
+ set traceWriter(value) {
58
+ this.hsm.traceWriter = value;
59
+ }
60
+ get dispatchErrorCallback() {
61
+ return this.hsm.dispatchErrorCallback;
62
+ }
63
+ set dispatchErrorCallback(value) {
64
+ this.hsm.dispatchErrorCallback = value;
65
+ }
66
+ transition(nextState) {
67
+ this.hsm.transition(nextState);
68
+ }
69
+ unhandled() {
70
+ this.hsm.unhandled();
71
+ }
72
+ sleep(millis) {
73
+ return this.hsm.sleep(millis);
74
+ }
75
+ post(eventName, ...eventPayload) {
76
+ this.hsm.post(eventName, ...eventPayload);
77
+ }
78
+ deferredPost(millis, eventName, ...eventPayload) {
79
+ this.hsm.deferredPost(millis, eventName, ...eventPayload);
80
+ }
81
+ postNow(eventName, ...eventPayload) {
82
+ this.hsm.postNow(eventName, ...eventPayload);
83
+ }
84
+ onExit() { }
85
+ onEntry() { }
86
+ onError(error) {
87
+ throw error;
88
+ }
89
+ onUnhandled(error) {
90
+ throw error;
91
+ }
92
+ }
93
+ /**
94
+ * @category Error
95
+ */
96
+ export class HsmError extends Error {
97
+ name;
98
+ topStateName;
99
+ stateName;
100
+ context;
101
+ cause;
102
+ constructor(name, hsm, message, cause) {
103
+ super(message);
104
+ this.name = name;
105
+ this.topStateName = hsm.topStateName;
106
+ this.stateName = hsm.currentStateName;
107
+ this.context = hsm.ctx;
108
+ this.cause = cause;
109
+ }
110
+ }
111
+ /**
112
+ * @category Error
113
+ */
114
+ export class RuntimeError extends HsmError {
115
+ eventName;
116
+ eventPayload;
117
+ constructor(errorName, hsm, message, cause) {
118
+ super(errorName, hsm, message, cause);
119
+ this.eventName = hsm.eventName;
120
+ this.eventPayload = hsm.eventPayload;
121
+ }
122
+ }
123
+ /**
124
+ * @category Error
125
+ */
126
+ export class TransitionError extends RuntimeError {
127
+ failedStateName;
128
+ failedCallback;
129
+ fromStateName;
130
+ toStateName;
131
+ constructor(hsm, cause, failedStateName, failedCallback, fromStateName, toStateName) {
132
+ super('TransitionError', hsm, `${failedStateName}.${failedCallback}() has failed while executing a transition from ${fromStateName} to ${toStateName}`, cause);
133
+ this.failedStateName = failedStateName;
134
+ this.failedCallback = failedCallback;
135
+ this.fromStateName = fromStateName;
136
+ this.toStateName = toStateName;
137
+ }
138
+ }
139
+ /**
140
+ * @category Error
141
+ */
142
+ export class EventHandlerError extends RuntimeError {
143
+ constructor(hsm, cause) {
144
+ super('EventHandlerError', hsm, `an error was thrown while executing event handler #${hsm.eventName} in state ${hsm.currentStateName}`, cause);
145
+ }
146
+ }
147
+ /**
148
+ * @category Error
149
+ */
150
+ export class UnhandledEventError extends RuntimeError {
151
+ constructor(hsm) {
152
+ super('UnhandledEventError', hsm, `event #${hsm.eventName} was unhandled in state ${hsm.currentStateName}`);
153
+ }
154
+ }
155
+ /**
156
+ * @category Error
157
+ */
158
+ export class InitialStateError extends Error {
159
+ targetStateName;
160
+ constructor(targetState) {
161
+ super(`State '${getStateName(Object.getPrototypeOf(targetState.prototype).constructor)}' must not have more than one initial state`);
162
+ this.name = 'InitialStateError';
163
+ this.targetStateName = getStateName(targetState);
164
+ }
165
+ }
166
+ /**
167
+ * @category Error
168
+ */
169
+ export class FatalError extends RuntimeError {
170
+ constructor(hsm, cause) {
171
+ super('FatalError', hsm, `onError() has thrown ${quoteError(cause)}`, cause);
172
+ }
173
+ }
174
+ /**
175
+ * @category Error
176
+ */
177
+ export class InitializationError extends HsmError {
178
+ failedState;
179
+ constructor(hsm, failedState, cause) {
180
+ super('InitializationError', hsm, `state ${getStateName(failedState)} has thrown ${quoteError(cause)} during initialization`, cause);
181
+ this.failedState = failedState;
182
+ }
183
+ }
184
+ /**
185
+ * Terminal error state class used when the machine cannot recover.
186
+ * @category State machine
187
+ */
188
+ export class FatalErrorState extends TopState {
189
+ }
190
+ defineStateNameInternal(TopState, 'TopState');
191
+ defineStateNameInternal(FatalErrorState, 'FatalErrorState');
192
+ /**
193
+ * Marks `TargetState` as the initial substate of its parent composite state.
194
+ * @category Factory
195
+ */
196
+ export function InitialState(TargetState) {
197
+ const ParentOfTargetState = Object.getPrototypeOf(TargetState.prototype).constructor;
198
+ if (hasInitialState(ParentOfTargetState))
199
+ throw new InitialStateError(TargetState);
200
+ Object.defineProperty(TargetState, '_isInitialState', {
201
+ value: true,
202
+ writable: false,
203
+ configurable: false,
204
+ enumerable: false,
205
+ });
206
+ Object.defineProperty(ParentOfTargetState, '_initialState', {
207
+ value: TargetState,
208
+ writable: false,
209
+ configurable: false,
210
+ enumerable: false,
211
+ });
212
+ }
213
+ /**
214
+ * Assigns a stable display name to a state class.
215
+ *
216
+ * Minifiers (and browser production bundles) rewrite class names, so the
217
+ * built-in `Class.name` is unreliable in optimized builds. Registering an
218
+ * explicit name keeps {@link Properties.currentStateName},
219
+ * {@link Properties.topStateName}, trace output, and error messages stable in
220
+ * every environment (Node and minified browsers alike).
221
+ *
222
+ * The name is stored as a non-enumerable, non-inherited own property, so it is
223
+ * never accidentally shared with subclasses through the prototype chain.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * class Door extends TopState {}
228
+ * defineStateName(Door, 'Door');
229
+ * ```
230
+ * @category State machine
231
+ */
232
+ export function defineStateName(state, name) {
233
+ defineStateNameInternal(state, name);
234
+ }
235
+ /**
236
+ * Registers stable display names for every state class found in an exports map,
237
+ * using the export key as the display name.
238
+ *
239
+ * This is the convenient way to make a whole machine module minification-safe:
240
+ * pass the module namespace (or an object literal of the state classes) and
241
+ * each state class gets its export key as its display name. Non state-class
242
+ * values (factory functions, interfaces compiled away, constants) are ignored.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * // machine.ts
247
+ * export class DoorTop extends TopState {}
248
+ * export class Open extends DoorTop {}
249
+ * export class Closed extends DoorTop {}
250
+ * registerStateNames({ DoorTop, Open, Closed });
251
+ * ```
252
+ * @example
253
+ * ```ts
254
+ * // from another module
255
+ * import * as machine from './machine';
256
+ * registerStateNames(machine);
257
+ * ```
258
+ * @category State machine
259
+ */
260
+ export function registerStateNames(exports) {
261
+ for (const [exportName, value] of Object.entries(exports)) {
262
+ if (isStateClass(value)) {
263
+ defineStateNameInternal(value, exportName);
264
+ }
265
+ }
266
+ }
267
+ /** @internal — structural guard: a constructor whose prototype derives from {@link TopState}. */
268
+ function isStateClass(value) {
269
+ if (typeof value !== 'function')
270
+ return false;
271
+ const prototype = value.prototype;
272
+ return typeof prototype === 'object' && prototype !== null && TopState.prototype.isPrototypeOf(prototype);
273
+ }
274
+ /** @internal */
275
+ class ConsoleTraceWriter {
276
+ write(hsm, Message) {
277
+ if (typeof Message == 'string') {
278
+ console.log(`${hsm.traceHeader}${hsm.currentStateName}: ${Message}`);
279
+ }
280
+ else {
281
+ console.log(Message);
282
+ }
283
+ }
284
+ }
285
+ function defaultDispatchErrorCallback(hsm, err) {
286
+ const writer = hsm.traceWriter;
287
+ writer.write(hsm, `An event dispatch has failed; error ${err.name}: ${err.message} has not been managed`);
288
+ writer.write(hsm, err);
289
+ throw err;
290
+ }
291
+ const defaultTraceWriter = new ConsoleTraceWriter();
292
+ const defaultTraceLevel = TraceLevel.DEBUG;
293
+ const defaultInitialize = true;
294
+ /**
295
+ * Creates a state machine instance bound to the given context object.
296
+ *
297
+ * @param topState - Root state class
298
+ * @param ctx - Mutable domain context
299
+ * @param initialize - When `true`, walk `@InitialState` chain and run `onEntry` on the path to the initial leaf (default `true`)
300
+ * @param traceLevel - Trace verbosity (default {@link TraceLevel.DEBUG})
301
+ * @param traceWriter - Trace sink (default console logger)
302
+ * @param dispatchErrorCallback - Hook when dispatch throws and is not recovered (default: log and rethrow)
303
+ * @category Factory
304
+ */
305
+ export function makeHsm(topState, ctx, initialize = defaultInitialize, traceLevel = defaultTraceLevel, traceWriter = defaultTraceWriter, dispatchErrorCallback = defaultDispatchErrorCallback) {
306
+ const instance = {
307
+ hsm: undefined,
308
+ ctx: ctx,
309
+ };
310
+ Object.setPrototypeOf(instance, topState.prototype);
311
+ instance.hsm = new HsmObject(topState, instance, traceWriter, traceLevel, dispatchErrorCallback, initialize);
312
+ return instance.hsm;
313
+ }
314
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,IAAI,uBAAuB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA+BzH,6JAA6J;AAE7J;;;GAGG;AACH,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACrB,uDAAU,CAAA;IACV,6CAAK,CAAA;IACL,6DAAa,CAAA;AACd,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AAuGD;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IACpB,GAAG,CAAW;IACd,GAAG,CAA4B;IACxC;QACC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;IAC3B,CAAC;IACD,IAAI,YAAY;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;IAC9B,CAAC;IACD,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;IAC7B,CAAC;IACD,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,GAAG,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A2C,GAA4B,EAAE,GAAU;IACvH,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,CAAC;IAC/B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,uCAAuC,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC;IAC1G,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvB,MAAM,GAAG,CAAC;AACX,CAAC;AAED,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;AACpD,MAAM,iBAAiB,GAAG,UAAU,CAAC,KAAK,CAAC;AAC3C,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CAA2C,QAAuC,EAAE,GAAY,EAAE,aAAsB,iBAAiB,EAAE,aAAyB,iBAAiB,EAAE,cAA2B,kBAAkB,EAAE,wBAAkE,4BAA4B;IAC1V,MAAM,QAAQ,GAAgC;QAC7C,GAAG,EAAE,SAAyD;QAC9D,GAAG,EAAE,GAAG;KACR,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpD,QAAQ,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,EAAE,UAAU,CAAC,CAAC;IAC7G,OAAO,QAAQ,CAAC,GAAG,CAAC;AACrB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { PostedEvent, EventPayload, Hsm, StateClass, State } from '../index.js';
2
+ /** @internal */
3
+ export interface Instance<Context, Protocol extends {} | undefined> {
4
+ ctx: Context;
5
+ hsm: HsmWithTracing<Context, Protocol>;
6
+ }
7
+ /** @internal */
8
+ export interface Transition<Context, Protocol extends {} | undefined> {
9
+ execute(hsm: HsmWithTracing<Context, Protocol>, srcState: StateClass<Context, Protocol>, dstState: StateClass<Context, Protocol>): Promise<void>;
10
+ }
11
+ /** @internal */
12
+ export type DoneCallback = () => void;
13
+ /** @internal */
14
+ export type Task = (done: DoneCallback) => void;
15
+ /** @internal */
16
+ export interface HsmWithTracing<Context, Protocol extends {} | undefined> extends Hsm<Context, Protocol>, State<Context, Protocol> {
17
+ _transitionCache: Map<string, Transition<Context, Protocol>>;
18
+ _createInitTask: <DispatchContext, DispatchProtocol extends {} | undefined>(hsm: HsmWithTracing<DispatchContext, DispatchProtocol>) => Task;
19
+ _createEventDispatchTask: <DispatchContext, DispatchProtocol extends {} | undefined, EventName extends keyof DispatchProtocol>(hsm: HsmWithTracing<DispatchContext, DispatchProtocol>, eventName: PostedEvent<DispatchProtocol, EventName>, ...eventPayload: EventPayload<DispatchProtocol, EventName>) => Task;
20
+ _instance: Instance<Context, Protocol>;
21
+ _transitionState?: StateClass<Context, Protocol>;
22
+ _currentEventName?: string;
23
+ _currentEventPayload?: any[];
24
+ currentState: StateClass<Context, Protocol>;
25
+ _tracePush(domain: string, msg: string): void;
26
+ _tracePopDone(msg: string): void;
27
+ _tracePopError(msg: string): void;
28
+ _traceWrite(msg: any): void;
29
+ unshiftHiPriorityTask(t: Task): void;
30
+ pushHiPriorityTask(t: Task): void;
31
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=defs.private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defs.private.js","sourceRoot":"","sources":["../../../src/internal/defs.private.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { PostedEvent, EventPayload } from '../index.js';
2
+ import { HsmWithTracing, Task } from './defs.private.js';
3
+ export declare function createInitTask<DispatchContext, DispatchProtocol extends {} | undefined>(hsm: HsmWithTracing<DispatchContext, DispatchProtocol>): Task;
4
+ export declare function createEventDispatchTask<DispatchContext, DispatchProtocol extends {} | undefined, EventName extends keyof DispatchProtocol>(hsm: HsmWithTracing<DispatchContext, DispatchProtocol>, eventName: PostedEvent<DispatchProtocol, EventName>, ...eventPayload: EventPayload<DispatchProtocol, EventName>): Task;