jssm 5.77.1 → 5.79.1
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/CHANGELOG.md +37 -44
- package/README.md +2 -2
- package/dist/es6/jssm-dot.js +1 -1
- package/dist/es6/jssm.d.ts +166 -16
- package/dist/es6/jssm.js +277 -22
- package/dist/es6/jssm_types.d.ts +27 -3
- package/dist/es6/jssm_util.d.ts +44 -1
- package/dist/es6/jssm_util.js +68 -1
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +166 -16
- package/jssm_types.d.ts +27 -3
- package/jssm_util.d.ts +44 -1
- package/package.json +1 -1
package/jssm.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
declare type StateType = string;
|
|
2
|
-
import { circular_buffer } from 'circular_buffer_js';
|
|
3
2
|
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
|
|
4
|
-
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
|
|
5
|
-
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
|
|
3
|
+
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
|
|
4
|
+
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
|
|
6
5
|
import { shapes, gviz_shapes, named_colors } from './jssm_constants';
|
|
7
6
|
import { version } from './version';
|
|
8
7
|
/*********
|
|
@@ -251,9 +250,12 @@ declare class Machine<mDT> {
|
|
|
251
250
|
_post_main_transition_hook: HookHandler<mDT> | undefined;
|
|
252
251
|
_post_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
253
252
|
_post_any_transition_hook: HookHandler<mDT> | undefined;
|
|
254
|
-
|
|
253
|
+
_property_keys: Set<string>;
|
|
254
|
+
_default_properties: Map<string, any>;
|
|
255
|
+
_state_properties: Map<string, any>;
|
|
256
|
+
_history: JssmHistory<mDT>;
|
|
255
257
|
_history_length: number;
|
|
256
|
-
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>);
|
|
257
259
|
/********
|
|
258
260
|
*
|
|
259
261
|
* Internal method for fabricating states. Not meant for external use.
|
|
@@ -295,6 +297,122 @@ declare class Machine<mDT> {
|
|
|
295
297
|
*
|
|
296
298
|
*/
|
|
297
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 a given property name. If missing on the state
|
|
318
|
+
* and without a global default, throw, unlike {@link prop}, which would
|
|
319
|
+
* return `undefined` instead.
|
|
320
|
+
*
|
|
321
|
+
* ```typescript
|
|
322
|
+
*
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* @param name The relevant property name to look up
|
|
326
|
+
*
|
|
327
|
+
* @returns The value behind the prop name. Because functional props are
|
|
328
|
+
* evaluated as getters, this can be anything.
|
|
329
|
+
*
|
|
330
|
+
*/
|
|
331
|
+
strict_prop(name: string): any;
|
|
332
|
+
/*********
|
|
333
|
+
*
|
|
334
|
+
* Get the current value of every prop, as an object. If no current definition
|
|
335
|
+
* exists for a prop - that is, if the prop was defined without a default and
|
|
336
|
+
* the current state also doesn't define the prop - then that prop will be listed
|
|
337
|
+
* in the returned object with a value of `undefined`.
|
|
338
|
+
*
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const traffic_light = sm`
|
|
341
|
+
*
|
|
342
|
+
* property can_go default true;
|
|
343
|
+
* property hesitate default true;
|
|
344
|
+
* property stop_first default false;
|
|
345
|
+
*
|
|
346
|
+
* Off -> Red => Green => Yellow => Red;
|
|
347
|
+
* [Red Yellow Green] ~> [Off FlashingRed];
|
|
348
|
+
* FlashingRed -> Red;
|
|
349
|
+
*
|
|
350
|
+
* state Red: { property stop_first true; property can_go false; };
|
|
351
|
+
* state Off: { property stop_first true; };
|
|
352
|
+
* state FlashingRed: { property stop_first true; };
|
|
353
|
+
* state Green: { property hesitate false; };
|
|
354
|
+
*
|
|
355
|
+
* `;
|
|
356
|
+
*
|
|
357
|
+
* traffic_light.state(); // Off
|
|
358
|
+
* traffic_light.props(); // { can_go: true, hesitate: true, stop_first: true; }
|
|
359
|
+
*
|
|
360
|
+
* traffic_light.go('Red');
|
|
361
|
+
* traffic_light.props(); // { can_go: false, hesitate: true, stop_first: true; }
|
|
362
|
+
*
|
|
363
|
+
* traffic_light.go('Green');
|
|
364
|
+
* traffic_light.props(); // { can_go: true, hesitate: false, stop_first: false; }
|
|
365
|
+
* ```
|
|
366
|
+
*
|
|
367
|
+
*/
|
|
368
|
+
props(): object;
|
|
369
|
+
/*********
|
|
370
|
+
*
|
|
371
|
+
* Get the current value of every prop, as an object. Compare
|
|
372
|
+
* {@link prop_map}, which returns a `Map`.
|
|
373
|
+
*
|
|
374
|
+
* ```typescript
|
|
375
|
+
*
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
*/
|
|
379
|
+
/*********
|
|
380
|
+
*
|
|
381
|
+
* Get the current value of every prop, as an object. Compare
|
|
382
|
+
* {@link prop_map}, which returns a `Map`. Akin to {@link strict_prop},
|
|
383
|
+
* this throws if a required prop is missing.
|
|
384
|
+
*
|
|
385
|
+
* ```typescript
|
|
386
|
+
*
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
*/
|
|
390
|
+
/*********
|
|
391
|
+
*
|
|
392
|
+
* Check whether a given string is a known property's name.
|
|
393
|
+
*
|
|
394
|
+
* ```typescript
|
|
395
|
+
* const example = sm`property foo default 1; a->b;`;
|
|
396
|
+
*
|
|
397
|
+
* example.known_prop('foo'); // true
|
|
398
|
+
* example.known_prop('bar'); // false
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @param prop_name The relevant property name to look up
|
|
402
|
+
*
|
|
403
|
+
*/
|
|
404
|
+
known_prop(prop_name: string): boolean;
|
|
405
|
+
/*********
|
|
406
|
+
*
|
|
407
|
+
* List all known property names. If you'd also like values, use
|
|
408
|
+
* {@link props} instead. The order of the properties is not defined, and
|
|
409
|
+
* the properties generally will not be sorted.
|
|
410
|
+
*
|
|
411
|
+
* ```typescript
|
|
412
|
+
* ```
|
|
413
|
+
*
|
|
414
|
+
*/
|
|
415
|
+
known_props(): string[];
|
|
298
416
|
/********
|
|
299
417
|
*
|
|
300
418
|
* Check whether a given state is final (either has no exits or is marked
|
|
@@ -330,10 +448,19 @@ declare class Machine<mDT> {
|
|
|
330
448
|
* console.log( final_test.is_final() ); // true
|
|
331
449
|
* ```
|
|
332
450
|
*
|
|
451
|
+
*/
|
|
452
|
+
is_final(): boolean;
|
|
453
|
+
/********
|
|
454
|
+
*
|
|
455
|
+
* Serialize the current machine, including all defining state but not the
|
|
456
|
+
* machine string, to a structure. This means you will need the machine
|
|
457
|
+
* string to recreate (to not waste repeated space;) if you want the machine
|
|
458
|
+
* string embedded, call {@link serialize_with_string} instead.
|
|
459
|
+
*
|
|
333
460
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
334
461
|
*
|
|
335
462
|
*/
|
|
336
|
-
|
|
463
|
+
serialize(comment?: string | undefined): JssmSerialization<mDT>;
|
|
337
464
|
graph_layout(): string;
|
|
338
465
|
dot_preamble(): string;
|
|
339
466
|
machine_author(): Array<string>;
|
|
@@ -688,15 +815,27 @@ declare class Machine<mDT> {
|
|
|
688
815
|
* Instruct the machine to complete an action. Synonym for {@link action}.
|
|
689
816
|
*
|
|
690
817
|
* ```typescript
|
|
691
|
-
* const light = sm`
|
|
818
|
+
* const light = sm`
|
|
819
|
+
* off 'start' -> red;
|
|
820
|
+
* red 'next' -> green 'next' -> yellow 'next' -> red;
|
|
821
|
+
* [red yellow green] 'shutdown' ~> off;
|
|
822
|
+
* `;
|
|
692
823
|
*
|
|
693
|
-
* light.state();
|
|
694
|
-
* light.do('
|
|
695
|
-
* light.state();
|
|
824
|
+
* light.state(); // 'off'
|
|
825
|
+
* light.do('start'); // true
|
|
826
|
+
* light.state(); // 'red'
|
|
827
|
+
* light.do('next'); // true
|
|
828
|
+
* light.state(); // 'green'
|
|
829
|
+
* light.do('next'); // true
|
|
830
|
+
* light.state(); // 'yellow'
|
|
831
|
+
* light.do('dance'); // !! false - no such action
|
|
832
|
+
* light.state(); // 'yellow'
|
|
833
|
+
* light.do('start'); // !! false - yellow does not have the action start
|
|
834
|
+
* light.state(); // 'yellow'
|
|
696
835
|
* ```
|
|
697
836
|
*
|
|
698
837
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
699
|
-
|
|
838
|
+
b *
|
|
700
839
|
* @param actionName The action to engage
|
|
701
840
|
*
|
|
702
841
|
* @param newData The data change to insert during the action
|
|
@@ -708,11 +847,21 @@ declare class Machine<mDT> {
|
|
|
708
847
|
* Instruct the machine to complete a transition. Synonym for {@link go}.
|
|
709
848
|
*
|
|
710
849
|
* ```typescript
|
|
711
|
-
* const light = sm`
|
|
850
|
+
* const light = sm`
|
|
851
|
+
* off 'start' -> red;
|
|
852
|
+
* red 'next' -> green 'next' -> yellow 'next' -> red;
|
|
853
|
+
* [red yellow green] 'shutdown' ~> off;
|
|
854
|
+
* `;
|
|
712
855
|
*
|
|
713
|
-
* light.state();
|
|
714
|
-
* light.
|
|
715
|
-
* light.state();
|
|
856
|
+
* light.state(); // 'off'
|
|
857
|
+
* light.go('red'); // true
|
|
858
|
+
* light.state(); // 'red'
|
|
859
|
+
* light.go('green'); // true
|
|
860
|
+
* light.state(); // 'green'
|
|
861
|
+
* light.go('blue'); // !! false - no such state
|
|
862
|
+
* light.state(); // 'green'
|
|
863
|
+
* light.go('red'); // !! false - green may not go directly to red, only to yellow
|
|
864
|
+
* light.state(); // 'green'
|
|
716
865
|
* ```
|
|
717
866
|
*
|
|
718
867
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -824,4 +973,5 @@ declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Par
|
|
|
824
973
|
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
|
|
825
974
|
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
|
|
826
975
|
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
|
|
827
|
-
|
|
976
|
+
declare function deserialize<mDT>(machine_string: string, ser: JssmSerialization<mDT>): Machine<mDT>;
|
|
977
|
+
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { circular_buffer } from 'circular_buffer_js';
|
|
1
2
|
declare type StateType = string;
|
|
2
3
|
declare type JssmSuccess = {
|
|
3
4
|
success: true;
|
|
@@ -25,6 +26,19 @@ declare type JssmCorner = 'regular' | 'rounded' | 'lined';
|
|
|
25
26
|
declare type JssmLineStyle = 'solid' | 'dashed' | 'dotted';
|
|
26
27
|
declare type FslDirection = 'up' | 'right' | 'down' | 'left';
|
|
27
28
|
declare type FslTheme = 'default' | 'ocean' | 'modern' | 'none';
|
|
29
|
+
declare type JssmSerialization<DataType> = {
|
|
30
|
+
jssm_version: string;
|
|
31
|
+
timestamp: number;
|
|
32
|
+
comment?: string | undefined;
|
|
33
|
+
state: StateType;
|
|
34
|
+
history: [string, DataType][];
|
|
35
|
+
history_capacity: number;
|
|
36
|
+
data: DataType;
|
|
37
|
+
};
|
|
38
|
+
declare type JssmPropertyDefinition = {
|
|
39
|
+
name: string;
|
|
40
|
+
default_value?: any;
|
|
41
|
+
};
|
|
28
42
|
declare type JssmTransitionPermitter<DataType> = (OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
29
43
|
declare type JssmTransitionPermitterMaybeArray<DataType> = JssmTransitionPermitter<DataType> | Array<JssmTransitionPermitter<DataType>>;
|
|
30
44
|
declare type JssmTransition<DataType> = {
|
|
@@ -38,7 +52,7 @@ declare type JssmTransition<DataType> = {
|
|
|
38
52
|
forced_only: boolean;
|
|
39
53
|
main_path: boolean;
|
|
40
54
|
};
|
|
41
|
-
declare type JssmTransitions<DataType> =
|
|
55
|
+
declare type JssmTransitions<DataType> = JssmTransition<DataType>[];
|
|
42
56
|
declare type JssmTransitionList = {
|
|
43
57
|
entrances: Array<StateType>;
|
|
44
58
|
exits: Array<StateType>;
|
|
@@ -83,6 +97,7 @@ declare type JssmGenericMachine<DataType> = {
|
|
|
83
97
|
declare type JssmStateDeclarationRule = {
|
|
84
98
|
key: string;
|
|
85
99
|
value: any;
|
|
100
|
+
name?: string;
|
|
86
101
|
};
|
|
87
102
|
declare type JssmStateDeclaration = {
|
|
88
103
|
declarations: Array<JssmStateDeclarationRule>;
|
|
@@ -94,6 +109,10 @@ declare type JssmStateDeclaration = {
|
|
|
94
109
|
backgroundColor?: JssmColor;
|
|
95
110
|
borderColor?: JssmColor;
|
|
96
111
|
state: StateType;
|
|
112
|
+
property?: {
|
|
113
|
+
name: string;
|
|
114
|
+
value: unknown;
|
|
115
|
+
};
|
|
97
116
|
};
|
|
98
117
|
declare type JssmGenericConfig<DataType> = {
|
|
99
118
|
graph_layout?: JssmLayout;
|
|
@@ -115,7 +134,9 @@ declare type JssmGenericConfig<DataType> = {
|
|
|
115
134
|
dot_preamble?: string;
|
|
116
135
|
start_states: Array<StateType>;
|
|
117
136
|
end_states?: Array<StateType>;
|
|
118
|
-
state_declaration?:
|
|
137
|
+
state_declaration?: Object[];
|
|
138
|
+
property_definition?: JssmPropertyDefinition[];
|
|
139
|
+
state_property?: JssmPropertyDefinition[];
|
|
119
140
|
arrange_declaration?: Array<Array<StateType>>;
|
|
120
141
|
arrange_start_declaration?: Array<Array<StateType>>;
|
|
121
142
|
arrange_end_declaration?: Array<Array<StateType>>;
|
|
@@ -150,6 +171,8 @@ declare type JssmCompileSeStart<DataType> = {
|
|
|
150
171
|
key: string;
|
|
151
172
|
value?: string | number;
|
|
152
173
|
name?: string;
|
|
174
|
+
state?: string;
|
|
175
|
+
default_value?: any;
|
|
153
176
|
};
|
|
154
177
|
declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
|
|
155
178
|
declare type JssmParseFunctionType = (string: any) => JssmParseTree;
|
|
@@ -264,4 +287,5 @@ declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
|
|
|
264
287
|
declare type JssmErrorExtendedInfo = {
|
|
265
288
|
requested_state?: StateType | undefined;
|
|
266
289
|
};
|
|
267
|
-
|
|
290
|
+
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
|
|
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
|
-
|
|
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 };
|