jssm 5.93.0 → 5.95.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.
@@ -101,7 +101,16 @@ declare class Machine<mDT> {
101
101
  _start_state_style: JssmStateConfig;
102
102
  _end_state_style: JssmStateConfig;
103
103
  _state_labels: Map<string, string>;
104
- constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed }: JssmGenericConfig<StateType, mDT>);
104
+ _time_source: () => number;
105
+ _create_started: number;
106
+ _created: number;
107
+ _after_mapping: Map<string, [string, number]>;
108
+ _timeout_source: (Function: any, number: any) => number;
109
+ _clear_timeout_source: (h: any) => void;
110
+ _timeout_handle: number | undefined;
111
+ _timeout_target: string | undefined;
112
+ _timeout_target_time: number | undefined;
113
+ constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
105
114
  /********
106
115
  *
107
116
  * Internal method for fabricating states. Not meant for external use.
@@ -694,6 +703,7 @@ declare class Machine<mDT> {
694
703
  */
695
704
  override(newState: StateType, newData?: mDT | undefined): void;
696
705
  transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
706
+ auto_set_state_timeout(): void;
697
707
  /*********
698
708
  *
699
709
  * Get a truncated history of the recent states and data of the machine.
@@ -1065,6 +1075,13 @@ declare class Machine<mDT> {
1065
1075
  valid_transition(newState: StateType, _newData?: mDT): boolean;
1066
1076
  valid_force_transition(newState: StateType, _newData?: mDT): boolean;
1067
1077
  instance_name(): string | undefined;
1078
+ get creation_date(): Date;
1079
+ get creation_timestamp(): number;
1080
+ get create_start_time(): number;
1081
+ set_state_timeout(next_state: StateType, after_time: number): void;
1082
+ clear_state_timeout(): void;
1083
+ state_timeout_for(which_state: StateType): [StateType, number] | undefined;
1084
+ current_state_timeout(): [StateType, number] | undefined;
1068
1085
  sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
1069
1086
  }
1070
1087
  /*********
package/dist/es6/jssm.js CHANGED
@@ -126,7 +126,9 @@ function state_style_condense(jssk) {
126
126
  // TODO add a lotta docblock here
127
127
  class Machine {
128
128
  // whargarbl this badly needs to be broken up, monolith master
129
- constructor({ start_states, end_states = [], complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed }) {
129
+ constructor({ start_states, end_states = [], complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }) {
130
+ this._time_source = () => new Date().getTime();
131
+ this._create_started = this._time_source();
130
132
  this._instance_name = instance_name;
131
133
  this._state = start_states[0];
132
134
  this._states = new Map();
@@ -214,6 +216,12 @@ class Machine {
214
216
  this._state_labels = new Map();
215
217
  this._rng_seed = rng_seed !== null && rng_seed !== void 0 ? rng_seed : new Date().getTime();
216
218
  this._rng = gen_splitmix32(this._rng_seed);
219
+ this._timeout_source = timeout_source !== null && timeout_source !== void 0 ? timeout_source : ((f, a) => setTimeout(f, a));
220
+ this._clear_timeout_source = clear_timeout_source !== null && clear_timeout_source !== void 0 ? clear_timeout_source : ((h) => clearTimeout(h));
221
+ this._timeout_handle = undefined;
222
+ this._timeout_target = undefined;
223
+ this._timeout_target_time = undefined;
224
+ this._after_mapping = new Map();
217
225
  // consolidate the state declarations
218
226
  if (state_declaration) {
219
227
  state_declaration.map((state_decl) => {
@@ -275,6 +283,10 @@ class Machine {
275
283
  this._named_transitions.set(tr.name, thisEdgeId);
276
284
  }
277
285
  }
286
+ // set up the after mapping, if any
287
+ if (tr.after_time) {
288
+ this._after_mapping.set(tr.from, [tr.to, tr.after_time]);
289
+ }
278
290
  // set up the mapping, so that edges can be looked up by endpoint pairs
279
291
  const from_mapping = this._edge_map.get(tr.from) || new Map();
280
292
  if (!(this._edge_map.has(tr.from))) {
@@ -382,6 +394,13 @@ class Machine {
382
394
  if (!(start_states.length === this._start_states.size)) {
383
395
  throw new JssmError(this, `Start states cannot be repeated`);
384
396
  }
397
+ this._created = this._time_source();
398
+ this.auto_set_state_timeout();
399
+ this._arrange_declaration.forEach((arrange_pair) => arrange_pair.forEach((possibleState) => {
400
+ if (!(this._states.has(possibleState))) {
401
+ throw new JssmError(this, `Cannot arrange state that does not exist "${possibleState}"`);
402
+ }
403
+ }));
385
404
  }
386
405
  /********
387
406
  *
@@ -1511,6 +1530,8 @@ class Machine {
1511
1530
  };
1512
1531
  if (valid) {
1513
1532
  if (this._has_hooks) {
1533
+ // once validity is known, clear old 'after' timeout clause
1534
+ this.clear_state_timeout();
1514
1535
  function update_fields(res) {
1515
1536
  if (res.hasOwnProperty('data')) {
1516
1537
  hook_args.data = res.data;
@@ -1700,8 +1721,17 @@ class Machine {
1700
1721
  }
1701
1722
  }
1702
1723
  }
1724
+ // possibly re-establish new 'after' clause
1725
+ this.auto_set_state_timeout();
1703
1726
  return true;
1704
1727
  }
1728
+ auto_set_state_timeout() {
1729
+ const after_res = this._after_mapping.get(this._state);
1730
+ if (after_res !== undefined) {
1731
+ const [next_state, after_time] = after_res;
1732
+ this.set_state_timeout(next_state, after_time);
1733
+ }
1734
+ }
1705
1735
  /*********
1706
1736
  *
1707
1737
  * Get a truncated history of the recent states and data of the machine.
@@ -2233,6 +2263,45 @@ class Machine {
2233
2263
  instance_name() {
2234
2264
  return this._instance_name;
2235
2265
  }
2266
+ get creation_date() {
2267
+ return new Date(Math.floor(this.creation_timestamp));
2268
+ }
2269
+ get creation_timestamp() {
2270
+ return this._created;
2271
+ }
2272
+ get create_start_time() {
2273
+ return this._create_started;
2274
+ }
2275
+ set_state_timeout(next_state, after_time) {
2276
+ if (this._timeout_handle !== undefined) {
2277
+ throw new JssmError(this, `Asked to set a state timeout to ${next_state}:${after_time}, but already timing out to ${this._timeout_target}:${this._timeout_target_time}`);
2278
+ }
2279
+ this._timeout_handle = this._timeout_source(
2280
+ // it seems like istanbul can't see this line being followed, even though it is, actively
2281
+ // this is enforced by the "after mapping runs normally with very short time" tests in after_mapping.spec
2282
+ // we'll mark it no-check so that our coverage numbers aren't wrecked
2283
+ /* istanbul ignore next */
2284
+ () => this.go(next_state), after_time);
2285
+ this._timeout_target = next_state;
2286
+ this._timeout_target_time = after_time;
2287
+ }
2288
+ clear_state_timeout() {
2289
+ if (this._timeout_handle === undefined) {
2290
+ return; // calling with no timeout is a no-op, means it can be called glad-handedly
2291
+ }
2292
+ this._clear_timeout_source(this._timeout_handle);
2293
+ this._timeout_handle = undefined;
2294
+ this._timeout_target = undefined;
2295
+ this._timeout_target_time = undefined;
2296
+ }
2297
+ state_timeout_for(which_state) {
2298
+ return this._after_mapping.get(which_state);
2299
+ }
2300
+ current_state_timeout() {
2301
+ return (this._timeout_target !== undefined)
2302
+ ? [this._timeout_target, this._timeout_target_time]
2303
+ : undefined;
2304
+ }
2236
2305
  /* eslint-disable no-use-before-define */
2237
2306
  /* eslint-disable class-methods-use-this */
2238
2307
  sm(template_strings, ...remainder /* , arguments */) {
@@ -21,6 +21,7 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
21
21
  from,
22
22
  to,
23
23
  kind,
24
+ after_time: isRight ? this_se.r_after : this_se.l_after,
24
25
  forced_only: kind === 'forced',
25
26
  main_path: kind === 'main'
26
27
  };
@@ -48,6 +48,8 @@ declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitt
48
48
  declare type JssmTransition<StateType, DataType> = {
49
49
  from: StateType;
50
50
  to: StateType;
51
+ after_time?: number;
52
+ se?: JssmCompileSe<StateType, DataType>;
51
53
  name?: StateType;
52
54
  action?: StateType;
53
55
  check?: JssmTransitionPermitterMaybeArray<DataType>;
@@ -220,6 +222,9 @@ declare type JssmGenericConfig<StateType, DataType> = {
220
222
  default_terminal_state_config?: JssmStateStyleKeyList;
221
223
  default_active_state_config?: JssmStateStyleKeyList;
222
224
  rng_seed?: number | undefined;
225
+ time_source?: () => number;
226
+ timeout_source?: (Function: any, number: any) => number;
227
+ clear_timeout_source?: (number: any) => void;
223
228
  };
224
229
  declare type JssmCompileRule<StateType> = {
225
230
  agg_as: string;
@@ -227,12 +232,14 @@ declare type JssmCompileRule<StateType> = {
227
232
  };
228
233
  declare type JssmCompileSe<StateType, mDT> = {
229
234
  to: StateType;
230
- se: JssmCompileSe<StateType, mDT>;
235
+ se?: JssmCompileSe<StateType, mDT>;
231
236
  kind: JssmArrow;
232
237
  l_action?: StateType;
233
238
  r_action?: StateType;
234
239
  l_probability: number;
235
240
  r_probability: number;
241
+ l_after?: number;
242
+ r_after?: number;
236
243
  };
237
244
  declare type JssmCompileSeStart<StateType, DataType> = {
238
245
  from: StateType;
@@ -1,2 +1,2 @@
1
- const version = "5.93.0", build_time = 1703723662470;
1
+ const version = "5.95.0", build_time = 1704098570300;
2
2
  export { version, build_time };