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