jssm 5.72.5 → 5.74.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/CHANGELOG.md +47 -38
- package/README.md +2 -2
- package/dist/es6/jssm.d.ts +113 -1
- package/dist/es6/jssm.js +290 -12
- package/dist/es6/jssm_types.d.ts +51 -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 +113 -1
- package/jssm_types.d.ts +51 -1
- package/package.json +2 -1
package/jssm.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare type StateType = string;
|
|
2
|
+
import { circular_buffer } from 'circular_buffer_js';
|
|
2
3
|
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
|
|
3
4
|
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
|
|
4
5
|
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
|
|
@@ -233,7 +234,26 @@ declare class Machine<mDT> {
|
|
|
233
234
|
_main_transition_hook: HookHandler<mDT> | undefined;
|
|
234
235
|
_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
235
236
|
_any_transition_hook: HookHandler<mDT> | undefined;
|
|
236
|
-
|
|
237
|
+
_has_post_hooks: boolean;
|
|
238
|
+
_has_post_basic_hooks: boolean;
|
|
239
|
+
_has_post_named_hooks: boolean;
|
|
240
|
+
_has_post_entry_hooks: boolean;
|
|
241
|
+
_has_post_exit_hooks: boolean;
|
|
242
|
+
_has_post_global_action_hooks: boolean;
|
|
243
|
+
_has_post_transition_hooks: boolean;
|
|
244
|
+
_post_hooks: Map<string, HookHandler<mDT>>;
|
|
245
|
+
_post_named_hooks: Map<string, HookHandler<mDT>>;
|
|
246
|
+
_post_entry_hooks: Map<string, HookHandler<mDT>>;
|
|
247
|
+
_post_exit_hooks: Map<string, HookHandler<mDT>>;
|
|
248
|
+
_post_global_action_hooks: Map<string, HookHandler<mDT>>;
|
|
249
|
+
_post_any_action_hook: HookHandler<mDT> | undefined;
|
|
250
|
+
_post_standard_transition_hook: HookHandler<mDT> | undefined;
|
|
251
|
+
_post_main_transition_hook: HookHandler<mDT> | undefined;
|
|
252
|
+
_post_forced_transition_hook: HookHandler<mDT> | undefined;
|
|
253
|
+
_post_any_transition_hook: HookHandler<mDT> | undefined;
|
|
254
|
+
_history: circular_buffer<[StateType, mDT]>;
|
|
255
|
+
_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>);
|
|
237
257
|
/********
|
|
238
258
|
*
|
|
239
259
|
* Internal method for fabricating states. Not meant for external use.
|
|
@@ -549,8 +569,100 @@ declare class Machine<mDT> {
|
|
|
549
569
|
hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
550
570
|
hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
551
571
|
hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
572
|
+
post_hook(from: string, to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
573
|
+
post_hook_action(from: string, to: string, action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
574
|
+
post_hook_global_action(action: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
575
|
+
post_hook_any_action(handler: HookHandler<mDT>): Machine<mDT>;
|
|
576
|
+
post_hook_standard_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
577
|
+
post_hook_main_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
578
|
+
post_hook_forced_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
579
|
+
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
|
|
580
|
+
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
581
|
+
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
552
582
|
edges_between(from: string, to: string): JssmTransition<mDT>[];
|
|
553
583
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
584
|
+
/*********
|
|
585
|
+
*
|
|
586
|
+
* Get a truncated history of the recent states and data of the machine.
|
|
587
|
+
* Turned off by default; configure with `.from('...', {data: 5})` by length,
|
|
588
|
+
* or set `.history_length` at runtime.
|
|
589
|
+
*
|
|
590
|
+
* History *does not contain the current state*. If you want that, call
|
|
591
|
+
* `.history_inclusive` instead.
|
|
592
|
+
*
|
|
593
|
+
* ```typescript
|
|
594
|
+
* const foo = jssm.from(
|
|
595
|
+
* "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
|
|
596
|
+
* { history: 3 }
|
|
597
|
+
* );
|
|
598
|
+
*
|
|
599
|
+
* foo.action('next');
|
|
600
|
+
* foo.action('next');
|
|
601
|
+
* foo.action('next');
|
|
602
|
+
* foo.action('next');
|
|
603
|
+
*
|
|
604
|
+
* foo.history; // [ ['b',undefined], ['c',undefined], ['d',undefined] ]
|
|
605
|
+
* ```
|
|
606
|
+
*
|
|
607
|
+
* Notice that the machine's current state, `e`, is not in the returned list.
|
|
608
|
+
*
|
|
609
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
610
|
+
*
|
|
611
|
+
*/
|
|
612
|
+
get history(): [string, mDT][];
|
|
613
|
+
/*********
|
|
614
|
+
*
|
|
615
|
+
* Get a truncated history of the recent states and data of the machine,
|
|
616
|
+
* including the current state. Turned off by default; configure with
|
|
617
|
+
* `.from('...', {data: 5})` by length, or set `.history_length` at runtime.
|
|
618
|
+
*
|
|
619
|
+
* History inclusive contains the current state. If you only want past
|
|
620
|
+
* states, call `.history` instead.
|
|
621
|
+
*
|
|
622
|
+
* The list returned will be one longer than the history buffer kept, as the
|
|
623
|
+
* history buffer kept gets the current state added to it to produce this
|
|
624
|
+
* list.
|
|
625
|
+
*
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const foo = jssm.from(
|
|
628
|
+
* "a 'next' -> b 'next' -> c 'next' -> d 'next' -> e;",
|
|
629
|
+
* { history: 3 }
|
|
630
|
+
* );
|
|
631
|
+
*
|
|
632
|
+
* foo.action('next');
|
|
633
|
+
* foo.action('next');
|
|
634
|
+
* foo.action('next');
|
|
635
|
+
* foo.action('next');
|
|
636
|
+
*
|
|
637
|
+
* foo.history_inclusive; // [ ['b',undefined], ['c',undefined], ['d',undefined], ['e',undefined] ]
|
|
638
|
+
* ```
|
|
639
|
+
*
|
|
640
|
+
* Notice that the machine's current state, `e`, is in the returned list.
|
|
641
|
+
*
|
|
642
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
643
|
+
*
|
|
644
|
+
*/
|
|
645
|
+
get history_inclusive(): [string, mDT][];
|
|
646
|
+
/*********
|
|
647
|
+
*
|
|
648
|
+
* Find out how long a history this machine is keeping. Defaults to zero.
|
|
649
|
+
* Settable directly.
|
|
650
|
+
*
|
|
651
|
+
* ```typescript
|
|
652
|
+
* const foo = jssm.from("a -> b;");
|
|
653
|
+
* foo.history_length; // 0
|
|
654
|
+
*
|
|
655
|
+
* const bar = jssm.from("a -> b;", { history: 3 });
|
|
656
|
+
* foo.history_length; // 3
|
|
657
|
+
* foo.history_length = 5;
|
|
658
|
+
* foo.history_length; // 5
|
|
659
|
+
* ```
|
|
660
|
+
*
|
|
661
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
662
|
+
*
|
|
663
|
+
*/
|
|
664
|
+
get history_length(): number;
|
|
665
|
+
set history_length(to: number);
|
|
554
666
|
/********
|
|
555
667
|
*
|
|
556
668
|
* Instruct the machine to complete an action.
|
package/jssm_types.d.ts
CHANGED
|
@@ -102,6 +102,7 @@ declare type JssmGenericConfig<DataType> = {
|
|
|
102
102
|
data?: DataType;
|
|
103
103
|
nodes?: Array<StateType>;
|
|
104
104
|
check?: JssmStatePermitterMaybeArray<DataType>;
|
|
105
|
+
history?: number;
|
|
105
106
|
min_exits?: number;
|
|
106
107
|
max_exits?: number;
|
|
107
108
|
allow_islands?: false;
|
|
@@ -197,7 +198,55 @@ declare type ExitHook<mDT> = {
|
|
|
197
198
|
from: string;
|
|
198
199
|
handler: HookHandler<mDT>;
|
|
199
200
|
};
|
|
200
|
-
declare type
|
|
201
|
+
declare type PostBasicHookDescription<mDT> = {
|
|
202
|
+
kind: 'post hook';
|
|
203
|
+
from: string;
|
|
204
|
+
to: string;
|
|
205
|
+
handler: PostHookHandler<mDT>;
|
|
206
|
+
};
|
|
207
|
+
declare type PostHookDescriptionWithAction<mDT> = {
|
|
208
|
+
kind: 'post named';
|
|
209
|
+
from: string;
|
|
210
|
+
to: string;
|
|
211
|
+
action: string;
|
|
212
|
+
handler: PostHookHandler<mDT>;
|
|
213
|
+
};
|
|
214
|
+
declare type PostStandardTransitionHook<mDT> = {
|
|
215
|
+
kind: 'post standard transition';
|
|
216
|
+
handler: PostHookHandler<mDT>;
|
|
217
|
+
};
|
|
218
|
+
declare type PostMainTransitionHook<mDT> = {
|
|
219
|
+
kind: 'post main transition';
|
|
220
|
+
handler: PostHookHandler<mDT>;
|
|
221
|
+
};
|
|
222
|
+
declare type PostForcedTransitionHook<mDT> = {
|
|
223
|
+
kind: 'post forced transition';
|
|
224
|
+
handler: PostHookHandler<mDT>;
|
|
225
|
+
};
|
|
226
|
+
declare type PostAnyTransitionHook<mDT> = {
|
|
227
|
+
kind: 'post any transition';
|
|
228
|
+
handler: PostHookHandler<mDT>;
|
|
229
|
+
};
|
|
230
|
+
declare type PostGlobalActionHook<mDT> = {
|
|
231
|
+
kind: 'post global action';
|
|
232
|
+
action: string;
|
|
233
|
+
handler: PostHookHandler<mDT>;
|
|
234
|
+
};
|
|
235
|
+
declare type PostAnyActionHook<mDT> = {
|
|
236
|
+
kind: 'post any action';
|
|
237
|
+
handler: PostHookHandler<mDT>;
|
|
238
|
+
};
|
|
239
|
+
declare type PostEntryHook<mDT> = {
|
|
240
|
+
kind: 'post entry';
|
|
241
|
+
to: string;
|
|
242
|
+
handler: PostHookHandler<mDT>;
|
|
243
|
+
};
|
|
244
|
+
declare type PostExitHook<mDT> = {
|
|
245
|
+
kind: 'post exit';
|
|
246
|
+
from: string;
|
|
247
|
+
handler: PostHookHandler<mDT>;
|
|
248
|
+
};
|
|
249
|
+
declare type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT>;
|
|
201
250
|
declare type HookComplexResult<mDT> = {
|
|
202
251
|
pass: boolean;
|
|
203
252
|
state?: StateType;
|
|
@@ -208,6 +257,7 @@ declare type HookContext<mDT> = {
|
|
|
208
257
|
data: mDT;
|
|
209
258
|
};
|
|
210
259
|
declare type HookHandler<mDT> = (hook_context: HookContext<mDT>) => HookResult<mDT>;
|
|
260
|
+
declare type PostHookHandler<mDT> = (hook_context: HookContext<mDT>) => void;
|
|
211
261
|
declare type JssmErrorExtendedInfo = {
|
|
212
262
|
requested_state?: StateType | undefined;
|
|
213
263
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jssm",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.74.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=10.0.0"
|
|
6
6
|
},
|
|
@@ -131,6 +131,7 @@
|
|
|
131
131
|
"typescript": "^4.6.4"
|
|
132
132
|
},
|
|
133
133
|
"dependencies": {
|
|
134
|
+
"circular_buffer_js": "^1.10.0",
|
|
134
135
|
"better_git_changelog": "^1.6.1",
|
|
135
136
|
"reduce-to-639-1": "^1.0.4"
|
|
136
137
|
}
|