jssm 5.77.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.
@@ -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> = Array<JssmTransition<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?: Array<Object>;
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
- export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
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 };
@@ -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 };
@@ -1,3 +1,4 @@
1
+ import { JssmError } from './jssm_error';
1
2
  /*******
2
3
  *
3
4
  * Predicate for validating an array for uniqueness. Not generally meant for
@@ -70,6 +71,21 @@ const weighted_histo_key = (n, opts, prob_prop, extract) => // TODO FIXME no any
70
71
  histograph(weighted_sample_select(n, opts, prob_prop)
71
72
  .map((s) => s[extract] // TODO FIXME eslint-disable-line flowtype/no-weak-types
72
73
  ));
74
+ /*******
75
+ *
76
+ * Internal method generating names for edges for the hook lookup map. Not
77
+ * meant for external use.
78
+ *
79
+ */
80
+ function name_bind_prop_and_state(prop, state) {
81
+ if (typeof prop !== 'string') {
82
+ throw new JssmError(undefined, `Name of property must be a string; got ${prop}`);
83
+ }
84
+ if (typeof state !== 'string') {
85
+ throw new JssmError(undefined, `Name of state must be a string; got ${prop}`);
86
+ }
87
+ return JSON.stringify([prop, state]);
88
+ }
73
89
  /*******
74
90
  *
75
91
  * Internal method generating names for edges for the hook lookup map. Not
@@ -100,4 +116,55 @@ const make_mulberry_rand = (a) => () => {
100
116
  t ^= t + Math.imul(t ^ t >>> 7, t | 61);
101
117
  return ((t ^ t >>> 14) >>> 0) / 4294967296;
102
118
  };
103
- 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 };
119
+ /*******
120
+ *
121
+ * Reduces an array to its unique contents. Compares with `===` and makes no
122
+ * effort to deep-compare contents; two matching arrays or objects contained
123
+ * will be treated as distinct, according to javascript rules. This also means
124
+ * that `NaNs` will be ***dropped***, because they do not self-compare.
125
+ *
126
+ * ```typescript
127
+ * unique( [] ); // []
128
+ * unique( [0,0] ); // [0]
129
+ * unique( [0,1,2, 0,1,2, 0,1,2] ); // [0,1,2]
130
+ * unique( [ [1], [1] ] ); // [ [1], [1] ] because arrays don't match
131
+ * unique( [0,NaN,2] ); // [0,2]
132
+ * ```
133
+ *
134
+ */
135
+ const unique = (arr) => arr.filter((v, i, a) => a.indexOf(v) === i);
136
+ /*******
137
+ *
138
+ * Lists all repeated items in an array along with their counts. Subject to
139
+ * matching rules of Map. `NaN` is manually removed because of conflict rules
140
+ * around {@link unique}. Because these are compared with `===` and because
141
+ * arrays and objects never match that way unless they're the same object,
142
+ * arrays and objects are never considered repeats.
143
+ *
144
+ * ```typescript
145
+ * find_repeated<string>([ ]); // []
146
+ * find_repeated<string>([ "one" ]); // []
147
+ * find_repeated<string>([ "one", "two" ]); // []
148
+ * find_repeated<string>([ "one", "one" ]); // [ ["one", 2] ]
149
+ * find_repeated<string>([ "one", "two", "one" ]); // [ ["one", 2] ]
150
+ * find_repeated<number>([ 0, NaN, 0, NaN ]); // [ [0, 2] ]
151
+ * ```
152
+ *
153
+ */
154
+ function find_repeated(arr) {
155
+ const uniqued = unique(arr);
156
+ if (uniqued.length !== arr.length) {
157
+ const residue_keys = new Map();
158
+ arr.forEach(k => residue_keys.set(k, residue_keys.has(k)
159
+ ? (residue_keys.get(k) + 1)
160
+ : 1));
161
+ uniqued.forEach(k => residue_keys.set(k, residue_keys.get(k) - 1));
162
+ return [...residue_keys.entries()]
163
+ .filter((e) => ((e[1] > 0) && (!(Number.isNaN(e[0])))))
164
+ .map((e) => [e[0], e[1] + 1]);
165
+ }
166
+ else {
167
+ return [];
168
+ }
169
+ }
170
+ 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 };
@@ -1,2 +1,2 @@
1
- const version = "5.77.0";
1
+ const version = "5.79.0";
2
2
  export { version };