1 | import { StateMachine } from "./StateMachine.js";
|
2 | import { GuardPredicate } from "./guards.js";
|
3 | import { ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
|
4 | import { ActionFunction, AnyActorRef, AnyEventObject, Cast, ConditionalRequired, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateSchema, ToChildren, UnknownActorLogic, Values } from "./types.js";
|
5 | type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = IsNever<TParameterizedMap> extends true ? never : Values<{
|
6 | [K in keyof TParameterizedMap & string]: {
|
7 | type: K;
|
8 | params: TParameterizedMap[K];
|
9 | };
|
10 | }>;
|
11 | type ToProvidedActor<TChildrenMap extends Record<string, string>, TActors extends Record<string, UnknownActorLogic>> = IsNever<TActors> extends true ? never : Values<{
|
12 | [K in keyof TActors & string]: {
|
13 | src: K;
|
14 | logic: TActors[K];
|
15 | id: IsNever<TChildrenMap> extends true ? string | undefined : K extends keyof Invert<TChildrenMap> ? Invert<TChildrenMap>[K] & string : string | undefined;
|
16 | };
|
17 | }>;
|
18 | type _GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = S extends any ? T['states'][S] extends {
|
19 | type: 'history';
|
20 | } ? [never, never] : T extends {
|
21 | type: 'parallel';
|
22 | } ? [S, never] : 'states' extends keyof T['states'][S] ? [S, never] : [never, S] : never;
|
23 | type GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = {
|
24 | nonLeaf: _GroupStateKeys<T, S & string>[0];
|
25 | leaf: _GroupStateKeys<T, S & string>[1];
|
26 | };
|
27 | type ToStateValue<T extends StateSchema> = T extends {
|
28 | states: Record<infer S, any>;
|
29 | } ? IsNever<S> extends true ? {} : GroupStateKeys<T, S>['leaf'] | (IsNever<GroupStateKeys<T, S>['nonLeaf']> extends false ? ConditionalRequired<{
|
30 | [K in GroupStateKeys<T, S>['nonLeaf']]?: ToStateValue<T['states'][K]>;
|
31 | }, T extends {
|
32 | type: 'parallel';
|
33 | } ? true : false> : never) : {};
|
34 | type RequiredSetupKeys<TChildrenMap> = IsNever<keyof TChildrenMap> extends true ? never : 'actors';
|
35 | export declare function setup<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
36 | TActors extends Record<string, UnknownActorLogic> = {}, TChildrenMap extends Record<string, string> = {}, TActions extends Record<string, ParameterizedObject['params'] | undefined> = {}, TGuards extends Record<string, ParameterizedObject['params'] | undefined> = {}, TDelay extends string = never, TTag extends string = string, TInput = NonReducibleUnknown, TOutput extends NonReducibleUnknown = NonReducibleUnknown, TEmitted extends EventObject = EventObject>({ schemas, actors, actions, guards, delays }: {
|
37 | schemas?: unknown;
|
38 | types?: SetupTypes<TContext, TEvent, TChildrenMap, TTag, TInput, TOutput, TEmitted>;
|
39 | actors?: {
|
40 | [K in keyof TActors | Values<TChildrenMap>]: K extends keyof TActors ? TActors[K] : never;
|
41 | };
|
42 | actions?: {
|
43 | [K in keyof TActions]: ActionFunction<TContext, TEvent, TEvent, TActions[K], ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TEmitted>;
|
44 | };
|
45 | guards?: {
|
46 | [K in keyof TGuards]: GuardPredicate<TContext, TEvent, TGuards[K], ToParameterizedObject<TGuards>>;
|
47 | };
|
48 | delays?: {
|
49 | [K in TDelay]: DelayConfig<TContext, TEvent, ToParameterizedObject<TActions>['params'], TEvent>;
|
50 | };
|
51 | } & {
|
52 | [K in RequiredSetupKeys<TChildrenMap>]: unknown;
|
53 | }): {
|
54 | createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TEmitted>>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TEmitted>>;
|
55 | };
|
56 | export {};
|