@typeonce/effect-machine-devtools 0.46.0 → 0.47.1
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 +14 -1
- package/dist/DevToolsProtocol.d.ts +62 -6
- package/dist/DevToolsProtocol.d.ts.map +1 -1
- package/dist/DevToolsProtocol.js +21 -0
- package/dist/DevToolsProtocol.js.map +1 -1
- package/dist/MachineDocument.d.ts +0 -3
- package/dist/MachineDocument.d.ts.map +1 -1
- package/dist/MachineDocument.js +1 -2
- package/dist/MachineDocument.js.map +1 -1
- package/dist/MachineRegistry.d.ts +0 -2
- package/dist/MachineRegistry.d.ts.map +1 -1
- package/dist/MachineWalkthrough.d.ts +1 -1
- package/dist/MachineWalkthrough.d.ts.map +1 -1
- package/dist/ProjectInspector.d.ts +9 -0
- package/dist/ProjectInspector.d.ts.map +1 -1
- package/dist/ProjectInspector.js +8 -0
- package/dist/ProjectInspector.js.map +1 -1
- package/dist/bin.js +13 -1
- package/dist/bin.js.map +1 -1
- package/dist/client/assets/index-BVMbU47j.js +37 -0
- package/dist/client/index.html +1 -1
- package/dist/internal/checkCommand.d.ts +6 -0
- package/dist/internal/checkCommand.d.ts.map +1 -0
- package/dist/internal/checkCommand.js +22 -0
- package/dist/internal/checkCommand.js.map +1 -0
- package/dist/internal/devServer.js +2 -2
- package/dist/internal/devServer.js.map +1 -1
- package/dist/internal/evaluationWorker.d.ts.map +1 -1
- package/dist/internal/evaluationWorker.js +43 -9
- package/dist/internal/evaluationWorker.js.map +1 -1
- package/dist/internal/machineDocument.d.ts.map +1 -1
- package/dist/internal/machineDocument.js +1 -1
- package/dist/internal/machineDocument.js.map +1 -1
- package/dist/internal/machineWalkthrough.d.ts.map +1 -1
- package/dist/internal/machineWalkthrough.js +0 -1
- package/dist/internal/machineWalkthrough.js.map +1 -1
- package/dist/internal/projectInspector.d.ts.map +1 -1
- package/dist/internal/projectInspector.js +16 -2
- package/dist/internal/projectInspector.js.map +1 -1
- package/package.json +8 -8
- package/src/DevToolsProtocol.ts +35 -0
- package/src/MachineDocument.ts +1 -2
- package/src/MachineWalkthrough.ts +1 -1
- package/src/ProjectInspector.ts +16 -0
- package/src/bin.ts +26 -1
- package/src/internal/browser/chart-layout.ts +19 -20
- package/src/internal/browser/chart-model.ts +2 -2
- package/src/internal/browser/example-machine.ts +16 -13
- package/src/internal/browser/hierarchy-routing-example.ts +9 -11
- package/src/internal/browser/invoke-outcomes-example.ts +10 -13
- package/src/internal/browser/layout-resilience-example.ts +17 -20
- package/src/internal/browser/parallel-completion-example.ts +3 -3
- package/src/internal/browser/parallel-owner-routing-example.ts +5 -5
- package/src/internal/browser/planner-example.ts +6 -11
- package/src/internal/browser/protocol-events-example.ts +16 -19
- package/src/internal/browser/text-tree.ts +2 -2
- package/src/internal/browser/transition-semantics-example.ts +37 -32
- package/src/internal/browser/visualizer-app.ts +8 -6
- package/src/internal/browser/visualizer-model.ts +1 -1
- package/src/internal/checkCommand.ts +38 -0
- package/src/internal/devServer.ts +2 -2
- package/src/internal/evaluationWorker.ts +93 -19
- package/src/internal/machineDocument.ts +2 -4
- package/src/internal/machineWalkthrough.ts +0 -1
- package/src/internal/projectInspector.ts +42 -4
- package/dist/client/assets/index-CVtleuI-.js +0 -37
package/src/bin.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
|
|
3
3
|
import * as NodeServices from "@effect/platform-node/NodeServices"
|
|
4
|
+
import * as Argument from "effect/cli/Argument"
|
|
4
5
|
import * as Command from "effect/cli/Command"
|
|
5
6
|
import * as Flag from "effect/cli/Flag"
|
|
6
7
|
import * as Console from "effect/Console"
|
|
7
8
|
import * as Effect from "effect/Effect"
|
|
8
9
|
import * as Layer from "effect/Layer"
|
|
10
|
+
import * as Option from "effect/Option"
|
|
9
11
|
import PackageJson from "../package.json" with { type: "json" }
|
|
10
12
|
import * as DevServer from "./DevServer.js"
|
|
13
|
+
import * as CheckCommand from "./internal/checkCommand.js"
|
|
11
14
|
import * as StaticSite from "./internal/staticSite.js"
|
|
12
15
|
import * as MachineRegistry from "./MachineRegistry.js"
|
|
13
16
|
import * as ProjectInspector from "./ProjectInspector.js"
|
|
@@ -78,7 +81,29 @@ const build = Command.make("build", { outputDirectory }).pipe(
|
|
|
78
81
|
}))
|
|
79
82
|
)
|
|
80
83
|
|
|
81
|
-
const
|
|
84
|
+
const target = Argument.String("path").pipe(
|
|
85
|
+
Argument.withDescription("Machine source file or glob relative to the project root"),
|
|
86
|
+
Argument.optional
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const json = Flag.Boolean("json").pipe(
|
|
90
|
+
Flag.withDescription("Print one JSON object instead of text"),
|
|
91
|
+
Flag.withDefault(false)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
const check = Command.make("check", { target, json }).pipe(
|
|
95
|
+
Command.withDescription("Analyze, explore, and verify the project's machines, and exit non-zero on any error"),
|
|
96
|
+
Command.withHandler(Effect.fnUntraced(function*({ json, target }) {
|
|
97
|
+
const { include, root } = yield* base
|
|
98
|
+
const results = yield* ProjectInspector.check({ root, include: Option.getOrElse(target, () => include) }).pipe(
|
|
99
|
+
Effect.provide(ProjectInspector.layer)
|
|
100
|
+
)
|
|
101
|
+
yield* Console.log(json ? CheckCommand.renderJson(results) : CheckCommand.renderText(results))
|
|
102
|
+
if (!CheckCommand.isOk(results)) yield* Effect.sync(() => (process.exitCode = 1))
|
|
103
|
+
}))
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
const cli = dev.pipe(Command.withSubcommands([build, check]))
|
|
82
107
|
|
|
83
108
|
Command.run(cli, { version: PackageJson.version }).pipe(
|
|
84
109
|
Effect.provide(NodeServices.layer),
|
|
@@ -261,6 +261,7 @@ const nodeMetric = (node: ChartNode, selfLoops: number): NodeMetric => {
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
// oxlint-disable-next-line typescript/no-unnecessary-type-assertion -- TypeScript 6 does not type the CommonJS default export as constructable.
|
|
264
265
|
const ELK = ELKBundle as unknown as new(args?: ELKConstructorArguments) => ElkApi
|
|
265
266
|
const elk = new ELK()
|
|
266
267
|
|
|
@@ -464,24 +465,22 @@ const makeGraph = (
|
|
|
464
465
|
return {
|
|
465
466
|
id: "chart-root",
|
|
466
467
|
children: children(null),
|
|
467
|
-
edges:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
"elk.layered.priority.straightness": "5"
|
|
481
|
-
}
|
|
468
|
+
edges: model.edges.map((edge): ElkExtendedEdge => {
|
|
469
|
+
const label = labelMetric(edge)
|
|
470
|
+
const edgeLayout = policy.edge(edge)
|
|
471
|
+
const runtimeTarget = edge.kind === "runtime" ? runtimeByEdgeId.get(edge.id) : undefined
|
|
472
|
+
return {
|
|
473
|
+
id: edge.id,
|
|
474
|
+
sources: [sourcePortId(edge)],
|
|
475
|
+
targets: [runtimeTarget === undefined ? targetPortId(edge) : runtimeTargetPortId(runtimeTarget)],
|
|
476
|
+
labels: [{ text: edge.accessibleLabel, width: label.width, height: label.height }],
|
|
477
|
+
layoutOptions: {
|
|
478
|
+
"elk.layered.priority.direction": edgeLayout.direction === "forward" ? "10" : "1",
|
|
479
|
+
"elk.layered.priority.shortness": "5",
|
|
480
|
+
"elk.layered.priority.straightness": "5"
|
|
482
481
|
}
|
|
483
|
-
}
|
|
484
|
-
|
|
482
|
+
}
|
|
483
|
+
}),
|
|
485
484
|
layoutOptions: {
|
|
486
485
|
"elk.algorithm": "layered",
|
|
487
486
|
"elk.direction": "DOWN",
|
|
@@ -916,20 +915,20 @@ const normalizeEndpointDirection = (
|
|
|
916
915
|
const validEndpoints = (route: ReadonlyArray<ChartPoint>): boolean =>
|
|
917
916
|
isOutwardStep(route[0]!, route[1]!, side) && chartRouteLength(route.slice(0, 2)) >= 9 &&
|
|
918
917
|
(!preserveOpposite ||
|
|
919
|
-
isOutwardStep(route.at(-1)!, route.at(-2)!, oppositeSide
|
|
918
|
+
isOutwardStep(route.at(-1)!, route.at(-2)!, oppositeSide) && chartRouteLength(route.slice(-2)) >= 9)
|
|
920
919
|
|
|
921
920
|
const tail = points.slice(1)
|
|
922
921
|
const attached = compactPoints([start, ...tail])
|
|
923
922
|
if (attached.length >= 2 && validEndpoints(attached)) return attached
|
|
924
923
|
|
|
925
924
|
if (tail.length === 1 && preserveOpposite) {
|
|
926
|
-
tail.unshift(outwardPoint(end, oppositeSide
|
|
925
|
+
tail.unshift(outwardPoint(end, oppositeSide, 18))
|
|
927
926
|
}
|
|
928
927
|
const stub = outwardPoint(start, side, 18)
|
|
929
928
|
const endpointObstacles = [
|
|
930
929
|
...obstacles,
|
|
931
930
|
routeNodeRect(node),
|
|
932
|
-
...(preserveOpposite ? [routeNodeRect(opposite
|
|
931
|
+
...(preserveOpposite ? [routeNodeRect(opposite)] : [])
|
|
933
932
|
]
|
|
934
933
|
return endpointConnections(stub, tail[0]!, routeNodeRect(node), side)
|
|
935
934
|
.map((connection) => compactPoints([start, ...connection, ...tail.slice(1)]))
|
|
@@ -89,7 +89,7 @@ const activityLabel = (activity: VisualizationActivity): string => {
|
|
|
89
89
|
|
|
90
90
|
const transitionLabel = (transition: VisualizationTransition, branch: VisualizationBranch): string => {
|
|
91
91
|
const trigger = triggerLabel(transition)
|
|
92
|
-
return branch.type === "branch" ? `${trigger} · ${branch.
|
|
92
|
+
return branch.type === "branch" ? `${trigger} · ${branch.key}` : trigger
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
interface TriggerPresentation {
|
|
@@ -118,7 +118,7 @@ const triggerPresentation = (transition: VisualizationTransition): TriggerPresen
|
|
|
118
118
|
const visibleLabel = (transition: VisualizationTransition, branches: ReadonlyArray<VisualizationBranch>): string => {
|
|
119
119
|
const presentation = triggerPresentation(transition)
|
|
120
120
|
if (branches.length !== 1 || branches[0]?.type !== "branch") return presentation.label
|
|
121
|
-
return [presentation.label, branches[0].
|
|
121
|
+
return [presentation.label, branches[0].key].filter((part) => part.length > 0).join(" · ")
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
const labelBadges = (
|
|
@@ -96,11 +96,6 @@ const initialWorkflow = (): Machine.Machine.CompleteSnapshotContaining<{
|
|
|
96
96
|
readonly "": typeof States.node
|
|
97
97
|
}, "application.workflow"> => snapshot
|
|
98
98
|
export const machine = Machine.make({
|
|
99
|
-
branches: {
|
|
100
|
-
transition1: {
|
|
101
|
-
destination: { target: "application.workflow.running", update: "application.workflow" }
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
99
|
id: "inspection-example",
|
|
105
100
|
root: States,
|
|
106
101
|
events: Machine.eventsFromSchemas(Start, Finish, Disconnect, Refresh)
|
|
@@ -138,19 +133,27 @@ export const machine = Machine.make({
|
|
|
138
133
|
idle: {
|
|
139
134
|
on: {
|
|
140
135
|
Start: {
|
|
141
|
-
branches: "
|
|
142
|
-
resolve: ({ select
|
|
143
|
-
target({
|
|
136
|
+
branches: [{ target: "application.workflow.running", update: "application.workflow" }],
|
|
137
|
+
resolve: ({ select }) =>
|
|
138
|
+
select.target("application.workflow.running", {
|
|
144
139
|
data: new Running({}),
|
|
145
140
|
decoded: true,
|
|
146
141
|
states: { editing: { data: new Editing({}), decoded: true } },
|
|
147
|
-
update: {
|
|
142
|
+
update: {
|
|
143
|
+
"application.workflow": {
|
|
144
|
+
decoded: true,
|
|
145
|
+
data: new Workflow({ document: "Machine.ts", unsavedChanges: 3 })
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
148
|
})
|
|
149
149
|
},
|
|
150
150
|
Refresh: {
|
|
151
|
-
update:
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
update: {
|
|
152
|
+
"application.workflow": {
|
|
153
|
+
decoded: true,
|
|
154
|
+
data: () => (new Workflow({ document: "Machine.ts", unsavedChanges: 0 }))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
},
|
|
@@ -158,7 +161,7 @@ export const machine = Machine.make({
|
|
|
158
161
|
initial: {
|
|
159
162
|
target: "application.workflow.running.editing",
|
|
160
163
|
decoded: true,
|
|
161
|
-
data: (
|
|
164
|
+
data: () => new Editing({})
|
|
162
165
|
},
|
|
163
166
|
states: {
|
|
164
167
|
editing: {
|
|
@@ -29,12 +29,6 @@ const ReviewEvents = Machine.eventsFromSchemas(Schema.TaggedUnion({
|
|
|
29
29
|
const saveReview: Effect.Effect<string, string> = Effect.succeed("deterministic-chart")
|
|
30
30
|
const publishReview = Effect.succeed("deterministic-chart")
|
|
31
31
|
export const hierarchyRoutingMachine = Machine.make({
|
|
32
|
-
branches: {
|
|
33
|
-
transition1: {
|
|
34
|
-
save: { target: "Workflow.Saving", title: "Save the review" },
|
|
35
|
-
invalid: { target: "Workflow.Review.Failed", title: "Show validation failure" }
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
32
|
effects: { source1: Effect.suspend(() => saveReview), source2: Effect.suspend(() => publishReview) },
|
|
39
33
|
id: "hierarchy-routing",
|
|
40
34
|
root: ReviewStates,
|
|
@@ -56,11 +50,11 @@ export const hierarchyRoutingMachine = Machine.make({
|
|
|
56
50
|
},
|
|
57
51
|
on: {
|
|
58
52
|
Submit: {
|
|
59
|
-
branches: "
|
|
53
|
+
branches: [{ target: "Workflow.Saving" }, { target: "Workflow.Review.Failed" }],
|
|
60
54
|
resolve: ({ event, select }) =>
|
|
61
55
|
event.route === "save"
|
|
62
|
-
? select.
|
|
63
|
-
: select.
|
|
56
|
+
? select.target("Workflow.Saving", {})
|
|
57
|
+
: select.target("Workflow.Review.Failed", { data: { message: "Add a title before continuing." } })
|
|
64
58
|
}
|
|
65
59
|
},
|
|
66
60
|
states: {
|
|
@@ -74,8 +68,12 @@ export const hierarchyRoutingMachine = Machine.make({
|
|
|
74
68
|
id: "save-review",
|
|
75
69
|
onDone: { target: "Workflow.Publishing" },
|
|
76
70
|
onFailure: {
|
|
77
|
-
target: "Workflow.Review
|
|
78
|
-
|
|
71
|
+
branches: [{ target: "Workflow.Review" }],
|
|
72
|
+
resolve: ({ select }) =>
|
|
73
|
+
select.target("Workflow.Review", {
|
|
74
|
+
data: { title: "A deterministic chart" },
|
|
75
|
+
states: { Failed: { data: { message: "The review could not be saved." } } }
|
|
76
|
+
})
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
},
|
|
@@ -101,7 +101,7 @@ class StreamValue extends Schema.TaggedClass<StreamValue>("InvokeGalleryStreamVa
|
|
|
101
101
|
const GalleryEvents = Machine.eventsFromSchemas(RunEffect, RunStream, RunTimer, RunProcess, RunChild, Reset)
|
|
102
102
|
const GalleryInternalEvents = Machine.internalEventsFromSchemas(StreamValue)
|
|
103
103
|
const processLogic = Machine.logic({
|
|
104
|
-
initial: "starting"
|
|
104
|
+
initial: "starting",
|
|
105
105
|
run: () => Effect.fail("process stopped")
|
|
106
106
|
})
|
|
107
107
|
const GalleryStates = Machine.state({
|
|
@@ -122,12 +122,6 @@ const GalleryStates = Machine.state({
|
|
|
122
122
|
}
|
|
123
123
|
})
|
|
124
124
|
export const invokeOutcomesMachine = Machine.make({
|
|
125
|
-
branches: {
|
|
126
|
-
transition13: {
|
|
127
|
-
ready: { target: "Completed", title: "Worker reports ready" },
|
|
128
|
-
waiting: { none: true, title: "Worker is still starting" }
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
125
|
effects: {
|
|
132
126
|
source1: ({ state }: {
|
|
133
127
|
readonly state: LoadingDocument
|
|
@@ -156,7 +150,7 @@ export const invokeOutcomesMachine = Machine.make({
|
|
|
156
150
|
initial: {
|
|
157
151
|
target: "Gallery.Choose",
|
|
158
152
|
decoded: true,
|
|
159
|
-
data: (
|
|
153
|
+
data: () => new Choose({})
|
|
160
154
|
},
|
|
161
155
|
on: {
|
|
162
156
|
Reset: { target: "Gallery.Choose", decoded: true, data: () => (new Choose({})) }
|
|
@@ -209,8 +203,8 @@ export const invokeOutcomesMachine = Machine.make({
|
|
|
209
203
|
src: "source2",
|
|
210
204
|
id: "document-updates",
|
|
211
205
|
onElement: {
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
stay: true,
|
|
207
|
+
commands: ({ element }, enqueue) => {
|
|
214
208
|
enqueue.raise(GalleryInternalEvents.StreamValue({ value: element }))
|
|
215
209
|
}
|
|
216
210
|
},
|
|
@@ -255,11 +249,14 @@ export const invokeOutcomesMachine = Machine.make({
|
|
|
255
249
|
data: ({ error }) => (new Failed({ source: "process", message: String(error) }))
|
|
256
250
|
},
|
|
257
251
|
onSnapshot: {
|
|
258
|
-
branches: "
|
|
252
|
+
branches: [{ target: "Completed" }, { stay: true }],
|
|
259
253
|
resolve: ({ select, snapshot }) =>
|
|
260
254
|
snapshot.state === "ready"
|
|
261
|
-
? select.
|
|
262
|
-
|
|
255
|
+
? select.target("Completed", {
|
|
256
|
+
data: new Completed({ source: "process", result: "ready" }),
|
|
257
|
+
decoded: true
|
|
258
|
+
})
|
|
259
|
+
: select.stay()
|
|
263
260
|
}
|
|
264
261
|
}
|
|
265
262
|
},
|
|
@@ -48,16 +48,6 @@ const AuthEvents = Machine.eventsFromSchemas(Schema.TaggedUnion({
|
|
|
48
48
|
Submit: { route: Schema.Literals(["verification", "login", "invalid"]) }
|
|
49
49
|
}))
|
|
50
50
|
export const layoutResilienceMachine = Machine.make({
|
|
51
|
-
branches: {
|
|
52
|
-
transition4: {
|
|
53
|
-
requestVerification: {
|
|
54
|
-
target: "Editing.RequestingVerification",
|
|
55
|
-
title: "Request a verification code"
|
|
56
|
-
},
|
|
57
|
-
login: { target: "Editing.SubmittingLogin", title: "Submit password login" },
|
|
58
|
-
invalid: { target: "Editing.Form.Failed", title: "Show validation failure" }
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
51
|
effects: {
|
|
62
52
|
source1: ({ containingState }: {
|
|
63
53
|
readonly containingState: {
|
|
@@ -101,27 +91,34 @@ export const layoutResilienceMachine = Machine.make({
|
|
|
101
91
|
},
|
|
102
92
|
on: {
|
|
103
93
|
EmailChanged: {
|
|
104
|
-
update:
|
|
105
|
-
|
|
94
|
+
update: {
|
|
95
|
+
Editing: ({ ancestors: { "Editing": current }, event }) => ({ ...current, email: event.value })
|
|
96
|
+
}
|
|
106
97
|
},
|
|
107
98
|
LoginMethodChanged: {
|
|
108
|
-
update:
|
|
109
|
-
|
|
99
|
+
update: {
|
|
100
|
+
Editing: ({ ancestors: { "Editing": current }, event }) => ({ ...current, loginMethod: event.value })
|
|
101
|
+
}
|
|
110
102
|
},
|
|
111
103
|
PasswordChanged: {
|
|
112
|
-
update:
|
|
113
|
-
|
|
104
|
+
update: {
|
|
105
|
+
Editing: ({ ancestors: { "Editing": current }, event }) => ({ ...current, password: event.value })
|
|
106
|
+
}
|
|
114
107
|
},
|
|
115
108
|
Submit: {
|
|
116
|
-
branches: "
|
|
109
|
+
branches: [{ target: "Editing.RequestingVerification" }, { target: "Editing.SubmittingLogin" }, {
|
|
110
|
+
target: "Editing.Form.Failed"
|
|
111
|
+
}],
|
|
117
112
|
resolve: ({ event, select }) => {
|
|
118
113
|
if (event.route === "login") {
|
|
119
|
-
return select.
|
|
114
|
+
return select.target("Editing.SubmittingLogin", {})
|
|
120
115
|
}
|
|
121
116
|
if (event.route === "verification") {
|
|
122
|
-
return select.
|
|
117
|
+
return select.target("Editing.RequestingVerification", {})
|
|
123
118
|
}
|
|
124
|
-
return select.
|
|
119
|
+
return select.target("Editing.Form.Failed", {
|
|
120
|
+
data: { message: "Enter valid authentication details." }
|
|
121
|
+
})
|
|
125
122
|
}
|
|
126
123
|
}
|
|
127
124
|
},
|
|
@@ -136,7 +136,7 @@ export const parallelCompletionMachine = Machine.make({
|
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
138
|
Order: {
|
|
139
|
-
initial: { payment: (
|
|
139
|
+
initial: { payment: () => ({ attempts: 0 }), fulfillment: () => ({ warehouse: "north" }) },
|
|
140
140
|
on: {
|
|
141
141
|
CancelOrder: {
|
|
142
142
|
target: "Cancelled",
|
|
@@ -206,8 +206,8 @@ export const parallelCompletionMachine = Machine.make({
|
|
|
206
206
|
src: "source1",
|
|
207
207
|
id: "packing-sla",
|
|
208
208
|
onDone: {
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
stay: true,
|
|
210
|
+
commands: (_, enqueue) => {
|
|
211
211
|
enqueue.raise(ParallelInternalEvents.AutoShip())
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -61,8 +61,8 @@ export const parallelOwnerRoutingChildMachine = Machine.make({
|
|
|
61
61
|
src: "source1",
|
|
62
62
|
id: "signal-parent",
|
|
63
63
|
input: (context) => context,
|
|
64
|
-
onDone: {
|
|
65
|
-
onFailure: {
|
|
64
|
+
onDone: { stay: true },
|
|
65
|
+
onFailure: { stay: true }
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -104,7 +104,7 @@ export const parallelOwnerRoutingMachine = Machine.make({
|
|
|
104
104
|
},
|
|
105
105
|
states: {
|
|
106
106
|
Print: {
|
|
107
|
-
initial: { Options: (
|
|
107
|
+
initial: { Options: () => ({}), Operation: () => ({}) },
|
|
108
108
|
invoke: { src: "source1" },
|
|
109
109
|
on: {
|
|
110
110
|
PrintRequested: {
|
|
@@ -118,7 +118,7 @@ export const parallelOwnerRoutingMachine = Machine.make({
|
|
|
118
118
|
Options: {
|
|
119
119
|
initial: {
|
|
120
120
|
target: "Print.Options.Ready",
|
|
121
|
-
data: (
|
|
121
|
+
data: () => ({})
|
|
122
122
|
},
|
|
123
123
|
states: {
|
|
124
124
|
Ready: {}
|
|
@@ -127,7 +127,7 @@ export const parallelOwnerRoutingMachine = Machine.make({
|
|
|
127
127
|
Operation: {
|
|
128
128
|
initial: {
|
|
129
129
|
target: "Print.Operation.Active",
|
|
130
|
-
data: (
|
|
130
|
+
data: () => ({})
|
|
131
131
|
},
|
|
132
132
|
states: {
|
|
133
133
|
Active: {},
|
|
@@ -110,12 +110,6 @@ const States = Machine.state({
|
|
|
110
110
|
}
|
|
111
111
|
})
|
|
112
112
|
export const plannerMachine = Machine.make({
|
|
113
|
-
branches: {
|
|
114
|
-
transition1: {
|
|
115
|
-
urgent: { target: "Working", title: "Finish immediately" },
|
|
116
|
-
normal: { target: "Working", title: "Wait in working" }
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
113
|
effects: { source1: Effect.suspend(() => Effect.never) },
|
|
120
114
|
id: "planner-example",
|
|
121
115
|
root: States,
|
|
@@ -156,24 +150,25 @@ export const plannerMachine = Machine.make({
|
|
|
156
150
|
initial: {
|
|
157
151
|
target: "Idle",
|
|
158
152
|
decoded: true,
|
|
159
|
-
data: ({ root: { input
|
|
153
|
+
data: ({ root: { input } }) => new Idle({ owner: input.owner })
|
|
160
154
|
},
|
|
161
155
|
root: ({ input }) => ({ input }),
|
|
162
156
|
states: {
|
|
163
157
|
Idle: {
|
|
164
158
|
on: {
|
|
165
159
|
Begin: {
|
|
166
|
-
branches: "
|
|
160
|
+
branches: [{ target: "Working" }, { target: "Finished" }],
|
|
167
161
|
resolve: ({ event, self, select, state }, enqueue) => {
|
|
162
|
+
if (!event.approved) {
|
|
163
|
+
return select.target("Finished", { data: new Finished({ job: event.job }), decoded: true })
|
|
164
|
+
}
|
|
168
165
|
enqueue.emit(new Planned({ job: event.job }))
|
|
169
166
|
enqueue.sendTo(self, Events.Cancel({ reason: "planner command example" }))
|
|
170
167
|
if (event.priority === "urgent") {
|
|
171
168
|
enqueue.raise(InternalEvents.AutoFinish())
|
|
172
169
|
}
|
|
173
170
|
const working = new Working({ owner: state.owner, job: event.job })
|
|
174
|
-
return
|
|
175
|
-
? select.urgent({ data: working, decoded: true })
|
|
176
|
-
: select.normal({ data: working, decoded: true })
|
|
171
|
+
return select.target("Working", { data: working, decoded: true })
|
|
177
172
|
}
|
|
178
173
|
}
|
|
179
174
|
}
|
|
@@ -58,10 +58,6 @@ const ChildStates = Machine.state({
|
|
|
58
58
|
}
|
|
59
59
|
})
|
|
60
60
|
export const requiredParentChildMachine = Machine.make({
|
|
61
|
-
branches: {
|
|
62
|
-
transition1: { destination: { target: "Working" } },
|
|
63
|
-
transition3: { destination: { target: "Working" } }
|
|
64
|
-
},
|
|
65
61
|
effects: {
|
|
66
62
|
source1: ({ parent, state }: {
|
|
67
63
|
readonly parent: Machine.MachineTarget<Machine.Machine.EventInput<ChildProgress | ChildFinished | ChildProblem>>
|
|
@@ -84,11 +80,11 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
84
80
|
Idle: {
|
|
85
81
|
on: {
|
|
86
82
|
BeginChildWork: {
|
|
87
|
-
branches: "
|
|
88
|
-
resolve: ({ event, select
|
|
83
|
+
branches: [{ target: "Working" }],
|
|
84
|
+
resolve: ({ event, select }, enqueue) => {
|
|
89
85
|
enqueue.raise(ChildInternalEvents.Heartbeat({ percent: 25 }))
|
|
90
86
|
enqueue.emit(ChildEmissions.ChildTrace({ message: `started ${event.job}` }))
|
|
91
|
-
return target({ data: new ChildWorking({ job: event.job, progress: 0 }), decoded: true })
|
|
87
|
+
return select.target("Working", { data: new ChildWorking({ job: event.job, progress: 0 }), decoded: true })
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
}
|
|
@@ -98,7 +94,7 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
98
94
|
src: "source1",
|
|
99
95
|
id: "report-progress-to-parent",
|
|
100
96
|
input: (context) => context,
|
|
101
|
-
onDone: {
|
|
97
|
+
onDone: { stay: true },
|
|
102
98
|
onFailure: {
|
|
103
99
|
target: "Cancelled",
|
|
104
100
|
decoded: true,
|
|
@@ -107,10 +103,13 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
107
103
|
},
|
|
108
104
|
on: {
|
|
109
105
|
Heartbeat: {
|
|
110
|
-
branches: "
|
|
111
|
-
resolve: ({ event, state, select
|
|
106
|
+
branches: [{ target: "Working" }],
|
|
107
|
+
resolve: ({ event, state, select }, enqueue) => {
|
|
112
108
|
enqueue.raise(ChildInternalEvents.CommitChildWork())
|
|
113
|
-
return target(
|
|
109
|
+
return select.target("Working", {
|
|
110
|
+
data: new ChildWorking({ job: state.job, progress: event.percent }),
|
|
111
|
+
decoded: true
|
|
112
|
+
})
|
|
114
113
|
}
|
|
115
114
|
},
|
|
116
115
|
CommitChildWork: {
|
|
@@ -161,10 +160,6 @@ const ParentStates = Machine.state({
|
|
|
161
160
|
}
|
|
162
161
|
})
|
|
163
162
|
export const parentProtocolMachine = Machine.make({
|
|
164
|
-
branches: {
|
|
165
|
-
transition1: { destination: { target: "Supervising" } },
|
|
166
|
-
transition3: { destination: { target: "Complete" } }
|
|
167
|
-
},
|
|
168
163
|
children: { source1: ProtocolChild },
|
|
169
164
|
id: "parent-child-protocol",
|
|
170
165
|
root: ParentStates,
|
|
@@ -235,7 +230,6 @@ class PublishOutside extends Schema.TaggedClass<PublishOutside>("OptionalParentP
|
|
|
235
230
|
}
|
|
236
231
|
const OptionalParentStates = Machine.state({ states: { Detached, Published } })
|
|
237
232
|
export const optionalParentMachine = Machine.make({
|
|
238
|
-
branches: { transition1: { destination: { target: "Published" } } },
|
|
239
233
|
id: "optional-parent-protocol",
|
|
240
234
|
root: OptionalParentStates,
|
|
241
235
|
events: Machine.eventsFromSchemas(PublishOutside),
|
|
@@ -250,12 +244,15 @@ export const optionalParentMachine = Machine.make({
|
|
|
250
244
|
Detached: {
|
|
251
245
|
on: {
|
|
252
246
|
PublishOutside: {
|
|
253
|
-
branches: "
|
|
254
|
-
resolve: ({ event, parent, select
|
|
247
|
+
branches: [{ target: "Published" }],
|
|
248
|
+
resolve: ({ event, parent, select }, enqueue) => {
|
|
255
249
|
if (parent !== undefined) {
|
|
256
250
|
enqueue.sendTo(parent, ParentEvents.ChildFinished({ result: event.result }))
|
|
257
251
|
}
|
|
258
|
-
return target(
|
|
252
|
+
return select.target("Published", {
|
|
253
|
+
data: new Published({ deliveredToParent: parent !== undefined }),
|
|
254
|
+
decoded: true
|
|
255
|
+
})
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
258
|
}
|
|
@@ -62,7 +62,7 @@ const branchLabel = (branch: VisualizationBranch): string | undefined => {
|
|
|
62
62
|
if (branch.target === null && branch.updates.length > 0) {
|
|
63
63
|
return branch.type === "direct"
|
|
64
64
|
? `update ${branch.updates.join(", ")}`
|
|
65
|
-
: `[${branch.
|
|
65
|
+
: `[${branch.key}] update ${branch.updates.join(", ")}`
|
|
66
66
|
}
|
|
67
67
|
if (branch.target === null) return undefined
|
|
68
68
|
|
|
@@ -70,7 +70,7 @@ const branchLabel = (branch: VisualizationBranch): string | undefined => {
|
|
|
70
70
|
const updates = branch.updates.length === 0 ? "" : ` / update ${branch.updates.join(", ")}`
|
|
71
71
|
return branch.type === "direct"
|
|
72
72
|
? `→ ${target}${updates}`
|
|
73
|
-
: `[${branch.
|
|
73
|
+
: `[${branch.key}] → ${target}${updates}`
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const activityLabel = (definition: VisualizationActivity): string => {
|