deno.land / x / xstate@xstate@4.33.6 / src / typegenTypes.ts

typegenTypes.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import { BaseActionObject, EventObject, IndexByType, IsNever, Prop, Values, IsAny, ServiceMap, Cast} from './types';
export interface TypegenDisabled { '@@xstate/typegen': false;}export interface TypegenEnabled { '@@xstate/typegen': true;}export interface TypegenMeta extends TypegenEnabled { /** * Allows you to specify all the results of state.matches */ matchesStates: string | {}; /** * Allows you to specify all tags used by the machine */ tags: string; /** * Allows you to specify all the missing implementations * of the machine */ missingImplementations: { actions: string; delays: string; guards: string; services: string; }; /** * A map for the internal events of the machine. * * key: 'done.invoke.myService' * value: { * type: 'done.invoke.myService'; * data: unknown; * __tip: 'Declare the type in event types!'; * } */ internalEvents: {}; /** * Maps the name of the service to the event type * of the done.invoke action * * key: 'invokeSrc' * value: 'done.invoke.invokeName' */ invokeSrcNameMap: Record<string, string>; /** * Keeps track of which events lead to which * actions. * * Key: 'EVENT_NAME' * Value: 'actionName' | 'otherActionName' */ eventsCausingActions: Record<string, string>; /** * Keeps track of which events lead to which * delays. * * Key: 'EVENT_NAME' * Value: 'delayName' | 'otherDelayName' */ eventsCausingDelays: Record<string, string>; /** * Keeps track of which events lead to which * guards. * * Key: 'EVENT_NAME' * Value: 'guardName' | 'otherGuardName' */ eventsCausingGuards: Record<string, string>; /** * Keeps track of which events lead to which * services. * * Key: 'EVENT_NAME' * Value: 'serviceName' | 'otherServiceName' */ eventsCausingServices: Record<string, string>;}
export interface ResolvedTypegenMeta extends TypegenMeta { resolved: TypegenMeta & { indexedActions: Record<string, BaseActionObject>; indexedEvents: Record<string, EventObject>; };}
export type TypegenConstraint = TypegenEnabled | TypegenDisabled;
// if combined union of all missing implementation types is never then everything has been providedexport type AreAllImplementationsAssumedToBeProvided< TResolvedTypesMeta, TMissingImplementations = Prop< Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations' >> = IsAny<TResolvedTypesMeta> extends true ? true : TResolvedTypesMeta extends TypegenEnabled ? IsNever< Values< { [K in keyof TMissingImplementations]: TMissingImplementations[K]; } > > extends true ? true : false : true;
interface AllImplementationsProvided { missingImplementations: { actions: never; delays: never; guards: never; services: never; };}
export interface MarkAllImplementationsAsProvided<TResolvedTypesMeta> { '@@xstate/typegen': Prop<TResolvedTypesMeta, '@@xstate/typegen'>; resolved: Prop<TResolvedTypesMeta, 'resolved'> & AllImplementationsProvided;}
type GenerateServiceEvent< TServiceName, TEventType, TServiceMap extends ServiceMap> = TEventType extends any ? { type: TEventType; } & Prop<TServiceMap, TServiceName> : never;
type GenerateServiceEvents< TServiceMap extends ServiceMap, TInvokeSrcNameMap> = string extends keyof TServiceMap ? never : Cast< { [K in keyof TInvokeSrcNameMap]: GenerateServiceEvent< K, TInvokeSrcNameMap[K], TServiceMap >; }[keyof TInvokeSrcNameMap], EventObject >;
// we don't even have to do that much here, technically, because `T & unknown` is equivalent to `T`// however, this doesn't display nicely in IDE tooltips, so let's fix thistype MergeWithInternalEvents<TIndexedEvents, TInternalEvents> = TIndexedEvents & // alternatively we could consider using key remapping in mapped types for this in the future // in theory it would be a single iteration rather than two Pick<TInternalEvents, Exclude<keyof TInternalEvents, keyof TIndexedEvents>>;
type AllowAllEvents = { eventsCausingActions: Record<string, string>; eventsCausingDelays: Record<string, string>; eventsCausingGuards: Record<string, string>; eventsCausingServices: Record<string, string>;};
export interface ResolveTypegenMeta< TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TAction extends BaseActionObject, TServiceMap extends ServiceMap> { '@@xstate/typegen': TTypesMeta['@@xstate/typegen']; resolved: { enabled: TTypesMeta & { indexedActions: IndexByType<TAction>; indexedEvents: MergeWithInternalEvents< IndexByType< | (string extends TEvent['type'] ? never : TEvent) | GenerateServiceEvents< TServiceMap, Prop<TTypesMeta, 'invokeSrcNameMap'> > >, Prop<TTypesMeta, 'internalEvents'> >; }; disabled: TypegenDisabled & AllImplementationsProvided & AllowAllEvents & { indexedActions: IndexByType<TAction>; indexedEvents: Record<string, TEvent> & { __XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__: { data: any }; }; invokeSrcNameMap: Record< string, '__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__' >; }; }[IsNever<TTypesMeta> extends true ? 'disabled' : TTypesMeta extends TypegenEnabled ? 'enabled' : 'disabled'];}
xstate

Version Info

Tagged at
2 years ago