@typeonce/effect-machine 0.34.0 → 0.36.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 (98) hide show
  1. package/README.md +98 -33
  2. package/dist/Machine.d.ts +408 -483
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +126 -87
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/command.d.ts +0 -1
  7. package/dist/internal/machine/command.d.ts.map +1 -1
  8. package/dist/internal/machine/command.js +0 -14
  9. package/dist/internal/machine/command.js.map +1 -1
  10. package/dist/internal/machine/configuration.d.ts +0 -1
  11. package/dist/internal/machine/configuration.d.ts.map +1 -1
  12. package/dist/internal/machine/configuration.js +15 -21
  13. package/dist/internal/machine/configuration.js.map +1 -1
  14. package/dist/internal/machine/construction.d.ts +9 -0
  15. package/dist/internal/machine/construction.d.ts.map +1 -0
  16. package/dist/internal/machine/construction.js +132 -0
  17. package/dist/internal/machine/construction.js.map +1 -0
  18. package/dist/internal/machine/declaration.d.ts +1 -0
  19. package/dist/internal/machine/declaration.d.ts.map +1 -1
  20. package/dist/internal/machine/declaration.js +3 -8
  21. package/dist/internal/machine/declaration.js.map +1 -1
  22. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  23. package/dist/internal/machine/executionPlan.js +21 -27
  24. package/dist/internal/machine/executionPlan.js.map +1 -1
  25. package/dist/internal/machine/implementation.d.ts +2 -3
  26. package/dist/internal/machine/implementation.d.ts.map +1 -1
  27. package/dist/internal/machine/implementation.js.map +1 -1
  28. package/dist/internal/machine/initialDeclaration.d.ts +14 -0
  29. package/dist/internal/machine/initialDeclaration.d.ts.map +1 -0
  30. package/dist/internal/machine/initialDeclaration.js +137 -0
  31. package/dist/internal/machine/initialDeclaration.js.map +1 -0
  32. package/dist/internal/machine/machine.d.ts +0 -2
  33. package/dist/internal/machine/machine.d.ts.map +1 -1
  34. package/dist/internal/machine/machine.js +101 -282
  35. package/dist/internal/machine/machine.js.map +1 -1
  36. package/dist/internal/machine/planner.d.ts +8 -0
  37. package/dist/internal/machine/planner.d.ts.map +1 -1
  38. package/dist/internal/machine/planner.js +86 -82
  39. package/dist/internal/machine/planner.js.map +1 -1
  40. package/dist/internal/machine/protocol.d.ts +1 -1
  41. package/dist/internal/machine/protocol.d.ts.map +1 -1
  42. package/dist/internal/machine/protocol.js.map +1 -1
  43. package/dist/internal/machine/stateDefinition.d.ts +1 -1
  44. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  45. package/dist/internal/machine/stateDefinition.js +1 -13
  46. package/dist/internal/machine/stateDefinition.js.map +1 -1
  47. package/dist/internal/machine/targetReference.d.ts.map +1 -1
  48. package/dist/internal/machine/targetReference.js +14 -4
  49. package/dist/internal/machine/targetReference.js.map +1 -1
  50. package/dist/internal/machine/topology.d.ts +6 -0
  51. package/dist/internal/machine/topology.d.ts.map +1 -1
  52. package/dist/internal/machine/topology.js +3 -2
  53. package/dist/internal/machine/topology.js.map +1 -1
  54. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  55. package/dist/internal/testing/machine/finiteModel.js +51 -82
  56. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  57. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  58. package/dist/internal/testing/machine/verification.js +7 -1
  59. package/dist/internal/testing/machine/verification.js.map +1 -1
  60. package/dist/testing/MachineTest.d.ts +105 -73
  61. package/dist/testing/MachineTest.d.ts.map +1 -1
  62. package/dist/testing/MachineTest.js +105 -73
  63. package/dist/testing/MachineTest.js.map +1 -1
  64. package/dist/unstable/cluster/ClusterMachine.d.ts +13 -8
  65. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  66. package/dist/unstable/cluster/ClusterMachine.js +13 -8
  67. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  68. package/dist/unstable/reactivity/AtomMachine.d.ts +41 -24
  69. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  70. package/dist/unstable/reactivity/AtomMachine.js +41 -24
  71. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  72. package/docs/agent-guide.md +37 -34
  73. package/docs/root-api.md +143 -190
  74. package/package.json +1 -1
  75. package/src/Machine.ts +631 -872
  76. package/src/internal/machine/command.ts +0 -16
  77. package/src/internal/machine/configuration.ts +13 -30
  78. package/src/internal/machine/construction.ts +147 -0
  79. package/src/internal/machine/declaration.ts +4 -7
  80. package/src/internal/machine/executionPlan.ts +20 -25
  81. package/src/internal/machine/implementation.ts +2 -3
  82. package/src/internal/machine/initialDeclaration.ts +157 -0
  83. package/src/internal/machine/machine.ts +118 -396
  84. package/src/internal/machine/planner.ts +97 -99
  85. package/src/internal/machine/protocol.ts +3 -3
  86. package/src/internal/machine/stateDefinition.ts +1 -15
  87. package/src/internal/machine/targetReference.ts +19 -4
  88. package/src/internal/machine/topology.ts +7 -2
  89. package/src/internal/testing/machine/finiteModel.ts +60 -132
  90. package/src/internal/testing/machine/verification.ts +7 -1
  91. package/src/testing/MachineTest.ts +105 -73
  92. package/src/unstable/cluster/ClusterMachine.ts +13 -8
  93. package/src/unstable/reactivity/AtomMachine.ts +41 -24
  94. package/dist/internal/machine/targetBuilder.d.ts +0 -16
  95. package/dist/internal/machine/targetBuilder.d.ts.map +0 -1
  96. package/dist/internal/machine/targetBuilder.js +0 -333
  97. package/dist/internal/machine/targetBuilder.js.map +0 -1
  98. package/src/internal/machine/targetBuilder.ts +0 -525
@@ -1203,7 +1203,6 @@ const makeStateTree = (
1203
1203
  } else if (node._tag === "Compound") {
1204
1204
  tree[node.key] = {
1205
1205
  schema,
1206
- initial: node.initial,
1207
1206
  states: makeStateTree(node.states, path)
1208
1207
  }
1209
1208
  } else {
@@ -1218,101 +1217,52 @@ const makeStateTree = (
1218
1217
  return tree
1219
1218
  }
1220
1219
 
1221
- const selectSnapshot = (
1222
- builder: Record<string, any>,
1220
+ const construction = (
1223
1221
  path: string,
1224
1222
  byPath: ReadonlyMap<string, FlatFiniteState>,
1225
1223
  requestedParts: ReadonlyArray<string> | undefined,
1226
1224
  index: number,
1227
1225
  sourcePath?: string,
1228
1226
  requestedValue?: number
1229
- ): unknown => {
1227
+ ): Readonly<Record<string, unknown>> => {
1230
1228
  const state = byPath.get(path)!
1231
- if (state.node._tag === "History") {
1232
- throw new Error(`MachineTest.compileModel cannot construct active history state "${path}"`)
1233
- }
1234
- if (state.node._tag === "Choice") {
1235
- return (builder[state.node.key] as () => unknown)()
1236
- }
1237
- const method = builder[state.node.key].decoded as (
1238
- value: unknown,
1239
- selector?: (builder: any) => unknown
1240
- ) => unknown
1241
- const value = stateValue(state, path === requestedParts?.join(".") ? requestedValue : undefined)
1242
- if (state.node._tag === "Atomic" || state.node._tag === "Final") return method(value)
1243
-
1229
+ if (state.node._tag === "History") throw new Error(`MachineTest cannot construct history state "${path}"`)
1230
+ if (state.node._tag === "Choice") return {}
1231
+ const data = stateValue(state, path === requestedParts?.join(".") ? requestedValue : undefined)
1232
+ if (state.node._tag === "Atomic" || state.node._tag === "Final") return { data, decoded: true }
1244
1233
  const requestedChild = requestedParts?.[index + 1]
1234
+ let keys: ReadonlyArray<string>
1245
1235
  if (state.node._tag === "Parallel") {
1246
- const parallel = state.node
1247
- const sourceInside = sourcePath === path || sourcePath?.startsWith(`${path}.`) === true
1248
- if (sourceInside) {
1249
- const childKey = requestedChild ?? (sourcePath === path
1250
- ? parallel.states.find((child) => child._tag !== "History" && child._tag !== "Choice")!.key
1251
- : sourcePath!.slice(path.length + 1).split(".")[0]!)
1252
- return method(
1253
- value,
1254
- (children: Record<string, any>) =>
1255
- selectSnapshot(
1256
- children,
1257
- `${path}.${childKey}`,
1258
- byPath,
1259
- requestedChild === undefined ? undefined : requestedParts,
1260
- index + 1,
1261
- sourcePath,
1262
- requestedValue
1263
- )
1236
+ const inside = sourcePath === path || sourcePath?.startsWith(`${path}.`) === true
1237
+ keys = inside ?
1238
+ [
1239
+ requestedChild ?? (sourcePath === path
1240
+ ? state.node.states.find((child) => child._tag !== "History" && child._tag !== "Choice")!.key
1241
+ : sourcePath!.slice(path.length + 1).split(".")[0]!)
1242
+ ]
1243
+ : state.node.states.filter((child) => child._tag !== "History" && child._tag !== "Choice").map((child) =>
1244
+ child.key
1264
1245
  )
1265
- }
1266
- return method(value, (children: Record<string, any>) => {
1267
- let selected: unknown = children
1268
- for (const child of parallel.states.filter((child) => child._tag !== "History" && child._tag !== "Choice")) {
1269
- const isRequestedRegion = requestedChild === child.key
1270
- selected = selectSnapshot(
1271
- selected as Record<string, any>,
1272
- `${path}.${child.key}`,
1246
+ } else keys = [requestedChild ?? state.node.initial]
1247
+ return {
1248
+ data,
1249
+ decoded: true,
1250
+ states: Object.fromEntries(
1251
+ keys.map((
1252
+ key
1253
+ ) => [
1254
+ key,
1255
+ construction(
1256
+ `${path}.${key}`,
1273
1257
  byPath,
1274
- isRequestedRegion ? requestedParts : undefined,
1258
+ key === requestedChild ? requestedParts : undefined,
1275
1259
  index + 1,
1276
1260
  sourcePath,
1277
1261
  requestedValue
1278
1262
  )
1279
- }
1280
- return selected
1281
- })
1282
- }
1283
-
1284
- const childKey = requestedChild ?? state.node.initial
1285
- const childPath = `${path}.${childKey}`
1286
- return method(
1287
- value,
1288
- (children: Record<string, any>) =>
1289
- selectSnapshot(
1290
- children,
1291
- childPath,
1292
- byPath,
1293
- requestedChild === undefined ? undefined : requestedParts,
1294
- index + 1,
1295
- sourcePath,
1296
- requestedValue
1297
- )
1298
- )
1299
- }
1300
-
1301
- const findSnapshot = (snapshot: unknown, path: string): unknown => {
1302
- if (typeof snapshot !== "object" || snapshot === null) return undefined
1303
- const current = snapshot as Record<string, unknown>
1304
- if (current.path === path) return snapshot
1305
- if (current.state !== undefined) {
1306
- const found = findSnapshot(current.state, path)
1307
- if (found !== undefined) return found
1308
- }
1309
- if (typeof current.states === "object" && current.states !== null) {
1310
- for (const child of Object.values(current.states)) {
1311
- const found = findSnapshot(child, path)
1312
- if (found !== undefined) return found
1313
- }
1263
+ ])
1264
+ )
1314
1265
  }
1315
- return undefined
1316
1266
  }
1317
1267
 
1318
1268
  const selectableDefinitionTarget = (
@@ -1350,47 +1300,19 @@ const selectDefinitionTarget = (
1350
1300
  }
1351
1301
 
1352
1302
  const resolveDefinitionTarget = (
1353
- builder: any,
1303
+ build: (config?: unknown) => unknown,
1354
1304
  source: string,
1355
1305
  target: string,
1356
1306
  byPath: ReadonlyMap<string, FlatFiniteState>,
1357
1307
  value?: number
1358
1308
  ): unknown => {
1359
1309
  const selected = byPath.get(target)!
1360
- if (selected.node._tag === "History") return builder()
1361
- if (selected.root !== byPath.get(source)!.root) {
1362
- const parts = target.split(".")
1363
- return selectSnapshot({ [parts[0]!]: builder }, parts[0]!, byPath, parts, 0, source, value)
1364
- }
1365
- const selectable = selectableDefinitionTarget(source, target, byPath)
1366
- if (selectable !== target) {
1367
- const bound = byPath.get(selectable)!
1368
- const parts = target.split(".")
1369
- return selectSnapshot(
1370
- { [bound.node.key]: builder },
1371
- selectable,
1372
- byPath,
1373
- parts,
1374
- selectable.split(".").length - 1,
1375
- source,
1376
- value
1377
- )
1378
- }
1379
- if (selected.node._tag === "Choice") return builder()
1380
- const input = { value: value ?? selected.node.value }
1381
- if (selected.node._tag === "Compound" || selected.node._tag === "Parallel") {
1382
- const parts = target.split(".")
1383
- return selectSnapshot(
1384
- { [selected.node.key]: builder },
1385
- target,
1386
- byPath,
1387
- parts,
1388
- parts.length - 1,
1389
- source,
1390
- value
1391
- )
1392
- }
1393
- return builder.from(input)
1310
+ if (selected.node._tag === "History") return build()
1311
+ const parts = target.split(".")
1312
+ const path = selected.root !== byPath.get(source)!.root
1313
+ ? parts[0]!
1314
+ : selectableDefinitionTarget(source, target, byPath)
1315
+ return build(construction(path, byPath, parts, path.split(".").length - 1, source, value))
1394
1316
  }
1395
1317
 
1396
1318
  const makeHandlers = (
@@ -1449,16 +1371,15 @@ const makeHandlers = (
1449
1371
  if (child._tag !== "History") return []
1450
1372
  return [[child.key, {
1451
1373
  default: ({ target: root }: { readonly target: any }) =>
1452
- root.from((target: Record<string, any>) => {
1453
- const fallback = byPath.get(child.fallback)!
1454
- const parts = child.fallback.split(".")
1455
- const completeRoot = selectSnapshot(target, fallback.root, byPath, parts, 0)
1456
- if (findSnapshot(completeRoot, path) === undefined) {
1457
- throw new Error(
1458
- `MachineTest.compileModel could not construct history fallback for "${path}.${child.key}"`
1374
+ root({
1375
+ states: {
1376
+ [byPath.get(child.fallback)!.root]: construction(
1377
+ byPath.get(child.fallback)!.root,
1378
+ byPath,
1379
+ child.fallback.split("."),
1380
+ 0
1459
1381
  )
1460
1382
  }
1461
- return completeRoot
1462
1383
  })
1463
1384
  }]]
1464
1385
  }))
@@ -1473,17 +1394,20 @@ const makeHandlers = (
1473
1394
  ...(Object.keys(history).length === 0 ? {} : { history }),
1474
1395
  ...(node._tag === "Compound"
1475
1396
  ? {
1476
- initialize: ({ builder }: any) => builder.decoded(stateValue(byPath.get(`${path}.${node.initial}`)!))
1397
+ initial: {
1398
+ target: `${path}.${node.initial}`.split(".").reduce((ref, key) => ref[key], references),
1399
+ ...(byPath.get(`${path}.${node.initial}`)!.node._tag === "Choice" ? {} : {
1400
+ decoded: true,
1401
+ data: stateValue(byPath.get(`${path}.${node.initial}`)!)
1402
+ })
1403
+ }
1477
1404
  }
1478
1405
  : {
1479
- initialize: ({ builder }: any) =>
1406
+ initial: Object.fromEntries(
1480
1407
  node.states
1481
1408
  .filter((child) => child._tag !== "History" && child._tag !== "Choice")
1482
- .reduce(
1483
- (current: any, child) =>
1484
- current[child.key].decoded(stateValue(byPath.get(`${path}.${child.key}`)!)),
1485
- builder
1486
- )
1409
+ .map((child) => [child.key, { decoded: true, data: stateValue(byPath.get(`${path}.${child.key}`)!) }])
1410
+ )
1487
1411
  }),
1488
1412
  states: makeHandlers(node.states, path, byPath, transitions, references, branches)
1489
1413
  }
@@ -1508,7 +1432,7 @@ export const compileModel = (model: FiniteModel): Machine.Machine.Any => {
1508
1432
  const flattened = validateModel(model)
1509
1433
  const byPath = new Map(flattened.map((state) => [state.path, state]))
1510
1434
  const stateTree = makeStateTree(model.roots, undefined)
1511
- const defined = Machine.state({ initial: model.initial, states: stateTree } as any)
1435
+ const defined = Machine.state({ states: stateTree } as any)
1512
1436
  const eventSchemas = model.events.map((event) => Schema.TaggedStruct(event, {}))
1513
1437
  const initial = byPath.get(model.initial)!
1514
1438
  const transitions = new Map(model.transitions.map((transition) => [
@@ -1524,7 +1448,11 @@ export const compileModel = (model: FiniteModel): Machine.Machine.Any => {
1524
1448
  } as any)
1525
1449
  return machine.handle(
1526
1450
  {
1527
- initialize: ({ builder }: any) => builder.decoded(stateValue(initial)),
1451
+ initial: {
1452
+ target: (Machine.targets(defined).root as unknown as Record<string, unknown>)[model.initial],
1453
+ decoded: true,
1454
+ data: stateValue(initial)
1455
+ },
1528
1456
  states: handlers
1529
1457
  } as any
1530
1458
  ) as Machine.Machine.Any
@@ -1738,7 +1738,13 @@ export const verify = <M extends AnyMachine>(
1738
1738
  const node = byPath.get(path)
1739
1739
  if (node?.type !== "compound") continue
1740
1740
  const child = node.children.find((child) => starting.active.has(child))
1741
- if (byPath.get(node.initial ?? "")?.type !== "choice" && child !== node.initial) {
1741
+ const routed = initialChoiceRouteRoot() !== undefined &&
1742
+ trace.initial.plan.microsteps[0]?.transitions.some((transition) => {
1743
+ const target = transition.resolvedTarget ?? transition.target
1744
+ return target !== undefined && child !== undefined &&
1745
+ isDescendantOrSelf(String(target), child)
1746
+ })
1747
+ if (byPath.get(node.initial ?? "")?.type !== "choice" && child !== node.initial && !routed) {
1742
1748
  add(
1743
1749
  "definitions.initial",
1744
1750
  initialLocation,
@@ -232,26 +232,29 @@ export interface Scenarios<M extends AnyMachine> {
232
232
  * **Example**
233
233
  *
234
234
  * ```ts
235
- * import { Schema } from "effect"
236
235
  * import { Machine } from "@typeonce/effect-machine"
237
236
  * import { MachineTest } from "@typeonce/effect-machine/testing"
238
- *
239
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
240
- * class Reset extends Schema.TaggedClass<Reset>("Reset")("Reset", {}) {}
241
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
237
+ * import { Schema } from "effect"
238
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
239
+ * }
240
+ * class Reset extends Schema.TaggedClass<Reset>("Reset")("Reset", {}) {
241
+ * }
242
+ * const States = Machine.state({ states: { Idle } })
242
243
  * const machine = Machine.make({
243
244
  * root: States,
244
- * events: Machine.eventsFromSchemas(Reset),
245
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
246
- * }).handle({ states: {
247
- * Idle: {
248
- * on: {
249
- * Reset: (to) =>
250
- * to.branch.Idle().resolve(({ target }) => target.from())
245
+ * events: Machine.eventsFromSchemas(Reset)
246
+ * }).handle({
247
+ * initial: {
248
+ * target: Machine.targets(States).root.Idle
249
+ * },
250
+ * states: {
251
+ * Idle: {
252
+ * on: {
253
+ * Reset: (to) => to.branch.Idle().resolve(({ target }) => target.from())
254
+ * }
251
255
  * }
252
256
  * }
253
- * } })
254
- *
257
+ * })
255
258
  * const generated = MachineTest.scenarios(machine, { maxEvents: 5 })
256
259
  * ```
257
260
  *
@@ -491,18 +494,23 @@ export { ProbeUnavailableError } from "../internal/testing/machine/probe.js"
491
494
  * **Example**
492
495
  *
493
496
  * ```ts
494
- * import { Effect, Schema } from "effect"
495
497
  * import { Machine } from "@typeonce/effect-machine"
496
498
  * import { MachineTest } from "@typeonce/effect-machine/testing"
497
- *
498
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
499
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
499
+ * import { Effect, Schema } from "effect"
500
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
501
+ * }
502
+ * const States = Machine.state({ states: { Idle } })
500
503
  * const machine = Machine.make({
501
504
  * root: States,
502
- * events: Machine.eventsFromSchemas(),
503
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
504
- * }).handle({ states: { Idle: {} } })
505
- *
505
+ * events: Machine.eventsFromSchemas()
506
+ * }).handle({
507
+ * initial: {
508
+ * target: Machine.targets(States).root.Idle
509
+ * },
510
+ * states: {
511
+ * Idle: {}
512
+ * }
513
+ * })
506
514
  * const program = Effect.gen(function*() {
507
515
  * const ref = yield* Machine.start(machine)
508
516
  * return yield* MachineTest.probe(machine, ref)
@@ -1100,20 +1108,27 @@ export const Invariant: {
1100
1108
  * **Example**
1101
1109
  *
1102
1110
  * ```ts
1103
- * import { Schema } from "effect"
1104
1111
  * import { Machine } from "@typeonce/effect-machine"
1105
1112
  * import { MachineTest } from "@typeonce/effect-machine/testing"
1106
- *
1113
+ * import { Schema } from "effect"
1107
1114
  * class Count extends Schema.TaggedClass<Count>("Count")("Count", {
1108
1115
  * value: Schema.Number
1109
- * }) {}
1110
- * const States = Machine.state({ initial: "Count", states: { Count } })
1116
+ * }) {
1117
+ * }
1118
+ * const States = Machine.state({ states: { Count } })
1111
1119
  * const machine = Machine.make({
1112
1120
  * root: States,
1113
- * events: Machine.eventsFromSchemas(),
1114
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Count.decoded(new Count({ value: 0 }))))
1115
- * }).handle({ states: { Count: {} } })
1116
- *
1121
+ * events: Machine.eventsFromSchemas()
1122
+ * }).handle({
1123
+ * initial: {
1124
+ * target: Machine.targets(States).root.Count,
1125
+ * decoded: true,
1126
+ * data: new Count({ value: 0 })
1127
+ * },
1128
+ * states: {
1129
+ * Count: {}
1130
+ * }
1131
+ * })
1117
1132
  * const nonNegative = MachineTest.invariants(machine).state(
1118
1133
  * "count is non-negative",
1119
1134
  * ({ snapshot }) => snapshot.value.value >= 0
@@ -1431,29 +1446,34 @@ export type ExploreOptions<M extends AnyMachine, Key extends ExplorationKey = Ex
1431
1446
  * **Example**
1432
1447
  *
1433
1448
  * ```ts
1434
- * import { Schema } from "effect"
1435
1449
  * import { Machine } from "@typeonce/effect-machine"
1436
1450
  * import { MachineTest } from "@typeonce/effect-machine/testing"
1437
- *
1451
+ * import { Schema } from "effect"
1438
1452
  * class Count extends Schema.TaggedClass<Count>("Count")("Count", {
1439
1453
  * value: Schema.Number
1440
- * }) {}
1441
- * class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {}) {}
1442
- * const States = Machine.state({ initial: "Count", states: { Count } })
1454
+ * }) {
1455
+ * }
1456
+ * class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {}) {
1457
+ * }
1458
+ * const States = Machine.state({ states: { Count } })
1443
1459
  * const machine = Machine.make({
1444
1460
  * root: States,
1445
- * events: Machine.eventsFromSchemas(Increment),
1446
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Count.decoded(new Count({ value: 0 }))))
1447
- * }).handle({ states: {
1448
- * Count: {
1449
- * on: {
1450
- * Increment: (to) =>
1451
- * to.branch.Count().resolve(({ state, target }) =>
1452
- * target.decoded(new Count({ value: state.value + 1 })))
1461
+ * events: Machine.eventsFromSchemas(Increment)
1462
+ * }).handle({
1463
+ * initial: {
1464
+ * target: Machine.targets(States).root.Count,
1465
+ * decoded: true,
1466
+ * data: new Count({ value: 0 })
1467
+ * },
1468
+ * states: {
1469
+ * Count: {
1470
+ * on: {
1471
+ * Increment: (to) =>
1472
+ * to.branch.Count().resolve(({ state, target }) => target.decoded(new Count({ value: state.value + 1 })))
1473
+ * }
1453
1474
  * }
1454
1475
  * }
1455
- * } })
1456
- *
1476
+ * })
1457
1477
  * const explored = MachineTest.explore(machine, {
1458
1478
  * events: ({ snapshot }) => snapshot.value.value < 2 ? [new Increment({})] : [],
1459
1479
  * stateKey: ({ snapshot }) => snapshot.value.value
@@ -1623,18 +1643,23 @@ export type RunServices<M extends AnyMachine> = IsAny<
1623
1643
  * **Example**
1624
1644
  *
1625
1645
  * ```ts
1626
- * import { Schema } from "effect"
1627
1646
  * import { Machine } from "@typeonce/effect-machine"
1628
1647
  * import { MachineTest } from "@typeonce/effect-machine/testing"
1629
- *
1630
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
1631
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
1648
+ * import { Schema } from "effect"
1649
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
1650
+ * }
1651
+ * const States = Machine.state({ states: { Idle } })
1632
1652
  * const machine = Machine.make({
1633
1653
  * root: States,
1634
- * events: Machine.eventsFromSchemas(),
1635
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
1636
- * }).handle({ states: { Idle: {} } })
1637
- *
1654
+ * events: Machine.eventsFromSchemas()
1655
+ * }).handle({
1656
+ * initial: {
1657
+ * target: Machine.targets(States).root.Idle
1658
+ * },
1659
+ * states: {
1660
+ * Idle: {}
1661
+ * }
1662
+ * })
1638
1663
  * const trace = MachineTest.run(machine, { events: [] })
1639
1664
  * ```
1640
1665
  *
@@ -1889,22 +1914,24 @@ export interface Coverage<M extends AnyMachine> {
1889
1914
  * **Example**
1890
1915
  *
1891
1916
  * ```ts
1892
- * import { Effect, Schema } from "effect"
1893
1917
  * import { Machine } from "@typeonce/effect-machine"
1894
1918
  * import { MachineTest } from "@typeonce/effect-machine/testing"
1895
- *
1896
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
1897
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
1919
+ * import { Effect, Schema } from "effect"
1920
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
1921
+ * }
1922
+ * const States = Machine.state({ states: { Idle } })
1898
1923
  * const machine = Machine.make({
1899
1924
  * root: States,
1900
- * events: Machine.eventsFromSchemas(),
1901
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
1902
- * }).handle({ states: { Idle: {} } })
1903
- *
1904
- * const report = Effect.map(
1905
- * MachineTest.run(machine, { events: [] }),
1906
- * (trace) => MachineTest.coverage(machine, trace)
1907
- * )
1925
+ * events: Machine.eventsFromSchemas()
1926
+ * }).handle({
1927
+ * initial: {
1928
+ * target: Machine.targets(States).root.Idle
1929
+ * },
1930
+ * states: {
1931
+ * Idle: {}
1932
+ * }
1933
+ * })
1934
+ * const report = Effect.map(MachineTest.run(machine, { events: [] }), (trace) => MachineTest.coverage(machine, trace))
1908
1935
  * ```
1909
1936
  *
1910
1937
  * @category verification
@@ -2115,18 +2142,23 @@ export interface VerifyOptions {
2115
2142
  * **Example**
2116
2143
  *
2117
2144
  * ```ts
2118
- * import { Effect, Schema } from "effect"
2119
2145
  * import { Machine } from "@typeonce/effect-machine"
2120
2146
  * import { MachineTest } from "@typeonce/effect-machine/testing"
2121
- *
2122
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
2123
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
2147
+ * import { Effect, Schema } from "effect"
2148
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
2149
+ * }
2150
+ * const States = Machine.state({ states: { Idle } })
2124
2151
  * const machine = Machine.make({
2125
2152
  * root: States,
2126
- * events: Machine.eventsFromSchemas(),
2127
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
2128
- * }).handle({ states: { Idle: {} } })
2129
- *
2153
+ * events: Machine.eventsFromSchemas()
2154
+ * }).handle({
2155
+ * initial: {
2156
+ * target: Machine.targets(States).root.Idle
2157
+ * },
2158
+ * states: {
2159
+ * Idle: {}
2160
+ * }
2161
+ * })
2130
2162
  * const checked = Effect.gen(function*() {
2131
2163
  * const trace = yield* MachineTest.run(machine, { events: [] })
2132
2164
  * yield* MachineTest.verify(machine, trace)
@@ -341,18 +341,23 @@ export const layerMemory: Layer.Layer<Storage> = internal.layerMemory
341
341
  * **Example**
342
342
  *
343
343
  * ```ts
344
- * import { Schema } from "effect"
345
344
  * import { Machine } from "@typeonce/effect-machine"
346
345
  * import { ClusterMachine } from "@typeonce/effect-machine/cluster"
347
- *
348
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
349
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
346
+ * import { Schema } from "effect"
347
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
348
+ * }
349
+ * const States = Machine.state({ states: { Idle } })
350
350
  * const machine = Machine.make({
351
351
  * root: States,
352
- * events: Machine.eventsFromSchemas(),
353
- * initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
354
- * }).handle({ states: { Idle: {} } })
355
- *
352
+ * events: Machine.eventsFromSchemas()
353
+ * }).handle({
354
+ * initial: {
355
+ * target: Machine.targets(States).root.Idle
356
+ * },
357
+ * states: {
358
+ * Idle: {}
359
+ * }
360
+ * })
356
361
  * const adapter = ClusterMachine.make("IdleMachine", machine, { version: "1" })
357
362
  * ```
358
363
  *