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/jssm.es6.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ declare type JssmStateDeclaration = {
|
|
|
85
85
|
textColor?: JssmColor;
|
|
86
86
|
backgroundColor?: JssmColor;
|
|
87
87
|
borderColor?: JssmColor;
|
|
88
|
+
image?: string;
|
|
88
89
|
state: StateType$1;
|
|
89
90
|
property?: {
|
|
90
91
|
name: string;
|
|
@@ -124,7 +125,11 @@ declare type JssmStateStyleBorderColor = {
|
|
|
124
125
|
key: 'border-color';
|
|
125
126
|
value: JssmColor;
|
|
126
127
|
};
|
|
127
|
-
declare type
|
|
128
|
+
declare type JssmStateStyleImage = {
|
|
129
|
+
key: 'image';
|
|
130
|
+
value: string;
|
|
131
|
+
};
|
|
132
|
+
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor | JssmStateStyleImage;
|
|
128
133
|
declare type JssmStateStyleKeyList = JssmStateStyleKey[];
|
|
129
134
|
declare type JssmGenericConfig<StateType, DataType> = {
|
|
130
135
|
graph_layout?: JssmLayout;
|
|
@@ -301,7 +306,23 @@ declare type PostExitHook<mDT> = {
|
|
|
301
306
|
from: string;
|
|
302
307
|
handler: PostHookHandler<mDT>;
|
|
303
308
|
};
|
|
304
|
-
declare type
|
|
309
|
+
declare type PreEverythingHook<mDT> = {
|
|
310
|
+
kind: 'pre everything';
|
|
311
|
+
handler: EverythingHookHandler<mDT>;
|
|
312
|
+
};
|
|
313
|
+
declare type EverythingHook<mDT> = {
|
|
314
|
+
kind: 'everything';
|
|
315
|
+
handler: EverythingHookHandler<mDT>;
|
|
316
|
+
};
|
|
317
|
+
declare type PrePostEverythingHook<mDT> = {
|
|
318
|
+
kind: 'pre post everything';
|
|
319
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
320
|
+
};
|
|
321
|
+
declare type PostEverythingHook<mDT> = {
|
|
322
|
+
kind: 'post everything';
|
|
323
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
324
|
+
};
|
|
325
|
+
declare type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
305
326
|
declare type HookComplexResult<mDT> = {
|
|
306
327
|
pass: boolean;
|
|
307
328
|
state?: StateType$1;
|
|
@@ -313,8 +334,13 @@ declare type HookContext<mDT> = {
|
|
|
313
334
|
data: mDT;
|
|
314
335
|
next_data: mDT;
|
|
315
336
|
};
|
|
337
|
+
declare type EverythingHookContext<mDT> = HookContext<mDT> & {
|
|
338
|
+
hook_name: string;
|
|
339
|
+
};
|
|
316
340
|
declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
|
|
317
341
|
declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
|
|
342
|
+
declare type EverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => HookResult<mDT>;
|
|
343
|
+
declare type PostEverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => void;
|
|
318
344
|
declare type JssmHistory<mDT> = circular_buffer<[StateType$1, mDT]>;
|
|
319
345
|
declare type JssmRng = () => number;
|
|
320
346
|
|
|
@@ -493,6 +519,33 @@ declare function compile<StateType, mDT>(tree: JssmParseTree<StateType, mDT>): J
|
|
|
493
519
|
*/
|
|
494
520
|
declare function make<StateType, mDT>(plan: string): JssmGenericConfig<StateType, mDT>;
|
|
495
521
|
|
|
522
|
+
/*******
|
|
523
|
+
*
|
|
524
|
+
* Selects a single item from a weighted array of objects using cumulative
|
|
525
|
+
* probability. Each object in the array should have a numeric property
|
|
526
|
+
* indicating its relative weight (defaults to `'probability'`). Objects
|
|
527
|
+
* missing the property are treated as weight 1.
|
|
528
|
+
*
|
|
529
|
+
* ```typescript
|
|
530
|
+
* const opts = [
|
|
531
|
+
* { value: 'common', probability: 0.8 },
|
|
532
|
+
* { value: 'rare', probability: 0.2 }
|
|
533
|
+
* ];
|
|
534
|
+
*
|
|
535
|
+
* weighted_rand_select(opts); // most often { value: 'common', ... }
|
|
536
|
+
* ```
|
|
537
|
+
*
|
|
538
|
+
* @param options - Non-empty array of objects to choose from.
|
|
539
|
+
* @param probability_property - Name of the numeric weight property on each
|
|
540
|
+
* object. Defaults to `'probability'`.
|
|
541
|
+
* @param rng - Optional random number generator `() => number`
|
|
542
|
+
* in `[0, 1)`. Defaults to `Math.random`.
|
|
543
|
+
*
|
|
544
|
+
* @returns One element from `options`, chosen by weighted random selection.
|
|
545
|
+
*
|
|
546
|
+
* @throws {TypeError} If `options` is not a non-empty array of objects.
|
|
547
|
+
*
|
|
548
|
+
*/
|
|
496
549
|
declare const weighted_rand_select: Function;
|
|
497
550
|
/*******
|
|
498
551
|
*
|
|
@@ -520,8 +573,68 @@ declare function seq(n: number): number[];
|
|
|
520
573
|
*
|
|
521
574
|
*/
|
|
522
575
|
declare const histograph: Function;
|
|
576
|
+
/*******
|
|
577
|
+
*
|
|
578
|
+
* Draws `n` weighted random samples from an array of objects. Each draw is
|
|
579
|
+
* independent (with replacement), delegating to {@link weighted_rand_select}.
|
|
580
|
+
*
|
|
581
|
+
* ```typescript
|
|
582
|
+
* const opts = [
|
|
583
|
+
* { value: 'a', probability: 0.9 },
|
|
584
|
+
* { value: 'b', probability: 0.1 }
|
|
585
|
+
* ];
|
|
586
|
+
*
|
|
587
|
+
* weighted_sample_select(3, opts, 'probability');
|
|
588
|
+
* // e.g. [ { value: 'a', ... }, { value: 'a', ... }, { value: 'b', ... } ]
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @param n - Number of samples to draw.
|
|
592
|
+
* @param options - Non-empty array of weighted objects.
|
|
593
|
+
* @param probability_property - Name of the numeric weight property.
|
|
594
|
+
* @param rng - Optional random number generator.
|
|
595
|
+
*
|
|
596
|
+
* @returns An array of `n` independently selected items.
|
|
597
|
+
*
|
|
598
|
+
*/
|
|
523
599
|
declare const weighted_sample_select: Function;
|
|
600
|
+
/*******
|
|
601
|
+
*
|
|
602
|
+
* Draws `n` weighted random samples, extracts a named key from each, and
|
|
603
|
+
* returns a histograph (`Map`) of how often each key value appeared. Useful
|
|
604
|
+
* for validating that a probabilistic transition distribution is roughly
|
|
605
|
+
* correct over many trials.
|
|
606
|
+
*
|
|
607
|
+
* ```typescript
|
|
608
|
+
* const opts = [
|
|
609
|
+
* { to: 'a', probability: 0.7 },
|
|
610
|
+
* { to: 'b', probability: 0.3 }
|
|
611
|
+
* ];
|
|
612
|
+
*
|
|
613
|
+
* weighted_histo_key(1000, opts, 'probability', 'to');
|
|
614
|
+
* // Map { 'a' => ~700, 'b' => ~300 }
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* @param n - Number of samples to draw.
|
|
618
|
+
* @param opts - Non-empty array of weighted objects.
|
|
619
|
+
* @param prob_prop - Name of the numeric weight property.
|
|
620
|
+
* @param extract - Name of the property to extract from each sample for
|
|
621
|
+
* histogramming.
|
|
622
|
+
* @param rng - Optional random number generator.
|
|
623
|
+
*
|
|
624
|
+
* @returns A `Map` from extracted key values to their occurrence counts.
|
|
625
|
+
*
|
|
626
|
+
*/
|
|
524
627
|
declare const weighted_histo_key: Function;
|
|
628
|
+
/*******
|
|
629
|
+
*
|
|
630
|
+
* Creates a SplitMix32 random generator. Used by the randomness test suite.
|
|
631
|
+
*
|
|
632
|
+
* Sourced from `bryc`: https://github.com/bryc/code/blob/master/jshash/PRNGs.md#splitmix32
|
|
633
|
+
*
|
|
634
|
+
* Replaces the Mulberry generator, which was found to have problems
|
|
635
|
+
*
|
|
636
|
+
*/
|
|
637
|
+
declare function gen_splitmix32(a?: number | undefined): () => number;
|
|
525
638
|
/*******
|
|
526
639
|
*
|
|
527
640
|
* Reduces an array to its unique contents. Compares with `===` and makes no
|
|
@@ -538,7 +651,7 @@ declare const weighted_histo_key: Function;
|
|
|
538
651
|
* ```
|
|
539
652
|
*
|
|
540
653
|
*/
|
|
541
|
-
declare const unique: <T>(arr
|
|
654
|
+
declare const unique: <T>(arr: T[]) => T[];
|
|
542
655
|
/*******
|
|
543
656
|
*
|
|
544
657
|
* Lists all repeated items in an array along with their counts. Subject to
|
|
@@ -558,8 +671,33 @@ declare const unique: <T>(arr?: T[]) => T[];
|
|
|
558
671
|
*
|
|
559
672
|
*/
|
|
560
673
|
declare function find_repeated<T>(arr: T[]): [T, number][];
|
|
674
|
+
/*******
|
|
675
|
+
*
|
|
676
|
+
* Returns a `Promise` that resolves after `ms` milliseconds. Useful for
|
|
677
|
+
* inserting delays in async test flows or demos.
|
|
678
|
+
*
|
|
679
|
+
* ```typescript
|
|
680
|
+
* await sleep(100); // pauses execution for 100ms
|
|
681
|
+
* ```
|
|
682
|
+
*
|
|
683
|
+
* @param ms - Number of milliseconds to wait before resolving.
|
|
684
|
+
*
|
|
685
|
+
* @returns A `Promise<void>` that resolves after the timeout.
|
|
686
|
+
*
|
|
687
|
+
*/
|
|
561
688
|
declare function sleep(ms: number): Promise<unknown>;
|
|
562
689
|
|
|
690
|
+
/*******
|
|
691
|
+
*
|
|
692
|
+
* Convenience aliases for common mathematical and numeric constants from
|
|
693
|
+
* `Number` and `Math`. Re-exported so that FSL data expressions and tests
|
|
694
|
+
* can reference them without importing `Math` directly.
|
|
695
|
+
*
|
|
696
|
+
* Includes: `NegInfinity`, `PosInfinity`, `Epsilon`, `Pi`, `E`, `Root2`,
|
|
697
|
+
* `RootHalf`, `Ln2`, `Ln10`, `Log2E`, `Log10E`, `MaxSafeInt`, `MinSafeInt`,
|
|
698
|
+
* `MaxPosNum`, `MinPosNum`, `Phi` (golden ratio), `EulerC` (Euler–Mascheroni).
|
|
699
|
+
*
|
|
700
|
+
*/
|
|
563
701
|
declare const NegInfinity: number;
|
|
564
702
|
declare const PosInfinity: number;
|
|
565
703
|
declare const Epsilon: number;
|
|
@@ -577,8 +715,24 @@ declare const MaxPosNum: number;
|
|
|
577
715
|
declare const MinPosNum: number;
|
|
578
716
|
declare const Phi = 1.618033988749895;
|
|
579
717
|
declare const EulerC = 0.5772156649015329;
|
|
718
|
+
/*******
|
|
719
|
+
*
|
|
720
|
+
* Complete list of node shapes supported by Graphviz. Used by jssm-viz to
|
|
721
|
+
* validate and render state shapes in FSL `state ... : { shape: ... }` blocks.
|
|
722
|
+
*
|
|
723
|
+
* `shapes` is an alias for `gviz_shapes`.
|
|
724
|
+
*
|
|
725
|
+
*/
|
|
580
726
|
declare const gviz_shapes$1: string[];
|
|
581
727
|
declare const shapes$1: string[];
|
|
728
|
+
/*******
|
|
729
|
+
*
|
|
730
|
+
* List of CSS/SVG named colors accepted by jssm-viz for state styling
|
|
731
|
+
* properties like `background-color` and `text-color`. Case-insensitive
|
|
732
|
+
* matching is done at parse time; the canonical casing here follows the
|
|
733
|
+
* CSS specification.
|
|
734
|
+
*
|
|
735
|
+
*/
|
|
582
736
|
declare const named_colors$1: string[];
|
|
583
737
|
|
|
584
738
|
declare const jssm_constants_d_E: typeof E;
|
|
@@ -599,7 +753,28 @@ declare const jssm_constants_d_PosInfinity: typeof PosInfinity;
|
|
|
599
753
|
declare const jssm_constants_d_Root2: typeof Root2;
|
|
600
754
|
declare const jssm_constants_d_RootHalf: typeof RootHalf;
|
|
601
755
|
declare namespace jssm_constants_d {
|
|
602
|
-
export {
|
|
756
|
+
export {
|
|
757
|
+
jssm_constants_d_E as E,
|
|
758
|
+
jssm_constants_d_Epsilon as Epsilon,
|
|
759
|
+
jssm_constants_d_EulerC as EulerC,
|
|
760
|
+
jssm_constants_d_Ln10 as Ln10,
|
|
761
|
+
jssm_constants_d_Ln2 as Ln2,
|
|
762
|
+
jssm_constants_d_Log10E as Log10E,
|
|
763
|
+
jssm_constants_d_Log2E as Log2E,
|
|
764
|
+
jssm_constants_d_MaxPosNum as MaxPosNum,
|
|
765
|
+
jssm_constants_d_MaxSafeInt as MaxSafeInt,
|
|
766
|
+
jssm_constants_d_MinPosNum as MinPosNum,
|
|
767
|
+
jssm_constants_d_MinSafeInt as MinSafeInt,
|
|
768
|
+
jssm_constants_d_NegInfinity as NegInfinity,
|
|
769
|
+
jssm_constants_d_Phi as Phi,
|
|
770
|
+
jssm_constants_d_Pi as Pi,
|
|
771
|
+
jssm_constants_d_PosInfinity as PosInfinity,
|
|
772
|
+
jssm_constants_d_Root2 as Root2,
|
|
773
|
+
jssm_constants_d_RootHalf as RootHalf,
|
|
774
|
+
gviz_shapes$1 as gviz_shapes,
|
|
775
|
+
named_colors$1 as named_colors,
|
|
776
|
+
shapes$1 as shapes,
|
|
777
|
+
};
|
|
603
778
|
}
|
|
604
779
|
|
|
605
780
|
declare const version: string;
|
|
@@ -621,7 +796,69 @@ declare const named_colors: string[];
|
|
|
621
796
|
*
|
|
622
797
|
*/
|
|
623
798
|
declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
|
|
624
|
-
|
|
799
|
+
/**
|
|
800
|
+
*
|
|
801
|
+
* Collapse a list of individual state-style key/value pairs into a single
|
|
802
|
+
* {@link JssmStateConfig} object, remapping FSL-style kebab-case keys to the
|
|
803
|
+
* camelCase field names the runtime uses.
|
|
804
|
+
*
|
|
805
|
+
* The parser emits state styling as a flat array like
|
|
806
|
+
* `[{ key: 'color', value: 'red' }, { key: 'line-style', value: 'dashed' }]`
|
|
807
|
+
* because that is the most natural shape for the grammar to produce. This
|
|
808
|
+
* helper runs once per style bucket during `Machine` construction to turn
|
|
809
|
+
* those arrays into the compact `{ color, lineStyle, ... }` objects the
|
|
810
|
+
* graph-rendering code expects.
|
|
811
|
+
*
|
|
812
|
+
* ```typescript
|
|
813
|
+
* state_style_condense([
|
|
814
|
+
* { key: 'color', value: 'red' },
|
|
815
|
+
* { key: 'shape', value: 'oval' },
|
|
816
|
+
* { key: 'line-style', value: 'dashed' }
|
|
817
|
+
* ]);
|
|
818
|
+
* // => { color: 'red', shape: 'oval', lineStyle: 'dashed' }
|
|
819
|
+
*
|
|
820
|
+
* state_style_condense(undefined);
|
|
821
|
+
* // => {}
|
|
822
|
+
* ```
|
|
823
|
+
*
|
|
824
|
+
* @param jssk The list of style keys to condense. `undefined` is accepted
|
|
825
|
+
* and yields an empty config.
|
|
826
|
+
*
|
|
827
|
+
* @param machine Optional `Machine` reference, used only so that any
|
|
828
|
+
* {@link JssmError} thrown can point at the offending machine in its
|
|
829
|
+
* diagnostic message.
|
|
830
|
+
*
|
|
831
|
+
* @returns A `JssmStateConfig` object containing every key from `jssk`
|
|
832
|
+
* remapped into its camelCase field.
|
|
833
|
+
*
|
|
834
|
+
* @throws {JssmError} If `jssk` is neither an array nor `undefined`, if any
|
|
835
|
+
* element is not an object, if the same key appears more than once, or if a
|
|
836
|
+
* key is not one of the recognized style names.
|
|
837
|
+
*
|
|
838
|
+
* @internal
|
|
839
|
+
*
|
|
840
|
+
*/
|
|
841
|
+
declare function state_style_condense(jssk: JssmStateStyleKeyList, machine?: any): JssmStateConfig;
|
|
842
|
+
/*******
|
|
843
|
+
*
|
|
844
|
+
* Core finite state machine class. Holds the full graph of states and
|
|
845
|
+
* transitions, the current state, hooks, data, properties, and all runtime
|
|
846
|
+
* behavior. Typically created via the {@link sm} tagged template literal
|
|
847
|
+
* rather than constructed directly.
|
|
848
|
+
*
|
|
849
|
+
* ```typescript
|
|
850
|
+
* import { sm } from 'jssm';
|
|
851
|
+
*
|
|
852
|
+
* const light = sm`Red 'next' => Green 'next' => Yellow 'next' => Red;`;
|
|
853
|
+
* light.state(); // 'Red'
|
|
854
|
+
* light.action('next'); // true
|
|
855
|
+
* light.state(); // 'Green'
|
|
856
|
+
* ```
|
|
857
|
+
*
|
|
858
|
+
* @typeparam mDT The machine data type — the type of the value stored in
|
|
859
|
+
* `.data()`. Defaults to `undefined` when no data is used.
|
|
860
|
+
*
|
|
861
|
+
*/
|
|
625
862
|
declare class Machine<mDT> {
|
|
626
863
|
_state: StateType;
|
|
627
864
|
_states: Map<StateType, JssmGenericState>;
|
|
@@ -694,6 +931,10 @@ declare class Machine<mDT> {
|
|
|
694
931
|
_post_main_transition_hook: HookHandler<mDT> | undefined;
|
|
695
932
|
_post_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
696
933
|
_post_any_transition_hook: HookHandler<mDT> | undefined;
|
|
934
|
+
_pre_everything_hook: EverythingHookHandler<mDT> | undefined;
|
|
935
|
+
_everything_hook: EverythingHookHandler<mDT> | undefined;
|
|
936
|
+
_pre_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
|
|
937
|
+
_post_everything_hook: PostEverythingHookHandler<mDT> | undefined;
|
|
697
938
|
_property_keys: Set<string>;
|
|
698
939
|
_default_properties: Map<string, any>;
|
|
699
940
|
_state_properties: Map<string, any>;
|
|
@@ -741,6 +982,8 @@ declare class Machine<mDT> {
|
|
|
741
982
|
*
|
|
742
983
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
743
984
|
*
|
|
985
|
+
* @returns The current state name.
|
|
986
|
+
*
|
|
744
987
|
*/
|
|
745
988
|
state(): StateType;
|
|
746
989
|
/*********
|
|
@@ -759,6 +1002,10 @@ declare class Machine<mDT> {
|
|
|
759
1002
|
*
|
|
760
1003
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
761
1004
|
*
|
|
1005
|
+
* @param state The state to get the label for.
|
|
1006
|
+
*
|
|
1007
|
+
* @returns The label string, or `undefined` if no label is set.
|
|
1008
|
+
*
|
|
762
1009
|
*/
|
|
763
1010
|
label_for(state: StateType): string;
|
|
764
1011
|
/*********
|
|
@@ -782,6 +1029,10 @@ declare class Machine<mDT> {
|
|
|
782
1029
|
*
|
|
783
1030
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
784
1031
|
*
|
|
1032
|
+
* @param state The state to get display text for.
|
|
1033
|
+
*
|
|
1034
|
+
* @returns The label if one exists, otherwise the state's name.
|
|
1035
|
+
*
|
|
785
1036
|
*/
|
|
786
1037
|
display_text(state: StateType): string;
|
|
787
1038
|
/*********
|
|
@@ -797,45 +1048,60 @@ declare class Machine<mDT> {
|
|
|
797
1048
|
*
|
|
798
1049
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
799
1050
|
*
|
|
1051
|
+
* @returns A deep clone of the machine's current data value.
|
|
1052
|
+
*
|
|
800
1053
|
*/
|
|
801
1054
|
data(): mDT;
|
|
802
1055
|
/*********
|
|
803
1056
|
*
|
|
804
|
-
* Get the current value of a given property name.
|
|
1057
|
+
* Get the current value of a given property name. Checks the current
|
|
1058
|
+
* state's properties first, then falls back to the global default.
|
|
1059
|
+
* Returns `undefined` if neither exists. For a throwing variant, see
|
|
1060
|
+
* {@link strict_prop}.
|
|
805
1061
|
*
|
|
806
1062
|
* ```typescript
|
|
1063
|
+
* const m = sm`property color default "grey"; a -> b;
|
|
1064
|
+
* state b: { property color "blue"; };`;
|
|
807
1065
|
*
|
|
1066
|
+
* m.prop('color'); // 'grey' (default, because state is 'a')
|
|
1067
|
+
* m.go('b');
|
|
1068
|
+
* m.prop('color'); // 'blue' (state 'b' overrides the default)
|
|
1069
|
+
* m.prop('size'); // undefined (no such property)
|
|
808
1070
|
* ```
|
|
809
1071
|
*
|
|
810
|
-
* @param name The relevant property name to look up
|
|
1072
|
+
* @param name The relevant property name to look up.
|
|
811
1073
|
*
|
|
812
|
-
* @returns The value behind the prop name
|
|
813
|
-
* evaluated as getters, this can be anything.
|
|
1074
|
+
* @returns The value behind the prop name, or `undefined` if not defined.
|
|
814
1075
|
*
|
|
815
1076
|
*/
|
|
816
1077
|
prop(name: string): any;
|
|
817
1078
|
/*********
|
|
818
1079
|
*
|
|
819
1080
|
* Get the current value of a given property name. If missing on the state
|
|
820
|
-
* and without a global default,
|
|
821
|
-
* return `undefined` instead.
|
|
1081
|
+
* and without a global default, throws a {@link JssmError}, unlike
|
|
1082
|
+
* {@link prop}, which would return `undefined` instead.
|
|
822
1083
|
*
|
|
823
1084
|
* ```typescript
|
|
1085
|
+
* const m = sm`property color default "grey"; a -> b;`;
|
|
824
1086
|
*
|
|
1087
|
+
* m.strict_prop('color'); // 'grey'
|
|
1088
|
+
* m.strict_prop('size'); // throws JssmError
|
|
825
1089
|
* ```
|
|
826
1090
|
*
|
|
827
|
-
* @param name The relevant property name to look up
|
|
1091
|
+
* @param name The relevant property name to look up.
|
|
828
1092
|
*
|
|
829
|
-
* @returns The value behind the prop name.
|
|
830
|
-
*
|
|
1093
|
+
* @returns The value behind the prop name.
|
|
1094
|
+
*
|
|
1095
|
+
* @throws {JssmError} If the property is not defined on the current state
|
|
1096
|
+
* and has no default.
|
|
831
1097
|
*
|
|
832
1098
|
*/
|
|
833
1099
|
strict_prop(name: string): any;
|
|
834
1100
|
/*********
|
|
835
1101
|
*
|
|
836
1102
|
* Get the current value of every prop, as an object. If no current definition
|
|
837
|
-
* exists for a prop
|
|
838
|
-
* the current state also doesn't define the prop
|
|
1103
|
+
* exists for a prop — that is, if the prop was defined without a default and
|
|
1104
|
+
* the current state also doesn't define the prop — then that prop will be listed
|
|
839
1105
|
* in the returned object with a value of `undefined`.
|
|
840
1106
|
*
|
|
841
1107
|
* ```typescript
|
|
@@ -866,29 +1132,12 @@ declare class Machine<mDT> {
|
|
|
866
1132
|
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
|
|
867
1133
|
* ```
|
|
868
1134
|
*
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
*
|
|
873
|
-
* Get the current value of every prop, as an object. Compare
|
|
874
|
-
* {@link prop_map}, which returns a `Map`.
|
|
875
|
-
*
|
|
876
|
-
* ```typescript
|
|
877
|
-
*
|
|
878
|
-
* ```
|
|
879
|
-
*
|
|
880
|
-
*/
|
|
881
|
-
/*********
|
|
882
|
-
*
|
|
883
|
-
* Get the current value of every prop, as an object. Compare
|
|
884
|
-
* {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
|
|
885
|
-
* this throws if a required prop is missing.
|
|
886
|
-
*
|
|
887
|
-
* ```typescript
|
|
888
|
-
*
|
|
889
|
-
* ```
|
|
1135
|
+
* @returns An object mapping every known property name to its current value
|
|
1136
|
+
* (or `undefined` if the property has no default and the current state
|
|
1137
|
+
* doesn't define it).
|
|
890
1138
|
*
|
|
891
1139
|
*/
|
|
1140
|
+
props(): object;
|
|
892
1141
|
/*********
|
|
893
1142
|
*
|
|
894
1143
|
* Check whether a given string is a known property's name.
|
|
@@ -911,8 +1160,13 @@ declare class Machine<mDT> {
|
|
|
911
1160
|
* the properties generally will not be sorted.
|
|
912
1161
|
*
|
|
913
1162
|
* ```typescript
|
|
1163
|
+
* const m = sm`property color default "grey"; property size default 1; a -> b;`;
|
|
1164
|
+
*
|
|
1165
|
+
* m.known_props(); // ['color', 'size']
|
|
914
1166
|
* ```
|
|
915
1167
|
*
|
|
1168
|
+
* @returns An array of all property name strings defined on this machine.
|
|
1169
|
+
*
|
|
916
1170
|
*/
|
|
917
1171
|
known_props(): string[];
|
|
918
1172
|
/********
|
|
@@ -1011,22 +1265,78 @@ declare class Machine<mDT> {
|
|
|
1011
1265
|
*
|
|
1012
1266
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1013
1267
|
*
|
|
1268
|
+
* @param comment An optional comment string to embed in the serialized
|
|
1269
|
+
* output for identification or debugging.
|
|
1270
|
+
*
|
|
1271
|
+
* @returns A {@link JssmSerialization} object containing the machine's
|
|
1272
|
+
* current state, data, and timestamp.
|
|
1273
|
+
*
|
|
1014
1274
|
*/
|
|
1015
1275
|
serialize(comment?: string | undefined): JssmSerialization<mDT>;
|
|
1276
|
+
/** Get the graph layout direction (e.g. `'LR'`, `'TB'`). Set via the
|
|
1277
|
+
* FSL `graph_layout` directive.
|
|
1278
|
+
* @returns The layout string, or the default if not set.
|
|
1279
|
+
*/
|
|
1016
1280
|
graph_layout(): string;
|
|
1281
|
+
/** Get the Graphviz DOT preamble string, injected before the graph body
|
|
1282
|
+
* during visualization. Set via the FSL `dot_preamble` directive.
|
|
1283
|
+
* @returns The preamble string.
|
|
1284
|
+
*/
|
|
1017
1285
|
dot_preamble(): string;
|
|
1286
|
+
/** Get the machine's author list. Set via the FSL `machine_author` directive.
|
|
1287
|
+
* @returns An array of author name strings.
|
|
1288
|
+
*/
|
|
1018
1289
|
machine_author(): Array<string>;
|
|
1290
|
+
/** Get the machine's comment string. Set via the FSL `machine_comment` directive.
|
|
1291
|
+
* @returns The comment string.
|
|
1292
|
+
*/
|
|
1019
1293
|
machine_comment(): string;
|
|
1294
|
+
/** Get the machine's contributor list. Set via the FSL `machine_contributor` directive.
|
|
1295
|
+
* @returns An array of contributor name strings.
|
|
1296
|
+
*/
|
|
1020
1297
|
machine_contributor(): Array<string>;
|
|
1298
|
+
/** Get the machine's definition string. Set via the FSL `machine_definition` directive.
|
|
1299
|
+
* @returns The definition string.
|
|
1300
|
+
*/
|
|
1021
1301
|
machine_definition(): string;
|
|
1302
|
+
/** Get the machine's language (ISO 639-1). Set via the FSL `machine_language` directive.
|
|
1303
|
+
* @returns The language code string.
|
|
1304
|
+
*/
|
|
1022
1305
|
machine_language(): string;
|
|
1306
|
+
/** Get the machine's license string. Set via the FSL `machine_license` directive.
|
|
1307
|
+
* @returns The license string.
|
|
1308
|
+
*/
|
|
1023
1309
|
machine_license(): string;
|
|
1310
|
+
/** Get the machine's name. Set via the FSL `machine_name` directive.
|
|
1311
|
+
* @returns The machine name string.
|
|
1312
|
+
*/
|
|
1024
1313
|
machine_name(): string;
|
|
1314
|
+
/** Get the machine's version string. Set via the FSL `machine_version` directive.
|
|
1315
|
+
* @returns The version string.
|
|
1316
|
+
*/
|
|
1025
1317
|
machine_version(): string;
|
|
1318
|
+
/** Get the raw state declaration objects as parsed from the FSL source.
|
|
1319
|
+
* @returns An array of raw state declaration objects.
|
|
1320
|
+
*/
|
|
1026
1321
|
raw_state_declarations(): Array<Object>;
|
|
1322
|
+
/** Get the processed state declaration for a specific state.
|
|
1323
|
+
* @param which - The state to look up.
|
|
1324
|
+
* @returns The {@link JssmStateDeclaration} for the given state.
|
|
1325
|
+
*/
|
|
1027
1326
|
state_declaration(which: StateType): JssmStateDeclaration;
|
|
1327
|
+
/** Get all processed state declarations as a Map.
|
|
1328
|
+
* @returns A `Map` from state name to {@link JssmStateDeclaration}.
|
|
1329
|
+
*/
|
|
1028
1330
|
state_declarations(): Map<StateType, JssmStateDeclaration>;
|
|
1331
|
+
/** Get the FSL language version this machine was compiled under.
|
|
1332
|
+
* @returns The FSL version string.
|
|
1333
|
+
*/
|
|
1029
1334
|
fsl_version(): string;
|
|
1335
|
+
/** Get the complete internal state of the machine as a serializable
|
|
1336
|
+
* structure. Includes actions, edges, edge map, named transitions,
|
|
1337
|
+
* reverse actions, current state, and states map.
|
|
1338
|
+
* @returns A {@link JssmMachineInternalState} snapshot.
|
|
1339
|
+
*/
|
|
1030
1340
|
machine_state(): JssmMachineInternalState<mDT>;
|
|
1031
1341
|
/*********
|
|
1032
1342
|
*
|
|
@@ -1042,8 +1352,15 @@ declare class Machine<mDT> {
|
|
|
1042
1352
|
*
|
|
1043
1353
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1044
1354
|
*
|
|
1355
|
+
* @returns An array of all state names in the machine.
|
|
1356
|
+
*
|
|
1045
1357
|
*/
|
|
1046
1358
|
states(): Array<StateType>;
|
|
1359
|
+
/** Get the internal state descriptor for a given state name.
|
|
1360
|
+
* @param whichState - The state to look up.
|
|
1361
|
+
* @returns The {@link JssmGenericState} descriptor.
|
|
1362
|
+
* @throws {JssmError} If the state does not exist.
|
|
1363
|
+
*/
|
|
1047
1364
|
state_for(whichState: StateType): JssmGenericState;
|
|
1048
1365
|
/*********
|
|
1049
1366
|
*
|
|
@@ -1060,7 +1377,9 @@ declare class Machine<mDT> {
|
|
|
1060
1377
|
*
|
|
1061
1378
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1062
1379
|
*
|
|
1063
|
-
* @param whichState The state to be checked for
|
|
1380
|
+
* @param whichState The state to be checked for existence.
|
|
1381
|
+
*
|
|
1382
|
+
* @returns `true` if the state exists, `false` otherwise.
|
|
1064
1383
|
*
|
|
1065
1384
|
*/
|
|
1066
1385
|
has_state(whichState: StateType): boolean;
|
|
@@ -1096,35 +1415,82 @@ declare class Machine<mDT> {
|
|
|
1096
1415
|
*
|
|
1097
1416
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1098
1417
|
*
|
|
1418
|
+
* @returns An array of all {@link JssmTransition} edge objects.
|
|
1419
|
+
*
|
|
1099
1420
|
*/
|
|
1100
1421
|
list_edges(): Array<JssmTransition<StateType, mDT>>;
|
|
1422
|
+
/** Get the map of named transitions (transitions with explicit names).
|
|
1423
|
+
* @returns A `Map` from transition name to edge index.
|
|
1424
|
+
*/
|
|
1101
1425
|
list_named_transitions(): Map<StateType, number>;
|
|
1426
|
+
/** List all distinct action names defined anywhere in the machine.
|
|
1427
|
+
* @returns An array of action name strings.
|
|
1428
|
+
*/
|
|
1102
1429
|
list_actions(): Array<StateType>;
|
|
1430
|
+
/** Whether any actions are defined on this machine.
|
|
1431
|
+
* @returns `true` if the machine has at least one action.
|
|
1432
|
+
*/
|
|
1103
1433
|
get uses_actions(): boolean;
|
|
1434
|
+
/** Whether any forced (`~>`) transitions exist in this machine.
|
|
1435
|
+
* @returns `true` if at least one forced transition is defined.
|
|
1436
|
+
*/
|
|
1104
1437
|
get uses_forced_transitions(): boolean;
|
|
1105
1438
|
/*********
|
|
1106
1439
|
*
|
|
1107
1440
|
* Check if the code that built the machine allows overriding state and data.
|
|
1108
1441
|
*
|
|
1442
|
+
* @returns The override permission from the FSL source code.
|
|
1443
|
+
*
|
|
1109
1444
|
*/
|
|
1110
1445
|
get code_allows_override(): JssmAllowsOverride;
|
|
1111
1446
|
/*********
|
|
1112
1447
|
*
|
|
1113
1448
|
* Check if the machine config allows overriding state and data.
|
|
1114
1449
|
*
|
|
1450
|
+
* @returns The override permission from the runtime config.
|
|
1451
|
+
*
|
|
1115
1452
|
*/
|
|
1116
1453
|
get config_allows_override(): JssmAllowsOverride;
|
|
1117
1454
|
/*********
|
|
1118
1455
|
*
|
|
1119
|
-
* Check if a machine allows overriding state and data.
|
|
1456
|
+
* Check if a machine allows overriding state and data. Resolves the
|
|
1457
|
+
* combined effect of code and config permissions — config may not be
|
|
1458
|
+
* less strict than code.
|
|
1459
|
+
*
|
|
1460
|
+
* @returns The effective override permission.
|
|
1120
1461
|
*
|
|
1121
1462
|
*/
|
|
1122
1463
|
get allows_override(): JssmAllowsOverride;
|
|
1464
|
+
/** List all available theme names.
|
|
1465
|
+
* @returns An array of theme name strings.
|
|
1466
|
+
*/
|
|
1123
1467
|
all_themes(): FslTheme[];
|
|
1468
|
+
/** Get the active theme(s) for this machine. Always stored as an array
|
|
1469
|
+
* internally; the union return type exists for setter compatibility.
|
|
1470
|
+
* @returns The current theme or array of themes.
|
|
1471
|
+
*/
|
|
1124
1472
|
get themes(): FslTheme | FslTheme[];
|
|
1473
|
+
/** Set the active theme(s). Accepts a single theme name or an array.
|
|
1474
|
+
* @param to - A theme name or array of theme names to apply.
|
|
1475
|
+
*/
|
|
1125
1476
|
set themes(to: FslTheme | FslTheme[]);
|
|
1477
|
+
/** Get the flow direction for graph layout (e.g. `'right'`, `'down'`).
|
|
1478
|
+
* Set via the FSL `flow` directive.
|
|
1479
|
+
* @returns The current flow direction.
|
|
1480
|
+
*/
|
|
1126
1481
|
flow(): FslDirection;
|
|
1482
|
+
/** Look up a transition's edge index by source and target state names.
|
|
1483
|
+
* @param from - Source state name.
|
|
1484
|
+
* @param to - Target state name.
|
|
1485
|
+
* @returns The edge index in the edges array, or `undefined` if no
|
|
1486
|
+
* such transition exists.
|
|
1487
|
+
*/
|
|
1127
1488
|
get_transition_by_state_names(from: StateType, to: StateType): number;
|
|
1489
|
+
/** Look up the full transition object for a given source→target pair.
|
|
1490
|
+
* @param from - Source state name.
|
|
1491
|
+
* @param to - Target state name.
|
|
1492
|
+
* @returns The {@link JssmTransition} object, or `undefined` if none exists.
|
|
1493
|
+
*/
|
|
1128
1494
|
lookup_transition_for(from: StateType, to: StateType): JssmTransition<StateType, mDT>;
|
|
1129
1495
|
/********
|
|
1130
1496
|
*
|
|
@@ -1192,9 +1558,29 @@ declare class Machine<mDT> {
|
|
|
1192
1558
|
*
|
|
1193
1559
|
*/
|
|
1194
1560
|
list_exits(whichState?: StateType): Array<StateType>;
|
|
1561
|
+
/** Get the transitions available from a state, filtered to those with
|
|
1562
|
+
* probability data. Used by the probabilistic walk system.
|
|
1563
|
+
* @param whichState - The state to inspect.
|
|
1564
|
+
* @returns An array of {@link JssmTransition} edges exiting the state.
|
|
1565
|
+
* @throws {JssmError} If the state does not exist.
|
|
1566
|
+
*/
|
|
1195
1567
|
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
|
|
1568
|
+
/** Take a single random transition from the current state, weighted by
|
|
1569
|
+
* edge probabilities.
|
|
1570
|
+
* @returns `true` if a transition was taken, `false` otherwise.
|
|
1571
|
+
*/
|
|
1196
1572
|
probabilistic_transition(): boolean;
|
|
1573
|
+
/** Take `n` consecutive probabilistic transitions and return the sequence
|
|
1574
|
+
* of states visited (before each transition).
|
|
1575
|
+
* @param n - Number of steps to walk.
|
|
1576
|
+
* @returns An array of state names visited during the walk.
|
|
1577
|
+
*/
|
|
1197
1578
|
probabilistic_walk(n: number): Array<StateType>;
|
|
1579
|
+
/** Take `n` probabilistic steps and return a histograph of how many times
|
|
1580
|
+
* each state was visited.
|
|
1581
|
+
* @param n - Number of steps to walk.
|
|
1582
|
+
* @returns A `Map` from state name to visit count.
|
|
1583
|
+
*/
|
|
1198
1584
|
probabilistic_histo_walk(n: number): Map<StateType, number>;
|
|
1199
1585
|
/********
|
|
1200
1586
|
*
|
|
@@ -1227,7 +1613,10 @@ declare class Machine<mDT> {
|
|
|
1227
1613
|
*
|
|
1228
1614
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1229
1615
|
*
|
|
1230
|
-
* @param whichState The state whose actions to
|
|
1616
|
+
* @param whichState The state whose actions to list. Defaults to the
|
|
1617
|
+
* current state.
|
|
1618
|
+
*
|
|
1619
|
+
* @returns An array of action names available from the given state.
|
|
1231
1620
|
*
|
|
1232
1621
|
*/
|
|
1233
1622
|
actions(whichState?: StateType): Array<StateType>;
|
|
@@ -1254,40 +1643,276 @@ declare class Machine<mDT> {
|
|
|
1254
1643
|
*
|
|
1255
1644
|
*/
|
|
1256
1645
|
list_states_having_action(whichState: StateType): Array<StateType>;
|
|
1646
|
+
/** List all action names available as exits from a given state.
|
|
1647
|
+
* @param whichState - The state to inspect. Defaults to the current state.
|
|
1648
|
+
* @returns An array of action name strings.
|
|
1649
|
+
* @throws {JssmError} If the state does not exist.
|
|
1650
|
+
*/
|
|
1257
1651
|
list_exit_actions(whichState?: StateType): Array<StateType>;
|
|
1652
|
+
/** List all action exits from a state with their probabilities.
|
|
1653
|
+
* @param whichState - The state to inspect. Defaults to the current state.
|
|
1654
|
+
* @returns An array of `{ action, probability }` objects.
|
|
1655
|
+
* @throws {JssmError} If the state does not exist.
|
|
1656
|
+
*/
|
|
1258
1657
|
probable_action_exits(whichState?: StateType): Array<any>;
|
|
1658
|
+
/** Check whether a state has no incoming transitions (unreachable after start).
|
|
1659
|
+
* @param whichState - The state to check.
|
|
1660
|
+
* @returns `true` if the state has zero entrances.
|
|
1661
|
+
* @throws {JssmError} If the state does not exist.
|
|
1662
|
+
*/
|
|
1259
1663
|
is_unenterable(whichState: StateType): boolean;
|
|
1664
|
+
/** Check whether any state in the machine is unenterable.
|
|
1665
|
+
* @returns `true` if at least one state has no incoming transitions.
|
|
1666
|
+
*/
|
|
1260
1667
|
has_unenterables(): boolean;
|
|
1668
|
+
/** Check whether the current state is terminal (has no exits).
|
|
1669
|
+
* @returns `true` if the current state has zero exits.
|
|
1670
|
+
*/
|
|
1261
1671
|
is_terminal(): boolean;
|
|
1672
|
+
/** Check whether a specific state is terminal (has no exits).
|
|
1673
|
+
* @param whichState - The state to check.
|
|
1674
|
+
* @returns `true` if the state has zero exits.
|
|
1675
|
+
* @throws {JssmError} If the state does not exist.
|
|
1676
|
+
*/
|
|
1262
1677
|
state_is_terminal(whichState: StateType): boolean;
|
|
1678
|
+
/** Check whether any state in the machine is terminal.
|
|
1679
|
+
* @returns `true` if at least one state has no exits.
|
|
1680
|
+
*/
|
|
1263
1681
|
has_terminals(): boolean;
|
|
1682
|
+
/** Check whether the current state is complete (every exit has an action).
|
|
1683
|
+
* @returns `true` if the current state is complete.
|
|
1684
|
+
*/
|
|
1264
1685
|
is_complete(): boolean;
|
|
1686
|
+
/** Check whether a specific state is complete (every exit has an action).
|
|
1687
|
+
* @param whichState - The state to check.
|
|
1688
|
+
* @returns `true` if the state is complete.
|
|
1689
|
+
* @throws {JssmError} If the state does not exist.
|
|
1690
|
+
*/
|
|
1265
1691
|
state_is_complete(whichState: StateType): boolean;
|
|
1692
|
+
/** Check whether any state in the machine is complete.
|
|
1693
|
+
* @returns `true` if at least one state is complete.
|
|
1694
|
+
*/
|
|
1266
1695
|
has_completes(): boolean;
|
|
1696
|
+
/** Low-level hook registration. Installs a handler described by a
|
|
1697
|
+
* {@link HookDescription} into the appropriate internal map. Prefer the
|
|
1698
|
+
* convenience wrappers ({@link hook}, {@link hook_entry}, etc.) over
|
|
1699
|
+
* calling this directly.
|
|
1700
|
+
* @param HookDesc - A hook descriptor specifying kind, states, and handler.
|
|
1701
|
+
*/
|
|
1267
1702
|
set_hook(HookDesc: HookDescription<mDT>): void;
|
|
1703
|
+
/** Register a pre-transition hook on a specific edge. Fires before
|
|
1704
|
+
* transitioning from `from` to `to`. If the handler returns `false`, the
|
|
1705
|
+
* transition is blocked.
|
|
1706
|
+
*
|
|
1707
|
+
* ```typescript
|
|
1708
|
+
* const m = sm`a -> b -> c;`;
|
|
1709
|
+
* m.hook('a', 'b', () => console.log('a->b'));
|
|
1710
|
+
* ```
|
|
1711
|
+
*
|
|
1712
|
+
* @param from - Source state name.
|
|
1713
|
+
* @param to - Target state name.
|
|
1714
|
+
* @param handler - Callback invoked before the transition.
|
|
1715
|
+
* @returns `this` for chaining.
|
|
1716
|
+
*/
|
|
1268
1717
|
hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1718
|
+
/** Register a pre-transition hook on a specific action-labeled edge.
|
|
1719
|
+
* @param from - Source state name.
|
|
1720
|
+
* @param to - Target state name.
|
|
1721
|
+
* @param action - The action label that triggers this hook.
|
|
1722
|
+
* @param handler - Callback invoked before the transition.
|
|
1723
|
+
* @returns `this` for chaining.
|
|
1724
|
+
*/
|
|
1269
1725
|
hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1726
|
+
/** Register a pre-transition hook on any edge triggered by a specific action.
|
|
1727
|
+
* @param action - The action name to hook.
|
|
1728
|
+
* @param handler - Callback invoked before any transition with this action.
|
|
1729
|
+
* @returns `this` for chaining.
|
|
1730
|
+
*/
|
|
1270
1731
|
hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1732
|
+
/** Register a pre-transition hook on any action-driven transition.
|
|
1733
|
+
* @param handler - Callback invoked before any action transition.
|
|
1734
|
+
* @returns `this` for chaining.
|
|
1735
|
+
*/
|
|
1271
1736
|
hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1737
|
+
/** Register a pre-transition hook on any standard (`->`) transition.
|
|
1738
|
+
* @param handler - Callback invoked before any legal transition.
|
|
1739
|
+
* @returns `this` for chaining.
|
|
1740
|
+
*/
|
|
1272
1741
|
hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1742
|
+
/** Register a pre-transition hook on any main-path (`=>`) transition.
|
|
1743
|
+
* @param handler - Callback invoked before any main transition.
|
|
1744
|
+
* @returns `this` for chaining.
|
|
1745
|
+
*/
|
|
1273
1746
|
hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1747
|
+
/** Register a pre-transition hook on any forced (`~>`) transition.
|
|
1748
|
+
* @param handler - Callback invoked before any forced transition.
|
|
1749
|
+
* @returns `this` for chaining.
|
|
1750
|
+
*/
|
|
1274
1751
|
hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1752
|
+
/** Register a pre-transition hook on any transition regardless of kind.
|
|
1753
|
+
* @param handler - Callback invoked before every transition.
|
|
1754
|
+
* @returns `this` for chaining.
|
|
1755
|
+
*/
|
|
1275
1756
|
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1757
|
+
/** Register a hook that fires when entering a specific state.
|
|
1758
|
+
* @param to - The state being entered.
|
|
1759
|
+
* @param handler - Callback invoked on entry.
|
|
1760
|
+
* @returns `this` for chaining.
|
|
1761
|
+
*/
|
|
1276
1762
|
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1763
|
+
/** Register a hook that fires when leaving a specific state.
|
|
1764
|
+
* @param from - The state being exited.
|
|
1765
|
+
* @param handler - Callback invoked on exit.
|
|
1766
|
+
* @returns `this` for chaining.
|
|
1767
|
+
*/
|
|
1277
1768
|
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1769
|
+
/** Register a hook that fires after leaving a specific state (post-exit).
|
|
1770
|
+
* @param from - The state that was exited.
|
|
1771
|
+
* @param handler - Callback invoked after exit completes.
|
|
1772
|
+
* @returns `this` for chaining.
|
|
1773
|
+
*/
|
|
1278
1774
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1775
|
+
/** Post-transition hook on a specific edge. Fires after the transition
|
|
1776
|
+
* from `from` to `to` has completed. Cannot block the transition.
|
|
1777
|
+
* @param from - Source state name.
|
|
1778
|
+
* @param to - Target state name.
|
|
1779
|
+
* @param handler - Callback invoked after the transition.
|
|
1780
|
+
* @returns `this` for chaining.
|
|
1781
|
+
*/
|
|
1279
1782
|
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1783
|
+
/** Post-transition hook on a specific action-labeled edge.
|
|
1784
|
+
* @param from - Source state name.
|
|
1785
|
+
* @param to - Target state name.
|
|
1786
|
+
* @param action - The action label.
|
|
1787
|
+
* @param handler - Callback invoked after the transition.
|
|
1788
|
+
* @returns `this` for chaining.
|
|
1789
|
+
*/
|
|
1280
1790
|
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1791
|
+
/** Post-transition hook on any edge triggered by a specific action.
|
|
1792
|
+
* @param action - The action name.
|
|
1793
|
+
* @param handler - Callback invoked after any transition with this action.
|
|
1794
|
+
* @returns `this` for chaining.
|
|
1795
|
+
*/
|
|
1281
1796
|
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1797
|
+
/** Post-transition hook on any action-driven transition.
|
|
1798
|
+
* @param handler - Callback invoked after any action transition.
|
|
1799
|
+
* @returns `this` for chaining.
|
|
1800
|
+
*/
|
|
1282
1801
|
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1802
|
+
/** Post-transition hook on any standard (`->`) transition.
|
|
1803
|
+
* @param handler - Callback invoked after any legal transition.
|
|
1804
|
+
* @returns `this` for chaining.
|
|
1805
|
+
*/
|
|
1283
1806
|
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1807
|
+
/** Post-transition hook on any main-path (`=>`) transition.
|
|
1808
|
+
* @param handler - Callback invoked after any main transition.
|
|
1809
|
+
* @returns `this` for chaining.
|
|
1810
|
+
*/
|
|
1284
1811
|
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1812
|
+
/** Post-transition hook on any forced (`~>`) transition.
|
|
1813
|
+
* @param handler - Callback invoked after any forced transition.
|
|
1814
|
+
* @returns `this` for chaining.
|
|
1815
|
+
*/
|
|
1285
1816
|
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1817
|
+
/** Post-transition hook on any transition regardless of kind.
|
|
1818
|
+
* @param handler - Callback invoked after every transition.
|
|
1819
|
+
* @returns `this` for chaining.
|
|
1820
|
+
*/
|
|
1286
1821
|
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
1822
|
+
/** Post-transition hook that fires after entering a specific state.
|
|
1823
|
+
* @param to - The state that was entered.
|
|
1824
|
+
* @param handler - Callback invoked after entry.
|
|
1825
|
+
* @returns `this` for chaining.
|
|
1826
|
+
*/
|
|
1287
1827
|
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1828
|
+
/** Post-transition hook that fires after leaving a specific state.
|
|
1829
|
+
* @param from - The state that was exited.
|
|
1830
|
+
* @param handler - Callback invoked after exit.
|
|
1831
|
+
* @returns `this` for chaining.
|
|
1832
|
+
*/
|
|
1288
1833
|
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
1834
|
+
/** Register a pre-transition hook that fires **before** all other pre-hooks
|
|
1835
|
+
* on every transition. If the handler returns `false`, the transition is
|
|
1836
|
+
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1837
|
+
* `hook_name` is `'pre everything'`.
|
|
1838
|
+
*
|
|
1839
|
+
* ```typescript
|
|
1840
|
+
* const m = sm`a -> b -> c;`;
|
|
1841
|
+
* m.hook_pre_everything(({ hook_name }) => {
|
|
1842
|
+
* console.log(`${hook_name} fired`);
|
|
1843
|
+
* return true;
|
|
1844
|
+
* });
|
|
1845
|
+
* ```
|
|
1846
|
+
*
|
|
1847
|
+
* @param handler - Callback invoked before all other pre-hooks.
|
|
1848
|
+
* @returns `this` for chaining.
|
|
1849
|
+
*/
|
|
1850
|
+
hook_pre_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1851
|
+
/** Register a pre-transition hook that fires **after** all other pre-hooks
|
|
1852
|
+
* on every transition. If the handler returns `false`, the transition is
|
|
1853
|
+
* blocked. The handler receives an {@link EverythingHookContext} whose
|
|
1854
|
+
* `hook_name` is `'everything'`.
|
|
1855
|
+
*
|
|
1856
|
+
* ```typescript
|
|
1857
|
+
* const m = sm`a -> b -> c;`;
|
|
1858
|
+
* m.hook_everything(({ hook_name }) => {
|
|
1859
|
+
* console.log(`${hook_name} fired`);
|
|
1860
|
+
* return true;
|
|
1861
|
+
* });
|
|
1862
|
+
* ```
|
|
1863
|
+
*
|
|
1864
|
+
* @param handler - Callback invoked after all other pre-hooks.
|
|
1865
|
+
* @returns `this` for chaining.
|
|
1866
|
+
*/
|
|
1867
|
+
hook_everything(handler: EverythingHookHandler<mDT>): Machine<mDT>;
|
|
1868
|
+
/** Register a post-transition hook that fires **after** all other
|
|
1869
|
+
* post-hooks on every transition. Cannot block the transition. The
|
|
1870
|
+
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1871
|
+
* `'post everything'`.
|
|
1872
|
+
*
|
|
1873
|
+
* ```typescript
|
|
1874
|
+
* const m = sm`a -> b -> c;`;
|
|
1875
|
+
* m.hook_post_everything(({ hook_name }) => {
|
|
1876
|
+
* console.log(`${hook_name} fired`);
|
|
1877
|
+
* });
|
|
1878
|
+
* ```
|
|
1879
|
+
*
|
|
1880
|
+
* @param handler - Callback invoked after all other post-hooks.
|
|
1881
|
+
* @returns `this` for chaining.
|
|
1882
|
+
*/
|
|
1883
|
+
hook_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1884
|
+
/** Register a post-transition hook that fires **before** all other
|
|
1885
|
+
* post-hooks on every transition. Cannot block the transition. The
|
|
1886
|
+
* handler receives an {@link EverythingHookContext} whose `hook_name` is
|
|
1887
|
+
* `'pre post everything'`.
|
|
1888
|
+
*
|
|
1889
|
+
* ```typescript
|
|
1890
|
+
* const m = sm`a -> b -> c;`;
|
|
1891
|
+
* m.hook_pre_post_everything(({ hook_name }) => {
|
|
1892
|
+
* console.log(`${hook_name} fired`);
|
|
1893
|
+
* });
|
|
1894
|
+
* ```
|
|
1895
|
+
*
|
|
1896
|
+
* @param handler - Callback invoked before all other post-hooks.
|
|
1897
|
+
* @returns `this` for chaining.
|
|
1898
|
+
*/
|
|
1899
|
+
hook_pre_post_everything(handler: PostEverythingHookHandler<mDT>): Machine<mDT>;
|
|
1900
|
+
/** Get the current RNG seed used for probabilistic transitions.
|
|
1901
|
+
* @returns The numeric seed value.
|
|
1902
|
+
*/
|
|
1289
1903
|
get rng_seed(): number;
|
|
1904
|
+
/** Set the RNG seed. Pass `undefined` to reseed from the current time.
|
|
1905
|
+
* Resets the internal PRNG so subsequent probabilistic operations use the
|
|
1906
|
+
* new seed.
|
|
1907
|
+
* @param to - The seed value, or `undefined` for time-based seeding.
|
|
1908
|
+
*/
|
|
1290
1909
|
set rng_seed(to: number | undefined);
|
|
1910
|
+
/** Get all edges between two states (there can be multiple with
|
|
1911
|
+
* different actions).
|
|
1912
|
+
* @param from - Source state name.
|
|
1913
|
+
* @param to - Target state name.
|
|
1914
|
+
* @returns An array of matching {@link JssmTransition} objects.
|
|
1915
|
+
*/
|
|
1291
1916
|
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
1292
1917
|
/*********
|
|
1293
1918
|
*
|
|
@@ -1309,7 +1934,53 @@ declare class Machine<mDT> {
|
|
|
1309
1934
|
*
|
|
1310
1935
|
*/
|
|
1311
1936
|
override(newState: StateType, newData?: mDT | undefined): void;
|
|
1937
|
+
/*********
|
|
1938
|
+
*
|
|
1939
|
+
* Shared transition core used by {@link transition}, {@link force_transition},
|
|
1940
|
+
* and {@link action}. Runs validation, fires the full hook pipeline (pre-
|
|
1941
|
+
* everything, any-action, after, any-transition, exit, named, basic,
|
|
1942
|
+
* edge-type, entry, everything), commits the new state if nothing
|
|
1943
|
+
* rejected, and returns whether the transition succeeded.
|
|
1944
|
+
*
|
|
1945
|
+
* Not meant for external use. Call one of the public wrappers instead:
|
|
1946
|
+
* - `transition` for an ordinary legal transition
|
|
1947
|
+
* - `force_transition` to bypass the legality check
|
|
1948
|
+
* - `action` to dispatch by action name rather than target state
|
|
1949
|
+
*
|
|
1950
|
+
* @remarks
|
|
1951
|
+
* Known sharp edges, carried over from the original `// TODO` comments:
|
|
1952
|
+
* - The forced-ness behavior needs to be cleaned up a lot here.
|
|
1953
|
+
* - The callbacks are not fully correct across the forced / action / plain
|
|
1954
|
+
* cases and should be revisited.
|
|
1955
|
+
* - When multiple edges exist between two states with different `kind`
|
|
1956
|
+
* values, only the first edge's kind is used to pick the edge-type hook.
|
|
1957
|
+
*
|
|
1958
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
1959
|
+
*
|
|
1960
|
+
* @param newStateOrAction The target state name (for a plain or forced
|
|
1961
|
+
* transition) or the action name (when `wasAction` is true).
|
|
1962
|
+
*
|
|
1963
|
+
* @param newData Optional replacement machine data to install alongside
|
|
1964
|
+
* the transition. Hooks may further override this via complex results.
|
|
1965
|
+
*
|
|
1966
|
+
* @param wasForced `true` if the caller invoked `force_transition`, in
|
|
1967
|
+
* which case legality is checked against `valid_force_transition` rather
|
|
1968
|
+
* than `valid_transition`.
|
|
1969
|
+
*
|
|
1970
|
+
* @param wasAction `true` if the caller invoked `action`, in which case
|
|
1971
|
+
* `newStateOrAction` is an action name and the target state is looked up
|
|
1972
|
+
* via the current action edge.
|
|
1973
|
+
*
|
|
1974
|
+
* @returns `true` if the transition was valid and every hook passed;
|
|
1975
|
+
* `false` if the transition was invalid or any hook rejected.
|
|
1976
|
+
*
|
|
1977
|
+
* @internal
|
|
1978
|
+
*
|
|
1979
|
+
*/
|
|
1312
1980
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
1981
|
+
/** If the current state has an `after` timeout configured, schedule it.
|
|
1982
|
+
* Called internally after each transition.
|
|
1983
|
+
*/
|
|
1313
1984
|
auto_set_state_timeout(): void;
|
|
1314
1985
|
/*********
|
|
1315
1986
|
*
|
|
@@ -1411,6 +2082,9 @@ declare class Machine<mDT> {
|
|
|
1411
2082
|
*
|
|
1412
2083
|
* @param newData The data change to insert during the action
|
|
1413
2084
|
*
|
|
2085
|
+
* @returns `true` if the action was valid and the transition occurred,
|
|
2086
|
+
* `false` otherwise.
|
|
2087
|
+
*
|
|
1414
2088
|
*/
|
|
1415
2089
|
action(actionName: StateType, newData?: mDT): boolean;
|
|
1416
2090
|
/********
|
|
@@ -1431,6 +2105,8 @@ declare class Machine<mDT> {
|
|
|
1431
2105
|
*
|
|
1432
2106
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1433
2107
|
*
|
|
2108
|
+
* @returns The {@link JssmStateConfig} for standard states.
|
|
2109
|
+
*
|
|
1434
2110
|
*/
|
|
1435
2111
|
get standard_state_style(): JssmStateConfig;
|
|
1436
2112
|
/********
|
|
@@ -1455,6 +2131,8 @@ declare class Machine<mDT> {
|
|
|
1455
2131
|
*
|
|
1456
2132
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1457
2133
|
*
|
|
2134
|
+
* @returns The {@link JssmStateConfig} for hooked states.
|
|
2135
|
+
*
|
|
1458
2136
|
*/
|
|
1459
2137
|
get hooked_state_style(): JssmStateConfig;
|
|
1460
2138
|
/********
|
|
@@ -1478,6 +2156,8 @@ declare class Machine<mDT> {
|
|
|
1478
2156
|
*
|
|
1479
2157
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1480
2158
|
*
|
|
2159
|
+
* @returns The {@link JssmStateConfig} for start states.
|
|
2160
|
+
*
|
|
1481
2161
|
*/
|
|
1482
2162
|
get start_state_style(): JssmStateConfig;
|
|
1483
2163
|
/********
|
|
@@ -1506,6 +2186,8 @@ declare class Machine<mDT> {
|
|
|
1506
2186
|
*
|
|
1507
2187
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1508
2188
|
*
|
|
2189
|
+
* @returns The {@link JssmStateConfig} for end states.
|
|
2190
|
+
*
|
|
1509
2191
|
*/
|
|
1510
2192
|
get end_state_style(): JssmStateConfig;
|
|
1511
2193
|
/********
|
|
@@ -1529,6 +2211,8 @@ declare class Machine<mDT> {
|
|
|
1529
2211
|
*
|
|
1530
2212
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1531
2213
|
*
|
|
2214
|
+
* @returns The {@link JssmStateConfig} for terminal states.
|
|
2215
|
+
*
|
|
1532
2216
|
*/
|
|
1533
2217
|
get terminal_state_style(): JssmStateConfig;
|
|
1534
2218
|
/********
|
|
@@ -1549,6 +2233,8 @@ declare class Machine<mDT> {
|
|
|
1549
2233
|
*
|
|
1550
2234
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1551
2235
|
*
|
|
2236
|
+
* @returns The {@link JssmStateConfig} for the active state.
|
|
2237
|
+
*
|
|
1552
2238
|
*/
|
|
1553
2239
|
get active_state_style(): JssmStateConfig;
|
|
1554
2240
|
/********
|
|
@@ -1569,6 +2255,10 @@ declare class Machine<mDT> {
|
|
|
1569
2255
|
*
|
|
1570
2256
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
1571
2257
|
*
|
|
2258
|
+
* @param state The state to compute the composite style for.
|
|
2259
|
+
*
|
|
2260
|
+
* @returns The fully composited {@link JssmStateConfig} for the given state.
|
|
2261
|
+
*
|
|
1572
2262
|
*/
|
|
1573
2263
|
style_for(state: StateType): JssmStateConfig;
|
|
1574
2264
|
/********
|
|
@@ -1601,6 +2291,9 @@ declare class Machine<mDT> {
|
|
|
1601
2291
|
*
|
|
1602
2292
|
* @param newData The data change to insert during the action
|
|
1603
2293
|
*
|
|
2294
|
+
* @returns `true` if the action was valid and the transition occurred,
|
|
2295
|
+
* `false` otherwise.
|
|
2296
|
+
*
|
|
1604
2297
|
*/
|
|
1605
2298
|
do(actionName: StateType, newData?: mDT): boolean;
|
|
1606
2299
|
/********
|
|
@@ -1631,6 +2324,8 @@ declare class Machine<mDT> {
|
|
|
1631
2324
|
*
|
|
1632
2325
|
* @param newData The data change to insert during the transition
|
|
1633
2326
|
*
|
|
2327
|
+
* @returns `true` if the transition was legal and occurred, `false` otherwise.
|
|
2328
|
+
*
|
|
1634
2329
|
*/
|
|
1635
2330
|
transition(newState: StateType, newData?: mDT): boolean;
|
|
1636
2331
|
/********
|
|
@@ -1651,6 +2346,8 @@ declare class Machine<mDT> {
|
|
|
1651
2346
|
*
|
|
1652
2347
|
* @param newData The data change to insert during the transition
|
|
1653
2348
|
*
|
|
2349
|
+
* @returns `true` if the transition was legal and occurred, `false` otherwise.
|
|
2350
|
+
*
|
|
1654
2351
|
*/
|
|
1655
2352
|
go(newState: StateType, newData?: mDT): boolean;
|
|
1656
2353
|
/********
|
|
@@ -1674,21 +2371,84 @@ declare class Machine<mDT> {
|
|
|
1674
2371
|
*
|
|
1675
2372
|
* @param newData The data change to insert during the transition
|
|
1676
2373
|
*
|
|
2374
|
+
* @returns `true` if a transition (forced or otherwise) existed and occurred,
|
|
2375
|
+
* `false` otherwise.
|
|
2376
|
+
*
|
|
1677
2377
|
*/
|
|
1678
2378
|
force_transition(newState: StateType, newData?: mDT): boolean;
|
|
2379
|
+
/** Get the edge index for an action from the current state.
|
|
2380
|
+
* @param action - The action name.
|
|
2381
|
+
* @returns The edge index, or `undefined` if the action is not available.
|
|
2382
|
+
*/
|
|
1679
2383
|
current_action_for(action: StateType): number;
|
|
2384
|
+
/** Get the full transition object for an action from the current state.
|
|
2385
|
+
* @param action - The action name.
|
|
2386
|
+
* @returns The {@link JssmTransition} object.
|
|
2387
|
+
* @throws {JssmError} If the action is not available from the current state.
|
|
2388
|
+
*/
|
|
1680
2389
|
current_action_edge_for(action: StateType): JssmTransition<StateType, mDT>;
|
|
2390
|
+
/** Check whether an action is available from the current state.
|
|
2391
|
+
* @param action - The action name to check.
|
|
2392
|
+
* @param _newData - Reserved for future data validation.
|
|
2393
|
+
* @returns `true` if the action can be taken.
|
|
2394
|
+
*/
|
|
1681
2395
|
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
2396
|
+
/** Check whether a transition to a given state is legal (non-forced) from
|
|
2397
|
+
* the current state.
|
|
2398
|
+
* @param newState - The target state.
|
|
2399
|
+
* @param _newData - Reserved for future data validation.
|
|
2400
|
+
* @returns `true` if the transition is legal.
|
|
2401
|
+
*/
|
|
1682
2402
|
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
2403
|
+
/** Check whether a forced transition to a given state exists from the
|
|
2404
|
+
* current state.
|
|
2405
|
+
* @param newState - The target state.
|
|
2406
|
+
* @param _newData - Reserved for future data validation.
|
|
2407
|
+
* @returns `true` if a forced (or any) transition exists.
|
|
2408
|
+
*/
|
|
1683
2409
|
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
2410
|
+
/** Get the instance name of this machine, if one was assigned at creation.
|
|
2411
|
+
* @returns The instance name string, or `undefined`.
|
|
2412
|
+
*/
|
|
1684
2413
|
instance_name(): string | undefined;
|
|
2414
|
+
/** Get the creation date of this machine as a `Date` object.
|
|
2415
|
+
* @returns A `Date` representing when the machine was created.
|
|
2416
|
+
*/
|
|
1685
2417
|
get creation_date(): Date;
|
|
2418
|
+
/** Get the creation timestamp (milliseconds since epoch).
|
|
2419
|
+
* @returns The timestamp as a number.
|
|
2420
|
+
*/
|
|
1686
2421
|
get creation_timestamp(): number;
|
|
2422
|
+
/** Get the timestamp when construction began (before parsing).
|
|
2423
|
+
* @returns The start-of-construction timestamp as a number.
|
|
2424
|
+
*/
|
|
1687
2425
|
get create_start_time(): number;
|
|
2426
|
+
/** Schedule an automatic transition to `next_state` after `after_time`
|
|
2427
|
+
* milliseconds. Only one timeout may be active at a time.
|
|
2428
|
+
* @param next_state - The state to transition to when the timer fires.
|
|
2429
|
+
* @param after_time - Delay in milliseconds.
|
|
2430
|
+
* @throws {JssmError} If a timeout is already pending.
|
|
2431
|
+
*/
|
|
1688
2432
|
set_state_timeout(next_state: StateType, after_time: number): void;
|
|
2433
|
+
/** Cancel any pending state timeout. Safe to call when no timeout is active.
|
|
2434
|
+
*/
|
|
1689
2435
|
clear_state_timeout(): void;
|
|
2436
|
+
/** Get the configured `after` timeout for a given state, if any.
|
|
2437
|
+
* @param which_state - The state to look up.
|
|
2438
|
+
* @returns A `[targetState, delayMs]` tuple, or `undefined` if no timeout
|
|
2439
|
+
* is configured for that state.
|
|
2440
|
+
*/
|
|
1690
2441
|
state_timeout_for(which_state: StateType): [StateType, number] | undefined;
|
|
2442
|
+
/** Get the configured `after` timeout for the current state, if any.
|
|
2443
|
+
* @returns A `[targetState, delayMs]` tuple, or `undefined`.
|
|
2444
|
+
*/
|
|
1691
2445
|
current_state_timeout(): [StateType, number] | undefined;
|
|
2446
|
+
/** Convenience method to create a new machine from a tagged template literal.
|
|
2447
|
+
* Equivalent to calling the top-level `sm` function.
|
|
2448
|
+
* @param template_strings - The template string array.
|
|
2449
|
+
* @param remainder - Interpolated values.
|
|
2450
|
+
* @returns A new {@link Machine} instance.
|
|
2451
|
+
*/
|
|
1692
2452
|
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
1693
2453
|
}
|
|
1694
2454
|
/*********
|
|
@@ -1738,9 +2498,158 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
|
|
|
1738
2498
|
*
|
|
1739
2499
|
*/
|
|
1740
2500
|
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<StateType, mDT>> | undefined): Machine<mDT>;
|
|
2501
|
+
/**
|
|
2502
|
+
*
|
|
2503
|
+
* Type guard that narrows an unknown value to a {@link HookComplexResult}.
|
|
2504
|
+
*
|
|
2505
|
+
* A hook complex result is an object with at minimum a boolean `pass` field,
|
|
2506
|
+
* and may optionally also carry replacement `data` / `next_data` fields that
|
|
2507
|
+
* the machine should adopt if the hook passes. This helper is used by the
|
|
2508
|
+
* hook-dispatch machinery to tell "hook returned a complex object" from
|
|
2509
|
+
* "hook returned a bare boolean / null / undefined".
|
|
2510
|
+
*
|
|
2511
|
+
* ```typescript
|
|
2512
|
+
* is_hook_complex_result({ pass: true }); // true
|
|
2513
|
+
* is_hook_complex_result({ pass: false, data: { x: 1 }}); // true
|
|
2514
|
+
* is_hook_complex_result(true); // false
|
|
2515
|
+
* is_hook_complex_result(null); // false
|
|
2516
|
+
* is_hook_complex_result({ other: 'thing' }); // false
|
|
2517
|
+
* ```
|
|
2518
|
+
*
|
|
2519
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
2520
|
+
*
|
|
2521
|
+
* @param hr The value to test.
|
|
2522
|
+
*
|
|
2523
|
+
* @returns `true` if `hr` is a non-null object with a boolean `pass` field;
|
|
2524
|
+
* `false` otherwise. When `true`, TypeScript narrows `hr` to
|
|
2525
|
+
* `HookComplexResult<mDT>`.
|
|
2526
|
+
*
|
|
2527
|
+
*/
|
|
1741
2528
|
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
|
|
2529
|
+
/**
|
|
2530
|
+
*
|
|
2531
|
+
* Normalize any legal hook return value to a single "did it reject?" boolean.
|
|
2532
|
+
*
|
|
2533
|
+
* Hooks in jssm may return any of the following to indicate success:
|
|
2534
|
+
* `true`, `undefined`, or a complex result whose `pass` field is `true`.
|
|
2535
|
+
* They may return any of the following to indicate rejection:
|
|
2536
|
+
* `false`, or a complex result whose `pass` field is `false`. This helper
|
|
2537
|
+
* collapses all of those shapes into one boolean so callers don't have to
|
|
2538
|
+
* re-implement the matrix.
|
|
2539
|
+
*
|
|
2540
|
+
* ```typescript
|
|
2541
|
+
* is_hook_rejection(true); // false (pass)
|
|
2542
|
+
* is_hook_rejection(undefined); // false (pass)
|
|
2543
|
+
* is_hook_rejection(false); // true (reject)
|
|
2544
|
+
* is_hook_rejection({ pass: true }); // false (pass)
|
|
2545
|
+
* is_hook_rejection({ pass: false }); // true (reject)
|
|
2546
|
+
* ```
|
|
2547
|
+
*
|
|
2548
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
2549
|
+
*
|
|
2550
|
+
* @param hr A hook result of any legal shape.
|
|
2551
|
+
*
|
|
2552
|
+
* @returns `true` if the hook rejected the transition; `false` if it passed.
|
|
2553
|
+
*
|
|
2554
|
+
* @throws {TypeError} If `hr` is not a recognized hook result shape (for
|
|
2555
|
+
* example, a number or a plain object without a `pass` field).
|
|
2556
|
+
*
|
|
2557
|
+
*/
|
|
1742
2558
|
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
2559
|
+
/**
|
|
2560
|
+
*
|
|
2561
|
+
* Invoke an optional transition/action hook and normalize its return value
|
|
2562
|
+
* into a {@link HookComplexResult}.
|
|
2563
|
+
*
|
|
2564
|
+
* This is the central adapter the transition pipeline uses to run every
|
|
2565
|
+
* non-"everything" hook kind (basic, named, entry, exit, after, action, etc).
|
|
2566
|
+
* It accepts `undefined` for the hook slot because most hooks are not set on
|
|
2567
|
+
* most machines; when no hook is installed the step is a no-op pass.
|
|
2568
|
+
*
|
|
2569
|
+
* The valid return shapes from a hook and their normalized meanings are:
|
|
2570
|
+
* - `undefined` → `{ pass: true }`
|
|
2571
|
+
* - `true` → `{ pass: true }`
|
|
2572
|
+
* - `false` → `{ pass: false }`
|
|
2573
|
+
* - `null` → `{ pass: false }`
|
|
2574
|
+
* - a complex result object → returned as-is
|
|
2575
|
+
*
|
|
2576
|
+
* Anything else is a programmer error and throws.
|
|
2577
|
+
*
|
|
2578
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
2579
|
+
*
|
|
2580
|
+
* @param maybe_hook The hook handler to call, or `undefined` for the
|
|
2581
|
+
* "no hook installed" case.
|
|
2582
|
+
*
|
|
2583
|
+
* @param hook_args The context object passed to the hook. Includes the
|
|
2584
|
+
* current and proposed state, current and proposed data, action name, and
|
|
2585
|
+
* transition kind.
|
|
2586
|
+
*
|
|
2587
|
+
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
2588
|
+
* and, optionally, any data replacements it requested.
|
|
2589
|
+
*
|
|
2590
|
+
* @throws {TypeError} If the hook returns a value that is not one of the
|
|
2591
|
+
* legal shapes listed above.
|
|
2592
|
+
*
|
|
2593
|
+
* @internal
|
|
2594
|
+
*
|
|
2595
|
+
*/
|
|
1743
2596
|
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
|
|
2597
|
+
/**
|
|
2598
|
+
*
|
|
2599
|
+
* Invoke an optional "everything" hook and normalize its return value into
|
|
2600
|
+
* a {@link HookComplexResult}.
|
|
2601
|
+
*
|
|
2602
|
+
* Mechanically identical to {@link abstract_hook_step}, but typed for the
|
|
2603
|
+
* everything-hook family (`pre_everything_hook` and `everything_hook`),
|
|
2604
|
+
* whose context object carries an extra `hook_name` field identifying which
|
|
2605
|
+
* bracket of the pipeline is firing. Separated from `abstract_hook_step`
|
|
2606
|
+
* so TypeScript can enforce that the hook handler and the context object
|
|
2607
|
+
* agree on shape.
|
|
2608
|
+
*
|
|
2609
|
+
* The valid return shapes and their meanings are the same as for
|
|
2610
|
+
* `abstract_hook_step`:
|
|
2611
|
+
* - `undefined` or `true` → `{ pass: true }`
|
|
2612
|
+
* - `false` or `null` → `{ pass: false }`
|
|
2613
|
+
* - a complex result → returned as-is
|
|
2614
|
+
*
|
|
2615
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
2616
|
+
*
|
|
2617
|
+
* @param maybe_hook The everything-hook handler, or `undefined` when none
|
|
2618
|
+
* is installed.
|
|
2619
|
+
*
|
|
2620
|
+
* @param hook_args The everything-hook context object. Differs from a
|
|
2621
|
+
* normal hook context in that it also includes `hook_name`.
|
|
2622
|
+
*
|
|
2623
|
+
* @returns A {@link HookComplexResult} describing whether the hook passed
|
|
2624
|
+
* and any data replacements it requested.
|
|
2625
|
+
*
|
|
2626
|
+
* @throws {TypeError} If the hook returns a value outside the legal shapes.
|
|
2627
|
+
*
|
|
2628
|
+
* @internal
|
|
2629
|
+
*
|
|
2630
|
+
*/
|
|
2631
|
+
declare function abstract_everything_hook_step<mDT>(maybe_hook: EverythingHookHandler<mDT> | undefined, hook_args: EverythingHookContext<mDT>): HookComplexResult<mDT>;
|
|
2632
|
+
/**
|
|
2633
|
+
* Deserializes a previously serialized machine state.
|
|
2634
|
+
*
|
|
2635
|
+
* This function recreates a machine from a serialization object, restoring its
|
|
2636
|
+
* state, data, and history. For security and compatibility reasons, it will
|
|
2637
|
+
* refuse to deserialize data from future versions of the library.
|
|
2638
|
+
*
|
|
2639
|
+
* @typeparam mDT - The type of the machine data member
|
|
2640
|
+
*
|
|
2641
|
+
* @param {string} machine_string - The FSL string defining the machine structure
|
|
2642
|
+
* @param {JssmSerialization<mDT>} ser - The serialization object to restore from
|
|
2643
|
+
*
|
|
2644
|
+
* @returns {Machine<mDT>} - The restored machine instance
|
|
2645
|
+
*
|
|
2646
|
+
* @throws {Error} If the serialization is from a future version
|
|
2647
|
+
*
|
|
2648
|
+
* @example
|
|
2649
|
+
* const machine = jssm.from("a -> b;");
|
|
2650
|
+
* const serialized = machine.serialize();
|
|
2651
|
+
* const restored = jssm.deserialize("a -> b;", serialized);
|
|
2652
|
+
*/
|
|
1744
2653
|
declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
|
|
1745
2654
|
|
|
1746
|
-
export { FslDirections, Machine, abstract_hook_step, arrow_direction, arrow_left_kind, arrow_right_kind, build_time, compile, jssm_constants_d as constants, deserialize, find_repeated, from, gviz_shapes, histograph, is_hook_complex_result, is_hook_rejection, make, named_colors, wrap_parse as parse, seq, shapes, sleep, sm, state_style_condense, transfer_state_properties, unique, version, weighted_histo_key, weighted_rand_select, weighted_sample_select };
|
|
2655
|
+
export { FslDirections, Machine, abstract_everything_hook_step, abstract_hook_step, arrow_direction, arrow_left_kind, arrow_right_kind, build_time, compile, jssm_constants_d as constants, deserialize, find_repeated, from, gen_splitmix32, gviz_shapes, histograph, is_hook_complex_result, is_hook_rejection, make, named_colors, wrap_parse as parse, seq, shapes, sleep, sm, state_style_condense, transfer_state_properties, unique, version, weighted_histo_key, weighted_rand_select, weighted_sample_select };
|