-
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
types.ts
239 lines (209 loc) · 6.8 KB
/
types.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import {
Comment,
DeclarationReflection,
LiteralType,
ParameterReflection,
ReferenceType,
ReflectionFlags,
ReflectionKind,
ReflectionType,
SignatureReflection,
SomeType,
TupleType,
TypeOperatorType,
} from 'typedoc';
import {AllowedHttpMethod, ParentReflection} from '../model';
import {NAME_EXTERNAL_DRIVER, NAME_TYPES_MODULE} from './builtin-external-driver';
import {NAME_BUILTIN_COMMAND_MODULE, NAME_METHOD_MAP} from './builtin-method-map';
import {NAME_NEW_METHOD_MAP, NAME_EXECUTE_METHOD_MAP, NAME_PARAMS} from './external';
type WithName<S extends string, R> = R & {
name: S;
};
type WithKind<K extends ReflectionKind, R> = R & {kind: K};
/**
* Utility to narrow a declaration reflection to a specific `SomeType`
*/
type WithSomeType<T extends SomeType, R> = R & {type: T};
type WithNameAndKind<S extends string, K extends ReflectionKind, R> = R & {name: S; kind: K};
/**
* Utility; a TupleType with literal elements
*/
export type TupleTypeWithLiteralElements = TupleType & {elements: LiteralType[]};
/**
* Type corresponding to a reflection of a {@linkcode @appium/types#MethodMap}
*/
export type MethodMapDeclarationReflection = WithName<
typeof NAME_METHOD_MAP | typeof NAME_NEW_METHOD_MAP,
DeclarationReflectionWithReflectedType
>;
/**
* Type corresponding to a reflection of {@linkcode @appium/base-driver}
*/
export type BaseDriverDeclarationReflection = WithNameAndKind<
typeof NAME_BUILTIN_COMMAND_MODULE,
ReflectionKind.Module,
DeclarationReflection
>;
/**
* Type for the parameters of a command definition or execute method definition.
*
* Node that merging `TypeOperatorType` won't work because it will no longer satisfy `SomeType`, because `SomeType` is a finite collection.
*/
export type MethodDefParamNamesDeclarationReflection = WithSomeType<
TypeOperatorTypeWithTupleTypeWithLiteralElements,
DeclarationReflection
>;
export type TypeOperatorTypeWithTupleTypeWithLiteralElements = TypeOperatorType & {
operator: 'readonly';
target: TupleTypeWithLiteralElements;
};
/**
* Narrows a declaration reflection to one having a reflection type and a property kind. Generic
*/
export type PropDeclarationReflection = WithKind<
ReflectionKind.Property,
DeclarationReflectionWithReflectedType
>;
/**
* A type corresponding to the HTTP method of a route, which is a property off of the object with the route name in a `MethodMap`
*/
export type HTTPMethodDeclarationReflection = WithName<
AllowedHttpMethod,
PropDeclarationReflection
>;
/**
* A declaration reflection having a reflection type. Generic
*/
export type DeclarationReflectionWithReflectedType = WithSomeType<
ReflectionType,
DeclarationReflection
>;
/**
* Type corresponding to the value of the `command` property within a `MethodDef`, which must be a type literal.
*/
export type CommandPropDeclarationReflection = WithSomeType<LiteralType, DeclarationReflection>;
/**
* A generic type guard
*/
export type Guard<T> = (value: any) => value is T;
/**
* Type corresponding to an execute method map
*/
export type ExecMethodDeclarationReflection = WithName<
typeof NAME_EXECUTE_METHOD_MAP,
DeclarationReflectionWithReflectedType
> & {
flags: ReflectionFlags & {isStatic: true};
};
export type WithStaticFlag = {flags: ReflectionFlags & {isStatic: true}};
export type WithoutStaticFlag = {flags: ReflectionFlags & {isStatic: false}};
/**
* Type corresponding to the `params` prop of a `MethodDef`
*/
export type MethodDefParamsPropDeclarationReflection = WithNameAndKind<
typeof NAME_PARAMS,
ReflectionKind.Property,
DeclarationReflectionWithReflectedType
>;
/**
* Type corresponding to the `payloadParams` prop of an `ExecMethodDef`
*/
export type ExecMethodDefParamsPropDeclarationReflection = WithName<
typeof NAME_PARAMS,
DeclarationReflectionWithReflectedType
>;
/**
* Type corresponding to `@appium/types` module
*/
export type AppiumTypesReflection = WithNameAndKind<
typeof NAME_TYPES_MODULE,
ReflectionKind.Module,
ParentReflection
>;
/**
* Type corresponding to a TS `interface`
*/
export type InterfaceDeclarationReflection = WithKind<
ReflectionKind.Interface,
DeclarationReflection
>;
/**
* Type corresponding to the `ExternalDriver` `interface` of `@appium/types`
*/
export type ExternalDriverDeclarationReflection = WithName<
typeof NAME_EXTERNAL_DRIVER,
InterfaceDeclarationReflection
>;
/**
* A call signature for a function that returns some sort of `Promise`.
*/
export type AsyncCallSignatureReflection = CallSignatureReflection & {
type: ReferenceType;
name: 'Promise';
};
/**
* An async method or reference to an async method. A command's method must be of this type.
*/
export type AsyncMethodDeclarationReflection<
T extends ReferenceType | ReflectionType = ReferenceType
> = WithSomeType<T, DeclarationReflection> &
WithKind<
T extends ReferenceType ? ReflectionKind.Method : ReflectionKind.Property,
DeclarationReflection
> &
WithoutStaticFlag &
(T extends ReferenceType
? {
signatures: NonEmptyArray<AsyncCallSignatureReflection>;
}
: T extends ReflectionType
? {
type: {
declaration: {
signatures: NonEmptyArray<AsyncCallSignatureReflection>;
};
};
}
: never);
/**
* A little "struct" containing a method and potentially a derived comment (which may not have been derived from
* the method itself).
*/
export interface KnownMethodData {
comment?: Comment;
method: AsyncMethodDeclarationReflection;
}
/**
* A lookup of command names to {@linkcode KnownMethodData} objects.
*/
export type KnownMethods = Map<string, KnownMethodData>;
/**
* A {@linkcode DeclarationReflection} which is a `class`.
*/
export type ClassDeclarationReflection = WithKind<ReflectionKind.Class, DeclarationReflection>;
/**
* One of {@linkcode ExecMethodDefParamsPropDeclarationReflection} or
* {@linkcode MethodDefParamsPropDeclarationReflection}, which are "parameters" properties of method
* definition objects (as in a `MethodMap`) or execute method definitions (in an `ExecMethodMap`)
*/
export type ParamsPropDeclarationReflection =
| ExecMethodDefParamsPropDeclarationReflection
| MethodDefParamsPropDeclarationReflection;
/**
* A {@linkcode SignatureReflection} which is a call signature; a function signature.
*
* (Other types of signatures include things like "constructor signatures")
*/
export type CallSignatureReflection = WithKind<ReflectionKind.CallSignature, SignatureReflection>;
/**
* An array with a nonzero number of items.
*/
export type NonEmptyArray<T> = [T, ...T[]];
/**
* A {@linkcode CallSignatureReflection} with a nonzero number of parameters.
*
* This is used to rename parameters on commands to prefer the ones as defined in the method map.
*/
export type CallSignatureReflectionWithArity = CallSignatureReflection & {
parameters: NonEmptyArray<ParameterReflection>;
};