@typeonce/effect-machine 0.46.0 → 0.47.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/AGENTS.md +1823 -0
- package/CLAUDE.md +1823 -0
- package/README.md +100 -77
- package/ai-docs/README.md +18 -0
- package/ai-docs/src/10_modeling/01_create-a-machine.ts +51 -0
- package/ai-docs/src/10_modeling/02_branch-on-an-event.ts +55 -0
- package/ai-docs/src/10_modeling/03_update-retained-state.ts +58 -0
- package/ai-docs/src/10_modeling/04_verify-after-changing.ts +29 -0
- package/{docs/agent-guide.md → ai-docs/src/10_modeling/index.md} +234 -155
- package/{docs/root-api.md → ai-docs/src/20_root-api/index.md} +29 -57
- package/{docs/effect-atom-react.md → ai-docs/src/30_react/index.md} +42 -49
- package/{docs/machine-review.md → ai-docs/src/40_review/index.md} +42 -40
- package/ai-docs/src/index.md +7 -0
- package/ai-docs/tsconfig.json +22 -0
- package/dist/Machine.d.ts +1195 -1474
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +366 -214
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/command.d.ts +8 -0
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/command.js +2 -2
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +21 -5
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +1 -0
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/construction.js.map +1 -1
- package/dist/internal/machine/declaration.d.ts +2 -1
- package/dist/internal/machine/declaration.d.ts.map +1 -1
- package/dist/internal/machine/declaration.js +28 -46
- package/dist/internal/machine/declaration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +23 -16
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +2 -0
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/implementation.js.map +1 -1
- package/dist/internal/machine/initialDeclaration.d.ts +2 -0
- package/dist/internal/machine/initialDeclaration.d.ts.map +1 -1
- package/dist/internal/machine/initialDeclaration.js +15 -0
- package/dist/internal/machine/initialDeclaration.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +25 -19
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +34 -17
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +16 -4
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +5 -22
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +157 -119
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +15 -4
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +18 -21
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +2 -0
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +2 -0
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.js.map +1 -1
- package/dist/internal/machine/runtimeGeneric.d.ts.map +1 -1
- package/dist/internal/machine/runtimeGeneric.js.map +1 -1
- package/dist/internal/machine/runtimeProtocol.d.ts +26 -0
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
- package/dist/internal/machine/runtimeProtocol.js +71 -0
- package/dist/internal/machine/runtimeProtocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +0 -14
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +9 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +18 -9
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +16 -1
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -1
- package/dist/internal/testing/machine/arbitrary.js +2 -0
- package/dist/internal/testing/machine/arbitrary.js.map +1 -1
- package/dist/internal/testing/machine/check.d.ts +17 -0
- package/dist/internal/testing/machine/check.d.ts.map +1 -0
- package/dist/internal/testing/machine/check.js +371 -0
- package/dist/internal/testing/machine/check.js.map +1 -0
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts +14 -13
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +21 -23
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +19 -88
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +0 -19
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/runtimeInvariant.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +349 -139
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +201 -136
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +9 -14
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +9 -14
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +169 -80
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +165 -76
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +11 -9
- package/src/Machine.ts +1139 -2130
- package/src/internal/machine/atom.ts +3 -3
- package/src/internal/machine/cluster.ts +2 -2
- package/src/internal/machine/command.ts +10 -4
- package/src/internal/machine/configuration.ts +16 -17
- package/src/internal/machine/construction.ts +1 -1
- package/src/internal/machine/declaration.ts +25 -50
- package/src/internal/machine/executionPlan.ts +90 -56
- package/src/internal/machine/implementation.ts +3 -1
- package/src/internal/machine/initialDeclaration.ts +16 -0
- package/src/internal/machine/invocation.ts +38 -44
- package/src/internal/machine/invocationEvent.ts +46 -20
- package/src/internal/machine/machine.ts +217 -243
- package/src/internal/machine/planner.ts +72 -106
- package/src/internal/machine/process.ts +12 -0
- package/src/internal/machine/protocol.ts +6 -6
- package/src/internal/machine/runtime.ts +1 -5
- package/src/internal/machine/runtimeCompiled.ts +2 -2
- package/src/internal/machine/runtimeGeneric.ts +2 -4
- package/src/internal/machine/runtimeProtocol.ts +80 -4
- package/src/internal/machine/stateDefinition.ts +0 -39
- package/src/internal/machine/symbols.ts +11 -0
- package/src/internal/machine/topology.ts +40 -18
- package/src/internal/testing/machine/arbitrary.ts +2 -0
- package/src/internal/testing/machine/check.ts +460 -0
- package/src/internal/testing/machine/exploration.ts +4 -5
- package/src/internal/testing/machine/finiteModel.ts +40 -42
- package/src/internal/testing/machine/runtime.ts +31 -170
- package/src/internal/testing/machine/runtimeInvariant.ts +3 -3
- package/src/internal/testing/machine/verification.ts +14 -14
- package/src/testing/MachineTest.ts +366 -145
- package/src/unstable/cluster/ClusterMachine.ts +9 -14
- package/src/unstable/reactivity/AtomMachine.ts +167 -78
|
@@ -62,32 +62,26 @@ const InvalidCanEventTypeId = "~effect/reactivity/AtomMachine/InvalidCanEvent";
|
|
|
62
62
|
* The derived atom suppresses structurally equal updates. Repeated calls with
|
|
63
63
|
* the same bridge and path return the same atom.
|
|
64
64
|
*
|
|
65
|
-
* **Example**
|
|
65
|
+
* **Example** (Selecting a state value)
|
|
66
66
|
*
|
|
67
|
-
* ```ts
|
|
67
|
+
* ```ts import.meta.vitest
|
|
68
68
|
* import { Machine } from "@typeonce/effect-machine"
|
|
69
69
|
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
70
|
-
* import {
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* })
|
|
74
|
-
* }
|
|
75
|
-
*
|
|
76
|
-
* const machine = Machine.make({
|
|
77
|
-
* root: States,
|
|
78
|
-
* events: Machine.eventsFromSchemas()
|
|
79
|
-
* }).handle({
|
|
80
|
-
* initial: {
|
|
81
|
-
* target: "Count",
|
|
82
|
-
* decoded: true,
|
|
83
|
-
* data: new Count({ value: 0 })
|
|
84
|
-
* },
|
|
85
|
-
* states: {
|
|
86
|
-
* Count: {}
|
|
87
|
-
* }
|
|
70
|
+
* import { AsyncResult, AtomRegistry } from "effect/reactivity"
|
|
71
|
+
* import { Option, Schema } from "effect"
|
|
72
|
+
*
|
|
73
|
+
* const States = Machine.state({ states: { Count: { fields: { value: Schema.Number } } } })
|
|
74
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
75
|
+
* initial: { target: "Count", data: { value: 0 } }
|
|
88
76
|
* })
|
|
89
|
-
*
|
|
90
|
-
* const countAtom = AtomMachine.select(
|
|
77
|
+
*
|
|
78
|
+
* const countAtom = AtomMachine.select(AtomMachine.make(machine), "Count")
|
|
79
|
+
* const registry = AtomRegistry.make()
|
|
80
|
+
* registry.mount(countAtom)
|
|
81
|
+
*
|
|
82
|
+
* const count = AsyncResult.value(registry.get(countAtom)).pipe(Option.flatten, Option.map(({ value }) => value))
|
|
83
|
+
*
|
|
84
|
+
* count // => Option.some(0)
|
|
91
85
|
* ```
|
|
92
86
|
*
|
|
93
87
|
* @category combinators
|
|
@@ -112,11 +106,35 @@ export const selectSnapshot = dual(2, internal.selectSnapshot);
|
|
|
112
106
|
* bridge. An inactive child produces `Option.none()`. Repeated calls with the
|
|
113
107
|
* same child bridge and path return the same atom.
|
|
114
108
|
*
|
|
115
|
-
* **Example**
|
|
109
|
+
* **Example** (Selecting a state value of a child)
|
|
116
110
|
*
|
|
117
|
-
* ```ts
|
|
111
|
+
* ```ts import.meta.vitest
|
|
112
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
113
|
+
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
114
|
+
* import { AtomRegistry } from "effect/reactivity"
|
|
115
|
+
* import { Schema } from "effect"
|
|
116
|
+
*
|
|
117
|
+
* const Editing = Schema.TaggedStruct("Editing", { text: Schema.String })
|
|
118
|
+
* const Editor = Machine.make({
|
|
119
|
+
* root: Machine.state({ states: { Editing } }),
|
|
120
|
+
* events: Machine.events({})
|
|
121
|
+
* }).handle({
|
|
122
|
+
* initial: { target: "Editing", data: { text: "" } }
|
|
123
|
+
* })
|
|
124
|
+
* const EditorChild = Machine.child("editor", Editor)
|
|
125
|
+
* const parent = Machine.make({
|
|
126
|
+
* root: Machine.state({ states: { Open: {} } }),
|
|
127
|
+
* events: Machine.events({}),
|
|
128
|
+
* children: { EditorChild }
|
|
129
|
+
* }).handle({
|
|
130
|
+
* initial: { target: "Open" },
|
|
131
|
+
* states: { Open: { invoke: { src: "EditorChild" } } }
|
|
132
|
+
* })
|
|
133
|
+
*
|
|
134
|
+
* const editorAtom = AtomMachine.make(parent).child(EditorChild)
|
|
118
135
|
* const editingAtom = AtomMachine.selectChild(editorAtom, "Editing")
|
|
119
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* AtomRegistry.make().mount(editingAtom)
|
|
120
138
|
* ```
|
|
121
139
|
*
|
|
122
140
|
* @category combinators
|
|
@@ -144,28 +162,24 @@ export const selectSnapshotChild = dual(2, internal.selectSnapshotChild);
|
|
|
144
162
|
* bridge and path return the same atom. Runtime failures remain in the typed
|
|
145
163
|
* failure channel.
|
|
146
164
|
*
|
|
147
|
-
* **Example**
|
|
165
|
+
* **Example** (Matching the active state)
|
|
148
166
|
*
|
|
149
|
-
* ```ts
|
|
167
|
+
* ```ts import.meta.vitest
|
|
150
168
|
* import { Machine } from "@typeonce/effect-machine"
|
|
151
169
|
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
152
|
-
* import {
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* const States = Machine.state({ states: { Idle } })
|
|
156
|
-
* const machine = Machine.make({
|
|
157
|
-
*
|
|
158
|
-
* events: Machine.eventsFromSchemas()
|
|
159
|
-
* }).handle({
|
|
160
|
-
* initial: {
|
|
161
|
-
* target: "Idle"
|
|
162
|
-
* },
|
|
163
|
-
* states: {
|
|
164
|
-
* Idle: {}
|
|
165
|
-
* }
|
|
170
|
+
* import { AsyncResult, AtomRegistry } from "effect/reactivity"
|
|
171
|
+
* import { Option } from "effect"
|
|
172
|
+
*
|
|
173
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
174
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
175
|
+
* initial: { target: "Idle" }
|
|
166
176
|
* })
|
|
167
|
-
*
|
|
168
|
-
* const isIdleAtom = AtomMachine.matches(
|
|
177
|
+
*
|
|
178
|
+
* const isIdleAtom = AtomMachine.matches(AtomMachine.make(machine), "Idle")
|
|
179
|
+
* const registry = AtomRegistry.make()
|
|
180
|
+
* registry.mount(isIdleAtom)
|
|
181
|
+
*
|
|
182
|
+
* AsyncResult.value(registry.get(isIdleAtom)) // => Option.some(true)
|
|
169
183
|
* ```
|
|
170
184
|
*
|
|
171
185
|
* @category combinators
|
|
@@ -184,15 +198,36 @@ export const matches = dual(2, internal.matches);
|
|
|
184
198
|
* {@link Machine.can}; done and stopped snapshots produce `false`, while
|
|
185
199
|
* runtime and schema failures remain in the typed failure channel.
|
|
186
200
|
*
|
|
187
|
-
* **Example**
|
|
201
|
+
* **Example** (Asking whether a machine accepts an event)
|
|
202
|
+
*
|
|
203
|
+
* ```ts import.meta.vitest
|
|
204
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
205
|
+
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
206
|
+
* import { Atom, AtomRegistry } from "effect/reactivity"
|
|
207
|
+
* import { Schema } from "effect"
|
|
208
|
+
*
|
|
209
|
+
* const Events = Machine.events({ Submitted: { draft: Schema.String } })
|
|
210
|
+
* const machine = Machine.make({
|
|
211
|
+
* root: Machine.state({ states: { Editing: {}, Sent: {} } }),
|
|
212
|
+
* events: Events
|
|
213
|
+
* }).handle({
|
|
214
|
+
* initial: { target: "Editing" },
|
|
215
|
+
* states: {
|
|
216
|
+
* Editing: { on: { Submitted: { target: "Sent", guard: ({ event }) => event.draft.length > 0 } } }
|
|
217
|
+
* }
|
|
218
|
+
* })
|
|
188
219
|
*
|
|
189
|
-
*
|
|
190
|
-
* const
|
|
191
|
-
* const canSubmitAtom = submitAllowed(authMachineAtom)
|
|
220
|
+
* const machineAtom = AtomMachine.make(machine)
|
|
221
|
+
* const canSubmitAtom = AtomMachine.can(Events.Submitted({ draft: "a" }))(machineAtom)
|
|
192
222
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* const
|
|
223
|
+
* // The event can also come from an atom, so acceptance follows its value.
|
|
224
|
+
* const draftAtom = Atom.make("")
|
|
225
|
+
* const submitEvent = Atom.map(draftAtom, (draft) => Events.Submitted({ draft }))
|
|
226
|
+
* const reactiveCanSubmitAtom = AtomMachine.can(submitEvent)(machineAtom)
|
|
227
|
+
*
|
|
228
|
+
* const registry = AtomRegistry.make()
|
|
229
|
+
* registry.mount(canSubmitAtom)
|
|
230
|
+
* registry.mount(reactiveCanSubmitAtom)
|
|
196
231
|
* ```
|
|
197
232
|
*
|
|
198
233
|
* @category combinators
|
|
@@ -221,9 +256,26 @@ const FamilyInputRequiredTypeId = "~effect/reactivity/AtomMachine/FamilyInputReq
|
|
|
221
256
|
* registry runtime mounted. Keys follow Effect `Equal` and `Hash` semantics.
|
|
222
257
|
* The optional `label` function labels each public projected atom.
|
|
223
258
|
*
|
|
224
|
-
* **Example**
|
|
259
|
+
* **Example** (Keeping one machine per key)
|
|
260
|
+
*
|
|
261
|
+
* ```ts import.meta.vitest
|
|
262
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
263
|
+
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
264
|
+
* import { AtomRegistry } from "effect/reactivity"
|
|
265
|
+
* import { Schema } from "effect"
|
|
266
|
+
*
|
|
267
|
+
* const Events = Machine.events({ Finish: {} })
|
|
268
|
+
* const processMachine = Machine.make({
|
|
269
|
+
* root: Machine.state({ states: { Running: {}, Ready: {} } }),
|
|
270
|
+
* events: Events,
|
|
271
|
+
* input: Schema.String
|
|
272
|
+
* }).handle({
|
|
273
|
+
* initial: { target: "Running" },
|
|
274
|
+
* states: {
|
|
275
|
+
* Running: { on: { Finish: { target: "Ready" } } }
|
|
276
|
+
* }
|
|
277
|
+
* })
|
|
225
278
|
*
|
|
226
|
-
* ```ts
|
|
227
279
|
* const processAtoms = AtomMachine.family(processMachine, {
|
|
228
280
|
* atoms: {
|
|
229
281
|
* ready: AtomMachine.matches("Ready"),
|
|
@@ -233,7 +285,8 @@ const FamilyInputRequiredTypeId = "~effect/reactivity/AtomMachine/FamilyInputReq
|
|
|
233
285
|
* })
|
|
234
286
|
*
|
|
235
287
|
* const readyAtom = processAtoms.ready("effect")
|
|
236
|
-
*
|
|
288
|
+
*
|
|
289
|
+
* AtomRegistry.make().mount(readyAtom)
|
|
237
290
|
* ```
|
|
238
291
|
*
|
|
239
292
|
* @category constructors
|
|
@@ -247,12 +300,32 @@ export const family = internal.family;
|
|
|
247
300
|
* Every projected atom retains the resulting child bridge while the projected
|
|
248
301
|
* atom remains reachable. Keys follow Effect `Equal` and `Hash` semantics.
|
|
249
302
|
*
|
|
250
|
-
* **Example**
|
|
303
|
+
* **Example** (Keeping child atoms per key)
|
|
304
|
+
*
|
|
305
|
+
* ```ts import.meta.vitest
|
|
306
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
307
|
+
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
308
|
+
* import { Schema } from "effect"
|
|
251
309
|
*
|
|
252
|
-
*
|
|
310
|
+
* const plantMachine = Machine.make({
|
|
311
|
+
* root: Machine.state({ states: { Growing: {}, Broken: {} } }),
|
|
312
|
+
* events: Machine.events({ Break: {} }),
|
|
313
|
+
* input: Schema.String
|
|
314
|
+
* }).handle({
|
|
315
|
+
* initial: { target: "Growing" },
|
|
316
|
+
* states: {
|
|
317
|
+
* Growing: { on: { Break: { target: "Broken" } } }
|
|
318
|
+
* }
|
|
319
|
+
* })
|
|
253
320
|
* const Plant = Machine.childFamily(plantMachine)
|
|
321
|
+
* const parent = Machine.make({
|
|
322
|
+
* root: Machine.state({ states: { Open: {} } }),
|
|
323
|
+
* events: Machine.events({})
|
|
324
|
+
* }).handle({
|
|
325
|
+
* initial: { target: "Open" }
|
|
326
|
+
* })
|
|
254
327
|
*
|
|
255
|
-
* const plantAtoms = AtomMachine.familyChild(
|
|
328
|
+
* const plantAtoms = AtomMachine.familyChild(AtomMachine.make(parent), {
|
|
256
329
|
* child: (plantId: string) => Plant(plantId),
|
|
257
330
|
* atoms: {
|
|
258
331
|
* broken: AtomMachine.matchesChild("Broken"),
|
|
@@ -260,6 +333,8 @@ export const family = internal.family;
|
|
|
260
333
|
* send: (child) => child.send
|
|
261
334
|
* }
|
|
262
335
|
* })
|
|
336
|
+
*
|
|
337
|
+
* plantAtoms.broken("a")
|
|
263
338
|
* ```
|
|
264
339
|
*
|
|
265
340
|
* @category constructors
|
|
@@ -272,27 +347,26 @@ export const familyChild = internal.familyChild;
|
|
|
272
347
|
* Use `bind(runtime).make(machine)` when the machine requires external
|
|
273
348
|
* services.
|
|
274
349
|
*
|
|
275
|
-
* **Example**
|
|
350
|
+
* **Example** (Owning a machine with an atom)
|
|
276
351
|
*
|
|
277
|
-
* ```ts
|
|
352
|
+
* ```ts import.meta.vitest
|
|
278
353
|
* import { Machine } from "@typeonce/effect-machine"
|
|
279
354
|
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
280
|
-
* import {
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* const States = Machine.state({ states: { Idle } })
|
|
284
|
-
* const machine = Machine.make({
|
|
285
|
-
*
|
|
286
|
-
* events: Machine.eventsFromSchemas()
|
|
287
|
-
* }).handle({
|
|
288
|
-
* initial: {
|
|
289
|
-
* target: "Idle"
|
|
290
|
-
* },
|
|
291
|
-
* states: {
|
|
292
|
-
* Idle: {}
|
|
293
|
-
* }
|
|
355
|
+
* import { AsyncResult, AtomRegistry } from "effect/reactivity"
|
|
356
|
+
* import { Option } from "effect"
|
|
357
|
+
*
|
|
358
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
359
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
360
|
+
* initial: { target: "Idle" }
|
|
294
361
|
* })
|
|
362
|
+
*
|
|
295
363
|
* const machineAtom = AtomMachine.make(machine)
|
|
364
|
+
* const registry = AtomRegistry.make()
|
|
365
|
+
* registry.mount(machineAtom.result)
|
|
366
|
+
*
|
|
367
|
+
* const path = AsyncResult.value(registry.get(machineAtom.result)).pipe(Option.map(({ state }) => state.path))
|
|
368
|
+
*
|
|
369
|
+
* path // => Option.some("Idle")
|
|
296
370
|
* ```
|
|
297
371
|
*
|
|
298
372
|
* @category constructors
|
|
@@ -306,13 +380,28 @@ export const make = internal.make;
|
|
|
306
380
|
* bridge type. Every call creates a fresh `MachineAtom`; it does not cache by
|
|
307
381
|
* input or start the machine before an `AtomRegistry` reads or mounts it.
|
|
308
382
|
*
|
|
309
|
-
* **Example**
|
|
383
|
+
* **Example** (Making machine atoms from input)
|
|
384
|
+
*
|
|
385
|
+
* ```ts import.meta.vitest
|
|
386
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
387
|
+
* import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
388
|
+
* import { Schema } from "effect"
|
|
389
|
+
*
|
|
390
|
+
* const searchMachine = Machine.make({
|
|
391
|
+
* root: Machine.state({ fields: { query: Schema.String } }),
|
|
392
|
+
* events: Machine.events({}),
|
|
393
|
+
* input: Schema.Struct({ query: Schema.String })
|
|
394
|
+
* }).handle({
|
|
395
|
+
* root: ({ input }) => ({ query: input.query })
|
|
396
|
+
* })
|
|
310
397
|
*
|
|
311
|
-
* ```ts
|
|
312
398
|
* const makeSearchMachine = AtomMachine.factory(searchMachine)
|
|
313
399
|
* const search = makeSearchMachine({ query: "effect" })
|
|
314
400
|
*
|
|
315
401
|
* type SearchMachineAtom = ReturnType<typeof makeSearchMachine>
|
|
402
|
+
* const typed: SearchMachineAtom = search
|
|
403
|
+
*
|
|
404
|
+
* typed === search // => true
|
|
316
405
|
* ```
|
|
317
406
|
*
|
|
318
407
|
* @category constructors
|
|
@@ -323,8 +412,8 @@ export const factory = internal.factory;
|
|
|
323
412
|
* Creates a lazy atom bridge from a decoded logical snapshot.
|
|
324
413
|
*
|
|
325
414
|
* The bridge owns one freshly resumed runtime per `AtomRegistry`, with the same
|
|
326
|
-
* lazy start and disposal semantics as {@link make}. The machine
|
|
327
|
-
*
|
|
415
|
+
* lazy start and disposal semantics as {@link make}. The machine's declared
|
|
416
|
+
* initial state and its input, errors, and services are not involved.
|
|
328
417
|
*
|
|
329
418
|
* @category constructors
|
|
330
419
|
* @since 0.4.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomMachine.js","sourceRoot":"","sources":["../../../src/unstable/reactivity/AtomMachine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAMtC,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAA;AAS1D;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CA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;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,WAAW,GAeqC,QAAQ,CAAC,WAAkB,CAAA;AAExF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,IAAI,GAqDb,QAAQ,CAAC,IAAI,CAAA;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,OAAO,GAM+C,QAAQ,CAAC,OAAO,CAAA;AAEnF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GASf,QAAQ,CAAC,MAAM,CAAA;AAEnB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,IAAI,GAEoB,QAAQ,CAAC,IAAI,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typeonce/effect-machine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"description": "Schema-first state machines and statecharts for Effect",
|
|
5
5
|
"author": "Sandro Maglione",
|
|
6
6
|
"repository": {
|
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/typeonce-dev/effect-machine/issues"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://effect-machine.typeonce.dev",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"files": [
|
|
18
18
|
"src/**/*.ts",
|
|
19
19
|
"dist",
|
|
20
|
-
"
|
|
20
|
+
"AGENTS.md",
|
|
21
|
+
"CLAUDE.md",
|
|
22
|
+
"ai-docs/**/*",
|
|
21
23
|
"README.md",
|
|
22
24
|
"LICENSE",
|
|
23
25
|
"NOTICE"
|
|
@@ -49,13 +51,13 @@
|
|
|
49
51
|
"effect": "^4.0.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@effect/vitest": "4.
|
|
53
|
-
"@types/node": "
|
|
54
|
-
"effect": "4.
|
|
55
|
-
"tinybench": "2.
|
|
56
|
-
"tstyche": "7.2.
|
|
54
|
+
"@effect/vitest": "4.1.1",
|
|
55
|
+
"@types/node": "26.6.6",
|
|
56
|
+
"effect": "4.1.1",
|
|
57
|
+
"tinybench": "6.2.2",
|
|
58
|
+
"tstyche": "7.2.5",
|
|
57
59
|
"typescript": "6.0.3",
|
|
58
|
-
"vitest": "5.0.
|
|
60
|
+
"vitest": "5.0.5"
|
|
59
61
|
},
|
|
60
62
|
"engines": {
|
|
61
63
|
"node": ">=20"
|