@typeonce/effect-machine 0.38.0 → 0.39.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 (61) hide show
  1. package/README.md +43 -36
  2. package/dist/Machine.d.ts +62 -88
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +11 -24
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/atom.d.ts.map +1 -1
  7. package/dist/internal/machine/atom.js.map +1 -1
  8. package/dist/internal/machine/declaration.d.ts +10 -3
  9. package/dist/internal/machine/declaration.d.ts.map +1 -1
  10. package/dist/internal/machine/declaration.js +47 -16
  11. package/dist/internal/machine/declaration.js.map +1 -1
  12. package/dist/internal/machine/errors.d.ts +15 -1
  13. package/dist/internal/machine/errors.d.ts.map +1 -1
  14. package/dist/internal/machine/errors.js +10 -0
  15. package/dist/internal/machine/errors.js.map +1 -1
  16. package/dist/internal/machine/initialDeclaration.d.ts +2 -2
  17. package/dist/internal/machine/initialDeclaration.d.ts.map +1 -1
  18. package/dist/internal/machine/initialDeclaration.js +8 -9
  19. package/dist/internal/machine/initialDeclaration.js.map +1 -1
  20. package/dist/internal/machine/machine.d.ts +26 -76
  21. package/dist/internal/machine/machine.d.ts.map +1 -1
  22. package/dist/internal/machine/machine.js +21 -16
  23. package/dist/internal/machine/machine.js.map +1 -1
  24. package/dist/internal/machine/planner.d.ts +216 -31
  25. package/dist/internal/machine/planner.d.ts.map +1 -1
  26. package/dist/internal/machine/planner.js +6 -12
  27. package/dist/internal/machine/planner.js.map +1 -1
  28. package/dist/internal/machine/process.d.ts +5 -9
  29. package/dist/internal/machine/process.d.ts.map +1 -1
  30. package/dist/internal/machine/process.js +19 -32
  31. package/dist/internal/machine/process.js.map +1 -1
  32. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  33. package/dist/internal/testing/machine/finiteModel.js +9 -12
  34. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  35. package/dist/testing/MachineTest.d.ts +7 -7
  36. package/dist/testing/MachineTest.js +7 -7
  37. package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
  38. package/dist/unstable/cluster/ClusterMachine.js +1 -1
  39. package/dist/unstable/reactivity/AtomMachine.d.ts +3 -3
  40. package/dist/unstable/reactivity/AtomMachine.js +3 -3
  41. package/docs/agent-guide.md +23 -30
  42. package/docs/machine-review.md +5 -6
  43. package/docs/root-api.md +27 -19
  44. package/package.json +5 -5
  45. package/src/Machine.ts +125 -163
  46. package/src/internal/machine/atom.ts +4 -7
  47. package/src/internal/machine/declaration.ts +56 -17
  48. package/src/internal/machine/errors.ts +22 -1
  49. package/src/internal/machine/initialDeclaration.ts +10 -12
  50. package/src/internal/machine/machine.ts +85 -465
  51. package/src/internal/machine/planner.ts +84 -190
  52. package/src/internal/machine/process.ts +80 -279
  53. package/src/internal/testing/machine/finiteModel.ts +7 -11
  54. package/src/testing/MachineTest.ts +7 -7
  55. package/src/unstable/cluster/ClusterMachine.ts +1 -1
  56. package/src/unstable/reactivity/AtomMachine.ts +3 -3
  57. package/dist/internal/machine/targetReference.d.ts +0 -15
  58. package/dist/internal/machine/targetReference.d.ts.map +0 -1
  59. package/dist/internal/machine/targetReference.js +0 -41
  60. package/dist/internal/machine/targetReference.js.map +0 -1
  61. package/src/internal/machine/targetReference.ts +0 -55
package/README.md CHANGED
@@ -34,7 +34,7 @@ Cluster and are exposed only through explicit integration boundaries.
34
34
  ## Install
35
35
 
36
36
  ```sh
37
- pnpm add @typeonce/effect-machine effect@4.0.0-rc.112
37
+ pnpm add @typeonce/effect-machine effect@4.0.0-rc.117
38
38
  ```
39
39
 
40
40
  `effect` is an exact peer dependency. Install the version above and upgrade it
@@ -42,13 +42,12 @@ in lockstep with this package.
42
42
 
43
43
  ## Quick start
44
44
 
45
- Declare the root once, derive its references, then add behavior with event maps:
45
+ Declare the root once, then add behavior with event maps:
46
46
 
47
47
  ```ts
48
48
  import { Machine } from "@typeonce/effect-machine"
49
49
  import { Effect, Schema } from "effect"
50
50
  const Root = Machine.state({ fields: { count: Schema.Number } })
51
- const targets = Machine.targets(Root)
52
51
  const Events = Machine.events({ Increment: { by: Schema.Number } })
53
52
  const Counter = Machine.make({
54
53
  root: Root,
@@ -57,7 +56,7 @@ const Counter = Machine.make({
57
56
  root: () => ({ count: 0 }),
58
57
  on: {
59
58
  Increment: {
60
- update: targets.root,
59
+ update: "root",
61
60
  data: ({ root, event }) => ({ count: root.count + event.by })
62
61
  }
63
62
  }
@@ -68,7 +67,7 @@ const program = Effect.scoped(Effect.gen(function*() {
68
67
  }))
69
68
  ```
70
69
 
71
- Root data is shared state. `update: targets.root` replaces that value while
70
+ Root data is shared state. `update: "root"` replaces that value while
72
71
  retaining the active child configuration and its running work. Ordinary
73
72
  transitions target a descendant; the root itself is not a destination.
74
73
 
@@ -97,10 +96,9 @@ const Root = Machine.state({
97
96
  Ready: {}
98
97
  }
99
98
  })
100
- const targets = Machine.targets(Root)
101
99
  const machine = Machine.make({ root: Root, input: Schema.Number, events: Machine.events({}) }).handle({
102
100
  root: ({ input }) => ({ seed: input }),
103
- initial: { target: targets.root.Loading, data: ({ root }) => ({ count: root.seed }) }
101
+ initial: { target: "Loading", data: ({ root }) => ({ count: root.seed }) }
104
102
  })
105
103
  ```
106
104
 
@@ -120,10 +118,9 @@ const Root = Machine.state({
120
118
  Network: { fields: { online: Schema.Boolean } }
121
119
  }
122
120
  })
123
- const targets = Machine.targets(Root)
124
121
  const machine = Machine.make({ root: Root, events: Machine.events({}) }).handle({
125
122
  initial: { Editor: { draft: "" }, Network: { online: false } },
126
- states: { Editor: { initial: { target: targets.root.Editor.Editing } } }
123
+ states: { Editor: { initial: { target: "Editor.Editing" } } }
127
124
  })
128
125
  ```
129
126
 
@@ -148,25 +145,24 @@ const Root = Machine.state({
148
145
  Failed: { fields: { message: Schema.String } }
149
146
  }
150
147
  })
151
- const targets = Machine.targets(Root)
152
148
  const Events = Machine.events({ Search: { query: Schema.String }, Reset: {} })
153
149
  const Search = Machine.make({
154
150
  root: Root,
155
151
  events: Events
156
152
  }).handle({
157
153
  initial: {
158
- target: targets.root.Idle
154
+ target: "Idle"
159
155
  },
160
156
  states: {
161
157
  Idle: {
162
158
  on: {
163
159
  Search: {
164
- target: targets.root.Loading,
160
+ target: "Loading",
165
161
  data: ({ event }) => ({ query: event.query })
166
162
  }
167
163
  }
168
164
  },
169
- Loading: { on: { Reset: { target: targets.root.Idle } } },
165
+ Loading: { on: { Reset: { target: "Idle" } } },
170
166
  Ready: {},
171
167
  Failed: {}
172
168
  }
@@ -196,12 +192,12 @@ const machine = Machine.make({
196
192
  events: Events,
197
193
  branches: {
198
194
  search: {
199
- loading: { target: targets.root.Loading, title: "Query supplied" },
200
- idle: { target: targets.root.Idle, title: "Empty query" }
195
+ loading: { target: "Loading", title: "Query supplied" },
196
+ idle: { target: "Idle", title: "Empty query" }
201
197
  }
202
198
  }
203
199
  }).handle({
204
- initial: { target: targets.root.Idle },
200
+ initial: { target: "Idle" },
205
201
  states: {
206
202
  Idle: {
207
203
  on: {
@@ -234,24 +230,31 @@ restart its lifecycle.
234
230
 
235
231
  ### Select destinations and retain owners
236
232
 
237
- All references come from the same root descriptor supplied to `make`:
238
-
239
- | Declaration | Meaning |
240
- | ----------------------------------------------------- | ------------------------------------------------------------------------- |
241
- | `{ target: targets.root.Checkout.Review, data: ... }` | Enter a declared destination with its value. |
242
- | `{ target: targets.root.Checkout, data: ... }` | Enter the declared initial configuration of a compound or parallel state. |
243
- | `{ history: targets.root.Checkout.recent }` | Restore a declared history state. |
244
- | `{ update: targets.root.Checkout, data: ... }` | Replace a retained active owner's value. |
245
- | `{ target: targets.root, input: ... }` | Reconstruct root and its initial children using fresh machine input. |
246
- | `{ update: targets.root, data: ... }` | Replace root data and retain active descendants. |
247
- | `{ none: true }` | Accept an event without changing the configuration. |
233
+ Destinations are dotted paths through the root descriptor supplied to `make`,
234
+ spelled the same way as snapshot paths. The root node is `"root"`, so a
235
+ top-level state cannot use that name. Paths are checked at compile time and
236
+ suggested by the editor:
237
+
238
+ | Declaration | Meaning |
239
+ | ------------------------------------------ | ------------------------------------------------------------------------- |
240
+ | `{ target: "Checkout.Review", data: ... }` | Enter a declared destination with its value. |
241
+ | `{ target: "Checkout", data: ... }` | Enter the declared initial configuration of a compound or parallel state. |
242
+ | `{ history: "Checkout.recent" }` | Restore a declared history state. |
243
+ | `{ update: "Checkout", data: ... }` | Replace a retained active owner's value. |
244
+ | `{ update: "root", data: ... }` | Replace root data and retain active descendants. |
245
+ | `{ initialize: ... }` | Reconstruct root and its initial children from fresh machine input. |
246
+ | `{ none: true }` | Accept an event without changing the configuration. |
247
+
248
+ Declarations written inline are checked in place. A declaration stored in a
249
+ variable before it reaches `make` or `.handle` needs `as const` so its paths
250
+ remain literal.
248
251
 
249
252
  An atomic transition can enter a destination and update one retained owner:
250
253
 
251
254
  ```ts
252
255
  Save: {
253
- target: targets.root.Checkout.Saving,
254
- update: targets.root.Checkout,
256
+ target: "Checkout.Saving",
257
+ update: "Checkout",
255
258
  data: ({ event, ancestors }) => ({
256
259
  target: { request: event.request },
257
260
  update: { ...ancestors.Checkout, revision: event.revision }
@@ -260,14 +263,18 @@ Save: {
260
263
  ```
261
264
 
262
265
  The complete replacement values are validated before either change is applied.
263
- Advanced construction declares both references in a branch and uses
266
+ Advanced construction declares both paths in a branch and uses
264
267
  `select.saved({ data: destinationValues, update: { data: ownerValues } })`.
265
268
  A retained owner must be active for that source and remain active through the
266
269
  transition. A sibling region's value cannot be updated through this operation.
267
270
 
268
271
  The runtime transition API does not replace arbitrary complete root
269
- configurations. Root targets accept fresh input and follow the initial declarations in `.handle`; history
270
- defaults retain complete subtree construction for restoration.
272
+ configurations. The root is not a destination. `initialize` restarts it: it
273
+ accepts fresh machine input, or `true` for a machine without input, and follows
274
+ the root constructor and initial declarations in `.handle`. Add `reenter: true`
275
+ to also exit and re-enter the root lifecycle. A branch declares
276
+ `{ initialize: true }` and its resolver supplies `select.branch({ input })`.
277
+ History defaults retain complete subtree construction for restoration.
271
278
 
272
279
  ### Protocols and ownership
273
280
 
@@ -318,7 +325,7 @@ const Search = Machine.make({
318
325
  children: { validation: ValidationChild }
319
326
  }).handle({
320
327
  initial: {
321
- target: Machine.targets(Root).root.Idle
328
+ target: "Idle"
322
329
  },
323
330
  states: {
324
331
  Idle: {},
@@ -326,8 +333,8 @@ const Search = Machine.make({
326
333
  invoke: {
327
334
  src: "load",
328
335
  input: ({ state }) => state.query,
329
- onDone: { target: targets.root.Ready, data: ({ output }) => ({ items: output }) },
330
- onFailure: { target: targets.root.Failed, data: ({ error }) => ({ message: error.message }) }
336
+ onDone: { target: "Ready", data: ({ output }) => ({ items: output }) },
337
+ onFailure: { target: "Failed", data: ({ error }) => ({ message: error.message }) }
331
338
  }
332
339
  },
333
340
  Ready: {},
@@ -368,7 +375,7 @@ const invocations = [
368
375
  onDone: { none: true },
369
376
  onFailure: { none: true }
370
377
  },
371
- { src: "timeout", onDone: { target: targets.root.Expired } },
378
+ { src: "timeout", onDone: { target: "Expired" } },
372
379
  { src: "worker", id: "worker", address: WorkerAddress, onSnapshot: { none: true } },
373
380
  { src: "validation", input: ({ state }) => ({ query: state.query }), onDone: { none: true } }
374
381
  ]
package/dist/Machine.d.ts CHANGED
@@ -102,7 +102,6 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
102
102
  * import { Schema } from "effect"
103
103
  * const events = Machine.events({ Add: { by: Schema.Number } })
104
104
  * const Root = Machine.state({ fields: { count: Schema.Number } })
105
- * const targets = Machine.targets(Root)
106
105
  * export const counter = Machine.make({
107
106
  * root: Root,
108
107
  * events
@@ -110,7 +109,7 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
110
109
  * root: () => ({ count: 0 }),
111
110
  * on: {
112
111
  * Add: {
113
- * update: targets.root,
112
+ * update: "root",
114
113
  * guard: ({ event }) => event.by > 0,
115
114
  * data: ({ root, event }) => ({ count: root.count + event.by })
116
115
  * }
@@ -210,12 +209,11 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
210
209
  * **Example**
211
210
  *
212
211
  * ```ts
213
- * const targets = Machine.targets(States)
214
212
  * const counter = definition.handle({ states: {
215
213
  * Count: {
216
214
  * on: {
217
215
  * Increment: {
218
- * update: targets.root.Count,
216
+ * update: "Count",
219
217
  * decoded: ({ event, state }) => new Count({ value: state.value + event.by })
220
218
  * }
221
219
  * }
@@ -1551,7 +1549,6 @@ export declare namespace Machine {
1551
1549
  /** @internal */
1552
1550
  readonly stateNodes: StateNodes;
1553
1551
  /** @internal */
1554
- /** @internal */
1555
1552
  readonly handlers: any;
1556
1553
  /** @internal */
1557
1554
  readonly initial: any;
@@ -3360,8 +3357,6 @@ export declare namespace Machine {
3360
3357
  * @since 0.4.0
3361
3358
  */
3362
3359
  type EventTransitionReturn<Transition> = Transition extends {
3363
- readonly initial: TargetReference<any, infer P, any>;
3364
- } ? InitialTarget<P> : Transition extends {
3365
3360
  readonly resolve?: infer Resolve;
3366
3361
  } ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never;
3367
3362
  /**
@@ -3968,11 +3963,10 @@ export declare namespace Machine {
3968
3963
  type ValidatePrograms<Sources> = {
3969
3964
  readonly [K in keyof Sources]: Sources[K] extends LazyProgramValue ? unknown : Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never : unknown;
3970
3965
  };
3971
- type ReferenceRoot<S extends StateSchemas> = Extract<S[""], StateNodeConfig>;
3972
- type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<ReferenceRoot<S>, P, P extends HistoryIdentifier<S> ? "history" : P extends ChoiceIdentifier<S> ? "choice" : "state">;
3973
- type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
3974
- readonly [P in Paths]: ReferenceAt<S, P>;
3975
- }[Paths];
3966
+ type PathName<P extends string> = P extends "" ? "root" : P;
3967
+ type PathOf<Name> = Name extends "root" ? "" : Name extends string ? Name : never;
3968
+ type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = PathName<P>;
3969
+ type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = PathName<Paths>;
3976
3970
  type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">;
3977
3971
  type RootSchemas<Root extends StateNodeConfig> = {
3978
3972
  readonly "": Root;
@@ -3983,7 +3977,7 @@ export declare namespace Machine {
3983
3977
  readonly title?: string;
3984
3978
  } & ({
3985
3979
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
3986
- readonly target: ReferenceUnion<S, DestinationPath<S>> | TargetReference<Root, "", "state">;
3980
+ readonly target: ReferenceUnion<S, DestinationPath<S>>;
3987
3981
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
3988
3982
  readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
3989
3983
  /** Enters a compound or parallel subtree through its declared initialization. */
@@ -3992,6 +3986,21 @@ export declare namespace Machine {
3992
3986
  readonly history?: never;
3993
3987
  /** Accepts the event without selecting a new destination. */
3994
3988
  readonly none?: never;
3989
+ /** Reconstructs root and its initial children from fresh machine input. */
3990
+ readonly initialize?: never;
3991
+ } | {
3992
+ /** Reconstructs root and its initial children from fresh machine input supplied by the resolver. */
3993
+ readonly initialize: true;
3994
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
3995
+ readonly target?: never;
3996
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
3997
+ readonly update?: never;
3998
+ /** Enters a compound or parallel subtree through its declared initialization. */
3999
+ readonly initial?: never;
4000
+ /** Restores the declared history reference, using its fallback on first entry. */
4001
+ readonly history?: never;
4002
+ /** Accepts the event without selecting a new destination. */
4003
+ readonly none?: never;
3995
4004
  } | {
3996
4005
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
3997
4006
  readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
@@ -4003,6 +4012,8 @@ export declare namespace Machine {
4003
4012
  readonly history?: never;
4004
4013
  /** Accepts the event without selecting a new destination. */
4005
4014
  readonly none?: never;
4015
+ /** Reconstructs root and its initial children from fresh machine input. */
4016
+ readonly initialize?: never;
4006
4017
  } | {
4007
4018
  /** Restores the declared history reference, using its fallback on first entry. */
4008
4019
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
@@ -4014,6 +4025,8 @@ export declare namespace Machine {
4014
4025
  readonly initial?: never;
4015
4026
  /** Accepts the event without selecting a new destination. */
4016
4027
  readonly none?: never;
4028
+ /** Reconstructs root and its initial children from fresh machine input. */
4029
+ readonly initialize?: never;
4017
4030
  } | {
4018
4031
  /** Accepts the event without selecting a new destination. */
4019
4032
  readonly none: true;
@@ -4025,6 +4038,8 @@ export declare namespace Machine {
4025
4038
  readonly initial?: never;
4026
4039
  /** Restores the declared history reference, using its fallback on first entry. */
4027
4040
  readonly history?: never;
4041
+ /** Reconstructs root and its initial children from fresh machine input. */
4042
+ readonly initialize?: never;
4028
4043
  });
4029
4044
  type BranchDefinitions<Root extends StateNodeConfig> = Readonly<Record<string, Readonly<Record<string, BranchDeclaration<Root>>>>>;
4030
4045
  /** Source programs and named topology declarations captured by a machine definition. */
@@ -4046,7 +4061,7 @@ export declare namespace Machine {
4046
4061
  readonly "~input": infer I extends Schema.Top;
4047
4062
  } ? I : typeof Schema.Void;
4048
4063
  type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
4049
- type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
4064
+ type RefPath<R> = PathOf<R>;
4050
4065
  type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? {
4051
4066
  readonly data?: never;
4052
4067
  readonly decoded?: never;
@@ -4096,6 +4111,8 @@ export declare namespace Machine {
4096
4111
  readonly update?: never;
4097
4112
  }, Target<S, P>> : never;
4098
4113
  type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D, R = {}> = D extends {
4114
+ readonly initialize: true;
4115
+ } ? TargetSelection<ObjectSelection<S, Src, Extract<"", StateNodeIdentifier<S>>, R>, "", "state", "branch"> : D extends {
4099
4116
  readonly target: infer Ref;
4100
4117
  } ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
4101
4118
  readonly update: infer Update;
@@ -4139,18 +4156,19 @@ export declare namespace Machine {
4139
4156
  readonly from?: never;
4140
4157
  readonly decoded?: never;
4141
4158
  } : P extends StateIdentifier<S> ? InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
4142
- type InlineRoot<S extends StateSchemas, C, R> = {
4143
- readonly target: ReferenceAt<S, Extract<"", StateNodeIdentifier<S>>>;
4159
+ type InlineRoot<C, R> = {
4160
+ /**
4161
+ * Reconstructs root and its initial children from fresh machine input.
4162
+ * Machines without an input schema use `true`.
4163
+ */
4164
+ readonly initialize: RegisteredInput<R> extends typeof Schema.Void ? true : DataValue<C, RegisteredInput<R>["Type"]>;
4165
+ readonly target?: never;
4144
4166
  readonly update?: never;
4145
4167
  readonly branches?: never;
4146
4168
  readonly resolve?: never;
4147
4169
  readonly history?: never;
4148
4170
  readonly none?: never;
4149
- } & (RegisteredInput<R> extends typeof Schema.Void ? {
4150
- readonly input?: never;
4151
- } : {
4152
- /** Fresh machine input used to reconstruct root and its initial children. */ readonly input: DataValue<C, RegisteredInput<R>["Type"]>;
4153
- });
4171
+ };
4154
4172
  type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
4155
4173
  readonly [P in DestinationPath<S>]: {
4156
4174
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
@@ -4294,7 +4312,7 @@ export declare namespace Machine {
4294
4312
  * @category models
4295
4313
  * @since 0.34.0
4296
4314
  */
4297
- type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & DeclarationData<(InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineRoot<S, C, R> | {
4315
+ type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & DeclarationData<(InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineRoot<C, R> | {
4298
4316
  /** Restores the declared history reference, using its fallback on first entry. */
4299
4317
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
4300
4318
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
@@ -4445,7 +4463,7 @@ export declare namespace Machine {
4445
4463
  readonly states: infer Children extends StateSchemas;
4446
4464
  } ? {
4447
4465
  readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: {
4448
- readonly target: TargetReference<ReferenceRoot<S>, JoinPath<Src, K>, Children[K] extends ChoiceStateNodeConfig ? "choice" : "state">;
4466
+ readonly target: JoinPath<Src, K>;
4449
4467
  } & InitialData<C, Children[K]>;
4450
4468
  }[ActiveStateKey<Children> | ChoiceStateKey<Children>] : never;
4451
4469
  type InitialRegions<C, Children extends StateSchemas> = {
@@ -4602,12 +4620,10 @@ export declare namespace Machine {
4602
4620
  readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
4603
4621
  readonly history?: never;
4604
4622
  }) : never);
4605
- type ValidateObjectTransition<T> = ("input" extends keyof T ? T extends {
4606
- readonly target: TargetReference<any, "", "state">;
4607
- } ? unknown : {
4608
- readonly input: never;
4623
+ type ValidateObjectTransition<T> = ("initialize" extends keyof T ? {
4624
+ readonly [K in Exclude<keyof T, "initialize" | "guard" | "reenter">]: never;
4609
4625
  } : unknown) & {
4610
- readonly [K in Exclude<keyof T, "target" | "update" | "input" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4626
+ readonly [K in Exclude<keyof T, "target" | "update" | "initialize" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4611
4627
  } & (T extends {
4612
4628
  /** Set to true when the resolver can explicitly return decline(). */
4613
4629
  readonly declinable: infer D;
@@ -4795,7 +4811,7 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
4795
4811
  /**
4796
4812
  * Defines root or nested state schemas while preserving the exact child topology.
4797
4813
  *
4798
- * Pass the root descriptor to {@link make} and {@link targets}. Nested states
4814
+ * Pass the root descriptor to {@link make}. Nested states
4799
4815
  * can be declared inline or reused by mounting a descriptor in multiple places.
4800
4816
  * Initial edges and value constructors belong in the handler tree.
4801
4817
  *
@@ -4829,56 +4845,16 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
4829
4845
  * @since 0.15.0
4830
4846
  */
4831
4847
  export declare const state: StateConstructor;
4832
- /**
4833
- * An opaque reference to one node in a declared state tree.
4834
- *
4835
- * @category models
4836
- * @since 0.34.0
4837
- */
4838
- export interface TargetReference<Root extends Machine.StateNodeConfig, Path extends string, Kind extends "state" | "choice" | "history"> {
4839
- readonly [internal.TargetReferenceTypeId]: {
4840
- readonly root: {
4841
- readonly node: Root;
4842
- };
4843
- readonly path: Path;
4844
- readonly kind: Kind;
4845
- };
4846
- }
4847
- type TargetReferenceTree<Root extends Machine.StateNodeConfig, Node, Path extends string> = TargetReference<Root, Path, Node extends {
4848
- readonly type: "history";
4849
- } ? "history" : Node extends {
4850
- readonly type: "choice";
4851
- } ? "choice" : "state"> & (Node extends {
4852
- /** Child handlers nested according to the declared root topology. */
4853
- readonly states: infer Children;
4854
- } ? {
4855
- readonly [Key in Extract<keyof Children, string>]: TargetReferenceTree<Root, Children[Key], Machine.JoinPath<Path, Key>>;
4856
- } : {});
4857
- /**
4858
- * References for every path in a declared root tree.
4859
- *
4860
- * @category models
4861
- * @since 0.34.0
4862
- */
4863
- export interface Targets<Root extends Machine.StateNodeConfig> {
4864
- /** Root data owner and the starting point for descendant state references. */
4865
- readonly root: TargetReferenceTree<Root, Root, "">;
4866
- }
4867
- /**
4868
- * Derives immutable state references from a root descriptor.
4869
- *
4870
- * References follow the declared tree: `targets.root.Checkout.Review`.
4871
- * Creating references does not construct state values or start machine work.
4872
- *
4873
- * @category constructors
4874
- * @since 0.34.0
4875
- */
4876
- export declare const targets: <const Root extends Machine.StateNodeConfig>(root: State<Root>) => Targets<Root>;
4877
4848
  type UniqueSourceNames<F, S, T, L, C> = [
4878
4849
  Extract<keyof F, keyof S | keyof T | keyof L | keyof C> | Extract<keyof S, keyof T | keyof L | keyof C> | Extract<keyof T, keyof L | keyof C> | Extract<keyof L, keyof C>
4879
4850
  ] extends [never] ? unknown : {
4880
4851
  readonly "~effect/Machine/DuplicateSourceName": never;
4881
4852
  };
4853
+ type ReservedRootName<Root> = Root extends {
4854
+ readonly states: infer Children;
4855
+ } ? "root" extends keyof Children ? {
4856
+ readonly "~effect/Machine/ReservedRootStateName": never;
4857
+ } : unknown : unknown;
4882
4858
  type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Machine.BranchDefinitions<Root>> = {
4883
4859
  /** Lazy Effects or functions with one required input, invoked by registered name. */
4884
4860
  readonly effects?: Effects & Machine.ValidatePrograms<Effects>;
@@ -4900,7 +4876,7 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
4900
4876
  readonly root: {
4901
4877
  readonly [StateTypeId]: typeof StateTypeId;
4902
4878
  readonly node: Root;
4903
- };
4879
+ } & ReservedRootName<NoInfer<Root>>;
4904
4880
  /** Public events accepted by independently running machine references. */
4905
4881
  readonly events: Machine.EventProtocol<"public", InputEvents> & ValidateInputEventProtocol<NoInfer<InputEvents>>;
4906
4882
  /** Machine-local events used by raised events and other internal deliveries. */
@@ -4977,13 +4953,12 @@ interface Make {
4977
4953
  * }
4978
4954
  * const States = Machine.state({ states: { Count } })
4979
4955
  * const Events = Machine.eventsFromSchemas(Increment)
4980
- * const targets = Machine.targets(States)
4981
4956
  * const counter = Machine.make({
4982
4957
  * root: States,
4983
4958
  * events: Events
4984
4959
  * }).handle({
4985
4960
  * initial: {
4986
- * target: Machine.targets(States).root.Count,
4961
+ * target: "Count",
4987
4962
  * decoded: true,
4988
4963
  * data: new Count({ value: 0 })
4989
4964
  * },
@@ -4991,7 +4966,7 @@ interface Make {
4991
4966
  * Count: {
4992
4967
  * on: {
4993
4968
  * Increment: {
4994
- * update: targets.root.Count,
4969
+ * update: "Count",
4995
4970
  * decoded: true,
4996
4971
  * data: ({ event, state }) => new Count({ value: state.value + event.by })
4997
4972
  * }
@@ -5189,7 +5164,7 @@ export declare const emittedEventsFromSchemas: {
5189
5164
  * events: Machine.eventsFromSchemas()
5190
5165
  * }).handle({
5191
5166
  * initial: {
5192
- * target: Machine.targets(States).root.Idle
5167
+ * target: "Idle"
5193
5168
  * },
5194
5169
  * states: {
5195
5170
  * Idle: {}
@@ -5238,7 +5213,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
5238
5213
  * events: Machine.eventsFromSchemas()
5239
5214
  * }).handle({
5240
5215
  * initial: {
5241
- * target: Machine.targets(States).root.Idle
5216
+ * target: "Idle"
5242
5217
  * },
5243
5218
  * states: {
5244
5219
  * Idle: {}
@@ -5263,7 +5238,7 @@ type TransitionBranchRecordError<Message extends string, Key extends PropertyKey
5263
5238
  type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol | `${number}` | "NaN" | "Infinity" | "-Infinity">;
5264
5239
  type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? {
5265
5240
  readonly [K in keyof Branches]: {
5266
- readonly [Extra in Exclude<keyof Branches[K], "target" | "update" | "initial" | "history" | "none" | "title">]: never;
5241
+ readonly [Extra in Exclude<keyof Branches[K], "target" | "update" | "initialize" | "initial" | "history" | "none" | "title">]: never;
5267
5242
  } & (Branches[K] extends {
5268
5243
  readonly title: "";
5269
5244
  } ? {
@@ -5301,7 +5276,7 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
5301
5276
  * events: Machine.eventsFromSchemas()
5302
5277
  * }).handle({
5303
5278
  * initial: {
5304
- * target: Machine.targets(States).root.Idle
5279
+ * target: "Idle"
5305
5280
  * },
5306
5281
  * states: {
5307
5282
  * Idle: {}
@@ -5474,7 +5449,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
5474
5449
  * events: Machine.eventsFromSchemas(),
5475
5450
  * internalEvents
5476
5451
  * }).handle({
5477
- * initial: { target: Machine.targets(Root).root.Idle },
5452
+ * initial: { target: "Idle" },
5478
5453
  * states: { Idle: { on: { Loaded: { none: true } } } }
5479
5454
  * })
5480
5455
  *
@@ -5520,18 +5495,17 @@ export declare const can: {
5520
5495
  * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
5521
5496
  * }
5522
5497
  * const States = Machine.state({ states: { Off, On } })
5523
- * const targets = Machine.targets(States)
5524
5498
  * const machine = Machine.make({
5525
5499
  * root: States,
5526
5500
  * events: Machine.eventsFromSchemas(Toggle)
5527
5501
  * }).handle({
5528
5502
  * initial: {
5529
- * target: Machine.targets(States).root.Off
5503
+ * target: "Off"
5530
5504
  * },
5531
5505
  * states: {
5532
5506
  * Off: {
5533
5507
  * on: {
5534
- * Toggle: { target: targets.root.On }
5508
+ * Toggle: { target: "On" }
5535
5509
  * }
5536
5510
  * },
5537
5511
  * On: {}
@@ -5775,7 +5749,7 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
5775
5749
  * events: Machine.eventsFromSchemas()
5776
5750
  * }).handle({
5777
5751
  * initial: {
5778
- * target: Machine.targets(States).root.Idle
5752
+ * target: "Idle"
5779
5753
  * },
5780
5754
  * states: {
5781
5755
  * Idle: {}
@@ -5830,7 +5804,7 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
5830
5804
  * events: Machine.eventsFromSchemas()
5831
5805
  * }).handle({
5832
5806
  * initial: {
5833
- * target: Machine.targets(States).root.Idle
5807
+ * target: "Idle"
5834
5808
  * },
5835
5809
  * states: {
5836
5810
  * Idle: {}