jssm 5.78.0 → 5.79.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,7 +1,7 @@
1
1
  declare type StateType = string;
2
2
  import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3
3
  JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
4
- import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
4
+ import { seq, unique, find_repeated, 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';
7
7
  /*********
@@ -250,9 +250,12 @@ declare class Machine<mDT> {
250
250
  _post_main_transition_hook: HookHandler<mDT> | undefined;
251
251
  _post_forced_transition_hook: HookHandler<mDT> | undefined;
252
252
  _post_any_transition_hook: HookHandler<mDT> | undefined;
253
+ _property_keys: Set<string>;
254
+ _default_properties: Map<string, any>;
255
+ _state_properties: Map<string, any>;
253
256
  _history: JssmHistory<mDT>;
254
257
  _history_length: number;
255
- 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>);
258
+ constructor({ start_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 }: JssmGenericConfig<mDT>);
256
259
  /********
257
260
  *
258
261
  * Internal method for fabricating states. Not meant for external use.
@@ -294,6 +297,105 @@ declare class Machine<mDT> {
294
297
  *
295
298
  */
296
299
  data(): mDT;
300
+ /*********
301
+ *
302
+ * Get the current value of a given property name.
303
+ *
304
+ * ```typescript
305
+ *
306
+ * ```
307
+ *
308
+ * @param name The relevant property name to look up
309
+ *
310
+ * @returns The value behind the prop name. Because functional props are
311
+ * evaluated as getters, this can be anything.
312
+ *
313
+ */
314
+ prop(name: string): any;
315
+ /*********
316
+ *
317
+ * Get the current value of every prop, as an object. If no current definition
318
+ * exists for a prop - that is, if the prop was defined without a default and
319
+ * the current state also doesn't define the prop - then that prop will be listed
320
+ * in the returned object with a value of `undefined`.
321
+ *
322
+ * ```typescript
323
+ * const traffic_light = sm`
324
+ *
325
+ * property can_go default true;
326
+ * property hesitate default true;
327
+ * property stop_first default false;
328
+ *
329
+ * Off -> Red => Green => Yellow => Red;
330
+ * [Red Yellow Green] ~> [Off FlashingRed];
331
+ * FlashingRed -> Red;
332
+ *
333
+ * state Red: { property stop_first true; property can_go false; };
334
+ * state Off: { property stop_first true; };
335
+ * state FlashingRed: { property stop_first true; };
336
+ * state Green: { property hesitate false; };
337
+ *
338
+ * `;
339
+ *
340
+ * traffic_light.state(); // Off
341
+ * traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true; }
342
+ *
343
+ * traffic_light.go('Red');
344
+ * traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true; }
345
+ *
346
+ * traffic_light.go('Green');
347
+ * traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
348
+ * ```
349
+ *
350
+ */
351
+ props(): object;
352
+ /*********
353
+ *
354
+ * Get the current value of every prop, as an object. Compare
355
+ * {@link prop_map}, which returns a `Map`.
356
+ *
357
+ * ```typescript
358
+ *
359
+ * ```
360
+ *
361
+ */
362
+ /*********
363
+ *
364
+ * Get the current value of every prop, as an object. Compare
365
+ * {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
366
+ * this throws if a required prop is missing.
367
+ *
368
+ * ```typescript
369
+ *
370
+ * ```
371
+ *
372
+ */
373
+ /*********
374
+ *
375
+ * Check whether a given string is a known property's name.
376
+ *
377
+ * ```typescript
378
+ * const example = sm`property foo default 1; a->b;`;
379
+ *
380
+ * example.known_prop('foo'); // true
381
+ * example.known_prop('bar'); // false
382
+ * ```
383
+ *
384
+ * @param prop_name The relevant property name to look up
385
+ *
386
+ */
387
+ known_prop(prop_name: string): boolean;
388
+ /*********
389
+ *
390
+ * List all known property names. If you'd also like values, use
391
+ * {@link props} instead. The order of the properties is not defined, and
392
+ * the properties generally will not be sorted.
393
+ *
394
+ * ```typescript
395
+ * ```
396
+ *
397
+ */
398
+ known_props(): string[];
297
399
  /********
298
400
  *
299
401
  * Check whether a given state is final (either has no exits or is marked
@@ -696,15 +798,27 @@ declare class Machine<mDT> {
696
798
  * Instruct the machine to complete an action. Synonym for {@link action}.
697
799
  *
698
800
  * ```typescript
699
- * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
801
+ * const light = sm`
802
+ * off 'start' -> red;
803
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
804
+ * [red yellow green] 'shutdown' ~> off;
805
+ * `;
700
806
  *
701
- * light.state(); // 'red'
702
- * light.do('next'); // true
703
- * light.state(); // 'green'
807
+ * light.state(); // 'off'
808
+ * light.do('start'); // true
809
+ * light.state(); // 'red'
810
+ * light.do('next'); // true
811
+ * light.state(); // 'green'
812
+ * light.do('next'); // true
813
+ * light.state(); // 'yellow'
814
+ * light.do('dance'); // !! false - no such action
815
+ * light.state(); // 'yellow'
816
+ * light.do('start'); // !! false - yellow does not have the action start
817
+ * light.state(); // 'yellow'
704
818
  * ```
705
819
  *
706
820
  * @typeparam mDT The type of the machine data member; usually omitted
707
- *
821
+ b *
708
822
  * @param actionName The action to engage
709
823
  *
710
824
  * @param newData The data change to insert during the action
@@ -716,11 +830,21 @@ declare class Machine<mDT> {
716
830
  * Instruct the machine to complete a transition. Synonym for {@link go}.
717
831
  *
718
832
  * ```typescript
719
- * const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
833
+ * const light = sm`
834
+ * off 'start' -> red;
835
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
836
+ * [red yellow green] 'shutdown' ~> off;
837
+ * `;
720
838
  *
721
- * light.state(); // 'red'
722
- * light.transition('green'); // true
723
- * light.state(); // 'green'
839
+ * light.state(); // 'off'
840
+ * light.go('red'); // true
841
+ * light.state(); // 'red'
842
+ * light.go('green'); // true
843
+ * light.state(); // 'green'
844
+ * light.go('blue'); // !! false - no such state
845
+ * light.state(); // 'green'
846
+ * light.go('red'); // !! false - green may not go directly to red, only to yellow
847
+ * light.state(); // 'green'
724
848
  * ```
725
849
  *
726
850
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -833,4 +957,4 @@ declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResu
833
957
  declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
834
958
  declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
835
959
  declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
836
- export { version, transfer_state_properties, Machine, deserialize, 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 };
960
+ export { version, transfer_state_properties, Machine, deserialize, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, unique, find_repeated, 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
@@ -35,6 +35,10 @@ declare type JssmSerialization<DataType> = {
35
35
  history_capacity: number;
36
36
  data: DataType;
37
37
  };
38
+ declare type JssmPropertyDefinition = {
39
+ name: string;
40
+ default_value?: any;
41
+ };
38
42
  declare type JssmTransitionPermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
39
43
  declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
40
44
  declare type JssmTransition<DataType> = {
@@ -48,7 +52,7 @@ declare type JssmTransition<DataType> = {
48
52
  forced_only: boolean;
49
53
  main_path: boolean;
50
54
  };
51
- declare type JssmTransitions<DataType> = Array<JssmTransition<DataType>>;
55
+ declare type JssmTransitions<DataType> = JssmTransition<DataType>[];
52
56
  declare type JssmTransitionList = {
53
57
  entrances: Array<StateType>;
54
58
  exits: Array<StateType>;
@@ -93,6 +97,7 @@ declare type JssmGenericMachine<DataType> = {
93
97
  declare type JssmStateDeclarationRule = {
94
98
  key: string;
95
99
  value: any;
100
+ name?: string;
96
101
  };
97
102
  declare type JssmStateDeclaration = {
98
103
  declarations: Array<JssmStateDeclarationRule>;
@@ -104,6 +109,10 @@ declare type JssmStateDeclaration = {
104
109
  backgroundColor?: JssmColor;
105
110
  borderColor?: JssmColor;
106
111
  state: StateType;
112
+ property?: {
113
+ name: string;
114
+ value: unknown;
115
+ };
107
116
  };
108
117
  declare type JssmGenericConfig<DataType> = {
109
118
  graph_layout?: JssmLayout;
@@ -125,7 +134,9 @@ declare type JssmGenericConfig<DataType> = {
125
134
  dot_preamble?: string;
126
135
  start_states: Array<StateType>;
127
136
  end_states?: Array<StateType>;
128
- state_declaration?: Array<Object>;
137
+ state_declaration?: Object[];
138
+ property_definition?: JssmPropertyDefinition[];
139
+ state_property?: JssmPropertyDefinition[];
129
140
  arrange_declaration?: Array<Array<StateType>>;
130
141
  arrange_start_declaration?: Array<Array<StateType>>;
131
142
  arrange_end_declaration?: Array<Array<StateType>>;
@@ -160,6 +171,8 @@ declare type JssmCompileSeStart<DataType> = {
160
171
  key: string;
161
172
  value?: string | number;
162
173
  name?: string;
174
+ state?: string;
175
+ default_value?: any;
163
176
  };
164
177
  declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
165
178
  declare type JssmParseFunctionType = (string: any) => JssmParseTree;
@@ -275,4 +288,4 @@ declare type JssmErrorExtendedInfo = {
275
288
  requested_state?: StateType | undefined;
276
289
  };
277
290
  declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
278
- export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmHistory, JssmSerialization, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
291
+ export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
package/jssm_util.d.ts CHANGED
@@ -35,6 +35,13 @@ declare function seq(n: number): number[];
35
35
  declare const histograph: Function;
36
36
  declare const weighted_sample_select: Function;
37
37
  declare const weighted_histo_key: Function;
38
+ /*******
39
+ *
40
+ * Internal method generating names for edges for the hook lookup map. Not
41
+ * meant for external use.
42
+ *
43
+ */
44
+ declare function name_bind_prop_and_state(prop: string, state: string): string;
38
45
  /*******
39
46
  *
40
47
  * Internal method generating names for edges for the hook lookup map. Not
@@ -57,4 +64,40 @@ declare const named_hook_name: (from: string, to: string, action: string) => str
57
64
  *
58
65
  */
59
66
  declare const make_mulberry_rand: (a?: number | undefined) => () => number;
60
- export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name, make_mulberry_rand };
67
+ /*******
68
+ *
69
+ * Reduces an array to its unique contents. Compares with `===` and makes no
70
+ * effort to deep-compare contents; two matching arrays or objects contained
71
+ * will be treated as distinct, according to javascript rules. This also means
72
+ * that `NaNs` will be ***dropped***, because they do not self-compare.
73
+ *
74
+ * ```typescript
75
+ * unique( [] ); // []
76
+ * unique( [0,0] ); // [0]
77
+ * unique( [0,1,2, 0,1,2, 0,1,2] ); // [0,1,2]
78
+ * unique( [ [1], [1] ] ); // [ [1], [1] ] because arrays don't match
79
+ * unique( [0,NaN,2] ); // [0,2]
80
+ * ```
81
+ *
82
+ */
83
+ declare const unique: <T>(arr?: T[]) => T[];
84
+ /*******
85
+ *
86
+ * Lists all repeated items in an array along with their counts. Subject to
87
+ * matching rules of Map. `NaN` is manually removed because of conflict rules
88
+ * around {@link unique}. Because these are compared with `===` and because
89
+ * arrays and objects never match that way unless they're the same object,
90
+ * arrays and objects are never considered repeats.
91
+ *
92
+ * ```typescript
93
+ * find_repeated<string>([ ]); // []
94
+ * find_repeated<string>([ "one" ]); // []
95
+ * find_repeated<string>([ "one", "two" ]); // []
96
+ * find_repeated<string>([ "one", "one" ]); // [ ["one", 2] ]
97
+ * find_repeated<string>([ "one", "two", "one" ]); // [ ["one", 2] ]
98
+ * find_repeated<number>([ 0, NaN, 0, NaN ]); // [ [0, 2] ]
99
+ * ```
100
+ *
101
+ */
102
+ declare function find_repeated<T>(arr: T[]): [T, number][];
103
+ export { seq, unique, find_repeated, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name, make_mulberry_rand };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jssm",
3
- "version": "5.78.0",
3
+ "version": "5.79.0",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },