@typeonce/effect-machine 0.31.2 → 0.32.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 +145 -140
- package/dist/Machine.d.ts +428 -254
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +91 -111
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +3 -4
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +0 -2
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/childRegistry.d.ts +52 -0
- package/dist/internal/machine/childRegistry.d.ts.map +1 -0
- package/dist/internal/machine/childRegistry.js +74 -0
- package/dist/internal/machine/childRegistry.js.map +1 -0
- package/dist/internal/machine/cluster.d.ts +2 -3
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +14 -4
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +1 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +97 -53
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +4 -2
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts +35 -0
- package/dist/internal/machine/invocationDefinition.d.ts.map +1 -0
- package/dist/internal/machine/invocationDefinition.js +21 -0
- package/dist/internal/machine/invocationDefinition.js.map +1 -0
- package/dist/internal/machine/invocationEvent.d.ts +0 -2
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +0 -8
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +21 -43
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +98 -374
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +13 -19
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +63 -35
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +6 -8
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +1 -0
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +2 -2
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +4 -18
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/readiness.d.ts +1 -1
- package/dist/internal/machine/readiness.d.ts.map +1 -1
- package/dist/internal/machine/requirements.d.ts +4 -0
- package/dist/internal/machine/requirements.d.ts.map +1 -0
- package/dist/internal/machine/requirements.js +2 -0
- package/dist/internal/machine/requirements.js.map +1 -0
- package/dist/internal/machine/runtime.d.ts +4 -58
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +1 -69
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/serialization.d.ts.map +1 -1
- package/dist/internal/machine/serialization.js +16 -0
- package/dist/internal/machine/serialization.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +3 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +36 -2
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/targetBuilder.d.ts +16 -0
- package/dist/internal/machine/targetBuilder.d.ts.map +1 -0
- package/dist/internal/machine/targetBuilder.js +333 -0
- package/dist/internal/machine/targetBuilder.js.map +1 -0
- package/dist/internal/machine/topology.js +3 -3
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/machine/transition.d.ts +16 -0
- package/dist/internal/machine/transition.d.ts.map +1 -0
- package/dist/internal/machine/transition.js +2 -0
- package/dist/internal/machine/transition.js.map +1 -0
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +10 -12
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/format.d.ts +7 -0
- package/dist/internal/testing/machine/format.d.ts.map +1 -0
- package/dist/internal/testing/machine/format.js +104 -0
- package/dist/internal/testing/machine/format.js.map +1 -0
- package/dist/internal/testing/machine/probe.d.ts +1 -1
- package/dist/internal/testing/machine/probe.d.ts.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.js.map +1 -1
- package/dist/internal/testing/machine/referenceModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/referenceModel.js +15 -19
- package/dist/internal/testing/machine/referenceModel.js.map +1 -1
- package/dist/internal/testing/machine/trace.d.ts +1 -1
- package/dist/internal/testing/machine/trace.d.ts.map +1 -1
- package/dist/internal/testing/machine/trace.js +3 -3
- package/dist/internal/testing/machine/trace.js.map +1 -1
- package/dist/internal/testing/machine/value.d.ts +8 -0
- package/dist/internal/testing/machine/value.d.ts.map +1 -0
- package/dist/internal/testing/machine/value.js +82 -0
- package/dist/internal/testing/machine/value.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts +2 -13
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +21 -113
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +89 -104
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +70 -84
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +10 -13
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +5 -8
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +26 -61
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +17 -26
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +45 -45
- package/docs/effect-atom-react.md +35 -63
- package/docs/machine-review.md +7 -7
- package/docs/root-api.md +214 -0
- package/package.json +1 -1
- package/src/Machine.ts +778 -437
- package/src/internal/machine/atom.ts +3 -13
- package/src/internal/machine/childRegistry.ts +141 -0
- package/src/internal/machine/cluster.ts +5 -14
- package/src/internal/machine/configuration.ts +20 -4
- package/src/internal/machine/executionPlan.ts +109 -52
- package/src/internal/machine/invocation.ts +10 -6
- package/src/internal/machine/invocationDefinition.ts +52 -0
- package/src/internal/machine/invocationEvent.ts +0 -8
- package/src/internal/machine/machine.ts +154 -679
- package/src/internal/machine/planner.ts +74 -62
- package/src/internal/machine/process.ts +14 -21
- package/src/internal/machine/protocol.ts +9 -32
- package/src/internal/machine/readiness.ts +1 -0
- package/src/internal/machine/requirements.ts +11 -0
- package/src/internal/machine/runtime.ts +17 -186
- package/src/internal/machine/serialization.ts +22 -0
- package/src/internal/machine/stateDefinition.ts +36 -3
- package/src/internal/machine/targetBuilder.ts +525 -0
- package/src/internal/machine/topology.ts +3 -3
- package/src/internal/machine/transition.ts +26 -0
- package/src/internal/testing/machine/finiteModel.ts +22 -23
- package/src/internal/testing/machine/format.ts +120 -0
- package/src/internal/testing/machine/probe.ts +4 -4
- package/src/internal/testing/machine/referenceModel.ts +25 -17
- package/src/internal/testing/machine/trace.ts +4 -4
- package/src/internal/testing/machine/value.ts +77 -0
- package/src/internal/testing/machine/verification.ts +904 -1109
- package/src/testing/MachineTest.ts +103 -114
- package/src/unstable/cluster/ClusterMachine.ts +10 -20
- package/src/unstable/reactivity/AtomMachine.ts +42 -79
package/src/Machine.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
import * as internal from "./internal/machine/machine.js"
|
|
28
28
|
import { InitialEventTypeId } from "./internal/machine/machine.js"
|
|
29
29
|
import type { EnsureExecutable } from "./internal/machine/readiness.js"
|
|
30
|
+
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js"
|
|
30
31
|
import type * as internalRuntime from "./internal/machine/runtime.js"
|
|
31
32
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js"
|
|
32
33
|
import type * as Topology from "./internal/machine/topology.js"
|
|
@@ -161,6 +162,9 @@ export interface Machine<
|
|
|
161
162
|
*/
|
|
162
163
|
readonly states: States
|
|
163
164
|
|
|
165
|
+
/** Root descriptor for topology and snapshot access. */
|
|
166
|
+
readonly root: State<Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, Machine.StateNodeConfig>>
|
|
167
|
+
|
|
164
168
|
/**
|
|
165
169
|
* Events accepted through public machine input boundaries.
|
|
166
170
|
*
|
|
@@ -281,15 +285,15 @@ export interface Definition<
|
|
|
281
285
|
* **Example**
|
|
282
286
|
*
|
|
283
287
|
* ```ts
|
|
284
|
-
* const counter = definition.handle({
|
|
288
|
+
* const counter = definition.handle({ states: {
|
|
285
289
|
* Count: {
|
|
286
290
|
* on: {
|
|
287
291
|
* Increment: (to) =>
|
|
288
|
-
* to.
|
|
292
|
+
* to.branch.Count().resolve(({ event, state, target }) =>
|
|
289
293
|
* target.decoded(new Count({ value: state.value + event.by })))
|
|
290
294
|
* }
|
|
291
295
|
* }
|
|
292
|
-
* })
|
|
296
|
+
* } })
|
|
293
297
|
* ```
|
|
294
298
|
*
|
|
295
299
|
* @since 0.4.0
|
|
@@ -631,14 +635,6 @@ export declare namespace Runtime {
|
|
|
631
635
|
}
|
|
632
636
|
}
|
|
633
637
|
|
|
634
|
-
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<
|
|
635
|
-
infer RequiredEvents,
|
|
636
|
-
infer RequiredEmits
|
|
637
|
-
> ? IsAny<Requirements> extends true ? Requirements
|
|
638
|
-
: [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements
|
|
639
|
-
: Requirements
|
|
640
|
-
: Requirements
|
|
641
|
-
|
|
642
638
|
type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<
|
|
643
639
|
infer RequiredEvents,
|
|
644
640
|
infer RequiredEmits
|
|
@@ -842,29 +838,6 @@ type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "i
|
|
|
842
838
|
: "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output">
|
|
843
839
|
: unknown
|
|
844
840
|
|
|
845
|
-
type DefineStateTreeInput<States extends Machine.StateSchemas> = {
|
|
846
|
-
readonly [Key in keyof States]: DefineStateNodeInput<States[Key]>
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node
|
|
850
|
-
: Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig
|
|
851
|
-
: Node extends Machine.ChoiceStateNodeConfig ? Machine.ChoiceStateNodeConfig
|
|
852
|
-
: Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
853
|
-
Omit<Node, "states"> & { readonly states: DefineStateTreeInput<Children> }
|
|
854
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ? Omit<Node, "initial" | "states"> & {
|
|
855
|
-
readonly initial: ActiveStateKey<Children> | ChoiceStateKey<Children>
|
|
856
|
-
readonly states: DefineStateTreeInput<Children>
|
|
857
|
-
}
|
|
858
|
-
: Node
|
|
859
|
-
|
|
860
|
-
type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] extends
|
|
861
|
-
[Machine.ValidateStateSchemas<States>] ? []
|
|
862
|
-
: [validation: Machine.ValidateStateSchemas<States>]
|
|
863
|
-
|
|
864
|
-
type InvalidDefinedStateTreeInput<States extends Machine.StateSchemas> = [States] extends
|
|
865
|
-
[Machine.ValidateStateSchemas<States>] ? never
|
|
866
|
-
: States & Machine.ValidateStateSchemas<States>
|
|
867
|
-
|
|
868
841
|
type ReusableStateNodeConfig =
|
|
869
842
|
| Machine.AtomicStateNodeConfig
|
|
870
843
|
| Machine.CompoundStateNodeConfig
|
|
@@ -876,23 +849,73 @@ type ReusableStateValidation<Node> = Node extends ReusableStateNodeConfig ? Vali
|
|
|
876
849
|
type ValidateDefinedState<Node> = [Node] extends [ReusableStateValidation<Node>] ? []
|
|
877
850
|
: [validation: ReusableStateValidation<Node>]
|
|
878
851
|
|
|
879
|
-
|
|
880
|
-
: Node & ReusableStateValidation<Node>
|
|
852
|
+
const StateTypeId = "~effect/Machine/State"
|
|
881
853
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
854
|
+
/** An immutable state descriptor, usable as a root or a nested state.
|
|
855
|
+
* @category models
|
|
856
|
+
* @since 0.32.0
|
|
857
|
+
*/
|
|
858
|
+
export interface State<Node extends Machine.StateNodeConfig> extends Machine.StateAccessors<{ readonly "": Node }> {
|
|
859
|
+
readonly [StateTypeId]: typeof StateTypeId
|
|
860
|
+
readonly node: Node
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
type NormalizeState<Node, Tag extends string = ""> = Node extends
|
|
864
|
+
{ readonly [StateTypeId]: typeof StateTypeId; readonly node: infer Config } ? Config
|
|
865
|
+
: Node extends Machine.TaggedSchema ? Node
|
|
866
|
+
: "fields" extends keyof Node ? NormalizeStateFields<Node, Tag>
|
|
867
|
+
: Node extends { readonly states: infer Children } ?
|
|
868
|
+
Children extends Readonly<Record<string, Machine.TaggedSchema>> ? Node : NormalizeStateFields<Node, Tag>
|
|
869
|
+
: Node
|
|
870
|
+
|
|
871
|
+
type NormalizeStateFields<Node, Tag extends string> = {
|
|
872
|
+
readonly [Key in keyof Node as Key extends "fields" ? "schema" : Key]: Key extends "fields" ?
|
|
873
|
+
Node[Key] extends Schema.Struct.Fields ? Schema.TaggedStruct<Tag, Node[Key]> : never
|
|
874
|
+
: Key extends "states" ?
|
|
875
|
+
{ readonly [Child in keyof Node[Key]]: NormalizeState<Node[Key][Child], Extract<Child, string>> }
|
|
876
|
+
: Node[Key]
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
type NormalizedState<Node> = Extract<NormalizeState<Node>, Machine.StateNodeConfig>
|
|
880
|
+
type StateFieldsValidation<Node> = Node extends { readonly [StateTypeId]: typeof StateTypeId } | Machine.TaggedSchema ?
|
|
881
|
+
unknown :
|
|
882
|
+
& (Node extends { readonly fields: infer Fields } ?
|
|
883
|
+
"schema" extends keyof Node ? StateDefinitionError<"Declare fields or schema, not both", "">
|
|
884
|
+
: Fields extends Schema.Struct.Fields ?
|
|
885
|
+
"_tag" extends keyof Fields ? StateDefinitionError<"State fields cannot declare _tag", ""> : unknown
|
|
886
|
+
: StateDefinitionError<"State fields must be schema fields", "">
|
|
887
|
+
: unknown)
|
|
888
|
+
& (Node extends { readonly states: infer Children } ? {
|
|
889
|
+
readonly states: {
|
|
890
|
+
readonly [Key in keyof Children]: StateFieldsValidation<Children[Key]>
|
|
891
|
+
}
|
|
892
|
+
} :
|
|
893
|
+
unknown)
|
|
894
|
+
|
|
895
|
+
interface StateInput {
|
|
896
|
+
readonly schema?: Machine.TaggedSchema
|
|
897
|
+
readonly fields?: Schema.Struct.Fields
|
|
898
|
+
readonly type?: "active" | "parallel" | "final" | "history" | "choice"
|
|
899
|
+
readonly initial?: string
|
|
900
|
+
readonly states?: Readonly<
|
|
901
|
+
Record<
|
|
902
|
+
string,
|
|
903
|
+
Machine.TaggedSchema | StateInput | {
|
|
904
|
+
readonly [StateTypeId]: typeof StateTypeId
|
|
905
|
+
readonly node: Machine.StateNodeConfig
|
|
906
|
+
}
|
|
907
|
+
>
|
|
908
|
+
>
|
|
909
|
+
readonly history?: "shallow" | "deep"
|
|
910
|
+
readonly output?: Schema.Top
|
|
911
|
+
readonly annotations?: Machine.SchemaLessStateAnnotations
|
|
888
912
|
}
|
|
889
913
|
|
|
890
|
-
interface
|
|
891
|
-
<const
|
|
892
|
-
|
|
893
|
-
..._validation:
|
|
894
|
-
):
|
|
895
|
-
<const States extends Machine.StateSchemas>(states: InvalidDefinedStateTreeInput<States>): never
|
|
914
|
+
interface StateConstructor {
|
|
915
|
+
<const Node extends StateInput>(
|
|
916
|
+
node: Node & StateFieldsValidation<NoInfer<Node>>,
|
|
917
|
+
..._validation: ValidateDefinedState<NormalizeState<NoInfer<Node>>>
|
|
918
|
+
): State<NormalizedState<Node>>
|
|
896
919
|
}
|
|
897
920
|
|
|
898
921
|
type EventProtocolError<Message extends string, Tag extends PropertyKey = never> = {
|
|
@@ -919,12 +942,6 @@ type ValidateInputEventProtocol<
|
|
|
919
942
|
> = [DuplicateInput] extends [never] ? unknown
|
|
920
943
|
: EventProtocolError<"Public event tags must be unique", DuplicateInput>
|
|
921
944
|
|
|
922
|
-
type ValidateEmittedEventProtocol<
|
|
923
|
-
EmittedEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
924
|
-
DuplicateEmitted extends PropertyKey = DuplicateEventTag<EmittedEvents>
|
|
925
|
-
> = [DuplicateEmitted] extends [never] ? unknown
|
|
926
|
-
: EventProtocolError<"Emitted event tags must be unique", DuplicateEmitted>
|
|
927
|
-
|
|
928
945
|
type ValidateInternalEventProtocol<
|
|
929
946
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
930
947
|
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -961,7 +978,7 @@ type FromCallable<Arguments extends ReadonlyArray<unknown>, Result> = Arguments
|
|
|
961
978
|
: (...args: Arguments) => Result
|
|
962
979
|
: (...args: Arguments) => Result
|
|
963
980
|
|
|
964
|
-
type FromMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
981
|
+
type FromMethod<in out Arguments extends ReadonlyArray<unknown>, out Result> = {
|
|
965
982
|
/**
|
|
966
983
|
* Constructs the selected state from its schema make input while the
|
|
967
984
|
* machine plans the resulting configuration. The input may be omitted when
|
|
@@ -1231,33 +1248,28 @@ type InitialParallelBuilder<
|
|
|
1231
1248
|
}
|
|
1232
1249
|
|
|
1233
1250
|
type FullSnapshotBuilderWithPrefix<
|
|
1234
|
-
States extends Machine.StateSchemas,
|
|
1235
|
-
Prefix extends string = ""
|
|
1236
|
-
> =
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>
|
|
1242
|
-
}
|
|
1251
|
+
in out States extends Machine.StateSchemas,
|
|
1252
|
+
in out Prefix extends string = ""
|
|
1253
|
+
> = {
|
|
1254
|
+
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States>
|
|
1255
|
+
? FullSnapshotMethod<States, Key, Prefix>
|
|
1256
|
+
: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>
|
|
1257
|
+
}
|
|
1243
1258
|
|
|
1244
1259
|
type FullSnapshotMethod<
|
|
1245
|
-
States extends Machine.StateSchemas,
|
|
1246
|
-
StateId extends ActiveStateKey<States>,
|
|
1247
|
-
Prefix extends string
|
|
1248
|
-
> =
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
:
|
|
1253
|
-
& DecodedMethod<
|
|
1254
|
-
FullSnapshotArguments<States, StateId, Prefix>,
|
|
1255
|
-
FullSnapshotResult<States, StateId, Prefix>
|
|
1256
|
-
>
|
|
1257
|
-
& FromMethod<
|
|
1260
|
+
in out States extends Machine.StateSchemas,
|
|
1261
|
+
in out StateId extends ActiveStateKey<States>,
|
|
1262
|
+
in out Prefix extends string
|
|
1263
|
+
> = {
|
|
1264
|
+
readonly [
|
|
1265
|
+
/** Constructs this node using schema make input or an already decoded value. */
|
|
1266
|
+
Method in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"
|
|
1267
|
+
]: Method extends "from" ? FromCallable<
|
|
1258
1268
|
FullSnapshotFromArguments<States, StateId, Prefix>,
|
|
1259
|
-
FullSnapshotResult<States, StateId, Prefix
|
|
1269
|
+
Machine.StateConstruction<FullSnapshotResult<States, StateId, Prefix>>
|
|
1260
1270
|
>
|
|
1271
|
+
: (...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>
|
|
1272
|
+
}
|
|
1261
1273
|
|
|
1262
1274
|
type FullSnapshotArguments<
|
|
1263
1275
|
States extends Machine.StateSchemas,
|
|
@@ -1416,23 +1428,20 @@ type HistorySnapshotResult<
|
|
|
1416
1428
|
: never
|
|
1417
1429
|
|
|
1418
1430
|
type HistorySnapshotMethod<
|
|
1419
|
-
States extends Machine.StateSchemas,
|
|
1420
|
-
StateId extends ActiveStateKey<States>,
|
|
1421
|
-
Prefix extends string,
|
|
1422
|
-
Owner extends string
|
|
1423
|
-
> =
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
>
|
|
1427
|
-
:
|
|
1428
|
-
& DecodedMethod<
|
|
1429
|
-
HistorySnapshotArguments<States, StateId, Prefix, Owner>,
|
|
1430
|
-
HistorySnapshotResult<States, StateId, Prefix, Owner>
|
|
1431
|
-
>
|
|
1432
|
-
& FromMethod<
|
|
1431
|
+
in out States extends Machine.StateSchemas,
|
|
1432
|
+
in out StateId extends ActiveStateKey<States>,
|
|
1433
|
+
in out Prefix extends string,
|
|
1434
|
+
in out Owner extends string
|
|
1435
|
+
> = {
|
|
1436
|
+
readonly [Key in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Key extends
|
|
1437
|
+
"from" ? FromCallable<
|
|
1433
1438
|
HistorySnapshotFromArguments<States, StateId, Prefix, Owner>,
|
|
1434
|
-
HistorySnapshotResult<States, StateId, Prefix, Owner
|
|
1435
|
-
>
|
|
1439
|
+
Machine.StateConstruction<HistorySnapshotResult<States, StateId, Prefix, Owner>>
|
|
1440
|
+
> :
|
|
1441
|
+
(
|
|
1442
|
+
...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>
|
|
1443
|
+
) => HistorySnapshotResult<States, StateId, Prefix, Owner>
|
|
1444
|
+
}
|
|
1436
1445
|
|
|
1437
1446
|
type HistorySnapshotWithPrefix<
|
|
1438
1447
|
States extends Machine.StateSchemas,
|
|
@@ -1441,7 +1450,8 @@ type HistorySnapshotWithPrefix<
|
|
|
1441
1450
|
> = {
|
|
1442
1451
|
readonly [Key in ActiveStateKey<States>]: Owner extends
|
|
1443
1452
|
| Machine.JoinPath<Prefix, Key>
|
|
1444
|
-
| `${Machine.JoinPath<Prefix, Key>}.${string}` ?
|
|
1453
|
+
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ?
|
|
1454
|
+
HistorySnapshotResult<States, Key, Prefix, Owner>
|
|
1445
1455
|
: never
|
|
1446
1456
|
}[ActiveStateKey<States>]
|
|
1447
1457
|
|
|
@@ -1453,7 +1463,7 @@ type HistorySnapshotBuilderWithPrefix<
|
|
|
1453
1463
|
readonly [
|
|
1454
1464
|
Key in ActiveStateKey<States> as Owner extends
|
|
1455
1465
|
| Machine.JoinPath<Prefix, Key>
|
|
1456
|
-
| `${Machine.JoinPath<Prefix, Key>}.${string}` ? Key
|
|
1466
|
+
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? Key
|
|
1457
1467
|
: never
|
|
1458
1468
|
]: HistorySnapshotMethod<States, Key, Prefix, Owner>
|
|
1459
1469
|
}
|
|
@@ -1465,7 +1475,8 @@ type HistorySnapshotRegions<
|
|
|
1465
1475
|
> = {
|
|
1466
1476
|
readonly [Key in ActiveStateKey<States>]: Owner extends
|
|
1467
1477
|
| Machine.JoinPath<Prefix, Key>
|
|
1468
|
-
| `${Machine.JoinPath<Prefix, Key>}.${string}` ?
|
|
1478
|
+
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ?
|
|
1479
|
+
HistorySnapshotResult<States, Key, Prefix, Owner>
|
|
1469
1480
|
: FullSnapshotResult<States, Key, Prefix>
|
|
1470
1481
|
}
|
|
1471
1482
|
|
|
@@ -1481,7 +1492,8 @@ type HistoryParallelBuilder<
|
|
|
1481
1492
|
& {
|
|
1482
1493
|
readonly [Key in Remaining]: Owner extends
|
|
1483
1494
|
| Machine.JoinPath<Prefix, Key>
|
|
1484
|
-
| `${Machine.JoinPath<Prefix, Key>}.${string}` ?
|
|
1495
|
+
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ?
|
|
1496
|
+
NodeBuilderMethod<
|
|
1485
1497
|
States[Key],
|
|
1486
1498
|
HistorySnapshotArguments<States, Key, Prefix, Owner>,
|
|
1487
1499
|
HistoryParallelBuilder<
|
|
@@ -1525,9 +1537,7 @@ type HistoryParallelBuilder<
|
|
|
1525
1537
|
>
|
|
1526
1538
|
}
|
|
1527
1539
|
|
|
1528
|
-
type ParentPath<Path extends string> = Path
|
|
1529
|
-
? Child extends `${string}.${string}` ? `${Parent}.${ParentPath<Child>}` : Parent
|
|
1530
|
-
: never
|
|
1540
|
+
type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>
|
|
1531
1541
|
|
|
1532
1542
|
type IsCompoundNode<Node> = Node extends { readonly type: "parallel" } ? false
|
|
1533
1543
|
: Node extends { readonly states: Machine.StateSchemas } ? true
|
|
@@ -1607,7 +1617,7 @@ type LocalTargetMethod<
|
|
|
1607
1617
|
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1608
1618
|
> = States[StateId] extends infer Node ?
|
|
1609
1619
|
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1610
|
-
Source extends Path | `${Path}.${string}` ? NestedTargetMethod<
|
|
1620
|
+
Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ? NestedTargetMethod<
|
|
1611
1621
|
Node,
|
|
1612
1622
|
LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
|
|
1613
1623
|
LocalTargetResultWithPrefix<AllStates, Children, Path>,
|
|
@@ -1722,7 +1732,7 @@ type BranchTargetMethod<
|
|
|
1722
1732
|
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1723
1733
|
> = States[StateId] extends infer Node ?
|
|
1724
1734
|
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1725
|
-
Source extends Path | `${Path}.${string}` ?
|
|
1735
|
+
Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ?
|
|
1726
1736
|
& NestedTargetMethod<
|
|
1727
1737
|
Node,
|
|
1728
1738
|
BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
|
|
@@ -1795,20 +1805,26 @@ type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
|
|
|
1795
1805
|
readonly [Key in HistoryStateKey<States>]: States[Key] extends { readonly history: "deep" } ? never : Key
|
|
1796
1806
|
}[HistoryStateKey<States>] extends never ? false : true
|
|
1797
1807
|
|
|
1798
|
-
type
|
|
1799
|
-
|
|
1808
|
+
type RequiresInitialValue<Node> = Machine.NodeSchema<Node> extends never ? false
|
|
1809
|
+
: {} extends NodeMakeInput<Node> ? false
|
|
1810
|
+
: true
|
|
1811
|
+
|
|
1812
|
+
type HasRequiredActiveChild<States extends Machine.StateSchemas> = {
|
|
1813
|
+
readonly [Key in ActiveStateKey<States>]: RequiresInitialValue<States[Key]> extends true ? Key : never
|
|
1800
1814
|
}[ActiveStateKey<States>] extends never ? false : true
|
|
1801
1815
|
|
|
1802
1816
|
type InitializerClosureForNode<
|
|
1803
1817
|
AllStates extends Machine.StateSchemas,
|
|
1804
1818
|
Node,
|
|
1805
1819
|
Path extends string
|
|
1806
|
-
> = Node extends { readonly
|
|
1807
|
-
|
|
1808
|
-
|
|
1820
|
+
> = Node extends { readonly states: infer Declared extends Machine.StateSchemas } ?
|
|
1821
|
+
string extends keyof Declared ? never :
|
|
1822
|
+
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1823
|
+
| (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never)
|
|
1824
|
+
| InitializerClosuresForChildren<AllStates, Children, Path>
|
|
1809
1825
|
: Node extends { readonly states: infer Children extends Machine.StateSchemas; readonly initial: infer Initial } ?
|
|
1810
|
-
| (Initial extends ActiveStateKey<Children> ?
|
|
1811
|
-
|
|
1826
|
+
| (Initial extends ActiveStateKey<Children> ?
|
|
1827
|
+
RequiresInitialValue<Children[Initial]> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never
|
|
1812
1828
|
: never)
|
|
1813
1829
|
| (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<
|
|
1814
1830
|
AllStates,
|
|
@@ -1817,6 +1833,7 @@ type InitializerClosureForNode<
|
|
|
1817
1833
|
>
|
|
1818
1834
|
: never)
|
|
1819
1835
|
: never
|
|
1836
|
+
: never
|
|
1820
1837
|
|
|
1821
1838
|
type InitializerClosuresForChildren<
|
|
1822
1839
|
AllStates extends Machine.StateSchemas,
|
|
@@ -2490,7 +2507,7 @@ export declare namespace ChildMachine {
|
|
|
2490
2507
|
ExcludeCompatibleRuntime<
|
|
2491
2508
|
Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>, MachineRuntimeRequirement>,
|
|
2492
2509
|
Machine.Event<M>,
|
|
2493
|
-
Machine.
|
|
2510
|
+
Machine.EmittedEvent<M>
|
|
2494
2511
|
>,
|
|
2495
2512
|
Scope.Scope
|
|
2496
2513
|
>
|
|
@@ -2728,6 +2745,7 @@ export declare namespace Machine {
|
|
|
2728
2745
|
/** @internal */
|
|
2729
2746
|
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any, any>
|
|
2730
2747
|
readonly states: StateSchemas
|
|
2748
|
+
readonly root: Pick<State<Machine.StateNodeConfig>, typeof StateTypeId | "node">
|
|
2731
2749
|
readonly events: EventProtocol.Any<"public">
|
|
2732
2750
|
readonly internalEvents: EventProtocol.Any<"internal">
|
|
2733
2751
|
readonly emittedEvents: EventProtocol.Any<"emitted">
|
|
@@ -2848,9 +2866,6 @@ export declare namespace Machine {
|
|
|
2848
2866
|
*/
|
|
2849
2867
|
export type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"]
|
|
2850
2868
|
|
|
2851
|
-
/** @deprecated Use {@link EmittedEvents}. */
|
|
2852
|
-
export type Emits<M extends Any> = EmittedEvents<M>
|
|
2853
|
-
|
|
2854
2869
|
/**
|
|
2855
2870
|
* Extracts state paths with implemented output handlers.
|
|
2856
2871
|
*
|
|
@@ -3037,10 +3052,7 @@ export declare namespace Machine {
|
|
|
3037
3052
|
* @category utility types
|
|
3038
3053
|
* @since 0.4.0
|
|
3039
3054
|
*/
|
|
3040
|
-
export type EmittedEvent<M extends Any> = EmittedEventOf<
|
|
3041
|
-
|
|
3042
|
-
/** @deprecated Use {@link EmittedEvent}. */
|
|
3043
|
-
export type Emit<M extends Any> = EmittedEvent<M>
|
|
3055
|
+
export type EmittedEvent<M extends Any> = EmittedEventOf<EmittedEvents<M>>
|
|
3044
3056
|
|
|
3045
3057
|
/**
|
|
3046
3058
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
@@ -3080,9 +3092,6 @@ export declare namespace Machine {
|
|
|
3080
3092
|
"title" | "description" | "documentation"
|
|
3081
3093
|
>
|
|
3082
3094
|
|
|
3083
|
-
/** @deprecated Use {@link SchemaLessStateAnnotations}. */
|
|
3084
|
-
export type PseudoStateAnnotations = SchemaLessStateAnnotations
|
|
3085
|
-
|
|
3086
3095
|
/**
|
|
3087
3096
|
* Configuration accepted for an atomic object state node.
|
|
3088
3097
|
*
|
|
@@ -3278,21 +3287,16 @@ export declare namespace Machine {
|
|
|
3278
3287
|
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>
|
|
3279
3288
|
|
|
3280
3289
|
/**
|
|
3281
|
-
*
|
|
3290
|
+
* Typed snapshot access shared by state descriptors.
|
|
3282
3291
|
*
|
|
3283
3292
|
* **Details**
|
|
3284
3293
|
*
|
|
3285
|
-
* The
|
|
3286
|
-
* to `make`. The remaining helpers match and read snapshots for the same
|
|
3287
|
-
* state tree.
|
|
3294
|
+
* The helpers match and read snapshots for the same captured topology.
|
|
3288
3295
|
*
|
|
3289
3296
|
* @category models
|
|
3290
3297
|
* @since 0.4.0
|
|
3291
3298
|
*/
|
|
3292
|
-
export interface
|
|
3293
|
-
/** Captured state tree supplied to {@link states}. */
|
|
3294
|
-
readonly states: States
|
|
3295
|
-
|
|
3299
|
+
export interface StateAccessors<States extends StateSchemas> {
|
|
3296
3300
|
/**
|
|
3297
3301
|
* Checks and preserves one active state path from this definition.
|
|
3298
3302
|
*
|
|
@@ -3321,7 +3325,10 @@ export declare namespace Machine {
|
|
|
3321
3325
|
const Path extends ValuedStateIdentifier<States>
|
|
3322
3326
|
>(
|
|
3323
3327
|
snapshot: SnapshotByIdentifier<States, From>,
|
|
3324
|
-
path:
|
|
3328
|
+
path:
|
|
3329
|
+
& Path
|
|
3330
|
+
& (Path extends NoInfer<From> | (NoInfer<From> extends "" ? string : `${NoInfer<From>}.${string}`) ? unknown
|
|
3331
|
+
: never)
|
|
3325
3332
|
): Option.Option<StateByIdentifier<States, Path>>
|
|
3326
3333
|
}
|
|
3327
3334
|
|
|
@@ -3358,7 +3365,10 @@ export declare namespace Machine {
|
|
|
3358
3365
|
const Path extends StateIdentifier<States>
|
|
3359
3366
|
>(
|
|
3360
3367
|
snapshot: SnapshotByIdentifier<States, From>,
|
|
3361
|
-
path:
|
|
3368
|
+
path:
|
|
3369
|
+
& Path
|
|
3370
|
+
& (Path extends NoInfer<From> | (NoInfer<From> extends "" ? string : `${NoInfer<From>}.${string}`) ? unknown
|
|
3371
|
+
: never)
|
|
3362
3372
|
): Option.Option<SnapshotByIdentifier<States, Path>>
|
|
3363
3373
|
}
|
|
3364
3374
|
|
|
@@ -3380,7 +3390,10 @@ export declare namespace Machine {
|
|
|
3380
3390
|
const Path extends StateIdentifier<States>
|
|
3381
3391
|
>(
|
|
3382
3392
|
snapshot: SnapshotByIdentifier<States, From>,
|
|
3383
|
-
path:
|
|
3393
|
+
path:
|
|
3394
|
+
& Path
|
|
3395
|
+
& (Path extends NoInfer<From> | (NoInfer<From> extends "" ? string : `${NoInfer<From>}.${string}`) ? unknown
|
|
3396
|
+
: never)
|
|
3384
3397
|
): boolean
|
|
3385
3398
|
}
|
|
3386
3399
|
}
|
|
@@ -3824,17 +3837,17 @@ export declare namespace Machine {
|
|
|
3824
3837
|
export type EnsureChoiceImplementations<
|
|
3825
3838
|
States extends StateSchemas,
|
|
3826
3839
|
UnhandledStates extends StateIdentifier<States>
|
|
3827
|
-
> = [ChoiceIdentifier<States>] extends [never] ? unknown
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3840
|
+
> = IsAny<States> extends true ? unknown : [ChoiceIdentifier<States>] extends [never] ? unknown
|
|
3841
|
+
: [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown
|
|
3842
|
+
: {
|
|
3843
|
+
readonly "~effect/Machine/MissingChoiceImplementation": MissingChoiceImplementations<States, UnhandledStates>
|
|
3844
|
+
}
|
|
3832
3845
|
|
|
3833
3846
|
/** @internal Readiness proof required by planning and managed execution. */
|
|
3834
3847
|
export type EnsureHistoryImplementations<
|
|
3835
3848
|
States extends StateSchemas,
|
|
3836
3849
|
UnhandledStates extends StateIdentifier<States>
|
|
3837
|
-
> =
|
|
3850
|
+
> = IsAny<States> extends true ? unknown :
|
|
3838
3851
|
& ([HistoryIdentifier<States>] extends [never] ? unknown
|
|
3839
3852
|
: [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown :
|
|
3840
3853
|
{
|
|
@@ -3842,6 +3855,20 @@ export declare namespace Machine {
|
|
|
3842
3855
|
})
|
|
3843
3856
|
& EnsureChoiceImplementations<States, UnhandledStates>
|
|
3844
3857
|
|
|
3858
|
+
/** Owners whose declared default descendants require supplied values. */
|
|
3859
|
+
export type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never :
|
|
3860
|
+
"" extends keyof States ? States[""] extends { readonly "~effect/Machine/ExplicitInitial": true } ? never
|
|
3861
|
+
: InitializerClosureForNode<States, States[""], ""> :
|
|
3862
|
+
never
|
|
3863
|
+
|
|
3864
|
+
/** Proof that initialization can construct every required default value. */
|
|
3865
|
+
export type EnsureInitialImplementations<
|
|
3866
|
+
States extends StateSchemas,
|
|
3867
|
+
UnhandledStates extends StateIdentifier<States>
|
|
3868
|
+
> = [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
|
|
3869
|
+
readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3845
3872
|
/**
|
|
3846
3873
|
* Extracts a state-tree node by state path.
|
|
3847
3874
|
*
|
|
@@ -3851,7 +3878,15 @@ export declare namespace Machine {
|
|
|
3851
3878
|
export type NodeByIdentifier<
|
|
3852
3879
|
States extends StateSchemas,
|
|
3853
3880
|
StateId extends StateIdentifier<States>
|
|
3854
|
-
> =
|
|
3881
|
+
> = string extends keyof States ? NodeByNamedIdentifier<States, StateId>
|
|
3882
|
+
: "" extends keyof States ? StateId extends "" ? States[""]
|
|
3883
|
+
: States[""] extends { readonly states: infer Children extends StateSchemas }
|
|
3884
|
+
? NodeByIdentifier<Children, Extract<StateId, StateIdentifier<Children>>> :
|
|
3885
|
+
never
|
|
3886
|
+
: NodeByNamedIdentifier<States, StateId>
|
|
3887
|
+
|
|
3888
|
+
type NodeByNamedIdentifier<States extends StateSchemas, StateId extends string> = StateId extends
|
|
3889
|
+
`${infer Head}.${infer Rest}`
|
|
3855
3890
|
? Head extends keyof States
|
|
3856
3891
|
? States[Head] extends { readonly states: infer Children extends StateSchemas }
|
|
3857
3892
|
? Rest extends StateIdentifier<Children> ? NodeByIdentifier<Children, Rest> : never
|
|
@@ -3899,9 +3934,6 @@ export declare namespace Machine {
|
|
|
3899
3934
|
*/
|
|
3900
3935
|
export type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"]
|
|
3901
3936
|
|
|
3902
|
-
/** @deprecated Use {@link EmittedEventOf}. */
|
|
3903
|
-
export type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = EmittedEventOf<Emits>
|
|
3904
|
-
|
|
3905
3937
|
/**
|
|
3906
3938
|
* Event values received by lifecycle callbacks.
|
|
3907
3939
|
*
|
|
@@ -3927,8 +3959,11 @@ export declare namespace Machine {
|
|
|
3927
3959
|
* @category utility types
|
|
3928
3960
|
* @since 0.4.0
|
|
3929
3961
|
*/
|
|
3930
|
-
export type ParentStateIdentifier<StateId extends string> = StateId extends
|
|
3931
|
-
|
|
3962
|
+
export type ParentStateIdentifier<StateId extends string> = StateId extends "" ? never
|
|
3963
|
+
: "" | NamedParentStateIdentifier<StateId>
|
|
3964
|
+
|
|
3965
|
+
type NamedParentStateIdentifier<StateId extends string> = StateId extends `${infer Parent}.${infer Child}`
|
|
3966
|
+
? Parent | (Child extends `${string}.${string}` ? `${Parent}.${NamedParentStateIdentifier<Child>}` : never)
|
|
3932
3967
|
: never
|
|
3933
3968
|
|
|
3934
3969
|
/**
|
|
@@ -3940,7 +3975,8 @@ export declare namespace Machine {
|
|
|
3940
3975
|
export type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ?
|
|
3941
3976
|
Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}`
|
|
3942
3977
|
: Head
|
|
3943
|
-
: never
|
|
3978
|
+
: StateId extends "" ? never
|
|
3979
|
+
: ""
|
|
3944
3980
|
|
|
3945
3981
|
/**
|
|
3946
3982
|
* Maps every parent state path of a state identifier to its decoded value.
|
|
@@ -4023,7 +4059,7 @@ export declare namespace Machine {
|
|
|
4023
4059
|
States extends StateSchemas,
|
|
4024
4060
|
Children extends StateSchemas,
|
|
4025
4061
|
Prefix extends StateIdentifier<States>
|
|
4026
|
-
> = {
|
|
4062
|
+
> = Prefix extends "" ? TerminalOutput<Children> : {
|
|
4027
4063
|
readonly [Key in ActiveStateKey<Children>]: DirectFinalCompletionOutput<
|
|
4028
4064
|
States,
|
|
4029
4065
|
Extract<JoinPath<Prefix, Key>, StateIdentifier<States>>
|
|
@@ -4194,6 +4230,7 @@ export declare namespace Machine {
|
|
|
4194
4230
|
* @since 0.4.0
|
|
4195
4231
|
*/
|
|
4196
4232
|
export interface EncodedSnapshot {
|
|
4233
|
+
readonly version: 2
|
|
4197
4234
|
readonly _tag: "MachineSnapshot"
|
|
4198
4235
|
readonly active: ReadonlyArray<EncodedSnapshotState>
|
|
4199
4236
|
readonly completed?: ReadonlyArray<EncodedSnapshotCompletion>
|
|
@@ -4388,7 +4425,7 @@ export declare namespace Machine {
|
|
|
4388
4425
|
* @category utility types
|
|
4389
4426
|
* @since 0.4.0
|
|
4390
4427
|
*/
|
|
4391
|
-
export type RootStateIdentifier<StateId extends string> = StateId extends
|
|
4428
|
+
export type RootStateIdentifier<StateId extends string> = StateId extends string ? "" : never
|
|
4392
4429
|
|
|
4393
4430
|
/**
|
|
4394
4431
|
* Extracts the public snapshot shape that contains a final state path.
|
|
@@ -4450,7 +4487,7 @@ export declare namespace Machine {
|
|
|
4450
4487
|
* @category models
|
|
4451
4488
|
* @since 0.4.0
|
|
4452
4489
|
*/
|
|
4453
|
-
export interface StateConstruction<Result> {
|
|
4490
|
+
export interface StateConstruction<out Result> {
|
|
4454
4491
|
readonly [Topology.StateConstructionTypeId]: Result
|
|
4455
4492
|
}
|
|
4456
4493
|
|
|
@@ -4633,7 +4670,12 @@ export declare namespace Machine {
|
|
|
4633
4670
|
export type HistoryDefaultTargetBuilder<
|
|
4634
4671
|
States extends StateSchemas,
|
|
4635
4672
|
Owner extends StateIdentifier<States>
|
|
4636
|
-
> =
|
|
4673
|
+
> = HistorySnapshotMethod<
|
|
4674
|
+
{ readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig> },
|
|
4675
|
+
"" & ActiveStateKey<{ readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig> }>,
|
|
4676
|
+
"",
|
|
4677
|
+
Owner
|
|
4678
|
+
>
|
|
4637
4679
|
|
|
4638
4680
|
/**
|
|
4639
4681
|
* Builder for source-local transition targets.
|
|
@@ -4670,7 +4712,7 @@ export declare namespace Machine {
|
|
|
4670
4712
|
Source extends StateNodeIdentifier<States>
|
|
4671
4713
|
> = BranchTargetBuilderForRoot<
|
|
4672
4714
|
States,
|
|
4673
|
-
Extract<RootStateIdentifier<Source>, ActiveStateKey<States>>,
|
|
4715
|
+
Extract<"" extends keyof States ? "" : RootStateIdentifier<Source>, ActiveStateKey<States>>,
|
|
4674
4716
|
Source
|
|
4675
4717
|
>
|
|
4676
4718
|
|
|
@@ -4694,8 +4736,8 @@ export declare namespace Machine {
|
|
|
4694
4736
|
* @since 0.4.0
|
|
4695
4737
|
*/
|
|
4696
4738
|
export interface TargetBuilder<
|
|
4697
|
-
States extends StateSchemas,
|
|
4698
|
-
Source extends StateNodeIdentifier<States>
|
|
4739
|
+
in out States extends StateSchemas,
|
|
4740
|
+
in out Source extends StateNodeIdentifier<States>
|
|
4699
4741
|
> {
|
|
4700
4742
|
/**
|
|
4701
4743
|
* Selects an explicitly targetless transition.
|
|
@@ -4827,16 +4869,15 @@ export declare namespace Machine {
|
|
|
4827
4869
|
Node,
|
|
4828
4870
|
Path extends string,
|
|
4829
4871
|
Scope extends "local" | "branch"
|
|
4830
|
-
> = Node extends { readonly
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
: {}
|
|
4872
|
+
> = Node extends { readonly type: "final" } ? {} : NodeSchema<Node> extends never ? {}
|
|
4873
|
+
: {
|
|
4874
|
+
readonly update: SelectionValue<
|
|
4875
|
+
StateUpdateBuilder<AllStates, Extract<Path, ValuedStateIdentifier<AllStates>>>,
|
|
4876
|
+
Path,
|
|
4877
|
+
"update",
|
|
4878
|
+
Scope
|
|
4879
|
+
>
|
|
4880
|
+
}
|
|
4840
4881
|
|
|
4841
4882
|
/** @internal */
|
|
4842
4883
|
type BranchUpdateSelectionPath<
|
|
@@ -4879,34 +4920,18 @@ export declare namespace Machine {
|
|
|
4879
4920
|
& InitialSelectionMethod<Builder, Path, "full">
|
|
4880
4921
|
: SelectionMethod<Builder, Path, "state", "full">
|
|
4881
4922
|
|
|
4882
|
-
type
|
|
4883
|
-
readonly [Key in Extract<ActiveStateKey<States>, keyof FullTargetBuilder<States>>]: FullSelectionNode<
|
|
4884
|
-
States,
|
|
4885
|
-
States[Key],
|
|
4886
|
-
Extract<Key, StateIdentifier<States>>,
|
|
4887
|
-
FullTargetBuilder<States>[Key]
|
|
4888
|
-
>
|
|
4889
|
-
}
|
|
4923
|
+
type RootBuilder<Builder> = Builder extends { readonly "": infer Root } ? Root : never
|
|
4890
4924
|
|
|
4891
|
-
type
|
|
4892
|
-
States
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
"branch",
|
|
4902
|
-
BranchTargetBuilder<States, Source>[Key]
|
|
4903
|
-
>
|
|
4904
|
-
& (Source extends ChoiceIdentifier<States> ? {}
|
|
4905
|
-
: Source extends `${Key}.${infer Rest}` ? BranchUpdateSelectionPath<States, States[Key], Key, Rest>
|
|
4906
|
-
: StateUpdateSelectionForNode<States, States[Key], Key, "branch">)
|
|
4907
|
-
}
|
|
4908
|
-
: {}
|
|
4909
|
-
: {}
|
|
4925
|
+
type FullTargetSelector<States extends StateSchemas> =
|
|
4926
|
+
& SelectionValue<RootBuilder<FullTargetBuilder<States>>, "", "state", "full">
|
|
4927
|
+
& InitialSelectionMethod<RootBuilder<FullTargetBuilder<States>>, "", "full">
|
|
4928
|
+
|
|
4929
|
+
type BranchTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> =
|
|
4930
|
+
States[""] extends { readonly states: infer Children extends StateSchemas } ?
|
|
4931
|
+
& SelectionTreeWithPrefix<States, Children, "", "branch", RootBuilder<BranchTargetBuilder<States, Source>>>
|
|
4932
|
+
& (Source extends ChoiceIdentifier<States> ? {}
|
|
4933
|
+
: Omit<BranchUpdateSelectionPath<States, States[""], "", Source>, "update">)
|
|
4934
|
+
: {}
|
|
4910
4935
|
|
|
4911
4936
|
type LocalTargetSelector<
|
|
4912
4937
|
States extends StateSchemas,
|
|
@@ -4965,6 +4990,22 @@ export declare namespace Machine {
|
|
|
4965
4990
|
States extends StateSchemas,
|
|
4966
4991
|
Source extends StateNodeIdentifier<States>
|
|
4967
4992
|
> {
|
|
4993
|
+
/** Replaces this handler owner's value without reentry. */
|
|
4994
|
+
/** Selects the current handler owner for a value update without reentry. */
|
|
4995
|
+
readonly self: Source extends ValuedStateIdentifier<States>
|
|
4996
|
+
? StateUpdateSelectionForNode<States, NodeByIdentifier<States, Source>, Source, "branch">
|
|
4997
|
+
: {}
|
|
4998
|
+
/** Addresses the root and its retained value from any active descendant. */
|
|
4999
|
+
readonly root: "" extends ActiveStateKey<States> ?
|
|
5000
|
+
& SelectionNode<
|
|
5001
|
+
States,
|
|
5002
|
+
States[""],
|
|
5003
|
+
"",
|
|
5004
|
+
"branch",
|
|
5005
|
+
(BranchTargetBuilder<States, Source> extends { readonly "": infer Builder } ? Builder : never)
|
|
5006
|
+
>
|
|
5007
|
+
& StateUpdateSelectionForNode<States, States[""], "", "branch">
|
|
5008
|
+
: never
|
|
4968
5009
|
/** Handles the trigger without selecting a destination. */
|
|
4969
5010
|
readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none", "local">
|
|
4970
5011
|
/** Selects a destination or updates the nearest active compound scope. */
|
|
@@ -4974,7 +5015,9 @@ export declare namespace Machine {
|
|
|
4974
5015
|
/** Selects a complete destination under any top-level state. */
|
|
4975
5016
|
readonly full: FullTargetSelector<States>
|
|
4976
5017
|
/** Restores a shallow or deep history pseudo-state. */
|
|
4977
|
-
readonly history:
|
|
5018
|
+
readonly history: States[""] extends { readonly states: infer Children extends StateSchemas }
|
|
5019
|
+
? HistorySelectionTree<States, Children, "", RootBuilder<HistoryTargetBuilder<States>>>
|
|
5020
|
+
: {}
|
|
4978
5021
|
}
|
|
4979
5022
|
|
|
4980
5023
|
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
@@ -5380,8 +5423,9 @@ export declare namespace Machine {
|
|
|
5380
5423
|
*
|
|
5381
5424
|
* Handlers return snapshots for complete state replacement, target builder
|
|
5382
5425
|
* results for path-safe partial transitions, state-value updates, or
|
|
5383
|
-
*
|
|
5384
|
-
*
|
|
5426
|
+
* an explicit targetless result. In a machine definition, select `to.none`;
|
|
5427
|
+
* its optional resolver returns `undefined`. Raw decoded state values are
|
|
5428
|
+
* not accepted as transition targets.
|
|
5385
5429
|
*
|
|
5386
5430
|
* @category utility types
|
|
5387
5431
|
* @since 0.4.0
|
|
@@ -5524,7 +5568,7 @@ export declare namespace Machine {
|
|
|
5524
5568
|
ExcludeCompatibleRuntime<
|
|
5525
5569
|
Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>,
|
|
5526
5570
|
Event<M>,
|
|
5527
|
-
|
|
5571
|
+
EmittedEvent<M>
|
|
5528
5572
|
>,
|
|
5529
5573
|
Output<M>,
|
|
5530
5574
|
| InitialError<M>
|
|
@@ -5612,7 +5656,7 @@ export declare namespace Machine {
|
|
|
5612
5656
|
export type InvokeEmits<Invoke> = Invoke extends {
|
|
5613
5657
|
readonly [InvokeTypeId]: { readonly emits: Types.Covariant<infer Emitted> }
|
|
5614
5658
|
} ? Emitted
|
|
5615
|
-
: Invoke extends { readonly child: ChildMachine<string, infer M> } ?
|
|
5659
|
+
: Invoke extends { readonly child: ChildMachine<string, infer M> } ? EmittedEvent<M>
|
|
5616
5660
|
: never
|
|
5617
5661
|
|
|
5618
5662
|
/** Public parent inputs required by an invoked child machine. */
|
|
@@ -5846,7 +5890,7 @@ export declare namespace Machine {
|
|
|
5846
5890
|
Selection
|
|
5847
5891
|
> = (
|
|
5848
5892
|
context: TransitionResolveContext<Context, Selection>,
|
|
5849
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
5893
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
5850
5894
|
) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined
|
|
5851
5895
|
|
|
5852
5896
|
export type DeclinableTransitionResolver<
|
|
@@ -5856,7 +5900,7 @@ export declare namespace Machine {
|
|
|
5856
5900
|
Selection
|
|
5857
5901
|
> = (
|
|
5858
5902
|
context: TransitionResolveContext<Context, Selection> & DeclineCapability,
|
|
5859
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
5903
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
5860
5904
|
) =>
|
|
5861
5905
|
| (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined)
|
|
5862
5906
|
| Declined
|
|
@@ -5870,7 +5914,7 @@ export declare namespace Machine {
|
|
|
5870
5914
|
Owner extends ValuedStateIdentifier<States>
|
|
5871
5915
|
> = (
|
|
5872
5916
|
context: StateUpdateResolveContext<States, Context, Owner>,
|
|
5873
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
5917
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
5874
5918
|
) => StateUpdate<States, Owner>
|
|
5875
5919
|
|
|
5876
5920
|
/** @internal */
|
|
@@ -5882,7 +5926,7 @@ export declare namespace Machine {
|
|
|
5882
5926
|
Owner extends ValuedStateIdentifier<States>
|
|
5883
5927
|
> = (
|
|
5884
5928
|
context: StateUpdateResolveContext<States, Context, Owner> & DeclineCapability,
|
|
5885
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
5929
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
5886
5930
|
) => StateUpdate<States, Owner> | Declined
|
|
5887
5931
|
|
|
5888
5932
|
/** One named destination declared by a branching transition. */
|
|
@@ -5950,7 +5994,7 @@ export declare namespace Machine {
|
|
|
5950
5994
|
Branches extends Readonly<Record<string, TransitionBranchInput>>
|
|
5951
5995
|
> = (
|
|
5952
5996
|
context: TransitionBranchesResolveContext<Context, Branches>,
|
|
5953
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
5997
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
5954
5998
|
) => BranchSelectionResult<Branches>
|
|
5955
5999
|
|
|
5956
6000
|
export type DeclinableTransitionBranchesResolver<
|
|
@@ -5960,7 +6004,7 @@ export declare namespace Machine {
|
|
|
5960
6004
|
Branches extends Readonly<Record<string, TransitionBranchInput>>
|
|
5961
6005
|
> = (
|
|
5962
6006
|
context: TransitionBranchesResolveContext<Context, Branches> & DeclineCapability,
|
|
5963
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
6007
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
5964
6008
|
) => BranchSelectionResult<Branches> | Declined
|
|
5965
6009
|
|
|
5966
6010
|
/** @internal Type evidence retained by a transition authored through its bound selector. */
|
|
@@ -6053,6 +6097,67 @@ export declare namespace Machine {
|
|
|
6053
6097
|
>
|
|
6054
6098
|
}
|
|
6055
6099
|
|
|
6100
|
+
type ConstructionCallbacks<Context, Builder, Result> = {
|
|
6101
|
+
readonly [
|
|
6102
|
+
Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown
|
|
6103
|
+
? Args extends readonly [unknown?] ? Method : never :
|
|
6104
|
+
never
|
|
6105
|
+
]: Builder[Method] extends (...args: infer Args) => unknown ? (
|
|
6106
|
+
value: (context: Context) => Args[0]
|
|
6107
|
+
) => Result :
|
|
6108
|
+
never
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6111
|
+
type GuardedTransition<
|
|
6112
|
+
States extends StateSchemas,
|
|
6113
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
6114
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6115
|
+
StateId extends StateNodeIdentifier<States>,
|
|
6116
|
+
Context,
|
|
6117
|
+
Reenter extends boolean,
|
|
6118
|
+
Selection extends TargetSelection<any, any, any>
|
|
6119
|
+
> =
|
|
6120
|
+
& ConstructionCallbacks<
|
|
6121
|
+
Omit<Context, "target">,
|
|
6122
|
+
SelectionBuilder<Selection>,
|
|
6123
|
+
BuiltTransition<
|
|
6124
|
+
States,
|
|
6125
|
+
Events,
|
|
6126
|
+
Emits,
|
|
6127
|
+
StateId,
|
|
6128
|
+
Context,
|
|
6129
|
+
Reenter,
|
|
6130
|
+
SelectedTargetResult<Selection> | Declined,
|
|
6131
|
+
"declinable"
|
|
6132
|
+
>
|
|
6133
|
+
>
|
|
6134
|
+
& (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<
|
|
6135
|
+
States,
|
|
6136
|
+
Events,
|
|
6137
|
+
Emits,
|
|
6138
|
+
StateId,
|
|
6139
|
+
Context,
|
|
6140
|
+
Reenter,
|
|
6141
|
+
SelectedTargetResult<Selection> | Declined,
|
|
6142
|
+
"declinable"
|
|
6143
|
+
>
|
|
6144
|
+
: {})
|
|
6145
|
+
& {
|
|
6146
|
+
readonly resolve: (
|
|
6147
|
+
resolve: TransitionResolver<Events, Emits, Context, Selection>,
|
|
6148
|
+
options?: TransitionRequiredOptions<Reenter>
|
|
6149
|
+
) => BuiltTransition<
|
|
6150
|
+
States,
|
|
6151
|
+
Events,
|
|
6152
|
+
Emits,
|
|
6153
|
+
StateId,
|
|
6154
|
+
Context,
|
|
6155
|
+
Reenter,
|
|
6156
|
+
SelectedTargetResult<Selection> | Declined,
|
|
6157
|
+
"declinable"
|
|
6158
|
+
>
|
|
6159
|
+
}
|
|
6160
|
+
|
|
6056
6161
|
/**
|
|
6057
6162
|
* A selected transition target with target-specific resolver operations.
|
|
6058
6163
|
*
|
|
@@ -6060,7 +6165,7 @@ export declare namespace Machine {
|
|
|
6060
6165
|
*
|
|
6061
6166
|
* ```ts
|
|
6062
6167
|
* Reset: (to) =>
|
|
6063
|
-
* to.
|
|
6168
|
+
* to.branch.Ready().resolve(
|
|
6064
6169
|
* ({ target }) => target.from(),
|
|
6065
6170
|
* { reenter: true }
|
|
6066
6171
|
* )
|
|
@@ -6081,6 +6186,27 @@ export declare namespace Machine {
|
|
|
6081
6186
|
Selection extends TargetSelection<any, any, any>
|
|
6082
6187
|
> =
|
|
6083
6188
|
& Selection
|
|
6189
|
+
& ("declinable" extends Acceptance ? {
|
|
6190
|
+
/** Declines this candidate before construction when the predicate is false. */
|
|
6191
|
+
readonly guard: (
|
|
6192
|
+
predicate: (context: Omit<Context, "target">) => boolean
|
|
6193
|
+
) => GuardedTransition<States, Events, Emits, StateId, Context, Reenter, Selection>
|
|
6194
|
+
} :
|
|
6195
|
+
{})
|
|
6196
|
+
& ConstructionCallbacks<
|
|
6197
|
+
Omit<Context, "target">,
|
|
6198
|
+
SelectionBuilder<Selection>,
|
|
6199
|
+
BuiltTransition<
|
|
6200
|
+
States,
|
|
6201
|
+
Events,
|
|
6202
|
+
Emits,
|
|
6203
|
+
StateId,
|
|
6204
|
+
Context,
|
|
6205
|
+
Reenter,
|
|
6206
|
+
SelectedTargetResult<Selection>,
|
|
6207
|
+
"required"
|
|
6208
|
+
>
|
|
6209
|
+
>
|
|
6084
6210
|
& (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<
|
|
6085
6211
|
States,
|
|
6086
6212
|
Events,
|
|
@@ -6164,7 +6290,7 @@ export declare namespace Machine {
|
|
|
6164
6290
|
& ((
|
|
6165
6291
|
resolve: (
|
|
6166
6292
|
context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>,
|
|
6167
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
6293
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
6168
6294
|
) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>,
|
|
6169
6295
|
options?: TransitionRequiredOptions<Reenter>
|
|
6170
6296
|
) => BuiltTransition<
|
|
@@ -6180,7 +6306,7 @@ export declare namespace Machine {
|
|
|
6180
6306
|
& ("declinable" extends Acceptance ? (
|
|
6181
6307
|
resolve: (
|
|
6182
6308
|
context: UpdatingTransitionResolveContext<States, Context, Selection, Owner> & DeclineCapability,
|
|
6183
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
6309
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
6184
6310
|
) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined,
|
|
6185
6311
|
options: TransitionDeclinableOptions<Reenter>
|
|
6186
6312
|
) => BuiltTransition<
|
|
@@ -6270,26 +6396,44 @@ export declare namespace Machine {
|
|
|
6270
6396
|
Selection extends TargetSelection<any, any, "update">
|
|
6271
6397
|
> =
|
|
6272
6398
|
& Selection
|
|
6273
|
-
&
|
|
6274
|
-
|
|
6275
|
-
States,
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6399
|
+
& ConstructionCallbacks<
|
|
6400
|
+
Omit<
|
|
6401
|
+
StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>,
|
|
6402
|
+
"owner"
|
|
6403
|
+
>,
|
|
6404
|
+
SelectionBuilder<Selection>,
|
|
6405
|
+
BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">
|
|
6406
|
+
>
|
|
6407
|
+
& {
|
|
6408
|
+
readonly resolve:
|
|
6409
|
+
& StateUpdateTransitionRequired<States, Events, Emits, StateId, Context, Reenter, Selection>
|
|
6410
|
+
& ("declinable" extends Acceptance ? StateUpdateTransitionDeclinable<
|
|
6411
|
+
States,
|
|
6412
|
+
Events,
|
|
6413
|
+
Emits,
|
|
6414
|
+
StateId,
|
|
6415
|
+
Context,
|
|
6416
|
+
Reenter,
|
|
6417
|
+
Selection
|
|
6418
|
+
>
|
|
6419
|
+
: {})
|
|
6420
|
+
}
|
|
6284
6421
|
|
|
6285
6422
|
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
6286
6423
|
export interface InitialBuilderEvidence<out Selection> {
|
|
6287
6424
|
readonly [InitialBuilderTypeId]: Types.Covariant<Selection>
|
|
6288
6425
|
}
|
|
6289
6426
|
|
|
6427
|
+
/** Decoded input shared by initial construction callbacks. */
|
|
6428
|
+
export interface InitialContext<Input> {
|
|
6429
|
+
/** Decoded value supplied when the machine is started. */
|
|
6430
|
+
readonly input: Input
|
|
6431
|
+
}
|
|
6432
|
+
|
|
6290
6433
|
/** A selected machine initial entry with its exact resolver target. */
|
|
6291
6434
|
export type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> =
|
|
6292
6435
|
& Selection
|
|
6436
|
+
& ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>>
|
|
6293
6437
|
& (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {})
|
|
6294
6438
|
& {
|
|
6295
6439
|
/** Lazily constructs the selected initial state from decoded machine input. */
|
|
@@ -6326,6 +6470,42 @@ export declare namespace Machine {
|
|
|
6326
6470
|
to: InitialSelector<States, Input>
|
|
6327
6471
|
) => InitialBuilderEvidence<TargetSelection<any, any, any>>
|
|
6328
6472
|
|
|
6473
|
+
/** Initializes the root and its declared default descendants. */
|
|
6474
|
+
export type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (
|
|
6475
|
+
root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>
|
|
6476
|
+
) => InitialBuilderEvidence<TargetSelection<any, any, any>>
|
|
6477
|
+
|
|
6478
|
+
interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends
|
|
6479
|
+
TargetSelection<
|
|
6480
|
+
FullSnapshotMethod<{ readonly "": Root }, "" & ActiveStateKey<{ readonly "": Root }>, "">,
|
|
6481
|
+
"",
|
|
6482
|
+
"state",
|
|
6483
|
+
"initial"
|
|
6484
|
+
>
|
|
6485
|
+
{}
|
|
6486
|
+
|
|
6487
|
+
/** Explicitly constructs a complete starting configuration. */
|
|
6488
|
+
export type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (
|
|
6489
|
+
root:
|
|
6490
|
+
& ConstructionCallbacks<
|
|
6491
|
+
InitialContext<Input>,
|
|
6492
|
+
SelectionBuilder<RootConfigurationSelection<Root>>,
|
|
6493
|
+
InitialBuilderEvidence<RootConfigurationSelection<Root>>
|
|
6494
|
+
>
|
|
6495
|
+
& {
|
|
6496
|
+
readonly resolve: (
|
|
6497
|
+
resolve: (
|
|
6498
|
+
context: {
|
|
6499
|
+
/** Decoded startup input. */
|
|
6500
|
+
readonly input: Input
|
|
6501
|
+
/** Builder for the complete root configuration. */
|
|
6502
|
+
readonly target: SelectionBuilder<RootConfigurationSelection<Root>>
|
|
6503
|
+
}
|
|
6504
|
+
) => ConstructionResult<Snapshot<{ readonly "": Root }>>
|
|
6505
|
+
) => InitialBuilderEvidence<RootConfigurationSelection<Root>>
|
|
6506
|
+
}
|
|
6507
|
+
) => InitialBuilderEvidence<TargetSelection<any, any, any>>
|
|
6508
|
+
|
|
6329
6509
|
type TransitionSelectorNode<
|
|
6330
6510
|
States extends StateSchemas,
|
|
6331
6511
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
@@ -6440,46 +6620,56 @@ export declare namespace Machine {
|
|
|
6440
6620
|
>
|
|
6441
6621
|
}
|
|
6442
6622
|
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
& TransitionSelectorNode<
|
|
6623
|
+
type TransitionSelectorTargets<
|
|
6624
|
+
in out States extends StateSchemas,
|
|
6625
|
+
in out Events extends ReadonlyArray<TaggedSchema>,
|
|
6626
|
+
in out Emits extends ReadonlyArray<TaggedSchema>,
|
|
6627
|
+
in out StateId extends StateNodeIdentifier<States>,
|
|
6628
|
+
in out Context,
|
|
6629
|
+
in out Reenter extends boolean,
|
|
6630
|
+
in out Acceptance extends TransitionAcceptance
|
|
6631
|
+
> = {
|
|
6632
|
+
readonly [Key in keyof TargetSelector<States, StateId>]: TransitionSelectorNode<
|
|
6454
6633
|
States,
|
|
6455
6634
|
Events,
|
|
6456
6635
|
Emits,
|
|
6457
6636
|
StateId,
|
|
6458
6637
|
Context,
|
|
6459
|
-
Reenter,
|
|
6638
|
+
Key extends "self" ? false : Reenter,
|
|
6460
6639
|
Acceptance,
|
|
6461
|
-
TargetSelector<States, StateId>
|
|
6640
|
+
TargetSelector<States, StateId>[Key]
|
|
6462
6641
|
>
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6642
|
+
}
|
|
6643
|
+
|
|
6644
|
+
/** Selector supplied to inline transition declarations. */
|
|
6645
|
+
export interface TransitionSelector<
|
|
6646
|
+
in out States extends StateSchemas,
|
|
6647
|
+
in out Events extends ReadonlyArray<TaggedSchema>,
|
|
6648
|
+
in out Emits extends ReadonlyArray<TaggedSchema>,
|
|
6649
|
+
in out StateId extends StateNodeIdentifier<States>,
|
|
6650
|
+
in out Context,
|
|
6651
|
+
in out Reenter extends boolean,
|
|
6652
|
+
in out Acceptance extends TransitionAcceptance
|
|
6653
|
+
> extends TransitionSelectorTargets<States, Events, Emits, StateId, Context, Reenter, Acceptance> {
|
|
6654
|
+
/** Declares a closed set of named destinations for one resolver. */
|
|
6655
|
+
readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(
|
|
6656
|
+
branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>
|
|
6657
|
+
) => {
|
|
6658
|
+
/** Resolves exactly one declared branch after this transition is selected. */
|
|
6659
|
+
readonly resolve:
|
|
6660
|
+
& TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches>
|
|
6661
|
+
& ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<
|
|
6662
|
+
States,
|
|
6663
|
+
Events,
|
|
6664
|
+
Emits,
|
|
6665
|
+
StateId,
|
|
6666
|
+
Context,
|
|
6667
|
+
Reenter,
|
|
6668
|
+
Branches
|
|
6669
|
+
>
|
|
6670
|
+
: {})
|
|
6482
6671
|
}
|
|
6672
|
+
}
|
|
6483
6673
|
|
|
6484
6674
|
/** Inline transition declaration accepted by state and invocation handlers. */
|
|
6485
6675
|
export type TransitionBuilderInput<
|
|
@@ -6980,7 +7170,7 @@ export declare namespace Machine {
|
|
|
6980
7170
|
Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
|
|
6981
7171
|
Services<ChildDefinition>,
|
|
6982
7172
|
InitialError<ChildDefinition>,
|
|
6983
|
-
|
|
7173
|
+
EmittedEvent<ChildDefinition>,
|
|
6984
7174
|
EventOf<Machine.ParentEvents<ChildDefinition>>,
|
|
6985
7175
|
never,
|
|
6986
7176
|
| RequiredInvokeChannel<Output<ChildDefinition>, "done">
|
|
@@ -7016,9 +7206,9 @@ export declare namespace Machine {
|
|
|
7016
7206
|
* ```ts
|
|
7017
7207
|
* invoke: (from) =>
|
|
7018
7208
|
* from.effect("load-user", () => loadUser).onDone((to) =>
|
|
7019
|
-
* to.
|
|
7209
|
+
* to.branch.Ready().resolve(({ output, target }) => target.from({ user: output }))
|
|
7020
7210
|
* ).onFailure((to) =>
|
|
7021
|
-
* to.
|
|
7211
|
+
* to.branch.Failed().resolve(({ error, target }) => target.from({ error }))
|
|
7022
7212
|
* )
|
|
7023
7213
|
* ```
|
|
7024
7214
|
*
|
|
@@ -7244,14 +7434,14 @@ export declare namespace Machine {
|
|
|
7244
7434
|
* **Example** (State actions, events, and invocation)
|
|
7245
7435
|
*
|
|
7246
7436
|
* ```ts
|
|
7247
|
-
* machine.handle({
|
|
7437
|
+
* machine.handle({ states: {
|
|
7248
7438
|
* Loading: {
|
|
7249
7439
|
* entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
|
|
7250
7440
|
* invoke: (from) =>
|
|
7251
|
-
* from.effect("load", () => load).onDone((to) => to.
|
|
7252
|
-
* on: { Cancel: (to) => to.
|
|
7441
|
+
* from.effect("load", () => load).onDone((to) => to.branch.Ready()),
|
|
7442
|
+
* on: { Cancel: (to) => to.branch.Idle() }
|
|
7253
7443
|
* }
|
|
7254
|
-
* })
|
|
7444
|
+
* } })
|
|
7255
7445
|
* ```
|
|
7256
7446
|
*
|
|
7257
7447
|
* @inlineType ActiveOutputHandlerConfig
|
|
@@ -7273,12 +7463,12 @@ export declare namespace Machine {
|
|
|
7273
7463
|
/** Runs synchronously when the state is entered and may enqueue commands. */
|
|
7274
7464
|
readonly entry?: (
|
|
7275
7465
|
context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
7276
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
7466
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
7277
7467
|
) => StateActionResult<any, any>
|
|
7278
7468
|
/** Runs synchronously before the state is exited and may enqueue commands. */
|
|
7279
7469
|
readonly exit?: (
|
|
7280
7470
|
context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
7281
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
7471
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
7282
7472
|
) => StateActionResult<any, any>
|
|
7283
7473
|
/** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
|
|
7284
7474
|
readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
@@ -7429,15 +7619,15 @@ export declare namespace Machine {
|
|
|
7429
7619
|
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
7430
7620
|
> = (
|
|
7431
7621
|
context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
7432
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
7622
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
7433
7623
|
) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>
|
|
7434
7624
|
|
|
7435
7625
|
/** Context used only when a history node has no previously captured record. */
|
|
7436
7626
|
export interface HistoryDefaultContext<
|
|
7437
|
-
States extends StateSchemas,
|
|
7627
|
+
in out States extends StateSchemas,
|
|
7438
7628
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
7439
7629
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
7440
|
-
ParentId extends StateIdentifier<States>
|
|
7630
|
+
in out ParentId extends StateIdentifier<States>
|
|
7441
7631
|
> {
|
|
7442
7632
|
/** Lifecycle event that attempted to restore this history node. */
|
|
7443
7633
|
readonly event: LifecycleEvent<Events>
|
|
@@ -7461,7 +7651,7 @@ export declare namespace Machine {
|
|
|
7461
7651
|
ParentId extends StateIdentifier<States>
|
|
7462
7652
|
> = (
|
|
7463
7653
|
context: HistoryDefaultContext<States, Events, Emits, ParentId>,
|
|
7464
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
7654
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
7465
7655
|
) =>
|
|
7466
7656
|
| CompleteSnapshotContaining<States, ParentId>
|
|
7467
7657
|
| StateConstruction<CompleteSnapshotContaining<States, ParentId>>
|
|
@@ -7542,7 +7732,7 @@ export declare namespace Machine {
|
|
|
7542
7732
|
/** Runs synchronously when the final state is entered and may enqueue commands. */
|
|
7543
7733
|
readonly entry?: (
|
|
7544
7734
|
context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
7545
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
7735
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
7546
7736
|
) => StateActionResult<any, any>
|
|
7547
7737
|
readonly exit?: never
|
|
7548
7738
|
readonly always?: never
|
|
@@ -7595,21 +7785,27 @@ export declare namespace Machine {
|
|
|
7595
7785
|
: never
|
|
7596
7786
|
: never
|
|
7597
7787
|
|
|
7598
|
-
type HandlerNodeByPath<States extends StateSchemas, Path extends string> =
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
} ? HandlerNodeByPath<Children, Rest>
|
|
7602
|
-
: never
|
|
7788
|
+
type HandlerNodeByPath<States extends StateSchemas, Path extends string> = "" extends keyof States ?
|
|
7789
|
+
Path extends "" ? States[""]
|
|
7790
|
+
: States[""] extends { readonly states: infer Children extends StateSchemas } ? HandlerNodeByPath<Children, Path>
|
|
7603
7791
|
: never
|
|
7792
|
+
: Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
7793
|
+
readonly states: infer Children extends StateSchemas
|
|
7794
|
+
} ? HandlerNodeByPath<Children, Rest>
|
|
7795
|
+
: never
|
|
7796
|
+
: never
|
|
7604
7797
|
: Path extends keyof States ? States[Path]
|
|
7605
7798
|
: never
|
|
7606
7799
|
|
|
7607
7800
|
// Resolve only the supplied branch for a flattened state-node path. Keeping
|
|
7608
7801
|
// this recursion on the finite path avoids recursively expanding an open
|
|
7609
7802
|
// generic handler config.
|
|
7610
|
-
type HandlerConfigAtPath<Config, Path extends string> =
|
|
7611
|
-
|
|
7612
|
-
|
|
7803
|
+
type HandlerConfigAtPath<Config, Path extends string> = [Config] extends [never] ? never :
|
|
7804
|
+
"" extends keyof Config ? Path extends "" ? Config[""]
|
|
7805
|
+
: HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[""]>, Path>
|
|
7806
|
+
: Path extends `${infer Head}.${infer Rest}` ?
|
|
7807
|
+
Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest>
|
|
7808
|
+
: never
|
|
7613
7809
|
: Path extends keyof Config ? Config[Path]
|
|
7614
7810
|
: never
|
|
7615
7811
|
|
|
@@ -7768,7 +7964,7 @@ export declare namespace Machine {
|
|
|
7768
7964
|
States extends StateSchemas,
|
|
7769
7965
|
Prefix extends string,
|
|
7770
7966
|
Config,
|
|
7771
|
-
UnknownKeys extends string = Exclude<Extract<keyof Config, string>,
|
|
7967
|
+
UnknownKeys extends string = Exclude<Extract<keyof Config, string>, ActiveStateKey<States> | ChoiceStateKey<States>>
|
|
7772
7968
|
> = [UnknownKeys] extends [never] ? unknown : {
|
|
7773
7969
|
readonly [Key in UnknownKeys]: HandlerValidationError<
|
|
7774
7970
|
"Handler tree contains a state key that does not exist",
|
|
@@ -7937,7 +8133,8 @@ export declare namespace Machine {
|
|
|
7937
8133
|
StateId extends StateIdentifier<AllStates>,
|
|
7938
8134
|
Config
|
|
7939
8135
|
> = [HistoryIdentifier<AllStates>] extends [never] ? unknown
|
|
7940
|
-
: StateId extends RequiredHistoryInitializers<AllStates>
|
|
8136
|
+
: StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ?
|
|
8137
|
+
"initialize" extends keyof Config ? unknown : {
|
|
7941
8138
|
readonly initialize: HandlerValidationError<
|
|
7942
8139
|
"State requires initialize for shallow history restoration",
|
|
7943
8140
|
StateId
|
|
@@ -7998,10 +8195,10 @@ export declare namespace Machine {
|
|
|
7998
8195
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
7999
8196
|
StateId extends string,
|
|
8000
8197
|
Config,
|
|
8001
|
-
Incompatible = IncompatibleRuntime<
|
|
8198
|
+
Incompatible = keyof Config extends never ? never : IncompatibleRuntime<
|
|
8002
8199
|
ConfigServices<HandlerConfigPart<Config>>,
|
|
8003
8200
|
EventOf<Events>,
|
|
8004
|
-
|
|
8201
|
+
EmittedEventOf<Emits>
|
|
8005
8202
|
>
|
|
8006
8203
|
> = [Incompatible] extends [never] ? unknown
|
|
8007
8204
|
: HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>
|
|
@@ -8026,6 +8223,8 @@ export declare namespace Machine {
|
|
|
8026
8223
|
NodeConfig,
|
|
8027
8224
|
AvailableOutputStates
|
|
8028
8225
|
> extends infer Validation ? unknown extends Validation ? never
|
|
8226
|
+
: "" extends keyof AllStates ? StateId extends "" ? { readonly ""?: Validation }
|
|
8227
|
+
: { readonly ""?: { readonly states: HandlerValidationAtPath<StateId, Validation> } }
|
|
8029
8228
|
: HandlerValidationAtPath<StateId, Validation>
|
|
8030
8229
|
: never
|
|
8031
8230
|
|
|
@@ -8062,11 +8261,82 @@ export declare namespace Machine {
|
|
|
8062
8261
|
& HandlerUnknownStateKeyValidation<AllStates, "", Config>
|
|
8063
8262
|
& HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>
|
|
8064
8263
|
|
|
8264
|
+
type RootInitialTargetValidation<States extends StateSchemas, Config> =
|
|
8265
|
+
RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{ readonly "": Config }>> extends
|
|
8266
|
+
infer Required ? Types.UnionToIntersection<
|
|
8267
|
+
Required extends string ?
|
|
8268
|
+
HandlerConfigAtPath<{ readonly "": Config }, Required> extends infer NodeConfig ?
|
|
8269
|
+
[NodeConfig] extends [never] ? RootInitializeError<Required>
|
|
8270
|
+
: "initialize" extends keyof NodeConfig ? never
|
|
8271
|
+
: RootInitializeError<Required>
|
|
8272
|
+
: never :
|
|
8273
|
+
unknown
|
|
8274
|
+
> :
|
|
8275
|
+
unknown
|
|
8276
|
+
|
|
8277
|
+
type RootInitializeError<Path extends string> = Path extends "" ? {
|
|
8278
|
+
readonly initialize: HandlerValidationError<
|
|
8279
|
+
"State requires initialize because a transition enters its declared initial configuration",
|
|
8280
|
+
Path
|
|
8281
|
+
>
|
|
8282
|
+
} :
|
|
8283
|
+
{
|
|
8284
|
+
readonly states: HandlerValidationAtPath<Path, {
|
|
8285
|
+
readonly initialize: HandlerValidationError<
|
|
8286
|
+
"State requires initialize because a transition enters its declared initial configuration",
|
|
8287
|
+
Path
|
|
8288
|
+
>
|
|
8289
|
+
}>
|
|
8290
|
+
}
|
|
8291
|
+
|
|
8292
|
+
type RootHandlerValidation<
|
|
8293
|
+
States extends StateSchemas,
|
|
8294
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
8295
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
8296
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
8297
|
+
Config,
|
|
8298
|
+
OutputStates extends StateIdentifier<States>
|
|
8299
|
+
> =
|
|
8300
|
+
& HandlerNodeValidation<
|
|
8301
|
+
States,
|
|
8302
|
+
States[""],
|
|
8303
|
+
Events,
|
|
8304
|
+
InputEvents,
|
|
8305
|
+
Emits,
|
|
8306
|
+
Extract<"", StateNodeIdentifier<States>>,
|
|
8307
|
+
Config,
|
|
8308
|
+
OutputStates
|
|
8309
|
+
>
|
|
8310
|
+
& RootInitialTargetValidation<States, Config>
|
|
8311
|
+
& Types.UnionToIntersection<
|
|
8312
|
+
Exclude<StateNodeIdentifier<States>, ""> extends infer Path ?
|
|
8313
|
+
Path extends StateNodeIdentifier<States> ?
|
|
8314
|
+
HandlerConfigAtPath<{ readonly "": Config }, Path> extends infer NodeConfig ?
|
|
8315
|
+
[NodeConfig] extends [never] ? never :
|
|
8316
|
+
HandlerNodeValidation<
|
|
8317
|
+
States,
|
|
8318
|
+
HandlerNodeByPath<States, Path>,
|
|
8319
|
+
Events,
|
|
8320
|
+
InputEvents,
|
|
8321
|
+
Emits,
|
|
8322
|
+
Path,
|
|
8323
|
+
NodeConfig,
|
|
8324
|
+
OutputStates
|
|
8325
|
+
> extends infer Validation ? unknown extends Validation ? never
|
|
8326
|
+
: { readonly states: HandlerValidationAtPath<Path, Validation> }
|
|
8327
|
+
: never :
|
|
8328
|
+
never :
|
|
8329
|
+
never :
|
|
8330
|
+
never
|
|
8331
|
+
>
|
|
8332
|
+
|
|
8065
8333
|
type HandlerHasRequiredInitial<
|
|
8066
8334
|
AllStates extends StateSchemas,
|
|
8067
8335
|
StateId extends StateIdentifier<AllStates>,
|
|
8068
8336
|
Config
|
|
8069
|
-
> = StateId extends RequiredHistoryInitializers<AllStates>
|
|
8337
|
+
> = StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates>
|
|
8338
|
+
? "initialize" extends keyof Config ? true : false
|
|
8339
|
+
: true
|
|
8070
8340
|
|
|
8071
8341
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
8072
8342
|
readonly states: infer Children extends StateSchemas
|
|
@@ -8093,7 +8363,8 @@ export declare namespace Machine {
|
|
|
8093
8363
|
Node,
|
|
8094
8364
|
StateId extends StateIdentifier<AllStates>,
|
|
8095
8365
|
Config
|
|
8096
|
-
> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates>] extends [never] ?
|
|
8366
|
+
> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates> | RequiredInitializers<AllStates>] extends [never] ?
|
|
8367
|
+
StateId
|
|
8097
8368
|
: HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ?
|
|
8098
8369
|
HandlerHasRequiredHistoryDefaults<Node, Config> extends true ?
|
|
8099
8370
|
HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never
|
|
@@ -8166,7 +8437,7 @@ export declare namespace Machine {
|
|
|
8166
8437
|
ExcludeCompatibleRuntime<
|
|
8167
8438
|
R | HandlerTreeEvidence<AllStates, Config>["services"],
|
|
8168
8439
|
EventOf<Events>,
|
|
8169
|
-
|
|
8440
|
+
EmittedEventOf<Emits>
|
|
8170
8441
|
>,
|
|
8171
8442
|
InitialE,
|
|
8172
8443
|
InitialR,
|
|
@@ -8201,21 +8472,23 @@ export declare namespace Machine {
|
|
|
8201
8472
|
ParentEvents extends ReadonlyArray<TaggedSchema>
|
|
8202
8473
|
> {
|
|
8203
8474
|
<
|
|
8204
|
-
const Config
|
|
8205
|
-
States,
|
|
8206
|
-
States,
|
|
8207
|
-
Events,
|
|
8208
|
-
Emits,
|
|
8209
|
-
E,
|
|
8210
|
-
R,
|
|
8211
|
-
InputEvents,
|
|
8212
|
-
ParentEvents,
|
|
8213
|
-
""
|
|
8214
|
-
>
|
|
8475
|
+
const Config
|
|
8215
8476
|
>(
|
|
8216
8477
|
config:
|
|
8217
8478
|
& Config
|
|
8218
|
-
&
|
|
8479
|
+
& (Config extends (...args: never[]) => unknown ? never : unknown)
|
|
8480
|
+
& HandlerNode<
|
|
8481
|
+
States,
|
|
8482
|
+
States[""],
|
|
8483
|
+
Events,
|
|
8484
|
+
Emits,
|
|
8485
|
+
E,
|
|
8486
|
+
R,
|
|
8487
|
+
InputEvents,
|
|
8488
|
+
ParentEvents,
|
|
8489
|
+
Extract<"", StateNodeIdentifier<States>>
|
|
8490
|
+
>
|
|
8491
|
+
& RootHandlerValidation<
|
|
8219
8492
|
States,
|
|
8220
8493
|
Events,
|
|
8221
8494
|
InputEvents,
|
|
@@ -8223,15 +8496,10 @@ export declare namespace Machine {
|
|
|
8223
8496
|
NoInfer<Config>,
|
|
8224
8497
|
| OutputStates
|
|
8225
8498
|
| Extract<
|
|
8226
|
-
HandlerTreeEvidence<States, NoInfer<Config
|
|
8499
|
+
HandlerTreeEvidence<States, { readonly "": NoInfer<Config> }>["outputState"],
|
|
8227
8500
|
StateIdentifier<States>
|
|
8228
8501
|
>
|
|
8229
8502
|
>
|
|
8230
|
-
& ([StateIdentifier<States>] extends [UnhandledStates] ? HandlerInitialTargetValidation<
|
|
8231
|
-
States,
|
|
8232
|
-
NoInfer<Config>
|
|
8233
|
-
>
|
|
8234
|
-
: unknown)
|
|
8235
8503
|
): HandleTreeResult<
|
|
8236
8504
|
States,
|
|
8237
8505
|
Events,
|
|
@@ -8247,7 +8515,7 @@ export declare namespace Machine {
|
|
|
8247
8515
|
OutputStates,
|
|
8248
8516
|
InputEvents,
|
|
8249
8517
|
ParentEvents,
|
|
8250
|
-
Config
|
|
8518
|
+
{ readonly "": Config }
|
|
8251
8519
|
>
|
|
8252
8520
|
}
|
|
8253
8521
|
|
|
@@ -8307,11 +8575,11 @@ export declare namespace Machine {
|
|
|
8307
8575
|
> {
|
|
8308
8576
|
readonly entry?: (
|
|
8309
8577
|
context: StateActionContext<States, Events, Emits, StateId>,
|
|
8310
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
8578
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
8311
8579
|
) => StateActionResult<E, R>
|
|
8312
8580
|
readonly exit?: (
|
|
8313
8581
|
context: StateActionContext<States, Events, Emits, StateId>,
|
|
8314
|
-
enqueue: Enqueue<EventOf<Events>,
|
|
8582
|
+
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
8315
8583
|
) => StateActionResult<E, R>
|
|
8316
8584
|
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>
|
|
8317
8585
|
readonly always?: TransitionConfig<
|
|
@@ -8361,9 +8629,9 @@ export declare namespace Machine {
|
|
|
8361
8629
|
>
|
|
8362
8630
|
}
|
|
8363
8631
|
|
|
8364
|
-
type StateSource =
|
|
8632
|
+
type StateSource = State<any> | Machine.Any
|
|
8365
8633
|
|
|
8366
|
-
type StateSchemasOf<Source extends StateSource> = Source extends
|
|
8634
|
+
type StateSchemasOf<Source extends StateSource> = Source extends State<infer Node> ? { readonly "": Node }
|
|
8367
8635
|
: Source extends Machine.Any ? Machine.States<Source>
|
|
8368
8636
|
: never
|
|
8369
8637
|
|
|
@@ -8376,6 +8644,29 @@ type StateSchemasOf<Source extends StateSource> = Source extends Machine.Defined
|
|
|
8376
8644
|
*/
|
|
8377
8645
|
export type Snapshot<Source extends StateSource> = Machine.Snapshot<StateSchemasOf<Source>>
|
|
8378
8646
|
|
|
8647
|
+
/** Type utilities for logical snapshots, including snapshots carried by atom bridges. */
|
|
8648
|
+
/** Typed traversal of root and child logical snapshots.
|
|
8649
|
+
* @category utility types
|
|
8650
|
+
* @since 0.32.0
|
|
8651
|
+
*/
|
|
8652
|
+
export declare namespace Snapshot {
|
|
8653
|
+
/** Every active node represented by a logical snapshot type. */
|
|
8654
|
+
export type Node<State> = State extends { readonly path: string; readonly value: unknown } ?
|
|
8655
|
+
| State
|
|
8656
|
+
| (State extends { readonly state: infer Child } ? Node<Child>
|
|
8657
|
+
: State extends { readonly states: infer Regions } ? Node<Regions[keyof Regions]>
|
|
8658
|
+
: never) :
|
|
8659
|
+
never
|
|
8660
|
+
/** Every valid absolute path in a logical snapshot type. */
|
|
8661
|
+
export type Path<State> = Node<State> extends infer Current
|
|
8662
|
+
? Current extends { readonly path: infer Path extends string } ? Path : never
|
|
8663
|
+
: never
|
|
8664
|
+
/** The node at one absolute path. Runtime access can still be inactive. */
|
|
8665
|
+
export type At<State, Path extends Snapshot.Path<State>> = Node<State> extends infer Current
|
|
8666
|
+
? Current extends { readonly path: Path } ? Current : never
|
|
8667
|
+
: never
|
|
8668
|
+
}
|
|
8669
|
+
|
|
8379
8670
|
/**
|
|
8380
8671
|
* Extracts the decoded value owned by a schema-backed state path.
|
|
8381
8672
|
*
|
|
@@ -8395,7 +8686,7 @@ export type Value<
|
|
|
8395
8686
|
*
|
|
8396
8687
|
* The source may be the object returned by {@link states} or a machine
|
|
8397
8688
|
* definition. This is the type-level counterpart of
|
|
8398
|
-
* `
|
|
8689
|
+
* `State.getSnapshot`.
|
|
8399
8690
|
*
|
|
8400
8691
|
* @category utility types
|
|
8401
8692
|
* @since 0.18.0
|
|
@@ -8480,10 +8771,10 @@ export const isFinal: <
|
|
|
8480
8771
|
* }
|
|
8481
8772
|
* })
|
|
8482
8773
|
*
|
|
8483
|
-
* const States = Machine.
|
|
8774
|
+
* const States = Machine.state({ initial: "slot1", states: {
|
|
8484
8775
|
* slot1: TradingSlot,
|
|
8485
8776
|
* slot2: TradingSlot
|
|
8486
|
-
* })
|
|
8777
|
+
* } })
|
|
8487
8778
|
* ```
|
|
8488
8779
|
*
|
|
8489
8780
|
* @category constructors
|
|
@@ -8491,47 +8782,8 @@ export const isFinal: <
|
|
|
8491
8782
|
*/
|
|
8492
8783
|
export const state: StateConstructor = internal.state as StateConstructor
|
|
8493
8784
|
|
|
8494
|
-
/**
|
|
8495
|
-
* Defines the complete state tree while preserving literal state paths.
|
|
8496
|
-
*
|
|
8497
|
-
* **When to use**
|
|
8498
|
-
*
|
|
8499
|
-
* Use when you want to pass a state tree to `make` and also get typed
|
|
8500
|
-
* snapshot matching and access helpers.
|
|
8501
|
-
*
|
|
8502
|
-
* **Details**
|
|
8503
|
-
*
|
|
8504
|
-
* The returned `states` property is an immutable structural capture of the
|
|
8505
|
-
* supplied tree.
|
|
8506
|
-
* `Machine.make` derives its initial target selector from that tree and
|
|
8507
|
-
* enforces compound and parallel initial-state rules. Active nodes may omit
|
|
8508
|
-
* `schema` when they own no value and still participate fully in targeting,
|
|
8509
|
-
* matching, and snapshots.
|
|
8510
|
-
*
|
|
8511
|
-
* **Example** (Atomic initial snapshot)
|
|
8512
|
-
*
|
|
8513
|
-
* ```ts
|
|
8514
|
-
* import { Schema } from "effect"
|
|
8515
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
8516
|
-
*
|
|
8517
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
8518
|
-
*
|
|
8519
|
-
* const States = Machine.states({ idle: Idle })
|
|
8520
|
-
*
|
|
8521
|
-
* Machine.make({
|
|
8522
|
-
* states: States.states,
|
|
8523
|
-
* events: Machine.events(),
|
|
8524
|
-
* initial: (to) => to.idle().resolve(({ target }) => target.from())
|
|
8525
|
-
* })
|
|
8526
|
-
* ```
|
|
8527
|
-
*
|
|
8528
|
-
* @category constructors
|
|
8529
|
-
* @since 0.4.0
|
|
8530
|
-
*/
|
|
8531
|
-
export const states: StatesConstructor = internal.states
|
|
8532
|
-
|
|
8533
8785
|
type MakeConfig<
|
|
8534
|
-
|
|
8786
|
+
Root extends Machine.StateNodeConfig,
|
|
8535
8787
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8536
8788
|
Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8537
8789
|
Input extends Schema.Top,
|
|
@@ -8542,8 +8794,8 @@ type MakeConfig<
|
|
|
8542
8794
|
> = {
|
|
8543
8795
|
/** Stable definition identifier used by inspection and visualization. */
|
|
8544
8796
|
readonly id?: string
|
|
8545
|
-
/** State topology and value schemas,
|
|
8546
|
-
readonly
|
|
8797
|
+
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
8798
|
+
readonly root: { readonly [StateTypeId]: typeof StateTypeId; readonly node: Root }
|
|
8547
8799
|
/** Public events accepted by independently running machine references. */
|
|
8548
8800
|
readonly events:
|
|
8549
8801
|
& Machine.EventProtocol<"public", InputEvents>
|
|
@@ -8561,12 +8813,10 @@ type MakeConfig<
|
|
|
8561
8813
|
readonly parent?: ParentDeclaration
|
|
8562
8814
|
/** Schema used to decode input before initial-state construction. */
|
|
8563
8815
|
readonly input?: Input
|
|
8564
|
-
/** Target-first declaration that constructs the initial active configuration. */
|
|
8565
|
-
readonly initial: unknown
|
|
8566
8816
|
}
|
|
8567
8817
|
|
|
8568
8818
|
type MakeResult<
|
|
8569
|
-
|
|
8819
|
+
Root extends Machine.StateNodeConfig,
|
|
8570
8820
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8571
8821
|
Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8572
8822
|
Input extends Schema.Top,
|
|
@@ -8575,23 +8825,29 @@ type MakeResult<
|
|
|
8575
8825
|
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8576
8826
|
ParentDeclaration extends Parent.Any | undefined
|
|
8577
8827
|
> = Definition<
|
|
8578
|
-
|
|
8828
|
+
{ readonly "": Root },
|
|
8579
8829
|
readonly [...InputEvents, ...InternalEvents],
|
|
8580
8830
|
Input,
|
|
8581
8831
|
InitialE,
|
|
8582
8832
|
InitialR,
|
|
8583
|
-
Machine.FinalStateFromDefinition<
|
|
8584
|
-
Machine.TerminalOutput<
|
|
8833
|
+
Machine.FinalStateFromDefinition<{ readonly "": Root }>,
|
|
8834
|
+
Machine.TerminalOutput<{ readonly "": Root }>,
|
|
8585
8835
|
Emits,
|
|
8586
8836
|
InputEvents,
|
|
8587
8837
|
Machine.ParentEventsOf<ParentDeclaration>
|
|
8588
8838
|
>
|
|
8589
8839
|
|
|
8840
|
+
type RootInitialization<Root extends Machine.StateNodeConfig, Input> =
|
|
8841
|
+
& { readonly initialConfiguration?: never }
|
|
8842
|
+
& (Machine.NodeSchema<Root> extends never ? { readonly initial?: Machine.RootInitialBuilderInput<Root, Input> }
|
|
8843
|
+
: {} extends NodeMakeInput<Root> ? { readonly initial?: Machine.RootInitialBuilderInput<Root, Input> }
|
|
8844
|
+
: { readonly initial: Machine.RootInitialBuilderInput<Root, Input> })
|
|
8845
|
+
|
|
8590
8846
|
/** @inline */
|
|
8591
8847
|
interface Make {
|
|
8592
|
-
/** @param config Complete
|
|
8848
|
+
/** @param config Complete starting configuration, including root and descendant values. */
|
|
8593
8849
|
<
|
|
8594
|
-
const
|
|
8850
|
+
const Root extends Machine.StateNodeConfig,
|
|
8595
8851
|
const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8596
8852
|
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8597
8853
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
@@ -8601,16 +8857,29 @@ interface Make {
|
|
|
8601
8857
|
const ParentDeclaration extends Parent.Any | undefined = undefined
|
|
8602
8858
|
>(
|
|
8603
8859
|
config:
|
|
8604
|
-
&
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8860
|
+
& MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>
|
|
8861
|
+
& {
|
|
8862
|
+
/** Mutually exclusive with a complete initial configuration. */
|
|
8863
|
+
readonly initial?: never
|
|
8864
|
+
/** Constructs the complete initial root configuration, overriding child defaults. */
|
|
8865
|
+
readonly initialConfiguration: Machine.RootConfigurationBuilderInput<
|
|
8866
|
+
NoInfer<Root>,
|
|
8867
|
+
Input["Type"]
|
|
8868
|
+
>
|
|
8869
|
+
}
|
|
8870
|
+
): MakeResult<
|
|
8871
|
+
Root & { readonly "~effect/Machine/ExplicitInitial": true },
|
|
8872
|
+
InputEvents,
|
|
8873
|
+
Emits,
|
|
8874
|
+
Input,
|
|
8875
|
+
InitialE,
|
|
8876
|
+
InitialR,
|
|
8877
|
+
InternalEvents,
|
|
8878
|
+
ParentDeclaration
|
|
8879
|
+
>
|
|
8880
|
+
/** @param config Complete schema-first machine definition. */
|
|
8612
8881
|
<
|
|
8613
|
-
const
|
|
8882
|
+
const Root extends Machine.StateNodeConfig,
|
|
8614
8883
|
const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8615
8884
|
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8616
8885
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
@@ -8620,12 +8889,21 @@ interface Make {
|
|
|
8620
8889
|
const ParentDeclaration extends Parent.Any | undefined = undefined
|
|
8621
8890
|
>(
|
|
8622
8891
|
config:
|
|
8623
|
-
&
|
|
8624
|
-
|
|
8625
|
-
"
|
|
8892
|
+
& MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>
|
|
8893
|
+
& Exclude<
|
|
8894
|
+
RootInitialization<NoInfer<Root>, Input["Type"]>,
|
|
8895
|
+
{ readonly initialConfiguration: unknown }
|
|
8626
8896
|
>
|
|
8627
|
-
|
|
8628
|
-
|
|
8897
|
+
): MakeResult<
|
|
8898
|
+
Root,
|
|
8899
|
+
InputEvents,
|
|
8900
|
+
Emits,
|
|
8901
|
+
Input,
|
|
8902
|
+
InitialE,
|
|
8903
|
+
InitialR,
|
|
8904
|
+
InternalEvents,
|
|
8905
|
+
ParentDeclaration
|
|
8906
|
+
>
|
|
8629
8907
|
}
|
|
8630
8908
|
|
|
8631
8909
|
/**
|
|
@@ -8667,30 +8945,30 @@ interface Make {
|
|
|
8667
8945
|
* by: Schema.Number
|
|
8668
8946
|
* }) {}
|
|
8669
8947
|
*
|
|
8670
|
-
* const States = Machine.
|
|
8671
|
-
* const Events = Machine.
|
|
8948
|
+
* const States = Machine.state({ initial: "Count", states: { Count } })
|
|
8949
|
+
* const Events = Machine.eventsFromSchemas(Increment)
|
|
8672
8950
|
*
|
|
8673
8951
|
* const counter = Machine.make({
|
|
8674
|
-
*
|
|
8952
|
+
* root: States,
|
|
8675
8953
|
* events: Events,
|
|
8676
|
-
*
|
|
8677
|
-
* }).handle({
|
|
8954
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Count.decoded(new Count({ value: 0 }))))
|
|
8955
|
+
* }).handle({ states: {
|
|
8678
8956
|
* Count: {
|
|
8679
8957
|
* on: {
|
|
8680
8958
|
* Increment: (to) =>
|
|
8681
|
-
* to.
|
|
8959
|
+
* to.branch.Count().resolve(({ event, state, target }) =>
|
|
8682
8960
|
* target.decoded(new Count({ value: state.value + event.by })))
|
|
8683
8961
|
* }
|
|
8684
8962
|
* }
|
|
8685
|
-
* })
|
|
8963
|
+
* } })
|
|
8686
8964
|
* ```
|
|
8687
8965
|
*
|
|
8688
|
-
* @see {@link
|
|
8966
|
+
* @see {@link state} for typed state-tree helpers.
|
|
8689
8967
|
* @inlineType MakeConfig
|
|
8690
8968
|
* @category constructors
|
|
8691
8969
|
* @since 0.4.0
|
|
8692
8970
|
*/
|
|
8693
|
-
export const make: Make = internal.make
|
|
8971
|
+
export const make: Make = internal.make as unknown as Make
|
|
8694
8972
|
|
|
8695
8973
|
/**
|
|
8696
8974
|
* Extracts the decoded event union carried by an event protocol descriptor.
|
|
@@ -8714,7 +8992,7 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
|
|
|
8714
8992
|
* **Example**
|
|
8715
8993
|
*
|
|
8716
8994
|
* ```ts
|
|
8717
|
-
* export const Event = Machine.
|
|
8995
|
+
* export const Event = Machine.eventsFromSchemas(
|
|
8718
8996
|
* Schema.TaggedUnion({
|
|
8719
8997
|
* Increment: { by: Schema.Number },
|
|
8720
8998
|
* Reset: {}
|
|
@@ -8727,10 +9005,41 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
|
|
|
8727
9005
|
* @category constructors
|
|
8728
9006
|
* @since 0.10.0
|
|
8729
9007
|
*/
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
9008
|
+
type EventFieldsSchemas<Cases extends Readonly<Record<string, Schema.Struct.Fields>>> = keyof Cases extends never
|
|
9009
|
+
? readonly []
|
|
9010
|
+
: readonly [
|
|
9011
|
+
Extract<
|
|
9012
|
+
Schema.TaggedUnion<{ readonly [Tag in keyof Cases & string]: Schema.TaggedStruct<Tag, Cases[Tag]> }>,
|
|
9013
|
+
Machine.TaggedSchema
|
|
9014
|
+
>
|
|
9015
|
+
]
|
|
9016
|
+
type ValidateEventFields<Cases> = {
|
|
9017
|
+
readonly [Tag in keyof Cases]: "_tag" extends keyof Cases[Tag]
|
|
9018
|
+
? EventProtocolError<"Event fields cannot declare _tag", Extract<Tag, PropertyKey>>
|
|
9019
|
+
: unknown
|
|
9020
|
+
}
|
|
9021
|
+
|
|
9022
|
+
/** Defines a public event protocol from tagged field records.
|
|
9023
|
+
*
|
|
9024
|
+
* ```ts
|
|
9025
|
+
* const Events = Machine.events({ Increment: { by: Schema.Number }, Reset: {} })
|
|
9026
|
+
* const increment = Events.Increment({ by: 1 })
|
|
9027
|
+
* ```
|
|
9028
|
+
*
|
|
9029
|
+
* Constructors defer schema validation until delivery. Use eventsFromSchemas
|
|
9030
|
+
* when importing existing tagged schemas or protocol descriptors.
|
|
9031
|
+
* @category constructors
|
|
9032
|
+
* @since 0.32.0
|
|
9033
|
+
*/
|
|
9034
|
+
export const events: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(
|
|
9035
|
+
cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"public", EventFieldsSchemas<Cases>>
|
|
9036
|
+
) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>> = internal.eventsFromFields as any
|
|
9037
|
+
|
|
9038
|
+
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
9039
|
+
* @category constructors
|
|
9040
|
+
* @since 0.32.0
|
|
9041
|
+
*/
|
|
9042
|
+
export const eventsFromSchemas: {
|
|
8734
9043
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(
|
|
8735
9044
|
...inputs: Inputs & ValidateEventProtocolBuilder<"public", Inputs>
|
|
8736
9045
|
): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>
|
|
@@ -8774,7 +9083,7 @@ export const optionalParent: <const Events extends ReadonlyArray<Machine.TaggedS
|
|
|
8774
9083
|
* **Example**
|
|
8775
9084
|
*
|
|
8776
9085
|
* ```ts
|
|
8777
|
-
* const Internal = Machine.
|
|
9086
|
+
* const Internal = Machine.internalEventsFromSchemas(
|
|
8778
9087
|
* Schema.TaggedUnion({
|
|
8779
9088
|
* Loaded: { value: Schema.String },
|
|
8780
9089
|
* Failed: { message: Schema.String }
|
|
@@ -8789,10 +9098,18 @@ export const optionalParent: <const Events extends ReadonlyArray<Machine.TaggedS
|
|
|
8789
9098
|
* @category constructors
|
|
8790
9099
|
* @since 0.10.0
|
|
8791
9100
|
*/
|
|
8792
|
-
export const internalEvents:
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
9101
|
+
export const internalEvents: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(
|
|
9102
|
+
cases:
|
|
9103
|
+
& Cases
|
|
9104
|
+
& ValidateEventFields<NoInfer<Cases>>
|
|
9105
|
+
& ValidateEventProtocolBuilder<"internal", EventFieldsSchemas<Cases>>
|
|
9106
|
+
) => Machine.EventProtocol<"internal", EventFieldsSchemas<Cases>> = internal.internalEventsFromFields as any
|
|
9107
|
+
|
|
9108
|
+
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
9109
|
+
* @category constructors
|
|
9110
|
+
* @since 0.32.0
|
|
9111
|
+
*/
|
|
9112
|
+
export const internalEventsFromSchemas: {
|
|
8796
9113
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(
|
|
8797
9114
|
...inputs: Inputs & ValidateEventProtocolBuilder<"internal", Inputs>
|
|
8798
9115
|
): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>
|
|
@@ -8807,7 +9124,7 @@ export const internalEvents: {
|
|
|
8807
9124
|
* **Example**
|
|
8808
9125
|
*
|
|
8809
9126
|
* ```ts
|
|
8810
|
-
* const Emitted = Machine.
|
|
9127
|
+
* const Emitted = Machine.emittedEventsFromSchemas(
|
|
8811
9128
|
* Schema.TaggedUnion({
|
|
8812
9129
|
* Saved: { id: Schema.String }
|
|
8813
9130
|
* })
|
|
@@ -8818,10 +9135,18 @@ export const internalEvents: {
|
|
|
8818
9135
|
* @category constructors
|
|
8819
9136
|
* @since 0.10.0
|
|
8820
9137
|
*/
|
|
8821
|
-
export const emittedEvents:
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
9138
|
+
export const emittedEvents: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(
|
|
9139
|
+
cases:
|
|
9140
|
+
& Cases
|
|
9141
|
+
& ValidateEventFields<NoInfer<Cases>>
|
|
9142
|
+
& ValidateEventProtocolBuilder<"emitted", EventFieldsSchemas<Cases>>
|
|
9143
|
+
) => Machine.EventProtocol<"emitted", EventFieldsSchemas<Cases>> = internal.emittedEventsFromFields as any
|
|
9144
|
+
|
|
9145
|
+
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
9146
|
+
* @category constructors
|
|
9147
|
+
* @since 0.32.0
|
|
9148
|
+
*/
|
|
9149
|
+
export const emittedEventsFromSchemas: {
|
|
8825
9150
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(
|
|
8826
9151
|
...inputs: Inputs & ValidateEventProtocolBuilder<"emitted", Inputs>
|
|
8827
9152
|
): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>
|
|
@@ -8860,12 +9185,12 @@ export const emittedEvents: {
|
|
|
8860
9185
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8861
9186
|
*
|
|
8862
9187
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
8863
|
-
* const States = Machine.
|
|
9188
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
8864
9189
|
* const machine = Machine.make({
|
|
8865
|
-
*
|
|
8866
|
-
* events: Machine.
|
|
8867
|
-
*
|
|
8868
|
-
* }).handle({ Idle: {} })
|
|
9190
|
+
* root: States,
|
|
9191
|
+
* events: Machine.eventsFromSchemas(),
|
|
9192
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
9193
|
+
* }).handle({ states: { Idle: {} } })
|
|
8869
9194
|
*
|
|
8870
9195
|
* const encoded = Effect.gen(function*() {
|
|
8871
9196
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -8942,12 +9267,12 @@ export const encodeSnapshot: <
|
|
|
8942
9267
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8943
9268
|
*
|
|
8944
9269
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
8945
|
-
* const States = Machine.
|
|
9270
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
8946
9271
|
* const machine = Machine.make({
|
|
8947
|
-
*
|
|
8948
|
-
* events: Machine.
|
|
8949
|
-
*
|
|
8950
|
-
* }).handle({ Idle: {} })
|
|
9272
|
+
* root: States,
|
|
9273
|
+
* events: Machine.eventsFromSchemas(),
|
|
9274
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
9275
|
+
* }).handle({ states: { Idle: {} } })
|
|
8951
9276
|
*
|
|
8952
9277
|
* const roundTrip = Effect.gen(function*() {
|
|
8953
9278
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -9051,12 +9376,12 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
9051
9376
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9052
9377
|
*
|
|
9053
9378
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
9054
|
-
* const States = Machine.
|
|
9379
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
9055
9380
|
* const machine = Machine.make({
|
|
9056
|
-
*
|
|
9057
|
-
* events: Machine.
|
|
9058
|
-
*
|
|
9059
|
-
* }).handle({ Idle: {} })
|
|
9381
|
+
* root: States,
|
|
9382
|
+
* events: Machine.eventsFromSchemas(),
|
|
9383
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
9384
|
+
* }).handle({ states: { Idle: {} } })
|
|
9060
9385
|
*
|
|
9061
9386
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
9062
9387
|
* ```
|
|
@@ -9108,7 +9433,7 @@ export const planInitial: <
|
|
|
9108
9433
|
readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>
|
|
9109
9434
|
readonly state: Machine.Snapshot<States>
|
|
9110
9435
|
readonly commands: ReadonlyArray<Command>
|
|
9111
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
9436
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
|
|
9112
9437
|
readonly microsteps: ReadonlyArray<{
|
|
9113
9438
|
readonly next: Machine.Snapshot<States>
|
|
9114
9439
|
readonly event: Machine.EventOf<Events> | InitialEvent
|
|
@@ -9121,7 +9446,7 @@ export const planInitial: <
|
|
|
9121
9446
|
>
|
|
9122
9447
|
readonly commands: ReadonlyArray<Command>
|
|
9123
9448
|
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>
|
|
9124
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
9449
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
|
|
9125
9450
|
readonly exitPaths: ReadonlyArray<string>
|
|
9126
9451
|
readonly entryPaths: ReadonlyArray<string>
|
|
9127
9452
|
readonly changed: boolean
|
|
@@ -9312,23 +9637,38 @@ export const enabled: <
|
|
|
9312
9637
|
* they accept the event. Any commands, emissions, or raised events collected
|
|
9313
9638
|
* during that check are discarded.
|
|
9314
9639
|
*
|
|
9315
|
-
* Event input is decoded through the machine's public event
|
|
9316
|
-
* input fails with `MachineSchemaDecodeError`. Final snapshots and valid events
|
|
9640
|
+
* Event input is decoded through the machine's public and internal event protocols.
|
|
9641
|
+
* Invalid input fails with `MachineSchemaDecodeError`. Final snapshots and valid events
|
|
9317
9642
|
* with no accepting handler return `false`.
|
|
9318
9643
|
*
|
|
9319
9644
|
* **Gotchas**
|
|
9320
9645
|
*
|
|
9321
9646
|
* This query does not execute transitions or stabilize the resulting machine.
|
|
9322
9647
|
* It does not run entry, exit, always, completion, child lifecycle, or command
|
|
9323
|
-
* effects. A `true` result therefore describes event acceptance only
|
|
9648
|
+
* effects. A `true` result therefore describes event acceptance only, for this
|
|
9649
|
+
* snapshot. It does not guarantee acceptance after the machine advances.
|
|
9650
|
+
*
|
|
9651
|
+
* This Effect can also be used by machine effects to query internal events.
|
|
9652
|
+
* Synchronous transition resolvers cannot execute it. Querying an internal event
|
|
9653
|
+
* does not make that event available to `MachineRef.send`.
|
|
9324
9654
|
*
|
|
9325
9655
|
* **Example**
|
|
9326
9656
|
*
|
|
9327
9657
|
* ```ts
|
|
9328
|
-
*
|
|
9658
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
9659
|
+
* import { Effect, Schema } from "effect"
|
|
9329
9660
|
*
|
|
9330
|
-
* const
|
|
9331
|
-
*
|
|
9661
|
+
* const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
|
|
9662
|
+
* const machine = Machine.make({
|
|
9663
|
+
* root: Machine.state({ initial: "Idle", states: { Idle: {} } }),
|
|
9664
|
+
* events: Machine.eventsFromSchemas(),
|
|
9665
|
+
* internalEvents,
|
|
9666
|
+
* initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.from()))
|
|
9667
|
+
* }).handle({ states: { Idle: { on: { Loaded: (to) => to.none } } } })
|
|
9668
|
+
*
|
|
9669
|
+
* export const canLoad = Effect.gen(function*() {
|
|
9670
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
9671
|
+
* return yield* Machine.can(machine, initial.state, internalEvents.Loaded())
|
|
9332
9672
|
* })
|
|
9333
9673
|
* ```
|
|
9334
9674
|
*
|
|
@@ -9373,7 +9713,7 @@ export const can: {
|
|
|
9373
9713
|
& Machine.RootCompatible<ParentEvents>
|
|
9374
9714
|
): (
|
|
9375
9715
|
state: Machine.Snapshot<States>,
|
|
9376
|
-
event: Machine.EventInputOf<
|
|
9716
|
+
event: Machine.EventInputOf<Events>
|
|
9377
9717
|
) => Effect.Effect<boolean, MachineSchemaDecodeError>
|
|
9378
9718
|
<
|
|
9379
9719
|
const States extends Machine.StateSchemas,
|
|
@@ -9411,12 +9751,12 @@ export const can: {
|
|
|
9411
9751
|
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
9412
9752
|
& Machine.RootCompatible<ParentEvents>,
|
|
9413
9753
|
state: Machine.Snapshot<States>,
|
|
9414
|
-
event: Machine.EventInputOf<
|
|
9754
|
+
event: Machine.EventInputOf<Events>
|
|
9415
9755
|
): Effect.Effect<boolean, MachineSchemaDecodeError>
|
|
9416
9756
|
} = internal.can as any
|
|
9417
9757
|
|
|
9418
9758
|
/**
|
|
9419
|
-
*
|
|
9759
|
+
* Returns an Effect that plans the next state snapshot without running command effects.
|
|
9420
9760
|
*
|
|
9421
9761
|
* **Details**
|
|
9422
9762
|
*
|
|
@@ -9441,20 +9781,20 @@ export const can: {
|
|
|
9441
9781
|
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
|
|
9442
9782
|
* class On extends Schema.TaggedClass<On>("On")("On", {}) {}
|
|
9443
9783
|
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
|
|
9444
|
-
* const States = Machine.
|
|
9784
|
+
* const States = Machine.state({ initial: "Off", states: { Off, On } })
|
|
9445
9785
|
* const machine = Machine.make({
|
|
9446
|
-
*
|
|
9447
|
-
* events: Machine.
|
|
9448
|
-
*
|
|
9449
|
-
* }).handle({
|
|
9786
|
+
* root: States,
|
|
9787
|
+
* events: Machine.eventsFromSchemas(Toggle),
|
|
9788
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Off.from()))
|
|
9789
|
+
* }).handle({ states: {
|
|
9450
9790
|
* Off: {
|
|
9451
9791
|
* on: {
|
|
9452
9792
|
* Toggle: (to) =>
|
|
9453
|
-
* to.
|
|
9793
|
+
* to.branch.On().resolve(({ target }) => target.from())
|
|
9454
9794
|
* }
|
|
9455
9795
|
* },
|
|
9456
9796
|
* On: {}
|
|
9457
|
-
* })
|
|
9797
|
+
* } })
|
|
9458
9798
|
*
|
|
9459
9799
|
* const nextState = Effect.gen(function*() {
|
|
9460
9800
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -9506,9 +9846,10 @@ export const plan: <
|
|
|
9506
9846
|
event: Machine.EventInputOf<InputEvents>
|
|
9507
9847
|
) => Effect.Effect<
|
|
9508
9848
|
& {
|
|
9849
|
+
readonly event: Machine.EventOf<InputEvents>
|
|
9509
9850
|
readonly next: Machine.Snapshot<States>
|
|
9510
9851
|
readonly commands: ReadonlyArray<Command>
|
|
9511
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
9852
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
|
|
9512
9853
|
readonly microsteps: ReadonlyArray<{
|
|
9513
9854
|
readonly next: Machine.Snapshot<States>
|
|
9514
9855
|
readonly event: Machine.EventOf<Events> | InitialEvent
|
|
@@ -9521,7 +9862,7 @@ export const plan: <
|
|
|
9521
9862
|
>
|
|
9522
9863
|
readonly commands: ReadonlyArray<Command>
|
|
9523
9864
|
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>
|
|
9524
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
9865
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
|
|
9525
9866
|
readonly exitPaths: ReadonlyArray<string>
|
|
9526
9867
|
readonly entryPaths: ReadonlyArray<string>
|
|
9527
9868
|
readonly changed: boolean
|
|
@@ -9799,7 +10140,7 @@ export const prepare: <
|
|
|
9799
10140
|
ExcludeCompatibleRuntime<
|
|
9800
10141
|
ExecutionServices<InitialR | R>,
|
|
9801
10142
|
Machine.EventOf<Events>,
|
|
9802
|
-
Machine.
|
|
10143
|
+
Machine.EmittedEventOf<Emits>
|
|
9803
10144
|
>
|
|
9804
10145
|
>
|
|
9805
10146
|
> = internal.prepare as any
|
|
@@ -9833,12 +10174,12 @@ export const prepare: <
|
|
|
9833
10174
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9834
10175
|
*
|
|
9835
10176
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
9836
|
-
* const States = Machine.
|
|
10177
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
9837
10178
|
* const machine = Machine.make({
|
|
9838
|
-
*
|
|
9839
|
-
* events: Machine.
|
|
9840
|
-
*
|
|
9841
|
-
* }).handle({ Idle: {} })
|
|
10179
|
+
* root: States,
|
|
10180
|
+
* events: Machine.eventsFromSchemas(),
|
|
10181
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
10182
|
+
* }).handle({ states: { Idle: {} } })
|
|
9842
10183
|
*
|
|
9843
10184
|
* const state = Effect.gen(function*() {
|
|
9844
10185
|
* const ref = yield* Machine.start(machine)
|
|
@@ -9909,7 +10250,7 @@ export const start: <
|
|
|
9909
10250
|
ExcludeCompatibleRuntime<
|
|
9910
10251
|
ExecutionServices<InitialR | R>,
|
|
9911
10252
|
Machine.EventOf<Events>,
|
|
9912
|
-
Machine.
|
|
10253
|
+
Machine.EmittedEventOf<Emits>
|
|
9913
10254
|
>
|
|
9914
10255
|
> = internal.start as any
|
|
9915
10256
|
|
|
@@ -9944,12 +10285,12 @@ export const start: <
|
|
|
9944
10285
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9945
10286
|
*
|
|
9946
10287
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
9947
|
-
* const States = Machine.
|
|
10288
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
9948
10289
|
* const machine = Machine.make({
|
|
9949
|
-
*
|
|
9950
|
-
* events: Machine.
|
|
9951
|
-
*
|
|
9952
|
-
* }).handle({ Idle: {} })
|
|
10290
|
+
* root: States,
|
|
10291
|
+
* events: Machine.eventsFromSchemas(),
|
|
10292
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
10293
|
+
* }).handle({ states: { Idle: {} } })
|
|
9953
10294
|
*
|
|
9954
10295
|
* const resumed = Effect.gen(function*() {
|
|
9955
10296
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -10016,6 +10357,6 @@ export const resume: <
|
|
|
10016
10357
|
ExcludeCompatibleRuntime<
|
|
10017
10358
|
ExecutionServices<R>,
|
|
10018
10359
|
Machine.EventOf<Events>,
|
|
10019
|
-
Machine.
|
|
10360
|
+
Machine.EmittedEventOf<Emits>
|
|
10020
10361
|
>
|
|
10021
10362
|
> = internal.resume as any
|