@typeonce/effect-machine-devtools 0.38.0 → 0.39.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.
@@ -57,11 +57,10 @@ const ChildStates = Machine.state({
57
57
  Cancelled: { schema: ChildCancelled, type: "final", output: Schema.String }
58
58
  }
59
59
  })
60
- const targets1 = Machine.targets(ChildStates)
61
60
  export const requiredParentChildMachine = Machine.make({
62
61
  branches: {
63
- transition1: { destination: { target: targets1.root.Working } },
64
- transition3: { destination: { target: targets1.root.Working } }
62
+ transition1: { destination: { target: "Working" } },
63
+ transition3: { destination: { target: "Working" } }
65
64
  },
66
65
  effects: {
67
66
  source1: ({ parent, state }: {
@@ -77,7 +76,7 @@ export const requiredParentChildMachine = Machine.make({
77
76
  parent: Machine.parent(ParentEvents)
78
77
  }).handle({
79
78
  initial: {
80
- target: Machine.targets(ChildStates).root.Idle,
79
+ target: "Idle",
81
80
  decoded: true,
82
81
  data: new ChildIdle({})
83
82
  },
@@ -101,7 +100,7 @@ export const requiredParentChildMachine = Machine.make({
101
100
  input: (context) => context,
102
101
  onDone: { none: true },
103
102
  onFailure: {
104
- target: targets1.root.Cancelled,
103
+ target: "Cancelled",
105
104
  decoded: true,
106
105
  data: ({ error }) => (new ChildCancelled({ reason: String(error) }))
107
106
  }
@@ -115,12 +114,12 @@ export const requiredParentChildMachine = Machine.make({
115
114
  }
116
115
  },
117
116
  CommitChildWork: {
118
- target: targets1.root.Done,
117
+ target: "Done",
119
118
  decoded: true,
120
119
  data: ({ state }) => (new ChildDone({ result: `${state.job}:complete` }))
121
120
  },
122
121
  CancelChildWork: {
123
- target: targets1.root.Cancelled,
122
+ target: "Cancelled",
124
123
  decoded: true,
125
124
  data: ({ event }) => (new ChildCancelled({ reason: event.reason }))
126
125
  }
@@ -161,11 +160,10 @@ const ParentStates = Machine.state({
161
160
  Failed: ParentFailed
162
161
  }
163
162
  })
164
- const targets2 = Machine.targets(ParentStates)
165
163
  export const parentProtocolMachine = Machine.make({
166
164
  branches: {
167
- transition1: { destination: { target: targets2.root.Supervising } },
168
- transition3: { destination: { target: targets2.root.Complete } }
165
+ transition1: { destination: { target: "Supervising" } },
166
+ transition3: { destination: { target: "Complete" } }
169
167
  },
170
168
  children: { source1: ProtocolChild },
171
169
  id: "parent-child-protocol",
@@ -173,7 +171,7 @@ export const parentProtocolMachine = Machine.make({
173
171
  events: Machine.eventsFromSchemas(LaunchChild, ResetParent, ParentEvents)
174
172
  }).handle({
175
173
  initial: {
176
- target: Machine.targets(ParentStates).root.Idle,
174
+ target: "Idle",
177
175
  decoded: true,
178
176
  data: new ParentIdle({})
179
177
  },
@@ -181,7 +179,7 @@ export const parentProtocolMachine = Machine.make({
181
179
  Idle: {
182
180
  on: {
183
181
  LaunchChild: {
184
- target: targets2.root.Supervising,
182
+ target: "Supervising",
185
183
  decoded: true,
186
184
  data: () => (new Supervising({ latestProgress: 0 }))
187
185
  }
@@ -191,33 +189,33 @@ export const parentProtocolMachine = Machine.make({
191
189
  invoke: {
192
190
  src: "source1",
193
191
  onDone: {
194
- target: targets2.root.Complete,
192
+ target: "Complete",
195
193
  decoded: true,
196
194
  data: ({ output }) => (new ParentComplete({ result: output }))
197
195
  },
198
196
  onFailure: {
199
- target: targets2.root.Failed,
197
+ target: "Failed",
200
198
  decoded: true,
201
199
  data: ({ error }) => (new ParentFailed({ message: String(error) }))
202
200
  }
203
201
  },
204
202
  on: {
205
203
  ChildProgress: {
206
- target: targets2.root.Supervising,
204
+ target: "Supervising",
207
205
  decoded: true,
208
206
  data: ({ event }) => (new Supervising({ latestProgress: event.percent }))
209
207
  },
210
208
  ChildFinished: {
211
- target: targets2.root.Complete,
209
+ target: "Complete",
212
210
  decoded: true,
213
211
  data: ({ event }) => (new ParentComplete({ result: event.result }))
214
212
  },
215
213
  ChildProblem: {
216
- target: targets2.root.Failed,
214
+ target: "Failed",
217
215
  decoded: true,
218
216
  data: ({ event }) => (new ParentFailed({ message: event.message }))
219
217
  },
220
- ResetParent: { target: targets2.root.Idle, decoded: true, data: () => (new ParentIdle({})) }
218
+ ResetParent: { target: "Idle", decoded: true, data: () => (new ParentIdle({})) }
221
219
  }
222
220
  },
223
221
  Complete: {
@@ -225,7 +223,7 @@ export const parentProtocolMachine = Machine.make({
225
223
  },
226
224
  Failed: {
227
225
  on: {
228
- ResetParent: { target: targets2.root.Idle, decoded: true, data: () => (new ParentIdle({})) }
226
+ ResetParent: { target: "Idle", decoded: true, data: () => (new ParentIdle({})) }
229
227
  }
230
228
  }
231
229
  }
@@ -241,16 +239,15 @@ class PublishOutside extends Schema.TaggedClass<PublishOutside>("OptionalParentP
241
239
  }) {
242
240
  }
243
241
  const OptionalParentStates = Machine.state({ states: { Detached, Published } })
244
- const targets3 = Machine.targets(OptionalParentStates)
245
242
  export const optionalParentMachine = Machine.make({
246
- branches: { transition1: { destination: { target: targets3.root.Published } } },
243
+ branches: { transition1: { destination: { target: "Published" } } },
247
244
  id: "optional-parent-protocol",
248
245
  root: OptionalParentStates,
249
246
  events: Machine.eventsFromSchemas(PublishOutside),
250
247
  parent: Machine.optionalParent(ParentEvents)
251
248
  }).handle({
252
249
  initial: {
253
- target: Machine.targets(OptionalParentStates).root.Detached,
250
+ target: "Detached",
254
251
  decoded: true,
255
252
  data: new Detached({})
256
253
  },
@@ -23,7 +23,6 @@ const ReplicationEvents = Machine.eventsFromSchemas(Schema.TaggedUnion({
23
23
  StopRequested: {}
24
24
  }))
25
25
  const operation: Effect.Effect<void, string> = Effect.succeed(undefined)
26
- const targets1 = Machine.targets(ReplicationStates)
27
26
  export const sharedTerminalRoutingMachine = Machine.make({
28
27
  effects: {
29
28
  source1: operation,
@@ -41,130 +40,130 @@ export const sharedTerminalRoutingMachine = Machine.make({
41
40
  events: ReplicationEvents
42
41
  }).handle({
43
42
  initial: {
44
- target: Machine.targets(ReplicationStates).root.Connecting
43
+ target: "Connecting"
45
44
  },
46
45
  states: {
47
46
  Connecting: {
48
47
  invoke: {
49
48
  src: "source1",
50
49
  id: "connect",
51
- onDone: { target: targets1.root.IdentifyingSource },
52
- onFailure: { target: targets1.root.Failed }
50
+ onDone: { target: "IdentifyingSource" },
51
+ onFailure: { target: "Failed" }
53
52
  },
54
53
  on: {
55
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
56
- StopRequested: { target: targets1.root.Stopping }
54
+ SessionUnavailable: { target: "SessionUnavailable" },
55
+ StopRequested: { target: "Stopping" }
57
56
  }
58
57
  },
59
58
  IdentifyingSource: {
60
59
  invoke: {
61
60
  src: "source2",
62
61
  id: "identify-source",
63
- onDone: { target: targets1.root.ReadingServerInfo },
64
- onFailure: { target: targets1.root.Failed }
62
+ onDone: { target: "ReadingServerInfo" },
63
+ onFailure: { target: "Failed" }
65
64
  },
66
65
  on: {
67
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
68
- StopRequested: { target: targets1.root.Stopping }
66
+ SessionUnavailable: { target: "SessionUnavailable" },
67
+ StopRequested: { target: "Stopping" }
69
68
  }
70
69
  },
71
70
  ReadingServerInfo: {
72
71
  invoke: {
73
72
  src: "source3",
74
73
  id: "read-server-info",
75
- onDone: { target: targets1.root.ReadingSlot },
76
- onFailure: { target: targets1.root.Failed }
74
+ onDone: { target: "ReadingSlot" },
75
+ onFailure: { target: "Failed" }
77
76
  },
78
77
  on: {
79
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
80
- StopRequested: { target: targets1.root.Stopping }
78
+ SessionUnavailable: { target: "SessionUnavailable" },
79
+ StopRequested: { target: "Stopping" }
81
80
  }
82
81
  },
83
82
  ReadingSlot: {
84
83
  invoke: {
85
84
  src: "source4",
86
85
  id: "read-slot",
87
- onDone: { target: targets1.root.CreatingSlot },
88
- onFailure: { target: targets1.root.Failed }
86
+ onDone: { target: "CreatingSlot" },
87
+ onFailure: { target: "Failed" }
89
88
  },
90
89
  on: {
91
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
92
- StopRequested: { target: targets1.root.Stopping }
90
+ SessionUnavailable: { target: "SessionUnavailable" },
91
+ StopRequested: { target: "Stopping" }
93
92
  }
94
93
  },
95
94
  CreatingSlot: {
96
95
  invoke: {
97
96
  src: "source5",
98
97
  id: "create-slot",
99
- onDone: { target: targets1.root.CopyingSnapshot },
100
- onFailure: { target: targets1.root.Failed }
98
+ onDone: { target: "CopyingSnapshot" },
99
+ onFailure: { target: "Failed" }
101
100
  },
102
101
  on: {
103
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
104
- StopRequested: { target: targets1.root.Stopping }
102
+ SessionUnavailable: { target: "SessionUnavailable" },
103
+ StopRequested: { target: "Stopping" }
105
104
  }
106
105
  },
107
106
  CopyingSnapshot: {
108
107
  invoke: {
109
108
  src: "source6",
110
109
  id: "copy-snapshot",
111
- onDone: { target: targets1.root.CatchingUp },
112
- onFailure: { target: targets1.root.Failed }
110
+ onDone: { target: "CatchingUp" },
111
+ onFailure: { target: "Failed" }
113
112
  },
114
113
  on: {
115
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
116
- StopRequested: { target: targets1.root.Stopping }
114
+ SessionUnavailable: { target: "SessionUnavailable" },
115
+ StopRequested: { target: "Stopping" }
117
116
  }
118
117
  },
119
118
  CatchingUp: {
120
119
  invoke: {
121
120
  src: "source7",
122
121
  id: "catch-up",
123
- onDone: { target: targets1.root.ApplyingChanges },
124
- onFailure: { target: targets1.root.Failed }
122
+ onDone: { target: "ApplyingChanges" },
123
+ onFailure: { target: "Failed" }
125
124
  },
126
125
  on: {
127
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
128
- StopRequested: { target: targets1.root.Stopping }
126
+ SessionUnavailable: { target: "SessionUnavailable" },
127
+ StopRequested: { target: "Stopping" }
129
128
  }
130
129
  },
131
130
  ApplyingChanges: {
132
131
  invoke: {
133
132
  src: "source8",
134
133
  id: "apply-changes",
135
- onDone: { target: targets1.root.Ready },
136
- onFailure: { target: targets1.root.Failed }
134
+ onDone: { target: "Ready" },
135
+ onFailure: { target: "Failed" }
137
136
  },
138
137
  on: {
139
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
140
- StopRequested: { target: targets1.root.Stopping }
138
+ SessionUnavailable: { target: "SessionUnavailable" },
139
+ StopRequested: { target: "Stopping" }
141
140
  }
142
141
  },
143
142
  Ready: {
144
143
  on: {
145
- SessionUnavailable: { target: targets1.root.SessionUnavailable },
146
- StopRequested: { target: targets1.root.Stopping }
144
+ SessionUnavailable: { target: "SessionUnavailable" },
145
+ StopRequested: { target: "Stopping" }
147
146
  }
148
147
  },
149
148
  SessionUnavailable: {
150
149
  on: {
151
- Retry: { target: targets1.root.Connecting },
152
- StopRequested: { target: targets1.root.Stopping }
150
+ Retry: { target: "Connecting" },
151
+ StopRequested: { target: "Stopping" }
153
152
  }
154
153
  },
155
154
  Stopping: {
156
155
  invoke: {
157
156
  src: "source9",
158
157
  id: "stop-session",
159
- onDone: { target: targets1.root.Stopped },
160
- onFailure: { target: targets1.root.Failed }
158
+ onDone: { target: "Stopped" },
159
+ onFailure: { target: "Failed" }
161
160
  }
162
161
  },
163
162
  Stopped: {},
164
163
  Failed: {
165
164
  on: {
166
- Retry: { target: targets1.root.Connecting },
167
- StopRequested: { target: targets1.root.Stopping }
165
+ Retry: { target: "Connecting" },
166
+ StopRequested: { target: "Stopping" }
168
167
  }
169
168
  }
170
169
  }
@@ -128,19 +128,18 @@ const defaultWorkspaceSnapshot = () => ({
128
128
  }
129
129
  }
130
130
  })
131
- const targets1 = Machine.targets(TransitionStates)
132
131
  export const transitionSemanticsMachine = Machine.make({
133
132
  branches: {
134
133
  transition4: {
135
- draft: { target: targets1.root.Workspace.Draft, title: "Preferred route is draft" },
136
- review: { target: targets1.root.Workspace.Review, title: "Preferred route is review" }
134
+ draft: { target: "Workspace.Draft", title: "Preferred route is draft" },
135
+ review: { target: "Workspace.Review", title: "Preferred route is review" }
137
136
  },
138
137
  transition7: {
139
- review: { target: targets1.root.Workspace.Review, title: "Enter the review flow" },
140
- publish: { target: targets1.root.Workspace.Finished, title: "Publish without review" }
138
+ review: { target: "Workspace.Review", title: "Enter the review flow" },
139
+ publish: { target: "Workspace.Finished", title: "Publish without review" }
141
140
  },
142
- transition14: { destination: { history: targets1.root.Workspace.recent } },
143
- transition15: { destination: { history: targets1.root.Workspace.exact } }
141
+ transition14: { destination: { history: "Workspace.recent" } },
142
+ transition15: { destination: { history: "Workspace.exact" } }
144
143
  },
145
144
  id: "transition-semantics",
146
145
  root: TransitionStates,
@@ -164,14 +163,14 @@ export const transitionSemanticsMachine = Machine.make({
164
163
  )
165
164
  }).handle({
166
165
  initial: {
167
- target: Machine.targets(TransitionStates).root.Paused,
166
+ target: "Paused",
168
167
  decoded: true,
169
168
  data: new Paused({ reason: "not started" })
170
169
  },
171
170
  states: {
172
171
  Workspace: {
173
172
  initial: {
174
- target: Machine.targets(TransitionStates).root.Workspace.Routing
173
+ target: "Workspace.Routing"
175
174
  },
176
175
  history: {
177
176
  recent: { default: defaultWorkspaceSnapshot },
@@ -179,12 +178,12 @@ export const transitionSemanticsMachine = Machine.make({
179
178
  },
180
179
  on: {
181
180
  Pause: {
182
- target: targets1.root.Paused,
181
+ target: "Paused",
183
182
  decoded: true,
184
183
  data: ({ event }) => (new Paused({ reason: event.reason }))
185
184
  },
186
185
  BumpWorkspace: {
187
- update: targets1.root.Workspace,
186
+ update: "Workspace",
188
187
  decoded: true,
189
188
  data: ({ state: current }) => (new Workspace({
190
189
  revision: current.revision + 1,
@@ -193,7 +192,7 @@ export const transitionSemanticsMachine = Machine.make({
193
192
  }
194
193
  },
195
194
  onDone: {
196
- target: targets1.root.Published,
195
+ target: "Published",
197
196
  decoded: true,
198
197
  data: () => (new Published({ result: "workspace published" }))
199
198
  },
@@ -210,11 +209,11 @@ export const transitionSemanticsMachine = Machine.make({
210
209
  Draft: {
211
210
  on: {
212
211
  Edit: {
213
- target: targets1.root.Workspace.Draft,
212
+ target: "Workspace.Draft",
214
213
  decoded: true,
215
214
  data: ({ event, state }) => (new Draft({ text: event.text, autosaves: state.autosaves }))
216
215
  },
217
- Save: { target: targets1.root.Workspace.AutoSaving, decoded: true, data: () => (new AutoSaving({})) },
216
+ Save: { target: "Workspace.AutoSaving", decoded: true, data: () => (new AutoSaving({})) },
218
217
  Submit: {
219
218
  branches: "transition7",
220
219
  resolve: ({ event, select }) =>
@@ -233,19 +232,19 @@ export const transitionSemanticsMachine = Machine.make({
233
232
  },
234
233
  AutoSaving: {
235
234
  always: {
236
- target: targets1.root.Workspace.Draft,
235
+ target: "Workspace.Draft",
237
236
  decoded: true,
238
237
  data: () => (new Draft({ text: "Autosaved draft", autosaves: 1 }))
239
238
  }
240
239
  },
241
240
  Review: {
242
241
  initial: {
243
- target: Machine.targets(TransitionStates).root.Workspace.Review.Checking,
242
+ target: "Workspace.Review.Checking",
244
243
  decoded: true,
245
244
  data: ({}) => new Checking({ checks: ["types", "tests"] })
246
245
  },
247
246
  onDone: {
248
- target: targets1.root.Workspace.Finished,
247
+ target: "Workspace.Finished",
249
248
  decoded: true,
250
249
  data: () => (new WorkspaceFinished({ result: "approved review" }))
251
250
  },
@@ -253,12 +252,12 @@ export const transitionSemanticsMachine = Machine.make({
253
252
  Checking: {
254
253
  on: {
255
254
  Approve: {
256
- target: targets1.root.Workspace.Review.Approved,
255
+ target: "Workspace.Review.Approved",
257
256
  decoded: true,
258
257
  data: ({ event }) => (new Approved({ reviewer: event.reviewer }))
259
258
  },
260
259
  Reject: {
261
- target: targets1.root.Workspace.Review.ChangesRequested,
260
+ target: "Workspace.Review.ChangesRequested",
262
261
  decoded: true,
263
262
  data: ({ event }) => (new ChangesRequested({ reason: event.reason }))
264
263
  }
@@ -267,7 +266,7 @@ export const transitionSemanticsMachine = Machine.make({
267
266
  ChangesRequested: {
268
267
  on: {
269
268
  Revise: {
270
- target: targets1.root.Workspace.Draft,
269
+ target: "Workspace.Draft",
271
270
  decoded: true,
272
271
  data: () => (new Draft({ text: "Revised draft", autosaves: 0 }))
273
272
  }
@@ -282,14 +281,14 @@ export const transitionSemanticsMachine = Machine.make({
282
281
  Paused: {
283
282
  on: {
284
283
  Create: {
285
- target: targets1.root.Workspace,
284
+ target: "Workspace",
286
285
  decoded: true,
287
286
  data: ({ event }) => (new Workspace({ revision: 0, preferredRoute: event.route }))
288
287
  },
289
288
  ResumeShallow: { branches: "transition14", resolve: ({ select: { destination: target } }) => target() },
290
289
  ResumeDeep: { branches: "transition15", resolve: ({ select: { destination: target } }) => target() },
291
290
  Restart: {
292
- target: targets1.root.Workspace,
291
+ target: "Workspace",
293
292
  decoded: true,
294
293
  data: () => (new Workspace({ revision: 0, preferredRoute: "draft" }))
295
294
  }
@@ -72,9 +72,7 @@ export const triggerLabel = (transition: VisualizationTransition): string => {
72
72
  }
73
73
  }
74
74
 
75
- const propertyAccess = (key: string): string => /^[$A-Z_a-z][$\w]*$/.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`
76
-
77
- const pathAccess = (path: string): string => path === "" ? "" : path.split(".").map(propertyAccess).join("")
75
+ const pathName = (path: string): string => JSON.stringify(path === "" ? "root" : path)
78
76
 
79
77
  /** Public declaration represented by a retained transition branch. */
80
78
  export const branchTargetApi = (branch: VisualizationBranch): string | undefined => {
@@ -84,9 +82,10 @@ export const branchTargetApi = (branch: VisualizationBranch): string | undefined
84
82
  if (path === null) return undefined
85
83
  if (selection.scope === "initial") return "initialConfiguration"
86
84
  const operation = selection.kind === "state" || selection.kind === "choice" ? "target" : selection.kind
87
- const fields = [`${operation}: targets.root${pathAccess(path)}`]
85
+ if (operation === "target" && path === "") return "{ initialize: … }"
86
+ const fields = [`${operation}: ${pathName(path)}`]
88
87
  if (operation !== "update") {
89
- for (const owner of branch.updates) fields.push(`update: targets.root${pathAccess(owner)}`)
88
+ for (const owner of branch.updates) fields.push(`update: ${pathName(owner)}`)
90
89
  }
91
90
  return `{ ${fields.join(", ")} }`
92
91
  }