@typeonce/effect-machine-devtools 0.23.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/LICENSE +21 -0
- package/NOTICE +3 -0
- package/README.md +81 -0
- package/dist/DevServer.d.ts +42 -0
- package/dist/DevServer.d.ts.map +1 -0
- package/dist/DevServer.js +28 -0
- package/dist/DevServer.js.map +1 -0
- package/dist/DevToolsProtocol.d.ts +954 -0
- package/dist/DevToolsProtocol.d.ts.map +1 -0
- package/dist/DevToolsProtocol.js +96 -0
- package/dist/DevToolsProtocol.js.map +1 -0
- package/dist/MachineDocument.d.ts +396 -0
- package/dist/MachineDocument.d.ts.map +1 -0
- package/dist/MachineDocument.js +172 -0
- package/dist/MachineDocument.js.map +1 -0
- package/dist/MachineRegistry.d.ts +349 -0
- package/dist/MachineRegistry.d.ts.map +1 -0
- package/dist/MachineRegistry.js +46 -0
- package/dist/MachineRegistry.js.map +1 -0
- package/dist/MachineSimulator.d.ts +169 -0
- package/dist/MachineSimulator.d.ts.map +1 -0
- package/dist/MachineSimulator.js +98 -0
- package/dist/MachineSimulator.js.map +1 -0
- package/dist/ProjectInspector.d.ts +116 -0
- package/dist/ProjectInspector.d.ts.map +1 -0
- package/dist/ProjectInspector.js +82 -0
- package/dist/ProjectInspector.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +23 -0
- package/dist/bin.js.map +1 -0
- package/dist/client/assets/index-BGOhE3Ng.css +1 -0
- package/dist/client/assets/index-DiqGhsGR.js +14 -0
- package/dist/client/index.html +14 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/devServer.d.ts +9 -0
- package/dist/internal/devServer.d.ts.map +1 -0
- package/dist/internal/devServer.js +119 -0
- package/dist/internal/devServer.js.map +1 -0
- package/dist/internal/evaluationWorker.d.ts +3 -0
- package/dist/internal/evaluationWorker.d.ts.map +1 -0
- package/dist/internal/evaluationWorker.js +69 -0
- package/dist/internal/evaluationWorker.js.map +1 -0
- package/dist/internal/evaluationWorkerBootstrap.d.ts +2 -0
- package/dist/internal/evaluationWorkerBootstrap.d.ts.map +1 -0
- package/dist/internal/evaluationWorkerBootstrap.js +21 -0
- package/dist/internal/evaluationWorkerBootstrap.js.map +1 -0
- package/dist/internal/machineDocument.d.ts +4 -0
- package/dist/internal/machineDocument.d.ts.map +1 -0
- package/dist/internal/machineDocument.js +122 -0
- package/dist/internal/machineDocument.js.map +1 -0
- package/dist/internal/machineRegistry.d.ts +12 -0
- package/dist/internal/machineRegistry.d.ts.map +1 -0
- package/dist/internal/machineRegistry.js +97 -0
- package/dist/internal/machineRegistry.js.map +1 -0
- package/dist/internal/machineSimulator.d.ts +5 -0
- package/dist/internal/machineSimulator.d.ts.map +1 -0
- package/dist/internal/machineSimulator.js +156 -0
- package/dist/internal/machineSimulator.js.map +1 -0
- package/dist/internal/projectInspector.d.ts +11 -0
- package/dist/internal/projectInspector.d.ts.map +1 -0
- package/dist/internal/projectInspector.js +150 -0
- package/dist/internal/projectInspector.js.map +1 -0
- package/index.html +13 -0
- package/package.json +69 -0
- package/src/DevServer.ts +45 -0
- package/src/DevToolsProtocol.ts +146 -0
- package/src/MachineDocument.ts +264 -0
- package/src/MachineRegistry.ts +69 -0
- package/src/MachineSimulator.ts +154 -0
- package/src/ProjectInspector.ts +140 -0
- package/src/bin.ts +56 -0
- package/src/index.ts +20 -0
- package/src/internal/browser/example-machine.ts +134 -0
- package/src/internal/browser/machine-index.ts +81 -0
- package/src/internal/browser/main.ts +42 -0
- package/src/internal/browser/styles.css +817 -0
- package/src/internal/browser/text-tree.ts +214 -0
- package/src/internal/browser/visualizer-app.ts +659 -0
- package/src/internal/browser/visualizer-model.ts +173 -0
- package/src/internal/browser/visualizer.ts +31 -0
- package/src/internal/devServer.ts +171 -0
- package/src/internal/evaluationWorker.ts +138 -0
- package/src/internal/evaluationWorkerBootstrap.js +21 -0
- package/src/internal/machineDocument.ts +138 -0
- package/src/internal/machineRegistry.ts +128 -0
- package/src/internal/machineSimulator.ts +199 -0
- package/src/internal/projectInspector.ts +226 -0
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typeonce/effect-machine-devtools",
|
|
3
|
+
"version": "0.23.0",
|
|
4
|
+
"description": "Local development tools for Effect Machine",
|
|
5
|
+
"author": "Sandro Maglione",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/typeonce-dev/effect-machine.git",
|
|
9
|
+
"directory": "packages/devtools"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/typeonce-dev/effect-machine/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/typeonce-dev/effect-machine/tree/main/packages/devtools#readme",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"bin": {
|
|
19
|
+
"effect-machine": "./dist/bin.js"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": "./dist/index.js",
|
|
24
|
+
"./DevToolsProtocol": "./dist/DevToolsProtocol.js",
|
|
25
|
+
"./MachineDocument": "./dist/MachineDocument.js",
|
|
26
|
+
"./MachineSimulator": "./dist/MachineSimulator.js",
|
|
27
|
+
"./internal/*": null
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@effect/platform-browser": "4.0.0-rc.111",
|
|
31
|
+
"@effect/platform-node": "4.0.0-rc.111",
|
|
32
|
+
"chokidar": "4.0.3",
|
|
33
|
+
"typescript": "6.0.3",
|
|
34
|
+
"vite": "8.1.5",
|
|
35
|
+
"@typeonce/effect-machine": "^0.23.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"effect": "4.0.0-rc.111"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "25.7.0",
|
|
42
|
+
"effect": "4.0.0-rc.111",
|
|
43
|
+
"tsx": "4.21.0"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"src/**/*",
|
|
47
|
+
"dist/**/*.js",
|
|
48
|
+
"dist/**/*.js.map",
|
|
49
|
+
"dist/**/*.d.ts",
|
|
50
|
+
"dist/**/*.d.ts.map",
|
|
51
|
+
"dist/client/**/*",
|
|
52
|
+
"index.html",
|
|
53
|
+
"README.md",
|
|
54
|
+
"LICENSE",
|
|
55
|
+
"NOTICE"
|
|
56
|
+
],
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"provenance": true
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=22.19.0"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "node scripts/clean.mjs && vite build --config vite.config.ts && tsc -p tsconfig.build.json",
|
|
66
|
+
"check": "tsc -p tsconfig.json",
|
|
67
|
+
"dev": "tsx src/bin.ts"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/DevServer.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local HTTP server for the Effect Machine visualizer.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.23.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Schema from "effect/Schema"
|
|
8
|
+
import * as internal from "./internal/devServer.js"
|
|
9
|
+
import type * as MachineRegistry from "./MachineRegistry.js"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @category models
|
|
13
|
+
* @since 0.23.0
|
|
14
|
+
*/
|
|
15
|
+
export interface Options {
|
|
16
|
+
readonly root: string
|
|
17
|
+
readonly host: string
|
|
18
|
+
readonly port: number
|
|
19
|
+
readonly open?: boolean | undefined
|
|
20
|
+
readonly debounce?: number | undefined
|
|
21
|
+
readonly watchPolling?: boolean | undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Failure while starting or serving the local visualizer.
|
|
26
|
+
*
|
|
27
|
+
* @category errors
|
|
28
|
+
* @since 0.23.0
|
|
29
|
+
*/
|
|
30
|
+
export class DevServerError extends Schema.Error<DevServerError>(
|
|
31
|
+
"@typeonce/effect-machine-devtools/DevServer/DevServerError"
|
|
32
|
+
)({
|
|
33
|
+
_tag: Schema.tag("DevServerError"),
|
|
34
|
+
message: Schema.String,
|
|
35
|
+
cause: Schema.optional(Schema.Defect())
|
|
36
|
+
}) {}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Starts the local visualizer and runs until interrupted.
|
|
40
|
+
*
|
|
41
|
+
* @category constructors
|
|
42
|
+
* @since 0.23.0
|
|
43
|
+
*/
|
|
44
|
+
export const run = (options: Options): Effect.Effect<never, DevServerError, MachineRegistry.MachineRegistry> =>
|
|
45
|
+
internal.run(DevServerError, options)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned messages exchanged by Effect Machine devtools processes.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.23.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema"
|
|
7
|
+
import * as MachineDocument from "./MachineDocument.js"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Current devtools protocol version.
|
|
11
|
+
*
|
|
12
|
+
* @category models
|
|
13
|
+
* @since 0.23.0
|
|
14
|
+
*/
|
|
15
|
+
export const protocolVersion = 1 as const
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @category schemas
|
|
19
|
+
* @since 0.23.0
|
|
20
|
+
*/
|
|
21
|
+
export const Location = Schema.Struct({
|
|
22
|
+
file: Schema.String,
|
|
23
|
+
line: Schema.NullOr(Schema.Natural),
|
|
24
|
+
column: Schema.NullOr(Schema.Natural)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @category models
|
|
29
|
+
* @since 0.23.0
|
|
30
|
+
*/
|
|
31
|
+
export type Location = Schema.Schema.Type<typeof Location>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A recoverable or terminal problem associated with one machine candidate.
|
|
35
|
+
*
|
|
36
|
+
* @category schemas
|
|
37
|
+
* @since 0.23.0
|
|
38
|
+
*/
|
|
39
|
+
export const Diagnostic = Schema.Struct({
|
|
40
|
+
severity: Schema.Literals(["warning", "error"]),
|
|
41
|
+
code: Schema.String,
|
|
42
|
+
message: Schema.String,
|
|
43
|
+
location: Schema.NullOr(Location),
|
|
44
|
+
statePath: Schema.NullOr(Schema.String)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @category models
|
|
49
|
+
* @since 0.23.0
|
|
50
|
+
*/
|
|
51
|
+
export type Diagnostic = Schema.Schema.Type<typeof Diagnostic>
|
|
52
|
+
|
|
53
|
+
const ResultFields = {
|
|
54
|
+
protocolVersion: Schema.Literal(protocolVersion),
|
|
55
|
+
key: Schema.String
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A complete machine inspection result.
|
|
60
|
+
*
|
|
61
|
+
* @category schemas
|
|
62
|
+
* @since 0.23.0
|
|
63
|
+
*/
|
|
64
|
+
export const Ready = Schema.Struct({
|
|
65
|
+
...ResultFields,
|
|
66
|
+
_tag: Schema.tag("Ready"),
|
|
67
|
+
document: MachineDocument.MachineDocument,
|
|
68
|
+
diagnostics: Schema.Array(Diagnostic)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @category models
|
|
73
|
+
* @since 0.23.0
|
|
74
|
+
*/
|
|
75
|
+
export type Ready = Schema.Schema.Type<typeof Ready>
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A usable document accompanied by diagnostics from an incomplete reload.
|
|
79
|
+
*
|
|
80
|
+
* @category schemas
|
|
81
|
+
* @since 0.23.0
|
|
82
|
+
*/
|
|
83
|
+
export const Partial = Schema.Struct({
|
|
84
|
+
...ResultFields,
|
|
85
|
+
_tag: Schema.tag("Partial"),
|
|
86
|
+
document: MachineDocument.MachineDocument,
|
|
87
|
+
diagnostics: Schema.Array(Diagnostic)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @category models
|
|
92
|
+
* @since 0.23.0
|
|
93
|
+
*/
|
|
94
|
+
export type Partial = Schema.Schema.Type<typeof Partial>
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A machine candidate that could not produce a document.
|
|
98
|
+
*
|
|
99
|
+
* @category schemas
|
|
100
|
+
* @since 0.23.0
|
|
101
|
+
*/
|
|
102
|
+
export const Failed = Schema.Struct({
|
|
103
|
+
...ResultFields,
|
|
104
|
+
_tag: Schema.tag("Failed"),
|
|
105
|
+
source: MachineDocument.Source,
|
|
106
|
+
machineId: Schema.NullOr(Schema.String),
|
|
107
|
+
diagnostics: Schema.Array(Diagnostic)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @category models
|
|
112
|
+
* @since 0.23.0
|
|
113
|
+
*/
|
|
114
|
+
export type Failed = Schema.Schema.Type<typeof Failed>
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Schema for every result returned by discovery and evaluation.
|
|
118
|
+
*
|
|
119
|
+
* @category schemas
|
|
120
|
+
* @since 0.23.0
|
|
121
|
+
*/
|
|
122
|
+
export const MachineResult = Schema.Union([Ready, Partial, Failed])
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @category models
|
|
126
|
+
* @since 0.23.0
|
|
127
|
+
*/
|
|
128
|
+
export type MachineResult = Schema.Schema.Type<typeof MachineResult>
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A complete live-registry update sent to browser clients.
|
|
132
|
+
*
|
|
133
|
+
* @category schemas
|
|
134
|
+
* @since 0.23.0
|
|
135
|
+
*/
|
|
136
|
+
export const RegistrySnapshot = Schema.Struct({
|
|
137
|
+
protocolVersion: Schema.Literal(protocolVersion),
|
|
138
|
+
revision: Schema.Natural,
|
|
139
|
+
results: Schema.Array(MachineResult)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @category models
|
|
144
|
+
* @since 0.23.0
|
|
145
|
+
*/
|
|
146
|
+
export type RegistrySnapshot = Schema.Schema.Type<typeof RegistrySnapshot>
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializable inspection documents for Effect Machine devtools.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.23.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Machine } from "@typeonce/effect-machine"
|
|
7
|
+
import * as Schema from "effect/Schema"
|
|
8
|
+
import * as internal from "./internal/machineDocument.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Current machine document schema version.
|
|
12
|
+
*
|
|
13
|
+
* @category models
|
|
14
|
+
* @since 0.23.0
|
|
15
|
+
*/
|
|
16
|
+
export const schemaVersion = 1 as const
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Source module and export that produced a machine.
|
|
20
|
+
*
|
|
21
|
+
* @category schemas
|
|
22
|
+
* @since 0.23.0
|
|
23
|
+
*/
|
|
24
|
+
export const Source = Schema.Struct({
|
|
25
|
+
file: Schema.String,
|
|
26
|
+
exportName: Schema.NullOr(Schema.String)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @category models
|
|
31
|
+
* @since 0.23.0
|
|
32
|
+
*/
|
|
33
|
+
export type Source = Schema.Schema.Type<typeof Source>
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Static target selection retained from a transition definition.
|
|
37
|
+
*
|
|
38
|
+
* @category schemas
|
|
39
|
+
* @since 0.23.0
|
|
40
|
+
*/
|
|
41
|
+
export const Selection = Schema.Struct({
|
|
42
|
+
path: Schema.NullOr(Schema.String),
|
|
43
|
+
kind: Schema.Literals(["state", "initial", "history", "choice", "update", "none"]),
|
|
44
|
+
scope: Schema.NullOr(Schema.Literals(["local", "branch", "full", "initial"]))
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @category models
|
|
49
|
+
* @since 0.23.0
|
|
50
|
+
*/
|
|
51
|
+
export type Selection = Schema.Schema.Type<typeof Selection>
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @category schemas
|
|
55
|
+
* @since 0.23.0
|
|
56
|
+
*/
|
|
57
|
+
export const Initial = Schema.Struct({
|
|
58
|
+
target: Schema.String,
|
|
59
|
+
selection: Selection
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @category models
|
|
64
|
+
* @since 0.23.0
|
|
65
|
+
*/
|
|
66
|
+
export type Initial = Schema.Schema.Type<typeof Initial>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @category schemas
|
|
70
|
+
* @since 0.23.0
|
|
71
|
+
*/
|
|
72
|
+
export const State = Schema.Struct({
|
|
73
|
+
path: Schema.String,
|
|
74
|
+
key: Schema.String,
|
|
75
|
+
order: Schema.Natural,
|
|
76
|
+
title: Schema.NullOr(Schema.String),
|
|
77
|
+
description: Schema.NullOr(Schema.String),
|
|
78
|
+
documentation: Schema.NullOr(Schema.String),
|
|
79
|
+
type: Schema.Literals(["atomic", "compound", "parallel", "final", "history", "choice"]),
|
|
80
|
+
history: Schema.NullOr(Schema.Literals(["shallow", "deep"])),
|
|
81
|
+
parent: Schema.NullOr(Schema.String),
|
|
82
|
+
children: Schema.Array(Schema.String),
|
|
83
|
+
initial: Schema.NullOr(Schema.String),
|
|
84
|
+
transitionIds: Schema.Array(Schema.String),
|
|
85
|
+
activityIds: Schema.Array(Schema.String)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @category models
|
|
90
|
+
* @since 0.23.0
|
|
91
|
+
*/
|
|
92
|
+
export type State = Schema.Schema.Type<typeof State>
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @category schemas
|
|
96
|
+
* @since 0.23.0
|
|
97
|
+
*/
|
|
98
|
+
export const Trigger = Schema.Union([
|
|
99
|
+
Schema.Struct({ type: Schema.tag("event"), event: Schema.String }),
|
|
100
|
+
Schema.Struct({ type: Schema.tag("always") }),
|
|
101
|
+
Schema.Struct({ type: Schema.tag("done") }),
|
|
102
|
+
Schema.Struct({ type: Schema.tag("choice") }),
|
|
103
|
+
Schema.Struct({
|
|
104
|
+
type: Schema.tag("invoke"),
|
|
105
|
+
id: Schema.String,
|
|
106
|
+
outcome: Schema.Literals(["element", "done", "failure", "snapshot"])
|
|
107
|
+
})
|
|
108
|
+
])
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @category models
|
|
112
|
+
* @since 0.23.0
|
|
113
|
+
*/
|
|
114
|
+
export type Trigger = Schema.Schema.Type<typeof Trigger>
|
|
115
|
+
|
|
116
|
+
const BranchFields = {
|
|
117
|
+
id: Schema.String,
|
|
118
|
+
target: Schema.NullOr(Schema.String),
|
|
119
|
+
selection: Selection,
|
|
120
|
+
updates: Schema.Array(Schema.String)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @category schemas
|
|
125
|
+
* @since 0.23.0
|
|
126
|
+
*/
|
|
127
|
+
export const Branch = Schema.Union([
|
|
128
|
+
Schema.Struct({ ...BranchFields, type: Schema.tag("direct") }),
|
|
129
|
+
Schema.Struct({
|
|
130
|
+
...BranchFields,
|
|
131
|
+
type: Schema.tag("branch"),
|
|
132
|
+
key: Schema.String,
|
|
133
|
+
title: Schema.String
|
|
134
|
+
})
|
|
135
|
+
])
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @category models
|
|
139
|
+
* @since 0.23.0
|
|
140
|
+
*/
|
|
141
|
+
export type Branch = Schema.Schema.Type<typeof Branch>
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @category schemas
|
|
145
|
+
* @since 0.23.0
|
|
146
|
+
*/
|
|
147
|
+
export const Transition = Schema.Struct({
|
|
148
|
+
id: Schema.String,
|
|
149
|
+
source: Schema.String,
|
|
150
|
+
trigger: Trigger,
|
|
151
|
+
reenter: Schema.Boolean,
|
|
152
|
+
acceptance: Schema.Literals(["required", "declinable"]),
|
|
153
|
+
branches: Schema.Array(Branch)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @category models
|
|
158
|
+
* @since 0.23.0
|
|
159
|
+
*/
|
|
160
|
+
export type Transition = Schema.Schema.Type<typeof Transition>
|
|
161
|
+
|
|
162
|
+
const ActivityFields = {
|
|
163
|
+
id: Schema.String,
|
|
164
|
+
source: Schema.String,
|
|
165
|
+
lifecycleId: Schema.String
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @category schemas
|
|
170
|
+
* @since 0.23.0
|
|
171
|
+
*/
|
|
172
|
+
export const Activity = Schema.Union([
|
|
173
|
+
Schema.Struct({ ...ActivityFields, type: Schema.tag("process") }),
|
|
174
|
+
Schema.Struct({
|
|
175
|
+
...ActivityFields,
|
|
176
|
+
type: Schema.tag("effect"),
|
|
177
|
+
outcomes: Schema.Struct({
|
|
178
|
+
success: Schema.Literal("dynamic"),
|
|
179
|
+
failure: Schema.Literals(["dynamic", "none"])
|
|
180
|
+
})
|
|
181
|
+
}),
|
|
182
|
+
Schema.Struct({
|
|
183
|
+
...ActivityFields,
|
|
184
|
+
type: Schema.tag("timer"),
|
|
185
|
+
duration: Schema.String
|
|
186
|
+
}),
|
|
187
|
+
Schema.Struct({ ...ActivityFields, type: Schema.tag("stream") }),
|
|
188
|
+
Schema.Struct({
|
|
189
|
+
...ActivityFields,
|
|
190
|
+
type: Schema.tag("machine"),
|
|
191
|
+
child: Schema.Struct({
|
|
192
|
+
id: Schema.String,
|
|
193
|
+
machineId: Schema.NullOr(Schema.String)
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
])
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @category models
|
|
200
|
+
* @since 0.23.0
|
|
201
|
+
*/
|
|
202
|
+
export type Activity = Schema.Schema.Type<typeof Activity>
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @category schemas
|
|
206
|
+
* @since 0.23.0
|
|
207
|
+
*/
|
|
208
|
+
export const Snapshot = Schema.Struct({
|
|
209
|
+
activePaths: Schema.Array(Schema.String),
|
|
210
|
+
candidateEvents: Schema.Array(Schema.String)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @category models
|
|
215
|
+
* @since 0.23.0
|
|
216
|
+
*/
|
|
217
|
+
export type Snapshot = Schema.Schema.Type<typeof Snapshot>
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Complete, versioned, JSON-safe machine inspection document.
|
|
221
|
+
*
|
|
222
|
+
* @category schemas
|
|
223
|
+
* @since 0.23.0
|
|
224
|
+
*/
|
|
225
|
+
export const MachineDocument = Schema.Struct({
|
|
226
|
+
schemaVersion: Schema.Literal(schemaVersion),
|
|
227
|
+
revision: Schema.Natural,
|
|
228
|
+
source: Schema.NullOr(Source),
|
|
229
|
+
machineId: Schema.String,
|
|
230
|
+
initial: Initial,
|
|
231
|
+
roots: Schema.Array(Schema.String),
|
|
232
|
+
states: Schema.Array(State),
|
|
233
|
+
transitions: Schema.Array(Transition),
|
|
234
|
+
activities: Schema.Array(Activity),
|
|
235
|
+
snapshot: Schema.NullOr(Snapshot)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @category models
|
|
240
|
+
* @since 0.23.0
|
|
241
|
+
*/
|
|
242
|
+
export type MachineDocument = Schema.Schema.Type<typeof MachineDocument>
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Options for capturing a machine document.
|
|
246
|
+
*
|
|
247
|
+
* @category models
|
|
248
|
+
* @since 0.23.0
|
|
249
|
+
*/
|
|
250
|
+
export interface MakeOptions<M extends Machine.Machine.Any> {
|
|
251
|
+
readonly revision?: number | undefined
|
|
252
|
+
readonly source?: Source | undefined
|
|
253
|
+
readonly snapshot?: Machine.Machine.Snapshot<Machine.Machine.States<M>> | undefined
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Captures every serializable definition exposed by Effect Machine inspection.
|
|
258
|
+
* It never evaluates transition resolvers or activity sources.
|
|
259
|
+
*
|
|
260
|
+
* @category constructors
|
|
261
|
+
* @since 0.23.0
|
|
262
|
+
*/
|
|
263
|
+
export const make: <M extends Machine.Machine.Any>(machine: M, options?: MakeOptions<M>) => MachineDocument =
|
|
264
|
+
internal.make
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live registry of machine inspection results for one project.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.23.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "effect/Context"
|
|
7
|
+
import type * as Effect from "effect/Effect"
|
|
8
|
+
import * as Schema from "effect/Schema"
|
|
9
|
+
import type * as Stream from "effect/Stream"
|
|
10
|
+
import * as DevToolsProtocol from "./DevToolsProtocol.js"
|
|
11
|
+
import * as internal from "./internal/machineRegistry.js"
|
|
12
|
+
import type * as ProjectInspector from "./ProjectInspector.js"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Current registry state sent to browser clients.
|
|
16
|
+
*
|
|
17
|
+
* @category schemas
|
|
18
|
+
* @since 0.23.0
|
|
19
|
+
*/
|
|
20
|
+
export const Snapshot = DevToolsProtocol.RegistrySnapshot
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @category models
|
|
24
|
+
* @since 0.23.0
|
|
25
|
+
*/
|
|
26
|
+
export type Snapshot = Schema.Schema.Type<typeof Snapshot>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @category models
|
|
30
|
+
* @since 0.23.0
|
|
31
|
+
*/
|
|
32
|
+
export interface Options extends ProjectInspector.InspectOptions {
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Failure while starting the initial project inspection.
|
|
37
|
+
*
|
|
38
|
+
* @category errors
|
|
39
|
+
* @since 0.23.0
|
|
40
|
+
*/
|
|
41
|
+
export class RegistryError extends Schema.Error<RegistryError>(
|
|
42
|
+
"@typeonce/effect-machine-devtools/MachineRegistry/RegistryError"
|
|
43
|
+
)({
|
|
44
|
+
_tag: Schema.tag("RegistryError"),
|
|
45
|
+
message: Schema.String,
|
|
46
|
+
cause: Schema.optional(Schema.Defect())
|
|
47
|
+
}) {}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A last-known-good machine registry. Reload failures preserve the previous
|
|
51
|
+
* document as a partial result while exposing the new diagnostics.
|
|
52
|
+
*
|
|
53
|
+
* @category services
|
|
54
|
+
* @since 0.23.0
|
|
55
|
+
*/
|
|
56
|
+
export class MachineRegistry extends Context.Service<MachineRegistry, {
|
|
57
|
+
readonly get: Effect.Effect<Snapshot>
|
|
58
|
+
readonly changes: Stream.Stream<Snapshot>
|
|
59
|
+
readonly refresh: Effect.Effect<Snapshot, RegistryError>
|
|
60
|
+
}>()("@typeonce/effect-machine-devtools/MachineRegistry") {}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Builds a scoped registry that scans immediately and refreshes after relevant
|
|
64
|
+
* source file changes.
|
|
65
|
+
*
|
|
66
|
+
* @category layers
|
|
67
|
+
* @since 0.23.0
|
|
68
|
+
*/
|
|
69
|
+
export const layer = (options: Options) => internal.layer({ MachineRegistry, RegistryError }, options)
|