@xstate/effect 1.0.0-alpha.10 → 1.0.0-alpha.12
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/declarations/src/actor.d.ts +29 -3
- package/dist/declarations/src/actorScope.d.ts +7 -1
- package/dist/declarations/src/atom.d.ts +3 -0
- package/dist/declarations/src/createEffectActor.d.ts +7 -1
- package/dist/declarations/src/effectActor.d.ts +2 -0
- package/dist/declarations/src/effectLogic.d.ts +22 -0
- package/dist/declarations/src/errors.d.ts +19 -3
- package/dist/declarations/src/oxlint.d.ts +1 -0
- package/dist/declarations/src/persistence.d.ts +7 -1
- package/dist/declarations/src/schema.d.ts +10 -0
- package/dist/declarations/src/setupEffect.d.ts +8 -0
- package/dist/declarations/src/state.d.ts +11 -1
- package/dist/declarations/src/test.d.ts +2 -0
- package/dist/declarations/src/types.d.ts +2 -0
- package/dist/{state-a3f54e06.js → state-a2154dce.js} +48 -6
- package/dist/xstate-effect-atom.js +6 -2
- package/dist/xstate-effect-oxlint.js +2 -0
- package/dist/xstate-effect-test.js +2 -0
- package/dist/xstate-effect.js +80 -6
- package/package.json +3 -3
|
@@ -2,11 +2,23 @@ import { Cause, Duration, Effect, Stream } from 'effect';
|
|
|
2
2
|
import type { Actor, ActorRef, AnyActorRef, AnyEventObject, EmittedFrom, EventRejection, ErrorFrom, InspectionEvent, OutputFrom, SnapshotFrom } from 'xstate';
|
|
3
3
|
import type { EffectActor } from "./effectActor.js";
|
|
4
4
|
import { ActorStoppedError, type UnwrapEffectFailure } from "./errors.js";
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The event type accepted by an actor's `send` method.
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
6
10
|
export type SendableEventFrom<TActor extends AnyActorRef> = Parameters<TActor['send']>[0];
|
|
7
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The event type an actor emits through `actor.on(...)`.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
15
|
+
*/
|
|
8
16
|
export type EmittedEventFrom<TActor> = TActor extends EffectActor<infer TLogic> ? EmittedFrom<TLogic> : TActor extends Actor<infer TLogic> ? EmittedFrom<TLogic> : TActor extends ActorRef<any, any, infer TEmitted, any> ? TEmitted : AnyEventObject;
|
|
9
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@link waitFor}.
|
|
19
|
+
*
|
|
20
|
+
* @experimental
|
|
21
|
+
*/
|
|
10
22
|
export interface WaitForOptions {
|
|
11
23
|
/**
|
|
12
24
|
* Fails with `Cause.TimeoutError` when no snapshot satisfies the predicate
|
|
@@ -19,6 +31,8 @@ export interface WaitForOptions {
|
|
|
19
31
|
* is enqueued, like `actor.send(event)`, and processed on the actor's own
|
|
20
32
|
* fiber. An event that cannot be delivered (for example to a stopped actor)
|
|
21
33
|
* is reported as a dead letter, observable with {@link deadLetters}.
|
|
34
|
+
*
|
|
35
|
+
* @experimental
|
|
22
36
|
*/
|
|
23
37
|
export declare const send: {
|
|
24
38
|
<TActor extends AnyActorRef>(event: SendableEventFrom<TActor>): (actor: TActor) => Effect.Effect<void>;
|
|
@@ -29,12 +43,16 @@ export declare const send: {
|
|
|
29
43
|
* when the actor completes or stops, and emits the error snapshot before
|
|
30
44
|
* ending when the actor errors. Interrupting the stream unsubscribes from the
|
|
31
45
|
* actor.
|
|
46
|
+
*
|
|
47
|
+
* @experimental
|
|
32
48
|
*/
|
|
33
49
|
export declare function snapshots<TActor extends AnyActorRef>(actor: TActor): Stream.Stream<SnapshotFrom<TActor>>;
|
|
34
50
|
/**
|
|
35
51
|
* Streams every event an actor emits, as delivered to `actor.on('*', …)`. The
|
|
36
52
|
* stream ends when the actor completes, errors or stops. Interrupting the
|
|
37
53
|
* stream removes the listener.
|
|
54
|
+
*
|
|
55
|
+
* @experimental
|
|
38
56
|
*/
|
|
39
57
|
export declare function emitted<TActor extends AnyActorRef>(actor: TActor): Stream.Stream<EmittedEventFrom<TActor>>;
|
|
40
58
|
/**
|
|
@@ -43,6 +61,8 @@ export declare function emitted<TActor extends AnyActorRef>(actor: TActor): Stre
|
|
|
43
61
|
* `ActorStoppedError` if the actor stops or errors first, and with
|
|
44
62
|
* `Cause.TimeoutError` when `options.timeout` elapses. Interrupting the Effect
|
|
45
63
|
* unsubscribes from the actor.
|
|
64
|
+
*
|
|
65
|
+
* @experimental
|
|
46
66
|
*/
|
|
47
67
|
export declare const waitFor: {
|
|
48
68
|
<TActor extends AnyActorRef, TNarrowed extends SnapshotFrom<TActor>>(predicate: (snapshot: SnapshotFrom<TActor>) => snapshot is TNarrowed): (actor: TActor) => Effect.Effect<TNarrowed, ActorStoppedError>;
|
|
@@ -59,12 +79,16 @@ export declare const waitFor: {
|
|
|
59
79
|
* when it is done, replays an Effect actor's original Cause when it errors, and fails with
|
|
60
80
|
* `ActorStoppedError` when it stops without output. Waits for a still-active
|
|
61
81
|
* actor to settle. Ordinary XState errors remain typed failures.
|
|
82
|
+
*
|
|
83
|
+
* @experimental
|
|
62
84
|
*/
|
|
63
85
|
export declare function join<TActor extends AnyActorRef>(actor: TActor): Effect.Effect<OutputFrom<TActor>, UnwrapEffectFailure<ErrorFrom<TActor>> | ActorStoppedError>;
|
|
64
86
|
/**
|
|
65
87
|
* Streams the inspection events of the actor's system, as delivered to
|
|
66
88
|
* `system.inspect(…)`. The stream runs until it is interrupted or its scope
|
|
67
89
|
* closes.
|
|
90
|
+
*
|
|
91
|
+
* @experimental
|
|
68
92
|
*/
|
|
69
93
|
export declare function inspect(actor: AnyActorRef): Stream.Stream<InspectionEvent>;
|
|
70
94
|
/**
|
|
@@ -73,5 +97,7 @@ export declare function inspect(actor: AnyActorRef): Stream.Stream<InspectionEve
|
|
|
73
97
|
* events and internal events sent from outside their owner. A dead letter is
|
|
74
98
|
* not an actor error. The stream runs until it is interrupted or its scope
|
|
75
99
|
* closes.
|
|
100
|
+
*
|
|
101
|
+
* @experimental
|
|
76
102
|
*/
|
|
77
103
|
export declare function deadLetters(actor: AnyActorRef): Stream.Stream<EventRejection>;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Context, Effect, Scope } from 'effect';
|
|
2
2
|
declare const ActorScope_base: Context.ServiceClass<ActorScope, "@xstate/effect/ActorScope", Scope.Scope>;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The owning Effect actor's scope, supplied by `createEffectActor`.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
4
8
|
export declare class ActorScope extends ActorScope_base {
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Acquires resources in the owning actor's scope. Their finalizers run when
|
|
8
12
|
* that actor stops, even if the invoking task finishes or is cancelled first.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
9
15
|
*/
|
|
10
16
|
export declare function withActorScope<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, Exclude<R, Scope.Scope> | ActorScope>;
|
|
11
17
|
export {};
|
|
@@ -34,6 +34,7 @@ interface BaseActorAtoms<TLogic extends AnyActorLogic, ER> {
|
|
|
34
34
|
/** Derives an atom of a value selected from the snapshot. */
|
|
35
35
|
readonly select: <T>(selector: (snapshot: SnapshotFrom<TLogic>) => T) => Atom.Atom<AsyncResult.AsyncResult<T, ER>>;
|
|
36
36
|
}
|
|
37
|
+
/** @experimental */
|
|
37
38
|
export type ActorAtoms<TLogic extends AnyActorLogic, ER = never> = BaseActorAtoms<TLogic, ER> & ([TLogic] extends [AnyStateMachine] ? {
|
|
38
39
|
/** The machine snapshot as a tagged union over its states. */
|
|
39
40
|
readonly state: Atom.Atom<AsyncResult.AsyncResult<TaggedStateFrom<SnapshotFrom<TLogic>>, ER>>;
|
|
@@ -52,5 +53,7 @@ interface MissingRequirements<T> {
|
|
|
52
53
|
* when the atom is released. Wrap the atoms with `Atom.keepAlive` to pin the
|
|
53
54
|
* actor for the registry's lifetime, or with `Atom.family` to create one
|
|
54
55
|
* actor per input.
|
|
56
|
+
*
|
|
57
|
+
* @experimental
|
|
55
58
|
*/
|
|
56
59
|
export declare function createActorAtoms<TLogic extends AnyActorLogic, R, ER = never>(runtime: Atom.AtomRuntime<R, ER> & ([RequirementsFrom<TLogic>] extends [R] ? unknown : MissingRequirements<Exclude<RequirementsFrom<TLogic>, R>>), logic: TLogic, ...[options]: EffectActorOptionsArgs<TLogic>): ActorAtoms<TLogic, ER>;
|
|
@@ -2,7 +2,11 @@ import { Effect, Scope } from 'effect';
|
|
|
2
2
|
import { type ActorOptions, type AnyActorLogic, type InputFrom, type RequiredActorOptionsFor, type RequiredActorOptionsKeys } from 'xstate';
|
|
3
3
|
import { EffectActor } from "./effectActor.js";
|
|
4
4
|
import type { RequirementsFrom } from "./types.js";
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Options for {@link createEffectActor}.
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
6
10
|
export type EffectActorOptions<TLogic extends AnyActorLogic> = {
|
|
7
11
|
readonly input?: InputFrom<TLogic>;
|
|
8
12
|
/**
|
|
@@ -32,5 +36,7 @@ export type EffectActorOptionsArgs<TLogic extends AnyActorLogic> = [
|
|
|
32
36
|
* The actor is a scoped resource: it stops, and every Effect it hosts is
|
|
33
37
|
* interrupted, when the enclosing `Scope` closes. The returned Effect never
|
|
34
38
|
* fails; the actor's own outcome is its snapshot status, read with `join`.
|
|
39
|
+
*
|
|
40
|
+
* @experimental
|
|
35
41
|
*/
|
|
36
42
|
export declare function createEffectActor<TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: EffectActorOptionsArgs<TLogic>): Effect.Effect<EffectActor<TLogic>, never, RequirementsFrom<TLogic> | Scope.Scope>;
|
|
@@ -23,6 +23,8 @@ export declare function safeCall<T>(fn: ((arg: T) => void) | undefined, arg?: T)
|
|
|
23
23
|
* contract (`send`, `getSnapshot`, `subscribe`, `on`), so it works with
|
|
24
24
|
* `useSelector`, this package's actor functions and the inspection APIs, while
|
|
25
25
|
* the actor itself is driven by an Effect fiber over pure transitions.
|
|
26
|
+
*
|
|
27
|
+
* @experimental
|
|
26
28
|
*/
|
|
27
29
|
export declare class EffectActor<TLogic extends AnyActorLogic> implements ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>> {
|
|
28
30
|
readonly logic: TLogic;
|
|
@@ -10,6 +10,8 @@ declare const effectLogicBrand: unique symbol;
|
|
|
10
10
|
* failure type and its Effect service requirements, which is how
|
|
11
11
|
* `RequirementsFrom` collects the `R` channel of `createEffectActor` without
|
|
12
12
|
* inspecting the logic at runtime.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
13
15
|
*/
|
|
14
16
|
export interface EffectLogicBrand<TError, TRequirements> {
|
|
15
17
|
readonly [effectLogicBrand]: {
|
|
@@ -21,6 +23,8 @@ export interface EffectLogicBrand<TError, TRequirements> {
|
|
|
21
23
|
* Snapshot of a `createEffectLogic` actor. The actor holds no context of its own: it
|
|
22
24
|
* is `active` while the Effect runs, `done` with the Effect's success value as
|
|
23
25
|
* `output`, or `error` with the original `Cause` wrapped in `EffectFailure` as `error`.
|
|
26
|
+
*
|
|
27
|
+
* @experimental
|
|
24
28
|
*/
|
|
25
29
|
export type EffectSnapshot<TOutput, TError, TInput> = Snapshot<TOutput> & {
|
|
26
30
|
readonly context: undefined;
|
|
@@ -32,6 +36,8 @@ export type EffectSnapshot<TOutput, TError, TInput> = Snapshot<TOutput> & {
|
|
|
32
36
|
* source the actor's `input`, its own reference (`self`), the actor `system`,
|
|
33
37
|
* and `emit` for publishing events that `actor.on(...)` and `emitted(actor)`
|
|
34
38
|
* observe.
|
|
39
|
+
*
|
|
40
|
+
* @experimental
|
|
35
41
|
*/
|
|
36
42
|
export type EffectSourceArgs<TInput> = {
|
|
37
43
|
readonly input: TInput;
|
|
@@ -44,6 +50,8 @@ export type EffectSourceArgs<TInput> = {
|
|
|
44
50
|
* What `createEffectLogic` accepts as its Effect: either an Effect value, or a
|
|
45
51
|
* function of {@link EffectSourceArgs} returning one. The function form is
|
|
46
52
|
* called once per actor start, so it sees that actor's input.
|
|
53
|
+
*
|
|
54
|
+
* @experimental
|
|
47
55
|
*/
|
|
48
56
|
export type EffectSource<TOutput, TError, TInput, TRequirements> = Effect.Effect<TOutput, TError, TRequirements> | ((args: EffectSourceArgs<TInput>) => Effect.Effect<TOutput, TError, TRequirements>);
|
|
49
57
|
type EffectActorSchemas = {
|
|
@@ -71,6 +79,8 @@ type EffectSchemaValidationConfig<TSchemas extends EffectActorSchemas> = {
|
|
|
71
79
|
* ordinary XState actor logic carrying {@link EffectLogicBrand}, so a machine
|
|
72
80
|
* can invoke or spawn it, and `createEffectActor` can collect its
|
|
73
81
|
* requirements.
|
|
82
|
+
*
|
|
83
|
+
* @experimental
|
|
74
84
|
*/
|
|
75
85
|
export type EffectActorLogic<TOutput, TError, TInput, TRequirements> = ActorLogic<EffectSnapshot<TOutput, TError, TInput>, EventObject, TInput, AnyActorSystem> & {
|
|
76
86
|
readonly id?: string;
|
|
@@ -79,6 +89,8 @@ export type EffectActorLogic<TOutput, TError, TInput, TRequirements> = ActorLogi
|
|
|
79
89
|
* Snapshot of a `createEffectStreamLogic` actor. `context` holds the most recent
|
|
80
90
|
* stream item, or `undefined` before the first one. The actor reaches `done`
|
|
81
91
|
* with no output when the stream completes, and `error` when it fails.
|
|
92
|
+
*
|
|
93
|
+
* @experimental
|
|
82
94
|
*/
|
|
83
95
|
export type EffectStreamSnapshot<TItem, TError, TInput> = Snapshot<undefined> & {
|
|
84
96
|
readonly context: TItem | undefined;
|
|
@@ -89,6 +101,8 @@ export type EffectStreamSnapshot<TItem, TError, TInput> = Snapshot<undefined> &
|
|
|
89
101
|
* Actor logic produced by `createEffectStreamLogic`. Its snapshot is an
|
|
90
102
|
* {@link EffectStreamSnapshot}, so the parent reads the latest item from the
|
|
91
103
|
* child's `context` rather than from events.
|
|
104
|
+
*
|
|
105
|
+
* @experimental
|
|
92
106
|
*/
|
|
93
107
|
export type EffectStreamActorLogic<TItem, TError, TInput, TRequirements> = ActorLogic<EffectStreamSnapshot<TItem, TError, TInput>, EventObject, TInput, AnyActorSystem> & {
|
|
94
108
|
readonly id?: string;
|
|
@@ -102,6 +116,8 @@ export type EffectStreamActorLogic<TItem, TError, TInput, TRequirements> = Actor
|
|
|
102
116
|
* Resources belong to this task's scope and close on completion, failure or
|
|
103
117
|
* interruption. Use `withActorScope` to retain a resource until the owning
|
|
104
118
|
* Effect actor stops.
|
|
119
|
+
*
|
|
120
|
+
* @experimental
|
|
105
121
|
*/
|
|
106
122
|
export declare function createEffectLogic<const TInputSchema extends EffectSchemaLike, const TOutputSchema extends EffectSchemaLike, TError = unknown, TRequirements = never>(config: Omit<EffectSourceConfig<SchemaOutput<TOutputSchema>, TError, SchemaOutput<TInputSchema>, TRequirements>, 'schemas' | 'validator'> & EffectSchemaValidationConfig<{
|
|
107
123
|
input: TInputSchema;
|
|
@@ -128,6 +144,8 @@ export declare function createEffectLogic<TOutput, TError = unknown, TInput = un
|
|
|
128
144
|
* What `createEffectStreamLogic` and `createEffectEventStreamLogic` accept as their stream:
|
|
129
145
|
* either a Stream value, or a function of {@link EffectSourceArgs} returning
|
|
130
146
|
* one. The function form is called once per actor start.
|
|
147
|
+
*
|
|
148
|
+
* @experimental
|
|
131
149
|
*/
|
|
132
150
|
export type EffectStreamSource<TItem, TError, TInput, TRequirements> = Stream.Stream<TItem, TError, TRequirements> | ((args: EffectSourceArgs<TInput>) => Stream.Stream<TItem, TError, TRequirements>);
|
|
133
151
|
type EffectStreamConfig<TItem, TError, TInput, TRequirements, TSchemas extends {
|
|
@@ -150,6 +168,8 @@ type StreamRequirements<T> = T extends Stream.Stream<any, any, infer R> ? R : ne
|
|
|
150
168
|
* {@link EffectSourceArgs} returning one, or a config object with `id`,
|
|
151
169
|
* `schemas`, `validator` and `stream`. Its resources close when the stream
|
|
152
170
|
* completes, fails or is interrupted.
|
|
171
|
+
*
|
|
172
|
+
* @experimental
|
|
153
173
|
*/
|
|
154
174
|
export declare function createEffectStreamLogic<const TInputSchema extends EffectSchemaLike, TStream extends Stream.Stream<any, any, any>>(config: Omit<EffectStreamConfig<StreamItem<TStream>, StreamError<TStream>, SchemaOutput<TInputSchema>, StreamRequirements<TStream>>, 'stream' | 'schemas' | 'validator'> & EffectSchemaValidationConfig<{
|
|
155
175
|
input: TInputSchema;
|
|
@@ -166,6 +186,8 @@ export declare function createEffectStreamLogic<TItem, TError = unknown, TInput
|
|
|
166
186
|
* has no output: it reaches `done` when the stream completes and `error` when
|
|
167
187
|
* it fails. Accepts the same forms as `createEffectStreamLogic`. Its resources close
|
|
168
188
|
* when the stream completes, fails or is interrupted.
|
|
189
|
+
*
|
|
190
|
+
* @experimental
|
|
169
191
|
*/
|
|
170
192
|
export declare function createEffectEventStreamLogic<const TInputSchema extends EffectSchemaLike, TStream extends Stream.Stream<EventObject, any, any>>(config: Omit<EffectStreamConfig<StreamItem<TStream>, StreamError<TStream>, SchemaOutput<TInputSchema>, StreamRequirements<TStream>>, 'stream' | 'schemas' | 'validator'> & EffectSchemaValidationConfig<{
|
|
171
193
|
input: TInputSchema;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Cause } from 'effect';
|
|
2
2
|
import type { Snapshot } from 'xstate';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Preserves an Effect failure, defect or interruption through XState error routing.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
4
8
|
export declare class EffectFailure<E> extends Error {
|
|
5
9
|
#private;
|
|
6
10
|
readonly cause: Cause.Cause<E>;
|
|
@@ -11,7 +15,11 @@ export declare class EffectFailure<E> extends Error {
|
|
|
11
15
|
declare const EffectInterruptedError_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]; }>) => Cause.YieldableError & {
|
|
12
16
|
readonly _tag: "EffectInterruptedError";
|
|
13
17
|
} & Readonly<A>;
|
|
14
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Inspect `EffectFailure.cause` for interruption instead.
|
|
20
|
+
*
|
|
21
|
+
* @experimental
|
|
22
|
+
*/
|
|
15
23
|
export declare class EffectInterruptedError extends EffectInterruptedError_base<{
|
|
16
24
|
readonly cause: Cause.Cause<never>;
|
|
17
25
|
}> {
|
|
@@ -24,6 +32,8 @@ declare const ActorStoppedError_base: new <A extends Record<string, any> = {}>(a
|
|
|
24
32
|
* Reported by `waitFor` when the actor stops or errors before a snapshot
|
|
25
33
|
* matches, and by `join` when the actor stops without output. `join` reports
|
|
26
34
|
* an errored actor's outcome instead, preserving an Effect failure's Cause.
|
|
35
|
+
*
|
|
36
|
+
* @experimental
|
|
27
37
|
*/
|
|
28
38
|
export declare class ActorStoppedError extends ActorStoppedError_base<{
|
|
29
39
|
readonly actorId: string;
|
|
@@ -37,6 +47,8 @@ declare const NotReadyError_base: new <A extends Record<string, any> = {}>(args:
|
|
|
37
47
|
/**
|
|
38
48
|
* Reported by the `send` atom of `createActorAtoms` when an event is sent
|
|
39
49
|
* before the actor's runtime has finished building.
|
|
50
|
+
*
|
|
51
|
+
* @experimental
|
|
40
52
|
*/
|
|
41
53
|
export declare class NotReadyError extends NotReadyError_base {
|
|
42
54
|
get message(): string;
|
|
@@ -45,7 +57,11 @@ export type UnwrapEffectFailure<E> = E extends EffectFailure<infer Failure> ? Fa
|
|
|
45
57
|
declare const EventRejectedError_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]; }>) => Cause.YieldableError & {
|
|
46
58
|
readonly _tag: "EventRejectedError";
|
|
47
59
|
} & Readonly<A>;
|
|
48
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* An event rejected at the actor's delivery boundary.
|
|
62
|
+
*
|
|
63
|
+
* @experimental
|
|
64
|
+
*/
|
|
49
65
|
export declare class EventRejectedError extends EventRejectedError_base<{
|
|
50
66
|
readonly actorId: string;
|
|
51
67
|
readonly event: {
|
|
@@ -13,7 +13,11 @@ type SnapshotData<TMachine extends AnyStateMachine> = {
|
|
|
13
13
|
declare const SnapshotCodecError_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 & {
|
|
14
14
|
readonly _tag: "SnapshotCodecError";
|
|
15
15
|
} & Readonly<A>;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* A malformed transport, unsupported JSON value or missing persistence metadata.
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
17
21
|
export declare class SnapshotCodecError extends SnapshotCodecError_base<{
|
|
18
22
|
readonly stage: 'encode' | 'decode';
|
|
19
23
|
readonly path: string;
|
|
@@ -25,6 +29,8 @@ export declare class SnapshotCodecError extends SnapshotCodecError_base<{
|
|
|
25
29
|
* Binds a full bidirectional snapshot schema to a versioned machine. The schema
|
|
26
30
|
* owns rich values and supported historical versions. Decoding never migrates;
|
|
27
31
|
* restore or `machineVersions` remains responsible for migration.
|
|
32
|
+
*
|
|
33
|
+
* @experimental
|
|
28
34
|
*/
|
|
29
35
|
export declare function createSnapshotCodec<TMachine extends AnyStateMachine & {
|
|
30
36
|
readonly version: string;
|
|
@@ -5,12 +5,16 @@ import type { SetupSchemas, SetupStateSchema, SetupStateSchemas, StandardSchemaV
|
|
|
5
5
|
* `createEffectStreamLogic` and `createEffectEventStreamLogic` convert it to a Standard
|
|
6
6
|
* Schema, so XState infers the decoded `Schema.Type` without an explicit call
|
|
7
7
|
* to `Schema.toStandardSchemaV1`.
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
8
10
|
*/
|
|
9
11
|
export type EffectSchema = Schema.ConstraintDecoder<unknown>;
|
|
10
12
|
/**
|
|
11
13
|
* Either an Effect {@link EffectSchema} or a Standard Schema. Every schema
|
|
12
14
|
* position in this package accepts both, so Effect schemas and schemas from
|
|
13
15
|
* other libraries can be mixed in one machine.
|
|
16
|
+
*
|
|
17
|
+
* @experimental
|
|
14
18
|
*/
|
|
15
19
|
export type EffectSchemaLike = StandardSchemaV1 | EffectSchema;
|
|
16
20
|
interface RuntimeValidationDoesNotSupportTransformingSchemas {
|
|
@@ -36,6 +40,8 @@ type ToStandardSchemaShape<TValue> = TValue extends EffectSchemaLike ? ToStandar
|
|
|
36
40
|
* schema position widened to {@link EffectSchemaLike}. Covers `context`,
|
|
37
41
|
* `input`, `output` and the per-key records for `events`, `internalEvents`,
|
|
38
42
|
* `emitted` and `children`.
|
|
43
|
+
*
|
|
44
|
+
* @experimental
|
|
39
45
|
*/
|
|
40
46
|
export type EffectSetupSchemas = {
|
|
41
47
|
[K in keyof SetupSchemas]?: EffectSchemaShape<NonNullable<SetupSchemas[K]>>;
|
|
@@ -48,6 +54,7 @@ export type ValidateEffectSetupSchemas<TSchemas> = {
|
|
|
48
54
|
[P in keyof TSchemas[K]]: AssertNonTransformingSchema<TSchemas[K][P]>;
|
|
49
55
|
} : K extends 'context' | 'input' | 'output' ? AssertNonTransformingSchema<TSchemas[K]> : TSchemas[K];
|
|
50
56
|
};
|
|
57
|
+
/** @experimental */
|
|
51
58
|
export type ToStandardSetupSchemas<TSchemas> = {
|
|
52
59
|
[K in keyof TSchemas]: ToStandardSchemaShape<TSchemas[K]>;
|
|
53
60
|
} extends infer TStandardSchemas extends SetupSchemas ? TStandardSchemas : never;
|
|
@@ -56,6 +63,8 @@ export type ToStandardSetupSchemas<TSchemas> = {
|
|
|
56
63
|
* that state, and the same shape recursively for its child states. It is
|
|
57
64
|
* XState's `SetupStateSchema` with Effect schemas allowed in every schema
|
|
58
65
|
* position.
|
|
66
|
+
*
|
|
67
|
+
* @experimental
|
|
59
68
|
*/
|
|
60
69
|
export interface EffectSetupStateSchema {
|
|
61
70
|
schemas?: EffectSchemaShape<SetupStateSchemas>;
|
|
@@ -71,6 +80,7 @@ export type ValidateEffectSetupStates<TStates> = {
|
|
|
71
80
|
type ToStandardSetupStateSchema<TStateSchema> = TStateSchema extends EffectSetupStateSchema ? {
|
|
72
81
|
[K in keyof TStateSchema]: K extends 'schemas' ? ToStandardSchemaShape<TStateSchema[K]> : K extends 'states' ? TStateSchema[K] extends Record<string, EffectSetupStateSchema> ? ToStandardSetupStates<TStateSchema[K]> : TStateSchema[K] : TStateSchema[K];
|
|
73
82
|
} extends infer TStandardStateSchema extends SetupStateSchema ? TStandardStateSchema : never : never;
|
|
83
|
+
/** @experimental */
|
|
74
84
|
export type ToStandardSetupStates<TStates> = {
|
|
75
85
|
[K in keyof TStates]: ToStandardSetupStateSchema<TStates[K]>;
|
|
76
86
|
};
|
|
@@ -8,6 +8,8 @@ import { type EffectSetupSchemas, type EffectSetupStateSchema, type ToStandardSe
|
|
|
8
8
|
* the actor itself and its family (`self`, `parent`, `children`), the
|
|
9
9
|
* registered `actions`, `actors`, `guards` and `delays`, the actor `system`,
|
|
10
10
|
* and the `params` and `output` the transition passed along.
|
|
11
|
+
*
|
|
12
|
+
* @experimental
|
|
11
13
|
*/
|
|
12
14
|
export type EffectActionArgs<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> = {
|
|
13
15
|
readonly context: TContext;
|
|
@@ -29,6 +31,8 @@ export type EffectActionArgs<TContext extends MachineContext = MachineContext, T
|
|
|
29
31
|
* enqueued, and returns an Effect that runs afterwards in the actor's Effect
|
|
30
32
|
* context. The Effect is interrupted when the actor stops; its failures and
|
|
31
33
|
* defects route to the state's `onError`.
|
|
34
|
+
*
|
|
35
|
+
* @experimental
|
|
32
36
|
*/
|
|
33
37
|
export type EffectAction<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject, TError = unknown, TRequirements = never> = (args: EffectActionArgs<TContext, TEvent>) => Effect.Effect<void, TError, TRequirements>;
|
|
34
38
|
type AnyEffectAction = EffectAction<any, any, any, any>;
|
|
@@ -110,6 +114,8 @@ type EffectSetupExtensionConfig<TBaseSchemas extends SetupSchemas, TBaseStates e
|
|
|
110
114
|
* that also accepts Effect schemas and Effect-returning actions. Call
|
|
111
115
|
* `createMachine` on it to build a machine whose registered actions and actors
|
|
112
116
|
* contribute to `RequirementsFrom`.
|
|
117
|
+
*
|
|
118
|
+
* @experimental
|
|
113
119
|
*/
|
|
114
120
|
export type EffectSetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}, TSetupActionMap extends Sources['actions'] = {}, TSetupActorMap extends Sources['actors'] = {}, TSetupGuardMap extends Sources['guards'] = {}, TSetupDelayMap extends Sources['delays'] = {}, TSetupDelays extends string = Extract<keyof TSetupDelayMap, string>, TValidator extends ActorLogicValidator | undefined = undefined> = Omit<SetupReturn<TStates, TSchemas, TSetupActionMap, TSetupActorMap, TSetupGuardMap, TSetupDelayMap, TSetupDelays, SystemRegistry, TValidator>, 'extend'> & {
|
|
115
121
|
extend<const TExtensionSchemas extends EffectSetupSchemas = {}, const TExtensionStates extends Record<string, EffectSetupStateSchema> = {}, TExtensionActionMap extends Record<string, EffectActionSource> = {}, TExtensionActorMap extends Sources['actors'] = {}, TExtensionGuardMap extends Sources['guards'] = {}, TExtensionDelayMap extends Sources['delays'] = {}, const TExtensionValidator extends ActorLogicValidator | undefined | InheritedEffectValidator = InheritedEffectValidator>(config: EffectSetupExtensionConfig<TSchemas, TStates, TValidator, TExtensionSchemas, TExtensionStates, TExtensionActionMap, TExtensionActorMap, TExtensionGuardMap, TExtensionDelayMap, TExtensionValidator>): EffectSetupReturn<MergeRecord<TStates, ToStandardSetupStates<TExtensionStates>>, MergeSetupSchemas<TSchemas, ToStandardSetupSchemas<TExtensionSchemas>>, MergeRecord<TSetupActionMap, CoreEffectActionMap<TExtensionActionMap, MergeSetupSchemas<TSchemas, ToStandardSetupSchemas<TExtensionSchemas>>>>, MergeRecord<TSetupActorMap, TExtensionActorMap>, MergeRecord<TSetupGuardMap, TExtensionGuardMap>, MergeRecord<TSetupDelayMap, TExtensionDelayMap>, TSetupDelays | Extract<keyof TExtensionDelayMap, string>, ResolveExtendedValidator<TValidator, TExtensionValidator>>;
|
|
@@ -122,6 +128,8 @@ export type EffectSetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
122
128
|
* runs in the actor's Effect context. Everything else, including `actors`,
|
|
123
129
|
* `guards`, `delays` and `extend`, behaves as in `setup`. Machines built from
|
|
124
130
|
* it must be started with `createEffectActor`.
|
|
131
|
+
*
|
|
132
|
+
* @experimental
|
|
125
133
|
*/
|
|
126
134
|
export declare function setupEffect(): EffectSetupReturn;
|
|
127
135
|
export declare function setupEffect<const TSchemas extends EffectSetupSchemas = {}, const TStates extends Record<string, EffectSetupStateSchema> = Record<string, EffectSetupStateSchema>, TActionMap extends Record<string, EffectActionSource> = {}, TActorMap extends Sources['actors'] = {}, TGuardMap extends Sources['guards'] = {}, TDelayMap extends Sources['delays'] = {}, const TValidator extends ActorLogicValidator | undefined = undefined>(config: EffectSetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap, TValidator>): EffectSetupReturn<ToStandardSetupStates<TStates>, ToStandardSetupSchemas<TSchemas>, CoreEffectActionMap<TActionMap, ToStandardSetupSchemas<TSchemas>>, TActorMap, TGuardMap, TDelayMap, Extract<keyof TDelayMap, string>, TValidator>;
|
|
@@ -6,6 +6,8 @@ type Join<TPrefix extends string, TKey extends string> = TPrefix extends '' ? TK
|
|
|
6
6
|
* state has no single path, so its tag stops at the parallel state. When the
|
|
7
7
|
* machine itself is parallel, the tag is `TRootTag`: the machine id, or `''`
|
|
8
8
|
* for a machine without one.
|
|
9
|
+
*
|
|
10
|
+
* @experimental
|
|
9
11
|
*/
|
|
10
12
|
export type StateTag<TValue, TPrefix extends string = '', TRootTag extends string = ''> = string extends TValue ? string : TValue extends string ? Join<TPrefix, TValue> : TValue extends object ? string extends keyof TValue ? string : IsUnion<keyof TValue & string> extends true ? TPrefix extends '' ? TRootTag : TPrefix : {
|
|
11
13
|
[K in keyof TValue & string]: StateTag<TValue[K], Join<TPrefix, K>, TRootTag>;
|
|
@@ -22,9 +24,15 @@ type TaggedStateOf<TSnapshot, TValue, TContext extends MachineContext, TSchema e
|
|
|
22
24
|
* A machine snapshot as a tagged union over its states. `_tag` is the state's
|
|
23
25
|
* dotted path and `context` is the context of that state, including any
|
|
24
26
|
* per-state context schema, so `Match.tag` narrows both.
|
|
27
|
+
*
|
|
28
|
+
* @experimental
|
|
25
29
|
*/
|
|
26
30
|
export type TaggedStateFrom<TSnapshot> = TSnapshot extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer TSchema> ? TaggedStateOf<TSnapshot, StateValueFromStateSchema<TSchema>, TContext, TSchema> : never;
|
|
27
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* The tagged state union of a machine.
|
|
33
|
+
*
|
|
34
|
+
* @experimental
|
|
35
|
+
*/
|
|
28
36
|
export type TaggedState<TMachine extends AnyStateMachine> = TaggedStateFrom<SnapshotFrom<TMachine>>;
|
|
29
37
|
/**
|
|
30
38
|
* Views a machine snapshot as a tagged union member for `Match.tag`,
|
|
@@ -40,6 +48,8 @@ export type TaggedState<TMachine extends AnyStateMachine> = TaggedStateFrom<Snap
|
|
|
40
48
|
* );
|
|
41
49
|
* view(taggedState(snapshot));
|
|
42
50
|
* ```
|
|
51
|
+
*
|
|
52
|
+
* @experimental
|
|
43
53
|
*/
|
|
44
54
|
export declare function taggedState<TSnapshot extends AnyMachineSnapshot>(snapshot: TSnapshot): TaggedStateFrom<TSnapshot>;
|
|
45
55
|
export {};
|
|
@@ -7,5 +7,7 @@ import type { ActorStoppedError, EventRejectedError } from "./errors.js";
|
|
|
7
7
|
* effect scheduling. Ignored events are acknowledged too. Does not await
|
|
8
8
|
* invoked work, background actions or future timers. Interrupting the waiter
|
|
9
9
|
* detaches its receipt without retracting the event.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
10
12
|
*/
|
|
11
13
|
export declare function sendAndAwait<TLogic extends AnyActorLogic>(actor: EffectActor<TLogic>, event: EventFromLogic<TLogic>): Effect.Effect<SnapshotFrom<TLogic>, ActorStoppedError | EventRejectedError>;
|
|
@@ -44,6 +44,8 @@ type RequirementsFromStateSchema<TSchema, TDepth extends Depth> = (TSchema exten
|
|
|
44
44
|
* Effect actors, the Effect logic passed inline as `invoke.src` anywhere in
|
|
45
45
|
* its state tree, and — recursively — the requirements of any child machine
|
|
46
46
|
* reached either way (capped at {@link MaxDepth} levels of machine nesting).
|
|
47
|
+
*
|
|
48
|
+
* @experimental
|
|
47
49
|
*/
|
|
48
50
|
export type RequirementsFrom<T, TDepth extends Depth = MaxDepth> = T extends EffectLogicBrand<any, infer R> ? Exclude<R, ActorScope | Scope.Scope> : T extends {
|
|
49
51
|
readonly _actionMap: infer TActionMap;
|
|
@@ -25,7 +25,11 @@ function _classPrivateFieldGet2(s, a) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
var _effectFailure = /*#__PURE__*/new WeakMap();
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Preserves an Effect failure, defect or interruption through XState error routing.
|
|
30
|
+
*
|
|
31
|
+
* @experimental
|
|
32
|
+
*/
|
|
29
33
|
class EffectFailure extends Error {
|
|
30
34
|
static is(value) {
|
|
31
35
|
return typeof value === 'object' && value !== null && _effectFailure.has(_checkInRHS(value)) && _classPrivateFieldGet2(_effectFailure, value);
|
|
@@ -39,7 +43,11 @@ class EffectFailure extends Error {
|
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Inspect `EffectFailure.cause` for interruption instead.
|
|
48
|
+
*
|
|
49
|
+
* @experimental
|
|
50
|
+
*/
|
|
43
51
|
class EffectInterruptedError extends Data.TaggedError('EffectInterruptedError') {
|
|
44
52
|
get message() {
|
|
45
53
|
return 'Effect was interrupted before the actor completed';
|
|
@@ -50,6 +58,8 @@ class EffectInterruptedError extends Data.TaggedError('EffectInterruptedError')
|
|
|
50
58
|
* Reported by `waitFor` when the actor stops or errors before a snapshot
|
|
51
59
|
* matches, and by `join` when the actor stops without output. `join` reports
|
|
52
60
|
* an errored actor's outcome instead, preserving an Effect failure's Cause.
|
|
61
|
+
*
|
|
62
|
+
* @experimental
|
|
53
63
|
*/
|
|
54
64
|
class ActorStoppedError extends Data.TaggedError('ActorStoppedError') {
|
|
55
65
|
get message() {
|
|
@@ -60,6 +70,8 @@ class ActorStoppedError extends Data.TaggedError('ActorStoppedError') {
|
|
|
60
70
|
/**
|
|
61
71
|
* Reported by the `send` atom of `createActorAtoms` when an event is sent
|
|
62
72
|
* before the actor's runtime has finished building.
|
|
73
|
+
*
|
|
74
|
+
* @experimental
|
|
63
75
|
*/
|
|
64
76
|
class NotReadyError extends Data.TaggedError('NotReadyError') {
|
|
65
77
|
get message() {
|
|
@@ -71,7 +83,11 @@ class NotReadyError extends Data.TaggedError('NotReadyError') {
|
|
|
71
83
|
function causeFromError(error) {
|
|
72
84
|
return error instanceof EffectFailure ? error.cause : Cause.fail(error);
|
|
73
85
|
}
|
|
74
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* An event rejected at the actor's delivery boundary.
|
|
88
|
+
*
|
|
89
|
+
* @experimental
|
|
90
|
+
*/
|
|
75
91
|
class EventRejectedError extends Data.TaggedError('EventRejectedError') {}
|
|
76
92
|
|
|
77
93
|
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
@@ -105,6 +121,8 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
|
105
121
|
* contract (`send`, `getSnapshot`, `subscribe`, `on`), so it works with
|
|
106
122
|
* `useSelector`, this package's actor functions and the inspection APIs, while
|
|
107
123
|
* the actor itself is driven by an Effect fiber over pure transitions.
|
|
124
|
+
*
|
|
125
|
+
* @experimental
|
|
108
126
|
*/
|
|
109
127
|
class EffectActor {
|
|
110
128
|
constructor(logic, root, snapshot, _mailbox, _stopExecution, _inspectors) {
|
|
@@ -533,12 +551,18 @@ function relayToParent(actor, event) {
|
|
|
533
551
|
}
|
|
534
552
|
}
|
|
535
553
|
|
|
536
|
-
/**
|
|
554
|
+
/**
|
|
555
|
+
* The owning Effect actor's scope, supplied by `createEffectActor`.
|
|
556
|
+
*
|
|
557
|
+
* @experimental
|
|
558
|
+
*/
|
|
537
559
|
class ActorScope extends Context.Service()('@xstate/effect/ActorScope') {}
|
|
538
560
|
|
|
539
561
|
/**
|
|
540
562
|
* Acquires resources in the owning actor's scope. Their finalizers run when
|
|
541
563
|
* that actor stops, even if the invoking task finishes or is cancelled first.
|
|
564
|
+
*
|
|
565
|
+
* @experimental
|
|
542
566
|
*/
|
|
543
567
|
function withActorScope(effect) {
|
|
544
568
|
return ActorScope.use(scope => Scope.provide(effect, scope));
|
|
@@ -547,7 +571,11 @@ function withActorScope(effect) {
|
|
|
547
571
|
const XSTATE_TIMER = 'xstate.timer';
|
|
548
572
|
const XSTATE_INIT = 'xstate.init';
|
|
549
573
|
|
|
550
|
-
/**
|
|
574
|
+
/**
|
|
575
|
+
* Options for {@link createEffectActor}.
|
|
576
|
+
*
|
|
577
|
+
* @experimental
|
|
578
|
+
*/
|
|
551
579
|
|
|
552
580
|
/**
|
|
553
581
|
* Creates and starts an actor as an Effect interpreter over pure transitions.
|
|
@@ -562,6 +590,8 @@ const XSTATE_INIT = 'xstate.init';
|
|
|
562
590
|
* The actor is a scoped resource: it stops, and every Effect it hosts is
|
|
563
591
|
* interrupted, when the enclosing `Scope` closes. The returned Effect never
|
|
564
592
|
* fails; the actor's own outcome is its snapshot status, read with `join`.
|
|
593
|
+
*
|
|
594
|
+
* @experimental
|
|
565
595
|
*/
|
|
566
596
|
function createEffectActor(logic, ...[options]) {
|
|
567
597
|
return Effect.acquireRelease(Effect.gen(function* () {
|
|
@@ -687,6 +717,8 @@ function createEffectActor(logic, ...[options]) {
|
|
|
687
717
|
};
|
|
688
718
|
})
|
|
689
719
|
}, {
|
|
720
|
+
// A live actor needs one FIFO for child events, sends and timers.
|
|
721
|
+
captureRootEvents: false,
|
|
690
722
|
inspect: event => {
|
|
691
723
|
// The pure step scope re-materializes the root ref per step and
|
|
692
724
|
// announces it again; observers should see the root once.
|
|
@@ -845,15 +877,23 @@ function createEffectActor(logic, ...[options]) {
|
|
|
845
877
|
* state has no single path, so its tag stops at the parallel state. When the
|
|
846
878
|
* machine itself is parallel, the tag is `TRootTag`: the machine id, or `''`
|
|
847
879
|
* for a machine without one.
|
|
880
|
+
*
|
|
881
|
+
* @experimental
|
|
848
882
|
*/
|
|
849
883
|
|
|
850
884
|
/**
|
|
851
885
|
* A machine snapshot as a tagged union over its states. `_tag` is the state's
|
|
852
886
|
* dotted path and `context` is the context of that state, including any
|
|
853
887
|
* per-state context schema, so `Match.tag` narrows both.
|
|
888
|
+
*
|
|
889
|
+
* @experimental
|
|
854
890
|
*/
|
|
855
891
|
|
|
856
|
-
/**
|
|
892
|
+
/**
|
|
893
|
+
* The tagged state union of a machine.
|
|
894
|
+
*
|
|
895
|
+
* @experimental
|
|
896
|
+
*/
|
|
857
897
|
|
|
858
898
|
/** Computes the dotted path tag of a state value. */
|
|
859
899
|
function stateTag(value, rootTag, prefix = '') {
|
|
@@ -882,6 +922,8 @@ function stateTag(value, rootTag, prefix = '') {
|
|
|
882
922
|
* );
|
|
883
923
|
* view(taggedState(snapshot));
|
|
884
924
|
* ```
|
|
925
|
+
*
|
|
926
|
+
* @experimental
|
|
885
927
|
*/
|
|
886
928
|
function taggedState(snapshot) {
|
|
887
929
|
return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Cause } from 'effect';
|
|
2
2
|
import { Atom, AsyncResult } from 'effect/reactivity';
|
|
3
3
|
import { StateMachine } from 'xstate';
|
|
4
|
-
import { c as createEffectActor, a as causeFromError, N as NotReadyError, t as taggedState } from './state-
|
|
5
|
-
export { N as NotReadyError } from './state-
|
|
4
|
+
import { c as createEffectActor, a as causeFromError, N as NotReadyError, t as taggedState } from './state-a2154dce.js';
|
|
5
|
+
export { N as NotReadyError } from './state-a2154dce.js';
|
|
6
6
|
import 'xstate/durable';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -11,6 +11,8 @@ import 'xstate/durable';
|
|
|
11
11
|
* framework, such as `@effect/atom-react`.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/** @experimental */
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Creates atoms for an actor that runs in an `Atom.runtime`. The runtime's
|
|
16
18
|
* Layer must provide every service the logic requires; a missing service is
|
|
@@ -22,6 +24,8 @@ import 'xstate/durable';
|
|
|
22
24
|
* when the atom is released. Wrap the atoms with `Atom.keepAlive` to pin the
|
|
23
25
|
* actor for the registry's lifetime, or with `Atom.family` to create one
|
|
24
26
|
* actor per input.
|
|
27
|
+
*
|
|
28
|
+
* @experimental
|
|
25
29
|
*/
|
|
26
30
|
function createActorAtoms(runtime, logic, ...[options]) {
|
|
27
31
|
const host = runtime;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* effect scheduling. Ignored events are acknowledged too. Does not await
|
|
4
4
|
* invoked work, background actions or future timers. Interrupting the waiter
|
|
5
5
|
* detaches its receipt without retracting the event.
|
|
6
|
+
*
|
|
7
|
+
* @experimental
|
|
6
8
|
*/
|
|
7
9
|
function sendAndAwait(actor, event) {
|
|
8
10
|
return actor._sendAndAwait(event);
|
package/dist/xstate-effect.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema, Effect, Stream, Cause, Exit, Queue, Data } from 'effect';
|
|
2
2
|
import { createStepLogic, setup } from 'xstate';
|
|
3
|
-
import { s as startHostedEffect, r as relayToParent, E as EffectFailure, A as ActorStoppedError, a as causeFromError, b as runHostedEffect } from './state-
|
|
4
|
-
export { e as ActorScope, A as ActorStoppedError, d as EffectActor, E as EffectFailure, g as EffectInterruptedError, f as EventRejectedError, c as createEffectActor, t as taggedState, w as withActorScope } from './state-
|
|
3
|
+
import { s as startHostedEffect, r as relayToParent, E as EffectFailure, A as ActorStoppedError, a as causeFromError, b as runHostedEffect } from './state-a2154dce.js';
|
|
4
|
+
export { e as ActorScope, A as ActorStoppedError, d as EffectActor, E as EffectFailure, g as EffectInterruptedError, f as EventRejectedError, c as createEffectActor, t as taggedState, w as withActorScope } from './state-a2154dce.js';
|
|
5
5
|
import { dual } from 'effect/Function';
|
|
6
6
|
import 'xstate/durable';
|
|
7
7
|
|
|
@@ -10,12 +10,16 @@ import 'xstate/durable';
|
|
|
10
10
|
* `createEffectStreamLogic` and `createEffectEventStreamLogic` convert it to a Standard
|
|
11
11
|
* Schema, so XState infers the decoded `Schema.Type` without an explicit call
|
|
12
12
|
* to `Schema.toStandardSchemaV1`.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Either an Effect {@link EffectSchema} or a Standard Schema. Every schema
|
|
17
19
|
* position in this package accepts both, so Effect schemas and schemas from
|
|
18
20
|
* other libraries can be mixed in one machine.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
19
23
|
*/
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -23,15 +27,23 @@ import 'xstate/durable';
|
|
|
23
27
|
* schema position widened to {@link EffectSchemaLike}. Covers `context`,
|
|
24
28
|
* `input`, `output` and the per-key records for `events`, `internalEvents`,
|
|
25
29
|
* `emitted` and `children`.
|
|
30
|
+
*
|
|
31
|
+
* @experimental
|
|
26
32
|
*/
|
|
27
33
|
|
|
34
|
+
/** @experimental */
|
|
35
|
+
|
|
28
36
|
/**
|
|
29
37
|
* One node of the `states` option of `setupEffect`: the schemas declared for
|
|
30
38
|
* that state, and the same shape recursively for its child states. It is
|
|
31
39
|
* XState's `SetupStateSchema` with Effect schemas allowed in every schema
|
|
32
40
|
* position.
|
|
41
|
+
*
|
|
42
|
+
* @experimental
|
|
33
43
|
*/
|
|
34
44
|
|
|
45
|
+
/** @experimental */
|
|
46
|
+
|
|
35
47
|
function isStandardSchema(value) {
|
|
36
48
|
return !!value && (typeof value === 'object' || typeof value === 'function') && '~standard' in value;
|
|
37
49
|
}
|
|
@@ -87,12 +99,16 @@ const effectLogicBrand = Symbol.for('@xstate/effect/logic');
|
|
|
87
99
|
* failure type and its Effect service requirements, which is how
|
|
88
100
|
* `RequirementsFrom` collects the `R` channel of `createEffectActor` without
|
|
89
101
|
* inspecting the logic at runtime.
|
|
102
|
+
*
|
|
103
|
+
* @experimental
|
|
90
104
|
*/
|
|
91
105
|
|
|
92
106
|
/**
|
|
93
107
|
* Snapshot of a `createEffectLogic` actor. The actor holds no context of its own: it
|
|
94
108
|
* is `active` while the Effect runs, `done` with the Effect's success value as
|
|
95
109
|
* `output`, or `error` with the original `Cause` wrapped in `EffectFailure` as `error`.
|
|
110
|
+
*
|
|
111
|
+
* @experimental
|
|
96
112
|
*/
|
|
97
113
|
|
|
98
114
|
/**
|
|
@@ -100,12 +116,16 @@ const effectLogicBrand = Symbol.for('@xstate/effect/logic');
|
|
|
100
116
|
* source the actor's `input`, its own reference (`self`), the actor `system`,
|
|
101
117
|
* and `emit` for publishing events that `actor.on(...)` and `emitted(actor)`
|
|
102
118
|
* observe.
|
|
119
|
+
*
|
|
120
|
+
* @experimental
|
|
103
121
|
*/
|
|
104
122
|
|
|
105
123
|
/**
|
|
106
124
|
* What `createEffectLogic` accepts as its Effect: either an Effect value, or a
|
|
107
125
|
* function of {@link EffectSourceArgs} returning one. The function form is
|
|
108
126
|
* called once per actor start, so it sees that actor's input.
|
|
127
|
+
*
|
|
128
|
+
* @experimental
|
|
109
129
|
*/
|
|
110
130
|
|
|
111
131
|
/**
|
|
@@ -113,18 +133,24 @@ const effectLogicBrand = Symbol.for('@xstate/effect/logic');
|
|
|
113
133
|
* ordinary XState actor logic carrying {@link EffectLogicBrand}, so a machine
|
|
114
134
|
* can invoke or spawn it, and `createEffectActor` can collect its
|
|
115
135
|
* requirements.
|
|
136
|
+
*
|
|
137
|
+
* @experimental
|
|
116
138
|
*/
|
|
117
139
|
|
|
118
140
|
/**
|
|
119
141
|
* Snapshot of a `createEffectStreamLogic` actor. `context` holds the most recent
|
|
120
142
|
* stream item, or `undefined` before the first one. The actor reaches `done`
|
|
121
143
|
* with no output when the stream completes, and `error` when it fails.
|
|
144
|
+
*
|
|
145
|
+
* @experimental
|
|
122
146
|
*/
|
|
123
147
|
|
|
124
148
|
/**
|
|
125
149
|
* Actor logic produced by `createEffectStreamLogic`. Its snapshot is an
|
|
126
150
|
* {@link EffectStreamSnapshot}, so the parent reads the latest item from the
|
|
127
151
|
* child's `context` rather than from events.
|
|
152
|
+
*
|
|
153
|
+
* @experimental
|
|
128
154
|
*/
|
|
129
155
|
|
|
130
156
|
function preserveFailure(error) {
|
|
@@ -187,6 +213,8 @@ function brandLogic(logic, error, requirements) {
|
|
|
187
213
|
* Resources belong to this task's scope and close on completion, failure or
|
|
188
214
|
* interruption. Use `withActorScope` to retain a resource until the owning
|
|
189
215
|
* Effect actor stops.
|
|
216
|
+
*
|
|
217
|
+
* @experimental
|
|
190
218
|
*/
|
|
191
219
|
|
|
192
220
|
function createEffectLogic(sourceOrConfig) {
|
|
@@ -256,6 +284,8 @@ function createEffectLogic(sourceOrConfig) {
|
|
|
256
284
|
* What `createEffectStreamLogic` and `createEffectEventStreamLogic` accept as their stream:
|
|
257
285
|
* either a Stream value, or a function of {@link EffectSourceArgs} returning
|
|
258
286
|
* one. The function form is called once per actor start.
|
|
287
|
+
*
|
|
288
|
+
* @experimental
|
|
259
289
|
*/
|
|
260
290
|
|
|
261
291
|
function resolveStreamConfig(sourceOrConfig) {
|
|
@@ -276,6 +306,8 @@ function toLogicSchemas(schemas) {
|
|
|
276
306
|
* {@link EffectSourceArgs} returning one, or a config object with `id`,
|
|
277
307
|
* `schemas`, `validator` and `stream`. Its resources close when the stream
|
|
278
308
|
* completes, fails or is interrupted.
|
|
309
|
+
*
|
|
310
|
+
* @experimental
|
|
279
311
|
*/
|
|
280
312
|
|
|
281
313
|
function createEffectStreamLogic(sourceOrConfig) {
|
|
@@ -348,6 +380,8 @@ function createEffectStreamLogic(sourceOrConfig) {
|
|
|
348
380
|
* has no output: it reaches `done` when the stream completes and `error` when
|
|
349
381
|
* it fails. Accepts the same forms as `createEffectStreamLogic`. Its resources close
|
|
350
382
|
* when the stream completes, fails or is interrupted.
|
|
383
|
+
*
|
|
384
|
+
* @experimental
|
|
351
385
|
*/
|
|
352
386
|
|
|
353
387
|
function createEffectEventStreamLogic(sourceOrConfig) {
|
|
@@ -402,11 +436,23 @@ function createEffectEventStreamLogic(sourceOrConfig) {
|
|
|
402
436
|
return brandLogic(logic, undefined, undefined);
|
|
403
437
|
}
|
|
404
438
|
|
|
405
|
-
/**
|
|
439
|
+
/**
|
|
440
|
+
* The event type accepted by an actor's `send` method.
|
|
441
|
+
*
|
|
442
|
+
* @experimental
|
|
443
|
+
*/
|
|
406
444
|
|
|
407
|
-
/**
|
|
445
|
+
/**
|
|
446
|
+
* The event type an actor emits through `actor.on(...)`.
|
|
447
|
+
*
|
|
448
|
+
* @experimental
|
|
449
|
+
*/
|
|
408
450
|
|
|
409
|
-
/**
|
|
451
|
+
/**
|
|
452
|
+
* Options for {@link waitFor}.
|
|
453
|
+
*
|
|
454
|
+
* @experimental
|
|
455
|
+
*/
|
|
410
456
|
|
|
411
457
|
const noopSubscription = {
|
|
412
458
|
unsubscribe: () => {}
|
|
@@ -439,6 +485,8 @@ function isActorRef(value) {
|
|
|
439
485
|
* is enqueued, like `actor.send(event)`, and processed on the actor's own
|
|
440
486
|
* fiber. An event that cannot be delivered (for example to a stopped actor)
|
|
441
487
|
* is reported as a dead letter, observable with {@link deadLetters}.
|
|
488
|
+
*
|
|
489
|
+
* @experimental
|
|
442
490
|
*/
|
|
443
491
|
const send = dual(2, (actor, event) => Effect.sync(() => {
|
|
444
492
|
actor.send(event);
|
|
@@ -449,6 +497,8 @@ const send = dual(2, (actor, event) => Effect.sync(() => {
|
|
|
449
497
|
* when the actor completes or stops, and emits the error snapshot before
|
|
450
498
|
* ending when the actor errors. Interrupting the stream unsubscribes from the
|
|
451
499
|
* actor.
|
|
500
|
+
*
|
|
501
|
+
* @experimental
|
|
452
502
|
*/
|
|
453
503
|
function snapshots(actor) {
|
|
454
504
|
return Stream.callback(queue => Effect.acquireRelease(Effect.sync(() => {
|
|
@@ -480,6 +530,8 @@ function snapshots(actor) {
|
|
|
480
530
|
* Streams every event an actor emits, as delivered to `actor.on('*', …)`. The
|
|
481
531
|
* stream ends when the actor completes, errors or stops. Interrupting the
|
|
482
532
|
* stream removes the listener.
|
|
533
|
+
*
|
|
534
|
+
* @experimental
|
|
483
535
|
*/
|
|
484
536
|
function emitted(actor) {
|
|
485
537
|
return Stream.callback(queue => Effect.acquireRelease(Effect.sync(() => {
|
|
@@ -511,6 +563,8 @@ function emitted(actor) {
|
|
|
511
563
|
* `ActorStoppedError` if the actor stops or errors first, and with
|
|
512
564
|
* `Cause.TimeoutError` when `options.timeout` elapses. Interrupting the Effect
|
|
513
565
|
* unsubscribes from the actor.
|
|
566
|
+
*
|
|
567
|
+
* @experimental
|
|
514
568
|
*/
|
|
515
569
|
const waitFor = dual(args => isActorRef(args[0]), (actor, predicate, options) => {
|
|
516
570
|
const waiting = Effect.callback(resume => {
|
|
@@ -567,6 +621,8 @@ const waitFor = dual(args => isActorRef(args[0]), (actor, predicate, options) =>
|
|
|
567
621
|
* when it is done, replays an Effect actor's original Cause when it errors, and fails with
|
|
568
622
|
* `ActorStoppedError` when it stops without output. Waits for a still-active
|
|
569
623
|
* actor to settle. Ordinary XState errors remain typed failures.
|
|
624
|
+
*
|
|
625
|
+
* @experimental
|
|
570
626
|
*/
|
|
571
627
|
function join(actor) {
|
|
572
628
|
return Effect.callback(resume => {
|
|
@@ -614,6 +670,8 @@ function join(actor) {
|
|
|
614
670
|
* Streams the inspection events of the actor's system, as delivered to
|
|
615
671
|
* `system.inspect(…)`. The stream runs until it is interrupted or its scope
|
|
616
672
|
* closes.
|
|
673
|
+
*
|
|
674
|
+
* @experimental
|
|
617
675
|
*/
|
|
618
676
|
function inspect(actor) {
|
|
619
677
|
return Stream.callback(queue => Effect.acquireRelease(Effect.sync(() => {
|
|
@@ -633,6 +691,8 @@ function inspect(actor) {
|
|
|
633
691
|
* events and internal events sent from outside their owner. A dead letter is
|
|
634
692
|
* not an actor error. The stream runs until it is interrupted or its scope
|
|
635
693
|
* closes.
|
|
694
|
+
*
|
|
695
|
+
* @experimental
|
|
636
696
|
*/
|
|
637
697
|
function deadLetters(actor) {
|
|
638
698
|
return Stream.callback(queue => Effect.acquireRelease(Effect.sync(() => actor.system.onRejectedEvent(rejection => {
|
|
@@ -648,6 +708,8 @@ function deadLetters(actor) {
|
|
|
648
708
|
* the actor itself and its family (`self`, `parent`, `children`), the
|
|
649
709
|
* registered `actions`, `actors`, `guards` and `delays`, the actor `system`,
|
|
650
710
|
* and the `params` and `output` the transition passed along.
|
|
711
|
+
*
|
|
712
|
+
* @experimental
|
|
651
713
|
*/
|
|
652
714
|
|
|
653
715
|
/**
|
|
@@ -656,6 +718,8 @@ function deadLetters(actor) {
|
|
|
656
718
|
* enqueued, and returns an Effect that runs afterwards in the actor's Effect
|
|
657
719
|
* context. The Effect is interrupted when the actor stops; its failures and
|
|
658
720
|
* defects route to the state's `onError`.
|
|
721
|
+
*
|
|
722
|
+
* @experimental
|
|
659
723
|
*/
|
|
660
724
|
|
|
661
725
|
/**
|
|
@@ -663,6 +727,8 @@ function deadLetters(actor) {
|
|
|
663
727
|
* that also accepts Effect schemas and Effect-returning actions. Call
|
|
664
728
|
* `createMachine` on it to build a machine whose registered actions and actors
|
|
665
729
|
* contribute to `RequirementsFrom`.
|
|
730
|
+
*
|
|
731
|
+
* @experimental
|
|
666
732
|
*/
|
|
667
733
|
|
|
668
734
|
function wrapActions(actions) {
|
|
@@ -719,6 +785,8 @@ function decorateEffectSetup(effectSetup) {
|
|
|
719
785
|
* runs in the actor's Effect context. Everything else, including `actors`,
|
|
720
786
|
* `guards`, `delays` and `extend`, behaves as in `setup`. Machines built from
|
|
721
787
|
* it must be started with `createEffectActor`.
|
|
788
|
+
*
|
|
789
|
+
* @experimental
|
|
722
790
|
*/
|
|
723
791
|
|
|
724
792
|
function setupEffect(config = {}) {
|
|
@@ -730,7 +798,11 @@ function setupEffect(config = {}) {
|
|
|
730
798
|
}));
|
|
731
799
|
}
|
|
732
800
|
|
|
733
|
-
/**
|
|
801
|
+
/**
|
|
802
|
+
* A malformed transport, unsupported JSON value or missing persistence metadata.
|
|
803
|
+
*
|
|
804
|
+
* @experimental
|
|
805
|
+
*/
|
|
734
806
|
class SnapshotCodecError extends Data.TaggedError('SnapshotCodecError') {
|
|
735
807
|
get message() {
|
|
736
808
|
return `${this.stage} at ${this.path}: ${this.reason}`;
|
|
@@ -845,6 +917,8 @@ function checked(stage, run) {
|
|
|
845
917
|
* Binds a full bidirectional snapshot schema to a versioned machine. The schema
|
|
846
918
|
* owns rich values and supported historical versions. Decoding never migrates;
|
|
847
919
|
* restore or `machineVersions` remains responsible for migration.
|
|
920
|
+
*
|
|
921
|
+
* @experimental
|
|
848
922
|
*/
|
|
849
923
|
function createSnapshotCodec(machine, schema) {
|
|
850
924
|
const format = '@xstate/effect/snapshot';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xstate/effect",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Effect integration for XState",
|
|
6
6
|
"keywords": [
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@oxlint/plugins": "^1.76.0",
|
|
35
35
|
"effect": "^4.0.0",
|
|
36
|
-
"xstate": "^6.0.0-alpha.
|
|
36
|
+
"xstate": "^6.0.0-alpha.73"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@oxlint/plugins": "^1.76.0",
|
|
40
40
|
"effect": "4.0.6",
|
|
41
41
|
"fast-check": "4.10.2",
|
|
42
42
|
"@xstate/test": "^2.0.0-alpha.4",
|
|
43
|
-
"xstate": "^6.0.0-alpha.
|
|
43
|
+
"xstate": "^6.0.0-alpha.73"
|
|
44
44
|
},
|
|
45
45
|
"preconstruct": {
|
|
46
46
|
"entrypoints": [
|