@typeonce/effect-machine 0.31.2 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -140
- package/dist/Machine.d.ts +428 -254
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +91 -111
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +3 -4
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +0 -2
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/childRegistry.d.ts +52 -0
- package/dist/internal/machine/childRegistry.d.ts.map +1 -0
- package/dist/internal/machine/childRegistry.js +74 -0
- package/dist/internal/machine/childRegistry.js.map +1 -0
- package/dist/internal/machine/cluster.d.ts +2 -3
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +14 -4
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +1 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +97 -53
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +4 -2
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts +35 -0
- package/dist/internal/machine/invocationDefinition.d.ts.map +1 -0
- package/dist/internal/machine/invocationDefinition.js +21 -0
- package/dist/internal/machine/invocationDefinition.js.map +1 -0
- package/dist/internal/machine/invocationEvent.d.ts +0 -2
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +0 -8
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +21 -43
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +98 -374
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +13 -19
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +63 -35
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +6 -8
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +1 -0
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +2 -2
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +4 -18
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/readiness.d.ts +1 -1
- package/dist/internal/machine/readiness.d.ts.map +1 -1
- package/dist/internal/machine/requirements.d.ts +4 -0
- package/dist/internal/machine/requirements.d.ts.map +1 -0
- package/dist/internal/machine/requirements.js +2 -0
- package/dist/internal/machine/requirements.js.map +1 -0
- package/dist/internal/machine/runtime.d.ts +4 -58
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +1 -69
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/serialization.d.ts.map +1 -1
- package/dist/internal/machine/serialization.js +16 -0
- package/dist/internal/machine/serialization.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +3 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +36 -2
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/targetBuilder.d.ts +16 -0
- package/dist/internal/machine/targetBuilder.d.ts.map +1 -0
- package/dist/internal/machine/targetBuilder.js +333 -0
- package/dist/internal/machine/targetBuilder.js.map +1 -0
- package/dist/internal/machine/topology.js +3 -3
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/machine/transition.d.ts +16 -0
- package/dist/internal/machine/transition.d.ts.map +1 -0
- package/dist/internal/machine/transition.js +2 -0
- package/dist/internal/machine/transition.js.map +1 -0
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +10 -12
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/format.d.ts +7 -0
- package/dist/internal/testing/machine/format.d.ts.map +1 -0
- package/dist/internal/testing/machine/format.js +104 -0
- package/dist/internal/testing/machine/format.js.map +1 -0
- package/dist/internal/testing/machine/probe.d.ts +1 -1
- package/dist/internal/testing/machine/probe.d.ts.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.js.map +1 -1
- package/dist/internal/testing/machine/referenceModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/referenceModel.js +15 -19
- package/dist/internal/testing/machine/referenceModel.js.map +1 -1
- package/dist/internal/testing/machine/trace.d.ts +1 -1
- package/dist/internal/testing/machine/trace.d.ts.map +1 -1
- package/dist/internal/testing/machine/trace.js +3 -3
- package/dist/internal/testing/machine/trace.js.map +1 -1
- package/dist/internal/testing/machine/value.d.ts +8 -0
- package/dist/internal/testing/machine/value.d.ts.map +1 -0
- package/dist/internal/testing/machine/value.js +82 -0
- package/dist/internal/testing/machine/value.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts +2 -13
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +21 -113
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +89 -104
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +70 -84
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +10 -13
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +5 -8
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +26 -61
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +17 -26
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +45 -45
- package/docs/effect-atom-react.md +35 -63
- package/docs/machine-review.md +7 -7
- package/docs/root-api.md +214 -0
- package/package.json +1 -1
- package/src/Machine.ts +778 -437
- package/src/internal/machine/atom.ts +3 -13
- package/src/internal/machine/childRegistry.ts +141 -0
- package/src/internal/machine/cluster.ts +5 -14
- package/src/internal/machine/configuration.ts +20 -4
- package/src/internal/machine/executionPlan.ts +109 -52
- package/src/internal/machine/invocation.ts +10 -6
- package/src/internal/machine/invocationDefinition.ts +52 -0
- package/src/internal/machine/invocationEvent.ts +0 -8
- package/src/internal/machine/machine.ts +154 -679
- package/src/internal/machine/planner.ts +74 -62
- package/src/internal/machine/process.ts +14 -21
- package/src/internal/machine/protocol.ts +9 -32
- package/src/internal/machine/readiness.ts +1 -0
- package/src/internal/machine/requirements.ts +11 -0
- package/src/internal/machine/runtime.ts +17 -186
- package/src/internal/machine/serialization.ts +22 -0
- package/src/internal/machine/stateDefinition.ts +36 -3
- package/src/internal/machine/targetBuilder.ts +525 -0
- package/src/internal/machine/topology.ts +3 -3
- package/src/internal/machine/transition.ts +26 -0
- package/src/internal/testing/machine/finiteModel.ts +22 -23
- package/src/internal/testing/machine/format.ts +120 -0
- package/src/internal/testing/machine/probe.ts +4 -4
- package/src/internal/testing/machine/referenceModel.ts +25 -17
- package/src/internal/testing/machine/trace.ts +4 -4
- package/src/internal/testing/machine/value.ts +77 -0
- package/src/internal/testing/machine/verification.ts +904 -1109
- package/src/testing/MachineTest.ts +103 -114
- package/src/unstable/cluster/ClusterMachine.ts +10 -20
- package/src/unstable/reactivity/AtomMachine.ts +42 -79
|
@@ -10,8 +10,15 @@ import type * as Schema from "effect/Schema"
|
|
|
10
10
|
import type { FastCheck } from "effect/testing"
|
|
11
11
|
import type { EnsureExecutable } from "../internal/machine/readiness.js"
|
|
12
12
|
import type { SchemaArbitraryReport } from "../internal/testing/machine/arbitrary.js"
|
|
13
|
+
import * as ExplorationImpl from "../internal/testing/machine/exploration.js"
|
|
13
14
|
import type { FiniteModel } from "../internal/testing/machine/finiteModel.js"
|
|
14
|
-
import
|
|
15
|
+
import * as Format from "../internal/testing/machine/format.js"
|
|
16
|
+
import * as InvariantTest from "../internal/testing/machine/invariant.js"
|
|
17
|
+
import * as ProbeTest from "../internal/testing/machine/probe.js"
|
|
18
|
+
import * as ReferenceModel from "../internal/testing/machine/referenceModel.js"
|
|
19
|
+
import type * as RuntimeTest from "../internal/testing/machine/runtime.js"
|
|
20
|
+
import * as RuntimeInvariantTest from "../internal/testing/machine/runtimeInvariant.js"
|
|
21
|
+
import * as TraceImpl from "../internal/testing/machine/trace.js"
|
|
15
22
|
import * as internal from "../internal/testing/machine/verification.js"
|
|
16
23
|
import type { VerificationError } from "../internal/testing/machine/verification.js"
|
|
17
24
|
import type * as Machine from "../Machine.js"
|
|
@@ -64,13 +71,13 @@ export {
|
|
|
64
71
|
sendCommand,
|
|
65
72
|
stopCommand,
|
|
66
73
|
verifyCausalCommands
|
|
67
|
-
} from "../internal/testing/machine/
|
|
74
|
+
} from "../internal/testing/machine/runtime.js"
|
|
68
75
|
|
|
69
76
|
export type {
|
|
70
77
|
SchemaArbitraryOpaqueFilterWarning,
|
|
71
78
|
SchemaArbitraryReport,
|
|
72
79
|
SchemaArbitraryWarning
|
|
73
|
-
} from "../internal/testing/machine/
|
|
80
|
+
} from "../internal/testing/machine/arbitrary.js"
|
|
74
81
|
|
|
75
82
|
export {
|
|
76
83
|
compileModel,
|
|
@@ -92,7 +99,7 @@ export {
|
|
|
92
99
|
type FiniteState,
|
|
93
100
|
type FiniteTransition,
|
|
94
101
|
type FiniteTransitionTrigger
|
|
95
|
-
} from "../internal/testing/machine/
|
|
102
|
+
} from "../internal/testing/machine/finiteModel.js"
|
|
96
103
|
|
|
97
104
|
export {
|
|
98
105
|
ModelVerificationError,
|
|
@@ -108,7 +115,7 @@ export {
|
|
|
108
115
|
type ReferenceStep,
|
|
109
116
|
type ReferenceTrace,
|
|
110
117
|
type ReferenceTransition
|
|
111
|
-
} from "../internal/testing/machine/
|
|
118
|
+
} from "../internal/testing/machine/referenceModel.js"
|
|
112
119
|
|
|
113
120
|
/**
|
|
114
121
|
* Purely interprets a finite hierarchical model without compiling a
|
|
@@ -118,7 +125,7 @@ export {
|
|
|
118
125
|
* @since 0.4.0
|
|
119
126
|
*/
|
|
120
127
|
export const interpretModel: (model: FiniteModel, events: ReadonlyArray<string>) => ReferenceModel.ReferenceTrace =
|
|
121
|
-
|
|
128
|
+
ReferenceModel.interpretModel
|
|
122
129
|
|
|
123
130
|
type AnyMachine = Machine.Machine.Any
|
|
124
131
|
|
|
@@ -152,11 +159,11 @@ type RootReadyMachine<M extends AnyMachine> =
|
|
|
152
159
|
* @since 0.4.0
|
|
153
160
|
*/
|
|
154
161
|
export type Scenario<M extends AnyMachine> = Machine.Machine.InputSchema<M> extends typeof Schema.Void ? {
|
|
155
|
-
readonly events: ReadonlyArray<Machine.Machine.InputEvent<M
|
|
162
|
+
readonly events: ReadonlyArray<Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>>
|
|
156
163
|
}
|
|
157
164
|
: {
|
|
158
165
|
readonly input: InputValue<M>
|
|
159
|
-
readonly events: ReadonlyArray<Machine.Machine.InputEvent<M
|
|
166
|
+
readonly events: ReadonlyArray<Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>>
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
/**
|
|
@@ -231,22 +238,19 @@ export interface Scenarios<M extends AnyMachine> {
|
|
|
231
238
|
*
|
|
232
239
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
233
240
|
* class Reset extends Schema.TaggedClass<Reset>("Reset")("Reset", {}) {}
|
|
234
|
-
* const States = Machine.
|
|
241
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
235
242
|
* const machine = Machine.make({
|
|
236
|
-
*
|
|
237
|
-
* events: Machine.
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* resolve: ({ target }) => target.from()
|
|
241
|
-
* }
|
|
242
|
-
* }).handle({
|
|
243
|
+
* root: States,
|
|
244
|
+
* events: Machine.eventsFromSchemas(Reset),
|
|
245
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
|
|
246
|
+
* }).handle({ states: {
|
|
243
247
|
* Idle: {
|
|
244
248
|
* on: {
|
|
245
249
|
* Reset: (to) =>
|
|
246
|
-
* to.
|
|
250
|
+
* to.branch.Idle().resolve(({ target }) => target.from())
|
|
247
251
|
* }
|
|
248
252
|
* }
|
|
249
|
-
* })
|
|
253
|
+
* } })
|
|
250
254
|
*
|
|
251
255
|
* const generated = MachineTest.scenarios(machine, { maxEvents: 5 })
|
|
252
256
|
* ```
|
|
@@ -294,7 +298,7 @@ export interface Microstep<
|
|
|
294
298
|
>
|
|
295
299
|
readonly commands: ReadonlyArray<Machine.Command>
|
|
296
300
|
readonly raisedEvents: ReadonlyArray<Machine.Machine.Event<M>>
|
|
297
|
-
readonly emittedEvents: ReadonlyArray<Machine.Machine.
|
|
301
|
+
readonly emittedEvents: ReadonlyArray<Machine.Machine.EmittedEvent<M>>
|
|
298
302
|
readonly exitPaths: ReadonlyArray<string>
|
|
299
303
|
readonly entryPaths: ReadonlyArray<string>
|
|
300
304
|
readonly changed: boolean
|
|
@@ -312,7 +316,7 @@ export type InitialPlan<M extends AnyMachine> =
|
|
|
312
316
|
readonly initialEntryPaths: ReadonlyArray<StatePath<M>>
|
|
313
317
|
readonly state: Machine.Machine.Snapshot<Machine.Machine.States<M>>
|
|
314
318
|
readonly commands: ReadonlyArray<Machine.Command>
|
|
315
|
-
readonly emittedEvents: ReadonlyArray<Machine.Machine.
|
|
319
|
+
readonly emittedEvents: ReadonlyArray<Machine.Machine.EmittedEvent<M>>
|
|
316
320
|
readonly microsteps: ReadonlyArray<
|
|
317
321
|
Microstep<M, Machine.Machine.InitialServices<M> | Machine.Machine.Services<M>>
|
|
318
322
|
>
|
|
@@ -327,9 +331,10 @@ export type InitialPlan<M extends AnyMachine> =
|
|
|
327
331
|
*/
|
|
328
332
|
export type EventPlan<M extends AnyMachine> =
|
|
329
333
|
& {
|
|
334
|
+
readonly event: Machine.Machine.InputEvent<M>
|
|
330
335
|
readonly next: Machine.Machine.Snapshot<Machine.Machine.States<M>>
|
|
331
336
|
readonly commands: ReadonlyArray<Machine.Command>
|
|
332
|
-
readonly emittedEvents: ReadonlyArray<Machine.Machine.
|
|
337
|
+
readonly emittedEvents: ReadonlyArray<Machine.Machine.EmittedEvent<M>>
|
|
333
338
|
readonly microsteps: ReadonlyArray<Microstep<M>>
|
|
334
339
|
}
|
|
335
340
|
& PlanCompletion<M>
|
|
@@ -398,9 +403,10 @@ export type ProbeMicrostep<M extends AnyMachine> = Omit<Microstep<M>, "transitio
|
|
|
398
403
|
*/
|
|
399
404
|
export type ProbePlan<M extends AnyMachine> =
|
|
400
405
|
& {
|
|
406
|
+
readonly event: Machine.Machine.InputEvent<M>
|
|
401
407
|
readonly next: Machine.Machine.Snapshot<Machine.Machine.States<M>>
|
|
402
408
|
readonly commands: ReadonlyArray<Machine.Command>
|
|
403
|
-
readonly emittedEvents: ReadonlyArray<Machine.Machine.
|
|
409
|
+
readonly emittedEvents: ReadonlyArray<Machine.Machine.EmittedEvent<M>>
|
|
404
410
|
readonly microsteps: ReadonlyArray<ProbeMicrostep<M>>
|
|
405
411
|
}
|
|
406
412
|
& PlanCompletion<M>
|
|
@@ -440,16 +446,16 @@ export interface Probe<M extends AnyMachine, Error = never, Output = never> {
|
|
|
440
446
|
readonly machine: M
|
|
441
447
|
readonly ref: Machine.MachineRef<
|
|
442
448
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
443
|
-
Machine.Machine.InputEvent<M
|
|
449
|
+
Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>,
|
|
444
450
|
Error,
|
|
445
451
|
Output
|
|
446
452
|
>
|
|
447
453
|
readonly sendAndAwait: (
|
|
448
|
-
event: Machine.Machine.InputEvent<M
|
|
449
|
-
) => Effect.Effect<ProbeStep<M>, Error | Machine.StoppedError>
|
|
454
|
+
event: Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>
|
|
455
|
+
) => Effect.Effect<ProbeStep<M>, Error | Machine.MachineSchemaDecodeError | Machine.StoppedError>
|
|
450
456
|
/** Constructors for asynchronous observation after a causal command. */
|
|
451
457
|
readonly await: {
|
|
452
|
-
readonly none:
|
|
458
|
+
readonly none: RuntimeTest.RuntimeAwait<
|
|
453
459
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
454
460
|
Error,
|
|
455
461
|
Output
|
|
@@ -462,7 +468,7 @@ export interface Probe<M extends AnyMachine, Error = never, Output = never> {
|
|
|
462
468
|
Output
|
|
463
469
|
>
|
|
464
470
|
) => boolean
|
|
465
|
-
) =>
|
|
471
|
+
) => RuntimeTest.RuntimeAwait<Machine.Machine.Snapshot<Machine.Machine.States<M>>, Error, Output>
|
|
466
472
|
}
|
|
467
473
|
}
|
|
468
474
|
|
|
@@ -473,7 +479,7 @@ export interface Probe<M extends AnyMachine, Error = never, Output = never> {
|
|
|
473
479
|
* @category errors
|
|
474
480
|
* @since 0.4.0
|
|
475
481
|
*/
|
|
476
|
-
export { ProbeUnavailableError } from "../internal/testing/machine/
|
|
482
|
+
export { ProbeUnavailableError } from "../internal/testing/machine/probe.js"
|
|
477
483
|
|
|
478
484
|
/**
|
|
479
485
|
* Attaches testing-only causal event delivery to a running statechart.
|
|
@@ -490,15 +496,12 @@ export { ProbeUnavailableError } from "../internal/testing/machine/verification.
|
|
|
490
496
|
* import { MachineTest } from "@typeonce/effect-machine/testing"
|
|
491
497
|
*
|
|
492
498
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
493
|
-
* const States = Machine.
|
|
499
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
494
500
|
* const machine = Machine.make({
|
|
495
|
-
*
|
|
496
|
-
* events: Machine.
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
* resolve: ({ target }) => target.from()
|
|
500
|
-
* }
|
|
501
|
-
* }).handle({ Idle: {} })
|
|
501
|
+
* root: States,
|
|
502
|
+
* events: Machine.eventsFromSchemas(),
|
|
503
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
|
|
504
|
+
* }).handle({ states: { Idle: {} } })
|
|
502
505
|
*
|
|
503
506
|
* const program = Effect.gen(function*() {
|
|
504
507
|
* const ref = yield* Machine.start(machine)
|
|
@@ -513,11 +516,11 @@ export const probe: <M extends AnyMachine, Error, Output>(
|
|
|
513
516
|
machine: ReadyMachine<M>,
|
|
514
517
|
ref: Machine.MachineRef<
|
|
515
518
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
516
|
-
Machine.Machine.InputEvent<M
|
|
519
|
+
Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>,
|
|
517
520
|
Error,
|
|
518
521
|
Output
|
|
519
522
|
>
|
|
520
|
-
) => Effect.Effect<Probe<M, Error, Output>,
|
|
523
|
+
) => Effect.Effect<Probe<M, Error, Output>, ProbeTest.ProbeUnavailableError> = ProbeTest.probe
|
|
521
524
|
|
|
522
525
|
/**
|
|
523
526
|
* The runtime error channel exposed by a managed reference for a machine.
|
|
@@ -540,8 +543,8 @@ export type RuntimeInvariantErrorChannel<M extends AnyMachine> =
|
|
|
540
543
|
*/
|
|
541
544
|
export interface CausalRuntimeEvidenceRecord<M extends AnyMachine, Error, Output> {
|
|
542
545
|
readonly index: number
|
|
543
|
-
readonly command:
|
|
544
|
-
readonly actual:
|
|
546
|
+
readonly command: RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>
|
|
547
|
+
readonly actual: RuntimeTest.CausalRuntimeCommandActual<M, Error, Output, unknown>
|
|
545
548
|
}
|
|
546
549
|
|
|
547
550
|
/**
|
|
@@ -551,7 +554,7 @@ export interface CausalRuntimeEvidenceRecord<M extends AnyMachine, Error, Output
|
|
|
551
554
|
* @since 0.4.0
|
|
552
555
|
*/
|
|
553
556
|
export interface CausalRuntimeEvidence<M extends AnyMachine, Error, Output> {
|
|
554
|
-
readonly commands: ReadonlyArray<
|
|
557
|
+
readonly commands: ReadonlyArray<RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>>
|
|
555
558
|
readonly initial: Machine.RuntimeSnapshot<Machine.Machine.Snapshot<Machine.Machine.States<M>>, Error, Output>
|
|
556
559
|
readonly records: ReadonlyArray<CausalRuntimeEvidenceRecord<M, Error, Output>>
|
|
557
560
|
readonly final: Machine.RuntimeSnapshot<Machine.Machine.Snapshot<Machine.Machine.States<M>>, Error, Output>
|
|
@@ -581,8 +584,8 @@ export type RuntimeSnapshotObservation = "initial" | "command" | "awaited" | "fi
|
|
|
581
584
|
*/
|
|
582
585
|
export interface RuntimeInvariantRecord<M extends AnyMachine> {
|
|
583
586
|
readonly index: number
|
|
584
|
-
readonly command:
|
|
585
|
-
readonly result:
|
|
587
|
+
readonly command: RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>
|
|
588
|
+
readonly result: RuntimeTest.CausalRuntimeCommandResult<M>
|
|
586
589
|
readonly snapshot: Machine.RuntimeSnapshot<
|
|
587
590
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
588
591
|
RuntimeInvariantErrorChannel<M>,
|
|
@@ -604,7 +607,7 @@ export interface RuntimeInvariantRecord<M extends AnyMachine> {
|
|
|
604
607
|
* @since 0.4.0
|
|
605
608
|
*/
|
|
606
609
|
export interface RuntimeInvariantTranscript<M extends AnyMachine> {
|
|
607
|
-
readonly commands: ReadonlyArray<
|
|
610
|
+
readonly commands: ReadonlyArray<RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>>
|
|
608
611
|
readonly initial: Machine.RuntimeSnapshot<
|
|
609
612
|
Machine.Machine.Snapshot<Machine.Machine.States<M>>,
|
|
610
613
|
RuntimeInvariantErrorChannel<M>,
|
|
@@ -632,8 +635,8 @@ export interface RuntimeSnapshotInvariantContext<M extends AnyMachine> {
|
|
|
632
635
|
readonly phase: RuntimeSnapshotObservation
|
|
633
636
|
readonly commandIndex: number | undefined
|
|
634
637
|
readonly awaitedIndex: number | undefined
|
|
635
|
-
readonly command:
|
|
636
|
-
readonly result:
|
|
638
|
+
readonly command: RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>> | undefined
|
|
639
|
+
readonly result: RuntimeTest.CausalRuntimeCommandResult<M> | undefined
|
|
637
640
|
}
|
|
638
641
|
|
|
639
642
|
/**
|
|
@@ -648,8 +651,8 @@ export interface RuntimeCommandInvariantContext<M extends AnyMachine> {
|
|
|
648
651
|
readonly record: RuntimeInvariantRecord<M>
|
|
649
652
|
readonly previous: RuntimeInvariantRecord<M> | undefined
|
|
650
653
|
readonly index: number
|
|
651
|
-
readonly command:
|
|
652
|
-
readonly result:
|
|
654
|
+
readonly command: RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>
|
|
655
|
+
readonly result: RuntimeTest.CausalRuntimeCommandResult<M>
|
|
653
656
|
readonly snapshot: RuntimeInvariantRecord<M>["snapshot"]
|
|
654
657
|
readonly awaited: RuntimeInvariantRecord<M>["awaited"]
|
|
655
658
|
}
|
|
@@ -762,7 +765,7 @@ export interface RuntimeInvariantBuilder<M extends AnyMachine> {
|
|
|
762
765
|
* @since 0.4.0
|
|
763
766
|
*/
|
|
764
767
|
export const runtimeInvariants: <M extends AnyMachine>(machine: M) => RuntimeInvariantBuilder<M> =
|
|
765
|
-
|
|
768
|
+
RuntimeInvariantTest.runtimeInvariants
|
|
766
769
|
|
|
767
770
|
/**
|
|
768
771
|
* Scope of a runtime invariant.
|
|
@@ -810,7 +813,7 @@ export interface RuntimeInvariantViolation<M extends AnyMachine = AnyMachine> {
|
|
|
810
813
|
readonly commandIndex: number | undefined
|
|
811
814
|
readonly awaitedIndex?: number
|
|
812
815
|
readonly phase?: RuntimeSnapshotObservation
|
|
813
|
-
readonly command?:
|
|
816
|
+
readonly command?: RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>
|
|
814
817
|
readonly message: string
|
|
815
818
|
}
|
|
816
819
|
|
|
@@ -820,7 +823,7 @@ export interface RuntimeInvariantViolation<M extends AnyMachine = AnyMachine> {
|
|
|
820
823
|
* @category errors
|
|
821
824
|
* @since 0.4.0
|
|
822
825
|
*/
|
|
823
|
-
export { RuntimeInvariantError } from "../internal/testing/machine/
|
|
826
|
+
export { RuntimeInvariantError } from "../internal/testing/machine/runtimeInvariant.js"
|
|
824
827
|
|
|
825
828
|
/**
|
|
826
829
|
* Checks runtime invariants and returns their complete non-vacuity report.
|
|
@@ -832,7 +835,8 @@ export const checkRuntimeInvariants: <M extends AnyMachine, Error, Output>(
|
|
|
832
835
|
machine: M,
|
|
833
836
|
transcript: CausalRuntimeEvidence<M, Error, Output>,
|
|
834
837
|
invariants: ReadonlyArray<RuntimeInvariant<M>>
|
|
835
|
-
) => Effect.Effect<RuntimeInvariantReport,
|
|
838
|
+
) => Effect.Effect<RuntimeInvariantReport, RuntimeInvariantTest.RuntimeInvariantError<M>> =
|
|
839
|
+
RuntimeInvariantTest.checkRuntimeInvariants
|
|
836
840
|
|
|
837
841
|
/**
|
|
838
842
|
* Asserts runtime invariants against an existing causal transcript.
|
|
@@ -844,7 +848,7 @@ export const assertRuntimeInvariants: <M extends AnyMachine, Error, Output>(
|
|
|
844
848
|
machine: M,
|
|
845
849
|
transcript: CausalRuntimeEvidence<M, Error, Output>,
|
|
846
850
|
invariants: ReadonlyArray<RuntimeInvariant<M>>
|
|
847
|
-
) => Effect.Effect<void,
|
|
851
|
+
) => Effect.Effect<void, RuntimeInvariantTest.RuntimeInvariantError<M>> = RuntimeInvariantTest.assertRuntimeInvariants
|
|
848
852
|
|
|
849
853
|
/**
|
|
850
854
|
* One disagreement between pure planning and a causally processed send.
|
|
@@ -854,7 +858,7 @@ export const assertRuntimeInvariants: <M extends AnyMachine, Error, Output>(
|
|
|
854
858
|
*/
|
|
855
859
|
export interface PlannerRuntimeAgreementViolation<M extends AnyMachine = AnyMachine> {
|
|
856
860
|
readonly commandIndex: number
|
|
857
|
-
readonly command:
|
|
861
|
+
readonly command: RuntimeTest.RuntimeCommand<Machine.Machine.InputEvent<M>>
|
|
858
862
|
readonly field:
|
|
859
863
|
| "planning"
|
|
860
864
|
| "handled"
|
|
@@ -874,7 +878,7 @@ export interface PlannerRuntimeAgreementViolation<M extends AnyMachine = AnyMach
|
|
|
874
878
|
* @category errors
|
|
875
879
|
* @since 0.4.0
|
|
876
880
|
*/
|
|
877
|
-
export { PlannerRuntimeAgreementError } from "../internal/testing/machine/
|
|
881
|
+
export { PlannerRuntimeAgreementError } from "../internal/testing/machine/runtimeInvariant.js"
|
|
878
882
|
|
|
879
883
|
/**
|
|
880
884
|
* Checks that every processed public send agrees with a fresh pure plan.
|
|
@@ -885,8 +889,8 @@ export { PlannerRuntimeAgreementError } from "../internal/testing/machine/verifi
|
|
|
885
889
|
export const assertPlannerRuntimeAgreement: <M extends AnyMachine, Error, Output>(
|
|
886
890
|
machine: RootReadyMachine<M>,
|
|
887
891
|
transcript: CausalRuntimeEvidence<M, Error, Output>
|
|
888
|
-
) => Effect.Effect<void,
|
|
889
|
-
|
|
892
|
+
) => Effect.Effect<void, RuntimeInvariantTest.PlannerRuntimeAgreementError<M>, RunServices<M>> =
|
|
893
|
+
RuntimeInvariantTest.assertPlannerRuntimeAgreement
|
|
890
894
|
|
|
891
895
|
/**
|
|
892
896
|
* The result of evaluating one semantic invariant.
|
|
@@ -1086,7 +1090,7 @@ export const Invariant: {
|
|
|
1086
1090
|
check: (context: TraceInvariantContext<M>) => InvariantOutcome,
|
|
1087
1091
|
options?: InvariantOptions<TraceInvariantContext<M>>
|
|
1088
1092
|
) => TraceInvariant<M>
|
|
1089
|
-
} =
|
|
1093
|
+
} = InvariantTest.Invariant
|
|
1090
1094
|
|
|
1091
1095
|
/**
|
|
1092
1096
|
* Creates invariant constructors bound to a machine's exact state and event
|
|
@@ -1103,15 +1107,12 @@ export const Invariant: {
|
|
|
1103
1107
|
* class Count extends Schema.TaggedClass<Count>("Count")("Count", {
|
|
1104
1108
|
* value: Schema.Number
|
|
1105
1109
|
* }) {}
|
|
1106
|
-
* const States = Machine.
|
|
1110
|
+
* const States = Machine.state({ initial: "Count", states: { Count } })
|
|
1107
1111
|
* const machine = Machine.make({
|
|
1108
|
-
*
|
|
1109
|
-
* events: Machine.
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
* resolve: ({ target }) => target.decoded(new Count({ value: 0 }))
|
|
1113
|
-
* }
|
|
1114
|
-
* }).handle({ Count: {} })
|
|
1112
|
+
* root: States,
|
|
1113
|
+
* events: Machine.eventsFromSchemas(),
|
|
1114
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Count.decoded(new Count({ value: 0 }))))
|
|
1115
|
+
* }).handle({ states: { Count: {} } })
|
|
1115
1116
|
*
|
|
1116
1117
|
* const nonNegative = MachineTest.invariants(machine).state(
|
|
1117
1118
|
* "count is non-negative",
|
|
@@ -1122,7 +1123,7 @@ export const Invariant: {
|
|
|
1122
1123
|
* @category constructors
|
|
1123
1124
|
* @since 0.4.0
|
|
1124
1125
|
*/
|
|
1125
|
-
export const invariants: <M extends AnyMachine>(machine: M) => InvariantBuilder<M> =
|
|
1126
|
+
export const invariants: <M extends AnyMachine>(machine: M) => InvariantBuilder<M> = InvariantTest.invariants
|
|
1126
1127
|
|
|
1127
1128
|
/**
|
|
1128
1129
|
* The scope of a semantic invariant.
|
|
@@ -1193,7 +1194,7 @@ export interface InvariantViolation<M extends AnyMachine = AnyMachine> {
|
|
|
1193
1194
|
* @category errors
|
|
1194
1195
|
* @since 0.4.0
|
|
1195
1196
|
*/
|
|
1196
|
-
export { InvariantError } from "../internal/testing/machine/
|
|
1197
|
+
export { InvariantError } from "../internal/testing/machine/invariant.js"
|
|
1197
1198
|
|
|
1198
1199
|
/**
|
|
1199
1200
|
* Checks user-defined semantic invariants against an existing planner trace.
|
|
@@ -1209,7 +1210,7 @@ export const checkInvariants: <M extends AnyMachine>(
|
|
|
1209
1210
|
machine: M,
|
|
1210
1211
|
trace: Trace<M>,
|
|
1211
1212
|
invariants: ReadonlyArray<Invariant<M>>
|
|
1212
|
-
) => Effect.Effect<InvariantReport,
|
|
1213
|
+
) => Effect.Effect<InvariantReport, InvariantTest.InvariantError<M>> = InvariantTest.checkInvariants
|
|
1213
1214
|
|
|
1214
1215
|
/**
|
|
1215
1216
|
* Asserts user-defined semantic invariants and discards the success report.
|
|
@@ -1225,7 +1226,7 @@ export const assertInvariants: <M extends AnyMachine>(
|
|
|
1225
1226
|
machine: M,
|
|
1226
1227
|
trace: Trace<M>,
|
|
1227
1228
|
invariants: ReadonlyArray<Invariant<M>>
|
|
1228
|
-
) => Effect.Effect<void,
|
|
1229
|
+
) => Effect.Effect<void, InvariantTest.InvariantError<M>> = InvariantTest.assertInvariants
|
|
1229
1230
|
|
|
1230
1231
|
/**
|
|
1231
1232
|
* User-defined identity for a logical exploration state.
|
|
@@ -1438,23 +1439,20 @@ export type ExploreOptions<M extends AnyMachine, Key extends ExplorationKey = Ex
|
|
|
1438
1439
|
* value: Schema.Number
|
|
1439
1440
|
* }) {}
|
|
1440
1441
|
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {}) {}
|
|
1441
|
-
* const States = Machine.
|
|
1442
|
+
* const States = Machine.state({ initial: "Count", states: { Count } })
|
|
1442
1443
|
* const machine = Machine.make({
|
|
1443
|
-
*
|
|
1444
|
-
* events: Machine.
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1447
|
-
* resolve: ({ target }) => target.decoded(new Count({ value: 0 }))
|
|
1448
|
-
* }
|
|
1449
|
-
* }).handle({
|
|
1444
|
+
* root: States,
|
|
1445
|
+
* events: Machine.eventsFromSchemas(Increment),
|
|
1446
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Count.decoded(new Count({ value: 0 }))))
|
|
1447
|
+
* }).handle({ states: {
|
|
1450
1448
|
* Count: {
|
|
1451
1449
|
* on: {
|
|
1452
1450
|
* Increment: (to) =>
|
|
1453
|
-
* to.
|
|
1451
|
+
* to.branch.Count().resolve(({ state, target }) =>
|
|
1454
1452
|
* target.decoded(new Count({ value: state.value + 1 })))
|
|
1455
1453
|
* }
|
|
1456
1454
|
* }
|
|
1457
|
-
* })
|
|
1455
|
+
* } })
|
|
1458
1456
|
*
|
|
1459
1457
|
* const explored = MachineTest.explore(machine, {
|
|
1460
1458
|
* events: ({ snapshot }) => snapshot.value.value < 2 ? [new Increment({})] : [],
|
|
@@ -1470,9 +1468,9 @@ export const explore: <M extends AnyMachine, Key extends ExplorationKey>(
|
|
|
1470
1468
|
options: ExploreOptions<M, Key>
|
|
1471
1469
|
) => Effect.Effect<
|
|
1472
1470
|
Exploration<M, Key>,
|
|
1473
|
-
RunFailure<RunError<M>, M> |
|
|
1471
|
+
RunFailure<RunError<M>, M> | InvariantTest.InvariantError<M>,
|
|
1474
1472
|
RunServices<M>
|
|
1475
|
-
> =
|
|
1473
|
+
> = ExplorationImpl.explore
|
|
1476
1474
|
|
|
1477
1475
|
/**
|
|
1478
1476
|
* A predicate over one explored logical state.
|
|
@@ -1498,7 +1496,7 @@ export type ReachabilityFailure = "NotFound" | "UnexpectedMatch" | "Inconclusive
|
|
|
1498
1496
|
* @category errors
|
|
1499
1497
|
* @since 0.4.0
|
|
1500
1498
|
*/
|
|
1501
|
-
export { ReachabilityError } from "../internal/testing/machine/
|
|
1499
|
+
export { ReachabilityError } from "../internal/testing/machine/exploration.js"
|
|
1502
1500
|
|
|
1503
1501
|
/**
|
|
1504
1502
|
* Finds the first, and therefore shortest, explored state matching a
|
|
@@ -1510,7 +1508,7 @@ export { ReachabilityError } from "../internal/testing/machine/verification.js"
|
|
|
1510
1508
|
export const findShortest: <M extends AnyMachine, Key extends ExplorationKey>(
|
|
1511
1509
|
exploration: Exploration<M, Key>,
|
|
1512
1510
|
predicate: ExplorationPredicate<M, Key>
|
|
1513
|
-
) => ExplorationNode<M, Key> | undefined =
|
|
1511
|
+
) => ExplorationNode<M, Key> | undefined = ExplorationImpl.findShortest
|
|
1514
1512
|
|
|
1515
1513
|
/**
|
|
1516
1514
|
* Requires a matching state and returns its shortest witness.
|
|
@@ -1525,7 +1523,7 @@ export const assertReachable: <M extends AnyMachine, Key extends ExplorationKey>
|
|
|
1525
1523
|
exploration: Exploration<M, Key>,
|
|
1526
1524
|
name: string,
|
|
1527
1525
|
predicate: ExplorationPredicate<M, Key>
|
|
1528
|
-
) => Effect.Effect<ExplorationNode<M, Key>,
|
|
1526
|
+
) => Effect.Effect<ExplorationNode<M, Key>, ExplorationImpl.ReachabilityError<M, Key>> = ExplorationImpl.assertReachable
|
|
1529
1527
|
|
|
1530
1528
|
/**
|
|
1531
1529
|
* Requires that no explored state matches a predicate.
|
|
@@ -1540,7 +1538,7 @@ export const assertUnreachable: <M extends AnyMachine, Key extends ExplorationKe
|
|
|
1540
1538
|
exploration: Exploration<M, Key>,
|
|
1541
1539
|
name: string,
|
|
1542
1540
|
predicate: ExplorationPredicate<M, Key>
|
|
1543
|
-
) => Effect.Effect<void,
|
|
1541
|
+
) => Effect.Effect<void, ExplorationImpl.ReachabilityError<M, Key>> = ExplorationImpl.assertUnreachable
|
|
1544
1542
|
|
|
1545
1543
|
/**
|
|
1546
1544
|
* Checks a real planner trace against the independent finite statechart model
|
|
@@ -1581,7 +1579,7 @@ export type RunFailure<Cause, M extends AnyMachine = AnyMachine> =
|
|
|
1581
1579
|
readonly scenario: Scenario<M>
|
|
1582
1580
|
readonly phase: "event"
|
|
1583
1581
|
readonly eventIndex: number
|
|
1584
|
-
readonly event: Machine.Machine.InputEvent<M
|
|
1582
|
+
readonly event: Machine.Machine.EventInput<Machine.Machine.InputEvent<M>>
|
|
1585
1583
|
readonly initial: InitialTrace<M>
|
|
1586
1584
|
readonly steps: ReadonlyArray<TraceStep<M>>
|
|
1587
1585
|
readonly cause: Cause
|
|
@@ -1630,15 +1628,12 @@ export type RunServices<M extends AnyMachine> = IsAny<
|
|
|
1630
1628
|
* import { MachineTest } from "@typeonce/effect-machine/testing"
|
|
1631
1629
|
*
|
|
1632
1630
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
1633
|
-
* const States = Machine.
|
|
1631
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
1634
1632
|
* const machine = Machine.make({
|
|
1635
|
-
*
|
|
1636
|
-
* events: Machine.
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1639
|
-
* resolve: ({ target }) => target.from()
|
|
1640
|
-
* }
|
|
1641
|
-
* }).handle({ Idle: {} })
|
|
1633
|
+
* root: States,
|
|
1634
|
+
* events: Machine.eventsFromSchemas(),
|
|
1635
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
|
|
1636
|
+
* }).handle({ states: { Idle: {} } })
|
|
1642
1637
|
*
|
|
1643
1638
|
* const trace = MachineTest.run(machine, { events: [] })
|
|
1644
1639
|
* ```
|
|
@@ -1649,7 +1644,7 @@ export type RunServices<M extends AnyMachine> = IsAny<
|
|
|
1649
1644
|
export const run: <M extends AnyMachine>(
|
|
1650
1645
|
machine: RootReadyMachine<M>,
|
|
1651
1646
|
scenario: Scenario<M>
|
|
1652
|
-
) => Effect.Effect<Trace<M>, RunFailure<RunError<M>, M>, RunServices<M>> =
|
|
1647
|
+
) => Effect.Effect<Trace<M>, RunFailure<RunError<M>, M>, RunServices<M>> = TraceImpl.run
|
|
1653
1648
|
|
|
1654
1649
|
/**
|
|
1655
1650
|
* A deterministic hit/miss summary for a finite set declared by a machine.
|
|
@@ -1899,15 +1894,12 @@ export interface Coverage<M extends AnyMachine> {
|
|
|
1899
1894
|
* import { MachineTest } from "@typeonce/effect-machine/testing"
|
|
1900
1895
|
*
|
|
1901
1896
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
1902
|
-
* const States = Machine.
|
|
1897
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
1903
1898
|
* const machine = Machine.make({
|
|
1904
|
-
*
|
|
1905
|
-
* events: Machine.
|
|
1906
|
-
*
|
|
1907
|
-
*
|
|
1908
|
-
* resolve: ({ target }) => target.from()
|
|
1909
|
-
* }
|
|
1910
|
-
* }).handle({ Idle: {} })
|
|
1899
|
+
* root: States,
|
|
1900
|
+
* events: Machine.eventsFromSchemas(),
|
|
1901
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
|
|
1902
|
+
* }).handle({ states: { Idle: {} } })
|
|
1911
1903
|
*
|
|
1912
1904
|
* const report = Effect.map(
|
|
1913
1905
|
* MachineTest.run(machine, { events: [] }),
|
|
@@ -1962,7 +1954,7 @@ export interface ObservedGraphMicrostep<M extends AnyMachine> {
|
|
|
1962
1954
|
readonly event: Machine.Machine.Event<M> | Machine.InitialEvent
|
|
1963
1955
|
readonly transitions: Microstep<M, any>["transitions"]
|
|
1964
1956
|
readonly raisedEvents: ReadonlyArray<Machine.Machine.Event<M>>
|
|
1965
|
-
readonly emittedEvents: ReadonlyArray<Machine.Machine.
|
|
1957
|
+
readonly emittedEvents: ReadonlyArray<Machine.Machine.EmittedEvent<M>>
|
|
1966
1958
|
readonly exitPaths: ReadonlyArray<StatePath<M>>
|
|
1967
1959
|
readonly entryPaths: ReadonlyArray<StatePath<M>>
|
|
1968
1960
|
readonly changed: boolean
|
|
@@ -2128,15 +2120,12 @@ export interface VerifyOptions {
|
|
|
2128
2120
|
* import { MachineTest } from "@typeonce/effect-machine/testing"
|
|
2129
2121
|
*
|
|
2130
2122
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
2131
|
-
* const States = Machine.
|
|
2123
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
2132
2124
|
* const machine = Machine.make({
|
|
2133
|
-
*
|
|
2134
|
-
* events: Machine.
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
2137
|
-
* resolve: ({ target }) => target.from()
|
|
2138
|
-
* }
|
|
2139
|
-
* }).handle({ Idle: {} })
|
|
2125
|
+
* root: States,
|
|
2126
|
+
* events: Machine.eventsFromSchemas(),
|
|
2127
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
|
|
2128
|
+
* }).handle({ states: { Idle: {} } })
|
|
2140
2129
|
*
|
|
2141
2130
|
* const checked = Effect.gen(function*() {
|
|
2142
2131
|
* const trace = yield* MachineTest.run(machine, { events: [] })
|
|
@@ -2164,4 +2153,4 @@ export const verify: <M extends AnyMachine>(
|
|
|
2164
2153
|
* @since 0.4.0
|
|
2165
2154
|
*/
|
|
2166
2155
|
export const formatTrace: <M extends AnyMachine, Cause>(trace: Trace<M> | RunFailure<Cause, M>) => string =
|
|
2167
|
-
|
|
2156
|
+
Format.formatTrace
|
|
@@ -12,6 +12,7 @@ import type { Rpc } from "effect/unstable/rpc"
|
|
|
12
12
|
import * as internal from "../../internal/machine/cluster.js"
|
|
13
13
|
import { Accepted, Rejected, Storage } from "../../internal/machine/cluster.js"
|
|
14
14
|
import type { EnsureExecutable } from "../../internal/machine/readiness.js"
|
|
15
|
+
import type { ExcludeCompatibleRuntime } from "../../internal/machine/requirements.js"
|
|
15
16
|
import type * as Machine from "../../Machine.js"
|
|
16
17
|
|
|
17
18
|
type Snowflake = Snowflake.Snowflake
|
|
@@ -191,7 +192,7 @@ type SendRpc<Events extends ReadonlyArray<Machine.Machine.TaggedSchema>> = Rpc.R
|
|
|
191
192
|
|
|
192
193
|
type MachineEvents<M extends Machine.Machine.Any> = Machine.Machine.InputEvents<M>
|
|
193
194
|
|
|
194
|
-
type MachineEmits<M extends Machine.Machine.Any> = Machine.Machine.
|
|
195
|
+
type MachineEmits<M extends Machine.Machine.Any> = Machine.Machine.EmittedEvents<M>
|
|
195
196
|
|
|
196
197
|
/**
|
|
197
198
|
* Cluster adapter for one machine definition and entity type.
|
|
@@ -231,7 +232,7 @@ export interface ClusterMachine<
|
|
|
231
232
|
*/
|
|
232
233
|
readonly toLayer: <R = never>(options?: {
|
|
233
234
|
readonly enqueue?: (
|
|
234
|
-
event: Machine.Machine.
|
|
235
|
+
event: Machine.Machine.EmittedEventOf<MachineEmits<M>>
|
|
235
236
|
) => Effect.Effect<void, unknown, R>
|
|
236
237
|
}) => Layer.Layer<never, never, Storage | MessageStorage.MessageStorage | Sharding.Sharding | R | Services>
|
|
237
238
|
}
|
|
@@ -240,7 +241,7 @@ type MachineServices<M extends Machine.Machine.Any> =
|
|
|
240
241
|
| ExcludeCompatibleRuntime<
|
|
241
242
|
Machine.ExecutionServices<Machine.Machine.Services<M> | Machine.Machine.InitialServices<M>>,
|
|
242
243
|
Machine.Machine.Event<M>,
|
|
243
|
-
Machine.Machine.
|
|
244
|
+
Machine.Machine.EmittedEvent<M>
|
|
244
245
|
>
|
|
245
246
|
| Machine.Machine.SnapshotDecodingServices<Machine.Machine.States<M>>
|
|
246
247
|
| Machine.Machine.SnapshotEncodingServices<Machine.Machine.States<M>>
|
|
@@ -292,14 +293,6 @@ type EnsureJsonEncoded<
|
|
|
292
293
|
}
|
|
293
294
|
}
|
|
294
295
|
|
|
295
|
-
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Machine.Runtime.Requirement<
|
|
296
|
-
infer RequiredEvents,
|
|
297
|
-
infer RequiredEmits
|
|
298
|
-
> ? IsAny<Requirements> extends true ? Requirements
|
|
299
|
-
: [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements
|
|
300
|
-
: Requirements
|
|
301
|
-
: Requirements
|
|
302
|
-
|
|
303
296
|
/**
|
|
304
297
|
* Creates an in-memory Cluster machine checkpoint store.
|
|
305
298
|
*
|
|
@@ -361,15 +354,12 @@ export const layerMemory: Layer.Layer<Storage> = internal.layerMemory
|
|
|
361
354
|
* import { ClusterMachine } from "@typeonce/effect-machine/cluster"
|
|
362
355
|
*
|
|
363
356
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
364
|
-
* const States = Machine.
|
|
357
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
365
358
|
* const machine = Machine.make({
|
|
366
|
-
*
|
|
367
|
-
* events: Machine.
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* resolve: ({ target }) => target.from()
|
|
371
|
-
* }
|
|
372
|
-
* }).handle({ Idle: {} })
|
|
359
|
+
* root: States,
|
|
360
|
+
* events: Machine.eventsFromSchemas(),
|
|
361
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(tree => tree.Idle.from()))
|
|
362
|
+
* }).handle({ states: { Idle: {} } })
|
|
373
363
|
*
|
|
374
364
|
* const adapter = ClusterMachine.make("IdleMachine", machine, { version: "1" })
|
|
375
365
|
* ```
|
|
@@ -440,7 +430,7 @@ export const make: <
|
|
|
440
430
|
| ExcludeCompatibleRuntime<
|
|
441
431
|
Machine.ExecutionServices<R | InitialR>,
|
|
442
432
|
Machine.Machine.EventOf<Events>,
|
|
443
|
-
Machine.Machine.
|
|
433
|
+
Machine.Machine.EmittedEventOf<Emits>
|
|
444
434
|
>
|
|
445
435
|
| Machine.Machine.SnapshotDecodingServices<States>
|
|
446
436
|
| Machine.Machine.SnapshotEncodingServices<States>
|