@typeonce/effect-machine-devtools 0.31.2 → 0.33.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/dist/MachineRegistry.d.ts +4 -3
- package/dist/MachineRegistry.d.ts.map +1 -1
- package/dist/MachineRegistry.js +4 -3
- package/dist/MachineRegistry.js.map +1 -1
- package/dist/client/assets/index-2uvShdlX.js +37 -0
- package/dist/client/index.html +1 -1
- package/dist/internal/devServer.d.ts +3 -1
- package/dist/internal/devServer.d.ts.map +1 -1
- package/dist/internal/devServer.js +8 -6
- package/dist/internal/devServer.js.map +1 -1
- package/dist/internal/machineRegistry.js +9 -6
- package/dist/internal/machineRegistry.js.map +1 -1
- package/package.json +2 -2
- package/src/MachineRegistry.ts +4 -3
- package/src/internal/browser/chart-layout-policy.ts +2 -2
- package/src/internal/browser/chart-layout.ts +236 -51
- package/src/internal/browser/chart-model.ts +3 -0
- package/src/internal/browser/chart-renderer.ts +5 -4
- package/src/internal/browser/example-machine.ts +94 -85
- package/src/internal/browser/hierarchy-routing-example.ts +67 -58
- package/src/internal/browser/invoke-outcomes-example.ts +153 -143
- package/src/internal/browser/layout-resilience-example.ts +115 -104
- package/src/internal/browser/parallel-completion-example.ts +117 -107
- package/src/internal/browser/parallel-owner-routing-example.ts +104 -0
- package/src/internal/browser/planner-example.ts +44 -38
- package/src/internal/browser/protocol-events-example.ts +123 -102
- package/src/internal/browser/shared-terminal-routing-example.ts +125 -120
- package/src/internal/browser/text-tree.ts +2 -2
- package/src/internal/browser/transition-semantics-example.ts +143 -131
- package/src/internal/browser/visualizer-model.ts +7 -7
- package/src/internal/devServer.ts +15 -12
- package/src/internal/machineRegistry.ts +17 -17
- package/dist/client/assets/index-CSgOYHLh.js +0 -37
|
@@ -62,40 +62,43 @@ class CancelOrder extends Schema.TaggedClass<CancelOrder>("ParallelCancelOrder")
|
|
|
62
62
|
class RetryOrder extends Schema.TaggedClass<RetryOrder>("ParallelRetryOrder")("RetryOrder", {}) {}
|
|
63
63
|
class AutoShip extends Schema.TaggedClass<AutoShip>("ParallelAutoShip")("AutoShip", {}) {}
|
|
64
64
|
|
|
65
|
-
const ParallelInternalEvents = Machine.
|
|
66
|
-
const ParallelStates = Machine.
|
|
67
|
-
Cart,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
AwaitingAuthorization,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
WaitingForPayment,
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
const ParallelInternalEvents = Machine.internalEventsFromSchemas(AutoShip)
|
|
66
|
+
const ParallelStates = Machine.state({
|
|
67
|
+
initial: "Cart",
|
|
68
|
+
states: {
|
|
69
|
+
Cart,
|
|
70
|
+
Order: {
|
|
71
|
+
schema: Order,
|
|
72
|
+
type: "parallel",
|
|
73
|
+
states: {
|
|
74
|
+
payment: {
|
|
75
|
+
schema: Payment,
|
|
76
|
+
initial: "AwaitingAuthorization",
|
|
77
|
+
states: {
|
|
78
|
+
AwaitingAuthorization,
|
|
79
|
+
Authorized: { schema: Authorized, type: "final" }
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
fulfillment: {
|
|
83
|
+
schema: Fulfillment,
|
|
84
|
+
initial: "WaitingForPayment",
|
|
85
|
+
states: {
|
|
86
|
+
WaitingForPayment,
|
|
87
|
+
Packing,
|
|
88
|
+
Shipped: { schema: Shipped, type: "final" }
|
|
89
|
+
}
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
},
|
|
93
|
+
Complete: { schema: OrderComplete, type: "final", output: Schema.String },
|
|
94
|
+
Cancelled: OrderCancelled
|
|
95
|
+
}
|
|
93
96
|
})
|
|
94
97
|
|
|
95
98
|
export const parallelCompletionMachine = Machine.make({
|
|
96
99
|
id: "parallel-completion",
|
|
97
|
-
|
|
98
|
-
events: Machine.
|
|
100
|
+
root: ParallelStates,
|
|
101
|
+
events: Machine.eventsFromSchemas(
|
|
99
102
|
Checkout,
|
|
100
103
|
Authorize,
|
|
101
104
|
DeclinePayment,
|
|
@@ -106,94 +109,101 @@ export const parallelCompletionMachine = Machine.make({
|
|
|
106
109
|
RetryOrder
|
|
107
110
|
),
|
|
108
111
|
internalEvents: ParallelInternalEvents,
|
|
109
|
-
|
|
112
|
+
initialConfiguration: (root) =>
|
|
113
|
+
root.resolve(({ target }) => target.from((to) => to.Cart.decoded(new Cart({ items: 2 }))))
|
|
110
114
|
}).handle({
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
to
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Order: {
|
|
120
|
-
initialize: ({ builder }) => builder.payment.from({ attempts: 0 }).fulfillment.from({ warehouse: "north" }),
|
|
121
|
-
on: {
|
|
122
|
-
CancelOrder: (to) =>
|
|
123
|
-
to.full.Cancelled().resolve(({ event, target }) => target.decoded(new OrderCancelled({ reason: event.reason })))
|
|
115
|
+
states: {
|
|
116
|
+
Cart: {
|
|
117
|
+
on: {
|
|
118
|
+
Checkout: (to) =>
|
|
119
|
+
to.branch.Order.initial.resolve(({ event, target }) =>
|
|
120
|
+
target.decoded(new Order({ orderId: event.orderId, total: event.total }))
|
|
121
|
+
)
|
|
122
|
+
}
|
|
124
123
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
on: {
|
|
133
|
-
Authorize: (to) =>
|
|
134
|
-
to.local.Authorized().resolve(({ event, target }) =>
|
|
135
|
-
target.decoded(new Authorized({ authorizationId: event.authorizationId }))
|
|
136
|
-
),
|
|
137
|
-
CompleteAll: (to) =>
|
|
138
|
-
to.local.Authorized().resolve(({ event, target }) =>
|
|
139
|
-
target.decoded(new Authorized({ authorizationId: event.authorizationId }))
|
|
140
|
-
),
|
|
141
|
-
DeclinePayment: (to) =>
|
|
142
|
-
to.full.Cancelled().resolve(({ event, target }) =>
|
|
143
|
-
target.decoded(new OrderCancelled({ reason: event.reason }))
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
124
|
+
Order: {
|
|
125
|
+
initialize: ({ builder }) => builder.payment.from({ attempts: 0 }).fulfillment.from({ warehouse: "north" }),
|
|
126
|
+
on: {
|
|
127
|
+
CancelOrder: (to) =>
|
|
128
|
+
to.branch.Cancelled().resolve(({ event, target }) =>
|
|
129
|
+
target.decoded(new OrderCancelled({ reason: event.reason }))
|
|
130
|
+
)
|
|
148
131
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
to
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
to
|
|
162
|
-
|
|
163
|
-
|
|
132
|
+
onDone: (to) =>
|
|
133
|
+
to.branch.Complete().resolve(({ target }) => target.decoded(new OrderComplete({ orderId: "completed-order" }))),
|
|
134
|
+
states: {
|
|
135
|
+
payment: {
|
|
136
|
+
initialize: ({ builder }) => builder.from(),
|
|
137
|
+
states: {
|
|
138
|
+
AwaitingAuthorization: {
|
|
139
|
+
on: {
|
|
140
|
+
Authorize: (to) =>
|
|
141
|
+
to.local.Authorized().resolve(({ event, target }) =>
|
|
142
|
+
target.decoded(new Authorized({ authorizationId: event.authorizationId }))
|
|
143
|
+
),
|
|
144
|
+
CompleteAll: (to) =>
|
|
145
|
+
to.local.Authorized().resolve(({ event, target }) =>
|
|
146
|
+
target.decoded(new Authorized({ authorizationId: event.authorizationId }))
|
|
147
|
+
),
|
|
148
|
+
DeclinePayment: (to) =>
|
|
149
|
+
to.branch.Cancelled().resolve(({ event, target }) =>
|
|
150
|
+
target.decoded(new OrderCancelled({ reason: event.reason }))
|
|
151
|
+
)
|
|
152
|
+
}
|
|
164
153
|
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
fulfillment: {
|
|
157
|
+
initialize: ({ builder }) => builder.from(),
|
|
158
|
+
states: {
|
|
159
|
+
WaitingForPayment: {
|
|
160
|
+
on: {
|
|
161
|
+
Authorize: (to) =>
|
|
162
|
+
to.local.Packing().resolve(({ target }) => target.decoded(new Packing({ packageCount: 1 }))),
|
|
163
|
+
Pack: (to) =>
|
|
164
|
+
to.local.Packing().resolve(({ event, target }) =>
|
|
165
|
+
target.decoded(new Packing({ packageCount: event.packages }))
|
|
166
|
+
),
|
|
167
|
+
CompleteAll: (to) =>
|
|
168
|
+
to.local.Shipped().resolve(({ event, target }) =>
|
|
169
|
+
target.decoded(new Shipped({ trackingCode: event.trackingCode }))
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
Packing: {
|
|
174
|
+
invoke: (from) =>
|
|
175
|
+
from.timer("packing-sla", "5 seconds").onDone((to) =>
|
|
176
|
+
to.none.resolve((_, enqueue) => {
|
|
177
|
+
enqueue.raise(ParallelInternalEvents.AutoShip())
|
|
178
|
+
})
|
|
179
179
|
),
|
|
180
|
-
|
|
181
|
-
to
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
on: {
|
|
181
|
+
AutoShip: (to) =>
|
|
182
|
+
to.local.Shipped().resolve(({ target }) =>
|
|
183
|
+
target.decoded(new Shipped({ trackingCode: "automatic" }))
|
|
184
|
+
),
|
|
185
|
+
Ship: (to) =>
|
|
186
|
+
to.local.Shipped().resolve(({ event, target }) =>
|
|
187
|
+
target.decoded(new Shipped({ trackingCode: event.trackingCode }))
|
|
188
|
+
),
|
|
189
|
+
CompleteAll: (to) =>
|
|
190
|
+
to.local.Shipped().resolve(({ event, target }) =>
|
|
191
|
+
target.decoded(new Shipped({ trackingCode: event.trackingCode }))
|
|
192
|
+
)
|
|
193
|
+
}
|
|
184
194
|
}
|
|
185
195
|
}
|
|
186
196
|
}
|
|
187
197
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
198
|
+
},
|
|
199
|
+
Complete: {
|
|
200
|
+
output: ({ state }) => state.orderId
|
|
201
|
+
},
|
|
202
|
+
Cancelled: {
|
|
203
|
+
on: {
|
|
204
|
+
RetryOrder: (to) =>
|
|
205
|
+
to.branch.Order.initial.resolve(({ target }) => target.decoded(new Order({ orderId: "retry", total: 0 })))
|
|
206
|
+
}
|
|
197
207
|
}
|
|
198
208
|
}
|
|
199
209
|
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Machine } from "@typeonce/effect-machine"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
|
|
4
|
+
class Print extends Schema.TaggedClass<Print>("ParallelOwnerPrint")("Print", {}) {}
|
|
5
|
+
class Options extends Schema.TaggedClass<Options>("ParallelOwnerOptions")("Options", {}) {}
|
|
6
|
+
class OptionsReady extends Schema.TaggedClass<OptionsReady>("ParallelOwnerOptionsReady")("Ready", {}) {}
|
|
7
|
+
class Operation extends Schema.TaggedClass<Operation>("ParallelOwnerOperation")("Operation", {}) {}
|
|
8
|
+
class Active extends Schema.TaggedClass<Active>("ParallelOwnerActive")("Active", {}) {}
|
|
9
|
+
class Printing extends Schema.TaggedClass<Printing>("ParallelOwnerPrinting")("Printing", {}) {}
|
|
10
|
+
class ChildIdle extends Schema.TaggedClass<ChildIdle>("ParallelOwnerChildIdle")("Idle", {}) {}
|
|
11
|
+
class ChildSignal extends Schema.TaggedClass<ChildSignal>("ParallelOwnerChildSignal")("ChildSignal", {}) {}
|
|
12
|
+
class PrintRequested extends Schema.TaggedClass<PrintRequested>("ParallelOwnerPrintRequested")(
|
|
13
|
+
"PrintRequested",
|
|
14
|
+
{}
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
const ChildParentEvents = Machine.eventsFromSchemas(ChildSignal)
|
|
18
|
+
const ParallelOwnerChildStates = Machine.state({ initial: "Idle", states: { Idle: ChildIdle } })
|
|
19
|
+
|
|
20
|
+
export const parallelOwnerRoutingChildMachine = Machine.make({
|
|
21
|
+
id: "parallel-owner-routing-child",
|
|
22
|
+
root: ParallelOwnerChildStates,
|
|
23
|
+
events: Machine.eventsFromSchemas(),
|
|
24
|
+
parent: Machine.parent(ChildParentEvents),
|
|
25
|
+
initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.decoded(new ChildIdle({}))))
|
|
26
|
+
}).handle({
|
|
27
|
+
states: {
|
|
28
|
+
Idle: {
|
|
29
|
+
invoke: (from) =>
|
|
30
|
+
from.effect(
|
|
31
|
+
"signal-parent",
|
|
32
|
+
({ parent }) => parent.send(ChildParentEvents.ChildSignal())
|
|
33
|
+
).onDone((to) => to.none).onFailure((to) => to.none)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const ParallelOwnerChild = Machine.child("parallel-owner-child", parallelOwnerRoutingChildMachine)
|
|
39
|
+
|
|
40
|
+
const ParallelOwnerStates = Machine.state({
|
|
41
|
+
initial: "Print",
|
|
42
|
+
states: {
|
|
43
|
+
Print: {
|
|
44
|
+
schema: Print,
|
|
45
|
+
type: "parallel",
|
|
46
|
+
states: {
|
|
47
|
+
Options: {
|
|
48
|
+
schema: Options,
|
|
49
|
+
initial: "Ready",
|
|
50
|
+
states: {
|
|
51
|
+
Ready: OptionsReady
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
Operation: {
|
|
55
|
+
schema: Operation,
|
|
56
|
+
initial: "Active",
|
|
57
|
+
states: {
|
|
58
|
+
Active,
|
|
59
|
+
Printing
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
export const parallelOwnerRoutingMachine = Machine.make({
|
|
68
|
+
id: "parallel-owner-routing",
|
|
69
|
+
root: ParallelOwnerStates,
|
|
70
|
+
events: Machine.eventsFromSchemas(PrintRequested, ChildParentEvents),
|
|
71
|
+
initialConfiguration: (root) =>
|
|
72
|
+
root.resolve(({ target }) =>
|
|
73
|
+
target.from((to) =>
|
|
74
|
+
to.Print.decoded(
|
|
75
|
+
new Print({}),
|
|
76
|
+
(print) =>
|
|
77
|
+
print.Options.decoded(new Options({}), (options) => options.Ready.decoded(new OptionsReady({}))).Operation
|
|
78
|
+
.decoded(new Operation({}), (operation) => operation.Active.decoded(new Active({})))
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
}).handle({
|
|
83
|
+
states: {
|
|
84
|
+
Print: {
|
|
85
|
+
initialize: ({ builder }) => builder.Options.from({}).Operation.from({}),
|
|
86
|
+
invoke: (from) =>
|
|
87
|
+
from.child(ParallelOwnerChild).onFailure((to) =>
|
|
88
|
+
to.branch.Print.Operation.Active().resolve(({ target }) => target.decoded(new Active({})))
|
|
89
|
+
),
|
|
90
|
+
on: {
|
|
91
|
+
PrintRequested: (to) =>
|
|
92
|
+
to.branch.Print.Operation.Printing().resolve(({ target }) => target.decoded(new Printing({})))
|
|
93
|
+
},
|
|
94
|
+
states: {
|
|
95
|
+
Options: {
|
|
96
|
+
initialize: ({ builder }) => builder.from({})
|
|
97
|
+
},
|
|
98
|
+
Operation: {
|
|
99
|
+
initialize: ({ builder }) => builder.from({})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})
|
|
@@ -64,18 +64,21 @@ class Cancel extends Schema.TaggedClass<Cancel>("PlannerCancel")("Cancel", { rea
|
|
|
64
64
|
class AutoFinish extends Schema.TaggedClass<AutoFinish>("PlannerAutoFinish")("AutoFinish", {}) {}
|
|
65
65
|
class Planned extends Schema.TaggedClass<Planned>("PlannerPlanned")("Planned", { job: Schema.String }) {}
|
|
66
66
|
|
|
67
|
-
const Events = Machine.
|
|
68
|
-
const InternalEvents = Machine.
|
|
69
|
-
const Emissions = Machine.
|
|
70
|
-
const States = Machine.
|
|
71
|
-
Idle,
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const Events = Machine.eventsFromSchemas(Begin, Cancel)
|
|
68
|
+
const InternalEvents = Machine.internalEventsFromSchemas(AutoFinish)
|
|
69
|
+
const Emissions = Machine.emittedEventsFromSchemas(Planned)
|
|
70
|
+
const States = Machine.state({
|
|
71
|
+
initial: "Idle",
|
|
72
|
+
states: {
|
|
73
|
+
Idle,
|
|
74
|
+
Working,
|
|
75
|
+
Finished: { schema: Finished, type: "final", output: Schema.String }
|
|
76
|
+
}
|
|
74
77
|
})
|
|
75
78
|
|
|
76
79
|
export const plannerMachine = Machine.make({
|
|
77
80
|
id: "planner-example",
|
|
78
|
-
|
|
81
|
+
root: States,
|
|
79
82
|
events: Events,
|
|
80
83
|
internalEvents: InternalEvents,
|
|
81
84
|
emittedEvents: Emissions,
|
|
@@ -109,37 +112,40 @@ export const plannerMachine = Machine.make({
|
|
|
109
112
|
})
|
|
110
113
|
)
|
|
111
114
|
}),
|
|
112
|
-
|
|
115
|
+
initialConfiguration: (root) =>
|
|
116
|
+
root.resolve(({ input, target }) => target.from((to) => to.Idle.decoded(new Idle({ owner: input.owner }))))
|
|
113
117
|
}).handle({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
to
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
to
|
|
136
|
-
|
|
137
|
-
to
|
|
138
|
-
|
|
139
|
-
|
|
118
|
+
states: {
|
|
119
|
+
Idle: {
|
|
120
|
+
on: {
|
|
121
|
+
Begin: (to) =>
|
|
122
|
+
to.branches({
|
|
123
|
+
urgent: { title: "Finish immediately", target: to.branch.Working() },
|
|
124
|
+
normal: { title: "Wait in working", target: to.branch.Working() }
|
|
125
|
+
}).resolve(({ event, self, select, state }, enqueue) => {
|
|
126
|
+
enqueue.emit(new Planned({ job: event.job }))
|
|
127
|
+
enqueue.sendTo(self, Events.Cancel({ reason: "planner command example" }))
|
|
128
|
+
if (event.priority === "urgent") enqueue.raise(InternalEvents.AutoFinish())
|
|
129
|
+
const working = new Working({ owner: state.owner, job: event.job })
|
|
130
|
+
return event.priority === "urgent"
|
|
131
|
+
? select.urgent.decoded(working)
|
|
132
|
+
: select.normal.decoded(working)
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
Working: {
|
|
137
|
+
invoke: (from) => from.effect("monitor-job", () => Effect.never),
|
|
138
|
+
on: {
|
|
139
|
+
AutoFinish: (to) =>
|
|
140
|
+
to.branch.Finished().resolve(({ state, target }) => target.decoded(new Finished({ job: state.job }))),
|
|
141
|
+
Cancel: (to) =>
|
|
142
|
+
to.branch.Idle().resolve(({ event, state, target }) =>
|
|
143
|
+
target.decoded(new Idle({ owner: `${state.owner} · ${event.reason}` }))
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
Finished: {
|
|
148
|
+
output: ({ state }) => state.job
|
|
140
149
|
}
|
|
141
|
-
},
|
|
142
|
-
Finished: {
|
|
143
|
-
output: ({ state }) => state.job
|
|
144
150
|
}
|
|
145
151
|
})
|