@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.
Files changed (66) hide show
  1. package/README.md +14 -1
  2. package/dist/DevToolsProtocol.d.ts +62 -6
  3. package/dist/DevToolsProtocol.d.ts.map +1 -1
  4. package/dist/DevToolsProtocol.js +21 -0
  5. package/dist/DevToolsProtocol.js.map +1 -1
  6. package/dist/MachineDocument.d.ts +0 -3
  7. package/dist/MachineDocument.d.ts.map +1 -1
  8. package/dist/MachineDocument.js +1 -2
  9. package/dist/MachineDocument.js.map +1 -1
  10. package/dist/MachineRegistry.d.ts +0 -2
  11. package/dist/MachineRegistry.d.ts.map +1 -1
  12. package/dist/MachineWalkthrough.d.ts +1 -1
  13. package/dist/MachineWalkthrough.d.ts.map +1 -1
  14. package/dist/ProjectInspector.d.ts +9 -0
  15. package/dist/ProjectInspector.d.ts.map +1 -1
  16. package/dist/ProjectInspector.js +8 -0
  17. package/dist/ProjectInspector.js.map +1 -1
  18. package/dist/bin.js +13 -1
  19. package/dist/bin.js.map +1 -1
  20. package/dist/client/assets/index-BVMbU47j.js +37 -0
  21. package/dist/client/index.html +1 -1
  22. package/dist/internal/checkCommand.d.ts +6 -0
  23. package/dist/internal/checkCommand.d.ts.map +1 -0
  24. package/dist/internal/checkCommand.js +22 -0
  25. package/dist/internal/checkCommand.js.map +1 -0
  26. package/dist/internal/devServer.js +2 -2
  27. package/dist/internal/devServer.js.map +1 -1
  28. package/dist/internal/evaluationWorker.d.ts.map +1 -1
  29. package/dist/internal/evaluationWorker.js +43 -9
  30. package/dist/internal/evaluationWorker.js.map +1 -1
  31. package/dist/internal/machineDocument.d.ts.map +1 -1
  32. package/dist/internal/machineDocument.js +1 -1
  33. package/dist/internal/machineDocument.js.map +1 -1
  34. package/dist/internal/machineWalkthrough.d.ts.map +1 -1
  35. package/dist/internal/machineWalkthrough.js +0 -1
  36. package/dist/internal/machineWalkthrough.js.map +1 -1
  37. package/dist/internal/projectInspector.d.ts.map +1 -1
  38. package/dist/internal/projectInspector.js +16 -2
  39. package/dist/internal/projectInspector.js.map +1 -1
  40. package/package.json +8 -8
  41. package/src/DevToolsProtocol.ts +35 -0
  42. package/src/MachineDocument.ts +1 -2
  43. package/src/MachineWalkthrough.ts +1 -1
  44. package/src/ProjectInspector.ts +16 -0
  45. package/src/bin.ts +26 -1
  46. package/src/internal/browser/chart-layout.ts +19 -20
  47. package/src/internal/browser/chart-model.ts +2 -2
  48. package/src/internal/browser/example-machine.ts +16 -13
  49. package/src/internal/browser/hierarchy-routing-example.ts +9 -11
  50. package/src/internal/browser/invoke-outcomes-example.ts +10 -13
  51. package/src/internal/browser/layout-resilience-example.ts +17 -20
  52. package/src/internal/browser/parallel-completion-example.ts +3 -3
  53. package/src/internal/browser/parallel-owner-routing-example.ts +5 -5
  54. package/src/internal/browser/planner-example.ts +6 -11
  55. package/src/internal/browser/protocol-events-example.ts +16 -19
  56. package/src/internal/browser/text-tree.ts +2 -2
  57. package/src/internal/browser/transition-semantics-example.ts +37 -32
  58. package/src/internal/browser/visualizer-app.ts +8 -6
  59. package/src/internal/browser/visualizer-model.ts +1 -1
  60. package/src/internal/checkCommand.ts +38 -0
  61. package/src/internal/devServer.ts +2 -2
  62. package/src/internal/evaluationWorker.ts +93 -19
  63. package/src/internal/machineDocument.ts +2 -4
  64. package/src/internal/machineWalkthrough.ts +0 -1
  65. package/src/internal/projectInspector.ts +42 -4
  66. package/dist/client/assets/index-CVtleuI-.js +0 -37
@@ -129,18 +129,6 @@ const defaultWorkspaceSnapshot = () => ({
129
129
  }
130
130
  })
131
131
  export const transitionSemanticsMachine = Machine.make({
132
- branches: {
133
- transition4: {
134
- draft: { target: "Workspace.Draft", title: "Preferred route is draft" },
135
- review: { target: "Workspace.Review", title: "Preferred route is review" }
136
- },
137
- transition7: {
138
- review: { target: "Workspace.Review", title: "Enter the review flow" },
139
- publish: { target: "Workspace.Finished", title: "Publish without review" }
140
- },
141
- transition14: { destination: { history: "Workspace.recent" } },
142
- transition15: { destination: { history: "Workspace.exact" } }
143
- },
144
132
  id: "transition-semantics",
145
133
  root: TransitionStates,
146
134
  events: Machine.eventsFromSchemas(
@@ -183,12 +171,15 @@ export const transitionSemanticsMachine = Machine.make({
183
171
  data: ({ event }) => (new Paused({ reason: event.reason }))
184
172
  },
185
173
  BumpWorkspace: {
186
- update: "Workspace",
187
- decoded: true,
188
- data: ({ state: current }) => (new Workspace({
189
- revision: current.revision + 1,
190
- preferredRoute: current.preferredRoute
191
- }))
174
+ update: {
175
+ Workspace: {
176
+ decoded: true,
177
+ data: ({ state: current }) => (new Workspace({
178
+ revision: current.revision + 1,
179
+ preferredRoute: current.preferredRoute
180
+ }))
181
+ }
182
+ }
192
183
  }
193
184
  },
194
185
  onDone: {
@@ -199,11 +190,14 @@ export const transitionSemanticsMachine = Machine.make({
199
190
  states: {
200
191
  Routing: {
201
192
  choice: {
202
- branches: "transition4",
193
+ branches: [{ target: "Workspace.Draft" }, { target: "Workspace.Review" }],
203
194
  resolve: ({ containingState, select }) =>
204
195
  containingState.preferredRoute === "review"
205
- ? select.review({ data: new Review({ requestedBy: "initial route" }), decoded: true })
206
- : select.draft({ data: new Draft({ text: "", autosaves: 0 }), decoded: true })
196
+ ? select.target("Workspace.Review", {
197
+ data: new Review({ requestedBy: "initial route" }),
198
+ decoded: true
199
+ })
200
+ : select.target("Workspace.Draft", { data: new Draft({ text: "", autosaves: 0 }), decoded: true })
207
201
  }
208
202
  },
209
203
  Draft: {
@@ -215,18 +209,23 @@ export const transitionSemanticsMachine = Machine.make({
215
209
  },
216
210
  Save: { target: "Workspace.AutoSaving", decoded: true, data: () => (new AutoSaving({})) },
217
211
  Submit: {
218
- branches: "transition7",
212
+ branches: [{ target: "Workspace.Review" }, { target: "Workspace.Finished" }],
219
213
  resolve: ({ event, select }) =>
220
214
  event.mode === "publish"
221
- ? select.publish({ data: new WorkspaceFinished({ result: "published directly" }), decoded: true })
222
- : select.review({ data: new Review({ requestedBy: event.requestedBy }), decoded: true })
215
+ ? select.target("Workspace.Finished", {
216
+ data: new WorkspaceFinished({ result: "published directly" }),
217
+ decoded: true
218
+ })
219
+ : select.target("Workspace.Review", {
220
+ data: new Review({ requestedBy: event.requestedBy }),
221
+ decoded: true
222
+ })
223
223
  },
224
- Refresh: { none: true, reenter: true },
225
- Ignore: { none: true },
224
+ Refresh: { reenter: true },
225
+ Ignore: { stay: true },
226
226
  MaybeHandle: {
227
- none: true,
228
- resolve: ({ decline, event }) => event.accept ? undefined : decline(),
229
- declinable: true
227
+ branches: [{ stay: true }, { decline: true }],
228
+ resolve: ({ select, event }) => event.accept ? select.stay() : select.decline()
230
229
  }
231
230
  }
232
231
  },
@@ -241,7 +240,7 @@ export const transitionSemanticsMachine = Machine.make({
241
240
  initial: {
242
241
  target: "Workspace.Review.Checking",
243
242
  decoded: true,
244
- data: ({}) => new Checking({ checks: ["types", "tests"] })
243
+ data: () => new Checking({ checks: ["types", "tests"] })
245
244
  },
246
245
  onDone: {
247
246
  target: "Workspace.Finished",
@@ -285,8 +284,14 @@ export const transitionSemanticsMachine = Machine.make({
285
284
  decoded: true,
286
285
  data: ({ event }) => (new Workspace({ revision: 0, preferredRoute: event.route }))
287
286
  },
288
- ResumeShallow: { branches: "transition14", resolve: ({ select: { destination: target } }) => target() },
289
- ResumeDeep: { branches: "transition15", resolve: ({ select: { destination: target } }) => target() },
287
+ ResumeShallow: {
288
+ branches: [{ history: "Workspace.recent" }],
289
+ resolve: ({ select }) => select.history("Workspace.recent")
290
+ },
291
+ ResumeDeep: {
292
+ branches: [{ history: "Workspace.exact" }],
293
+ resolve: ({ select }) => select.history("Workspace.exact")
294
+ },
290
295
  Restart: {
291
296
  target: "Workspace",
292
297
  decoded: true,
@@ -81,7 +81,7 @@ const renderBranch = (
81
81
  ): HTMLElement => {
82
82
  const row = createElement("div", "branch-row")
83
83
  const main = createElement("div", "branch-main")
84
- if (branch.type === "branch") main.append(badge(branch.title, "condition"))
84
+ if (branch.type === "branch") main.append(badge(branch.key, "condition"))
85
85
  if (branch.target !== null) {
86
86
  main.append(createElement("span", "branch-arrow", "→"), stateLink(branch.target, branch.target, navigate))
87
87
  } else if (branch.selection.kind === "update") {
@@ -158,7 +158,7 @@ const renderIncomingTransition = (
158
158
  if (api === undefined) {
159
159
  details.push(["Selection", incoming.branch.selection.kind], ["Scope", incoming.branch.selection.scope])
160
160
  }
161
- if (incoming.branch.type === "branch") details.unshift(["Title", incoming.branch.title])
161
+ if (incoming.branch.type === "branch") details.unshift(["Branch", incoming.branch.key])
162
162
  card.append(metadata(details))
163
163
  return card
164
164
  }
@@ -715,7 +715,7 @@ export const renderVisualizer = (
715
715
  eyebrow.append(badge("walkthrough", "active"))
716
716
  const title = frame.choice === null
717
717
  ? "Initial configuration"
718
- : frame.choice.title ?? triggerName(frame.choice.trigger)
718
+ : frame.choice.branchKey ?? triggerName(frame.choice.trigger)
719
719
  header.append(eyebrow, createElement("h2", undefined, title))
720
720
  header.append(metadata([
721
721
  ["Step", String(frame.step)],
@@ -760,7 +760,7 @@ export const renderVisualizer = (
760
760
  cardHeader.append(cardTitle, flags)
761
761
  card.append(cardHeader)
762
762
  card.append(metadata([
763
- ["Title", choice.title],
763
+ ["Branch", choice.branchKey],
764
764
  ["Source", stateLink(choice.source, choice.source, navigateToState)],
765
765
  ["Target", choice.target === null ? "No target" : stateLink(choice.target, choice.target, navigateToState)],
766
766
  ["API", api]
@@ -936,7 +936,9 @@ export const renderVisualizer = (
936
936
  button.disabled = choice.unavailableReason !== null
937
937
  const main = createElement("span", "transition-picker-choice-main")
938
938
  main.append(createElement("strong", undefined, triggerName(choice.trigger)))
939
- if (choice.title !== null) main.append(createElement("span", "transition-picker-choice-title", choice.title))
939
+ if (choice.branchKey !== null) {
940
+ main.append(createElement("span", "transition-picker-choice-title", choice.branchKey))
941
+ }
940
942
  button.append(main, createElement("span", "transition-picker-choice-route", choiceRoute(choice)))
941
943
  const contract = contractSummary(choice.input)
942
944
  if (contract !== null) button.append(createElement("span", "transition-picker-choice-contract", contract))
@@ -1028,7 +1030,7 @@ export const renderVisualizer = (
1028
1030
  : "Click a highlighted transition to advance"
1029
1031
  walkthroughTimeline.replaceChildren()
1030
1032
  timeline.forEach((frame) => {
1031
- const label = frame.choice === null ? "Initial" : frame.choice.title ?? triggerName(frame.choice.trigger)
1033
+ const label = frame.choice === null ? "Initial" : frame.choice.branchKey ?? triggerName(frame.choice.trigger)
1032
1034
  const button = createElement(
1033
1035
  "button",
1034
1036
  `walkthrough-step${frame.step === cursor ? " is-current" : ""}`,
@@ -77,7 +77,7 @@ const pathName = (path: string): string => JSON.stringify(path === "" ? "root" :
77
77
  /** Public declaration represented by a retained transition branch. */
78
78
  export const branchTargetApi = (branch: VisualizationBranch): string | undefined => {
79
79
  const { selection } = branch
80
- if (selection.kind === "none") return "{ none: true }"
80
+ if (selection.kind === "none") return "{ stay: true }"
81
81
  const path = selection.path
82
82
  if (path === null) return undefined
83
83
  if (selection.scope === "initial") return "initialConfiguration"
@@ -0,0 +1,38 @@
1
+ import type * as DevToolsProtocol from "../DevToolsProtocol.js"
2
+
3
+ const reportOf = (result: DevToolsProtocol.Checked): {
4
+ readonly ok: boolean
5
+ readonly text: string
6
+ } => result.report as never
7
+
8
+ const failureText = (result: DevToolsProtocol.Failed): string =>
9
+ [
10
+ `FAIL ${result.key}`,
11
+ ...result.diagnostics.map((diagnostic) => ` error ${diagnostic.code}: ${diagnostic.message}`)
12
+ ].join("\n")
13
+
14
+ /** A project with nothing to check fails too, so a wrong path is not reported as a pass. */
15
+ export const isOk = (results: ReadonlyArray<DevToolsProtocol.CheckResult>): boolean =>
16
+ results.length > 0 && results.every((result) => result._tag === "Checked" && reportOf(result).ok)
17
+
18
+ export const renderJson = (results: ReadonlyArray<DevToolsProtocol.CheckResult>): string =>
19
+ JSON.stringify(
20
+ {
21
+ schemaVersion: 1,
22
+ ok: isOk(results),
23
+ machines: results.map((result) => {
24
+ if (result._tag !== "Checked") {
25
+ return { key: result.key, source: result.source, ok: false, diagnostics: result.diagnostics }
26
+ }
27
+ const { text: _text, ...report } = result.report as Record<string, unknown>
28
+ return { key: result.key, source: result.source, ...report }
29
+ })
30
+ },
31
+ null,
32
+ 2
33
+ )
34
+
35
+ export const renderText = (results: ReadonlyArray<DevToolsProtocol.CheckResult>): string =>
36
+ results.length === 0
37
+ ? "No Effect Machine definitions found"
38
+ : results.map((result) => result._tag === "Checked" ? reportOf(result).text : failureText(result)).join("\n")
@@ -153,8 +153,8 @@ export const acquireWatcher = (
153
153
  export const watcherOptions = (options: DevServer.Options): ChokidarOptions =>
154
154
  ({
155
155
  ignoreInitial: true,
156
- interval: 200,
157
- usePolling: options.watchPolling ?? false,
156
+ backend: options.watchPolling === true ? "polling" : "auto",
157
+ pollingInterval: 200,
158
158
  ignored: (file, stats) => isIgnored(file) || stats?.isFile() === true && !sourceExtension.test(file)
159
159
  }) satisfies ChokidarOptions
160
160
 
@@ -1,5 +1,7 @@
1
1
  import * as NodeWorkerRunner from "@effect/platform-node/NodeWorkerRunner"
2
2
  import { Machine } from "@typeonce/effect-machine"
3
+ import { MachineTest } from "@typeonce/effect-machine/testing"
4
+ import * as Cause from "effect/Cause"
3
5
  import * as Effect from "effect/Effect"
4
6
  import * as Schema from "effect/Schema"
5
7
  import * as WorkerRunner from "effect/workers/WorkerRunner"
@@ -22,8 +24,19 @@ interface EvaluationResponse {
22
24
  readonly results: ReadonlyArray<DevToolsProtocol.MachineResult>
23
25
  }
24
26
 
25
- type WorkerRequest = EvaluationRequest
26
- type WorkerResponse = EvaluationResponse
27
+ interface CheckRequest {
28
+ readonly _tag: "CheckMachines"
29
+ readonly root: string
30
+ readonly candidates: ReadonlyArray<ProjectInspector.Candidate>
31
+ }
32
+
33
+ interface CheckResponse {
34
+ readonly _tag: "CheckedMachines"
35
+ readonly results: ReadonlyArray<DevToolsProtocol.CheckResult>
36
+ }
37
+
38
+ type WorkerRequest = EvaluationRequest | CheckRequest
39
+ type WorkerResponse = EvaluationResponse | CheckResponse
27
40
 
28
41
  const isMachine = (value: unknown): value is Machine.Machine.Any =>
29
42
  typeof value === "object" &&
@@ -78,28 +91,37 @@ const failed = (
78
91
  diagnostics: [diagnostic(candidate.file, code, message)]
79
92
  })
80
93
 
81
- const evaluateCandidate = (
94
+ const loadMachines = (
82
95
  server: ViteDevServer,
83
- request: EvaluationRequest,
96
+ root: string,
84
97
  candidate: ProjectInspector.Candidate
85
- ): Effect.Effect<ReadonlyArray<DevToolsProtocol.MachineResult>> =>
98
+ ): Effect.Effect<ReadonlyArray<[string, Machine.Machine.Any]>, unknown> =>
86
99
  Effect.tryPromise({
87
- try: () => server.ssrLoadModule(pathToFileURL(resolve(request.root, candidate.file)).href),
100
+ try: () => server.ssrLoadModule(pathToFileURL(resolve(root, candidate.file)).href),
88
101
  catch: (cause) => cause
89
102
  }).pipe(
90
103
  Effect.flatMap((module) =>
91
104
  Effect.try(() =>
92
105
  Object.entries(module).filter((entry): entry is [string, Machine.Machine.Any] => isMachine(entry[1]))
93
106
  )
94
- ),
107
+ )
108
+ )
109
+
110
+ const machineExportNotFound = (candidate: ProjectInspector.Candidate): DevToolsProtocol.Failed =>
111
+ failed(
112
+ candidate,
113
+ "machine-export-not-found",
114
+ "The module contains a .handle(...) call but does not export the resulting machine"
115
+ )
116
+
117
+ const evaluateCandidate = (
118
+ server: ViteDevServer,
119
+ request: EvaluationRequest,
120
+ candidate: ProjectInspector.Candidate
121
+ ): Effect.Effect<ReadonlyArray<DevToolsProtocol.MachineResult>> =>
122
+ loadMachines(server, request.root, candidate).pipe(
95
123
  Effect.flatMap((machines) => {
96
- if (machines.length === 0) {
97
- return Effect.succeed([failed(
98
- candidate,
99
- "machine-export-not-found",
100
- "The module contains a .handle(...) call but does not export the resulting machine"
101
- )])
102
- }
124
+ if (machines.length === 0) return Effect.succeed([machineExportNotFound(candidate)])
103
125
 
104
126
  const seen = new Set<Machine.Machine.Any>()
105
127
  return Effect.forEach(machines, ([exportName, machine]) => {
@@ -138,13 +160,65 @@ const evaluateCandidate = (
138
160
  Effect.catch((cause) => Effect.succeed([failed(candidate, "module-load-failed", messageOf(cause))]))
139
161
  )
140
162
 
141
- const handle = (server: ViteDevServer, request: EvaluationRequest): Effect.Effect<EvaluationResponse> =>
142
- Effect.forEach(request.candidates, (candidate) => evaluateCandidate(server, request, candidate), {
143
- concurrency: 1
144
- }).pipe(
145
- Effect.map((results) => ({ _tag: "InspectedMachines" as const, results: results.flat() }))
163
+ // Reports cross a worker boundary and reach a JSON consumer, so decoded event
164
+ // values in replays must become plain JSON here.
165
+ const toJson = (value: unknown): Schema.Json =>
166
+ JSON.parse(
167
+ JSON.stringify(value, (_key, item) => {
168
+ if (typeof item === "bigint") return item.toString()
169
+ if (typeof item === "function" || typeof item === "symbol") return String(item)
170
+ return item
171
+ })
172
+ ) as Schema.Json
173
+
174
+ const checkCandidate = (
175
+ server: ViteDevServer,
176
+ request: CheckRequest,
177
+ candidate: ProjectInspector.Candidate
178
+ ): Effect.Effect<ReadonlyArray<DevToolsProtocol.CheckResult>> =>
179
+ loadMachines(server, request.root, candidate).pipe(
180
+ Effect.flatMap((machines) => {
181
+ if (machines.length === 0) return Effect.succeed([machineExportNotFound(candidate)])
182
+
183
+ const seen = new Set<Machine.Machine.Any>()
184
+ return Effect.forEach(machines, ([exportName, machine]) => {
185
+ if (seen.has(machine)) return Effect.succeed<DevToolsProtocol.CheckResult | undefined>(undefined)
186
+ seen.add(machine)
187
+ // The CLI cannot supply services. A machine whose planning requires them
188
+ // reports that as a planning failure.
189
+ return (MachineTest.check as (machine: unknown) => Effect.Effect<MachineTest.CheckReport>)(machine).pipe(
190
+ Effect.map((report): DevToolsProtocol.CheckResult => ({
191
+ _tag: "Checked",
192
+ key: `${candidate.file}#${exportName}`,
193
+ source: sourceOf(candidate.file, exportName),
194
+ report: toJson({ ...report, text: MachineTest.formatCheckReport(report) })
195
+ })),
196
+ Effect.catchCause((cause) =>
197
+ Effect.succeed(failed(candidate, "machine-check-failed", Cause.pretty(cause), exportName))
198
+ )
199
+ )
200
+ }).pipe(
201
+ Effect.map((results) =>
202
+ results.filter((result): result is DevToolsProtocol.CheckResult => result !== undefined)
203
+ )
204
+ )
205
+ }),
206
+ Effect.catch((cause) => Effect.succeed([failed(candidate, "module-load-failed", messageOf(cause))]))
146
207
  )
147
208
 
209
+ const handle = (server: ViteDevServer, request: WorkerRequest): Effect.Effect<WorkerResponse> =>
210
+ request._tag === "CheckMachines"
211
+ ? Effect.forEach(request.candidates, (candidate) => checkCandidate(server, request, candidate), {
212
+ concurrency: 1
213
+ }).pipe(
214
+ Effect.map((results) => ({ _tag: "CheckedMachines" as const, results: results.flat() }))
215
+ )
216
+ : Effect.forEach(request.candidates, (candidate) => evaluateCandidate(server, request, candidate), {
217
+ concurrency: 1
218
+ }).pipe(
219
+ Effect.map((results) => ({ _tag: "InspectedMachines" as const, results: results.flat() }))
220
+ )
221
+
148
222
  export const run = (server: ViteDevServer): Promise<void> =>
149
223
  Effect.gen(function*() {
150
224
  const platform = yield* WorkerRunner.WorkerRunnerPlatform
@@ -7,9 +7,7 @@ const enabled = Machine.enabled as (
7
7
  snapshot: unknown
8
8
  ) => ReadonlyArray<PropertyKey>
9
9
 
10
- const inputEventSchemas = Machine.inputEventSchemas as (
11
- machine: Machine.Machine.Any
12
- ) => ReadonlyArray<Machine.Machine.TaggedSchema>
10
+ const inputEventSchemas = Machine.inputEventSchemas
13
11
 
14
12
  const isRecord = (value: unknown): value is Record<string, unknown> =>
15
13
  typeof value === "object" && value !== null && !Array.isArray(value)
@@ -154,7 +152,7 @@ export const make = <M extends Machine.Machine.Any>(
154
152
  }
155
153
  return branch.type === "direct"
156
154
  ? { ...common, type: "direct" }
157
- : { ...common, type: "branch", key: branch.key, title: branch.title }
155
+ : { ...common, type: "branch", key: branch.key }
158
156
  })
159
157
  }
160
158
  })
@@ -226,7 +226,6 @@ export const choices = (self: MachineWalkthrough.Session): ReadonlyArray<Machine
226
226
  branchId: branch.id,
227
227
  branchIndex,
228
228
  branchKey: branch.type === "branch" ? branch.key : null,
229
- title: branch.type === "branch" ? branch.title : null,
230
229
  source: transition.source,
231
230
  trigger: transition.trigger,
232
231
  target: branch.target,
@@ -39,8 +39,19 @@ interface EvaluationResponse {
39
39
  readonly results: ReadonlyArray<unknown>
40
40
  }
41
41
 
42
- type WorkerRequest = EvaluationRequest
43
- type WorkerResponse = EvaluationResponse
42
+ interface CheckRequest {
43
+ readonly _tag: "CheckMachines"
44
+ readonly root: string
45
+ readonly candidates: ReadonlyArray<ProjectInspector.Candidate>
46
+ }
47
+
48
+ interface CheckResponse {
49
+ readonly _tag: "CheckedMachines"
50
+ readonly results: ReadonlyArray<unknown>
51
+ }
52
+
53
+ type WorkerRequest = EvaluationRequest | CheckRequest
54
+ type WorkerResponse = EvaluationResponse | CheckResponse
44
55
 
45
56
  const scriptKind = (file: string): ts.ScriptKind => {
46
57
  if (file.endsWith(".tsx")) return ts.ScriptKind.TSX
@@ -207,7 +218,7 @@ const evaluate = (
207
218
  return runWorker(request).pipe(
208
219
  Effect.flatMap((message) => {
209
220
  if (message._tag !== "InspectedMachines") {
210
- return Effect.fail(new Error(`Unexpected worker response: ${message._tag}`))
221
+ return Effect.fail(new Error(`Unexpected worker response: ${String(message._tag)}`))
211
222
  }
212
223
  return Effect.forEach(
213
224
  message.results,
@@ -223,6 +234,32 @@ const evaluate = (
223
234
  )
224
235
  }
225
236
 
237
+ const check = (
238
+ api: PublicApi,
239
+ candidates: ReadonlyArray<ProjectInspector.Candidate>,
240
+ options: ProjectInspector.InspectOptions
241
+ ): Effect.Effect<ReadonlyArray<DevToolsProtocol.CheckResult>, ProjectInspector.EvaluationError> => {
242
+ if (candidates.length === 0) return Effect.succeed([])
243
+
244
+ return runWorker({ _tag: "CheckMachines", root: options.root, candidates }).pipe(
245
+ Effect.flatMap((message) => {
246
+ if (message._tag !== "CheckedMachines") {
247
+ return Effect.fail(new Error(`Unexpected worker response: ${String(message._tag)}`))
248
+ }
249
+ return Effect.forEach(
250
+ message.results,
251
+ (result) => Schema.decodeUnknownEffect(DevToolsProtocol.CheckResult)(result)
252
+ )
253
+ }),
254
+ Effect.mapError((cause) =>
255
+ new api.EvaluationError({
256
+ message: "The isolated machine evaluator failed",
257
+ cause
258
+ })
259
+ )
260
+ )
261
+ }
262
+
226
263
  const make = (api: PublicApi) =>
227
264
  Effect.gen(function*() {
228
265
  const discover = yield* makeDiscovery(api)
@@ -231,7 +268,8 @@ const make = (api: PublicApi) =>
231
268
  return api.ProjectInspector.of({
232
269
  discover,
233
270
  evaluate: (candidates, options) => evaluate(api, candidates, options),
234
- inspect
271
+ inspect,
272
+ check: (options) => Effect.flatMap(discover(options), (candidates) => check(api, candidates, options))
235
273
  })
236
274
  })
237
275