1 | import type { MachineSnapshot } from "./State.js";
|
2 | import type { StateMachine } from "./StateMachine.js";
|
3 | import type { StateNode } from "./StateNode.js";
|
4 | import { AssignArgs } from "./actions/assign.js";
|
5 | import { PromiseActorLogic } from "./actors/promise.js";
|
6 | import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
|
7 | import type { Actor } from "./createActor.js";
|
8 | import { Spawner } from "./spawn.js";
|
9 | import { AnyActorSystem, Clock } from './system.js';
|
10 | import { InspectionEvent } from "./inspection.js";
|
11 | import { ExecutableRaiseAction } from "./actions/raise.js";
|
12 | import { ExecutableSendToAction } from "./actions/send.js";
|
13 | export type Identity<T> = {
|
14 | [K in keyof T]: T[K];
|
15 | };
|
16 | export type HomomorphicPick<T, K extends keyof any> = {
|
17 | [P in keyof T as P & K]: T[P];
|
18 | };
|
19 | export type HomomorphicOmit<T, K extends keyof any> = {
|
20 | [P in keyof T as Exclude<P, K>]: T[P];
|
21 | };
|
22 | export type Invert<T extends Record<PropertyKey, PropertyKey>> = {
|
23 | [K in keyof T as T[K]]: K;
|
24 | };
|
25 | export type GetParameterizedParams<T extends ParameterizedObject | undefined> = T extends any ? ('params' extends keyof T ? T['params'] : undefined) : never;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export type NonReducibleUnknown = {} | null | undefined;
|
43 | export type AnyFunction = (...args: any[]) => any;
|
44 | type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
45 | export type IsNever<T> = [T] extends [never] ? true : false;
|
46 | export type IsNotNever<T> = [T] extends [never] ? false : true;
|
47 | export type Compute<A> = {
|
48 | [K in keyof A]: A[K];
|
49 | } & unknown;
|
50 | export type Prop<T, K> = K extends keyof T ? T[K] : never;
|
51 | export type Values<T> = T[keyof T];
|
52 | export type Elements<T> = T[keyof T & `${number}`];
|
53 | export type Merge<M, N> = Omit<M, keyof N> & N;
|
54 | export type IndexByProp<T extends Record<P, string>, P extends keyof T> = {
|
55 | [E in T as E[P]]: E;
|
56 | };
|
57 | export type IndexByType<T extends {
|
58 | type: string;
|
59 | }> = IndexByProp<T, 'type'>;
|
60 | export type Equals<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
|
61 | export type IsAny<T> = Equals<T, any>;
|
62 | export type Cast<A, B> = A extends B ? A : B;
|
63 | export type DoNotInfer<T> = [T][T extends any ? 0 : any];
|
64 |
|
65 | export type NoInfer<T> = DoNotInfer<T>;
|
66 | export type LowInfer<T> = T & NonNullable<unknown>;
|
67 | export type MetaObject = Record<string, any>;
|
68 | export type Lazy<T> = () => T;
|
69 | export type MaybeLazy<T> = T | Lazy<T>;
|
70 |
|
71 | export type EventObject = {
|
72 |
|
73 | type: string;
|
74 | };
|
75 | export interface AnyEventObject extends EventObject {
|
76 | [key: string]: any;
|
77 | }
|
78 | export interface ParameterizedObject {
|
79 | type: string;
|
80 | params?: NonReducibleUnknown;
|
81 | }
|
82 | export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> {
|
83 | context: TContext;
|
84 | event: TExpressionEvent;
|
85 | self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>,
|
86 | StateValue, string, unknown, TODO,
|
87 | TODO>, TEvent, AnyEventObject>;
|
88 | system: AnyActorSystem;
|
89 | }
|
90 | export type MachineContext = Record<string, any>;
|
91 | export interface ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
|
92 | }
|
93 | export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
94 | export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
95 | status: 'done';
|
96 | })['output'] : T extends ActorRef<infer TSnapshot, infer _TEvent, infer _TEmitted> ? (TSnapshot & {
|
97 | status: 'done';
|
98 | })['output'] : never;
|
99 | export type ActionFunction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = {
|
100 | (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
101 | _out_TEvent?: TEvent;
|
102 | _out_TActor?: TActor;
|
103 | _out_TAction?: TAction;
|
104 | _out_TGuard?: TGuard;
|
105 | _out_TDelay?: TDelay;
|
106 | _out_TEmitted?: TEmitted;
|
107 | };
|
108 | export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? undefined extends T['params'] ? T['type'] : never : never;
|
109 | export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
110 | export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
111 | type: T['type'];
|
112 | params?: T['params'] | (({ context, event }: {
|
113 | context: TContext;
|
114 | event: TExpressionEvent;
|
115 | }) => T['params']);
|
116 | }, undefined extends T['params'] ? false : true> : never;
|
117 | export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = NoRequiredParams<TAction> | WithDynamicParams<TContext, TExpressionEvent, TAction> | ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>;
|
118 | export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string, EventObject>;
|
119 | export type Actions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
120 | export type StateKey = string | AnyMachineSnapshot;
|
121 | export interface StateValueMap {
|
122 | [key: string]: StateValue | undefined;
|
123 | }
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | export type StateValue = string | StateValueMap;
|
134 | export type TransitionTarget = SingleOrArray<string>;
|
135 | export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject = EventObject, TMeta extends MetaObject = MetaObject> {
|
136 | guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
137 | actions?: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
138 | reenter?: boolean;
|
139 | target?: TransitionTarget | undefined;
|
140 | meta?: TMeta;
|
141 | description?: string;
|
142 | }
|
143 | export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> extends TransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TODO, // TEmitted
|
144 | TODO> {
|
145 | target: string;
|
146 | }
|
147 | export type AnyTransitionConfig = TransitionConfig<any,
|
148 | any,
|
149 | any,
|
150 | any,
|
151 | any,
|
152 | any,
|
153 | any,
|
154 | any,
|
155 | any>;
|
156 | export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject> {
|
157 | id: string;
|
158 | systemId: string | undefined;
|
159 |
|
160 | src: AnyActorLogic | string;
|
161 | input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
162 | |
163 |
|
164 |
|
165 |
|
166 | onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
167 | |
168 |
|
169 |
|
170 |
|
171 | onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
172 | onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
173 | toJSON: () => Omit<InvokeDefinition<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>, 'onDone' | 'onError' | 'toJSON'>;
|
174 | }
|
175 | type Delay<TDelay extends string> = TDelay | number;
|
176 | export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = {
|
177 | [K in Delay<TDelay>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TODO,
|
178 | TODO>>;
|
179 | };
|
180 | export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | ({} & string);
|
181 | export type SingleOrArray<T> = readonly T[] | T;
|
182 | export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {
|
183 | [K in string]: StateNode<TContext, TEvent>;
|
184 | };
|
185 | export type StatesConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> = {
|
186 | [K in string]: StateNodeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TOutput, TEmitted, TMeta>;
|
187 | };
|
188 | export type StatesDefinition<TContext extends MachineContext, TEvent extends EventObject> = {
|
189 | [K in string]: StateNodeDefinition<TContext, TEvent>;
|
190 | };
|
191 | export type TransitionConfigTarget = string | undefined;
|
192 | export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
193 | export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject> = {
|
194 | [K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
195 | };
|
196 | type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
197 | export type EventDescriptor<TEvent extends EventObject> = TEvent['type'] | PartialEventDescriptor<TEvent['type']> | '*';
|
198 | type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
|
199 | export type IsLiteralString<T extends string> = string extends T ? false : true;
|
200 | type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
201 | src: infer TSrc;
|
202 | } ? Compute<{
|
203 | systemId?: string;
|
204 |
|
205 | src: TSrc;
|
206 | |
207 |
|
208 |
|
209 |
|
210 | id?: TSpecificActor['id'];
|
211 | input?: Mapper<TContext, TEvent, InputFrom<TSpecificActor['logic']>, TEvent> | InputFrom<TSpecificActor['logic']>;
|
212 | |
213 |
|
214 |
|
215 |
|
216 | onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
217 | |
218 |
|
219 |
|
220 |
|
221 | onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
222 | onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
223 | } & {
|
224 | [K in RequiredActorOptions<TSpecificActor>]: unknown;
|
225 | }> | {
|
226 | id?: never;
|
227 | systemId?: string;
|
228 | src: AnyActorLogic;
|
229 | input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
230 | onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
231 | onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
232 | onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
233 | } : never;
|
234 | export type InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta, TActor> : {
|
235 | |
236 |
|
237 |
|
238 |
|
239 | id?: string;
|
240 | systemId?: string;
|
241 |
|
242 | src: AnyActorLogic | string;
|
243 | input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
244 | |
245 |
|
246 |
|
247 |
|
248 | onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<any>,
|
249 | TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
250 | |
251 |
|
252 |
|
253 |
|
254 | onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
255 | onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
256 | };
|
257 | export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
|
258 | export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject> {
|
259 |
|
260 | initial?: InitialTransitionConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay> | string | undefined;
|
261 | |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
271 | |
272 |
|
273 |
|
274 |
|
275 | history?: 'shallow' | 'deep' | boolean | undefined;
|
276 | |
277 |
|
278 |
|
279 |
|
280 | states?: StatesConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, NonReducibleUnknown, TEmitted, TMeta> | undefined;
|
281 | |
282 |
|
283 |
|
284 |
|
285 | invoke?: SingleOrArray<InvokeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
286 |
|
287 | on?: TransitionsConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
288 |
|
289 | entry?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
290 |
|
291 | exit?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
292 | |
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneStateEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>> | undefined;
|
300 | |
301 |
|
302 |
|
303 |
|
304 |
|
305 | after?: DelayedTransitions<TContext, TEvent, TActor, TAction, TGuard, TDelay>;
|
306 | |
307 |
|
308 |
|
309 |
|
310 | always?: TransitionConfigOrTarget<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
311 | parent?: StateNode<TContext, TEvent>;
|
312 | |
313 |
|
314 |
|
315 |
|
316 | meta?: TMeta;
|
317 | |
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | output?: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
325 | |
326 |
|
327 |
|
328 |
|
329 | id?: string | undefined;
|
330 | |
331 |
|
332 |
|
333 |
|
334 | order?: number;
|
335 | |
336 |
|
337 |
|
338 |
|
339 | tags?: SingleOrArray<TTag>;
|
340 |
|
341 | description?: string;
|
342 |
|
343 | target?: string;
|
344 | }
|
345 | export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any, any,
|
346 | any>;
|
347 | export interface StateNodeDefinition<TContext extends MachineContext, TEvent extends EventObject> {
|
348 | id: string;
|
349 | version?: string | undefined;
|
350 | key: string;
|
351 | type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
352 | initial: InitialTransitionDefinition<TContext, TEvent> | undefined;
|
353 | history: boolean | 'shallow' | 'deep' | undefined;
|
354 | states: StatesDefinition<TContext, TEvent>;
|
355 | on: TransitionDefinitionMap<TContext, TEvent>;
|
356 | transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
357 | entry: UnknownAction[];
|
358 | exit: UnknownAction[];
|
359 | meta: any;
|
360 | order: number;
|
361 | output?: StateNodeConfig<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string, string, unknown, EventObject,
|
362 | any>['output'];
|
363 | invoke: Array<InvokeDefinition<TContext, TEvent, TODO, TODO, TODO, TODO, TODO,
|
364 | TODO>>;
|
365 | description?: string;
|
366 | tags: string[];
|
367 | }
|
368 | export interface StateMachineDefinition<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeDefinition<TContext, TEvent> {
|
369 | }
|
370 | export type AnyStateNode = StateNode<any, any>;
|
371 | export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
372 | export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any, any>;
|
373 |
|
374 | export type AnyState = AnyMachineSnapshot;
|
375 | export type AnyStateMachine = StateMachine<any,
|
376 | any,
|
377 | any,
|
378 | any,
|
379 | any,
|
380 | any,
|
381 | any,
|
382 | any,
|
383 | any,
|
384 | any,
|
385 | any,
|
386 | any,
|
387 | any,
|
388 | any>;
|
389 | export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
390 | export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO, TODO, // emitted
|
391 | TODO> {
|
392 | initial?: undefined;
|
393 | parallel?: false | undefined;
|
394 | states?: undefined;
|
395 | onDone?: undefined;
|
396 | }
|
397 | export interface HistoryStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends AtomicStateNodeConfig<TContext, TEvent> {
|
398 | history: 'shallow' | 'deep' | true;
|
399 | target: string | undefined;
|
400 | }
|
401 | export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO, TODO,
|
402 | TODO>;
|
403 | export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TEmitted extends EventObject = EventObject> = {
|
404 | [K in TAction['type']]?: ActionFunction<TContext, TEvent, TEvent, GetParameterizedParams<TAction extends {
|
405 | type: K;
|
406 | } ? TAction : never>, TActor, TAction, TGuard, TDelay, TEmitted>;
|
407 | };
|
408 | type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuard extends ParameterizedObject> = {
|
409 | [K in TGuard['type']]?: GuardPredicate<TContext, TEvent, GetParameterizedParams<TGuard extends {
|
410 | type: K;
|
411 | } ? TGuard : never>, TGuard>;
|
412 | };
|
413 | export type DelayFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject> = Record<string, DelayConfig<TContext, TEvent, TAction['params'], TEvent>>;
|
414 | export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
415 |
|
416 | export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject> {
|
417 | guards: GuardMap<TContext, TEvent, TGuard>;
|
418 | actions: ActionFunctionMap<TContext, TEvent, TActor, TAction>;
|
419 | actors: Record<string, AnyActorLogic | {
|
420 | src: AnyActorLogic;
|
421 | input: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
422 | }>;
|
423 | delays: DelayFunctionMap<TContext, TEvent, TAction>;
|
424 | }
|
425 | type MachineImplementationsActions<TTypes extends StateMachineTypes> = {
|
426 | [K in TTypes['actions']['type']]?: ActionFunction<TTypes['context'], TTypes['events'], TTypes['events'], GetConcreteByKey<TTypes['actions'], 'type', K>['params'], TTypes['actors'], TTypes['actions'], TTypes['guards'], TTypes['delays'], TTypes['emitted']>;
|
427 | };
|
428 | type MachineImplementationsActors<TTypes extends StateMachineTypes> = {
|
429 | [K in TTypes['actors']['src']]?: GetConcreteByKey<TTypes['actors'], 'src', K>['logic'];
|
430 | };
|
431 | type MachineImplementationsDelays<TTypes extends StateMachineTypes> = {
|
432 | [K in TTypes['delays']]?: DelayConfig<TTypes['context'], TTypes['events'], undefined, TTypes['events']>;
|
433 | };
|
434 | type MachineImplementationsGuards<TTypes extends StateMachineTypes> = {
|
435 | [K in TTypes['guards']['type']]?: Guard<TTypes['context'], TTypes['events'], GetConcreteByKey<TTypes['guards'], 'type', K>['params'], TTypes['guards']>;
|
436 | };
|
437 | export type InternalMachineImplementations<TTypes extends StateMachineTypes> = {
|
438 | actions?: MachineImplementationsActions<TTypes>;
|
439 | actors?: MachineImplementationsActors<TTypes>;
|
440 | delays?: MachineImplementationsDelays<TTypes>;
|
441 | guards?: MachineImplementationsGuards<TTypes>;
|
442 | };
|
443 | type InitialContext<TContext extends MachineContext, TActor extends ProvidedActor, TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActor, TInput, TEvent>;
|
444 | export type ContextFactory<TContext extends MachineContext, TActor extends ProvidedActor, TInput, TEvent extends EventObject = EventObject> = ({ spawn, input, self }: {
|
445 | spawn: Spawner<TActor>;
|
446 | input: TInput;
|
447 | self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>,
|
448 | StateValue, string, unknown, TODO,
|
449 | TODO>, TEvent, AnyEventObject>;
|
450 | }) => TContext;
|
451 | export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = unknown, TEmitted extends EventObject = EventObject, TMeta extends MetaObject = MetaObject> = (Omit<StateNodeConfig<DoNotInfer<TContext>, DoNotInfer<TEvent>, DoNotInfer<TActor>, DoNotInfer<TAction>, DoNotInfer<TGuard>, DoNotInfer<TDelay>, DoNotInfer<TTag>, DoNotInfer<TOutput>, DoNotInfer<TEmitted>, DoNotInfer<TMeta>>, 'output'> & {
|
452 |
|
453 |
|
454 | version?: string;
|
455 | output?: Mapper<TContext, DoneStateEvent, TOutput, TEvent> | TOutput;
|
456 | }) & (MachineContext extends TContext ? {
|
457 | context?: InitialContext<LowInfer<TContext>, TActor, TInput, TEvent>;
|
458 | } : {
|
459 | context: InitialContext<LowInfer<TContext>, TActor, TInput, TEvent>;
|
460 | });
|
461 | export type UnknownMachineConfig = MachineConfig<MachineContext, EventObject>;
|
462 | export interface ProvidedActor {
|
463 | src: string;
|
464 | logic: UnknownActorLogic;
|
465 | id?: string;
|
466 | }
|
467 | export interface SetupTypes<TContext extends MachineContext, TEvent extends EventObject, TChildrenMap extends Record<string, string>, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> {
|
468 | context?: TContext;
|
469 | events?: TEvent;
|
470 | children?: TChildrenMap;
|
471 | tags?: TTag;
|
472 | input?: TInput;
|
473 | output?: TOutput;
|
474 | emitted?: TEmitted;
|
475 | meta?: TMeta;
|
476 | }
|
477 | export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput, TEmitted, TMeta> {
|
478 | actors?: TActor;
|
479 | actions?: TAction;
|
480 | guards?: TGuard;
|
481 | delays?: TDelay;
|
482 | meta?: TMeta;
|
483 | }
|
484 | export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
485 | history: 'shallow' | 'deep';
|
486 | target: string | undefined;
|
487 | }
|
488 | export type HistoryValue<TContext extends MachineContext, TEvent extends EventObject> = Record<string, Array<StateNode<TContext, TEvent>>>;
|
489 | export type AnyHistoryValue = HistoryValue<any, any>;
|
490 | export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? ReturnType<T['transition']> : T extends (...args: any[]) => AnyStateMachine ? ReturnType<ReturnType<T>['transition']> : never;
|
491 | export type Transitions<TContext extends MachineContext, TEvent extends EventObject> = Array<TransitionDefinition<TContext, TEvent>>;
|
492 | export interface DoneActorEvent<TOutput = unknown, TId extends string = string> extends EventObject {
|
493 | type: `xstate.done.actor.${TId}`;
|
494 | output: TOutput;
|
495 | actorId: TId;
|
496 | }
|
497 | export interface ErrorActorEvent<TErrorData = unknown, TId extends string = string> extends EventObject {
|
498 | type: `xstate.error.actor.${TId}`;
|
499 | error: TErrorData;
|
500 | actorId: TId;
|
501 | }
|
502 | export interface SnapshotEvent<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>> extends EventObject {
|
503 | type: `xstate.snapshot.${string}`;
|
504 | snapshot: TSnapshot;
|
505 | }
|
506 | export interface DoneStateEvent<TOutput = unknown> extends EventObject {
|
507 | type: `xstate.done.state.${string}`;
|
508 | output: TOutput;
|
509 | }
|
510 | export type DelayExpr<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => number;
|
511 | export type LogExpr<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => unknown;
|
512 | export type SendExpr<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TSentEvent extends EventObject, TEvent extends EventObject> = (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => TSentEvent;
|
513 | export declare enum SpecialTargets {
|
514 | Parent = "#_parent",
|
515 | Internal = "#_internal"
|
516 | }
|
517 | export interface SendToActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> extends RaiseActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay> {
|
518 | }
|
519 | export interface RaiseActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
520 | id?: string;
|
521 | delay?: Delay<TDelay> | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
522 | }
|
523 | export interface RaiseActionParams<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> extends RaiseActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay> {
|
524 | event: TEvent | SendExpr<TContext, TExpressionEvent, TParams, TEvent, TEvent>;
|
525 | }
|
526 | export interface SendToActionParams<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TSentEvent extends EventObject, TEvent extends EventObject, TDelay extends string> extends SendToActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay> {
|
527 | event: TSentEvent | SendExpr<TContext, TExpressionEvent, TParams, TSentEvent, TEvent>;
|
528 | }
|
529 | export type Assigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> = (args: AssignArgs<TContext, TExpressionEvent, TEvent, TActor>, params: TParams) => Partial<TContext>;
|
530 | export type PartialAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor, TKey extends keyof TContext> = (args: AssignArgs<TContext, TExpressionEvent, TEvent, TActor>, params: TParams) => TContext[TKey];
|
531 | export type PropertyAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> = {
|
532 | [K in keyof TContext]?: PartialAssigner<TContext, TExpressionEvent, TParams, TEvent, TActor, K> | TContext[K];
|
533 | };
|
534 | export type Mapper<TContext extends MachineContext, TExpressionEvent extends EventObject, TResult, TEvent extends EventObject> = (args: {
|
535 | context: TContext;
|
536 | event: TExpressionEvent;
|
537 | self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef>,
|
538 | StateValue, string, unknown, TODO,
|
539 | TODO>, TEvent, AnyEventObject>;
|
540 | }) => TResult;
|
541 | export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO, TODO, // TEmitted
|
542 | TODO>, 'target' | 'guard'> {
|
543 | target: ReadonlyArray<StateNode<TContext, TEvent>> | undefined;
|
544 | source: StateNode<TContext, TEvent>;
|
545 | actions: readonly UnknownAction[];
|
546 | reenter: boolean;
|
547 | guard?: UnknownGuard;
|
548 | eventType: EventDescriptor<TEvent>;
|
549 | toJSON: () => {
|
550 | target: string[] | undefined;
|
551 | source: string;
|
552 | actions: readonly UnknownAction[];
|
553 | guard?: UnknownGuard;
|
554 | eventType: EventDescriptor<TEvent>;
|
555 | meta?: Record<string, any>;
|
556 | };
|
557 | }
|
558 | export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
559 | export interface InitialTransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
|
560 | target: ReadonlyArray<StateNode<TContext, TEvent>>;
|
561 | guard?: never;
|
562 | }
|
563 | export type TransitionDefinitionMap<TContext extends MachineContext, TEvent extends EventObject> = {
|
564 | [K in EventDescriptor<TEvent>]: Array<TransitionDefinition<TContext, ExtractEvent<TEvent, K>>>;
|
565 | };
|
566 | export interface DelayedTransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
|
567 | delay: number | string | DelayExpr<TContext, TEvent, undefined, TEvent>;
|
568 | }
|
569 | export interface StateLike<TContext extends MachineContext> {
|
570 | value: StateValue;
|
571 | context: TContext;
|
572 | event: EventObject;
|
573 | }
|
574 | export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
575 | context: TContext;
|
576 | historyValue?: HistoryValue<TContext, TEvent>;
|
577 | children: Record<string, AnyActorRef>;
|
578 | status: SnapshotStatus;
|
579 | output?: any;
|
580 | error?: unknown;
|
581 | machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any, any,
|
582 | any>;
|
583 | }
|
584 | export interface ActorOptions<TLogic extends AnyActorLogic> {
|
585 | |
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 | clock?: Clock;
|
603 | |
604 |
|
605 |
|
606 |
|
607 | logger?: (...args: any[]) => void;
|
608 | parent?: AnyActorRef;
|
609 |
|
610 | id?: string;
|
611 |
|
612 | devTools?: never;
|
613 |
|
614 | systemId?: string;
|
615 |
|
616 | input?: InputFrom<TLogic>;
|
617 | |
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 | snapshot?: Snapshot<unknown>;
|
631 |
|
632 | state?: Snapshot<unknown>;
|
633 |
|
634 | src?: string | AnyActorLogic;
|
635 | |
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 | inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
717 | }
|
718 | export type AnyActor = Actor<any>;
|
719 | /** @deprecated Use `AnyActor` instead. */
|
720 | export type AnyInterpreter = AnyActor;
|
721 | export type Observer<T> = {
|
722 | next?: (value: T) => void;
|
723 | error?: (err: unknown) => void;
|
724 | complete?: () => void;
|
725 | };
|
726 | export interface Subscription {
|
727 | unsubscribe(): void;
|
728 | }
|
729 | export interface InteropObservable<T> {
|
730 | [Symbol.observable]: () => InteropSubscribable<T>;
|
731 | }
|
732 | export interface InteropSubscribable<T> {
|
733 | subscribe(observer: Observer<T>): Subscription;
|
734 | }
|
735 | export interface Subscribable<T> extends InteropSubscribable<T> {
|
736 | subscribe(observer: Observer<T>): Subscription;
|
737 | subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
738 | }
|
739 | type EventDescriptorMatches<TEventType extends string, TNormalizedDescriptor> = TEventType extends TNormalizedDescriptor ? true : false;
|
740 | export type ExtractEvent<TEvent extends EventObject, TDescriptor extends EventDescriptor<TEvent>> = string extends TEvent['type'] ? TEvent : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor ? TEvent extends any ? true extends EventDescriptorMatches<TEvent['type'], TNormalizedDescriptor> ? TEvent : never : never : never;
|
741 | export interface BaseActorRef<TEvent extends EventObject> {
|
742 | send: (event: TEvent) => void;
|
743 | }
|
744 | export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscribable<TCurrent> {
|
745 | send: (event: TEvent) => void;
|
746 | }
|
747 | export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
748 |
|
749 | id: string;
|
750 | sessionId: string;
|
751 | send: (event: TEvent) => void;
|
752 | start: () => void;
|
753 | getSnapshot: () => TSnapshot;
|
754 | getPersistedSnapshot: () => Snapshot<unknown>;
|
755 | stop: () => void;
|
756 | toJSON?: () => any;
|
757 | _parent?: AnyActorRef;
|
758 | system: AnyActorSystem;
|
759 | src: string | AnyActorLogic;
|
760 | on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? unknown : {
|
761 | type: TType;
|
762 | })) => void) => Subscription;
|
763 | }
|
764 | export type AnyActorRef = ActorRef<any, any,
|
765 | any>;
|
766 | export type ActorRefLike = Pick<AnyActorRef, 'sessionId' | 'send' | 'getSnapshot'>;
|
767 | export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
768 | export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any, any, any,
|
769 | any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
770 | export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta, infer TStateSchema> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, TEvent, TEmitted> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never : never;
|
771 | export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>>;
|
772 | export type DevToolsAdapter = (service: AnyActor) => void;
|
773 |
|
774 | export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TEmitted, infer TMeta, infer TStateSchema> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, TEvent, TInput, AnyActorSystem, TEmitted>> : never;
|
775 | export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer _TChildren, infer TActor, infer TAction, infer TGuard, infer TDelay, infer _TStateValue, infer TTag, infer _TInput, infer _TOutput, infer TEmitted, infer _TMeta, infer _TStateSchema> ? InternalMachineImplementations<ResolvedStateMachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>> : never;
|
776 | export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends AnyActorSystem = AnyActorSystem, TEmitted extends EventObject = EventObject> {
|
777 | self: ActorRef<TSnapshot, TEvent, TEmitted>;
|
778 | id: string;
|
779 | sessionId: string;
|
780 | logger: (...args: any[]) => void;
|
781 | defer: (fn: () => void) => void;
|
782 | emit: (event: TEmitted) => void;
|
783 | system: TSystem;
|
784 | stopChild: (child: AnyActorRef) => void;
|
785 | actionExecutor: ActionExecutor;
|
786 | }
|
787 | export type AnyActorScope = ActorScope<any,
|
788 | any,
|
789 | AnyActorSystem, any>;
|
790 | export type SnapshotStatus = 'active' | 'done' | 'error' | 'stopped';
|
791 | export type Snapshot<TOutput> = {
|
792 | status: 'active';
|
793 | output: undefined;
|
794 | error: undefined;
|
795 | } | {
|
796 | status: 'done';
|
797 | output: TOutput;
|
798 | error: undefined;
|
799 | } | {
|
800 | status: 'error';
|
801 | output: undefined;
|
802 | error: unknown;
|
803 | } | {
|
804 | status: 'stopped';
|
805 | output: undefined;
|
806 | error: undefined;
|
807 | };
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 | export interface ActorLogic<in out TSnapshot extends Snapshot<unknown>, // it's invariant because it's also part of `ActorScope["self"]["getSnapshot"]`
|
817 | in out TEvent extends EventObject, // it's invariant because it's also part of `ActorScope["self"]["send"]`
|
818 | in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem, in out TEmitted extends EventObject = EventObject> {
|
819 |
|
820 | config?: unknown;
|
821 | |
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 | transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
|
831 | |
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 | getInitialSnapshot: (actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>, input: TInput) => TSnapshot;
|
839 | |
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 | restoreSnapshot?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>) => TSnapshot;
|
849 | |
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 | start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>) => void;
|
856 | |
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 | getPersistedSnapshot: (snapshot: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
864 | }
|
865 | export type AnyActorLogic = ActorLogic<any,
|
866 | any,
|
867 | any,
|
868 | any,
|
869 | any>;
|
870 | export type UnknownActorLogic = ActorLogic<any,
|
871 | any,
|
872 | any,
|
873 | AnyActorSystem, any>;
|
874 | export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
|
875 | export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? TEvent : never;
|
876 | export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted : never;
|
877 | type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TEvent : R extends ActorRef<infer _TSnapshot, infer TEvent, infer _TEmitted> ? TEvent : never : never;
|
878 | export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
879 | export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema> ? TContext : never : never : never;
|
880 | export type InferEvent<E extends EventObject> = {
|
881 | [T in E['type']]: {
|
882 | type: T;
|
883 | } & Extract<E, {
|
884 | type: T;
|
885 | }>;
|
886 | }[E['type']];
|
887 | export type TODO = any;
|
888 | export type StateValueFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['matches']>[0];
|
889 | export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
|
890 | export interface ActorSystemInfo {
|
891 | actors: Record<string, AnyActorRef>;
|
892 | }
|
893 | export type RequiredActorOptions<TActor extends ProvidedActor> = (undefined extends TActor['id'] ? never : 'id') | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
894 | type ExtractLiteralString<T extends string | undefined> = T extends string ? string extends T ? never : T : never;
|
895 | type ToConcreteChildren<TActor extends ProvidedActor> = {
|
896 | [A in TActor as ExtractLiteralString<A['id']>]?: ActorRefFromLogic<A['logic']>;
|
897 | };
|
898 | export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string, AnyActorRef> : Compute<ToConcreteChildren<TActor> & {
|
899 | include: {
|
900 | [id: string]: TActor extends any ? ActorRefFromLogic<TActor['logic']> | undefined : never;
|
901 | };
|
902 | exclude: unknown;
|
903 | }[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']>;
|
904 | export type StateSchema = {
|
905 | id?: string;
|
906 | states?: Record<string, StateSchema>;
|
907 | type?: unknown;
|
908 | invoke?: unknown;
|
909 | on?: unknown;
|
910 | entry?: unknown;
|
911 | exit?: unknown;
|
912 | onDone?: unknown;
|
913 | after?: unknown;
|
914 | always?: unknown;
|
915 | meta?: unknown;
|
916 | output?: unknown;
|
917 | tags?: unknown;
|
918 | description?: unknown;
|
919 | };
|
920 | export type StateId<TSchema extends StateSchema, TKey extends string = '(machine)', TParentKey extends string | null = null> = (TSchema extends {
|
921 | id: string;
|
922 | } ? TSchema['id'] : TParentKey extends null ? TKey : `${TParentKey}.${TKey}`) | (TSchema['states'] extends Record<string, any> ? Values<{
|
923 | [K in keyof TSchema['states'] & string]: StateId<TSchema['states'][K], K, TParentKey extends string ? `${TParentKey}.${TKey}` : TSchema['id'] extends string ? TSchema['id'] : TKey>;
|
924 | }> : never);
|
925 | export interface StateMachineTypes {
|
926 | context: MachineContext;
|
927 | events: EventObject;
|
928 | actors: ProvidedActor;
|
929 | actions: ParameterizedObject;
|
930 | guards: ParameterizedObject;
|
931 | delays: string;
|
932 | tags: string;
|
933 | emitted: EventObject;
|
934 | }
|
935 |
|
936 | export interface ResolvedStateMachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TEmitted extends EventObject = EventObject> {
|
937 | context: TContext;
|
938 | events: TEvent;
|
939 | actors: TActor;
|
940 | actions: TAction;
|
941 | guards: TGuard;
|
942 | delays: TDelay;
|
943 | tags: TTag;
|
944 | emitted: TEmitted;
|
945 | }
|
946 | export type GetConcreteByKey<T, TKey extends keyof T, TValue extends T[TKey]> = T & Record<TKey, TValue>;
|
947 | type _GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = S extends any ? T['states'][S] extends {
|
948 | type: 'history';
|
949 | } ? [never, never] : T extends {
|
950 | type: 'parallel';
|
951 | } ? [S, never] : 'states' extends keyof T['states'][S] ? [S, never] : [never, S] : never;
|
952 | type GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = {
|
953 | nonLeaf: _GroupStateKeys<T, S & string>[0];
|
954 | leaf: _GroupStateKeys<T, S & string>[1];
|
955 | };
|
956 | export type ToStateValue<T extends StateSchema> = T extends {
|
957 | states: Record<infer S, any>;
|
958 | } ? IsNever<S> extends true ? {} : GroupStateKeys<T, S>['leaf'] | (IsNever<GroupStateKeys<T, S>['nonLeaf']> extends false ? T extends {
|
959 | type: 'parallel';
|
960 | } ? {
|
961 | [K in GroupStateKeys<T, S>['nonLeaf']]: ToStateValue<T['states'][K]>;
|
962 | } : Compute<Values<{
|
963 | [K in GroupStateKeys<T, S>['nonLeaf']]: {
|
964 | [StateKey in K]: ToStateValue<T['states'][K]>;
|
965 | };
|
966 | }>> : never) : {};
|
967 | export interface ExecutableActionObject {
|
968 | type: string;
|
969 | info: ActionArgs<MachineContext, EventObject, EventObject>;
|
970 | params: NonReducibleUnknown;
|
971 | exec: ((info: ActionArgs<any, any, any>, params: unknown) => void) | undefined;
|
972 | }
|
973 | export interface ToExecutableAction<T extends ParameterizedObject> extends ExecutableActionObject {
|
974 | type: T['type'];
|
975 | params: T['params'];
|
976 | exec: undefined;
|
977 | }
|
978 | export interface ExecutableSpawnAction extends ExecutableActionObject {
|
979 | type: 'xstate.spawnChild';
|
980 | info: ActionArgs<MachineContext, EventObject, EventObject>;
|
981 | params: {
|
982 | id: string;
|
983 | actorRef: AnyActorRef | undefined;
|
984 | src: string | AnyActorLogic;
|
985 | };
|
986 | }
|
987 | export type SpecialExecutableAction = ExecutableSpawnAction | ExecutableRaiseAction | ExecutableSendToAction;
|
988 | export type ExecutableActionsFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig> ? SpecialExecutableAction | (string extends TAction['type'] ? never : ToExecutableAction<TAction>) : never;
|
989 | export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
|
990 | export type BuiltinActionResolution = [
|
991 | AnyMachineSnapshot,
|
992 | NonReducibleUnknown,
|
993 |
|
994 | UnknownAction[] | undefined
|
995 | ];
|
996 | export {};
|