1 | import { EventObject, IndexByType, IsNever, Prop, ParameterizedObject, ProvidedActor, OutputFrom, AnyActorLogic, IndexByProp } from "./types.js";
|
2 |
|
3 |
|
4 |
|
5 | export interface TypegenDisabled {
|
6 | '@@xstate/typegen': false;
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 | export interface TypegenEnabled {
|
12 | '@@xstate/typegen': true;
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 | export interface TypegenMeta extends TypegenEnabled {
|
18 | |
19 |
|
20 |
|
21 | matchesStates: string | {};
|
22 | |
23 |
|
24 |
|
25 | tags: string;
|
26 | |
27 |
|
28 |
|
29 |
|
30 | missingImplementations: {
|
31 | actions: string;
|
32 | actors: string;
|
33 | delays: string;
|
34 | guards: string;
|
35 | };
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | internalEvents: {};
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | invokeSrcNameMap: Record<string, string>;
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | eventsCausingActions: Record<string, string>;
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | eventsCausingDelays: Record<string, string>;
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | eventsCausingGuards: Record<string, string>;
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | eventsCausingActors: Record<string, string>;
|
88 | }
|
89 |
|
90 |
|
91 |
|
92 | export interface ResolvedTypegenMeta extends TypegenMeta {
|
93 | resolved: TypegenMeta & {
|
94 | indexedActors: Record<string, ProvidedActor>;
|
95 | indexedActions: Record<string, ParameterizedObject>;
|
96 | indexedEvents: Record<string, EventObject>;
|
97 | indexedGuards: Record<string, ParameterizedObject>;
|
98 | indexedDelays: Record<string, ParameterizedObject>;
|
99 | };
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 | export type TypegenConstraint = TypegenEnabled | TypegenDisabled;
|
105 |
|
106 |
|
107 |
|
108 | export type AreAllImplementationsAssumedToBeProvided<_TResolvedTypesMeta, _TMissingImplementations = never> = true;
|
109 |
|
110 |
|
111 |
|
112 | export type MissingImplementationsError<_TResolvedTypesMeta, _TMissingImplementations = never> = never;
|
113 |
|
114 |
|
115 |
|
116 | interface AllImplementationsProvided {
|
117 | missingImplementations: {
|
118 | actions: never;
|
119 | actors: never;
|
120 | delays: never;
|
121 | guards: never;
|
122 | };
|
123 | }
|
124 | type GenerateActorEvents<TActor extends ProvidedActor, TInvokeSrcNameMap> = string extends TActor['src'] ? never : TActor extends any ? {
|
125 | type: TActor['id'] extends string ? `xstate.done.actor.${TActor['id']}` : TActor['src'] extends keyof TInvokeSrcNameMap ? `xstate.done.actor.${TInvokeSrcNameMap[TActor['src']] & string}` : `xstate.done.actor.${string}`;
|
126 | output: OutputFrom<TActor['logic']>;
|
127 | } : never;
|
128 | type MergeWithInternalEvents<TIndexedEvents, TInternalEvents> = TIndexedEvents & Pick<TInternalEvents, Exclude<keyof TInternalEvents, keyof TIndexedEvents>>;
|
129 | type AllowAllEvents = {
|
130 | eventsCausingActions: Record<string, string>;
|
131 | eventsCausingActors: Record<string, string>;
|
132 | eventsCausingDelays: Record<string, string>;
|
133 | eventsCausingGuards: Record<string, string>;
|
134 | };
|
135 | type IndexParameterizedImplementation<TParameterizedImplementation extends ParameterizedObject, TCausingLookup> = string extends TParameterizedImplementation['type'] ? IsNever<TCausingLookup> extends true ? never : Record<keyof TCausingLookup, ParameterizedObject> : IndexByType<TParameterizedImplementation>;
|
136 | type WrapIntoParameterizedObject<T extends string> = T extends any ? {
|
137 | type: T;
|
138 | } : never;
|
139 |
|
140 |
|
141 |
|
142 | export interface ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TEmitted extends EventObject = EventObject> {
|
143 | '@@xstate/typegen': TTypesMeta['@@xstate/typegen'];
|
144 | resolved: {
|
145 | enabled: TTypesMeta & {
|
146 | indexedActions: IndexParameterizedImplementation<TAction, Prop<TTypesMeta, 'eventsCausingActions'>>;
|
147 | indexedActors: string extends TActor['src'] ? Record<keyof Prop<TTypesMeta, 'eventsCausingActors'>, {
|
148 | logic: AnyActorLogic;
|
149 | }> : IndexByProp<TActor, 'src'>;
|
150 | indexedEvents: MergeWithInternalEvents<IndexByType<(string extends TEvent['type'] ? never : TEvent) | GenerateActorEvents<TActor, Prop<TTypesMeta, 'invokeSrcNameMap'>>>, Prop<TTypesMeta, 'internalEvents'>>;
|
151 | indexedGuards: IndexParameterizedImplementation<TGuard, Prop<TTypesMeta, 'eventsCausingGuards'>>;
|
152 | indexedDelays: IndexParameterizedImplementation<WrapIntoParameterizedObject<TDelay>, Prop<TTypesMeta, 'eventsCausingDelays'>>;
|
153 | tags: string extends TTag ? Prop<TTypesMeta, 'tags'> : TTag;
|
154 | emitted: TEmitted;
|
155 | };
|
156 | disabled: TypegenDisabled & AllImplementationsProvided & AllowAllEvents & {
|
157 | indexedActions: IndexByType<TAction>;
|
158 | indexedActors: IndexByProp<TActor, 'src'>;
|
159 | indexedEvents: Record<string, TEvent>;
|
160 | indexedGuards: IndexByType<TGuard>;
|
161 | indexedDelays: IndexByType<WrapIntoParameterizedObject<TDelay>>;
|
162 | invokeSrcNameMap: Record<string, string>;
|
163 | tags: TTag;
|
164 | emitted: TEmitted;
|
165 | };
|
166 | }[IsNever<TTypesMeta> extends true ? 'disabled' : TTypesMeta['@@xstate/typegen'] extends true ? 'enabled' : 'disabled'];
|
167 | }
|
168 | export {};
|