UNPKG

6.19 kBTypeScriptView Raw
1declare type StateType = string;
2import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
4import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
5import { version } from './version';
6declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
7declare function arrow_left_kind(arrow: JssmArrow): JssmArrowKind;
8declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
9declare function wrap_parse(input: string, options?: Object): any;
10declare function compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>;
11declare function make<mDT>(plan: string): JssmGenericConfig<mDT>;
12declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
13declare class Machine<mDT> {
14 _state: StateType;
15 _states: Map<StateType, JssmGenericState>;
16 _edges: Array<JssmTransition<mDT>>;
17 _edge_map: Map<StateType, Map<StateType, number>>;
18 _named_transitions: Map<StateType, number>;
19 _actions: Map<StateType, Map<StateType, number>>;
20 _reverse_actions: Map<StateType, Map<StateType, number>>;
21 _reverse_action_targets: Map<StateType, Map<StateType, number>>;
22 _machine_author?: Array<string>;
23 _machine_comment?: string;
24 _machine_contributor?: Array<string>;
25 _machine_definition?: string;
26 _machine_language?: string;
27 _machine_license?: string;
28 _machine_name?: string;
29 _machine_version?: string;
30 _fsl_version?: string;
31 _raw_state_declaration?: Array<Object>;
32 _state_declarations: Map<StateType, JssmStateDeclaration>;
33 _graph_layout: JssmLayout;
34 _dot_preamble: string;
35 _arrange_declaration: Array<Array<StateType>>;
36 _arrange_start_declaration: Array<Array<StateType>>;
37 _arrange_end_declaration: Array<Array<StateType>>;
38 _theme: FslTheme;
39 _flow: FslDirection;
40 _has_hooks: boolean;
41 _has_basic_hooks: boolean;
42 _has_named_hooks: boolean;
43 _hooks: Map<string, Function>;
44 _named_hooks: Map<string, Function>;
45 _any_transition_hook: HookHandler | undefined;
46 constructor({ start_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout }: JssmGenericConfig<mDT>);
47 _new_state(state_config: JssmGenericState): StateType;
48 state(): StateType;
49 state_is_final(whichState: StateType): boolean;
50 is_final(): boolean;
51 graph_layout(): string;
52 dot_preamble(): string;
53 machine_author(): Array<string>;
54 machine_comment(): string;
55 machine_contributor(): Array<string>;
56 machine_definition(): string;
57 machine_language(): string;
58 machine_license(): string;
59 machine_name(): string;
60 machine_version(): string;
61 raw_state_declarations(): Array<Object>;
62 state_declaration(which: StateType): JssmStateDeclaration;
63 state_declarations(): Map<StateType, JssmStateDeclaration>;
64 fsl_version(): string;
65 machine_state(): JssmMachineInternalState<mDT>;
66 states(): Array<StateType>;
67 state_for(whichState: StateType): JssmGenericState;
68 has_state(whichState: StateType): boolean;
69 list_edges(): Array<JssmTransition<mDT>>;
70 list_named_transitions(): Map<StateType, number>;
71 list_actions(): Array<StateType>;
72 theme(): FslTheme;
73 flow(): FslDirection;
74 get_transition_by_state_names(from: StateType, to: StateType): number;
75 lookup_transition_for(from: StateType, to: StateType): JssmTransition<mDT>;
76 list_transitions(whichState?: StateType): JssmTransitionList;
77 list_entrances(whichState?: StateType): Array<StateType>;
78 list_exits(whichState?: StateType): Array<StateType>;
79 probable_exits_for(whichState: StateType): Array<JssmTransition<mDT>>;
80 probabilistic_transition(): boolean;
81 probabilistic_walk(n: number): Array<StateType>;
82 probabilistic_histo_walk(n: number): Map<StateType, number>;
83 actions(whichState?: StateType): Array<StateType>;
84 list_states_having_action(whichState: StateType): Array<StateType>;
85 list_exit_actions(whichState?: StateType): Array<StateType>;
86 probable_action_exits(whichState?: StateType): Array<any>;
87 is_unenterable(whichState: StateType): boolean;
88 has_unenterables(): boolean;
89 is_terminal(): boolean;
90 state_is_terminal(whichState: StateType): boolean;
91 has_terminals(): boolean;
92 is_complete(): boolean;
93 state_is_complete(whichState: StateType): boolean;
94 has_completes(): boolean;
95 set_hook(HookDesc: HookDescription): void;
96 hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
97 hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
98 hook_any_transition(handler: HookHandler): Machine<mDT>;
99 action(name: StateType, newData?: mDT): boolean;
100 transition_impl(newState: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
101 transition(newState: StateType, newData?: mDT): boolean;
102 force_transition(newState: StateType, newData?: mDT): boolean;
103 current_action_for(action: StateType): number;
104 current_action_edge_for(action: StateType): JssmTransition<mDT>;
105 valid_action(action: StateType, _newData?: mDT): boolean;
106 valid_transition(newState: StateType, _newData?: mDT): boolean;
107 valid_force_transition(newState: StateType, _newData?: mDT): boolean;
108 sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
109}
110declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
111export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key };