-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathjssm_viz.es5.d.cts
More file actions
4616 lines (4608 loc) · 188 KB
/
Copy pathjssm_viz.es5.d.cts
File metadata and controls
4616 lines (4608 loc) · 188 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { circular_buffer } from 'circular_buffer_js';
type StateType$1 = string;
/**
* A color value accepted by jssm-viz for state and arrow styling. Currently
* any string, validated downstream by Graphviz / the named-colors list.
* Intended to be narrowed to `#RRGGBB` / `#RRGGBBAA` and CSS named colors
* in a future release.
*/
type JssmColor = string;
/**
* Three-state policy flag: `'required'`, `'disallowed'`, or `'optional'`.
* Used by machine configuration where a default-permissive middle ground
* is meaningful (for example, the `actions` config key).
*/
type JssmPermittedOpt = 'required' | 'disallowed' | 'optional';
/**
* A type teaching Typescript the various supported shapes for nodes, mostly inherited from GraphViz
*/
type JssmShape = "box" | "polygon" | "ellipse" | "oval" | "circle" | "point" | "egg" | "triangle" | "plaintext" | "plain" | "diamond" | "trapezium" | "parallelogram" | "house" | "pentagon" | "hexagon" | "septagon" | "octagon" | "doublecircle" | "doubleoctagon" | "tripleoctagon" | "invtriangle" | "invtrapezium" | "invhouse" | "Mdiamond" | "Msquare" | "Mcircle" | "rect" | "rectangle" | "square" | "star" | "none" | "underline" | "cylinder" | "note" | "tab" | "folder" | "box3d" | "component" | "promoter" | "cds" | "terminator" | "utr" | "primersite" | "restrictionsite" | "fivepoverhang" | "threepoverhang" | "noverhang" | "assembly" | "signature" | "insulator" | "ribosite" | "rnastab" | "proteasesite" | "proteinstab" | "rpromoter" | "rarrow" | "larrow" | "lpromoter" | "record";
/**
* Semantic category of an arrow's transition. `'legal'` is a normal
* transition, `'main'` is part of the machine's primary path, `'forced'`
* may only be taken via {@link jssm!Machine.force_transition}, and `'none'`
* means no transition exists in that direction.
*/
type JssmArrowKind = 'none' | 'legal' | 'main' | 'forced';
/**
* Graphviz layout engine selector. Controls how jssm-viz lays out the
* rendered diagram; `'dot'` is the default and most useful for state
* machines. See the Graphviz documentation for the differences.
*/
type JssmLayout = 'dot' | 'circo' | 'twopi' | 'fdp' | 'neato';
type JssmCorner = 'regular' | 'rounded' | 'lined';
type JssmLineStyle = 'solid' | 'dashed' | 'dotted';
/**
* Tristate flag for whether a property may be overridden at runtime.
* `true` permits overrides, `false` forbids them, and `undefined` defers
* the decision to the surrounding configuration's default.
*/
type JssmAllowsOverride = true | false | undefined;
/**
* Controls whether the state graph may contain disconnected components
* (islands). `true` permits islands (default), `false` requires a single
* connected component, and `'with_start'` permits islands only when every
* component contains at least one start state.
*/
type JssmAllowIslands = true | false | 'with_start';
/**
* Structured render-size hint for a machine visualization, set by the FSL
* `default_size` directive. All three forms are optional in the sense that
* only one or two fields will be present depending on the form used:
*
* - `{ width }` — single-number form (`default_size: 800;`)
* - `{ width, height }` — bounding-box form (`default_size: 800 600;`)
* - `{ height }` — height-only form (`default_size: height 600;`)
*
* This is a *hint*, not a hard constraint. Renderers may ignore it.
* @see Machine.default_size
*/
type JssmDefaultSize = {
width?: number;
height?: number;
};
/**
* A parsed semantic-version breakdown, as produced by the FSL parser for
* version-valued directives (`machine_version`, `fsl_version`). `major`,
* `minor`, and `patch` are the three numeric components; `full` preserves
* the exact source text of the version. `loc` is present only when the
* source was parsed with `{ locations: true }`.
*
* ```typescript
* const m = sm`machine_version: 1.2.3; a -> b;`;
* m.machine_version(); // { major: 1, minor: 2, patch: 3, full: '1.2.3' }
* ```
* @see Machine.machine_version
* @see Machine.fsl_version
*/
type JssmParsedSemver = {
major: number;
minor: number;
patch: number;
full: string;
loc?: FslSourceLocation;
};
/**
* Runtime-iterable list of valid `flow` directions for FSL diagrams.
* Use this when you need to enumerate directions; for the type itself
* see {@link FslDirection}.
*/
declare const FslDirections: readonly ["up", "right", "down", "left"];
/**
* String literal type of the four supported FSL flow directions. This is
* the type of the `flow` config key on a machine.
*/
type FslDirection = typeof FslDirections[number];
/**
* Runtime-iterable list of the built-in theme names that ship with jssm-viz.
* Use this when you need to enumerate themes; for the type itself see
* {@link FslTheme}.
*/
declare const FslThemes: readonly ["default", "ocean", "modern", "plain", "bold"];
/**
* String literal type of the built-in theme names. This is the element
* type of the `theme` config key (which accepts an array so that themes
* can be layered).
*/
type FslTheme = typeof FslThemes[number];
/**
* Persistable snapshot of a Machine produced by {@link jssm!Machine.serialize}
* and consumed by {@link jssm!deserialize}. Carries the current state, the
* associated machine data, the recent history (subject to the configured
* capacity), and metadata to detect version-skew on rehydration.
* @template DataType - The type of the user-supplied data payload (`mDT`).
*/
type JssmSerialization<DataType> = {
jssm_version: string;
timestamp: number;
comment?: string | undefined;
state: StateType$1;
history: [string, DataType][];
history_capacity: number;
data: DataType;
};
/**
* One ordered member of a named group's membership list. A `'state'`
* member is an ordinary state (`a` inside `&g : [a]`). A `'group'` member
* references another group: `mode: 'nest'` is the `&child` form, which
* preserves the child group's identity for later precedence/viz, while
* `mode: 'spread'` is the `...&child` form, which inlines the child's
* members and erases that identity. Both modes resolve to the same flat
* set of states via {@link JssmGroupRegistry} resolution; only their
* structural bookkeeping differs.
*
* ```typescript
* // `&outer : [&inner x];` direct members:
* // [ { kind: 'group', name: 'inner', mode: 'nest' },
* // { kind: 'state', name: 'x' } ]
* ```
* @see JssmGroupRef
* @see JssmGroupRegistry
*/
type JssmGroupMemberRef = {
kind: 'state';
name: string;
} | {
kind: 'group';
name: string;
mode: 'nest' | 'spread';
};
/**
* The compiled group table: maps each declared group name to its
* **ordered, direct** members (a {@link JssmGroupMemberRef} list). Order
* is meaningful — it carries declaration/iteration/precedence order — so
* this is always an array-valued `Map`, never a `Set`. Only direct
* members are stored; transitive (flattened) membership is resolved
* lazily so the group→group graph survives for viz and precedence.
*
* ```typescript
* // for `&inner : [a b]; &outer : [&inner c];`
* // registry.get('inner') === [ { kind:'state', name:'a' },
* // { kind:'state', name:'b' } ]
* // registry.get('outer') === [ { kind:'group', name:'inner', mode:'nest' },
* // { kind:'state', name:'c' } ]
* ```
* @see JssmGroupMemberRef
*/
type JssmGroupRegistry = Map<string, JssmGroupMemberRef[]>;
/**
* The compiled boundary-hook surface for a single subject (a group or a
* state): the action to run on entry (`onEnter`) and/or on exit (`onExit`).
* Each is optional so a subject may declare only one direction; the compiler
* merges an `enter` and an `exit` declaration for the same subject into one
* of these.
* @see JssmHookDeclaration
*/
type JssmBoundaryHooks = {
onEnter?: string;
onExit?: string;
};
/**
* Maps each group name that has at least one boundary hook to its merged
* {@link JssmBoundaryHooks}. Carried on {@link JssmGenericConfig} for the
* runtime to consume; depth-aware firing is a later task.
* @see JssmHookDeclaration
*/
type JssmGroupHooks = Map<string, JssmBoundaryHooks>;
/**
* Maps each plain state name that has at least one boundary hook to its
* merged {@link JssmBoundaryHooks}. The state-subject analogue of
* {@link JssmGroupHooks}.
* @see JssmHookDeclaration
*/
type JssmStateHooks = Map<string, JssmBoundaryHooks>;
/**
* Declaration of a named property that a machine's states may carry.
* Set `required: true` to force every state to define the property, or
* provide `default_value` to fall back when the state does not specify it.
*
* For state-property *bindings* (the `state_property` config list), the
* compiler also writes `property` and `state` — the unserialized pair behind
* the serialized `name` — so the Machine constructor can validate bindings
* without parsing `name` back apart. Both are optional: hand-built configs
* may carry only the serialized `name`, and global property definitions
* never set them.
*/
type JssmPropertyDefinition = {
name: string;
default_value?: any;
required?: boolean;
property?: string;
state?: string;
};
type JssmTransitionPermitter<DataType> = (OldState: StateType$1, NewState: StateType$1, OldData: DataType, NewData: DataType) => boolean;
type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
/**
* A single directed transition (edge) within a state machine. Captures
* both the topology (`from` / `to`), the FSL semantics (`kind`,
* `forced_only`, `main_path`), and any optional metadata such as a
* per-edge `name`, an action label, a guard `check`, a transition
* `probability` for stochastic models, and an `after_time` for timed
* transitions.
* @template StateType - The state-name type (usually `string`).
* @template DataType - The machine's data payload type (`mDT`).
*/
type JssmTransition<StateType, DataType> = {
from: StateType;
to: StateType;
after_time?: number;
se?: JssmCompileSe<StateType, DataType>;
name?: StateType;
action?: StateType;
check?: JssmTransitionPermitterMaybeArray<DataType>;
probability?: number;
kind: JssmArrowKind;
forced_only: boolean;
main_path: boolean;
};
/** A list of {@link JssmTransition}s — the edge set of a machine. */
type JssmTransitions<StateType, DataType> = JssmTransition<StateType, DataType>[];
/**
* The set of states that can immediately precede or follow a given state.
* Returned by jssm helpers that report a state's connectivity in the graph.
*/
type JssmTransitionList = {
entrances: Array<StateType$1>;
exits: Array<StateType$1>;
};
/**
* Topology record for one node in a compiled machine: its name, the set of
* states it can be reached from, the set of states it can transition to,
* and whether reaching it constitutes "completing" the machine.
*/
type JssmGenericState = {
from: Array<StateType$1>;
name: StateType$1;
to: Array<StateType$1>;
complete: boolean;
};
/**
* The full internal bookkeeping snapshot of a {@link jssm!Machine}, exposed for
* advanced introspection. Contains the current state, the state map, the
* edge map and reverse-action map, and the original edge list. The
* `internal_state_impl_version` field exists so that consumers can detect
* shape changes if this representation evolves.
*/
type JssmMachineInternalState<DataType> = {
internal_state_impl_version: 1;
state: StateType$1;
states: Map<StateType$1, JssmGenericState>;
named_transitions: Map<StateType$1, number>;
edge_map: Map<StateType$1, Map<StateType$1, number>>;
actions: Map<StateType$1, Map<StateType$1, number>>;
reverse_actions: Map<StateType$1, Map<StateType$1, number>>;
edges: Array<JssmTransition<StateType$1, DataType>>;
};
type JssmStatePermitter<DataType> = (OldState: StateType$1, NewState: StateType$1, OldData: DataType, NewData: DataType) => boolean;
type JssmStatePermitterMaybeArray<DataType> = JssmStatePermitter<DataType> | Array<JssmStatePermitter<DataType>>;
/**
* A source span produced by the FSL parser when `parse(input, { locations:
* true })` is used. Mirrors PEG.js's native `location()` shape: byte
* `offset`s (0-based, half-open) plus 1-based `line`/`column` for display.
*
* ```typescript
* const [t] = parse('a -> b;', { locations: true });
* // t.loc === { start: { offset: 0, line: 1, column: 1 },
* // end: { offset: 7, line: 1, column: 8 } }
* ```
*/
type FslSourcePoint = {
offset: number;
line: number;
column: number;
};
type FslSourceLocation = {
start: FslSourcePoint;
end: FslSourcePoint;
};
/**
* A single key/value pair from an FSL `state X: { ... };` block, in the
* raw form produced by the parser before being condensed into a
* {@link JssmStateDeclaration}.
*/
type JssmStateDeclarationRule = {
key: string;
value: any;
name?: string;
loc?: FslSourceLocation;
value_loc?: FslSourceLocation;
};
/**
* The fully-condensed declaration for a single state, including its raw
* rule list (`declarations`) and the well-known styling fields jssm-viz
* understands. Returned by {@link jssm!Machine.state_declaration}.
*/
type JssmStateDeclaration = {
declarations: Array<JssmStateDeclarationRule>;
shape?: JssmShape;
color?: JssmColor;
corners?: JssmCorner;
lineStyle?: JssmLineStyle;
stateLabel?: string;
textColor?: JssmColor;
backgroundColor?: JssmColor;
borderColor?: JssmColor;
image?: string;
url?: string;
state: StateType$1;
property?: {
name: string;
value: unknown;
};
};
/**
* A loosened version of {@link JssmStateDeclaration} where every field is
* optional. Used as the value type for theme entries and for default
* state configuration where most fields will be inherited or merged.
*/
type JssmStateConfig = Partial<JssmStateDeclaration>;
type JssmStateStyleShape = {
key: 'shape';
value: JssmShape;
};
type JssmStateStyleColor = {
key: 'color';
value: JssmColor;
};
type JssmStateStyleTextColor = {
key: 'text-color';
value: JssmColor;
};
type JssmStateStyleCorners = {
key: 'corners';
value: JssmCorner;
};
type JssmStateStyleLineStyle = {
key: 'line-style';
value: JssmLineStyle;
};
type JssmStateStyleStateLabel = {
key: 'state-label';
value: string;
};
type JssmStateStyleBackgroundColor = {
key: 'background-color';
value: JssmColor;
};
type JssmStateStyleBorderColor = {
key: 'border-color';
value: JssmColor;
};
type JssmStateStyleImage = {
key: 'image';
value: string;
};
type JssmStateStyleUrl = {
key: 'url';
value: string;
};
/**
* Tagged union of all individual style key/value pairs that may appear in
* a state's style configuration. The `key` discriminator selects which
* member, and the `value` is typed accordingly.
*/
type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor | JssmStateStyleImage | JssmStateStyleUrl;
/**
* An ordered list of {@link JssmStateStyleKey} entries. Used by the
* `default_*_state_config` machine config options to provide a fallback
* style stack.
*/
type JssmStateStyleKeyList = JssmStateStyleKey[];
/**
* The graph-wide default edge colour style item, produced by the
* `edge-color`/`edge_color` line inside a `transition: {}` (or `graph: {}`)
* config block. Kept distinct from {@link JssmStateStyleColor} because it
* applies to edges rather than nodes, and because it carries the legacy
* `graph_default_edge_color` key the grammar emits.
*/
type JssmGraphDefaultEdgeColor = {
key: 'graph_default_edge_color';
value: JssmColor;
};
/**
* A single item inside a `transition: {}` default-config block. For v1 this
* reuses the per-state style items (so `color: red;` works inside a
* `transition:` block exactly as inside a `state:` block) plus the
* edge-scoped {@link JssmGraphDefaultEdgeColor} default.
* @see JssmTransitionConfig
*/
type JssmTransitionStyleKey = JssmStateStyleKey | JssmGraphDefaultEdgeColor;
/**
* The compiled value of a `transition: {}` config block: an ordered list of
* edge-default style items. V1 mirrors the state-style shape used by
* `default_state_config`; group machinery that consumes it lands in a later
* task.
*
* ```typescript
* import { compile, parse } from 'jssm';
* const cfg = compile(parse('a -> b; transition: { color: red; };'));
* // cfg.default_transition_config === [ { key: 'color', value: '#ff0000ff' } ]
* ```
* @see JssmGraphConfig
*/
type JssmTransitionConfig = JssmTransitionStyleKey[];
/**
* Graph-scope default-config style items folded from the deprecated
* top-level graph keywords (`graph_layout`, `graph_bg_color`,
* `dot_preamble`, `theme`, `flow`, and the `edge-color`/`edge_color`
* default) into the consolidated `graph: {}` config. Each carries the
* legacy parse key so downstream consumers can disambiguate.
*/
type JssmGraphAliasKey = JssmGraphDefaultEdgeColor | {
key: 'graph_layout';
value: JssmLayout;
} | {
key: 'graph_bg_color';
value: JssmColor;
} | {
key: 'dot_preamble';
value: string;
} | {
key: 'theme';
value: FslTheme | FslTheme[];
} | {
key: 'flow';
value: FslDirection;
};
/**
* A single item inside a `graph: {}` default-config block. For v1 this
* reuses the per-state style items plus the graph-scope alias items
* ({@link JssmGraphAliasKey}) folded in from the deprecated top-level
* graph keywords.
* @see JssmGraphConfig
*/
type JssmGraphStyleKey = JssmStateStyleKey | JssmGraphAliasKey;
/**
* The compiled value of a `graph: {}` config block: an ordered list of
* graph-default style items. The compiler folds the deprecated top-level
* graph keywords into this list first, then lets an explicit `graph: {}`
* block override on key conflict.
*
* ```typescript
* import { compile, parse } from 'jssm';
* const cfg = compile(parse('a -> b; graph_bg_color: #ffffff;'));
* // the compiler canonicalizes the folded `graph_bg_color` alias to a
* // `background-color` item, so:
* // cfg.default_graph_config includes { key: 'background-color', value: '#ffffffff' }
* ```
* @see JssmTransitionConfig
*/
type JssmGraphConfig = JssmGraphStyleKey[];
/**
* Full configuration object accepted by the {@link jssm!Machine} constructor and
* by {@link from}. Carries the transition list and the optional knobs
* governing layout, theming, history, start/end states, property
* definitions, machine metadata (author, license, version, ...) and the
* runtime hook surfaces (`time_source`, `timeout_source`, ...).
*
* Most users never construct one of these directly — the `sm` tagged
* template literal and {@link from} produce one from FSL source.
* @template StateType - The state-name type (usually `string`).
* @template DataType - The user-supplied data payload type (`mDT`).
*/
/**
* Editor/panel defaults an FSL machine declares in an `editor: {}` block
* (fsl#1334), read by the all-widgets web control: a stochastic run-count
* and the panels the machine requests under `request` panel mode.
*/
type JssmEditorConfig = {
stochastic_run_count?: number;
panels?: Array<string>;
};
/** Which stochastic view a run batch produces. */
type JssmStochasticMode = 'montecarlo' | 'steady_state';
/** Options for {@link jssm!Machine.stochastic_summary} / {@link jssm!Machine.stochastic_runs}. */
type JssmStochasticOptions = {
mode?: JssmStochasticMode;
runs?: number;
max_steps?: number;
seed?: number;
};
/** One walk's result, yielded by {@link jssm!Machine.stochastic_runs}. */
type JssmStochasticRun = {
states: Array<string>;
edges: Array<string>;
length: number;
terminated: boolean;
};
/** Aggregate statistics over a stochastic run batch. */
type JssmStochasticSummary = {
mode: JssmStochasticMode;
runs: number;
seed: number;
state_visits: Map<string, number>;
state_visit_fraction: Map<string, number>;
edge_traversals: Map<string, number>;
path_lengths?: Array<number>;
terminal_reached?: number;
capped?: number;
};
type JssmGenericConfig<StateType, DataType> = {
graph_layout?: JssmLayout;
complete?: Array<StateType>;
transitions: JssmTransitions<StateType, DataType>;
theme?: FslTheme[];
flow?: FslDirection;
name?: string;
data?: DataType;
nodes?: Array<StateType>;
check?: JssmStatePermitterMaybeArray<DataType>;
history?: number;
/**
* Maximum depth of the boundary-hook action cascade before the machine
* throws a {@link jssm_error!JssmError} rather than risking a stack overflow or hang.
*
* Each time a boundary action fires a transition that itself crosses a
* boundary, the depth counter increments. A cascade exceeding this limit is
* treated as a probable infinite loop and rejected.
*
* Defaults to `100`. Raise it for legitimate pipelines that genuinely nest
* more than 100 transitions via boundary hooks.
* @see Machine._boundary_depth_limit
* @see Machine._fire_boundary_actions
*/
boundary_depth_limit?: number;
min_exits?: number;
max_exits?: number;
allow_islands?: JssmAllowIslands;
editor_config?: JssmEditorConfig;
allow_force?: false;
actions?: JssmPermittedOpt;
simplify_bidi?: boolean;
allows_override?: JssmAllowsOverride;
config_allows_override?: JssmAllowsOverride;
dot_preamble?: string;
start_states: Array<StateType>;
end_states?: Array<StateType>;
failed_outputs?: Array<StateType>;
initial_state?: StateType;
start_states_no_enforce?: boolean;
state_declaration?: object[];
property_definition?: JssmPropertyDefinition[];
state_property?: JssmPropertyDefinition[];
arrange_declaration?: Array<Array<StateType>>;
arrange_start_declaration?: Array<Array<StateType>>;
arrange_end_declaration?: Array<Array<StateType>>;
oarrange_declaration?: Array<Array<StateType>>;
farrange_declaration?: Array<Array<StateType>>;
machine_author?: string | Array<string>;
machine_comment?: string;
machine_contributor?: string | Array<string>;
machine_definition?: string;
machine_language?: string;
machine_license?: string;
machine_name?: string;
machine_version?: JssmParsedSemver;
npm_name?: string;
default_size?: JssmDefaultSize;
fsl_version?: JssmParsedSemver;
auto_api?: boolean | string;
instance_name?: string | undefined;
default_state_config?: JssmStateStyleKeyList;
default_start_state_config?: JssmStateStyleKeyList;
default_end_state_config?: JssmStateStyleKeyList;
default_hooked_state_config?: JssmStateStyleKeyList;
default_terminal_state_config?: JssmStateStyleKeyList;
default_active_state_config?: JssmStateStyleKeyList;
default_transition_config?: JssmTransitionConfig;
default_graph_config?: JssmGraphConfig;
/**
* Overlapping-state-group tables produced by the compile pass and consumed
* by the Task-3 runtime cascade.
*
* `group_registry` maps each group name to its ordered list of direct
* members (states and sub-group references) as declared in the FSL source.
*
* `group_metadata` maps each group name to its RAW style object
* `{ declarations: [...] }` — parsed style items from a
* `state &g : { … };` declaration, **not** condensed `JssmStateConfig`
* style fields. Condensation is intentionally deferred to the Task-3
* runtime cascade so that depth-specificity resolution can weight each
* group's contribution before merging into per-state config.
*
* `group_hooks` and `state_hooks` hold boundary-hook payloads keyed by
* group name and state name respectively; firing is also a Task-3 concern.
*
* All four fields are absent (`undefined`) on machines that declare no
* groups or hooks.
*/
group_registry?: JssmGroupRegistry;
group_metadata?: Map<string, JssmStateConfig>;
group_hooks?: JssmGroupHooks;
state_hooks?: JssmStateHooks;
rng_seed?: number | undefined;
time_source?: () => number;
/**
* Schedules `fn` to run after `delay_ms`, and returns a handle that will be
* handed back to `clear_timeout_source` untouched. Defaults to `setTimeout`.
*
* The handle is typed `number` — the browser shape. Node's `setTimeout`
* returns a `Timeout` object instead, so a Node-shaped source casts it (as
* jssm's own `DEFAULT_TIMEOUT_SOURCE` does); jssm never inspects the handle,
* it only stores it and gives it back.
*
* (Before 5.162.14 these read `(Function, number) => number`, in which
* `Function` and `number` were *parameter names*, not types — so both
* parameters were silently `any`.)
*/
timeout_source?: (fn: () => void, delay_ms: number) => number;
/** Cancels a timer previously scheduled by `timeout_source`. Defaults to `clearTimeout`. */
clear_timeout_source?: (handle: number) => void;
};
/**
* Internal compiler intermediate: one link in a chained transition
* expression (an "s-expression" segment). Carries both directions of an
* arrow with optional per-direction action labels, probabilities, and
* after-times. The recursive `se` field allows the parser to chain
* arrows of the form `A -> B -> C`. Not intended for end-user code.
* @internal
*/
type JssmCompileSe<StateType, mDT> = {
to: StateType;
se?: JssmCompileSe<StateType, mDT>;
/**
* The arrow token as the parser emitted it. Deliberately `string` and not
* {@link JssmArrow}: this internal intermediate flows through the whole
* compiler, and threading a 42-member string-literal union through that much
* control-flow analysis overflows `tsc`'s stack (it type-checks standalone
* but dies under `npm run make`). The value *is* a `JssmArrow` — the two
* places that care re-assert it on the way into the arrow classifiers.
*/
kind: string;
l_action?: StateType;
r_action?: StateType;
l_probability: number;
r_probability: number;
l_after?: number;
r_after?: number;
loc?: FslSourceLocation;
to_loc?: FslSourceLocation;
l_action_loc?: FslSourceLocation;
r_action_loc?: FslSourceLocation;
};
type BasicHookDescription<mDT> = {
kind: 'hook';
from: string;
to: string;
handler: HookHandler<mDT>;
};
type HookDescriptionWithAction<mDT> = {
kind: 'named';
from: string;
to: string;
action: string;
handler: HookHandler<mDT>;
};
type StandardTransitionHook<mDT> = {
kind: 'standard transition';
handler: HookHandler<mDT>;
};
type MainTransitionHook<mDT> = {
kind: 'main transition';
handler: HookHandler<mDT>;
};
type ForcedTransitionHook<mDT> = {
kind: 'forced transition';
handler: HookHandler<mDT>;
};
type AnyTransitionHook<mDT> = {
kind: 'any transition';
handler: HookHandler<mDT>;
};
type GlobalActionHook<mDT> = {
kind: 'global action';
action: string;
handler: HookHandler<mDT>;
};
type AnyActionHook<mDT> = {
kind: 'any action';
handler: HookHandler<mDT>;
};
type EntryHook<mDT> = {
kind: 'entry';
to: string;
handler: HookHandler<mDT>;
};
type ExitHook<mDT> = {
kind: 'exit';
from: string;
handler: HookHandler<mDT>;
};
type AfterHook<mDT> = {
kind: 'after';
from: string;
handler: HookHandler<mDT>;
};
type AfterAnyHook<mDT> = {
kind: 'after any';
handler: HookHandler<mDT>;
};
type PostBasicHookDescription<mDT> = {
kind: 'post hook';
from: string;
to: string;
handler: PostHookHandler<mDT>;
};
type PostHookDescriptionWithAction<mDT> = {
kind: 'post named';
from: string;
to: string;
action: string;
handler: PostHookHandler<mDT>;
};
type PostStandardTransitionHook<mDT> = {
kind: 'post standard transition';
handler: PostHookHandler<mDT>;
};
type PostMainTransitionHook<mDT> = {
kind: 'post main transition';
handler: PostHookHandler<mDT>;
};
type PostForcedTransitionHook<mDT> = {
kind: 'post forced transition';
handler: PostHookHandler<mDT>;
};
type PostAnyTransitionHook<mDT> = {
kind: 'post any transition';
handler: PostHookHandler<mDT>;
};
type PostGlobalActionHook<mDT> = {
kind: 'post global action';
action: string;
handler: PostHookHandler<mDT>;
};
type PostAnyActionHook<mDT> = {
kind: 'post any action';
handler: PostHookHandler<mDT>;
};
type PostEntryHook<mDT> = {
kind: 'post entry';
to: string;
handler: PostHookHandler<mDT>;
};
type PostExitHook<mDT> = {
kind: 'post exit';
from: string;
handler: PostHookHandler<mDT>;
};
type PreEverythingHook<mDT> = {
kind: 'pre everything';
handler: EverythingHookHandler<mDT>;
};
type EverythingHook<mDT> = {
kind: 'everything';
handler: EverythingHookHandler<mDT>;
};
type PrePostEverythingHook<mDT> = {
kind: 'pre post everything';
handler: PostEverythingHookHandler<mDT>;
};
type PostEverythingHook<mDT> = {
kind: 'post everything';
handler: PostEverythingHookHandler<mDT>;
};
/**
* Discriminated union of every kind of hook registration jssm understands,
* pre-transition and post-transition. The `kind` field selects the
* variant; remaining fields describe which transitions / states / actions
* the hook is bound to and supply the {@link HookHandler} or
* {@link PostHookHandler} to invoke.
*
* Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
* `'main transition'`, `'forced transition'`, `'any transition'`,
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`,
* `'after any'`) may return a falsy value to veto a transition. Post-transition
* variants (`'post *'`) cannot veto and are invoked only after a
* successful transition.
*/
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> | AfterAnyHook<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>;
/**
* Whether an observational hook runs in the pre-transition phase (where it
* may veto/mutate the transition) or the post-transition phase (a pure
* observer that runs only after a successful transition commits).
*/
type HookPhase = 'pre' | 'post';
/**
* Normalized description of the target a registry entry is bound to. Exactly
* one scope variant applies; the present fields depend on the scope:
*
* - `'edge'` carries `from` + `to` (+ optional `action` for named hooks),
* - `'state'` carries `state`,
* - `'action'` carries `action`,
* - `'global'` carries no further keys (it matches everything),
* - `'group'` carries `group` (a named state group with a boundary hook).
*/
type HookTarget = {
scope: 'edge';
from: StateType$1;
to: StateType$1;
action?: string;
} | {
scope: 'state';
state: StateType$1;
} | {
scope: 'action';
action: string;
} | {
scope: 'global';
} | {
scope: 'group';
group: string;
};
/**
* Kinds for FSL boundary hooks (`on enter/exit &group do 'X'` and the plain-
* state analogue). These fire post-commit when a transition crosses the
* subject's boundary and are not part of {@link HookDescription} (that union
* covers only the programmatically-registered observational hooks), so the
* registry widens its `kind` field with them.
*/
type HookBoundaryKind = 'group enter' | 'group exit' | 'state enter' | 'state exit';
/**
* One row of the generated uniform observational-hook registry. `kind` is
* either an original {@link HookDescription} discriminator (e.g. `'entry'`,
* `'post named'`) or a {@link HookBoundaryKind} for an FSL boundary hook,
* `phase` is the {@link HookPhase} the hook runs in, and `target` is the
* normalized {@link HookTarget} it is bound to. The triple
* `(kind, target, phase)` is the registry key the spec calls for.
*/
type HookRegistryEntry = {
kind: HookDescription<unknown>['kind'] | HookBoundaryKind;
phase: HookPhase;
target: HookTarget;
};
/**
* Query for {@link jssm!Machine.has_hook} / {@link jssm!Machine.hooks_on}. A bare
* string is read as a state name; an `{ from, to, action? }` object is read
* as an edge (optionally a named edge); an `{ action }` object is read as a
* named action; a `{ group }` object is read as a named state group. This
* mirrors the spec's `hooks_on(state)` / `hooks_on(from→to)` /
* `hooks_on(action)` / `hooks_on(&group)` set with one parameter shape.
*/
type HookQuery = StateType$1 | {
from: StateType$1;
to: StateType$1;
action?: string;
} | {
action: string;
} | {
group: string;
};
/**
* Richer hook return value used when a hook needs to do more than just
* accept or veto a transition. `pass` is the required accept/veto flag
* (kept non-optional so that returning a stray object doesn't accidentally
* veto everything). The optional `state` overrides the destination state,
* `data` overrides the data observed by other hooks in the same chain,
* and `next_data` overrides the data committed after the transition.
*/
type HookComplexResult<mDT> = {
pass: boolean;
state?: StateType$1;
data?: mDT;
next_data?: mDT;
};
/**
* Return value from a {@link HookHandler}. May be a plain boolean to
* accept (`true`/`undefined`/`void`) or veto (`false`) the transition, or
* a {@link HookComplexResult} that additionally rewrites the next state
* and/or the next data payload.
*/
type HookResult<mDT> = true | false | undefined | void | HookComplexResult<mDT>;
/**
* Context object passed to every {@link HookHandler}. `data` is the
* data payload as it stands before the transition, and `next_data` is
* the payload that will be committed if the transition is accepted —
* handlers may inspect or mutate the latter via a
* {@link HookComplexResult} return value.
*
* The remaining fields describe the transition the hook is firing on. They
* are optional because a handler is not obliged to care about them, but the
* transition path always supplies all of them; `action` is `undefined` when
* the transition was not driven by an action.
*/
type HookContext<mDT> = {
data: mDT;
next_data: mDT;
/** The state being left. */
from?: string;
/** The state being entered. */
to?: string;
/** The action that drove the transition, or `undefined` if none did. */
action?: string;
/** Whether this transition came from `force_transition` rather than `transition`. */
forced?: boolean;
/**
* Which arrow kind the traversed edge carries — `legal`, `main`, or `forced`.
*
* Populated **only when a transition-kind hook is installed** (a standard,
* main, or forced transition hook, or their post- equivalents). With no such
* hook registered there is nothing to switch on, so jssm skips resolving the
* edge's kind and this is `undefined`. Install `hook_standard_transition`
* (or a sibling) if a general handler needs to read it.
*/
trans_type?: JssmArrowKind;
};
/**
* Context object passed to "everything" hooks ({@link EverythingHookHandler}
* and {@link PostEverythingHookHandler}). Extends the usual
* {@link HookContext} with `hook_name`, which identifies which specific
* hook fired so a single handler can route on it.
*/
type EverythingHookContext<mDT> = HookContext<mDT> & {
hook_name: string;
};
/**
* Signature of a pre-transition hook handler. Receives the current and
* proposed-next data payloads via a {@link HookContext} and returns a
* {@link HookResult}: a falsy result vetoes the transition, a truthy
* result allows it, and a {@link HookComplexResult} can additionally
* rewrite the next state or next data.
*/
type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
/**
* Signature of a post-transition hook handler. Invoked after a successful
* transition has been committed; the return value is ignored (the
* transition cannot be undone).
*/
type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
/**
* Signature of an "everything" pre-transition hook handler. Like
* {@link HookHandler} but receives an {@link EverythingHookContext} so the
* handler can dispatch on `hook_name`.
*/
type EverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => HookResult<mDT>;
/**
* Signature of an "everything" post-transition hook handler. Like
* {@link PostHookHandler} but receives an {@link EverythingHookContext}.
* The return value is ignored.
*/
type PostEverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => void;
/**
* Bounded history of recently-visited states paired with the data payload
* observed in each. Backed by `circular_buffer_js`, so the oldest entry
* is dropped silently once the configured capacity is exceeded.
*/
type JssmHistory<mDT> = circular_buffer<[StateType$1, mDT]>;
/**
* Pluggable random-number-generator function shape. Must return a value
* in `[0, 1)` exactly as `Math.random` does. Supplied via the
* `rng_seed`-aware machine configuration so that stochastic models can be
* made reproducible.
*/
type JssmRng = () => number;
/**
* All event names that {@link jssm!Machine.on} accepts. These are observation
* events fired by the machine in addition to (not in place of) the hook
* system. Hooks intercept; events observe.
* @see Machine.on
*/
type JssmEventName = 'transition' | 'rejection' | 'action' | 'entry' | 'exit' | 'terminal' | 'complete' | 'error' | 'data-change' | 'override' | 'timeout' | 'hook-registration' | 'hook-removal';
/**
* Detail payload fired with a `transition` event. Carries the resolved
* source and target, the action name (if the transition was driven by an
* action), the data observed before and after the change, the edge kind,
* and whether the call was a forced transition.
*/
type JssmTransitionEventDetail<mDT> = {
from: StateType$1;
to: StateType$1;
action?: StateType$1;
data: mDT;
next_data?: mDT;
trans_type: string | undefined;
forced: boolean;
};
/**
* Detail payload fired with a `rejection` event. Carries the resolved
* source and target plus an indication of who rejected the transition
* and why. `reason` is `'invalid'` when no edge existed, `'hook'` when
* a hook handler vetoed; `hook_name` is set when `reason` is `'hook'`.