-
Notifications
You must be signed in to change notification settings - Fork 23
/
jssm.d.ts
1141 lines (1141 loc) · 42 KB
/
jssm.d.ts
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
declare type StateType = string;
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng } from './jssm_types';
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
import { compile, make, wrap_parse } from './jssm_compiler';
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, sleep } from './jssm_util';
import * as constants from './jssm_constants';
declare const shapes: string[], gviz_shapes: string[], named_colors: string[];
import { version, build_time } from './version';
/*********
*
* An internal method meant to take a series of declarations and fold them into
* a single multi-faceted declaration, in the process of building a state. Not
* generally meant for external use.
*
* @internal
*
*/
declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
declare function state_style_condense(jssk: JssmStateStyleKeyList): JssmStateConfig;
declare class Machine<mDT> {
_state: StateType;
_states: Map<StateType, JssmGenericState>;
_edges: Array<JssmTransition<StateType, mDT>>;
_edge_map: Map<StateType, Map<StateType, number>>;
_named_transitions: Map<StateType, number>;
_actions: Map<StateType, Map<StateType, number>>;
_reverse_actions: Map<StateType, Map<StateType, number>>;
_reverse_action_targets: Map<StateType, Map<StateType, number>>;
_start_states: Set<StateType>;
_end_states: Set<StateType>;
_machine_author?: Array<string>;
_machine_comment?: string;
_machine_contributor?: Array<string>;
_machine_definition?: string;
_machine_language?: string;
_machine_license?: string;
_machine_name?: string;
_machine_version?: string;
_fsl_version?: string;
_raw_state_declaration?: Array<Object>;
_state_declarations: Map<StateType, JssmStateDeclaration>;
_data?: mDT;
_instance_name: string;
_rng_seed: number;
_rng: JssmRng;
_graph_layout: JssmLayout;
_dot_preamble: string;
_arrange_declaration: Array<Array<StateType>>;
_arrange_start_declaration: Array<Array<StateType>>;
_arrange_end_declaration: Array<Array<StateType>>;
_themes: FslTheme[];
_flow: FslDirection;
_has_hooks: boolean;
_has_basic_hooks: boolean;
_has_named_hooks: boolean;
_has_entry_hooks: boolean;
_has_exit_hooks: boolean;
_has_after_hooks: boolean;
_has_global_action_hooks: boolean;
_has_transition_hooks: boolean;
_has_forced_transitions: boolean;
_hooks: Map<string, HookHandler<mDT>>;
_named_hooks: Map<string, HookHandler<mDT>>;
_entry_hooks: Map<string, HookHandler<mDT>>;
_exit_hooks: Map<string, HookHandler<mDT>>;
_after_hooks: Map<string, HookHandler<mDT>>;
_global_action_hooks: Map<string, HookHandler<mDT>>;
_any_action_hook: HookHandler<mDT> | undefined;
_standard_transition_hook: HookHandler<mDT> | undefined;
_main_transition_hook: HookHandler<mDT> | undefined;
_forced_transition_hook: HookHandler<mDT> | undefined;
_any_transition_hook: HookHandler<mDT> | undefined;
_has_post_hooks: boolean;
_has_post_basic_hooks: boolean;
_has_post_named_hooks: boolean;
_has_post_entry_hooks: boolean;
_has_post_exit_hooks: boolean;
_has_post_global_action_hooks: boolean;
_has_post_transition_hooks: boolean;
_code_allows_override: JssmAllowsOverride;
_config_allows_override: JssmAllowsOverride;
_post_hooks: Map<string, HookHandler<mDT>>;
_post_named_hooks: Map<string, HookHandler<mDT>>;
_post_entry_hooks: Map<string, HookHandler<mDT>>;
_post_exit_hooks: Map<string, HookHandler<mDT>>;
_post_global_action_hooks: Map<string, HookHandler<mDT>>;
_post_any_action_hook: HookHandler<mDT> | undefined;
_post_standard_transition_hook: HookHandler<mDT> | undefined;
_post_main_transition_hook: HookHandler<mDT> | undefined;
_post_forced_transition_hook: HookHandler<mDT> | undefined;
_post_any_transition_hook: HookHandler<mDT> | undefined;
_property_keys: Set<string>;
_default_properties: Map<string, any>;
_state_properties: Map<string, any>;
_required_properties: Set<string>;
_history: JssmHistory<mDT>;
_history_length: number;
_state_style: JssmStateConfig;
_active_state_style: JssmStateConfig;
_hooked_state_style: JssmStateConfig;
_terminal_state_style: JssmStateConfig;
_start_state_style: JssmStateConfig;
_end_state_style: JssmStateConfig;
_state_labels: Map<string, string>;
_time_source: () => number;
_create_started: number;
_created: number;
_after_mapping: Map<string, [string, number]>;
_timeout_source: (Function: any, number: any) => number;
_clear_timeout_source: (h: any) => void;
_timeout_handle: number | undefined;
_timeout_target: string | undefined;
_timeout_target_time: number | undefined;
constructor({ start_states, end_states, initial_state, start_states_no_enforce, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
/********
*
* Internal method for fabricating states. Not meant for external use.
*
* @internal
*
*/
_new_state(state_config: JssmGenericState): StateType;
/*********
*
* Get the current state of a machine.
*
* ```typescript
* import * as jssm from 'jssm';
*
* const lswitch = jssm.from('on <=> off;');
* console.log( lswitch.state() ); // 'on'
*
* lswitch.transition('off');
* console.log( lswitch.state() ); // 'off'
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
state(): StateType;
/*********
*
* Get the label for a given state, if any; return `undefined` otherwise.
*
* ```typescript
* import * as jssm from 'jssm';
*
* const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
* console.log( lswitch.label_for('a') ); // 'Foo!'
* console.log( lswitch.label_for('b') ); // undefined
* ```
*
* See also {@link display_text}.
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
label_for(state: StateType): string;
/*********
*
* Get whatever the node should show as text.
*
* Currently, this means to get the label for a given state, if any;
* otherwise to return the node's name. However, this definition is expected
* to grow with time, and it is currently considered ill-advised to manually
* parse this text.
*
* See also {@link label_for}.
*
* ```typescript
* import * as jssm from 'jssm';
*
* const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
* console.log( lswitch.display_text('a') ); // 'Foo!'
* console.log( lswitch.display_text('b') ); // 'b'
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
display_text(state: StateType): string;
/*********
*
* Get the current data of a machine.
*
* ```typescript
* import * as jssm from 'jssm';
*
* const lswitch = jssm.from('on <=> off;', {data: 1});
* console.log( lswitch.data() ); // 1
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
data(): mDT;
/*********
*
* Get the current value of a given property name.
*
* ```typescript
*
* ```
*
* @param name The relevant property name to look up
*
* @returns The value behind the prop name. Because functional props are
* evaluated as getters, this can be anything.
*
*/
prop(name: string): any;
/*********
*
* Get the current value of a given property name. If missing on the state
* and without a global default, throw, unlike {@link prop}, which would
* return `undefined` instead.
*
* ```typescript
*
* ```
*
* @param name The relevant property name to look up
*
* @returns The value behind the prop name. Because functional props are
* evaluated as getters, this can be anything.
*
*/
strict_prop(name: string): any;
/*********
*
* Get the current value of every prop, as an object. If no current definition
* exists for a prop - that is, if the prop was defined without a default and
* the current state also doesn't define the prop - then that prop will be listed
* in the returned object with a value of `undefined`.
*
* ```typescript
* const traffic_light = sm`
*
* property can_go default true;
* property hesitate default true;
* property stop_first default false;
*
* Off -> Red => Green => Yellow => Red;
* [Red Yellow Green] ~> [Off FlashingRed];
* FlashingRed -> Red;
*
* state Red: { property stop_first true; property can_go false; };
* state Off: { property stop_first true; };
* state FlashingRed: { property stop_first true; };
* state Green: { property hesitate false; };
*
* `;
*
* traffic_light.state(); // Off
* traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true; }
*
* traffic_light.go('Red');
* traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true; }
*
* traffic_light.go('Green');
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
* ```
*
*/
props(): object;
/*********
*
* Get the current value of every prop, as an object. Compare
* {@link prop_map}, which returns a `Map`.
*
* ```typescript
*
* ```
*
*/
/*********
*
* Get the current value of every prop, as an object. Compare
* {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
* this throws if a required prop is missing.
*
* ```typescript
*
* ```
*
*/
/*********
*
* Check whether a given string is a known property's name.
*
* ```typescript
* const example = sm`property foo default 1; a->b;`;
*
* example.known_prop('foo'); // true
* example.known_prop('bar'); // false
* ```
*
* @param prop_name The relevant property name to look up
*
*/
known_prop(prop_name: string): boolean;
/*********
*
* List all known property names. If you'd also like values, use
* {@link props} instead. The order of the properties is not defined, and
* the properties generally will not be sorted.
*
* ```typescript
* ```
*
*/
known_props(): string[];
/********
*
* Check whether a given state is a valid start state (either because it was
* explicitly named as such, or because it was the first mentioned state.)
*
* ```typescript
* import { sm, is_start_state } from 'jssm';
*
* const example = sm`a -> b;`;
*
* console.log( final_test.is_start_state('a') ); // true
* console.log( final_test.is_start_state('b') ); // false
*
* const example = sm`start_states: [a b]; a -> b;`;
*
* console.log( final_test.is_start_state('a') ); // true
* console.log( final_test.is_start_state('b') ); // true
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The name of the state to check
*
*/
is_start_state(whichState: StateType): boolean;
/********
*
* Check whether a given state is a valid start state (either because it was
* explicitly named as such, or because it was the first mentioned state.)
*
* ```typescript
* import { sm, is_end_state } from 'jssm';
*
* const example = sm`a -> b;`;
*
* console.log( final_test.is_start_state('a') ); // false
* console.log( final_test.is_start_state('b') ); // true
*
* const example = sm`end_states: [a b]; a -> b;`;
*
* console.log( final_test.is_start_state('a') ); // true
* console.log( final_test.is_start_state('b') ); // true
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The name of the state to check
*
*/
is_end_state(whichState: StateType): boolean;
/********
*
* Check whether a given state is final (either has no exits or is marked
* `complete`.)
*
* ```typescript
* import { sm, state_is_final } from 'jssm';
*
* const final_test = sm`first -> second;`;
*
* console.log( final_test.state_is_final('first') ); // false
* console.log( final_test.state_is_final('second') ); // true
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The name of the state to check for finality
*
*/
state_is_final(whichState: StateType): boolean;
/********
*
* Check whether the current state is final (either has no exits or is marked
* `complete`.)
*
* ```typescript
* import { sm, is_final } from 'jssm';
*
* const final_test = sm`first -> second;`;
*
* console.log( final_test.is_final() ); // false
* state.transition('second');
* console.log( final_test.is_final() ); // true
* ```
*
*/
is_final(): boolean;
/********
*
* Serialize the current machine, including all defining state but not the
* machine string, to a structure. This means you will need the machine
* string to recreate (to not waste repeated space;) if you want the machine
* string embedded, call {@link serialize_with_string} instead.
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
serialize(comment?: string | undefined): JssmSerialization<mDT>;
graph_layout(): string;
dot_preamble(): string;
machine_author(): Array<string>;
machine_comment(): string;
machine_contributor(): Array<string>;
machine_definition(): string;
machine_language(): string;
machine_license(): string;
machine_name(): string;
machine_version(): string;
raw_state_declarations(): Array<Object>;
state_declaration(which: StateType): JssmStateDeclaration;
state_declarations(): Map<StateType, JssmStateDeclaration>;
fsl_version(): string;
machine_state(): JssmMachineInternalState<mDT>;
/*********
*
* List all the states known by the machine. Please note that the order of
* these states is not guaranteed.
*
* ```typescript
* import * as jssm from 'jssm';
*
* const lswitch = jssm.from('on <=> off;');
* console.log( lswitch.states() ); // ['on', 'off']
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
states(): Array<StateType>;
state_for(whichState: StateType): JssmGenericState;
/*********
*
* Check whether the machine knows a given state.
*
* ```typescript
* import * as jssm from 'jssm';
*
* const lswitch = jssm.from('on <=> off;');
*
* console.log( lswitch.has_state('off') ); // true
* console.log( lswitch.has_state('dance') ); // false
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The state to be checked for extance
*
*/
has_state(whichState: StateType): boolean;
/*********
*
* Lists all edges of a machine.
*
* ```typescript
* import { sm } from 'jssm';
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
*
* lswitch.list_edges();
* [
* {
* from: 'on',
* to: 'off',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* },
* {
* from: 'off',
* to: 'on',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* }
* ]
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
list_edges(): Array<JssmTransition<StateType, mDT>>;
list_named_transitions(): Map<StateType, number>;
list_actions(): Array<StateType>;
get uses_actions(): boolean;
get uses_forced_transitions(): boolean;
/*********
*
* Check if the code that built the machine allows overriding state and data.
*
*/
get code_allows_override(): JssmAllowsOverride;
/*********
*
* Check if the machine config allows overriding state and data.
*
*/
get config_allows_override(): JssmAllowsOverride;
/*********
*
* Check if a machine allows overriding state and data.
*
*/
get allows_override(): JssmAllowsOverride;
all_themes(): FslTheme[];
get themes(): FslTheme | FslTheme[];
set themes(to: FslTheme | FslTheme[]);
flow(): FslDirection;
get_transition_by_state_names(from: StateType, to: StateType): number;
lookup_transition_for(from: StateType, to: StateType): JssmTransition<StateType, mDT>;
/********
*
* List all transitions attached to the current state, sorted by entrance and
* exit. The order of each sublist is not defined. A node could appear in
* both lists.
*
* ```typescript
* import { sm } from 'jssm';
*
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The state whose transitions to have listed
*
*/
list_transitions(whichState?: StateType): JssmTransitionList;
/********
*
* List all entrances attached to the current state. Please note that the
* order of the list is not defined. This list includes both unforced and
* forced entrances; if this isn't desired, consider
* {@link list_unforced_entrances} or {@link list_forced_entrances} as
* appropriate.
*
* ```typescript
* import { sm } from 'jssm';
*
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_entrances(); // [ 'yellow', 'off' ]
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The state whose entrances to have listed
*
*/
list_entrances(whichState?: StateType): Array<StateType>;
/********
*
* List all exits attached to the current state. Please note that the order
* of the list is not defined. This list includes both unforced and forced
* exits; if this isn't desired, consider {@link list_unforced_exits} or
* {@link list_forced_exits} as appropriate.
*
* ```typescript
* import { sm } from 'jssm';
*
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_exits(); // [ 'green', 'off' ]
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The state whose exits to have listed
*
*/
list_exits(whichState?: StateType): Array<StateType>;
probable_exits_for(whichState: StateType): Array<JssmTransition<StateType, mDT>>;
probabilistic_transition(): boolean;
probabilistic_walk(n: number): Array<StateType>;
probabilistic_histo_walk(n: number): Map<StateType, number>;
/********
*
* List all actions available from this state. Please note that the order of
* the actions is not guaranteed.
*
* ```typescript
* import { sm } from 'jssm';
*
* const machine = sm`
* red 'next' -> green 'next' -> yellow 'next' -> red;
* [red yellow green] 'shutdown' ~> off 'start' -> red;
* `;
*
* console.log( machine.state() ); // logs 'red'
* console.log( machine.actions() ); // logs ['next', 'shutdown']
*
* machine.action('next'); // true
* console.log( machine.state() ); // logs 'green'
* console.log( machine.actions() ); // logs ['next', 'shutdown']
*
* machine.action('shutdown'); // true
* console.log( machine.state() ); // logs 'off'
* console.log( machine.actions() ); // logs ['start']
*
* machine.action('start'); // true
* console.log( machine.state() ); // logs 'red'
* console.log( machine.actions() ); // logs ['next', 'shutdown']
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The state whose actions to have listed
*
*/
actions(whichState?: StateType): Array<StateType>;
/********
*
* List all states that have a specific action attached. Please note that
* the order of the states is not guaranteed.
*
* ```typescript
* import { sm } from 'jssm';
*
* const machine = sm`
* red 'next' -> green 'next' -> yellow 'next' -> red;
* [red yellow green] 'shutdown' ~> off 'start' -> red;
* `;
*
* console.log( machine.list_states_having_action('next') ); // ['red', 'green', 'yellow']
* console.log( machine.list_states_having_action('start') ); // ['off']
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param whichState The action to be checked for associated states
*
*/
list_states_having_action(whichState: StateType): Array<StateType>;
list_exit_actions(whichState?: StateType): Array<StateType>;
probable_action_exits(whichState?: StateType): Array<any>;
is_unenterable(whichState: StateType): boolean;
has_unenterables(): boolean;
is_terminal(): boolean;
state_is_terminal(whichState: StateType): boolean;
has_terminals(): boolean;
is_complete(): boolean;
state_is_complete(whichState: StateType): boolean;
has_completes(): boolean;
set_hook(HookDesc: HookDescription<mDT>): void;
hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
get rng_seed(): number;
set rng_seed(to: number | undefined);
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
/*********
*
* Replace the current state and data with no regard to the graph.
*
* ```typescript
* import { sm } from 'jssm';
*
* const machine = sm`a -> b -> c;`;
* console.log( machine.state() ); // 'a'
*
* machine.go('b');
* machine.go('c');
* console.log( machine.state() ); // 'c'
*
* machine.override('a');
* console.log( machine.state() ); // 'a'
* ```
*
*/
override(newState: StateType, newData?: mDT | undefined): void;
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
auto_set_state_timeout(): void;
/*********
*
* Get a truncated history of the recent states and data of the machine.
* Turned off by default; configure with `.from('...', {data: 5})` by length,
* or set `.history_length` at runtime.
*
* History *does not contain the current state*. If you want that, call
* `.history_inclusive` instead.
*
* ```typescript
* const foo = jssm.from(
* "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
* { history: 3 }
* );
*
* foo.action('next');
* foo.action('next');
* foo.action('next');
* foo.action('next');
*
* foo.history; // [ ['b',undefined], ['c',undefined], ['d',undefined] ]
* ```
*
* Notice that the machine's current state, `e`, is not in the returned list.
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get history(): [string, mDT][];
/*********
*
* Get a truncated history of the recent states and data of the machine,
* including the current state. Turned off by default; configure with
* `.from('...', {data: 5})` by length, or set `.history_length` at runtime.
*
* History inclusive contains the current state. If you only want past
* states, call `.history` instead.
*
* The list returned will be one longer than the history buffer kept, as the
* history buffer kept gets the current state added to it to produce this
* list.
*
* ```typescript
* const foo = jssm.from(
* "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
* { history: 3 }
* );
*
* foo.action('next');
* foo.action('next');
* foo.action('next');
* foo.action('next');
*
* foo.history_inclusive; // [ ['b',undefined], ['c',undefined], ['d',undefined], ['e',undefined] ]
* ```
*
* Notice that the machine's current state, `e`, is in the returned list.
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get history_inclusive(): [string, mDT][];
/*********
*
* Find out how long a history this machine is keeping. Defaults to zero.
* Settable directly.
*
* ```typescript
* const foo = jssm.from("a -> b;");
* foo.history_length; // 0
*
* const bar = jssm.from("a -> b;", { history: 3 });
* foo.history_length; // 3
* foo.history_length = 5;
* foo.history_length; // 5
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get history_length(): number;
set history_length(to: number);
/********
*
* Instruct the machine to complete an action. Synonym for {@link do}.
*
* ```typescript
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.action('next'); // true
* light.state(); // 'green'
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param actionName The action to engage
*
* @param newData The data change to insert during the action
*
*/
action(actionName: StateType, newData?: mDT): boolean;
/********
*
* Get the standard style for a single state. ***Does not*** include
* composition from an applied theme, or things from the underlying base
* stylesheet; only the modifications applied by this machine.
*
* ```typescript
* const light = sm`a -> b;`;
* console.log(light.standard_state_style);
* // {}
*
* const light = sm`a -> b; state: { shape: circle; };`;
* console.log(light.standard_state_style);
* // { shape: 'circle' }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get standard_state_style(): JssmStateConfig;
/********
*
* Get the hooked state style. ***Does not*** include
* composition from an applied theme, or things from the underlying base
* stylesheet; only the modifications applied by this machine.
*
* The hooked style is only applied to nodes which have a named hook in the
* graph. Open hooks set through the external API aren't graphed, because
* that would be literally every node.
*
* ```typescript
* const light = sm`a -> b;`;
* console.log(light.hooked_state_style);
* // {}
*
* const light = sm`a -> b; hooked_state: { shape: circle; };`;
* console.log(light.hooked_state_style);
* // { shape: 'circle' }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get hooked_state_style(): JssmStateConfig;
/********
*
* Get the start state style. ***Does not*** include composition from an
* applied theme, or things from the underlying base stylesheet; only the
* modifications applied by this machine.
*
* Start states are defined by the directive `start_states`, or in absentia,
* are the first mentioned state.
*
* ```typescript
* const light = sm`a -> b;`;
* console.log(light.start_state_style);
* // {}
*
* const light = sm`a -> b; start_state: { shape: circle; };`;
* console.log(light.start_state_style);
* // { shape: 'circle' }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get start_state_style(): JssmStateConfig;
/********
*
* Get the end state style. ***Does not*** include
* composition from an applied theme, or things from the underlying base
* stylesheet; only the modifications applied by this machine.
*
* End states are defined in the directive `end_states`, and are distinct
* from terminal states. End states are voluntary successful endpoints for a
* process. Terminal states are states that cannot be exited. By example,
* most error states are terminal states, but not end states. Also, since
* some end states can be exited and are determined by hooks, such as
* recursive or iterative nodes, there is such a thing as an end state that
* is not a terminal state.
*
* ```typescript
* const light = sm`a -> b;`;
* console.log(light.standard_state_style);
* // {}
*
* const light = sm`a -> b; end_state: { shape: circle; };`;
* console.log(light.standard_state_style);
* // { shape: 'circle' }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get end_state_style(): JssmStateConfig;
/********
*
* Get the terminal state style. ***Does not*** include
* composition from an applied theme, or things from the underlying base
* stylesheet; only the modifications applied by this machine.
*
* Terminal state styles are automatically determined by the machine. Any
* state without a valid exit transition is terminal.
*
* ```typescript
* const light = sm`a -> b;`;
* console.log(light.terminal_state_style);
* // {}
*
* const light = sm`a -> b; terminal_state: { shape: circle; };`;
* console.log(light.terminal_state_style);
* // { shape: 'circle' }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get terminal_state_style(): JssmStateConfig;
/********
*
* Get the style for the active state. ***Does not*** include
* composition from an applied theme, or things from the underlying base
* stylesheet; only the modifications applied by this machine.
*
* ```typescript
* const light = sm`a -> b;`;
* console.log(light.active_state_style);
* // {}
*
* const light = sm`a -> b; active_state: { shape: circle; };`;
* console.log(light.active_state_style);
* // { shape: 'circle' }
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
get active_state_style(): JssmStateConfig;
/********
*
* Gets the composite style for a specific node by individually imposing the
* style layers on a given object, after determining which layers are
* appropriate.
*
* The order of composition is base, then theme, then user content. Each
* item in the stack will be composited independently. First, the base state
* style, then the theme state style, then the user state style.
*
* After the three state styles, we'll composite the hooked styles; then the
* terminal styles; then the start styles; then the end styles; finally, the
* active styles. Remember, last wins.
*
* The base state style must exist. All other styles are optional.
*
* @typeparam mDT The type of the machine data member; usually omitted
*
*/
style_for(state: StateType): JssmStateConfig;
/********
*
* Instruct the machine to complete an action. Synonym for {@link action}.
*
* ```typescript
* const light = sm`
* off 'start' -> red;
* red 'next' -> green 'next' -> yellow 'next' -> red;
* [red yellow green] 'shutdown' ~> off;
* `;
*
* light.state(); // 'off'
* light.do('start'); // true
* light.state(); // 'red'
* light.do('next'); // true
* light.state(); // 'green'
* light.do('next'); // true
* light.state(); // 'yellow'
* light.do('dance'); // !! false - no such action
* light.state(); // 'yellow'
* light.do('start'); // !! false - yellow does not have the action start
* light.state(); // 'yellow'
* ```
*
* @typeparam mDT The type of the machine data member; usually omitted
*
* @param actionName The action to engage
*
* @param newData The data change to insert during the action
*
*/