@typeonce/effect-machine 0.9.0 → 0.11.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.
Files changed (93) hide show
  1. package/README.md +167 -28
  2. package/dist/Machine.d.ts +491 -283
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +74 -76
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/atom.d.ts +7 -3
  7. package/dist/internal/machine/atom.d.ts.map +1 -1
  8. package/dist/internal/machine/atom.js +42 -6
  9. package/dist/internal/machine/atom.js.map +1 -1
  10. package/dist/internal/machine/cluster.d.ts.map +1 -1
  11. package/dist/internal/machine/cluster.js +2 -1
  12. package/dist/internal/machine/cluster.js.map +1 -1
  13. package/dist/internal/machine/command.js +2 -2
  14. package/dist/internal/machine/command.js.map +1 -1
  15. package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
  16. package/dist/internal/machine/commandRuntime.js +6 -3
  17. package/dist/internal/machine/commandRuntime.js.map +1 -1
  18. package/dist/internal/machine/configuration.d.ts +8 -1
  19. package/dist/internal/machine/configuration.d.ts.map +1 -1
  20. package/dist/internal/machine/configuration.js +9 -4
  21. package/dist/internal/machine/configuration.js.map +1 -1
  22. package/dist/internal/machine/errors.d.ts +1 -1
  23. package/dist/internal/machine/errors.d.ts.map +1 -1
  24. package/dist/internal/machine/executionPlan.d.ts +3 -3
  25. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  26. package/dist/internal/machine/executionPlan.js +50 -25
  27. package/dist/internal/machine/executionPlan.js.map +1 -1
  28. package/dist/internal/machine/invocation.d.ts.map +1 -1
  29. package/dist/internal/machine/invocation.js +3 -2
  30. package/dist/internal/machine/invocation.js.map +1 -1
  31. package/dist/internal/machine/machine.d.ts +15 -19
  32. package/dist/internal/machine/machine.d.ts.map +1 -1
  33. package/dist/internal/machine/machine.js +16 -10
  34. package/dist/internal/machine/machine.js.map +1 -1
  35. package/dist/internal/machine/planner.d.ts +2 -1
  36. package/dist/internal/machine/planner.d.ts.map +1 -1
  37. package/dist/internal/machine/planner.js +61 -24
  38. package/dist/internal/machine/planner.js.map +1 -1
  39. package/dist/internal/machine/process.d.ts +3 -0
  40. package/dist/internal/machine/process.d.ts.map +1 -1
  41. package/dist/internal/machine/process.js +11 -8
  42. package/dist/internal/machine/process.js.map +1 -1
  43. package/dist/internal/machine/protocol.d.ts +7 -13
  44. package/dist/internal/machine/protocol.d.ts.map +1 -1
  45. package/dist/internal/machine/protocol.js +128 -50
  46. package/dist/internal/machine/protocol.js.map +1 -1
  47. package/dist/internal/machine/runtime.d.ts +22 -2
  48. package/dist/internal/machine/runtime.d.ts.map +1 -1
  49. package/dist/internal/machine/runtime.js +138 -10
  50. package/dist/internal/machine/runtime.js.map +1 -1
  51. package/dist/internal/machine/topology.d.ts +7 -0
  52. package/dist/internal/machine/topology.d.ts.map +1 -1
  53. package/dist/internal/machine/topology.js +6 -0
  54. package/dist/internal/machine/topology.js.map +1 -1
  55. package/dist/internal/testing/machine/finiteModel.js +1 -1
  56. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  57. package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
  58. package/dist/internal/testing/machine/runtime.js +2 -1
  59. package/dist/internal/testing/machine/runtime.js.map +1 -1
  60. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  61. package/dist/internal/testing/machine/verification.js +5 -3
  62. package/dist/internal/testing/machine/verification.js.map +1 -1
  63. package/dist/testing/MachineTest.d.ts +7 -7
  64. package/dist/testing/MachineTest.js +7 -7
  65. package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
  66. package/dist/unstable/cluster/ClusterMachine.js +1 -1
  67. package/dist/unstable/reactivity/AtomMachine.d.ts +27 -8
  68. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  69. package/dist/unstable/reactivity/AtomMachine.js +20 -3
  70. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  71. package/docs/agent-guide.md +191 -54
  72. package/package.json +1 -1
  73. package/src/Machine.ts +1220 -360
  74. package/src/internal/machine/atom.ts +76 -53
  75. package/src/internal/machine/cluster.ts +2 -1
  76. package/src/internal/machine/command.ts +2 -2
  77. package/src/internal/machine/commandRuntime.ts +9 -4
  78. package/src/internal/machine/configuration.ts +23 -5
  79. package/src/internal/machine/errors.ts +1 -1
  80. package/src/internal/machine/executionPlan.ts +74 -29
  81. package/src/internal/machine/invocation.ts +3 -2
  82. package/src/internal/machine/machine.ts +74 -49
  83. package/src/internal/machine/planner.ts +68 -24
  84. package/src/internal/machine/process.ts +75 -8
  85. package/src/internal/machine/protocol.ts +207 -68
  86. package/src/internal/machine/runtime.ts +266 -11
  87. package/src/internal/machine/topology.ts +15 -0
  88. package/src/internal/testing/machine/finiteModel.ts +1 -1
  89. package/src/internal/testing/machine/runtime.ts +2 -1
  90. package/src/internal/testing/machine/verification.ts +5 -3
  91. package/src/testing/MachineTest.ts +7 -7
  92. package/src/unstable/cluster/ClusterMachine.ts +1 -1
  93. package/src/unstable/reactivity/AtomMachine.ts +44 -10
package/src/Machine.ts CHANGED
@@ -50,6 +50,8 @@ export const TypeId: TypeId = "~effect/Machine"
50
50
  declare const MachineOutputStatesTypeId: unique symbol
51
51
  declare const MachineTypeId: unique symbol
52
52
  declare const EventConstructionTypeId: unique symbol
53
+ declare const EmittedEventConstructionTypeId: unique symbol
54
+ declare const EventProtocolTypeId: unique symbol
53
55
 
54
56
  const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId = internal.ChildMachineLogicTypeId
55
57
 
@@ -124,7 +126,8 @@ export interface Machine<
124
126
  Output = never,
125
127
  Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
126
128
  OutputStates extends Machine.StateIdentifier<States> = never,
127
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
129
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
130
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
128
131
  > extends Pipeable {
129
132
  readonly [TypeId]: TypeId
130
133
  /** @internal Stable type-level carrier for machine protocol extraction. */
@@ -141,7 +144,8 @@ export interface Machine<
141
144
  Output,
142
145
  Emits,
143
146
  OutputStates,
144
- InputEvents
147
+ InputEvents,
148
+ ParentEvents
145
149
  >
146
150
  /** @internal Prevents output implementation evidence from being widened. */
147
151
  readonly [MachineOutputStatesTypeId]: Readonly<Record<OutputStates, true>>
@@ -158,22 +162,37 @@ export interface Machine<
158
162
  *
159
163
  * @since 0.4.0
160
164
  */
161
- readonly events: InputEvents
165
+ readonly events: Machine.EventProtocol<"public", InputEvents>
162
166
 
163
167
  /**
164
- * Events reserved for raised events, child emissions, and other machine-local
165
- * work.
168
+ * Events reserved for raised events and other machine-local work.
166
169
  *
167
170
  * @since 0.4.0
168
171
  */
169
- readonly internalEvents: ReadonlyArray<Machine.TaggedSchema>
172
+ readonly internalEvents: Machine.EventProtocol<
173
+ "internal",
174
+ Machine.InternalEventSchemas<Events, InputEvents>
175
+ >
170
176
 
171
177
  /**
172
- * Events that the machine may emit to its parent or external adapter.
178
+ * Ephemeral outward notifications published to this actor's observers.
179
+ * Emissions are never delivered implicitly to an owning actor.
173
180
  *
174
181
  * @since 0.4.0
175
182
  */
176
- readonly emits: Emits
183
+ readonly emittedEvents: Machine.EventProtocol<"emitted", Emits>
184
+
185
+ /**
186
+ * Public input events accepted by an owning actor when this machine is
187
+ * running as a child.
188
+ *
189
+ * The protocol types the optional `parent` actor reference exposed to
190
+ * handlers and is checked against a concrete parent's public events at
191
+ * composition boundaries.
192
+ *
193
+ * @since 0.10.0
194
+ */
195
+ readonly parentEvents: Machine.EventProtocol<"public", ParentEvents>
177
196
 
178
197
  /**
179
198
  * Optional schema used to decode the machine input before initialization.
@@ -223,9 +242,19 @@ export interface Machine<
223
242
  FinalStates,
224
243
  Output,
225
244
  OutputStates,
226
- InputEvents
245
+ InputEvents,
246
+ ParentEvents
227
247
  >
228
248
 
249
+ /**
250
+ * Preserves invocation inference with this machine's public input and parent
251
+ * protocols. Prefer this bound constructor when an invocation source or
252
+ * lifecycle handler uses `self` or `parent`.
253
+ *
254
+ * @since 0.11.0
255
+ */
256
+ readonly invoke: Invoker<States, Events, Emits, InputEvents, ParentEvents>
257
+
229
258
  /** @internal */
230
259
  readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
231
260
  }
@@ -343,7 +372,8 @@ export type ExecutionServices<Requirements> =
343
372
  | Exclude<ActionServices<Requirements>, MachineRuntimeRequirement>
344
373
 
345
374
  /**
346
- * Managed runtime capability used to deliver raised and emitted events.
375
+ * Managed runtime capability used to deliver raised events and publish
376
+ * emitted notifications.
347
377
  *
348
378
  * @category models
349
379
  * @since 0.4.0
@@ -357,11 +387,42 @@ export interface Runtime<in Events, in Emits> {
357
387
  readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
358
388
 
359
389
  /**
360
- * Emits an event through the running machine's parent boundary.
390
+ * Publishes an ephemeral notification to the running actor's observers.
361
391
  *
362
392
  * @since 0.4.0
363
393
  */
364
- readonly sendParent: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
394
+ readonly emit: (
395
+ event: Machine.EmittedEventInput<Emits>
396
+ ) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
397
+ }
398
+
399
+ /**
400
+ * Minimal typed reference accepted by targeted actor commands.
401
+ *
402
+ * @category models
403
+ * @since 0.10.0
404
+ */
405
+ export interface ActorRef<in Event> {
406
+ readonly id: string
407
+ readonly sessionId: string
408
+ readonly send: (event: Event) => Effect.Effect<void, StoppedError>
409
+ }
410
+
411
+ /**
412
+ * Actor references available while evaluating machine behavior.
413
+ *
414
+ * @category models
415
+ * @since 0.10.0
416
+ */
417
+ export interface ActorContext<
418
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
419
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
420
+ > {
421
+ /** Reference to the current actor. Sending queues a later mailbox event. */
422
+ readonly self: ActorRef<Machine.EventInputOf<InputEvents>>
423
+
424
+ /** Reference to the owning actor, or `undefined` when running as a root. */
425
+ readonly parent: ActorRef<Machine.EventInputOf<ParentEvents>> | undefined
365
426
  }
366
427
 
367
428
  /**
@@ -376,11 +437,12 @@ export interface Enqueue<in Events, in Emits> {
376
437
  /** Raises an event inside the current macrostep. */
377
438
  readonly raise: (event: Machine.EventInput<Events>) => void
378
439
 
379
- /** Emits an event through the machine's parent boundary. */
380
- readonly emit: (event: Emits) => void
440
+ /** Publishes an ephemeral notification to this actor's observers. */
441
+ readonly emit: (event: Machine.EmittedEventInput<Emits>) => void
381
442
 
382
443
  /** Sends an event to an invoked child after the transition is selected. */
383
444
  readonly sendTo: {
445
+ <Event>(target: ActorRef<Event>, event: Event): void
384
446
  <Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): void
385
447
  <Address extends ChildAddress<never>>(child: Address, event: ChildAddress.Event<Address>): void
386
448
  }
@@ -401,7 +463,7 @@ export interface Enqueue<in Events, in Emits> {
401
463
  export type Command =
402
464
  | {
403
465
  readonly _tag: "SendTo"
404
- readonly child: ChildMachine.Any | ChildAddress<never>
466
+ readonly target: ActorRef<unknown> | ChildMachine.Any | ChildAddress<never>
405
467
  readonly event: unknown
406
468
  }
407
469
  | {
@@ -676,8 +738,9 @@ type DuplicateEventTag<
676
738
  : Events extends readonly [
677
739
  infer Head extends Machine.TaggedSchema,
678
740
  ...infer Tail extends ReadonlyArray<Machine.TaggedSchema>
679
- ] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Tag extends Seen ? Tag | DuplicateEventTag<Tail, Seen>
680
- : DuplicateEventTag<Tail, Seen | Tag>
741
+ ] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ?
742
+ | Extract<Tag, Seen>
743
+ | DuplicateEventTag<Tail, Seen | Tag>
681
744
  : never
682
745
  : never
683
746
 
@@ -687,6 +750,12 @@ type ValidateInputEventProtocol<
687
750
  > = [DuplicateInput] extends [never] ? unknown
688
751
  : EventProtocolError<"Public event tags must be unique", DuplicateInput>
689
752
 
753
+ type ValidateEmittedEventProtocol<
754
+ EmittedEvents extends ReadonlyArray<Machine.TaggedSchema>,
755
+ DuplicateEmitted extends PropertyKey = DuplicateEventTag<EmittedEvents>
756
+ > = [DuplicateEmitted] extends [never] ? unknown
757
+ : EventProtocolError<"Emitted event tags must be unique", DuplicateEmitted>
758
+
690
759
  type ValidateInternalEventProtocol<
691
760
  InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
692
761
  InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
@@ -699,6 +768,14 @@ type ValidateInternalEventProtocol<
699
768
  : EventProtocolError<"Public and internal event tags must be disjoint", Overlap>
700
769
  : EventProtocolError<"Internal event tags must be unique", DuplicateInternal>
701
770
 
771
+ type ValidateEventProtocolBuilder<
772
+ Kind extends Machine.EventProtocolKind,
773
+ Inputs extends ReadonlyArray<Machine.EventProtocolInput<Kind>>,
774
+ Schemas extends ReadonlyArray<Machine.TaggedSchema> = Machine.EventProtocolInputSchemasOf<Kind, Inputs>,
775
+ Duplicate extends PropertyKey = DuplicateEventTag<Schemas>
776
+ > = [Duplicate] extends [never] ? unknown
777
+ : EventProtocolError<"Event protocol tags must be unique", Duplicate>
778
+
702
779
  const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId = internal.SnapshotBuilderStateTypeId
703
780
  const SnapshotBuilderConstructionTypeId: unique symbol = Symbol("effect/Machine/SnapshotBuilderConstruction")
704
781
 
@@ -1626,6 +1703,33 @@ export type RuntimeOutcome<State, Error = never, Output = never> =
1626
1703
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "stopped" }>
1627
1704
  }
1628
1705
 
1706
+ /**
1707
+ * A fresh machine whose observable streams exist before initialization.
1708
+ *
1709
+ * Subscribe to `emissions` before evaluating `start` when initial-entry
1710
+ * emissions must be observed. `start` is one-shot: concurrent and repeated
1711
+ * evaluations share the same initialization and running reference.
1712
+ *
1713
+ * @category models
1714
+ * @since 0.11.0
1715
+ */
1716
+ export interface Prepared<out State, in Event, out Error, out Output, out Emitted, out StartError, StartRequirements> {
1717
+ /** Stable machine definition id, or a generated fallback when none was declared. */
1718
+ readonly id: string
1719
+
1720
+ /** Unique identity reserved for this prepared machine instance. */
1721
+ readonly sessionId: string
1722
+
1723
+ /** Waits for startup, then streams the initial lifecycle snapshot and later changes. */
1724
+ readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>, StartError>
1725
+
1726
+ /** Streams ephemeral notifications published after subscription. */
1727
+ readonly emissions: Stream.Stream<Emitted>
1728
+
1729
+ /** Initializes this machine once and returns its running reference. */
1730
+ readonly start: Effect.Effect<MachineRef<State, Event, Error, Output, Emitted>, StartError, StartRequirements>
1731
+ }
1732
+
1629
1733
  /**
1630
1734
  * Provides access to a running machine's state, lifecycle, event input, and
1631
1735
  * termination operations.
@@ -1640,7 +1744,9 @@ export type RuntimeOutcome<State, Error = never, Output = never> =
1640
1744
  * @category models
1641
1745
  * @since 0.4.0
1642
1746
  */
1643
- export interface MachineRef<out State, in Event, out Error = never, out Output = never> {
1747
+ export interface MachineRef<out State, in Event, out Error = never, out Output = never, out Emitted = never>
1748
+ extends ActorRef<Event>
1749
+ {
1644
1750
  /** Stable machine definition id, or a generated fallback when none was declared. */
1645
1751
  readonly id: string
1646
1752
 
@@ -1653,9 +1759,15 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
1653
1759
  /** Reads the latest lifecycle snapshot. */
1654
1760
  readonly snapshot: Effect.Effect<RuntimeSnapshot<State, Error, Output>>
1655
1761
 
1656
- /** Streams lifecycle snapshots published after subscription. */
1762
+ /** Streams the current lifecycle snapshot followed by later changes. */
1657
1763
  readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>>
1658
1764
 
1765
+ /**
1766
+ * Streams ephemeral notifications published after subscription. Emissions
1767
+ * are not retained or replayed; the stream completes when the actor stops.
1768
+ */
1769
+ readonly emissions: Stream.Stream<Emitted>
1770
+
1659
1771
  /** Waits for machine output or fails when execution fails or is stopped. */
1660
1772
  readonly join: Effect.Effect<Output, Error | StoppedError>
1661
1773
 
@@ -1767,13 +1879,6 @@ export declare namespace Logic {
1767
1879
  /**
1768
1880
  * Machine-local capabilities available while process logic initializes.
1769
1881
  *
1770
- * **Gotchas**
1771
- *
1772
- * `sendParent` accepts `unknown` because process logic is independent from
1773
- * the parent that eventually owns it. Prefer typed process output or an
1774
- * invocation lifecycle transition when either can represent the
1775
- * communication.
1776
- *
1777
1882
  * @category models
1778
1883
  * @since 0.4.0
1779
1884
  */
@@ -1787,14 +1892,14 @@ export declare namespace Logic {
1787
1892
  /** Starts a child process owned by this scope. */
1788
1893
  readonly spawn: Spawn
1789
1894
 
1790
- /** Sends an untyped event to the owning process. */
1791
- readonly sendParent: (event: unknown) => Effect.Effect<void, StoppedError>
1792
-
1793
- /** Sends an event through a typed parent-local child address. */
1794
- readonly sendTo: <Address extends ChildAddress<never>>(
1795
- id: Address,
1796
- event: ChildAddress.Event<Address>
1797
- ) => Effect.Effect<void, StoppedError>
1895
+ /** Sends an event to an actor reference or typed parent-local child address. */
1896
+ readonly sendTo: {
1897
+ <TargetEvent>(target: ActorRef<TargetEvent>, event: TargetEvent): Effect.Effect<void, StoppedError>
1898
+ <Address extends ChildAddress<never>>(
1899
+ id: Address,
1900
+ event: ChildAddress.Event<Address>
1901
+ ): Effect.Effect<void, StoppedError>
1902
+ }
1798
1903
 
1799
1904
  /** Stops a child process selected by its parent-local address. */
1800
1905
  readonly stopChild: <Event>(id: ChildAddress<Event>) => Effect.Effect<void>
@@ -1883,7 +1988,8 @@ export declare namespace ChildMachine {
1883
1988
  | InfiniteTransitionError
1884
1989
  | MachineSchemaDecodeError
1885
1990
  | StoppedError,
1886
- Machine.Output<M>
1991
+ Machine.Output<M>,
1992
+ Machine.EmittedEvent<M>
1887
1993
  >
1888
1994
  : never
1889
1995
 
@@ -1893,7 +1999,8 @@ export declare namespace ChildMachine {
1893
1999
  * @category utility types
1894
2000
  * @since 0.4.0
1895
2001
  */
1896
- export type Event<Child> = Ref<Child> extends MachineRef<any, infer Event, any, any> ? Event : never
2002
+ export type Event<Child> = Child extends ChildMachine<string, infer M> ? Machine.EventInput<Machine.InputEvent<M>>
2003
+ : never
1897
2004
  }
1898
2005
 
1899
2006
  /**
@@ -2006,7 +2113,8 @@ export declare namespace Machine {
2006
2113
  Output,
2007
2114
  Emits extends ReadonlyArray<TaggedSchema>,
2008
2115
  OutputStates extends StateIdentifier<States>,
2009
- InputEvents extends ReadonlyArray<TaggedSchema>
2116
+ InputEvents extends ReadonlyArray<TaggedSchema>,
2117
+ ParentEvents extends ReadonlyArray<TaggedSchema>
2010
2118
  > {
2011
2119
  readonly states: States
2012
2120
  readonly events: Events
@@ -2018,9 +2126,10 @@ export declare namespace Machine {
2018
2126
  readonly initialServices: InitialR
2019
2127
  readonly finalStates: FinalStates
2020
2128
  readonly output: Output
2021
- readonly emits: Emits
2129
+ readonly emittedEvents: Emits
2022
2130
  readonly outputStates: OutputStates
2023
2131
  readonly inputEvents: InputEvents
2132
+ readonly parentEvents: ParentEvents
2024
2133
  }
2025
2134
 
2026
2135
  /**
@@ -2038,11 +2147,12 @@ export declare namespace Machine {
2038
2147
  export interface Any extends Pipeable {
2039
2148
  readonly [TypeId]: TypeId
2040
2149
  /** @internal */
2041
- readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any>
2150
+ readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any, any>
2042
2151
  readonly states: StateSchemas
2043
- readonly events: ReadonlyArray<TaggedSchema>
2044
- readonly internalEvents: ReadonlyArray<TaggedSchema>
2045
- readonly emits: ReadonlyArray<TaggedSchema>
2152
+ readonly events: EventProtocol.Any<"public">
2153
+ readonly internalEvents: EventProtocol.Any<"internal">
2154
+ readonly emittedEvents: EventProtocol.Any<"emitted">
2155
+ readonly parentEvents: EventProtocol.Any<"public">
2046
2156
  readonly input: Schema.Top | undefined
2047
2157
  readonly id: string | undefined
2048
2158
  /** @internal */
@@ -2054,6 +2164,8 @@ export declare namespace Machine {
2054
2164
  /** @internal */
2055
2165
  readonly handle: any
2056
2166
  /** @internal */
2167
+ readonly invoke: any
2168
+ /** @internal */
2057
2169
  readonly initial: any
2058
2170
  }
2059
2171
 
@@ -2143,7 +2255,10 @@ export declare namespace Machine {
2143
2255
  * @category utility types
2144
2256
  * @since 0.4.0
2145
2257
  */
2146
- export type Emits<M extends Any> = M[typeof MachineTypeId]["emits"]
2258
+ export type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"]
2259
+
2260
+ /** @deprecated Use {@link EmittedEvents}. */
2261
+ export type Emits<M extends Any> = EmittedEvents<M>
2147
2262
 
2148
2263
  /**
2149
2264
  * Extracts state paths with implemented output handlers.
@@ -2161,13 +2276,22 @@ export declare namespace Machine {
2161
2276
  */
2162
2277
  export type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"]
2163
2278
 
2164
- /** Extracts the internal event schema tuple carried by a machine definition. */
2165
- export type InternalEvents<M extends Any> = Events<M> extends readonly [
2166
- ...InputEvents<M>,
2279
+ /** Extracts the public input protocol required from an owning actor. */
2280
+ export type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"]
2281
+
2282
+ /** Extracts an internal event schema tuple from the complete and public protocols. */
2283
+ export type InternalEventSchemas<
2284
+ Events extends ReadonlyArray<TaggedSchema>,
2285
+ InputEvents extends ReadonlyArray<TaggedSchema>
2286
+ > = Events extends readonly [
2287
+ ...InputEvents,
2167
2288
  ...infer Internal extends ReadonlyArray<TaggedSchema>
2168
- ] ? Internal
2289
+ ] ? readonly [...Internal]
2169
2290
  : readonly []
2170
2291
 
2292
+ /** Extracts the internal event schema tuple carried by a machine definition. */
2293
+ export type InternalEvents<M extends Any> = InternalEventSchemas<Events<M>, InputEvents<M>>
2294
+
2171
2295
  /**
2172
2296
  * Extracts the complete event protocol handled inside a machine.
2173
2297
  *
@@ -2196,48 +2320,133 @@ export declare namespace Machine {
2196
2320
  readonly _tag: Event["_tag"]
2197
2321
  }
2198
2322
 
2323
+ /** Opaque construction returned by {@link emittedEvents}. */
2324
+ export interface EmittedEventConstruction<out Event extends { readonly _tag: PropertyKey }> {
2325
+ readonly [EmittedEventConstructionTypeId]: Event
2326
+ readonly _tag: Event["_tag"]
2327
+ }
2328
+
2199
2329
  /** A decoded event or a deferred machine-bound construction of that event. */
2200
2330
  export type EventInput<Event> =
2201
2331
  | Event
2202
2332
  | (Event extends { readonly _tag: PropertyKey } ? EventConstruction<Event> : never)
2203
2333
 
2334
+ /** A decoded emitted event or a deferred emitted-event construction. */
2335
+ export type EmittedEventInput<Event> =
2336
+ | Event
2337
+ | (Event extends { readonly _tag: PropertyKey } ? EmittedEventConstruction<Event> : never)
2338
+
2204
2339
  /** Event inputs accepted for a schema tuple at machine delivery boundaries. */
2205
2340
  export type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>
2206
2341
 
2342
+ /** Identifies whether an event protocol is accepted publicly or only inside a machine. */
2343
+ export type EventProtocolKind = "public" | "internal" | "emitted"
2344
+
2207
2345
  type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">
2208
2346
 
2209
2347
  type EventConstructor<
2210
2348
  EventSchema extends TaggedSchema,
2211
- Tag extends EventSchema["Type"]["_tag"]
2212
- > = {} extends EventConstructorInput<EventSchema> ?
2213
- (input?: EventConstructorInput<EventSchema>) => EventConstruction<EventByTag<readonly [EventSchema], Tag>>
2214
- : (input: EventConstructorInput<EventSchema>) => EventConstruction<EventByTag<readonly [EventSchema], Tag>>
2215
-
2216
- type EventConstructorsForSchema<EventSchema extends TaggedSchema> = EventSchema extends {
2349
+ Tag extends EventSchema["Type"]["_tag"],
2350
+ Kind extends EventProtocolKind
2351
+ > = {} extends EventConstructorInput<EventSchema> ? (
2352
+ input?: EventConstructorInput<EventSchema>
2353
+ ) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>>
2354
+ : EventConstruction<EventByTag<readonly [EventSchema], Tag>>
2355
+ : (
2356
+ input: EventConstructorInput<EventSchema>
2357
+ ) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>>
2358
+ : EventConstruction<EventByTag<readonly [EventSchema], Tag>>
2359
+
2360
+ type FiniteEventTag<Tag extends PropertyKey> = string extends Tag ? never
2361
+ : number extends Tag ? never
2362
+ : symbol extends Tag ? never
2363
+ : Tag
2364
+
2365
+ type EventConstructorsForSchema<
2366
+ EventSchema extends TaggedSchema,
2367
+ Kind extends EventProtocolKind
2368
+ > = EventSchema extends {
2217
2369
  readonly cases: infer Cases extends Readonly<Record<PropertyKey, TaggedSchema>>
2218
2370
  } ? {
2219
- readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag>
2371
+ readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag, Kind>
2220
2372
  : never
2221
2373
  }
2222
2374
  : EventSchema extends { readonly members: infer Members extends ReadonlyArray<TaggedSchema> } ?
2223
- Types.UnionToIntersection<EventConstructorsForSchema<Members[number]>>
2375
+ Types.UnionToIntersection<EventConstructorsForSchema<Members[number], Kind>>
2224
2376
  : {
2225
- readonly [Tag in EventSchema["Type"]["_tag"]]: EventConstructor<EventSchema, Tag>
2377
+ readonly [Tag in FiniteEventTag<EventSchema["Type"]["_tag"]>]: EventConstructor<EventSchema, Tag, Kind>
2226
2378
  }
2227
2379
 
2228
2380
  /** Protocol-bound constructors keyed by each configured event tag. */
2229
- export type EventConstructors<Events extends ReadonlyArray<TaggedSchema>> = {
2230
- readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number]>>]:
2231
- Types.UnionToIntersection<EventConstructorsForSchema<Events[number]>>[Tag]
2381
+ export type EventConstructors<
2382
+ Events extends ReadonlyArray<TaggedSchema>,
2383
+ Kind extends EventProtocolKind = "public"
2384
+ > = {
2385
+ readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>]:
2386
+ Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>[Tag]
2387
+ }
2388
+
2389
+ /**
2390
+ * A schema-backed event protocol exposing only deferred event constructors.
2391
+ *
2392
+ * The schema tuple is retained opaquely for machine runtime validation and
2393
+ * type inference. It is not exposed as a runtime property.
2394
+ *
2395
+ * @since 0.10.0
2396
+ */
2397
+ export type EventProtocol<
2398
+ Kind extends EventProtocolKind,
2399
+ Schemas extends ReadonlyArray<TaggedSchema>
2400
+ > = EventConstructors<Schemas, Kind> & {
2401
+ readonly [EventProtocolTypeId]: {
2402
+ readonly kind: Kind
2403
+ readonly schemas: Schemas
2404
+ }
2405
+ }
2406
+
2407
+ export namespace EventProtocol {
2408
+ /** An erased event protocol descriptor retaining its kind and schema carrier. */
2409
+ export interface Any<Kind extends EventProtocolKind = EventProtocolKind> {
2410
+ readonly [EventProtocolTypeId]: {
2411
+ readonly kind: Kind
2412
+ readonly schemas: ReadonlyArray<TaggedSchema>
2413
+ }
2414
+ }
2232
2415
  }
2233
2416
 
2417
+ /** A schema or an existing protocol accepted by an event builder. */
2418
+ export type EventProtocolInput<Kind extends EventProtocolKind> = TaggedSchema | EventProtocol.Any<Kind>
2419
+
2420
+ type EventProtocolInputSchemas<
2421
+ Kind extends EventProtocolKind,
2422
+ Input extends EventProtocolInput<Kind>
2423
+ > = Input extends EventProtocol<Kind, infer Schemas> ? Schemas
2424
+ : Input extends TaggedSchema ? readonly [Input]
2425
+ : readonly []
2426
+
2427
+ /** Flattens schema and protocol inputs into one owned schema tuple. */
2428
+ export type EventProtocolInputSchemasOf<
2429
+ Kind extends EventProtocolKind,
2430
+ Inputs extends ReadonlyArray<EventProtocolInput<Kind>>
2431
+ > = Inputs extends readonly [
2432
+ infer Head extends EventProtocolInput<Kind>,
2433
+ ...infer Tail extends ReadonlyArray<EventProtocolInput<Kind>>
2434
+ ] ? readonly [...EventProtocolInputSchemas<Kind, Head>, ...EventProtocolInputSchemasOf<Kind, Tail>]
2435
+ : readonly []
2436
+
2437
+ /** @internal Extracts the schema tuple carried opaquely by an event protocol. */
2438
+ export type EventProtocolSchemas<Protocol extends EventProtocol.Any> = Protocol[typeof EventProtocolTypeId]["schemas"]
2439
+
2234
2440
  /**
2235
2441
  * Extracts the event protocol emitted by a machine.
2236
2442
  *
2237
2443
  * @category utility types
2238
2444
  * @since 0.4.0
2239
2445
  */
2240
- export type Emit<M extends Any> = EmitOf<Emits<M>>
2446
+ export type EmittedEvent<M extends Any> = EmittedEventOf<Emits<M>>
2447
+
2448
+ /** @deprecated Use {@link EmittedEvent}. */
2449
+ export type Emit<M extends Any> = EmittedEvent<M>
2241
2450
 
2242
2451
  /**
2243
2452
  * A schema whose decoded value contains a `_tag` discriminator.
@@ -3025,7 +3234,10 @@ export declare namespace Machine {
3025
3234
  * @category utility types
3026
3235
  * @since 0.4.0
3027
3236
  */
3028
- export type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"]
3237
+ export type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"]
3238
+
3239
+ /** @deprecated Use {@link EmittedEventOf}. */
3240
+ export type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = EmittedEventOf<Emits>
3029
3241
 
3030
3242
  /**
3031
3243
  * Event values received by lifecycle callbacks.
@@ -3597,6 +3809,21 @@ export declare namespace Machine {
3597
3809
  >
3598
3810
  }
3599
3811
 
3812
+ /**
3813
+ * Opaque result returned by an explicitly targetless transition.
3814
+ *
3815
+ * The transition remains handled and retains its queued commands, raised
3816
+ * events, and emitted events, but selects no concrete destination. Declared
3817
+ * `targets` constrain only concrete destinations, so this result is always
3818
+ * permitted from ordinary transition handlers.
3819
+ *
3820
+ * @category models
3821
+ * @since 0.10.0
3822
+ */
3823
+ export interface NoTarget {
3824
+ readonly [Topology.NoTargetTypeId]: typeof Topology.NoTargetTypeId
3825
+ }
3826
+
3600
3827
  /**
3601
3828
  * Transition instruction that restores a history pseudo-state's parent.
3602
3829
  *
@@ -3703,9 +3930,9 @@ export declare namespace Machine {
3703
3930
  *
3704
3931
  * **Details**
3705
3932
  *
3706
- * `local` targets the nearest compound scope for the source state, `branch`
3707
- * targets descendants of the source root, and `full` builds complete
3708
- * snapshots for any root.
3933
+ * `none()` handles without selecting a destination, `local` targets the
3934
+ * nearest compound scope for the source state, `branch` targets descendants
3935
+ * of the source root, and `full` builds complete snapshots for any root.
3709
3936
  *
3710
3937
  * These builders control how the next active configuration is assembled; they
3711
3938
  * do not directly control state re-entry. Exit and entry paths are derived
@@ -3721,6 +3948,18 @@ export declare namespace Machine {
3721
3948
  States extends StateSchemas,
3722
3949
  Source extends StateNodeIdentifier<States>
3723
3950
  > {
3951
+ /**
3952
+ * Selects an explicitly targetless transition.
3953
+ *
3954
+ * The event or lifecycle outcome is handled and queued operations are
3955
+ * retained, while the current state configuration remains the transition
3956
+ * result. This remains valid when the handler declares concrete `targets`,
3957
+ * because those paths are an upper bound rather than an exhaustive result.
3958
+ *
3959
+ * @since 0.10.0
3960
+ */
3961
+ readonly none: () => NoTarget
3962
+
3724
3963
  /**
3725
3964
  * Moves to another state in the same local group. The value of the state
3726
3965
  * containing that group, and values in other active branches, are kept.
@@ -3769,11 +4008,13 @@ export declare namespace Machine {
3769
4008
  StateId extends StateIdentifier<States>,
3770
4009
  EventTag extends TagOf<Events[number]>,
3771
4010
  E,
3772
- R
3773
- > {
4011
+ R,
4012
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4013
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4014
+ > extends ActorContext<InputEvents, ParentEvents> {
3774
4015
  readonly state: StateByIdentifier<States, StateId>
3775
- readonly parent: ParentStateValue<States, StateId>
3776
- readonly parents: ParentStateValues<States, StateId>
4016
+ readonly containingState: ParentStateValue<States, StateId>
4017
+ readonly ancestors: ParentStateValues<States, StateId>
3777
4018
  /** Complete logical configuration captured at the start of this microstep. */
3778
4019
  readonly snapshot: Snapshot<States>
3779
4020
  readonly event: EventByTag<Events, EventTag>
@@ -3797,11 +4038,13 @@ export declare namespace Machine {
3797
4038
  States extends StateSchemas,
3798
4039
  Events extends ReadonlyArray<TaggedSchema>,
3799
4040
  Emits extends ReadonlyArray<TaggedSchema>,
3800
- StateId extends StateIdentifier<States>
3801
- > {
4041
+ StateId extends StateIdentifier<States>,
4042
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4043
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4044
+ > extends ActorContext<InputEvents, ParentEvents> {
3802
4045
  readonly state: StateByIdentifier<States, StateId>
3803
- readonly parent: ParentStateValue<States, StateId>
3804
- readonly parents: ParentStateValues<States, StateId>
4046
+ readonly containingState: ParentStateValue<States, StateId>
4047
+ readonly ancestors: ParentStateValues<States, StateId>
3805
4048
  readonly event: LifecycleEvent<Events>
3806
4049
  }
3807
4050
 
@@ -3815,11 +4058,13 @@ export declare namespace Machine {
3815
4058
  States extends StateSchemas,
3816
4059
  Events extends ReadonlyArray<TaggedSchema>,
3817
4060
  Emits extends ReadonlyArray<TaggedSchema>,
3818
- StateId extends StateIdentifier<States>
3819
- > {
4061
+ StateId extends StateIdentifier<States>,
4062
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4063
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4064
+ > extends ActorContext<InputEvents, ParentEvents> {
3820
4065
  readonly state: StateByIdentifier<States, StateId>
3821
- readonly parent: ParentStateValue<States, StateId>
3822
- readonly parents: ParentStateValues<States, StateId>
4066
+ readonly containingState: ParentStateValue<States, StateId>
4067
+ readonly ancestors: ParentStateValues<States, StateId>
3823
4068
  readonly event: LifecycleEvent<Events>
3824
4069
  }
3825
4070
 
@@ -3836,12 +4081,14 @@ export declare namespace Machine {
3836
4081
  StateId extends StateIdentifier<States>,
3837
4082
  State,
3838
4083
  Error,
3839
- Output
3840
- > {
4084
+ Output,
4085
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4086
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4087
+ > extends ActorContext<InputEvents, ParentEvents> {
3841
4088
  readonly id: string
3842
4089
  readonly state: StateByIdentifier<States, StateId>
3843
- readonly parent: ParentStateValue<States, StateId>
3844
- readonly parents: ParentStateValues<States, StateId>
4090
+ readonly containingState: ParentStateValue<States, StateId>
4091
+ readonly ancestors: ParentStateValues<States, StateId>
3845
4092
  readonly target: TargetBuilder<States, StateId>
3846
4093
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "active" }>
3847
4094
  }
@@ -3857,12 +4104,14 @@ export declare namespace Machine {
3857
4104
  Events extends ReadonlyArray<TaggedSchema>,
3858
4105
  Emits extends ReadonlyArray<TaggedSchema>,
3859
4106
  StateId extends StateIdentifier<States>,
3860
- Output
3861
- > {
4107
+ Output,
4108
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4109
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4110
+ > extends ActorContext<InputEvents, ParentEvents> {
3862
4111
  readonly id: string
3863
4112
  readonly state: StateByIdentifier<States, StateId>
3864
- readonly parent: ParentStateValue<States, StateId>
3865
- readonly parents: ParentStateValues<States, StateId>
4113
+ readonly containingState: ParentStateValue<States, StateId>
4114
+ readonly ancestors: ParentStateValues<States, StateId>
3866
4115
  readonly snapshot: Snapshot<States>
3867
4116
  readonly target: TargetBuilder<States, StateId>
3868
4117
  readonly output: Output
@@ -3874,12 +4123,14 @@ export declare namespace Machine {
3874
4123
  Events extends ReadonlyArray<TaggedSchema>,
3875
4124
  Emits extends ReadonlyArray<TaggedSchema>,
3876
4125
  StateId extends StateIdentifier<States>,
3877
- Error
3878
- > {
4126
+ Error,
4127
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4128
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4129
+ > extends ActorContext<InputEvents, ParentEvents> {
3879
4130
  readonly id: string
3880
4131
  readonly state: StateByIdentifier<States, StateId>
3881
- readonly parent: ParentStateValue<States, StateId>
3882
- readonly parents: ParentStateValues<States, StateId>
4132
+ readonly containingState: ParentStateValue<States, StateId>
4133
+ readonly ancestors: ParentStateValues<States, StateId>
3883
4134
  readonly snapshot: Snapshot<States>
3884
4135
  readonly target: TargetBuilder<States, StateId>
3885
4136
  readonly error: Error
@@ -3895,11 +4146,13 @@ export declare namespace Machine {
3895
4146
  States extends StateSchemas,
3896
4147
  Events extends ReadonlyArray<TaggedSchema>,
3897
4148
  Emits extends ReadonlyArray<TaggedSchema>,
3898
- StateId extends StateIdentifier<States>
3899
- > {
4149
+ StateId extends StateIdentifier<States>,
4150
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4151
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4152
+ > extends ActorContext<InputEvents, ParentEvents> {
3900
4153
  readonly state: StateByIdentifier<States, StateId>
3901
- readonly parent: ParentStateValue<States, StateId>
3902
- readonly parents: ParentStateValues<States, StateId>
4154
+ readonly containingState: ParentStateValue<States, StateId>
4155
+ readonly ancestors: ParentStateValues<States, StateId>
3903
4156
  /** Complete logical configuration captured at the start of this microstep. */
3904
4157
  readonly snapshot: Snapshot<States>
3905
4158
  readonly event: LifecycleEvent<Events>
@@ -3924,11 +4177,13 @@ export declare namespace Machine {
3924
4177
  States extends StateSchemas,
3925
4178
  Events extends ReadonlyArray<TaggedSchema>,
3926
4179
  Emits extends ReadonlyArray<TaggedSchema>,
3927
- StateId extends StateIdentifier<States>
3928
- > {
4180
+ StateId extends StateIdentifier<States>,
4181
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4182
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4183
+ > extends ActorContext<InputEvents, ParentEvents> {
3929
4184
  readonly state: StateByIdentifier<States, StateId>
3930
- readonly parent: ParentStateValue<States, StateId>
3931
- readonly parents: ParentStateValues<States, StateId>
4185
+ readonly containingState: ParentStateValue<States, StateId>
4186
+ readonly ancestors: ParentStateValues<States, StateId>
3932
4187
  /** Complete logical configuration captured at the start of this microstep. */
3933
4188
  readonly snapshot: Snapshot<States>
3934
4189
  readonly event: LifecycleEvent<Events>
@@ -3949,13 +4204,15 @@ export declare namespace Machine {
3949
4204
  States extends StateSchemas,
3950
4205
  Events extends ReadonlyArray<TaggedSchema>,
3951
4206
  Emits extends ReadonlyArray<TaggedSchema>,
3952
- ChoiceId extends ChoiceIdentifier<States>
3953
- > {
3954
- readonly parent: StateByIdentifier<
4207
+ ChoiceId extends ChoiceIdentifier<States>,
4208
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4209
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4210
+ > extends ActorContext<InputEvents, ParentEvents> {
4211
+ readonly containingState: StateByIdentifier<
3955
4212
  States,
3956
4213
  Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>
3957
4214
  >
3958
- readonly parents: {
4215
+ readonly ancestors: {
3959
4216
  readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<
3960
4217
  States,
3961
4218
  Parent
@@ -3977,8 +4234,8 @@ export declare namespace Machine {
3977
4234
  StateId extends StateIdentifier<States>
3978
4235
  > {
3979
4236
  readonly state: StateByIdentifier<States, StateId>
3980
- readonly parent: ParentStateValue<States, StateId>
3981
- readonly parents: ParentStateValues<States, StateId>
4237
+ readonly containingState: ParentStateValue<States, StateId>
4238
+ readonly ancestors: ParentStateValues<States, StateId>
3982
4239
  readonly event: LifecycleEvent<Events>
3983
4240
  }
3984
4241
 
@@ -4012,8 +4269,8 @@ export declare namespace Machine {
4012
4269
  StateId extends StateIdentifier<States>
4013
4270
  > {
4014
4271
  readonly state: StateByIdentifier<States, StateId>
4015
- readonly parent: ParentStateValue<States, StateId>
4016
- readonly parents: ParentStateValues<States, StateId>
4272
+ readonly containingState: ParentStateValue<States, StateId>
4273
+ readonly ancestors: ParentStateValues<States, StateId>
4017
4274
  readonly event: LifecycleEvent<Events>
4018
4275
  readonly outputs: ParallelOutputRegions<States, StateId>
4019
4276
  }
@@ -4047,9 +4304,10 @@ export declare namespace Machine {
4047
4304
  *
4048
4305
  * **Details**
4049
4306
  *
4050
- * Handlers return snapshots for complete state replacement or target builder
4051
- * results for path-safe partial transitions. Raw decoded state values are not
4052
- * accepted at transition boundaries.
4307
+ * Handlers return snapshots for complete state replacement, target builder
4308
+ * results for path-safe partial transitions, or `target.none()` for an
4309
+ * explicitly targetless transition. Raw decoded state values and `void` are
4310
+ * not accepted at transition boundaries.
4053
4311
  *
4054
4312
  * @category utility types
4055
4313
  * @since 0.4.0
@@ -4065,7 +4323,7 @@ export declare namespace Machine {
4065
4323
  | HistoryTarget<States, HistoryIdentifier<States>>
4066
4324
  | ChoiceTarget<States, ChoiceIdentifier<States>>
4067
4325
  >
4068
- | void
4326
+ | NoTarget
4069
4327
 
4070
4328
  /** A choice resolver must always select a typed target synchronously. */
4071
4329
  export type ChoiceResult<States extends StateSchemas, E, R> =
@@ -4264,6 +4522,14 @@ export declare namespace Machine {
4264
4522
  } ? Emitted
4265
4523
  : Invoke extends { readonly child: ChildMachine<string, infer M> } ? Emit<M>
4266
4524
  : never
4525
+
4526
+ /** Public parent inputs required by an invoked child machine. */
4527
+ export type InvokeParentEvents<Invoke> = Invoke extends {
4528
+ readonly [InvokeTypeId]: { readonly parentEvents: Types.Covariant<infer ParentEvent> }
4529
+ } ? ParentEvent
4530
+ : IsAny<Invoke> extends true ? never
4531
+ : Invoke extends { readonly child: ChildMachine<string, infer M> } ? EventOf<ParentEvents<M>>
4532
+ : never
4267
4533
  /** Extracts transition results returned by invocation lifecycle handlers. */
4268
4534
  export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ?
4269
4535
  | (Invoke extends { readonly onDone?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
@@ -4373,13 +4639,14 @@ export declare namespace Machine {
4373
4639
  }
4374
4640
 
4375
4641
  /** Type evidence retained by {@link invoke} without affecting runtime data. */
4376
- export interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never> {
4642
+ export interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never> {
4377
4643
  readonly [InvokeTypeId]: {
4378
4644
  readonly output: Types.Covariant<Output>
4379
4645
  readonly error: Types.Covariant<Error>
4380
4646
  readonly requirements: Types.Covariant<Requirements>
4381
4647
  readonly initialError: Types.Covariant<InitialError>
4382
4648
  readonly emits: Types.Covariant<Emits>
4649
+ readonly parentEvents: Types.Covariant<ParentEvent>
4383
4650
  }
4384
4651
  }
4385
4652
 
@@ -4387,13 +4654,18 @@ export declare namespace Machine {
4387
4654
  States extends StateSchemas,
4388
4655
  Events extends ReadonlyArray<TaggedSchema>,
4389
4656
  Emits extends ReadonlyArray<TaggedSchema>,
4390
- StateId extends StateIdentifier<States>
4657
+ StateId extends StateIdentifier<States>,
4658
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4659
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4391
4660
  > =
4392
4661
  & InvokeOwned<States, Events, Emits, StateId>
4393
4662
  & (
4394
4663
  | {
4395
4664
  readonly id: string
4396
- readonly effect: InvokeSource<Effect.Effect<any, any, any>, InvokeContext<States, Events, Emits, StateId>>
4665
+ readonly effect: InvokeSource<
4666
+ Effect.Effect<any, any, any>,
4667
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4668
+ >
4397
4669
  readonly after?: never
4398
4670
  readonly logic?: never
4399
4671
  readonly child?: never
@@ -4404,7 +4676,10 @@ export declare namespace Machine {
4404
4676
  }
4405
4677
  | {
4406
4678
  readonly id: string
4407
- readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>
4679
+ readonly after: InvokeSource<
4680
+ Duration.Input,
4681
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4682
+ >
4408
4683
  readonly effect?: never
4409
4684
  readonly logic?: never
4410
4685
  readonly child?: never
@@ -4416,7 +4691,10 @@ export declare namespace Machine {
4416
4691
  | {
4417
4692
  readonly id: string
4418
4693
  readonly address: string
4419
- readonly logic: InvokeSource<AnyLogicSource, InvokeContext<States, Events, Emits, StateId>>
4694
+ readonly logic: InvokeSource<
4695
+ AnyLogicSource,
4696
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4697
+ >
4420
4698
  readonly effect?: never
4421
4699
  readonly after?: never
4422
4700
  readonly child?: never
@@ -4426,7 +4704,10 @@ export declare namespace Machine {
4426
4704
  }
4427
4705
  | {
4428
4706
  readonly child: ChildMachine.Any
4429
- readonly input?: {} | null | ((context: InvokeContext<States, Events, Emits, StateId>) => unknown)
4707
+ readonly input?:
4708
+ | {}
4709
+ | null
4710
+ | ((context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown)
4430
4711
  readonly id?: never
4431
4712
  readonly address?: never
4432
4713
  readonly effect?: never
@@ -4443,10 +4724,16 @@ export declare namespace Machine {
4443
4724
  States extends StateSchemas,
4444
4725
  Events extends ReadonlyArray<TaggedSchema>,
4445
4726
  Emits extends ReadonlyArray<TaggedSchema>,
4446
- StateId extends StateIdentifier<States>
4727
+ StateId extends StateIdentifier<States>,
4728
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4729
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4447
4730
  > =
4448
- | InvokeConfig<States, Events, Emits, StateId>
4449
- | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId>>
4731
+ | InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
4732
+ | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>
4733
+
4734
+ type TypedInvokeDefinition =
4735
+ | InvokeTyped<any, any, any, any, any, any>
4736
+ | ReadonlyArray<InvokeTyped<any, any, any, any, any, any>>
4450
4737
 
4451
4738
  type InvokeHandlerRequirement<Value, Handler> = IsAny<Value> extends true ? { readonly handler: Handler }
4452
4739
  : [Value] extends [never] ? { readonly handler?: never }
@@ -4468,7 +4755,9 @@ export declare namespace Machine {
4468
4755
  Emits extends ReadonlyArray<TaggedSchema>,
4469
4756
  StateId extends StateIdentifier<States>,
4470
4757
  Fx extends Effect.Effect<any, any, any>,
4471
- Source = Fx
4758
+ Source = Fx,
4759
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4760
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4472
4761
  > =
4473
4762
  & {
4474
4763
  readonly id: InvokeLifecycleId
@@ -4485,7 +4774,15 @@ export declare namespace Machine {
4485
4774
  States,
4486
4775
  Events,
4487
4776
  Emits,
4488
- InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<NoInfer<Fx>>>
4777
+ InvokeDoneContext<
4778
+ States,
4779
+ Events,
4780
+ Emits,
4781
+ StateId,
4782
+ Effect.Success<NoInfer<Fx>>,
4783
+ InputEvents,
4784
+ ParentEvents
4785
+ >
4489
4786
  >
4490
4787
  >
4491
4788
  & InvokeFailureRequirement<
@@ -4494,7 +4791,15 @@ export declare namespace Machine {
4494
4791
  States,
4495
4792
  Events,
4496
4793
  Emits,
4497
- InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<NoInfer<Fx>>>
4794
+ InvokeFailureContext<
4795
+ States,
4796
+ Events,
4797
+ Emits,
4798
+ StateId,
4799
+ Effect.Error<NoInfer<Fx>>,
4800
+ InputEvents,
4801
+ ParentEvents
4802
+ >
4498
4803
  >
4499
4804
  >
4500
4805
 
@@ -4502,10 +4807,15 @@ export declare namespace Machine {
4502
4807
  States extends StateSchemas,
4503
4808
  Events extends ReadonlyArray<TaggedSchema>,
4504
4809
  Emits extends ReadonlyArray<TaggedSchema>,
4505
- StateId extends StateIdentifier<States>
4810
+ StateId extends StateIdentifier<States>,
4811
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4812
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4506
4813
  > = {
4507
4814
  readonly id: InvokeLifecycleId
4508
- readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>
4815
+ readonly after: InvokeSource<
4816
+ Duration.Input,
4817
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4818
+ >
4509
4819
  readonly effect?: never
4510
4820
  readonly logic?: never
4511
4821
  readonly child?: never
@@ -4516,7 +4826,7 @@ export declare namespace Machine {
4516
4826
  States,
4517
4827
  Events,
4518
4828
  Emits,
4519
- InvokeDoneContext<States, Events, Emits, StateId, void>
4829
+ InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
4520
4830
  >
4521
4831
  }
4522
4832
 
@@ -4532,7 +4842,9 @@ export declare namespace Machine {
4532
4842
  ChildOutput,
4533
4843
  ChildInitialError,
4534
4844
  Address extends ChildAddress<never>,
4535
- Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>
4845
+ Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>,
4846
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4847
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4536
4848
  > =
4537
4849
  & {
4538
4850
  readonly id: InvokeLifecycleId
@@ -4545,16 +4857,36 @@ export declare namespace Machine {
4545
4857
  States,
4546
4858
  Events,
4547
4859
  Emits,
4548
- InvokeSnapshotContext<States, Events, Emits, StateId, ChildState, ChildError, ChildOutput>
4860
+ InvokeSnapshotContext<
4861
+ States,
4862
+ Events,
4863
+ Emits,
4864
+ StateId,
4865
+ ChildState,
4866
+ ChildError,
4867
+ ChildOutput,
4868
+ InputEvents,
4869
+ ParentEvents
4870
+ >
4549
4871
  >
4550
4872
  }
4551
4873
  & InvokeDoneRequirement<
4552
4874
  ChildOutput,
4553
- InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, ChildOutput>>
4875
+ InvokeTransition<
4876
+ States,
4877
+ Events,
4878
+ Emits,
4879
+ InvokeDoneContext<States, Events, Emits, StateId, ChildOutput, InputEvents, ParentEvents>
4880
+ >
4554
4881
  >
4555
4882
  & InvokeFailureRequirement<
4556
4883
  ChildError,
4557
- InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, ChildError>>
4884
+ InvokeTransition<
4885
+ States,
4886
+ Events,
4887
+ Emits,
4888
+ InvokeFailureContext<States, Events, Emits, StateId, ChildError, InputEvents, ParentEvents>
4889
+ >
4558
4890
  >
4559
4891
 
4560
4892
  export type ChildInvokeArgs<
@@ -4563,7 +4895,9 @@ export declare namespace Machine {
4563
4895
  Emits extends ReadonlyArray<TaggedSchema>,
4564
4896
  StateId extends StateIdentifier<States>,
4565
4897
  ChildDefinition extends Machine.Any,
4566
- Child extends ChildMachine<string, ChildDefinition>
4898
+ Child extends ChildMachine<string, ChildDefinition>,
4899
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4900
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4567
4901
  > =
4568
4902
  & {
4569
4903
  readonly child:
@@ -4590,12 +4924,17 @@ export declare namespace Machine {
4590
4924
  StateId,
4591
4925
  Snapshot<Machine.States<ChildDefinition>>,
4592
4926
  Error<ChildDefinition>,
4593
- Output<ChildDefinition>
4927
+ Output<ChildDefinition>,
4928
+ InputEvents,
4929
+ ParentEvents
4594
4930
  >
4595
4931
  >
4596
4932
  }
4597
4933
  & (Input<ChildDefinition> extends typeof Schema.Void ? { readonly input?: never } : {
4598
- readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>
4934
+ readonly input: InvokeSource<
4935
+ Input<ChildDefinition>["Type"],
4936
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4937
+ >
4599
4938
  })
4600
4939
  & InvokeDoneRequirement<
4601
4940
  Output<ChildDefinition>,
@@ -4603,7 +4942,15 @@ export declare namespace Machine {
4603
4942
  States,
4604
4943
  Events,
4605
4944
  Emits,
4606
- InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>
4945
+ InvokeDoneContext<
4946
+ States,
4947
+ Events,
4948
+ Emits,
4949
+ StateId,
4950
+ Output<ChildDefinition>,
4951
+ InputEvents,
4952
+ ParentEvents
4953
+ >
4607
4954
  >
4608
4955
  >
4609
4956
  & InvokeFailureRequirement<
@@ -4617,7 +4964,9 @@ export declare namespace Machine {
4617
4964
  Events,
4618
4965
  Emits,
4619
4966
  StateId,
4620
- Error<ChildDefinition> | ActionError<Services<ChildDefinition>>
4967
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
4968
+ InputEvents,
4969
+ ParentEvents
4621
4970
  >
4622
4971
  >
4623
4972
  >
@@ -4634,6 +4983,8 @@ export declare namespace Machine {
4634
4983
  Events extends ReadonlyArray<TaggedSchema>,
4635
4984
  Emits extends ReadonlyArray<TaggedSchema>,
4636
4985
  StateId extends StateIdentifier<States>,
4986
+ InputEvents extends ReadonlyArray<TaggedSchema>,
4987
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
4637
4988
  Raw
4638
4989
  > = Raw extends InvokeTyped<any, any, any, any, any> ? unknown
4639
4990
  : Raw extends { readonly effect: infer Source } ?
@@ -4644,7 +4995,7 @@ export declare namespace Machine {
4644
4995
  States,
4645
4996
  Events,
4646
4997
  Emits,
4647
- InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>>
4998
+ InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>, InputEvents, ParentEvents>
4648
4999
  >
4649
5000
  >
4650
5001
  & InvokeFailureRequirement<
@@ -4653,7 +5004,7 @@ export declare namespace Machine {
4653
5004
  States,
4654
5005
  Events,
4655
5006
  Emits,
4656
- InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>>
5007
+ InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>, InputEvents, ParentEvents>
4657
5008
  >
4658
5009
  >
4659
5010
  & { readonly onSnapshot?: never }
@@ -4663,7 +5014,7 @@ export declare namespace Machine {
4663
5014
  States,
4664
5015
  Events,
4665
5016
  Emits,
4666
- InvokeDoneContext<States, Events, Emits, StateId, void>
5017
+ InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
4667
5018
  >
4668
5019
  readonly onFailure?: never
4669
5020
  readonly onSnapshot?: never
@@ -4676,7 +5027,7 @@ export declare namespace Machine {
4676
5027
  States,
4677
5028
  Events,
4678
5029
  Emits,
4679
- InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>>
5030
+ InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>, InputEvents, ParentEvents>
4680
5031
  >
4681
5032
  >
4682
5033
  & InvokeFailureRequirement<
@@ -4685,7 +5036,15 @@ export declare namespace Machine {
4685
5036
  States,
4686
5037
  Events,
4687
5038
  Emits,
4688
- InvokeFailureContext<States, Events, Emits, StateId, InvokeRuntimeError<Raw>>
5039
+ InvokeFailureContext<
5040
+ States,
5041
+ Events,
5042
+ Emits,
5043
+ StateId,
5044
+ InvokeRuntimeError<Raw>,
5045
+ InputEvents,
5046
+ ParentEvents
5047
+ >
4689
5048
  >
4690
5049
  >
4691
5050
  & {
@@ -4706,7 +5065,9 @@ export declare namespace Machine {
4706
5065
  StateId,
4707
5066
  ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never,
4708
5067
  InvokeRuntimeError<Raw>,
4709
- InvokeOutput<Raw>
5068
+ InvokeOutput<Raw>,
5069
+ InputEvents,
5070
+ ParentEvents
4710
5071
  >
4711
5072
  >
4712
5073
  }
@@ -4719,7 +5080,15 @@ export declare namespace Machine {
4719
5080
  States,
4720
5081
  Events,
4721
5082
  Emits,
4722
- InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>
5083
+ InvokeDoneContext<
5084
+ States,
5085
+ Events,
5086
+ Emits,
5087
+ StateId,
5088
+ Output<ChildDefinition>,
5089
+ InputEvents,
5090
+ ParentEvents
5091
+ >
4723
5092
  >
4724
5093
  >
4725
5094
  & InvokeFailureRequirement<
@@ -4733,12 +5102,17 @@ export declare namespace Machine {
4733
5102
  Events,
4734
5103
  Emits,
4735
5104
  StateId,
4736
- Error<ChildDefinition> | ActionError<Services<ChildDefinition>>
5105
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
5106
+ InputEvents,
5107
+ ParentEvents
4737
5108
  >
4738
5109
  >
4739
5110
  >
4740
5111
  & (Input<ChildDefinition> extends typeof Schema.Void ? { readonly input?: never } : {
4741
- readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>
5112
+ readonly input: InvokeSource<
5113
+ Input<ChildDefinition>["Type"],
5114
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
5115
+ >
4742
5116
  })
4743
5117
  & {
4744
5118
  readonly onSnapshot?: InvokeTransition<
@@ -4752,7 +5126,9 @@ export declare namespace Machine {
4752
5126
  StateId,
4753
5127
  Snapshot<Machine.States<ChildDefinition>>,
4754
5128
  Error<ChildDefinition>,
4755
- Output<ChildDefinition>
5129
+ Output<ChildDefinition>,
5130
+ InputEvents,
5131
+ ParentEvents
4756
5132
  >
4757
5133
  >
4758
5134
  }
@@ -4764,11 +5140,21 @@ export declare namespace Machine {
4764
5140
  Events extends ReadonlyArray<TaggedSchema>,
4765
5141
  Emits extends ReadonlyArray<TaggedSchema>,
4766
5142
  StateId extends StateIdentifier<States>,
5143
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5144
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
4767
5145
  Raw
4768
5146
  > = Raw extends ReadonlyArray<any> ? {
4769
- readonly [Index in keyof Raw]: ContextualInvokeConfig<States, Events, Emits, StateId, Raw[Index]>
5147
+ readonly [Index in keyof Raw]: ContextualInvokeConfig<
5148
+ States,
5149
+ Events,
5150
+ Emits,
5151
+ StateId,
5152
+ InputEvents,
5153
+ ParentEvents,
5154
+ Raw[Index]
5155
+ >
4770
5156
  }
4771
- : ContextualInvokeConfig<States, Events, Emits, StateId, Raw>
5157
+ : ContextualInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents, Raw>
4772
5158
 
4773
5159
  type OutputHandlerConfig<
4774
5160
  States extends StateSchemas,
@@ -4808,64 +5194,68 @@ export declare namespace Machine {
4808
5194
  Emits extends ReadonlyArray<TaggedSchema>,
4809
5195
  StateId extends StateIdentifier<States>,
4810
5196
  E,
4811
- R
5197
+ R,
5198
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5199
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4812
5200
  > = {
4813
5201
  readonly entry?: (
4814
- context: StateActionContext<States, Events, Emits, StateId>,
5202
+ context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4815
5203
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4816
5204
  ) => StateActionResult<any, any>
4817
5205
  readonly exit?: (
4818
- context: StateActionContext<States, Events, Emits, StateId>,
5206
+ context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4819
5207
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4820
5208
  ) => StateActionResult<any, any>
4821
- readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>
5209
+ readonly invoke?:
5210
+ | InvokeDefinition<States, Events, Emits, StateId, InputEvents, ParentEvents>
5211
+ | TypedInvokeDefinition
4822
5212
  readonly always?:
4823
5213
  | ((
4824
- context: AlwaysContext<States, Events, Emits, StateId>,
5214
+ context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4825
5215
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4826
5216
  ) => HandlerResult<States, any, any>)
4827
5217
  | {
4828
5218
  /** Statically declared upper bound of possible target paths. */
4829
5219
  readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
4830
5220
  readonly transition: (
4831
- context: AlwaysContext<States, Events, Emits, StateId>,
5221
+ context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4832
5222
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4833
5223
  ) => HandlerResult<States, any, any>
4834
5224
  }
4835
5225
  readonly onDone?:
4836
5226
  | ((
4837
- context: DoneContext<States, Events, Emits, StateId>,
5227
+ context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4838
5228
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4839
5229
  ) => HandlerResult<States, any, any>)
4840
5230
  | {
4841
5231
  /** Statically declared upper bound of possible target paths. */
4842
5232
  readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
4843
5233
  readonly transition: (
4844
- context: DoneContext<States, Events, Emits, StateId>,
5234
+ context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4845
5235
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4846
5236
  ) => HandlerResult<States, any, any>
4847
5237
  }
4848
5238
  readonly on?: {
4849
5239
  readonly [EventTag in TagOf<Events[number]>]?:
4850
5240
  | ((
4851
- context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
5241
+ context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>,
4852
5242
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4853
5243
  ) => HandlerResult<States, any, any>)
4854
5244
  | {
4855
5245
  readonly reenter?: boolean
4856
5246
  /**
4857
5247
  * Upper bound of state or history paths this handler may target.
4858
- * Returning `void` is always permitted. Declaring a parent state also
5248
+ * Returning `target.none()` is always permitted. Declaring a parent state also
4859
5249
  * permits concrete descendant targets below it.
4860
5250
  */
4861
5251
  readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
4862
5252
  readonly transition: (
4863
- context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
5253
+ context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>,
4864
5254
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4865
5255
  ) => HandlerResult<States, any, any>
4866
5256
  }
4867
5257
  }
4868
- readonly initial?: StateInitialHandler<States, Events, Emits, StateId>
5258
+ readonly initial?: StateInitialHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
4869
5259
  } & ActiveOutputHandlerConfig<States, Events, StateId>
4870
5260
 
4871
5261
  /** Values supplied when a statechart implicitly enters a state's initial children. */
@@ -4890,17 +5280,21 @@ export declare namespace Machine {
4890
5280
  States extends StateSchemas,
4891
5281
  Events extends ReadonlyArray<TaggedSchema>,
4892
5282
  Emits extends ReadonlyArray<TaggedSchema>,
4893
- StateId extends StateIdentifier<States>
4894
- > = StateActionContext<States, Events, Emits, StateId>
5283
+ StateId extends StateIdentifier<States>,
5284
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5285
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
5286
+ > = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4895
5287
 
4896
5288
  /** Initial child value implementation for a compound or parallel state. */
4897
5289
  export type StateInitialHandler<
4898
5290
  States extends StateSchemas,
4899
5291
  Events extends ReadonlyArray<TaggedSchema>,
4900
5292
  Emits extends ReadonlyArray<TaggedSchema>,
4901
- StateId extends StateIdentifier<States>
5293
+ StateId extends StateIdentifier<States>,
5294
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5295
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4902
5296
  > = (
4903
- context: StateInitialContext<States, Events, Emits, StateId>,
5297
+ context: StateInitialContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4904
5298
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4905
5299
  ) => StateInitialValue<States, StateId>
4906
5300
 
@@ -4913,7 +5307,7 @@ export declare namespace Machine {
4913
5307
  > {
4914
5308
  readonly event: LifecycleEvent<Events>
4915
5309
  readonly target: HistoryDefaultTargetBuilder<States, ParentId>
4916
- readonly parent: ParentId
5310
+ readonly owner: ParentId
4917
5311
  }
4918
5312
 
4919
5313
  /**
@@ -4953,13 +5347,15 @@ export declare namespace Machine {
4953
5347
  States extends StateSchemas,
4954
5348
  Events extends ReadonlyArray<TaggedSchema>,
4955
5349
  Emits extends ReadonlyArray<TaggedSchema>,
4956
- ChoiceId extends ChoiceIdentifier<States>
5350
+ ChoiceId extends ChoiceIdentifier<States>,
5351
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5352
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4957
5353
  > {
4958
5354
  readonly choice: {
4959
5355
  /** Statically inspectable upper bound of every possible target. */
4960
5356
  readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>]
4961
5357
  readonly transition: (
4962
- context: ChoiceContext<States, Events, Emits, ChoiceId>,
5358
+ context: ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>,
4963
5359
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4964
5360
  ) => ChoiceResult<States, any, any>
4965
5361
  }
@@ -4983,10 +5379,12 @@ export declare namespace Machine {
4983
5379
  States extends StateSchemas,
4984
5380
  Events extends ReadonlyArray<TaggedSchema>,
4985
5381
  Emits extends ReadonlyArray<TaggedSchema>,
4986
- StateId extends StateIdentifier<States>
5382
+ StateId extends StateIdentifier<States>,
5383
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5384
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4987
5385
  > = {
4988
5386
  readonly entry?: (
4989
- context: StateActionContext<States, Events, Emits, StateId>,
5387
+ context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
4990
5388
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4991
5389
  ) => StateActionResult<any, any>
4992
5390
  readonly exit?: never
@@ -5007,10 +5405,12 @@ export declare namespace Machine {
5007
5405
  Emits extends ReadonlyArray<TaggedSchema>,
5008
5406
  StateId extends StateIdentifier<States>,
5009
5407
  E,
5010
- R
5408
+ R,
5409
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5410
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
5011
5411
  > = NodeByIdentifier<States, StateId> extends { readonly type: "final" } ?
5012
- FinalStateConfig<States, Events, Emits, StateId>
5013
- : ActiveStateConfig<States, Events, Emits, StateId, E, R>
5412
+ FinalStateConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
5413
+ : ActiveStateConfig<States, Events, Emits, StateId, E, R, InputEvents, ParentEvents>
5014
5414
 
5015
5415
  type HandlerNodeConfig<
5016
5416
  States extends StateSchemas,
@@ -5018,9 +5418,11 @@ export declare namespace Machine {
5018
5418
  Emits extends ReadonlyArray<TaggedSchema>,
5019
5419
  Path extends StateNodeIdentifier<States>,
5020
5420
  E,
5021
- R
5022
- > = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path>
5023
- : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R>
5421
+ R,
5422
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5423
+ ParentEvents extends ReadonlyArray<TaggedSchema>
5424
+ > = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path, InputEvents, ParentEvents>
5425
+ : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R, InputEvents, ParentEvents>
5024
5426
  : never
5025
5427
 
5026
5428
  type HandlerChildren<Node> = Node extends { readonly states: infer Children extends StateSchemas } ? Children : never
@@ -5057,14 +5459,26 @@ export declare namespace Machine {
5057
5459
  type HandlerInvokeContextAtPath<
5058
5460
  AllStates extends StateSchemas,
5059
5461
  Events extends ReadonlyArray<TaggedSchema>,
5462
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5060
5463
  Emits extends ReadonlyArray<TaggedSchema>,
5464
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
5061
5465
  Config,
5062
5466
  StateId extends StateNodeIdentifier<AllStates>,
5063
5467
  NodeConfig = HandlerConfigAtPath<Config, StateId>
5064
5468
  > = StateId extends StateIdentifier<AllStates> ?
5065
5469
  NodeConfig extends { readonly invoke: infer Invoke } ? HandlerValidationAtPath<
5066
5470
  StateId,
5067
- { readonly invoke: ContextualInvokeDefinition<AllStates, Events, Emits, StateId, Invoke> }
5471
+ {
5472
+ readonly invoke: ContextualInvokeDefinition<
5473
+ AllStates,
5474
+ Events,
5475
+ Emits,
5476
+ StateId,
5477
+ InputEvents,
5478
+ ParentEvents,
5479
+ Invoke
5480
+ >
5481
+ }
5068
5482
  >
5069
5483
  : unknown
5070
5484
  : unknown
@@ -5072,14 +5486,18 @@ export declare namespace Machine {
5072
5486
  type HandlerInvokeContexts<
5073
5487
  AllStates extends StateSchemas,
5074
5488
  Events extends ReadonlyArray<TaggedSchema>,
5489
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5075
5490
  Emits extends ReadonlyArray<TaggedSchema>,
5491
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
5076
5492
  Config
5077
5493
  > = Types.UnionToIntersection<
5078
5494
  StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ?
5079
5495
  StateId extends StateNodeIdentifier<AllStates> ? HandlerInvokeContextAtPath<
5080
5496
  AllStates,
5081
5497
  Events,
5498
+ InputEvents,
5082
5499
  Emits,
5500
+ ParentEvents,
5083
5501
  Config,
5084
5502
  StateId
5085
5503
  >
@@ -5103,9 +5521,11 @@ export declare namespace Machine {
5103
5521
  Emits extends ReadonlyArray<TaggedSchema>,
5104
5522
  E,
5105
5523
  R,
5524
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5525
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
5106
5526
  StateId extends StateNodeIdentifier<AllStates>
5107
5527
  > =
5108
- & HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R>
5528
+ & HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents>
5109
5529
  & (StateId extends ChoiceIdentifier<AllStates> ? {
5110
5530
  readonly states?: never
5111
5531
  readonly history?: never
@@ -5122,6 +5542,8 @@ export declare namespace Machine {
5122
5542
  Emits,
5123
5543
  E,
5124
5544
  R,
5545
+ InputEvents,
5546
+ ParentEvents,
5125
5547
  Extract<StateId, StateIdentifier<AllStates>>
5126
5548
  >
5127
5549
  readonly history?: HistoryDefaultConfig<
@@ -5144,6 +5566,8 @@ export declare namespace Machine {
5144
5566
  Emits extends ReadonlyArray<TaggedSchema>,
5145
5567
  E,
5146
5568
  R,
5569
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5570
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
5147
5571
  Prefix extends string
5148
5572
  > = {
5149
5573
  readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<
@@ -5153,6 +5577,8 @@ export declare namespace Machine {
5153
5577
  Emits,
5154
5578
  E,
5155
5579
  R,
5580
+ InputEvents,
5581
+ ParentEvents,
5156
5582
  HandlerNodeId<AllStates, JoinPath<Prefix, Key>>
5157
5583
  >
5158
5584
  }
@@ -5387,6 +5813,7 @@ export declare namespace Machine {
5387
5813
  AllStates extends StateSchemas,
5388
5814
  Node,
5389
5815
  Events extends ReadonlyArray<TaggedSchema>,
5816
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5390
5817
  Emits extends ReadonlyArray<TaggedSchema>,
5391
5818
  StateId extends StateNodeIdentifier<AllStates>,
5392
5819
  Config,
@@ -5401,7 +5828,7 @@ export declare namespace Machine {
5401
5828
  & HandlerOnTargetValidation<StateId, Config>
5402
5829
  & HandlerDirectTargetValidation<StateId, Config, "always">
5403
5830
  & HandlerDirectTargetValidation<StateId, Config, "onDone">
5404
- & HandlerInvokeEmitsValidation<Events, StateId, Config>
5831
+ & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config>
5405
5832
  & HandlerChildrenValidation<Node, StateId, Config>
5406
5833
  & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
5407
5834
  & HandlerRuntimeValidation<Events, Emits, StateId, Config>
@@ -5430,17 +5857,17 @@ export declare namespace Machine {
5430
5857
  }
5431
5858
  : unknown
5432
5859
 
5433
- type HandlerInvokeEmitsValidation<
5860
+ type HandlerInvokeParentEventsValidation<
5434
5861
  Events extends ReadonlyArray<TaggedSchema>,
5435
5862
  StateId extends string,
5436
5863
  Config
5437
5864
  > = [InvokeReturn<Config>] extends [never] ? unknown
5438
- : [Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown
5865
+ : [Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown
5439
5866
  : {
5440
5867
  readonly invoke: HandlerValidationError<
5441
- "Invoked child emits events not accepted by the parent machine",
5868
+ "Invoked child expects parent events not accepted by this machine",
5442
5869
  StateId,
5443
- Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>
5870
+ Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>
5444
5871
  >
5445
5872
  }
5446
5873
 
@@ -5460,6 +5887,7 @@ export declare namespace Machine {
5460
5887
  type HandlerNodeValidationAtPath<
5461
5888
  AllStates extends StateSchemas,
5462
5889
  Events extends ReadonlyArray<TaggedSchema>,
5890
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5463
5891
  Emits extends ReadonlyArray<TaggedSchema>,
5464
5892
  Config,
5465
5893
  AvailableOutputStates extends StateIdentifier<AllStates>,
@@ -5470,6 +5898,7 @@ export declare namespace Machine {
5470
5898
  AllStates,
5471
5899
  HandlerNodeByPath<AllStates, StateId>,
5472
5900
  Events,
5901
+ InputEvents,
5473
5902
  Emits,
5474
5903
  StateId,
5475
5904
  NodeConfig,
@@ -5481,6 +5910,7 @@ export declare namespace Machine {
5481
5910
  type HandlerTreeNodeValidations<
5482
5911
  AllStates extends StateSchemas,
5483
5912
  Events extends ReadonlyArray<TaggedSchema>,
5913
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5484
5914
  Emits extends ReadonlyArray<TaggedSchema>,
5485
5915
  Config,
5486
5916
  AvailableOutputStates extends StateIdentifier<AllStates>
@@ -5489,6 +5919,7 @@ export declare namespace Machine {
5489
5919
  StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<
5490
5920
  AllStates,
5491
5921
  Events,
5922
+ InputEvents,
5492
5923
  Emits,
5493
5924
  Config,
5494
5925
  AvailableOutputStates,
@@ -5501,12 +5932,13 @@ export declare namespace Machine {
5501
5932
  type HandlerTreeValidation<
5502
5933
  AllStates extends StateSchemas,
5503
5934
  Events extends ReadonlyArray<TaggedSchema>,
5935
+ InputEvents extends ReadonlyArray<TaggedSchema>,
5504
5936
  Emits extends ReadonlyArray<TaggedSchema>,
5505
5937
  Config,
5506
5938
  AvailableOutputStates extends StateIdentifier<AllStates>
5507
5939
  > =
5508
5940
  & HandlerUnknownStateKeyValidation<AllStates, "", Config>
5509
- & HandlerTreeNodeValidations<AllStates, Events, Emits, Config, AvailableOutputStates>
5941
+ & HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>
5510
5942
 
5511
5943
  type HandlerHasRequiredInitial<
5512
5944
  AllStates extends StateSchemas,
@@ -5602,6 +6034,7 @@ export declare namespace Machine {
5602
6034
  Output,
5603
6035
  OutputStates extends StateIdentifier<AllStates>,
5604
6036
  InputEvents extends ReadonlyArray<TaggedSchema>,
6037
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
5605
6038
  Config
5606
6039
  > = Machine<
5607
6040
  AllStates,
@@ -5620,7 +6053,8 @@ export declare namespace Machine {
5620
6053
  Output,
5621
6054
  Emits,
5622
6055
  OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>,
5623
- InputEvents
6056
+ InputEvents,
6057
+ ParentEvents
5624
6058
  >
5625
6059
 
5626
6060
  /**
@@ -5642,15 +6076,29 @@ export declare namespace Machine {
5642
6076
  FinalStates extends StateIdentifier<States>,
5643
6077
  Output,
5644
6078
  OutputStates extends StateIdentifier<States>,
5645
- InputEvents extends ReadonlyArray<TaggedSchema>
6079
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6080
+ ParentEvents extends ReadonlyArray<TaggedSchema>
5646
6081
  > {
5647
- <const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(
6082
+ <
6083
+ const Config extends HandlerTree<
6084
+ States,
6085
+ States,
6086
+ Events,
6087
+ Emits,
6088
+ E,
6089
+ R,
6090
+ InputEvents,
6091
+ ParentEvents,
6092
+ ""
6093
+ >
6094
+ >(
5648
6095
  config:
5649
6096
  & Config
5650
- & HandlerInvokeContexts<States, Events, Emits, NoInfer<Config>>
6097
+ & HandlerInvokeContexts<States, Events, InputEvents, Emits, ParentEvents, NoInfer<Config>>
5651
6098
  & HandlerTreeValidation<
5652
6099
  States,
5653
6100
  Events,
6101
+ InputEvents,
5654
6102
  Emits,
5655
6103
  NoInfer<Config>,
5656
6104
  | OutputStates
@@ -5673,6 +6121,7 @@ export declare namespace Machine {
5673
6121
  Output,
5674
6122
  OutputStates,
5675
6123
  InputEvents,
6124
+ ParentEvents,
5676
6125
  Config
5677
6126
  >
5678
6127
  }
@@ -5824,7 +6273,8 @@ export const isFinal: <
5824
6273
  FinalStates extends Machine.StateIdentifier<States> = never,
5825
6274
  Output = never,
5826
6275
  OutputStates extends Machine.StateIdentifier<States> = never,
5827
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
6276
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
6277
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
5828
6278
  >(
5829
6279
  machine: Machine<
5830
6280
  States,
@@ -5839,10 +6289,11 @@ export const isFinal: <
5839
6289
  Output,
5840
6290
  Emits,
5841
6291
  OutputStates,
5842
- InputEvents
6292
+ InputEvents,
6293
+ ParentEvents
5843
6294
  >,
5844
6295
  state: Machine.Snapshot<States>
5845
- ) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal
6296
+ ) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal as any
5846
6297
 
5847
6298
  /**
5848
6299
  * Defines a state tree while preserving literal state paths.
@@ -5872,7 +6323,7 @@ export const isFinal: <
5872
6323
  *
5873
6324
  * Machine.make({
5874
6325
  * states: States.states,
5875
- * events: [],
6326
+ * events: Machine.events(),
5876
6327
  * initial: () => States.initial.idle.from()
5877
6328
  * })
5878
6329
  * ```
@@ -5889,18 +6340,22 @@ type MakeConfig<
5889
6340
  Input extends Schema.Top,
5890
6341
  InitialE,
5891
6342
  InitialR,
5892
- InternalEvents extends ReadonlyArray<Machine.TaggedSchema>
6343
+ InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
6344
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
5893
6345
  > = {
5894
6346
  readonly id?: string
5895
6347
  readonly states: States & DefineStateTreeInput<NoInfer<States>>
5896
- readonly events: InputEvents & ValidateInputEventProtocol<NoInfer<InputEvents>>
6348
+ readonly events:
6349
+ & Machine.EventProtocol<"public", InputEvents>
6350
+ & ValidateInputEventProtocol<NoInfer<InputEvents>>
5897
6351
  readonly internalEvents?:
5898
- & InternalEvents
6352
+ & Machine.EventProtocol<"internal", InternalEvents>
5899
6353
  & ValidateInternalEventProtocol<
5900
6354
  NoInfer<InputEvents>,
5901
6355
  NoInfer<InternalEvents>
5902
6356
  >
5903
- readonly emits?: Emits
6357
+ readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
6358
+ readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>
5904
6359
  readonly input?: Input
5905
6360
  readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
5906
6361
  }
@@ -5912,7 +6367,8 @@ type MakeResult<
5912
6367
  Input extends Schema.Top,
5913
6368
  InitialE,
5914
6369
  InitialR,
5915
- InternalEvents extends ReadonlyArray<Machine.TaggedSchema>
6370
+ InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
6371
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
5916
6372
  > = Machine<
5917
6373
  States,
5918
6374
  readonly [...InputEvents, ...InternalEvents],
@@ -5926,7 +6382,8 @@ type MakeResult<
5926
6382
  Machine.TerminalOutput<States>,
5927
6383
  Emits,
5928
6384
  never,
5929
- InputEvents
6385
+ InputEvents,
6386
+ ParentEvents
5930
6387
  >
5931
6388
 
5932
6389
  interface Make {
@@ -5937,11 +6394,12 @@ interface Make {
5937
6394
  const Input extends Schema.Top = typeof Schema.Void,
5938
6395
  InitialE = never,
5939
6396
  InitialR = never,
5940
- const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6397
+ const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
6398
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
5941
6399
  >(
5942
- config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>,
6400
+ config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>,
5943
6401
  ..._validation: ValidateDefinedStates<NoInfer<States>>
5944
- ): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>
6402
+ ): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>
5945
6403
  <
5946
6404
  const States extends Machine.StateSchemas,
5947
6405
  const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
@@ -5949,10 +6407,11 @@ interface Make {
5949
6407
  const Input extends Schema.Top = typeof Schema.Void,
5950
6408
  InitialE = never,
5951
6409
  InitialR = never,
5952
- const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6410
+ const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
6411
+ const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
5953
6412
  >(
5954
6413
  config:
5955
- & Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>, "states">
6414
+ & Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "states">
5956
6415
  & { readonly states: InvalidDefinedStateTreeInput<States> }
5957
6416
  ): never
5958
6417
  }
@@ -5968,10 +6427,13 @@ interface Make {
5968
6427
  * `defineStates` or is passed inline. Call `handle` on the returned definition
5969
6428
  * to implement state behavior with ordinary TypeScript control flow.
5970
6429
  *
5971
- * Schemas in `events` define the public input protocol. Schemas in
5972
- * `internalEvents` are added to the complete handler protocol for raised
5973
- * events, child emissions, and other machine-local deliveries. Their tags
5974
- * must be disjoint.
6430
+ * `Machine.events` defines the public input protocol. `Machine.internalEvents`
6431
+ * adds raised events and other machine-local deliveries.
6432
+ * `Machine.emittedEvents` defines outward ephemeral notifications, while
6433
+ * `parentEvents` declares the inputs a child may explicitly send to its owning
6434
+ * actor. All descriptors expose deferred constructors while retaining their
6435
+ * schemas opaquely for runtime validation. Public and internal tags must be
6436
+ * disjoint.
5975
6437
  *
5976
6438
  * **Example** (Typed counter machine)
5977
6439
  *
@@ -5988,10 +6450,11 @@ interface Make {
5988
6450
  * }) {}
5989
6451
  *
5990
6452
  * const States = Machine.defineStates({ Count })
6453
+ * const Events = Machine.events(Increment)
5991
6454
  *
5992
6455
  * const counter = Machine.make({
5993
6456
  * states: States.states,
5994
- * events: [Increment],
6457
+ * events: Events,
5995
6458
  * initial: () => States.initial.Count(new Count({ value: 0 }))
5996
6459
  * }).handle({
5997
6460
  * Count: {
@@ -6009,94 +6472,92 @@ interface Make {
6009
6472
  */
6010
6473
  export const make: Make = internal.make
6011
6474
 
6012
- type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends EventSchema["~type.make.in"] ?
6013
- [input?: EventSchema["~type.make.in"]]
6014
- : [input: EventSchema["~type.make.in"]]
6015
-
6016
6475
  /**
6017
- * Constructs an event from a schema owned by a machine's protocol.
6018
- *
6019
- * **Details**
6476
+ * Extracts the decoded event union carried by an event protocol descriptor.
6020
6477
  *
6021
- * The schema constructor runs exactly once. The resulting decoded event is
6022
- * trusted by this machine and definitions derived from it with `handle`, so
6023
- * repeated delivery does not decode the same already-constructed value again.
6024
- * Events supplied through ordinary `send` and `plan` calls remain untrusted
6025
- * and continue through full runtime schema validation.
6026
- * Treat the returned event as immutable after construction.
6027
- * This eager low-level constructor throws `MachineSchemaDecodeError` when
6028
- * construction fails. Prefer {@link events} and {@link internalEvents} for
6029
- * ordinary delivery so construction remains inside the machine error channel.
6478
+ * @category utility types
6479
+ * @since 0.10.0
6480
+ */
6481
+ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventOf<
6482
+ Machine.EventProtocolSchemas<Protocol>
6483
+ >
6484
+
6485
+ /**
6486
+ * Defines a public event protocol and returns deferred constructors for every
6487
+ * statically finite configured event tag.
6030
6488
  *
6031
- * The schema must be one of the machine's configured public or internal event
6032
- * schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
6489
+ * Constructor inputs retain their schema-derived required fields, defaults,
6490
+ * and transformations. Construction is deferred until delivery so failures
6491
+ * enter the machine's `MachineSchemaDecodeError` channel rather than throwing
6492
+ * at the call site.
6033
6493
  *
6034
6494
  * **Example**
6035
6495
  *
6036
6496
  * ```ts
6037
- * import { Schema } from "effect"
6038
- * import { Machine } from "@typeonce/effect-machine"
6039
- *
6040
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
6041
- * class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
6042
- * by: Schema.Number
6043
- * }) {}
6044
- *
6045
- * const States = Machine.defineStates({ Idle })
6046
- * const counter = Machine.make({
6047
- * states: States.states,
6048
- * events: [Increment],
6049
- * initial: () => States.initial.Idle.from()
6050
- * }).handle({ Idle: { on: { Increment: () => States.initial.Idle.from() } } })
6051
- *
6052
- * const increment = Machine.event(counter, Increment, { by: 1 })
6497
+ * const Events = Machine.events(Increment, Reset)
6498
+ * const machine = Machine.make({ events: Events, ... })
6499
+ * yield* ref.send(Events.Increment({ by: 1 }))
6053
6500
  * ```
6054
6501
  *
6055
6502
  * @category constructors
6056
- * @since 0.4.0
6503
+ * @since 0.10.0
6057
6504
  */
6058
- export const event: <const M extends Machine.Any, const EventSchema extends Machine.TaggedSchema>(
6059
- machine: M,
6060
- schema: EventSchema & ([EventSchema["Type"]] extends [Machine.Event<M>] ? unknown : never),
6061
- ...args: EventConstructorArgs<EventSchema>
6062
- ) => EventSchema["Type"] = internal.event
6505
+ export const events: {
6506
+ <const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(
6507
+ ...schemas: Schemas & ValidateInputEventProtocol<NoInfer<Schemas>>
6508
+ ): Machine.EventProtocol<"public", readonly [...Schemas]>
6509
+ <const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(
6510
+ ...inputs: Inputs & ValidateEventProtocolBuilder<"public", Inputs>
6511
+ ): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>
6512
+ } = internal.events as any
6063
6513
 
6064
6514
  /**
6065
- * Returns deferred constructors for every public event in a machine protocol.
6515
+ * Defines an internal event protocol and returns deferred constructors for
6516
+ * every statically finite configured event tag.
6066
6517
  *
6067
- * Constructor inputs retain their schema-derived required fields, defaults,
6068
- * and transformations. Construction is deferred until delivery so failures
6069
- * enter the machine's `MachineSchemaDecodeError` channel rather than throwing
6070
- * at the call site.
6518
+ * Use these constructors for raised events and other machine-local deliveries.
6519
+ * Construction failures are reported through the
6520
+ * owning machine's `MachineSchemaDecodeError` channel.
6071
6521
  *
6072
6522
  * **Example**
6073
6523
  *
6074
6524
  * ```ts
6075
- * const Event = Machine.events(counter)
6076
- * yield* ref.send(Event.Increment({ by: 1 }))
6525
+ * const InternalEvents = Machine.internalEvents(Loaded, Failed)
6526
+ * const machine = Machine.make({ internalEvents: InternalEvents, ... })
6527
+ *
6528
+ * // Inside a transition callback:
6529
+ * enqueue.raise(InternalEvents.Loaded({ value }))
6077
6530
  * ```
6078
6531
  *
6079
6532
  * @category constructors
6080
- * @since 0.9.0
6533
+ * @since 0.10.0
6081
6534
  */
6082
- export const events: <const M extends Machine.Any>(
6083
- machine: M
6084
- ) => Machine.EventConstructors<Machine.InputEvents<M>> = internal.events
6535
+ export const internalEvents: {
6536
+ <const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(
6537
+ ...schemas: Schemas & ValidateInternalEventProtocol<readonly [], NoInfer<Schemas>>
6538
+ ): Machine.EventProtocol<"internal", readonly [...Schemas]>
6539
+ <const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(
6540
+ ...inputs: Inputs & ValidateEventProtocolBuilder<"internal", Inputs>
6541
+ ): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>
6542
+ } = internal.internalEvents as any
6085
6543
 
6086
6544
  /**
6087
- * Returns deferred constructors for every internal event in a machine
6088
- * protocol.
6089
- *
6090
- * Use these constructors for raised events and other machine-local deliveries.
6091
- * Construction failures are reported through the
6092
- * owning machine's `MachineSchemaDecodeError` channel.
6545
+ * Defines the ephemeral notifications a machine may publish to external
6546
+ * observers. Emitted events are separate from actor input and are never sent
6547
+ * implicitly to a parent actor. Observe them through `MachineRef.emissions` or
6548
+ * the AtomMachine emission stream adapters.
6093
6549
  *
6094
6550
  * @category constructors
6095
- * @since 0.9.0
6551
+ * @since 0.10.0
6096
6552
  */
6097
- export const internalEvents: <const M extends Machine.Any>(
6098
- machine: M
6099
- ) => Machine.EventConstructors<Machine.InternalEvents<M>> = internal.internalEvents
6553
+ export const emittedEvents: {
6554
+ <const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(
6555
+ ...schemas: Schemas & ValidateEmittedEventProtocol<NoInfer<Schemas>>
6556
+ ): Machine.EventProtocol<"emitted", readonly [...Schemas]>
6557
+ <const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(
6558
+ ...inputs: Inputs & ValidateEventProtocolBuilder<"emitted", Inputs>
6559
+ ): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>
6560
+ } = internal.emittedEvents as any
6100
6561
 
6101
6562
  /**
6102
6563
  * Encodes a decoded machine snapshot into a normalized data representation.
@@ -6131,7 +6592,7 @@ export const internalEvents: <const M extends Machine.Any>(
6131
6592
  * const States = Machine.defineStates({ Idle })
6132
6593
  * const machine = Machine.make({
6133
6594
  * states: States.states,
6134
- * events: [],
6595
+ * events: Machine.events(),
6135
6596
  * initial: () => States.initial.Idle.from()
6136
6597
  * }).handle({ Idle: {} })
6137
6598
  *
@@ -6158,7 +6619,8 @@ export const encodeSnapshot: <
6158
6619
  FinalStates extends Machine.StateIdentifier<States> = never,
6159
6620
  Output = never,
6160
6621
  OutputStates extends Machine.StateIdentifier<States> = never,
6161
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
6622
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
6623
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6162
6624
  >(
6163
6625
  machine: Machine<
6164
6626
  States,
@@ -6173,14 +6635,15 @@ export const encodeSnapshot: <
6173
6635
  Output,
6174
6636
  Emits,
6175
6637
  OutputStates,
6176
- InputEvents
6638
+ InputEvents,
6639
+ ParentEvents
6177
6640
  >,
6178
6641
  snapshot: Machine.Snapshot<States>
6179
6642
  ) => Effect.Effect<
6180
6643
  Machine.EncodedSnapshot,
6181
6644
  MachineSchemaEncodeError,
6182
6645
  Machine.SnapshotEncodingServices<States>
6183
- > = internal.encodeSnapshot
6646
+ > = internal.encodeSnapshot as any
6184
6647
 
6185
6648
  /**
6186
6649
  * Decodes a normalized data representation into a validated machine snapshot.
@@ -6211,7 +6674,7 @@ export const encodeSnapshot: <
6211
6674
  * const States = Machine.defineStates({ Idle })
6212
6675
  * const machine = Machine.make({
6213
6676
  * states: States.states,
6214
- * events: [],
6677
+ * events: Machine.events(),
6215
6678
  * initial: () => States.initial.Idle.from()
6216
6679
  * }).handle({ Idle: {} })
6217
6680
  *
@@ -6239,7 +6702,8 @@ export const decodeSnapshot: <
6239
6702
  FinalStates extends Machine.StateIdentifier<States> = never,
6240
6703
  Output = never,
6241
6704
  OutputStates extends Machine.StateIdentifier<States> = never,
6242
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
6705
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
6706
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6243
6707
  >(
6244
6708
  machine: Machine<
6245
6709
  States,
@@ -6254,14 +6718,15 @@ export const decodeSnapshot: <
6254
6718
  Output,
6255
6719
  Emits,
6256
6720
  OutputStates,
6257
- InputEvents
6721
+ InputEvents,
6722
+ ParentEvents
6258
6723
  >,
6259
6724
  encoded: unknown
6260
6725
  ) => Effect.Effect<
6261
6726
  Machine.Snapshot<States>,
6262
6727
  MachineSchemaDecodeError,
6263
6728
  Machine.SnapshotDecodingServices<States>
6264
- > = internal.decodeSnapshot
6729
+ > = internal.decodeSnapshot as any
6265
6730
 
6266
6731
  type DynamicEffectInvokeSource<
6267
6732
  States extends Machine.StateSchemas,
@@ -6269,7 +6734,7 @@ type DynamicEffectInvokeSource<
6269
6734
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
6270
6735
  StateId extends Machine.StateIdentifier<States>,
6271
6736
  Source extends (
6272
- context: Machine.InvokeContext<States, Events, Emits, StateId>
6737
+ context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
6273
6738
  ) => Effect.Effect<unknown, unknown, unknown>
6274
6739
  > = {
6275
6740
  readonly id: InvokeLifecycleId
@@ -6291,7 +6756,15 @@ type DynamicEffectDoneHandler<
6291
6756
  States,
6292
6757
  Events,
6293
6758
  Emits,
6294
- Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>>
6759
+ Machine.InvokeDoneContext<
6760
+ States,
6761
+ Events,
6762
+ Emits,
6763
+ StateId,
6764
+ Effect.Success<ReturnType<NoInfer<Source>>>,
6765
+ readonly [],
6766
+ readonly []
6767
+ >
6295
6768
  >
6296
6769
 
6297
6770
  type DynamicEffectFailureHandler<
@@ -6304,7 +6777,15 @@ type DynamicEffectFailureHandler<
6304
6777
  States,
6305
6778
  Events,
6306
6779
  Emits,
6307
- Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>>
6780
+ Machine.InvokeFailureContext<
6781
+ States,
6782
+ Events,
6783
+ Emits,
6784
+ StateId,
6785
+ Effect.Error<ReturnType<NoInfer<Source>>>,
6786
+ readonly [],
6787
+ readonly []
6788
+ >
6308
6789
  >
6309
6790
 
6310
6791
  type DynamicEffectInvokeResult<
@@ -6314,7 +6795,7 @@ type DynamicEffectInvokeResult<
6314
6795
  StateId extends Machine.StateIdentifier<States>,
6315
6796
  Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6316
6797
  > =
6317
- & Machine.InvokeConfig<States, Events, Emits, StateId>
6798
+ & Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []>
6318
6799
  & Machine.InvokeTyped<
6319
6800
  Effect.Success<ReturnType<Source>>,
6320
6801
  Effect.Error<ReturnType<Source>>,
@@ -6324,6 +6805,325 @@ type DynamicEffectInvokeResult<
6324
6805
 
6325
6806
  type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false
6326
6807
 
6808
+ type BoundDynamicEffectInvokeSource<
6809
+ States extends Machine.StateSchemas,
6810
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6811
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6812
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
6813
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
6814
+ StateId extends Machine.StateIdentifier<States>,
6815
+ Source extends (
6816
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6817
+ ) => Effect.Effect<unknown, unknown, unknown>
6818
+ > = {
6819
+ readonly id: InvokeLifecycleId
6820
+ readonly effect: Source
6821
+ readonly after?: never
6822
+ readonly logic?: never
6823
+ readonly child?: never
6824
+ readonly address?: never
6825
+ readonly onSnapshot?: never
6826
+ }
6827
+
6828
+ type BoundDynamicEffectDoneHandler<
6829
+ States extends Machine.StateSchemas,
6830
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6831
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6832
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
6833
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
6834
+ StateId extends Machine.StateIdentifier<States>,
6835
+ Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6836
+ > = Machine.InvokeTransition<
6837
+ States,
6838
+ Events,
6839
+ Emits,
6840
+ Machine.InvokeDoneContext<
6841
+ States,
6842
+ Events,
6843
+ Emits,
6844
+ StateId,
6845
+ Effect.Success<ReturnType<NoInfer<Source>>>,
6846
+ InputEvents,
6847
+ ParentEvents
6848
+ >
6849
+ >
6850
+
6851
+ type BoundDynamicEffectFailureHandler<
6852
+ States extends Machine.StateSchemas,
6853
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6854
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6855
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
6856
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
6857
+ StateId extends Machine.StateIdentifier<States>,
6858
+ Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6859
+ > = Machine.InvokeTransition<
6860
+ States,
6861
+ Events,
6862
+ Emits,
6863
+ Machine.InvokeFailureContext<
6864
+ States,
6865
+ Events,
6866
+ Emits,
6867
+ StateId,
6868
+ Effect.Error<ReturnType<NoInfer<Source>>>,
6869
+ InputEvents,
6870
+ ParentEvents
6871
+ >
6872
+ >
6873
+
6874
+ type BoundDynamicEffectInvokeResult<
6875
+ States extends Machine.StateSchemas,
6876
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6877
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6878
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
6879
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
6880
+ StateId extends Machine.StateIdentifier<States>,
6881
+ Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6882
+ > =
6883
+ & Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
6884
+ & Machine.InvokeTyped<
6885
+ Effect.Success<ReturnType<Source>>,
6886
+ Effect.Error<ReturnType<Source>>,
6887
+ Effect.Services<ReturnType<Source>>,
6888
+ never
6889
+ >
6890
+
6891
+ /**
6892
+ * Machine-bound invocation constructor that preserves the owning machine's
6893
+ * public input and parent protocols in every invocation callback.
6894
+ *
6895
+ * @category constructors
6896
+ * @since 0.11.0
6897
+ */
6898
+ export interface Invoker<
6899
+ States extends Machine.StateSchemas,
6900
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6901
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6902
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
6903
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
6904
+ > {
6905
+ <
6906
+ StateId extends Machine.StateIdentifier<States>,
6907
+ const Source extends (
6908
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6909
+ ) => Effect.Effect<unknown, unknown, unknown>
6910
+ >(
6911
+ config:
6912
+ & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6913
+ & {
6914
+ readonly onDone: BoundDynamicEffectDoneHandler<
6915
+ States,
6916
+ Events,
6917
+ Emits,
6918
+ InputEvents,
6919
+ ParentEvents,
6920
+ StateId,
6921
+ Source
6922
+ >
6923
+ readonly onFailure: BoundDynamicEffectFailureHandler<
6924
+ States,
6925
+ Events,
6926
+ Emits,
6927
+ InputEvents,
6928
+ ParentEvents,
6929
+ StateId,
6930
+ Source
6931
+ >
6932
+ },
6933
+ ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
6934
+ "onDone must be omitted when the Effect output is never"
6935
+ ]
6936
+ : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
6937
+ "onFailure must be omitted when the Effect error is never"
6938
+ ]
6939
+ : []
6940
+ ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6941
+ <
6942
+ StateId extends Machine.StateIdentifier<States>,
6943
+ const Source extends (
6944
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6945
+ ) => Effect.Effect<unknown, never, unknown>
6946
+ >(
6947
+ config:
6948
+ & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6949
+ & {
6950
+ readonly onDone: BoundDynamicEffectDoneHandler<
6951
+ States,
6952
+ Events,
6953
+ Emits,
6954
+ InputEvents,
6955
+ ParentEvents,
6956
+ StateId,
6957
+ Source
6958
+ >
6959
+ readonly onFailure?: never
6960
+ },
6961
+ ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
6962
+ "onDone must be omitted when the Effect output is never"
6963
+ ]
6964
+ : []
6965
+ ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6966
+ <
6967
+ StateId extends Machine.StateIdentifier<States>,
6968
+ const Source extends (
6969
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6970
+ ) => Effect.Effect<never, unknown, unknown>
6971
+ >(
6972
+ config:
6973
+ & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6974
+ & {
6975
+ readonly onDone?: never
6976
+ readonly onFailure: BoundDynamicEffectFailureHandler<
6977
+ States,
6978
+ Events,
6979
+ Emits,
6980
+ InputEvents,
6981
+ ParentEvents,
6982
+ StateId,
6983
+ Source
6984
+ >
6985
+ },
6986
+ ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
6987
+ "onFailure must be omitted when the Effect error is never"
6988
+ ]
6989
+ : []
6990
+ ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6991
+ <
6992
+ StateId extends Machine.StateIdentifier<States>,
6993
+ const Source extends (
6994
+ context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6995
+ ) => Effect.Effect<never, never, unknown>
6996
+ >(
6997
+ config:
6998
+ & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6999
+ & {
7000
+ readonly onDone?: never
7001
+ readonly onFailure?: never
7002
+ }
7003
+ ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7004
+ <
7005
+ StateId extends Machine.StateIdentifier<States>,
7006
+ const Fx extends Effect.Effect<any, any, any>,
7007
+ const Config extends object
7008
+ >(
7009
+ config:
7010
+ & Config
7011
+ & Machine.EffectInvokeArgs<
7012
+ States,
7013
+ Events,
7014
+ Emits,
7015
+ StateId,
7016
+ Fx,
7017
+ Fx,
7018
+ InputEvents,
7019
+ ParentEvents
7020
+ >
7021
+ ):
7022
+ & Config
7023
+ & Machine.InvokeOwned<States, Events, Emits, StateId>
7024
+ & Machine.InvokeTyped<Effect.Success<Fx>, Effect.Error<Fx>, Effect.Services<Fx>, never>
7025
+ <StateId extends Machine.StateIdentifier<States>, const Config extends object>(
7026
+ config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>
7027
+ ): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>
7028
+ <
7029
+ StateId extends Machine.StateIdentifier<States>,
7030
+ ChildState,
7031
+ ChildEvent,
7032
+ ChildError,
7033
+ ChildRequirements,
7034
+ ChildOutput,
7035
+ ChildInitialError,
7036
+ Address extends ChildAddress<never>
7037
+ >(
7038
+ config: Machine.LogicInvokeArgs<
7039
+ States,
7040
+ Events,
7041
+ Emits,
7042
+ StateId,
7043
+ ChildState,
7044
+ ChildEvent,
7045
+ ChildError,
7046
+ ChildRequirements,
7047
+ ChildOutput,
7048
+ ChildInitialError,
7049
+ Address,
7050
+ (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Logic<
7051
+ ChildState,
7052
+ ChildEvent,
7053
+ ChildError,
7054
+ ChildRequirements,
7055
+ ChildOutput,
7056
+ ChildInitialError
7057
+ >,
7058
+ InputEvents,
7059
+ ParentEvents
7060
+ >
7061
+ ):
7062
+ & Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
7063
+ & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>
7064
+ <
7065
+ StateId extends Machine.StateIdentifier<States>,
7066
+ ChildState,
7067
+ ChildEvent,
7068
+ ChildError,
7069
+ ChildRequirements,
7070
+ ChildOutput,
7071
+ ChildInitialError,
7072
+ Address extends ChildAddress<never>,
7073
+ const Config extends object
7074
+ >(
7075
+ config:
7076
+ & Config
7077
+ & Machine.LogicInvokeArgs<
7078
+ States,
7079
+ Events,
7080
+ Emits,
7081
+ StateId,
7082
+ ChildState,
7083
+ ChildEvent,
7084
+ ChildError,
7085
+ ChildRequirements,
7086
+ ChildOutput,
7087
+ ChildInitialError,
7088
+ Address,
7089
+ Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>,
7090
+ InputEvents,
7091
+ ParentEvents
7092
+ >
7093
+ ):
7094
+ & Config
7095
+ & Machine.InvokeOwned<States, Events, Emits, StateId>
7096
+ & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>
7097
+ <
7098
+ StateId extends Machine.StateIdentifier<States>,
7099
+ const Child extends ChildMachine.Any,
7100
+ const Config extends object
7101
+ >(
7102
+ config:
7103
+ & Config
7104
+ & Machine.ChildInvokeArgs<
7105
+ States,
7106
+ Events,
7107
+ Emits,
7108
+ StateId,
7109
+ Child["machine"],
7110
+ Child,
7111
+ InputEvents,
7112
+ ParentEvents
7113
+ >
7114
+ ):
7115
+ & Config
7116
+ & Machine.InvokeOwned<States, Events, Emits, StateId>
7117
+ & Machine.InvokeTyped<
7118
+ Machine.Output<Child["machine"]>,
7119
+ Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>,
7120
+ Machine.Services<Child["machine"]>,
7121
+ Machine.InitialError<Child["machine"]>,
7122
+ Machine.Emit<Child["machine"]>,
7123
+ Machine.EventOf<Machine.ParentEvents<Child["machine"]>>
7124
+ >
7125
+ }
7126
+
6327
7127
  /**
6328
7128
  * Preserves inference for a state-owned invocation configuration.
6329
7129
  *
@@ -6340,6 +7140,12 @@ type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] e
6340
7140
  * lifecycle `id` and a typed communication `address`. Child descriptors already
6341
7141
  * own their identity, so `id` and `address` must not be repeated.
6342
7142
  *
7143
+ * Owner references are intentionally non-sendable here because this standalone
7144
+ * constructor does not know the owning definition. When a callback sends to
7145
+ * `self` or `parent`, use the bound constructor on the owning definition
7146
+ * (`definition.invoke(...)`) so the exact public input and `parentEvents`
7147
+ * protocols are available.
7148
+ *
6343
7149
  * ```ts
6344
7150
  * invoke: Machine.invoke({
6345
7151
  * id: "load",
@@ -6362,7 +7168,7 @@ export const invoke: {
6362
7168
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6363
7169
  StateId extends Machine.StateIdentifier<States>,
6364
7170
  const Source extends (
6365
- context: Machine.InvokeContext<States, Events, Emits, StateId>
7171
+ context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
6366
7172
  ) => Effect.Effect<unknown, unknown, unknown>
6367
7173
  >(
6368
7174
  config:
@@ -6385,7 +7191,7 @@ export const invoke: {
6385
7191
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6386
7192
  StateId extends Machine.StateIdentifier<States>,
6387
7193
  const Source extends (
6388
- context: Machine.InvokeContext<States, Events, Emits, StateId>
7194
+ context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
6389
7195
  ) => Effect.Effect<unknown, never, unknown>
6390
7196
  >(
6391
7197
  config:
@@ -6405,7 +7211,7 @@ export const invoke: {
6405
7211
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6406
7212
  StateId extends Machine.StateIdentifier<States>,
6407
7213
  const Source extends (
6408
- context: Machine.InvokeContext<States, Events, Emits, StateId>
7214
+ context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
6409
7215
  ) => Effect.Effect<never, unknown, unknown>
6410
7216
  >(
6411
7217
  config:
@@ -6425,7 +7231,7 @@ export const invoke: {
6425
7231
  const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6426
7232
  StateId extends Machine.StateIdentifier<States>,
6427
7233
  const Source extends (
6428
- context: Machine.InvokeContext<States, Events, Emits, StateId>
7234
+ context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>
6429
7235
  ) => Effect.Effect<never, never, unknown>
6430
7236
  >(
6431
7237
  config:
@@ -6443,7 +7249,9 @@ export const invoke: {
6443
7249
  const Fx extends Effect.Effect<any, any, any>,
6444
7250
  const Config extends object
6445
7251
  >(
6446
- config: Config & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx>
7252
+ config:
7253
+ & Config
7254
+ & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx, Fx, readonly [], readonly []>
6447
7255
  ):
6448
7256
  & Config
6449
7257
  & Machine.InvokeOwned<States, Events, Emits, StateId>
@@ -6460,7 +7268,7 @@ export const invoke: {
6460
7268
  StateId extends Machine.StateIdentifier<States>,
6461
7269
  const Config extends object
6462
7270
  >(
6463
- config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId>
7271
+ config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, readonly [], readonly []>
6464
7272
  ): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>
6465
7273
  <
6466
7274
  const States extends Machine.StateSchemas,
@@ -6487,17 +7295,19 @@ export const invoke: {
6487
7295
  ChildOutput,
6488
7296
  ChildInitialError,
6489
7297
  Address,
6490
- (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Logic<
7298
+ (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Logic<
6491
7299
  ChildState,
6492
7300
  ChildEvent,
6493
7301
  ChildError,
6494
7302
  ChildRequirements,
6495
7303
  ChildOutput,
6496
7304
  ChildInitialError
6497
- >
7305
+ >,
7306
+ readonly [],
7307
+ readonly []
6498
7308
  >
6499
7309
  ):
6500
- & Machine.InvokeConfig<States, Events, Emits, StateId>
7310
+ & Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []>
6501
7311
  & Machine.InvokeTyped<
6502
7312
  ChildOutput,
6503
7313
  ChildError,
@@ -6531,7 +7341,10 @@ export const invoke: {
6531
7341
  ChildRequirements,
6532
7342
  ChildOutput,
6533
7343
  ChildInitialError,
6534
- Address
7344
+ Address,
7345
+ Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>,
7346
+ readonly [],
7347
+ readonly []
6535
7348
  >
6536
7349
  ):
6537
7350
  & Config
@@ -6550,7 +7363,9 @@ export const invoke: {
6550
7363
  const Child extends ChildMachine.Any,
6551
7364
  const Config extends object
6552
7365
  >(
6553
- config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child>
7366
+ config:
7367
+ & Config
7368
+ & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, readonly [], readonly []>
6554
7369
  ):
6555
7370
  & Config
6556
7371
  & Machine.InvokeOwned<States, Events, Emits, StateId>
@@ -6559,60 +7374,10 @@ export const invoke: {
6559
7374
  Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>,
6560
7375
  Machine.Services<Child["machine"]>,
6561
7376
  Machine.InitialError<Child["machine"]>,
6562
- Machine.Emit<Child["machine"]>
7377
+ Machine.Emit<Child["machine"]>,
7378
+ Machine.EventOf<Machine.ParentEvents<Child["machine"]>>
6563
7379
  >
6564
7380
  } = ((config: unknown) => config) as any
6565
- type RetagFields<Target extends Machine.TaggedSchema> = Omit<Target["~type.make.in"], "_tag">
6566
-
6567
- type RetagTargetCompatibility<Target extends Machine.TaggedSchema> = Target extends {
6568
- readonly fields: Schema.Struct.Fields
6569
- } ? "_tag" extends keyof Target["~type.make.in"] ? {} extends Pick<Target["~type.make.in"], "_tag"> ? unknown : {
6570
- readonly "~effect/Machine/RetagTargetError": "Target schema must supply its discriminator when make is called"
6571
- }
6572
- : unknown
6573
- : {
6574
- readonly "~effect/Machine/RetagTargetError": "Target schema must be one tagged struct or tagged class"
6575
- }
6576
-
6577
- type RequiredKeys<A> = {
6578
- readonly [Key in keyof A]-?: {} extends Pick<A, Key> ? never : Key
6579
- }[keyof A]
6580
-
6581
- type CompatibleSourceKeys<Fields, Source> = {
6582
- readonly [Key in Extract<keyof Fields, keyof Source>]: Source[Key] extends Fields[Key] ? Key : never
6583
- }[Extract<keyof Fields, keyof Source>]
6584
-
6585
- type RetagPatch<Target extends Machine.TaggedSchema, Source> =
6586
- & Partial<RetagFields<Target>>
6587
- & Pick<
6588
- RetagFields<Target>,
6589
- Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>
6590
- >
6591
-
6592
- type RetagArgs<Target extends Machine.TaggedSchema, Source> = [
6593
- Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>
6594
- ] extends [never] ? [patch?: RetagPatch<Target, Source>]
6595
- : [patch: RetagPatch<Target, Source>]
6596
-
6597
- /**
6598
- * Constructs another tagged case from compatible source fields.
6599
- *
6600
- * The target must be one tagged struct or tagged class whose discriminator is
6601
- * supplied by its constructor. Union wrappers are rejected because their
6602
- * `make` operation cannot select a member after the source discriminator has
6603
- * been discarded. Missing or incompatible required target fields must be
6604
- * supplied by the patch, and the target schema's normal `make` validation
6605
- * remains authoritative at runtime.
6606
- *
6607
- * @category constructors
6608
- * @since 0.4.0
6609
- */
6610
- export const retag: <const Target extends Machine.TaggedSchema, const Source extends { readonly _tag: PropertyKey }>(
6611
- target: Target & RetagTargetCompatibility<Target>,
6612
- source: Source,
6613
- ...args: RetagArgs<Target, Source>
6614
- ) => Target["Type"] = internal.retag
6615
-
6616
7381
  /**
6617
7382
  * Plans the initial state for a machine without executing actor commands.
6618
7383
  *
@@ -6641,7 +7406,7 @@ export const retag: <const Target extends Machine.TaggedSchema, const Source ext
6641
7406
  * const States = Machine.defineStates({ Idle })
6642
7407
  * const machine = Machine.make({
6643
7408
  * states: States.states,
6644
- * events: [],
7409
+ * events: Machine.events(),
6645
7410
  * initial: () => States.initial.Idle.from()
6646
7411
  * }).handle({ Idle: {} })
6647
7412
  *
@@ -6666,7 +7431,8 @@ export const planInitial: <
6666
7431
  FinalStates extends Machine.StateIdentifier<States> = never,
6667
7432
  Output = never,
6668
7433
  OutputStates extends Machine.StateIdentifier<States> = never,
6669
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
7434
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
7435
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6670
7436
  >(
6671
7437
  machine:
6672
7438
  & Machine<
@@ -6682,7 +7448,8 @@ export const planInitial: <
6682
7448
  Output,
6683
7449
  Emits,
6684
7450
  OutputStates,
6685
- InputEvents
7451
+ InputEvents,
7452
+ ParentEvents
6686
7453
  >
6687
7454
  & EnsureExecutable<States, UnhandledStates, OutputStates>,
6688
7455
  ...args: [...Machine.InputArgs<Input>]
@@ -6723,7 +7490,7 @@ export const planInitial: <
6723
7490
  ),
6724
7491
  InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
6725
7492
  never
6726
- > = internal.planInitial
7493
+ > = internal.planInitial as any
6727
7494
 
6728
7495
  /**
6729
7496
  * Returns every compiled state node in definition order.
@@ -6827,7 +7594,8 @@ export const enabled: <
6827
7594
  FinalStates extends Machine.StateIdentifier<States> = never,
6828
7595
  Output = never,
6829
7596
  OutputStates extends Machine.StateIdentifier<States> = never,
6830
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
7597
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
7598
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6831
7599
  >(
6832
7600
  machine: Machine<
6833
7601
  States,
@@ -6842,10 +7610,11 @@ export const enabled: <
6842
7610
  Output,
6843
7611
  Emits,
6844
7612
  OutputStates,
6845
- InputEvents
7613
+ InputEvents,
7614
+ ParentEvents
6846
7615
  >,
6847
7616
  state: Machine.Snapshot<States>
6848
- ) => ReadonlyArray<Machine.TagOf<Events[number]>> = internal.enabled
7617
+ ) => ReadonlyArray<Machine.TagOf<Events[number]>> = internal.enabled as any
6849
7618
 
6850
7619
  /**
6851
7620
  * Plans the next state snapshot synchronously.
@@ -6876,7 +7645,7 @@ export const enabled: <
6876
7645
  * const States = Machine.defineStates({ Off, On })
6877
7646
  * const machine = Machine.make({
6878
7647
  * states: States.states,
6879
- * events: [Toggle],
7648
+ * events: Machine.events(Toggle),
6880
7649
  * initial: () => States.initial.Off.from()
6881
7650
  * }).handle({ Off: { on: { Toggle: () => States.initial.On.from() } }, On: {} })
6882
7651
  *
@@ -6904,7 +7673,8 @@ export const plan: <
6904
7673
  FinalStates extends Machine.StateIdentifier<States> = never,
6905
7674
  Output = never,
6906
7675
  OutputStates extends Machine.StateIdentifier<States> = never,
6907
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
7676
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
7677
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
6908
7678
  >(
6909
7679
  machine:
6910
7680
  & Machine<
@@ -6920,7 +7690,8 @@ export const plan: <
6920
7690
  Output,
6921
7691
  Emits,
6922
7692
  OutputStates,
6923
- InputEvents
7693
+ InputEvents,
7694
+ ParentEvents
6924
7695
  >
6925
7696
  & EnsureExecutable<States, UnhandledStates, OutputStates>,
6926
7697
  state: Machine.Snapshot<States>,
@@ -6960,7 +7731,7 @@ export const plan: <
6960
7731
  ),
6961
7732
  E | InfiniteTransitionError | MachineSchemaDecodeError,
6962
7733
  never
6963
- > = internal.plan
7734
+ > = internal.plan as any
6964
7735
 
6965
7736
  /**
6966
7737
  * Creates advanced stateful process logic from explicit initialization and
@@ -7164,6 +7935,89 @@ export const watch: <State, Event, Error = never, Output = never>(
7164
7935
  ref: MachineRef<State, Event, Error, Output>
7165
7936
  ) => Stream.Stream<RuntimeOutcome<State, Error, Output>> = internal.watch
7166
7937
 
7938
+ /**
7939
+ * Prepares a fresh machine without initializing it.
7940
+ *
7941
+ * Use this constructor when observation must be composed before initial-entry
7942
+ * actions run. Subscribe to `prepared.emissions`, then evaluate
7943
+ * `prepared.start`. Ordinary callers can continue to use {@link start}, which
7944
+ * starts directly and does not allocate the prepared lifecycle boundary.
7945
+ *
7946
+ * ```ts
7947
+ * const prepared = yield* Machine.prepare(machine)
7948
+ *
7949
+ * yield* prepared.emissions.pipe(
7950
+ * Stream.runForEach(handleEmission),
7951
+ * Effect.forkScoped({ startImmediately: true })
7952
+ * )
7953
+ *
7954
+ * const ref = yield* prepared.start
7955
+ * ```
7956
+ *
7957
+ * @category constructors
7958
+ * @since 0.11.0
7959
+ */
7960
+ export const prepare: <
7961
+ const States extends Machine.StateSchemas,
7962
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
7963
+ const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
7964
+ const Input extends Schema.Top = typeof Schema.Void,
7965
+ UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
7966
+ E = never,
7967
+ R = never,
7968
+ InitialE = never,
7969
+ InitialR = never,
7970
+ FinalStates extends Machine.StateIdentifier<States> = never,
7971
+ Output = never,
7972
+ OutputStates extends Machine.StateIdentifier<States> = never,
7973
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
7974
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
7975
+ >(
7976
+ machine:
7977
+ & Machine<
7978
+ States,
7979
+ Events,
7980
+ Input,
7981
+ UnhandledStates,
7982
+ E,
7983
+ R,
7984
+ InitialE,
7985
+ InitialR,
7986
+ FinalStates,
7987
+ Output,
7988
+ Emits,
7989
+ OutputStates,
7990
+ InputEvents,
7991
+ ParentEvents
7992
+ >
7993
+ & EnsureExecutable<States, UnhandledStates, OutputStates>,
7994
+ ...args: [...Machine.InputArgs<Input>]
7995
+ ) => Effect.Effect<
7996
+ Prepared<
7997
+ Machine.Snapshot<States>,
7998
+ Machine.EventInputOf<InputEvents>,
7999
+ | E
8000
+ | ActionError<R>
8001
+ | InfiniteTransitionError
8002
+ | MachineSchemaDecodeError
8003
+ | StoppedError,
8004
+ Output,
8005
+ Machine.EmittedEventOf<Emits>,
8006
+ | InitialE
8007
+ | E
8008
+ | ActionError<InitialR | R>
8009
+ | InfiniteTransitionError
8010
+ | MachineSchemaDecodeError
8011
+ | StartupError
8012
+ | StoppedError,
8013
+ ExcludeCompatibleRuntime<
8014
+ ExecutionServices<InitialR | R>,
8015
+ Machine.EventOf<Events>,
8016
+ Machine.EmitOf<Emits>
8017
+ >
8018
+ >
8019
+ > = internal.prepare as any
8020
+
7167
8021
  /**
7168
8022
  * Starts a machine.
7169
8023
  *
@@ -7196,7 +8050,7 @@ export const watch: <State, Event, Error = never, Output = never>(
7196
8050
  * const States = Machine.defineStates({ Idle })
7197
8051
  * const machine = Machine.make({
7198
8052
  * states: States.states,
7199
- * events: [],
8053
+ * events: Machine.events(),
7200
8054
  * initial: () => States.initial.Idle.from()
7201
8055
  * }).handle({ Idle: {} })
7202
8056
  *
@@ -7224,7 +8078,8 @@ export const start: <
7224
8078
  FinalStates extends Machine.StateIdentifier<States> = never,
7225
8079
  Output = never,
7226
8080
  OutputStates extends Machine.StateIdentifier<States> = never,
7227
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
8081
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
8082
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
7228
8083
  >(
7229
8084
  machine:
7230
8085
  & Machine<
@@ -7240,7 +8095,8 @@ export const start: <
7240
8095
  Output,
7241
8096
  Emits,
7242
8097
  OutputStates,
7243
- InputEvents
8098
+ InputEvents,
8099
+ ParentEvents
7244
8100
  >
7245
8101
  & EnsureExecutable<States, UnhandledStates, OutputStates>,
7246
8102
  ...args: [...Machine.InputArgs<Input>]
@@ -7253,7 +8109,8 @@ export const start: <
7253
8109
  | InfiniteTransitionError
7254
8110
  | MachineSchemaDecodeError
7255
8111
  | StoppedError,
7256
- Output
8112
+ Output,
8113
+ Machine.EmittedEventOf<Emits>
7257
8114
  >,
7258
8115
  | InitialE
7259
8116
  | E
@@ -7267,7 +8124,7 @@ export const start: <
7267
8124
  Machine.EventOf<Events>,
7268
8125
  Machine.EmitOf<Emits>
7269
8126
  >
7270
- > = internal.start
8127
+ > = internal.start as any
7271
8128
 
7272
8129
  /**
7273
8130
  * Starts a fresh managed runtime from a decoded logical snapshot.
@@ -7303,7 +8160,7 @@ export const start: <
7303
8160
  * const States = Machine.defineStates({ Idle })
7304
8161
  * const machine = Machine.make({
7305
8162
  * states: States.states,
7306
- * events: [],
8163
+ * events: Machine.events(),
7307
8164
  * initial: () => States.initial.Idle.from()
7308
8165
  * }).handle({ Idle: {} })
7309
8166
  *
@@ -7333,7 +8190,8 @@ export const resume: <
7333
8190
  FinalStates extends Machine.StateIdentifier<States> = never,
7334
8191
  Output = never,
7335
8192
  OutputStates extends Machine.StateIdentifier<States> = never,
7336
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
8193
+ InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
8194
+ ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
7337
8195
  >(
7338
8196
  machine:
7339
8197
  & Machine<
@@ -7349,7 +8207,8 @@ export const resume: <
7349
8207
  Output,
7350
8208
  Emits,
7351
8209
  OutputStates,
7352
- InputEvents
8210
+ InputEvents,
8211
+ ParentEvents
7353
8212
  >
7354
8213
  & EnsureExecutable<States, UnhandledStates, OutputStates>,
7355
8214
  snapshot: Machine.Snapshot<States>
@@ -7362,7 +8221,8 @@ export const resume: <
7362
8221
  | InfiniteTransitionError
7363
8222
  | MachineSchemaDecodeError
7364
8223
  | StoppedError,
7365
- Output
8224
+ Output,
8225
+ Machine.EmittedEventOf<Emits>
7366
8226
  >,
7367
8227
  MachineSchemaDecodeError,
7368
8228
  ExcludeCompatibleRuntime<
@@ -7370,4 +8230,4 @@ export const resume: <
7370
8230
  Machine.EventOf<Events>,
7371
8231
  Machine.EmitOf<Emits>
7372
8232
  >
7373
- > = internal.resume
8233
+ > = internal.resume as any