@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,2 +1,5 @@
|
|
|
1
1
|
/** @internal */
|
|
2
2
|
export const InitialEventTypeId: unique symbol = Symbol("effect/Machine/InitialEvent")
|
|
3
|
+
|
|
4
|
+
/** @internal Returns process logic for a child descriptor and optional input. */
|
|
5
|
+
export const ChildMachineLogicTypeId: unique symbol = Symbol("effect/Machine/ChildMachineLogic")
|
|
@@ -70,7 +70,7 @@ interface NormalizedStateNodeDefinitionBase {
|
|
|
70
70
|
type NormalizedStateNodeDefinition =
|
|
71
71
|
| (NormalizedStateNodeDefinitionBase & {
|
|
72
72
|
readonly type: "atomic"
|
|
73
|
-
readonly schema: Machine.TaggedSchema
|
|
73
|
+
readonly schema: Machine.TaggedSchema | undefined
|
|
74
74
|
readonly output: undefined
|
|
75
75
|
readonly history: undefined
|
|
76
76
|
readonly initial: undefined
|
|
@@ -78,7 +78,7 @@ type NormalizedStateNodeDefinition =
|
|
|
78
78
|
})
|
|
79
79
|
| (NormalizedStateNodeDefinitionBase & {
|
|
80
80
|
readonly type: "compound"
|
|
81
|
-
readonly schema: Machine.TaggedSchema
|
|
81
|
+
readonly schema: Machine.TaggedSchema | undefined
|
|
82
82
|
readonly output: undefined
|
|
83
83
|
readonly history: undefined
|
|
84
84
|
readonly initial: string
|
|
@@ -86,7 +86,7 @@ type NormalizedStateNodeDefinition =
|
|
|
86
86
|
})
|
|
87
87
|
| (NormalizedStateNodeDefinitionBase & {
|
|
88
88
|
readonly type: "parallel"
|
|
89
|
-
readonly schema: Machine.TaggedSchema
|
|
89
|
+
readonly schema: Machine.TaggedSchema | undefined
|
|
90
90
|
readonly output: Schema.Top | undefined
|
|
91
91
|
readonly history: undefined
|
|
92
92
|
readonly initial: undefined
|
|
@@ -94,7 +94,7 @@ type NormalizedStateNodeDefinition =
|
|
|
94
94
|
})
|
|
95
95
|
| (NormalizedStateNodeDefinitionBase & {
|
|
96
96
|
readonly type: "final"
|
|
97
|
-
readonly schema: Machine.TaggedSchema
|
|
97
|
+
readonly schema: Machine.TaggedSchema | undefined
|
|
98
98
|
readonly output: Schema.Top | undefined
|
|
99
99
|
readonly history: undefined
|
|
100
100
|
readonly initial: undefined
|
|
@@ -154,9 +154,10 @@ export const getStateNodeDefinition = (
|
|
|
154
154
|
states: undefined
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const schema = hasProperty(definition, "schema") && Schema.isSchema(definition.schema)
|
|
158
|
+
? definition.schema as Machine.TaggedSchema
|
|
159
|
+
: undefined
|
|
160
|
+
const annotations = schema === undefined ? definition.annotations : Schema.resolveAnnotations(schema)
|
|
160
161
|
if (definition.type === "parallel" && !hasProperty(definition, "states")) {
|
|
161
162
|
throw new Error(`Machine.make expected parallel state "${path}" to declare child regions`)
|
|
162
163
|
}
|
|
@@ -167,9 +168,9 @@ export const getStateNodeDefinition = (
|
|
|
167
168
|
}
|
|
168
169
|
if (definition.type === "parallel") {
|
|
169
170
|
return {
|
|
170
|
-
schema
|
|
171
|
+
schema,
|
|
171
172
|
output: Schema.isSchema(definition.output) ? definition.output : undefined,
|
|
172
|
-
annotations
|
|
173
|
+
annotations,
|
|
173
174
|
type: "parallel",
|
|
174
175
|
history: undefined,
|
|
175
176
|
initial: undefined,
|
|
@@ -180,9 +181,9 @@ export const getStateNodeDefinition = (
|
|
|
180
181
|
throw new Error(`Machine.make expected compound state "${path}" to declare an initial child`)
|
|
181
182
|
}
|
|
182
183
|
return {
|
|
183
|
-
schema
|
|
184
|
+
schema,
|
|
184
185
|
output: undefined,
|
|
185
|
-
annotations
|
|
186
|
+
annotations,
|
|
186
187
|
type: "compound",
|
|
187
188
|
history: undefined,
|
|
188
189
|
initial: definition.initial,
|
|
@@ -192,18 +193,18 @@ export const getStateNodeDefinition = (
|
|
|
192
193
|
const output = Schema.isSchema(definition.output) ? definition.output : undefined
|
|
193
194
|
return definition.type === "final"
|
|
194
195
|
? {
|
|
195
|
-
schema
|
|
196
|
+
schema,
|
|
196
197
|
output,
|
|
197
|
-
annotations
|
|
198
|
+
annotations,
|
|
198
199
|
type: "final",
|
|
199
200
|
history: undefined,
|
|
200
201
|
initial: undefined,
|
|
201
202
|
states: undefined
|
|
202
203
|
}
|
|
203
204
|
: {
|
|
204
|
-
schema
|
|
205
|
+
schema,
|
|
205
206
|
output: undefined,
|
|
206
|
-
annotations
|
|
207
|
+
annotations,
|
|
207
208
|
type: "atomic",
|
|
208
209
|
history: undefined,
|
|
209
210
|
initial: undefined,
|
|
@@ -391,6 +392,29 @@ export const transitionDefinitions = (
|
|
|
391
392
|
targets: transitionTargets(config.onDone)
|
|
392
393
|
})
|
|
393
394
|
}
|
|
395
|
+
const invokes = config.invoke === undefined
|
|
396
|
+
? []
|
|
397
|
+
: Array.isArray(config.invoke)
|
|
398
|
+
? config.invoke
|
|
399
|
+
: [config.invoke]
|
|
400
|
+
for (const invoke of invokes) {
|
|
401
|
+
const id = "child" in invoke ? String(invoke.child.id) : String(invoke.id)
|
|
402
|
+
for (const outcome of ["done", "failure", "snapshot"] as const) {
|
|
403
|
+
const handler = outcome === "done"
|
|
404
|
+
? invoke.onDone
|
|
405
|
+
: outcome === "failure"
|
|
406
|
+
? invoke.onFailure
|
|
407
|
+
: invoke.onSnapshot
|
|
408
|
+
if (handler !== undefined) {
|
|
409
|
+
definitions.push({
|
|
410
|
+
source: node.path,
|
|
411
|
+
trigger: { type: "invoke", id, outcome },
|
|
412
|
+
reenter: typeof handler === "object" && handler !== null && handler.reenter === true,
|
|
413
|
+
targets: transitionTargets(handler)
|
|
414
|
+
})
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
394
418
|
}
|
|
395
419
|
return definitions
|
|
396
420
|
}
|
|
@@ -405,7 +429,7 @@ export const makeTarget = <
|
|
|
405
429
|
readonly snapshot?: Machine.SnapshotByIdentifier<States, StateId>
|
|
406
430
|
readonly values?: Partial<
|
|
407
431
|
{
|
|
408
|
-
readonly [AncestorStateId in Machine.
|
|
432
|
+
readonly [AncestorStateId in Machine.ValuedStateIdentifier<States>]: Machine.StateByIdentifier<
|
|
409
433
|
States,
|
|
410
434
|
AncestorStateId
|
|
411
435
|
>
|
|
@@ -445,7 +469,9 @@ export const getSnapshotByPath = (
|
|
|
445
469
|
return Option.none()
|
|
446
470
|
}
|
|
447
471
|
if (parents !== undefined) {
|
|
448
|
-
|
|
472
|
+
if (snapshot.value !== undefined) {
|
|
473
|
+
parents[snapshot.path] = snapshot.value
|
|
474
|
+
}
|
|
449
475
|
}
|
|
450
476
|
if (hasProperty(snapshot, "state") && isSnapshot(snapshot.state)) {
|
|
451
477
|
return getSnapshotByPath(snapshot.state, path, parents)
|
|
@@ -473,7 +499,7 @@ export const getNode = (machine: Machine.Any, path: string): Machine.StateNode =
|
|
|
473
499
|
|
|
474
500
|
export const getStateNodeSchema = (node: Machine.StateNode): Machine.TaggedSchema => {
|
|
475
501
|
if (node.schema === undefined) {
|
|
476
|
-
throw new Error(`Machine
|
|
502
|
+
throw new Error(`Machine state "${node.path}" has no value schema`)
|
|
477
503
|
}
|
|
478
504
|
return node.schema
|
|
479
505
|
}
|
|
@@ -1114,7 +1114,9 @@ export const verify = <M extends AnyMachine>(
|
|
|
1114
1114
|
}
|
|
1115
1115
|
return
|
|
1116
1116
|
}
|
|
1117
|
-
if (reportConfiguration &&
|
|
1117
|
+
if (reportConfiguration && node.schema === undefined && current.value !== undefined) {
|
|
1118
|
+
add("configuration.schema", location, `${label} structural state "${path}" contains a value`, path)
|
|
1119
|
+
} else if (reportConfiguration && node.schema !== undefined && !schemaMatches(node.schema, current.value)) {
|
|
1118
1120
|
add("configuration.schema", location, `${label} value for "${path}" does not match its schema`, path)
|
|
1119
1121
|
}
|
|
1120
1122
|
|
|
@@ -1284,9 +1286,17 @@ export const verify = <M extends AnyMachine>(
|
|
|
1284
1286
|
path
|
|
1285
1287
|
)
|
|
1286
1288
|
}
|
|
1287
|
-
|
|
1289
|
+
const hasValue = hasOwn(entry.values, path)
|
|
1290
|
+
if (node.schema === undefined && hasValue) {
|
|
1291
|
+
add(
|
|
1292
|
+
"history.value",
|
|
1293
|
+
location,
|
|
1294
|
+
`${label} history record "${historyPath}" values structural state "${path}"`,
|
|
1295
|
+
path
|
|
1296
|
+
)
|
|
1297
|
+
} else if (node.schema !== undefined && !hasValue) {
|
|
1288
1298
|
add("history.value", location, `${label} history record "${historyPath}" omits value for "${path}"`, path)
|
|
1289
|
-
} else if (!schemaMatches(node.schema, entry.values[path])) {
|
|
1299
|
+
} else if (node.schema !== undefined && !schemaMatches(node.schema, entry.values[path])) {
|
|
1290
1300
|
add(
|
|
1291
1301
|
"history.value",
|
|
1292
1302
|
location,
|
|
@@ -291,6 +291,13 @@ type SnapshotIdentifier<State> = SnapshotNode<State> extends infer Node ?
|
|
|
291
291
|
Node extends { readonly path: infer Path extends string } ? Path : never
|
|
292
292
|
: never
|
|
293
293
|
|
|
294
|
+
type ValuedSnapshotIdentifier<State> = SnapshotNode<State> extends infer Node ?
|
|
295
|
+
Node extends { readonly path: infer Path extends string; readonly value: infer Value } ?
|
|
296
|
+
[Value] extends [undefined] ? never
|
|
297
|
+
: Path
|
|
298
|
+
: never
|
|
299
|
+
: never
|
|
300
|
+
|
|
294
301
|
type SnapshotValueByIdentifier<State, Path extends SnapshotIdentifier<State>> = SnapshotNode<State> extends infer Node ?
|
|
295
302
|
Node extends { readonly path: Path; readonly value: infer Value } ? Value : never
|
|
296
303
|
: never
|
|
@@ -338,7 +345,7 @@ export const select: <
|
|
|
338
345
|
Error,
|
|
339
346
|
Output,
|
|
340
347
|
StartError,
|
|
341
|
-
const Path extends
|
|
348
|
+
const Path extends ValuedSnapshotIdentifier<State>
|
|
342
349
|
>(self: MachineAtom<State, Event, Error, Output, StartError>, path: Path) => Atom.Atom<
|
|
343
350
|
AsyncResult.AsyncResult<Option.Option<SnapshotValueByIdentifier<State, Path>>, StartError | Error>
|
|
344
351
|
> = internal.select
|
|
@@ -384,7 +391,7 @@ export const selectSnapshot: <
|
|
|
384
391
|
export const selectChild: <
|
|
385
392
|
Child extends Machine.ChildMachine.Any,
|
|
386
393
|
StartError,
|
|
387
|
-
const Path extends
|
|
394
|
+
const Path extends ValuedSnapshotIdentifier<ChildState<Child>>
|
|
388
395
|
>(self: ChildMachineAtom<Child, StartError>, path: Path) => Atom.Atom<
|
|
389
396
|
AsyncResult.AsyncResult<
|
|
390
397
|
Option.Option<SnapshotValueByIdentifier<ChildState<Child>, Path>>,
|
|
@@ -530,7 +537,7 @@ type MachineInputArgsOf<M extends Machine.Machine.Any> = [
|
|
|
530
537
|
|
|
531
538
|
type MachineAtomOf<M extends Machine.Machine.Any, RuntimeError> = MachineAtom<
|
|
532
539
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
533
|
-
Machine.Machine.InputEvent<M
|
|
540
|
+
Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>,
|
|
534
541
|
MachineRuntimeError<Machine.Machine.Error<M>, Machine.Machine.Services<M>>,
|
|
535
542
|
Machine.Machine.Output<M>,
|
|
536
543
|
MachineStartError<
|
|
@@ -544,7 +551,7 @@ type MachineAtomOf<M extends Machine.Machine.Any, RuntimeError> = MachineAtom<
|
|
|
544
551
|
|
|
545
552
|
type ResumedMachineAtomOf<M extends Machine.Machine.Any, RuntimeError> = MachineAtom<
|
|
546
553
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
547
|
-
Machine.Machine.InputEvent<M
|
|
554
|
+
Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>,
|
|
548
555
|
MachineRuntimeError<Machine.Machine.Error<M>, Machine.Machine.Services<M>>,
|
|
549
556
|
Machine.Machine.Output<M>,
|
|
550
557
|
Machine.MachineSchemaDecodeError | RuntimeError
|
|
@@ -654,7 +661,7 @@ export const make: {
|
|
|
654
661
|
...args: [...Machine.Machine.InputArgs<Input>]
|
|
655
662
|
): MachineAtom<
|
|
656
663
|
Machine.Machine.Snapshot<States>,
|
|
657
|
-
Machine.Machine.
|
|
664
|
+
Machine.Machine.EventInputOf<InputEvents>,
|
|
658
665
|
MachineRuntimeError<E, R>,
|
|
659
666
|
Output,
|
|
660
667
|
MachineStartError<InitialE, E, InitialR, R>
|