@typeonce/effect-machine-devtools 0.34.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.
- package/package.json +2 -2
- package/src/internal/browser/example-machine.ts +79 -42
- package/src/internal/browser/hierarchy-routing-example.ts +16 -25
- package/src/internal/browser/invoke-outcomes-example.ts +100 -74
- package/src/internal/browser/layout-resilience-example.ts +48 -41
- package/src/internal/browser/parallel-completion-example.ts +97 -61
- package/src/internal/browser/parallel-owner-routing-example.ts +66 -48
- package/src/internal/browser/planner-example.ts +63 -20
- package/src/internal/browser/protocol-events-example.ts +95 -73
- package/src/internal/browser/shared-terminal-routing-example.ts +9 -15
- package/src/internal/browser/transition-semantics-example.ts +105 -66
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Machine } from "@typeonce/effect-machine"
|
|
2
2
|
import { Schema } from "effect"
|
|
3
3
|
import * as Effect from "effect/Effect"
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Idle extends Schema.TaggedClass<Idle>("PlannerIdle")("Idle", { owner: Schema.String }) {
|
|
5
|
+
}
|
|
6
6
|
class Working extends Schema.TaggedClass<Working>("PlannerWorking")("Working", {
|
|
7
7
|
owner: Schema.String,
|
|
8
8
|
job: Schema.String
|
|
9
|
-
}) {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
}) {
|
|
10
|
+
}
|
|
11
|
+
class Finished extends Schema.TaggedClass<Finished>("PlannerFinished")("Finished", { job: Schema.String }) {
|
|
12
|
+
}
|
|
12
13
|
const Owner = Schema.NonEmptyString.annotate({
|
|
13
14
|
title: "Owner",
|
|
14
15
|
description: "A non-empty name carried into the initial Idle state."
|
|
@@ -33,7 +34,6 @@ const Route = Schema.Union([
|
|
|
33
34
|
title: "Route",
|
|
34
35
|
description: "Choose a literal direct route or provide a queue."
|
|
35
36
|
})
|
|
36
|
-
|
|
37
37
|
class Begin extends Schema.TaggedClass<Begin>("PlannerBegin")("Begin", {
|
|
38
38
|
job: Schema.NonEmptyString.annotate({
|
|
39
39
|
title: "Job",
|
|
@@ -59,23 +59,56 @@ class Begin extends Schema.TaggedClass<Begin>("PlannerBegin")("Begin", {
|
|
|
59
59
|
),
|
|
60
60
|
labels: Schema.optionalKey(Labels),
|
|
61
61
|
route: Schema.optionalKey(Route)
|
|
62
|
-
}) {
|
|
63
|
-
|
|
64
|
-
class
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
}) {
|
|
63
|
+
}
|
|
64
|
+
class Cancel extends Schema.TaggedClass<Cancel>("PlannerCancel")("Cancel", { reason: Schema.String }) {
|
|
65
|
+
}
|
|
66
|
+
class AutoFinish extends Schema.TaggedClass<AutoFinish>("PlannerAutoFinish")("AutoFinish", {}) {
|
|
67
|
+
}
|
|
68
|
+
class Planned extends Schema.TaggedClass<Planned>("PlannerPlanned")("Planned", { job: Schema.String }) {
|
|
69
|
+
}
|
|
67
70
|
const Events = Machine.eventsFromSchemas(Begin, Cancel)
|
|
68
71
|
const InternalEvents = Machine.internalEventsFromSchemas(AutoFinish)
|
|
69
72
|
const Emissions = Machine.emittedEventsFromSchemas(Planned)
|
|
70
73
|
const States = Machine.state({
|
|
71
|
-
|
|
74
|
+
fields: {
|
|
75
|
+
input: Schema.toType(Schema.Struct({
|
|
76
|
+
owner: Owner,
|
|
77
|
+
attempts: Attempts,
|
|
78
|
+
notifications: Schema.Boolean.annotate({
|
|
79
|
+
title: "Notifications",
|
|
80
|
+
description: "A required boolean with false as a valid value."
|
|
81
|
+
}),
|
|
82
|
+
mode: Schema.Literals(["guided", "automatic"]).annotate({
|
|
83
|
+
title: "Mode",
|
|
84
|
+
description: "A fixed set of startup modes."
|
|
85
|
+
}),
|
|
86
|
+
note: Schema.optionalKey(
|
|
87
|
+
Schema.String.check(Schema.isMaxLength(40)).annotate({
|
|
88
|
+
title: "Note",
|
|
89
|
+
description: "Optional startup text limited to forty characters."
|
|
90
|
+
})
|
|
91
|
+
),
|
|
92
|
+
labels: Schema.optionalKey(Labels),
|
|
93
|
+
preferences: Schema.optionalKey(
|
|
94
|
+
Schema.Struct({
|
|
95
|
+
retries: Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 3 })).annotate({
|
|
96
|
+
title: "Retries"
|
|
97
|
+
}),
|
|
98
|
+
dryRun: Schema.Boolean.annotate({ title: "Dry run" })
|
|
99
|
+
}).annotate({
|
|
100
|
+
title: "Preferences",
|
|
101
|
+
description: "An optional nested object."
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
}))
|
|
105
|
+
},
|
|
72
106
|
states: {
|
|
73
107
|
Idle,
|
|
74
108
|
Working,
|
|
75
109
|
Finished: { schema: Finished, type: "final", output: Schema.String }
|
|
76
110
|
}
|
|
77
111
|
})
|
|
78
|
-
|
|
79
112
|
const targets1 = Machine.targets(States)
|
|
80
113
|
export const plannerMachine = Machine.make({
|
|
81
114
|
branches: {
|
|
@@ -85,7 +118,6 @@ export const plannerMachine = Machine.make({
|
|
|
85
118
|
}
|
|
86
119
|
},
|
|
87
120
|
effects: { source1: Effect.suspend(() => Effect.never) },
|
|
88
|
-
|
|
89
121
|
id: "planner-example",
|
|
90
122
|
root: States,
|
|
91
123
|
events: Events,
|
|
@@ -120,10 +152,14 @@ export const plannerMachine = Machine.make({
|
|
|
120
152
|
description: "An optional nested object."
|
|
121
153
|
})
|
|
122
154
|
)
|
|
123
|
-
})
|
|
124
|
-
initialConfiguration: (root) =>
|
|
125
|
-
root.resolve(({ input, target }) => target.from((to) => to.Idle.decoded(new Idle({ owner: input.owner }))))
|
|
155
|
+
})
|
|
126
156
|
}).handle({
|
|
157
|
+
initial: {
|
|
158
|
+
target: Machine.targets(States).root.Idle,
|
|
159
|
+
decoded: true,
|
|
160
|
+
data: ({ root: { input: input } }) => new Idle({ owner: input.owner })
|
|
161
|
+
},
|
|
162
|
+
root: ({ input }) => ({ input }),
|
|
127
163
|
states: {
|
|
128
164
|
Idle: {
|
|
129
165
|
on: {
|
|
@@ -132,7 +168,9 @@ export const plannerMachine = Machine.make({
|
|
|
132
168
|
resolve: ({ event, self, select, state }, enqueue) => {
|
|
133
169
|
enqueue.emit(new Planned({ job: event.job }))
|
|
134
170
|
enqueue.sendTo(self, Events.Cancel({ reason: "planner command example" }))
|
|
135
|
-
if (event.priority === "urgent")
|
|
171
|
+
if (event.priority === "urgent") {
|
|
172
|
+
enqueue.raise(InternalEvents.AutoFinish())
|
|
173
|
+
}
|
|
136
174
|
const working = new Working({ owner: state.owner, job: event.job })
|
|
137
175
|
return event.priority === "urgent"
|
|
138
176
|
? select.urgent.decoded(working)
|
|
@@ -144,10 +182,15 @@ export const plannerMachine = Machine.make({
|
|
|
144
182
|
Working: {
|
|
145
183
|
invoke: { src: "source1", id: "monitor-job" },
|
|
146
184
|
on: {
|
|
147
|
-
AutoFinish: {
|
|
185
|
+
AutoFinish: {
|
|
186
|
+
target: targets1.root.Finished,
|
|
187
|
+
decoded: true,
|
|
188
|
+
data: ({ state }) => (new Finished({ job: state.job }))
|
|
189
|
+
},
|
|
148
190
|
Cancel: {
|
|
149
191
|
target: targets1.root.Idle,
|
|
150
|
-
decoded:
|
|
192
|
+
decoded: true,
|
|
193
|
+
data: ({ event, state }) => (new Idle({ owner: `${state.owner} · ${event.reason}` }))
|
|
151
194
|
}
|
|
152
195
|
}
|
|
153
196
|
},
|
|
@@ -1,53 +1,55 @@
|
|
|
1
1
|
import { Machine } from "@typeonce/effect-machine"
|
|
2
2
|
import { Schema } from "effect"
|
|
3
|
-
|
|
4
3
|
class ChildProgress extends Schema.TaggedClass<ChildProgress>("ProtocolChildProgress")("ChildProgress", {
|
|
5
4
|
percent: Schema.Number
|
|
6
|
-
}) {
|
|
5
|
+
}) {
|
|
6
|
+
}
|
|
7
7
|
class ChildFinished extends Schema.TaggedClass<ChildFinished>("ProtocolChildFinished")("ChildFinished", {
|
|
8
8
|
result: Schema.String
|
|
9
|
-
}) {
|
|
9
|
+
}) {
|
|
10
|
+
}
|
|
10
11
|
class ChildProblem extends Schema.TaggedClass<ChildProblem>("ProtocolChildProblem")("ChildProblem", {
|
|
11
12
|
message: Schema.String
|
|
12
|
-
}) {
|
|
13
|
-
|
|
13
|
+
}) {
|
|
14
|
+
}
|
|
14
15
|
const ParentEvents = Machine.eventsFromSchemas(ChildProgress, ChildFinished, ChildProblem)
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
class ChildIdle extends Schema.TaggedClass<ChildIdle>("ProtocolChildIdle")("Idle", {}) {
|
|
17
|
+
}
|
|
17
18
|
class ChildWorking extends Schema.TaggedClass<ChildWorking>("ProtocolChildWorking")("Working", {
|
|
18
19
|
job: Schema.String,
|
|
19
20
|
progress: Schema.Number
|
|
20
|
-
}) {
|
|
21
|
+
}) {
|
|
22
|
+
}
|
|
21
23
|
class ChildDone extends Schema.TaggedClass<ChildDone>("ProtocolChildDone")("Done", {
|
|
22
24
|
result: Schema.String
|
|
23
|
-
}) {
|
|
25
|
+
}) {
|
|
26
|
+
}
|
|
24
27
|
class ChildCancelled extends Schema.TaggedClass<ChildCancelled>("ProtocolChildCancelled")("Cancelled", {
|
|
25
28
|
reason: Schema.String
|
|
26
|
-
}) {
|
|
27
|
-
|
|
29
|
+
}) {
|
|
30
|
+
}
|
|
28
31
|
class BeginChildWork extends Schema.TaggedClass<BeginChildWork>("ProtocolBeginChildWork")("BeginChildWork", {
|
|
29
32
|
job: Schema.String
|
|
30
|
-
}) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{ reason: Schema.String }
|
|
34
|
-
|
|
33
|
+
}) {
|
|
34
|
+
}
|
|
35
|
+
class CancelChildWork
|
|
36
|
+
extends Schema.TaggedClass<CancelChildWork>("ProtocolCancelChildWork")("CancelChildWork", { reason: Schema.String })
|
|
37
|
+
{
|
|
38
|
+
}
|
|
35
39
|
class Heartbeat extends Schema.TaggedClass<Heartbeat>("ProtocolHeartbeat")("Heartbeat", {
|
|
36
40
|
percent: Schema.Number
|
|
37
|
-
}) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
) {}
|
|
41
|
+
}) {
|
|
42
|
+
}
|
|
43
|
+
class CommitChildWork extends Schema.TaggedClass<CommitChildWork>("ProtocolCommitChildWork")("CommitChildWork", {}) {
|
|
44
|
+
}
|
|
42
45
|
class ChildTrace extends Schema.TaggedClass<ChildTrace>("ProtocolChildTrace")("ChildTrace", {
|
|
43
46
|
message: Schema.String
|
|
44
|
-
}) {
|
|
45
|
-
|
|
47
|
+
}) {
|
|
48
|
+
}
|
|
46
49
|
const ChildEvents = Machine.eventsFromSchemas(BeginChildWork, CancelChildWork)
|
|
47
50
|
const ChildInternalEvents = Machine.internalEventsFromSchemas(Heartbeat, CommitChildWork)
|
|
48
51
|
const ChildEmissions = Machine.emittedEventsFromSchemas(ChildTrace)
|
|
49
52
|
const ChildStates = Machine.state({
|
|
50
|
-
initial: "Idle",
|
|
51
53
|
states: {
|
|
52
54
|
Idle: ChildIdle,
|
|
53
55
|
Working: ChildWorking,
|
|
@@ -55,7 +57,6 @@ const ChildStates = Machine.state({
|
|
|
55
57
|
Cancelled: { schema: ChildCancelled, type: "final", output: Schema.String }
|
|
56
58
|
}
|
|
57
59
|
})
|
|
58
|
-
|
|
59
60
|
const targets1 = Machine.targets(ChildStates)
|
|
60
61
|
export const requiredParentChildMachine = Machine.make({
|
|
61
62
|
branches: {
|
|
@@ -63,22 +64,23 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
63
64
|
transition3: { destination: { target: targets1.root.Working } }
|
|
64
65
|
},
|
|
65
66
|
effects: {
|
|
66
|
-
source1: (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
) => parent.send(ParentEvents.ChildProgress({ percent: state.progress }))
|
|
67
|
+
source1: ({ parent, state }: {
|
|
68
|
+
readonly parent: Machine.MachineTarget<Machine.Machine.EventInput<ChildProgress | ChildFinished | ChildProblem>>
|
|
69
|
+
readonly state: ChildWorking
|
|
70
|
+
}) => parent.send(ParentEvents.ChildProgress({ percent: state.progress }))
|
|
72
71
|
},
|
|
73
|
-
|
|
74
72
|
id: "required-parent-child",
|
|
75
73
|
root: ChildStates,
|
|
76
74
|
events: ChildEvents,
|
|
77
75
|
internalEvents: ChildInternalEvents,
|
|
78
76
|
emittedEvents: ChildEmissions,
|
|
79
|
-
parent: Machine.parent(ParentEvents)
|
|
80
|
-
initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.decoded(new ChildIdle({}))))
|
|
77
|
+
parent: Machine.parent(ParentEvents)
|
|
81
78
|
}).handle({
|
|
79
|
+
initial: {
|
|
80
|
+
target: Machine.targets(ChildStates).root.Idle,
|
|
81
|
+
decoded: true,
|
|
82
|
+
data: new ChildIdle({})
|
|
83
|
+
},
|
|
82
84
|
states: {
|
|
83
85
|
Idle: {
|
|
84
86
|
on: {
|
|
@@ -100,7 +102,8 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
100
102
|
onDone: { none: true },
|
|
101
103
|
onFailure: {
|
|
102
104
|
target: targets1.root.Cancelled,
|
|
103
|
-
decoded:
|
|
105
|
+
decoded: true,
|
|
106
|
+
data: ({ error }) => (new ChildCancelled({ reason: String(error) }))
|
|
104
107
|
}
|
|
105
108
|
},
|
|
106
109
|
on: {
|
|
@@ -113,11 +116,13 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
113
116
|
},
|
|
114
117
|
CommitChildWork: {
|
|
115
118
|
target: targets1.root.Done,
|
|
116
|
-
decoded:
|
|
119
|
+
decoded: true,
|
|
120
|
+
data: ({ state }) => (new ChildDone({ result: `${state.job}:complete` }))
|
|
117
121
|
},
|
|
118
122
|
CancelChildWork: {
|
|
119
123
|
target: targets1.root.Cancelled,
|
|
120
|
-
decoded:
|
|
124
|
+
decoded: true,
|
|
125
|
+
data: ({ event }) => (new ChildCancelled({ reason: event.reason }))
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
},
|
|
@@ -129,24 +134,26 @@ export const requiredParentChildMachine = Machine.make({
|
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
})
|
|
132
|
-
|
|
133
137
|
const ProtocolChild = Machine.child("protocol-child", requiredParentChildMachine)
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
class ParentIdle extends Schema.TaggedClass<ParentIdle>("ProtocolParentIdle")("Idle", {}) {
|
|
139
|
+
}
|
|
136
140
|
class Supervising extends Schema.TaggedClass<Supervising>("ProtocolSupervising")("Supervising", {
|
|
137
141
|
latestProgress: Schema.Number
|
|
138
|
-
}) {
|
|
142
|
+
}) {
|
|
143
|
+
}
|
|
139
144
|
class ParentComplete extends Schema.TaggedClass<ParentComplete>("ProtocolParentComplete")("Complete", {
|
|
140
145
|
result: Schema.String
|
|
141
|
-
}) {
|
|
146
|
+
}) {
|
|
147
|
+
}
|
|
142
148
|
class ParentFailed extends Schema.TaggedClass<ParentFailed>("ProtocolParentFailed")("Failed", {
|
|
143
149
|
message: Schema.String
|
|
144
|
-
}) {
|
|
145
|
-
|
|
146
|
-
class
|
|
147
|
-
|
|
150
|
+
}) {
|
|
151
|
+
}
|
|
152
|
+
class LaunchChild extends Schema.TaggedClass<LaunchChild>("ProtocolLaunchChild")("LaunchChild", {}) {
|
|
153
|
+
}
|
|
154
|
+
class ResetParent extends Schema.TaggedClass<ResetParent>("ProtocolResetParent")("ResetParent", {}) {
|
|
155
|
+
}
|
|
148
156
|
const ParentStates = Machine.state({
|
|
149
|
-
initial: "Idle",
|
|
150
157
|
states: {
|
|
151
158
|
Idle: ParentIdle,
|
|
152
159
|
Supervising,
|
|
@@ -154,7 +161,6 @@ const ParentStates = Machine.state({
|
|
|
154
161
|
Failed: ParentFailed
|
|
155
162
|
}
|
|
156
163
|
})
|
|
157
|
-
|
|
158
164
|
const targets2 = Machine.targets(ParentStates)
|
|
159
165
|
export const parentProtocolMachine = Machine.make({
|
|
160
166
|
branches: {
|
|
@@ -162,41 +168,56 @@ export const parentProtocolMachine = Machine.make({
|
|
|
162
168
|
transition3: { destination: { target: targets2.root.Complete } }
|
|
163
169
|
},
|
|
164
170
|
children: { source1: ProtocolChild },
|
|
165
|
-
|
|
166
171
|
id: "parent-child-protocol",
|
|
167
172
|
root: ParentStates,
|
|
168
|
-
events: Machine.eventsFromSchemas(LaunchChild, ResetParent, ParentEvents)
|
|
169
|
-
initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.decoded(new ParentIdle({}))))
|
|
173
|
+
events: Machine.eventsFromSchemas(LaunchChild, ResetParent, ParentEvents)
|
|
170
174
|
}).handle({
|
|
175
|
+
initial: {
|
|
176
|
+
target: Machine.targets(ParentStates).root.Idle,
|
|
177
|
+
decoded: true,
|
|
178
|
+
data: new ParentIdle({})
|
|
179
|
+
},
|
|
171
180
|
states: {
|
|
172
181
|
Idle: {
|
|
173
182
|
on: {
|
|
174
|
-
LaunchChild: {
|
|
183
|
+
LaunchChild: {
|
|
184
|
+
target: targets2.root.Supervising,
|
|
185
|
+
decoded: true,
|
|
186
|
+
data: () => (new Supervising({ latestProgress: 0 }))
|
|
187
|
+
}
|
|
175
188
|
}
|
|
176
189
|
},
|
|
177
190
|
Supervising: {
|
|
178
191
|
invoke: {
|
|
179
192
|
src: "source1",
|
|
180
|
-
onDone: {
|
|
193
|
+
onDone: {
|
|
194
|
+
target: targets2.root.Complete,
|
|
195
|
+
decoded: true,
|
|
196
|
+
data: ({ output }) => (new ParentComplete({ result: output }))
|
|
197
|
+
},
|
|
181
198
|
onFailure: {
|
|
182
199
|
target: targets2.root.Failed,
|
|
183
|
-
decoded:
|
|
200
|
+
decoded: true,
|
|
201
|
+
data: ({ error }) => (new ParentFailed({ message: String(error) }))
|
|
184
202
|
}
|
|
185
203
|
},
|
|
186
204
|
on: {
|
|
187
205
|
ChildProgress: {
|
|
188
206
|
target: targets2.root.Supervising,
|
|
189
|
-
decoded:
|
|
207
|
+
decoded: true,
|
|
208
|
+
data: ({ event }) => (new Supervising({ latestProgress: event.percent }))
|
|
190
209
|
},
|
|
191
210
|
ChildFinished: {
|
|
192
211
|
target: targets2.root.Complete,
|
|
193
|
-
decoded:
|
|
212
|
+
decoded: true,
|
|
213
|
+
data: ({ event }) => (new ParentComplete({ result: event.result }))
|
|
194
214
|
},
|
|
195
215
|
ChildProblem: {
|
|
196
216
|
target: targets2.root.Failed,
|
|
197
|
-
decoded:
|
|
217
|
+
decoded: true,
|
|
218
|
+
data: ({ event }) => (new ParentFailed({ message: event.message }))
|
|
198
219
|
},
|
|
199
|
-
ResetParent: { target: targets2.root.Idle, decoded: () => (new ParentIdle({})) }
|
|
220
|
+
ResetParent: { target: targets2.root.Idle, decoded: true, data: () => (new ParentIdle({})) }
|
|
200
221
|
}
|
|
201
222
|
},
|
|
202
223
|
Complete: {
|
|
@@ -204,34 +225,35 @@ export const parentProtocolMachine = Machine.make({
|
|
|
204
225
|
},
|
|
205
226
|
Failed: {
|
|
206
227
|
on: {
|
|
207
|
-
ResetParent: { target: targets2.root.Idle, decoded: () => (new ParentIdle({})) }
|
|
228
|
+
ResetParent: { target: targets2.root.Idle, decoded: true, data: () => (new ParentIdle({})) }
|
|
208
229
|
}
|
|
209
230
|
}
|
|
210
231
|
}
|
|
211
232
|
})
|
|
212
|
-
|
|
213
|
-
|
|
233
|
+
class Detached extends Schema.TaggedClass<Detached>("OptionalParentDetached")("Detached", {}) {
|
|
234
|
+
}
|
|
214
235
|
class Published extends Schema.TaggedClass<Published>("OptionalParentPublished")("Published", {
|
|
215
236
|
deliveredToParent: Schema.Boolean
|
|
216
|
-
}) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
) {
|
|
221
|
-
|
|
222
|
-
const OptionalParentStates = Machine.state({
|
|
223
|
-
|
|
237
|
+
}) {
|
|
238
|
+
}
|
|
239
|
+
class PublishOutside extends Schema.TaggedClass<PublishOutside>("OptionalParentPublishOutside")("PublishOutside", {
|
|
240
|
+
result: Schema.String
|
|
241
|
+
}) {
|
|
242
|
+
}
|
|
243
|
+
const OptionalParentStates = Machine.state({ states: { Detached, Published } })
|
|
224
244
|
const targets3 = Machine.targets(OptionalParentStates)
|
|
225
245
|
export const optionalParentMachine = Machine.make({
|
|
226
246
|
branches: { transition1: { destination: { target: targets3.root.Published } } },
|
|
227
|
-
|
|
228
247
|
id: "optional-parent-protocol",
|
|
229
248
|
root: OptionalParentStates,
|
|
230
249
|
events: Machine.eventsFromSchemas(PublishOutside),
|
|
231
|
-
parent: Machine.optionalParent(ParentEvents)
|
|
232
|
-
initialConfiguration: (root) =>
|
|
233
|
-
root.resolve(({ target }) => target.from((to) => to.Detached.decoded(new Detached({}))))
|
|
250
|
+
parent: Machine.optionalParent(ParentEvents)
|
|
234
251
|
}).handle({
|
|
252
|
+
initial: {
|
|
253
|
+
target: Machine.targets(OptionalParentStates).root.Detached,
|
|
254
|
+
decoded: true,
|
|
255
|
+
data: new Detached({})
|
|
256
|
+
},
|
|
235
257
|
states: {
|
|
236
258
|
Detached: {
|
|
237
259
|
on: {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Machine } from "@typeonce/effect-machine"
|
|
2
2
|
import { Effect, Schema } from "effect"
|
|
3
|
-
|
|
4
3
|
const ReplicationStates = Machine.state({
|
|
5
|
-
initial: "Connecting",
|
|
6
4
|
states: {
|
|
7
5
|
Connecting: {},
|
|
8
6
|
IdentifyingSource: {},
|
|
@@ -19,17 +17,12 @@ const ReplicationStates = Machine.state({
|
|
|
19
17
|
Failed: {}
|
|
20
18
|
}
|
|
21
19
|
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
StopRequested: {}
|
|
28
|
-
})
|
|
29
|
-
)
|
|
30
|
-
|
|
20
|
+
const ReplicationEvents = Machine.eventsFromSchemas(Schema.TaggedUnion({
|
|
21
|
+
Retry: {},
|
|
22
|
+
SessionUnavailable: {},
|
|
23
|
+
StopRequested: {}
|
|
24
|
+
}))
|
|
31
25
|
const operation: Effect.Effect<void, string> = Effect.succeed(undefined)
|
|
32
|
-
|
|
33
26
|
const targets1 = Machine.targets(ReplicationStates)
|
|
34
27
|
export const sharedTerminalRoutingMachine = Machine.make({
|
|
35
28
|
effects: {
|
|
@@ -43,12 +36,13 @@ export const sharedTerminalRoutingMachine = Machine.make({
|
|
|
43
36
|
source8: operation,
|
|
44
37
|
source9: operation
|
|
45
38
|
},
|
|
46
|
-
|
|
47
39
|
id: "shared-terminal-routing",
|
|
48
40
|
root: ReplicationStates,
|
|
49
|
-
events: ReplicationEvents
|
|
50
|
-
initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Connecting.from()))
|
|
41
|
+
events: ReplicationEvents
|
|
51
42
|
}).handle({
|
|
43
|
+
initial: {
|
|
44
|
+
target: Machine.targets(ReplicationStates).root.Connecting
|
|
45
|
+
},
|
|
52
46
|
states: {
|
|
53
47
|
Connecting: {
|
|
54
48
|
invoke: {
|