jssm 5.162.4 → 5.162.6

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.
@@ -723,6 +723,10 @@ type AfterHook<mDT> = {
723
723
  from: string;
724
724
  handler: HookHandler<mDT>;
725
725
  };
726
+ type AfterAnyHook<mDT> = {
727
+ kind: 'after any';
728
+ handler: HookHandler<mDT>;
729
+ };
726
730
  type PostBasicHookDescription<mDT> = {
727
731
  kind: 'post hook';
728
732
  from: string;
@@ -796,12 +800,12 @@ type PostEverythingHook<mDT> = {
796
800
  *
797
801
  * Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
798
802
  * `'main transition'`, `'forced transition'`, `'any transition'`,
799
- * `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`)
800
- * may return a falsy value to veto a transition. Post-transition
803
+ * `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`,
804
+ * `'after any'`) may return a falsy value to veto a transition. Post-transition
801
805
  * variants (`'post *'`) cannot veto and are invoked only after a
802
806
  * successful transition.
803
807
  */
804
- type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
808
+ type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | AfterAnyHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
805
809
  /**
806
810
  * Whether an observational hook runs in the pre-transition phase (where it
807
811
  * may veto/mutate the transition) or the post-transition phase (a pure
@@ -1056,7 +1060,9 @@ type JssmErrorEventDetail = {
1056
1060
  /**
1057
1061
  * Detail payload fired with a `data-change` event. Fires whenever the
1058
1062
  * machine's data payload is replaced. `old_data` is the value before the
1059
- * change; `new_data` is the value after.
1063
+ * change; `new_data` is the value after. `cause` names the API family that
1064
+ * performed the replacement: a data-bearing `transition`, an `override`, or
1065
+ * a direct `set_data` call.
1060
1066
  */
1061
1067
  type JssmDataChangeEventDetail<mDT> = {
1062
1068
  from?: StateType$1;
@@ -1064,7 +1070,7 @@ type JssmDataChangeEventDetail<mDT> = {
1064
1070
  action?: StateType$1;
1065
1071
  old_data: mDT;
1066
1072
  new_data: mDT;
1067
- cause: 'transition' | 'override';
1073
+ cause: 'transition' | 'override' | 'set_data';
1068
1074
  };
1069
1075
  /**
1070
1076
  * Detail payload fired with an `override` event. Distinguishes a forced
@@ -1317,6 +1323,7 @@ declare class Machine<mDT> {
1317
1323
  _entry_hooks: Map<number, HookHandler<mDT>>;
1318
1324
  _exit_hooks: Map<number, HookHandler<mDT>>;
1319
1325
  _after_hooks: Map<string, HookHandler<mDT>>;
1326
+ _after_any_hook: HookHandler<mDT> | undefined;
1320
1327
  _global_action_hooks: Map<number, HookHandler<mDT>>;
1321
1328
  _any_action_hook: HookHandler<mDT> | undefined;
1322
1329
  _standard_transition_hook: HookHandler<mDT> | undefined;
@@ -1478,6 +1485,40 @@ declare class Machine<mDT> {
1478
1485
  *
1479
1486
  */
1480
1487
  data(): mDT;
1488
+ /*********
1489
+ *
1490
+ * Replace the machine's data in place, without a transition. This is the
1491
+ * practical way to assign any value — including `undefined`, `null`, or
1492
+ * `false` — outside a hook's complex return, closing the gap where an
1493
+ * `undefined` assignment had no direct API (StoneCypher/fsl#1264). Fires
1494
+ * a `data-change` event with cause `'set_data'` when the value actually
1495
+ * changes; unlike {@link override} it requires no `allows_override`
1496
+ * config, because it never moves the state.
1497
+ *
1498
+ * ```typescript
1499
+ * import * as jssm from 'jssm';
1500
+ *
1501
+ * const lswitch = jssm.from('on <=> off;', {data: 1});
1502
+ * console.log( lswitch.data() ); // 1
1503
+ *
1504
+ * lswitch.set_data(2);
1505
+ * console.log( lswitch.data() ); // 2
1506
+ *
1507
+ * lswitch.set_data(undefined);
1508
+ * console.log( lswitch.data() ); // undefined
1509
+ * ```
1510
+ *
1511
+ * @typeParam mDT The type of the machine data member; usually omitted
1512
+ *
1513
+ * @param newData The value to install as the machine's data.
1514
+ *
1515
+ * @returns The machine, for chaining.
1516
+ *
1517
+ * @see Machine.data
1518
+ * @see override
1519
+ *
1520
+ */
1521
+ set_data(newData: mDT): Machine<mDT>;
1481
1522
  /**
1482
1523
  * The machine's current data by REFERENCE — no clone. The public
1483
1524
  * {@link Machine.data} contract is a deep clone per call (a mutation
@@ -2793,6 +2834,33 @@ declare class Machine<mDT> {
2793
2834
  * @see set_state_timeout
2794
2835
  */
2795
2836
  hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
2837
+ /** Register a hook that fires when ANY state's `after` timer elapses — the
2838
+ * whole-machine companion to {@link hook_after}, mirroring how
2839
+ * {@link hook_any_transition} companions {@link hook}. When the elapsing
2840
+ * state also has a specific {@link hook_after}, the specific hook fires
2841
+ * first and this one fires second; a specific after hook firing always
2842
+ * implies the any-after hook fires too (StoneCypher/fsl#1299). Like
2843
+ * `hook_after` it is informational — its outcome cannot reject the timed
2844
+ * transition — and it does NOT fire on ordinary dispatch.
2845
+ * @param handler - Callback invoked whenever any `after` timer fires, just
2846
+ * before the timed transition is taken.
2847
+ * @returns `this` for chaining.
2848
+ *
2849
+ * @example
2850
+ * const m = sm`a after 1000 -> b; a -> c; c -> a;`;
2851
+ * let calls = 0;
2852
+ * m.hook_after_any(() => { calls += 1; });
2853
+ * m.go('c');
2854
+ * m.go('a');
2855
+ * // ordinary dispatch never fires it; only a timer elapsing does:
2856
+ * calls; // => 0
2857
+ * m.clear_state_timeout();
2858
+ *
2859
+ * @see hook_after
2860
+ * @see hook_any_transition
2861
+ * @see set_state_timeout
2862
+ */
2863
+ hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
2796
2864
  /** Post-transition hook on a specific edge. Fires after the transition
2797
2865
  * from `from` to `to` has completed. Cannot block the transition.
2798
2866
  * @param from - Source state name.
@@ -2937,7 +3005,13 @@ declare class Machine<mDT> {
2937
3005
  edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
2938
3006
  /*********
2939
3007
  *
2940
- * Replace the current state and data with no regard to the graph.
3008
+ * Replace the current state and, when a data argument is provided, the
3009
+ * data — with no regard to the graph.
3010
+ *
3011
+ * The data argument is arity-detected: omitting it preserves the current
3012
+ * data, while explicitly passing `undefined` really sets the data to
3013
+ * `undefined` (StoneCypher/fsl#1264). Before 5.163 an omitted data
3014
+ * argument silently cleared the data.
2941
3015
  *
2942
3016
  * ```typescript
2943
3017
  * import { sm } from 'jssm';
@@ -2953,6 +3027,16 @@ declare class Machine<mDT> {
2953
3027
  * console.log( machine.state() ); // 'a'
2954
3028
  * ```
2955
3029
  *
3030
+ * @param newState The state to teleport to; must exist in the graph.
3031
+ *
3032
+ * @param newData Replacement data. Omit to keep the current data; pass
3033
+ * `undefined` explicitly to clear it.
3034
+ *
3035
+ * @throws {JssmError} If the machine's config does not set
3036
+ * `allows_override: true`, or if `newState` does not exist.
3037
+ *
3038
+ * @see set_data
3039
+ *
2956
3040
  */
2957
3041
  override(newState: StateType, newData?: mDT | undefined): void;
2958
3042
  /*********
@@ -3067,13 +3151,20 @@ declare class Machine<mDT> {
3067
3151
  * `newStateOrAction` is an action name and the target state is looked up
3068
3152
  * via the current action edge.
3069
3153
  *
3154
+ * @param dataProvided `true` when the caller explicitly supplied a data
3155
+ * argument — even an explicitly-`undefined` one, which commits `undefined`
3156
+ * as the new data (StoneCypher/fsl#1264). When `false` the current data
3157
+ * is preserved. The public wrappers derive this from call arity; the
3158
+ * default reproduces the old `!== undefined` inference for any direct
3159
+ * callers.
3160
+ *
3070
3161
  * @returns `true` if the transition was valid and every hook passed;
3071
3162
  * `false` if the transition was invalid or any hook rejected.
3072
3163
  *
3073
3164
  * @internal
3074
3165
  *
3075
3166
  */
3076
- transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
3167
+ transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
3077
3168
  /** If the current state has an `after` timeout configured, schedule it.
3078
3169
  * Called internally after each transition.
3079
3170
  */
package/jssm_viz.es6.d.ts CHANGED
@@ -723,6 +723,10 @@ type AfterHook<mDT> = {
723
723
  from: string;
724
724
  handler: HookHandler<mDT>;
725
725
  };
726
+ type AfterAnyHook<mDT> = {
727
+ kind: 'after any';
728
+ handler: HookHandler<mDT>;
729
+ };
726
730
  type PostBasicHookDescription<mDT> = {
727
731
  kind: 'post hook';
728
732
  from: string;
@@ -796,12 +800,12 @@ type PostEverythingHook<mDT> = {
796
800
  *
797
801
  * Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
798
802
  * `'main transition'`, `'forced transition'`, `'any transition'`,
799
- * `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`)
800
- * may return a falsy value to veto a transition. Post-transition
803
+ * `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`,
804
+ * `'after any'`) may return a falsy value to veto a transition. Post-transition
801
805
  * variants (`'post *'`) cannot veto and are invoked only after a
802
806
  * successful transition.
803
807
  */
804
- type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
808
+ type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | AfterAnyHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
805
809
  /**
806
810
  * Whether an observational hook runs in the pre-transition phase (where it
807
811
  * may veto/mutate the transition) or the post-transition phase (a pure
@@ -1056,7 +1060,9 @@ type JssmErrorEventDetail = {
1056
1060
  /**
1057
1061
  * Detail payload fired with a `data-change` event. Fires whenever the
1058
1062
  * machine's data payload is replaced. `old_data` is the value before the
1059
- * change; `new_data` is the value after.
1063
+ * change; `new_data` is the value after. `cause` names the API family that
1064
+ * performed the replacement: a data-bearing `transition`, an `override`, or
1065
+ * a direct `set_data` call.
1060
1066
  */
1061
1067
  type JssmDataChangeEventDetail<mDT> = {
1062
1068
  from?: StateType$1;
@@ -1064,7 +1070,7 @@ type JssmDataChangeEventDetail<mDT> = {
1064
1070
  action?: StateType$1;
1065
1071
  old_data: mDT;
1066
1072
  new_data: mDT;
1067
- cause: 'transition' | 'override';
1073
+ cause: 'transition' | 'override' | 'set_data';
1068
1074
  };
1069
1075
  /**
1070
1076
  * Detail payload fired with an `override` event. Distinguishes a forced
@@ -1317,6 +1323,7 @@ declare class Machine<mDT> {
1317
1323
  _entry_hooks: Map<number, HookHandler<mDT>>;
1318
1324
  _exit_hooks: Map<number, HookHandler<mDT>>;
1319
1325
  _after_hooks: Map<string, HookHandler<mDT>>;
1326
+ _after_any_hook: HookHandler<mDT> | undefined;
1320
1327
  _global_action_hooks: Map<number, HookHandler<mDT>>;
1321
1328
  _any_action_hook: HookHandler<mDT> | undefined;
1322
1329
  _standard_transition_hook: HookHandler<mDT> | undefined;
@@ -1478,6 +1485,40 @@ declare class Machine<mDT> {
1478
1485
  *
1479
1486
  */
1480
1487
  data(): mDT;
1488
+ /*********
1489
+ *
1490
+ * Replace the machine's data in place, without a transition. This is the
1491
+ * practical way to assign any value — including `undefined`, `null`, or
1492
+ * `false` — outside a hook's complex return, closing the gap where an
1493
+ * `undefined` assignment had no direct API (StoneCypher/fsl#1264). Fires
1494
+ * a `data-change` event with cause `'set_data'` when the value actually
1495
+ * changes; unlike {@link override} it requires no `allows_override`
1496
+ * config, because it never moves the state.
1497
+ *
1498
+ * ```typescript
1499
+ * import * as jssm from 'jssm';
1500
+ *
1501
+ * const lswitch = jssm.from('on <=> off;', {data: 1});
1502
+ * console.log( lswitch.data() ); // 1
1503
+ *
1504
+ * lswitch.set_data(2);
1505
+ * console.log( lswitch.data() ); // 2
1506
+ *
1507
+ * lswitch.set_data(undefined);
1508
+ * console.log( lswitch.data() ); // undefined
1509
+ * ```
1510
+ *
1511
+ * @typeParam mDT The type of the machine data member; usually omitted
1512
+ *
1513
+ * @param newData The value to install as the machine's data.
1514
+ *
1515
+ * @returns The machine, for chaining.
1516
+ *
1517
+ * @see Machine.data
1518
+ * @see override
1519
+ *
1520
+ */
1521
+ set_data(newData: mDT): Machine<mDT>;
1481
1522
  /**
1482
1523
  * The machine's current data by REFERENCE — no clone. The public
1483
1524
  * {@link Machine.data} contract is a deep clone per call (a mutation
@@ -2793,6 +2834,33 @@ declare class Machine<mDT> {
2793
2834
  * @see set_state_timeout
2794
2835
  */
2795
2836
  hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
2837
+ /** Register a hook that fires when ANY state's `after` timer elapses — the
2838
+ * whole-machine companion to {@link hook_after}, mirroring how
2839
+ * {@link hook_any_transition} companions {@link hook}. When the elapsing
2840
+ * state also has a specific {@link hook_after}, the specific hook fires
2841
+ * first and this one fires second; a specific after hook firing always
2842
+ * implies the any-after hook fires too (StoneCypher/fsl#1299). Like
2843
+ * `hook_after` it is informational — its outcome cannot reject the timed
2844
+ * transition — and it does NOT fire on ordinary dispatch.
2845
+ * @param handler - Callback invoked whenever any `after` timer fires, just
2846
+ * before the timed transition is taken.
2847
+ * @returns `this` for chaining.
2848
+ *
2849
+ * @example
2850
+ * const m = sm`a after 1000 -> b; a -> c; c -> a;`;
2851
+ * let calls = 0;
2852
+ * m.hook_after_any(() => { calls += 1; });
2853
+ * m.go('c');
2854
+ * m.go('a');
2855
+ * // ordinary dispatch never fires it; only a timer elapsing does:
2856
+ * calls; // => 0
2857
+ * m.clear_state_timeout();
2858
+ *
2859
+ * @see hook_after
2860
+ * @see hook_any_transition
2861
+ * @see set_state_timeout
2862
+ */
2863
+ hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
2796
2864
  /** Post-transition hook on a specific edge. Fires after the transition
2797
2865
  * from `from` to `to` has completed. Cannot block the transition.
2798
2866
  * @param from - Source state name.
@@ -2937,7 +3005,13 @@ declare class Machine<mDT> {
2937
3005
  edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
2938
3006
  /*********
2939
3007
  *
2940
- * Replace the current state and data with no regard to the graph.
3008
+ * Replace the current state and, when a data argument is provided, the
3009
+ * data — with no regard to the graph.
3010
+ *
3011
+ * The data argument is arity-detected: omitting it preserves the current
3012
+ * data, while explicitly passing `undefined` really sets the data to
3013
+ * `undefined` (StoneCypher/fsl#1264). Before 5.163 an omitted data
3014
+ * argument silently cleared the data.
2941
3015
  *
2942
3016
  * ```typescript
2943
3017
  * import { sm } from 'jssm';
@@ -2953,6 +3027,16 @@ declare class Machine<mDT> {
2953
3027
  * console.log( machine.state() ); // 'a'
2954
3028
  * ```
2955
3029
  *
3030
+ * @param newState The state to teleport to; must exist in the graph.
3031
+ *
3032
+ * @param newData Replacement data. Omit to keep the current data; pass
3033
+ * `undefined` explicitly to clear it.
3034
+ *
3035
+ * @throws {JssmError} If the machine's config does not set
3036
+ * `allows_override: true`, or if `newState` does not exist.
3037
+ *
3038
+ * @see set_data
3039
+ *
2956
3040
  */
2957
3041
  override(newState: StateType, newData?: mDT | undefined): void;
2958
3042
  /*********
@@ -3067,13 +3151,20 @@ declare class Machine<mDT> {
3067
3151
  * `newStateOrAction` is an action name and the target state is looked up
3068
3152
  * via the current action edge.
3069
3153
  *
3154
+ * @param dataProvided `true` when the caller explicitly supplied a data
3155
+ * argument — even an explicitly-`undefined` one, which commits `undefined`
3156
+ * as the new data (StoneCypher/fsl#1264). When `false` the current data
3157
+ * is preserved. The public wrappers derive this from call arity; the
3158
+ * default reproduces the old `!== undefined` inference for any direct
3159
+ * callers.
3160
+ *
3070
3161
  * @returns `true` if the transition was valid and every hook passed;
3071
3162
  * `false` if the transition was invalid or any hook rejected.
3072
3163
  *
3073
3164
  * @internal
3074
3165
  *
3075
3166
  */
3076
- transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
3167
+ transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
3077
3168
  /** If the current state has an `after` timeout configured, schedule it.
3078
3169
  * Called internally after each transition.
3079
3170
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jssm",
3
- "version": "5.162.4",
3
+ "version": "5.162.6",
4
4
  "engines": {
5
5
  "node": ">=10.0.0"
6
6
  },