@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
|
@@ -34,7 +34,8 @@ import {
|
|
|
34
34
|
} from "./childRegistry.js"
|
|
35
35
|
import { ChildAlreadyExistsError, StoppedError } from "./errors.js"
|
|
36
36
|
import * as InspectionRuntime from "./inspectionRuntime.js"
|
|
37
|
-
import
|
|
37
|
+
import type * as InvocationEvent from "./invocationEvent.js"
|
|
38
|
+
import { type ChildMachineLogicSlot, ChildMachineLogicTypeId } from "./symbols.js"
|
|
38
39
|
|
|
39
40
|
/** @internal */
|
|
40
41
|
export const activeSnapshotObserver: unique symbol = Symbol.for("effect/Machine/activeSnapshotObserver")
|
|
@@ -106,7 +107,7 @@ export const succeedAcknowledgedMessage = <State>(
|
|
|
106
107
|
if (message.deferred !== undefined) {
|
|
107
108
|
Deferred.doneUnsafe(message.deferred, Effect.succeed(delivery as AcknowledgedDelivery<unknown>))
|
|
108
109
|
}
|
|
109
|
-
message.inspection?.complete(delivery
|
|
110
|
+
message.inspection?.complete(delivery)
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -519,6 +520,25 @@ interface ProcessSpawn<OwnerEvent = unknown> {
|
|
|
519
520
|
>
|
|
520
521
|
}
|
|
521
522
|
|
|
523
|
+
/**
|
|
524
|
+
* Service required by operations that act on the machine executing them,
|
|
525
|
+
* such as `sendTo`, `stopChild`, and `spawn`.
|
|
526
|
+
*
|
|
527
|
+
* **When to use**
|
|
528
|
+
*
|
|
529
|
+
* Name this requirement when annotating a reusable helper built from those
|
|
530
|
+
* operations, or when exporting a value whose inferred type includes it.
|
|
531
|
+
*
|
|
532
|
+
* **Details**
|
|
533
|
+
*
|
|
534
|
+
* A running machine provides this service to the effects it executes, so it
|
|
535
|
+
* never appears in the requirements of the machine itself. Only the type is
|
|
536
|
+
* public: the service cannot be constructed or provided outside a running
|
|
537
|
+
* machine.
|
|
538
|
+
*
|
|
539
|
+
* @category services
|
|
540
|
+
* @since 0.47.0
|
|
541
|
+
*/
|
|
522
542
|
export class MachineRuntime extends Context.Service<MachineRuntime, ProcessScope<any>>()(
|
|
523
543
|
"effect/Machine/MachineRuntime"
|
|
524
544
|
) {}
|
|
@@ -782,6 +802,12 @@ export interface OwnedChildRuntime {
|
|
|
782
802
|
makeLogic: () => ProcessLogic<any, any, any, any, any, any>,
|
|
783
803
|
options: OwnedChildSpawnOptions
|
|
784
804
|
) => Effect.Effect<void, any, any>
|
|
805
|
+
/**
|
|
806
|
+
* Begins the generation of an entered invoking state and retires the one it
|
|
807
|
+
* replaces. The generation stays current after its children finish and is
|
|
808
|
+
* retired only when the state exits, by `stopPaths` or `stopAll`.
|
|
809
|
+
*/
|
|
810
|
+
readonly beginGeneration: (path: string) => InvocationEvent.Generation
|
|
785
811
|
readonly stopAll: () => Effect.Effect<void>
|
|
786
812
|
readonly stopPaths: (paths: ReadonlyArray<string>) => Effect.Effect<void> | undefined
|
|
787
813
|
}
|
|
@@ -807,6 +833,13 @@ export interface ChildRuntime {
|
|
|
807
833
|
|
|
808
834
|
class OwnedChildRuntimeImpl implements OwnedChildRuntime {
|
|
809
835
|
private scopedServices: Context.Context<any> | undefined
|
|
836
|
+
// The current generation of each active invoking state path. Most
|
|
837
|
+
// configurations have one such path, held inline; further paths use the map.
|
|
838
|
+
// Entries are removed when their state exits, so neither outgrows the active
|
|
839
|
+
// configuration.
|
|
840
|
+
private generationPath: string | undefined
|
|
841
|
+
private generation: InvocationEvent.Generation | undefined
|
|
842
|
+
private generations: Map<string, InvocationEvent.Generation> | undefined
|
|
810
843
|
|
|
811
844
|
constructor(
|
|
812
845
|
private readonly registry: ChildRegistry,
|
|
@@ -924,8 +957,46 @@ class OwnedChildRuntimeImpl implements OwnedChildRuntime {
|
|
|
924
957
|
})
|
|
925
958
|
}
|
|
926
959
|
|
|
960
|
+
beginGeneration(path: string): InvocationEvent.Generation {
|
|
961
|
+
this.retireGeneration(path)
|
|
962
|
+
const generation: InvocationEvent.Generation = { current: true }
|
|
963
|
+
if (this.generationPath === undefined) {
|
|
964
|
+
this.generationPath = path
|
|
965
|
+
this.generation = generation
|
|
966
|
+
} else {
|
|
967
|
+
;(this.generations ??= new Map()).set(path, generation)
|
|
968
|
+
}
|
|
969
|
+
return generation
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
private retireGeneration(path: string): void {
|
|
973
|
+
const inline = this.generation
|
|
974
|
+
if (inline !== undefined && this.generationPath === path) {
|
|
975
|
+
inline.current = false
|
|
976
|
+
this.generationPath = undefined
|
|
977
|
+
this.generation = undefined
|
|
978
|
+
return
|
|
979
|
+
}
|
|
980
|
+
const generations = this.generations
|
|
981
|
+
const generation = generations?.get(path)
|
|
982
|
+
if (generations !== undefined && generation !== undefined) {
|
|
983
|
+
generation.current = false
|
|
984
|
+
generations.delete(path)
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
927
988
|
stopAll(): Effect.Effect<void> {
|
|
928
989
|
return Effect.suspend(() => {
|
|
990
|
+
if (this.generation !== undefined) {
|
|
991
|
+
this.generation.current = false
|
|
992
|
+
this.generationPath = undefined
|
|
993
|
+
this.generation = undefined
|
|
994
|
+
}
|
|
995
|
+
const generations = this.generations
|
|
996
|
+
if (generations !== undefined && generations.size > 0) {
|
|
997
|
+
for (const generation of generations.values()) generation.current = false
|
|
998
|
+
generations.clear()
|
|
999
|
+
}
|
|
929
1000
|
const effects: Array<Effect.Effect<void>> = []
|
|
930
1001
|
for (const entry of this.registry.children.values()) {
|
|
931
1002
|
if (entry.ownerActive) effects.push(this.stopEntry(entry))
|
|
@@ -940,6 +1011,9 @@ class OwnedChildRuntimeImpl implements OwnedChildRuntime {
|
|
|
940
1011
|
|
|
941
1012
|
stopPaths(paths: ReadonlyArray<string>): Effect.Effect<void> | undefined {
|
|
942
1013
|
if (paths.length === 0) return undefined
|
|
1014
|
+
if (this.generation !== undefined || (this.generations !== undefined && this.generations.size > 0)) {
|
|
1015
|
+
for (const path of paths) this.retireGeneration(path)
|
|
1016
|
+
}
|
|
943
1017
|
const pathSet = new Set(paths)
|
|
944
1018
|
const effects: Array<Effect.Effect<void>> = []
|
|
945
1019
|
for (const entry of this.registry.children.values()) {
|
|
@@ -1013,13 +1087,15 @@ export const makeEmissionRuntime = (): EmissionRuntime => {
|
|
|
1013
1087
|
|
|
1014
1088
|
export const childlessRuntime: ChildRuntime = {
|
|
1015
1089
|
close: () => Effect.void,
|
|
1016
|
-
spawn: (() => Effect.die(new Error("Childless machine logic cannot spawn a process")))
|
|
1090
|
+
spawn: (() => Effect.die(new Error("Childless machine logic cannot spawn a process"))),
|
|
1017
1091
|
get: () => Effect.succeed(Option.none()),
|
|
1018
1092
|
changes: () => noChildChanges,
|
|
1019
1093
|
sendTo: () => Effect.void,
|
|
1020
1094
|
stop: () => Effect.void,
|
|
1021
1095
|
owned: {
|
|
1022
1096
|
spawn: () => Effect.die(new Error("Childless machine logic cannot spawn an owned process")),
|
|
1097
|
+
// Unreachable for childless logic; `spawn` reports the defect as a failure.
|
|
1098
|
+
beginGeneration: () => ({ current: true }),
|
|
1023
1099
|
stopAll: () => Effect.void,
|
|
1024
1100
|
stopPaths: () => undefined
|
|
1025
1101
|
}
|
|
@@ -1222,7 +1298,7 @@ export const makeChildRuntimeSync = (
|
|
|
1222
1298
|
): Effect.Effect<MachineRef<any, any, any, any>, any, any> {
|
|
1223
1299
|
const descriptor = typeof logicOrChild === "object" && logicOrChild !== null &&
|
|
1224
1300
|
ChildMachineLogicTypeId in logicOrChild
|
|
1225
|
-
? logicOrChild as ChildMachine.Any
|
|
1301
|
+
? logicOrChild as unknown as ChildMachine.Any & ChildMachineLogicSlot
|
|
1226
1302
|
: undefined
|
|
1227
1303
|
const logic = descriptor === undefined
|
|
1228
1304
|
? logicOrChild as ProcessLogic<any, any, any, any, any, any>
|
|
@@ -138,22 +138,6 @@ const assertPlainRecord: (
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const validateTargetSelectorChildKey = (
|
|
142
|
-
boundary: StateDefinitionBoundary,
|
|
143
|
-
path: string,
|
|
144
|
-
states: unknown,
|
|
145
|
-
key: "initial" | "with",
|
|
146
|
-
message: string
|
|
147
|
-
): void => {
|
|
148
|
-
if (typeof states !== "object" || states === null || Array.isArray(states) || !hasOwn(states, key)) return
|
|
149
|
-
const child = (states as Readonly<Record<string, unknown>>)[key]
|
|
150
|
-
if (
|
|
151
|
-
typeof child === "object" && child !== null && !Schema.isSchema(child) &&
|
|
152
|
-
(child as Readonly<Record<string, unknown>>).type === "history"
|
|
153
|
-
) return
|
|
154
|
-
fail(boundary, `${path}.${key}`, message)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
141
|
const assertAllowedProperties = (
|
|
158
142
|
boundary: StateDefinitionBoundary,
|
|
159
143
|
path: string,
|
|
@@ -266,22 +250,6 @@ const validateStateTree = (
|
|
|
266
250
|
fail(boundary, `${path}.output`, "state output must be an Effect Schema")
|
|
267
251
|
}
|
|
268
252
|
if (kind === "compound") {
|
|
269
|
-
validateTargetSelectorChildKey(
|
|
270
|
-
boundary,
|
|
271
|
-
path,
|
|
272
|
-
node.states,
|
|
273
|
-
"initial",
|
|
274
|
-
"active and choice child states cannot use the reserved target selector key \"initial\""
|
|
275
|
-
)
|
|
276
|
-
if (valued) {
|
|
277
|
-
validateTargetSelectorChildKey(
|
|
278
|
-
boundary,
|
|
279
|
-
path,
|
|
280
|
-
node.states,
|
|
281
|
-
"with",
|
|
282
|
-
"schema-backed compound child states cannot use the reserved local target selector key \"with\""
|
|
283
|
-
)
|
|
284
|
-
}
|
|
285
253
|
validateStateTree(boundary, node.states, path, true)
|
|
286
254
|
continue
|
|
287
255
|
}
|
|
@@ -289,13 +257,6 @@ const validateStateTree = (
|
|
|
289
257
|
if (!hasOwn(node, "states")) {
|
|
290
258
|
fail(boundary, `${path}.states`, "parallel states must declare child regions")
|
|
291
259
|
}
|
|
292
|
-
validateTargetSelectorChildKey(
|
|
293
|
-
boundary,
|
|
294
|
-
path,
|
|
295
|
-
node.states,
|
|
296
|
-
"initial",
|
|
297
|
-
"active and choice child states cannot use the reserved target selector key \"initial\""
|
|
298
|
-
)
|
|
299
260
|
validateStateTree(boundary, node.states, path, true)
|
|
300
261
|
}
|
|
301
262
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Logic } from "../../Machine.js"
|
|
2
|
+
|
|
1
3
|
/** @internal */
|
|
2
4
|
export const InitialEventTypeId: unique symbol = Symbol("effect/Machine/InitialEvent")
|
|
3
5
|
|
|
@@ -6,3 +8,12 @@ export const SnapshotBuilderStateTypeId: unique symbol = Symbol("effect/Machine/
|
|
|
6
8
|
|
|
7
9
|
/** @internal Returns process logic for a child descriptor and optional input. */
|
|
8
10
|
export const ChildMachineLogicTypeId: unique symbol = Symbol("effect/Machine/ChildMachineLogic")
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @internal Runtime slot of a child machine descriptor. The public
|
|
14
|
+
* `ChildMachine` declares this key as a type-level brand only, so descriptors
|
|
15
|
+
* cross that erased boundary where they are built and where their logic is read.
|
|
16
|
+
*/
|
|
17
|
+
export interface ChildMachineLogicSlot {
|
|
18
|
+
readonly [ChildMachineLogicTypeId]: (input?: unknown) => Logic<any, any, any, any, any, any>
|
|
19
|
+
}
|
|
@@ -8,15 +8,22 @@ import * as Option from "effect/Option"
|
|
|
8
8
|
import { hasProperty } from "effect/Predicate"
|
|
9
9
|
import * as Schema from "effect/Schema"
|
|
10
10
|
import type { Machine } from "../../Machine.js"
|
|
11
|
-
import {
|
|
11
|
+
import { toImpl } from "./implementation.js"
|
|
12
12
|
|
|
13
13
|
export const TargetTypeId = "~effect/Machine/Target"
|
|
14
14
|
|
|
15
15
|
export const TargetSnapshotTypeId: unique symbol = Symbol("effect/Machine/TargetSnapshot")
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Runtime slot for the decoded snapshot a target may carry. It stays under a
|
|
19
|
+
* private symbol so it is absent from `Object.keys`, JSON, and inspection
|
|
20
|
+
* payloads; the public `Machine.Target` declares it as a type-level brand only.
|
|
21
|
+
*/
|
|
22
|
+
export interface TargetSnapshotSlot<out Snapshot = Machine.AtomicSnapshot<string, unknown>> {
|
|
23
|
+
readonly [TargetSnapshotTypeId]?: Snapshot | undefined
|
|
24
|
+
}
|
|
18
25
|
|
|
19
|
-
export const
|
|
26
|
+
export const StateInputTypeId: unique symbol = Symbol("effect/Machine/StateInput")
|
|
20
27
|
|
|
21
28
|
export const HistoryTargetTypeId: unique symbol = Symbol("effect/Machine/HistoryTarget")
|
|
22
29
|
|
|
@@ -72,16 +79,6 @@ export interface ChoiceTarget {
|
|
|
72
79
|
readonly values?: Readonly<Record<string, unknown>>
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
/** Internal marker returned by an explicitly targetless transition. */
|
|
76
|
-
export interface NoTarget {
|
|
77
|
-
readonly [NoTargetTypeId]: typeof NoTargetTypeId
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Internal marker returned when a declinable transition is not enabled. */
|
|
81
|
-
export interface Declined {
|
|
82
|
-
readonly [DeclinedTypeId]: typeof DeclinedTypeId
|
|
83
|
-
}
|
|
84
|
-
|
|
85
82
|
export type TargetSelectionKind = "state" | "initial" | "history" | "choice" | "update" | "none"
|
|
86
83
|
|
|
87
84
|
export type TargetSelectionScope = "local" | "branch" | "full" | "initial"
|
|
@@ -111,6 +108,7 @@ export const makeTargetSelection = (
|
|
|
111
108
|
updatePath?: string
|
|
112
109
|
): TargetSelection =>
|
|
113
110
|
Object.freeze({
|
|
111
|
+
// oxlint-disable-next-line typescript/no-unnecessary-type-assertion -- TypeScript 6 widens the computed key to `symbol` without it.
|
|
114
112
|
[TargetSelectionTypeId]: TargetSelectionTypeId as typeof TargetSelectionTypeId,
|
|
115
113
|
kind,
|
|
116
114
|
scope,
|
|
@@ -169,9 +167,11 @@ export const makeSelectedBranch = (
|
|
|
169
167
|
|
|
170
168
|
export const isSelectedBranch = (u: unknown): u is SelectedBranch => hasProperty(u, SelectedBranchTypeId)
|
|
171
169
|
|
|
170
|
+
// Public markers carry their key as a type-level brand; the runtime marker is
|
|
171
|
+
// the private symbol, so the frozen singletons cross that erased boundary here.
|
|
172
172
|
const noTarget = Object.freeze({
|
|
173
173
|
[NoTargetTypeId]: NoTargetTypeId
|
|
174
|
-
}) as NoTarget
|
|
174
|
+
}) as unknown as Machine.NoTarget
|
|
175
175
|
|
|
176
176
|
export const makeNoTarget = (): Machine.NoTarget => noTarget
|
|
177
177
|
|
|
@@ -179,7 +179,7 @@ export const isNoTarget = (u: unknown): u is Machine.NoTarget => hasProperty(u,
|
|
|
179
179
|
|
|
180
180
|
const declined = Object.freeze({
|
|
181
181
|
[DeclinedTypeId]: DeclinedTypeId
|
|
182
|
-
}) as Declined
|
|
182
|
+
}) as unknown as Machine.Declined
|
|
183
183
|
|
|
184
184
|
export const makeDeclined = (): Machine.Declined => declined
|
|
185
185
|
|
|
@@ -312,7 +312,7 @@ export const getStateNodeDefinition = (
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
const schema = hasProperty(definition, "schema") && Schema.isSchema(definition.schema)
|
|
315
|
-
? definition.schema
|
|
315
|
+
? definition.schema
|
|
316
316
|
: undefined
|
|
317
317
|
const annotations = schema === undefined ? definition.annotations : Schema.resolveAnnotations(schema)
|
|
318
318
|
if (definition.type === "parallel" && !hasProperty(definition, "states")) {
|
|
@@ -494,7 +494,7 @@ export const compileStateNodes = (states: Machine.StateSchemas): Machine.StateNo
|
|
|
494
494
|
return {
|
|
495
495
|
byPath,
|
|
496
496
|
roots: compile(states, undefined)
|
|
497
|
-
}
|
|
497
|
+
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
const transitionBranches = (handler: unknown): ReadonlyArray<Machine.TransitionBranch> =>
|
|
@@ -512,7 +512,7 @@ export const transitionDefinitions = (
|
|
|
512
512
|
): ReadonlyArray<Machine.TransitionDefinition> => {
|
|
513
513
|
const definitions: Array<Machine.TransitionDefinition> = []
|
|
514
514
|
for (const node of machine.stateNodes.byPath.values()) {
|
|
515
|
-
const config = toImpl(machine).handlers[node.path]
|
|
515
|
+
const config = toImpl(machine).handlers[node.path]
|
|
516
516
|
if (config === undefined) {
|
|
517
517
|
continue
|
|
518
518
|
}
|
|
@@ -613,6 +613,28 @@ export const makeTarget = <
|
|
|
613
613
|
values: options?.values
|
|
614
614
|
}) as Machine.Target<States, StateId>
|
|
615
615
|
|
|
616
|
+
/**
|
|
617
|
+
* Builds a target from a planned configuration whose path, value, snapshot,
|
|
618
|
+
* and ancestor values were already decoded, so no state schema type applies.
|
|
619
|
+
* It keeps the same own-property shape as `makeTarget`, including `values`
|
|
620
|
+
* when undefined, which the optional public `values` field cannot express.
|
|
621
|
+
*/
|
|
622
|
+
export const makeResolvedTarget = (
|
|
623
|
+
path: string,
|
|
624
|
+
value: unknown,
|
|
625
|
+
options: {
|
|
626
|
+
readonly snapshot: Machine.AtomicSnapshot<string, unknown>
|
|
627
|
+
readonly values: Readonly<Record<string, unknown>> | undefined
|
|
628
|
+
}
|
|
629
|
+
): Machine.Target<any, string> =>
|
|
630
|
+
({
|
|
631
|
+
[TargetTypeId]: TargetTypeId,
|
|
632
|
+
[TargetSnapshotTypeId]: options.snapshot,
|
|
633
|
+
path,
|
|
634
|
+
value,
|
|
635
|
+
values: options.values
|
|
636
|
+
}) as Machine.Target<any, string>
|
|
637
|
+
|
|
616
638
|
export const isTarget = (u: unknown): u is Machine.Target<any, any> => hasProperty(u, TargetTypeId)
|
|
617
639
|
|
|
618
640
|
export const makeStateInput = (input: unknown): StateInput => ({
|