@xstate/effect 1.0.0-alpha.9 → 1.0.0-beta.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/README.md +20 -9
- package/dist/declarations/src/actor.d.ts +33 -7
- package/dist/declarations/src/actorScope.d.ts +7 -1
- package/dist/declarations/src/atom.d.ts +11 -9
- package/dist/declarations/src/createEffectActor.d.ts +16 -5
- package/dist/declarations/src/effectActor.d.ts +20 -11
- package/dist/declarations/src/effectLogic.d.ts +30 -10
- package/dist/declarations/src/errors.d.ts +37 -4
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/oxlint.d.ts +3 -0
- package/dist/declarations/src/persistence.d.ts +45 -0
- package/dist/declarations/src/schema.d.ts +10 -0
- package/dist/declarations/src/setupEffect.d.ts +56 -13
- package/dist/declarations/src/state.d.ts +11 -1
- package/dist/declarations/src/test.d.ts +13 -0
- package/dist/declarations/src/types.d.ts +3 -2
- package/dist/{state-a2e5cb31.js → state-a2154dce.js} +240 -73
- package/dist/xstate-effect-atom.js +14 -8
- package/dist/xstate-effect-oxlint.d.ts +3 -0
- package/dist/xstate-effect-oxlint.js +126 -0
- package/dist/xstate-effect-test.d.ts +2 -0
- package/dist/xstate-effect-test.js +13 -0
- package/dist/xstate-effect.js +286 -35
- package/package.json +17 -5
- package/dist/declarations/src/brands.d.ts +0 -1
|
@@ -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
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { type ActorLogicValidator, type AnyActorRef, type EventObject, type MachineContext, type SetupConfig, type SetupReturn, type SetupSchemas, type SetupStateSchema, type Sources, type SystemRegistry, type SystemRuntime } from 'xstate';
|
|
3
|
-
import { effectActionBrand } from "./brands.js";
|
|
2
|
+
import { type ActorLogicValidator, type AnyActorRef, type EventObject, type MachineContext, type InferEvents, type StandardSchemaV1, type SetupConfig, type SetupReturn, type SetupSchemas, type SetupStateSchema, type Sources, type SystemRegistry, type SystemRuntime } from 'xstate';
|
|
4
3
|
import type { EffectRequirements } from "./types.js";
|
|
5
4
|
import { type EffectSetupSchemas, type EffectSetupStateSchema, type ToStandardSetupSchemas, type ToStandardSetupStates, type ValidateEffectSetupSchemas, type ValidateEffectSetupStates } from "./schema.js";
|
|
6
5
|
/**
|
|
@@ -9,6 +8,8 @@ import { type EffectSetupSchemas, type EffectSetupStateSchema, type ToStandardSe
|
|
|
9
8
|
* the actor itself and its family (`self`, `parent`, `children`), the
|
|
10
9
|
* registered `actions`, `actors`, `guards` and `delays`, the actor `system`,
|
|
11
10
|
* and the `params` and `output` the transition passed along.
|
|
11
|
+
*
|
|
12
|
+
* @experimental
|
|
12
13
|
*/
|
|
13
14
|
export type EffectActionArgs<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> = {
|
|
14
15
|
readonly context: TContext;
|
|
@@ -30,22 +31,58 @@ export type EffectActionArgs<TContext extends MachineContext = MachineContext, T
|
|
|
30
31
|
* enqueued, and returns an Effect that runs afterwards in the actor's Effect
|
|
31
32
|
* context. The Effect is interrupted when the actor stops; its failures and
|
|
32
33
|
* defects route to the state's `onError`.
|
|
34
|
+
*
|
|
35
|
+
* @experimental
|
|
33
36
|
*/
|
|
34
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>;
|
|
35
38
|
type AnyEffectAction = EffectAction<any, any, any, any>;
|
|
39
|
+
type EffectActionSource = (...args: never[]) => Effect.Effect<void, any, any>;
|
|
40
|
+
type ActionContext<TSchemas> = TSchemas extends {
|
|
41
|
+
context: infer TContext extends StandardSchemaV1;
|
|
42
|
+
} ? Extract<StandardSchemaV1.InferOutput<TContext>, MachineContext> : Record<string, unknown>;
|
|
43
|
+
type ActionEvents<TSchemas> = (TSchemas extends {
|
|
44
|
+
events: infer TEvents extends Record<string, StandardSchemaV1>;
|
|
45
|
+
} ? InferEvents<TEvents> : EventObject) | (TSchemas extends {
|
|
46
|
+
internalEvents: infer TEvents extends Record<string, StandardSchemaV1>;
|
|
47
|
+
} ? string extends keyof TEvents ? never : InferEvents<TEvents> : never);
|
|
48
|
+
type ActionInput<TSchemas, TKey extends PropertyKey> = TSchemas extends {
|
|
49
|
+
actions: {
|
|
50
|
+
[K in TKey]: {
|
|
51
|
+
params: infer TParams extends StandardSchemaV1;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
} ? StandardSchemaV1.InferOutput<TParams> & Pick<EffectActionArgs, 'self'> : EffectActionArgs<ActionContext<TSchemas>, ActionEvents<TSchemas>>;
|
|
55
|
+
type ActionSources<TSchemas, TActionMap> = {
|
|
56
|
+
[K in keyof TActionMap]: (args: ActionInput<TSchemas, K>) => Effect.Effect<void, any, any>;
|
|
57
|
+
};
|
|
58
|
+
type AnnotatedActionSources<TSchemas, TActionMap> = TActionMap extends {
|
|
59
|
+
[K in keyof TActionMap]: TSchemas extends {
|
|
60
|
+
actions: {
|
|
61
|
+
[P in K]: {
|
|
62
|
+
params: StandardSchemaV1;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
} ? ActionSources<TSchemas, TActionMap>[K] : AnyEffectAction;
|
|
66
|
+
} ? unknown : never;
|
|
36
67
|
type EffectActionRequirements<TAction> = TAction extends (...args: any[]) => infer TResult ? EffectRequirements<TResult> : never;
|
|
37
|
-
type CoreEffectAction<TAction> = TAction extends (...args: infer TArgs) => any ? ((...args: TArgs) => void) & {
|
|
38
|
-
readonly
|
|
68
|
+
type CoreEffectAction<TAction, TInput = never> = TAction extends (...args: infer TArgs) => any ? ((...args: [TInput] extends [never] ? TArgs : [args: TInput]) => void) & {
|
|
69
|
+
readonly '~effectRequirements'?: EffectActionRequirements<TAction>;
|
|
39
70
|
} : never;
|
|
40
|
-
type CoreEffectActionMap<TActionMap> = {
|
|
41
|
-
[K in keyof TActionMap]: CoreEffectAction<TActionMap[K]
|
|
71
|
+
type CoreEffectActionMap<TActionMap, TSchemas> = {
|
|
72
|
+
[K in keyof TActionMap]: CoreEffectAction<TActionMap[K], TSchemas extends {
|
|
73
|
+
actions: {
|
|
74
|
+
[P in K]: {
|
|
75
|
+
params: StandardSchemaV1;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
} ? ActionInput<TSchemas, K> : never>;
|
|
42
79
|
};
|
|
43
|
-
type EffectSetupConfig<TSchemas extends EffectSetupSchemas, TStates extends Record<string, EffectSetupStateSchema>, TActionMap extends Record<string,
|
|
80
|
+
type EffectSetupConfig<TSchemas extends EffectSetupSchemas, TStates extends Record<string, EffectSetupStateSchema>, TActionMap extends Record<string, EffectActionSource>, TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TValidator extends ActorLogicValidator | undefined, TSourceSchemas extends SetupSchemas = ToStandardSetupSchemas<TSchemas>, TContextualActions extends boolean = true> = {
|
|
44
81
|
validator?: TValidator;
|
|
45
|
-
actions?: TActionMap &
|
|
82
|
+
actions?: TActionMap & (TContextualActions extends true ? ActionSources<NoInfer<TSourceSchemas>, TActionMap> : AnnotatedActionSources<NoInfer<TSourceSchemas>, TActionMap>);
|
|
46
83
|
actors?: TActorMap;
|
|
47
|
-
guards?: NonNullable<SetupConfig<TSourceSchemas, ToStandardSetupStates<TStates>, CoreEffectActionMap<TActionMap>, TActorMap, TGuardMap, TDelayMap, TValidator>['guards']>;
|
|
48
|
-
delays?: NonNullable<SetupConfig<TSourceSchemas, ToStandardSetupStates<TStates>, CoreEffectActionMap<TActionMap>, TActorMap, TGuardMap, TDelayMap, TValidator>['delays']>;
|
|
84
|
+
guards?: NonNullable<SetupConfig<TSourceSchemas, ToStandardSetupStates<TStates>, CoreEffectActionMap<TActionMap, TSourceSchemas>, TActorMap, TGuardMap, TDelayMap, TValidator>['guards']>;
|
|
85
|
+
delays?: NonNullable<SetupConfig<TSourceSchemas, ToStandardSetupStates<TStates>, CoreEffectActionMap<TActionMap, TSourceSchemas>, TActorMap, TGuardMap, TDelayMap, TValidator>['delays']>;
|
|
49
86
|
schemas?: TSchemas & ([TValidator] extends [ActorLogicValidator] ? ValidateEffectSetupSchemas<TSchemas> : unknown);
|
|
50
87
|
states?: TStates & ([TValidator] extends [ActorLogicValidator] ? ValidateEffectSetupStates<TStates> : unknown);
|
|
51
88
|
};
|
|
@@ -71,15 +108,18 @@ type ExtendValidatorConfig<TExtension> = [TExtension] extends [
|
|
|
71
108
|
} : {
|
|
72
109
|
validator: TExtension;
|
|
73
110
|
};
|
|
74
|
-
type EffectSetupExtensionConfig<TBaseSchemas extends SetupSchemas, TBaseStates extends Record<string, SetupStateSchema>, TBaseValidator extends ActorLogicValidator | undefined, TExtensionSchemas extends EffectSetupSchemas, TExtensionStates extends Record<string, EffectSetupStateSchema>, TExtensionActionMap extends Record<string,
|
|
111
|
+
type EffectSetupExtensionConfig<TBaseSchemas extends SetupSchemas, TBaseStates extends Record<string, SetupStateSchema>, TBaseValidator extends ActorLogicValidator | undefined, TExtensionSchemas extends EffectSetupSchemas, TExtensionStates extends Record<string, EffectSetupStateSchema>, TExtensionActionMap extends Record<string, EffectActionSource>, TExtensionActorMap extends Sources['actors'], TExtensionGuardMap extends Sources['guards'], TExtensionDelayMap extends Sources['delays'], TExtensionValidator extends ActorLogicValidator | undefined | InheritedEffectValidator, TContextualActions extends boolean = true> = EffectSetupConfig<TExtensionSchemas, TExtensionStates, TExtensionActionMap, TExtensionActorMap, TExtensionGuardMap, TExtensionDelayMap, ResolveExtendedValidator<TBaseValidator, TExtensionValidator>, MergeSetupSchemas<TBaseSchemas, ToStandardSetupSchemas<TExtensionSchemas>>, TContextualActions> & ExtendValidatorConfig<TExtensionValidator> & RuntimeValidationCompatibility<NoInfer<TBaseSchemas>, NoInfer<TBaseStates>, ResolveExtendedValidator<TBaseValidator, TExtensionValidator>>;
|
|
75
112
|
/**
|
|
76
113
|
* What `setupEffect` returns: the XState `SetupReturn` with an `extend` method
|
|
77
114
|
* that also accepts Effect schemas and Effect-returning actions. Call
|
|
78
115
|
* `createMachine` on it to build a machine whose registered actions and actors
|
|
79
116
|
* contribute to `RequirementsFrom`.
|
|
117
|
+
*
|
|
118
|
+
* @experimental
|
|
80
119
|
*/
|
|
81
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'> & {
|
|
82
|
-
extend<const TExtensionSchemas extends EffectSetupSchemas = {}, const TExtensionStates extends Record<string, EffectSetupStateSchema> = {}, TExtensionActionMap extends Record<string,
|
|
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
|
+
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, false>): 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>>;
|
|
83
123
|
};
|
|
84
124
|
/**
|
|
85
125
|
* The Effect-aware form of XState's `setup`. It accepts Effect `Schema` values
|
|
@@ -88,7 +128,10 @@ export type EffectSetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
88
128
|
* runs in the actor's Effect context. Everything else, including `actors`,
|
|
89
129
|
* `guards`, `delays` and `extend`, behaves as in `setup`. Machines built from
|
|
90
130
|
* it must be started with `createEffectActor`.
|
|
131
|
+
*
|
|
132
|
+
* @experimental
|
|
91
133
|
*/
|
|
92
134
|
export declare function setupEffect(): EffectSetupReturn;
|
|
93
|
-
export declare function setupEffect<const TSchemas extends EffectSetupSchemas = {}, const TStates extends Record<string, EffectSetupStateSchema> = Record<string, EffectSetupStateSchema>, TActionMap extends Record<string,
|
|
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>;
|
|
136
|
+
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, ToStandardSetupSchemas<TSchemas>, false>): EffectSetupReturn<ToStandardSetupStates<TStates>, ToStandardSetupSchemas<TSchemas>, CoreEffectActionMap<TActionMap, ToStandardSetupSchemas<TSchemas>>, TActorMap, TGuardMap, TDelayMap, Extract<keyof TDelayMap, string>, TValidator>;
|
|
94
137
|
export {};
|
|
@@ -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 {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Effect } from 'effect';
|
|
2
|
+
import type { AnyActorLogic, EventFromLogic, SnapshotFrom } from 'xstate';
|
|
3
|
+
import type { EffectActor } from "./effectActor.js";
|
|
4
|
+
import type { ActorStoppedError, EventRejectedError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Sends one mailbox item and awaits its macrostep publication and immediate
|
|
7
|
+
* effect scheduling. Ignored events are acknowledged too. Does not await
|
|
8
|
+
* invoked work, background actions or future timers. Interrupting the waiter
|
|
9
|
+
* detaches its receipt without retracting the event.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
export declare function sendAndAwait<TLogic extends AnyActorLogic>(actor: EffectActor<TLogic>, event: EventFromLogic<TLogic>): Effect.Effect<SnapshotFrom<TLogic>, ActorStoppedError | EventRejectedError>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Effect, Scope } from 'effect';
|
|
2
2
|
import type { EffectLogicBrand } from "./effectLogic.js";
|
|
3
|
-
import { effectActionBrand } from "./brands.js";
|
|
4
3
|
import type { ActorScope } from "./actorScope.js";
|
|
5
4
|
/** The `R` channel of an Effect type, or `never` for anything else. */
|
|
6
5
|
export type EffectRequirements<T> = T extends Effect.Effect<any, any, infer R> ? R : never;
|
|
7
6
|
type RequirementsFromActions<T> = T extends Record<string, (...args: any[]) => any> ? T[keyof T] extends infer TAction ? TAction extends {
|
|
8
|
-
readonly
|
|
7
|
+
readonly '~effectRequirements'?: infer R;
|
|
9
8
|
} ? unknown extends R ? EffectRequirements<TAction extends (...args: any[]) => infer TResult ? TResult : never> : Exclude<R, undefined> : EffectRequirements<TAction extends (...args: any[]) => infer TResult ? TResult : never> : never : never;
|
|
10
9
|
/**
|
|
11
10
|
* Recursion budget for walking registered child machines. A machine cannot
|
|
@@ -45,6 +44,8 @@ type RequirementsFromStateSchema<TSchema, TDepth extends Depth> = (TSchema exten
|
|
|
45
44
|
* Effect actors, the Effect logic passed inline as `invoke.src` anywhere in
|
|
46
45
|
* its state tree, and — recursively — the requirements of any child machine
|
|
47
46
|
* reached either way (capped at {@link MaxDepth} levels of machine nesting).
|
|
47
|
+
*
|
|
48
|
+
* @experimental
|
|
48
49
|
*/
|
|
49
50
|
export type RequirementsFrom<T, TDepth extends Depth = MaxDepth> = T extends EffectLogicBrand<any, infer R> ? Exclude<R, ActorScope | Scope.Scope> : T extends {
|
|
50
51
|
readonly _actionMap: infer TActionMap;
|