jssm 5.72.0 → 5.72.3

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- 918 merges; 114 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
5
+ 922 merges; 114 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
6
6
 
7
7
 
8
8
 
@@ -22,13 +22,13 @@ Published tags:
22
22
 
23
23
   
24
24
 
25
- ## [Untagged] - 6/23/2022 6:34:38 PM
25
+ ## [Untagged] - 6/24/2022 7:36:27 PM
26
26
 
27
- Commit [1dc7c24bfb651eec57fddc902f78db796f71a6c5](https://github.com/StoneCypher/jssm/commit/1dc7c24bfb651eec57fddc902f78db796f71a6c5)
27
+ Commit [adfa9069ba5e78d8a227896a5f7e14a8f4b80117](https://github.com/StoneCypher/jssm/commit/adfa9069ba5e78d8a227896a5f7e14a8f4b80117)
28
28
 
29
29
  Author: `John Haugeland <stonecypher@gmail.com>`
30
30
 
31
- * Small documentation tweaks. First attempt to lodge on deno.land
31
+ * the conversion continues
32
32
 
33
33
 
34
34
 
@@ -37,13 +37,13 @@ Author: `John Haugeland <stonecypher@gmail.com>`
37
37
 
38
38
  &nbsp;
39
39
 
40
- ## [Untagged] - 6/23/2022 1:41:18 PM
40
+ ## [Untagged] - 6/24/2022 5:49:06 PM
41
41
 
42
- Commit [67c3240798d31933413aab27db7ea9fbb5de3b2a](https://github.com/StoneCypher/jssm/commit/67c3240798d31933413aab27db7ea9fbb5de3b2a)
42
+ Commit [b0cbe1c1ae0199c8d78a82f624e8ee94b344cf71](https://github.com/StoneCypher/jssm/commit/b0cbe1c1ae0199c8d78a82f624e8ee94b344cf71)
43
43
 
44
44
  Author: `John Haugeland <stonecypher@gmail.com>`
45
45
 
46
- * Normalize arguments to hooks, fixes StoneCypher/fsl#895; more docs
46
+ * Normalize hook return pattern, fixes StoneCypher/fsl#930
47
47
 
48
48
 
49
49
 
@@ -52,15 +52,13 @@ Author: `John Haugeland <stonecypher@gmail.com>`
52
52
 
53
53
  &nbsp;
54
54
 
55
- <a name="5__70__36" />
55
+ ## [Untagged] - 6/24/2022 4:55:33 PM
56
56
 
57
- ## [5.70.36] - 6/21/2022 6:53:36 PM
58
-
59
- Commit [093db23b719161e35e477cc0fe7d9f1132bc28b8](https://github.com/StoneCypher/jssm/commit/093db23b719161e35e477cc0fe7d9f1132bc28b8)
57
+ Commit [547e35599ed312bf5300d3f1685e2cb16b80a73e](https://github.com/StoneCypher/jssm/commit/547e35599ed312bf5300d3f1685e2cb16b80a73e)
60
58
 
61
59
  Author: `John Haugeland <stonecypher@gmail.com>`
62
60
 
63
- * Another trivial build - this one to cause chain publishment
61
+ * Can read data from outside, fixes StoneCypher/fsl#929
64
62
 
65
63
 
66
64
 
@@ -69,15 +67,13 @@ Author: `John Haugeland <stonecypher@gmail.com>`
69
67
 
70
68
  &nbsp;
71
69
 
72
- <a name="5__70__35" />
73
-
74
- ## [5.70.35] - 6/19/2022 10:56:41 AM
70
+ ## [Untagged] - 6/24/2022 4:08:35 PM
75
71
 
76
- Commit [13ee9eb71ca9ab868699e535abf6ba30c8ad5829](https://github.com/StoneCypher/jssm/commit/13ee9eb71ca9ab868699e535abf6ba30c8ad5829)
72
+ Commit [a1c43e9f65f2fd8e856a2544f7c3056b4c06d9d3](https://github.com/StoneCypher/jssm/commit/a1c43e9f65f2fd8e856a2544f7c3056b4c06d9d3)
77
73
 
78
74
  Author: `John Haugeland <stonecypher@gmail.com>`
79
75
 
80
- * new trigger with replaced token - this time with a bump
76
+ * First steps towards being a Moore machine - initial data in constructor fixes StoneCypher/fsl#923 , can read in hooks fixes StoneCypher/fsl#924
81
77
 
82
78
 
83
79
 
@@ -86,13 +82,13 @@ Author: `John Haugeland <stonecypher@gmail.com>`
86
82
 
87
83
  &nbsp;
88
84
 
89
- ## [Untagged] - 6/19/2022 10:37:04 AM
85
+ ## [Untagged] - 6/23/2022 6:34:38 PM
90
86
 
91
- Commit [b3e69d9745b92d845bedcfbc08f342997137af3d](https://github.com/StoneCypher/jssm/commit/b3e69d9745b92d845bedcfbc08f342997137af3d)
87
+ Commit [1dc7c24bfb651eec57fddc902f78db796f71a6c5](https://github.com/StoneCypher/jssm/commit/1dc7c24bfb651eec57fddc902f78db796f71a6c5)
92
88
 
93
89
  Author: `John Haugeland <stonecypher@gmail.com>`
94
90
 
95
- * new trigger with replaced token
91
+ * Small documentation tweaks. First attempt to lodge on deno.land
96
92
 
97
93
 
98
94
 
@@ -101,15 +97,13 @@ Author: `John Haugeland <stonecypher@gmail.com>`
101
97
 
102
98
  &nbsp;
103
99
 
104
- <a name="5__70__34" />
105
-
106
- ## [5.70.34] - 6/18/2022 9:40:31 PM
100
+ ## [Untagged] - 6/23/2022 1:41:18 PM
107
101
 
108
- Commit [a0f295f060c7f08a8b10b2208dd1c95dc7f3c97a](https://github.com/StoneCypher/jssm/commit/a0f295f060c7f08a8b10b2208dd1c95dc7f3c97a)
102
+ Commit [67c3240798d31933413aab27db7ea9fbb5de3b2a](https://github.com/StoneCypher/jssm/commit/67c3240798d31933413aab27db7ea9fbb5de3b2a)
109
103
 
110
104
  Author: `John Haugeland <stonecypher@gmail.com>`
111
105
 
112
- * another trigger commit with mild doc extension
106
+ * Normalize arguments to hooks, fixes StoneCypher/fsl#895; more docs
113
107
 
114
108
 
115
109
 
@@ -118,15 +112,15 @@ Author: `John Haugeland <stonecypher@gmail.com>`
118
112
 
119
113
  &nbsp;
120
114
 
121
- <a name="5__70__33" />
115
+ <a name="5__70__36" />
122
116
 
123
- ## [5.70.33] - 6/18/2022 8:57:42 PM
117
+ ## [5.70.36] - 6/21/2022 6:53:36 PM
124
118
 
125
- Commit [ca254f455f2c19f21e77834e993c310e05272822](https://github.com/StoneCypher/jssm/commit/ca254f455f2c19f21e77834e993c310e05272822)
119
+ Commit [093db23b719161e35e477cc0fe7d9f1132bc28b8](https://github.com/StoneCypher/jssm/commit/093db23b719161e35e477cc0fe7d9f1132bc28b8)
126
120
 
127
121
  Author: `John Haugeland <stonecypher@gmail.com>`
128
122
 
129
- * holy another facile build for triggering, batman
123
+ * Another trivial build - this one to cause chain publishment
130
124
 
131
125
 
132
126
 
@@ -135,15 +129,15 @@ Author: `John Haugeland <stonecypher@gmail.com>`
135
129
 
136
130
  &nbsp;
137
131
 
138
- <a name="5__70__32" />
132
+ <a name="5__70__35" />
139
133
 
140
- ## [5.70.32] - 6/18/2022 8:48:07 PM
134
+ ## [5.70.35] - 6/19/2022 10:56:41 AM
141
135
 
142
- Commit [8115e8b62d8ac1cff3c7eb07afabced097f1be42](https://github.com/StoneCypher/jssm/commit/8115e8b62d8ac1cff3c7eb07afabced097f1be42)
136
+ Commit [13ee9eb71ca9ab868699e535abf6ba30c8ad5829](https://github.com/StoneCypher/jssm/commit/13ee9eb71ca9ab868699e535abf6ba30c8ad5829)
143
137
 
144
138
  Author: `John Haugeland <stonecypher@gmail.com>`
145
139
 
146
- * yet another small commit as a trigger, this time to get the extended diff
140
+ * new trigger with replaced token - this time with a bump
147
141
 
148
142
 
149
143
 
@@ -152,15 +146,13 @@ Author: `John Haugeland <stonecypher@gmail.com>`
152
146
 
153
147
  &nbsp;
154
148
 
155
- <a name="5__70__31" />
156
-
157
- ## [5.70.31] - 6/18/2022 8:00:06 PM
149
+ ## [Untagged] - 6/19/2022 10:37:04 AM
158
150
 
159
- Commit [de3d8a105aa85045a9f19ed46b4b3c5e5fb1e235](https://github.com/StoneCypher/jssm/commit/de3d8a105aa85045a9f19ed46b4b3c5e5fb1e235)
151
+ Commit [b3e69d9745b92d845bedcfbc08f342997137af3d](https://github.com/StoneCypher/jssm/commit/b3e69d9745b92d845bedcfbc08f342997137af3d)
160
152
 
161
153
  Author: `John Haugeland <stonecypher@gmail.com>`
162
154
 
163
- * another small commit as a trigger, this time to get the diff
155
+ * new trigger with replaced token
164
156
 
165
157
 
166
158
 
@@ -169,12 +161,12 @@ Author: `John Haugeland <stonecypher@gmail.com>`
169
161
 
170
162
  &nbsp;
171
163
 
172
- <a name="5__70__30" />
164
+ <a name="5__70__34" />
173
165
 
174
- ## [5.70.30] - 6/18/2022 10:54:02 AM
166
+ ## [5.70.34] - 6/18/2022 9:40:31 PM
175
167
 
176
- Commit [3211f94bb943a63ae07f202eb168916d73f94f90](https://github.com/StoneCypher/jssm/commit/3211f94bb943a63ae07f202eb168916d73f94f90)
168
+ Commit [a0f295f060c7f08a8b10b2208dd1c95dc7f3c97a](https://github.com/StoneCypher/jssm/commit/a0f295f060c7f08a8b10b2208dd1c95dc7f3c97a)
177
169
 
178
170
  Author: `John Haugeland <stonecypher@gmail.com>`
179
171
 
180
- * missing closing div tag was breaking examples page
172
+ * another trigger commit with mild doc extension
@@ -1,6 +1,6 @@
1
1
  declare type StateType = string;
2
2
  import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3
- JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
3
+ JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookResult } from './jssm_types';
4
4
  import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
5
5
  import { shapes, gviz_shapes, named_colors } from './jssm_constants';
6
6
  import { version } from './version';
@@ -223,16 +223,16 @@ declare class Machine<mDT> {
223
223
  _has_exit_hooks: boolean;
224
224
  _has_global_action_hooks: boolean;
225
225
  _has_transition_hooks: boolean;
226
- _hooks: Map<string, Function>;
227
- _named_hooks: Map<string, Function>;
228
- _entry_hooks: Map<string, Function>;
229
- _exit_hooks: Map<string, Function>;
230
- _global_action_hooks: Map<string, Function>;
231
- _any_action_hook: HookHandler | undefined;
232
- _standard_transition_hook: HookHandler | undefined;
233
- _main_transition_hook: HookHandler | undefined;
234
- _forced_transition_hook: HookHandler | undefined;
235
- _any_transition_hook: HookHandler | undefined;
226
+ _hooks: Map<string, HookHandler<mDT>>;
227
+ _named_hooks: Map<string, HookHandler<mDT>>;
228
+ _entry_hooks: Map<string, HookHandler<mDT>>;
229
+ _exit_hooks: Map<string, HookHandler<mDT>>;
230
+ _global_action_hooks: Map<string, HookHandler<mDT>>;
231
+ _any_action_hook: HookHandler<mDT> | undefined;
232
+ _standard_transition_hook: HookHandler<mDT> | undefined;
233
+ _main_transition_hook: HookHandler<mDT> | undefined;
234
+ _forced_transition_hook: HookHandler<mDT> | undefined;
235
+ _any_transition_hook: HookHandler<mDT> | undefined;
236
236
  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, data }: JssmGenericConfig<mDT>);
237
237
  /********
238
238
  *
@@ -260,6 +260,21 @@ declare class Machine<mDT> {
260
260
  *
261
261
  */
262
262
  state(): StateType;
263
+ /*********
264
+ *
265
+ * Get the current data of a machine.
266
+ *
267
+ * ```typescript
268
+ * import * as jssm from 'jssm';
269
+ *
270
+ * const switch = jssm.from('on <=> off;', {data: 1});
271
+ * console.log( switch.data() ); // 1
272
+ * ```
273
+ *
274
+ * @typeparam mDT The type of the machine data member; usually omitted
275
+ *
276
+ */
277
+ data(): mDT;
263
278
  /********
264
279
  *
265
280
  * Check whether a given state is final (either has no exits or is marked
@@ -523,17 +538,17 @@ declare class Machine<mDT> {
523
538
  is_complete(): boolean;
524
539
  state_is_complete(whichState: StateType): boolean;
525
540
  has_completes(): boolean;
526
- set_hook(HookDesc: HookDescription): void;
527
- hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
528
- hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
529
- hook_global_action(action: string, handler: HookHandler): Machine<mDT>;
530
- hook_any_action(handler: HookHandler): Machine<mDT>;
531
- hook_standard_transition(handler: HookHandler): Machine<mDT>;
532
- hook_main_transition(handler: HookHandler): Machine<mDT>;
533
- hook_forced_transition(handler: HookHandler): Machine<mDT>;
534
- hook_any_transition(handler: HookHandler): Machine<mDT>;
535
- hook_entry(to: string, handler: HookHandler): Machine<mDT>;
536
- hook_exit(from: string, handler: HookHandler): Machine<mDT>;
541
+ set_hook(HookDesc: HookDescription<mDT>): void;
542
+ hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
543
+ hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
544
+ hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
545
+ hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
546
+ hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
547
+ hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
548
+ hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
549
+ hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
550
+ hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
551
+ hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
537
552
  edges_between(from: string, to: string): JssmTransition<mDT>[];
538
553
  transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
539
554
  /********
@@ -654,4 +669,5 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
654
669
  *
655
670
  */
656
671
  declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
657
- 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, shapes, gviz_shapes, named_colors };
672
+ declare function is_hook_rejection(hr: HookResult): boolean;
673
+ 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, shapes, gviz_shapes, named_colors, is_hook_rejection };
package/dist/es6/jssm.js CHANGED
@@ -719,6 +719,30 @@ class Machine {
719
719
  return true; // todo whargarbl
720
720
  }
721
721
  */
722
+ /*********
723
+ *
724
+ * Get the current data of a machine.
725
+ *
726
+ * ```typescript
727
+ * import * as jssm from 'jssm';
728
+ *
729
+ * const switch = jssm.from('on <=> off;', {data: 1});
730
+ * console.log( switch.data() ); // 1
731
+ * ```
732
+ *
733
+ * @typeparam mDT The type of the machine data member; usually omitted
734
+ *
735
+ */
736
+ data() {
737
+ return this._data;
738
+ }
739
+ /* whargarbl todo major
740
+ when we reimplement this, reintroduce this change to the is_final call
741
+
742
+ is_changing(): boolean {
743
+ return true; // todo whargarbl
744
+ }
745
+ */
722
746
  /********
723
747
  *
724
748
  * Check whether a given state is final (either has no exits or is marked
@@ -1304,99 +1328,78 @@ class Machine {
1304
1328
  newState = newStateOrAction;
1305
1329
  }
1306
1330
  }
1307
- // todo whargarbl implement data stuff
1308
- // todo major incomplete whargarbl comeback
1309
1331
  if (valid) {
1310
1332
  if (this._has_hooks) {
1311
1333
  const hook_args = { data: this._data, action: fromAction, from: this._state, to: newState, forced: wasForced };
1312
1334
  if (wasAction) {
1313
1335
  // 1. any action hook
1314
- if (this._any_action_hook !== undefined) {
1315
- if (this._any_action_hook(hook_args) === false) {
1316
- return false;
1317
- }
1336
+ const outcome = AbstractHookStep(this._any_action_hook, hook_args);
1337
+ if (outcome.pass === false) {
1338
+ return false;
1318
1339
  }
1319
1340
  // 2. global specific action hook
1320
- const maybe_ga_hook = this._global_action_hooks.get(newStateOrAction);
1321
- if (maybe_ga_hook !== undefined) {
1322
- if (maybe_ga_hook(hook_args) === false) {
1323
- return false;
1324
- }
1341
+ const outcome2 = AbstractHookStep(this._global_action_hooks.get(newStateOrAction), hook_args);
1342
+ if (outcome2.pass === false) {
1343
+ return false;
1325
1344
  }
1326
1345
  }
1327
1346
  // 3. any transition hook
1328
1347
  if (this._any_transition_hook !== undefined) {
1329
- if (this._any_transition_hook(hook_args) === false) {
1348
+ const outcome = AbstractHookStep(this._any_transition_hook, hook_args);
1349
+ if (outcome.pass === false) {
1330
1350
  return false;
1331
1351
  }
1332
1352
  }
1333
1353
  // 4. exit hook
1334
1354
  if (this._has_exit_hooks) {
1335
- const maybe_ex_hook = this._exit_hooks.get(this._state);
1336
- if (maybe_ex_hook !== undefined) {
1337
- if (maybe_ex_hook(hook_args) === false) {
1338
- return false;
1339
- }
1355
+ const outcome = AbstractHookStep(this._exit_hooks.get(this._state), hook_args);
1356
+ if (outcome.pass === false) {
1357
+ return false;
1340
1358
  }
1341
1359
  }
1342
1360
  // 5. named transition / action hook
1343
1361
  if (this._has_named_hooks) {
1344
1362
  if (wasAction) {
1345
- const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
1346
- if (n_maybe_hook !== undefined) {
1347
- if (n_maybe_hook(hook_args) === false) {
1348
- return false;
1349
- }
1363
+ const nhn = named_hook_name(this._state, newState, newStateOrAction), outcome = AbstractHookStep(this._named_hooks.get(nhn), hook_args);
1364
+ if (outcome.pass === false) {
1365
+ return false;
1350
1366
  }
1351
1367
  }
1352
1368
  }
1353
1369
  // 6. regular hook
1354
1370
  if (this._has_basic_hooks) {
1355
- const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
1356
- if (maybe_hook !== undefined) {
1357
- if (maybe_hook(hook_args) === false) {
1358
- return false;
1359
- }
1371
+ const hn = hook_name(this._state, newState), outcome = AbstractHookStep(this._hooks.get(hn), hook_args);
1372
+ if (outcome.pass === false) {
1373
+ return false;
1360
1374
  }
1361
1375
  }
1362
1376
  // 7. edge type hook
1363
1377
  // 7a. standard transition hook
1364
1378
  if (trans_type === 'legal') {
1365
- if (this._standard_transition_hook !== undefined) {
1366
- // todo handle actions
1367
- // todo handle forced
1368
- if (this._standard_transition_hook(hook_args) === false) {
1369
- return false;
1370
- }
1379
+ const outcome = AbstractHookStep(this._standard_transition_hook, hook_args);
1380
+ if (outcome.pass === false) {
1381
+ return false;
1371
1382
  }
1372
1383
  }
1373
1384
  // 7b. main type hook
1374
1385
  if (trans_type === 'main') {
1375
- if (this._main_transition_hook !== undefined) {
1376
- // todo handle actions
1377
- // todo handle forced
1378
- if (this._main_transition_hook(hook_args) === false) {
1379
- return false;
1380
- }
1386
+ const outcome = AbstractHookStep(this._main_transition_hook, hook_args);
1387
+ if (outcome.pass === false) {
1388
+ return false;
1381
1389
  }
1382
1390
  }
1383
1391
  // 7c. forced transition hook
1384
1392
  if (trans_type === 'forced') {
1385
- if (this._forced_transition_hook !== undefined) {
1386
- // todo handle actions
1387
- // todo handle forced
1388
- if (this._forced_transition_hook(hook_args) === false) {
1389
- return false;
1390
- }
1393
+ const outcome = AbstractHookStep(this._forced_transition_hook, hook_args);
1394
+ if (outcome.pass === false) {
1395
+ return false;
1391
1396
  }
1392
1397
  }
1393
1398
  // 8. entry hook
1394
1399
  if (this._has_entry_hooks) {
1395
- const maybe_en_hook = this._entry_hooks.get(newState);
1396
- if (maybe_en_hook !== undefined) {
1397
- if (maybe_en_hook(hook_args) === false) {
1398
- return false;
1399
- }
1400
+ const outcome = AbstractHookStep(this._entry_hooks.get(newState), hook_args);
1401
+ if (outcome.pass === false) {
1402
+ return false;
1400
1403
  }
1401
1404
  }
1402
1405
  this._state = newState;
@@ -1591,6 +1594,51 @@ function from(MachineAsString, ExtraConstructorFields) {
1591
1594
  }
1592
1595
  return new Machine(to_decorate);
1593
1596
  }
1597
+ function is_hook_complex_result(hr) {
1598
+ if (typeof hr === 'object') {
1599
+ if (typeof hr.pass === 'boolean') {
1600
+ return true;
1601
+ }
1602
+ }
1603
+ return false;
1604
+ }
1605
+ function is_hook_rejection(hr) {
1606
+ if (hr === true) {
1607
+ return false;
1608
+ }
1609
+ if (hr === undefined) {
1610
+ return false;
1611
+ }
1612
+ if (hr === false) {
1613
+ return true;
1614
+ }
1615
+ if (is_hook_complex_result(hr)) {
1616
+ return (!(hr.pass));
1617
+ }
1618
+ throw new TypeError('unknown hook rejection type result');
1619
+ }
1620
+ // TODO hook_args: unknown
1621
+ function AbstractHookStep(maybe_hook, hook_args) {
1622
+ if (maybe_hook !== undefined) {
1623
+ const result = maybe_hook(hook_args);
1624
+ if (result === undefined) {
1625
+ return { pass: true };
1626
+ }
1627
+ if (result === true) {
1628
+ return { pass: true };
1629
+ }
1630
+ if (result === false) {
1631
+ return { pass: false };
1632
+ }
1633
+ // if (is_hook_complex_result(result)) {
1634
+ // return result;
1635
+ // }
1636
+ throw new TypeError(`Unknown hook result type ${result}`);
1637
+ }
1638
+ else {
1639
+ return { pass: true };
1640
+ }
1641
+ }
1594
1642
  export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind,
1595
1643
  // WHARGARBL TODO these should be exported to a utility library
1596
- seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors };
1644
+ seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors, is_hook_rejection };
@@ -149,57 +149,66 @@ declare type JssmCompileSeStart<DataType> = {
149
149
  };
150
150
  declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
151
151
  declare type JssmParseFunctionType = (string: any) => JssmParseTree;
152
- declare type HookHandler = Function;
153
- declare type BasicHookDescription = {
152
+ declare type BasicHookDescription<mDT> = {
154
153
  kind: 'hook';
155
154
  from: string;
156
155
  to: string;
157
- handler: HookHandler;
156
+ handler: HookHandler<mDT>;
158
157
  };
159
- declare type HookDescriptionWithAction = {
158
+ declare type HookDescriptionWithAction<mDT> = {
160
159
  kind: 'named';
161
160
  from: string;
162
161
  to: string;
163
162
  action: string;
164
- handler: HookHandler;
163
+ handler: HookHandler<mDT>;
165
164
  };
166
- declare type StandardTransitionHook = {
165
+ declare type StandardTransitionHook<mDT> = {
167
166
  kind: 'standard transition';
168
- handler: HookHandler;
167
+ handler: HookHandler<mDT>;
169
168
  };
170
- declare type MainTransitionHook = {
169
+ declare type MainTransitionHook<mDT> = {
171
170
  kind: 'main transition';
172
- handler: HookHandler;
171
+ handler: HookHandler<mDT>;
173
172
  };
174
- declare type ForcedTransitionHook = {
173
+ declare type ForcedTransitionHook<mDT> = {
175
174
  kind: 'forced transition';
176
- handler: HookHandler;
175
+ handler: HookHandler<mDT>;
177
176
  };
178
- declare type AnyTransitionHook = {
177
+ declare type AnyTransitionHook<mDT> = {
179
178
  kind: 'any transition';
180
- handler: HookHandler;
179
+ handler: HookHandler<mDT>;
181
180
  };
182
- declare type GlobalActionHook = {
181
+ declare type GlobalActionHook<mDT> = {
183
182
  kind: 'global action';
184
183
  action: string;
185
- handler: HookHandler;
184
+ handler: HookHandler<mDT>;
186
185
  };
187
- declare type AnyActionHook = {
186
+ declare type AnyActionHook<mDT> = {
188
187
  kind: 'any action';
189
- handler: HookHandler;
188
+ handler: HookHandler<mDT>;
190
189
  };
191
- declare type EntryHook = {
190
+ declare type EntryHook<mDT> = {
192
191
  kind: 'entry';
193
192
  to: string;
194
- handler: HookHandler;
193
+ handler: HookHandler<mDT>;
195
194
  };
196
- declare type ExitHook = {
195
+ declare type ExitHook<mDT> = {
197
196
  kind: 'exit';
198
197
  from: string;
199
- handler: HookHandler;
198
+ handler: HookHandler<mDT>;
200
199
  };
201
- declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | StandardTransitionHook | MainTransitionHook | ForcedTransitionHook | AnyTransitionHook | EntryHook | ExitHook;
200
+ declare type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT>;
201
+ declare type HookComplexResult<mDT> = {
202
+ pass: boolean;
203
+ state?: StateType;
204
+ data?: mDT;
205
+ };
206
+ declare type HookResult = true | false | undefined | void;
207
+ declare type HookContext<mDT> = {
208
+ data: mDT;
209
+ };
210
+ declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult;
202
211
  declare type JssmErrorExtendedInfo = {
203
212
  requested_state?: StateType | undefined;
204
213
  };
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 };
214
+ 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, HookContext, HookResult, HookComplexResult };
@@ -1,2 +1,2 @@
1
- const version = "5.72.0";
1
+ const version = "5.72.3";
2
2
  export { version };