@typeonce/effect-machine 0.34.0 → 0.36.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 +98 -33
- package/dist/Machine.d.ts +408 -483
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +126 -87
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/command.d.ts +0 -1
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/command.js +0 -14
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +0 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +15 -21
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/construction.d.ts +9 -0
- package/dist/internal/machine/construction.d.ts.map +1 -0
- package/dist/internal/machine/construction.js +132 -0
- package/dist/internal/machine/construction.js.map +1 -0
- package/dist/internal/machine/declaration.d.ts +1 -0
- package/dist/internal/machine/declaration.d.ts.map +1 -1
- package/dist/internal/machine/declaration.js +3 -8
- package/dist/internal/machine/declaration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +21 -27
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +2 -3
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/implementation.js.map +1 -1
- package/dist/internal/machine/initialDeclaration.d.ts +14 -0
- package/dist/internal/machine/initialDeclaration.d.ts.map +1 -0
- package/dist/internal/machine/initialDeclaration.js +137 -0
- package/dist/internal/machine/initialDeclaration.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +0 -2
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +101 -282
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +8 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +86 -82
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +1 -1
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +1 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +1 -13
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/targetReference.d.ts.map +1 -1
- package/dist/internal/machine/targetReference.js +14 -4
- package/dist/internal/machine/targetReference.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +6 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +3 -2
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +51 -82
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +7 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +105 -73
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +105 -73
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +13 -8
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +13 -8
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +41 -24
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +41 -24
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +37 -34
- package/docs/root-api.md +143 -190
- package/package.json +1 -1
- package/src/Machine.ts +631 -872
- package/src/internal/machine/command.ts +0 -16
- package/src/internal/machine/configuration.ts +13 -30
- package/src/internal/machine/construction.ts +147 -0
- package/src/internal/machine/declaration.ts +4 -7
- package/src/internal/machine/executionPlan.ts +20 -25
- package/src/internal/machine/implementation.ts +2 -3
- package/src/internal/machine/initialDeclaration.ts +157 -0
- package/src/internal/machine/machine.ts +118 -396
- package/src/internal/machine/planner.ts +97 -99
- package/src/internal/machine/protocol.ts +3 -3
- package/src/internal/machine/stateDefinition.ts +1 -15
- package/src/internal/machine/targetReference.ts +19 -4
- package/src/internal/machine/topology.ts +7 -2
- package/src/internal/testing/machine/finiteModel.ts +60 -132
- package/src/internal/testing/machine/verification.ts +7 -1
- package/src/testing/MachineTest.ts +105 -73
- package/src/unstable/cluster/ClusterMachine.ts +13 -8
- package/src/unstable/reactivity/AtomMachine.ts +41 -24
- package/dist/internal/machine/targetBuilder.d.ts +0 -16
- package/dist/internal/machine/targetBuilder.d.ts.map +0 -1
- package/dist/internal/machine/targetBuilder.js +0 -333
- package/dist/internal/machine/targetBuilder.js.map +0 -1
- package/src/internal/machine/targetBuilder.ts +0 -525
package/src/Machine.ts
CHANGED
|
@@ -120,20 +120,19 @@ type IsAny<A> = 0 extends (1 & A) ? true : false
|
|
|
120
120
|
* ```ts
|
|
121
121
|
* import { Machine } from "@typeonce/effect-machine"
|
|
122
122
|
* import { Schema } from "effect"
|
|
123
|
-
*
|
|
124
123
|
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
125
124
|
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
126
125
|
* const targets = Machine.targets(Root)
|
|
127
126
|
* export const counter = Machine.make({
|
|
128
127
|
* root: Root,
|
|
129
|
-
* events
|
|
130
|
-
* initial: (root) => root.from(() => ({ count: 0 }))
|
|
128
|
+
* events
|
|
131
129
|
* }).handle({
|
|
130
|
+
* root: () => ({ count: 0 }),
|
|
132
131
|
* on: {
|
|
133
132
|
* Add: {
|
|
134
133
|
* update: targets.root,
|
|
135
134
|
* guard: ({ event }) => event.by > 0,
|
|
136
|
-
*
|
|
135
|
+
* data: ({ root, event }) => ({ count: root.count + event.by })
|
|
137
136
|
* }
|
|
138
137
|
* }
|
|
139
138
|
* })
|
|
@@ -243,11 +242,6 @@ export interface Machine<
|
|
|
243
242
|
/** @internal */
|
|
244
243
|
readonly stateNodes: Machine.StateNodes
|
|
245
244
|
|
|
246
|
-
/** @internal */
|
|
247
|
-
readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(
|
|
248
|
-
source: Source
|
|
249
|
-
) => Machine.TargetBuilder<States, Source>
|
|
250
|
-
|
|
251
245
|
/** @internal */
|
|
252
246
|
readonly handlers: Readonly<Record<string, unknown>>
|
|
253
247
|
|
|
@@ -284,21 +278,24 @@ export interface Definition<
|
|
|
284
278
|
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
285
279
|
Registrations extends Machine.Registrations = {}
|
|
286
280
|
> extends
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
281
|
+
Omit<
|
|
282
|
+
Machine<
|
|
283
|
+
States,
|
|
284
|
+
Events,
|
|
285
|
+
Input,
|
|
286
|
+
Machine.StateIdentifier<States>,
|
|
287
|
+
never,
|
|
288
|
+
never,
|
|
289
|
+
InitialE,
|
|
290
|
+
InitialR,
|
|
291
|
+
FinalStates,
|
|
292
|
+
Output,
|
|
293
|
+
Emits,
|
|
294
|
+
never,
|
|
295
|
+
InputEvents,
|
|
296
|
+
ParentEvents
|
|
297
|
+
>,
|
|
298
|
+
TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"
|
|
302
299
|
>
|
|
303
300
|
{
|
|
304
301
|
/**
|
|
@@ -353,7 +350,7 @@ export declare namespace Definition {
|
|
|
353
350
|
* @category models
|
|
354
351
|
* @since 0.15.0
|
|
355
352
|
*/
|
|
356
|
-
export interface Any extends Machine.Any {
|
|
353
|
+
export interface Any extends Omit<Machine.Any, TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"> {
|
|
357
354
|
readonly handle: any
|
|
358
355
|
}
|
|
359
356
|
}
|
|
@@ -668,7 +665,6 @@ type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Run
|
|
|
668
665
|
: never
|
|
669
666
|
|
|
670
667
|
const InvokeTypeId: typeof internal.InvokeTypeId = internal.InvokeTypeId
|
|
671
|
-
declare const InitialBuilderTypeId: unique symbol
|
|
672
668
|
|
|
673
669
|
type StateDefinitionError<
|
|
674
670
|
Message extends string,
|
|
@@ -835,19 +831,10 @@ type ValidateCompoundStateNode<
|
|
|
835
831
|
Node extends Machine.StateNodeConfig,
|
|
836
832
|
Children extends Machine.StateSchemas,
|
|
837
833
|
Path extends PropertyKey
|
|
838
|
-
> =
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
& {
|
|
843
|
-
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>
|
|
844
|
-
}
|
|
845
|
-
: StateDefinitionError<
|
|
846
|
-
"Compound initial must be one of its direct child keys",
|
|
847
|
-
Path,
|
|
848
|
-
Extract<Initial, PropertyKey>
|
|
849
|
-
>
|
|
850
|
-
: StateDefinitionError<"Compound states must declare an initial child", Path>
|
|
834
|
+
> = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path>
|
|
835
|
+
: ValidateInitialSelectorChild<Children, Path> & ValidateWithSelectorChild<Node, Children, Path> & {
|
|
836
|
+
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>
|
|
837
|
+
}
|
|
851
838
|
|
|
852
839
|
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ?
|
|
853
840
|
StateDefinitionError<"Atomic states cannot declare an initial child">
|
|
@@ -1125,149 +1112,6 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
|
|
|
1125
1112
|
state: (builder: Builder) => Selected
|
|
1126
1113
|
) => Machine.StateConstruction<UnwrapConstruction<Selected>>
|
|
1127
1114
|
|
|
1128
|
-
type InitialSnapshotBuilderWithPrefix<
|
|
1129
|
-
States extends Machine.StateSchemas,
|
|
1130
|
-
Prefix extends string = ""
|
|
1131
|
-
> =
|
|
1132
|
-
& {
|
|
1133
|
-
readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>
|
|
1134
|
-
}
|
|
1135
|
-
& {
|
|
1136
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
type InitialSnapshotMethod<
|
|
1140
|
-
States extends Machine.StateSchemas,
|
|
1141
|
-
StateId extends ActiveStateKey<States>,
|
|
1142
|
-
Prefix extends string
|
|
1143
|
-
> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<
|
|
1144
|
-
InitialSnapshotFromArguments<States, StateId, Prefix>,
|
|
1145
|
-
InitialSnapshotResult<States, StateId, Prefix>
|
|
1146
|
-
>
|
|
1147
|
-
:
|
|
1148
|
-
& DecodedMethod<
|
|
1149
|
-
InitialSnapshotArguments<States, StateId, Prefix>,
|
|
1150
|
-
InitialSnapshotResult<States, StateId, Prefix>
|
|
1151
|
-
>
|
|
1152
|
-
& FromMethod<
|
|
1153
|
-
InitialSnapshotFromArguments<States, StateId, Prefix>,
|
|
1154
|
-
InitialSnapshotResult<States, StateId, Prefix>
|
|
1155
|
-
>
|
|
1156
|
-
|
|
1157
|
-
type InitialSnapshotArguments<
|
|
1158
|
-
States extends Machine.StateSchemas,
|
|
1159
|
-
StateId extends ActiveStateKey<States>,
|
|
1160
|
-
Prefix extends string,
|
|
1161
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1162
|
-
> = States[StateId] extends infer Node ?
|
|
1163
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1164
|
-
WithNodeValue<Node, [
|
|
1165
|
-
states: (
|
|
1166
|
-
builder: InitialParallelBuilder<Children, Path>
|
|
1167
|
-
) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
|
|
1168
|
-
]>
|
|
1169
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1170
|
-
Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
|
|
1171
|
-
WithNodeValue<Node, [
|
|
1172
|
-
state: (
|
|
1173
|
-
builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>
|
|
1174
|
-
) => InitialSelectableResult<Children, Initial, Path>
|
|
1175
|
-
]>
|
|
1176
|
-
: never
|
|
1177
|
-
: WithNodeValue<Node, []>
|
|
1178
|
-
: never
|
|
1179
|
-
|
|
1180
|
-
type InitialSnapshotFromArguments<
|
|
1181
|
-
States extends Machine.StateSchemas,
|
|
1182
|
-
StateId extends ActiveStateKey<States>,
|
|
1183
|
-
Prefix extends string,
|
|
1184
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1185
|
-
> = States[StateId] extends infer Node ?
|
|
1186
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1187
|
-
WithNodeInput<Node, [
|
|
1188
|
-
states: (
|
|
1189
|
-
builder: InitialParallelBuilder<Children, Path>
|
|
1190
|
-
) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
1191
|
-
]>
|
|
1192
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1193
|
-
Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
|
|
1194
|
-
WithNodeInput<Node, [
|
|
1195
|
-
state: (
|
|
1196
|
-
builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>
|
|
1197
|
-
) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
|
|
1198
|
-
]>
|
|
1199
|
-
: never
|
|
1200
|
-
: WithNodeInput<Node, []>
|
|
1201
|
-
: never
|
|
1202
|
-
|
|
1203
|
-
type InitialSnapshotResult<
|
|
1204
|
-
States extends Machine.StateSchemas,
|
|
1205
|
-
StateId extends ActiveStateKey<States>,
|
|
1206
|
-
Prefix extends string,
|
|
1207
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1208
|
-
> = States[StateId] extends infer Node ?
|
|
1209
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1210
|
-
Machine.ParallelSnapshot<
|
|
1211
|
-
Path,
|
|
1212
|
-
NodeValue<Node>,
|
|
1213
|
-
InitialSnapshotRegionsWithPrefix<Children, Path>
|
|
1214
|
-
>
|
|
1215
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1216
|
-
Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
|
|
1217
|
-
Machine.CompoundSnapshot<
|
|
1218
|
-
Path,
|
|
1219
|
-
NodeValue<Node>,
|
|
1220
|
-
InitialSelectableResult<Children, Initial, Path>
|
|
1221
|
-
>
|
|
1222
|
-
: never
|
|
1223
|
-
: Machine.AtomicSnapshot<Path, NodeValue<Node>>
|
|
1224
|
-
: never
|
|
1225
|
-
|
|
1226
|
-
type InitialSelectableResult<
|
|
1227
|
-
States extends Machine.StateSchemas,
|
|
1228
|
-
StateId extends ActiveStateKey<States> | ChoiceStateKey<States>,
|
|
1229
|
-
Prefix extends string
|
|
1230
|
-
> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>>
|
|
1231
|
-
: StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix>
|
|
1232
|
-
: never
|
|
1233
|
-
|
|
1234
|
-
type InitialSnapshotRegionsWithPrefix<
|
|
1235
|
-
States extends Machine.StateSchemas,
|
|
1236
|
-
Prefix extends string
|
|
1237
|
-
> = {
|
|
1238
|
-
readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
type InitialParallelBuilder<
|
|
1242
|
-
States extends Machine.StateSchemas,
|
|
1243
|
-
Prefix extends string,
|
|
1244
|
-
Remaining extends ActiveStateKey<States> = ActiveStateKey<States>,
|
|
1245
|
-
Regions = {},
|
|
1246
|
-
Constructed extends boolean = false
|
|
1247
|
-
> =
|
|
1248
|
-
& SnapshotBuilderComplete<Regions, Constructed>
|
|
1249
|
-
& {
|
|
1250
|
-
readonly [Key in Remaining]: NodeBuilderMethod<
|
|
1251
|
-
States[Key],
|
|
1252
|
-
InitialSnapshotArguments<States, Key, Prefix>,
|
|
1253
|
-
InitialParallelBuilder<
|
|
1254
|
-
States,
|
|
1255
|
-
Prefix,
|
|
1256
|
-
Exclude<Remaining, Key>,
|
|
1257
|
-
Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
|
|
1258
|
-
Constructed
|
|
1259
|
-
>,
|
|
1260
|
-
InitialSnapshotFromArguments<States, Key, Prefix>,
|
|
1261
|
-
InitialParallelBuilder<
|
|
1262
|
-
States,
|
|
1263
|
-
Prefix,
|
|
1264
|
-
Exclude<Remaining, Key>,
|
|
1265
|
-
Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
|
|
1266
|
-
true
|
|
1267
|
-
>
|
|
1268
|
-
>
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
1115
|
type FullSnapshotBuilderWithPrefix<
|
|
1272
1116
|
in out States extends Machine.StateSchemas,
|
|
1273
1117
|
in out Prefix extends string = ""
|
|
@@ -1843,16 +1687,9 @@ type InitializerClosureForNode<
|
|
|
1843
1687
|
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1844
1688
|
| (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never)
|
|
1845
1689
|
| InitializerClosuresForChildren<AllStates, Children, Path>
|
|
1846
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas
|
|
1847
|
-
|
|
|
1848
|
-
|
|
1849
|
-
: never)
|
|
1850
|
-
| (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<
|
|
1851
|
-
AllStates,
|
|
1852
|
-
Children[Initial],
|
|
1853
|
-
Machine.JoinPath<Path, Initial>
|
|
1854
|
-
>
|
|
1855
|
-
: never)
|
|
1690
|
+
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1691
|
+
| Extract<Path, Machine.StateIdentifier<AllStates>>
|
|
1692
|
+
| InitializerClosuresForChildren<AllStates, Children, Path>
|
|
1856
1693
|
: never
|
|
1857
1694
|
: never
|
|
1858
1695
|
|
|
@@ -2776,7 +2613,6 @@ export declare namespace Machine {
|
|
|
2776
2613
|
/** @internal */
|
|
2777
2614
|
readonly stateNodes: StateNodes
|
|
2778
2615
|
/** @internal */
|
|
2779
|
-
readonly makeTargetBuilder: any
|
|
2780
2616
|
/** @internal */
|
|
2781
2617
|
readonly handlers: any
|
|
2782
2618
|
/** @internal */
|
|
@@ -3170,7 +3006,6 @@ export declare namespace Machine {
|
|
|
3170
3006
|
/** Compound states are ordinary active states. */
|
|
3171
3007
|
readonly type?: "active"
|
|
3172
3008
|
/** Direct child selected when the compound state is entered initially. */
|
|
3173
|
-
readonly initial: string
|
|
3174
3009
|
/** Nested state nodes owned by this compound state. */
|
|
3175
3010
|
readonly states: StateTree
|
|
3176
3011
|
/** Schema-backed states take their annotations from the schema. */
|
|
@@ -3179,7 +3014,6 @@ export declare namespace Machine {
|
|
|
3179
3014
|
| {
|
|
3180
3015
|
readonly schema?: never
|
|
3181
3016
|
readonly type?: "active"
|
|
3182
|
-
readonly initial: string
|
|
3183
3017
|
readonly states: StateTree
|
|
3184
3018
|
/** Descriptive metadata for a schema-less state. */
|
|
3185
3019
|
readonly annotations?: SchemaLessStateAnnotations
|
|
@@ -3305,7 +3139,6 @@ export declare namespace Machine {
|
|
|
3305
3139
|
* @category utility types
|
|
3306
3140
|
* @since 0.4.0
|
|
3307
3141
|
*/
|
|
3308
|
-
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>
|
|
3309
3142
|
|
|
3310
3143
|
/**
|
|
3311
3144
|
* Typed snapshot access shared by state descriptors.
|
|
@@ -3876,19 +3709,20 @@ export declare namespace Machine {
|
|
|
3876
3709
|
})
|
|
3877
3710
|
& EnsureChoiceImplementations<States, UnhandledStates>
|
|
3878
3711
|
|
|
3879
|
-
/** Owners
|
|
3712
|
+
/** Owners that require a handler-owned initial edge or region data. */
|
|
3880
3713
|
export type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never :
|
|
3881
|
-
"" extends keyof States ? States[""]
|
|
3882
|
-
: InitializerClosureForNode<States, States[""], ""> :
|
|
3714
|
+
"" extends keyof States ? InitializerClosureForNode<States, States[""], ""> :
|
|
3883
3715
|
never
|
|
3884
3716
|
|
|
3885
3717
|
/** Proof that initialization can construct every required default value. */
|
|
3886
3718
|
export type EnsureInitialImplementations<
|
|
3887
3719
|
States extends StateSchemas,
|
|
3888
3720
|
UnhandledStates extends StateIdentifier<States>
|
|
3889
|
-
> = [
|
|
3890
|
-
|
|
3891
|
-
|
|
3721
|
+
> = [UnhandledStates] extends [never] ? unknown
|
|
3722
|
+
: [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown :
|
|
3723
|
+
{
|
|
3724
|
+
readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>
|
|
3725
|
+
}
|
|
3892
3726
|
|
|
3893
3727
|
/**
|
|
3894
3728
|
* Extracts a state-tree node by state path.
|
|
@@ -4691,12 +4525,9 @@ export declare namespace Machine {
|
|
|
4691
4525
|
export type HistoryDefaultTargetBuilder<
|
|
4692
4526
|
States extends StateSchemas,
|
|
4693
4527
|
Owner extends StateIdentifier<States>
|
|
4694
|
-
> =
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
"",
|
|
4698
|
-
Owner
|
|
4699
|
-
>
|
|
4528
|
+
> = (
|
|
4529
|
+
construction: HistoryConstruction<States[""], Owner>
|
|
4530
|
+
) => StateConstruction<CompleteSnapshotContaining<States, Owner>>
|
|
4700
4531
|
|
|
4701
4532
|
/**
|
|
4702
4533
|
* Builder for source-local transition targets.
|
|
@@ -4843,15 +4674,6 @@ export declare namespace Machine {
|
|
|
4843
4674
|
|
|
4844
4675
|
type RootBuilder<Builder> = Builder extends { readonly "": infer Root } ? Root : never
|
|
4845
4676
|
|
|
4846
|
-
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
4847
|
-
type InitialTargetSelector<States extends StateSchemas> = {
|
|
4848
|
-
readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends
|
|
4849
|
-
{ readonly states: StateSchemas } ? {
|
|
4850
|
-
readonly initial: SelectionValue<InitialBuilder<States>[Key], Key, "initial", "initial">
|
|
4851
|
-
}
|
|
4852
|
-
: SelectionMethod<InitialBuilder<States>[Key], Key, "state", "initial">
|
|
4853
|
-
}
|
|
4854
|
-
|
|
4855
4677
|
/**
|
|
4856
4678
|
* Context passed to a state/event handler.
|
|
4857
4679
|
*
|
|
@@ -5213,16 +5035,7 @@ export declare namespace Machine {
|
|
|
5213
5035
|
* @category utility types
|
|
5214
5036
|
* @since 0.4.0
|
|
5215
5037
|
*/
|
|
5216
|
-
export type InitialResult<States extends StateSchemas, E, R> =
|
|
5217
|
-
| Snapshot<States>
|
|
5218
|
-
| InitialSnapshot<States>
|
|
5219
|
-
| InitialTarget<StateIdentifier<States>>
|
|
5220
|
-
| StateConstruction<Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>>>
|
|
5221
|
-
|
|
5222
|
-
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
5223
|
-
export type InitialSnapshot<States extends StateSchemas> = {
|
|
5224
|
-
readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">
|
|
5225
|
-
}[ActiveStateKey<States>]
|
|
5038
|
+
export type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>
|
|
5226
5039
|
|
|
5227
5040
|
/**
|
|
5228
5041
|
* Return value accepted from transition handlers.
|
|
@@ -5308,10 +5121,6 @@ export declare namespace Machine {
|
|
|
5308
5121
|
export type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config
|
|
5309
5122
|
? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never
|
|
5310
5123
|
: never
|
|
5311
|
-
/** Extracts the return value from an implicit initial child implementation. */
|
|
5312
|
-
export type StateInitializeReturn<Config> = Config extends { readonly initialize?: infer Initialize }
|
|
5313
|
-
? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never
|
|
5314
|
-
: never
|
|
5315
5124
|
/** Extracts the return values from a state's history defaults. */
|
|
5316
5125
|
export type HistoryDefaultReturn<Config> = Config extends { readonly history?: infer History } ? {
|
|
5317
5126
|
readonly [Key in keyof NonNullable<History>]: NonNullable<History>[Key] extends {
|
|
@@ -5543,7 +5352,7 @@ export declare namespace Machine {
|
|
|
5543
5352
|
* @category utility types
|
|
5544
5353
|
* @since 0.4.0
|
|
5545
5354
|
*/
|
|
5546
|
-
export type ConfigServices<Config> =
|
|
5355
|
+
export type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never :
|
|
5547
5356
|
| Effect.Services<EventHandlerReturn<Config>>
|
|
5548
5357
|
| Effect.Services<AlwaysReturn<Config>>
|
|
5549
5358
|
| Effect.Services<DoneReturn<Config>>
|
|
@@ -5552,6 +5361,7 @@ export declare namespace Machine {
|
|
|
5552
5361
|
| Effect.Services<HistoryDefaultReturn<Config>>
|
|
5553
5362
|
| Effect.Services<ChoiceReturn<Config>>
|
|
5554
5363
|
| InvokeRequirements<Config>
|
|
5364
|
+
: never
|
|
5555
5365
|
|
|
5556
5366
|
/** The only transition value accepted by machine handler APIs. */
|
|
5557
5367
|
type TransitionConfig<
|
|
@@ -5713,104 +5523,6 @@ export declare namespace Machine {
|
|
|
5713
5523
|
Branches extends Readonly<Record<string, TransitionBranchInput>>
|
|
5714
5524
|
> = Omit<Context, "target"> & { readonly select: BranchSelectors<Branches> }
|
|
5715
5525
|
|
|
5716
|
-
type ConstructionCallbacks<Context, Builder, Result> = {
|
|
5717
|
-
readonly [
|
|
5718
|
-
Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown
|
|
5719
|
-
? Args extends readonly [unknown?] ? Method : never :
|
|
5720
|
-
never
|
|
5721
|
-
]: Builder[Method] extends (...args: infer Args) => unknown ? (
|
|
5722
|
-
value: (context: Context) => Args[0]
|
|
5723
|
-
) => Result :
|
|
5724
|
-
never
|
|
5725
|
-
}
|
|
5726
|
-
|
|
5727
|
-
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
5728
|
-
export interface InitialBuilderEvidence<out Selection> {
|
|
5729
|
-
readonly [InitialBuilderTypeId]: Types.Covariant<Selection>
|
|
5730
|
-
}
|
|
5731
|
-
|
|
5732
|
-
/** Decoded input shared by initial construction callbacks. */
|
|
5733
|
-
export interface InitialContext<Input> {
|
|
5734
|
-
/** Decoded value supplied when the machine is started. */
|
|
5735
|
-
readonly input: Input
|
|
5736
|
-
}
|
|
5737
|
-
|
|
5738
|
-
/** A selected machine initial entry with its exact resolver target. */
|
|
5739
|
-
export type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> =
|
|
5740
|
-
& Selection
|
|
5741
|
-
& ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>>
|
|
5742
|
-
& (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {})
|
|
5743
|
-
& {
|
|
5744
|
-
/** Lazily constructs the selected initial state from decoded machine input. */
|
|
5745
|
-
readonly resolve: (
|
|
5746
|
-
resolve: (context: {
|
|
5747
|
-
/** Decoded value supplied when the machine is started. */
|
|
5748
|
-
readonly input: Input
|
|
5749
|
-
/** Builder specialized to the selected initial destination. */
|
|
5750
|
-
readonly target: SelectionBuilder<Selection>
|
|
5751
|
-
}) => SelectedTargetResult<Selection>
|
|
5752
|
-
) => InitialBuilderEvidence<Selection>
|
|
5753
|
-
}
|
|
5754
|
-
|
|
5755
|
-
type InitialSelectorNode<Input, Node> = Node extends (...args: infer Args) => infer Selection ?
|
|
5756
|
-
Selection extends TargetSelection<any, any, any> ?
|
|
5757
|
-
& ((...args: Args) => InitialTransitionTarget<Input, Selection>)
|
|
5758
|
-
& {
|
|
5759
|
-
readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>
|
|
5760
|
-
}
|
|
5761
|
-
: never
|
|
5762
|
-
: Node extends TargetSelection<any, any, any> ? InitialTransitionTarget<Input, Node>
|
|
5763
|
-
: {
|
|
5764
|
-
readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>
|
|
5765
|
-
}
|
|
5766
|
-
|
|
5767
|
-
/** Definition-time selector for a machine's top-level initial entry. */
|
|
5768
|
-
export type InitialSelector<States extends StateSchemas, Input = void> = InitialSelectorNode<
|
|
5769
|
-
Input,
|
|
5770
|
-
InitialTargetSelector<States>
|
|
5771
|
-
>
|
|
5772
|
-
|
|
5773
|
-
/** Target-first initial-entry declaration accepted by {@link make}. */
|
|
5774
|
-
export type InitialBuilderInput<States extends StateSchemas, Input> = (
|
|
5775
|
-
to: InitialSelector<States, Input>
|
|
5776
|
-
) => InitialBuilderEvidence<TargetSelection<any, any, any>>
|
|
5777
|
-
|
|
5778
|
-
/** Initializes the root and its declared default descendants. */
|
|
5779
|
-
export type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (
|
|
5780
|
-
root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>
|
|
5781
|
-
) => InitialBuilderEvidence<TargetSelection<any, any, any>>
|
|
5782
|
-
|
|
5783
|
-
interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends
|
|
5784
|
-
TargetSelection<
|
|
5785
|
-
FullSnapshotMethod<{ readonly "": Root }, "" & ActiveStateKey<{ readonly "": Root }>, "">,
|
|
5786
|
-
"",
|
|
5787
|
-
"state",
|
|
5788
|
-
"initial"
|
|
5789
|
-
>
|
|
5790
|
-
{}
|
|
5791
|
-
|
|
5792
|
-
/** Explicitly constructs a complete starting configuration. */
|
|
5793
|
-
export type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (
|
|
5794
|
-
root:
|
|
5795
|
-
& ConstructionCallbacks<
|
|
5796
|
-
InitialContext<Input>,
|
|
5797
|
-
SelectionBuilder<RootConfigurationSelection<Root>>,
|
|
5798
|
-
InitialBuilderEvidence<RootConfigurationSelection<Root>>
|
|
5799
|
-
>
|
|
5800
|
-
& {
|
|
5801
|
-
readonly resolve: (
|
|
5802
|
-
resolve: (
|
|
5803
|
-
context: {
|
|
5804
|
-
/** Decoded startup input. */
|
|
5805
|
-
readonly input: Input
|
|
5806
|
-
/** Builder for the complete root configuration. */
|
|
5807
|
-
readonly target: SelectionBuilder<RootConfigurationSelection<Root>>
|
|
5808
|
-
}
|
|
5809
|
-
) => ConstructionResult<Snapshot<{ readonly "": Root }>>
|
|
5810
|
-
) => InitialBuilderEvidence<RootConfigurationSelection<Root>>
|
|
5811
|
-
}
|
|
5812
|
-
) => InitialBuilderEvidence<TargetSelection<any, any, any>>
|
|
5813
|
-
|
|
5814
5526
|
export type InvokeTransition<
|
|
5815
5527
|
States extends StateSchemas,
|
|
5816
5528
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
@@ -5984,119 +5696,31 @@ export declare namespace Machine {
|
|
|
5984
5696
|
readonly output?: never
|
|
5985
5697
|
}
|
|
5986
5698
|
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
5699
|
+
type HistoryConstruction<Node, Owner extends string> =
|
|
5700
|
+
& ConstructionData<Node>
|
|
5701
|
+
& (Node extends {
|
|
5702
|
+
readonly states: infer Children extends StateSchemas
|
|
5703
|
+
} ? {
|
|
5704
|
+
readonly states: Node extends { readonly type: "parallel" } ? {
|
|
5705
|
+
readonly [K in (ActiveStateKey<Children> | ChoiceStateKey<Children>)]: HistoryConstruction<
|
|
5706
|
+
Children[K],
|
|
5707
|
+
Owner extends `${K}.${infer Rest}` ? Rest : ""
|
|
5708
|
+
>
|
|
5709
|
+
}
|
|
5710
|
+
: {
|
|
5711
|
+
readonly [K in (ActiveStateKey<Children> | ChoiceStateKey<Children>)]: Owner extends
|
|
5712
|
+
"" | K | `${K}.${string}` ?
|
|
5713
|
+
& {
|
|
5714
|
+
readonly [P in K]: HistoryConstruction<
|
|
5715
|
+
Children[P],
|
|
5716
|
+
Owner extends `${K}.${infer Rest}` ? Rest : ""
|
|
5717
|
+
>
|
|
5718
|
+
}
|
|
5719
|
+
& { readonly [P in Exclude<(ActiveStateKey<Children> | ChoiceStateKey<Children>), K>]?: never } :
|
|
5720
|
+
never
|
|
5721
|
+
}[(ActiveStateKey<Children> | ChoiceStateKey<Children>)]
|
|
6001
5722
|
}
|
|
6002
|
-
|
|
6003
|
-
Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
|
|
6004
|
-
: { readonly [Key in Initial]: NodeValue<Children[Initial]> }
|
|
6005
|
-
: never
|
|
6006
|
-
: never
|
|
6007
|
-
: never
|
|
6008
|
-
|
|
6009
|
-
type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
|
|
6010
|
-
readonly states: infer Children extends StateSchemas
|
|
6011
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
|
|
6012
|
-
: NodeBuilderMethod<
|
|
6013
|
-
Children[Initial],
|
|
6014
|
-
readonly [value: NodeValue<Children[Initial]>],
|
|
6015
|
-
SnapshotBuilderComplete<{ readonly [Key in Initial]: NodeValue<Children[Initial]> }>,
|
|
6016
|
-
readonly [input: NodeMakeInput<Children[Initial]>],
|
|
6017
|
-
SnapshotBuilderComplete<{ readonly [Key in Initial]: NodeValue<Children[Initial]> }, true>
|
|
6018
|
-
>
|
|
6019
|
-
: never
|
|
6020
|
-
: never
|
|
6021
|
-
|
|
6022
|
-
type StateInitializeParallelBuilder<
|
|
6023
|
-
Children extends StateSchemas,
|
|
6024
|
-
Remaining extends ActiveStateKey<Children> = {
|
|
6025
|
-
readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key
|
|
6026
|
-
}[ActiveStateKey<Children>],
|
|
6027
|
-
Values = {},
|
|
6028
|
-
Constructed extends boolean = false
|
|
6029
|
-
> =
|
|
6030
|
-
& SnapshotBuilderComplete<Values, Constructed>
|
|
6031
|
-
& {
|
|
6032
|
-
readonly [Key in Remaining]: NodeBuilderMethod<
|
|
6033
|
-
Children[Key],
|
|
6034
|
-
readonly [value: NodeValue<Children[Key]>],
|
|
6035
|
-
StateInitializeParallelBuilder<
|
|
6036
|
-
Children,
|
|
6037
|
-
Exclude<Remaining, Key>,
|
|
6038
|
-
Values & { readonly [Region in Key]: NodeValue<Children[Key]> },
|
|
6039
|
-
Constructed
|
|
6040
|
-
>,
|
|
6041
|
-
readonly [input: NodeMakeInput<Children[Key]>],
|
|
6042
|
-
StateInitializeParallelBuilder<
|
|
6043
|
-
Children,
|
|
6044
|
-
Exclude<Remaining, Key>,
|
|
6045
|
-
Values & { readonly [Region in Key]: NodeValue<Children[Key]> },
|
|
6046
|
-
true
|
|
6047
|
-
>
|
|
6048
|
-
>
|
|
6049
|
-
}
|
|
6050
|
-
|
|
6051
|
-
/**
|
|
6052
|
-
* Builder bound to the direct initial child or regions owned by a state.
|
|
6053
|
-
*
|
|
6054
|
-
* @category utility types
|
|
6055
|
-
* @since 0.13.0
|
|
6056
|
-
*/
|
|
6057
|
-
export type StateInitializeBuilder<
|
|
6058
|
-
States extends StateSchemas,
|
|
6059
|
-
StateId extends StateIdentifier<States>,
|
|
6060
|
-
Node = NodeByIdentifier<States, StateId>
|
|
6061
|
-
> = Node extends { readonly type: "parallel"; readonly states: infer Children extends StateSchemas } ?
|
|
6062
|
-
StateInitializeParallelBuilder<Children>
|
|
6063
|
-
: Node extends { readonly initial: infer Initial } ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey>
|
|
6064
|
-
: never
|
|
6065
|
-
|
|
6066
|
-
/**
|
|
6067
|
-
* Context passed to an implicit child-state initializer.
|
|
6068
|
-
*
|
|
6069
|
-
* @category models
|
|
6070
|
-
* @since 0.13.0
|
|
6071
|
-
*/
|
|
6072
|
-
export type StateInitializeContext<
|
|
6073
|
-
States extends StateSchemas,
|
|
6074
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
6075
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6076
|
-
StateId extends StateIdentifier<States>,
|
|
6077
|
-
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
6078
|
-
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
6079
|
-
> = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
6080
|
-
readonly builder: StateInitializeBuilder<States, StateId>
|
|
6081
|
-
}
|
|
6082
|
-
|
|
6083
|
-
/**
|
|
6084
|
-
* Initial child value implementation for a compound or parallel state.
|
|
6085
|
-
*
|
|
6086
|
-
* @category models
|
|
6087
|
-
* @since 0.13.0
|
|
6088
|
-
*/
|
|
6089
|
-
export type StateInitializeHandler<
|
|
6090
|
-
States extends StateSchemas,
|
|
6091
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
6092
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6093
|
-
StateId extends StateIdentifier<States>,
|
|
6094
|
-
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
6095
|
-
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
6096
|
-
> = (
|
|
6097
|
-
context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
6098
|
-
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
6099
|
-
) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>
|
|
5723
|
+
: { readonly states?: never })
|
|
6100
5724
|
|
|
6101
5725
|
/** Context used only when a history node has no previously captured record. */
|
|
6102
5726
|
export interface HistoryDefaultContext<
|
|
@@ -6186,13 +5810,12 @@ export declare namespace Machine {
|
|
|
6186
5810
|
readonly on?: never
|
|
6187
5811
|
readonly onDone?: never
|
|
6188
5812
|
readonly output?: never
|
|
6189
|
-
readonly initialize?: never
|
|
6190
5813
|
}
|
|
6191
5814
|
|
|
6192
5815
|
type HandlerChildren<Node> = Node extends { readonly states: infer Children extends StateSchemas } ? Children : never
|
|
6193
5816
|
|
|
6194
5817
|
type HandlerConfigPart<Config> = {
|
|
6195
|
-
readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key]
|
|
5818
|
+
readonly [Key in keyof Config as Key extends "states" | "initial" | "root" ? never : Key]: Config[Key]
|
|
6196
5819
|
}
|
|
6197
5820
|
|
|
6198
5821
|
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ?
|
|
@@ -6239,7 +5862,8 @@ export declare namespace Machine {
|
|
|
6239
5862
|
| "entry"
|
|
6240
5863
|
| "exit"
|
|
6241
5864
|
| "history"
|
|
6242
|
-
| "
|
|
5865
|
+
| "initial"
|
|
5866
|
+
| "root"
|
|
6243
5867
|
| "invoke"
|
|
6244
5868
|
| "on"
|
|
6245
5869
|
| "onDone"
|
|
@@ -6443,9 +6067,9 @@ export declare namespace Machine {
|
|
|
6443
6067
|
Config
|
|
6444
6068
|
> = [HistoryIdentifier<AllStates>] extends [never] ? unknown
|
|
6445
6069
|
: StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ?
|
|
6446
|
-
"
|
|
6447
|
-
readonly
|
|
6448
|
-
"State requires
|
|
6070
|
+
"initial" extends keyof Config ? unknown : {
|
|
6071
|
+
readonly initial: HandlerValidationError<
|
|
6072
|
+
"State requires an initial declaration for shallow history restoration",
|
|
6449
6073
|
StateId
|
|
6450
6074
|
>
|
|
6451
6075
|
}
|
|
@@ -6470,6 +6094,7 @@ export declare namespace Machine {
|
|
|
6470
6094
|
& HandlerChildrenValidation<Node, StateId, Config>
|
|
6471
6095
|
& HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
|
|
6472
6096
|
& HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config>
|
|
6097
|
+
& ValidateConstructionDeclarations<Node, Config>
|
|
6473
6098
|
& HandlerRuntimeValidation<Events, Emits, StateId, Config>
|
|
6474
6099
|
: unknown
|
|
6475
6100
|
|
|
@@ -6518,7 +6143,7 @@ export declare namespace Machine {
|
|
|
6518
6143
|
Required extends string ?
|
|
6519
6144
|
HandlerConfigAtPath<{ readonly "": Config }, Required> extends infer NodeConfig ?
|
|
6520
6145
|
[NodeConfig] extends [never] ? RootInitializeError<Required>
|
|
6521
|
-
: "
|
|
6146
|
+
: "initial" extends keyof NodeConfig ? never
|
|
6522
6147
|
: RootInitializeError<Required>
|
|
6523
6148
|
: never :
|
|
6524
6149
|
unknown
|
|
@@ -6540,53 +6165,71 @@ export declare namespace Machine {
|
|
|
6540
6165
|
}>
|
|
6541
6166
|
}
|
|
6542
6167
|
|
|
6543
|
-
type
|
|
6168
|
+
type HandlerTreeValidation<
|
|
6544
6169
|
States extends StateSchemas,
|
|
6170
|
+
Node,
|
|
6545
6171
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
6546
6172
|
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
6547
6173
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6174
|
+
Path extends StateNodeIdentifier<States>,
|
|
6548
6175
|
Config,
|
|
6549
6176
|
OutputStates extends StateIdentifier<States>
|
|
6550
6177
|
> =
|
|
6551
6178
|
& HandlerNodeValidation<
|
|
6552
6179
|
States,
|
|
6553
|
-
|
|
6180
|
+
Node,
|
|
6554
6181
|
Events,
|
|
6555
6182
|
InputEvents,
|
|
6556
6183
|
Emits,
|
|
6557
|
-
|
|
6184
|
+
Path,
|
|
6558
6185
|
Config,
|
|
6559
6186
|
OutputStates
|
|
6560
6187
|
>
|
|
6561
|
-
&
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6188
|
+
& (Config extends { readonly states: infer Handlers }
|
|
6189
|
+
? Node extends { readonly states: infer Children extends StateSchemas } ? {
|
|
6190
|
+
readonly states: {
|
|
6191
|
+
readonly [K in keyof Handlers]: K extends keyof Children ? HandlerTreeValidation<
|
|
6192
|
+
States,
|
|
6193
|
+
Children[K],
|
|
6194
|
+
Events,
|
|
6195
|
+
InputEvents,
|
|
6196
|
+
Emits,
|
|
6197
|
+
Extract<JoinPath<Path, Extract<K, string>>, StateNodeIdentifier<States>>,
|
|
6198
|
+
Handlers[K],
|
|
6199
|
+
OutputStates
|
|
6200
|
+
> :
|
|
6201
|
+
unknown
|
|
6202
|
+
}
|
|
6203
|
+
} :
|
|
6204
|
+
unknown
|
|
6205
|
+
: unknown)
|
|
6206
|
+
|
|
6207
|
+
type RootHandlerValidation<
|
|
6208
|
+
States extends StateSchemas,
|
|
6209
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
6210
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
6211
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6212
|
+
Config,
|
|
6213
|
+
OutputStates extends StateIdentifier<States>
|
|
6214
|
+
> = HandlerTreeValidation<
|
|
6215
|
+
States,
|
|
6216
|
+
States[""],
|
|
6217
|
+
Events,
|
|
6218
|
+
InputEvents,
|
|
6219
|
+
Emits,
|
|
6220
|
+
Extract<"", StateNodeIdentifier<States>>,
|
|
6221
|
+
Config,
|
|
6222
|
+
OutputStates
|
|
6223
|
+
>
|
|
6224
|
+
|
|
6225
|
+
type HandlerHasRequiredInitial<
|
|
6226
|
+
Node,
|
|
6587
6227
|
Config
|
|
6588
|
-
> =
|
|
6589
|
-
?
|
|
6228
|
+
> = Node extends { readonly states: infer Children extends StateSchemas }
|
|
6229
|
+
? Node extends { readonly type: "parallel" }
|
|
6230
|
+
? HasRequiredActiveChild<Children> extends true ? "initial" extends keyof Config ? true : false : true
|
|
6231
|
+
: "initial" extends keyof Config ? true
|
|
6232
|
+
: false
|
|
6590
6233
|
: true
|
|
6591
6234
|
|
|
6592
6235
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
@@ -6614,15 +6257,13 @@ export declare namespace Machine {
|
|
|
6614
6257
|
Node,
|
|
6615
6258
|
StateId extends StateIdentifier<AllStates>,
|
|
6616
6259
|
Config
|
|
6617
|
-
> =
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never
|
|
6622
|
-
: never
|
|
6260
|
+
> = HandlerHasRequiredInitial<Node, Config> extends true ?
|
|
6261
|
+
HandlerHasRequiredHistoryDefaults<Node, Config> extends true ?
|
|
6262
|
+
HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never
|
|
6263
|
+
: never
|
|
6623
6264
|
: never
|
|
6624
6265
|
|
|
6625
|
-
type HandlerConfigError<Config> =
|
|
6266
|
+
type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never :
|
|
6626
6267
|
| Effect.Error<EventHandlerReturn<Config>>
|
|
6627
6268
|
| Effect.Error<AlwaysReturn<Config>>
|
|
6628
6269
|
| Effect.Error<DoneReturn<Config>>
|
|
@@ -6631,16 +6272,17 @@ export declare namespace Machine {
|
|
|
6631
6272
|
| Effect.Error<HistoryDefaultReturn<Config>>
|
|
6632
6273
|
| Effect.Error<ChoiceReturn<Config>>
|
|
6633
6274
|
| InvokeError<Config>
|
|
6275
|
+
: never
|
|
6634
6276
|
|
|
6635
6277
|
type HandlerNodeEvidence<
|
|
6636
6278
|
AllStates extends StateSchemas,
|
|
6637
|
-
|
|
6279
|
+
Node,
|
|
6638
6280
|
StateId extends StateNodeIdentifier<AllStates>,
|
|
6639
|
-
NodeConfig
|
|
6281
|
+
NodeConfig
|
|
6640
6282
|
> = [NodeConfig] extends [never] ? never : {
|
|
6641
6283
|
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<
|
|
6642
6284
|
AllStates,
|
|
6643
|
-
|
|
6285
|
+
Node,
|
|
6644
6286
|
StateId,
|
|
6645
6287
|
NodeConfig
|
|
6646
6288
|
>
|
|
@@ -6657,11 +6299,25 @@ export declare namespace Machine {
|
|
|
6657
6299
|
|
|
6658
6300
|
// Compute every accumulated channel from one normalized node union instead
|
|
6659
6301
|
// of repeating recursive walks for states, errors, services, and outputs.
|
|
6660
|
-
type HandlerTreeEvidence<
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6302
|
+
type HandlerTreeEvidence<
|
|
6303
|
+
AllStates extends StateSchemas,
|
|
6304
|
+
Config,
|
|
6305
|
+
Nodes extends StateSchemas = AllStates,
|
|
6306
|
+
Prefix extends string = ""
|
|
6307
|
+
> = {
|
|
6308
|
+
readonly [K in Extract<keyof Config & keyof Nodes, string>]:
|
|
6309
|
+
| HandlerNodeEvidence<
|
|
6310
|
+
AllStates,
|
|
6311
|
+
Nodes[K],
|
|
6312
|
+
Extract<JoinPath<Prefix, K>, StateNodeIdentifier<AllStates>>,
|
|
6313
|
+
Config[K]
|
|
6314
|
+
>
|
|
6315
|
+
| (Nodes[K] extends { readonly states: infer Children extends StateSchemas }
|
|
6316
|
+
? Config[K] extends { readonly states: infer Handlers }
|
|
6317
|
+
? HandlerTreeEvidence<AllStates, Handlers, Children, JoinPath<Prefix, K>>
|
|
6318
|
+
: never
|
|
6319
|
+
: never)
|
|
6320
|
+
}[Extract<keyof Config & keyof Nodes, string>]
|
|
6665
6321
|
|
|
6666
6322
|
type HandleTreeResult<
|
|
6667
6323
|
AllStates extends StateSchemas,
|
|
@@ -6730,9 +6386,7 @@ export declare namespace Machine {
|
|
|
6730
6386
|
Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never
|
|
6731
6387
|
: unknown
|
|
6732
6388
|
}
|
|
6733
|
-
type ReferenceRoot<S extends StateSchemas> =
|
|
6734
|
-
? Extract<Omit<S[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>
|
|
6735
|
-
: Extract<S[""], StateNodeConfig>
|
|
6389
|
+
type ReferenceRoot<S extends StateSchemas> = Extract<S[""], StateNodeConfig>
|
|
6736
6390
|
type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<
|
|
6737
6391
|
ReferenceRoot<S>,
|
|
6738
6392
|
P,
|
|
@@ -6752,8 +6406,8 @@ export declare namespace Machine {
|
|
|
6752
6406
|
}
|
|
6753
6407
|
& (
|
|
6754
6408
|
| {
|
|
6755
|
-
/** Selects
|
|
6756
|
-
readonly target: ReferenceUnion<S, DestinationPath<S>>
|
|
6409
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6410
|
+
readonly target: ReferenceUnion<S, DestinationPath<S>> | TargetReference<Root, "", "state">
|
|
6757
6411
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6758
6412
|
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>
|
|
6759
6413
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
@@ -6766,7 +6420,7 @@ export declare namespace Machine {
|
|
|
6766
6420
|
| {
|
|
6767
6421
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6768
6422
|
readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>
|
|
6769
|
-
/** Selects
|
|
6423
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6770
6424
|
readonly target?: never
|
|
6771
6425
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6772
6426
|
readonly initial?: never
|
|
@@ -6775,22 +6429,10 @@ export declare namespace Machine {
|
|
|
6775
6429
|
/** Accepts the event without selecting a new destination. */
|
|
6776
6430
|
readonly none?: never
|
|
6777
6431
|
}
|
|
6778
|
-
| {
|
|
6779
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6780
|
-
readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>
|
|
6781
|
-
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
6782
|
-
readonly target?: never
|
|
6783
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6784
|
-
readonly update?: never
|
|
6785
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6786
|
-
readonly history?: never
|
|
6787
|
-
/** Accepts the event without selecting a new destination. */
|
|
6788
|
-
readonly none?: never
|
|
6789
|
-
}
|
|
6790
6432
|
| {
|
|
6791
6433
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6792
6434
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
|
|
6793
|
-
/** Selects
|
|
6435
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6794
6436
|
readonly target?: never
|
|
6795
6437
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6796
6438
|
readonly update?: never
|
|
@@ -6802,7 +6444,7 @@ export declare namespace Machine {
|
|
|
6802
6444
|
| {
|
|
6803
6445
|
/** Accepts the event without selecting a new destination. */
|
|
6804
6446
|
readonly none: true
|
|
6805
|
-
/** Selects
|
|
6447
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6806
6448
|
readonly target?: never
|
|
6807
6449
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6808
6450
|
readonly update?: never
|
|
@@ -6830,56 +6472,111 @@ export declare namespace Machine {
|
|
|
6830
6472
|
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6831
6473
|
readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>
|
|
6832
6474
|
}
|
|
6475
|
+
type RegisteredInput<R> = R extends { readonly "~input": infer I extends Schema.Top } ? I : typeof Schema.Void
|
|
6833
6476
|
type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {}
|
|
6834
|
-
type AtBuilder<T, P extends string> = P extends "" ? T
|
|
6835
|
-
: P extends `${infer H}.${infer Rest}` ? H extends keyof T ? AtBuilder<T[H], Rest> : never
|
|
6836
|
-
: P extends keyof T ? T[P]
|
|
6837
|
-
: never
|
|
6838
|
-
type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<
|
|
6839
|
-
RootBuilder<BranchTargetBuilder<S, Src>>,
|
|
6840
|
-
P
|
|
6841
|
-
>
|
|
6842
6477
|
type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never
|
|
6843
|
-
type
|
|
6844
|
-
|
|
6478
|
+
type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? { readonly data?: never; readonly decoded?: never }
|
|
6479
|
+
:
|
|
6480
|
+
| (
|
|
6481
|
+
& { readonly decoded?: false }
|
|
6482
|
+
& ({} extends NodeMakeInput<Node> ? { readonly data?: NodeMakeInput<Node> } :
|
|
6483
|
+
{ readonly data: NodeMakeInput<Node> })
|
|
6484
|
+
)
|
|
6485
|
+
| { readonly decoded: true; readonly data: NodeValue<Node> }
|
|
6486
|
+
type ConstructionChildren<Children extends StateSchemas, Parallel extends boolean, Source extends string = never> =
|
|
6487
|
+
Parallel extends true ? {
|
|
6488
|
+
readonly [K in ActiveStateKey<Children>]: ConstructionObject<
|
|
6489
|
+
Children[K],
|
|
6490
|
+
Source extends `${K}.${infer Rest}` ? Rest : Source extends K ? "" : never
|
|
6491
|
+
>
|
|
6492
|
+
}
|
|
6493
|
+
: {
|
|
6494
|
+
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]:
|
|
6495
|
+
& {
|
|
6496
|
+
readonly [P in K]: ConstructionObject<
|
|
6497
|
+
Children[P],
|
|
6498
|
+
Source extends `${P}.${infer Rest}` ? Rest : Source extends P ? "" : never
|
|
6499
|
+
>
|
|
6500
|
+
}
|
|
6501
|
+
& { readonly [P in Exclude<ActiveStateKey<Children> | ChoiceStateKey<Children>, K>]?: never }
|
|
6502
|
+
}[ActiveStateKey<Children> | ChoiceStateKey<Children>]
|
|
6503
|
+
/** Values for one state and, optionally, its explicitly selected descendants. */
|
|
6504
|
+
export type ConstructionObject<Node, Source extends string = never> =
|
|
6505
|
+
& { readonly input?: never }
|
|
6506
|
+
& ConstructionData<Node>
|
|
6507
|
+
& (Node extends {
|
|
6508
|
+
readonly states: infer Children extends StateSchemas
|
|
6509
|
+
} ? {
|
|
6510
|
+
readonly states?: ConstructionChildren<
|
|
6511
|
+
Children,
|
|
6512
|
+
Node extends { readonly type: "parallel" } ? [Source] extends [never] ? true : false
|
|
6513
|
+
: false,
|
|
6514
|
+
Source
|
|
6515
|
+
>
|
|
6516
|
+
}
|
|
6517
|
+
: { readonly states?: never })
|
|
6518
|
+
type ConstructionCall<A, Result> = {} extends A ? (construction?: A) => Result : (construction: A) => Result
|
|
6519
|
+
type RootInput<R> =
|
|
6520
|
+
& { readonly data?: never; readonly decoded?: never; readonly states?: never; readonly update?: never }
|
|
6521
|
+
& (RegisteredInput<R> extends typeof Schema.Void ? { readonly input?: never }
|
|
6522
|
+
: {
|
|
6523
|
+
/** Fresh machine input used by root construction and root initial callbacks. */ readonly input:
|
|
6524
|
+
RegisteredInput<R>["Type"]
|
|
6525
|
+
})
|
|
6526
|
+
type ObjectSelection<
|
|
6527
|
+
S extends StateSchemas,
|
|
6528
|
+
Src extends StateNodeIdentifier<S>,
|
|
6529
|
+
P extends StateNodeIdentifier<S>,
|
|
6530
|
+
R
|
|
6531
|
+
> = P extends "" ? ConstructionCall<RootInput<R>, InitialTarget<P>>
|
|
6532
|
+
: P extends ChoiceIdentifier<S> ? () => ChoiceTarget<S, P>
|
|
6533
|
+
: P extends StateIdentifier<S> ? ConstructionCall<
|
|
6534
|
+
ConstructionObject<
|
|
6535
|
+
NodeByIdentifier<S, P>,
|
|
6536
|
+
Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never
|
|
6537
|
+
> & { readonly update?: never },
|
|
6538
|
+
Target<S, P>
|
|
6539
|
+
>
|
|
6540
|
+
: never
|
|
6541
|
+
type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D, R = {}> = D extends {
|
|
6845
6542
|
readonly target: infer Ref
|
|
6846
|
-
} ?
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
RefPath<Update> extends
|
|
6543
|
+
} ?
|
|
6544
|
+
RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ?
|
|
6545
|
+
D extends { readonly update: infer Update }
|
|
6546
|
+
? RefPath<Update> extends
|
|
6851
6547
|
infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>
|
|
6852
|
-
?
|
|
6853
|
-
|
|
6854
|
-
|
|
6548
|
+
? P extends StateIdentifier<S> ? TargetSelection<
|
|
6549
|
+
ConstructionCall<
|
|
6550
|
+
ConstructionObject<
|
|
6551
|
+
NodeByIdentifier<S, P>,
|
|
6552
|
+
Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never
|
|
6553
|
+
> & {
|
|
6554
|
+
readonly update: ConstructionData<NodeByIdentifier<S, Owner>>
|
|
6555
|
+
},
|
|
6556
|
+
CombinedTarget<Target<S, P>, S, Owner>
|
|
6557
|
+
>,
|
|
6558
|
+
P,
|
|
6559
|
+
"state",
|
|
6560
|
+
"branch"
|
|
6561
|
+
> :
|
|
6562
|
+
never
|
|
6563
|
+
: never
|
|
6564
|
+
: TargetSelection<ObjectSelection<S, Src, P, R>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch">
|
|
6855
6565
|
: never
|
|
6856
|
-
: D extends {
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
} ? RefPath<Ref> extends infer P extends string ? BranchBuilderAt<S, Src, P> extends {
|
|
6860
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6861
|
-
readonly initial: infer B
|
|
6862
|
-
} ? TargetSelection<B, P, "initial", "branch">
|
|
6863
|
-
: never :
|
|
6864
|
-
never
|
|
6865
|
-
: D extends {
|
|
6866
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6867
|
-
readonly history: infer Ref
|
|
6868
|
-
} ?
|
|
6869
|
-
RefPath<Ref> extends infer P extends string
|
|
6870
|
-
? TargetSelection<AtBuilder<RootBuilder<HistoryTargetBuilder<S>>, P>, P, "history", "full"> :
|
|
6566
|
+
: D extends { readonly history: infer Ref }
|
|
6567
|
+
? RefPath<Ref> extends infer P extends HistoryIdentifier<S>
|
|
6568
|
+
? TargetSelection<() => HistoryTarget<S, P>, P, "history", "full"> :
|
|
6871
6569
|
never
|
|
6872
|
-
: D extends {
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6570
|
+
: D extends { readonly update: infer Ref }
|
|
6571
|
+
? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>
|
|
6572
|
+
? TargetSelection<
|
|
6573
|
+
ConstructionCall<ConstructionData<NodeByIdentifier<S, P>>, StateUpdate<S, P>>,
|
|
6574
|
+
P,
|
|
6575
|
+
"update",
|
|
6576
|
+
"branch"
|
|
6577
|
+
> :
|
|
6878
6578
|
never
|
|
6879
|
-
: D extends {
|
|
6880
|
-
/** Accepts the event without selecting a new destination. */
|
|
6881
|
-
readonly none: true
|
|
6882
|
-
} ? TargetSelection<() => NoTarget, never, "none", "local">
|
|
6579
|
+
: D extends { readonly none: true } ? TargetSelection<() => NoTarget, never, "none", "local">
|
|
6883
6580
|
: never
|
|
6884
6581
|
type BuilderArgs<B, K extends PropertyKey> = K extends keyof B
|
|
6885
6582
|
? B[K] extends (...args: infer A) => unknown ? A : never
|
|
@@ -6890,15 +6587,6 @@ export declare namespace Machine {
|
|
|
6890
6587
|
& { readonly [K in Exclude<"from" | "decoded", M>]?: never }
|
|
6891
6588
|
: never
|
|
6892
6589
|
}[Extract<keyof B, "from" | "decoded">]
|
|
6893
|
-
type ObjectDefault<B> = B extends {
|
|
6894
|
-
/** Constructs schema make input from the typed source context. */
|
|
6895
|
-
readonly from: () => unknown
|
|
6896
|
-
} | (() => unknown) ? {
|
|
6897
|
-
/** Constructs schema make input from the typed source context. */
|
|
6898
|
-
readonly from?: never /** Supplies an already decoded schema value from the typed source context. */
|
|
6899
|
-
readonly decoded?: never
|
|
6900
|
-
}
|
|
6901
|
-
: never
|
|
6902
6590
|
type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
|
|
6903
6591
|
/** Set to true to exit and reenter the handler source. */
|
|
6904
6592
|
readonly reenter?: Reenter extends true ? boolean : never
|
|
@@ -6920,17 +6608,28 @@ export declare namespace Machine {
|
|
|
6920
6608
|
P extends DestinationPath<S>,
|
|
6921
6609
|
C
|
|
6922
6610
|
> = P extends ChoiceIdentifier<S> ? { readonly from?: never; readonly decoded?: never }
|
|
6923
|
-
: P extends StateIdentifier<S> ?
|
|
6924
|
-
NodeByIdentifier<S, P> extends { readonly states: StateSchemas }
|
|
6925
|
-
? [NodeSchema<NodeByIdentifier<S, P>>] extends [never]
|
|
6926
|
-
? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>>
|
|
6927
|
-
: never
|
|
6928
|
-
: InlineNodeConstruction<C, NodeByIdentifier<S, P>>
|
|
6611
|
+
: P extends StateIdentifier<S> ? InlineNodeConstruction<C, NodeByIdentifier<S, P>>
|
|
6929
6612
|
: never
|
|
6613
|
+
type InlineRoot<S extends StateSchemas, C, R> =
|
|
6614
|
+
& {
|
|
6615
|
+
readonly target: ReferenceAt<S, Extract<"", StateNodeIdentifier<S>>>
|
|
6616
|
+
readonly update?: never
|
|
6617
|
+
readonly branches?: never
|
|
6618
|
+
readonly resolve?: never
|
|
6619
|
+
readonly history?: never
|
|
6620
|
+
readonly none?: never
|
|
6621
|
+
}
|
|
6622
|
+
& (RegisteredInput<R> extends typeof Schema.Void ? { readonly input?: never }
|
|
6623
|
+
: {
|
|
6624
|
+
/** Fresh machine input used to reconstruct root and its initial children. */ readonly input: DataValue<
|
|
6625
|
+
C,
|
|
6626
|
+
RegisteredInput<R>["Type"]
|
|
6627
|
+
>
|
|
6628
|
+
})
|
|
6930
6629
|
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
6931
6630
|
readonly [P in DestinationPath<S>]:
|
|
6932
6631
|
& {
|
|
6933
|
-
/** Selects
|
|
6632
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6934
6633
|
readonly target: ReferenceAt<S, P>
|
|
6935
6634
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6936
6635
|
readonly update?: never
|
|
@@ -6955,24 +6654,7 @@ export declare namespace Machine {
|
|
|
6955
6654
|
P extends string,
|
|
6956
6655
|
Owner extends ValuedStateIdentifier<S>,
|
|
6957
6656
|
C
|
|
6958
|
-
> = P extends StateIdentifier<S> ?
|
|
6959
|
-
readonly [
|
|
6960
|
-
M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">
|
|
6961
|
-
]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ?
|
|
6962
|
-
& {
|
|
6963
|
-
readonly [K in M]: (
|
|
6964
|
-
context: C
|
|
6965
|
-
) => {
|
|
6966
|
-
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
6967
|
-
readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0]
|
|
6968
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6969
|
-
readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0]
|
|
6970
|
-
}
|
|
6971
|
-
}
|
|
6972
|
-
& { readonly [K in Exclude<"from" | "decoded", M>]?: never }
|
|
6973
|
-
: never
|
|
6974
|
-
}[Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]
|
|
6975
|
-
:
|
|
6657
|
+
> = P extends StateIdentifier<S> ?
|
|
6976
6658
|
| {
|
|
6977
6659
|
readonly from: (
|
|
6978
6660
|
context: C
|
|
@@ -6998,7 +6680,7 @@ export declare namespace Machine {
|
|
|
6998
6680
|
readonly [P in DestinationPath<S>]: {
|
|
6999
6681
|
readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]:
|
|
7000
6682
|
& {
|
|
7001
|
-
/** Selects
|
|
6683
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
7002
6684
|
readonly target: ReferenceAt<S, P>
|
|
7003
6685
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
7004
6686
|
readonly update: ReferenceAt<S, Owner>
|
|
@@ -7027,7 +6709,7 @@ export declare namespace Machine {
|
|
|
7027
6709
|
readonly reenter?: P extends Src ? never : boolean
|
|
7028
6710
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
7029
6711
|
readonly update: ReferenceAt<S, P>
|
|
7030
|
-
/** Selects
|
|
6712
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
7031
6713
|
readonly target?: never
|
|
7032
6714
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
7033
6715
|
readonly initial?: never
|
|
@@ -7044,35 +6726,10 @@ export declare namespace Machine {
|
|
|
7044
6726
|
}
|
|
7045
6727
|
& ObjectConstruction<C, StateUpdateBuilder<S, P>>
|
|
7046
6728
|
}[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>]
|
|
7047
|
-
type
|
|
7048
|
-
[Exclude<ObjectCompoundPath<S>, "">] extends [never] ? never : {
|
|
7049
|
-
readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends
|
|
7050
|
-
infer B ?
|
|
7051
|
-
& {
|
|
7052
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
7053
|
-
readonly initial: ReferenceAt<S, P>
|
|
7054
|
-
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
7055
|
-
readonly target?: never
|
|
7056
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
7057
|
-
readonly update?: never
|
|
7058
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
7059
|
-
readonly history?: never
|
|
7060
|
-
/** Accepts the event without selecting a new destination. */
|
|
7061
|
-
readonly none?: never
|
|
7062
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
7063
|
-
readonly branches?: never
|
|
7064
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
7065
|
-
readonly resolve?: never
|
|
7066
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
7067
|
-
readonly declinable?: never
|
|
7068
|
-
}
|
|
7069
|
-
& (ObjectConstruction<C, B> | ObjectDefault<B>) :
|
|
7070
|
-
never
|
|
7071
|
-
}[Exclude<ObjectCompoundPath<S>, "">]
|
|
7072
|
-
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
6729
|
+
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
|
|
7073
6730
|
readonly [K in Extract<keyof Group, string>]: {
|
|
7074
|
-
/** Selects
|
|
7075
|
-
readonly target: SelectionOf<S, Src, Group[K]>
|
|
6731
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6732
|
+
readonly target: SelectionOf<S, Src, Group[K], R>
|
|
7076
6733
|
}
|
|
7077
6734
|
}
|
|
7078
6735
|
type ObjectBranchResolver<
|
|
@@ -7085,7 +6742,7 @@ export declare namespace Machine {
|
|
|
7085
6742
|
context: C & { readonly select: BranchSelectors<B> } & DeclineCapability,
|
|
7086
6743
|
enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
|
|
7087
6744
|
) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never)
|
|
7088
|
-
type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
6745
|
+
type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
|
|
7089
6746
|
readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
|
|
7090
6747
|
/** Accepts the event without selecting a new destination. */
|
|
7091
6748
|
readonly none: true
|
|
@@ -7093,9 +6750,9 @@ export declare namespace Machine {
|
|
|
7093
6750
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
7094
6751
|
readonly update: unknown
|
|
7095
6752
|
} ? K
|
|
7096
|
-
: [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K
|
|
6753
|
+
: [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K
|
|
7097
6754
|
: never
|
|
7098
|
-
: [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K
|
|
6755
|
+
: [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K
|
|
7099
6756
|
: never
|
|
7100
6757
|
}[keyof Group]
|
|
7101
6758
|
type ObjectBranches<
|
|
@@ -7108,11 +6765,11 @@ export declare namespace Machine {
|
|
|
7108
6765
|
Acceptance extends TransitionAcceptance
|
|
7109
6766
|
> = {
|
|
7110
6767
|
readonly [K in Extract<keyof Registered<R, "branches">, string>]:
|
|
7111
|
-
& ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never)
|
|
6768
|
+
& ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K], R>] extends [never] ? unknown : never)
|
|
7112
6769
|
& {
|
|
7113
6770
|
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
7114
6771
|
readonly branches: K
|
|
7115
|
-
/** Selects
|
|
6772
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
7116
6773
|
readonly target?: never
|
|
7117
6774
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
7118
6775
|
readonly update?: never
|
|
@@ -7131,9 +6788,22 @@ export declare namespace Machine {
|
|
|
7131
6788
|
/** Set to true when the resolver can explicitly return decline(). */
|
|
7132
6789
|
readonly declinable?: "declinable" extends Acceptance ? boolean : false
|
|
7133
6790
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
7134
|
-
readonly resolve: ObjectBranchResolver<
|
|
6791
|
+
readonly resolve: ObjectBranchResolver<
|
|
6792
|
+
Ev,
|
|
6793
|
+
Em,
|
|
6794
|
+
C,
|
|
6795
|
+
BranchSelections<S, Src, Registered<R, "branches">[K], R>,
|
|
6796
|
+
true
|
|
6797
|
+
>
|
|
7135
6798
|
}
|
|
7136
6799
|
}[Extract<keyof Registered<R, "branches">, string>]
|
|
6800
|
+
type DataValue<C, A> = A | ((context: C) => A)
|
|
6801
|
+
type DeclarationData<T> = T extends { readonly from: (context: infer C) => infer A }
|
|
6802
|
+
? Omit<T, "from" | "decoded"> & { readonly data: DataValue<C, A>; readonly decoded?: false }
|
|
6803
|
+
: T extends { readonly decoded: (context: infer C) => infer A }
|
|
6804
|
+
? Omit<T, "from" | "decoded"> & { readonly data: DataValue<C, A>; readonly decoded: true }
|
|
6805
|
+
: T extends unknown ? Omit<T, "from" | "decoded"> & { readonly data?: never; readonly decoded?: never }
|
|
6806
|
+
: never
|
|
7137
6807
|
/**
|
|
7138
6808
|
* A transition with an inspectable destination and source-specific construction.
|
|
7139
6809
|
*
|
|
@@ -7151,60 +6821,62 @@ export declare namespace Machine {
|
|
|
7151
6821
|
Acceptance extends TransitionAcceptance = "required"
|
|
7152
6822
|
> =
|
|
7153
6823
|
& ObjectPolicy<C, Reenter, Acceptance>
|
|
7154
|
-
&
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
6824
|
+
& DeclarationData<
|
|
6825
|
+
(
|
|
6826
|
+
| InlineDestination<S, Src, C>
|
|
6827
|
+
| InlineUpdate<S, Src, C>
|
|
6828
|
+
| InlineCombined<S, Src, C>
|
|
6829
|
+
| InlineRoot<S, C, R>
|
|
6830
|
+
| {
|
|
6831
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6832
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
|
|
6833
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6834
|
+
readonly target?: never
|
|
6835
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6836
|
+
readonly update?: never
|
|
6837
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6838
|
+
readonly initial?: never
|
|
6839
|
+
/** Accepts the event without selecting a new destination. */
|
|
6840
|
+
readonly none?: never
|
|
6841
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6842
|
+
readonly branches?: never
|
|
6843
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6844
|
+
readonly resolve?: never
|
|
6845
|
+
/** Constructs schema make input from the typed source context. */
|
|
6846
|
+
readonly from?: never
|
|
6847
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
6848
|
+
readonly decoded?: never
|
|
6849
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
6850
|
+
readonly declinable?: never
|
|
6851
|
+
}
|
|
6852
|
+
| (Src extends ChoiceIdentifier<S> ? never : {
|
|
6853
|
+
/** Accepts the event without selecting a new destination. */
|
|
6854
|
+
readonly none: true
|
|
6855
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6856
|
+
readonly target?: never
|
|
6857
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6858
|
+
readonly update?: never
|
|
6859
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6860
|
+
readonly initial?: never
|
|
6861
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6862
|
+
readonly history?: never
|
|
6863
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6864
|
+
readonly branches?: never
|
|
6865
|
+
/** Constructs schema make input from the typed source context. */
|
|
6866
|
+
readonly from?: never
|
|
6867
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
6868
|
+
readonly decoded?: never
|
|
6869
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
6870
|
+
readonly declinable?: "declinable" extends Acceptance ? boolean : false
|
|
6871
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6872
|
+
readonly resolve?: (
|
|
6873
|
+
context: C & DeclineCapability,
|
|
6874
|
+
enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
|
|
6875
|
+
) => undefined | Declined
|
|
6876
|
+
})
|
|
6877
|
+
| ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>
|
|
6878
|
+
)
|
|
6879
|
+
>
|
|
7208
6880
|
type SourceValue<R, K extends PropertyKey> = {
|
|
7209
6881
|
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind>
|
|
7210
6882
|
? Registered<R, Kind>[K]
|
|
@@ -7388,6 +7060,128 @@ export declare namespace Machine {
|
|
|
7388
7060
|
: {})
|
|
7389
7061
|
>
|
|
7390
7062
|
}[Extract<SourceKeys<R>, string>]
|
|
7063
|
+
type OrdinaryData<A> = A extends unknown ?
|
|
7064
|
+
& A
|
|
7065
|
+
& (
|
|
7066
|
+
| { readonly decoded?: false | undefined }
|
|
7067
|
+
| { readonly data?: never }
|
|
7068
|
+
) :
|
|
7069
|
+
never
|
|
7070
|
+
type ShortConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? never
|
|
7071
|
+
: OrdinaryData<NodeMakeInput<Node>> | ((context: C) => NodeMakeInput<Node>) | {
|
|
7072
|
+
readonly decoded: true
|
|
7073
|
+
readonly data: DataValue<C, NodeValue<Node>>
|
|
7074
|
+
}
|
|
7075
|
+
type InitialData<C, Node> = [NodeSchema<Node>] extends [never] ? { readonly data?: never; readonly decoded?: never }
|
|
7076
|
+
:
|
|
7077
|
+
| (
|
|
7078
|
+
& { readonly decoded?: false }
|
|
7079
|
+
& ({} extends NodeMakeInput<Node> ? { readonly data?: DataValue<C, NodeMakeInput<Node>> }
|
|
7080
|
+
: { readonly data: DataValue<C, NodeMakeInput<Node>> })
|
|
7081
|
+
)
|
|
7082
|
+
| { readonly decoded: true; readonly data: DataValue<C, NodeValue<Node>> }
|
|
7083
|
+
type InitialEdge<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends
|
|
7084
|
+
{ readonly states: infer Children extends StateSchemas } ? {
|
|
7085
|
+
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]:
|
|
7086
|
+
& {
|
|
7087
|
+
readonly target: TargetReference<
|
|
7088
|
+
ReferenceRoot<S>,
|
|
7089
|
+
JoinPath<Src, K>,
|
|
7090
|
+
Children[K] extends ChoiceStateNodeConfig ? "choice" : "state"
|
|
7091
|
+
>
|
|
7092
|
+
}
|
|
7093
|
+
& InitialData<C, Children[K]>
|
|
7094
|
+
}[ActiveStateKey<Children> | ChoiceStateKey<Children>]
|
|
7095
|
+
: never
|
|
7096
|
+
type InitialRegions<C, Children extends StateSchemas> =
|
|
7097
|
+
& { readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? K : never]?: never }
|
|
7098
|
+
& {
|
|
7099
|
+
readonly [
|
|
7100
|
+
K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never
|
|
7101
|
+
: {} extends NodeMakeInput<Children[K]> ? never
|
|
7102
|
+
: K
|
|
7103
|
+
]: ShortConstruction<C, Children[K]>
|
|
7104
|
+
}
|
|
7105
|
+
& {
|
|
7106
|
+
readonly [
|
|
7107
|
+
K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never
|
|
7108
|
+
: {} extends NodeMakeInput<Children[K]> ? K
|
|
7109
|
+
: never
|
|
7110
|
+
]?: ShortConstruction<C, Children[K]>
|
|
7111
|
+
}
|
|
7112
|
+
type RequiresInitialHandler<Node> = Node extends { readonly states: StateSchemas } ? true : false
|
|
7113
|
+
type ChildHandlerMap<
|
|
7114
|
+
S extends StateSchemas,
|
|
7115
|
+
Children extends StateSchemas,
|
|
7116
|
+
Ev extends ReadonlyArray<TaggedSchema>,
|
|
7117
|
+
Em extends ReadonlyArray<TaggedSchema>,
|
|
7118
|
+
Src extends StateNodeIdentifier<S>,
|
|
7119
|
+
In extends ReadonlyArray<TaggedSchema>,
|
|
7120
|
+
Pa extends ReadonlyArray<TaggedSchema>,
|
|
7121
|
+
R
|
|
7122
|
+
> =
|
|
7123
|
+
& {
|
|
7124
|
+
readonly [
|
|
7125
|
+
K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true ? K
|
|
7126
|
+
: never
|
|
7127
|
+
]: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>
|
|
7128
|
+
}
|
|
7129
|
+
& {
|
|
7130
|
+
readonly [
|
|
7131
|
+
K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true
|
|
7132
|
+
? never
|
|
7133
|
+
: K
|
|
7134
|
+
]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>
|
|
7135
|
+
}
|
|
7136
|
+
type ChildHandlers<
|
|
7137
|
+
S extends StateSchemas,
|
|
7138
|
+
Children extends StateSchemas,
|
|
7139
|
+
Ev extends ReadonlyArray<TaggedSchema>,
|
|
7140
|
+
Em extends ReadonlyArray<TaggedSchema>,
|
|
7141
|
+
Src extends StateNodeIdentifier<S>,
|
|
7142
|
+
In extends ReadonlyArray<TaggedSchema>,
|
|
7143
|
+
Pa extends ReadonlyArray<TaggedSchema>,
|
|
7144
|
+
R
|
|
7145
|
+
> = [
|
|
7146
|
+
{
|
|
7147
|
+
[K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: RequiresInitialHandler<Children[K]> extends true ? K
|
|
7148
|
+
: never
|
|
7149
|
+
}[ActiveStateKey<Children> | ChoiceStateKey<Children>]
|
|
7150
|
+
] extends [never] ? { readonly states?: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R> }
|
|
7151
|
+
: { readonly states: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R> }
|
|
7152
|
+
type InitialHandler<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends
|
|
7153
|
+
{ readonly type: "parallel"; readonly states: infer Children extends StateSchemas }
|
|
7154
|
+
? {} extends InitialRegions<C, Children> ? { readonly initial?: InitialRegions<C, Children> }
|
|
7155
|
+
: { readonly initial: InitialRegions<C, Children> }
|
|
7156
|
+
: Node extends { readonly states: StateSchemas } ? { readonly initial: InitialEdge<S, Node, Src, C> }
|
|
7157
|
+
: { readonly initial?: never }
|
|
7158
|
+
type RootConstruction<Node, Input> = [NodeSchema<Node>] extends [never] ?
|
|
7159
|
+
{ /** Root-owned data is available only when the root declares a schema. */ readonly root?: never }
|
|
7160
|
+
: {} extends NodeMakeInput<Node> ? {
|
|
7161
|
+
/** Constructs root-owned data from startup or fresh root-target input. */ readonly root?: ShortConstruction<
|
|
7162
|
+
{ readonly input: Input },
|
|
7163
|
+
Node
|
|
7164
|
+
>
|
|
7165
|
+
}
|
|
7166
|
+
: {
|
|
7167
|
+
/** Constructs root-owned data from startup or fresh root-target input. */ readonly root: ShortConstruction<
|
|
7168
|
+
{ readonly input: Input },
|
|
7169
|
+
Node
|
|
7170
|
+
>
|
|
7171
|
+
}
|
|
7172
|
+
type ExactConstruction<C> = C extends { readonly decoded: true; readonly data: unknown }
|
|
7173
|
+
? { readonly [K in Exclude<keyof C, "decoded" | "data">]: never }
|
|
7174
|
+
: unknown
|
|
7175
|
+
type ValidateInitialDeclaration<Node, C> = Node extends {
|
|
7176
|
+
readonly type: "parallel"
|
|
7177
|
+
readonly states: infer Children extends StateSchemas
|
|
7178
|
+
} ? { readonly [K in keyof C]: K extends ActiveStateKey<Children> ? ExactConstruction<C[K]> : never }
|
|
7179
|
+
: { readonly [K in Exclude<keyof C, "target" | "data" | "decoded">]: never }
|
|
7180
|
+
type ValidateConstructionDeclarations<Node, C> = {
|
|
7181
|
+
readonly [K in Extract<keyof C, "root" | "initial">]: K extends "root" ? ExactConstruction<C[K]>
|
|
7182
|
+
: K extends "initial" ? ValidateInitialDeclaration<Node, C[K]>
|
|
7183
|
+
: unknown
|
|
7184
|
+
}
|
|
7391
7185
|
type ObjectLifecycle<
|
|
7392
7186
|
S extends StateSchemas,
|
|
7393
7187
|
Node,
|
|
@@ -7407,8 +7201,7 @@ export declare namespace Machine {
|
|
|
7407
7201
|
& (Node extends { readonly type: "final" } ?
|
|
7408
7202
|
& {
|
|
7409
7203
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
7410
|
-
readonly exit?: never
|
|
7411
|
-
readonly initialize?: never
|
|
7204
|
+
readonly exit?: never
|
|
7412
7205
|
}
|
|
7413
7206
|
& OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>>
|
|
7414
7207
|
: {
|
|
@@ -7417,14 +7210,11 @@ export declare namespace Machine {
|
|
|
7417
7210
|
context: StateActionContext<S, Ev, Em, Src, In, Pa>,
|
|
7418
7211
|
enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
|
|
7419
7212
|
) => StateActionResult<any, any>
|
|
7420
|
-
/** Constructs required values for the declared initial child or parallel regions. */
|
|
7421
|
-
readonly initialize?: StateInitializeHandler<S, Ev, Em, Src, In, Pa>
|
|
7422
7213
|
} & ActiveOutputHandlerConfig<S, Ev, Src>)
|
|
7423
7214
|
: {
|
|
7424
7215
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
7425
7216
|
readonly entry?: never /** Runs synchronously on exit and may enqueue commands. */
|
|
7426
|
-
readonly exit?: never /** Constructs
|
|
7427
|
-
readonly initialize?: never /** Constructs the decoded output declared by the state schema. */
|
|
7217
|
+
readonly exit?: never /** Constructs the decoded output declared by the state schema. */
|
|
7428
7218
|
readonly output?: never
|
|
7429
7219
|
}
|
|
7430
7220
|
/**
|
|
@@ -7444,6 +7234,21 @@ export declare namespace Machine {
|
|
|
7444
7234
|
R
|
|
7445
7235
|
> =
|
|
7446
7236
|
& ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa>
|
|
7237
|
+
& InitialHandler<
|
|
7238
|
+
S,
|
|
7239
|
+
Node,
|
|
7240
|
+
Src,
|
|
7241
|
+
& StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa>
|
|
7242
|
+
& {
|
|
7243
|
+
/** Root-owned data constructed before initial descendant values. */
|
|
7244
|
+
readonly root: StateByIdentifier<S, Extract<"", StateIdentifier<S>>>
|
|
7245
|
+
}
|
|
7246
|
+
& (Src extends "" ? {
|
|
7247
|
+
/** Fresh machine input used by root construction and root initial callbacks. */ readonly input:
|
|
7248
|
+
RegisteredInput<R>["Type"]
|
|
7249
|
+
}
|
|
7250
|
+
: {})
|
|
7251
|
+
>
|
|
7447
7252
|
& (Src extends ChoiceIdentifier<S> ? {
|
|
7448
7253
|
/** Required total transition for a transient choice state. */
|
|
7449
7254
|
readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>
|
|
@@ -7528,21 +7333,9 @@ export declare namespace Machine {
|
|
|
7528
7333
|
readonly states: infer Children extends StateSchemas
|
|
7529
7334
|
} ? {
|
|
7530
7335
|
/** Child handlers nested according to the declared root topology. */
|
|
7531
|
-
readonly states?: {
|
|
7532
|
-
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]?: StateHandler<
|
|
7533
|
-
S,
|
|
7534
|
-
Children[K],
|
|
7535
|
-
Ev,
|
|
7536
|
-
Em,
|
|
7537
|
-
Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>,
|
|
7538
|
-
In,
|
|
7539
|
-
Pa,
|
|
7540
|
-
R
|
|
7541
|
-
>
|
|
7542
|
-
}
|
|
7543
7336
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
7544
7337
|
readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>
|
|
7545
|
-
} :
|
|
7338
|
+
} & ChildHandlers<S, Children, Ev, Em, Src, In, Pa, R> :
|
|
7546
7339
|
{
|
|
7547
7340
|
/** Child handlers nested according to the declared root topology. */
|
|
7548
7341
|
readonly states?: never /** Restores the declared history reference, using its fallback on first entry. */
|
|
@@ -7550,17 +7343,20 @@ export declare namespace Machine {
|
|
|
7550
7343
|
}) :
|
|
7551
7344
|
never)
|
|
7552
7345
|
type ValidateObjectTransition<T> =
|
|
7346
|
+
& ("input" extends keyof T
|
|
7347
|
+
? T extends { readonly target: TargetReference<any, "", "state"> } ? unknown : { readonly input: never }
|
|
7348
|
+
: unknown)
|
|
7553
7349
|
& {
|
|
7554
7350
|
readonly [
|
|
7555
7351
|
K in Exclude<
|
|
7556
7352
|
keyof T,
|
|
7557
7353
|
| "target"
|
|
7558
7354
|
| "update"
|
|
7559
|
-
| "
|
|
7355
|
+
| "input"
|
|
7560
7356
|
| "history"
|
|
7561
7357
|
| "none"
|
|
7562
7358
|
| "branches"
|
|
7563
|
-
| "
|
|
7359
|
+
| "data"
|
|
7564
7360
|
| "decoded"
|
|
7565
7361
|
| "resolve"
|
|
7566
7362
|
| "guard"
|
|
@@ -7670,9 +7466,12 @@ export declare namespace Machine {
|
|
|
7670
7466
|
config:
|
|
7671
7467
|
& C
|
|
7672
7468
|
& (C extends (...args: never[]) => unknown ? never : unknown)
|
|
7673
|
-
&
|
|
7674
|
-
|
|
7675
|
-
|
|
7469
|
+
& HandlerShape<
|
|
7470
|
+
C,
|
|
7471
|
+
& StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & { readonly "~input": I }>
|
|
7472
|
+
& RootConstruction<S[""], I["Type"]>
|
|
7473
|
+
>
|
|
7474
|
+
& RootConstruction<S[""], I["Type"]>
|
|
7676
7475
|
& ValidateObjectConfig<NoInfer<C>, R>
|
|
7677
7476
|
& RootHandlerValidation<
|
|
7678
7477
|
S,
|
|
@@ -7941,24 +7740,23 @@ export const isFinal: <
|
|
|
7941
7740
|
) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal as any
|
|
7942
7741
|
|
|
7943
7742
|
/**
|
|
7944
|
-
* Defines
|
|
7743
|
+
* Defines root or nested state schemas while preserving the exact child topology.
|
|
7945
7744
|
*
|
|
7946
|
-
*
|
|
7947
|
-
*
|
|
7948
|
-
*
|
|
7745
|
+
* Pass the root descriptor to {@link make} and {@link targets}. Nested states
|
|
7746
|
+
* can be declared inline or reused by mounting a descriptor in multiple places.
|
|
7747
|
+
* Initial edges and value constructors belong in the handler tree.
|
|
7949
7748
|
*
|
|
7950
7749
|
* **Example** (Repeated compound state)
|
|
7951
7750
|
*
|
|
7952
7751
|
* ```ts
|
|
7953
|
-
* import { Schema } from "effect"
|
|
7954
7752
|
* import { Machine } from "@typeonce/effect-machine"
|
|
7753
|
+
* import { Schema } from "effect"
|
|
7955
7754
|
*
|
|
7956
7755
|
* const TradingState = Schema.TaggedUnion({
|
|
7957
7756
|
* InSession: {},
|
|
7958
7757
|
* Applying: {}
|
|
7959
7758
|
* })
|
|
7960
7759
|
* const TradingSlot = Machine.state({
|
|
7961
|
-
* initial: "Idle",
|
|
7962
7760
|
* states: {
|
|
7963
7761
|
* Idle: {},
|
|
7964
7762
|
* InSession: TradingState.cases.InSession,
|
|
@@ -7966,10 +7764,12 @@ export const isFinal: <
|
|
|
7966
7764
|
* }
|
|
7967
7765
|
* })
|
|
7968
7766
|
*
|
|
7969
|
-
* const States = Machine.state({
|
|
7970
|
-
*
|
|
7971
|
-
*
|
|
7972
|
-
*
|
|
7767
|
+
* const States = Machine.state({
|
|
7768
|
+
* states: {
|
|
7769
|
+
* slot1: TradingSlot,
|
|
7770
|
+
* slot2: TradingSlot
|
|
7771
|
+
* }
|
|
7772
|
+
* })
|
|
7973
7773
|
* ```
|
|
7974
7774
|
*
|
|
7975
7775
|
* @category constructors
|
|
@@ -8142,83 +7942,8 @@ type MakeResult<
|
|
|
8142
7942
|
}
|
|
8143
7943
|
>
|
|
8144
7944
|
|
|
8145
|
-
type RootInitialization<Root extends Machine.StateNodeConfig, Input> =
|
|
8146
|
-
& { readonly initialConfiguration?: never }
|
|
8147
|
-
& (Machine.NodeSchema<Root> extends never ? {
|
|
8148
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
8149
|
-
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>
|
|
8150
|
-
}
|
|
8151
|
-
: {} extends NodeMakeInput<Root> ? {
|
|
8152
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
8153
|
-
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>
|
|
8154
|
-
}
|
|
8155
|
-
: {
|
|
8156
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
8157
|
-
readonly initial: Machine.RootInitialBuilderInput<Root, Input>
|
|
8158
|
-
})
|
|
8159
|
-
|
|
8160
7945
|
/** @inline */
|
|
8161
7946
|
interface Make {
|
|
8162
|
-
/** @param config Complete starting configuration, including root and descendant values. */
|
|
8163
|
-
<
|
|
8164
|
-
const Root extends Machine.StateNodeConfig,
|
|
8165
|
-
const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8166
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8167
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
8168
|
-
InitialE = never,
|
|
8169
|
-
InitialR = never,
|
|
8170
|
-
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8171
|
-
const ParentDeclaration extends Parent.Any | undefined = undefined,
|
|
8172
|
-
const Effects extends Machine.EffectSources = {},
|
|
8173
|
-
const Streams extends Machine.StreamSources = {},
|
|
8174
|
-
const Timers extends Machine.TimerSources = {},
|
|
8175
|
-
const Logics extends Machine.LogicSources = {},
|
|
8176
|
-
const Children extends Machine.ChildSources = {},
|
|
8177
|
-
const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}
|
|
8178
|
-
>(
|
|
8179
|
-
config:
|
|
8180
|
-
& MakeConfig<
|
|
8181
|
-
Root,
|
|
8182
|
-
InputEvents,
|
|
8183
|
-
Emits,
|
|
8184
|
-
Input,
|
|
8185
|
-
InitialE,
|
|
8186
|
-
InitialR,
|
|
8187
|
-
InternalEvents,
|
|
8188
|
-
ParentDeclaration,
|
|
8189
|
-
Effects,
|
|
8190
|
-
Streams,
|
|
8191
|
-
Timers,
|
|
8192
|
-
Logics,
|
|
8193
|
-
Children,
|
|
8194
|
-
Branches
|
|
8195
|
-
>
|
|
8196
|
-
& UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>
|
|
8197
|
-
& {
|
|
8198
|
-
/** Mutually exclusive with a complete initial configuration. */
|
|
8199
|
-
readonly initial?: never
|
|
8200
|
-
/** Constructs the complete initial root configuration, overriding child defaults. */
|
|
8201
|
-
readonly initialConfiguration: Machine.RootConfigurationBuilderInput<
|
|
8202
|
-
NoInfer<Root>,
|
|
8203
|
-
Input["Type"]
|
|
8204
|
-
>
|
|
8205
|
-
}
|
|
8206
|
-
): MakeResult<
|
|
8207
|
-
Root & { readonly "~effect/Machine/ExplicitInitial": true },
|
|
8208
|
-
InputEvents,
|
|
8209
|
-
Emits,
|
|
8210
|
-
Input,
|
|
8211
|
-
InitialE,
|
|
8212
|
-
InitialR,
|
|
8213
|
-
InternalEvents,
|
|
8214
|
-
ParentDeclaration,
|
|
8215
|
-
Effects,
|
|
8216
|
-
Streams,
|
|
8217
|
-
Timers,
|
|
8218
|
-
Logics,
|
|
8219
|
-
Children,
|
|
8220
|
-
Branches
|
|
8221
|
-
>
|
|
8222
7947
|
/** @param config Complete schema-first machine definition. */
|
|
8223
7948
|
<
|
|
8224
7949
|
const Root extends Machine.StateNodeConfig,
|
|
@@ -8254,10 +7979,6 @@ interface Make {
|
|
|
8254
7979
|
Branches
|
|
8255
7980
|
>
|
|
8256
7981
|
& UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>
|
|
8257
|
-
& Exclude<
|
|
8258
|
-
RootInitialization<NoInfer<Root>, Input["Type"]>,
|
|
8259
|
-
{ readonly initialConfiguration: unknown }
|
|
8260
|
-
>
|
|
8261
7982
|
): MakeResult<
|
|
8262
7983
|
Root,
|
|
8263
7984
|
InputEvents,
|
|
@@ -8304,35 +8025,40 @@ interface Make {
|
|
|
8304
8025
|
* **Example** (Typed counter machine)
|
|
8305
8026
|
*
|
|
8306
8027
|
* ```ts
|
|
8307
|
-
* import { Schema } from "effect"
|
|
8308
8028
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8309
|
-
*
|
|
8029
|
+
* import { Schema } from "effect"
|
|
8310
8030
|
* class Count extends Schema.TaggedClass<Count>("Count")("Count", {
|
|
8311
8031
|
* value: Schema.Number
|
|
8312
|
-
* }) {
|
|
8313
|
-
*
|
|
8032
|
+
* }) {
|
|
8033
|
+
* }
|
|
8314
8034
|
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
|
|
8315
8035
|
* by: Schema.Number
|
|
8316
|
-
* }) {
|
|
8317
|
-
*
|
|
8318
|
-
* const States = Machine.state({
|
|
8036
|
+
* }) {
|
|
8037
|
+
* }
|
|
8038
|
+
* const States = Machine.state({ states: { Count } })
|
|
8319
8039
|
* const Events = Machine.eventsFromSchemas(Increment)
|
|
8320
8040
|
* const targets = Machine.targets(States)
|
|
8321
|
-
*
|
|
8322
8041
|
* const counter = Machine.make({
|
|
8323
8042
|
* root: States,
|
|
8324
|
-
* events: Events
|
|
8325
|
-
*
|
|
8326
|
-
*
|
|
8327
|
-
*
|
|
8328
|
-
*
|
|
8329
|
-
*
|
|
8330
|
-
*
|
|
8331
|
-
*
|
|
8043
|
+
* events: Events
|
|
8044
|
+
* }).handle({
|
|
8045
|
+
* initial: {
|
|
8046
|
+
* target: Machine.targets(States).root.Count,
|
|
8047
|
+
* decoded: true,
|
|
8048
|
+
* data: new Count({ value: 0 })
|
|
8049
|
+
* },
|
|
8050
|
+
* states: {
|
|
8051
|
+
* Count: {
|
|
8052
|
+
* on: {
|
|
8053
|
+
* Increment: {
|
|
8054
|
+
* update: targets.root.Count,
|
|
8055
|
+
* decoded: true,
|
|
8056
|
+
* data: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
8057
|
+
* }
|
|
8332
8058
|
* }
|
|
8333
8059
|
* }
|
|
8334
8060
|
* }
|
|
8335
|
-
* }
|
|
8061
|
+
* })
|
|
8336
8062
|
* ```
|
|
8337
8063
|
*
|
|
8338
8064
|
* @see {@link state} for typed state-tree helpers.
|
|
@@ -8553,17 +8279,22 @@ export const emittedEventsFromSchemas: {
|
|
|
8553
8279
|
* **Example**
|
|
8554
8280
|
*
|
|
8555
8281
|
* ```ts
|
|
8556
|
-
* import { Effect, Schema } from "effect"
|
|
8557
8282
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8558
|
-
*
|
|
8559
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
8560
|
-
*
|
|
8283
|
+
* import { Effect, Schema } from "effect"
|
|
8284
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
8285
|
+
* }
|
|
8286
|
+
* const States = Machine.state({ states: { Idle } })
|
|
8561
8287
|
* const machine = Machine.make({
|
|
8562
8288
|
* root: States,
|
|
8563
|
-
* events: Machine.eventsFromSchemas()
|
|
8564
|
-
*
|
|
8565
|
-
*
|
|
8566
|
-
*
|
|
8289
|
+
* events: Machine.eventsFromSchemas()
|
|
8290
|
+
* }).handle({
|
|
8291
|
+
* initial: {
|
|
8292
|
+
* target: Machine.targets(States).root.Idle
|
|
8293
|
+
* },
|
|
8294
|
+
* states: {
|
|
8295
|
+
* Idle: {}
|
|
8296
|
+
* }
|
|
8297
|
+
* })
|
|
8567
8298
|
* const encoded = Effect.gen(function*() {
|
|
8568
8299
|
* const initial = yield* Machine.planInitial(machine)
|
|
8569
8300
|
* return yield* Machine.encodeSnapshot(machine, initial.state)
|
|
@@ -8635,17 +8366,22 @@ export const encodeSnapshot: <
|
|
|
8635
8366
|
* **Example**
|
|
8636
8367
|
*
|
|
8637
8368
|
* ```ts
|
|
8638
|
-
* import { Effect, Schema } from "effect"
|
|
8639
8369
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8640
|
-
*
|
|
8641
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
8642
|
-
*
|
|
8370
|
+
* import { Effect, Schema } from "effect"
|
|
8371
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
8372
|
+
* }
|
|
8373
|
+
* const States = Machine.state({ states: { Idle } })
|
|
8643
8374
|
* const machine = Machine.make({
|
|
8644
8375
|
* root: States,
|
|
8645
|
-
* events: Machine.eventsFromSchemas()
|
|
8646
|
-
*
|
|
8647
|
-
*
|
|
8648
|
-
*
|
|
8376
|
+
* events: Machine.eventsFromSchemas()
|
|
8377
|
+
* }).handle({
|
|
8378
|
+
* initial: {
|
|
8379
|
+
* target: Machine.targets(States).root.Idle
|
|
8380
|
+
* },
|
|
8381
|
+
* states: {
|
|
8382
|
+
* Idle: {}
|
|
8383
|
+
* }
|
|
8384
|
+
* })
|
|
8649
8385
|
* const roundTrip = Effect.gen(function*() {
|
|
8650
8386
|
* const initial = yield* Machine.planInitial(machine)
|
|
8651
8387
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
@@ -8743,17 +8479,22 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
8743
8479
|
* **Example**
|
|
8744
8480
|
*
|
|
8745
8481
|
* ```ts
|
|
8746
|
-
* import { Effect, Schema } from "effect"
|
|
8747
8482
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8748
|
-
*
|
|
8749
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
8750
|
-
*
|
|
8483
|
+
* import { Effect, Schema } from "effect"
|
|
8484
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
8485
|
+
* }
|
|
8486
|
+
* const States = Machine.state({ states: { Idle } })
|
|
8751
8487
|
* const machine = Machine.make({
|
|
8752
8488
|
* root: States,
|
|
8753
|
-
* events: Machine.eventsFromSchemas()
|
|
8754
|
-
*
|
|
8755
|
-
*
|
|
8756
|
-
*
|
|
8489
|
+
* events: Machine.eventsFromSchemas()
|
|
8490
|
+
* }).handle({
|
|
8491
|
+
* initial: {
|
|
8492
|
+
* target: Machine.targets(States).root.Idle
|
|
8493
|
+
* },
|
|
8494
|
+
* states: {
|
|
8495
|
+
* Idle: {}
|
|
8496
|
+
* }
|
|
8497
|
+
* })
|
|
8757
8498
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
8758
8499
|
* ```
|
|
8759
8500
|
*
|
|
@@ -9032,12 +8773,15 @@ export const enabled: <
|
|
|
9032
8773
|
* import { Effect, Schema } from "effect"
|
|
9033
8774
|
*
|
|
9034
8775
|
* const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
|
|
8776
|
+
* const Root = Machine.state({ states: { Idle: {} } })
|
|
9035
8777
|
* const machine = Machine.make({
|
|
9036
|
-
* root:
|
|
8778
|
+
* root: Root,
|
|
9037
8779
|
* events: Machine.eventsFromSchemas(),
|
|
9038
|
-
* internalEvents
|
|
9039
|
-
*
|
|
9040
|
-
*
|
|
8780
|
+
* internalEvents
|
|
8781
|
+
* }).handle({
|
|
8782
|
+
* initial: { target: Machine.targets(Root).root.Idle },
|
|
8783
|
+
* states: { Idle: { on: { Loaded: { none: true } } } }
|
|
8784
|
+
* })
|
|
9041
8785
|
*
|
|
9042
8786
|
* export const canLoad = Effect.gen(function*() {
|
|
9043
8787
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -9148,27 +8892,32 @@ export const can: {
|
|
|
9148
8892
|
* **Example**
|
|
9149
8893
|
*
|
|
9150
8894
|
* ```ts
|
|
9151
|
-
* import { Effect, Schema } from "effect"
|
|
9152
8895
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9153
|
-
*
|
|
9154
|
-
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
|
|
9155
|
-
*
|
|
9156
|
-
* class
|
|
9157
|
-
*
|
|
8896
|
+
* import { Effect, Schema } from "effect"
|
|
8897
|
+
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
|
|
8898
|
+
* }
|
|
8899
|
+
* class On extends Schema.TaggedClass<On>("On")("On", {}) {
|
|
8900
|
+
* }
|
|
8901
|
+
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
|
|
8902
|
+
* }
|
|
8903
|
+
* const States = Machine.state({ states: { Off, On } })
|
|
9158
8904
|
* const targets = Machine.targets(States)
|
|
9159
8905
|
* const machine = Machine.make({
|
|
9160
8906
|
* root: States,
|
|
9161
|
-
* events: Machine.eventsFromSchemas(Toggle)
|
|
9162
|
-
*
|
|
9163
|
-
*
|
|
9164
|
-
*
|
|
9165
|
-
* on: {
|
|
9166
|
-
* Toggle: { target: targets.root.On }
|
|
9167
|
-
* }
|
|
8907
|
+
* events: Machine.eventsFromSchemas(Toggle)
|
|
8908
|
+
* }).handle({
|
|
8909
|
+
* initial: {
|
|
8910
|
+
* target: Machine.targets(States).root.Off
|
|
9168
8911
|
* },
|
|
9169
|
-
*
|
|
9170
|
-
*
|
|
9171
|
-
*
|
|
8912
|
+
* states: {
|
|
8913
|
+
* Off: {
|
|
8914
|
+
* on: {
|
|
8915
|
+
* Toggle: { target: targets.root.On }
|
|
8916
|
+
* }
|
|
8917
|
+
* },
|
|
8918
|
+
* On: {}
|
|
8919
|
+
* }
|
|
8920
|
+
* })
|
|
9172
8921
|
* const nextState = Effect.gen(function*() {
|
|
9173
8922
|
* const initial = yield* Machine.planInitial(machine)
|
|
9174
8923
|
* return (yield* Machine.plan(machine, initial.state, new Toggle({}))).next
|
|
@@ -9546,17 +9295,22 @@ export const prepare: <
|
|
|
9546
9295
|
* **Example**
|
|
9547
9296
|
*
|
|
9548
9297
|
* ```ts
|
|
9549
|
-
* import { Effect, Schema } from "effect"
|
|
9550
9298
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9551
|
-
*
|
|
9552
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
9553
|
-
*
|
|
9299
|
+
* import { Effect, Schema } from "effect"
|
|
9300
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
9301
|
+
* }
|
|
9302
|
+
* const States = Machine.state({ states: { Idle } })
|
|
9554
9303
|
* const machine = Machine.make({
|
|
9555
9304
|
* root: States,
|
|
9556
|
-
* events: Machine.eventsFromSchemas()
|
|
9557
|
-
*
|
|
9558
|
-
*
|
|
9559
|
-
*
|
|
9305
|
+
* events: Machine.eventsFromSchemas()
|
|
9306
|
+
* }).handle({
|
|
9307
|
+
* initial: {
|
|
9308
|
+
* target: Machine.targets(States).root.Idle
|
|
9309
|
+
* },
|
|
9310
|
+
* states: {
|
|
9311
|
+
* Idle: {}
|
|
9312
|
+
* }
|
|
9313
|
+
* })
|
|
9560
9314
|
* const state = Effect.gen(function*() {
|
|
9561
9315
|
* const ref = yield* Machine.start(machine)
|
|
9562
9316
|
* return yield* ref.state
|
|
@@ -9657,17 +9411,22 @@ export const start: <
|
|
|
9657
9411
|
* **Example**
|
|
9658
9412
|
*
|
|
9659
9413
|
* ```ts
|
|
9660
|
-
* import { Effect, Schema } from "effect"
|
|
9661
9414
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9662
|
-
*
|
|
9663
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
9664
|
-
*
|
|
9415
|
+
* import { Effect, Schema } from "effect"
|
|
9416
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
9417
|
+
* }
|
|
9418
|
+
* const States = Machine.state({ states: { Idle } })
|
|
9665
9419
|
* const machine = Machine.make({
|
|
9666
9420
|
* root: States,
|
|
9667
|
-
* events: Machine.eventsFromSchemas()
|
|
9668
|
-
*
|
|
9669
|
-
*
|
|
9670
|
-
*
|
|
9421
|
+
* events: Machine.eventsFromSchemas()
|
|
9422
|
+
* }).handle({
|
|
9423
|
+
* initial: {
|
|
9424
|
+
* target: Machine.targets(States).root.Idle
|
|
9425
|
+
* },
|
|
9426
|
+
* states: {
|
|
9427
|
+
* Idle: {}
|
|
9428
|
+
* }
|
|
9429
|
+
* })
|
|
9671
9430
|
* const resumed = Effect.gen(function*() {
|
|
9672
9431
|
* const initial = yield* Machine.planInitial(machine)
|
|
9673
9432
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|