@typeonce/effect-machine 0.1.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/LICENSE +21 -0
- package/NOTICE +5 -0
- package/README.md +117 -0
- package/dist/AtomMachine.d.ts +141 -0
- package/dist/AtomMachine.d.ts.map +1 -0
- package/dist/AtomMachine.js +191 -0
- package/dist/AtomMachine.js.map +1 -0
- package/dist/ClusterMachine.d.ts +250 -0
- package/dist/ClusterMachine.d.ts.map +1 -0
- package/dist/ClusterMachine.js +280 -0
- package/dist/ClusterMachine.js.map +1 -0
- package/dist/Machine.d.ts +2587 -0
- package/dist/Machine.d.ts.map +1 -0
- package/dist/Machine.js +923 -0
- package/dist/Machine.js.map +1 -0
- package/dist/cluster.d.ts +2 -0
- package/dist/cluster.d.ts.map +1 -0
- package/dist/cluster.js +2 -0
- package/dist/cluster.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/machineErrors.d.ts +109 -0
- package/dist/internal/machineErrors.d.ts.map +1 -0
- package/dist/internal/machineErrors.js +65 -0
- package/dist/internal/machineErrors.js.map +1 -0
- package/dist/internal/machineModel.d.ts +88 -0
- package/dist/internal/machineModel.d.ts.map +1 -0
- package/dist/internal/machineModel.js +713 -0
- package/dist/internal/machineModel.js.map +1 -0
- package/dist/internal/machinePlanner.d.ts +64 -0
- package/dist/internal/machinePlanner.d.ts.map +1 -0
- package/dist/internal/machinePlanner.js +594 -0
- package/dist/internal/machinePlanner.js.map +1 -0
- package/dist/internal/machineProcess.d.ts +16 -0
- package/dist/internal/machineProcess.d.ts.map +1 -0
- package/dist/internal/machineProcess.js +170 -0
- package/dist/internal/machineProcess.js.map +1 -0
- package/dist/internal/machineRuntime.d.ts +119 -0
- package/dist/internal/machineRuntime.d.ts.map +1 -0
- package/dist/internal/machineRuntime.js +354 -0
- package/dist/internal/machineRuntime.js.map +1 -0
- package/dist/reactivity.d.ts +2 -0
- package/dist/reactivity.d.ts.map +1 -0
- package/dist/reactivity.js +2 -0
- package/dist/reactivity.js.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sandro Maglione
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @typeonce/effect-machine
|
|
2
|
+
|
|
3
|
+
External home for the schema-first Machine API proposed in
|
|
4
|
+
[Effect PR #6429](https://github.com/Effect-TS/effect/pull/6429). During
|
|
5
|
+
incubation this repository is the canonical implementation; the synchronization
|
|
6
|
+
tool keeps the Effect PR mechanically aligned without a second logic
|
|
7
|
+
implementation.
|
|
8
|
+
|
|
9
|
+
> Early-release software: APIs may change, and releases are coupled to an exact
|
|
10
|
+
> Effect beta.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add @typeonce/effect-machine effect@4.0.0-beta.102
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`effect` is an exact peer dependency, not a bundled runtime dependency. Consumers
|
|
19
|
+
must install `effect@4.0.0-beta.102`. Upgrading this package may require upgrading
|
|
20
|
+
Effect in lockstep; do not override the peer to another beta.
|
|
21
|
+
|
|
22
|
+
## Entrypoints
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Machine } from "@typeonce/effect-machine"
|
|
26
|
+
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
|
|
27
|
+
import { ClusterMachine } from "@typeonce/effect-machine/cluster"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Each ESM entrypoint is independent and tree-shakeable. Importing the root does
|
|
31
|
+
not load the reactivity or cluster adapters.
|
|
32
|
+
|
|
33
|
+
## Basic machine
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { Effect, Schema } from "effect"
|
|
37
|
+
import { Machine } from "@typeonce/effect-machine"
|
|
38
|
+
|
|
39
|
+
class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
40
|
+
class Running extends Schema.TaggedClass<Running>("Running")("Running", {}) {}
|
|
41
|
+
class Start extends Schema.TaggedClass<Start>("Start")("Start", {}) {}
|
|
42
|
+
|
|
43
|
+
const states = Machine.defineStates({ Idle, Running })
|
|
44
|
+
|
|
45
|
+
const Counter = Machine.make({
|
|
46
|
+
id: "Counter",
|
|
47
|
+
states: states.states,
|
|
48
|
+
events: [Start],
|
|
49
|
+
initial: states.initial.Idle(new Idle())
|
|
50
|
+
}).handle({
|
|
51
|
+
Idle: {
|
|
52
|
+
on: {
|
|
53
|
+
Start: ({ target }) => Effect.succeed(target.full.Running(new Running()))
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The exported namespaces preserve the API, type identifiers, service keys,
|
|
60
|
+
semantics, and documentation of the Effect proposal.
|
|
61
|
+
|
|
62
|
+
## Development and validation
|
|
63
|
+
|
|
64
|
+
Use pnpm 10 and Node.js 20 or newer:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
pnpm install --frozen-lockfile
|
|
68
|
+
pnpm check
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Individual commands are available for `build`, `test`, `test:types`,
|
|
72
|
+
`typecheck`, `format:check`, `test:consumer`, `test:sync`, `sync:check`, and
|
|
73
|
+
`pack:check`. Runtime tests use `@effect/vitest`; type tests use TSTyche and
|
|
74
|
+
TypeScript 6.0.3.
|
|
75
|
+
|
|
76
|
+
## Synchronizing Effect PR #6429
|
|
77
|
+
|
|
78
|
+
Make logic changes here first and run `pnpm check`. Then generate the mapped
|
|
79
|
+
production files, runtime tests, and type tests into a writable Effect checkout:
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
pnpm sync:effect -- /path/to/effect
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The explicit mapping covers only the eight production files and six test files.
|
|
86
|
+
It rewrites package imports to Effect repository-relative `.ts` imports and
|
|
87
|
+
restores Effect's private `PipeInspectableProto` boundary. It never copies
|
|
88
|
+
package metadata, documentation, release files, or changesets.
|
|
89
|
+
|
|
90
|
+
Check an existing checkout without writing:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
pnpm sync:effect -- --check /path/to/effect
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Check mode exits non-zero on any drift. `pnpm test:sync` exercises generation,
|
|
97
|
+
a clean check, and drift detection in a disposable temporary directory. Never
|
|
98
|
+
generate into a checkout with work you have not reviewed. After generation,
|
|
99
|
+
inspect the Effect diff and run its targeted machine, reactivity, cluster, and
|
|
100
|
+
type-test validations followed by `pnpm check`.
|
|
101
|
+
|
|
102
|
+
The current source reference is branch `sandro/state-charts` in the Effect
|
|
103
|
+
repository. Exact dependency pins and the sync check are the proof boundary;
|
|
104
|
+
vendoring the rest of Effect is intentionally unnecessary.
|
|
105
|
+
|
|
106
|
+
## Releases
|
|
107
|
+
|
|
108
|
+
Add a changeset with `pnpm changeset`. CI validates frozen installation and the
|
|
109
|
+
complete check suite. The release workflow opens version PRs and publishes with
|
|
110
|
+
npm provenance through GitHub Actions.
|
|
111
|
+
|
|
112
|
+
Before the first release, create the `typeonce-dev/effect-machine` GitHub
|
|
113
|
+
repository and configure npm trusted publishing for the repository and
|
|
114
|
+
`.github/workflows/release.yml` environment. No npm token is intended.
|
|
115
|
+
|
|
116
|
+
When equivalent Machine modules ship in Effect, this package is intended to
|
|
117
|
+
become a thin compatibility re-export package before eventual retirement.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atom bridge for running machines.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import type * as Schema from "effect/Schema";
|
|
8
|
+
import type * as Scope from "effect/Scope";
|
|
9
|
+
import * as Machine from "./Machine.js";
|
|
10
|
+
import { AsyncResult, Atom, type AtomRegistry } from "effect/unstable/reactivity";
|
|
11
|
+
declare const NotReadyError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
12
|
+
readonly _tag: "NotReadyError";
|
|
13
|
+
} & Readonly<A>;
|
|
14
|
+
/**
|
|
15
|
+
* Error returned when a machine command is issued before startup completes.
|
|
16
|
+
*
|
|
17
|
+
* @category errors
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
export declare class NotReadyError extends NotReadyError_base {
|
|
21
|
+
}
|
|
22
|
+
declare const ChildNotActiveError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
23
|
+
readonly _tag: "ChildNotActiveError";
|
|
24
|
+
} & Readonly<A>;
|
|
25
|
+
/**
|
|
26
|
+
* Error returned when a command targets a child machine that is not active.
|
|
27
|
+
*
|
|
28
|
+
* @category errors
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
export declare class ChildNotActiveError extends ChildNotActiveError_base<{
|
|
32
|
+
readonly id: string;
|
|
33
|
+
}> {
|
|
34
|
+
}
|
|
35
|
+
type AtomSupportedRequirements = Scope.Scope | AtomRegistry.AtomRegistry;
|
|
36
|
+
type ExternalRequirements<Requirements> = Exclude<Requirements, AtomSupportedRequirements>;
|
|
37
|
+
declare const ExternalRequirementsTypeId = "~effect/reactivity/AtomMachine/ExternalRequirements";
|
|
38
|
+
type EnsureNoExternalRequirements<Requirements> = [ExternalRequirements<Requirements>] extends [never] ? unknown : {
|
|
39
|
+
readonly [ExternalRequirementsTypeId]: ExternalRequirements<Requirements>;
|
|
40
|
+
};
|
|
41
|
+
type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
42
|
+
type ExcludeCompatibleMachineRuntime<Requirements, Events, Emits> = Requirements extends Machine.Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? Requirements : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : Requirements;
|
|
43
|
+
type MachineRequirements<InitialR, R, Events, Emits> = ExcludeCompatibleMachineRuntime<Machine.ExecutionServices<InitialR | R>, Events, Emits>;
|
|
44
|
+
/**
|
|
45
|
+
* Atoms backed by one running machine instance in an `AtomRegistry`.
|
|
46
|
+
*
|
|
47
|
+
* **Details**
|
|
48
|
+
*
|
|
49
|
+
* The machine starts when one of the returned atoms is mounted or read in
|
|
50
|
+
* a registry, and it is stopped when the registry disposes the ref atom. The
|
|
51
|
+
* same atom values share one running machine per registry.
|
|
52
|
+
*
|
|
53
|
+
* @category models
|
|
54
|
+
* @since 4.0.0
|
|
55
|
+
*/
|
|
56
|
+
export interface MachineAtom<State, Event, Error = never, Output = never, StartError = never> {
|
|
57
|
+
/**
|
|
58
|
+
* Atom containing the running machine handle once startup succeeds.
|
|
59
|
+
*
|
|
60
|
+
* @since 4.0.0
|
|
61
|
+
*/
|
|
62
|
+
readonly ref: Atom.Atom<AsyncResult.AsyncResult<Machine.MachineRef<State, Event, Error, Output>, StartError>>;
|
|
63
|
+
/**
|
|
64
|
+
* Atom containing the latest machine lifecycle snapshot.
|
|
65
|
+
*
|
|
66
|
+
* @since 4.0.0
|
|
67
|
+
*/
|
|
68
|
+
readonly snapshot: Atom.Atom<AsyncResult.AsyncResult<Machine.RuntimeSnapshot<State, Error, Output>, StartError>>;
|
|
69
|
+
/**
|
|
70
|
+
* Atom containing the state value from the latest runtime snapshot.
|
|
71
|
+
*
|
|
72
|
+
* @since 4.0.0
|
|
73
|
+
*/
|
|
74
|
+
readonly state: Atom.Atom<AsyncResult.AsyncResult<State, StartError>>;
|
|
75
|
+
/**
|
|
76
|
+
* Writable atom that sends events to the machine. Writes before startup
|
|
77
|
+
* completes fail with `NotReadyError`.
|
|
78
|
+
*
|
|
79
|
+
* @since 4.0.0
|
|
80
|
+
*/
|
|
81
|
+
readonly send: Atom.Writable<AsyncResult.AsyncResult<void, StartError | NotReadyError | Machine.StoppedError>, Event>;
|
|
82
|
+
/**
|
|
83
|
+
* Writable atom that stops the machine. Writes before startup completes fail
|
|
84
|
+
* with `NotReadyError`.
|
|
85
|
+
*
|
|
86
|
+
* @since 4.0.0
|
|
87
|
+
*/
|
|
88
|
+
readonly stop: Atom.Writable<AsyncResult.AsyncResult<void, StartError | NotReadyError>, void>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a reactive bridge for a directly invoked child machine.
|
|
91
|
+
*
|
|
92
|
+
* @since 4.0.0
|
|
93
|
+
*/
|
|
94
|
+
readonly child: <Child extends Machine.ChildMachine.Any>(child: Child) => ChildMachineAtom<Child, StartError>;
|
|
95
|
+
}
|
|
96
|
+
type RefState<Ref> = Ref extends Machine.MachineRef<infer State, any, any, any> ? State : never;
|
|
97
|
+
type RefError<Ref> = Ref extends Machine.MachineRef<any, any, infer Error, any> ? Error : never;
|
|
98
|
+
type RefOutput<Ref> = Ref extends Machine.MachineRef<any, any, any, infer Output> ? Output : never;
|
|
99
|
+
/**
|
|
100
|
+
* Reactive access to one invoked child machine selected by its descriptor.
|
|
101
|
+
*
|
|
102
|
+
* **Details**
|
|
103
|
+
*
|
|
104
|
+
* Each atom contains `Option.none()` while the state that owns the invocation
|
|
105
|
+
* is inactive or while the child is starting. It contains `Option.some(...)`
|
|
106
|
+
* for the current child instance and follows replacements after re-entry.
|
|
107
|
+
*
|
|
108
|
+
* **Gotchas**
|
|
109
|
+
*
|
|
110
|
+
* Lookup is direct-child scoped. Use `child` again on this bridge to reach a
|
|
111
|
+
* machine invoked by the selected child.
|
|
112
|
+
*
|
|
113
|
+
* @category models
|
|
114
|
+
* @since 4.0.0
|
|
115
|
+
*/
|
|
116
|
+
export interface ChildMachineAtom<Child extends Machine.ChildMachine.Any, StartError = never> {
|
|
117
|
+
/** Atom containing the current child reference when the child is active. */
|
|
118
|
+
readonly ref: Atom.Atom<AsyncResult.AsyncResult<Option.Option<Machine.ChildMachine.Ref<Child>>, StartError>>;
|
|
119
|
+
/** Atom containing the current child lifecycle snapshot when active. */
|
|
120
|
+
readonly snapshot: Atom.Atom<AsyncResult.AsyncResult<Option.Option<Machine.RuntimeSnapshot<RefState<Machine.ChildMachine.Ref<Child>>, RefError<Machine.ChildMachine.Ref<Child>>, RefOutput<Machine.ChildMachine.Ref<Child>>>>, StartError>>;
|
|
121
|
+
/** Atom containing the current child state when active. */
|
|
122
|
+
readonly state: Atom.Atom<AsyncResult.AsyncResult<Option.Option<RefState<Machine.ChildMachine.Ref<Child>>>, StartError>>;
|
|
123
|
+
/** Writable atom that sends events to the active child. */
|
|
124
|
+
readonly send: Atom.Writable<AsyncResult.AsyncResult<void, StartError | NotReadyError | ChildNotActiveError | Machine.StoppedError>, Machine.ChildMachine.Event<Child>>;
|
|
125
|
+
/** Writable atom that stops the active child. */
|
|
126
|
+
readonly stop: Atom.Writable<AsyncResult.AsyncResult<void, StartError | NotReadyError | ChildNotActiveError>, void>;
|
|
127
|
+
/** Creates a reactive bridge for a directly owned nested child. */
|
|
128
|
+
readonly child: <Nested extends Machine.ChildMachine.Any>(child: Nested) => ChildMachineAtom<Nested, StartError>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates atoms backed by a running machine.
|
|
132
|
+
*
|
|
133
|
+
* @category constructors
|
|
134
|
+
* @since 4.0.0
|
|
135
|
+
*/
|
|
136
|
+
export declare const make: {
|
|
137
|
+
<const States extends Machine.Machine.StateSchemas, const Events extends ReadonlyArray<Machine.Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.Machine.TaggedSchema> = any, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.Machine.StateIdentifier<States> = Machine.Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.Machine.StateIdentifier<States> = never, Output = never>(machine: Machine.Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits> & EnsureNoExternalRequirements<MachineRequirements<InitialR, R, Machine.Machine.EventOf<Events>, Machine.Machine.EmitOf<Emits>>>, ...args: [...Machine.Machine.InputArgs<Input>]): MachineAtom<Machine.Machine.Snapshot<States>, Machine.Machine.EventOf<Events>, E | Machine.ActionError<InitialR | R> | Machine.InfiniteTransitionError | Machine.MachineSchemaDecodeError | Machine.StartupError | Machine.StoppedError | InitialE, Output | undefined, InitialE | Machine.ActionError<InitialR | R> | Machine.MachineSchemaDecodeError | Machine.StartupError | Machine.StoppedError>;
|
|
138
|
+
<RuntimeError, const States extends Machine.Machine.StateSchemas, const Events extends ReadonlyArray<Machine.Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.Machine.TaggedSchema> = any, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.Machine.StateIdentifier<States> = Machine.Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.Machine.StateIdentifier<States> = never, Output = never>(runtime: Atom.AtomRuntime<ExternalRequirements<MachineRequirements<InitialR, R, Machine.Machine.EventOf<Events>, Machine.Machine.EmitOf<Emits>>>, RuntimeError>, machine: Machine.Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>, ...args: [...Machine.Machine.InputArgs<Input>]): MachineAtom<Machine.Machine.Snapshot<States>, Machine.Machine.EventOf<Events>, E | Machine.ActionError<InitialR | R> | Machine.InfiniteTransitionError | Machine.MachineSchemaDecodeError | Machine.StartupError | Machine.StoppedError | InitialE, Output | undefined, InitialE | Machine.ActionError<InitialR | R> | Machine.MachineSchemaDecodeError | Machine.StartupError | Machine.StoppedError | RuntimeError>;
|
|
139
|
+
};
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=AtomMachine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AtomMachine.d.ts","sourceRoot":"","sources":["../src/AtomMachine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;;;;AAEjF;;;;;GAKG;AACH,qBAAa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AS,EAChB,QAAQ,GACR,OAAO,CAAC,WAAW,CAAC,QAAQ,GAAG,CAAC,CAAC,GACjC,OAAO,CAAC,wBAAwB,GAChC,OAAO,CAAC,YAAY,GACpB,OAAO,CAAC,YAAY,GACpB,YAAY,CACf,CAAA;CAeM,CAAA"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atom bridge for running machines.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Data from "effect/Data";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
10
|
+
import * as Machine from "./Machine.js";
|
|
11
|
+
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
12
|
+
/**
|
|
13
|
+
* Error returned when a machine command is issued before startup completes.
|
|
14
|
+
*
|
|
15
|
+
* @category errors
|
|
16
|
+
* @since 4.0.0
|
|
17
|
+
*/
|
|
18
|
+
export class NotReadyError extends Data.TaggedError("NotReadyError") {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error returned when a command targets a child machine that is not active.
|
|
22
|
+
*
|
|
23
|
+
* @category errors
|
|
24
|
+
* @since 4.0.0
|
|
25
|
+
*/
|
|
26
|
+
export class ChildNotActiveError extends Data.TaggedError("ChildNotActiveError") {
|
|
27
|
+
}
|
|
28
|
+
const ExternalRequirementsTypeId = "~effect/reactivity/AtomMachine/ExternalRequirements";
|
|
29
|
+
const startMachineAtomEffect = (get, machine, args) => Effect.scoped(Effect.acquireRelease(Machine.start(machine, ...args), (ref) => ref.stop).pipe(Effect.tap((ref) => Effect.sync(() => get.setSelf(AsyncResult.success(ref)))), Effect.flatMap(() => Effect.never)));
|
|
30
|
+
const makeChildRefAtom = (parentRef, child) => Atom.readable((get) => {
|
|
31
|
+
const parent = get(parentRef);
|
|
32
|
+
if (AsyncResult.isInitial(parent)) {
|
|
33
|
+
return AsyncResult.initial(parent.waiting);
|
|
34
|
+
}
|
|
35
|
+
else if (AsyncResult.isFailure(parent)) {
|
|
36
|
+
return AsyncResult.failureWithPrevious(parent.cause, {
|
|
37
|
+
previous: get.self(),
|
|
38
|
+
waiting: parent.waiting
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (Option.isNone(parent.value)) {
|
|
42
|
+
return AsyncResult.success(Option.none());
|
|
43
|
+
}
|
|
44
|
+
const handle = parent.value.value;
|
|
45
|
+
const current = Effect.runSync(handle.child(child));
|
|
46
|
+
const cancel = Effect.runCallback(Effect.yieldNow.pipe(Effect.andThen(handle.childChanges(child).pipe(Stream.runForEach((ref) => Effect.sync(() => get.setSelf(AsyncResult.success(ref))))))));
|
|
47
|
+
get.addFinalizer(cancel);
|
|
48
|
+
return AsyncResult.success(current);
|
|
49
|
+
});
|
|
50
|
+
const makeChildFromRefAtom = (ref, descriptor) => {
|
|
51
|
+
const snapshot = Atom.readable((get) => {
|
|
52
|
+
const result = get(ref);
|
|
53
|
+
if (AsyncResult.isInitial(result)) {
|
|
54
|
+
return AsyncResult.initial(result.waiting);
|
|
55
|
+
}
|
|
56
|
+
else if (AsyncResult.isFailure(result)) {
|
|
57
|
+
return AsyncResult.failureWithPrevious(result.cause, {
|
|
58
|
+
previous: get.self(),
|
|
59
|
+
waiting: result.waiting
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else if (Option.isNone(result.value)) {
|
|
63
|
+
return AsyncResult.success(Option.none());
|
|
64
|
+
}
|
|
65
|
+
const handle = result.value.value;
|
|
66
|
+
const cancel = Effect.runCallback(handle.changes.pipe(Stream.runForEach((snapshot) => Effect.sync(() => get.setSelf(AsyncResult.success(Option.some(snapshot)))))));
|
|
67
|
+
get.addFinalizer(cancel);
|
|
68
|
+
return AsyncResult.success(Option.some(Effect.runSync(handle.snapshot)));
|
|
69
|
+
});
|
|
70
|
+
const send = Atom.writable((get) => AsyncResult.map(get(ref), () => undefined), (ctx, event) => {
|
|
71
|
+
const result = ctx.get(ref);
|
|
72
|
+
if (AsyncResult.isInitial(result)) {
|
|
73
|
+
ctx.setSelf(AsyncResult.fail(new NotReadyError()));
|
|
74
|
+
}
|
|
75
|
+
else if (AsyncResult.isFailure(result)) {
|
|
76
|
+
ctx.setSelf(AsyncResult.map(result, () => undefined));
|
|
77
|
+
}
|
|
78
|
+
else if (Option.isNone(result.value)) {
|
|
79
|
+
ctx.setSelf(AsyncResult.fail(new ChildNotActiveError({ id: descriptor.id })));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
Effect.runCallback(result.value.value.send(event), {
|
|
83
|
+
onExit: (exit) => ctx.setSelf(AsyncResult.fromExit(exit))
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const stop = Atom.writable((get) => AsyncResult.map(get(ref), () => undefined), (ctx) => {
|
|
88
|
+
const result = ctx.get(ref);
|
|
89
|
+
if (AsyncResult.isInitial(result)) {
|
|
90
|
+
ctx.setSelf(AsyncResult.fail(new NotReadyError()));
|
|
91
|
+
}
|
|
92
|
+
else if (AsyncResult.isFailure(result)) {
|
|
93
|
+
ctx.setSelf(AsyncResult.map(result, () => undefined));
|
|
94
|
+
}
|
|
95
|
+
else if (Option.isNone(result.value)) {
|
|
96
|
+
ctx.setSelf(AsyncResult.fail(new ChildNotActiveError({ id: descriptor.id })));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
Effect.runCallback(result.value.value.stop);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
ref,
|
|
104
|
+
snapshot,
|
|
105
|
+
state: Atom.mapResult(snapshot, Option.map((snapshot) => snapshot.state)),
|
|
106
|
+
send,
|
|
107
|
+
stop,
|
|
108
|
+
child: (nested) => makeChildFromRefAtom(makeChildRefAtom(ref, nested), nested)
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const makeFromRefAtom = (ref) => {
|
|
112
|
+
const snapshot = Atom.readable((get) => {
|
|
113
|
+
const result = get(ref);
|
|
114
|
+
if (AsyncResult.isInitial(result)) {
|
|
115
|
+
return AsyncResult.initial(result.waiting);
|
|
116
|
+
}
|
|
117
|
+
else if (AsyncResult.isFailure(result)) {
|
|
118
|
+
return AsyncResult.failureWithPrevious(result.cause, {
|
|
119
|
+
previous: get.self(),
|
|
120
|
+
waiting: result.waiting
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const handle = result.value;
|
|
124
|
+
const cancel = Effect.runCallback(handle.changes.pipe(Stream.runForEach((snapshot) => Effect.sync(() => get.setSelf(AsyncResult.success(snapshot, {
|
|
125
|
+
waiting: snapshot.status === "active"
|
|
126
|
+
}))))));
|
|
127
|
+
get.addFinalizer(cancel);
|
|
128
|
+
const current = Effect.runSync(handle.snapshot);
|
|
129
|
+
return AsyncResult.success(current, {
|
|
130
|
+
waiting: current.status === "active"
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
const send = Atom.writable((get) => AsyncResult.map(get(ref), () => undefined), (ctx, event) => {
|
|
134
|
+
const result = ctx.get(ref);
|
|
135
|
+
if (AsyncResult.isInitial(result)) {
|
|
136
|
+
ctx.setSelf(AsyncResult.fail(new NotReadyError()));
|
|
137
|
+
}
|
|
138
|
+
else if (AsyncResult.isFailure(result)) {
|
|
139
|
+
ctx.setSelf(AsyncResult.map(result, () => undefined));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
Effect.runCallback(result.value.send(event), {
|
|
143
|
+
onExit: (exit) => ctx.setSelf(AsyncResult.fromExit(exit))
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const stop = Atom.writable((get) => AsyncResult.map(get(ref), () => undefined), (ctx) => {
|
|
148
|
+
const result = ctx.get(ref);
|
|
149
|
+
if (AsyncResult.isInitial(result)) {
|
|
150
|
+
ctx.setSelf(AsyncResult.fail(new NotReadyError()));
|
|
151
|
+
}
|
|
152
|
+
else if (AsyncResult.isFailure(result)) {
|
|
153
|
+
ctx.setSelf(AsyncResult.map(result, () => undefined));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
Effect.runCallback(result.value.stop);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
ref,
|
|
161
|
+
snapshot,
|
|
162
|
+
state: Atom.mapResult(snapshot, (snapshot) => snapshot.state),
|
|
163
|
+
send,
|
|
164
|
+
stop,
|
|
165
|
+
child: (child) => {
|
|
166
|
+
const optionalRef = Atom.mapResult(ref, Option.some);
|
|
167
|
+
return makeChildFromRefAtom(makeChildRefAtom(optionalRef, child), child);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Creates atoms backed by a running machine.
|
|
173
|
+
*
|
|
174
|
+
* @category constructors
|
|
175
|
+
* @since 4.0.0
|
|
176
|
+
*/
|
|
177
|
+
export const make = ((...args) => {
|
|
178
|
+
const runtimeOrMachine = args[0];
|
|
179
|
+
if (Machine.isMachine(runtimeOrMachine)) {
|
|
180
|
+
const machine = runtimeOrMachine;
|
|
181
|
+
const input = args.slice(1);
|
|
182
|
+
const ref = Atom.make((get) => startMachineAtomEffect(get, machine, input));
|
|
183
|
+
return makeFromRefAtom(ref);
|
|
184
|
+
}
|
|
185
|
+
const runtime = runtimeOrMachine;
|
|
186
|
+
const machine = args[1];
|
|
187
|
+
const input = args.slice(2);
|
|
188
|
+
const ref = runtime.atom((get) => startMachineAtomEffect(get, machine, input));
|
|
189
|
+
return makeFromRefAtom(ref);
|
|
190
|
+
});
|
|
191
|
+
//# sourceMappingURL=AtomMachine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AtomMachine.js","sourceRoot":"","sources":["../src/AtomMachine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;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