@typeonce/effect-machine 0.35.0 → 0.37.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 +45 -7
- package/dist/Machine.d.ts +143 -136
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +25 -0
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/command.d.ts +0 -1
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/command.js +0 -14
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +15 -2
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/construction.d.ts +9 -0
- package/dist/internal/machine/construction.d.ts.map +1 -0
- package/dist/internal/machine/construction.js +132 -0
- package/dist/internal/machine/construction.js.map +1 -0
- package/dist/internal/machine/declaration.d.ts +1 -0
- package/dist/internal/machine/declaration.d.ts.map +1 -1
- package/dist/internal/machine/declaration.js +4 -8
- 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 +13 -9
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +2 -3
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/implementation.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts +1 -0
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +26 -3
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts +3 -1
- package/dist/internal/machine/invocationDefinition.d.ts.map +1 -1
- package/dist/internal/machine/invocationDefinition.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +6 -0
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +70 -168
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/observation.d.ts +3 -0
- package/dist/internal/machine/observation.d.ts.map +1 -0
- package/dist/internal/machine/observation.js +28 -0
- package/dist/internal/machine/observation.js.map +1 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +63 -17
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +6 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +36 -76
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/docs/agent-guide.md +57 -34
- package/docs/root-api.md +143 -190
- package/package.json +1 -1
- package/src/Machine.ts +223 -144
- package/src/internal/machine/command.ts +0 -16
- package/src/internal/machine/configuration.ts +13 -10
- package/src/internal/machine/construction.ts +147 -0
- package/src/internal/machine/declaration.ts +5 -7
- package/src/internal/machine/executionPlan.ts +13 -9
- package/src/internal/machine/implementation.ts +2 -3
- package/src/internal/machine/invocation.ts +34 -3
- package/src/internal/machine/invocationDefinition.ts +1 -0
- package/src/internal/machine/machine.ts +89 -223
- package/src/internal/machine/observation.ts +39 -0
- package/src/internal/machine/planner.ts +69 -18
- package/src/internal/machine/topology.ts +4 -0
- package/src/internal/testing/machine/finiteModel.ts +44 -122
- package/dist/internal/machine/targetBuilder.d.ts +0 -16
- package/dist/internal/machine/targetBuilder.d.ts.map +0 -1
- package/dist/internal/machine/targetBuilder.js +0 -333
- package/dist/internal/machine/targetBuilder.js.map +0 -1
- package/src/internal/machine/targetBuilder.ts +0 -525
|
@@ -8,7 +8,7 @@ import * as Cause from "effect/Cause"
|
|
|
8
8
|
import * as Effect from "effect/Effect"
|
|
9
9
|
import type * as Schema from "effect/Schema"
|
|
10
10
|
import type { Enqueue, InitialEvent as MachineInitialEvent, Machine, MachineTarget } from "../../Machine.js"
|
|
11
|
-
import {
|
|
11
|
+
import { makeCollector, type RuntimeCommand } from "./command.js"
|
|
12
12
|
import {
|
|
13
13
|
type ActiveConfiguration,
|
|
14
14
|
captureHistory,
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
snapshotFromConfiguration,
|
|
38
38
|
snapshotFromConfigurationAtPath
|
|
39
39
|
} from "./configuration.js"
|
|
40
|
+
import * as Construction from "./construction.js"
|
|
40
41
|
import { InfiniteTransitionError, MachineSchemaDecodeError, StartupError, StoppedError } from "./errors.js"
|
|
41
42
|
import { type CapturedStateConfig, toImpl } from "./implementation.js"
|
|
42
43
|
import { isDataInitializer } from "./initialDeclaration.js"
|
|
@@ -265,7 +266,8 @@ const collectStateInitializer = (
|
|
|
265
266
|
const completeHistoryConfiguration = (
|
|
266
267
|
machine: Machine.Any,
|
|
267
268
|
configuration: ActiveConfiguration,
|
|
268
|
-
event: unknown
|
|
269
|
+
event: unknown,
|
|
270
|
+
input?: { readonly value: unknown }
|
|
269
271
|
) => {
|
|
270
272
|
const active = new Set(configuration.active)
|
|
271
273
|
const values = new Map(configuration.values)
|
|
@@ -345,6 +347,7 @@ const completeHistoryConfiguration = (
|
|
|
345
347
|
containingState: getParentValue(machine, current, path),
|
|
346
348
|
ancestors: getParentValues(machine, current, path),
|
|
347
349
|
event,
|
|
350
|
+
...(path === "" && input !== undefined ? { input: input.value } : {}),
|
|
348
351
|
...(isDataInitializer(initializer) ? {} : { builder: makeStateInitializeBuilder(machine, path) })
|
|
349
352
|
})
|
|
350
353
|
const initializedValues = getStateInitializeValues(path, initialized.value)
|
|
@@ -373,6 +376,7 @@ const completeHistoryConfiguration = (
|
|
|
373
376
|
containingState: getParentValue(machine, current, path),
|
|
374
377
|
ancestors: getParentValues(machine, current, path),
|
|
375
378
|
event,
|
|
379
|
+
...(path === "" && input !== undefined ? { input: input.value } : {}),
|
|
376
380
|
...(isDataInitializer(initializer) ? {} : { builder: makeStateInitializeBuilder(machine, path) })
|
|
377
381
|
})
|
|
378
382
|
const initializedValues = initialized === undefined
|
|
@@ -432,8 +436,53 @@ export function resolveInitialConfiguration(
|
|
|
432
436
|
target: InitialTargetInstruction,
|
|
433
437
|
event: unknown
|
|
434
438
|
) {
|
|
435
|
-
|
|
436
|
-
|
|
439
|
+
let partial = configurationFromInitialTargetSync(machine, configuration, target)
|
|
440
|
+
if (
|
|
441
|
+
target.children === undefined ||
|
|
442
|
+
![...target.children.keys()].some((path) => getNode(machine, path).type === "choice")
|
|
443
|
+
) {
|
|
444
|
+
return completeHistoryConfiguration(machine, partial, event, target.input)
|
|
445
|
+
}
|
|
446
|
+
const commands: Array<RuntimeCommand> = []
|
|
447
|
+
const raisedEvents: Array<unknown> = []
|
|
448
|
+
const emittedEvents: Array<unknown> = []
|
|
449
|
+
const transitions: Array<ResolvedChoiceTransition> = []
|
|
450
|
+
for (const path of target.children?.keys() ?? []) {
|
|
451
|
+
const node = getNode(machine, path)
|
|
452
|
+
if (node.type !== "choice") continue
|
|
453
|
+
const choice = resolveChoiceTarget(machine, partial, makeChoiceTarget(path, node.parent!), event)
|
|
454
|
+
for (const routed of [choice.target, ...choice.additionalTargets]) {
|
|
455
|
+
const resolved = isInitialTarget(routed) ?
|
|
456
|
+
resolveInitialTarget(machine, partial, routed, event)
|
|
457
|
+
: isHistoryTarget(routed)
|
|
458
|
+
? resolveHistoryTarget(machine, partial, routed, event)
|
|
459
|
+
: undefined
|
|
460
|
+
partial = normalizeTargetConfigurationSync(
|
|
461
|
+
machine,
|
|
462
|
+
partial,
|
|
463
|
+
(resolved?.target ?? routed) as Machine.Target<any, any>
|
|
464
|
+
)
|
|
465
|
+
if (resolved !== undefined) {
|
|
466
|
+
commands.push(...resolved.commands)
|
|
467
|
+
raisedEvents.push(...resolved.raisedEvents)
|
|
468
|
+
emittedEvents.push(...resolved.emittedEvents)
|
|
469
|
+
transitions.push(...resolved.transitions)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
commands.push(...choice.commands)
|
|
473
|
+
raisedEvents.push(...choice.raisedEvents)
|
|
474
|
+
emittedEvents.push(...choice.emittedEvents)
|
|
475
|
+
transitions.push(...choice.transitions)
|
|
476
|
+
}
|
|
477
|
+
const completed = completeHistoryConfiguration(machine, partial, event, target.input)
|
|
478
|
+
if (transitions.length === 0) return completed
|
|
479
|
+
return {
|
|
480
|
+
...completed,
|
|
481
|
+
commands: [...commands, ...completed.commands],
|
|
482
|
+
raisedEvents: [...raisedEvents, ...completed.raisedEvents],
|
|
483
|
+
emittedEvents: [...emittedEvents, ...completed.emittedEvents],
|
|
484
|
+
transitions: [...transitions, ...completed.transitions]
|
|
485
|
+
}
|
|
437
486
|
}
|
|
438
487
|
|
|
439
488
|
export function resolveInitialTarget(
|
|
@@ -447,7 +496,7 @@ export function resolveInitialTarget(
|
|
|
447
496
|
return {
|
|
448
497
|
target: makeTarget(target.path as any, snapshot.value as any, {
|
|
449
498
|
snapshot: snapshot as any,
|
|
450
|
-
values:
|
|
499
|
+
values: target.values as any
|
|
451
500
|
}),
|
|
452
501
|
commands: completed.commands,
|
|
453
502
|
raisedEvents: completed.raisedEvents,
|
|
@@ -495,7 +544,7 @@ function resolveHistoryTarget(
|
|
|
495
544
|
}
|
|
496
545
|
const collected = collectTransition(machine, fallback, {
|
|
497
546
|
event,
|
|
498
|
-
target:
|
|
547
|
+
target: (config: unknown) => Construction.snapshot(machine.stateNodes, config),
|
|
499
548
|
owner: target.parent
|
|
500
549
|
})
|
|
501
550
|
if (collected.state === undefined || isHistoryTarget(collected.state) || !isSnapshot(collected.state)) {
|
|
@@ -732,8 +781,7 @@ const makeTransitionContext = <
|
|
|
732
781
|
containingState: getParentValue(machine, configuration, path) as Machine.ParentStateValue<States, StateId>,
|
|
733
782
|
ancestors: getParentValues(machine, configuration, path) as Machine.ParentStateValues<States, StateId>,
|
|
734
783
|
event,
|
|
735
|
-
snapshot
|
|
736
|
-
target: getTargetBuilder(machine, path)
|
|
784
|
+
snapshot
|
|
737
785
|
})
|
|
738
786
|
|
|
739
787
|
const makeDoneContext = <
|
|
@@ -755,8 +803,7 @@ const makeDoneContext = <
|
|
|
755
803
|
ancestors: getParentValues(machine, configuration, path) as Machine.ParentStateValues<States, StateId>,
|
|
756
804
|
event,
|
|
757
805
|
output: output as Machine.CompletionOutputByIdentifier<States, StateId>,
|
|
758
|
-
snapshot
|
|
759
|
-
target: getTargetBuilder(machine, path)
|
|
806
|
+
snapshot
|
|
760
807
|
})
|
|
761
808
|
|
|
762
809
|
const collectStateActions = <
|
|
@@ -859,8 +906,7 @@ const selectAlwaysTransitions = <
|
|
|
859
906
|
Machine.StateIdentifier<States>
|
|
860
907
|
>,
|
|
861
908
|
event,
|
|
862
|
-
snapshot: capturedSnapshot()
|
|
863
|
-
target: getTargetBuilder(machine, path)
|
|
909
|
+
snapshot: capturedSnapshot()
|
|
864
910
|
}
|
|
865
911
|
})
|
|
866
912
|
evaluatedSources.set(path, candidate)
|
|
@@ -1068,7 +1114,6 @@ const selectInvocationTransition = <
|
|
|
1068
1114
|
containingState: getParentValue(machine, configuration, event.path),
|
|
1069
1115
|
ancestors: getParentValues(machine, configuration, event.path),
|
|
1070
1116
|
snapshot,
|
|
1071
|
-
target: getTargetBuilder(machine, event.path),
|
|
1072
1117
|
id: event.id,
|
|
1073
1118
|
...(event.type === "element"
|
|
1074
1119
|
? { element: event.element }
|
|
@@ -1244,6 +1289,7 @@ const withChoiceValues = (target: unknown, values: Readonly<Record<string, unkno
|
|
|
1244
1289
|
if (isChoiceTarget(target)) {
|
|
1245
1290
|
return makeChoiceTarget(target.path, target.parent, { ...values, ...(target.values ?? {}) })
|
|
1246
1291
|
}
|
|
1292
|
+
if (isInitialTarget(target)) return { ...target, values: { ...values, ...target.values } }
|
|
1247
1293
|
if (!isTarget(target) || Object.keys(values).length === 0) return target
|
|
1248
1294
|
const snapshot = target[TargetSnapshotTypeId]
|
|
1249
1295
|
return makeTarget(target.path, target.value, {
|
|
@@ -1324,8 +1370,7 @@ function resolveChoiceTarget(
|
|
|
1324
1370
|
...resolveMachineReferences(machine, provisional),
|
|
1325
1371
|
containingState: getParentValue(machine, provisional, node.path),
|
|
1326
1372
|
ancestors: getParentValues(machine, provisional, node.path),
|
|
1327
|
-
event
|
|
1328
|
-
target: getTargetBuilder(machine, node.path)
|
|
1373
|
+
event
|
|
1329
1374
|
},
|
|
1330
1375
|
choice.evaluate
|
|
1331
1376
|
)
|
|
@@ -1419,17 +1464,23 @@ const collectEvaluatedTransition = <
|
|
|
1419
1464
|
}
|
|
1420
1465
|
})()
|
|
1421
1466
|
: undefined
|
|
1467
|
+
// Initial constructors and choices observe the owner value being committed
|
|
1468
|
+
// with this target, while the source configuration remains untouched.
|
|
1469
|
+
const constructionState =
|
|
1470
|
+
update !== undefined && (isInitialTarget(unresolvedTarget) || isChoiceTarget(unresolvedTarget))
|
|
1471
|
+
? { ...state, values: new Map(state.values).set(update.path, update.value) }
|
|
1472
|
+
: state
|
|
1422
1473
|
const choiceResolution = unresolvedTarget === undefined
|
|
1423
1474
|
? undefined
|
|
1424
1475
|
: resolveChoiceTarget(
|
|
1425
1476
|
machine,
|
|
1426
|
-
|
|
1477
|
+
constructionState,
|
|
1427
1478
|
unresolvedTarget,
|
|
1428
1479
|
(selection.context as any).event
|
|
1429
1480
|
)
|
|
1430
1481
|
const choiceResolvedTarget = choiceResolution?.target ?? unresolvedTarget
|
|
1431
1482
|
const initialResolution = choiceResolvedTarget !== undefined && isInitialTarget(choiceResolvedTarget)
|
|
1432
|
-
? resolveInitialTarget(machine,
|
|
1483
|
+
? resolveInitialTarget(machine, constructionState, choiceResolvedTarget, (selection.context as any).event)
|
|
1433
1484
|
: undefined
|
|
1434
1485
|
const routedTarget = initialResolution?.target ?? choiceResolvedTarget
|
|
1435
1486
|
let historyResolution: {
|
|
@@ -2321,4 +2372,4 @@ export const planInitial = (
|
|
|
2321
2372
|
|
|
2322
2373
|
// Captured constructors are private planner inputs. Public callbacks receive root data
|
|
2323
2374
|
// and the constructors bound to their declared branches during normalization.
|
|
2324
|
-
type ConstructionContext<C> = Omit<C, "root">
|
|
2375
|
+
type ConstructionContext<C> = Omit<C, "root">
|
|
@@ -55,6 +55,10 @@ export interface HistoryTarget {
|
|
|
55
55
|
export interface InitialTarget {
|
|
56
56
|
readonly [InitialTargetTypeId]: typeof InitialTargetTypeId
|
|
57
57
|
readonly _tag: "InitialTarget"
|
|
58
|
+
/** Transient startup input, never retained in a configuration. */
|
|
59
|
+
readonly input?: { readonly value: unknown }
|
|
60
|
+
/** Explicitly selected descendants and their construction values. */
|
|
61
|
+
readonly children?: ReadonlyMap<string, unknown>
|
|
58
62
|
readonly path: string
|
|
59
63
|
readonly value: unknown
|
|
60
64
|
readonly values?: Readonly<Record<string, unknown>>
|
|
@@ -1217,101 +1217,52 @@ const makeStateTree = (
|
|
|
1217
1217
|
return tree
|
|
1218
1218
|
}
|
|
1219
1219
|
|
|
1220
|
-
const
|
|
1221
|
-
builder: Record<string, any>,
|
|
1220
|
+
const construction = (
|
|
1222
1221
|
path: string,
|
|
1223
1222
|
byPath: ReadonlyMap<string, FlatFiniteState>,
|
|
1224
1223
|
requestedParts: ReadonlyArray<string> | undefined,
|
|
1225
1224
|
index: number,
|
|
1226
1225
|
sourcePath?: string,
|
|
1227
1226
|
requestedValue?: number
|
|
1228
|
-
): unknown => {
|
|
1227
|
+
): Readonly<Record<string, unknown>> => {
|
|
1229
1228
|
const state = byPath.get(path)!
|
|
1230
|
-
if (state.node._tag === "History") {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
if (state.node._tag === "
|
|
1234
|
-
return (builder[state.node.key] as () => unknown)()
|
|
1235
|
-
}
|
|
1236
|
-
const method = builder[state.node.key].decoded as (
|
|
1237
|
-
value: unknown,
|
|
1238
|
-
selector?: (builder: any) => unknown
|
|
1239
|
-
) => unknown
|
|
1240
|
-
const value = stateValue(state, path === requestedParts?.join(".") ? requestedValue : undefined)
|
|
1241
|
-
if (state.node._tag === "Atomic" || state.node._tag === "Final") return method(value)
|
|
1242
|
-
|
|
1229
|
+
if (state.node._tag === "History") throw new Error(`MachineTest cannot construct history state "${path}"`)
|
|
1230
|
+
if (state.node._tag === "Choice") return {}
|
|
1231
|
+
const data = stateValue(state, path === requestedParts?.join(".") ? requestedValue : undefined)
|
|
1232
|
+
if (state.node._tag === "Atomic" || state.node._tag === "Final") return { data, decoded: true }
|
|
1243
1233
|
const requestedChild = requestedParts?.[index + 1]
|
|
1234
|
+
let keys: ReadonlyArray<string>
|
|
1244
1235
|
if (state.node._tag === "Parallel") {
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
selectSnapshot(
|
|
1255
|
-
children,
|
|
1256
|
-
`${path}.${childKey}`,
|
|
1257
|
-
byPath,
|
|
1258
|
-
requestedChild === undefined ? undefined : requestedParts,
|
|
1259
|
-
index + 1,
|
|
1260
|
-
sourcePath,
|
|
1261
|
-
requestedValue
|
|
1262
|
-
)
|
|
1236
|
+
const inside = sourcePath === path || sourcePath?.startsWith(`${path}.`) === true
|
|
1237
|
+
keys = inside ?
|
|
1238
|
+
[
|
|
1239
|
+
requestedChild ?? (sourcePath === path
|
|
1240
|
+
? state.node.states.find((child) => child._tag !== "History" && child._tag !== "Choice")!.key
|
|
1241
|
+
: sourcePath!.slice(path.length + 1).split(".")[0]!)
|
|
1242
|
+
]
|
|
1243
|
+
: state.node.states.filter((child) => child._tag !== "History" && child._tag !== "Choice").map((child) =>
|
|
1244
|
+
child.key
|
|
1263
1245
|
)
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1246
|
+
} else keys = [requestedChild ?? state.node.initial]
|
|
1247
|
+
return {
|
|
1248
|
+
data,
|
|
1249
|
+
decoded: true,
|
|
1250
|
+
states: Object.fromEntries(
|
|
1251
|
+
keys.map((
|
|
1252
|
+
key
|
|
1253
|
+
) => [
|
|
1254
|
+
key,
|
|
1255
|
+
construction(
|
|
1256
|
+
`${path}.${key}`,
|
|
1272
1257
|
byPath,
|
|
1273
|
-
|
|
1258
|
+
key === requestedChild ? requestedParts : undefined,
|
|
1274
1259
|
index + 1,
|
|
1275
1260
|
sourcePath,
|
|
1276
1261
|
requestedValue
|
|
1277
1262
|
)
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
})
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
const childKey = requestedChild ?? state.node.initial
|
|
1284
|
-
const childPath = `${path}.${childKey}`
|
|
1285
|
-
return method(
|
|
1286
|
-
value,
|
|
1287
|
-
(children: Record<string, any>) =>
|
|
1288
|
-
selectSnapshot(
|
|
1289
|
-
children,
|
|
1290
|
-
childPath,
|
|
1291
|
-
byPath,
|
|
1292
|
-
requestedChild === undefined ? undefined : requestedParts,
|
|
1293
|
-
index + 1,
|
|
1294
|
-
sourcePath,
|
|
1295
|
-
requestedValue
|
|
1296
|
-
)
|
|
1297
|
-
)
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
const findSnapshot = (snapshot: unknown, path: string): unknown => {
|
|
1301
|
-
if (typeof snapshot !== "object" || snapshot === null) return undefined
|
|
1302
|
-
const current = snapshot as Record<string, unknown>
|
|
1303
|
-
if (current.path === path) return snapshot
|
|
1304
|
-
if (current.state !== undefined) {
|
|
1305
|
-
const found = findSnapshot(current.state, path)
|
|
1306
|
-
if (found !== undefined) return found
|
|
1307
|
-
}
|
|
1308
|
-
if (typeof current.states === "object" && current.states !== null) {
|
|
1309
|
-
for (const child of Object.values(current.states)) {
|
|
1310
|
-
const found = findSnapshot(child, path)
|
|
1311
|
-
if (found !== undefined) return found
|
|
1312
|
-
}
|
|
1263
|
+
])
|
|
1264
|
+
)
|
|
1313
1265
|
}
|
|
1314
|
-
return undefined
|
|
1315
1266
|
}
|
|
1316
1267
|
|
|
1317
1268
|
const selectableDefinitionTarget = (
|
|
@@ -1349,47 +1300,19 @@ const selectDefinitionTarget = (
|
|
|
1349
1300
|
}
|
|
1350
1301
|
|
|
1351
1302
|
const resolveDefinitionTarget = (
|
|
1352
|
-
|
|
1303
|
+
build: (config?: unknown) => unknown,
|
|
1353
1304
|
source: string,
|
|
1354
1305
|
target: string,
|
|
1355
1306
|
byPath: ReadonlyMap<string, FlatFiniteState>,
|
|
1356
1307
|
value?: number
|
|
1357
1308
|
): unknown => {
|
|
1358
1309
|
const selected = byPath.get(target)!
|
|
1359
|
-
if (selected.node._tag === "History") return
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
if (selectable !== target) {
|
|
1366
|
-
const bound = byPath.get(selectable)!
|
|
1367
|
-
const parts = target.split(".")
|
|
1368
|
-
return selectSnapshot(
|
|
1369
|
-
{ [bound.node.key]: builder },
|
|
1370
|
-
selectable,
|
|
1371
|
-
byPath,
|
|
1372
|
-
parts,
|
|
1373
|
-
selectable.split(".").length - 1,
|
|
1374
|
-
source,
|
|
1375
|
-
value
|
|
1376
|
-
)
|
|
1377
|
-
}
|
|
1378
|
-
if (selected.node._tag === "Choice") return builder()
|
|
1379
|
-
const input = { value: value ?? selected.node.value }
|
|
1380
|
-
if (selected.node._tag === "Compound" || selected.node._tag === "Parallel") {
|
|
1381
|
-
const parts = target.split(".")
|
|
1382
|
-
return selectSnapshot(
|
|
1383
|
-
{ [selected.node.key]: builder },
|
|
1384
|
-
target,
|
|
1385
|
-
byPath,
|
|
1386
|
-
parts,
|
|
1387
|
-
parts.length - 1,
|
|
1388
|
-
source,
|
|
1389
|
-
value
|
|
1390
|
-
)
|
|
1391
|
-
}
|
|
1392
|
-
return builder.from(input)
|
|
1310
|
+
if (selected.node._tag === "History") return build()
|
|
1311
|
+
const parts = target.split(".")
|
|
1312
|
+
const path = selected.root !== byPath.get(source)!.root
|
|
1313
|
+
? parts[0]!
|
|
1314
|
+
: selectableDefinitionTarget(source, target, byPath)
|
|
1315
|
+
return build(construction(path, byPath, parts, path.split(".").length - 1, source, value))
|
|
1393
1316
|
}
|
|
1394
1317
|
|
|
1395
1318
|
const makeHandlers = (
|
|
@@ -1448,16 +1371,15 @@ const makeHandlers = (
|
|
|
1448
1371
|
if (child._tag !== "History") return []
|
|
1449
1372
|
return [[child.key, {
|
|
1450
1373
|
default: ({ target: root }: { readonly target: any }) =>
|
|
1451
|
-
root
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1374
|
+
root({
|
|
1375
|
+
states: {
|
|
1376
|
+
[byPath.get(child.fallback)!.root]: construction(
|
|
1377
|
+
byPath.get(child.fallback)!.root,
|
|
1378
|
+
byPath,
|
|
1379
|
+
child.fallback.split("."),
|
|
1380
|
+
0
|
|
1458
1381
|
)
|
|
1459
1382
|
}
|
|
1460
|
-
return completeRoot
|
|
1461
1383
|
})
|
|
1462
1384
|
}]]
|
|
1463
1385
|
}))
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Machine } from "../../Machine.js";
|
|
2
|
-
type SnapshotBuilderOptions = {
|
|
3
|
-
readonly mode: "initial" | "full";
|
|
4
|
-
readonly prefix: string;
|
|
5
|
-
};
|
|
6
|
-
type FromMethodKind = "leaf" | "nested";
|
|
7
|
-
export declare const withFrom: <Method extends (value: unknown, ...args: ReadonlyArray<any>) => unknown>(method: Method, kind: FromMethodKind, valued: boolean) => {
|
|
8
|
-
readonly decoded?: Method;
|
|
9
|
-
readonly from: (...args: ReadonlyArray<any>) => unknown;
|
|
10
|
-
};
|
|
11
|
-
export declare const makeSnapshotBuilder: (states: Machine.StateTree, options: SnapshotBuilderOptions) => unknown;
|
|
12
|
-
export declare const getTargetBuilderNode: (stateNodes: Machine.StateNodes, path: string) => Machine.StateNode;
|
|
13
|
-
export declare const getLocalTargetScope: (stateNodes: Machine.StateNodes, source: string) => string | undefined;
|
|
14
|
-
export declare const makeTargetBuilder: <const States extends Machine.StateSchemas>(states: States, stateNodes: Machine.StateNodes) => <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=targetBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"targetBuilder.d.ts","sourceRoot":"","sources":["../../../src/internal/machine/targetBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAI/C,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAA;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,KAAK,cAAc,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEvC,eAAO,MAAM,QAAQ,GAAI,MAAM,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,OAAO,EAC9F,QAAQ,MAAM,EACd,MAAM,cAAc,EACpB,QAAQ,OAAO,KACd;IACD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,OAAO,CAAA;CAyBxD,CAAA;AAoBD,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,OAAO,CAAC,SAAS,EACzB,SAAS,sBAAsB,KAC9B,OA0BF,CAAA;AA2GD,eAAO,MAAM,oBAAoB,GAC/B,YAAY,OAAO,CAAC,UAAU,EAC9B,MAAM,MAAM,KACX,OAAO,CAAC,SAMV,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,YAAY,OAAO,CAAC,UAAU,EAC9B,QAAQ,MAAM,KACb,MAAM,GAAG,SAaX,CAAA;AA2RD,eAAO,MAAM,iBAAiB,GAAI,KAAK,CAAC,MAAM,SAAS,OAAO,CAAC,YAAY,EACzE,QAAQ,MAAM,EACd,YAAY,OAAO,CAAC,UAAU,MAItB,MAAM,SAAS,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAQlH,CAAA"}
|