@typeonce/effect-machine 0.7.0 → 0.9.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/README.md +85 -24
- package/dist/Machine.d.ts +545 -444
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +69 -172
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/activities.d.ts +5 -12
- package/dist/internal/machine/activities.d.ts.map +1 -1
- package/dist/internal/machine/activities.js +47 -17
- package/dist/internal/machine/activities.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +10 -4
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +103 -20
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +31 -0
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts +10 -2
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +93 -34
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +39 -0
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -0
- package/dist/internal/machine/invocationEvent.js +43 -0
- package/dist/internal/machine/invocationEvent.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +6 -50
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +30 -81
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +12 -1
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +90 -37
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +9 -0
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +114 -0
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/serialization.d.ts.map +1 -1
- package/dist/internal/machine/serialization.js +53 -21
- package/dist/internal/machine/serialization.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +4 -4
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +18 -11
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +2 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -0
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +5 -5
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +39 -13
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +10 -3
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +11 -5
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +174 -121
- package/package.json +3 -3
- package/src/Machine.ts +1336 -872
- package/src/internal/machine/activities.ts +48 -33
- package/src/internal/machine/atom.ts +13 -6
- package/src/internal/machine/configuration.ts +102 -23
- package/src/internal/machine/executionPlan.ts +35 -0
- package/src/internal/machine/invocation.ts +180 -49
- package/src/internal/machine/invocationEvent.ts +72 -0
- package/src/internal/machine/machine.ts +105 -403
- package/src/internal/machine/planner.ts +110 -48
- package/src/internal/machine/protocol.ts +149 -0
- package/src/internal/machine/serialization.ts +56 -31
- package/src/internal/machine/stateDefinition.ts +22 -11
- package/src/internal/machine/symbols.ts +3 -0
- package/src/internal/machine/topology.ts +44 -18
- package/src/internal/testing/machine/verification.ts +13 -3
- package/src/unstable/reactivity/AtomMachine.ts +12 -5
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Duration from "effect/Duration"
|
|
2
1
|
import * as Effect from "effect/Effect"
|
|
3
2
|
import * as Inspectable from "effect/Inspectable"
|
|
4
3
|
import * as Option from "effect/Option"
|
|
@@ -34,6 +33,7 @@ import type { EnsureExecutable } from "./readiness.js"
|
|
|
34
33
|
import * as internalRuntime from "./runtime.js"
|
|
35
34
|
import * as Serialization from "./serialization.js"
|
|
36
35
|
import * as StateDefinition from "./stateDefinition.js"
|
|
36
|
+
import { ChildMachineLogicTypeId } from "./symbols.js"
|
|
37
37
|
import * as Topology from "./topology.js"
|
|
38
38
|
|
|
39
39
|
export {
|
|
@@ -45,13 +45,12 @@ export {
|
|
|
45
45
|
StartupError,
|
|
46
46
|
StoppedError
|
|
47
47
|
} from "./errors.js"
|
|
48
|
-
export { InitialEventTypeId } from "./symbols.js"
|
|
48
|
+
export { ChildMachineLogicTypeId, InitialEventTypeId } from "./symbols.js"
|
|
49
49
|
|
|
50
50
|
const TypeId = "~effect/Machine"
|
|
51
51
|
export const SnapshotBuilderStateTypeId: unique symbol = Symbol("effect/Machine/SnapshotBuilderState")
|
|
52
52
|
export const InvokeTypeId: unique symbol = Symbol.for("effect/Machine/Invoke")
|
|
53
53
|
const ChildMachineTypeId = "~effect/Machine/ChildMachine"
|
|
54
|
-
type InvokeLifecycleId = string
|
|
55
54
|
type IsAny<A> = 0 extends 1 & A ? true : false
|
|
56
55
|
type MachineRuntimeRequirement = internalRuntime.MachineRuntime
|
|
57
56
|
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<
|
|
@@ -278,10 +277,14 @@ type FromMethodKind = "leaf" | "nested"
|
|
|
278
277
|
|
|
279
278
|
const withFrom = <Method extends (value: unknown, ...args: ReadonlyArray<any>) => unknown>(
|
|
280
279
|
method: Method,
|
|
281
|
-
kind: FromMethodKind
|
|
280
|
+
kind: FromMethodKind,
|
|
281
|
+
valued: boolean
|
|
282
282
|
): Method & { readonly from: (...args: ReadonlyArray<any>) => unknown } => {
|
|
283
283
|
Object.defineProperty(method, "from", {
|
|
284
284
|
value: (...args: ReadonlyArray<any>) => {
|
|
285
|
+
if (!valued) {
|
|
286
|
+
return method(undefined, ...args)
|
|
287
|
+
}
|
|
285
288
|
const omitted = args.length === 0 || (kind === "nested" && args.length === 1 && typeof args[0] === "function")
|
|
286
289
|
const input = omitted ? {} : args[0]
|
|
287
290
|
const rest = omitted ? args : args.slice(1)
|
|
@@ -312,7 +315,8 @@ const makeSnapshotBuilder = (
|
|
|
312
315
|
builder[key] = withFrom(
|
|
313
316
|
(value: unknown, selector?: (builder: unknown) => unknown) =>
|
|
314
317
|
makeSnapshotForNode(definition, key, value, selector, options),
|
|
315
|
-
node.states === undefined ? "leaf" : "nested"
|
|
318
|
+
node.states === undefined ? "leaf" : "nested",
|
|
319
|
+
node.schema !== undefined
|
|
316
320
|
)
|
|
317
321
|
}
|
|
318
322
|
return builder
|
|
@@ -339,14 +343,18 @@ const makeParallelSnapshotBuilder = (
|
|
|
339
343
|
}
|
|
340
344
|
const path = options.prefix === "" ? key : `${options.prefix}.${key}`
|
|
341
345
|
const node = Topology.getStateNodeDefinition(path, definition)
|
|
342
|
-
builder[key] = withFrom(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
builder[key] = withFrom(
|
|
347
|
+
(value: unknown, selector?: (builder: unknown) => unknown) => {
|
|
348
|
+
const nextRegions: Record<string, unknown> = {}
|
|
349
|
+
for (const regionKey of Object.keys(regions)) {
|
|
350
|
+
nextRegions[regionKey] = regions[regionKey]
|
|
351
|
+
}
|
|
352
|
+
nextRegions[key] = makeSnapshotForNode(definition, key, value, selector, options)
|
|
353
|
+
return makeParallelSnapshotBuilder(states, options, nextRegions)
|
|
354
|
+
},
|
|
355
|
+
node.states === undefined ? "leaf" : "nested",
|
|
356
|
+
node.schema !== undefined
|
|
357
|
+
)
|
|
350
358
|
}
|
|
351
359
|
return builder
|
|
352
360
|
}
|
|
@@ -525,13 +533,25 @@ const makeLocalTargetChildBuilder = (
|
|
|
525
533
|
builder[child.key] = () => Topology.makeChoiceTarget(child.path, parent.path, values)
|
|
526
534
|
continue
|
|
527
535
|
}
|
|
528
|
-
builder[child.key] = withFrom(
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (
|
|
534
|
-
|
|
536
|
+
builder[child.key] = withFrom(
|
|
537
|
+
(value: unknown, selector?: (builder: unknown) => unknown) => {
|
|
538
|
+
if (child.type === "atomic" || child.type === "final") {
|
|
539
|
+
return makeTargetWithValues(child.path, value, values)
|
|
540
|
+
}
|
|
541
|
+
if (child.type === "parallel") {
|
|
542
|
+
if (source !== child.path && !source.startsWith(`${child.path}.`)) {
|
|
543
|
+
return makeParallelTarget(states, child, value, selector, values)
|
|
544
|
+
}
|
|
545
|
+
if (selector === undefined) {
|
|
546
|
+
throw new Error(`Machine expected target "${child.path}" builder to provide an active child state`)
|
|
547
|
+
}
|
|
548
|
+
return selector(makeLocalTargetChildBuilder(
|
|
549
|
+
states,
|
|
550
|
+
stateNodes,
|
|
551
|
+
child.path,
|
|
552
|
+
child.schema === undefined ? values : extendTargetValues(values, child.path, value),
|
|
553
|
+
source
|
|
554
|
+
))
|
|
535
555
|
}
|
|
536
556
|
if (selector === undefined) {
|
|
537
557
|
throw new Error(`Machine expected target "${child.path}" builder to provide an active child state`)
|
|
@@ -540,21 +560,13 @@ const makeLocalTargetChildBuilder = (
|
|
|
540
560
|
states,
|
|
541
561
|
stateNodes,
|
|
542
562
|
child.path,
|
|
543
|
-
extendTargetValues(values, child.path, value),
|
|
563
|
+
child.schema === undefined ? values : extendTargetValues(values, child.path, value),
|
|
544
564
|
source
|
|
545
565
|
))
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
return selector(makeLocalTargetChildBuilder(
|
|
551
|
-
states,
|
|
552
|
-
stateNodes,
|
|
553
|
-
child.path,
|
|
554
|
-
extendTargetValues(values, child.path, value),
|
|
555
|
-
source
|
|
556
|
-
))
|
|
557
|
-
}, child.type === "atomic" || child.type === "final" ? "leaf" : "nested")
|
|
566
|
+
},
|
|
567
|
+
child.type === "atomic" || child.type === "final" ? "leaf" : "nested",
|
|
568
|
+
child.schema !== undefined
|
|
569
|
+
)
|
|
558
570
|
}
|
|
559
571
|
return builder
|
|
560
572
|
}
|
|
@@ -569,12 +581,19 @@ const makeLocalTargetBuilder = (
|
|
|
569
581
|
return {}
|
|
570
582
|
}
|
|
571
583
|
const builder = makeLocalTargetChildBuilder(states, stateNodes, scope, undefined, source) as Record<string, unknown>
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
584
|
+
const scopeNode = getTargetBuilderNode(stateNodes, scope)
|
|
585
|
+
if (scopeNode.schema !== undefined) {
|
|
586
|
+
builder.with = withFrom(
|
|
587
|
+
(value: unknown, selector?: (builder: unknown) => unknown) => {
|
|
588
|
+
if (selector === undefined) {
|
|
589
|
+
throw new Error(`Machine expected target "${scope}" builder to provide an active child state`)
|
|
590
|
+
}
|
|
591
|
+
return selector(makeLocalTargetChildBuilder(states, stateNodes, scope, { [scope]: value }, source))
|
|
592
|
+
},
|
|
593
|
+
"nested",
|
|
594
|
+
true
|
|
595
|
+
)
|
|
596
|
+
}
|
|
578
597
|
return builder
|
|
579
598
|
}
|
|
580
599
|
|
|
@@ -610,12 +629,31 @@ const makeBranchTargetNodeBuilder = (
|
|
|
610
629
|
): unknown => {
|
|
611
630
|
const node = getTargetBuilderNode(stateNodes, path)
|
|
612
631
|
if (node.type === "atomic" || node.type === "final") {
|
|
613
|
-
return withFrom(
|
|
632
|
+
return withFrom(
|
|
633
|
+
(value: unknown) => makeTargetWithValues(node.path, value, values),
|
|
634
|
+
"leaf",
|
|
635
|
+
node.schema !== undefined
|
|
636
|
+
)
|
|
614
637
|
}
|
|
615
|
-
const builder = withFrom(
|
|
616
|
-
|
|
617
|
-
if (
|
|
618
|
-
|
|
638
|
+
const builder = withFrom(
|
|
639
|
+
(value: unknown, selector?: (builder: unknown) => unknown) => {
|
|
640
|
+
if (node.type === "parallel") {
|
|
641
|
+
if (source !== node.path && !source.startsWith(`${node.path}.`)) {
|
|
642
|
+
return makeParallelTarget(states, node, value, selector, values)
|
|
643
|
+
}
|
|
644
|
+
if (selector === undefined) {
|
|
645
|
+
throw new Error(`Machine expected target "${node.path}" builder to provide an active child state`)
|
|
646
|
+
}
|
|
647
|
+
const nextBuilder: Record<string, unknown> = {}
|
|
648
|
+
addBranchTargetChildren(
|
|
649
|
+
nextBuilder,
|
|
650
|
+
states,
|
|
651
|
+
stateNodes,
|
|
652
|
+
node.path,
|
|
653
|
+
node.schema === undefined ? values : extendTargetValues(values, node.path, value),
|
|
654
|
+
source
|
|
655
|
+
)
|
|
656
|
+
return selector(nextBuilder)
|
|
619
657
|
}
|
|
620
658
|
if (selector === undefined) {
|
|
621
659
|
throw new Error(`Machine expected target "${node.path}" builder to provide an active child state`)
|
|
@@ -626,25 +664,14 @@ const makeBranchTargetNodeBuilder = (
|
|
|
626
664
|
states,
|
|
627
665
|
stateNodes,
|
|
628
666
|
node.path,
|
|
629
|
-
extendTargetValues(values, node.path, value),
|
|
667
|
+
node.schema === undefined ? values : extendTargetValues(values, node.path, value),
|
|
630
668
|
source
|
|
631
669
|
)
|
|
632
670
|
return selector(nextBuilder)
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
const nextBuilder: Record<string, unknown> = {}
|
|
638
|
-
addBranchTargetChildren(
|
|
639
|
-
nextBuilder,
|
|
640
|
-
states,
|
|
641
|
-
stateNodes,
|
|
642
|
-
node.path,
|
|
643
|
-
extendTargetValues(values, node.path, value),
|
|
644
|
-
source
|
|
645
|
-
)
|
|
646
|
-
return selector(nextBuilder)
|
|
647
|
-
}, "nested") as unknown as Record<string, unknown>
|
|
671
|
+
},
|
|
672
|
+
"nested",
|
|
673
|
+
node.schema !== undefined
|
|
674
|
+
) as unknown as Record<string, unknown>
|
|
648
675
|
if (node.type !== "parallel" || source === node.path || source.startsWith(`${node.path}.`)) {
|
|
649
676
|
addBranchTargetChildren(builder, states, stateNodes, node.path, values, source)
|
|
650
677
|
}
|
|
@@ -855,6 +882,16 @@ export const event = <
|
|
|
855
882
|
...args: EventConstructorArgs<EventSchema>
|
|
856
883
|
): EventSchema["Type"] => Protocol.makeEvent(machine, schema, args.length === 0 ? {} : args[0])
|
|
857
884
|
|
|
885
|
+
export const events = <M extends Machine.Any>(
|
|
886
|
+
machine: M
|
|
887
|
+
): Machine.EventConstructors<Machine.InputEvents<M>> =>
|
|
888
|
+
Protocol.eventConstructors(machine.events) as Machine.EventConstructors<Machine.InputEvents<M>>
|
|
889
|
+
|
|
890
|
+
export const internalEvents = <M extends Machine.Any>(
|
|
891
|
+
machine: M
|
|
892
|
+
): Machine.EventConstructors<Machine.InternalEvents<M>> =>
|
|
893
|
+
Protocol.eventConstructors(machine.internalEvents) as Machine.EventConstructors<Machine.InternalEvents<M>>
|
|
894
|
+
|
|
858
895
|
export const encodeSnapshot: <
|
|
859
896
|
const States extends Machine.StateSchemas,
|
|
860
897
|
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -929,145 +966,6 @@ export const decodeSnapshot: <
|
|
|
929
966
|
Machine.SnapshotDecodingServices<States>
|
|
930
967
|
> = Serialization.decodeSnapshot as any
|
|
931
968
|
|
|
932
|
-
export const invoke = <
|
|
933
|
-
ChildState,
|
|
934
|
-
ChildEvent,
|
|
935
|
-
ChildError = never,
|
|
936
|
-
ChildRequirements = never,
|
|
937
|
-
ChildOutput = never,
|
|
938
|
-
ChildInitialError = never,
|
|
939
|
-
Event = never,
|
|
940
|
-
Address extends ChildAddress<never> | undefined = undefined
|
|
941
|
-
>(
|
|
942
|
-
config:
|
|
943
|
-
& {
|
|
944
|
-
readonly id: InvokeLifecycleId
|
|
945
|
-
readonly src: () => Logic<
|
|
946
|
-
ChildState,
|
|
947
|
-
ChildEvent,
|
|
948
|
-
ChildError,
|
|
949
|
-
ChildRequirements,
|
|
950
|
-
ChildOutput,
|
|
951
|
-
ChildInitialError
|
|
952
|
-
>
|
|
953
|
-
readonly snapshot?: (
|
|
954
|
-
context: Machine.InvokeSnapshotContext<ChildState, ChildError, ChildOutput>
|
|
955
|
-
) => Event | undefined
|
|
956
|
-
}
|
|
957
|
-
& ([Address] extends [undefined] ? {
|
|
958
|
-
readonly address?: never
|
|
959
|
-
}
|
|
960
|
-
: {
|
|
961
|
-
readonly address: Exclude<Address, undefined>
|
|
962
|
-
} & ChildAddress.Compatibility<Exclude<Address, undefined>, NoInfer<ChildEvent>>)
|
|
963
|
-
): Machine.InvokeConfig<
|
|
964
|
-
any,
|
|
965
|
-
any,
|
|
966
|
-
any,
|
|
967
|
-
any,
|
|
968
|
-
Event,
|
|
969
|
-
ChildState,
|
|
970
|
-
ChildEvent,
|
|
971
|
-
ChildError,
|
|
972
|
-
ChildRequirements,
|
|
973
|
-
ChildOutput,
|
|
974
|
-
ChildInitialError
|
|
975
|
-
> => ({
|
|
976
|
-
...config,
|
|
977
|
-
[InvokeTypeId]: undefined as any,
|
|
978
|
-
[Activities.ActivityMetadataTypeId]: { type: "process" }
|
|
979
|
-
})
|
|
980
|
-
|
|
981
|
-
type InvokeEffectResult<Requirements, Event> = Machine.InvokeConfig<
|
|
982
|
-
any,
|
|
983
|
-
any,
|
|
984
|
-
any,
|
|
985
|
-
any,
|
|
986
|
-
never,
|
|
987
|
-
void,
|
|
988
|
-
never,
|
|
989
|
-
never,
|
|
990
|
-
Requirements,
|
|
991
|
-
Event | void,
|
|
992
|
-
never
|
|
993
|
-
>
|
|
994
|
-
|
|
995
|
-
type InvokeEffectIsInfallible<Fx extends Effect.Effect<any, any, any>> = IsAny<Effect.Error<Fx>> extends true ? false
|
|
996
|
-
: [Effect.Error<Fx>] extends [never] ? true
|
|
997
|
-
: false
|
|
998
|
-
|
|
999
|
-
type InvokeEffectConfig<
|
|
1000
|
-
Fx extends Effect.Effect<any, any, any>,
|
|
1001
|
-
SuccessEvent,
|
|
1002
|
-
FailureEvent
|
|
1003
|
-
> =
|
|
1004
|
-
& {
|
|
1005
|
-
readonly id: InvokeLifecycleId
|
|
1006
|
-
readonly effect: Fx
|
|
1007
|
-
readonly onSuccess: (value: NoInfer<Effect.Success<Fx>>) => SuccessEvent | void
|
|
1008
|
-
}
|
|
1009
|
-
& (
|
|
1010
|
-
InvokeEffectIsInfallible<Fx> extends true ? {
|
|
1011
|
-
readonly onFailure?: never
|
|
1012
|
-
}
|
|
1013
|
-
: {
|
|
1014
|
-
readonly onFailure: (error: NoInfer<Effect.Error<Fx>>) => FailureEvent | void
|
|
1015
|
-
}
|
|
1016
|
-
)
|
|
1017
|
-
|
|
1018
|
-
export const invokeEffect = <
|
|
1019
|
-
const Fx extends Effect.Effect<any, any, any>,
|
|
1020
|
-
SuccessEvent,
|
|
1021
|
-
FailureEvent = never
|
|
1022
|
-
>(
|
|
1023
|
-
config: InvokeEffectConfig<Fx, SuccessEvent, FailureEvent>
|
|
1024
|
-
): InvokeEffectResult<
|
|
1025
|
-
Effect.Services<Fx>,
|
|
1026
|
-
SuccessEvent | (InvokeEffectIsInfallible<Fx> extends true ? never : FailureEvent)
|
|
1027
|
-
> =>
|
|
1028
|
-
((config: {
|
|
1029
|
-
readonly id: string
|
|
1030
|
-
readonly effect: Effect.Effect<unknown, unknown, unknown>
|
|
1031
|
-
readonly onSuccess: (value: unknown) => unknown
|
|
1032
|
-
readonly onFailure?: (error: unknown) => unknown
|
|
1033
|
-
}) => ({
|
|
1034
|
-
...invoke({
|
|
1035
|
-
id: config.id,
|
|
1036
|
-
src: () =>
|
|
1037
|
-
effect(
|
|
1038
|
-
config.onFailure === undefined
|
|
1039
|
-
? Effect.map(config.effect, config.onSuccess)
|
|
1040
|
-
: Effect.matchEffect(config.effect, {
|
|
1041
|
-
onFailure: (error) => Effect.succeed(config.onFailure!(error)),
|
|
1042
|
-
onSuccess: (value) => Effect.succeed(config.onSuccess(value))
|
|
1043
|
-
})
|
|
1044
|
-
)
|
|
1045
|
-
}),
|
|
1046
|
-
[Activities.ActivityMetadataTypeId]: {
|
|
1047
|
-
type: "effect",
|
|
1048
|
-
outcomes: {
|
|
1049
|
-
success: "dynamic",
|
|
1050
|
-
failure: config.onFailure === undefined ? "none" : "dynamic"
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
}))(config as any) as any
|
|
1054
|
-
|
|
1055
|
-
export const after = <Event extends { readonly _tag: PropertyKey }>(
|
|
1056
|
-
duration: Duration.Input,
|
|
1057
|
-
event: Event,
|
|
1058
|
-
options?: { readonly id?: InvokeLifecycleId }
|
|
1059
|
-
): InvokeEffectResult<never, Event> => ({
|
|
1060
|
-
...invoke({
|
|
1061
|
-
id: options?.id ?? `Machine.after:${String(event._tag)}`,
|
|
1062
|
-
src: () => effect(Effect.as(Effect.sleep(duration), event))
|
|
1063
|
-
}),
|
|
1064
|
-
[Activities.ActivityMetadataTypeId]: {
|
|
1065
|
-
type: "timer",
|
|
1066
|
-
duration: Duration.format(Duration.fromInputUnsafe(duration)),
|
|
1067
|
-
event: String(event._tag)
|
|
1068
|
-
}
|
|
1069
|
-
})
|
|
1070
|
-
|
|
1071
969
|
export const retag = (
|
|
1072
970
|
target: Machine.TaggedSchema,
|
|
1073
971
|
source: { readonly _tag: PropertyKey },
|
|
@@ -1076,199 +974,6 @@ export const retag = (
|
|
|
1076
974
|
const { _tag: _, ...fields } = source
|
|
1077
975
|
return target.make({ ...fields, ...((patch ?? {}) as object) } as never)
|
|
1078
976
|
}
|
|
1079
|
-
|
|
1080
|
-
type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.Void ? {
|
|
1081
|
-
readonly input?: never
|
|
1082
|
-
}
|
|
1083
|
-
: {
|
|
1084
|
-
readonly input: Input["Type"]
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
export const invokeMachine: {
|
|
1088
|
-
<
|
|
1089
|
-
const States extends Machine.StateSchemas,
|
|
1090
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
1091
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
1092
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
1093
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
1094
|
-
E = never,
|
|
1095
|
-
R = never,
|
|
1096
|
-
InitialE = never,
|
|
1097
|
-
InitialR = never,
|
|
1098
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
1099
|
-
Output = never,
|
|
1100
|
-
SnapshotEvent = never,
|
|
1101
|
-
DoneEvent = never,
|
|
1102
|
-
Id extends string = string,
|
|
1103
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
1104
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
1105
|
-
>(
|
|
1106
|
-
config:
|
|
1107
|
-
& {
|
|
1108
|
-
readonly child: ChildMachine<
|
|
1109
|
-
Id,
|
|
1110
|
-
& Machine<
|
|
1111
|
-
States,
|
|
1112
|
-
Events,
|
|
1113
|
-
Input,
|
|
1114
|
-
UnhandledStates,
|
|
1115
|
-
E,
|
|
1116
|
-
R,
|
|
1117
|
-
InitialE,
|
|
1118
|
-
InitialR,
|
|
1119
|
-
FinalStates,
|
|
1120
|
-
Output,
|
|
1121
|
-
Emits,
|
|
1122
|
-
OutputStates,
|
|
1123
|
-
InputEvents
|
|
1124
|
-
>
|
|
1125
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
1126
|
-
>
|
|
1127
|
-
readonly snapshot?: (
|
|
1128
|
-
context: Machine.InvokeSnapshotContext<
|
|
1129
|
-
Machine.Snapshot<States>,
|
|
1130
|
-
| E
|
|
1131
|
-
| ActionError<R>
|
|
1132
|
-
| InfiniteTransitionError
|
|
1133
|
-
| MachineSchemaDecodeError
|
|
1134
|
-
| StoppedError,
|
|
1135
|
-
Output
|
|
1136
|
-
>
|
|
1137
|
-
) => SnapshotEvent | undefined
|
|
1138
|
-
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined
|
|
1139
|
-
}
|
|
1140
|
-
& InvokeMachineInput<Input>
|
|
1141
|
-
): Machine.InvokeConfig<
|
|
1142
|
-
any,
|
|
1143
|
-
any,
|
|
1144
|
-
any,
|
|
1145
|
-
any,
|
|
1146
|
-
SnapshotEvent,
|
|
1147
|
-
Machine.Snapshot<States>,
|
|
1148
|
-
Machine.EventOf<InputEvents>,
|
|
1149
|
-
E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
|
|
1150
|
-
ExcludeCompatibleRuntime<
|
|
1151
|
-
Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>,
|
|
1152
|
-
Machine.EventOf<Events>,
|
|
1153
|
-
Machine.EmitOf<Emits>
|
|
1154
|
-
>,
|
|
1155
|
-
Output,
|
|
1156
|
-
| InitialE
|
|
1157
|
-
| E
|
|
1158
|
-
| ActionError<InitialR | R>
|
|
1159
|
-
| InfiniteTransitionError
|
|
1160
|
-
| MachineSchemaDecodeError
|
|
1161
|
-
| StartupError
|
|
1162
|
-
| StoppedError,
|
|
1163
|
-
Machine.EmitOf<Emits>,
|
|
1164
|
-
DoneEvent
|
|
1165
|
-
>
|
|
1166
|
-
<
|
|
1167
|
-
const States extends Machine.StateSchemas,
|
|
1168
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
1169
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
1170
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
1171
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
1172
|
-
E = never,
|
|
1173
|
-
R = never,
|
|
1174
|
-
InitialE = never,
|
|
1175
|
-
InitialR = never,
|
|
1176
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
1177
|
-
Output = never,
|
|
1178
|
-
SnapshotEvent = never,
|
|
1179
|
-
Id extends string = string,
|
|
1180
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
1181
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
1182
|
-
>(
|
|
1183
|
-
config:
|
|
1184
|
-
& {
|
|
1185
|
-
readonly child: ChildMachine<
|
|
1186
|
-
Id,
|
|
1187
|
-
& Machine<
|
|
1188
|
-
States,
|
|
1189
|
-
Events,
|
|
1190
|
-
Input,
|
|
1191
|
-
UnhandledStates,
|
|
1192
|
-
E,
|
|
1193
|
-
R,
|
|
1194
|
-
InitialE,
|
|
1195
|
-
InitialR,
|
|
1196
|
-
FinalStates,
|
|
1197
|
-
Output,
|
|
1198
|
-
Emits,
|
|
1199
|
-
OutputStates,
|
|
1200
|
-
InputEvents
|
|
1201
|
-
>
|
|
1202
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
1203
|
-
>
|
|
1204
|
-
readonly snapshot?: (
|
|
1205
|
-
context: Machine.InvokeSnapshotContext<
|
|
1206
|
-
Machine.Snapshot<States>,
|
|
1207
|
-
| E
|
|
1208
|
-
| ActionError<R>
|
|
1209
|
-
| InfiniteTransitionError
|
|
1210
|
-
| MachineSchemaDecodeError
|
|
1211
|
-
| StoppedError,
|
|
1212
|
-
Output
|
|
1213
|
-
>
|
|
1214
|
-
) => SnapshotEvent | undefined
|
|
1215
|
-
readonly onDone?: never
|
|
1216
|
-
}
|
|
1217
|
-
& InvokeMachineInput<Input>
|
|
1218
|
-
): Machine.InvokeConfig<
|
|
1219
|
-
any,
|
|
1220
|
-
any,
|
|
1221
|
-
any,
|
|
1222
|
-
any,
|
|
1223
|
-
SnapshotEvent,
|
|
1224
|
-
Machine.Snapshot<States>,
|
|
1225
|
-
Machine.EventOf<InputEvents>,
|
|
1226
|
-
E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
|
|
1227
|
-
ExcludeCompatibleRuntime<
|
|
1228
|
-
Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>,
|
|
1229
|
-
Machine.EventOf<Events>,
|
|
1230
|
-
Machine.EmitOf<Emits>
|
|
1231
|
-
>,
|
|
1232
|
-
Output,
|
|
1233
|
-
| InitialE
|
|
1234
|
-
| E
|
|
1235
|
-
| ActionError<InitialR | R>
|
|
1236
|
-
| InfiniteTransitionError
|
|
1237
|
-
| MachineSchemaDecodeError
|
|
1238
|
-
| StartupError
|
|
1239
|
-
| StoppedError,
|
|
1240
|
-
Machine.EmitOf<Emits>
|
|
1241
|
-
>
|
|
1242
|
-
} = ((config: {
|
|
1243
|
-
readonly child: ChildMachine.Any
|
|
1244
|
-
readonly input?: unknown
|
|
1245
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<any, any, any>) => unknown
|
|
1246
|
-
readonly onDone?: (context: Machine.InvokeDoneContext<any>) => unknown
|
|
1247
|
-
}) => {
|
|
1248
|
-
const machine = config.child.machine
|
|
1249
|
-
// An invoke descriptor fixes both its machine and input. Compile its process
|
|
1250
|
-
// logic once; all mutable execution state belongs to the process instance.
|
|
1251
|
-
const logic = machine.input === undefined
|
|
1252
|
-
? (internalProcess.toProcessLogic as any)(machine)
|
|
1253
|
-
: (internalProcess.toProcessLogic as any)(machine, config.input)
|
|
1254
|
-
return {
|
|
1255
|
-
id: config.child.id,
|
|
1256
|
-
address: config.child.id,
|
|
1257
|
-
descriptor: config.child,
|
|
1258
|
-
src: () => logic,
|
|
1259
|
-
snapshot: config.snapshot,
|
|
1260
|
-
onDone: config.onDone,
|
|
1261
|
-
[Activities.ActivityMetadataTypeId]: {
|
|
1262
|
-
type: "machine",
|
|
1263
|
-
child: {
|
|
1264
|
-
id: config.child.id,
|
|
1265
|
-
machineId: machine.id ?? null
|
|
1266
|
-
}
|
|
1267
|
-
},
|
|
1268
|
-
[InvokeTypeId]: undefined as any
|
|
1269
|
-
}
|
|
1270
|
-
}) as any
|
|
1271
|
-
|
|
1272
977
|
export const planInitial: <
|
|
1273
978
|
const States extends Machine.StateSchemas,
|
|
1274
979
|
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -1466,7 +1171,7 @@ export const plan: <
|
|
|
1466
1171
|
>
|
|
1467
1172
|
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
1468
1173
|
state: Machine.Snapshot<States>,
|
|
1469
|
-
event: Machine.
|
|
1174
|
+
event: Machine.EventInputOf<InputEvents>
|
|
1470
1175
|
) => Effect.Effect<
|
|
1471
1176
|
& {
|
|
1472
1177
|
readonly next: Machine.Snapshot<States>
|
|
@@ -1504,13 +1209,6 @@ export const plan: <
|
|
|
1504
1209
|
never
|
|
1505
1210
|
> = internalPlanner.plan as any
|
|
1506
1211
|
|
|
1507
|
-
export const effect = <Output, Error = never, Requirements = never>(
|
|
1508
|
-
effect: Effect.Effect<Output, Error, Requirements>
|
|
1509
|
-
): Logic<void, never, Error, Requirements, Output> => ({
|
|
1510
|
-
initial: () => Effect.void,
|
|
1511
|
-
run: () => effect
|
|
1512
|
-
})
|
|
1513
|
-
|
|
1514
1212
|
export const logic = <
|
|
1515
1213
|
State,
|
|
1516
1214
|
Event = never,
|
|
@@ -1559,7 +1257,11 @@ export const child = <const Id extends string, M extends Machine.Any>(
|
|
|
1559
1257
|
): ChildMachine<Id, M> => ({
|
|
1560
1258
|
[ChildMachineTypeId]: ChildMachineTypeId,
|
|
1561
1259
|
id,
|
|
1562
|
-
machine
|
|
1260
|
+
machine,
|
|
1261
|
+
[ChildMachineLogicTypeId]: (input) =>
|
|
1262
|
+
machine.input === undefined
|
|
1263
|
+
? (internalProcess.toProcessLogic as any)(machine)
|
|
1264
|
+
: (internalProcess.toProcessLogic as any)(machine, input)
|
|
1563
1265
|
})
|
|
1564
1266
|
|
|
1565
1267
|
export const childAddress = <Event = never>(id: string): ChildAddress<Event> => id as ChildAddress<Event>
|
|
@@ -1675,7 +1377,7 @@ export const start: <
|
|
|
1675
1377
|
) => Effect.Effect<
|
|
1676
1378
|
MachineRef<
|
|
1677
1379
|
Machine.Snapshot<States>,
|
|
1678
|
-
Machine.
|
|
1380
|
+
Machine.EventInputOf<InputEvents>,
|
|
1679
1381
|
| E
|
|
1680
1382
|
| ActionError<R>
|
|
1681
1383
|
| InfiniteTransitionError
|
|
@@ -1733,7 +1435,7 @@ export const resume: <
|
|
|
1733
1435
|
) => Effect.Effect<
|
|
1734
1436
|
MachineRef<
|
|
1735
1437
|
Machine.Snapshot<States>,
|
|
1736
|
-
Machine.
|
|
1438
|
+
Machine.EventInputOf<InputEvents>,
|
|
1737
1439
|
| E
|
|
1738
1440
|
| ActionError<R>
|
|
1739
1441
|
| InfiniteTransitionError
|