@typeonce/effect-machine 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1823 -0
- package/CLAUDE.md +1823 -0
- package/README.md +100 -77
- package/ai-docs/README.md +18 -0
- package/ai-docs/src/10_modeling/01_create-a-machine.ts +51 -0
- package/ai-docs/src/10_modeling/02_branch-on-an-event.ts +55 -0
- package/ai-docs/src/10_modeling/03_update-retained-state.ts +58 -0
- package/ai-docs/src/10_modeling/04_verify-after-changing.ts +29 -0
- package/{docs/agent-guide.md → ai-docs/src/10_modeling/index.md} +234 -155
- package/{docs/root-api.md → ai-docs/src/20_root-api/index.md} +29 -57
- package/{docs/effect-atom-react.md → ai-docs/src/30_react/index.md} +42 -49
- package/{docs/machine-review.md → ai-docs/src/40_review/index.md} +42 -40
- package/ai-docs/src/index.md +7 -0
- package/ai-docs/tsconfig.json +22 -0
- package/dist/Machine.d.ts +1195 -1474
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +366 -214
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/command.d.ts +8 -0
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/command.js +2 -2
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +21 -5
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +1 -0
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/construction.js.map +1 -1
- package/dist/internal/machine/declaration.d.ts +2 -1
- package/dist/internal/machine/declaration.d.ts.map +1 -1
- package/dist/internal/machine/declaration.js +28 -46
- package/dist/internal/machine/declaration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +23 -16
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +2 -0
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/implementation.js.map +1 -1
- package/dist/internal/machine/initialDeclaration.d.ts +2 -0
- package/dist/internal/machine/initialDeclaration.d.ts.map +1 -1
- package/dist/internal/machine/initialDeclaration.js +15 -0
- package/dist/internal/machine/initialDeclaration.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +25 -19
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +34 -17
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +16 -4
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +5 -22
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +157 -119
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +15 -4
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +18 -21
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +2 -0
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +2 -0
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.js.map +1 -1
- package/dist/internal/machine/runtimeGeneric.d.ts.map +1 -1
- package/dist/internal/machine/runtimeGeneric.js.map +1 -1
- package/dist/internal/machine/runtimeProtocol.d.ts +26 -0
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
- package/dist/internal/machine/runtimeProtocol.js +71 -0
- package/dist/internal/machine/runtimeProtocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +0 -14
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +9 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +18 -9
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +16 -1
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -1
- package/dist/internal/testing/machine/arbitrary.js +2 -0
- package/dist/internal/testing/machine/arbitrary.js.map +1 -1
- package/dist/internal/testing/machine/check.d.ts +17 -0
- package/dist/internal/testing/machine/check.d.ts.map +1 -0
- package/dist/internal/testing/machine/check.js +371 -0
- package/dist/internal/testing/machine/check.js.map +1 -0
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts +14 -13
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +21 -23
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +19 -88
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +0 -19
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/runtimeInvariant.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +349 -139
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +201 -136
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +9 -14
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +9 -14
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +169 -80
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +165 -76
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +11 -9
- package/src/Machine.ts +1139 -2130
- package/src/internal/machine/atom.ts +3 -3
- package/src/internal/machine/cluster.ts +2 -2
- package/src/internal/machine/command.ts +10 -4
- package/src/internal/machine/configuration.ts +16 -17
- package/src/internal/machine/construction.ts +1 -1
- package/src/internal/machine/declaration.ts +25 -50
- package/src/internal/machine/executionPlan.ts +90 -56
- package/src/internal/machine/implementation.ts +3 -1
- package/src/internal/machine/initialDeclaration.ts +16 -0
- package/src/internal/machine/invocation.ts +38 -44
- package/src/internal/machine/invocationEvent.ts +46 -20
- package/src/internal/machine/machine.ts +217 -243
- package/src/internal/machine/planner.ts +72 -106
- package/src/internal/machine/process.ts +12 -0
- package/src/internal/machine/protocol.ts +6 -6
- package/src/internal/machine/runtime.ts +1 -5
- package/src/internal/machine/runtimeCompiled.ts +2 -2
- package/src/internal/machine/runtimeGeneric.ts +2 -4
- package/src/internal/machine/runtimeProtocol.ts +80 -4
- package/src/internal/machine/stateDefinition.ts +0 -39
- package/src/internal/machine/symbols.ts +11 -0
- package/src/internal/machine/topology.ts +40 -18
- package/src/internal/testing/machine/arbitrary.ts +2 -0
- package/src/internal/testing/machine/check.ts +460 -0
- package/src/internal/testing/machine/exploration.ts +4 -5
- package/src/internal/testing/machine/finiteModel.ts +40 -42
- package/src/internal/testing/machine/runtime.ts +31 -170
- package/src/internal/testing/machine/runtimeInvariant.ts +3 -3
- package/src/internal/testing/machine/verification.ts +14 -14
- package/src/testing/MachineTest.ts +366 -145
- package/src/unstable/cluster/ClusterMachine.ts +9 -14
- package/src/unstable/reactivity/AtomMachine.ts +167 -78
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as Effect from "effect/Effect"
|
|
8
8
|
import type { Machine, MachineTarget } from "../../Machine.js"
|
|
9
|
-
import { type RuntimeCommand } from "./command.js"
|
|
9
|
+
import { type RuntimeCommand, type SendToTarget, type StopTarget } from "./command.js"
|
|
10
10
|
import {
|
|
11
11
|
type ActiveConfiguration,
|
|
12
12
|
compareDocumentOrder,
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
isSnapshot,
|
|
57
57
|
isStateUpdate,
|
|
58
58
|
isTarget,
|
|
59
|
+
type TargetSnapshotSlot,
|
|
59
60
|
TargetSnapshotTypeId
|
|
60
61
|
} from "./topology.js"
|
|
61
62
|
|
|
@@ -151,7 +152,7 @@ const compileIndexedExecutionDescriptor = (
|
|
|
151
152
|
finalPaths.push(node.path)
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
const config = toImpl(machine).handlers[node.path]
|
|
155
|
+
const config = toImpl(machine).handlers[node.path]
|
|
155
156
|
if (!supportsIndexedStateConfig(config)) {
|
|
156
157
|
return undefined
|
|
157
158
|
}
|
|
@@ -328,13 +329,22 @@ const activeConfigurationFromIndexedState = (
|
|
|
328
329
|
return { active, values, outputs, history: new Map() }
|
|
329
330
|
}
|
|
330
331
|
|
|
332
|
+
/** A snapshot node under construction; it is detached from the indexed tables. */
|
|
333
|
+
interface IndexedSnapshotNode {
|
|
334
|
+
readonly path: string
|
|
335
|
+
readonly value: unknown
|
|
336
|
+
state?: IndexedSnapshotNode
|
|
337
|
+
states?: Record<string, IndexedSnapshotNode>
|
|
338
|
+
completed?: ReadonlyArray<Machine.SnapshotCompletion>
|
|
339
|
+
}
|
|
340
|
+
|
|
331
341
|
const snapshotFromIndexedStateStatePath = (
|
|
332
342
|
descriptor: IndexedExecutionDescriptor,
|
|
333
343
|
configuration: OwnedIndexedState,
|
|
334
344
|
index: number
|
|
335
|
-
):
|
|
345
|
+
): IndexedSnapshotNode => {
|
|
336
346
|
const node = descriptor.nodes[index]!
|
|
337
|
-
const snapshot:
|
|
347
|
+
const snapshot: IndexedSnapshotNode = {
|
|
338
348
|
path: node.path,
|
|
339
349
|
value: descriptor.valued[index] ? configuration.values[index] : undefined
|
|
340
350
|
}
|
|
@@ -345,7 +355,7 @@ const snapshotFromIndexedStateStatePath = (
|
|
|
345
355
|
}
|
|
346
356
|
snapshot.state = snapshotFromIndexedStateStatePath(descriptor, configuration, childIndex)
|
|
347
357
|
} else if (node.type === "parallel") {
|
|
348
|
-
const states: Record<string,
|
|
358
|
+
const states: Record<string, IndexedSnapshotNode> = {}
|
|
349
359
|
for (const childIndex of descriptor.childIndices[index]!) {
|
|
350
360
|
if (configuration.active[childIndex] !== 1) {
|
|
351
361
|
throw new Error(
|
|
@@ -362,7 +372,7 @@ const snapshotFromIndexedStateStatePath = (
|
|
|
362
372
|
}
|
|
363
373
|
snapshot.states = states
|
|
364
374
|
}
|
|
365
|
-
return snapshot
|
|
375
|
+
return snapshot
|
|
366
376
|
}
|
|
367
377
|
|
|
368
378
|
const snapshotFromIndexedState = (
|
|
@@ -371,11 +381,9 @@ const snapshotFromIndexedState = (
|
|
|
371
381
|
): Machine.Snapshot<any> => {
|
|
372
382
|
const rootIndex = descriptor.rootIndices.find((index) => configuration.active[index] === 1)
|
|
373
383
|
if (rootIndex === undefined) throw new Error("Machine expected an active indexed root state")
|
|
374
|
-
const snapshot = snapshotFromIndexedStateStatePath(descriptor, configuration, rootIndex)
|
|
384
|
+
const snapshot = snapshotFromIndexedStateStatePath(descriptor, configuration, rootIndex)
|
|
375
385
|
if (configuration.completedOrder.length > 0) {
|
|
376
|
-
|
|
377
|
-
completed: ReadonlyArray<Machine.SnapshotCompletion>
|
|
378
|
-
}).completed = configuration.completedOrder.map((index) => ({
|
|
386
|
+
snapshot.completed = configuration.completedOrder.map((index) => ({
|
|
379
387
|
path: descriptor.nodes[index]!.path,
|
|
380
388
|
output: configuration.outputs[index]
|
|
381
389
|
}))
|
|
@@ -383,14 +391,30 @@ const snapshotFromIndexedState = (
|
|
|
383
391
|
return snapshot
|
|
384
392
|
}
|
|
385
393
|
|
|
394
|
+
/** A decoded machine event; indexed dispatch reads only its tag. */
|
|
395
|
+
interface IndexedEvent {
|
|
396
|
+
readonly _tag: PropertyKey
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Handler context built by indexed dispatch, matching the generic planner's transition context. */
|
|
400
|
+
interface IndexedTransitionContext {
|
|
401
|
+
readonly self: MachineTarget<any>
|
|
402
|
+
readonly parent?: MachineTarget<any> | undefined
|
|
403
|
+
readonly state: unknown
|
|
404
|
+
readonly containingState: unknown
|
|
405
|
+
readonly ancestors: Readonly<Record<string, unknown>>
|
|
406
|
+
readonly event: IndexedEvent
|
|
407
|
+
readonly snapshot: Machine.Snapshot<any>
|
|
408
|
+
}
|
|
409
|
+
|
|
386
410
|
const makeIndexedTransitionContext = (
|
|
387
411
|
machine: Machine.Any,
|
|
388
412
|
descriptor: IndexedExecutionDescriptor,
|
|
389
413
|
configuration: OwnedIndexedState,
|
|
390
414
|
sourceIndex: number,
|
|
391
|
-
event:
|
|
415
|
+
event: IndexedEvent,
|
|
392
416
|
machineReferences?: PlanningMachineReferences
|
|
393
|
-
):
|
|
417
|
+
): IndexedTransitionContext => {
|
|
394
418
|
const parentIndex = descriptor.parentIndices[sourceIndex]!
|
|
395
419
|
const ancestors: Record<string, unknown> = {}
|
|
396
420
|
for (const ancestorIndex of descriptor.ancestorIndices[sourceIndex]!) {
|
|
@@ -408,14 +432,14 @@ const makeIndexedTransitionContext = (
|
|
|
408
432
|
}
|
|
409
433
|
}
|
|
410
434
|
|
|
411
|
-
type IndexedSelectedTransition = SelectedTransition<any, any, any,
|
|
435
|
+
type IndexedSelectedTransition = SelectedTransition<any, any, any, IndexedTransitionContext> & {
|
|
412
436
|
readonly sourceIndex: number
|
|
413
437
|
readonly leafIndex: number
|
|
414
438
|
}
|
|
415
439
|
|
|
416
440
|
type IndexedEvaluatedTransition =
|
|
417
441
|
& Omit<
|
|
418
|
-
EvaluatedTransition<any,
|
|
442
|
+
EvaluatedTransition<any, IndexedEvent, any, any, IndexedTransitionContext>,
|
|
419
443
|
"selection"
|
|
420
444
|
>
|
|
421
445
|
& {
|
|
@@ -447,14 +471,14 @@ export interface ExecutionMacrostep<State = unknown> {
|
|
|
447
471
|
readonly output: unknown
|
|
448
472
|
}
|
|
449
473
|
|
|
450
|
-
const collectIndexedTransition = (
|
|
474
|
+
const collectIndexedTransition = <Context>(
|
|
451
475
|
machine: Machine.Any,
|
|
452
|
-
transition: TransitionHandler<any, any, any,
|
|
453
|
-
context:
|
|
454
|
-
evaluate?: NonNullable<MicrostepTransition<any, any, any,
|
|
476
|
+
transition: TransitionHandler<any, any, any, Context>,
|
|
477
|
+
context: Context,
|
|
478
|
+
evaluate?: NonNullable<MicrostepTransition<any, any, any, Context>["evaluate"]>
|
|
455
479
|
) => {
|
|
456
480
|
let commands: Array<RuntimeCommand> | undefined
|
|
457
|
-
let raisedEvents: Array<
|
|
481
|
+
let raisedEvents: Array<IndexedEvent> | undefined
|
|
458
482
|
let emittedEvents: Array<unknown> | undefined
|
|
459
483
|
const enqueue = {
|
|
460
484
|
raise: (event: unknown) => {
|
|
@@ -463,11 +487,11 @@ const collectIndexedTransition = (
|
|
|
463
487
|
emit: (event: unknown) => {
|
|
464
488
|
;(emittedEvents ??= []).push(decodeEmitSync(machine, event))
|
|
465
489
|
},
|
|
466
|
-
sendTo: (
|
|
467
|
-
;(commands ??= []).push({ _tag: "SendTo", target
|
|
490
|
+
sendTo: (target: SendToTarget, event: unknown) => {
|
|
491
|
+
;(commands ??= []).push({ _tag: "SendTo", target, event })
|
|
468
492
|
},
|
|
469
|
-
stop: (child:
|
|
470
|
-
;(commands ??= []).push({ _tag: "Stop", child
|
|
493
|
+
stop: (child: StopTarget) => {
|
|
494
|
+
;(commands ??= []).push({ _tag: "Stop", child })
|
|
471
495
|
}
|
|
472
496
|
}
|
|
473
497
|
const evaluated = evaluate === undefined
|
|
@@ -487,7 +511,7 @@ const selectIndexedEventTransitions = (
|
|
|
487
511
|
machine: Machine.Any,
|
|
488
512
|
descriptor: IndexedExecutionDescriptor,
|
|
489
513
|
configuration: OwnedIndexedState,
|
|
490
|
-
event:
|
|
514
|
+
event: IndexedEvent,
|
|
491
515
|
machineReferences?: PlanningMachineReferences
|
|
492
516
|
): ReadonlyArray<IndexedSelectedTransition> => {
|
|
493
517
|
const selected: Array<IndexedSelectedTransition> = []
|
|
@@ -537,7 +561,8 @@ const normalizeIndexedTargetStateSync = (
|
|
|
537
561
|
const targetIndex = isTarget(target) ? descriptor.indexByPath.get(String(target.path)) : undefined
|
|
538
562
|
if (
|
|
539
563
|
targetIndex === activeLeafIndex && current.active[activeLeafIndex] === 1 && isTarget(target) &&
|
|
540
|
-
target[TargetSnapshotTypeId] === undefined && target.values === undefined &&
|
|
564
|
+
(target as TargetSnapshotSlot)[TargetSnapshotTypeId] === undefined && target.values === undefined &&
|
|
565
|
+
current.completedOrder.length === 0 &&
|
|
541
566
|
descriptor.valued[activeLeafIndex]
|
|
542
567
|
) {
|
|
543
568
|
const values = current.values.slice()
|
|
@@ -597,8 +622,12 @@ const collectIndexedEvaluatedTransition = (
|
|
|
597
622
|
selection.transition.targets,
|
|
598
623
|
unresolvedTarget
|
|
599
624
|
)
|
|
600
|
-
const
|
|
601
|
-
?
|
|
625
|
+
const initialTarget = unresolvedTarget !== undefined && isInitialTarget(unresolvedTarget)
|
|
626
|
+
? unresolvedTarget
|
|
627
|
+
: undefined
|
|
628
|
+
const initialResolution = initialTarget === undefined
|
|
629
|
+
? undefined
|
|
630
|
+
: resolveInitialTarget(
|
|
602
631
|
machine,
|
|
603
632
|
(() => {
|
|
604
633
|
const current = activeConfigurationFromIndexedState(descriptor, state)
|
|
@@ -606,21 +635,24 @@ const collectIndexedEvaluatedTransition = (
|
|
|
606
635
|
? current
|
|
607
636
|
: { ...current, values: new Map(current.values).set(update.path, update.value) }
|
|
608
637
|
})(),
|
|
609
|
-
|
|
610
|
-
|
|
638
|
+
initialTarget,
|
|
639
|
+
selection.context.event
|
|
611
640
|
)
|
|
612
|
-
: undefined
|
|
613
641
|
const target = initialResolution?.target ?? unresolvedTarget
|
|
614
642
|
if (target !== undefined && !isTarget(target) && !isSnapshot(target)) {
|
|
615
643
|
throw new Error("Machine expected indexed transition target to be a snapshot or target builder result")
|
|
616
644
|
}
|
|
645
|
+
// Without an initial target, the validated target is the returned target.
|
|
646
|
+
const retainedTarget = initialTarget ?? target
|
|
647
|
+
// The shared initial-target resolver decodes raised events but erases their type.
|
|
648
|
+
const initialRaisedEvents = (initialResolution?.raisedEvents ?? emptyExecutionValues) as ReadonlyArray<IndexedEvent>
|
|
617
649
|
let next = target === undefined
|
|
618
650
|
? update === undefined ? state : (() => {
|
|
619
651
|
const next = copyOwnedIndexedState(state)
|
|
620
652
|
next.values[descriptor.indexByPath.get(update.path)!] = update.value
|
|
621
653
|
return next
|
|
622
654
|
})()
|
|
623
|
-
: normalizeIndexedTargetStateSync(machine, descriptor, state, target
|
|
655
|
+
: normalizeIndexedTargetStateSync(machine, descriptor, state, target, selection.leafIndex)
|
|
624
656
|
if (combined !== undefined && update !== undefined) {
|
|
625
657
|
const ownerIndex = descriptor.indexByPath.get(update.path)!
|
|
626
658
|
if (next.active[ownerIndex] !== 1) {
|
|
@@ -637,12 +669,12 @@ const collectIndexedEvaluatedTransition = (
|
|
|
637
669
|
selection,
|
|
638
670
|
branchIndex: transitionResult.branchIndex,
|
|
639
671
|
branchKey: transitionResult.branchKey,
|
|
640
|
-
unresolvedTarget:
|
|
641
|
-
target
|
|
672
|
+
unresolvedTarget: retainedTarget,
|
|
673
|
+
target,
|
|
642
674
|
update,
|
|
643
675
|
next,
|
|
644
676
|
commands: [...transitionResult.commands, ...(initialResolution?.commands ?? [])],
|
|
645
|
-
raisedEvents: [...transitionResult.raisedEvents, ...
|
|
677
|
+
raisedEvents: [...transitionResult.raisedEvents, ...initialRaisedEvents],
|
|
646
678
|
emittedEvents: [...transitionResult.emittedEvents, ...(initialResolution?.emittedEvents ?? [])],
|
|
647
679
|
changed: false,
|
|
648
680
|
stabilize,
|
|
@@ -652,7 +684,7 @@ const collectIndexedEvaluatedTransition = (
|
|
|
652
684
|
}
|
|
653
685
|
}
|
|
654
686
|
|
|
655
|
-
const targetPath = target === undefined ? undefined : getTargetNodePath(target
|
|
687
|
+
const targetPath = target === undefined ? undefined : getTargetNodePath(target)
|
|
656
688
|
const naturalBoundary = targetPath === undefined
|
|
657
689
|
? descriptor.nodes[selection.sourceIndex]!.parent
|
|
658
690
|
: getLeastCommonAncestor(machine, selection.leafPath, targetPath)
|
|
@@ -664,12 +696,12 @@ const collectIndexedEvaluatedTransition = (
|
|
|
664
696
|
selection,
|
|
665
697
|
branchIndex: transitionResult.branchIndex,
|
|
666
698
|
branchKey: transitionResult.branchKey,
|
|
667
|
-
unresolvedTarget:
|
|
668
|
-
target
|
|
699
|
+
unresolvedTarget: retainedTarget,
|
|
700
|
+
target,
|
|
669
701
|
update,
|
|
670
702
|
next,
|
|
671
703
|
commands: [...transitionResult.commands, ...(initialResolution?.commands ?? [])],
|
|
672
|
-
raisedEvents: [...transitionResult.raisedEvents, ...
|
|
704
|
+
raisedEvents: [...transitionResult.raisedEvents, ...initialRaisedEvents],
|
|
673
705
|
emittedEvents: [...transitionResult.emittedEvents, ...(initialResolution?.emittedEvents ?? [])],
|
|
674
706
|
changed: true,
|
|
675
707
|
stabilize,
|
|
@@ -679,14 +711,19 @@ const collectIndexedEvaluatedTransition = (
|
|
|
679
711
|
}
|
|
680
712
|
}
|
|
681
713
|
|
|
714
|
+
/** Indexed microsteps keep decoded raised events typed for the next dispatch. */
|
|
715
|
+
type IndexedMicrostep = ExecutionMicrostep<OwnedIndexedState> & {
|
|
716
|
+
readonly raisedEvents: ReadonlyArray<IndexedEvent>
|
|
717
|
+
}
|
|
718
|
+
|
|
682
719
|
const indexedMicrostep = (
|
|
683
720
|
machine: Machine.Any,
|
|
684
721
|
descriptor: IndexedExecutionDescriptor,
|
|
685
722
|
state: OwnedIndexedState,
|
|
686
|
-
event:
|
|
723
|
+
event: IndexedEvent,
|
|
687
724
|
selections: ReadonlyArray<IndexedSelectedTransition>,
|
|
688
725
|
retainTransitions: boolean
|
|
689
|
-
):
|
|
726
|
+
): IndexedMicrostep => {
|
|
690
727
|
const retain = (transition: IndexedEvaluatedTransition): Machine.RetainedTransition => ({
|
|
691
728
|
source: transition.selection.sourcePath,
|
|
692
729
|
trigger: transition.selection.trigger,
|
|
@@ -720,10 +757,7 @@ const indexedMicrostep = (
|
|
|
720
757
|
const evaluated = activeSelections.map((selection) =>
|
|
721
758
|
collectIndexedEvaluatedTransition(machine, descriptor, state, selection)
|
|
722
759
|
)
|
|
723
|
-
const transitions = sortEvaluatedTransitions(
|
|
724
|
-
machine,
|
|
725
|
-
removeConflictingTransitions(machine, evaluated as any)
|
|
726
|
-
) as ReadonlyArray<IndexedEvaluatedTransition>
|
|
760
|
+
const transitions = sortEvaluatedTransitions(machine, removeConflictingTransitions(machine, evaluated))
|
|
727
761
|
|
|
728
762
|
let next = state
|
|
729
763
|
if (transitions.length === 1) {
|
|
@@ -774,14 +808,14 @@ const planIndexedFlatState = (
|
|
|
774
808
|
machine: Machine.Any,
|
|
775
809
|
descriptor: IndexedExecutionDescriptor,
|
|
776
810
|
configuration: OwnedIndexedState,
|
|
777
|
-
decoded:
|
|
811
|
+
decoded: IndexedEvent,
|
|
778
812
|
retainMicrosteps: boolean,
|
|
779
813
|
machineReferences?: PlanningMachineReferences
|
|
780
814
|
): ExecutionMacrostep<OwnedIndexedState> => {
|
|
781
815
|
let current = configuration
|
|
782
|
-
let event:
|
|
816
|
+
let event: IndexedEvent = decoded
|
|
783
817
|
let commands: Array<RuntimeCommand> | undefined
|
|
784
|
-
let raisedEvents: Array<
|
|
818
|
+
let raisedEvents: Array<IndexedEvent> | undefined
|
|
785
819
|
let emittedEvents: Array<unknown> | undefined
|
|
786
820
|
let microsteps: Array<ExecutionMicrostep<OwnedIndexedState>> | undefined
|
|
787
821
|
let raisedIndex = 0
|
|
@@ -861,7 +895,7 @@ const planIndexedFlatState = (
|
|
|
861
895
|
if (target !== undefined) {
|
|
862
896
|
const targetIndex = descriptor.indexByPath.get(String(target.path))
|
|
863
897
|
const isSimpleTarget = isTarget(target)
|
|
864
|
-
? target[TargetSnapshotTypeId] === undefined && target.values === undefined
|
|
898
|
+
? (target as TargetSnapshotSlot)[TargetSnapshotTypeId] === undefined && target.values === undefined
|
|
865
899
|
: !("state" in target) && !("states" in target) && !("completed" in target) && !("history" in target)
|
|
866
900
|
if (
|
|
867
901
|
targetIndex === sourceIndex && isSimpleTarget && current.completedOrder.length === 0 &&
|
|
@@ -877,7 +911,7 @@ const planIndexedFlatState = (
|
|
|
877
911
|
)
|
|
878
912
|
)
|
|
879
913
|
} else {
|
|
880
|
-
next = normalizeIndexedTargetStateSync(machine, descriptor, current, target
|
|
914
|
+
next = normalizeIndexedTargetStateSync(machine, descriptor, current, target, sourceIndex)
|
|
881
915
|
}
|
|
882
916
|
}
|
|
883
917
|
const changed = transition.reenter || !hasSameIndexedActive(current, next)
|
|
@@ -896,8 +930,8 @@ const planIndexedFlatState = (
|
|
|
896
930
|
reenter: transition.reenter,
|
|
897
931
|
branchIndex: transitionResult.branchIndex,
|
|
898
932
|
branchKey: transitionResult.branchKey,
|
|
899
|
-
target: target === undefined ? undefined : getTargetNodePath(target
|
|
900
|
-
resolvedTarget: target === undefined ? undefined : getTargetNodePath(target
|
|
933
|
+
target: target === undefined ? undefined : getTargetNodePath(target),
|
|
934
|
+
resolvedTarget: target === undefined ? undefined : getTargetNodePath(target),
|
|
901
935
|
updates: update === undefined ? [] : [update.path]
|
|
902
936
|
}]
|
|
903
937
|
}
|
|
@@ -956,7 +990,7 @@ const planIndexedState = (
|
|
|
956
990
|
// the indexed representation; only the private lifecycle macrostep crosses
|
|
957
991
|
// the representation boundary.
|
|
958
992
|
const planned = planConfiguration(
|
|
959
|
-
machine
|
|
993
|
+
machine,
|
|
960
994
|
machineReferences === undefined
|
|
961
995
|
? activeConfigurationFromIndexedState(descriptor, configuration)
|
|
962
996
|
: withMachineReferences(activeConfigurationFromIndexedState(descriptor, configuration), machineReferences),
|
|
@@ -1021,7 +1055,7 @@ const planIndexedState = (
|
|
|
1021
1055
|
|
|
1022
1056
|
const first = indexedMicrostep(machine, descriptor, configuration, decoded, selections, retainMicrosteps)
|
|
1023
1057
|
let current = first.next
|
|
1024
|
-
let currentEvent:
|
|
1058
|
+
let currentEvent: IndexedEvent = decoded
|
|
1025
1059
|
const commands = [...first.commands]
|
|
1026
1060
|
const raisedEvents = [...first.raisedEvents]
|
|
1027
1061
|
const emittedEvents = [...first.emittedEvents]
|
|
@@ -1119,11 +1153,11 @@ const makeActiveExecutionPlan = (machine: Machine.Any): CompiledExecutionPlan =>
|
|
|
1119
1153
|
snapshot: (state) => snapshotFromConfiguration(machine, state as ActiveConfiguration),
|
|
1120
1154
|
plan: (state, event, _retainMicrosteps, machineReferences) =>
|
|
1121
1155
|
planConfiguration(
|
|
1122
|
-
machine
|
|
1156
|
+
machine,
|
|
1123
1157
|
machineReferences === undefined
|
|
1124
1158
|
? state as ActiveConfiguration
|
|
1125
1159
|
: withMachineReferences(state as ActiveConfiguration, machineReferences),
|
|
1126
|
-
event
|
|
1160
|
+
event
|
|
1127
1161
|
)
|
|
1128
1162
|
})
|
|
1129
1163
|
|
|
@@ -1149,7 +1183,7 @@ const makeIndexedExecutionPlan = (
|
|
|
1149
1183
|
: args.length === 0
|
|
1150
1184
|
? (decodeInputSync(machine, machine.input, undefined), args)
|
|
1151
1185
|
: [decodeInputSync(machine, machine.input, args[0])]
|
|
1152
|
-
const initial = machine.initial(...inputArgs
|
|
1186
|
+
const initial = toImpl(machine).initial(...inputArgs)
|
|
1153
1187
|
const normalized = isInitialTarget(initial)
|
|
1154
1188
|
? resolveInitialConfiguration(
|
|
1155
1189
|
machine,
|
|
@@ -34,7 +34,9 @@ export interface CapturedStateConfig {
|
|
|
34
34
|
*/
|
|
35
35
|
export interface MachineInternal extends Machine.Any {
|
|
36
36
|
readonly handlers: Readonly<Record<string, CapturedStateConfig | undefined>>
|
|
37
|
+
/** Startup constructor; callers decode its input first and validate its result. */
|
|
38
|
+
readonly initial: (...args: ReadonlyArray<unknown>) => unknown
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/** The single conversion from an erased public machine to its captured implementation. */
|
|
40
|
-
export const toImpl = (machine: Machine.Any): MachineInternal => machine
|
|
42
|
+
export const toImpl = (machine: Machine.Any): MachineInternal => machine
|
|
@@ -34,6 +34,22 @@ export const construction = (value: unknown): Constructor => {
|
|
|
34
34
|
return (context) => Topology.makeStateInput(value === undefined ? {} : resolve(context))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/** One `update` record value: a make input, a function of the context, or a decoded construction. */
|
|
38
|
+
export const ownerUpdate = (value: unknown): Constructor => {
|
|
39
|
+
const descriptor = typeof value === "object" && value !== null &&
|
|
40
|
+
hasProperty(value, "decoded") && value.decoded === true && hasProperty(value, "data")
|
|
41
|
+
if (descriptor) {
|
|
42
|
+
const config = record(value, "decoded construction")
|
|
43
|
+
if (Reflect.ownKeys(config).some((key) => key !== "decoded" && key !== "data")) {
|
|
44
|
+
throw new Error("Machine decoded construction accepts only decoded and data")
|
|
45
|
+
}
|
|
46
|
+
const resolve = evaluate(config.data)
|
|
47
|
+
return (context) => ({ decoded: true, data: resolve(context) })
|
|
48
|
+
}
|
|
49
|
+
const resolve = evaluate(value)
|
|
50
|
+
return (context) => ({ data: resolve(context) })
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
export const edgeConstruction = (config: Readonly<Record<string, unknown>>): Constructor => {
|
|
38
54
|
if (config.decoded !== undefined && typeof config.decoded !== "boolean") {
|
|
39
55
|
throw new Error("Machine decoded construction flag must be a boolean")
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import * as Cause from "effect/Cause"
|
|
8
8
|
import * as Effect from "effect/Effect"
|
|
9
9
|
import * as Stream from "effect/Stream"
|
|
10
|
-
import type { ChildMachine, ChildOwner, Inspection,
|
|
10
|
+
import type { ChildMachine, ChildOwner, Inspection, Machine } from "../../Machine.js"
|
|
11
11
|
import * as ChildRegistry from "./childRegistry.js"
|
|
12
12
|
import * as Configuration from "./configuration.js"
|
|
13
13
|
import { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, StoppedError } from "./errors.js"
|
|
@@ -15,7 +15,7 @@ import * as InvocationDefinition from "./invocationDefinition.js"
|
|
|
15
15
|
import * as InvocationEvent from "./invocationEvent.js"
|
|
16
16
|
import * as Planner from "./planner.js"
|
|
17
17
|
import * as Runtime from "./runtimeProtocol.js"
|
|
18
|
-
import { ChildMachineLogicTypeId } from "./symbols.js"
|
|
18
|
+
import { type ChildMachineLogicSlot, ChildMachineLogicTypeId } from "./symbols.js"
|
|
19
19
|
|
|
20
20
|
/** @internal */
|
|
21
21
|
export interface AnyConfig {
|
|
@@ -37,7 +37,9 @@ export const makeKey = (path: string, id: string): string => `${path.length}:${p
|
|
|
37
37
|
export const makeChildId = (path: string, id: string): string =>
|
|
38
38
|
`${ChildRegistry.invocationChildIdPrefix}${makeKey(path, id)}`
|
|
39
39
|
|
|
40
|
-
const oneShot = (
|
|
40
|
+
const oneShot = (
|
|
41
|
+
effect: Effect.Effect<unknown, unknown, unknown>
|
|
42
|
+
): Runtime.ProcessLogic<void, unknown, unknown, unknown, unknown> => ({
|
|
41
43
|
initial: () => Effect.void,
|
|
42
44
|
run: () => effect
|
|
43
45
|
})
|
|
@@ -45,8 +47,9 @@ const oneShot = (effect: Effect.Effect<any, any, any>): Logic<void, never, any,
|
|
|
45
47
|
const streamLogic = (
|
|
46
48
|
stream: Stream.Stream<any, any, any>,
|
|
47
49
|
path: string,
|
|
48
|
-
id: string
|
|
49
|
-
|
|
50
|
+
id: string,
|
|
51
|
+
generation: InvocationEvent.Generation
|
|
52
|
+
): Runtime.ProcessLogic<void, unknown, unknown, unknown, void> => ({
|
|
50
53
|
initial: () => Effect.void,
|
|
51
54
|
run: ({ parent }) => {
|
|
52
55
|
const send = parent?.[Runtime.acknowledgedSend]
|
|
@@ -56,7 +59,7 @@ const streamLogic = (
|
|
|
56
59
|
return Stream.runForEach(
|
|
57
60
|
stream,
|
|
58
61
|
(element) =>
|
|
59
|
-
send(InvocationEvent.element(path, id, element)).pipe(
|
|
62
|
+
send(InvocationEvent.element(path, id, generation, element)).pipe(
|
|
60
63
|
Effect.asVoid,
|
|
61
64
|
Effect.catchCause(() => Effect.interrupt)
|
|
62
65
|
)
|
|
@@ -68,33 +71,25 @@ const resolveValue = (value: unknown, context: Omit<Machine.InvokeContext<any, a
|
|
|
68
71
|
typeof value === "function" ? value(context) : value
|
|
69
72
|
|
|
70
73
|
const makeChildOwner = (scope: Runtime.ProcessScope<any>): ChildOwner<any> => ({
|
|
71
|
-
spawn:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
stop: ((descriptor: ChildMachine.Any) => scope.stopChild(descriptor)) as ChildOwner<any>["stop"]
|
|
74
|
+
spawn: <const Child extends ChildMachine.Any>(
|
|
75
|
+
child: Child & ChildMachine.Executable<Child> & ChildMachine.ParentCompatibility<Child, any>,
|
|
76
|
+
...options: ChildMachine.SpawnArgs<Child>
|
|
77
|
+
) => scope.spawn<Child>(child, ...options),
|
|
78
|
+
sendTo: (descriptor: ChildMachine.Any, event: unknown) => scope.sendTo(descriptor, event),
|
|
79
|
+
stop: (descriptor: ChildMachine.Any) => scope.stopChild(descriptor)
|
|
78
80
|
})
|
|
79
81
|
|
|
80
82
|
const resolveOne = (
|
|
81
83
|
raw: InvocationDefinition.InvocationDefinition,
|
|
82
84
|
context: Omit<Machine.InvokeContext<any, any, any, any>, "root">,
|
|
83
|
-
path: string
|
|
85
|
+
path: string,
|
|
86
|
+
generation: InvocationEvent.Generation
|
|
84
87
|
): AnyConfig => {
|
|
85
88
|
if ("effect" in raw) {
|
|
86
89
|
return {
|
|
87
90
|
id: String(raw.id),
|
|
88
91
|
sourceName: raw.sourceName,
|
|
89
|
-
src: () =>
|
|
90
|
-
oneShot(raw.effect(context) as Effect.Effect<any, any, any>) as unknown as Runtime.ProcessLogic<
|
|
91
|
-
any,
|
|
92
|
-
any,
|
|
93
|
-
any,
|
|
94
|
-
any,
|
|
95
|
-
any,
|
|
96
|
-
any
|
|
97
|
-
>,
|
|
92
|
+
src: () => oneShot(raw.effect(context)),
|
|
98
93
|
onDone: raw.onDone,
|
|
99
94
|
onFailure: raw.onFailure,
|
|
100
95
|
onSnapshot: raw.onSnapshot,
|
|
@@ -105,15 +100,7 @@ const resolveOne = (
|
|
|
105
100
|
return {
|
|
106
101
|
id: String(raw.id),
|
|
107
102
|
sourceName: raw.sourceName,
|
|
108
|
-
src: () =>
|
|
109
|
-
oneShot(Effect.sleep(resolveValue(raw.after, context) as any)) as unknown as Runtime.ProcessLogic<
|
|
110
|
-
any,
|
|
111
|
-
any,
|
|
112
|
-
any,
|
|
113
|
-
any,
|
|
114
|
-
any,
|
|
115
|
-
any
|
|
116
|
-
>,
|
|
103
|
+
src: () => oneShot(Effect.sleep(typeof raw.after === "function" ? raw.after(context) : raw.after)),
|
|
117
104
|
onDone: raw.onDone,
|
|
118
105
|
activityKind: "Timer"
|
|
119
106
|
}
|
|
@@ -123,8 +110,7 @@ const resolveOne = (
|
|
|
123
110
|
return {
|
|
124
111
|
id,
|
|
125
112
|
sourceName: raw.sourceName,
|
|
126
|
-
src: () =>
|
|
127
|
-
streamLogic(raw.stream(context), path, id) as unknown as Runtime.ProcessLogic<any, any, any, any, any, any>,
|
|
113
|
+
src: () => streamLogic(raw.stream(context), path, id, generation),
|
|
128
114
|
onDone: raw.onDone,
|
|
129
115
|
onFailure: raw.onFailure,
|
|
130
116
|
activityKind: "Stream"
|
|
@@ -147,7 +133,7 @@ const resolveOne = (
|
|
|
147
133
|
address: descriptor.id,
|
|
148
134
|
descriptor,
|
|
149
135
|
src: () =>
|
|
150
|
-
descriptor[ChildMachineLogicTypeId](
|
|
136
|
+
(descriptor as unknown as ChildMachineLogicSlot)[ChildMachineLogicTypeId](
|
|
151
137
|
"input" in raw ? resolveValue(raw.input, context) : undefined
|
|
152
138
|
) as Runtime.ProcessLogic<any, any, any, any, any, any>,
|
|
153
139
|
onDone: raw.onDone,
|
|
@@ -191,6 +177,7 @@ const startResolved = (
|
|
|
191
177
|
scope: Runtime.ProcessScope<any>,
|
|
192
178
|
ownedChildren: Runtime.OwnedChildRuntime,
|
|
193
179
|
path: string,
|
|
180
|
+
generation: InvocationEvent.Generation,
|
|
194
181
|
invokeId: string,
|
|
195
182
|
childId: string,
|
|
196
183
|
descriptor: ChildMachine.Any | undefined,
|
|
@@ -256,7 +243,7 @@ const startResolved = (
|
|
|
256
243
|
}
|
|
257
244
|
return sendLifecycle(
|
|
258
245
|
scope,
|
|
259
|
-
InvocationEvent.done(path, invokeId, outcome.output),
|
|
246
|
+
InvocationEvent.done(path, invokeId, generation, outcome.output),
|
|
260
247
|
activityKind === undefined ? undefined : activitySessionId
|
|
261
248
|
)
|
|
262
249
|
}
|
|
@@ -267,7 +254,7 @@ const startResolved = (
|
|
|
267
254
|
) {
|
|
268
255
|
return sendLifecycle(
|
|
269
256
|
scope,
|
|
270
|
-
InvocationEvent.failure(path, invokeId, outcome.error),
|
|
257
|
+
InvocationEvent.failure(path, invokeId, generation, outcome.error),
|
|
271
258
|
activityKind === undefined ? undefined : activitySessionId
|
|
272
259
|
)
|
|
273
260
|
}
|
|
@@ -277,7 +264,7 @@ const startResolved = (
|
|
|
277
264
|
...(onSnapshot === undefined ? undefined : {
|
|
278
265
|
onSnapshot: (isCurrent: () => boolean, snapshot: any) =>
|
|
279
266
|
isCurrent()
|
|
280
|
-
? sendLifecycle(scope, InvocationEvent.snapshot(path, invokeId, snapshot))
|
|
267
|
+
? sendLifecycle(scope, InvocationEvent.snapshot(path, invokeId, generation, snapshot))
|
|
281
268
|
: Effect.void
|
|
282
269
|
})
|
|
283
270
|
})
|
|
@@ -296,6 +283,7 @@ const start = (
|
|
|
296
283
|
scope: Runtime.ProcessScope<any>,
|
|
297
284
|
ownedChildren: Runtime.OwnedChildRuntime,
|
|
298
285
|
path: string,
|
|
286
|
+
generation: InvocationEvent.Generation,
|
|
299
287
|
config: AnyConfig
|
|
300
288
|
): Effect.Effect<void, any, any> => {
|
|
301
289
|
const invokeId = String(config.id)
|
|
@@ -305,6 +293,7 @@ const start = (
|
|
|
305
293
|
scope,
|
|
306
294
|
ownedChildren,
|
|
307
295
|
path,
|
|
296
|
+
generation,
|
|
308
297
|
invokeId,
|
|
309
298
|
config.address === undefined ? makeChildId(path, invokeId) : String(config.address),
|
|
310
299
|
config.descriptor,
|
|
@@ -321,6 +310,7 @@ const startStaticChild = (
|
|
|
321
310
|
scope: Runtime.ProcessScope<any>,
|
|
322
311
|
ownedChildren: Runtime.OwnedChildRuntime,
|
|
323
312
|
path: string,
|
|
313
|
+
generation: InvocationEvent.Generation,
|
|
324
314
|
raw: Extract<InvocationDefinition.InvocationDefinition, { readonly child: ChildMachine.Any }>
|
|
325
315
|
): Effect.Effect<void, any, any> => {
|
|
326
316
|
// A zero-input child has no entry-context dependency. Reuse the descriptor's
|
|
@@ -333,10 +323,11 @@ const startStaticChild = (
|
|
|
333
323
|
scope,
|
|
334
324
|
ownedChildren,
|
|
335
325
|
path,
|
|
326
|
+
generation,
|
|
336
327
|
descriptor.id,
|
|
337
328
|
descriptor.id,
|
|
338
329
|
descriptor,
|
|
339
|
-
descriptor[ChildMachineLogicTypeId],
|
|
330
|
+
(descriptor as unknown as ChildMachineLogicSlot)[ChildMachineLogicTypeId],
|
|
340
331
|
raw.onDone,
|
|
341
332
|
raw.onFailure,
|
|
342
333
|
raw.onSnapshot,
|
|
@@ -362,6 +353,11 @@ export const startAll = (
|
|
|
362
353
|
const effects = Planner.sortEntryPaths(machine, paths)
|
|
363
354
|
.filter((path) => configuration.active.has(path))
|
|
364
355
|
.flatMap((path) => {
|
|
356
|
+
const definitions = InvocationDefinition.definitions(Configuration.getStateConfigByPath(machine, path)?.invoke)
|
|
357
|
+
if (definitions.length === 0) return []
|
|
358
|
+
// Every invocation started by this entry shares one generation, which
|
|
359
|
+
// its outcomes carry until the state exits.
|
|
360
|
+
const generation = ownedChildren.beginGeneration(path)
|
|
365
361
|
const context = {
|
|
366
362
|
...(Configuration.getMachineReferences(configuration) ?? { self: scope.self, parent: scope.parent }),
|
|
367
363
|
children,
|
|
@@ -370,12 +366,10 @@ export const startAll = (
|
|
|
370
366
|
ancestors: Configuration.getParentValues(machine, configuration, path),
|
|
371
367
|
event
|
|
372
368
|
}
|
|
373
|
-
return
|
|
374
|
-
definition
|
|
375
|
-
) =>
|
|
369
|
+
return definitions.map((definition) =>
|
|
376
370
|
"child" in definition && !("input" in definition)
|
|
377
|
-
? startStaticChild(scope, ownedChildren, path, definition)
|
|
378
|
-
: start(scope, ownedChildren, path, resolveOne(definition, context, path))
|
|
371
|
+
? startStaticChild(scope, ownedChildren, path, generation, definition)
|
|
372
|
+
: start(scope, ownedChildren, path, generation, resolveOne(definition, context, path, generation))
|
|
379
373
|
)
|
|
380
374
|
})
|
|
381
375
|
return effects.length === 0 ? undefined : runSequentialDiscard(effects)
|