UNPKG

2.04 kBTypeScriptView Raw
1import { ActorRefFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, GetConcreteByKey, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions, type RequiredLogicInput } from "./types.js";
2type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {
3 src: TSrc;
4} ? ConditionalRequired<[
5 options?: {
6 id?: TActor['id'];
7 systemId?: string;
8 input?: InputFrom<TActor['logic']>;
9 syncSnapshot?: boolean;
10 } & {
11 [K in RequiredActorOptions<TActor>]: unknown;
12 }
13], IsNotNever<RequiredActorOptions<TActor>>> : never;
14export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? {
15 <TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFromLogic<GetConcreteByKey<TActor, 'src', TSrc>['logic']>;
16 <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
17 options?: {
18 id?: never;
19 systemId?: string;
20 input?: InputFrom<TLogic>;
21 syncSnapshot?: boolean;
22 } & {
23 [K in RequiredLogicInput<TLogic>]: unknown;
24 }
25 ], IsNotNever<RequiredLogicInput<TLogic>>>): ActorRefFromLogic<TLogic>;
26} : <TLogic extends AnyActorLogic | string>(src: TLogic, ...[options]: ConditionalRequired<[
27 options?: {
28 id?: string;
29 systemId?: string;
30 input?: TLogic extends string ? unknown : InputFrom<TLogic>;
31 syncSnapshot?: boolean;
32 } & (TLogic extends AnyActorLogic ? {
33 [K in RequiredLogicInput<TLogic>]: unknown;
34 } : {})
35], IsNotNever<TLogic extends AnyActorLogic ? RequiredLogicInput<TLogic> : never>>) => TLogic extends AnyActorLogic ? ActorRefFromLogic<TLogic> : AnyActorRef;
36export declare function createSpawner(actorScope: AnyActorScope, { machine, context }: AnyMachineSnapshot, event: AnyEventObject, spawnedChildren: Record<string, AnyActorRef>): Spawner<any>;
37export {};