@typeonce/effect-machine-devtools 0.33.0 → 0.35.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.
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <meta name="description" content="Interactive statechart visualization for Effect Machine" />
7
7
  <title>Effect Machine · Statechart</title>
8
- <script type="module" crossorigin src="./assets/index-2uvShdlX.js"></script>
8
+ <script type="module" crossorigin src="./assets/index-s8iI2tep.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="./assets/index-DkC3PbTy.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeonce/effect-machine-devtools",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "Local development tools for Effect Machine",
5
5
  "author": "Sandro Maglione",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "elkjs": "0.12.0",
34
34
  "typescript": "6.0.3",
35
35
  "vite": "8.1.5",
36
- "@typeonce/effect-machine": "^0.33.0"
36
+ "@typeonce/effect-machine": "^0.35.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "effect": "4.0.0-rc.112"
@@ -1,31 +1,41 @@
1
1
  import { Machine } from "@typeonce/effect-machine"
2
2
  import { Schema } from "effect"
3
-
4
3
  // Shared by the live browser UI and its project-inspection fixture.
5
-
6
4
  class Application extends Schema.TaggedClass<Application>("Application")("Application", {
7
5
  workspace: Schema.String,
8
6
  revision: Schema.Number
9
- }) {}
7
+ }) {
8
+ }
10
9
  class Workflow extends Schema.TaggedClass<Workflow>("Workflow")("Workflow", {
11
10
  document: Schema.String,
12
11
  unsavedChanges: Schema.Number
13
- }) {}
14
- class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
15
- class Running extends Schema.TaggedClass<Running>("Running")("Running", {}) {}
16
- class Editing extends Schema.TaggedClass<Editing>("Editing")("Editing", {}) {}
17
- class Complete extends Schema.TaggedClass<Complete>("Complete")("Complete", {}) {}
18
- class Connection extends Schema.TaggedClass<Connection>("Connection")("Connection", {}) {}
19
- class Online extends Schema.TaggedClass<Online>("Online")("Online", {}) {}
20
- class Offline extends Schema.TaggedClass<Offline>("Offline")("Offline", {}) {}
21
- class Disabled extends Schema.TaggedClass<Disabled>("Disabled")("Disabled", {}) {}
22
- class Start extends Schema.TaggedClass<Start>("Start")("Start", {}) {}
23
- class Finish extends Schema.TaggedClass<Finish>("Finish")("Finish", {}) {}
24
- class Disconnect extends Schema.TaggedClass<Disconnect>("Disconnect")("Disconnect", {}) {}
25
- class Refresh extends Schema.TaggedClass<Refresh>("Refresh")("Refresh", {}) {}
26
-
12
+ }) {
13
+ }
14
+ class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
15
+ }
16
+ class Running extends Schema.TaggedClass<Running>("Running")("Running", {}) {
17
+ }
18
+ class Editing extends Schema.TaggedClass<Editing>("Editing")("Editing", {}) {
19
+ }
20
+ class Complete extends Schema.TaggedClass<Complete>("Complete")("Complete", {}) {
21
+ }
22
+ class Connection extends Schema.TaggedClass<Connection>("Connection")("Connection", {}) {
23
+ }
24
+ class Online extends Schema.TaggedClass<Online>("Online")("Online", {}) {
25
+ }
26
+ class Offline extends Schema.TaggedClass<Offline>("Offline")("Offline", {}) {
27
+ }
28
+ class Disabled extends Schema.TaggedClass<Disabled>("Disabled")("Disabled", {}) {
29
+ }
30
+ class Start extends Schema.TaggedClass<Start>("Start")("Start", {}) {
31
+ }
32
+ class Finish extends Schema.TaggedClass<Finish>("Finish")("Finish", {}) {
33
+ }
34
+ class Disconnect extends Schema.TaggedClass<Disconnect>("Disconnect")("Disconnect", {}) {
35
+ }
36
+ class Refresh extends Schema.TaggedClass<Refresh>("Refresh")("Refresh", {}) {
37
+ }
27
38
  const States = Machine.state({
28
- initial: "application",
29
39
  states: {
30
40
  application: {
31
41
  schema: Application,
@@ -33,12 +43,10 @@ const States = Machine.state({
33
43
  states: {
34
44
  workflow: {
35
45
  schema: Workflow,
36
- initial: "idle",
37
46
  states: {
38
47
  idle: Idle,
39
48
  running: {
40
49
  schema: Running,
41
- initial: "editing",
42
50
  states: {
43
51
  editing: Editing,
44
52
  complete: {
@@ -54,7 +62,6 @@ const States = Machine.state({
54
62
  },
55
63
  connection: {
56
64
  schema: Connection,
57
- initial: "online",
58
65
  states: {
59
66
  online: Online,
60
67
  offline: Offline
@@ -65,7 +72,6 @@ const States = Machine.state({
65
72
  disabled: Disabled
66
73
  }
67
74
  })
68
-
69
75
  export const snapshot = {
70
76
  path: "" as const,
71
77
  value: undefined,
@@ -86,22 +92,44 @@ export const snapshot = {
86
92
  }
87
93
  }
88
94
  }
89
-
90
- const initialWorkflow = (): Machine.Machine.CompleteSnapshotContaining<
91
- { readonly "": typeof States.node },
92
- "application.workflow"
93
- > => snapshot
94
-
95
+ const initialWorkflow = (): Machine.Machine.CompleteSnapshotContaining<{
96
+ readonly "": typeof States.node
97
+ }, "application.workflow"> => snapshot
98
+ const targets1 = Machine.targets(States)
95
99
  export const machine = Machine.make({
100
+ branches: {
101
+ transition1: {
102
+ destination: { target: targets1.root.application.workflow.running, update: targets1.root.application.workflow }
103
+ }
104
+ },
96
105
  id: "inspection-example",
97
106
  root: States,
98
- events: Machine.eventsFromSchemas(Start, Finish, Disconnect, Refresh),
99
- initialConfiguration: (to) => to.resolve(() => snapshot)
107
+ events: Machine.eventsFromSchemas(Start, Finish, Disconnect, Refresh)
100
108
  }).handle({
109
+ initial: {
110
+ target: Machine.targets(States).root.application,
111
+ decoded: true,
112
+ data: new Application({ workspace: "effect-machine", revision: 7 })
113
+ },
101
114
  states: {
102
115
  application: {
116
+ initial: {
117
+ workflow: {
118
+ decoded: true,
119
+ data: new Workflow({ document: "Machine.ts", unsavedChanges: 2 })
120
+ },
121
+ connection: {
122
+ decoded: true,
123
+ data: new Connection({})
124
+ }
125
+ },
103
126
  states: {
104
127
  workflow: {
128
+ initial: {
129
+ target: Machine.targets(States).root.application.workflow.idle,
130
+ decoded: true,
131
+ data: new Idle({})
132
+ },
105
133
  history: {
106
134
  recent: {
107
135
  default: initialWorkflow
@@ -110,43 +138,61 @@ export const machine = Machine.make({
110
138
  states: {
111
139
  idle: {
112
140
  on: {
113
- Start: (to) =>
114
- to.local.running()
115
- .updating(to.branch.application.workflow)
116
- .resolve(({ owner, target }) =>
117
- target.decoded(
118
- new Running({}),
119
- (running) => running.editing.decoded(new Editing({}))
120
- ).update(owner.decoded(new Workflow({ document: "Machine.ts", unsavedChanges: 3 })))
121
- ),
122
- Refresh: (to) =>
123
- to.local.update.resolve(({ owner }) =>
124
- owner.decoded(new Workflow({ document: "Machine.ts", unsavedChanges: 0 }))
125
- )
141
+ Start: {
142
+ branches: "transition1",
143
+ resolve: ({ select: { destination: target } }) =>
144
+ target.decoded(new Running({}), (running) => running.editing.decoded(new Editing({}))).update
145
+ .decoded(new Workflow({ document: "Machine.ts", unsavedChanges: 3 }))
146
+ },
147
+ Refresh: {
148
+ update: targets1.root.application.workflow,
149
+ decoded: true,
150
+ data: () => (new Workflow({ document: "Machine.ts", unsavedChanges: 0 }))
151
+ }
126
152
  }
127
153
  },
128
154
  running: {
129
- initialize: ({ builder }) => builder.decoded(new Editing({})),
155
+ initial: {
156
+ target: Machine.targets(States).root.application.workflow.running.editing,
157
+ decoded: true,
158
+ data: ({}) => new Editing({})
159
+ },
130
160
  states: {
131
161
  editing: {
132
162
  on: {
133
- Finish: (to) => to.local.complete().resolve(({ target }) => target.decoded(new Complete({})))
163
+ Finish: {
164
+ target: targets1.root.application.workflow.running.complete,
165
+ decoded: true,
166
+ data: () => (new Complete({}))
167
+ }
134
168
  }
135
- }
169
+ },
170
+ complete: {}
136
171
  }
137
172
  }
138
173
  }
139
174
  },
140
175
  connection: {
176
+ initial: {
177
+ target: Machine.targets(States).root.application.connection.online,
178
+ decoded: true,
179
+ data: new Online({})
180
+ },
141
181
  states: {
142
182
  online: {
143
183
  on: {
144
- Disconnect: (to) => to.local.offline().resolve(({ target }) => target.decoded(new Offline({})))
184
+ Disconnect: {
185
+ target: targets1.root.application.connection.offline,
186
+ decoded: true,
187
+ data: () => (new Offline({}))
188
+ }
145
189
  }
146
- }
190
+ },
191
+ offline: {}
147
192
  }
148
193
  }
149
194
  }
150
- }
195
+ },
196
+ disabled: {}
151
197
  }
152
198
  })
@@ -1,21 +1,16 @@
1
1
  import { Machine } from "@typeonce/effect-machine"
2
2
  import { Effect, Schema } from "effect"
3
-
4
3
  const ReviewState = Schema.TaggedUnion({
5
4
  Review: { title: Schema.String },
6
5
  ReviewFailed: { message: Schema.String },
7
6
  Complete: { slug: Schema.String }
8
7
  })
9
-
10
8
  const ReviewStates = Machine.state({
11
- initial: "Workflow",
12
9
  states: {
13
10
  Workflow: {
14
- initial: "Review",
15
11
  states: {
16
12
  Review: {
17
13
  schema: ReviewState.cases.Review,
18
- initial: "Form",
19
14
  states: {
20
15
  Form: {},
21
16
  Failed: ReviewState.cases.ReviewFailed
@@ -28,49 +23,46 @@ const ReviewStates = Machine.state({
28
23
  }
29
24
  }
30
25
  })
31
-
32
- const ReviewEvents = Machine.eventsFromSchemas(
33
- Schema.TaggedUnion({
34
- Submit: { route: Schema.Literals(["save", "invalid"]) }
35
- })
36
- )
37
-
26
+ const ReviewEvents = Machine.eventsFromSchemas(Schema.TaggedUnion({
27
+ Submit: { route: Schema.Literals(["save", "invalid"]) }
28
+ }))
38
29
  const saveReview: Effect.Effect<string, string> = Effect.succeed("deterministic-chart")
39
30
  const publishReview = Effect.succeed("deterministic-chart")
40
-
31
+ const targets1 = Machine.targets(ReviewStates)
41
32
  export const hierarchyRoutingMachine = Machine.make({
33
+ branches: {
34
+ transition1: {
35
+ save: { target: targets1.root.Workflow.Saving, title: "Save the review" },
36
+ invalid: { target: targets1.root.Workflow.Review.Failed, title: "Show validation failure" }
37
+ }
38
+ },
39
+ effects: { source1: Effect.suspend(() => saveReview), source2: Effect.suspend(() => publishReview) },
42
40
  id: "hierarchy-routing",
43
41
  root: ReviewStates,
44
- events: ReviewEvents,
45
- initialConfiguration: (root) =>
46
- root.resolve(({ target }) =>
47
- target.from((to) =>
48
- to.Workflow.from((workflow) =>
49
- workflow.Review.from({ title: "A deterministic chart" }, (review) => review.Form.from())
50
- )
51
- )
52
- )
42
+ events: ReviewEvents
53
43
  }).handle({
44
+ initial: {
45
+ target: Machine.targets(ReviewStates).root.Workflow
46
+ },
54
47
  states: {
55
48
  Workflow: {
49
+ initial: {
50
+ target: Machine.targets(ReviewStates).root.Workflow.Review,
51
+ data: { title: "A deterministic chart" }
52
+ },
56
53
  states: {
57
54
  Review: {
55
+ initial: {
56
+ target: Machine.targets(ReviewStates).root.Workflow.Review.Form
57
+ },
58
58
  on: {
59
- Submit: (to) =>
60
- to.branches({
61
- save: {
62
- title: "Save the review",
63
- target: to.branch.Workflow.Saving()
64
- },
65
- invalid: {
66
- title: "Show validation failure",
67
- target: to.local.Failed()
68
- }
69
- }).resolve(({ event, select }) =>
59
+ Submit: {
60
+ branches: "transition1",
61
+ resolve: ({ event, select }) =>
70
62
  event.route === "save"
71
63
  ? select.save.from()
72
64
  : select.invalid.from({ message: "Add a title before continuing." })
73
- )
65
+ }
74
66
  },
75
67
  states: {
76
68
  Form: {},
@@ -78,20 +70,22 @@ export const hierarchyRoutingMachine = Machine.make({
78
70
  }
79
71
  },
80
72
  Saving: {
81
- invoke: (from) =>
82
- from.effect("save-review", () => saveReview).onDone((to) => to.branch.Workflow.Publishing()).onFailure((
83
- to
84
- ) =>
85
- to.branch.Workflow.Review.Failed().resolve(({ target }) =>
86
- target.from({ message: "The review could not be saved." })
87
- )
88
- )
73
+ invoke: {
74
+ src: "source1",
75
+ id: "save-review",
76
+ onDone: { target: targets1.root.Workflow.Publishing },
77
+ onFailure: {
78
+ target: targets1.root.Workflow.Review.Failed,
79
+ data: () => ({ message: "The review could not be saved." })
80
+ }
81
+ }
89
82
  },
90
83
  Publishing: {
91
- invoke: (from) =>
92
- from.effect("publish-review", () => publishReview).onDone((to) =>
93
- to.branch.Workflow.Complete().resolve(({ output, target }) => target.from({ slug: output }))
94
- )
84
+ invoke: {
85
+ src: "source2",
86
+ id: "publish-review",
87
+ onDone: { target: targets1.root.Workflow.Complete, data: ({ output }) => ({ slug: output }) }
88
+ }
95
89
  },
96
90
  Complete: {}
97
91
  }