@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
package/dist/Machine.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export type TypeId = "~effect/Machine";
|
|
|
37
37
|
export declare const TypeId: TypeId;
|
|
38
38
|
declare const MachineOutputStatesTypeId: unique symbol;
|
|
39
39
|
declare const MachineTypeId: unique symbol;
|
|
40
|
+
declare const EventConstructionTypeId: unique symbol;
|
|
41
|
+
declare const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId;
|
|
40
42
|
/**
|
|
41
43
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
42
44
|
* actions.
|
|
@@ -109,7 +111,8 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
109
111
|
*/
|
|
110
112
|
readonly events: InputEvents;
|
|
111
113
|
/**
|
|
112
|
-
* Events reserved for
|
|
114
|
+
* Events reserved for raised events, child emissions, and other machine-local
|
|
115
|
+
* work.
|
|
113
116
|
*
|
|
114
117
|
* @since 0.4.0
|
|
115
118
|
*/
|
|
@@ -265,7 +268,7 @@ export interface Runtime<in Events, in Emits> {
|
|
|
265
268
|
*
|
|
266
269
|
* @since 0.4.0
|
|
267
270
|
*/
|
|
268
|
-
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
271
|
+
readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
269
272
|
/**
|
|
270
273
|
* Emits an event through the running machine's parent boundary.
|
|
271
274
|
*
|
|
@@ -283,7 +286,7 @@ export interface Runtime<in Events, in Emits> {
|
|
|
283
286
|
*/
|
|
284
287
|
export interface Enqueue<in Events, in Emits> {
|
|
285
288
|
/** Raises an event inside the current macrostep. */
|
|
286
|
-
readonly raise: (event: Events) => void;
|
|
289
|
+
readonly raise: (event: Machine.EventInput<Events>) => void;
|
|
287
290
|
/** Emits an event through the machine's parent boundary. */
|
|
288
291
|
readonly emit: (event: Emits) => void;
|
|
289
292
|
/** Sends an event to an invoked child after the transition is selected. */
|
|
@@ -383,48 +386,38 @@ type UnknownPseudoAnnotationProperty<Node> = Node extends {
|
|
|
383
386
|
type ValidatePseudoStateAnnotations<Node, Path extends PropertyKey> = [UnknownPseudoAnnotationProperty<Node>] extends [
|
|
384
387
|
never
|
|
385
388
|
] ? unknown : StateDefinitionError<"Pseudo-state annotations contain unknown properties", Path, Extract<UnknownPseudoAnnotationProperty<Node>, PropertyKey>>;
|
|
386
|
-
type ValidateStateNode<Node, AllowHistory extends boolean, Path extends PropertyKey> = Node extends Machine.TaggedSchema ? unknown : Node extends Machine.HistoryStateNodeConfig ? ValidateExactStateNodeProperties<Node, "history", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state", Path>) : Node extends Machine.ChoiceStateNodeConfig ? ValidateExactStateNodeProperties<Node, "choice", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateChoiceStateNode<Node> : StateDefinitionError<"Choice states must be declared below an active parent state", Path>) : Node extends
|
|
387
|
-
readonly schema: Machine.TaggedSchema;
|
|
388
|
-
} ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
|
|
389
|
+
type ValidateStateNode<Node, AllowHistory extends boolean, Path extends PropertyKey> = Node extends Machine.TaggedSchema ? unknown : Node extends Machine.HistoryStateNodeConfig ? ValidateExactStateNodeProperties<Node, "history", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state", Path>) : Node extends Machine.ChoiceStateNodeConfig ? ValidateExactStateNodeProperties<Node, "choice", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateChoiceStateNode<Node> : StateDefinitionError<"Choice states must be declared below an active parent state", Path>) : Node extends Machine.StateNodeConfig ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
|
|
389
390
|
type ValidateHistoryStateNode<Node extends Machine.HistoryStateNodeConfig> = [
|
|
390
391
|
Extract<keyof Node, "schema" | "states" | "initial" | "output" | "choice">
|
|
391
392
|
] extends [never] ? unknown : StateDefinitionError<"History states cannot declare schemas, children, initial states, or output">;
|
|
392
393
|
type ValidateChoiceStateNode<Node extends Machine.ChoiceStateNodeConfig> = [
|
|
393
394
|
Extract<keyof Node, "schema" | "states" | "initial" | "output" | "history">
|
|
394
395
|
] extends [never] ? unknown : StateDefinitionError<"Choice states cannot declare schemas, children, initial states, output, or history">;
|
|
395
|
-
type ValidateStateNodeConfig<Node extends {
|
|
396
|
-
readonly schema: Machine.TaggedSchema;
|
|
397
|
-
}, Path extends PropertyKey> = Node extends {
|
|
396
|
+
type ValidateStateNodeConfig<Node extends Machine.StateNodeConfig, Path extends PropertyKey> = Node extends {
|
|
398
397
|
readonly type: "parallel";
|
|
399
398
|
} ? ValidateExactStateNodeProperties<Node, "parallel", Path> & ValidateStateNodeWithChildren<Node, Node extends {
|
|
400
399
|
readonly states: infer Children;
|
|
401
|
-
} ? Children : never, Path> : Node extends {
|
|
400
|
+
} ? Children : never, Path> & ValidatePseudoStateAnnotations<Node, Path> : Node extends {
|
|
402
401
|
readonly type: "final";
|
|
403
|
-
} ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> : Node extends {
|
|
402
|
+
} ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> & ValidatePseudoStateAnnotations<Node, Path> : Node extends {
|
|
404
403
|
readonly states: infer Children;
|
|
405
|
-
} ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node>;
|
|
404
|
+
} ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> & ValidatePseudoStateAnnotations<Node, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node> & ValidatePseudoStateAnnotations<Node, Path>;
|
|
406
405
|
type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends {
|
|
407
406
|
readonly output: Schema.Top;
|
|
408
407
|
} ? unknown : StateDefinitionError<"State output must be a schema"> : unknown;
|
|
409
|
-
type ValidateStateNodeWithChildren<Node extends {
|
|
410
|
-
readonly schema: Machine.TaggedSchema;
|
|
411
|
-
}, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
|
|
408
|
+
type ValidateStateNodeWithChildren<Node extends Machine.StateNodeConfig, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
|
|
412
409
|
readonly type: "final";
|
|
413
410
|
} ? StateDefinitionError<"Final states cannot declare child states"> : Node extends {
|
|
414
411
|
readonly type: "parallel";
|
|
415
412
|
} ? "initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
|
|
416
413
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
417
414
|
} & ValidateOutputSchema<Node> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children, Path> : StateDefinitionError<"Child states must be a state tree">;
|
|
418
|
-
type ValidateCompoundStateNode<Node extends {
|
|
419
|
-
readonly schema: Machine.TaggedSchema;
|
|
420
|
-
}, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
|
|
415
|
+
type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
|
|
421
416
|
readonly initial: infer Initial;
|
|
422
417
|
} ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
|
|
423
418
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
424
419
|
} : StateDefinitionError<"Compound initial must be one of its direct child keys"> : StateDefinitionError<"Compound states must declare an initial child">;
|
|
425
|
-
type ValidateStateNodeWithoutChildren<Node extends {
|
|
426
|
-
readonly schema: Machine.TaggedSchema;
|
|
427
|
-
}> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
|
|
420
|
+
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
|
|
428
421
|
readonly type: infer Type;
|
|
429
422
|
} ? Type extends "final" ? ValidateOutputSchema<Node> : Type extends "active" | undefined ? "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown : StateDefinitionError<"State node type must be active, final, or parallel"> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown;
|
|
430
423
|
type DefineStateTreeInput<States extends Machine.StateSchemas> = {
|
|
@@ -483,6 +476,24 @@ type FromMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
|
483
476
|
};
|
|
484
477
|
type ConstructionResult<Result> = Result | Machine.StateConstruction<Result>;
|
|
485
478
|
type UnwrapConstruction<Result> = Result extends Machine.StateConstruction<infer Value> ? Value : Result;
|
|
479
|
+
type NodeValue<Node> = [Machine.NodeSchema<Node>] extends [never] ? undefined : Machine.NodeSchema<Node>["Type"];
|
|
480
|
+
type NodeMakeInput<Node> = [Machine.NodeSchema<Node>] extends [never] ? never : Machine.NodeSchema<Node>["~type.make.in"];
|
|
481
|
+
type WithNodeValue<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest : readonly [value: NodeValue<Node>, ...Rest];
|
|
482
|
+
type WithNodeInput<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest : readonly [input: NodeMakeInput<Node>, ...Rest];
|
|
483
|
+
type NodeBuilderMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>, FromResult> = Machine.NodeSchema<Node> extends never ? {
|
|
484
|
+
readonly from: FromCallable<FromArguments, FromResult>;
|
|
485
|
+
} : ((...args: Arguments) => Result) & {
|
|
486
|
+
readonly from: FromCallable<FromArguments, FromResult>;
|
|
487
|
+
};
|
|
488
|
+
type NodeMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? FromMethod<FromArguments, Result> : ((...args: Arguments) => Result) & FromMethod<FromArguments, Result>;
|
|
489
|
+
type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
|
|
490
|
+
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
491
|
+
} : ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>;
|
|
492
|
+
type NestedTargetMethod<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
|
|
493
|
+
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
|
|
494
|
+
} : (<Selected extends ConstructionResult<Result>>(value: NodeValue<Node>, state: (builder: Builder) => Selected) => Selected) & {
|
|
495
|
+
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
|
|
496
|
+
};
|
|
486
497
|
type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
|
|
487
498
|
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
488
499
|
<Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
@@ -492,127 +503,111 @@ type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefi
|
|
|
492
503
|
} & {
|
|
493
504
|
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
494
505
|
};
|
|
495
|
-
type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: InitialSnapshotArguments<States, StateId, Prefix>) => InitialSnapshotResult<States, StateId, Prefix>) & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
|
|
506
|
+
type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>> : ((...args: InitialSnapshotArguments<States, StateId, Prefix>) => InitialSnapshotResult<States, StateId, Prefix>) & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
|
|
496
507
|
type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
497
508
|
readonly type: "parallel";
|
|
498
509
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
499
|
-
} ? [
|
|
500
|
-
value: Machine.NodeSchema<Node>["Type"],
|
|
510
|
+
} ? WithNodeValue<Node, [
|
|
501
511
|
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
|
|
502
|
-
] : Node extends {
|
|
512
|
+
]> : Node extends {
|
|
503
513
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
504
514
|
} ? Node extends {
|
|
505
515
|
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
506
|
-
} ? [
|
|
507
|
-
value: Machine.NodeSchema<Node>["Type"],
|
|
516
|
+
} ? WithNodeValue<Node, [
|
|
508
517
|
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
|
|
509
|
-
] : never :
|
|
518
|
+
]> : never : WithNodeValue<Node, []> : never;
|
|
510
519
|
type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
511
520
|
readonly type: "parallel";
|
|
512
521
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
513
|
-
} ? [
|
|
514
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
522
|
+
} ? WithNodeInput<Node, [
|
|
515
523
|
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
516
|
-
] : Node extends {
|
|
524
|
+
]> : Node extends {
|
|
517
525
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
518
526
|
} ? Node extends {
|
|
519
527
|
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
520
|
-
} ? [
|
|
521
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
528
|
+
} ? WithNodeInput<Node, [
|
|
522
529
|
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
|
|
523
|
-
] : never :
|
|
530
|
+
]> : never : WithNodeInput<Node, []> : never;
|
|
524
531
|
type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
525
532
|
readonly type: "parallel";
|
|
526
533
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
527
|
-
} ? Machine.ParallelSnapshot<Path,
|
|
534
|
+
} ? Machine.ParallelSnapshot<Path, NodeValue<Node>, InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
|
|
528
535
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
529
536
|
} ? Node extends {
|
|
530
537
|
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
531
|
-
} ? Machine.CompoundSnapshot<Path,
|
|
538
|
+
} ? Machine.CompoundSnapshot<Path, NodeValue<Node>, InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, NodeValue<Node>> : never;
|
|
532
539
|
type InitialSelectableResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States> | ChoiceStateKey<States>, Prefix extends string> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>> : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix> : never;
|
|
533
540
|
type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
|
|
534
541
|
readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
|
|
535
542
|
};
|
|
536
543
|
type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
537
|
-
readonly [Key in Remaining]:
|
|
544
|
+
readonly [Key in Remaining]: NodeBuilderMethod<States[Key], InitialSnapshotArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
538
545
|
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
539
|
-
}, Constructed
|
|
540
|
-
readonly
|
|
541
|
-
|
|
542
|
-
}, true>>;
|
|
543
|
-
};
|
|
546
|
+
}, Constructed>, InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
547
|
+
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
548
|
+
}, true>>;
|
|
544
549
|
};
|
|
545
550
|
type FullSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
546
551
|
readonly [Key in ActiveStateKey<States>]: FullSnapshotMethod<States, Key, Prefix>;
|
|
547
552
|
} & {
|
|
548
553
|
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
549
554
|
};
|
|
550
|
-
type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>) & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
|
|
555
|
+
type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>> : ((...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>) & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
|
|
551
556
|
type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
552
557
|
readonly type: "parallel";
|
|
553
558
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
554
|
-
} ? [
|
|
555
|
-
value: Machine.NodeSchema<Node>["Type"],
|
|
559
|
+
} ? WithNodeValue<Node, [
|
|
556
560
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
557
|
-
] : Node extends {
|
|
561
|
+
]> : Node extends {
|
|
558
562
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
559
|
-
} ? [
|
|
560
|
-
value: Machine.NodeSchema<Node>["Type"],
|
|
563
|
+
} ? WithNodeValue<Node, [
|
|
561
564
|
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
|
|
562
|
-
] :
|
|
565
|
+
]> : WithNodeValue<Node, []> : never;
|
|
563
566
|
type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
564
567
|
readonly type: "parallel";
|
|
565
568
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
566
|
-
} ? [
|
|
567
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
569
|
+
} ? WithNodeInput<Node, [
|
|
568
570
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
569
|
-
] : Node extends {
|
|
571
|
+
]> : Node extends {
|
|
570
572
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
571
|
-
} ? [
|
|
572
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
573
|
+
} ? WithNodeInput<Node, [
|
|
573
574
|
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
|
|
574
|
-
] :
|
|
575
|
+
]> : WithNodeInput<Node, []> : never;
|
|
575
576
|
type FullSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Machine.SnapshotByIdentifierWithPath<States, StateId, Path>;
|
|
576
577
|
type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
577
|
-
readonly [Key in Remaining]:
|
|
578
|
+
readonly [Key in Remaining]: NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
578
579
|
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
579
|
-
}, Constructed
|
|
580
|
-
readonly
|
|
581
|
-
|
|
582
|
-
}, true>>;
|
|
583
|
-
};
|
|
580
|
+
}, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
581
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
582
|
+
}, true>>;
|
|
584
583
|
};
|
|
585
584
|
type HistorySnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
|
|
586
585
|
readonly type: "parallel";
|
|
587
586
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
588
|
-
} ? [
|
|
589
|
-
value: Machine.NodeSchema<Node>["Type"],
|
|
587
|
+
} ? WithNodeValue<Node, [
|
|
590
588
|
states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
|
|
591
|
-
] : Node extends {
|
|
589
|
+
]> : Node extends {
|
|
592
590
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
593
|
-
} ? [
|
|
594
|
-
value: Machine.NodeSchema<Node>["Type"],
|
|
591
|
+
} ? WithNodeValue<Node, [
|
|
595
592
|
state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
596
|
-
] : never : never;
|
|
593
|
+
]> : never : never;
|
|
597
594
|
type HistorySnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
|
|
598
595
|
readonly type: "parallel";
|
|
599
596
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
600
|
-
} ? [
|
|
601
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
597
|
+
} ? WithNodeInput<Node, [
|
|
602
598
|
states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
|
|
603
|
-
] : Node extends {
|
|
599
|
+
]> : Node extends {
|
|
604
600
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
605
|
-
} ? [
|
|
606
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
601
|
+
} ? WithNodeInput<Node, [
|
|
607
602
|
state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
608
|
-
] : never : never;
|
|
603
|
+
]> : never : never;
|
|
609
604
|
type HistorySnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotResult<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
|
|
610
605
|
readonly type: "parallel";
|
|
611
606
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
612
|
-
} ? Machine.ParallelSnapshot<Path,
|
|
607
|
+
} ? Machine.ParallelSnapshot<Path, NodeValue<Node>, HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
|
|
613
608
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
614
|
-
} ? Machine.CompoundSnapshot<Path,
|
|
615
|
-
type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> = ((...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>) & FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>>;
|
|
609
|
+
} ? Machine.CompoundSnapshot<Path, NodeValue<Node>, HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
|
|
610
|
+
type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>> : ((...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>) & FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>>;
|
|
616
611
|
type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
|
|
617
612
|
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
|
|
618
613
|
}[ActiveStateKey<States>];
|
|
@@ -623,19 +618,15 @@ type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends
|
|
|
623
618
|
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
|
|
624
619
|
};
|
|
625
620
|
type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Owner extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
626
|
-
readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ?
|
|
621
|
+
readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? NodeBuilderMethod<States[Key], HistorySnapshotArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
622
|
+
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
623
|
+
}, Constructed>, HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
627
624
|
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
628
|
-
},
|
|
629
|
-
readonly from: FromCallable<HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
630
|
-
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
631
|
-
}, true>>;
|
|
632
|
-
} : ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
625
|
+
}, true>> : NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
633
626
|
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
634
|
-
}, Constructed
|
|
635
|
-
readonly
|
|
636
|
-
|
|
637
|
-
}, true>>;
|
|
638
|
-
};
|
|
627
|
+
}, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
628
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
629
|
+
}, true>>;
|
|
639
630
|
};
|
|
640
631
|
type ParentPath<Path extends string> = Path extends `${infer Parent}.${infer Child}` ? Child extends `${string}.${string}` ? `${Parent}.${ParentPath<Child>}` : Parent : never;
|
|
641
632
|
type IsCompoundNode<Node> = Node extends {
|
|
@@ -664,19 +655,14 @@ type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States
|
|
|
664
655
|
type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
665
656
|
readonly type: "parallel";
|
|
666
657
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
667
|
-
} ? Source extends Path | `${Path}.${string}` ?
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
658
|
+
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>> : NodeMethod<Node, WithNodeValue<Node, [
|
|
659
|
+
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
660
|
+
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
671
661
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
672
|
-
]
|
|
662
|
+
]>> : Node extends {
|
|
673
663
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
674
|
-
} ?
|
|
675
|
-
|
|
676
|
-
} : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
677
|
-
input: Machine.NodeSchema<Node>["~type.make.in"]
|
|
678
|
-
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
|
|
679
|
-
type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateNodeIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & {
|
|
664
|
+
} ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
|
|
665
|
+
type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateNodeIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & (Scope extends Machine.ValuedStateIdentifier<States> ? {
|
|
680
666
|
/**
|
|
681
667
|
* Updates the value of the state containing the local group and moves to
|
|
682
668
|
* one of the states inside it. Values in other active branches are kept.
|
|
@@ -686,7 +672,7 @@ type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope exten
|
|
|
686
672
|
readonly with: (<Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(value: Machine.StateByIdentifier<States, Scope>, state: (builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>) => Result) => Result) & {
|
|
687
673
|
readonly from: ConstructionSelectorFromCallable<Machine.SchemaByIdentifier<States, Scope>["~type.make.in"], LocalTargetBuilderWithPrefix<States, Children, Scope, Source>, LocalTargetResultWithPrefix<States, Children, Scope>>;
|
|
688
674
|
};
|
|
689
|
-
} : {};
|
|
675
|
+
} : {}) : {};
|
|
690
676
|
type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends {
|
|
691
677
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
692
678
|
} ? States[StateId] extends {
|
|
@@ -703,18 +689,13 @@ type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, State
|
|
|
703
689
|
type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
704
690
|
readonly type: "parallel";
|
|
705
691
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
706
|
-
} ? Source extends Path | `${Path}.${string}` ?
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
692
|
+
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethod<Node, WithNodeValue<Node, [
|
|
693
|
+
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
694
|
+
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
710
695
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
711
|
-
]
|
|
696
|
+
]>> : Node extends {
|
|
712
697
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
713
|
-
} ?
|
|
714
|
-
readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>>;
|
|
715
|
-
} & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
716
|
-
input: Machine.NodeSchema<Node>["~type.make.in"]
|
|
717
|
-
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
|
|
698
|
+
} ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
|
|
718
699
|
type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
|
|
719
700
|
readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
|
|
720
701
|
};
|
|
@@ -735,13 +716,16 @@ type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
|
|
|
735
716
|
readonly history: "deep";
|
|
736
717
|
} ? never : Key;
|
|
737
718
|
}[HistoryStateKey<States>] extends never ? false : true;
|
|
719
|
+
type HasValuedActiveChild<States extends Machine.StateSchemas> = {
|
|
720
|
+
readonly [Key in ActiveStateKey<States>]: Machine.NodeSchema<States[Key]> extends never ? never : Key;
|
|
721
|
+
}[ActiveStateKey<States>] extends never ? false : true;
|
|
738
722
|
type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Path extends string> = Node extends {
|
|
739
723
|
readonly type: "parallel";
|
|
740
724
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
741
|
-
} ? Extract<Path, Machine.StateIdentifier<AllStates>> | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
|
|
725
|
+
} ? (HasValuedActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never) | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
|
|
742
726
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
743
727
|
readonly initial: infer Initial;
|
|
744
|
-
} ? Extract<Path, Machine.StateIdentifier<AllStates>> | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never;
|
|
728
|
+
} ? (Initial extends ActiveStateKey<Children> ? Machine.NodeSchema<Children[Initial]> extends never ? never : Extract<Path, Machine.StateIdentifier<AllStates>> : never) | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never;
|
|
745
729
|
type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
746
730
|
readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
|
|
747
731
|
}[ActiveStateKey<States>];
|
|
@@ -923,7 +907,8 @@ export declare namespace Logic {
|
|
|
923
907
|
*
|
|
924
908
|
* `sendParent` accepts `unknown` because process logic is independent from
|
|
925
909
|
* the parent that eventually owns it. Prefer typed process output or an
|
|
926
|
-
*
|
|
910
|
+
* invocation lifecycle transition when either can represent the
|
|
911
|
+
* communication.
|
|
927
912
|
*
|
|
928
913
|
* @category models
|
|
929
914
|
* @since 0.4.0
|
|
@@ -971,8 +956,9 @@ type InvokeLifecycleId = string & {
|
|
|
971
956
|
* **Details**
|
|
972
957
|
*
|
|
973
958
|
* The descriptor carries the child's address and complete machine type. Pass
|
|
974
|
-
* the same
|
|
975
|
-
* event, error, and output types are inferred
|
|
959
|
+
* a descriptor for the same id and machine to inline `invoke`, `sendTo`, and
|
|
960
|
+
* child lookup APIs so state, event, error, and output types are inferred
|
|
961
|
+
* without separate annotations.
|
|
976
962
|
*
|
|
977
963
|
* @category models
|
|
978
964
|
* @since 0.4.0
|
|
@@ -983,6 +969,8 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
983
969
|
readonly id: Id;
|
|
984
970
|
/** Complete machine definition carried by this descriptor. */
|
|
985
971
|
readonly machine: M;
|
|
972
|
+
/** @internal */
|
|
973
|
+
readonly [ChildMachineLogicTypeId]: (input?: unknown) => Logic<any, any, any, any, any, any>;
|
|
986
974
|
}
|
|
987
975
|
/**
|
|
988
976
|
* Namespace containing type-level members associated with `ChildMachine`.
|
|
@@ -1004,7 +992,7 @@ export declare namespace ChildMachine {
|
|
|
1004
992
|
* @category utility types
|
|
1005
993
|
* @since 0.4.0
|
|
1006
994
|
*/
|
|
1007
|
-
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.InputEvent<M
|
|
995
|
+
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.EventInput<Machine.InputEvent<M>>, Machine.Error<M> | ActionError<Machine.Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Machine.Output<M>> : never;
|
|
1008
996
|
/**
|
|
1009
997
|
* Event accepted by the child selected by a descriptor.
|
|
1010
998
|
*
|
|
@@ -1240,6 +1228,11 @@ export declare namespace Machine {
|
|
|
1240
1228
|
* @since 0.4.0
|
|
1241
1229
|
*/
|
|
1242
1230
|
type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
1231
|
+
/** Extracts the internal event schema tuple carried by a machine definition. */
|
|
1232
|
+
type InternalEvents<M extends Any> = Events<M> extends readonly [
|
|
1233
|
+
...InputEvents<M>,
|
|
1234
|
+
...infer Internal extends ReadonlyArray<TaggedSchema>
|
|
1235
|
+
] ? Internal : readonly [];
|
|
1243
1236
|
/**
|
|
1244
1237
|
* Extracts the complete event protocol handled inside a machine.
|
|
1245
1238
|
*
|
|
@@ -1254,6 +1247,40 @@ export declare namespace Machine {
|
|
|
1254
1247
|
* @since 0.4.0
|
|
1255
1248
|
*/
|
|
1256
1249
|
type InputEvent<M extends Any> = EventOf<InputEvents<M>>;
|
|
1250
|
+
/**
|
|
1251
|
+
* Opaque event construction returned by {@link events} and
|
|
1252
|
+
* {@link internalEvents}.
|
|
1253
|
+
*
|
|
1254
|
+
* The machine resolves the instruction through its event schema when it is
|
|
1255
|
+
* delivered. Only the discriminator is available before decoding succeeds.
|
|
1256
|
+
*/
|
|
1257
|
+
interface EventConstruction<out Event extends {
|
|
1258
|
+
readonly _tag: PropertyKey;
|
|
1259
|
+
}> {
|
|
1260
|
+
readonly [EventConstructionTypeId]: Event;
|
|
1261
|
+
readonly _tag: Event["_tag"];
|
|
1262
|
+
}
|
|
1263
|
+
/** A decoded event or a deferred machine-bound construction of that event. */
|
|
1264
|
+
type EventInput<Event> = Event | (Event extends {
|
|
1265
|
+
readonly _tag: PropertyKey;
|
|
1266
|
+
} ? EventConstruction<Event> : never);
|
|
1267
|
+
/** Event inputs accepted for a schema tuple at machine delivery boundaries. */
|
|
1268
|
+
type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>;
|
|
1269
|
+
type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">;
|
|
1270
|
+
type EventConstructor<EventSchema extends TaggedSchema, Tag extends EventSchema["Type"]["_tag"]> = {} extends EventConstructorInput<EventSchema> ? (input?: EventConstructorInput<EventSchema>) => EventConstruction<EventByTag<readonly [EventSchema], Tag>> : (input: EventConstructorInput<EventSchema>) => EventConstruction<EventByTag<readonly [EventSchema], Tag>>;
|
|
1271
|
+
type EventConstructorsForSchema<EventSchema extends TaggedSchema> = EventSchema extends {
|
|
1272
|
+
readonly cases: infer Cases extends Readonly<Record<PropertyKey, TaggedSchema>>;
|
|
1273
|
+
} ? {
|
|
1274
|
+
readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag> : never;
|
|
1275
|
+
} : EventSchema extends {
|
|
1276
|
+
readonly members: infer Members extends ReadonlyArray<TaggedSchema>;
|
|
1277
|
+
} ? Types.UnionToIntersection<EventConstructorsForSchema<Members[number]>> : {
|
|
1278
|
+
readonly [Tag in EventSchema["Type"]["_tag"]]: EventConstructor<EventSchema, Tag>;
|
|
1279
|
+
};
|
|
1280
|
+
/** Protocol-bound constructors keyed by each configured event tag. */
|
|
1281
|
+
type EventConstructors<Events extends ReadonlyArray<TaggedSchema>> = {
|
|
1282
|
+
readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number]>>]: Types.UnionToIntersection<EventConstructorsForSchema<Events[number]>>[Tag];
|
|
1283
|
+
};
|
|
1257
1284
|
/**
|
|
1258
1285
|
* Extracts the event protocol emitted by a machine.
|
|
1259
1286
|
*
|
|
@@ -1280,8 +1307,9 @@ export declare namespace Machine {
|
|
|
1280
1307
|
* Descriptive annotations exposed for compiled state nodes.
|
|
1281
1308
|
*
|
|
1282
1309
|
* Schema-backed states resolve their complete Effect Schema annotation map.
|
|
1283
|
-
*
|
|
1284
|
-
* affect state identity, targeting, or
|
|
1310
|
+
* Schema-less active states and pseudo-states accept only the descriptive
|
|
1311
|
+
* fields below. Annotations never affect state identity, targeting, or
|
|
1312
|
+
* runtime behavior.
|
|
1285
1313
|
*
|
|
1286
1314
|
* @category models
|
|
1287
1315
|
* @since 0.4.0
|
|
@@ -1291,10 +1319,13 @@ export declare namespace Machine {
|
|
|
1291
1319
|
readonly description?: string | undefined;
|
|
1292
1320
|
readonly documentation?: string | undefined;
|
|
1293
1321
|
}
|
|
1294
|
-
/** Descriptive annotations accepted by schema-less pseudo-states. */
|
|
1295
|
-
type
|
|
1322
|
+
/** Descriptive annotations accepted by schema-less active and pseudo-states. */
|
|
1323
|
+
type SchemaLessStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
|
|
1324
|
+
/** @deprecated Use {@link SchemaLessStateAnnotations}. */
|
|
1325
|
+
type PseudoStateAnnotations = SchemaLessStateAnnotations;
|
|
1296
1326
|
/**
|
|
1297
|
-
* Configuration accepted for an atomic object state node.
|
|
1327
|
+
* Configuration accepted for an atomic object state node. Omit `schema` when
|
|
1328
|
+
* the state owns no value; a schema-less final may still declare `output`.
|
|
1298
1329
|
*
|
|
1299
1330
|
* @category models
|
|
1300
1331
|
* @since 0.4.0
|
|
@@ -1303,35 +1334,63 @@ export declare namespace Machine {
|
|
|
1303
1334
|
readonly schema: TaggedSchema;
|
|
1304
1335
|
readonly type?: "active";
|
|
1305
1336
|
readonly output?: never;
|
|
1337
|
+
readonly annotations?: never;
|
|
1306
1338
|
} | {
|
|
1307
1339
|
readonly schema: TaggedSchema;
|
|
1308
1340
|
readonly type: "final";
|
|
1309
1341
|
readonly output?: Schema.Top;
|
|
1342
|
+
readonly annotations?: never;
|
|
1343
|
+
} | {
|
|
1344
|
+
readonly schema?: never;
|
|
1345
|
+
readonly type?: "active";
|
|
1346
|
+
readonly output?: never;
|
|
1347
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1348
|
+
} | {
|
|
1349
|
+
readonly schema?: never;
|
|
1350
|
+
readonly type: "final";
|
|
1351
|
+
readonly output?: Schema.Top;
|
|
1352
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1310
1353
|
};
|
|
1311
1354
|
/**
|
|
1312
|
-
* Configuration accepted for a compound object state node.
|
|
1355
|
+
* Configuration accepted for a compound object state node. Omit `schema`
|
|
1356
|
+
* when the compound state exists only to own control topology.
|
|
1313
1357
|
*
|
|
1314
1358
|
* @category models
|
|
1315
1359
|
* @since 0.4.0
|
|
1316
1360
|
*/
|
|
1317
|
-
|
|
1361
|
+
type CompoundStateNodeConfig = {
|
|
1318
1362
|
readonly schema: TaggedSchema;
|
|
1319
1363
|
readonly type?: "active";
|
|
1320
1364
|
readonly initial: string;
|
|
1321
1365
|
readonly states: StateTree;
|
|
1322
|
-
|
|
1366
|
+
readonly annotations?: never;
|
|
1367
|
+
} | {
|
|
1368
|
+
readonly schema?: never;
|
|
1369
|
+
readonly type?: "active";
|
|
1370
|
+
readonly initial: string;
|
|
1371
|
+
readonly states: StateTree;
|
|
1372
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1373
|
+
};
|
|
1323
1374
|
/**
|
|
1324
|
-
* Configuration accepted for a parallel object state node.
|
|
1375
|
+
* Configuration accepted for a parallel object state node. Omit `schema`
|
|
1376
|
+
* when the parallel state exists only to own its regions.
|
|
1325
1377
|
*
|
|
1326
1378
|
* @category models
|
|
1327
1379
|
* @since 0.4.0
|
|
1328
1380
|
*/
|
|
1329
|
-
|
|
1381
|
+
type ParallelStateNodeConfig = {
|
|
1330
1382
|
readonly schema: TaggedSchema;
|
|
1331
1383
|
readonly type: "parallel";
|
|
1332
1384
|
readonly output?: Schema.Top;
|
|
1333
1385
|
readonly states: StateTree;
|
|
1334
|
-
|
|
1386
|
+
readonly annotations?: never;
|
|
1387
|
+
} | {
|
|
1388
|
+
readonly schema?: never;
|
|
1389
|
+
readonly type: "parallel";
|
|
1390
|
+
readonly output?: Schema.Top;
|
|
1391
|
+
readonly states: StateTree;
|
|
1392
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1393
|
+
};
|
|
1335
1394
|
/**
|
|
1336
1395
|
* Pseudo-state that restores the last active configuration of its parent.
|
|
1337
1396
|
*
|
|
@@ -1348,7 +1407,7 @@ export declare namespace Machine {
|
|
|
1348
1407
|
readonly type: "history";
|
|
1349
1408
|
/** Defaults to shallow history. */
|
|
1350
1409
|
readonly history?: "shallow" | "deep";
|
|
1351
|
-
readonly annotations?:
|
|
1410
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1352
1411
|
}
|
|
1353
1412
|
/**
|
|
1354
1413
|
* Transient decision pseudo-state resolved immediately when targeted.
|
|
@@ -1362,7 +1421,7 @@ export declare namespace Machine {
|
|
|
1362
1421
|
*/
|
|
1363
1422
|
interface ChoiceStateNodeConfig {
|
|
1364
1423
|
readonly type: "choice";
|
|
1365
|
-
readonly annotations?:
|
|
1424
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1366
1425
|
}
|
|
1367
1426
|
/**
|
|
1368
1427
|
* Configuration accepted for an object state node.
|
|
@@ -1431,8 +1490,8 @@ export declare namespace Machine {
|
|
|
1431
1490
|
* @since 0.4.0
|
|
1432
1491
|
*/
|
|
1433
1492
|
readonly get: {
|
|
1434
|
-
<Path extends
|
|
1435
|
-
<const From extends StateIdentifier<States>, const Path extends
|
|
1493
|
+
<Path extends ValuedStateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): Option.Option<StateByIdentifier<States, Path>>;
|
|
1494
|
+
<const From extends StateIdentifier<States>, const Path extends ValuedStateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): Option.Option<StateByIdentifier<States, Path>>;
|
|
1436
1495
|
};
|
|
1437
1496
|
/**
|
|
1438
1497
|
* Returns the decoded value for an active state path together with all of
|
|
@@ -1444,7 +1503,7 @@ export declare namespace Machine {
|
|
|
1444
1503
|
*
|
|
1445
1504
|
* @since 0.4.0
|
|
1446
1505
|
*/
|
|
1447
|
-
readonly getWithParents: <Path extends
|
|
1506
|
+
readonly getWithParents: <Path extends ValuedStateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateWithParents<States, Path>>;
|
|
1448
1507
|
/**
|
|
1449
1508
|
* Returns the snapshot for an active state path. The supplied snapshot may
|
|
1450
1509
|
* be a complete root snapshot or a snapshot previously extracted from this
|
|
@@ -1481,14 +1540,14 @@ export declare namespace Machine {
|
|
|
1481
1540
|
interface StateNodeBase<Path extends string = string> {
|
|
1482
1541
|
readonly path: Path;
|
|
1483
1542
|
readonly key: string;
|
|
1484
|
-
/** Resolved
|
|
1543
|
+
/** Resolved schema annotations, or descriptive schema-less-state annotations. */
|
|
1485
1544
|
readonly annotations: Readonly<StateNodeAnnotations> | undefined;
|
|
1486
1545
|
readonly order: number;
|
|
1487
1546
|
}
|
|
1488
1547
|
/** Runtime metadata for a compiled atomic state. */
|
|
1489
1548
|
interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1490
1549
|
readonly type: "atomic";
|
|
1491
|
-
readonly schema: TaggedSchema;
|
|
1550
|
+
readonly schema: TaggedSchema | undefined;
|
|
1492
1551
|
readonly output: undefined;
|
|
1493
1552
|
readonly history: undefined;
|
|
1494
1553
|
readonly parent: ActivePath | undefined;
|
|
@@ -1498,7 +1557,7 @@ export declare namespace Machine {
|
|
|
1498
1557
|
/** Runtime metadata for a compiled compound state. */
|
|
1499
1558
|
interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
|
|
1500
1559
|
readonly type: "compound";
|
|
1501
|
-
readonly schema: TaggedSchema;
|
|
1560
|
+
readonly schema: TaggedSchema | undefined;
|
|
1502
1561
|
readonly output: undefined;
|
|
1503
1562
|
readonly history: undefined;
|
|
1504
1563
|
readonly parent: ActivePath | undefined;
|
|
@@ -1509,7 +1568,7 @@ export declare namespace Machine {
|
|
|
1509
1568
|
/** Runtime metadata for a compiled parallel state. */
|
|
1510
1569
|
interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1511
1570
|
readonly type: "parallel";
|
|
1512
|
-
readonly schema: TaggedSchema;
|
|
1571
|
+
readonly schema: TaggedSchema | undefined;
|
|
1513
1572
|
readonly output: Schema.Top | undefined;
|
|
1514
1573
|
readonly history: undefined;
|
|
1515
1574
|
readonly parent: ActivePath | undefined;
|
|
@@ -1520,7 +1579,7 @@ export declare namespace Machine {
|
|
|
1520
1579
|
/** Runtime metadata for a compiled final state. */
|
|
1521
1580
|
interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1522
1581
|
readonly type: "final";
|
|
1523
|
-
readonly schema: TaggedSchema;
|
|
1582
|
+
readonly schema: TaggedSchema | undefined;
|
|
1524
1583
|
readonly output: Schema.Top | undefined;
|
|
1525
1584
|
readonly history: undefined;
|
|
1526
1585
|
readonly parent: ActivePath | undefined;
|
|
@@ -1583,6 +1642,10 @@ export declare namespace Machine {
|
|
|
1583
1642
|
readonly type: "done";
|
|
1584
1643
|
} | {
|
|
1585
1644
|
readonly type: "choice";
|
|
1645
|
+
} | {
|
|
1646
|
+
readonly type: "invoke";
|
|
1647
|
+
readonly id: string;
|
|
1648
|
+
readonly outcome: "done" | "failure" | "snapshot";
|
|
1586
1649
|
};
|
|
1587
1650
|
/**
|
|
1588
1651
|
* Statically inspectable destination paths for a transition handler.
|
|
@@ -1602,10 +1665,10 @@ export declare namespace Machine {
|
|
|
1602
1665
|
*
|
|
1603
1666
|
* **Details**
|
|
1604
1667
|
*
|
|
1605
|
-
* Event, eventless, and
|
|
1606
|
-
* possible target paths. A handler without that
|
|
1607
|
-
* reported as dynamic. The source, trigger, and
|
|
1608
|
-
* available without executing the handler.
|
|
1668
|
+
* Event, eventless, completion, and invocation lifecycle handlers may
|
|
1669
|
+
* declare an upper bound of possible target paths. A handler without that
|
|
1670
|
+
* declaration is explicitly reported as dynamic. The source, trigger, and
|
|
1671
|
+
* reentry behavior are available without executing the handler.
|
|
1609
1672
|
*
|
|
1610
1673
|
* @category models
|
|
1611
1674
|
* @since 0.4.0
|
|
@@ -1619,9 +1682,9 @@ export declare namespace Machine {
|
|
|
1619
1682
|
/**
|
|
1620
1683
|
* Serializable description of state-owned work.
|
|
1621
1684
|
*
|
|
1622
|
-
* Static invoke
|
|
1623
|
-
* retaining Effects, closures, services, or child runtimes.
|
|
1624
|
-
*
|
|
1685
|
+
* Static invoke definitions expose their lifecycle id and kind without
|
|
1686
|
+
* retaining Effects, closures, services, or child runtimes. Function-valued
|
|
1687
|
+
* sources are reported as dynamic and are never evaluated by inspection.
|
|
1625
1688
|
*
|
|
1626
1689
|
* @category models
|
|
1627
1690
|
* @since 0.4.0
|
|
@@ -1680,6 +1743,10 @@ export declare namespace Machine {
|
|
|
1680
1743
|
* @since 0.4.0
|
|
1681
1744
|
*/
|
|
1682
1745
|
type StateIdentifier<States extends StateSchemas> = StateIdentifierWithPrefix<States>;
|
|
1746
|
+
/** Extracts active state paths whose definitions declare a state value schema. */
|
|
1747
|
+
type ValuedStateIdentifier<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? NodeSchema<NodeByIdentifier<States, StateId>> extends never ? never : StateId : never : never;
|
|
1748
|
+
/** Extracts active state paths whose definitions intentionally omit a state value schema. */
|
|
1749
|
+
type StructuralStateIdentifier<States extends StateSchemas> = Exclude<StateIdentifier<States>, ValuedStateIdentifier<States>>;
|
|
1683
1750
|
/**
|
|
1684
1751
|
* Extracts the state path values represented by a state definition under a
|
|
1685
1752
|
* parent path prefix.
|
|
@@ -1807,7 +1874,7 @@ export declare namespace Machine {
|
|
|
1807
1874
|
* @category utility types
|
|
1808
1875
|
* @since 0.4.0
|
|
1809
1876
|
*/
|
|
1810
|
-
type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> =
|
|
1877
|
+
type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends ValuedStateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : undefined;
|
|
1811
1878
|
/**
|
|
1812
1879
|
* Extracts every parent state path from a state identifier.
|
|
1813
1880
|
*
|
|
@@ -1829,7 +1896,7 @@ export declare namespace Machine {
|
|
|
1829
1896
|
* @since 0.4.0
|
|
1830
1897
|
*/
|
|
1831
1898
|
type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
1832
|
-
readonly [Parent in Extract<ParentStateIdentifier<StateId>,
|
|
1899
|
+
readonly [Parent in Extract<ParentStateIdentifier<StateId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
1833
1900
|
} : never;
|
|
1834
1901
|
/**
|
|
1835
1902
|
* Extracts the nearest parent value, or `undefined` for a root state.
|
|
@@ -1837,7 +1904,7 @@ export declare namespace Machine {
|
|
|
1837
1904
|
* @category utility types
|
|
1838
1905
|
* @since 0.4.0
|
|
1839
1906
|
*/
|
|
1840
|
-
type ParentStateValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent ? [Parent] extends [never] ? undefined : Parent extends
|
|
1907
|
+
type ParentStateValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent ? [Parent] extends [never] ? undefined : Parent extends ValuedStateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
|
|
1841
1908
|
/**
|
|
1842
1909
|
* Represents a decoded state value together with all of its parent values.
|
|
1843
1910
|
*
|
|
@@ -1954,7 +2021,7 @@ export declare namespace Machine {
|
|
|
1954
2021
|
*/
|
|
1955
2022
|
interface EncodedSnapshotState {
|
|
1956
2023
|
readonly path: string;
|
|
1957
|
-
readonly value
|
|
2024
|
+
readonly value?: unknown;
|
|
1958
2025
|
}
|
|
1959
2026
|
/**
|
|
1960
2027
|
* Encoded output for one completed state path in a normalized machine
|
|
@@ -2103,9 +2170,9 @@ export declare namespace Machine {
|
|
|
2103
2170
|
type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
|
|
2104
2171
|
readonly type: "parallel";
|
|
2105
2172
|
readonly states: infer Children;
|
|
2106
|
-
} ? Children extends StateSchemas ? ParallelSnapshot<Path,
|
|
2173
|
+
} ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeValue<States[StateId]>, SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : States[StateId] extends {
|
|
2107
2174
|
readonly states: infer Children;
|
|
2108
|
-
} ? Children extends StateSchemas ? CompoundSnapshot<Path,
|
|
2175
|
+
} ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeValue<States[StateId]>, SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : AtomicSnapshot<Path, NodeValue<States[StateId]>>;
|
|
2109
2176
|
/**
|
|
2110
2177
|
* Extracts a complete root snapshot whose selected configuration contains a
|
|
2111
2178
|
* particular active state.
|
|
@@ -2190,7 +2257,7 @@ export declare namespace Machine {
|
|
|
2190
2257
|
readonly path: StateId;
|
|
2191
2258
|
readonly value: StateByIdentifier<States, StateId>;
|
|
2192
2259
|
readonly values?: Partial<{
|
|
2193
|
-
readonly [AncestorStateId in
|
|
2260
|
+
readonly [AncestorStateId in ValuedStateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>;
|
|
2194
2261
|
}>;
|
|
2195
2262
|
}
|
|
2196
2263
|
/**
|
|
@@ -2349,7 +2416,7 @@ export declare namespace Machine {
|
|
|
2349
2416
|
readonly event: LifecycleEvent<Events>;
|
|
2350
2417
|
}
|
|
2351
2418
|
/**
|
|
2352
|
-
* Context passed to
|
|
2419
|
+
* Context passed to a function-valued invocation source.
|
|
2353
2420
|
*
|
|
2354
2421
|
* @category models
|
|
2355
2422
|
* @since 0.4.0
|
|
@@ -2361,27 +2428,46 @@ export declare namespace Machine {
|
|
|
2361
2428
|
readonly event: LifecycleEvent<Events>;
|
|
2362
2429
|
}
|
|
2363
2430
|
/**
|
|
2364
|
-
* Context passed to an
|
|
2431
|
+
* Context passed to an invocation's active-snapshot transition.
|
|
2365
2432
|
*
|
|
2366
2433
|
* @category models
|
|
2367
2434
|
* @since 0.4.0
|
|
2368
2435
|
*/
|
|
2369
|
-
interface InvokeSnapshotContext<State, Error, Output> {
|
|
2436
|
+
interface InvokeSnapshotContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, State, Error, Output> {
|
|
2370
2437
|
readonly id: string;
|
|
2438
|
+
readonly state: StateByIdentifier<States, StateId>;
|
|
2439
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
2440
|
+
readonly parents: ParentStateValues<States, StateId>;
|
|
2441
|
+
readonly target: TargetBuilder<States, StateId>;
|
|
2371
2442
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
2372
2443
|
readonly status: "active";
|
|
2373
2444
|
}>;
|
|
2374
2445
|
}
|
|
2375
2446
|
/**
|
|
2376
|
-
* Context passed to an
|
|
2447
|
+
* Context passed to an invocation's successful completion transition.
|
|
2377
2448
|
*
|
|
2378
2449
|
* @category models
|
|
2379
2450
|
* @since 0.4.0
|
|
2380
2451
|
*/
|
|
2381
|
-
interface InvokeDoneContext<Output> {
|
|
2452
|
+
interface InvokeDoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Output> {
|
|
2382
2453
|
readonly id: string;
|
|
2454
|
+
readonly state: StateByIdentifier<States, StateId>;
|
|
2455
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
2456
|
+
readonly parents: ParentStateValues<States, StateId>;
|
|
2457
|
+
readonly snapshot: Snapshot<States>;
|
|
2458
|
+
readonly target: TargetBuilder<States, StateId>;
|
|
2383
2459
|
readonly output: Output;
|
|
2384
2460
|
}
|
|
2461
|
+
/** Context passed to an invocation typed-failure transition. */
|
|
2462
|
+
interface InvokeFailureContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Error> {
|
|
2463
|
+
readonly id: string;
|
|
2464
|
+
readonly state: StateByIdentifier<States, StateId>;
|
|
2465
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
2466
|
+
readonly parents: ParentStateValues<States, StateId>;
|
|
2467
|
+
readonly snapshot: Snapshot<States>;
|
|
2468
|
+
readonly target: TargetBuilder<States, StateId>;
|
|
2469
|
+
readonly error: Error;
|
|
2470
|
+
}
|
|
2385
2471
|
/**
|
|
2386
2472
|
* Context passed to an eventless transition handler.
|
|
2387
2473
|
*
|
|
@@ -2431,7 +2517,7 @@ export declare namespace Machine {
|
|
|
2431
2517
|
interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
|
|
2432
2518
|
readonly parent: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
2433
2519
|
readonly parents: {
|
|
2434
|
-
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>,
|
|
2520
|
+
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
2435
2521
|
};
|
|
2436
2522
|
readonly event: LifecycleEvent<Events>;
|
|
2437
2523
|
readonly target: TargetBuilder<States, ChoiceId>;
|
|
@@ -2594,9 +2680,17 @@ export declare namespace Machine {
|
|
|
2594
2680
|
* @category utility types
|
|
2595
2681
|
* @since 0.4.0
|
|
2596
2682
|
*/
|
|
2683
|
+
type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
2684
|
+
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>, Event<M>, Emit<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
2597
2685
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
2598
|
-
readonly
|
|
2599
|
-
} ? Logic : never
|
|
2686
|
+
readonly effect: infer Source;
|
|
2687
|
+
} ? InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<void, never, Effect.Error<Fx>, Effect.Services<Fx>, Effect.Success<Fx>> : never : Invoke extends {
|
|
2688
|
+
readonly after: unknown;
|
|
2689
|
+
} ? Logic<void, never, never, never, void> : Invoke extends {
|
|
2690
|
+
readonly logic: infer Source;
|
|
2691
|
+
} ? InvokeResolvedSource<Source> : Invoke extends {
|
|
2692
|
+
readonly child: infer Child;
|
|
2693
|
+
} ? ChildMachineLogic<Child> : never;
|
|
2600
2694
|
/**
|
|
2601
2695
|
* Extracts the startup error from an invoke source child process logic.
|
|
2602
2696
|
*
|
|
@@ -2649,34 +2743,33 @@ export declare namespace Machine {
|
|
|
2649
2743
|
*/
|
|
2650
2744
|
type InvokeEmits<Invoke> = Invoke extends {
|
|
2651
2745
|
readonly [InvokeTypeId]: {
|
|
2652
|
-
readonly emits: Types.Covariant<infer
|
|
2746
|
+
readonly emits: Types.Covariant<infer Emitted>;
|
|
2653
2747
|
};
|
|
2654
|
-
} ?
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
} ? Event : never;
|
|
2748
|
+
} ? Emitted : Invoke extends {
|
|
2749
|
+
readonly child: ChildMachine<string, infer M>;
|
|
2750
|
+
} ? Emit<M> : never;
|
|
2751
|
+
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
2752
|
+
type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ? (Invoke extends {
|
|
2753
|
+
readonly onDone?: infer Handler;
|
|
2754
|
+
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
2755
|
+
readonly onFailure?: infer Handler;
|
|
2756
|
+
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
2757
|
+
readonly onSnapshot?: infer Handler;
|
|
2758
|
+
} ? EventTransitionReturn<NonNullable<Handler>> : never) : never;
|
|
2666
2759
|
/**
|
|
2667
2760
|
* Extracts the parent transition error contribution from invoked children.
|
|
2668
2761
|
*
|
|
2669
2762
|
* @category utility types
|
|
2670
2763
|
* @since 0.4.0
|
|
2671
2764
|
*/
|
|
2672
|
-
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> |
|
|
2765
|
+
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> | Effect.Error<InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
2673
2766
|
/**
|
|
2674
2767
|
* Extracts the parent service requirement contribution from invoked children.
|
|
2675
2768
|
*
|
|
2676
2769
|
* @category utility types
|
|
2677
2770
|
* @since 0.4.0
|
|
2678
2771
|
*/
|
|
2679
|
-
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config
|
|
2772
|
+
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config>> | Effect.Services<InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
2680
2773
|
/**
|
|
2681
2774
|
* Extracts the return value from an eventless transition.
|
|
2682
2775
|
*
|
|
@@ -2711,63 +2804,171 @@ export declare namespace Machine {
|
|
|
2711
2804
|
* @since 0.4.0
|
|
2712
2805
|
*/
|
|
2713
2806
|
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<StateInitialReturn<Config>> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
interface
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
readonly emits: Types.Covariant<ChildEmits>;
|
|
2724
|
-
readonly snapshotEvent: Types.Covariant<Event>;
|
|
2725
|
-
readonly error: Types.Covariant<ChildError>;
|
|
2726
|
-
readonly requirements: Types.Covariant<ChildRequirements>;
|
|
2727
|
-
readonly initialError: Types.Covariant<ChildInitialError>;
|
|
2728
|
-
};
|
|
2729
|
-
/** @internal Serializable descriptor metadata used by inspection. */
|
|
2730
|
-
readonly [Activities.ActivityMetadataTypeId]?: Activities.StaticActivityMetadata;
|
|
2731
|
-
readonly id: string;
|
|
2732
|
-
/**
|
|
2733
|
-
* Optional parent-local address for sending events to this invocation.
|
|
2734
|
-
*
|
|
2735
|
-
* The invocation `id` is only its state-local lifecycle key. Use an
|
|
2736
|
-
* explicit typed address when the parent must communicate with it.
|
|
2737
|
-
*/
|
|
2738
|
-
readonly address?: string;
|
|
2739
|
-
/** @internal */
|
|
2740
|
-
readonly descriptor?: ChildMachine.Any;
|
|
2741
|
-
src(): Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>;
|
|
2742
|
-
snapshot?(context: InvokeSnapshotContext<ChildState, ChildError, ChildOutput>): Event | undefined;
|
|
2743
|
-
onDone?(context: InvokeDoneContext<ChildOutput>): DeliveredOutput | undefined;
|
|
2807
|
+
type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context> = ((context: Context, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2808
|
+
readonly reenter?: boolean;
|
|
2809
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2810
|
+
readonly transition: (context: Context, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2811
|
+
};
|
|
2812
|
+
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
2813
|
+
interface AnyLogicSource {
|
|
2814
|
+
initial(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>;
|
|
2815
|
+
run(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>;
|
|
2744
2816
|
}
|
|
2745
|
-
/**
|
|
2746
|
-
interface
|
|
2817
|
+
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
2818
|
+
interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2819
|
+
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId]>;
|
|
2820
|
+
}
|
|
2821
|
+
/** Type evidence retained by {@link invoke} without affecting runtime data. */
|
|
2822
|
+
interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never> {
|
|
2747
2823
|
readonly [InvokeTypeId]: {
|
|
2748
2824
|
readonly output: Types.Covariant<Output>;
|
|
2749
|
-
readonly emits: Types.Covariant<Emits>;
|
|
2750
|
-
readonly snapshotEvent: Types.Covariant<SnapshotEvent>;
|
|
2751
2825
|
readonly error: Types.Covariant<Error>;
|
|
2752
2826
|
readonly requirements: Types.Covariant<Requirements>;
|
|
2753
2827
|
readonly initialError: Types.Covariant<InitialError>;
|
|
2828
|
+
readonly emits: Types.Covariant<Emits>;
|
|
2754
2829
|
};
|
|
2755
2830
|
}
|
|
2756
|
-
|
|
2757
|
-
readonly
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2831
|
+
type InvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = InvokeOwned<States, Events, Emits, StateId> & ({
|
|
2832
|
+
readonly id: string;
|
|
2833
|
+
readonly effect: InvokeSource<Effect.Effect<any, any, any>, InvokeContext<States, Events, Emits, StateId>>;
|
|
2834
|
+
readonly after?: never;
|
|
2835
|
+
readonly logic?: never;
|
|
2836
|
+
readonly child?: never;
|
|
2837
|
+
readonly address?: never;
|
|
2838
|
+
readonly onDone?: unknown;
|
|
2839
|
+
readonly onFailure?: unknown;
|
|
2840
|
+
readonly onSnapshot?: never;
|
|
2841
|
+
} | {
|
|
2842
|
+
readonly id: string;
|
|
2843
|
+
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>;
|
|
2844
|
+
readonly effect?: never;
|
|
2845
|
+
readonly logic?: never;
|
|
2846
|
+
readonly child?: never;
|
|
2847
|
+
readonly address?: never;
|
|
2848
|
+
readonly onDone: unknown;
|
|
2849
|
+
readonly onFailure?: never;
|
|
2850
|
+
readonly onSnapshot?: never;
|
|
2851
|
+
} | {
|
|
2852
|
+
readonly id: string;
|
|
2853
|
+
readonly address: string;
|
|
2854
|
+
readonly logic: InvokeSource<AnyLogicSource, InvokeContext<States, Events, Emits, StateId>>;
|
|
2855
|
+
readonly effect?: never;
|
|
2856
|
+
readonly after?: never;
|
|
2857
|
+
readonly child?: never;
|
|
2858
|
+
readonly onDone?: unknown;
|
|
2859
|
+
readonly onFailure?: unknown;
|
|
2860
|
+
readonly onSnapshot?: unknown;
|
|
2861
|
+
} | {
|
|
2862
|
+
readonly child: ChildMachine.Any;
|
|
2863
|
+
readonly input?: {} | null | ((context: InvokeContext<States, Events, Emits, StateId>) => unknown);
|
|
2864
|
+
readonly id?: never;
|
|
2865
|
+
readonly address?: never;
|
|
2866
|
+
readonly effect?: never;
|
|
2867
|
+
readonly after?: never;
|
|
2868
|
+
readonly logic?: never;
|
|
2869
|
+
readonly onDone?: unknown;
|
|
2870
|
+
readonly onFailure?: unknown;
|
|
2871
|
+
readonly onSnapshot?: unknown;
|
|
2872
|
+
});
|
|
2873
|
+
/** State-bound inline invocation configuration. */
|
|
2874
|
+
type InvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = InvokeConfig<States, Events, Emits, StateId> | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId>>;
|
|
2875
|
+
type InvokeHandlerRequirement<Value, Handler> = IsAny<Value> extends true ? {
|
|
2876
|
+
readonly handler: Handler;
|
|
2877
|
+
} : [Value] extends [never] ? {
|
|
2878
|
+
readonly handler?: never;
|
|
2879
|
+
} : {
|
|
2880
|
+
readonly handler: Handler;
|
|
2881
|
+
};
|
|
2882
|
+
type InvokeDoneRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
2883
|
+
readonly handler: infer Required;
|
|
2884
|
+
} ? {
|
|
2885
|
+
readonly onDone: Required;
|
|
2886
|
+
} : {
|
|
2887
|
+
readonly onDone?: never;
|
|
2888
|
+
} : never;
|
|
2889
|
+
type InvokeFailureRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
2890
|
+
readonly handler: infer Required;
|
|
2891
|
+
} ? {
|
|
2892
|
+
readonly onFailure: Required;
|
|
2893
|
+
} : {
|
|
2894
|
+
readonly onFailure?: never;
|
|
2895
|
+
} : never;
|
|
2896
|
+
type EffectInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Fx extends Effect.Effect<any, any, any>, Source = Fx> = {
|
|
2897
|
+
readonly id: InvokeLifecycleId;
|
|
2898
|
+
readonly effect: Source;
|
|
2899
|
+
readonly after?: never;
|
|
2900
|
+
readonly logic?: never;
|
|
2901
|
+
readonly child?: never;
|
|
2902
|
+
readonly address?: never;
|
|
2903
|
+
readonly onSnapshot?: never;
|
|
2904
|
+
} & InvokeDoneRequirement<Effect.Success<NoInfer<Fx>>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<NoInfer<Fx>>>>> & InvokeFailureRequirement<Effect.Error<NoInfer<Fx>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<NoInfer<Fx>>>>>;
|
|
2905
|
+
type TimerInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = {
|
|
2906
|
+
readonly id: InvokeLifecycleId;
|
|
2907
|
+
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>;
|
|
2908
|
+
readonly effect?: never;
|
|
2909
|
+
readonly logic?: never;
|
|
2910
|
+
readonly child?: never;
|
|
2911
|
+
readonly address?: never;
|
|
2912
|
+
readonly onFailure?: never;
|
|
2913
|
+
readonly onSnapshot?: never;
|
|
2914
|
+
readonly onDone: InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, void>>;
|
|
2915
|
+
};
|
|
2916
|
+
type LogicInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>> = {
|
|
2917
|
+
readonly id: InvokeLifecycleId;
|
|
2918
|
+
readonly address: Address & ChildAddress.Compatibility<Address, ChildEvent>;
|
|
2919
|
+
readonly logic: Source;
|
|
2920
|
+
readonly effect?: never;
|
|
2921
|
+
readonly after?: never;
|
|
2922
|
+
readonly child?: never;
|
|
2923
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, ChildState, ChildError, ChildOutput>>;
|
|
2924
|
+
} & InvokeDoneRequirement<ChildOutput, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, ChildOutput>>> & InvokeFailureRequirement<ChildError, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, ChildError>>>;
|
|
2925
|
+
type ChildInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildDefinition extends Machine.Any, Child extends ChildMachine<string, ChildDefinition>> = {
|
|
2926
|
+
readonly child: Child & (ChildDefinition extends EnsureExecutable<Machine.States<ChildDefinition>, Machine.UnhandledStates<ChildDefinition>, Machine.OutputStates<ChildDefinition>> ? unknown : never);
|
|
2927
|
+
readonly id?: never;
|
|
2928
|
+
readonly address?: never;
|
|
2929
|
+
readonly effect?: never;
|
|
2930
|
+
readonly after?: never;
|
|
2931
|
+
readonly logic?: never;
|
|
2932
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>>>;
|
|
2933
|
+
} & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
2934
|
+
readonly input?: never;
|
|
2935
|
+
} : {
|
|
2936
|
+
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>;
|
|
2937
|
+
}) & InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>>>>;
|
|
2938
|
+
type LogicStateOf<Value> = Value extends Logic<infer State, any, any, any, any, any> ? State : never;
|
|
2939
|
+
type LogicEventOf<Value> = Value extends Logic<any, infer Event, any, any, any, any> ? Event : never;
|
|
2940
|
+
type LogicErrorOf<Value> = Value extends Logic<any, any, infer Error, any, any, any> ? Error : never;
|
|
2941
|
+
type LogicServicesOf<Value> = Value extends Logic<any, any, any, infer Services, any, any> ? Services : never;
|
|
2942
|
+
type LogicOutputOf<Value> = Value extends Logic<any, any, any, any, infer Output, any> ? Output : never;
|
|
2943
|
+
type LogicInitialErrorOf<Value> = Value extends Logic<any, any, any, any, any, infer Error> ? Error : never;
|
|
2944
|
+
type ContextualInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Raw> = Raw extends InvokeTyped<any, any, any, any, any> ? unknown : Raw extends {
|
|
2945
|
+
readonly effect: infer Source;
|
|
2946
|
+
} ? InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ? InvokeDoneRequirement<Effect.Success<Fx>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>>>> & InvokeFailureRequirement<Effect.Error<Fx>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>>>> & {
|
|
2947
|
+
readonly onSnapshot?: never;
|
|
2948
|
+
} : never : Raw extends {
|
|
2949
|
+
readonly after: unknown;
|
|
2950
|
+
} ? {
|
|
2951
|
+
readonly onDone: InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, void>>;
|
|
2952
|
+
readonly onFailure?: never;
|
|
2953
|
+
readonly onSnapshot?: never;
|
|
2954
|
+
} : Raw extends {
|
|
2955
|
+
readonly logic: infer Source;
|
|
2956
|
+
readonly address: infer Address;
|
|
2957
|
+
} ? InvokeResolvedSource<Source> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<InvokeOutput<Raw>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>>>> & InvokeFailureRequirement<InvokeRuntimeError<Raw>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, InvokeRuntimeError<Raw>>>> & {
|
|
2958
|
+
readonly address: ChildAddress<never> & ChildAddress.Compatibility<Address, ChildLogic extends Logic<any, infer ChildEvent, any, any, any, any> ? ChildEvent : never>;
|
|
2959
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never, InvokeRuntimeError<Raw>, InvokeOutput<Raw>>>;
|
|
2960
|
+
} : never : Raw extends {
|
|
2961
|
+
readonly child: infer Child extends ChildMachine<string, infer ChildDefinition>;
|
|
2962
|
+
} ? ChildMachineLogic<Child> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>>>> & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
2963
|
+
readonly input?: never;
|
|
2964
|
+
} : {
|
|
2965
|
+
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>;
|
|
2966
|
+
}) & {
|
|
2967
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>>>;
|
|
2968
|
+
} : never : never;
|
|
2969
|
+
type ContextualInvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Raw> = Raw extends ReadonlyArray<any> ? {
|
|
2970
|
+
readonly [Index in keyof Raw]: ContextualInvokeConfig<States, Events, Emits, StateId, Raw[Index]>;
|
|
2971
|
+
} : ContextualInvokeConfig<States, Events, Emits, StateId, Raw>;
|
|
2771
2972
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
2772
2973
|
readonly output: Schema.Top;
|
|
2773
2974
|
} ? {
|
|
@@ -2819,11 +3020,11 @@ export declare namespace Machine {
|
|
|
2819
3020
|
readonly type: "parallel";
|
|
2820
3021
|
readonly states: infer Children extends StateSchemas;
|
|
2821
3022
|
} ? {
|
|
2822
|
-
readonly [Key in ActiveStateKey<Children>
|
|
3023
|
+
readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<Children[Key]>;
|
|
2823
3024
|
} : Node extends {
|
|
2824
3025
|
readonly states: infer Children extends StateSchemas;
|
|
2825
3026
|
readonly initial: infer Initial;
|
|
2826
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]>[
|
|
3027
|
+
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeValue<Children[Initial]> : never : never : never;
|
|
2827
3028
|
/** Context passed to an implicit child-state initializer. */
|
|
2828
3029
|
type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = StateActionContext<States, Events, Emits, StateId>;
|
|
2829
3030
|
/** Initial child value implementation for a compound or parallel state. */
|
|
@@ -2901,6 +3102,12 @@ export declare namespace Machine {
|
|
|
2901
3102
|
readonly states: infer Children extends StateSchemas;
|
|
2902
3103
|
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
2903
3104
|
type HandlerConfigAtPath<Config, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest> : never : Path extends keyof Config ? Config[Path] : never;
|
|
3105
|
+
type HandlerInvokeContextAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = StateId extends StateIdentifier<AllStates> ? NodeConfig extends {
|
|
3106
|
+
readonly invoke: infer Invoke;
|
|
3107
|
+
} ? HandlerValidationAtPath<StateId, {
|
|
3108
|
+
readonly invoke: ContextualInvokeDefinition<AllStates, Events, Emits, StateId, Invoke>;
|
|
3109
|
+
}> : unknown : unknown;
|
|
3110
|
+
type HandlerInvokeContexts<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerInvokeContextAtPath<AllStates, Events, Emits, Config, StateId> : never : never>;
|
|
2904
3111
|
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
2905
3112
|
readonly [Key in Head]?: {
|
|
2906
3113
|
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
@@ -3003,7 +3210,7 @@ export declare namespace Machine {
|
|
|
3003
3210
|
] extends [never] ? unknown : {
|
|
3004
3211
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
3005
3212
|
} : unknown : unknown);
|
|
3006
|
-
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerChoiceTargetValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerOnTargetValidation<StateId, Config> & HandlerDirectTargetValidation<StateId, Config, "always"> & HandlerDirectTargetValidation<StateId, Config, "onDone"> &
|
|
3213
|
+
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerChoiceTargetValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerOnTargetValidation<StateId, Config> & HandlerDirectTargetValidation<StateId, Config, "always"> & HandlerDirectTargetValidation<StateId, Config, "onDone"> & HandlerInvokeEmitsValidation<Events, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
|
|
3007
3214
|
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
3008
3215
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
3009
3216
|
};
|
|
@@ -3012,15 +3219,9 @@ export declare namespace Machine {
|
|
|
3012
3219
|
} ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
|
|
3013
3220
|
readonly choice: HandlerValidationError<"Choice resolver returns a target not listed in targets", StateId, UndeclaredTransitionTarget<Choice>>;
|
|
3014
3221
|
} : unknown;
|
|
3015
|
-
type HandlerInvokeOutputValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>] extends [never] ? unknown : {
|
|
3016
|
-
readonly invoke: HandlerValidationError<"Invoked child output must be a machine event or void", StateId, Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>>;
|
|
3017
|
-
};
|
|
3018
3222
|
type HandlerInvokeEmitsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
3019
3223
|
readonly invoke: HandlerValidationError<"Invoked child emits events not accepted by the parent machine", StateId, Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
3020
3224
|
};
|
|
3021
|
-
type HandlerInvokeSnapshotValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : IsAny<InvokeSnapshotEvent<InvokeReturn<Config>>> extends true ? unknown : [Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>] extends [never] ? unknown : {
|
|
3022
|
-
readonly invoke: HandlerValidationError<"Invoked child snapshot mapper must return a machine event or undefined", StateId, Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>>;
|
|
3023
|
-
};
|
|
3024
3225
|
type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmitOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
|
|
3025
3226
|
type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : HandlerValidationAtPath<StateId, Validation> : never;
|
|
3026
3227
|
type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<AllStates, Events, Emits, Config, AvailableOutputStates, StateId> : never : never>;
|
|
@@ -3057,7 +3258,7 @@ export declare namespace Machine {
|
|
|
3057
3258
|
* @since 0.4.0
|
|
3058
3259
|
*/
|
|
3059
3260
|
interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>> {
|
|
3060
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States, Events, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, Config>;
|
|
3261
|
+
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerInvokeContexts<States, Events, Emits, NoInfer<Config>> & HandlerTreeValidation<States, Events, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, Config>;
|
|
3061
3262
|
}
|
|
3062
3263
|
/**
|
|
3063
3264
|
* Any state config.
|
|
@@ -3133,7 +3334,9 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3133
3334
|
*
|
|
3134
3335
|
* The returned `states` property is the same object passed to `defineStates`.
|
|
3135
3336
|
* The returned `initial` builder creates snapshots without user-authored path
|
|
3136
|
-
* strings and enforces compound and parallel initial-state rules.
|
|
3337
|
+
* strings and enforces compound and parallel initial-state rules. Active nodes
|
|
3338
|
+
* may omit `schema` when they own no value; those builders expose `.from(...)`
|
|
3339
|
+
* and still participate fully in targeting, matching, and snapshots.
|
|
3137
3340
|
*
|
|
3138
3341
|
* **Example** (Atomic initial snapshot)
|
|
3139
3342
|
*
|
|
@@ -3184,8 +3387,8 @@ interface Make {
|
|
|
3184
3387
|
* to implement state behavior with ordinary TypeScript control flow.
|
|
3185
3388
|
*
|
|
3186
3389
|
* Schemas in `events` define the public input protocol. Schemas in
|
|
3187
|
-
* `internalEvents` are added to the complete handler protocol for
|
|
3188
|
-
*
|
|
3390
|
+
* `internalEvents` are added to the complete handler protocol for raised
|
|
3391
|
+
* events, child emissions, and other machine-local deliveries. Their tags
|
|
3189
3392
|
* must be disjoint.
|
|
3190
3393
|
*
|
|
3191
3394
|
* **Example** (Typed counter machine)
|
|
@@ -3237,6 +3440,9 @@ type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends
|
|
|
3237
3440
|
* Events supplied through ordinary `send` and `plan` calls remain untrusted
|
|
3238
3441
|
* and continue through full runtime schema validation.
|
|
3239
3442
|
* Treat the returned event as immutable after construction.
|
|
3443
|
+
* This eager low-level constructor throws `MachineSchemaDecodeError` when
|
|
3444
|
+
* construction fails. Prefer {@link events} and {@link internalEvents} for
|
|
3445
|
+
* ordinary delivery so construction remains inside the machine error channel.
|
|
3240
3446
|
*
|
|
3241
3447
|
* The schema must be one of the machine's configured public or internal event
|
|
3242
3448
|
* schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
|
|
@@ -3266,6 +3472,37 @@ type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends
|
|
|
3266
3472
|
* @since 0.4.0
|
|
3267
3473
|
*/
|
|
3268
3474
|
export declare const event: <const M extends Machine.Any, const EventSchema extends Machine.TaggedSchema>(machine: M, schema: EventSchema & ([EventSchema["Type"]] extends [Machine.Event<M>] ? unknown : never), ...args: EventConstructorArgs<EventSchema>) => EventSchema["Type"];
|
|
3475
|
+
/**
|
|
3476
|
+
* Returns deferred constructors for every public event in a machine protocol.
|
|
3477
|
+
*
|
|
3478
|
+
* Constructor inputs retain their schema-derived required fields, defaults,
|
|
3479
|
+
* and transformations. Construction is deferred until delivery so failures
|
|
3480
|
+
* enter the machine's `MachineSchemaDecodeError` channel rather than throwing
|
|
3481
|
+
* at the call site.
|
|
3482
|
+
*
|
|
3483
|
+
* **Example**
|
|
3484
|
+
*
|
|
3485
|
+
* ```ts
|
|
3486
|
+
* const Event = Machine.events(counter)
|
|
3487
|
+
* yield* ref.send(Event.Increment({ by: 1 }))
|
|
3488
|
+
* ```
|
|
3489
|
+
*
|
|
3490
|
+
* @category constructors
|
|
3491
|
+
* @since 0.9.0
|
|
3492
|
+
*/
|
|
3493
|
+
export declare const events: <const M extends Machine.Any>(machine: M) => Machine.EventConstructors<Machine.InputEvents<M>>;
|
|
3494
|
+
/**
|
|
3495
|
+
* Returns deferred constructors for every internal event in a machine
|
|
3496
|
+
* protocol.
|
|
3497
|
+
*
|
|
3498
|
+
* Use these constructors for raised events and other machine-local deliveries.
|
|
3499
|
+
* Construction failures are reported through the
|
|
3500
|
+
* owning machine's `MachineSchemaDecodeError` channel.
|
|
3501
|
+
*
|
|
3502
|
+
* @category constructors
|
|
3503
|
+
* @since 0.9.0
|
|
3504
|
+
*/
|
|
3505
|
+
export declare const internalEvents: <const M extends Machine.Any>(machine: M) => Machine.EventConstructors<Machine.InternalEvents<M>>;
|
|
3269
3506
|
/**
|
|
3270
3507
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
3271
3508
|
*
|
|
@@ -3359,131 +3596,81 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
3359
3596
|
* @since 0.4.0
|
|
3360
3597
|
*/
|
|
3361
3598
|
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
3362
|
-
|
|
3363
|
-
* Creates an invoked child process configuration for an active state.
|
|
3364
|
-
*
|
|
3365
|
-
* **When to use**
|
|
3366
|
-
*
|
|
3367
|
-
* Use to run a child process while a machine remains in a state. Successful
|
|
3368
|
-
* outputs are sent directly to the parent machine as events; `void` sends
|
|
3369
|
-
* nothing. Unrecovered child failures fail the owning machine. Active
|
|
3370
|
-
* snapshots can optionally be mapped to progress events.
|
|
3371
|
-
*
|
|
3372
|
-
* **Gotchas**
|
|
3373
|
-
*
|
|
3374
|
-
* Invoked child processes run while their owning state is active and are
|
|
3375
|
-
* stopped before the state exits. An unrecovered child failure fails the owning
|
|
3376
|
-
* machine; recover inside the child Effect when failure should become an event.
|
|
3377
|
-
* The `id` is a state-local lifecycle key, not a communication address. To
|
|
3378
|
-
* send events to the invocation, pass a typed `childAddress` as `address`.
|
|
3379
|
-
* The `src` callback is intentionally independent from its parent state. When
|
|
3380
|
-
* construction depends on the typed state, lifecycle event, or runtime, use
|
|
3381
|
-
* the state config factory form `invoke: (context) => Machine.invoke(...)` and
|
|
3382
|
-
* close over that context from `src`.
|
|
3383
|
-
*
|
|
3384
|
-
* **Example** (Effect output as a parent event)
|
|
3385
|
-
*
|
|
3386
|
-
* ```ts
|
|
3387
|
-
* import { Effect, Schema } from "effect"
|
|
3388
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3389
|
-
*
|
|
3390
|
-
* class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
|
|
3391
|
-
* value: Schema.String
|
|
3392
|
-
* }) {}
|
|
3393
|
-
*
|
|
3394
|
-
* const load = Machine.invoke({
|
|
3395
|
-
* id: "load",
|
|
3396
|
-
* src: () => Machine.effect(Effect.succeed(new Loaded({ value: "ready" })))
|
|
3397
|
-
* })
|
|
3398
|
-
* ```
|
|
3399
|
-
*
|
|
3400
|
-
* @see {@link effect} for one-shot child effects.
|
|
3401
|
-
* @see {@link spawn} for children whose lifetime is controlled by actions.
|
|
3402
|
-
* @category constructors
|
|
3403
|
-
* @since 0.4.0
|
|
3404
|
-
*/
|
|
3405
|
-
export declare const invoke: <ChildState, ChildEvent, ChildError = never, ChildRequirements = never, ChildOutput = never, ChildInitialError = never, Event = never, Address extends ChildAddress<never> | undefined = undefined>(config: {
|
|
3599
|
+
type DynamicEffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<unknown, unknown, unknown>> = {
|
|
3406
3600
|
readonly id: InvokeLifecycleId;
|
|
3407
|
-
readonly
|
|
3408
|
-
readonly
|
|
3409
|
-
|
|
3601
|
+
readonly effect: Source;
|
|
3602
|
+
readonly after?: never;
|
|
3603
|
+
readonly logic?: never;
|
|
3604
|
+
readonly child?: never;
|
|
3410
3605
|
readonly address?: never;
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
type
|
|
3415
|
-
type
|
|
3416
|
-
type
|
|
3417
|
-
readonly id: InvokeLifecycleId;
|
|
3418
|
-
readonly effect: Fx;
|
|
3419
|
-
readonly onSuccess: (value: NoInfer<Effect.Success<Fx>>) => SuccessEvent | void;
|
|
3420
|
-
} & (InvokeEffectIsInfallible<Fx> extends true ? {
|
|
3421
|
-
readonly onFailure?: never;
|
|
3422
|
-
} : {
|
|
3423
|
-
readonly onFailure: (error: NoInfer<Effect.Error<Fx>>) => FailureEvent | void;
|
|
3424
|
-
});
|
|
3606
|
+
readonly onSnapshot?: never;
|
|
3607
|
+
};
|
|
3608
|
+
type DynamicEffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>>>;
|
|
3609
|
+
type DynamicEffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>>>;
|
|
3610
|
+
type DynamicEffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeConfig<States, Events, Emits, StateId> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
|
|
3611
|
+
type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false;
|
|
3425
3612
|
/**
|
|
3426
|
-
*
|
|
3613
|
+
* Preserves inference for a state-owned invocation configuration.
|
|
3427
3614
|
*
|
|
3428
|
-
*
|
|
3429
|
-
*
|
|
3430
|
-
*
|
|
3431
|
-
*
|
|
3432
|
-
* an Effect into a common event union by hand. Defects and interruption remain
|
|
3433
|
-
* failures of the owning machine.
|
|
3615
|
+
* Use `effect` for one-shot work, `after` for a cancellable timer, `logic` for
|
|
3616
|
+
* reusable process logic, or `child` for a complete child machine. `onDone` is
|
|
3617
|
+
* required whenever the source can complete with an output, while `onFailure`
|
|
3618
|
+
* is required only when the source has a typed failure channel.
|
|
3434
3619
|
*
|
|
3435
|
-
*
|
|
3436
|
-
*
|
|
3437
|
-
*
|
|
3438
|
-
*
|
|
3620
|
+
* This constructor is an identity at runtime, but preserves lifecycle callback
|
|
3621
|
+
* inference through published declarations. Effects and durations may be
|
|
3622
|
+
* supplied directly or derived from the owning state's entry context. Dynamic
|
|
3623
|
+
* Effect sources infer the owner context, output, error, and service channels
|
|
3624
|
+
* together without a return annotation. Logic invocations require both a
|
|
3625
|
+
* lifecycle `id` and a typed communication `address`. Child descriptors already
|
|
3626
|
+
* own their identity, so `id` and `address` must not be repeated.
|
|
3439
3627
|
*
|
|
3440
3628
|
* ```ts
|
|
3441
|
-
*
|
|
3442
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3443
|
-
*
|
|
3444
|
-
* class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
|
|
3445
|
-
* value: Schema.String
|
|
3446
|
-
* }) {}
|
|
3447
|
-
*
|
|
3448
|
-
* const load = Machine.invokeEffect({
|
|
3629
|
+
* invoke: Machine.invoke({
|
|
3449
3630
|
* id: "load",
|
|
3450
|
-
* effect: Effect.
|
|
3451
|
-
*
|
|
3631
|
+
* effect: Effect.tryPromise({
|
|
3632
|
+
* try: () => fetch("/api/data").then((response) => response.json()),
|
|
3633
|
+
* catch: (cause) => new LoadError({ cause })
|
|
3634
|
+
* }),
|
|
3635
|
+
* onDone: ({ output, target }) => target.full.Ready({ data: output }),
|
|
3636
|
+
* onFailure: ({ error, target }) => target.full.Failed({ error })
|
|
3452
3637
|
* })
|
|
3453
3638
|
* ```
|
|
3454
3639
|
*
|
|
3455
|
-
* @see {@link invoke} for arbitrary child process logic.
|
|
3456
|
-
* @see {@link after} for a state-scoped delayed event.
|
|
3457
|
-
* @category constructors
|
|
3458
|
-
* @since 0.4.0
|
|
3459
|
-
*/
|
|
3460
|
-
export declare const invokeEffect: <const Fx extends Effect.Effect<any, any, any>, SuccessEvent, FailureEvent = never>(config: InvokeEffectConfig<Fx, SuccessEvent, FailureEvent>) => InvokeEffectResult<Effect.Services<Fx>, SuccessEvent | (InvokeEffectIsInfallible<Fx> extends true ? never : FailureEvent)>;
|
|
3461
|
-
/**
|
|
3462
|
-
* Creates a cancellable state-scoped delayed event.
|
|
3463
|
-
*
|
|
3464
|
-
* The timer starts when its owning state is entered and is interrupted when
|
|
3465
|
-
* that state exits. The delayed value should normally be declared in
|
|
3466
|
-
* `internalEvents`.
|
|
3467
|
-
*
|
|
3468
|
-
* **Example**
|
|
3469
|
-
*
|
|
3470
|
-
* ```ts
|
|
3471
|
-
* import { Schema } from "effect"
|
|
3472
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3473
|
-
*
|
|
3474
|
-
* class TimedOut extends Schema.TaggedClass<TimedOut>("TimedOut")("TimedOut", {}) {}
|
|
3475
|
-
*
|
|
3476
|
-
* const timeout = Machine.after("5 seconds", new TimedOut({}))
|
|
3477
|
-
* ```
|
|
3478
|
-
*
|
|
3479
3640
|
* @category constructors
|
|
3480
|
-
* @since 0.
|
|
3641
|
+
* @since 0.9.0
|
|
3481
3642
|
*/
|
|
3482
|
-
export declare const
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
}
|
|
3643
|
+
export declare const invoke: {
|
|
3644
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<unknown, unknown, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3645
|
+
readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>;
|
|
3646
|
+
readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>;
|
|
3647
|
+
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3648
|
+
"onDone must be omitted when the Effect output is never"
|
|
3649
|
+
] : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3650
|
+
"onFailure must be omitted when the Effect error is never"
|
|
3651
|
+
] : []): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3652
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<unknown, never, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3653
|
+
readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>;
|
|
3654
|
+
readonly onFailure?: never;
|
|
3655
|
+
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3656
|
+
"onDone must be omitted when the Effect output is never"
|
|
3657
|
+
] : []): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3658
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<never, unknown, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3659
|
+
readonly onDone?: never;
|
|
3660
|
+
readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>;
|
|
3661
|
+
}, ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3662
|
+
"onFailure must be omitted when the Effect error is never"
|
|
3663
|
+
] : []): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3664
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<never, never, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3665
|
+
readonly onDone?: never;
|
|
3666
|
+
readonly onFailure?: never;
|
|
3667
|
+
}): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3668
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Fx extends Effect.Effect<any, any, any>, const Config extends object>(config: Config & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Effect.Success<Fx>, Effect.Error<Fx>, Effect.Services<Fx>, never>;
|
|
3669
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Config extends object>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>;
|
|
3670
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>>(config: Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>>): Machine.InvokeConfig<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
|
|
3671
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, const Config extends object>(config: Config & Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
|
|
3672
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Child extends ChildMachine.Any, const Config extends object>(config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Machine.Output<Child["machine"]>, Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>, Machine.Services<Child["machine"]>, Machine.InitialError<Child["machine"]>, Machine.Emit<Child["machine"]>>;
|
|
3673
|
+
};
|
|
3487
3674
|
type RetagFields<Target extends Machine.TaggedSchema> = Omit<Target["~type.make.in"], "_tag">;
|
|
3488
3675
|
type RetagTargetCompatibility<Target extends Machine.TaggedSchema> = Target extends {
|
|
3489
3676
|
readonly fields: Schema.Struct.Fields;
|
|
@@ -3518,48 +3705,6 @@ type RetagArgs<Target extends Machine.TaggedSchema, Source> = [
|
|
|
3518
3705
|
export declare const retag: <const Target extends Machine.TaggedSchema, const Source extends {
|
|
3519
3706
|
readonly _tag: PropertyKey;
|
|
3520
3707
|
}>(target: Target & RetagTargetCompatibility<Target>, source: Source, ...args: RetagArgs<Target, Source>) => Target["Type"];
|
|
3521
|
-
type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.Void ? {
|
|
3522
|
-
readonly input?: never;
|
|
3523
|
-
} : {
|
|
3524
|
-
readonly input: Input["Type"];
|
|
3525
|
-
};
|
|
3526
|
-
/**
|
|
3527
|
-
* Creates an invoked child process from a complete statechart machine.
|
|
3528
|
-
*
|
|
3529
|
-
* **When to use**
|
|
3530
|
-
*
|
|
3531
|
-
* Use when a state should own another statechart machine and communicate with
|
|
3532
|
-
* it through typed child events, emissions, snapshots, or terminal output.
|
|
3533
|
-
*
|
|
3534
|
-
* **Details**
|
|
3535
|
-
*
|
|
3536
|
-
* Child emissions are delivered directly to the parent as events. Active
|
|
3537
|
-
* snapshots and terminal output can be mapped to parent events. The owning
|
|
3538
|
-
* state controls the child lifetime.
|
|
3539
|
-
*
|
|
3540
|
-
* **Gotchas**
|
|
3541
|
-
*
|
|
3542
|
-
* Active invoked machines must have unique child addresses. A machine starts
|
|
3543
|
-
* after its owning state's entry actions, so those actions cannot send events
|
|
3544
|
-
* to a newly entered child. Unrecovered child failures fail the parent.
|
|
3545
|
-
*
|
|
3546
|
-
* @see {@link invoke} for invoking lower-level process logic.
|
|
3547
|
-
* @see {@link sendTo} for sending events to the invoked machine.
|
|
3548
|
-
* @category constructors
|
|
3549
|
-
* @since 0.4.0
|
|
3550
|
-
*/
|
|
3551
|
-
export declare const invokeMachine: {
|
|
3552
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, SnapshotEvent = never, DoneEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
|
|
3553
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
3554
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
3555
|
-
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined;
|
|
3556
|
-
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>, DoneEvent>;
|
|
3557
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, SnapshotEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
|
|
3558
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
3559
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
3560
|
-
readonly onDone?: never;
|
|
3561
|
-
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>>;
|
|
3562
|
-
};
|
|
3563
3708
|
/**
|
|
3564
3709
|
* Plans the initial state for a machine without executing actor commands.
|
|
3565
3710
|
*
|
|
@@ -3659,10 +3804,9 @@ export declare const transitionDefinitions: <M extends Machine.Any>(machine: M)
|
|
|
3659
3804
|
*
|
|
3660
3805
|
* **Details**
|
|
3661
3806
|
*
|
|
3662
|
-
* Static
|
|
3663
|
-
*
|
|
3664
|
-
*
|
|
3665
|
-
* never evaluated during inspection.
|
|
3807
|
+
* Static inline invocation definitions expose stable ownership and lifecycle
|
|
3808
|
+
* metadata without serializing runtime values. Function-valued sources are
|
|
3809
|
+
* represented as dynamic and are never evaluated during inspection.
|
|
3666
3810
|
*
|
|
3667
3811
|
* @category getters
|
|
3668
3812
|
* @since 0.4.0
|
|
@@ -3732,7 +3876,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
3732
3876
|
* @category combinators
|
|
3733
3877
|
* @since 0.4.0
|
|
3734
3878
|
*/
|
|
3735
|
-
export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, state: Machine.Snapshot<States>, event: Machine.
|
|
3879
|
+
export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<InputEvents>) => Effect.Effect<{
|
|
3736
3880
|
readonly next: Machine.Snapshot<States>;
|
|
3737
3881
|
readonly commands: ReadonlyArray<Command>;
|
|
3738
3882
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
@@ -3754,49 +3898,6 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
3754
3898
|
readonly done: false;
|
|
3755
3899
|
readonly output: undefined;
|
|
3756
3900
|
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
3757
|
-
/**
|
|
3758
|
-
* Creates a one-shot child process from an Effect.
|
|
3759
|
-
*
|
|
3760
|
-
* **When to use**
|
|
3761
|
-
*
|
|
3762
|
-
* Use when you need side effects that produce one typed output or error.
|
|
3763
|
-
*
|
|
3764
|
-
* **Details**
|
|
3765
|
-
*
|
|
3766
|
-
* The Effect may run arbitrary side effects. Its success value is the process
|
|
3767
|
-
* output, its typed error is preserved, and its services are inferred. When
|
|
3768
|
-
* invoked, the output is sent to the owning machine as an event unless it is
|
|
3769
|
-
* `void`.
|
|
3770
|
-
*
|
|
3771
|
-
* **Gotchas**
|
|
3772
|
-
*
|
|
3773
|
-
* This process has no incoming event protocol. Its Effect runs once. Use
|
|
3774
|
-
* `transition` for a process that receives events over time and `logic` for
|
|
3775
|
-
* direct machine-local communication or intermediate snapshots.
|
|
3776
|
-
*
|
|
3777
|
-
* **Example** (Recover a child failure as output)
|
|
3778
|
-
*
|
|
3779
|
-
* ```ts
|
|
3780
|
-
* import { Effect, Schema } from "effect"
|
|
3781
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3782
|
-
*
|
|
3783
|
-
* class LoadFailed extends Schema.TaggedClass<LoadFailed>("LoadFailed")("LoadFailed", {
|
|
3784
|
-
* reason: Schema.String
|
|
3785
|
-
* }) {}
|
|
3786
|
-
*
|
|
3787
|
-
* const load = Machine.effect(
|
|
3788
|
-
* Effect.fail("unavailable").pipe(
|
|
3789
|
-
* Effect.catch((reason) => Effect.succeed(new LoadFailed({ reason })))
|
|
3790
|
-
* )
|
|
3791
|
-
* )
|
|
3792
|
-
* ```
|
|
3793
|
-
*
|
|
3794
|
-
* @see {@link transition} for event-driven state.
|
|
3795
|
-
* @see {@link logic} for direct control over intermediate snapshots.
|
|
3796
|
-
* @category constructors
|
|
3797
|
-
* @since 0.4.0
|
|
3798
|
-
*/
|
|
3799
|
-
export declare const effect: <Output, Error = never, Requirements = never>(effect: Effect.Effect<Output, Error, Requirements>) => Logic<void, never, Error, Requirements, Output>;
|
|
3800
3901
|
/**
|
|
3801
3902
|
* Creates advanced stateful process logic from explicit initialization and
|
|
3802
3903
|
* execution methods.
|
|
@@ -3818,9 +3919,9 @@ export declare const effect: <Output, Error = never, Requirements = never>(effec
|
|
|
3818
3919
|
* This is the low-level process constructor. Parent messages sent directly
|
|
3819
3920
|
* through its scope are intentionally `unknown` because the logic does not know
|
|
3820
3921
|
* which machine will eventually own it. Prefer typed output, typed child
|
|
3821
|
-
* addresses, or
|
|
3922
|
+
* addresses, or invocation lifecycle transitions when possible.
|
|
3822
3923
|
*
|
|
3823
|
-
*
|
|
3924
|
+
* Use an inline `invoke` with an `effect` source for one-shot work.
|
|
3824
3925
|
* @see {@link transition} for event-driven state.
|
|
3825
3926
|
* @category constructors
|
|
3826
3927
|
* @since 0.4.0
|
|
@@ -3854,7 +3955,7 @@ export declare const logic: <State, Event = never, Output = void, Error = never,
|
|
|
3854
3955
|
* )
|
|
3855
3956
|
* ```
|
|
3856
3957
|
*
|
|
3857
|
-
*
|
|
3958
|
+
* Use an inline `invoke` with an `effect` source for one-shot work.
|
|
3858
3959
|
* @see {@link logic} for direct process lifecycle control.
|
|
3859
3960
|
* @category constructors
|
|
3860
3961
|
* @since 0.4.0
|
|
@@ -3977,7 +4078,7 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
3977
4078
|
* @category constructors
|
|
3978
4079
|
* @since 0.4.0
|
|
3979
4080
|
*/
|
|
3980
|
-
export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.
|
|
4081
|
+
export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
3981
4082
|
/**
|
|
3982
4083
|
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
3983
4084
|
*
|
|
@@ -3988,8 +4089,8 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
3988
4089
|
* entry or transition actions, re-deliver raised or emitted events, or
|
|
3989
4090
|
* re-evaluate historical completion and eventless transitions. Active-state
|
|
3990
4091
|
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
3991
|
-
*
|
|
3992
|
-
* from their own initial state.
|
|
4092
|
+
* timer invocations restart their complete duration and child-machine
|
|
4093
|
+
* invocations start from their own initial state.
|
|
3993
4094
|
*
|
|
3994
4095
|
* Only logical state, completion, and history metadata are resumed. Queues,
|
|
3995
4096
|
* scopes, subscriptions, fibers, spawned children, invoke progress, and prior
|
|
@@ -4029,5 +4130,5 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
4029
4130
|
* @category constructors
|
|
4030
4131
|
* @since 0.4.0
|
|
4031
4132
|
*/
|
|
4032
|
-
export declare const resume: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.
|
|
4133
|
+
export declare const resume: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, MachineSchemaDecodeError, ExcludeCompatibleRuntime<ExecutionServices<R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
4033
4134
|
//# sourceMappingURL=Machine.d.ts.map
|