jssm 5.78.0 → 5.79.2

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,13 @@ 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>;
256
+ _required_properties: Set<string>;
253
257
  _history: JssmHistory<mDT>;
254
258
  _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>);
259
+ 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
260
  /********
257
261
  *
258
262
  * Internal method for fabricating states. Not meant for external use.
@@ -294,6 +298,122 @@ declare class Machine<mDT> {
294
298
  *
295
299
  */
296
300
  data(): mDT;
301
+ /*********
302
+ *
303
+ * Get the current value of a given property name.
304
+ *
305
+ * ```typescript
306
+ *
307
+ * ```
308
+ *
309
+ * @param name The relevant property name to look up
310
+ *
311
+ * @returns The value behind the prop name. Because functional props are
312
+ * evaluated as getters, this can be anything.
313
+ *
314
+ */
315
+ prop(name: string): any;
316
+ /*********
317
+ *
318
+ * Get the current value of a given property name. If missing on the state
319
+ * and without a global default, throw, unlike {@link prop}, which would
320
+ * return `undefined` instead.
321
+ *
322
+ * ```typescript
323
+ *
324
+ * ```
325
+ *
326
+ * @param name The relevant property name to look up
327
+ *
328
+ * @returns The value behind the prop name. Because functional props are
329
+ * evaluated as getters, this can be anything.
330
+ *
331
+ */
332
+ strict_prop(name: string): any;
333
+ /*********
334
+ *
335
+ * Get the current value of every prop, as an object. If no current definition
336
+ * exists for a prop - that is, if the prop was defined without a default and
337
+ * the current state also doesn't define the prop - then that prop will be listed
338
+ * in the returned object with a value of `undefined`.
339
+ *
340
+ * ```typescript
341
+ * const traffic_light = sm`
342
+ *
343
+ * property can_go default true;
344
+ * property hesitate default true;
345
+ * property stop_first default false;
346
+ *
347
+ * Off -> Red => Green => Yellow => Red;
348
+ * [Red Yellow Green] ~> [Off FlashingRed];
349
+ * FlashingRed -> Red;
350
+ *
351
+ * state Red: { property stop_first true; property can_go false; };
352
+ * state Off: { property stop_first true; };
353
+ * state FlashingRed: { property stop_first true; };
354
+ * state Green: { property hesitate false; };
355
+ *
356
+ * `;
357
+ *
358
+ * traffic_light.state(); // Off
359
+ * traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true; }
360
+ *
361
+ * traffic_light.go('Red');
362
+ * traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true; }
363
+ *
364
+ * traffic_light.go('Green');
365
+ * traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
366
+ * ```
367
+ *
368
+ */
369
+ props(): object;
370
+ /*********
371
+ *
372
+ * Get the current value of every prop, as an object. Compare
373
+ * {@link prop_map}, which returns a `Map`.
374
+ *
375
+ * ```typescript
376
+ *
377
+ * ```
378
+ *
379
+ */
380
+ /*********
381
+ *
382
+ * Get the current value of every prop, as an object. Compare
383
+ * {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
384
+ * this throws if a required prop is missing.
385
+ *
386
+ * ```typescript
387
+ *
388
+ * ```
389
+ *
390
+ */
391
+ /*********
392
+ *
393
+ * Check whether a given string is a known property's name.
394
+ *
395
+ * ```typescript
396
+ * const example = sm`property foo default 1; a->b;`;
397
+ *
398
+ * example.known_prop('foo'); // true
399
+ * example.known_prop('bar'); // false
400
+ * ```
401
+ *
402
+ * @param prop_name The relevant property name to look up
403
+ *
404
+ */
405
+ known_prop(prop_name: string): boolean;
406
+ /*********
407
+ *
408
+ * List all known property names. If you'd also like values, use
409
+ * {@link props} instead. The order of the properties is not defined, and
410
+ * the properties generally will not be sorted.
411
+ *
412
+ * ```typescript
413
+ * ```
414
+ *
415
+ */
416
+ known_props(): string[];
297
417
  /********
298
418
  *
299
419
  * Check whether a given state is final (either has no exits or is marked
@@ -696,15 +816,27 @@ declare class Machine<mDT> {
696
816
  * Instruct the machine to complete an action. Synonym for {@link action}.
697
817
  *
698
818
  * ```typescript
699
- * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
819
+ * const light = sm`
820
+ * off 'start' -> red;
821
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
822
+ * [red yellow green] 'shutdown' ~> off;
823
+ * `;
700
824
  *
701
- * light.state(); // 'red'
702
- * light.do('next'); // true
703
- * light.state(); // 'green'
825
+ * light.state(); // 'off'
826
+ * light.do('start'); // true
827
+ * light.state(); // 'red'
828
+ * light.do('next'); // true
829
+ * light.state(); // 'green'
830
+ * light.do('next'); // true
831
+ * light.state(); // 'yellow'
832
+ * light.do('dance'); // !! false - no such action
833
+ * light.state(); // 'yellow'
834
+ * light.do('start'); // !! false - yellow does not have the action start
835
+ * light.state(); // 'yellow'
704
836
  * ```
705
837
  *
706
838
  * @typeparam mDT The type of the machine data member; usually omitted
707
- *
839
+ b *
708
840
  * @param actionName The action to engage
709
841
  *
710
842
  * @param newData The data change to insert during the action
@@ -716,11 +848,21 @@ declare class Machine<mDT> {
716
848
  * Instruct the machine to complete a transition. Synonym for {@link go}.
717
849
  *
718
850
  * ```typescript
719
- * const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
851
+ * const light = sm`
852
+ * off 'start' -> red;
853
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
854
+ * [red yellow green] 'shutdown' ~> off;
855
+ * `;
720
856
  *
721
- * light.state(); // 'red'
722
- * light.transition('green'); // true
723
- * light.state(); // 'green'
857
+ * light.state(); // 'off'
858
+ * light.go('red'); // true
859
+ * light.state(); // 'red'
860
+ * light.go('green'); // true
861
+ * light.state(); // 'green'
862
+ * light.go('blue'); // !! false - no such state
863
+ * light.state(); // 'green'
864
+ * light.go('red'); // !! false - green may not go directly to red, only to yellow
865
+ * light.state(); // 'green'
724
866
  * ```
725
867
  *
726
868
  * @typeparam mDT The type of the machine data member; usually omitted
@@ -833,4 +975,4 @@ declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResu
833
975
  declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
834
976
  declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
835
977
  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 };
978
+ 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,11 @@ 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
+ required?: boolean;
42
+ };
38
43
  declare type JssmTransitionPermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
39
44
  declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
40
45
  declare type JssmTransition<DataType> = {
@@ -48,7 +53,7 @@ declare type JssmTransition<DataType> = {
48
53
  forced_only: boolean;
49
54
  main_path: boolean;
50
55
  };
51
- declare type JssmTransitions<DataType> = Array<JssmTransition<DataType>>;
56
+ declare type JssmTransitions<DataType> = JssmTransition<DataType>[];
52
57
  declare type JssmTransitionList = {
53
58
  entrances: Array<StateType>;
54
59
  exits: Array<StateType>;
@@ -93,6 +98,7 @@ declare type JssmGenericMachine<DataType> = {
93
98
  declare type JssmStateDeclarationRule = {
94
99
  key: string;
95
100
  value: any;
101
+ name?: string;
96
102
  };
97
103
  declare type JssmStateDeclaration = {
98
104
  declarations: Array<JssmStateDeclarationRule>;
@@ -104,6 +110,10 @@ declare type JssmStateDeclaration = {
104
110
  backgroundColor?: JssmColor;
105
111
  borderColor?: JssmColor;
106
112
  state: StateType;
113
+ property?: {
114
+ name: string;
115
+ value: unknown;
116
+ };
107
117
  };
108
118
  declare type JssmGenericConfig<DataType> = {
109
119
  graph_layout?: JssmLayout;
@@ -125,7 +135,9 @@ declare type JssmGenericConfig<DataType> = {
125
135
  dot_preamble?: string;
126
136
  start_states: Array<StateType>;
127
137
  end_states?: Array<StateType>;
128
- state_declaration?: Array<Object>;
138
+ state_declaration?: Object[];
139
+ property_definition?: JssmPropertyDefinition[];
140
+ state_property?: JssmPropertyDefinition[];
129
141
  arrange_declaration?: Array<Array<StateType>>;
130
142
  arrange_start_declaration?: Array<Array<StateType>>;
131
143
  arrange_end_declaration?: Array<Array<StateType>>;
@@ -160,6 +172,9 @@ declare type JssmCompileSeStart<DataType> = {
160
172
  key: string;
161
173
  value?: string | number;
162
174
  name?: string;
175
+ state?: string;
176
+ default_value?: any;
177
+ required?: boolean;
163
178
  };
164
179
  declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
165
180
  declare type JssmParseFunctionType = (string: any) => JssmParseTree;
@@ -275,4 +290,4 @@ declare type JssmErrorExtendedInfo = {
275
290
  requested_state?: StateType | undefined;
276
291
  };
277
292
  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 };
293
+ 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.2",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },