@typeonce/effect-machine 0.32.0 → 0.33.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/README.md CHANGED
@@ -411,8 +411,9 @@ selecting a destination. Concrete destinations stay narrowed inside their
411
411
  resolver, and `to.branches({...})` gives the resolver only the declared named
412
412
  `select` builders. Builders describe the
413
413
  next logical configuration. Shared states exit and enter only when paths
414
- change; call `.reenter()` for resolver-free reentry or pass `{ reenter: true }`
415
- to `.resolve(...)` when the source must restart. With `to.none`, reentry
414
+ change; call `.reenter()` before `.from(...)`, `.decoded(...)`, or `.resolve(...)`
415
+ when the source must restart. Default-constructible targets can finish at
416
+ `.reenter()`. With `to.none`, reentry
416
417
  restarts the source while retaining its configuration.
417
418
 
418
419
  Topology-only definition instructions are values: `to.none`, declared
@@ -430,7 +431,7 @@ handler source:
430
431
 
431
432
  ```ts
432
433
  const handlers = {
433
- Increment: (to) => to.branch.root.session.update(({ current, owner }) => owner.from({ count: current.count + 1 }))
434
+ Increment: (to) => to.branch.root.session.update.from(({ current }) => ({ count: current.count + 1 }))
434
435
  }
435
436
  ```
436
437
 
@@ -463,30 +464,28 @@ const handlers = {
463
464
  CreatePlan: (to) =>
464
465
  to.local.SavingPlan()
465
466
  .updating(to.branch.Ready)
466
- .resolve(({ current, event, owner, target }) =>
467
- target.from({
468
- request: { _tag: "Create", input: event.input }
469
- }).update(
470
- owner.decoded(new Ready({ ...current, notice: null }))
471
- )
472
- )
467
+ .from(({ current, event }) => ({
468
+ target: { request: { _tag: "Create", input: event.input } },
469
+ update: { ...current, notice: null }
470
+ }))
473
471
  }
474
472
  ```
475
473
 
476
474
  `to.local.SavingPlan()` selects topology. `.updating(to.branch.Ready)` names
477
- the retained valued owner and makes its replacement mandatory: the resolver
478
- does not type-check unless destination construction finishes with
479
- `.update(...)`. `current` is that owner's decoded value from the
480
- pre-transition snapshot. `target` constructs the destination; `owner`
481
- constructs the complete replacement owner value.
475
+ the retained valued owner and makes its replacement mandatory. `.from(...)`
476
+ returns `{ target, update }` with constructor inputs for both values;
477
+ `.decoded(...)` returns already decoded values for both. `current` is that
478
+ owner's decoded value from the pre-transition snapshot. Use `.resolve(...)`
479
+ when constructing explicit children, mixing construction methods, or queuing
480
+ commands; its `target` and `owner` builders construct the two values.
482
481
 
483
482
  The topology change and owner replacement apply atomically in one microstep.
484
483
  The owner does not exit or reenter, its work is not restarted, and destination
485
484
  entry actions observe the new owner value. Eventless stabilization follows.
486
485
  Only one retained owner may be replaced by a combined target. A `full` target,
487
486
  or any target that exits the selected owner, does not expose `.updating`.
488
- Combined updates use a direct resolver in this release; named branches continue
489
- to support value-only updates.
487
+ Named branches support value-only updates; a combined update declares its
488
+ destination directly.
490
489
 
491
490
  For a schema-less destination, construction remains explicit:
492
491
 
@@ -511,11 +510,13 @@ before lifecycle actions run. Competing transitions that write the same owner
511
510
  conflict; document order and hierarchy select one writer rather than applying
512
511
  last-write-wins behavior.
513
512
 
514
- The resolver must return `target.decoded(value)` or `target.from(input)`. It
515
- may return `decline()` only with `{ declinable: true }`. Pass `{ reenter: true }`
516
- on event or invocation transitions when the handler source should exit and
517
- enter again. Reentry applies to that source, not to the ancestor whose value
518
- changed.
513
+ Use `.guard(predicate)` before construction to decline an update without
514
+ constructing values or queuing commands. It is available on standalone and
515
+ combined updates. A false guard allows ancestor fallback. A resolver may also
516
+ return `decline()` with `{ declinable: true }` for decisions during resolution.
517
+ Call `.reenter()` before construction on event or invocation transitions when
518
+ the handler source should exit and enter again. Reentry applies to that source,
519
+ not to the retained ancestor whose value changed.
519
520
 
520
521
  The selector omits `update` for schema-less scopes, atomic and final states,
521
522
  inactive branches, parallel sibling regions, and choice resolvers. Updating a
package/dist/Machine.d.ts CHANGED
@@ -3052,7 +3052,7 @@ export declare namespace Machine {
3052
3052
  * do not directly control state re-entry. Exit and entry paths are derived
3053
3053
  * from the previous and next active paths. Shared active ancestors remain
3054
3054
  * entered even when a `full` target supplies their values again. Use an event
3055
- * transition with `reenter: true` when the source should explicitly exit and
3055
+ * transition with `.reenter()` when the source should explicitly exit and
3056
3056
  * enter again.
3057
3057
  *
3058
3058
  * @category models
@@ -3831,49 +3831,41 @@ export declare namespace Machine {
3831
3831
  readonly acceptance: Types.Covariant<Acceptance>;
3832
3832
  };
3833
3833
  }
3834
- type TransitionReenterOption<Reenter extends boolean> = [Reenter] extends [true] ? {
3835
- /** Forces the source state to exit and enter even when active paths remain unchanged. */
3836
- readonly reenter?: boolean;
3837
- } : {
3838
- readonly reenter?: never;
3839
- };
3840
- type TransitionRequiredOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
3834
+ type TransitionRequiredOptions = {
3841
3835
  /** Keeps the transition required. The resolver cannot return `decline()`. */
3842
3836
  readonly declinable?: false;
3837
+ readonly reenter?: never;
3843
3838
  };
3844
- type TransitionDeclinableOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
3839
+ type TransitionDeclinableOptions = {
3845
3840
  /** Adds `decline()` to the resolver context and permits declining this candidate. */
3846
3841
  readonly declinable: true;
3842
+ readonly reenter?: never;
3847
3843
  };
3848
3844
  type BuiltTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Result, Acceptance extends TransitionAcceptance> = TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<Result, Acceptance>;
3849
3845
  interface TransitionResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
3850
- (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
3846
+ (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
3851
3847
  }
3852
3848
  interface TransitionResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
3853
- (resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
3849
+ (resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
3854
3850
  }
3855
3851
  type ConstructionCallbacks<Context, Builder, Result> = {
3856
3852
  readonly [Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? (value: (context: Context) => Args[0]) => Result : never;
3857
3853
  };
3858
3854
  type GuardedTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> = ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable"> : {}) & {
3859
- readonly resolve: (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3855
+ readonly resolve: (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3860
3856
  };
3861
3857
  /**
3862
3858
  * A selected transition target with target-specific resolver operations.
3863
3859
  *
3864
- * **Example** (Updating state while reentering)
3860
+ * **Example** (Constructing state while reentering)
3865
3861
  *
3866
3862
  * ```ts
3867
3863
  * Reset: (to) =>
3868
- * to.branch.Ready().resolve(
3869
- * ({ target }) => target.from(),
3870
- * { reenter: true }
3871
- * )
3864
+ * to.branch.Ready().reenter().from(({ event }) => ({ count: event.count }))
3872
3865
  * ```
3873
3866
  *
3874
3867
  * @inlineType TransitionRequiredOptions
3875
3868
  * @inlineType TransitionDeclinableOptions
3876
- * @inlineType TransitionReenterOption
3877
3869
  */
3878
3870
  type TransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, any>> = Selection & ("declinable" extends Acceptance ? {
3879
3871
  /** Declines this candidate before construction when the predicate is false. */
@@ -3881,31 +3873,73 @@ export declare namespace Machine {
3881
3873
  } : {}) & ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required"> : {}) & {
3882
3874
  /** Evaluates state construction after this transition is selected. */
3883
3875
  readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
3884
- } & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
3885
- /** Reenters the source using the selected target's default construction. */
3886
- readonly reenter: () => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
3887
- } : {} : {}) & (SelectionKind<Selection> extends "state" ? SelectionScope<Selection> extends "local" | "branch" ? RetainedUpdateOwner<States, StateId, Selection> extends infer Owner extends ValuedStateIdentifier<States> ? [
3876
+ } & ([Reenter] extends [true] ? {
3877
+ /** Forces source exit and entry, preserving subsequent construction and guards. */
3878
+ readonly reenter: () => Omit<TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>, typeof Topology.TargetSelectionTypeId>;
3879
+ } : {}) & (SelectionKind<Selection> extends "state" ? SelectionScope<Selection> extends "local" | "branch" ? RetainedUpdateOwner<States, StateId, Selection> extends infer Owner extends ValuedStateIdentifier<States> ? [
3888
3880
  Owner
3889
3881
  ] extends [never] ? {} : {
3890
3882
  /** Declares one valued owner retained by the selected topology. */
3891
3883
  readonly updating: <SelectedOwner extends Owner>(owner: RetainedOwnerSelector<SelectedOwner>) => UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, SelectedOwner>;
3892
3884
  } : {} : {} : {});
3893
- /** A topology selection that requires one retained owner replacement. */
3894
- type UpdatingTransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = Selection & {
3885
+ type UpdatingConstructionCallbacks<Context, Builder, OwnerBuilder, Result> = {
3886
+ readonly [Method in Extract<keyof Builder & keyof OwnerBuilder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? OwnerBuilder[Method] extends (value: infer Update) => unknown ? (construct: (context: Context) => {
3887
+ readonly target: Args[0];
3888
+ readonly update: Update;
3889
+ }) => Result : never : never;
3890
+ };
3891
+ type UpdatingCallbacks<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>, Acceptance extends TransitionAcceptance> = UpdatingConstructionCallbacks<Omit<UpdatingTransitionResolveContext<States, Context, Selection, Owner>, "owner" | "target">, SelectionBuilder<Selection>, StateUpdateBuilder<States, Owner>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | (Acceptance extends "declinable" ? Declined : never), Acceptance>>;
3892
+ type GuardedUpdatingTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = UpdatingCallbacks<States, Events, Emits, StateId, Context, Reenter, Selection, Owner, "declinable"> & {
3893
+ readonly resolve: (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable">;
3894
+ };
3895
+ /**
3896
+ * A topology selection that requires one retained owner replacement.
3897
+ *
3898
+ * `.from` constructs both values from schema inputs; `.decoded` accepts both
3899
+ * decoded values. Both callbacks return `{ target, update }` and read the same
3900
+ * pre-transition snapshot. Use `.resolve` for explicit child construction,
3901
+ * mixed construction methods, or queued commands.
3902
+ *
3903
+ * **Example** (Guarding an atomic destination and owner update)
3904
+ *
3905
+ * ```ts
3906
+ * Save: (to) => to.local.Saving().updating(to.root)
3907
+ * .guard(({ current }) => current.draft.length > 0)
3908
+ * .from(({ current }) => ({
3909
+ * target: { text: current.draft },
3910
+ * update: { ...current, attempts: current.attempts + 1 }
3911
+ * }))
3912
+ * ```
3913
+ */
3914
+ type UpdatingTransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = Selection & UpdatingCallbacks<States, Events, Emits, StateId, Context, Reenter, Selection, Owner, "required"> & ([Reenter] extends [true] ? {
3915
+ readonly reenter: () => Omit<UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, Owner>, typeof Topology.TargetSelectionTypeId>;
3916
+ } : {}) & ("declinable" extends Acceptance ? {
3917
+ /** Declines before either value is constructed or any commands are enqueued. */
3918
+ readonly guard: (predicate: (context: Omit<UpdatingTransitionResolveContext<States, Context, Selection, Owner>, "owner" | "target">) => boolean) => GuardedUpdatingTransition<States, Events, Emits, StateId, Context, Reenter, Selection, Owner>;
3919
+ } : {}) & {
3895
3920
  /** @internal */
3896
3921
  readonly "~effect/Machine/UpdatingTransitionTarget": Owner;
3897
- readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, "required">) & ("declinable" extends Acceptance ? (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, options: TransitionDeclinableOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable"> : {});
3922
+ readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, "required">) & ("declinable" extends Acceptance ? (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, options: TransitionDeclinableOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable"> : {});
3898
3923
  };
3899
3924
  /** @internal */
3900
3925
  interface StateUpdateTransitionRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
3901
- (resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">;
3926
+ (resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">;
3902
3927
  }
3903
3928
  /** @internal */
3904
3929
  interface StateUpdateTransitionDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
3905
- (resolve: DeclinableStateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3930
+ (resolve: DeclinableStateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3906
3931
  }
3932
+ type GuardedStateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> = ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & {
3933
+ readonly resolve: (resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3934
+ };
3907
3935
  /** @internal */
3908
- type StateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "update">> = Selection & ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & {
3936
+ type StateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "update">> = Selection & ([Reenter] extends [true] ? {
3937
+ /** Reenters the source while updating its retained valued ancestor. */
3938
+ readonly reenter: () => Omit<StateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>, typeof Topology.TargetSelectionTypeId>;
3939
+ } : {}) & ("declinable" extends Acceptance ? {
3940
+ /** Declines before replacing the selected owner value. */
3941
+ readonly guard: (predicate: (context: Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">) => boolean) => GuardedStateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
3942
+ } : {}) & ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & {
3909
3943
  readonly resolve: StateUpdateTransitionRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? StateUpdateTransitionDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
3910
3944
  };
3911
3945
  /** @internal Type evidence retained by a machine initial-entry declaration. */
@@ -3961,21 +3995,24 @@ export declare namespace Machine {
3961
3995
  readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
3962
3996
  };
3963
3997
  interface TransitionBranchesResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
3964
- (resolve: TransitionBranchesResolver<Events, Emits, Context, Branches>, options?: TransitionRequiredOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches>, "required">;
3998
+ (resolve: TransitionBranchesResolver<Events, Emits, Context, Branches>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches>, "required">;
3965
3999
  }
3966
4000
  interface TransitionBranchesResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
3967
- (resolve: DeclinableTransitionBranchesResolver<Events, Emits, Context, Branches>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches> | Declined, "declinable">;
4001
+ (resolve: DeclinableTransitionBranchesResolver<Events, Emits, Context, Branches>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches> | Declined, "declinable">;
3968
4002
  }
3969
4003
  type TransitionSelectorTargets<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> = {
3970
4004
  readonly [Key in keyof TargetSelector<States, StateId>]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Key extends "self" ? false : Reenter, Acceptance, TargetSelector<States, StateId>[Key]>;
3971
4005
  };
4006
+ type TransitionBranchesTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
4007
+ /** Resolves exactly one declared branch after this transition is selected. */
4008
+ readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
4009
+ } & ([Reenter] extends [true] ? {
4010
+ readonly reenter: () => TransitionBranchesTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Branches>;
4011
+ } : {});
3972
4012
  /** Selector supplied to inline transition declarations. */
3973
4013
  interface TransitionSelector<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> extends TransitionSelectorTargets<States, Events, Emits, StateId, Context, Reenter, Acceptance> {
3974
4014
  /** Declares a closed set of named destinations for one resolver. */
3975
- readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => {
3976
- /** Resolves exactly one declared branch after this transition is selected. */
3977
- readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
3978
- };
4015
+ readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => TransitionBranchesTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Branches>;
3979
4016
  }
3980
4017
  /** Inline transition declaration accepted by state and invocation handlers. */
3981
4018
  type TransitionBuilderInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance> = (to: TransitionSelector<States, Events, Emits, StateId, Context, Reenter, Acceptance>) => TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<any, Acceptance>;