@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/src/Machine.ts CHANGED
@@ -96,7 +96,7 @@ export const isInitialEvent = (u: unknown): u is InitialEvent => hasProperty(u,
96
96
  type IsAny<A> = 0 extends (1 & A) ? true : false
97
97
 
98
98
  /**
99
- * A schema-first machine definition.
99
+ * A schema-first machine implementation.
100
100
  *
101
101
  * **Details**
102
102
  *
@@ -222,12 +222,68 @@ export interface Machine<
222
222
  readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>
223
223
 
224
224
  /**
225
- * Adds typed state handlers and returns the refined machine definition.
226
- * Successive calls implement the remaining unhandled states while retaining
227
- * accumulated errors, services, final states, and output evidence.
228
- * Event dispatch maps and transition descriptors are captured by value, so
229
- * later mutation of the objects supplied to this call cannot alter the
230
- * resulting machine.
225
+ * Machine-bound equivalent of {@link invoke}. Both forms preserve this
226
+ * machine's public input and parent protocols in invocation callbacks;
227
+ * `Machine.invoke(...)` inside `handle(...)` is the canonical inline form.
228
+ *
229
+ * @since 0.11.0
230
+ */
231
+ readonly invoke: Invoker<States, Events, Emits, InputEvents, ParentEvents>
232
+
233
+ /** @internal */
234
+ readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
235
+ /** @internal */
236
+ readonly initialDefinition: Machine.InitialDefinition
237
+ }
238
+
239
+ /**
240
+ * A schema-first machine definition that can produce independent
241
+ * implementations.
242
+ *
243
+ * **Details**
244
+ *
245
+ * Call `handle` once for each implementation. The returned {@link Machine}
246
+ * does not expose `handle`, so handler configuration cannot be accumulated or
247
+ * replaced through chained calls. Calling `handle` multiple times on the same
248
+ * definition remains supported and creates independent machines.
249
+ *
250
+ * @category models
251
+ * @since 0.15.0
252
+ */
253
+ export interface Definition<
254
+ States extends Machine.StateSchemas,
255
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
256
+ Input extends Schema.Top = typeof Schema.Void,
257
+ InitialE = never,
258
+ InitialR = never,
259
+ FinalStates extends Machine.StateIdentifier<States> = never,
260
+ Output = never,
261
+ Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
262
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
263
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
264
+ > extends
265
+ Machine<
266
+ States,
267
+ Events,
268
+ Input,
269
+ Machine.StateIdentifier<States>,
270
+ never,
271
+ never,
272
+ InitialE,
273
+ InitialR,
274
+ FinalStates,
275
+ Output,
276
+ Emits,
277
+ never,
278
+ InputEvents,
279
+ ParentEvents
280
+ >
281
+ {
282
+ /**
283
+ * Adds typed state handlers and returns an independent machine
284
+ * implementation. Event dispatch maps and transition descriptors are
285
+ * captured by value, so later mutation of the supplied objects cannot alter
286
+ * the resulting machine.
231
287
  *
232
288
  * @since 0.4.0
233
289
  */
@@ -236,31 +292,35 @@ export interface Machine<
236
292
  Events,
237
293
  Emits,
238
294
  Input,
239
- UnhandledStates,
240
- E,
241
- R,
295
+ Machine.StateIdentifier<States>,
296
+ never,
297
+ never,
242
298
  InitialE,
243
299
  InitialR,
244
300
  FinalStates,
245
301
  Output,
246
- OutputStates,
302
+ never,
247
303
  InputEvents,
248
304
  ParentEvents
249
305
  >
306
+ }
250
307
 
308
+ /**
309
+ * Namespace containing type-level members associated with {@link Definition}.
310
+ *
311
+ * @category models
312
+ * @since 0.15.0
313
+ */
314
+ export declare namespace Definition {
251
315
  /**
252
- * Preserves invocation inference with this machine's public input and parent
253
- * protocols. Prefer this bound constructor when an invocation source or
254
- * lifecycle handler uses `self` or `parent`.
316
+ * Any schema-first machine definition.
255
317
  *
256
- * @since 0.11.0
318
+ * @category models
319
+ * @since 0.15.0
257
320
  */
258
- readonly invoke: Invoker<States, Events, Emits, InputEvents, ParentEvents>
259
-
260
- /** @internal */
261
- readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
262
- /** @internal */
263
- readonly initialDefinition: Machine.InitialDefinition
321
+ export interface Any extends Machine.Any {
322
+ readonly handle: any
323
+ }
264
324
  }
265
325
 
266
326
  export {
@@ -687,8 +747,12 @@ type ValidateCompoundStateNode<
687
747
  Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
688
748
  readonly states: ValidateStateTree<Children, true, Extract<Path, string>>
689
749
  }
690
- : StateDefinitionError<"Compound initial must be one of its direct child keys">
691
- : StateDefinitionError<"Compound states must declare an initial child">
750
+ : StateDefinitionError<
751
+ "Compound initial must be one of its direct child keys",
752
+ Path,
753
+ Extract<Initial, PropertyKey>
754
+ >
755
+ : StateDefinitionError<"Compound states must declare an initial child", Path>
692
756
 
693
757
  type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ?
694
758
  StateDefinitionError<"Atomic states cannot declare an initial child">
@@ -723,7 +787,29 @@ type InvalidDefinedStateTreeInput<States extends Machine.StateSchemas> = [States
723
787
  [Machine.ValidateStateSchemas<States>] ? never
724
788
  : States & Machine.ValidateStateSchemas<States>
725
789
 
726
- interface DefineStates {
790
+ type ReusableStateNodeConfig =
791
+ | Machine.AtomicStateNodeConfig
792
+ | Machine.CompoundStateNodeConfig
793
+ | Machine.ParallelStateNodeConfig
794
+
795
+ type ReusableStateValidation<Node> = Node extends ReusableStateNodeConfig ? ValidateStateNode<Node, false, "state">
796
+ : StateDefinitionError<"Reusable states must be active state nodes", "state">
797
+
798
+ type ValidateDefinedState<Node> = [Node] extends [ReusableStateValidation<Node>] ? []
799
+ : [validation: ReusableStateValidation<Node>]
800
+
801
+ type InvalidDefinedStateInput<Node> = [Node] extends [ReusableStateValidation<Node>] ? never
802
+ : Node & ReusableStateValidation<Node>
803
+
804
+ interface StateConstructor {
805
+ <const Node>(
806
+ node: Node & DefineStateNodeInput<NoInfer<Node>>,
807
+ ..._validation: ValidateDefinedState<NoInfer<Node>>
808
+ ): Node
809
+ <const Node>(node: InvalidDefinedStateInput<Node>): never
810
+ }
811
+
812
+ interface StatesConstructor {
727
813
  <const States extends Machine.StateSchemas>(
728
814
  states: States & DefineStateTreeInput<NoInfer<States>>,
729
815
  ..._validation: ValidateDefinedStates<NoInfer<States>>
@@ -2410,8 +2496,6 @@ export declare namespace Machine {
2410
2496
  /** @internal */
2411
2497
  readonly handlers: any
2412
2498
  /** @internal */
2413
- readonly handle: any
2414
- /** @internal */
2415
2499
  readonly invoke: any
2416
2500
  /** @internal */
2417
2501
  readonly initial: any
@@ -2882,12 +2966,12 @@ export declare namespace Machine {
2882
2966
  export type StateSchemas = StateTree
2883
2967
 
2884
2968
  /**
2885
- * Builder for initial state snapshots generated by `defineStates`.
2969
+ * Builder for initial state snapshots generated by `states`.
2886
2970
  *
2887
2971
  * **When to use**
2888
2972
  *
2889
2973
  * Use when you need the type of the `initial` property returned by
2890
- * `defineStates` or want to expose an initial snapshot builder from a helper.
2974
+ * `states` or want to expose an initial snapshot builder from a helper.
2891
2975
  *
2892
2976
  * **Details**
2893
2977
  *
@@ -2900,7 +2984,7 @@ export declare namespace Machine {
2900
2984
  type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>
2901
2985
 
2902
2986
  /**
2903
- * State definitions and snapshot access helpers returned by `defineStates`.
2987
+ * State definitions and snapshot access helpers returned by `states`.
2904
2988
  *
2905
2989
  * **Details**
2906
2990
  *
@@ -2912,9 +2996,19 @@ export declare namespace Machine {
2912
2996
  * @since 0.4.0
2913
2997
  */
2914
2998
  export interface DefinedStates<States extends StateSchemas> {
2915
- /** Original state tree supplied to {@link defineStates}. */
2999
+ /** Captured state tree supplied to {@link states}. */
2916
3000
  readonly states: States
2917
3001
 
3002
+ /**
3003
+ * Checks and preserves one active state path from this definition.
3004
+ *
3005
+ * This is useful for named path helpers, including finite template-literal
3006
+ * families. Every member of a path union must exist in the state tree.
3007
+ *
3008
+ * @since 0.15.0
3009
+ */
3010
+ readonly path: <const Path extends StateIdentifier<States>>(path: Path) => Path
3011
+
2918
3012
  /**
2919
3013
  * Returns the decoded value for an active state path. The supplied
2920
3014
  * snapshot may be a complete root snapshot or a snapshot previously
@@ -6827,6 +6921,16 @@ export declare namespace Machine {
6827
6921
  >
6828
6922
  }
6829
6923
 
6924
+ /**
6925
+ * Extracts the complete logical snapshot represented by a state definition.
6926
+ *
6927
+ * @category utility types
6928
+ * @since 0.15.0
6929
+ */
6930
+ export type Snapshot<Defined extends Machine.DefinedStates<any>> = Defined extends Machine.DefinedStates<infer States>
6931
+ ? Machine.Snapshot<States>
6932
+ : never
6933
+
6830
6934
  /**
6831
6935
  * Returns `true` if a value is a `Machine`.
6832
6936
  *
@@ -6877,7 +6981,44 @@ export const isFinal: <
6877
6981
  ) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal as any
6878
6982
 
6879
6983
  /**
6880
- * Defines a state tree while preserving literal state paths.
6984
+ * Defines one reusable active state while preserving its exact child topology.
6985
+ *
6986
+ * Prefer declaring state nodes inline in {@link states}. Use this constructor
6987
+ * only when the same state definition is mounted more than once.
6988
+ * Tagged schemas are already reusable and do not need this constructor.
6989
+ *
6990
+ * **Example** (Repeated compound state)
6991
+ *
6992
+ * ```ts
6993
+ * import { Schema } from "effect"
6994
+ * import { Machine } from "@typeonce/effect-machine"
6995
+ *
6996
+ * const TradingState = Schema.TaggedUnion({
6997
+ * InSession: {},
6998
+ * Applying: {}
6999
+ * })
7000
+ * const TradingSlot = Machine.state({
7001
+ * initial: "Idle",
7002
+ * states: {
7003
+ * Idle: {},
7004
+ * InSession: TradingState.cases.InSession,
7005
+ * Applying: TradingState.cases.Applying
7006
+ * }
7007
+ * })
7008
+ *
7009
+ * const States = Machine.states({
7010
+ * slot1: TradingSlot,
7011
+ * slot2: TradingSlot
7012
+ * })
7013
+ * ```
7014
+ *
7015
+ * @category constructors
7016
+ * @since 0.15.0
7017
+ */
7018
+ export const state: StateConstructor = internal.state as StateConstructor
7019
+
7020
+ /**
7021
+ * Defines the complete state tree while preserving literal state paths.
6881
7022
  *
6882
7023
  * **When to use**
6883
7024
  *
@@ -6886,7 +7027,8 @@ export const isFinal: <
6886
7027
  *
6887
7028
  * **Details**
6888
7029
  *
6889
- * The returned `states` property is the same object passed to `defineStates`.
7030
+ * The returned `states` property is an immutable structural capture of the
7031
+ * supplied tree.
6890
7032
  * `Machine.make` derives its initial target selector from that tree and
6891
7033
  * enforces compound and parallel initial-state rules. Active nodes may omit
6892
7034
  * `schema` when they own no value and still participate fully in targeting,
@@ -6900,7 +7042,7 @@ export const isFinal: <
6900
7042
  *
6901
7043
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
6902
7044
  *
6903
- * const States = Machine.defineStates({ idle: Idle })
7045
+ * const States = Machine.states({ idle: Idle })
6904
7046
  *
6905
7047
  * Machine.make({
6906
7048
  * states: States.states,
@@ -6915,7 +7057,7 @@ export const isFinal: <
6915
7057
  * @category constructors
6916
7058
  * @since 0.4.0
6917
7059
  */
6918
- export const defineStates: DefineStates = internal.defineStates
7060
+ export const states: StatesConstructor = internal.states
6919
7061
 
6920
7062
  type InitialDirectInput<
6921
7063
  States extends Machine.StateSchemas,
@@ -6967,19 +7109,15 @@ type MakeResult<
6967
7109
  InitialR,
6968
7110
  InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
6969
7111
  ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
6970
- > = Machine<
7112
+ > = Definition<
6971
7113
  States,
6972
7114
  readonly [...InputEvents, ...InternalEvents],
6973
7115
  Input,
6974
- Machine.StateIdentifier<States>,
6975
- never,
6976
- never,
6977
7116
  InitialE,
6978
7117
  InitialR,
6979
7118
  Machine.FinalStateFromDefinition<States>,
6980
7119
  Machine.TerminalOutput<States>,
6981
7120
  Emits,
6982
- never,
6983
7121
  InputEvents,
6984
7122
  ParentEvents
6985
7123
  >
@@ -7028,7 +7166,7 @@ interface Make {
7028
7166
  * State and event schemas provide runtime boundary validation while their
7029
7167
  * decoded types drive handler, state, event, target, error, and service
7030
7168
  * inference. State-tree validation is applied whether `states` comes from
7031
- * `defineStates` or is passed inline. Call `handle` on the returned definition
7169
+ * `states` or is passed inline. Call `handle` on the returned definition
7032
7170
  * to implement state behavior with ordinary TypeScript control flow.
7033
7171
  *
7034
7172
  * `Machine.events` defines the public input protocol. `Machine.internalEvents`
@@ -7053,7 +7191,7 @@ interface Make {
7053
7191
  * by: Schema.Number
7054
7192
  * }) {}
7055
7193
  *
7056
- * const States = Machine.defineStates({ Count })
7194
+ * const States = Machine.states({ Count })
7057
7195
  * const Events = Machine.events(Increment)
7058
7196
  *
7059
7197
  * const counter = Machine.make({
@@ -7076,7 +7214,7 @@ interface Make {
7076
7214
  * })
7077
7215
  * ```
7078
7216
  *
7079
- * @see {@link defineStates} for typed state-tree helpers.
7217
+ * @see {@link states} for typed state-tree helpers.
7080
7218
  * @category constructors
7081
7219
  * @since 0.4.0
7082
7220
  */
@@ -7104,9 +7242,14 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
7104
7242
  * **Example**
7105
7243
  *
7106
7244
  * ```ts
7107
- * const Events = Machine.events(Increment, Reset)
7108
- * const machine = Machine.make({ events: Events, ... })
7109
- * yield* ref.send(Events.Increment({ by: 1 }))
7245
+ * export const Event = Machine.events(
7246
+ * Schema.TaggedUnion({
7247
+ * Increment: { by: Schema.Number },
7248
+ * Reset: {}
7249
+ * })
7250
+ * )
7251
+ * const machine = Machine.make({ events: Event, ... })
7252
+ * yield* ref.send(Event.Increment({ by: 1 }))
7110
7253
  * ```
7111
7254
  *
7112
7255
  * @category constructors
@@ -7132,11 +7275,16 @@ export const events: {
7132
7275
  * **Example**
7133
7276
  *
7134
7277
  * ```ts
7135
- * const InternalEvents = Machine.internalEvents(Loaded, Failed)
7136
- * const machine = Machine.make({ internalEvents: InternalEvents, ... })
7278
+ * const Internal = Machine.internalEvents(
7279
+ * Schema.TaggedUnion({
7280
+ * Loaded: { value: Schema.String },
7281
+ * Failed: { message: Schema.String }
7282
+ * })
7283
+ * )
7284
+ * const machine = Machine.make({ internalEvents: Internal, ... })
7137
7285
  *
7138
7286
  * // Inside a transition callback:
7139
- * enqueue.raise(InternalEvents.Loaded({ value }))
7287
+ * enqueue.raise(Internal.Loaded({ value }))
7140
7288
  * ```
7141
7289
  *
7142
7290
  * @category constructors
@@ -7157,6 +7305,17 @@ export const internalEvents: {
7157
7305
  * implicitly to a parent machine. Observe them through `MachineRef.emissions` or
7158
7306
  * the AtomMachine emission stream adapters.
7159
7307
  *
7308
+ * **Example**
7309
+ *
7310
+ * ```ts
7311
+ * const Emitted = Machine.emittedEvents(
7312
+ * Schema.TaggedUnion({
7313
+ * Saved: { id: Schema.String }
7314
+ * })
7315
+ * )
7316
+ * const machine = Machine.make({ emittedEvents: Emitted, ... })
7317
+ * ```
7318
+ *
7160
7319
  * @category constructors
7161
7320
  * @since 0.10.0
7162
7321
  */
@@ -7199,7 +7358,7 @@ export const emittedEvents: {
7199
7358
  * import { Machine } from "@typeonce/effect-machine"
7200
7359
  *
7201
7360
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
7202
- * const States = Machine.defineStates({ Idle })
7361
+ * const States = Machine.states({ Idle })
7203
7362
  * const machine = Machine.make({
7204
7363
  * states: States.states,
7205
7364
  * events: Machine.events(),
@@ -7284,7 +7443,7 @@ export const encodeSnapshot: <
7284
7443
  * import { Machine } from "@typeonce/effect-machine"
7285
7444
  *
7286
7445
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
7287
- * const States = Machine.defineStates({ Idle })
7446
+ * const States = Machine.states({ Idle })
7288
7447
  * const machine = Machine.make({
7289
7448
  * states: States.states,
7290
7449
  * events: Machine.events(),
@@ -7348,9 +7507,11 @@ type EffectInvokeSource<
7348
7507
  States extends Machine.StateSchemas,
7349
7508
  Events extends ReadonlyArray<Machine.TaggedSchema>,
7350
7509
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
7510
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
7511
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
7351
7512
  StateId extends Machine.StateIdentifier<States>,
7352
7513
  Source extends (
7353
- context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
7514
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
7354
7515
  ) => Effect.Effect<unknown, unknown, unknown>
7355
7516
  > = {
7356
7517
  readonly id: InvokeLifecycleId
@@ -7366,6 +7527,8 @@ type EffectDoneHandler<
7366
7527
  States extends Machine.StateSchemas,
7367
7528
  Events extends ReadonlyArray<Machine.TaggedSchema>,
7368
7529
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
7530
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
7531
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
7369
7532
  StateId extends Machine.StateIdentifier<States>,
7370
7533
  Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
7371
7534
  > = Machine.InvokeTransition<
@@ -7379,8 +7542,8 @@ type EffectDoneHandler<
7379
7542
  Emits,
7380
7543
  StateId,
7381
7544
  Effect.Success<ReturnType<NoInfer<Source>>>,
7382
- readonly [],
7383
- readonly []
7545
+ InputEvents,
7546
+ ParentEvents
7384
7547
  >
7385
7548
  >
7386
7549
 
@@ -7388,6 +7551,8 @@ type EffectFailureHandler<
7388
7551
  States extends Machine.StateSchemas,
7389
7552
  Events extends ReadonlyArray<Machine.TaggedSchema>,
7390
7553
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
7554
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
7555
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
7391
7556
  StateId extends Machine.StateIdentifier<States>,
7392
7557
  Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
7393
7558
  > = Machine.InvokeTransition<
@@ -7401,8 +7566,8 @@ type EffectFailureHandler<
7401
7566
  Emits,
7402
7567
  StateId,
7403
7568
  Effect.Error<ReturnType<NoInfer<Source>>>,
7404
- readonly [],
7405
- readonly []
7569
+ InputEvents,
7570
+ ParentEvents
7406
7571
  >
7407
7572
  >
7408
7573
 
@@ -7410,10 +7575,12 @@ type EffectInvokeResult<
7410
7575
  States extends Machine.StateSchemas,
7411
7576
  Events extends ReadonlyArray<Machine.TaggedSchema>,
7412
7577
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
7578
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
7579
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
7413
7580
  StateId extends Machine.StateIdentifier<States>,
7414
7581
  Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
7415
7582
  > =
7416
- & Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []>
7583
+ & Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
7417
7584
  & Machine.InvokeTyped<
7418
7585
  Effect.Success<ReturnType<Source>>,
7419
7586
  Effect.Error<ReturnType<Source>>,
@@ -7897,11 +8064,10 @@ export interface Invoker<
7897
8064
  * `address`. Child descriptors already own their identity, so `id` and
7898
8065
  * `address` must not be repeated.
7899
8066
  *
7900
- * Owner references are intentionally non-sendable here because this standalone
7901
- * constructor does not know the owning definition. When a callback sends to
7902
- * `self` or `parent`, use the bound constructor on the owning definition
7903
- * (`definition.invoke(...)`) so the exact public input and `parentEvents`
7904
- * protocols are available.
8067
+ * Inside `handle(...)`, the owning definition contextually supplies its public
8068
+ * input and `parentEvents` protocols. Invocation sources and lifecycle handlers
8069
+ * can therefore send through `self` and `parent` without naming the definition.
8070
+ * The bound `definition.invoke(...)` constructor remains an equivalent form.
7905
8071
  *
7906
8072
  * ```ts
7907
8073
  * invoke: Machine.invoke({
@@ -7932,14 +8098,16 @@ export const invoke: {
7932
8098
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
7933
8099
  StateId extends Machine.StateIdentifier<States>,
7934
8100
  const Source extends (
7935
- context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
7936
- ) => Effect.Effect<unknown, unknown, unknown>
8101
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8102
+ ) => Effect.Effect<unknown, unknown, unknown>,
8103
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8104
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
7937
8105
  >(
7938
8106
  config:
7939
- & EffectInvokeSource<States, Events, Emits, StateId, Source>
8107
+ & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7940
8108
  & {
7941
- readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>
7942
- readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>
8109
+ readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8110
+ readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7943
8111
  },
7944
8112
  ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
7945
8113
  "onDone must be omitted when the Effect output is never"
@@ -7948,71 +8116,79 @@ export const invoke: {
7948
8116
  "onFailure must be omitted when the Effect error is never"
7949
8117
  ]
7950
8118
  : []
7951
- ): EffectInvokeResult<States, Events, Emits, StateId, Source>
8119
+ ): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7952
8120
  <
7953
8121
  const States extends Machine.StateSchemas,
7954
8122
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
7955
8123
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
7956
8124
  StateId extends Machine.StateIdentifier<States>,
7957
8125
  const Source extends (
7958
- context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
7959
- ) => Effect.Effect<unknown, never, unknown>
8126
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8127
+ ) => Effect.Effect<unknown, never, unknown>,
8128
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8129
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
7960
8130
  >(
7961
8131
  config:
7962
- & EffectInvokeSource<States, Events, Emits, StateId, Source>
8132
+ & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7963
8133
  & {
7964
- readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>
8134
+ readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7965
8135
  readonly onFailure?: never
7966
8136
  },
7967
8137
  ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
7968
8138
  "onDone must be omitted when the Effect output is never"
7969
8139
  ]
7970
8140
  : []
7971
- ): EffectInvokeResult<States, Events, Emits, StateId, Source>
8141
+ ): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7972
8142
  <
7973
8143
  const States extends Machine.StateSchemas,
7974
8144
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
7975
8145
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
7976
8146
  StateId extends Machine.StateIdentifier<States>,
7977
8147
  const Source extends (
7978
- context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
7979
- ) => Effect.Effect<never, unknown, unknown>
8148
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8149
+ ) => Effect.Effect<never, unknown, unknown>,
8150
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8151
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
7980
8152
  >(
7981
8153
  config:
7982
- & EffectInvokeSource<States, Events, Emits, StateId, Source>
8154
+ & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7983
8155
  & {
7984
8156
  readonly onDone?: never
7985
- readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>
8157
+ readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7986
8158
  },
7987
8159
  ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
7988
8160
  "onFailure must be omitted when the Effect error is never"
7989
8161
  ]
7990
8162
  : []
7991
- ): EffectInvokeResult<States, Events, Emits, StateId, Source>
8163
+ ): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7992
8164
  <
7993
8165
  const States extends Machine.StateSchemas,
7994
8166
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
7995
8167
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
7996
8168
  StateId extends Machine.StateIdentifier<States>,
7997
8169
  const Source extends (
7998
- context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
7999
- ) => Effect.Effect<never, never, unknown>
8170
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8171
+ ) => Effect.Effect<never, never, unknown>,
8172
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8173
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8000
8174
  >(
8001
8175
  config:
8002
- & EffectInvokeSource<States, Events, Emits, StateId, Source>
8176
+ & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8003
8177
  & {
8004
8178
  readonly onDone?: never
8005
8179
  readonly onFailure?: never
8006
8180
  }
8007
- ): EffectInvokeResult<States, Events, Emits, StateId, Source>
8181
+ ): EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8008
8182
  <
8009
8183
  const States extends Machine.StateSchemas,
8010
8184
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
8011
8185
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8012
8186
  StateId extends Machine.StateIdentifier<States>,
8013
- const Config extends object
8187
+ const Config extends object,
8188
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8189
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8014
8190
  >(
8015
- config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, readonly [], readonly []>
8191
+ config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>
8016
8192
  ): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>
8017
8193
  <
8018
8194
  const States extends Machine.StateSchemas,
@@ -8025,7 +8201,9 @@ export const invoke: {
8025
8201
  ChildRequirements,
8026
8202
  ChildOutput,
8027
8203
  ChildInitialError,
8028
- Address extends ChildAddress<never>
8204
+ Address extends ChildAddress<never>,
8205
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8206
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8029
8207
  >(
8030
8208
  config: Machine.LogicInvokeArgs<
8031
8209
  States,
@@ -8039,7 +8217,7 @@ export const invoke: {
8039
8217
  ChildOutput,
8040
8218
  ChildInitialError,
8041
8219
  Address,
8042
- (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Logic<
8220
+ (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Logic<
8043
8221
  ChildState,
8044
8222
  ChildEvent,
8045
8223
  ChildError,
@@ -8047,11 +8225,11 @@ export const invoke: {
8047
8225
  ChildOutput,
8048
8226
  ChildInitialError
8049
8227
  >,
8050
- readonly [],
8051
- readonly []
8228
+ InputEvents,
8229
+ ParentEvents
8052
8230
  >
8053
8231
  ):
8054
- & Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []>
8232
+ & Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
8055
8233
  & Machine.InvokeTyped<
8056
8234
  ChildOutput,
8057
8235
  ChildError,
@@ -8070,7 +8248,9 @@ export const invoke: {
8070
8248
  ChildOutput,
8071
8249
  ChildInitialError,
8072
8250
  Address extends ChildAddress<never>,
8073
- const Config extends object
8251
+ const Config extends object,
8252
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8253
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8074
8254
  >(
8075
8255
  config:
8076
8256
  & Config
@@ -8087,8 +8267,8 @@ export const invoke: {
8087
8267
  ChildInitialError,
8088
8268
  Address,
8089
8269
  Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>,
8090
- readonly [],
8091
- readonly []
8270
+ InputEvents,
8271
+ ParentEvents
8092
8272
  >
8093
8273
  ):
8094
8274
  & Config
@@ -8105,11 +8285,13 @@ export const invoke: {
8105
8285
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8106
8286
  StateId extends Machine.StateIdentifier<States>,
8107
8287
  const Child extends ChildMachine.Any,
8108
- const Config extends object
8288
+ const Config extends object,
8289
+ const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8290
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8109
8291
  >(
8110
8292
  config:
8111
8293
  & Config
8112
- & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, readonly [], readonly []>
8294
+ & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, InputEvents, ParentEvents>
8113
8295
  ):
8114
8296
  & Config
8115
8297
  & Machine.InvokeOwned<States, Events, Emits, StateId>
@@ -8147,7 +8329,7 @@ export const invoke: {
8147
8329
  * import { Machine } from "@typeonce/effect-machine"
8148
8330
  *
8149
8331
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
8150
- * const States = Machine.defineStates({ Idle })
8332
+ * const States = Machine.states({ Idle })
8151
8333
  * const machine = Machine.make({
8152
8334
  * states: States.states,
8153
8335
  * events: Machine.events(),
@@ -8403,7 +8585,7 @@ export const enabled: <
8403
8585
  * class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
8404
8586
  * class On extends Schema.TaggedClass<On>("On")("On", {}) {}
8405
8587
  * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
8406
- * const States = Machine.defineStates({ Off, On })
8588
+ * const States = Machine.states({ Off, On })
8407
8589
  * const machine = Machine.make({
8408
8590
  * states: States.states,
8409
8591
  * events: Machine.events(Toggle),
@@ -8786,7 +8968,7 @@ export const prepare: <
8786
8968
  * import { Machine } from "@typeonce/effect-machine"
8787
8969
  *
8788
8970
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
8789
- * const States = Machine.defineStates({ Idle })
8971
+ * const States = Machine.states({ Idle })
8790
8972
  * const machine = Machine.make({
8791
8973
  * states: States.states,
8792
8974
  * events: Machine.events(),
@@ -8899,7 +9081,7 @@ export const start: <
8899
9081
  * import { Machine } from "@typeonce/effect-machine"
8900
9082
  *
8901
9083
  * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
8902
- * const States = Machine.defineStates({ Idle })
9084
+ * const States = Machine.states({ Idle })
8903
9085
  * const machine = Machine.make({
8904
9086
  * states: States.states,
8905
9087
  * events: Machine.events(),