@typeonce/effect-machine 0.14.0 → 0.15.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/dist/Machine.d.ts CHANGED
@@ -77,7 +77,7 @@ export declare const InitialEvent: InitialEvent;
77
77
  export declare const isInitialEvent: (u: unknown) => u is InitialEvent;
78
78
  type IsAny<A> = 0 extends (1 & A) ? true : false;
79
79
  /**
80
- * A schema-first machine definition.
80
+ * A schema-first machine implementation.
81
81
  *
82
82
  * **Details**
83
83
  *
@@ -157,20 +157,9 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
157
157
  /** @internal */
158
158
  readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>;
159
159
  /**
160
- * Adds typed state handlers and returns the refined machine definition.
161
- * Successive calls implement the remaining unhandled states while retaining
162
- * accumulated errors, services, final states, and output evidence.
163
- * Event dispatch maps and transition descriptors are captured by value, so
164
- * later mutation of the objects supplied to this call cannot alter the
165
- * resulting machine.
166
- *
167
- * @since 0.4.0
168
- */
169
- readonly handle: Machine.Handler<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents>;
170
- /**
171
- * Preserves invocation inference with this machine's public input and parent
172
- * protocols. Prefer this bound constructor when an invocation source or
173
- * lifecycle handler uses `self` or `parent`.
160
+ * Machine-bound equivalent of {@link invoke}. Both forms preserve this
161
+ * machine's public input and parent protocols in invocation callbacks;
162
+ * `Machine.invoke(...)` inside `handle(...)` is the canonical inline form.
174
163
  *
175
164
  * @since 0.11.0
176
165
  */
@@ -180,6 +169,48 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
180
169
  /** @internal */
181
170
  readonly initialDefinition: Machine.InitialDefinition;
182
171
  }
172
+ /**
173
+ * A schema-first machine definition that can produce independent
174
+ * implementations.
175
+ *
176
+ * **Details**
177
+ *
178
+ * Call `handle` once for each implementation. The returned {@link Machine}
179
+ * does not expose `handle`, so handler configuration cannot be accumulated or
180
+ * replaced through chained calls. Calling `handle` multiple times on the same
181
+ * definition remains supported and creates independent machines.
182
+ *
183
+ * @category models
184
+ * @since 0.15.0
185
+ */
186
+ export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
187
+ /**
188
+ * Adds typed state handlers and returns an independent machine
189
+ * implementation. Event dispatch maps and transition descriptors are
190
+ * captured by value, so later mutation of the supplied objects cannot alter
191
+ * the resulting machine.
192
+ *
193
+ * @since 0.4.0
194
+ */
195
+ readonly handle: Machine.Handler<States, Events, Emits, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, never, InputEvents, ParentEvents>;
196
+ }
197
+ /**
198
+ * Namespace containing type-level members associated with {@link Definition}.
199
+ *
200
+ * @category models
201
+ * @since 0.15.0
202
+ */
203
+ export declare namespace Definition {
204
+ /**
205
+ * Any schema-first machine definition.
206
+ *
207
+ * @category models
208
+ * @since 0.15.0
209
+ */
210
+ interface Any extends Machine.Any {
211
+ readonly handle: any;
212
+ }
213
+ }
183
214
  export {
184
215
  /**
185
216
  * Error returned by `spawn` when a child process with the same id already
@@ -467,7 +498,7 @@ type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children ex
467
498
  readonly initial: infer Initial;
468
499
  } ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
469
500
  readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
470
- } : StateDefinitionError<"Compound initial must be one of its direct child keys"> : StateDefinitionError<"Compound states must declare an initial child">;
501
+ } : StateDefinitionError<"Compound initial must be one of its direct child keys", Path, Extract<Initial, PropertyKey>> : StateDefinitionError<"Compound states must declare an initial child", Path>;
471
502
  type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
472
503
  readonly type: infer Type;
473
504
  } ? Type extends "final" ? ValidateOutputSchema<Node> : Type extends "active" | undefined ? "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown : StateDefinitionError<"State node type must be active, final, or parallel"> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown;
@@ -491,7 +522,15 @@ type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] exten
491
522
  type InvalidDefinedStateTreeInput<States extends Machine.StateSchemas> = [States] extends [
492
523
  Machine.ValidateStateSchemas<States>
493
524
  ] ? never : States & Machine.ValidateStateSchemas<States>;
494
- interface DefineStates {
525
+ type ReusableStateNodeConfig = Machine.AtomicStateNodeConfig | Machine.CompoundStateNodeConfig | Machine.ParallelStateNodeConfig;
526
+ type ReusableStateValidation<Node> = Node extends ReusableStateNodeConfig ? ValidateStateNode<Node, false, "state"> : StateDefinitionError<"Reusable states must be active state nodes", "state">;
527
+ type ValidateDefinedState<Node> = [Node] extends [ReusableStateValidation<Node>] ? [] : [validation: ReusableStateValidation<Node>];
528
+ type InvalidDefinedStateInput<Node> = [Node] extends [ReusableStateValidation<Node>] ? never : Node & ReusableStateValidation<Node>;
529
+ interface StateConstructor {
530
+ <const Node>(node: Node & DefineStateNodeInput<NoInfer<Node>>, ..._validation: ValidateDefinedState<NoInfer<Node>>): Node;
531
+ <const Node>(node: InvalidDefinedStateInput<Node>): never;
532
+ }
533
+ interface StatesConstructor {
495
534
  <const States extends Machine.StateSchemas>(states: States & DefineStateTreeInput<NoInfer<States>>, ..._validation: ValidateDefinedStates<NoInfer<States>>): Machine.DefinedStates<States>;
496
535
  <const States extends Machine.StateSchemas>(states: InvalidDefinedStateTreeInput<States>): never;
497
536
  }
@@ -1399,8 +1438,6 @@ export declare namespace Machine {
1399
1438
  /** @internal */
1400
1439
  readonly handlers: any;
1401
1440
  /** @internal */
1402
- readonly handle: any;
1403
- /** @internal */
1404
1441
  readonly invoke: any;
1405
1442
  /** @internal */
1406
1443
  readonly initial: any;
@@ -1773,12 +1810,12 @@ export declare namespace Machine {
1773
1810
  */
1774
1811
  type StateSchemas = StateTree;
1775
1812
  /**
1776
- * Builder for initial state snapshots generated by `defineStates`.
1813
+ * Builder for initial state snapshots generated by `states`.
1777
1814
  *
1778
1815
  * **When to use**
1779
1816
  *
1780
1817
  * Use when you need the type of the `initial` property returned by
1781
- * `defineStates` or want to expose an initial snapshot builder from a helper.
1818
+ * `states` or want to expose an initial snapshot builder from a helper.
1782
1819
  *
1783
1820
  * **Details**
1784
1821
  *
@@ -1790,7 +1827,7 @@ export declare namespace Machine {
1790
1827
  */
1791
1828
  type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
1792
1829
  /**
1793
- * State definitions and snapshot access helpers returned by `defineStates`.
1830
+ * State definitions and snapshot access helpers returned by `states`.
1794
1831
  *
1795
1832
  * **Details**
1796
1833
  *
@@ -1802,8 +1839,17 @@ export declare namespace Machine {
1802
1839
  * @since 0.4.0
1803
1840
  */
1804
1841
  interface DefinedStates<States extends StateSchemas> {
1805
- /** Original state tree supplied to {@link defineStates}. */
1842
+ /** Captured state tree supplied to {@link states}. */
1806
1843
  readonly states: States;
1844
+ /**
1845
+ * Checks and preserves one active state path from this definition.
1846
+ *
1847
+ * This is useful for named path helpers, including finite template-literal
1848
+ * families. Every member of a path union must exist in the state tree.
1849
+ *
1850
+ * @since 0.15.0
1851
+ */
1852
+ readonly path: <const Path extends StateIdentifier<States>>(path: Path) => Path;
1807
1853
  /**
1808
1854
  * Returns the decoded value for an active state path. The supplied
1809
1855
  * snapshot may be a complete root snapshot or a snapshot previously
@@ -3818,6 +3864,13 @@ export declare namespace Machine {
3818
3864
  */
3819
3865
  type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R> | ChoiceStateConfig<States, Events, Emits, ChoiceIdentifier<States>>>>;
3820
3866
  }
3867
+ /**
3868
+ * Extracts the complete logical snapshot represented by a state definition.
3869
+ *
3870
+ * @category utility types
3871
+ * @since 0.15.0
3872
+ */
3873
+ export type Snapshot<Defined extends Machine.DefinedStates<any>> = Defined extends Machine.DefinedStates<infer States> ? Machine.Snapshot<States> : never;
3821
3874
  /**
3822
3875
  * Returns `true` if a value is a `Machine`.
3823
3876
  *
@@ -3833,7 +3886,43 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
3833
3886
  */
3834
3887
  export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
3835
3888
  /**
3836
- * Defines a state tree while preserving literal state paths.
3889
+ * Defines one reusable active state while preserving its exact child topology.
3890
+ *
3891
+ * Prefer declaring state nodes inline in {@link states}. Use this constructor
3892
+ * only when the same state definition is mounted more than once.
3893
+ * Tagged schemas are already reusable and do not need this constructor.
3894
+ *
3895
+ * **Example** (Repeated compound state)
3896
+ *
3897
+ * ```ts
3898
+ * import { Schema } from "effect"
3899
+ * import { Machine } from "@typeonce/effect-machine"
3900
+ *
3901
+ * const TradingState = Schema.TaggedUnion({
3902
+ * InSession: {},
3903
+ * Applying: {}
3904
+ * })
3905
+ * const TradingSlot = Machine.state({
3906
+ * initial: "Idle",
3907
+ * states: {
3908
+ * Idle: {},
3909
+ * InSession: TradingState.cases.InSession,
3910
+ * Applying: TradingState.cases.Applying
3911
+ * }
3912
+ * })
3913
+ *
3914
+ * const States = Machine.states({
3915
+ * slot1: TradingSlot,
3916
+ * slot2: TradingSlot
3917
+ * })
3918
+ * ```
3919
+ *
3920
+ * @category constructors
3921
+ * @since 0.15.0
3922
+ */
3923
+ export declare const state: StateConstructor;
3924
+ /**
3925
+ * Defines the complete state tree while preserving literal state paths.
3837
3926
  *
3838
3927
  * **When to use**
3839
3928
  *
@@ -3842,7 +3931,8 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
3842
3931
  *
3843
3932
  * **Details**
3844
3933
  *
3845
- * The returned `states` property is the same object passed to `defineStates`.
3934
+ * The returned `states` property is an immutable structural capture of the
3935
+ * supplied tree.
3846
3936
  * `Machine.make` derives its initial target selector from that tree and
3847
3937
  * enforces compound and parallel initial-state rules. Active nodes may omit
3848
3938
  * `schema` when they own no value and still participate fully in targeting,
@@ -3856,7 +3946,7 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
3856
3946
  *
3857
3947
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
3858
3948
  *
3859
- * const States = Machine.defineStates({ idle: Idle })
3949
+ * const States = Machine.states({ idle: Idle })
3860
3950
  *
3861
3951
  * Machine.make({
3862
3952
  * states: States.states,
@@ -3871,7 +3961,7 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
3871
3961
  * @category constructors
3872
3962
  * @since 0.4.0
3873
3963
  */
3874
- export declare const defineStates: DefineStates;
3964
+ export declare const states: StatesConstructor;
3875
3965
  type InitialDirectInput<States extends Machine.StateSchemas, Input, Selection extends Machine.TargetSelection<any, any, any>> = {
3876
3966
  readonly target: (to: Machine.InitialSelector<States>) => Selection;
3877
3967
  readonly resolve?: (context: {
@@ -3891,7 +3981,7 @@ type MakeConfig<States extends Machine.StateSchemas, InputEvents extends Readonl
3891
3981
  readonly input?: Input;
3892
3982
  readonly initial: unknown;
3893
3983
  };
3894
- type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = Machine<States, readonly [...InputEvents, ...InternalEvents], Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, never, InputEvents, ParentEvents>;
3984
+ type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = Definition<States, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, InputEvents, ParentEvents>;
3895
3985
  interface Make {
3896
3986
  <const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const InitialSelection extends Machine.TargetSelection<any, any, any> = Machine.TargetSelection<any, any, any>>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "initial"> & {
3897
3987
  readonly initial: InitialDirectInput<States, Input["Type"], InitialSelection>;
@@ -3908,7 +3998,7 @@ interface Make {
3908
3998
  * State and event schemas provide runtime boundary validation while their
3909
3999
  * decoded types drive handler, state, event, target, error, and service
3910
4000
  * inference. State-tree validation is applied whether `states` comes from
3911
- * `defineStates` or is passed inline. Call `handle` on the returned definition
4001
+ * `states` or is passed inline. Call `handle` on the returned definition
3912
4002
  * to implement state behavior with ordinary TypeScript control flow.
3913
4003
  *
3914
4004
  * `Machine.events` defines the public input protocol. `Machine.internalEvents`
@@ -3933,7 +4023,7 @@ interface Make {
3933
4023
  * by: Schema.Number
3934
4024
  * }) {}
3935
4025
  *
3936
- * const States = Machine.defineStates({ Count })
4026
+ * const States = Machine.states({ Count })
3937
4027
  * const Events = Machine.events(Increment)
3938
4028
  *
3939
4029
  * const counter = Machine.make({
@@ -3956,7 +4046,7 @@ interface Make {
3956
4046
  * })
3957
4047
  * ```
3958
4048
  *
3959
- * @see {@link defineStates} for typed state-tree helpers.
4049
+ * @see {@link states} for typed state-tree helpers.
3960
4050
  * @category constructors
3961
4051
  * @since 0.4.0
3962
4052
  */
@@ -3980,9 +4070,14 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
3980
4070
  * **Example**
3981
4071
  *
3982
4072
  * ```ts
3983
- * const Events = Machine.events(Increment, Reset)
3984
- * const machine = Machine.make({ events: Events, ... })
3985
- * yield* ref.send(Events.Increment({ by: 1 }))
4073
+ * export const Event = Machine.events(
4074
+ * Schema.TaggedUnion({
4075
+ * Increment: { by: Schema.Number },
4076
+ * Reset: {}
4077
+ * })
4078
+ * )
4079
+ * const machine = Machine.make({ events: Event, ... })
4080
+ * yield* ref.send(Event.Increment({ by: 1 }))
3986
4081
  * ```
3987
4082
  *
3988
4083
  * @category constructors
@@ -4003,11 +4098,16 @@ export declare const events: {
4003
4098
  * **Example**
4004
4099
  *
4005
4100
  * ```ts
4006
- * const InternalEvents = Machine.internalEvents(Loaded, Failed)
4007
- * const machine = Machine.make({ internalEvents: InternalEvents, ... })
4101
+ * const Internal = Machine.internalEvents(
4102
+ * Schema.TaggedUnion({
4103
+ * Loaded: { value: Schema.String },
4104
+ * Failed: { message: Schema.String }
4105
+ * })
4106
+ * )
4107
+ * const machine = Machine.make({ internalEvents: Internal, ... })
4008
4108
  *
4009
4109
  * // Inside a transition callback:
4010
- * enqueue.raise(InternalEvents.Loaded({ value }))
4110
+ * enqueue.raise(Internal.Loaded({ value }))
4011
4111
  * ```
4012
4112
  *
4013
4113
  * @category constructors
@@ -4023,6 +4123,17 @@ export declare const internalEvents: {
4023
4123
  * implicitly to a parent machine. Observe them through `MachineRef.emissions` or
4024
4124
  * the AtomMachine emission stream adapters.
4025
4125
  *
4126
+ * **Example**
4127
+ *
4128
+ * ```ts
4129
+ * const Emitted = Machine.emittedEvents(
4130
+ * Schema.TaggedUnion({
4131
+ * Saved: { id: Schema.String }
4132
+ * })
4133
+ * )
4134
+ * const machine = Machine.make({ emittedEvents: Emitted, ... })
4135
+ * ```
4136
+ *
4026
4137
  * @category constructors
4027
4138
  * @since 0.10.0
4028
4139
  */
@@ -4060,7 +4171,7 @@ export declare const emittedEvents: {
4060
4171
  * import { Machine } from "@typeonce/effect-machine"
4061
4172
  *
4062
4173
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
4063
- * const States = Machine.defineStates({ Idle })
4174
+ * const States = Machine.states({ Idle })
4064
4175
  * const machine = Machine.make({
4065
4176
  * states: States.states,
4066
4177
  * events: Machine.events(),
@@ -4107,7 +4218,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
4107
4218
  * import { Machine } from "@typeonce/effect-machine"
4108
4219
  *
4109
4220
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
4110
- * const States = Machine.defineStates({ Idle })
4221
+ * const States = Machine.states({ Idle })
4111
4222
  * const machine = Machine.make({
4112
4223
  * states: States.states,
4113
4224
  * events: Machine.events(),
@@ -4129,7 +4240,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
4129
4240
  * @since 0.4.0
4130
4241
  */
4131
4242
  export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
4132
- type EffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, unknown, unknown>> = {
4243
+ type EffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>> = {
4133
4244
  readonly id: InvokeLifecycleId;
4134
4245
  readonly effect: Source;
4135
4246
  readonly after?: never;
@@ -4138,9 +4249,9 @@ type EffectInvokeSource<States extends Machine.StateSchemas, Events extends Read
4138
4249
  readonly address?: never;
4139
4250
  readonly onSnapshot?: never;
4140
4251
  };
4141
- type EffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>, readonly [], readonly []>>;
4142
- type EffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>, readonly [], readonly []>>;
4143
- type EffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
4252
+ type EffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>, InputEvents, ParentEvents>>;
4253
+ type EffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>, InputEvents, ParentEvents>>;
4254
+ type EffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
4144
4255
  type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false;
4145
4256
  type BoundEffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>> = {
4146
4257
  readonly id: InvokeLifecycleId;
@@ -4290,11 +4401,10 @@ export interface Invoker<States extends Machine.StateSchemas, Events extends Rea
4290
4401
  * `address`. Child descriptors already own their identity, so `id` and
4291
4402
  * `address` must not be repeated.
4292
4403
  *
4293
- * Owner references are intentionally non-sendable here because this standalone
4294
- * constructor does not know the owning definition. When a callback sends to
4295
- * `self` or `parent`, use the bound constructor on the owning definition
4296
- * (`definition.invoke(...)`) so the exact public input and `parentEvents`
4297
- * protocols are available.
4404
+ * Inside `handle(...)`, the owning definition contextually supplies its public
4405
+ * input and `parentEvents` protocols. Invocation sources and lifecycle handlers
4406
+ * can therefore send through `self` and `parent` without naming the definition.
4407
+ * The bound `definition.invoke(...)` constructor remains an equivalent form.
4298
4408
  *
4299
4409
  * ```ts
4300
4410
  * invoke: Machine.invoke({
@@ -4319,34 +4429,34 @@ export interface Invoker<States extends Machine.StateSchemas, Events extends Rea
4319
4429
  * @since 0.9.0
4320
4430
  */
4321
4431
  export declare const invoke: {
4322
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, unknown, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
4323
- readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>;
4324
- readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>;
4432
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
4433
+ readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4434
+ readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4325
4435
  }, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
4326
4436
  "onDone must be omitted when the Effect output is never"
4327
4437
  ] : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
4328
4438
  "onFailure must be omitted when the Effect error is never"
4329
- ] : []): EffectInvokeResult<States, Events, Emits, StateId, Source>;
4330
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, never, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
4331
- readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>;
4439
+ ] : []): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4440
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, never, unknown>, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
4441
+ readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4332
4442
  readonly onFailure?: never;
4333
4443
  }, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
4334
4444
  "onDone must be omitted when the Effect output is never"
4335
- ] : []): EffectInvokeResult<States, Events, Emits, StateId, Source>;
4336
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<never, unknown, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
4445
+ ] : []): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4446
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, unknown, unknown>, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
4337
4447
  readonly onDone?: never;
4338
- readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>;
4448
+ readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4339
4449
  }, ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
4340
4450
  "onFailure must be omitted when the Effect error is never"
4341
- ] : []): EffectInvokeResult<States, Events, Emits, StateId, Source>;
4342
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<never, never, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
4451
+ ] : []): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4452
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, never, unknown>, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
4343
4453
  readonly onDone?: never;
4344
4454
  readonly onFailure?: never;
4345
- }): EffectInvokeResult<States, Events, Emits, StateId, Source>;
4346
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Config extends object>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, readonly [], readonly []>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>;
4347
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>>(config: Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, readonly [], readonly []>): Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
4348
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, const Config extends object>(config: Config & Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, readonly [], readonly []>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
4349
- <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Child extends ChildMachine.Any, const Config extends object>(config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, readonly [], readonly []>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Machine.Output<Child["machine"]>, Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>, Machine.Services<Child["machine"]>, Machine.InitialError<Child["machine"]>, Machine.Emit<Child["machine"]>, Machine.EventOf<Machine.ParentEvents<Child["machine"]>>>;
4455
+ }): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
4456
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>;
4457
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, InputEvents, ParentEvents>): Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
4458
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
4459
+ <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Child extends ChildMachine.Any, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Machine.Output<Child["machine"]>, Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>, Machine.Services<Child["machine"]>, Machine.InitialError<Child["machine"]>, Machine.Emit<Child["machine"]>, Machine.EventOf<Machine.ParentEvents<Child["machine"]>>>;
4350
4460
  };
4351
4461
  /**
4352
4462
  * Plans the initial state for a machine without executing machine commands.
@@ -4373,7 +4483,7 @@ export declare const invoke: {
4373
4483
  * import { Machine } from "@typeonce/effect-machine"
4374
4484
  *
4375
4485
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
4376
- * const States = Machine.defineStates({ Idle })
4486
+ * const States = Machine.states({ Idle })
4377
4487
  * const machine = Machine.make({
4378
4488
  * states: States.states,
4379
4489
  * events: Machine.events(),
@@ -4515,7 +4625,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
4515
4625
  * class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
4516
4626
  * class On extends Schema.TaggedClass<On>("On")("On", {}) {}
4517
4627
  * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
4518
- * const States = Machine.defineStates({ Off, On })
4628
+ * const States = Machine.states({ Off, On })
4519
4629
  * const machine = Machine.make({
4520
4630
  * states: States.states,
4521
4631
  * events: Machine.events(Toggle),
@@ -4722,7 +4832,7 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
4722
4832
  * import { Machine } from "@typeonce/effect-machine"
4723
4833
  *
4724
4834
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
4725
- * const States = Machine.defineStates({ Idle })
4835
+ * const States = Machine.states({ Idle })
4726
4836
  * const machine = Machine.make({
4727
4837
  * states: States.states,
4728
4838
  * events: Machine.events(),
@@ -4775,7 +4885,7 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
4775
4885
  * import { Machine } from "@typeonce/effect-machine"
4776
4886
  *
4777
4887
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
4778
- * const States = Machine.defineStates({ Idle })
4888
+ * const States = Machine.states({ Idle })
4779
4889
  * const machine = Machine.make({
4780
4890
  * states: States.states,
4781
4891
  * events: Machine.events(),