UNPKG

5.62 kBTypeScriptView Raw
1import { BaseActionObject, EventObject, IndexByType, IsNever, Prop, Values, IsAny, ServiceMap, Cast, Compute } from './types';
2export interface TypegenDisabled {
3 '@@xstate/typegen': false;
4}
5export interface TypegenEnabled {
6 '@@xstate/typegen': true;
7}
8export interface TypegenMeta extends TypegenEnabled {
9 /**
10 * Allows you to specify all the results of state.matches
11 */
12 matchesStates: string | {};
13 /**
14 * Allows you to specify all tags used by the machine
15 */
16 tags: string;
17 /**
18 * Allows you to specify all the missing implementations
19 * of the machine
20 */
21 missingImplementations: {
22 actions: string;
23 delays: string;
24 guards: string;
25 services: string;
26 };
27 /**
28 * A map for the internal events of the machine.
29 *
30 * key: 'done.invoke.myService'
31 * value: {
32 * type: 'done.invoke.myService';
33 * data: unknown;
34 * __tip: 'Declare the type in event types!';
35 * }
36 */
37 internalEvents: {};
38 /**
39 * Maps the name of the service to the event type
40 * of the done.invoke action
41 *
42 * key: 'invokeSrc'
43 * value: 'done.invoke.invokeName'
44 */
45 invokeSrcNameMap: Record<string, string>;
46 /**
47 * Keeps track of which events lead to which
48 * actions.
49 *
50 * Key: 'EVENT_NAME'
51 * Value: 'actionName' | 'otherActionName'
52 */
53 eventsCausingActions: Record<string, string>;
54 /**
55 * Keeps track of which events lead to which
56 * delays.
57 *
58 * Key: 'EVENT_NAME'
59 * Value: 'delayName' | 'otherDelayName'
60 */
61 eventsCausingDelays: Record<string, string>;
62 /**
63 * Keeps track of which events lead to which
64 * guards.
65 *
66 * Key: 'EVENT_NAME'
67 * Value: 'guardName' | 'otherGuardName'
68 */
69 eventsCausingGuards: Record<string, string>;
70 /**
71 * Keeps track of which events lead to which
72 * services.
73 *
74 * Key: 'EVENT_NAME'
75 * Value: 'serviceName' | 'otherServiceName'
76 */
77 eventsCausingServices: Record<string, string>;
78}
79export interface ResolvedTypegenMeta extends TypegenMeta {
80 resolved: TypegenMeta & {
81 indexedActions: Record<string, BaseActionObject>;
82 indexedEvents: Record<string, EventObject>;
83 };
84}
85export declare type TypegenConstraint = TypegenEnabled | TypegenDisabled;
86export declare type AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = IsAny<TResolvedTypesMeta> extends true ? true : TResolvedTypesMeta extends TypegenEnabled ? IsNever<Values<{
87 [K in keyof TMissingImplementations]: TMissingImplementations[K];
88}>> extends true ? true : false : true;
89export declare type MissingImplementationsError<TResolvedTypesMeta, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = Compute<[
90 'Some implementations missing',
91 Values<{
92 [K in keyof TMissingImplementations]: TMissingImplementations[K];
93 }>
94]>;
95interface AllImplementationsProvided {
96 missingImplementations: {
97 actions: never;
98 delays: never;
99 guards: never;
100 services: never;
101 };
102}
103export interface MarkAllImplementationsAsProvided<TResolvedTypesMeta> {
104 '@@xstate/typegen': Prop<TResolvedTypesMeta, '@@xstate/typegen'>;
105 resolved: Prop<TResolvedTypesMeta, 'resolved'> & AllImplementationsProvided;
106}
107declare type GenerateServiceEvent<TServiceName, TEventType, TServiceMap extends ServiceMap> = TEventType extends any ? {
108 type: TEventType;
109} & Prop<TServiceMap, TServiceName> : never;
110declare type GenerateServiceEvents<TServiceMap extends ServiceMap, TInvokeSrcNameMap> = string extends keyof TServiceMap ? never : Cast<{
111 [K in keyof TInvokeSrcNameMap]: GenerateServiceEvent<K, TInvokeSrcNameMap[K], TServiceMap>;
112}[keyof TInvokeSrcNameMap], EventObject>;
113declare type MergeWithInternalEvents<TIndexedEvents, TInternalEvents> = TIndexedEvents & Pick<TInternalEvents, Exclude<keyof TInternalEvents, keyof TIndexedEvents>>;
114declare type AllowAllEvents = {
115 eventsCausingActions: Record<string, string>;
116 eventsCausingDelays: Record<string, string>;
117 eventsCausingGuards: Record<string, string>;
118 eventsCausingServices: Record<string, string>;
119};
120export interface ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TAction extends BaseActionObject, TServiceMap extends ServiceMap> {
121 '@@xstate/typegen': TTypesMeta['@@xstate/typegen'];
122 resolved: {
123 enabled: TTypesMeta & {
124 indexedActions: IndexByType<TAction>;
125 indexedEvents: MergeWithInternalEvents<IndexByType<(string extends TEvent['type'] ? never : TEvent) | GenerateServiceEvents<TServiceMap, Prop<TTypesMeta, 'invokeSrcNameMap'>>>, Prop<TTypesMeta, 'internalEvents'>>;
126 };
127 disabled: TypegenDisabled & AllImplementationsProvided & AllowAllEvents & {
128 indexedActions: IndexByType<TAction>;
129 indexedEvents: Record<string, TEvent> & {
130 __XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__: {
131 data: any;
132 };
133 };
134 invokeSrcNameMap: Record<string, '__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__'>;
135 };
136 }[IsNever<TTypesMeta> extends true ? 'disabled' : TTypesMeta extends TypegenEnabled ? 'enabled' : 'disabled'];
137}
138export {};
139//# sourceMappingURL=typegenTypes.d.ts.map
\No newline at end of file