jssm 5.44.0 → 5.46.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.
Files changed (85) hide show
  1. package/dist/es6/jssm.d.ts +6 -1
  2. package/dist/es6/jssm.js +104 -14
  3. package/dist/es6/jssm_types.d.ts +26 -1
  4. package/dist/es6/jssm_util.d.ts +3 -1
  5. package/dist/es6/jssm_util.js +3 -1
  6. package/dist/es6/version.js +1 -1
  7. package/dist/jssm.es5.cjs.js +1 -1
  8. package/jssm.d.ts +6 -1
  9. package/jssm_types.d.ts +26 -1
  10. package/jssm_util.d.ts +3 -1
  11. package/package.json +2 -3
  12. package/.codeclimate.yml +0 -22
  13. package/.editorconfig +0 -12
  14. package/.eslintrc +0 -20
  15. package/.nycrc +0 -6
  16. package/.travis.yml +0 -9
  17. package/dist/jssm.es5.iife.js +0 -1
  18. package/jest-spec.config.js +0 -27
  19. package/jest-stoch.config.js +0 -27
  20. package/rollup.config.iife.js +0 -44
  21. package/rollup.config.js +0 -44
  22. package/src/demo/index.html +0 -38
  23. package/src/demo/style.css +0 -2
  24. package/src/ts/jssm-dot.peg +0 -928
  25. package/src/ts/jssm.ts +0 -1120
  26. package/src/ts/jssm_types.ts +0 -346
  27. package/src/ts/jssm_util.ts +0 -100
  28. package/src/ts/tests/actions.spec.ts +0 -167
  29. package/src/ts/tests/arrange.spec.ts +0 -72
  30. package/src/ts/tests/arrange.stoch.ts +0 -4
  31. package/src/ts/tests/array_box_if_string.spec.ts +0 -30
  32. package/src/ts/tests/array_transitions.spec.ts +0 -129
  33. package/src/ts/tests/arrow unicode.spec.ts +0 -88
  34. package/src/ts/tests/arrow.spec.ts +0 -124
  35. package/src/ts/tests/colors.spec.ts +0 -58
  36. package/src/ts/tests/comment.spec.ts +0 -134
  37. package/src/ts/tests/compile.spec.ts +0 -79
  38. package/src/ts/tests/constants.spec.ts +0 -98
  39. package/src/ts/tests/cycles.spec.ts +0 -153
  40. package/src/ts/tests/dot_preamble.spec.ts +0 -16
  41. package/src/ts/tests/embedded_sm.spec.ts +0 -36
  42. package/src/ts/tests/flow.spec.ts +0 -22
  43. package/src/ts/tests/forced transitions.spec.ts +0 -26
  44. package/src/ts/tests/general.spec.ts +0 -933
  45. package/src/ts/tests/graph node lists.spec.ts +0 -21
  46. package/src/ts/tests/histo.spec.ts +0 -24
  47. package/src/ts/tests/hooks.spec.ts +0 -28
  48. package/src/ts/tests/language.spec.ts +0 -37
  49. package/src/ts/tests/language_data/belarussian.json +0 -14
  50. package/src/ts/tests/language_data/bengali.json +0 -16
  51. package/src/ts/tests/language_data/emoji.json +0 -22
  52. package/src/ts/tests/language_data/english.json +0 -17
  53. package/src/ts/tests/language_data/french.json +0 -17
  54. package/src/ts/tests/language_data/german.json +0 -17
  55. package/src/ts/tests/language_data/hebrew.json +0 -16
  56. package/src/ts/tests/language_data/portuguese.json +0 -13
  57. package/src/ts/tests/language_data/russian.json +0 -13
  58. package/src/ts/tests/language_data/spanish.json +0 -17
  59. package/src/ts/tests/language_data/ukrainian.json +0 -19
  60. package/src/ts/tests/layout.spec.ts +0 -29
  61. package/src/ts/tests/machine_attributes.spec.ts +0 -398
  62. package/src/ts/tests/machine_name.spec.ts +0 -14
  63. package/src/ts/tests/named lists.spec.ts +0 -24
  64. package/src/ts/tests/nominated states.spec.ts +0 -133
  65. package/src/ts/tests/parse actions.spec.ts +0 -32
  66. package/src/ts/tests/parse.spec.ts +0 -94
  67. package/src/ts/tests/probability.spec.ts +0 -146
  68. package/src/ts/tests/r639.spec.ts +0 -27
  69. package/src/ts/tests/sample_select.spec.ts +0 -173
  70. package/src/ts/tests/seq.spec.ts +0 -14
  71. package/src/ts/tests/seq.stoch.ts +0 -83
  72. package/src/ts/tests/shapes.spec.ts +0 -63
  73. package/src/ts/tests/sm_tag.spec.ts +0 -37
  74. package/src/ts/tests/special characters.spec.ts +0 -39
  75. package/src/ts/tests/state_declaration.spec.ts +0 -214
  76. package/src/ts/tests/state_style.spec.ts +0 -82
  77. package/src/ts/tests/stop light.spec.ts +0 -157
  78. package/src/ts/tests/stripes.spec.ts +0 -52
  79. package/src/ts/tests/theme.spec.ts +0 -45
  80. package/src/ts/tests/weighted_histo_key.spec.ts +0 -22
  81. package/src/ts/tests/weighted_rand_select.spec.ts +0 -27
  82. package/src/ts/tests/weighted_sample_select.spec.ts +0 -24
  83. package/src/ts/version.ts +0 -3
  84. package/tree.txt +0 -1794
  85. package/tsconfig.json +0 -27
@@ -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 } from './jssm_types';
3
+ JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
4
4
  import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
5
5
  import { version } from './version';
6
6
  declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
@@ -37,6 +37,9 @@ declare class Machine<mDT> {
37
37
  _arrange_end_declaration: Array<Array<StateType>>;
38
38
  _theme: FslTheme;
39
39
  _flow: FslDirection;
40
+ _has_hooks: boolean;
41
+ _hooks: Map<string, Function>;
42
+ _named_hooks: Map<string, Function>;
40
43
  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>);
41
44
  _new_state(state_config: JssmGenericState): StateType;
42
45
  state(): StateType;
@@ -86,6 +89,8 @@ declare class Machine<mDT> {
86
89
  is_complete(): boolean;
87
90
  state_is_complete(whichState: StateType): boolean;
88
91
  has_completes(): boolean;
92
+ set_hook(HookDesc: HookDescription): void;
93
+ hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
89
94
  action(name: StateType, newData?: mDT): boolean;
90
95
  transition(newState: StateType, newData?: mDT): boolean;
91
96
  force_transition(newState: StateType, newData?: mDT): boolean;
package/dist/es6/jssm.js CHANGED
@@ -1,8 +1,8 @@
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
- import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, array_box_if_string } from './jssm_util';
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
4
  import { parse } from './jssm-dot'; // TODO FIXME WHARGARBL this could be post-typed
5
- import { version } from './version'; // replaced from package.js in build // TODO FIXME currently broken
5
+ import { version } from './version'; // replaced from package.js in build
6
6
  /* eslint-disable complexity */
7
7
  function arrow_direction(arrow) {
8
8
  switch (String(arrow)) {
@@ -345,6 +345,9 @@ class Machine {
345
345
  this._theme = theme;
346
346
  this._flow = flow;
347
347
  this._graph_layout = graph_layout;
348
+ this._has_hooks = false;
349
+ this._hooks = new Map();
350
+ this._named_hooks = new Map();
348
351
  if (state_declaration) {
349
352
  state_declaration.map((state_decl) => {
350
353
  if (this._state_declarations.has(state_decl.state)) { // no repeats
@@ -401,7 +404,7 @@ class Machine {
401
404
  // set up the action mapping, so that actions can be looked up by origin
402
405
  if (tr.action) {
403
406
  // forward mapping first by action name
404
- let actionMap = this._actions.get(tr.action); // TODO FIXME ?Map equiv
407
+ let actionMap = this._actions.get(tr.action);
405
408
  if (!(actionMap)) {
406
409
  actionMap = new Map();
407
410
  this._actions.set(tr.action, actionMap);
@@ -413,7 +416,7 @@ class Machine {
413
416
  actionMap.set(tr.from, thisEdgeId);
414
417
  }
415
418
  // reverse mapping first by state origin name
416
- let rActionMap = this._reverse_actions.get(tr.from); // TODO FIXME ?Map equiv
419
+ let rActionMap = this._reverse_actions.get(tr.from);
417
420
  if (!(rActionMap)) {
418
421
  rActionMap = new Map();
419
422
  this._reverse_actions.set(tr.from, rActionMap);
@@ -694,14 +697,64 @@ class Machine {
694
697
  has_completes() {
695
698
  return this.states().some((x) => this.state_is_complete(x));
696
699
  }
700
+ // basic toolable hook call. convenience wrappers will follow, like
701
+ // hook(from, to, handler) and exit_hook(from, handler) and etc
702
+ set_hook(HookDesc) {
703
+ switch (HookDesc.kind) {
704
+ case 'hook':
705
+ this._hooks.set(hook_name(HookDesc.from, HookDesc.to), HookDesc.handler);
706
+ this._has_hooks = true;
707
+ break;
708
+ case 'named':
709
+ this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
710
+ this._has_hooks = true;
711
+ break;
712
+ // case 'entry':
713
+ // console.log('TODO: Should add entry hook here');
714
+ // throw 'TODO: Should add entry hook here';
715
+ // case 'exit':
716
+ // console.log('TODO: Should add exit hook here');
717
+ // throw 'TODO: Should add exit hook here';
718
+ default:
719
+ console.log(`Unknown hook type ${HookDesc.kind}, should be impossible`);
720
+ throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
721
+ }
722
+ }
723
+ hook(from, to, handler) {
724
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
725
+ this.set_hook({ kind: 'hook', from, to, handler });
726
+ return this;
727
+ }
728
+ // remove_hook(HookDesc: HookDescription) {
729
+ // throw 'TODO: Should remove hook here';
730
+ // }
697
731
  action(name, newData) {
698
732
  // todo whargarbl implement hooks
699
733
  // todo whargarbl implement data stuff
700
734
  // todo major incomplete whargarbl comeback
701
735
  if (this.valid_action(name, newData)) {
702
736
  const edge = this.current_action_edge_for(name);
703
- this._state = edge.to;
704
- return true;
737
+ if (this._has_hooks) {
738
+ let hook_permits = undefined;
739
+ const nhn = named_hook_name(this._state, edge.to, name), maybe_hook = this._named_hooks.get(nhn);
740
+ if (maybe_hook === undefined) {
741
+ hook_permits = true;
742
+ }
743
+ else {
744
+ hook_permits = maybe_hook({ from: this._state, to: edge.to, action: name });
745
+ }
746
+ if (hook_permits !== false) {
747
+ this._state = edge.to;
748
+ return true;
749
+ }
750
+ else {
751
+ return false;
752
+ }
753
+ }
754
+ else {
755
+ this._state = edge.to;
756
+ return true;
757
+ }
705
758
  }
706
759
  else {
707
760
  return false;
@@ -712,8 +765,27 @@ class Machine {
712
765
  // todo whargarbl implement data stuff
713
766
  // todo major incomplete whargarbl comeback
714
767
  if (this.valid_transition(newState, newData)) {
715
- this._state = newState;
716
- return true;
768
+ if (this._has_hooks) {
769
+ let hook_permits = undefined;
770
+ const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
771
+ if (maybe_hook === undefined) {
772
+ hook_permits = true;
773
+ }
774
+ else {
775
+ hook_permits = maybe_hook({ from: this._state, to: newState });
776
+ }
777
+ if (hook_permits !== false) {
778
+ this._state = newState;
779
+ return true;
780
+ }
781
+ else {
782
+ return false;
783
+ }
784
+ }
785
+ else {
786
+ this._state = newState;
787
+ return true;
788
+ }
717
789
  }
718
790
  else {
719
791
  return false;
@@ -725,8 +797,27 @@ class Machine {
725
797
  // todo whargarbl implement data stuff
726
798
  // todo major incomplete whargarbl comeback
727
799
  if (this.valid_force_transition(newState, newData)) {
728
- this._state = newState;
729
- return true;
800
+ if (this._has_hooks) {
801
+ let hook_permits = undefined;
802
+ const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
803
+ if (maybe_hook === undefined) {
804
+ hook_permits = true;
805
+ }
806
+ else {
807
+ hook_permits = maybe_hook({ from: this._state, to: newState, forced: true });
808
+ }
809
+ if (hook_permits !== false) {
810
+ this._state = newState;
811
+ return true;
812
+ }
813
+ else {
814
+ return false;
815
+ }
816
+ }
817
+ else {
818
+ this._state = newState;
819
+ return true;
820
+ }
730
821
  }
731
822
  else {
732
823
  return false;
@@ -734,7 +825,9 @@ class Machine {
734
825
  }
735
826
  current_action_for(action) {
736
827
  const action_base = this._actions.get(action);
737
- return action_base ? action_base.get(this.state()) : undefined;
828
+ return action_base
829
+ ? action_base.get(this.state())
830
+ : undefined;
738
831
  }
739
832
  current_action_edge_for(action) {
740
833
  const idx = this.current_action_for(action);
@@ -744,13 +837,11 @@ class Machine {
744
837
  return this._edges[idx];
745
838
  }
746
839
  valid_action(action, _newData) {
747
- // todo whargarbl implement hooks
748
840
  // todo whargarbl implement data stuff
749
841
  // todo major incomplete whargarbl comeback
750
842
  return this.current_action_for(action) !== undefined;
751
843
  }
752
844
  valid_transition(newState, _newData) {
753
- // todo whargarbl implement hooks
754
845
  // todo whargarbl implement data stuff
755
846
  // todo major incomplete whargarbl comeback
756
847
  const transition_for = this.lookup_transition_for(this.state(), newState);
@@ -763,7 +854,6 @@ class Machine {
763
854
  return true;
764
855
  }
765
856
  valid_force_transition(newState, _newData) {
766
- // todo whargarbl implement hooks
767
857
  // todo whargarbl implement data stuff
768
858
  // todo major incomplete whargarbl comeback
769
859
  return (this.lookup_transition_for(this.state(), newState) !== undefined);
@@ -148,4 +148,29 @@ declare type JssmCompileSeStart<DataType> = {
148
148
  };
149
149
  declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
150
150
  declare type JssmParseFunctionType = (string: any) => JssmParseTree;
151
- export { JssmColor, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmParseFunctionType, JssmMachineInternalState, FslDirection, FslTheme };
151
+ declare type HookHandler = Function;
152
+ declare type BasicHookDescription = {
153
+ kind: 'hook';
154
+ from: string;
155
+ to: string;
156
+ handler: HookHandler;
157
+ };
158
+ declare type HookDescriptionWithAction = {
159
+ kind: 'named';
160
+ from: string;
161
+ to: string;
162
+ action: string;
163
+ handler: HookHandler;
164
+ };
165
+ declare type EntryHook = {
166
+ kind: 'entry';
167
+ to: string;
168
+ handler: HookHandler;
169
+ };
170
+ declare type ExitHook = {
171
+ kind: 'exit';
172
+ from: string;
173
+ handler: HookHandler;
174
+ };
175
+ declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | EntryHook | ExitHook;
176
+ export { JssmColor, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmParseFunctionType, JssmMachineInternalState, FslDirection, FslTheme, HookDescription, HookHandler };
@@ -5,4 +5,6 @@ declare const seq: Function;
5
5
  declare const histograph: Function;
6
6
  declare const weighted_sample_select: Function;
7
7
  declare const weighted_histo_key: Function;
8
- export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string };
8
+ declare const hook_name: (from: string, to: string) => string;
9
+ declare const named_hook_name: (from: string, to: string, action: string) => string;
10
+ export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name };
@@ -31,4 +31,6 @@ const weighted_histo_key = (n, opts, prob_prop, extract) => // TODO FIXME no any
31
31
  histograph(weighted_sample_select(n, opts, prob_prop)
32
32
  .map((s) => s[extract] // TODO FIXME eslint-disable-line flowtype/no-weak-types
33
33
  ));
34
- export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string };
34
+ const hook_name = (from, to) => JSON.stringify([from, to]);
35
+ const named_hook_name = (from, to, action) => JSON.stringify([from, to, action]);
36
+ export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name };
@@ -1,2 +1,2 @@
1
- const version = "5.44.0";
1
+ const version = "5.46.0";
2
2
  export { version };