jssm 5.104.2 → 5.112.3
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/.gitattributes +17 -6
- package/.log-progress.json +9 -0
- package/CHANGELOG.md +130 -45
- package/CLAUDE.md +11 -0
- package/MIGRATING-jssm-viz.md +67 -0
- package/README.md +179 -882
- package/dist/es6/fsl_parser.js +1 -1
- package/dist/es6/jssm.d.ts +773 -39
- package/dist/es6/jssm.js +921 -89
- package/dist/es6/jssm_arrow.js +24 -0
- package/dist/es6/jssm_compiler.d.ts +17 -2
- package/dist/es6/jssm_compiler.js +17 -3
- package/dist/es6/jssm_constants.d.ts +27 -0
- package/dist/es6/jssm_constants.js +27 -0
- package/dist/es6/jssm_error.d.ts +19 -0
- package/dist/es6/jssm_error.js +19 -0
- package/dist/es6/jssm_theme.d.ts +11 -0
- package/dist/es6/jssm_theme.js +11 -0
- package/dist/es6/jssm_types.d.ts +29 -3
- package/dist/es6/jssm_util.d.ts +161 -9
- package/dist/es6/jssm_util.js +174 -17
- package/dist/es6/jssm_viz.d.ts +175 -0
- package/dist/es6/jssm_viz.js +560 -0
- package/dist/es6/jssm_viz_colors.d.ts +63 -0
- package/dist/es6/jssm_viz_colors.js +63 -0
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -0
- package/dist/jssm.es5.nonmin.cjs +2201 -870
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm.es6.nonmin.cjs +2200 -871
- package/dist/jssm_viz.cjs +1 -0
- package/dist/{jssm.es5.iife.nonmin.cjs → jssm_viz.es5.iife.nonmin.cjs} +2589 -1090
- package/dist/jssm_viz.es5.nonmin.cjs +24674 -0
- package/dist/jssm_viz.es6.nonmin.cjs +24661 -0
- package/dist/jssm_viz.iife.cjs +1 -0
- package/dist/jssm_viz.mjs +1 -0
- package/jest-dragon.config.cjs +4 -1
- package/jest-spec.config.cjs +9 -6
- package/jest-stoch.config.cjs +4 -1
- package/jest-unicode.config.cjs +4 -1
- package/jssm.es5.d.cts +950 -41
- package/jssm.es6.d.ts +950 -41
- package/jssm_viz.es5.d.cts +2127 -0
- package/jssm_viz.es6.d.ts +2127 -0
- package/log-progress.data.json +28 -0
- package/package.json +56 -23
- package/rollup.config.viz.es5.js +46 -0
- package/rollup.config.viz.es6.js +46 -0
- package/rollup.config.viz.iife.js +36 -0
- package/typedoc-options.cjs +4 -3
- package/dist/jssm.es5.iife.cjs +0 -1
- package/fsl_parser.d.ts +0 -6
- package/jssm.d.ts +0 -1141
- package/jssm_arrow.d.ts +0 -53
- package/jssm_compiler.d.ts +0 -135
- package/jssm_constants.d.ts +0 -5
- package/jssm_error.d.ts +0 -8
- package/jssm_theme.d.ts +0 -4
- package/jssm_types.d.ts +0 -378
- package/jssm_util.d.ts +0 -106
- package/version.d.ts +0 -2
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
declare type StateType = string;
|
|
2
2
|
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
|
|
3
|
-
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng } from './jssm_types';
|
|
3
|
+
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, EverythingHookContext, EverythingHookHandler, PostEverythingHookHandler, JssmRng } from './jssm_types';
|
|
4
4
|
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
|
|
5
5
|
import { compile, make, wrap_parse } from './jssm_compiler';
|
|
6
|
-
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, sleep } from './jssm_util';
|
|
6
|
+
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, gen_splitmix32, sleep } from './jssm_util';
|
|
7
7
|
import * as constants from './jssm_constants';
|
|
8
8
|
declare const shapes: string[], gviz_shapes: string[], named_colors: string[];
|
|
9
9
|
import { version, build_time } from './version';
|
|
@@ -17,7 +17,69 @@ import { version, build_time } from './version';
|
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
19
|
declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* Collapse a list of individual state-style key/value pairs into a single
|
|
23
|
+
* {@link JssmStateConfig} object, remapping FSL-style kebab-case keys to the
|
|
24
|
+
* camelCase field names the runtime uses.
|
|
25
|
+
*
|
|
26
|
+
* The parser emits state styling as a flat array like
|
|
27
|
+
* `[{ key: 'color', value: 'red' }, { key: 'line-style', value: 'dashed' }]`
|
|
28
|
+
* because that is the most natural shape for the grammar to produce. This
|
|
29
|
+
* helper runs once per style bucket during `Machine` construction to turn
|
|
30
|
+
* those arrays into the compact `{ color, lineStyle, ... }` objects the
|
|
31
|
+
* graph-rendering code expects.
|
|
32
|
+
*
|
|
33
|
+
* ```typescript
|
|
34
|
+
* state_style_condense([
|
|
35
|
+
* { key: 'color', value: 'red' },
|
|
36
|
+
* { key: 'shape', value: 'oval' },
|
|
37
|
+
* { key: 'line-style', value: 'dashed' }
|
|
38
|
+
* ]);
|
|
39
|
+
* // => { color: 'red', shape: 'oval', lineStyle: 'dashed' }
|
|
40
|
+
*
|
|
41
|
+
* state_style_condense(undefined);
|
|
42
|
+
* // => {}
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @param jssk The list of style keys to condense. `undefined` is accepted
|
|
46
|
+
* and yields an empty config.
|
|
47
|
+
*
|
|
48
|
+
* @param machine Optional `Machine` reference, used only so that any
|
|
49
|
+
* {@link JssmError} thrown can point at the offending machine in its
|
|
50
|
+
* diagnostic message.
|
|
51
|
+
*
|
|
52
|
+
* @returns A `JssmStateConfig` object containing every key from `jssk`
|
|
53
|
+
* remapped into its camelCase field.
|
|
54
|
+
*
|
|
55
|
+
* @throws {JssmError} If `jssk` is neither an array nor `undefined`, if any
|
|
56
|
+
* element is not an object, if the same key appears more than once, or if a
|
|
57
|
+
* key is not one of the recognized style names.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
declare function state_style_condense(jssk: JssmStateStyleKeyList, machine?: any): JssmStateConfig;
|
|
63
|
+
/*******
|
|
64
|
+
*
|
|
65
|
+
* Core finite state machine class. Holds the full graph of states and
|
|
66
|
+
* transitions, the current state, hooks, data, properties, and all runtime
|
|
67
|
+
* behavior. Typically created via the {@link sm} tagged template literal
|
|
68
|
+
* rather than constructed directly.
|
|
69
|
+
*
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { sm } from 'jssm';
|
|
72
|
+
*
|
|
73
|
+
* const light = sm`Red 'next' => Green 'next' => Yellow 'next' => Red;`;
|
|
74
|
+
* light.state(); // 'Red'
|
|
75
|
+
* light.action('next'); // true
|
|
76
|
+
* light.state(); // 'Green'
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @typeparam mDT The machine data type — the type of the value stored in
|
|
80
|
+
* `.data()`. Defaults to `undefined` when no data is used.
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
21
83
|
declare class Machine<mDT> {
|
|
22
84
|
_state: StateType;
|
|
23
85
|
_states: Map<StateType, JssmGenericState>;
|
|
@@ -90,6 +152,10 @@ declare class Machine<mDT> {
|
|
|
90
152
|
_post_main_transition_hook: HookHandler<mDT> | undefined;
|
|
91
153
|
_post_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
92
154
|
_post_any_transition_hook: HookHandler<mDT> | undefined;
|
|
155
|
+
_pre_everything_hook: EverythingHookHandler<mDT> | undefined;
|
|
156
|
+
_everything_hook: EverythingHookHandler<mDT> | undefined;
|
|
157
|
+
_pre_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
|
|
158
|
+
_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
|
|
93
159
|
_property_keys: Set<string>;
|
|
94
160
|
_default_properties: Map<string, any>;
|
|
95
161
|
_state_properties: Map<string, any>;
|
|
@@ -137,6 +203,8 @@ declare class Machine<mDT> {
|
|
|
137
203
|
*
|
|
138
204
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
139
205
|
*
|
|
206
|
+
* @returns The current state name.
|
|
207
|
+
*
|
|
140
208
|
*/
|
|
141
209
|
state(): StateType;
|
|
142
210
|
/*********
|
|
@@ -155,6 +223,10 @@ declare class Machine<mDT> {
|
|
|
155
223
|
*
|
|
156
224
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
157
225
|
*
|
|
226
|
+
* @param state The state to get the label for.
|
|
227
|
+
*
|
|
228
|
+
* @returns The label string, or `undefined` if no label is set.
|
|
229
|
+
*
|
|
158
230
|
*/
|
|
159
231
|
label_for(state: StateType): string;
|
|
160
232
|
/*********
|
|
@@ -178,6 +250,10 @@ declare class Machine<mDT> {
|
|
|
178
250
|
*
|
|
179
251
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
180
252
|
*
|
|
253
|
+
* @param state The state to get display text for.
|
|
254
|
+
*
|
|
255
|
+
* @returns The label if one exists, otherwise the state's name.
|
|
256
|
+
*
|
|
181
257
|
*/
|
|
182
258
|
display_text(state: StateType): string;
|
|
183
259
|
/*********
|
|
@@ -193,45 +269,60 @@ declare class Machine<mDT> {
|
|
|
193
269
|
*
|
|
194
270
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
195
271
|
*
|
|
272
|
+
* @returns A deep clone of the machine's current data value.
|
|
273
|
+
*
|
|
196
274
|
*/
|
|
197
275
|
data(): mDT;
|
|
198
276
|
/*********
|
|
199
277
|
*
|
|
200
|
-
* Get the current value of a given property name.
|
|
278
|
+
* Get the current value of a given property name. Checks the current
|
|
279
|
+
* state's properties first, then falls back to the global default.
|
|
280
|
+
* Returns `undefined` if neither exists. For a throwing variant, see
|
|
281
|
+
* {@link strict_prop}.
|
|
201
282
|
*
|
|
202
283
|
* ```typescript
|
|
284
|
+
* const m = sm`property color default "grey"; a -> b;
|
|
285
|
+
* state b: { property color "blue"; };`;
|
|
203
286
|
*
|
|
287
|
+
* m.prop('color'); // 'grey' (default, because state is 'a')
|
|
288
|
+
* m.go('b');
|
|
289
|
+
* m.prop('color'); // 'blue' (state 'b' overrides the default)
|
|
290
|
+
* m.prop('size'); // undefined (no such property)
|
|
204
291
|
* ```
|
|
205
292
|
*
|
|
206
|
-
* @param name The relevant property name to look up
|
|
293
|
+
* @param name The relevant property name to look up.
|
|
207
294
|
*
|
|
208
|
-
* @returns The value behind the prop name
|
|
209
|
-
* evaluated as getters, this can be anything.
|
|
295
|
+
* @returns The value behind the prop name, or `undefined` if not defined.
|
|
210
296
|
*
|
|
211
297
|
*/
|
|
212
298
|
prop(name: string): any;
|
|
213
299
|
/*********
|
|
214
300
|
*
|
|
215
301
|
* Get the current value of a given property name. If missing on the state
|
|
216
|
-
* and without a global default,
|
|
217
|
-
* return `undefined` instead.
|
|
302
|
+
* and without a global default, throws a {@link JssmError}, unlike
|
|
303
|
+
* {@link prop}, which would return `undefined` instead.
|
|
218
304
|
*
|
|
219
305
|
* ```typescript
|
|
306
|
+
* const m = sm`property color default "grey"; a -> b;`;
|
|
220
307
|
*
|
|
308
|
+
* m.strict_prop('color'); // 'grey'
|
|
309
|
+
* m.strict_prop('size'); // throws JssmError
|
|
221
310
|
* ```
|
|
222
311
|
*
|
|
223
|
-
* @param name The relevant property name to look up
|
|
312
|
+
* @param name The relevant property name to look up.
|
|
224
313
|
*
|
|
225
|
-
* @returns The value behind the prop name.
|
|
226
|
-
*
|
|
314
|
+
* @returns The value behind the prop name.
|
|
315
|
+
*
|
|
316
|
+
* @throws {JssmError} If the property is not defined on the current state
|
|
317
|
+
* and has no default.
|
|
227
318
|
*
|
|
228
319
|
*/
|
|
229
320
|
strict_prop(name: string): any;
|
|
230
321
|
/*********
|
|
231
322
|
*
|
|
232
323
|
* Get the current value of every prop, as an object. If no current definition
|
|
233
|
-
* exists for a prop
|
|
234
|
-
* the current state also doesn't define the prop
|
|
324
|
+
* exists for a prop — that is, if the prop was defined without a default and
|
|
325
|
+
* the current state also doesn't define the prop — then that prop will be listed
|
|
235
326
|
* in the returned object with a value of `undefined`.
|
|
236
327
|
*
|
|
237
328
|
* ```typescript
|
|
@@ -262,29 +353,12 @@ declare class Machine<mDT> {
|
|
|
262
353
|
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
|
|
263
354
|
* ```
|
|
264
355
|
*
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*
|
|
269
|
-
* Get the current value of every prop, as an object. Compare
|
|
270
|
-
* {@link prop_map}, which returns a `Map`.
|
|
271
|
-
*
|
|
272
|
-
* ```typescript
|
|
273
|
-
*
|
|
274
|
-
* ```
|
|
275
|
-
*
|
|
276
|
-
*/
|
|
277
|
-
/*********
|
|
278
|
-
*
|
|
279
|
-
* Get the current value of every prop, as an object. Compare
|
|
280
|
-
* {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
|
|
281
|
-
* this throws if a required prop is missing.
|
|
282
|
-
*
|
|
283
|
-
* ```typescript
|
|
284
|
-
*
|
|
285
|
-
* ```
|
|
356
|
+
* @returns An object mapping every known property name to its current value
|
|
357
|
+
* (or `undefined` if the property has no default and the current state
|
|
358
|
+
* doesn't define it).
|
|
286
359
|
*
|
|
287
360
|
*/
|
|
361
|
+
props(): object;
|
|
288
362
|
/*********
|
|
289
363
|
*
|
|
290
364
|
* Check whether a given string is a known property's name.
|
|
@@ -307,8 +381,13 @@ declare class Machine<mDT> {
|
|
|
307
381
|
* the properties generally will not be sorted.
|
|
308
382
|
*
|
|
309
383
|
* ```typescript
|
|
384
|
+
* const m = sm`property color default "grey"; property size default 1; a -> b;`;
|
|
385
|
+
*
|
|
386
|
+
* m.known_props(); // ['color', 'size']
|
|
310
387
|
* ```
|
|
311
388
|
*
|
|
389
|
+
* @returns An array of all property name strings defined on this machine.
|
|
390
|
+
*
|
|
312
391
|
*/
|
|
313
392
|
known_props(): string[];
|
|
314
393
|
/********
|
|
@@ -407,22 +486,78 @@ declare class Machine<mDT> {
|
|
|
407
486
|
*
|
|
408
487
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
409
488
|
*
|
|
489
|
+
* @param comment An optional comment string to embed in the serialized
|
|
490
|
+
* output for identification or debugging.
|
|
491
|
+
*
|
|
492
|
+
* @returns A {@link JssmSerialization} object containing the machine's
|
|
493
|
+
* current state, data, and timestamp.
|
|
494
|
+
*
|
|
410
495
|
*/
|
|
411
496
|
serialize(comment?: string | undefined): JssmSerialization<mDT>;
|
|
497
|
+
/** Get the graph layout direction (e.g. `'LR'`, `'TB'`). Set via the
|
|
498
|
+
* FSL `graph_layout` directive.
|
|
499
|
+
* @returns The layout string, or the default if not set.
|
|
500
|
+
*/
|
|
412
501
|
graph_layout(): string;
|
|
502
|
+
/** Get the Graphviz DOT preamble string, injected before the graph body
|
|
503
|
+
* during visualization. Set via the FSL `dot_preamble` directive.
|
|
504
|
+
* @returns The preamble string.
|
|
505
|
+
*/
|
|
413
506
|
dot_preamble(): string;
|
|
507
|
+
/** Get the machine's author list. Set via the FSL `machine_author` directive.
|
|
508
|
+
* @returns An array of author name strings.
|
|
509
|
+
*/
|
|
414
510
|
machine_author(): Array<string>;
|
|
511
|
+
/** Get the machine's comment string. Set via the FSL `machine_comment` directive.
|
|
512
|
+
* @returns The comment string.
|
|
513
|
+
*/
|
|
415
514
|
machine_comment(): string;
|
|
515
|
+
/** Get the machine's contributor list. Set via the FSL `machine_contributor` directive.
|
|
516
|
+
* @returns An array of contributor name strings.
|
|
517
|
+
*/
|
|
416
518
|
machine_contributor(): Array<string>;
|
|
519
|
+
/** Get the machine's definition string. Set via the FSL `machine_definition` directive.
|
|
520
|
+
* @returns The definition string.
|
|
521
|
+
*/
|
|
417
522
|
machine_definition(): string;
|
|
523
|
+
/** Get the machine's language (ISO 639-1). Set via the FSL `machine_language` directive.
|
|
524
|
+
* @returns The language code string.
|
|
525
|
+
*/
|
|
418
526
|
machine_language(): string;
|
|
527
|
+
/** Get the machine's license string. Set via the FSL `machine_license` directive.
|
|
528
|
+
* @returns The license string.
|
|
529
|
+
*/
|
|
419
530
|
machine_license(): string;
|
|
531
|
+
/** Get the machine's name. Set via the FSL `machine_name` directive.
|
|
532
|
+
* @returns The machine name string.
|
|
533
|
+
*/
|
|
420
534
|
machine_name(): string;
|
|
535
|
+
/** Get the machine's version string. Set via the FSL `machine_version` directive.
|
|
536
|
+
* @returns The version string.
|
|
537
|
+
*/
|
|
421
538
|
machine_version(): string;
|
|
539
|
+
/** Get the raw state declaration objects as parsed from the FSL source.
|
|
540
|
+
* @returns An array of raw state declaration objects.
|
|
541
|
+
*/
|
|
422
542
|
raw_state_declarations(): Array<Object>;
|
|
543
|
+
/** Get the processed state declaration for a specific state.
|
|
544
|
+
* @param which - The state to look up.
|
|
545
|
+
* @returns The {@link JssmStateDeclaration} for the given state.
|
|
546
|
+
*/
|
|
423
547
|
state_declaration(which: StateType): JssmStateDeclaration;
|
|
548
|
+
/** Get all processed state declarations as a Map.
|
|
549
|
+
* @returns A `Map` from state name to {@link JssmStateDeclaration}.
|
|
550
|
+
*/
|
|
424
551
|
state_declarations(): Map<StateType, JssmStateDeclaration>;
|
|
552
|
+
/** Get the FSL language version this machine was compiled under.
|
|
553
|
+
* @returns The FSL version string.
|
|
554
|
+
*/
|
|
425
555
|
fsl_version(): string;
|
|
556
|
+
/** Get the complete internal state of the machine as a serializable
|
|
557
|
+
* structure. Includes actions, edges, edge map, named transitions,
|
|
558
|
+
* reverse actions, current state, and states map.
|
|
559
|
+
* @returns A {@link JssmMachineInternalState} snapshot.
|
|
560
|
+
*/
|
|
426
561
|
machine_state(): JssmMachineInternalState<mDT>;
|
|
427
562
|
/*********
|
|
428
563
|
*
|
|
@@ -438,8 +573,15 @@ declare class Machine<mDT> {
|
|
|
438
573
|
*
|
|
439
574
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
440
575
|
*
|
|
576
|
+
* @returns An array of all state names in the machine.
|
|
577
|
+
*
|
|
441
578
|
*/
|
|
442
579
|
states(): Array<StateType>;
|
|
580
|
+
/** Get the internal state descriptor for a given state name.
|
|
581
|
+
* @param whichState - The state to look up.
|
|
582
|
+
* @returns The {@link JssmGenericState} descriptor.
|
|
583
|
+
* @throws {JssmError} If the state does not exist.
|
|
584
|
+
*/
|
|
443
585
|
state_for(whichState: StateType): JssmGenericState;
|
|
444
586
|
/*********
|
|
445
587
|
*
|
|
@@ -456,7 +598,9 @@ declare class Machine<mDT> {
|
|
|
456
598
|
*
|
|
457
599
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
458
600
|
*
|
|
459
|
-
* @param whichState The state to be checked for
|
|
601
|
+
* @param whichState The state to be checked for existence.
|
|
602
|
+
*
|
|
603
|
+
* @returns `true` if the state exists, `false` otherwise.
|
|
460
604
|
*
|
|
461
605
|
*/
|
|
462
606
|
has_state(whichState: StateType): boolean;
|
|
@@ -492,35 +636,82 @@ declare class Machine<mDT> {
|
|
|
492
636
|
*
|
|
493
637
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
494
638
|
*
|
|
639
|
+
* @returns An array of all {@link JssmTransition} edge objects.
|
|
640
|
+
*
|
|
495
641
|
*/
|
|
496
642
|
list_edges(): Array<JssmTransition<StateType, mDT>>;
|
|
643
|
+
/** Get the map of named transitions (transitions with explicit names).
|
|
644
|
+
* @returns A `Map` from transition name to edge index.
|
|
645
|
+
*/
|
|
497
646
|
list_named_transitions(): Map<StateType, number>;
|
|
647
|
+
/** List all distinct action names defined anywhere in the machine.
|
|
648
|
+
* @returns An array of action name strings.
|
|
649
|
+
*/
|
|
498
650
|
list_actions(): Array<StateType>;
|
|
651
|
+
/** Whether any actions are defined on this machine.
|
|
652
|
+
* @returns `true` if the machine has at least one action.
|
|
653
|
+
*/
|
|
499
654
|
get uses_actions(): boolean;
|
|
655
|
+
/** Whether any forced (`~>`) transitions exist in this machine.
|
|
656
|
+
* @returns `true` if at least one forced transition is defined.
|
|
657
|
+
*/
|
|
500
658
|
get uses_forced_transitions(): boolean;
|
|
501
659
|
/*********
|
|
502
660
|
*
|
|
503
661
|
* Check if the code that built the machine allows overriding state and data.
|
|
504
662
|
*
|
|
663
|
+
* @returns The override permission from the FSL source code.
|
|
664
|
+
*
|
|
505
665
|
*/
|
|
506
666
|
get code_allows_override(): JssmAllowsOverride;
|
|
507
667
|
/*********
|
|
508
668
|
*
|
|
509
669
|
* Check if the machine config allows overriding state and data.
|
|
510
670
|
*
|
|
671
|
+
* @returns The override permission from the runtime config.
|
|
672
|
+
*
|
|
511
673
|
*/
|
|
512
674
|
get config_allows_override(): JssmAllowsOverride;
|
|
513
675
|
/*********
|
|
514
676
|
*
|
|
515
|
-
* Check if a machine allows overriding state and data.
|
|
677
|
+
* Check if a machine allows overriding state and data. Resolves the
|
|
678
|
+
* combined effect of code and config permissions — config may not be
|
|
679
|
+
* less strict than code.
|
|
680
|
+
*
|
|
681
|
+
* @returns The effective override permission.
|
|
516
682
|
*
|
|
517
683
|
*/
|
|
518
684
|
get allows_override(): JssmAllowsOverride;
|
|
685
|
+
/** List all available theme names.
|
|
686
|
+
* @returns An array of theme name strings.
|
|
687
|
+
*/
|
|
519
688
|
all_themes(): FslTheme[];
|
|
689
|
+
/** Get the active theme(s) for this machine. Always stored as an array
|
|
690
|
+
* internally; the union return type exists for setter compatibility.
|
|
691
|
+
* @returns The current theme or array of themes.
|
|
692
|
+
*/
|
|
520
693
|
get themes(): FslTheme | FslTheme[];
|
|
694
|
+
/** Set the active theme(s). Accepts a single theme name or an array.
|
|
695
|
+
* @param to - A theme name or array of theme names to apply.
|
|
696
|
+
*/
|
|
521
697
|
set themes(to: FslTheme | FslTheme[]);
|
|
698
|
+
/** Get the flow direction for graph layout (e.g. `'right'`, `'down'`).
|
|
699
|
+
* Set via the FSL `flow` directive.
|
|
700
|
+
* @returns The current flow direction.
|
|
701
|
+
*/
|
|
522
702
|
flow(): FslDirection;
|
|
703
|
+
/** Look up a transition's edge index by source and target state names.
|
|
704
|
+
* @param from - Source state name.
|
|
705
|
+
* @param to - Target state name.
|
|
706
|
+
* @returns The edge index in the edges array, or `undefined` if no
|
|
707
|
+
* such transition exists.
|
|
708
|
+
*/
|
|
523
709
|
get_transition_by_state_names(from: StateType, to: StateType): number;
|
|
710
|
+
/** Look up the full transition object for a given source→target pair.
|
|
711
|
+
* @param from - Source state name.
|
|
712
|
+
* @param to - Target state name.
|
|
713
|
+
* @returns The {@link JssmTransition} object, or `undefined` if none exists.
|
|
714
|
+
*/
|
|
524
715
|
lookup_transition_for(from: StateType, to: StateType): JssmTransition<StateType, mDT>;
|
|
525
716
|
/********
|
|
526
717
|
*
|
|
@@ -588,9 +779,29 @@ declare class Machine<mDT> {
|
|
|
588
779
|
*
|
|
589
780
|
*/
|
|
590
781
|
list_exits(whichState?: StateType): Array<StateType>;
|
|
782
|
+
/** Get the transitions available from a state, filtered to those with
|
|
783
|
+
* probability data. Used by the probabilistic walk system.
|
|
784
|
+
* @param whichState - The state to inspect.
|
|
785
|
+
* @returns An array of {@link JssmTransition} edges exiting the state.
|
|
786
|
+
* @throws {JssmError} If the state does not exist.
|
|
787
|
+
*/
|
|
591
788
|
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
|
|
789
|
+
/** Take a single random transition from the current state, weighted by
|
|
790
|
+
* edge probabilities.
|
|
791
|
+
* @returns `true` if a transition was taken, `false` otherwise.
|
|
792
|
+
*/
|
|
592
793
|
probabilistic_transition(): boolean;
|
|
794
|
+
/** Take `n` consecutive probabilistic transitions and return the sequence
|
|
795
|
+
* of states visited (before each transition).
|
|
796
|
+
* @param n - Number of steps to walk.
|
|
797
|
+
* @returns An array of state names visited during the walk.
|
|
798
|
+
*/
|
|
593
799
|
probabilistic_walk(n: number): Array<StateType>;
|
|
800
|
+
/** Take `n` probabilistic steps and return a histograph of how many times
|
|
801
|
+
* each state was visited.
|
|
802
|
+
* @param n - Number of steps to walk.
|
|
803
|
+
* @returns A `Map` from state name to visit count.
|
|
804
|
+
*/
|
|
594
805
|
probabilistic_histo_walk(n: number): Map<StateType, number>;
|
|
595
806
|
/********
|
|
596
807
|
*
|
|
@@ -623,7 +834,10 @@ declare class Machine<mDT> {
|
|
|
623
834
|
*
|
|
624
835
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
625
836
|
*
|
|
626
|
-
* @param whichState The state whose actions to
|
|
837
|
+
* @param whichState The state whose actions to list. Defaults to the
|
|
838
|
+
* current state.
|
|
839
|
+
*
|
|
840
|
+
* @returns An array of action names available from the given state.
|
|
627
841
|
*
|
|
628
842
|
*/
|
|
629
843
|
actions(whichState?: StateType): Array<StateType>;
|
|
@@ -650,40 +864,276 @@ declare class Machine<mDT> {
|
|
|
650
864
|
*
|
|
651
865
|
*/
|
|
652
866
|
list_states_having_action(whichState: StateType): Array<StateType>;
|
|
867
|
+
/** List all action names available as exits from a given state.
|
|
868
|
+
* @param whichState - The state to inspect. Defaults to the current state.
|
|
869
|
+
* @returns An array of action name strings.
|
|
870
|
+
* @throws {JssmError} If the state does not exist.
|
|
871
|
+
*/
|
|
653
872
|
list_exit_actions(whichState?: StateType): Array<StateType>;
|
|
873
|
+
/** List all action exits from a state with their probabilities.
|
|
874
|
+
* @param whichState - The state to inspect. Defaults to the current state.
|
|
875
|
+
* @returns An array of `{ action, probability }` objects.
|
|
876
|
+
* @throws {JssmError} If the state does not exist.
|
|
877
|
+
*/
|
|
654
878
|
probable_action_exits(whichState?: StateType): Array<any>;
|
|
879
|
+
/** Check whether a state has no incoming transitions (unreachable after start).
|
|
880
|
+
* @param whichState - The state to check.
|
|
881
|
+
* @returns `true` if the state has zero entrances.
|
|
882
|
+
* @throws {JssmError} If the state does not exist.
|
|
883
|
+
*/
|
|
655
884
|
is_unenterable(whichState: StateType): boolean;
|
|
885
|
+
/** Check whether any state in the machine is unenterable.
|
|
886
|
+
* @returns `true` if at least one state has no incoming transitions.
|
|
887
|
+
*/
|
|
656
888
|
has_unenterables(): boolean;
|
|
889
|
+
/** Check whether the current state is terminal (has no exits).
|
|
890
|
+
* @returns `true` if the current state has zero exits.
|
|
891
|
+
*/
|
|
657
892
|
is_terminal(): boolean;
|
|
893
|
+
/** Check whether a specific state is terminal (has no exits).
|
|
894
|
+
* @param whichState - The state to check.
|
|
895
|
+
* @returns `true` if the state has zero exits.
|
|
896
|
+
* @throws {JssmError} If the state does not exist.
|
|
897
|
+
*/
|
|
658
898
|
state_is_terminal(whichState: StateType): boolean;
|
|
899
|
+
/** Check whether any state in the machine is terminal.
|
|
900
|
+
* @returns `true` if at least one state has no exits.
|
|
901
|
+
*/
|
|
659
902
|
has_terminals(): boolean;
|
|
903
|
+
/** Check whether the current state is complete (every exit has an action).
|
|
904
|
+
* @returns `true` if the current state is complete.
|
|
905
|
+
*/
|
|
660
906
|
is_complete(): boolean;
|
|
907
|
+
/** Check whether a specific state is complete (every exit has an action).
|
|
908
|
+
* @param whichState - The state to check.
|
|
909
|
+
* @returns `true` if the state is complete.
|
|
910
|
+
* @throws {JssmError} If the state does not exist.
|
|
911
|
+
*/
|
|
661
912
|
state_is_complete(whichState: StateType): boolean;
|
|
913
|
+
/** Check whether any state in the machine is complete.
|
|
914
|
+
* @returns `true` if at least one state is complete.
|
|
915
|
+
*/
|
|
662
916
|
has_completes(): boolean;
|
|
917
|
+
/** Low-level hook registration. Installs a handler described by a
|
|
918
|
+
* {@link HookDescription} into the appropriate internal map. Prefer the
|
|
919
|
+
* convenience wrappers ({@link hook}, {@link hook_entry}, etc.) over
|
|
920
|
+
* calling this directly.
|
|
921
|
+
* @param HookDesc - A hook descriptor specifying kind, states, and handler.
|
|
922
|
+
*/
|
|
663
923
|
set_hook(HookDesc: HookDescription<mDT>): void;
|
|
924
|
+
/** Register a pre-transition hook on a specific edge. Fires before
|
|
925
|
+
* transitioning from `from` to `to`. If the handler returns `false`, the
|
|
926
|
+
* transition is blocked.
|
|
927
|
+
*
|
|
928
|
+
* ```typescript
|
|
929
|
+
* const m = sm`a -> b -> c;`;
|
|
930
|
+
* m.hook('a', 'b', () => console.log('a->b'));
|
|
931
|
+
* ```
|
|
932
|
+
*
|
|
933
|
+
* @param from - Source state name.
|
|
934
|
+
* @param to - Target state name.
|
|
935
|
+
* @param handler - Callback invoked before the transition.
|
|
936
|
+
* @returns `this` for chaining.
|
|
937
|
+
*/
|
|
664
938
|
hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
939
|
+
/** Register a pre-transition hook on a specific action-labeled edge.
|
|
940
|
+
* @param from - Source state name.
|
|
941
|
+
* @param to - Target state name.
|
|
942
|
+
* @param action - The action label that triggers this hook.
|
|
943
|
+
* @param handler - Callback invoked before the transition.
|
|
944
|
+
* @returns `this` for chaining.
|
|
945
|
+
*/
|
|
665
946
|
hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
947
|
+
/** Register a pre-transition hook on any edge triggered by a specific action.
|
|
948
|
+
* @param action - The action name to hook.
|
|
949
|
+
* @param handler - Callback invoked before any transition with this action.
|
|
950
|
+
* @returns `this` for chaining.
|
|
951
|
+
*/
|
|
666
952
|
hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
953
|
+
/** Register a pre-transition hook on any action-driven transition.
|
|
954
|
+
* @param handler - Callback invoked before any action transition.
|
|
955
|
+
* @returns `this` for chaining.
|
|
956
|
+
*/
|
|
667
957
|
hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
958
|
+
/** Register a pre-transition hook on any standard (`->`) transition.
|
|
959
|
+
* @param handler - Callback invoked before any legal transition.
|
|
960
|
+
* @returns `this` for chaining.
|
|
961
|
+
*/
|
|
668
962
|
hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
963
|
+
/** Register a pre-transition hook on any main-path (`=>`) transition.
|
|
964
|
+
* @param handler - Callback invoked before any main transition.
|
|
965
|
+
* @returns `this` for chaining.
|
|
966
|
+
*/
|
|
669
967
|
hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
968
|
+
/** Register a pre-transition hook on any forced (`~>`) transition.
|
|
969
|
+
* @param handler - Callback invoked before any forced transition.
|
|
970
|
+
* @returns `this` for chaining.
|
|
971
|
+
*/
|
|
670
972
|
hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
973
|
+
/** Register a pre-transition hook on any transition regardless of kind.
|
|
974
|
+
* @param handler - Callback invoked before every transition.
|
|
975
|
+
* @returns `this` for chaining.
|
|
976
|
+
*/
|
|
671
977
|
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
978
|
+
/** Register a hook that fires when entering a specific state.
|
|
979
|
+
* @param to - The state being entered.
|
|
980
|
+
* @param handler - Callback invoked on entry.
|
|
981
|
+
* @returns `this` for chaining.
|
|
982
|
+
*/
|
|
672
983
|
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
984
|
+
/** Register a hook that fires when leaving a specific state.
|
|
985
|
+
* @param from - The state being exited.
|
|
986
|
+
* @param handler - Callback invoked on exit.
|
|
987
|
+
* @returns `this` for chaining.
|
|
988
|
+
*/
|
|
673
989
|
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
990
|
+
/** Register a hook that fires after leaving a specific state (post-exit).
|
|
991
|
+
* @param from - The state that was exited.
|
|
992
|
+
* @param handler - Callback invoked after exit completes.
|
|
993
|
+
* @returns `this` for chaining.
|
|
994
|
+
*/
|
|
674
995
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
996
|
+
/** Post-transition hook on a specific edge. Fires after the transition
|
|
997
|
+
* from `from` to `to` has completed. Cannot block the transition.
|
|
998
|
+
* @param from - Source state name.
|
|
999
|
+
* @param to - Target state name.
|
|
1000
|
+
* @param handler - Callback invoked after the transition.
|
|
1001
|
+
* @returns `this` for chaining.
|
|
1002
|
+
*/
|
|
675
1003
|
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1004
|
+
/** Post-transition hook on a specific action-labeled edge.
|
|
1005
|
+
* @param from - Source state name.
|
|
1006
|
+
* @param to - Target state name.
|
|
1007
|
+
* @param action - The action label.
|
|
1008
|
+
* @param handler - Callback invoked after the transition.
|
|
1009
|
+
* @returns `this` for chaining.
|
|
1010
|
+
*/
|
|
676
1011
|
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1012
|
+
/** Post-transition hook on any edge triggered by a specific action.
|
|
1013
|
+
* @param action - The action name.
|
|
1014
|
+
* @param handler - Callback invoked after any transition with this action.
|
|
1015
|
+
* @returns `this` for chaining.
|
|
1016
|
+
*/
|
|
677
1017
|
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1018
|
+
/** Post-transition hook on any action-driven transition.
|
|
1019
|
+
* @param handler - Callback invoked after any action transition.
|
|
1020
|
+
* @returns `this` for chaining.
|
|
1021
|
+
*/
|
|
678
1022
|
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1023
|
+
/** Post-transition hook on any standard (`->`) transition.
|
|
1024
|
+
* @param handler - Callback invoked after any legal transition.
|
|
1025
|
+
* @returns `this` for chaining.
|
|
1026
|
+
*/
|
|
679
1027
|
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1028
|
+
/** Post-transition hook on any main-path (`=>`) transition.
|
|
1029
|
+
* @param handler - Callback invoked after any main transition.
|
|
1030
|
+
* @returns `this` for chaining.
|
|
1031
|
+
*/
|
|
680
1032
|
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1033
|
+
/** Post-transition hook on any forced (`~>`) transition.
|
|
1034
|
+
* @param handler - Callback invoked after any forced transition.
|
|
1035
|
+
* @returns `this` for chaining.
|
|
1036
|
+
*/
|
|
681
1037
|
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1038
|
+
/** Post-transition hook on any transition regardless of kind.
|
|
1039
|
+
* @param handler - Callback invoked after every transition.
|
|
1040
|
+
* @returns `this` for chaining.
|
|
1041
|
+
*/
|
|
682
1042
|
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1043
|
+
/** Post-transition hook that fires after entering a specific state.
|
|
1044
|
+
* @param to - The state that was entered.
|
|
1045
|
+
* @param handler - Callback invoked after entry.
|
|
1046
|
+
* @returns `this` for chaining.
|
|
1047
|
+
*/
|
|
683
1048
|
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1049
|
+
/** Post-transition hook that fires after leaving a specific state.
|
|
1050
|
+
* @param from - The state that was exited.
|
|
1051
|
+
* @param handler - Callback invoked after exit.
|
|
1052
|
+
* @returns `this` for chaining.
|
|
1053
|
+
*/
|
|
684
1054
|
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1055
|
+
/** Register a pre-transition hook that fires **before** all other pre-hooks
|
|
1056
|
+
* on every transition. If the handler returns `false`, the transition is
|
|
1057
|
+
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1058
|
+
* `hook_name` is `'pre everything'`.
|
|
1059
|
+
*
|
|
1060
|
+
* ```typescript
|
|
1061
|
+
* const m = sm`a -> b -> c;`;
|
|
1062
|
+
* m.hook_pre_everything(({ hook_name }) => {
|
|
1063
|
+
* console.log(`${hook_name} fired`);
|
|
1064
|
+
* return true;
|
|
1065
|
+
* });
|
|
1066
|
+
* ```
|
|
1067
|
+
*
|
|
1068
|
+
* @param handler - Callback invoked before all other pre-hooks.
|
|
1069
|
+
* @returns `this` for chaining.
|
|
1070
|
+
*/
|
|
1071
|
+
hook_pre_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1072
|
+
/** Register a pre-transition hook that fires **after** all other pre-hooks
|
|
1073
|
+
* on every transition. If the handler returns `false`, the transition is
|
|
1074
|
+
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1075
|
+
* `hook_name` is `'everything'`.
|
|
1076
|
+
*
|
|
1077
|
+
* ```typescript
|
|
1078
|
+
* const m = sm`a -> b -> c;`;
|
|
1079
|
+
* m.hook_everything(({ hook_name }) => {
|
|
1080
|
+
* console.log(`${hook_name} fired`);
|
|
1081
|
+
* return true;
|
|
1082
|
+
* });
|
|
1083
|
+
* ```
|
|
1084
|
+
*
|
|
1085
|
+
* @param handler - Callback invoked after all other pre-hooks.
|
|
1086
|
+
* @returns `this` for chaining.
|
|
1087
|
+
*/
|
|
1088
|
+
hook_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1089
|
+
/** Register a post-transition hook that fires **after** all other
|
|
1090
|
+
* post-hooks on every transition. Cannot block the transition. The
|
|
1091
|
+
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1092
|
+
* `'post everything'`.
|
|
1093
|
+
*
|
|
1094
|
+
* ```typescript
|
|
1095
|
+
* const m = sm`a -> b -> c;`;
|
|
1096
|
+
* m.hook_post_everything(({ hook_name }) => {
|
|
1097
|
+
* console.log(`${hook_name} fired`);
|
|
1098
|
+
* });
|
|
1099
|
+
* ```
|
|
1100
|
+
*
|
|
1101
|
+
* @param handler - Callback invoked after all other post-hooks.
|
|
1102
|
+
* @returns `this` for chaining.
|
|
1103
|
+
*/
|
|
1104
|
+
hook_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1105
|
+
/** Register a post-transition hook that fires **before** all other
|
|
1106
|
+
* post-hooks on every transition. Cannot block the transition. The
|
|
1107
|
+
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1108
|
+
* `'pre post everything'`.
|
|
1109
|
+
*
|
|
1110
|
+
* ```typescript
|
|
1111
|
+
* const m = sm`a -> b -> c;`;
|
|
1112
|
+
* m.hook_pre_post_everything(({ hook_name }) => {
|
|
1113
|
+
* console.log(`${hook_name} fired`);
|
|
1114
|
+
* });
|
|
1115
|
+
* ```
|
|
1116
|
+
*
|
|
1117
|
+
* @param handler - Callback invoked before all other post-hooks.
|
|
1118
|
+
* @returns `this` for chaining.
|
|
1119
|
+
*/
|
|
1120
|
+
hook_pre_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1121
|
+
/** Get the current RNG seed used for probabilistic transitions.
|
|
1122
|
+
* @returns The numeric seed value.
|
|
1123
|
+
*/
|
|
685
1124
|
get rng_seed(): number;
|
|
1125
|
+
/** Set the RNG seed. Pass `undefined` to reseed from the current time.
|
|
1126
|
+
* Resets the internal PRNG so subsequent probabilistic operations use the
|
|
1127
|
+
* new seed.
|
|
1128
|
+
* @param to - The seed value, or `undefined` for time-based seeding.
|
|
1129
|
+
*/
|
|
686
1130
|
set rng_seed(to: number | undefined);
|
|
1131
|
+
/** Get all edges between two states (there can be multiple with
|
|
1132
|
+
* different actions).
|
|
1133
|
+
* @param from - Source state name.
|
|
1134
|
+
* @param to - Target state name.
|
|
1135
|
+
* @returns An array of matching {@link JssmTransition} objects.
|
|
1136
|
+
*/
|
|
687
1137
|
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
688
1138
|
/*********
|
|
689
1139
|
*
|
|
@@ -705,7 +1155,53 @@ declare class Machine<mDT> {
|
|
|
705
1155
|
*
|
|
706
1156
|
*/
|
|
707
1157
|
override(newState: StateType, newData?: mDT | undefined): void;
|
|
1158
|
+
/*********
|
|
1159
|
+
*
|
|
1160
|
+
* Shared transition core used by {@link transition}, {@link force_transition},
|
|
1161
|
+
* and {@link action}. Runs validation, fires the full hook pipeline (pre-
|
|
1162
|
+
* everything, any-action, after, any-transition, exit, named, basic,
|
|
1163
|
+
* edge-type, entry, everything), commits the new state if nothing
|
|
1164
|
+
* rejected, and returns whether the transition succeeded.
|
|
1165
|
+
*
|
|
1166
|
+
* Not meant for external use. Call one of the public wrappers instead:
|
|
1167
|
+
* - `transition` for an ordinary legal transition
|
|
1168
|
+
* - `force_transition` to bypass the legality check
|
|
1169
|
+
* - `action` to dispatch by action name rather than target state
|
|
1170
|
+
*
|
|
1171
|
+
* @remarks
|
|
1172
|
+
* Known sharp edges, carried over from the original `// TODO` comments:
|
|
1173
|
+
* - The forced-ness behavior needs to be cleaned up a lot here.
|
|
1174
|
+
* - The callbacks are not fully correct across the forced / action / plain
|
|
1175
|
+
* cases and should be revisited.
|
|
1176
|
+
* - When multiple edges exist between two states with different `kind`
|
|
1177
|
+
* values, only the first edge's kind is used to pick the edge-type hook.
|
|
1178
|
+
*
|
|
1179
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1180
|
+
*
|
|
1181
|
+
* @param newStateOrAction The target state name (for a plain or forced
|
|
1182
|
+
* transition) or the action name (when `wasAction` is true).
|
|
1183
|
+
*
|
|
1184
|
+
* @param newData Optional replacement machine data to install alongside
|
|
1185
|
+
* the transition. Hooks may further override this via complex results.
|
|
1186
|
+
*
|
|
1187
|
+
* @param wasForced `true` if the caller invoked `force_transition`, in
|
|
1188
|
+
* which case legality is checked against `valid_force_transition` rather
|
|
1189
|
+
* than `valid_transition`.
|
|
1190
|
+
*
|
|
1191
|
+
* @param wasAction `true` if the caller invoked `action`, in which case
|
|
1192
|
+
* `newStateOrAction` is an action name and the target state is looked up
|
|
1193
|
+
* via the current action edge.
|
|
1194
|
+
*
|
|
1195
|
+
* @returns `true` if the transition was valid and every hook passed;
|
|
1196
|
+
* `false` if the transition was invalid or any hook rejected.
|
|
1197
|
+
*
|
|
1198
|
+
* @internal
|
|
1199
|
+
*
|
|
1200
|
+
*/
|
|
708
1201
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
1202
|
+
/** If the current state has an `after` timeout configured, schedule it.
|
|
1203
|
+
* Called internally after each transition.
|
|
1204
|
+
*/
|
|
709
1205
|
auto_set_state_timeout(): void;
|
|
710
1206
|
/*********
|
|
711
1207
|
*
|
|
@@ -807,6 +1303,9 @@ declare class Machine<mDT> {
|
|
|
807
1303
|
*
|
|
808
1304
|
* @param newData The data change to insert during the action
|
|
809
1305
|
*
|
|
1306
|
+
* @returns `true` if the action was valid and the transition occurred,
|
|
1307
|
+
* `false` otherwise.
|
|
1308
|
+
*
|
|
810
1309
|
*/
|
|
811
1310
|
action(actionName: StateType, newData?: mDT): boolean;
|
|
812
1311
|
/********
|
|
@@ -827,6 +1326,8 @@ declare class Machine<mDT> {
|
|
|
827
1326
|
*
|
|
828
1327
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
829
1328
|
*
|
|
1329
|
+
* @returns The {@link JssmStateConfig} for standard states.
|
|
1330
|
+
*
|
|
830
1331
|
*/
|
|
831
1332
|
get standard_state_style(): JssmStateConfig;
|
|
832
1333
|
/********
|
|
@@ -851,6 +1352,8 @@ declare class Machine<mDT> {
|
|
|
851
1352
|
*
|
|
852
1353
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
853
1354
|
*
|
|
1355
|
+
* @returns The {@link JssmStateConfig} for hooked states.
|
|
1356
|
+
*
|
|
854
1357
|
*/
|
|
855
1358
|
get hooked_state_style(): JssmStateConfig;
|
|
856
1359
|
/********
|
|
@@ -874,6 +1377,8 @@ declare class Machine<mDT> {
|
|
|
874
1377
|
*
|
|
875
1378
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
876
1379
|
*
|
|
1380
|
+
* @returns The {@link JssmStateConfig} for start states.
|
|
1381
|
+
*
|
|
877
1382
|
*/
|
|
878
1383
|
get start_state_style(): JssmStateConfig;
|
|
879
1384
|
/********
|
|
@@ -902,6 +1407,8 @@ declare class Machine<mDT> {
|
|
|
902
1407
|
*
|
|
903
1408
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
904
1409
|
*
|
|
1410
|
+
* @returns The {@link JssmStateConfig} for end states.
|
|
1411
|
+
*
|
|
905
1412
|
*/
|
|
906
1413
|
get end_state_style(): JssmStateConfig;
|
|
907
1414
|
/********
|
|
@@ -925,6 +1432,8 @@ declare class Machine<mDT> {
|
|
|
925
1432
|
*
|
|
926
1433
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
927
1434
|
*
|
|
1435
|
+
* @returns The {@link JssmStateConfig} for terminal states.
|
|
1436
|
+
*
|
|
928
1437
|
*/
|
|
929
1438
|
get terminal_state_style(): JssmStateConfig;
|
|
930
1439
|
/********
|
|
@@ -945,6 +1454,8 @@ declare class Machine<mDT> {
|
|
|
945
1454
|
*
|
|
946
1455
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
947
1456
|
*
|
|
1457
|
+
* @returns The {@link JssmStateConfig} for the active state.
|
|
1458
|
+
*
|
|
948
1459
|
*/
|
|
949
1460
|
get active_state_style(): JssmStateConfig;
|
|
950
1461
|
/********
|
|
@@ -965,6 +1476,10 @@ declare class Machine<mDT> {
|
|
|
965
1476
|
*
|
|
966
1477
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
967
1478
|
*
|
|
1479
|
+
* @param state The state to compute the composite style for.
|
|
1480
|
+
*
|
|
1481
|
+
* @returns The fully composited {@link JssmStateConfig} for the given state.
|
|
1482
|
+
*
|
|
968
1483
|
*/
|
|
969
1484
|
style_for(state: StateType): JssmStateConfig;
|
|
970
1485
|
/********
|
|
@@ -997,6 +1512,9 @@ declare class Machine<mDT> {
|
|
|
997
1512
|
*
|
|
998
1513
|
* @param newData The data change to insert during the action
|
|
999
1514
|
*
|
|
1515
|
+
* @returns `true` if the action was valid and the transition occurred,
|
|
1516
|
+
* `false` otherwise.
|
|
1517
|
+
*
|
|
1000
1518
|
*/
|
|
1001
1519
|
do(actionName: StateType, newData?: mDT): boolean;
|
|
1002
1520
|
/********
|
|
@@ -1027,6 +1545,8 @@ declare class Machine<mDT> {
|
|
|
1027
1545
|
*
|
|
1028
1546
|
* @param newData The data change to insert during the transition
|
|
1029
1547
|
*
|
|
1548
|
+
* @returns `true` if the transition was legal and occurred, `false` otherwise.
|
|
1549
|
+
*
|
|
1030
1550
|
*/
|
|
1031
1551
|
transition(newState: StateType, newData?: mDT): boolean;
|
|
1032
1552
|
/********
|
|
@@ -1047,6 +1567,8 @@ declare class Machine<mDT> {
|
|
|
1047
1567
|
*
|
|
1048
1568
|
* @param newData The data change to insert during the transition
|
|
1049
1569
|
*
|
|
1570
|
+
* @returns `true` if the transition was legal and occurred, `false` otherwise.
|
|
1571
|
+
*
|
|
1050
1572
|
*/
|
|
1051
1573
|
go(newState: StateType, newData?: mDT): boolean;
|
|
1052
1574
|
/********
|
|
@@ -1070,21 +1592,84 @@ declare class Machine<mDT> {
|
|
|
1070
1592
|
*
|
|
1071
1593
|
* @param newData The data change to insert during the transition
|
|
1072
1594
|
*
|
|
1595
|
+
* @returns `true` if a transition (forced or otherwise) existed and occurred,
|
|
1596
|
+
* `false` otherwise.
|
|
1597
|
+
*
|
|
1073
1598
|
*/
|
|
1074
1599
|
force_transition(newState: StateType, newData?: mDT): boolean;
|
|
1600
|
+
/** Get the edge index for an action from the current state.
|
|
1601
|
+
* @param action - The action name.
|
|
1602
|
+
* @returns The edge index, or `undefined` if the action is not available.
|
|
1603
|
+
*/
|
|
1075
1604
|
current_action_for(action: StateType): number;
|
|
1605
|
+
/** Get the full transition object for an action from the current state.
|
|
1606
|
+
* @param action - The action name.
|
|
1607
|
+
* @returns The {@link JssmTransition} object.
|
|
1608
|
+
* @throws {JssmError} If the action is not available from the current state.
|
|
1609
|
+
*/
|
|
1076
1610
|
current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
|
|
1611
|
+
/** Check whether an action is available from the current state.
|
|
1612
|
+
* @param action - The action name to check.
|
|
1613
|
+
* @param _newData - Reserved for future data validation.
|
|
1614
|
+
* @returns `true` if the action can be taken.
|
|
1615
|
+
*/
|
|
1077
1616
|
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
1617
|
+
/** Check whether a transition to a given state is legal (non-forced) from
|
|
1618
|
+
* the current state.
|
|
1619
|
+
* @param newState - The target state.
|
|
1620
|
+
* @param _newData - Reserved for future data validation.
|
|
1621
|
+
* @returns `true` if the transition is legal.
|
|
1622
|
+
*/
|
|
1078
1623
|
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
1624
|
+
/** Check whether a forced transition to a given state exists from the
|
|
1625
|
+
* current state.
|
|
1626
|
+
* @param newState - The target state.
|
|
1627
|
+
* @param _newData - Reserved for future data validation.
|
|
1628
|
+
* @returns `true` if a forced (or any) transition exists.
|
|
1629
|
+
*/
|
|
1079
1630
|
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
1631
|
+
/** Get the instance name of this machine, if one was assigned at creation.
|
|
1632
|
+
* @returns The instance name string, or `undefined`.
|
|
1633
|
+
*/
|
|
1080
1634
|
instance_name(): string | undefined;
|
|
1635
|
+
/** Get the creation date of this machine as a `Date` object.
|
|
1636
|
+
* @returns A `Date` representing when the machine was created.
|
|
1637
|
+
*/
|
|
1081
1638
|
get creation_date(): Date;
|
|
1639
|
+
/** Get the creation timestamp (milliseconds since epoch).
|
|
1640
|
+
* @returns The timestamp as a number.
|
|
1641
|
+
*/
|
|
1082
1642
|
get creation_timestamp(): number;
|
|
1643
|
+
/** Get the timestamp when construction began (before parsing).
|
|
1644
|
+
* @returns The start-of-construction timestamp as a number.
|
|
1645
|
+
*/
|
|
1083
1646
|
get create_start_time(): number;
|
|
1647
|
+
/** Schedule an automatic transition to `next_state` after `after_time`
|
|
1648
|
+
* milliseconds. Only one timeout may be active at a time.
|
|
1649
|
+
* @param next_state - The state to transition to when the timer fires.
|
|
1650
|
+
* @param after_time - Delay in milliseconds.
|
|
1651
|
+
* @throws {JssmError} If a timeout is already pending.
|
|
1652
|
+
*/
|
|
1084
1653
|
set_state_timeout(next_state: StateType, after_time: number): void;
|
|
1654
|
+
/** Cancel any pending state timeout. Safe to call when no timeout is active.
|
|
1655
|
+
*/
|
|
1085
1656
|
clear_state_timeout(): void;
|
|
1657
|
+
/** Get the configured `after` timeout for a given state, if any.
|
|
1658
|
+
* @param which_state - The state to look up.
|
|
1659
|
+
* @returns A `[targetState, delayMs]` tuple, or `undefined` if no timeout
|
|
1660
|
+
* is configured for that state.
|
|
1661
|
+
*/
|
|
1086
1662
|
state_timeout_for(which_state: StateType): [StateType, number] | undefined;
|
|
1663
|
+
/** Get the configured `after` timeout for the current state, if any.
|
|
1664
|
+
* @returns A `[targetState, delayMs]` tuple, or `undefined`.
|
|
1665
|
+
*/
|
|
1087
1666
|
current_state_timeout(): [StateType, number] | undefined;
|
|
1667
|
+
/** Convenience method to create a new machine from a tagged template literal.
|
|
1668
|
+
* Equivalent to calling the top-level `sm` function.
|
|
1669
|
+
* @param template_strings - The template string array.
|
|
1670
|
+
* @param remainder - Interpolated values.
|
|
1671
|
+
* @returns A new {@link Machine} instance.
|
|
1672
|
+
*/
|
|
1088
1673
|
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
1089
1674
|
}
|
|
1090
1675
|
/*********
|
|
@@ -1134,8 +1719,157 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
|
|
|
1134
1719
|
*
|
|
1135
1720
|
*/
|
|
1136
1721
|
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>> | undefined): Machine<mDT>;
|
|
1722
|
+
/**
|
|
1723
|
+
*
|
|
1724
|
+
* Type guard that narrows an unknown value to a {@link HookComplexResult}.
|
|
1725
|
+
*
|
|
1726
|
+
* A hook complex result is an object with at minimum a boolean `pass` field,
|
|
1727
|
+
* and may optionally also carry replacement `data` / `next_data` fields that
|
|
1728
|
+
* the machine should adopt if the hook passes. This helper is used by the
|
|
1729
|
+
* hook-dispatch machinery to tell "hook returned a complex object" from
|
|
1730
|
+
* "hook returned a bare boolean / null / undefined".
|
|
1731
|
+
*
|
|
1732
|
+
* ```typescript
|
|
1733
|
+
* is_hook_complex_result({ pass: true }); // true
|
|
1734
|
+
* is_hook_complex_result({ pass: false, data: { x: 1 }}); // true
|
|
1735
|
+
* is_hook_complex_result(true); // false
|
|
1736
|
+
* is_hook_complex_result(null); // false
|
|
1737
|
+
* is_hook_complex_result({ other: 'thing' }); // false
|
|
1738
|
+
* ```
|
|
1739
|
+
*
|
|
1740
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1741
|
+
*
|
|
1742
|
+
* @param hr The value to test.
|
|
1743
|
+
*
|
|
1744
|
+
* @returns `true` if `hr` is a non-null object with a boolean `pass` field;
|
|
1745
|
+
* `false` otherwise. When `true`, TypeScript narrows `hr` to
|
|
1746
|
+
* `HookComplexResult<mDT>`.
|
|
1747
|
+
*
|
|
1748
|
+
*/
|
|
1137
1749
|
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
|
|
1750
|
+
/**
|
|
1751
|
+
*
|
|
1752
|
+
* Normalize any legal hook return value to a single "did it reject?" boolean.
|
|
1753
|
+
*
|
|
1754
|
+
* Hooks in jssm may return any of the following to indicate success:
|
|
1755
|
+
* `true`, `undefined`, or a complex result whose `pass` field is `true`.
|
|
1756
|
+
* They may return any of the following to indicate rejection:
|
|
1757
|
+
* `false`, or a complex result whose `pass` field is `false`. This helper
|
|
1758
|
+
* collapses all of those shapes into one boolean so callers don't have to
|
|
1759
|
+
* re-implement the matrix.
|
|
1760
|
+
*
|
|
1761
|
+
* ```typescript
|
|
1762
|
+
* is_hook_rejection(true); // false (pass)
|
|
1763
|
+
* is_hook_rejection(undefined); // false (pass)
|
|
1764
|
+
* is_hook_rejection(false); // true (reject)
|
|
1765
|
+
* is_hook_rejection({ pass: true }); // false (pass)
|
|
1766
|
+
* is_hook_rejection({ pass: false }); // true (reject)
|
|
1767
|
+
* ```
|
|
1768
|
+
*
|
|
1769
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1770
|
+
*
|
|
1771
|
+
* @param hr A hook result of any legal shape.
|
|
1772
|
+
*
|
|
1773
|
+
* @returns `true` if the hook rejected the transition; `false` if it passed.
|
|
1774
|
+
*
|
|
1775
|
+
* @throws {TypeError} If `hr` is not a recognized hook result shape (for
|
|
1776
|
+
* example, a number or a plain object without a `pass` field).
|
|
1777
|
+
*
|
|
1778
|
+
*/
|
|
1138
1779
|
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
1780
|
+
/**
|
|
1781
|
+
*
|
|
1782
|
+
* Invoke an optional transition/action hook and normalize its return value
|
|
1783
|
+
* into a {@link HookComplexResult}.
|
|
1784
|
+
*
|
|
1785
|
+
* This is the central adapter the transition pipeline uses to run every
|
|
1786
|
+
* non-"everything" hook kind (basic, named, entry, exit, after, action, etc).
|
|
1787
|
+
* It accepts `undefined` for the hook slot because most hooks are not set on
|
|
1788
|
+
* most machines; when no hook is installed the step is a no-op pass.
|
|
1789
|
+
*
|
|
1790
|
+
* The valid return shapes from a hook and their normalized meanings are:
|
|
1791
|
+
* - `undefined` → `{ pass: true }`
|
|
1792
|
+
* - `true` → `{ pass: true }`
|
|
1793
|
+
* - `false` → `{ pass: false }`
|
|
1794
|
+
* - `null` → `{ pass: false }`
|
|
1795
|
+
* - a complex result object → returned as-is
|
|
1796
|
+
*
|
|
1797
|
+
* Anything else is a programmer error and throws.
|
|
1798
|
+
*
|
|
1799
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1800
|
+
*
|
|
1801
|
+
* @param maybe_hook The hook handler to call, or `undefined` for the
|
|
1802
|
+
* "no hook installed" case.
|
|
1803
|
+
*
|
|
1804
|
+
* @param hook_args The context object passed to the hook. Includes the
|
|
1805
|
+
* current and proposed state, current and proposed data, action name, and
|
|
1806
|
+
* transition kind.
|
|
1807
|
+
*
|
|
1808
|
+
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
1809
|
+
* and, optionally, any data replacements it requested.
|
|
1810
|
+
*
|
|
1811
|
+
* @throws {TypeError} If the hook returns a value that is not one of the
|
|
1812
|
+
* legal shapes listed above.
|
|
1813
|
+
*
|
|
1814
|
+
* @internal
|
|
1815
|
+
*
|
|
1816
|
+
*/
|
|
1139
1817
|
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
|
|
1818
|
+
/**
|
|
1819
|
+
*
|
|
1820
|
+
* Invoke an optional "everything" hook and normalize its return value into
|
|
1821
|
+
* a {@link HookComplexResult}.
|
|
1822
|
+
*
|
|
1823
|
+
* Mechanically identical to {@link abstract_hook_step}, but typed for the
|
|
1824
|
+
* everything-hook family (`pre_everything_hook` and `everything_hook`),
|
|
1825
|
+
* whose context object carries an extra `hook_name` field identifying which
|
|
1826
|
+
* bracket of the pipeline is firing. Separated from `abstract_hook_step`
|
|
1827
|
+
* so TypeScript can enforce that the hook handler and the context object
|
|
1828
|
+
* agree on shape.
|
|
1829
|
+
*
|
|
1830
|
+
* The valid return shapes and their meanings are the same as for
|
|
1831
|
+
* `abstract_hook_step`:
|
|
1832
|
+
* - `undefined` or `true` → `{ pass: true }`
|
|
1833
|
+
* - `false` or `null` → `{ pass: false }`
|
|
1834
|
+
* - a complex result → returned as-is
|
|
1835
|
+
*
|
|
1836
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1837
|
+
*
|
|
1838
|
+
* @param maybe_hook The everything-hook handler, or `undefined` when none
|
|
1839
|
+
* is installed.
|
|
1840
|
+
*
|
|
1841
|
+
* @param hook_args The everything-hook context object. Differs from a
|
|
1842
|
+
* normal hook context in that it also includes `hook_name`.
|
|
1843
|
+
*
|
|
1844
|
+
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
1845
|
+
* and any data replacements it requested.
|
|
1846
|
+
*
|
|
1847
|
+
* @throws {TypeError} If the hook returns a value outside the legal shapes.
|
|
1848
|
+
*
|
|
1849
|
+
* @internal
|
|
1850
|
+
*
|
|
1851
|
+
*/
|
|
1852
|
+
declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHandler<mDT> | undefined, hook_args: EverythingHookContext<mDT>): HookComplexResult<mDT>;
|
|
1853
|
+
/**
|
|
1854
|
+
* Deserializes a previously serialized machine state.
|
|
1855
|
+
*
|
|
1856
|
+
* This function recreates a machine from a serialization object, restoring its
|
|
1857
|
+
* state, data, and history. For security and compatibility reasons, it will
|
|
1858
|
+
* refuse to deserialize data from future versions of the library.
|
|
1859
|
+
*
|
|
1860
|
+
* @typeparam mDT - The type of the machine data member
|
|
1861
|
+
*
|
|
1862
|
+
* @param {string} machine_string - The FSL string defining the machine structure
|
|
1863
|
+
* @param {JssmSerialization<mDT>} ser - The serialization object to restore from
|
|
1864
|
+
*
|
|
1865
|
+
* @returns {Machine<mDT>} - The restored machine instance
|
|
1866
|
+
*
|
|
1867
|
+
* @throws {Error} If the serialization is from a future version
|
|
1868
|
+
*
|
|
1869
|
+
* @example
|
|
1870
|
+
* const machine = jssm.from("a -> b;");
|
|
1871
|
+
* const serialized = machine.serialize();
|
|
1872
|
+
* const restored = jssm.deserialize("a -> b;", serialized);
|
|
1873
|
+
*/
|
|
1140
1874
|
declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
|
|
1141
|
-
export { version, build_time, transfer_state_properties, Machine, deserialize, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, unique, find_repeated, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, sleep, constants, shapes, gviz_shapes, named_colors, is_hook_rejection, is_hook_complex_result, abstract_hook_step, state_style_condense, FslDirections };
|
|
1875
|
+
export { version, build_time, transfer_state_properties, Machine, deserialize, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, unique, find_repeated, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, gen_splitmix32, sleep, constants, shapes, gviz_shapes, named_colors, is_hook_rejection, is_hook_complex_result, abstract_hook_step, abstract_everything_hook_step, state_style_condense, FslDirections };
|