jssm 5.104.2 → 5.112.4
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/MIGRATING-jssm-viz.md +67 -0
- package/README.md +179 -882
- package/dist/deno/README.md +347 -0
- package/dist/{es6 → deno}/jssm.d.ts +773 -39
- package/dist/deno/jssm.js +1 -0
- package/{jssm_compiler.d.ts → dist/deno/jssm_compiler.d.ts} +17 -2
- package/dist/deno/jssm_constants.d.ts +37 -0
- package/dist/deno/jssm_error.d.ts +27 -0
- package/dist/deno/jssm_theme.d.ts +15 -0
- package/dist/{es6 → deno}/jssm_types.d.ts +327 -8
- package/dist/deno/jssm_util.d.ts +258 -0
- package/dist/deno/jssm_viz.d.ts +175 -0
- package/dist/deno/jssm_viz_colors.d.ts +63 -0
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -0
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm_viz.cjs +1 -0
- package/dist/jssm_viz.iife.cjs +1 -0
- package/dist/jssm_viz.mjs +1 -0
- package/jssm.es5.d.cts +1191 -43
- package/jssm.es6.d.ts +1191 -43
- package/jssm_viz.es5.d.cts +2341 -0
- package/jssm_viz.es6.d.ts +2341 -0
- package/package.json +73 -24
- package/.clocignore +0 -1
- package/.codeclimate.yml +0 -22
- package/.editorconfig +0 -12
- package/.eslintrc +0 -20
- package/.gitattributes +0 -6
- package/.nycrc +0 -6
- package/.travis.yml +0 -9
- package/CHANGELOG.md +0 -178
- package/dist/es6/fsl_parser.js +0 -1
- package/dist/es6/jssm.js +0 -2488
- package/dist/es6/jssm_arrow.js +0 -187
- package/dist/es6/jssm_compiler.d.ts +0 -135
- package/dist/es6/jssm_compiler.js +0 -366
- package/dist/es6/jssm_constants.d.ts +0 -5
- package/dist/es6/jssm_constants.js +0 -94
- package/dist/es6/jssm_error.d.ts +0 -8
- package/dist/es6/jssm_error.js +0 -28
- package/dist/es6/jssm_theme.d.ts +0 -4
- package/dist/es6/jssm_theme.js +0 -13
- package/dist/es6/jssm_types.js +0 -3
- package/dist/es6/jssm_util.d.ts +0 -106
- package/dist/es6/jssm_util.js +0 -180
- package/dist/es6/themes/jssm_base_stylesheet.d.ts +0 -11
- package/dist/es6/themes/jssm_base_stylesheet.js +0 -58
- package/dist/es6/themes/jssm_theme_bold.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_bold.js +0 -58
- package/dist/es6/themes/jssm_theme_default.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_default.js +0 -58
- package/dist/es6/themes/jssm_theme_modern.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_modern.js +0 -58
- package/dist/es6/themes/jssm_theme_ocean.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_ocean.js +0 -56
- package/dist/es6/themes/jssm_theme_plain.d.ts +0 -11
- package/dist/es6/themes/jssm_theme_plain.js +0 -70
- package/dist/es6/version.js +0 -2
- package/dist/jssm.es5.iife.cjs +0 -1
- package/dist/jssm.es5.iife.nonmin.cjs +0 -23180
- package/dist/jssm.es5.nonmin.cjs +0 -23175
- package/dist/jssm.es6.nonmin.cjs +0 -23144
- package/fsl_parser.d.ts +0 -6
- package/jest-dragon.config.cjs +0 -33
- package/jest-spec.config.cjs +0 -33
- package/jest-stoch.config.cjs +0 -33
- package/jest-unicode.config.cjs +0 -33
- package/jssm.d.ts +0 -1141
- package/jssm_arrow.d.ts +0 -53
- 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/rollup.config.deno.js +0 -44
- package/rollup.config.es5.js +0 -52
- package/rollup.config.es6.js +0 -55
- package/tutorial_learn_testing.md +0 -168
- package/typedoc-options.cjs +0 -68
- package/version.d.ts +0 -2
- /package/dist/{es6 → deno}/fsl_parser.d.ts +0 -0
- /package/dist/{es6 → deno}/jssm_arrow.d.ts +0 -0
- /package/dist/{es6 → deno}/version.d.ts +0 -0
|
@@ -2,11 +2,26 @@ import { JssmTransition, JssmCompileSe, JssmParseTree, JssmGenericConfig } from
|
|
|
2
2
|
/*********
|
|
3
3
|
*
|
|
4
4
|
* Internal method meant to perform factory assembly of an edge. Not meant for
|
|
5
|
-
* external use.
|
|
5
|
+
* external use. Constructs a {@link JssmTransition} from a parsed
|
|
6
|
+
* semi-edge (`this_se`), a source state, a target state, and directionality.
|
|
6
7
|
*
|
|
7
8
|
* @internal
|
|
8
9
|
*
|
|
9
|
-
* @typeparam
|
|
10
|
+
* @typeparam StateType The type of state names (usually `string`).
|
|
11
|
+
* @typeparam mDT The type of the machine data member; usually omitted.
|
|
12
|
+
*
|
|
13
|
+
* @param this_se - The parsed semi-edge containing kind, action, and
|
|
14
|
+
* probability metadata.
|
|
15
|
+
* @param from - The source state of the transition.
|
|
16
|
+
* @param to - The target state of the transition.
|
|
17
|
+
* @param isRight - `true` if this is a left-to-right transition, `false`
|
|
18
|
+
* for right-to-left. Determines which arrow kind
|
|
19
|
+
* extraction function is used.
|
|
20
|
+
* @param _wasList - If the transition was expanded from a list (e.g.
|
|
21
|
+
* `[A B C] -> D`), the original list of states.
|
|
22
|
+
* @param _wasIndex - The index of `from` within `_wasList`, if applicable.
|
|
23
|
+
*
|
|
24
|
+
* @returns A fully assembled {@link JssmTransition} edge object.
|
|
10
25
|
*
|
|
11
26
|
*/
|
|
12
27
|
declare function makeTransition<StateType, mDT>(this_se: JssmCompileSe<StateType, mDT>, from: StateType, to: StateType, isRight: boolean, _wasList?: Array<StateType>, _wasIndex?: number): JssmTransition<StateType, mDT>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
3
|
+
* Convenience aliases for common mathematical and numeric constants from
|
|
4
|
+
* `Number` and `Math`. Re-exported so that FSL data expressions and tests
|
|
5
|
+
* can reference them without importing `Math` directly.
|
|
6
|
+
*
|
|
7
|
+
* Includes: `NegInfinity`, `PosInfinity`, `Epsilon`, `Pi`, `E`, `Root2`,
|
|
8
|
+
* `RootHalf`, `Ln2`, `Ln10`, `Log2E`, `Log10E`, `MaxSafeInt`, `MinSafeInt`,
|
|
9
|
+
* `MaxPosNum`, `MinPosNum`, `Phi` (golden ratio), `EulerC` (Euler–Mascheroni).
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare const NegInfinity: number, PosInfinity: number, Epsilon: number, Pi: number, E: number, Root2: number, RootHalf: number, Ln2: number, Ln10: number, Log2E: number, Log10E: number, MaxSafeInt: number, MinSafeInt: number, MaxPosNum: number, MinPosNum: number, Phi = 1.618033988749895, EulerC = 0.5772156649015329;
|
|
13
|
+
/*******
|
|
14
|
+
*
|
|
15
|
+
* Complete list of node shapes supported by Graphviz. Used by jssm-viz to
|
|
16
|
+
* validate and render state shapes in FSL `state ... : { shape: ... }` blocks.
|
|
17
|
+
*
|
|
18
|
+
* `shapes` is an alias for `gviz_shapes`.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
declare const gviz_shapes: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Public alias for {@link gviz_shapes}. The list of node shapes supported
|
|
24
|
+
* by Graphviz that jssm-viz accepts in FSL `state ... : { shape: ... }`
|
|
25
|
+
* declarations.
|
|
26
|
+
*/
|
|
27
|
+
declare const shapes: string[];
|
|
28
|
+
/*******
|
|
29
|
+
*
|
|
30
|
+
* List of CSS/SVG named colors accepted by jssm-viz for state styling
|
|
31
|
+
* properties like `background-color` and `text-color`. Case-insensitive
|
|
32
|
+
* matching is done at parse time; the canonical casing here follows the
|
|
33
|
+
* CSS specification.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
declare const named_colors: string[];
|
|
37
|
+
export { gviz_shapes, shapes, named_colors, };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JssmErrorExtendedInfo } from './jssm_types';
|
|
2
|
+
/*******
|
|
3
|
+
*
|
|
4
|
+
* Custom error class for jssm. Enriches the standard `Error` with
|
|
5
|
+
* machine context (current state, instance name) and an optional
|
|
6
|
+
* `requested_state` so that error messages are self-describing.
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* throw new JssmError(machine, 'no such state', { requested_state: 'Blue' });
|
|
10
|
+
* // JssmError: [[my-light]]: no such state (at "Red", requested "Blue")
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param machine - The `Machine` instance that raised the error, or
|
|
14
|
+
* `undefined` if no machine is available. Used to
|
|
15
|
+
* read `state()` and `instance_name()` for context.
|
|
16
|
+
* @param message - A human-readable description of the error.
|
|
17
|
+
* @param JEEI - Optional {@link JssmErrorExtendedInfo} with extra
|
|
18
|
+
* context such as `requested_state`.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
declare class JssmError extends Error {
|
|
22
|
+
message: string;
|
|
23
|
+
base_message: string;
|
|
24
|
+
requested_state: string | undefined;
|
|
25
|
+
constructor(machine: any, message: string, JEEI?: JssmErrorExtendedInfo);
|
|
26
|
+
}
|
|
27
|
+
export { JssmError };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FslTheme, JssmBaseTheme } from './jssm_types';
|
|
2
|
+
import { base_theme } from './themes/jssm_base_stylesheet';
|
|
3
|
+
/*******
|
|
4
|
+
*
|
|
5
|
+
* Registry mapping theme names to their stylesheet definitions. Each entry
|
|
6
|
+
* maps an {@link FslTheme} string (e.g. `'default'`, `'ocean'`) to a
|
|
7
|
+
* {@link JssmBaseTheme} object containing colors, shapes, and other visual
|
|
8
|
+
* defaults used by jssm-viz when rendering state machine diagrams.
|
|
9
|
+
*
|
|
10
|
+
* Add new themes by importing their definition and calling
|
|
11
|
+
* `theme_mapping.set(name, theme)`.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
declare const theme_mapping: Map<FslTheme, JssmBaseTheme>;
|
|
15
|
+
export { theme_mapping, base_theme };
|
|
@@ -1,34 +1,110 @@
|
|
|
1
1
|
import { circular_buffer } from 'circular_buffer_js';
|
|
2
2
|
declare type StateType = string;
|
|
3
|
+
/** Composite type indicating success as part of a result. */
|
|
3
4
|
declare type JssmSuccess = {
|
|
4
5
|
success: true;
|
|
5
|
-
};
|
|
6
|
+
};
|
|
7
|
+
/** Composite type indicating an error, and the reason for it, as part of a result. */
|
|
6
8
|
declare type JssmFailure = {
|
|
7
9
|
success: false;
|
|
8
10
|
error: any;
|
|
9
|
-
};
|
|
11
|
+
};
|
|
12
|
+
/** Composite type indicating that a result isn't finished yet. */
|
|
10
13
|
declare type JssmIncomplete = {
|
|
11
14
|
success: 'incomplete';
|
|
12
|
-
};
|
|
13
|
-
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Discriminated union representing the outcome of an operation: either
|
|
18
|
+
* success, failure (with an `error`), or incomplete. Used as the return
|
|
19
|
+
* shape for operations that may need to report partial progress.
|
|
20
|
+
*/
|
|
21
|
+
declare type JssmResult = JssmSuccess | JssmFailure | JssmIncomplete;
|
|
22
|
+
/**
|
|
23
|
+
* A color value accepted by jssm-viz for state and arrow styling. Currently
|
|
24
|
+
* any string, validated downstream by Graphviz / the named-colors list.
|
|
25
|
+
* Intended to be narrowed to `#RRGGBB` / `#RRGGBBAA` and CSS named colors
|
|
26
|
+
* in a future release.
|
|
27
|
+
*/
|
|
14
28
|
declare type JssmColor = string;
|
|
29
|
+
/**
|
|
30
|
+
* Two-state policy flag: a feature is either `'required'` or `'disallowed'`.
|
|
31
|
+
* Used by machine configuration where the option must take a definite stance.
|
|
32
|
+
*/
|
|
15
33
|
declare type JssmPermitted = 'required' | 'disallowed';
|
|
34
|
+
/**
|
|
35
|
+
* Three-state policy flag: `'required'`, `'disallowed'`, or `'optional'`.
|
|
36
|
+
* Used by machine configuration where a default-permissive middle ground
|
|
37
|
+
* is meaningful (for example, the `actions` config key).
|
|
38
|
+
*/
|
|
16
39
|
declare type JssmPermittedOpt = 'required' | 'disallowed' | 'optional';
|
|
40
|
+
/**
|
|
41
|
+
* The set of ASCII arrow tokens recognized by the FSL grammar. Each arrow
|
|
42
|
+
* encodes a direction (one-way left/right, or two-way) and a "kind" for
|
|
43
|
+
* each direction (`-` legal, `=` main path, `~` forced-only). See the
|
|
44
|
+
* Language Reference docs for the full semantic table.
|
|
45
|
+
*/
|
|
17
46
|
declare type JssmArrow = '->' | '<-' | '<->' | '<=->' | '<~->' | '=>' | '<=' | '<=>' | '<-=>' | '<~=>' | '~>' | '<~' | '<~>' | '<-~>' | '<=~>';
|
|
18
47
|
/**
|
|
19
48
|
* A type teaching Typescript the various supported shapes for nodes, mostly inherited from GraphViz
|
|
20
49
|
*/
|
|
21
50
|
declare 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";
|
|
51
|
+
/**
|
|
52
|
+
* Direction polarity of an arrow: pointing only `'left'`, only `'right'`,
|
|
53
|
+
* or `'both'` (a bidirectional arrow).
|
|
54
|
+
*/
|
|
22
55
|
declare type JssmArrowDirection = 'left' | 'right' | 'both';
|
|
56
|
+
/**
|
|
57
|
+
* Semantic category of an arrow's transition. `'legal'` is a normal
|
|
58
|
+
* transition, `'main'` is part of the machine's primary path, `'forced'`
|
|
59
|
+
* may only be taken via {@link Machine.force_transition}, and `'none'`
|
|
60
|
+
* means no transition exists in that direction.
|
|
61
|
+
*/
|
|
23
62
|
declare type JssmArrowKind = 'none' | 'legal' | 'main' | 'forced';
|
|
63
|
+
/**
|
|
64
|
+
* Graphviz layout engine selector. Controls how jssm-viz lays out the
|
|
65
|
+
* rendered diagram; `'dot'` is the default and most useful for state
|
|
66
|
+
* machines. See the Graphviz documentation for the differences.
|
|
67
|
+
*/
|
|
24
68
|
declare type JssmLayout = 'dot' | 'circo' | 'twopi' | 'fdp' | 'neato';
|
|
25
69
|
declare type JssmCorner = 'regular' | 'rounded' | 'lined';
|
|
26
70
|
declare type JssmLineStyle = 'solid' | 'dashed' | 'dotted';
|
|
71
|
+
/**
|
|
72
|
+
* Tristate flag for whether a property may be overridden at runtime.
|
|
73
|
+
* `true` permits overrides, `false` forbids them, and `undefined` defers
|
|
74
|
+
* the decision to the surrounding configuration's default.
|
|
75
|
+
*/
|
|
27
76
|
declare type JssmAllowsOverride = true | false | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Runtime-iterable list of valid `flow` directions for FSL diagrams.
|
|
79
|
+
* Use this when you need to enumerate directions; for the type itself
|
|
80
|
+
* see {@link FslDirection}.
|
|
81
|
+
*/
|
|
28
82
|
declare const FslDirections: readonly ["up", "right", "down", "left"];
|
|
83
|
+
/**
|
|
84
|
+
* String literal type of the four supported FSL flow directions. This is
|
|
85
|
+
* the type of the `flow` config key on a machine.
|
|
86
|
+
*/
|
|
29
87
|
declare type FslDirection = typeof FslDirections[number];
|
|
88
|
+
/**
|
|
89
|
+
* Runtime-iterable list of the built-in theme names that ship with jssm-viz.
|
|
90
|
+
* Use this when you need to enumerate themes; for the type itself see
|
|
91
|
+
* {@link FslTheme}.
|
|
92
|
+
*/
|
|
30
93
|
declare const FslThemes: readonly ["default", "ocean", "modern", "plain", "bold"];
|
|
94
|
+
/**
|
|
95
|
+
* String literal type of the built-in theme names. This is the element
|
|
96
|
+
* type of the `theme` config key (which accepts an array so that themes
|
|
97
|
+
* can be layered).
|
|
98
|
+
*/
|
|
31
99
|
declare type FslTheme = typeof FslThemes[number];
|
|
100
|
+
/**
|
|
101
|
+
* Persistable snapshot of a Machine produced by {@link Machine.serialize}
|
|
102
|
+
* and consumed by {@link deserialize}. Carries the current state, the
|
|
103
|
+
* associated machine data, the recent history (subject to the configured
|
|
104
|
+
* capacity), and metadata to detect version-skew on rehydration.
|
|
105
|
+
*
|
|
106
|
+
* @typeParam DataType - The type of the user-supplied data payload (`mDT`).
|
|
107
|
+
*/
|
|
32
108
|
declare type JssmSerialization<DataType> = {
|
|
33
109
|
jssm_version: string;
|
|
34
110
|
timestamp: number;
|
|
@@ -38,6 +114,11 @@ declare type JssmSerialization<DataType> = {
|
|
|
38
114
|
history_capacity: number;
|
|
39
115
|
data: DataType;
|
|
40
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Declaration of a named property that a machine's states may carry.
|
|
119
|
+
* Set `required: true` to force every state to define the property, or
|
|
120
|
+
* provide `default_value` to fall back when the state does not specify it.
|
|
121
|
+
*/
|
|
41
122
|
declare type JssmPropertyDefinition = {
|
|
42
123
|
name: string;
|
|
43
124
|
default_value?: any;
|
|
@@ -45,6 +126,17 @@ declare type JssmPropertyDefinition = {
|
|
|
45
126
|
};
|
|
46
127
|
declare type JssmTransitionPermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
47
128
|
declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
|
|
129
|
+
/**
|
|
130
|
+
* A single directed transition (edge) within a state machine. Captures
|
|
131
|
+
* both the topology (`from` / `to`), the FSL semantics (`kind`,
|
|
132
|
+
* `forced_only`, `main_path`), and any optional metadata such as a
|
|
133
|
+
* per-edge `name`, an action label, a guard `check`, a transition
|
|
134
|
+
* `probability` for stochastic models, and an `after_time` for timed
|
|
135
|
+
* transitions.
|
|
136
|
+
*
|
|
137
|
+
* @typeParam StateType - The state-name type (usually `string`).
|
|
138
|
+
* @typeParam DataType - The machine's data payload type (`mDT`).
|
|
139
|
+
*/
|
|
48
140
|
declare type JssmTransition<StateType, DataType> = {
|
|
49
141
|
from: StateType;
|
|
50
142
|
to: StateType;
|
|
@@ -58,22 +150,48 @@ declare type JssmTransition<StateType, DataType> = {
|
|
|
58
150
|
forced_only: boolean;
|
|
59
151
|
main_path: boolean;
|
|
60
152
|
};
|
|
153
|
+
/** A list of {@link JssmTransition}s — the edge set of a machine. */
|
|
61
154
|
declare type JssmTransitions<StateType, DataType> = JssmTransition<StateType, DataType>[];
|
|
155
|
+
/**
|
|
156
|
+
* The set of states that can immediately precede or follow a given state.
|
|
157
|
+
* Returned by jssm helpers that report a state's connectivity in the graph.
|
|
158
|
+
*/
|
|
62
159
|
declare type JssmTransitionList = {
|
|
63
160
|
entrances: Array<StateType>;
|
|
64
161
|
exits: Array<StateType>;
|
|
65
162
|
};
|
|
163
|
+
/**
|
|
164
|
+
* Internal marker used by the compiler to indicate a cycle declaration in
|
|
165
|
+
* the parse stream, rather than a literal state name. See
|
|
166
|
+
* {@link JssmTransitionRule}.
|
|
167
|
+
*/
|
|
66
168
|
declare type JssmTransitionCycle = {
|
|
67
169
|
key: 'cycle';
|
|
68
170
|
value: StateType;
|
|
69
171
|
};
|
|
172
|
+
/**
|
|
173
|
+
* An entry produced while parsing a transition rule: either a literal
|
|
174
|
+
* state name (`StateType`) or a {@link JssmTransitionCycle} marker.
|
|
175
|
+
*/
|
|
70
176
|
declare type JssmTransitionRule = StateType | JssmTransitionCycle;
|
|
177
|
+
/**
|
|
178
|
+
* Topology record for one node in a compiled machine: its name, the set of
|
|
179
|
+
* states it can be reached from, the set of states it can transition to,
|
|
180
|
+
* and whether reaching it constitutes "completing" the machine.
|
|
181
|
+
*/
|
|
71
182
|
declare type JssmGenericState = {
|
|
72
183
|
from: Array<StateType>;
|
|
73
184
|
name: StateType;
|
|
74
185
|
to: Array<StateType>;
|
|
75
186
|
complete: boolean;
|
|
76
187
|
};
|
|
188
|
+
/**
|
|
189
|
+
* The full internal bookkeeping snapshot of a {@link Machine}, exposed for
|
|
190
|
+
* advanced introspection. Contains the current state, the state map, the
|
|
191
|
+
* edge map and reverse-action map, and the original edge list. The
|
|
192
|
+
* `internal_state_impl_version` field exists so that consumers can detect
|
|
193
|
+
* shape changes if this representation evolves.
|
|
194
|
+
*/
|
|
77
195
|
declare type JssmMachineInternalState<DataType> = {
|
|
78
196
|
internal_state_impl_version: 1;
|
|
79
197
|
state: StateType;
|
|
@@ -86,6 +204,11 @@ declare type JssmMachineInternalState<DataType> = {
|
|
|
86
204
|
};
|
|
87
205
|
declare type JssmStatePermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
88
206
|
declare type JssmStatePermitterMaybeArray<DataType> = JssmStatePermitter<DataType> | Array<JssmStatePermitter<DataType>>;
|
|
207
|
+
/**
|
|
208
|
+
* Minimal machine description used internally and accepted by some
|
|
209
|
+
* lower-level constructors. Most callers should use the richer
|
|
210
|
+
* {@link JssmGenericConfig} instead.
|
|
211
|
+
*/
|
|
89
212
|
declare type JssmGenericMachine<DataType> = {
|
|
90
213
|
name?: string;
|
|
91
214
|
state: StateType;
|
|
@@ -100,11 +223,21 @@ declare type JssmGenericMachine<DataType> = {
|
|
|
100
223
|
allow_force?: boolean;
|
|
101
224
|
keep_history?: boolean | number;
|
|
102
225
|
};
|
|
226
|
+
/**
|
|
227
|
+
* A single key/value pair from an FSL `state X: { ... };` block, in the
|
|
228
|
+
* raw form produced by the parser before being condensed into a
|
|
229
|
+
* {@link JssmStateDeclaration}.
|
|
230
|
+
*/
|
|
103
231
|
declare type JssmStateDeclarationRule = {
|
|
104
232
|
key: string;
|
|
105
233
|
value: any;
|
|
106
234
|
name?: string;
|
|
107
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* The fully-condensed declaration for a single state, including its raw
|
|
238
|
+
* rule list (`declarations`) and the well-known styling fields jssm-viz
|
|
239
|
+
* understands. Returned by {@link Machine.state_declaration}.
|
|
240
|
+
*/
|
|
108
241
|
declare type JssmStateDeclaration = {
|
|
109
242
|
declarations: Array<JssmStateDeclarationRule>;
|
|
110
243
|
shape?: JssmShape;
|
|
@@ -115,12 +248,18 @@ declare type JssmStateDeclaration = {
|
|
|
115
248
|
textColor?: JssmColor;
|
|
116
249
|
backgroundColor?: JssmColor;
|
|
117
250
|
borderColor?: JssmColor;
|
|
251
|
+
image?: string;
|
|
118
252
|
state: StateType;
|
|
119
253
|
property?: {
|
|
120
254
|
name: string;
|
|
121
255
|
value: unknown;
|
|
122
256
|
};
|
|
123
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* A loosened version of {@link JssmStateDeclaration} where every field is
|
|
260
|
+
* optional. Used as the value type for theme entries and for default
|
|
261
|
+
* state configuration where most fields will be inherited or merged.
|
|
262
|
+
*/
|
|
124
263
|
declare type JssmStateConfig = Partial<JssmStateDeclaration>;
|
|
125
264
|
declare type JssmStateStyleShape = {
|
|
126
265
|
key: 'shape';
|
|
@@ -154,8 +293,33 @@ declare type JssmStateStyleBorderColor = {
|
|
|
154
293
|
key: 'border-color';
|
|
155
294
|
value: JssmColor;
|
|
156
295
|
};
|
|
157
|
-
declare type
|
|
296
|
+
declare type JssmStateStyleImage = {
|
|
297
|
+
key: 'image';
|
|
298
|
+
value: string;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Tagged union of all individual style key/value pairs that may appear in
|
|
302
|
+
* a state's style configuration. The `key` discriminator selects which
|
|
303
|
+
* member, and the `value` is typed accordingly.
|
|
304
|
+
*/
|
|
305
|
+
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor | JssmStateStyleImage;
|
|
306
|
+
/**
|
|
307
|
+
* An ordered list of {@link JssmStateStyleKey} entries. Used by the
|
|
308
|
+
* `default_*_state_config` machine config options to provide a fallback
|
|
309
|
+
* style stack.
|
|
310
|
+
*/
|
|
158
311
|
declare type JssmStateStyleKeyList = JssmStateStyleKey[];
|
|
312
|
+
/**
|
|
313
|
+
* Complete shape of a jssm-viz theme. A theme provides a style block for
|
|
314
|
+
* each kind of state (`state`, `hooked`, `start`, `end`, `terminal`) as
|
|
315
|
+
* well as a matching `active_*` variant used while that state is current.
|
|
316
|
+
*
|
|
317
|
+
* The `graph`, `legal`, `main`, `forced`, `action`, and `title` slots are
|
|
318
|
+
* reserved for future use and currently typed as `undefined`.
|
|
319
|
+
*
|
|
320
|
+
* Most user-defined themes should be typed as {@link JssmTheme} (the
|
|
321
|
+
* `Partial` of this) so that omitted fields fall back to the base theme.
|
|
322
|
+
*/
|
|
159
323
|
declare type JssmBaseTheme = {
|
|
160
324
|
name: string;
|
|
161
325
|
state: JssmStateConfig;
|
|
@@ -175,7 +339,25 @@ declare type JssmBaseTheme = {
|
|
|
175
339
|
action: undefined;
|
|
176
340
|
title: undefined;
|
|
177
341
|
};
|
|
342
|
+
/**
|
|
343
|
+
* A user-supplied theme. Identical in shape to {@link JssmBaseTheme}, but
|
|
344
|
+
* every field is optional so themes can be layered: omitted slots fall
|
|
345
|
+
* through to the underlying base theme.
|
|
346
|
+
*/
|
|
178
347
|
declare type JssmTheme = Partial<JssmBaseTheme>;
|
|
348
|
+
/**
|
|
349
|
+
* Full configuration object accepted by the {@link Machine} constructor and
|
|
350
|
+
* by {@link from}. Carries the transition list and the optional knobs
|
|
351
|
+
* governing layout, theming, history, start/end states, property
|
|
352
|
+
* definitions, machine metadata (author, license, version, ...) and the
|
|
353
|
+
* runtime hook surfaces (`time_source`, `timeout_source`, ...).
|
|
354
|
+
*
|
|
355
|
+
* Most users never construct one of these directly — the `sm` tagged
|
|
356
|
+
* template literal and {@link from} produce one from FSL source.
|
|
357
|
+
*
|
|
358
|
+
* @typeParam StateType - The state-name type (usually `string`).
|
|
359
|
+
* @typeParam DataType - The user-supplied data payload type (`mDT`).
|
|
360
|
+
*/
|
|
179
361
|
declare type JssmGenericConfig<StateType, DataType> = {
|
|
180
362
|
graph_layout?: JssmLayout;
|
|
181
363
|
complete?: Array<StateType>;
|
|
@@ -228,10 +410,26 @@ declare type JssmGenericConfig<StateType, DataType> = {
|
|
|
228
410
|
timeout_source?: (Function: any, number: any) => number;
|
|
229
411
|
clear_timeout_source?: (number: any) => void;
|
|
230
412
|
};
|
|
413
|
+
/**
|
|
414
|
+
* Internal compiler intermediate: a single aggregated rule produced while
|
|
415
|
+
* folding a parse tree into a machine configuration. Not intended for
|
|
416
|
+
* end-user code.
|
|
417
|
+
*
|
|
418
|
+
* @internal
|
|
419
|
+
*/
|
|
231
420
|
declare type JssmCompileRule<StateType> = {
|
|
232
421
|
agg_as: string;
|
|
233
422
|
val: any;
|
|
234
423
|
};
|
|
424
|
+
/**
|
|
425
|
+
* Internal compiler intermediate: one link in a chained transition
|
|
426
|
+
* expression (an "s-expression" segment). Carries both directions of an
|
|
427
|
+
* arrow with optional per-direction action labels, probabilities, and
|
|
428
|
+
* after-times. The recursive `se` field allows the parser to chain
|
|
429
|
+
* arrows of the form `A -> B -> C`. Not intended for end-user code.
|
|
430
|
+
*
|
|
431
|
+
* @internal
|
|
432
|
+
*/
|
|
235
433
|
declare type JssmCompileSe<StateType, mDT> = {
|
|
236
434
|
to: StateType;
|
|
237
435
|
se?: JssmCompileSe<StateType, mDT>;
|
|
@@ -243,6 +441,15 @@ declare type JssmCompileSe<StateType, mDT> = {
|
|
|
243
441
|
l_after?: number;
|
|
244
442
|
r_after?: number;
|
|
245
443
|
};
|
|
444
|
+
/**
|
|
445
|
+
* Internal compiler intermediate: the root of a chained transition
|
|
446
|
+
* expression, anchored at a `from` state. Also doubles as the carrier
|
|
447
|
+
* for non-transition rules (state declarations, property definitions,
|
|
448
|
+
* machine metadata) via its `key`/`value`/`name`/`state` fields. Not
|
|
449
|
+
* intended for end-user code.
|
|
450
|
+
*
|
|
451
|
+
* @internal
|
|
452
|
+
*/
|
|
246
453
|
declare type JssmCompileSeStart<StateType, DataType> = {
|
|
247
454
|
from: StateType;
|
|
248
455
|
se: JssmCompileSe<StateType, DataType>;
|
|
@@ -253,7 +460,19 @@ declare type JssmCompileSeStart<StateType, DataType> = {
|
|
|
253
460
|
default_value?: any;
|
|
254
461
|
required?: boolean;
|
|
255
462
|
};
|
|
463
|
+
/**
|
|
464
|
+
* The output shape of the FSL parser: a flat array of
|
|
465
|
+
* {@link JssmCompileSeStart} entries, one per top-level rule in the
|
|
466
|
+
* source. Consumed by the compiler to build a machine configuration.
|
|
467
|
+
*
|
|
468
|
+
* @internal
|
|
469
|
+
*/
|
|
256
470
|
declare type JssmParseTree<StateType, mDT> = Array<JssmCompileSeStart<StateType, mDT>>;
|
|
471
|
+
/**
|
|
472
|
+
* Signature of an FSL parse function: takes a source string and returns a
|
|
473
|
+
* {@link JssmParseTree}. Used to type the parser export so consumers can
|
|
474
|
+
* swap in alternative parser implementations.
|
|
475
|
+
*/
|
|
257
476
|
declare type JssmParseFunctionType<StateType, mDT> = (string: any) => JssmParseTree<StateType, mDT>;
|
|
258
477
|
declare type BasicHookDescription<mDT> = {
|
|
259
478
|
kind: 'hook';
|
|
@@ -356,23 +575,123 @@ declare type PostExitHook<mDT> = {
|
|
|
356
575
|
from: string;
|
|
357
576
|
handler: PostHookHandler<mDT>;
|
|
358
577
|
};
|
|
359
|
-
declare type
|
|
578
|
+
declare type PreEverythingHook<mDT> = {
|
|
579
|
+
kind: 'pre everything';
|
|
580
|
+
handler: EverythingHookHandler<mDT>;
|
|
581
|
+
};
|
|
582
|
+
declare type EverythingHook<mDT> = {
|
|
583
|
+
kind: 'everything';
|
|
584
|
+
handler: EverythingHookHandler<mDT>;
|
|
585
|
+
};
|
|
586
|
+
declare type PrePostEverythingHook<mDT> = {
|
|
587
|
+
kind: 'pre post everything';
|
|
588
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
589
|
+
};
|
|
590
|
+
declare type PostEverythingHook<mDT> = {
|
|
591
|
+
kind: 'post everything';
|
|
592
|
+
handler: PostEverythingHookHandler<mDT>;
|
|
593
|
+
};
|
|
594
|
+
/**
|
|
595
|
+
* Discriminated union of every kind of hook registration jssm understands,
|
|
596
|
+
* pre-transition and post-transition. The `kind` field selects the
|
|
597
|
+
* variant; remaining fields describe which transitions / states / actions
|
|
598
|
+
* the hook is bound to and supply the {@link HookHandler} or
|
|
599
|
+
* {@link PostHookHandler} to invoke.
|
|
600
|
+
*
|
|
601
|
+
* Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
|
|
602
|
+
* `'main transition'`, `'forced transition'`, `'any transition'`,
|
|
603
|
+
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`)
|
|
604
|
+
* may return a falsy value to veto a transition. Post-transition
|
|
605
|
+
* variants (`'post *'`) cannot veto and are invoked only after a
|
|
606
|
+
* successful transition.
|
|
607
|
+
*/
|
|
608
|
+
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>;
|
|
609
|
+
/**
|
|
610
|
+
* Richer hook return value used when a hook needs to do more than just
|
|
611
|
+
* accept or veto a transition. `pass` is the required accept/veto flag
|
|
612
|
+
* (kept non-optional so that returning a stray object doesn't accidentally
|
|
613
|
+
* veto everything). The optional `state` overrides the destination state,
|
|
614
|
+
* `data` overrides the data observed by other hooks in the same chain,
|
|
615
|
+
* and `next_data` overrides the data committed after the transition.
|
|
616
|
+
*/
|
|
360
617
|
declare type HookComplexResult<mDT> = {
|
|
361
618
|
pass: boolean;
|
|
362
619
|
state?: StateType;
|
|
363
620
|
data?: mDT;
|
|
364
621
|
next_data?: mDT;
|
|
365
622
|
};
|
|
366
|
-
|
|
623
|
+
/**
|
|
624
|
+
* Return value from a {@link HookHandler}. May be a plain boolean to
|
|
625
|
+
* accept (`true`/`undefined`/`void`) or veto (`false`) the transition, or
|
|
626
|
+
* a {@link HookComplexResult} that additionally rewrites the next state
|
|
627
|
+
* and/or the next data payload.
|
|
628
|
+
*/
|
|
629
|
+
declare type HookResult<mDT> = true | false | undefined | void | HookComplexResult<mDT>;
|
|
630
|
+
/**
|
|
631
|
+
* Context object passed to every {@link HookHandler}. `data` is the
|
|
632
|
+
* data payload as it stands before the transition, and `next_data` is
|
|
633
|
+
* the payload that will be committed if the transition is accepted —
|
|
634
|
+
* handlers may inspect or mutate the latter via a
|
|
635
|
+
* {@link HookComplexResult} return value.
|
|
636
|
+
*/
|
|
367
637
|
declare type HookContext<mDT> = {
|
|
368
638
|
data: mDT;
|
|
369
639
|
next_data: mDT;
|
|
370
640
|
};
|
|
641
|
+
/**
|
|
642
|
+
* Context object passed to "everything" hooks ({@link EverythingHookHandler}
|
|
643
|
+
* and {@link PostEverythingHookHandler}). Extends the usual
|
|
644
|
+
* {@link HookContext} with `hook_name`, which identifies which specific
|
|
645
|
+
* hook fired so a single handler can route on it.
|
|
646
|
+
*/
|
|
647
|
+
declare type EverythingHookContext<mDT> = HookContext<mDT> & {
|
|
648
|
+
hook_name: string;
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* Signature of a pre-transition hook handler. Receives the current and
|
|
652
|
+
* proposed-next data payloads via a {@link HookContext} and returns a
|
|
653
|
+
* {@link HookResult}: a falsy result vetoes the transition, a truthy
|
|
654
|
+
* result allows it, and a {@link HookComplexResult} can additionally
|
|
655
|
+
* rewrite the next state or next data.
|
|
656
|
+
*/
|
|
371
657
|
declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
|
|
658
|
+
/**
|
|
659
|
+
* Signature of a post-transition hook handler. Invoked after a successful
|
|
660
|
+
* transition has been committed; the return value is ignored (the
|
|
661
|
+
* transition cannot be undone).
|
|
662
|
+
*/
|
|
372
663
|
declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
|
|
664
|
+
/**
|
|
665
|
+
* Signature of an "everything" pre-transition hook handler. Like
|
|
666
|
+
* {@link HookHandler} but receives an {@link EverythingHookContext} so the
|
|
667
|
+
* handler can dispatch on `hook_name`.
|
|
668
|
+
*/
|
|
669
|
+
declare type EverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => HookResult<mDT>;
|
|
670
|
+
/**
|
|
671
|
+
* Signature of an "everything" post-transition hook handler. Like
|
|
672
|
+
* {@link PostHookHandler} but receives an {@link EverythingHookContext}.
|
|
673
|
+
* The return value is ignored.
|
|
674
|
+
*/
|
|
675
|
+
declare type PostEverythingHookHandler<mDT> = (hook_context: EverythingHookContext<mDT>) => void;
|
|
676
|
+
/**
|
|
677
|
+
* Extra diagnostic information attached to a {@link JssmError} when it
|
|
678
|
+
* carries machine-relative context — most often the state name a caller
|
|
679
|
+
* asked about when the error was raised.
|
|
680
|
+
*/
|
|
373
681
|
declare type JssmErrorExtendedInfo = {
|
|
374
682
|
requested_state?: StateType | undefined;
|
|
375
683
|
};
|
|
684
|
+
/**
|
|
685
|
+
* Bounded history of recently-visited states paired with the data payload
|
|
686
|
+
* observed in each. Backed by `circular_buffer_js`, so the oldest entry
|
|
687
|
+
* is dropped silently once the configured capacity is exceeded.
|
|
688
|
+
*/
|
|
376
689
|
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
|
|
690
|
+
/**
|
|
691
|
+
* Pluggable random-number-generator function shape. Must return a value
|
|
692
|
+
* in `[0, 1)` exactly as `Math.random` does. Supplied via the
|
|
693
|
+
* `rng_seed`-aware machine configuration so that stochastic models can be
|
|
694
|
+
* made reproducible.
|
|
695
|
+
*/
|
|
377
696
|
declare type JssmRng = () => number;
|
|
378
|
-
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng };
|
|
697
|
+
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, EverythingHookContext, EverythingHookHandler, PostEverythingHookHandler, JssmRng };
|