jssm 5.72.3 → 5.73.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.
@@ -22,6 +22,12 @@ module.exports = {
22
22
  },
23
23
  },
24
24
 
25
- collectCoverageFrom: ["src/ts/**/{!(jssm-dot),}.{js,ts}"]
25
+ collectCoverageFrom: ["src/ts/**/{!(jssm-dot),}.{js,ts}"],
26
+
27
+ reporters: [
28
+ ['default', {}],
29
+ ['jest-json-reporter2', { outputDir: './coverage/spec', outputFile: 'metrics.json', fullOutput: false }],
30
+ // ['jest-json-reporter2', { outputDir: './coverage/spec', outputFile: 'extended-metrics.json', fullOutput: true }],
31
+ ]
26
32
 
27
33
  };
package/jssm.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  declare type StateType = string;
2
+ import { circular_buffer } from 'circular_buffer_js';
2
3
  import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3
- JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookResult } from './jssm_types';
4
+ JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
4
5
  import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
5
6
  import { shapes, gviz_shapes, named_colors } from './jssm_constants';
6
7
  import { version } from './version';
@@ -233,7 +234,9 @@ declare class Machine<mDT> {
233
234
  _main_transition_hook: HookHandler<mDT> | undefined;
234
235
  _forced_transition_hook: HookHandler<mDT> | undefined;
235
236
  _any_transition_hook: HookHandler<mDT> | undefined;
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
+ _history: circular_buffer<[StateType, mDT]>;
238
+ _history_length: number;
239
+ 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, history, data }: JssmGenericConfig<mDT>);
237
240
  /********
238
241
  *
239
242
  * Internal method for fabricating states. Not meant for external use.
@@ -551,6 +554,88 @@ declare class Machine<mDT> {
551
554
  hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
552
555
  edges_between(from: string, to: string): JssmTransition<mDT>[];
553
556
  transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
557
+ /*********
558
+ *
559
+ * Get a truncated history of the recent states and data of the machine.
560
+ * Turned off by default; configure with `.from('...', {data: 5})` by length,
561
+ * or set `.history_length` at runtime.
562
+ *
563
+ * History *does not contain the current state*. If you want that, call
564
+ * `.history_inclusive` instead.
565
+ *
566
+ * ```typescript
567
+ * const foo = jssm.from(
568
+ * "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
569
+ * { history: 3 }
570
+ * );
571
+ *
572
+ * foo.action('next');
573
+ * foo.action('next');
574
+ * foo.action('next');
575
+ * foo.action('next');
576
+ *
577
+ * foo.history; // [ ['b',undefined], ['c',undefined], ['d',undefined] ]
578
+ * ```
579
+ *
580
+ * Notice that the machine's current state, `e`, is not in the returned list.
581
+ *
582
+ * @typeparam mDT The type of the machine data member; usually omitted
583
+ *
584
+ */
585
+ get history(): [string, mDT][];
586
+ /*********
587
+ *
588
+ * Get a truncated history of the recent states and data of the machine,
589
+ * including the current state. Turned off by default; configure with
590
+ * `.from('...', {data: 5})` by length, or set `.history_length` at runtime.
591
+ *
592
+ * History inclusive contains the current state. If you only want past
593
+ * states, call `.history` instead.
594
+ *
595
+ * The list returned will be one longer than the history buffer kept, as the
596
+ * history buffer kept gets the current state added to it to produce this
597
+ * list.
598
+ *
599
+ * ```typescript
600
+ * const foo = jssm.from(
601
+ * "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
602
+ * { history: 3 }
603
+ * );
604
+ *
605
+ * foo.action('next');
606
+ * foo.action('next');
607
+ * foo.action('next');
608
+ * foo.action('next');
609
+ *
610
+ * foo.history_inclusive; // [ ['b',undefined], ['c',undefined], ['d',undefined], ['e',undefined] ]
611
+ * ```
612
+ *
613
+ * Notice that the machine's current state, `e`, is in the returned list.
614
+ *
615
+ * @typeparam mDT The type of the machine data member; usually omitted
616
+ *
617
+ */
618
+ get history_inclusive(): [string, mDT][];
619
+ /*********
620
+ *
621
+ * Find out how long a history this machine is keeping. Defaults to zero.
622
+ * Settable directly.
623
+ *
624
+ * ```typescript
625
+ * const foo = jssm.from("a -> b;");
626
+ * foo.history_length; // 0
627
+ *
628
+ * const bar = jssm.from("a -> b;", { history: 3 });
629
+ * foo.history_length; // 3
630
+ * foo.history_length = 5;
631
+ * foo.history_length; // 5
632
+ * ```
633
+ *
634
+ * @typeparam mDT The type of the machine data member; usually omitted
635
+ *
636
+ */
637
+ get history_length(): number;
638
+ set history_length(to: number);
554
639
  /********
555
640
  *
556
641
  * Instruct the machine to complete an action.
@@ -669,5 +754,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
669
754
  *
670
755
  */
671
756
  declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
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 };
757
+ declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
758
+ declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
759
+ declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
760
+ 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, is_hook_complex_result, abstract_hook_step };
package/jssm_types.d.ts CHANGED
@@ -102,6 +102,7 @@ declare type JssmGenericConfig<DataType> = {
102
102
  data?: DataType;
103
103
  nodes?: Array<StateType>;
104
104
  check?: JssmStatePermitterMaybeArray<DataType>;
105
+ history?: number;
105
106
  min_exits?: number;
106
107
  max_exits?: number;
107
108
  allow_islands?: false;
@@ -203,11 +204,11 @@ declare type HookComplexResult<mDT> = {
203
204
  state?: StateType;
204
205
  data?: mDT;
205
206
  };
206
- declare type HookResult = true | false | undefined | void;
207
+ declare type HookResult<mDT> = true | false | undefined | void | HookComplexResult<mDT>;
207
208
  declare type HookContext<mDT> = {
208
209
  data: mDT;
209
210
  };
210
- declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult;
211
+ declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
211
212
  declare type JssmErrorExtendedInfo = {
212
213
  requested_state?: StateType | undefined;
213
214
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jssm",
3
- "version": "5.72.3",
3
+ "version": "5.73.0",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },
@@ -47,7 +47,7 @@
47
47
  "audit": "text_audit -r -t major MAJOR wasteful WASTEFUL any mixed fixme FIXME checkme CHECKME testme TESTME stochable STOCHABLE todo TODO comeback COMEBACK whargarbl WHARGARBL -g ./src/ts/**/*.{js,ts}",
48
48
  "vet": "npm run eslint && npm run audit",
49
49
  "benny": "node ./src/buildjs/benchmark.js",
50
- "build": "npm run vet && npm run test && npm run site && npm run changelog && npm run docs",
50
+ "build": "npm run vet && npm run test && npm run site && npm run changelog && npm run docs && npm run readme",
51
51
  "clean_bench": "npm run test && npm run benny",
52
52
  "qbuild": "npm run test",
53
53
  "ci_build": "npm run vet && npm run test",
@@ -56,6 +56,7 @@
56
56
  "min_cjs": "mv dist/jssm.es5.cjs.js dist/jssm.es5.cjs.nonmin.js && terser dist/jssm.es5.cjs.nonmin.js > dist/jssm.es5.cjs.js",
57
57
  "site": "cp src/site/* docs/ && cp -r src/assets docs/assets/",
58
58
  "docs": "typedoc src/ts/jssm.ts --options typedoc-options.js",
59
+ "readme": "rm ./README.md && node ./src/buildjs/make_readme.js",
59
60
  "changelog": "rm -f CHANGELOG.md && rm -f ./src/doc_md/CHANGELOG.md && better_git_changelog -b && cp CHANGELOG.* ./src/doc_md/"
60
61
  },
61
62
  "repository": {
@@ -109,6 +110,7 @@
109
110
  "@typescript-eslint/eslint-plugin": "^4.13.0",
110
111
  "@typescript-eslint/parser": "^4.13.0",
111
112
  "benny": "^3.7.1",
113
+ "circular_buffer_js": "^1.10.0",
112
114
  "coveralls": "^3.0.11",
113
115
  "eslint": "^7.32.0",
114
116
  "eslint-plugin-fp": "^2.3.0",
@@ -119,6 +121,7 @@
119
121
  "fast-check": "^2.12.0",
120
122
  "glob": "^7.1.6",
121
123
  "jest": "^27.3.1",
124
+ "jest-json-reporter2": "^1.1.0",
122
125
  "pegjs": "^0.10.0",
123
126
  "rollup": "^2.72.1",
124
127
  "semver": "^5.7.1",