jssm 5.61.3 → 5.63.0
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/README.md +33 -12
- package/dist/es6/jssm.d.ts +5 -2
- package/dist/es6/jssm.js +47 -36
- package/dist/es6/jssm_error.d.ts +8 -0
- package/dist/es6/jssm_error.js +28 -0
- package/dist/es6/jssm_types.d.ts +5 -1
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +5 -2
- package/jssm_error.d.ts +8 -0
- package/jssm_types.d.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,18 +42,39 @@ log( TrafficLight.state() ); // 'Green'
|
|
|
42
42
|
What if the notation supported action names easily?
|
|
43
43
|
|
|
44
44
|
```javascript
|
|
45
|
-
const
|
|
45
|
+
const TLWA = sm`Red 'next' -> Green 'next' -> Yellow 'next' -> Red;`; // TLWA = Traffic Light With Actions
|
|
46
46
|
|
|
47
|
-
log(
|
|
47
|
+
log( TLWA.state() ); // 'Red'
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
log(
|
|
49
|
+
TLWA.action('next'); // true
|
|
50
|
+
log( TLWA.state() ); // 'Green'
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
log(
|
|
52
|
+
TLWA.action('next'); // true
|
|
53
|
+
log( TLWA.state() ); // 'Yellow'
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
log(
|
|
55
|
+
TLWA.action('next'); // true
|
|
56
|
+
log( TLWA.state() ); // 'Red'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
<br/>
|
|
60
|
+
|
|
61
|
+
What if integration with the outside was straightforward?
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
const MTL = sm`Red 'next' -> Green 'next' -> Yellow 'next' -> Red;` // MTL = More Traffic Lights
|
|
65
|
+
.hook('Red', 'Green', () => log('GO GO GO') ) // node will jump the gun when you hit return, though
|
|
66
|
+
.hook_entry('Red', () => log('STOP') ); // so put it on one line in node
|
|
67
|
+
|
|
68
|
+
log( MTL.state() ); // 'Red'
|
|
69
|
+
|
|
70
|
+
TLWA.action('next'); // true, console logs 'GO GO GO'
|
|
71
|
+
log( TLWA.state() ); // 'Green'
|
|
72
|
+
|
|
73
|
+
TLWA.action('next'); // true
|
|
74
|
+
log( TLWA.state() ); // 'Yellow'
|
|
75
|
+
|
|
76
|
+
TLWA.action('next'); // true, console logs 'STOP'
|
|
77
|
+
log( TLWA.state() ); // 'Red'
|
|
57
78
|
```
|
|
58
79
|
|
|
59
80
|
<br/>
|
|
@@ -61,11 +82,11 @@ log( TrafficLightWithActions.state() ); // 'Red'
|
|
|
61
82
|
What if the machine followed JS standards, and distinguished refusals as `false` from mistakes as `throw`n?
|
|
62
83
|
|
|
63
84
|
```javascript
|
|
64
|
-
const
|
|
85
|
+
const ATL = sm`Red -> Green -> Yellow -> Red;`; // ATL = Another Traffic Light
|
|
65
86
|
|
|
66
|
-
log(
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
log( ATL.state() ); // 'Red' - uses 1st state unless told otherwise
|
|
88
|
+
ATL.transition('Yellow'); // false (Yellow isn't allowed from Red)
|
|
89
|
+
ATL.transition('Blue'); // throws (Blue isn't a state at all)
|
|
69
90
|
```
|
|
70
91
|
|
|
71
92
|
<br/>
|
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ declare class Machine<mDT> {
|
|
|
30
30
|
_fsl_version?: string;
|
|
31
31
|
_raw_state_declaration?: Array<Object>;
|
|
32
32
|
_state_declarations: Map<StateType, JssmStateDeclaration>;
|
|
33
|
+
_instance_name: string;
|
|
33
34
|
_graph_layout: JssmLayout;
|
|
34
35
|
_dot_preamble: string;
|
|
35
36
|
_arrange_declaration: Array<Array<StateType>>;
|
|
@@ -54,7 +55,7 @@ declare class Machine<mDT> {
|
|
|
54
55
|
_main_transition_hook: HookHandler | undefined;
|
|
55
56
|
_forced_transition_hook: HookHandler | undefined;
|
|
56
57
|
_any_transition_hook: HookHandler | undefined;
|
|
57
|
-
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>);
|
|
58
|
+
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, instance_name }: JssmGenericConfig<mDT>);
|
|
58
59
|
_new_state(state_config: JssmGenericState): StateType;
|
|
59
60
|
state(): StateType;
|
|
60
61
|
state_is_final(whichState: StateType): boolean;
|
|
@@ -124,7 +125,9 @@ declare class Machine<mDT> {
|
|
|
124
125
|
valid_action(action: StateType, _newData?: mDT): boolean;
|
|
125
126
|
valid_transition(newState: StateType, _newData?: mDT): boolean;
|
|
126
127
|
valid_force_transition(newState: StateType, _newData?: mDT): boolean;
|
|
128
|
+
instance_name(): string | undefined;
|
|
127
129
|
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
128
130
|
}
|
|
129
131
|
declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
130
|
-
|
|
132
|
+
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
|
|
133
|
+
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key };
|
package/dist/es6/jssm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// whargarbl lots of these return arrays could/should be sets
|
|
2
2
|
import { reduce as reduce_to_639 } from 'reduce-to-639-1';
|
|
3
3
|
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, array_box_if_string, hook_name, named_hook_name } from './jssm_util';
|
|
4
|
-
import { parse } from './jssm-dot';
|
|
4
|
+
import { parse } from './jssm-dot';
|
|
5
5
|
import { version } from './version'; // replaced from package.js in build
|
|
6
|
+
import { JssmError } from './jssm_error';
|
|
6
7
|
/* eslint-disable complexity */
|
|
7
8
|
function arrow_direction(arrow) {
|
|
8
9
|
switch (String(arrow)) {
|
|
@@ -52,7 +53,7 @@ function arrow_direction(arrow) {
|
|
|
52
53
|
case '<~⇒':
|
|
53
54
|
return 'both';
|
|
54
55
|
default:
|
|
55
|
-
throw new
|
|
56
|
+
throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
/* eslint-enable complexity */
|
|
@@ -94,7 +95,7 @@ function arrow_left_kind(arrow) {
|
|
|
94
95
|
case '↚⇒':
|
|
95
96
|
return 'forced';
|
|
96
97
|
default:
|
|
97
|
-
throw new
|
|
98
|
+
throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
/* eslint-enable complexity */
|
|
@@ -136,7 +137,7 @@ function arrow_right_kind(arrow) {
|
|
|
136
137
|
case '⇐↛':
|
|
137
138
|
return 'forced';
|
|
138
139
|
default:
|
|
139
|
-
throw new
|
|
140
|
+
throw new JssmError(undefined, `arrow_direction: unknown arrow type ${arrow}`);
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
/* eslint-enable complexity */
|
|
@@ -148,13 +149,13 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
|
|
|
148
149
|
forced_only: kind === 'forced',
|
|
149
150
|
main_path: kind === 'main'
|
|
150
151
|
};
|
|
151
|
-
// if ((wasList !== undefined) && (wasIndex === undefined)) { throw new
|
|
152
|
-
// if ((wasIndex !== undefined) && (wasList === undefined)) { throw new
|
|
152
|
+
// if ((wasList !== undefined) && (wasIndex === undefined)) { throw new JssmError(undefined, `Must have an index if transition was in a list"); }
|
|
153
|
+
// if ((wasIndex !== undefined) && (wasList === undefined)) { throw new JssmError(undefined, `Must be in a list if transition has an index"); }
|
|
153
154
|
/*
|
|
154
155
|
if (typeof edge.to === 'object') {
|
|
155
156
|
|
|
156
157
|
if (edge.to.key === 'cycle') {
|
|
157
|
-
if (wasList === undefined) { throw "Must have a waslist if a to is type cycle"; }
|
|
158
|
+
if (wasList === undefined) { throw new JssmError(undefined, "Must have a waslist if a to is type cycle"); }
|
|
158
159
|
const nextIndex = wrapBy(wasIndex, edge.to.value, wasList.length);
|
|
159
160
|
edge.to = wasList[nextIndex];
|
|
160
161
|
}
|
|
@@ -208,7 +209,7 @@ function compile_rule_handler(rule) {
|
|
|
208
209
|
}
|
|
209
210
|
if (rule.key === 'state_declaration') {
|
|
210
211
|
if (!rule.name) {
|
|
211
|
-
throw new
|
|
212
|
+
throw new JssmError(undefined, 'State declarations must have a name');
|
|
212
213
|
}
|
|
213
214
|
return { agg_as: 'state_declaration', val: { state: rule.name, declarations: rule.value } };
|
|
214
215
|
}
|
|
@@ -225,7 +226,7 @@ function compile_rule_handler(rule) {
|
|
|
225
226
|
if (tautologies.includes(rule.key)) {
|
|
226
227
|
return { agg_as: rule.key, val: rule.value };
|
|
227
228
|
}
|
|
228
|
-
throw new
|
|
229
|
+
throw new JssmError(undefined, `compile_rule_handler: Unknown rule: ${JSON.stringify(rule)}`);
|
|
229
230
|
}
|
|
230
231
|
function compile(tree) {
|
|
231
232
|
const results = {
|
|
@@ -268,7 +269,7 @@ function compile(tree) {
|
|
|
268
269
|
];
|
|
269
270
|
oneOnlyKeys.map((oneOnlyKey) => {
|
|
270
271
|
if (results[oneOnlyKey].length > 1) {
|
|
271
|
-
throw new
|
|
272
|
+
throw new JssmError(undefined, `May only have one ${oneOnlyKey} statement maximum: ${JSON.stringify(results[oneOnlyKey])}`);
|
|
272
273
|
}
|
|
273
274
|
else {
|
|
274
275
|
if (results[oneOnlyKey].length) {
|
|
@@ -311,14 +312,15 @@ function transfer_state_properties(state_decl) {
|
|
|
311
312
|
case 'border-color':
|
|
312
313
|
state_decl.borderColor = d.value;
|
|
313
314
|
break;
|
|
314
|
-
default: throw new
|
|
315
|
+
default: throw new JssmError(undefined, `Unknown state property: '${JSON.stringify(d)}'`);
|
|
315
316
|
}
|
|
316
317
|
});
|
|
317
318
|
return state_decl;
|
|
318
319
|
}
|
|
319
320
|
class Machine {
|
|
320
321
|
// whargarbl this badly needs to be broken up, monolith master
|
|
321
|
-
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 = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = 'default', flow = 'down', graph_layout = 'dot' }) {
|
|
322
|
+
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 = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = 'default', flow = 'down', graph_layout = 'dot', instance_name }) {
|
|
323
|
+
this._instance_name = instance_name;
|
|
322
324
|
this._state = start_states[0];
|
|
323
325
|
this._states = new Map();
|
|
324
326
|
this._state_declarations = new Map();
|
|
@@ -367,17 +369,17 @@ class Machine {
|
|
|
367
369
|
if (state_declaration) {
|
|
368
370
|
state_declaration.map((state_decl) => {
|
|
369
371
|
if (this._state_declarations.has(state_decl.state)) { // no repeats
|
|
370
|
-
throw new
|
|
372
|
+
throw new JssmError(this, `Added the same state declaration twice: ${JSON.stringify(state_decl.state)}`);
|
|
371
373
|
}
|
|
372
374
|
this._state_declarations.set(state_decl.state, transfer_state_properties(state_decl));
|
|
373
375
|
});
|
|
374
376
|
}
|
|
375
377
|
transitions.map((tr) => {
|
|
376
378
|
if (tr.from === undefined) {
|
|
377
|
-
throw new
|
|
379
|
+
throw new JssmError(this, `transition must define 'from': ${JSON.stringify(tr)}`);
|
|
378
380
|
}
|
|
379
381
|
if (tr.to === undefined) {
|
|
380
|
-
throw new
|
|
382
|
+
throw new JssmError(this, `transition must define 'to': ${JSON.stringify(tr)}`);
|
|
381
383
|
}
|
|
382
384
|
// get the cursors. what a mess
|
|
383
385
|
const cursor_from = this._states.get(tr.from)
|
|
@@ -392,7 +394,7 @@ class Machine {
|
|
|
392
394
|
}
|
|
393
395
|
// guard against existing connections being re-added
|
|
394
396
|
if (cursor_from.to.includes(tr.to)) {
|
|
395
|
-
throw new
|
|
397
|
+
throw new JssmError(this, `already has ${JSON.stringify(tr.from)} to ${JSON.stringify(tr.to)}`);
|
|
396
398
|
}
|
|
397
399
|
else {
|
|
398
400
|
cursor_from.to.push(tr.to);
|
|
@@ -404,7 +406,7 @@ class Machine {
|
|
|
404
406
|
// guard against repeating a transition name
|
|
405
407
|
if (tr.name) {
|
|
406
408
|
if (this._named_transitions.has(tr.name)) {
|
|
407
|
-
throw new
|
|
409
|
+
throw new JssmError(this, `named transition "${JSON.stringify(tr.name)}" already created`);
|
|
408
410
|
}
|
|
409
411
|
else {
|
|
410
412
|
this._named_transitions.set(tr.name, thisEdgeId);
|
|
@@ -426,7 +428,7 @@ class Machine {
|
|
|
426
428
|
this._actions.set(tr.action, actionMap);
|
|
427
429
|
}
|
|
428
430
|
if (actionMap.has(tr.from)) {
|
|
429
|
-
throw new
|
|
431
|
+
throw new JssmError(this, `action ${JSON.stringify(tr.action)} already attached to origin ${JSON.stringify(tr.from)}`);
|
|
430
432
|
}
|
|
431
433
|
else {
|
|
432
434
|
actionMap.set(tr.from, thisEdgeId);
|
|
@@ -449,12 +451,12 @@ class Machine {
|
|
|
449
451
|
const roActionMap = this._reverse_action_targets.get(tr.to); // wasteful - already did has - refactor
|
|
450
452
|
if (roActionMap) {
|
|
451
453
|
if (roActionMap.has(tr.action)) {
|
|
452
|
-
throw new
|
|
454
|
+
throw new JssmError(this, `ro-action ${tr.to} already attached to action ${tr.action}`);
|
|
453
455
|
} else {
|
|
454
456
|
roActionMap.set(tr.action, thisEdgeId);
|
|
455
457
|
}
|
|
456
458
|
} else {
|
|
457
|
-
throw new
|
|
459
|
+
throw new JssmError(this, `should be impossible - flow doesn\'t know .set precedes .get yet again. severe error?');
|
|
458
460
|
}
|
|
459
461
|
*/
|
|
460
462
|
}
|
|
@@ -462,7 +464,7 @@ class Machine {
|
|
|
462
464
|
}
|
|
463
465
|
_new_state(state_config) {
|
|
464
466
|
if (this._states.has(state_config.name)) {
|
|
465
|
-
throw new
|
|
467
|
+
throw new JssmError(this, `state ${JSON.stringify(state_config.name)} already exists`);
|
|
466
468
|
}
|
|
467
469
|
this._states.set(state_config.name, state_config);
|
|
468
470
|
return state_config.name;
|
|
@@ -534,7 +536,7 @@ class Machine {
|
|
|
534
536
|
edges: this._edges,
|
|
535
537
|
named_transitions: this._named_transitions,
|
|
536
538
|
reverse_actions: this._reverse_actions,
|
|
537
|
-
//
|
|
539
|
+
// reverse_action_targets : this._reverse_action_targets,
|
|
538
540
|
state: this._state,
|
|
539
541
|
states: this._states
|
|
540
542
|
};
|
|
@@ -553,7 +555,7 @@ class Machine {
|
|
|
553
555
|
return state;
|
|
554
556
|
}
|
|
555
557
|
else {
|
|
556
|
-
throw new
|
|
558
|
+
throw new JssmError(this, 'No such state', { requested_state: whichState });
|
|
557
559
|
}
|
|
558
560
|
}
|
|
559
561
|
has_state(whichState) {
|
|
@@ -603,7 +605,7 @@ class Machine {
|
|
|
603
605
|
probable_exits_for(whichState) {
|
|
604
606
|
const wstate = this._states.get(whichState);
|
|
605
607
|
if (!(wstate)) {
|
|
606
|
-
throw new
|
|
608
|
+
throw new JssmError(this, `No such state ${JSON.stringify(whichState)} in probable_exits_for`);
|
|
607
609
|
}
|
|
608
610
|
const wstate_to = wstate.to, wtf = wstate_to
|
|
609
611
|
.map((ws) => this.lookup_transition_for(this.state(), ws))
|
|
@@ -632,7 +634,7 @@ class Machine {
|
|
|
632
634
|
return Array.from(wstate.keys());
|
|
633
635
|
}
|
|
634
636
|
else {
|
|
635
|
-
throw new
|
|
637
|
+
throw new JssmError(this, `No such state ${JSON.stringify(whichState)}`);
|
|
636
638
|
}
|
|
637
639
|
}
|
|
638
640
|
list_states_having_action(whichState) {
|
|
@@ -641,7 +643,7 @@ class Machine {
|
|
|
641
643
|
return Array.from(wstate.keys());
|
|
642
644
|
}
|
|
643
645
|
else {
|
|
644
|
-
throw new
|
|
646
|
+
throw new JssmError(this, `No such state ${JSON.stringify(whichState)}`);
|
|
645
647
|
}
|
|
646
648
|
}
|
|
647
649
|
// comeback
|
|
@@ -656,7 +658,7 @@ class Machine {
|
|
|
656
658
|
list_exit_actions(whichState = this.state()) {
|
|
657
659
|
const ra_base = this._reverse_actions.get(whichState);
|
|
658
660
|
if (!(ra_base)) {
|
|
659
|
-
throw new
|
|
661
|
+
throw new JssmError(this, `No such state ${JSON.stringify(whichState)}`);
|
|
660
662
|
}
|
|
661
663
|
return Array.from(ra_base.values())
|
|
662
664
|
.map((edgeId) => this._edges[edgeId])
|
|
@@ -666,7 +668,7 @@ class Machine {
|
|
|
666
668
|
probable_action_exits(whichState = this.state()) {
|
|
667
669
|
const ra_base = this._reverse_actions.get(whichState);
|
|
668
670
|
if (!(ra_base)) {
|
|
669
|
-
throw new
|
|
671
|
+
throw new JssmError(this, `No such state ${JSON.stringify(whichState)}`);
|
|
670
672
|
}
|
|
671
673
|
return Array.from(ra_base.values())
|
|
672
674
|
.map((edgeId) => this._edges[edgeId])
|
|
@@ -679,7 +681,7 @@ class Machine {
|
|
|
679
681
|
// TODO FIXME test that is_unenterable on non-state throws
|
|
680
682
|
is_unenterable(whichState) {
|
|
681
683
|
if (!(this.has_state(whichState))) {
|
|
682
|
-
throw new
|
|
684
|
+
throw new JssmError(this, `No such state ${whichState}`);
|
|
683
685
|
}
|
|
684
686
|
return this.list_entrances(whichState).length === 0;
|
|
685
687
|
}
|
|
@@ -692,7 +694,7 @@ class Machine {
|
|
|
692
694
|
// TODO FIXME test that state_is_terminal on non-state throws
|
|
693
695
|
state_is_terminal(whichState) {
|
|
694
696
|
if (!(this.has_state(whichState))) {
|
|
695
|
-
throw new
|
|
697
|
+
throw new JssmError(this, `No such state ${whichState}`);
|
|
696
698
|
}
|
|
697
699
|
return this.list_exits(whichState).length === 0;
|
|
698
700
|
}
|
|
@@ -708,7 +710,7 @@ class Machine {
|
|
|
708
710
|
return wstate.complete;
|
|
709
711
|
}
|
|
710
712
|
else {
|
|
711
|
-
throw new
|
|
713
|
+
throw new JssmError(this, `No such state ${JSON.stringify(whichState)}`);
|
|
712
714
|
}
|
|
713
715
|
}
|
|
714
716
|
has_completes() {
|
|
@@ -767,8 +769,7 @@ class Machine {
|
|
|
767
769
|
this._has_exit_hooks = true;
|
|
768
770
|
break;
|
|
769
771
|
default:
|
|
770
|
-
|
|
771
|
-
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
|
|
772
|
+
throw new JssmError(this, `Unknown hook type ${HookDesc.kind}, should be impossible`);
|
|
772
773
|
}
|
|
773
774
|
}
|
|
774
775
|
hook(from, to, handler) {
|
|
@@ -822,7 +823,7 @@ class Machine {
|
|
|
822
823
|
return this;
|
|
823
824
|
}
|
|
824
825
|
// remove_hook(HookDesc: HookDescription) {
|
|
825
|
-
// throw 'TODO: Should remove hook here';
|
|
826
|
+
// throw new JssmError(this, 'TODO: Should remove hook here');
|
|
826
827
|
// }
|
|
827
828
|
edges_between(from, to) {
|
|
828
829
|
return this._edges.filter(edge => ((edge.from === from) && (edge.to === to)));
|
|
@@ -982,7 +983,7 @@ class Machine {
|
|
|
982
983
|
current_action_edge_for(action) {
|
|
983
984
|
const idx = this.current_action_for(action);
|
|
984
985
|
if ((idx === undefined) || (idx === null)) {
|
|
985
|
-
throw new
|
|
986
|
+
throw new JssmError(this, `No such action ${JSON.stringify(action)}`);
|
|
986
987
|
}
|
|
987
988
|
return this._edges[idx];
|
|
988
989
|
}
|
|
@@ -1008,6 +1009,9 @@ class Machine {
|
|
|
1008
1009
|
// todo major incomplete whargarbl comeback
|
|
1009
1010
|
return (this.lookup_transition_for(this.state(), newState) !== undefined);
|
|
1010
1011
|
}
|
|
1012
|
+
instance_name() {
|
|
1013
|
+
return this._instance_name;
|
|
1014
|
+
}
|
|
1011
1015
|
/* eslint-disable no-use-before-define */
|
|
1012
1016
|
/* eslint-disable class-methods-use-this */
|
|
1013
1017
|
sm(template_strings, ...remainder /* , arguments */) {
|
|
@@ -1027,6 +1031,13 @@ function sm(template_strings, ...remainder /* , arguments */) {
|
|
|
1027
1031
|
/* eslint-enable prefer-rest-params */
|
|
1028
1032
|
)));
|
|
1029
1033
|
}
|
|
1030
|
-
|
|
1034
|
+
function from(MachineAsString, ExtraConstructorFields) {
|
|
1035
|
+
const to_decorate = make(MachineAsString);
|
|
1036
|
+
if (ExtraConstructorFields !== undefined) {
|
|
1037
|
+
Object.keys(ExtraConstructorFields).map(key => to_decorate[key] = ExtraConstructorFields[key]);
|
|
1038
|
+
}
|
|
1039
|
+
return new Machine(to_decorate);
|
|
1040
|
+
}
|
|
1041
|
+
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind,
|
|
1031
1042
|
// WHARGARBL TODO these should be exported to a utility library
|
|
1032
1043
|
seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JssmErrorExtendedInfo } from './jssm_types';
|
|
2
|
+
declare class JssmError extends Error {
|
|
3
|
+
message: string;
|
|
4
|
+
base_message: string;
|
|
5
|
+
requested_state: string | undefined;
|
|
6
|
+
constructor(machine: any, message: string, JEEI?: JssmErrorExtendedInfo);
|
|
7
|
+
}
|
|
8
|
+
export { JssmError };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class JssmError extends Error {
|
|
2
|
+
constructor(machine, message, JEEI) {
|
|
3
|
+
const { requested_state } = (JEEI === undefined)
|
|
4
|
+
? { requested_state: undefined }
|
|
5
|
+
: JEEI;
|
|
6
|
+
const follow_ups = [];
|
|
7
|
+
if (machine) {
|
|
8
|
+
if (machine.state() !== undefined) {
|
|
9
|
+
follow_ups.push(`at "${machine.state()}"`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (requested_state !== undefined) {
|
|
13
|
+
follow_ups.push(`requested "${requested_state}"`);
|
|
14
|
+
}
|
|
15
|
+
const complex_msg = `${((machine === null || machine === void 0 ? void 0 : machine.instance_name()) !== undefined)
|
|
16
|
+
? `[[${machine.instance_name()}]]: `
|
|
17
|
+
: ''}${message}${follow_ups.length
|
|
18
|
+
? ` (${follow_ups.join(', ')})`
|
|
19
|
+
: ''}`;
|
|
20
|
+
super(complex_msg);
|
|
21
|
+
this.name = 'JssmError';
|
|
22
|
+
this.message = complex_msg;
|
|
23
|
+
this.base_message = message;
|
|
24
|
+
this.requested_state = requested_state;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
export { JssmError };
|
package/dist/es6/jssm_types.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ declare type JssmGenericConfig<DataType> = {
|
|
|
125
125
|
machine_version?: string;
|
|
126
126
|
fsl_version?: string;
|
|
127
127
|
auto_api?: boolean | string;
|
|
128
|
+
instance_name?: string | undefined;
|
|
128
129
|
};
|
|
129
130
|
declare type JssmCompileRule = {
|
|
130
131
|
agg_as: string;
|
|
@@ -198,4 +199,7 @@ declare type ExitHook = {
|
|
|
198
199
|
handler: HookHandler;
|
|
199
200
|
};
|
|
200
201
|
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | StandardTransitionHook | MainTransitionHook | ForcedTransitionHook | AnyTransitionHook | EntryHook | ExitHook;
|
|
201
|
-
|
|
202
|
+
declare type JssmErrorExtendedInfo = {
|
|
203
|
+
requested_state?: StateType | undefined;
|
|
204
|
+
};
|
|
205
|
+
export { JssmColor, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler };
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.63.0";
|
|
2
2
|
export { version };
|