jssm 5.72.5 → 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.
package/jssm.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  declare type StateType = string;
2
+ import { circular_buffer } from 'circular_buffer_js';
2
3
  import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3
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';
@@ -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.
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jssm",
3
- "version": "5.72.5",
3
+ "version": "5.73.0",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },
@@ -110,6 +110,7 @@
110
110
  "@typescript-eslint/eslint-plugin": "^4.13.0",
111
111
  "@typescript-eslint/parser": "^4.13.0",
112
112
  "benny": "^3.7.1",
113
+ "circular_buffer_js": "^1.10.0",
113
114
  "coveralls": "^3.0.11",
114
115
  "eslint": "^7.32.0",
115
116
  "eslint-plugin-fp": "^2.3.0",