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