@appium/types 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/lib/action.d.ts +1 -7
  2. package/build/lib/action.d.ts.map +1 -1
  3. package/build/lib/action.js.map +1 -1
  4. package/build/lib/capabilities.d.ts +34 -23
  5. package/build/lib/capabilities.d.ts.map +1 -1
  6. package/build/lib/command.d.ts +24 -6
  7. package/build/lib/command.d.ts.map +1 -1
  8. package/build/lib/config.d.ts +2 -13
  9. package/build/lib/config.d.ts.map +1 -1
  10. package/build/lib/config.js.map +1 -1
  11. package/build/lib/constraints.d.ts +54 -67
  12. package/build/lib/constraints.d.ts.map +1 -1
  13. package/build/lib/constraints.js +2 -5
  14. package/build/lib/constraints.js.map +1 -1
  15. package/build/lib/driver.d.ts +206 -281
  16. package/build/lib/driver.d.ts.map +1 -1
  17. package/build/lib/http.d.ts +11 -0
  18. package/build/lib/http.d.ts.map +1 -0
  19. package/build/lib/http.js +3 -0
  20. package/build/lib/http.js.map +1 -0
  21. package/build/lib/index.d.ts +5 -104
  22. package/build/lib/index.d.ts.map +1 -1
  23. package/build/lib/index.js +5 -3
  24. package/build/lib/index.js.map +1 -1
  25. package/build/lib/logger.d.ts +39 -0
  26. package/build/lib/logger.d.ts.map +1 -0
  27. package/build/lib/logger.js +3 -0
  28. package/build/lib/logger.js.map +1 -0
  29. package/build/lib/plugin.d.ts +29 -5
  30. package/build/lib/plugin.d.ts.map +1 -1
  31. package/build/lib/server.d.ts +60 -0
  32. package/build/lib/server.d.ts.map +1 -0
  33. package/build/lib/server.js +3 -0
  34. package/build/lib/server.js.map +1 -0
  35. package/build/lib/util.d.ts +67 -0
  36. package/build/lib/util.d.ts.map +1 -0
  37. package/build/lib/util.js +3 -0
  38. package/build/lib/util.js.map +1 -0
  39. package/lib/action.ts +1 -7
  40. package/lib/capabilities.ts +40 -53
  41. package/lib/command.ts +30 -10
  42. package/lib/config.ts +2 -36
  43. package/lib/{constraints.js → constraints.ts} +5 -5
  44. package/lib/driver.ts +240 -345
  45. package/lib/http.ts +31 -0
  46. package/lib/index.ts +5 -143
  47. package/lib/logger.ts +41 -0
  48. package/lib/plugin.ts +37 -6
  49. package/lib/server.ts +73 -0
  50. package/lib/util.ts +91 -0
  51. package/package.json +5 -4
@@ -1,6 +1,7 @@
1
- import {StandardCapabilities} from './standard-caps';
2
- import {StringRecord, Constraint, Constraints} from '.';
3
1
  import {BaseDriverCapConstraints} from './constraints';
2
+ import {Constraint, Constraints} from './driver';
3
+ import {StandardCapabilities} from './standard-caps';
4
+ import {AnyCase, StringRecord} from './util';
4
5
 
5
6
  export {StandardCapabilities};
6
7
 
@@ -9,20 +10,23 @@ export type W3C_APPIUM_PREFIX = 'appium';
9
10
  /**
10
11
  * Base capabilities as derived from {@linkcode BaseDriverCapConstraints}.
11
12
  */
12
- export type BaseCapabilities = ConstraintsToCaps<BaseDriverCapConstraints>;
13
+ export type BaseCapabilities = Capabilities<BaseDriverCapConstraints>;
13
14
 
14
15
  /**
15
16
  * Like {@linkcode BaseCapabilities}, except all Appium-specific keys are namespaced.
16
17
  */
17
- export type BaseNSCapabilities = CapsToNSCaps<ConstraintsToCaps<BaseDriverCapConstraints>>;
18
+ export type BaseNSCapabilities = NSCapabilities<BaseDriverCapConstraints>;
19
+
20
+ /**
21
+ * Like {@linkcode NSBaseCapabilities}, except W3C-style.
22
+ * @see {@linkcode W3CCapabilities}
23
+ */
24
+ export type BaseW3CCapabilities = W3CCapabilities<BaseDriverCapConstraints>;
18
25
 
19
26
  /**
20
27
  * Given a {@linkcode Constraint} `C` and a type `T`, see if `inclusion`/`inclusionCaseInsensitive` is present, and create a union of its allowed literals; otherwise just use `T`.
21
28
  */
22
- type ConstraintChoice<
23
- C extends Constraint,
24
- T
25
- > = C['inclusionCaseInsensitive'] extends ReadonlyArray<T>
29
+ export type ConstraintChoice<C extends Constraint, T> = C['inclusionCaseInsensitive'] extends T[]
26
30
  ? AnyCase<C['inclusionCaseInsensitive'][number]>
27
31
  : C['inclusion'] extends ReadonlyArray<T>
28
32
  ? C['inclusion'][number]
@@ -37,7 +41,7 @@ type ConstraintChoice<
37
41
  * - If `isArray` is `true`, the type is always of type `string[]`. If this is incorrect, then it will be `any[]`.
38
42
  * - There is no way to express the shape of an object if `ifObject` is `true`.
39
43
  */
40
- type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true
44
+ export type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true
41
45
  ? ConstraintChoice<C, string>
42
46
  : C['isNumber'] extends true
43
47
  ? ConstraintChoice<C, number>
@@ -47,7 +51,7 @@ type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true
47
51
  ? string[]
48
52
  : C['isObject'] extends true
49
53
  ? object
50
- : any;
54
+ : unknown;
51
55
 
52
56
  /**
53
57
  * Given {@linkcode Constraint} `C`, determine if it is required or optional.
@@ -60,17 +64,6 @@ export type ConstraintToCap<C extends Constraint> = C['presence'] extends
60
64
  ? ConstraintToCapKind<C>
61
65
  : ConstraintToCapKind<C> | undefined;
62
66
 
63
- /**
64
- * Given `string` `T`, this is a case-insensitive version of `T`.
65
- */
66
- export type AnyCase<T extends string> = string extends T
67
- ? string
68
- : T extends `${infer F1}${infer F2}${infer R}`
69
- ? `${Uppercase<F1> | Lowercase<F1>}${Uppercase<F2> | Lowercase<F2>}${AnyCase<R>}`
70
- : T extends `${infer F}${infer R}`
71
- ? `${Uppercase<F> | Lowercase<F>}${AnyCase<R>}`
72
- : '';
73
-
74
67
  /**
75
68
  * Given {@linkcode StringRecord} `T` and namespace string `NS`, a type with the key names prefixed by `${NS}:` _except_ for standard capabilities. `NS` defaults to `appium`.
76
69
  *
@@ -82,6 +75,10 @@ export type CapsToNSCaps<T extends StringRecord, NS extends string = W3C_APPIUM_
82
75
  : NamespacedString<K & string, NS>]: T[K];
83
76
  };
84
77
 
78
+ /**
79
+ * A namespaced string of the format `<NS>:<S>` where `NS` defaults to the value of
80
+ * {@linkcode W3C_APPIUM_PREFIX} and `S` is a string.
81
+ */
85
82
  export type NamespacedString<
86
83
  S extends string,
87
84
  NS extends string = W3C_APPIUM_PREFIX
@@ -89,6 +86,7 @@ export type NamespacedString<
89
86
 
90
87
  /**
91
88
  * Converts {@linkcode Constraint} `C` to a {@linkcode Capabilities} object.
89
+ * @privateRemarks I would like to figure out how to simplify this type
92
90
  */
93
91
  export type ConstraintsToCaps<C extends Constraints> = {
94
92
  -readonly [K in keyof C]: ConstraintToCap<C[K]>;
@@ -99,34 +97,26 @@ export type ConstraintsToCaps<C extends Constraints> = {
99
97
  *
100
98
  * Does not contain {@linkcode BaseCapabilities}; see {@linkcode DriverCaps}.
101
99
  */
102
- export type Capabilities<
103
- C extends Constraints = BaseDriverCapConstraints,
104
- Extra extends StringRecord | void = void
105
- > = Partial<ConstraintsToCaps<C> & Extra>;
100
+ export type Capabilities<C extends Constraints> = ConstraintsToCaps<C>;
106
101
 
107
102
  /**
108
103
  * Like {@linkcode Capabilities}, except W3C-style.
109
104
  *
110
105
  * Does not contain {@linkcode BaseCapabilities}; see {@linkcode W3CDriverCaps}.
111
106
  */
112
- export type W3CCapabilities<
113
- C extends Constraints = BaseDriverCapConstraints,
114
- Extra extends StringRecord | void = void
115
- > = {
116
- alwaysMatch: NSCapabilities<C, Extra>;
117
- firstMatch: NSCapabilities<C, Extra>[];
118
- };
107
+ export interface W3CCapabilities<C extends Constraints> {
108
+ alwaysMatch: NSCapabilities<C>;
109
+ firstMatch: NSCapabilities<C>[];
110
+ }
119
111
 
120
112
  /**
121
113
  * Namespaced caps (where appropriate).
122
114
  *
123
115
  * Does not contain {@linkcode BaseCapabilities}; see {@linkcode NSDriverCaps}.
124
116
  */
125
- export type NSCapabilities<
126
- C extends Constraints = BaseDriverCapConstraints,
127
- Extra extends StringRecord | void = void,
128
- NS extends string = W3C_APPIUM_PREFIX
129
- > = Partial<CapsToNSCaps<ConstraintsToCaps<C> & Extra, NS>>;
117
+ export type NSCapabilities<C extends Constraints, NS extends string = W3C_APPIUM_PREFIX> = Partial<
118
+ CapsToNSCaps<ConstraintsToCaps<C>, NS>
119
+ >;
130
120
 
131
121
  /**
132
122
  * Capabilities for drivers extending `BaseDriver`.
@@ -135,7 +125,7 @@ export type NSCapabilities<
135
125
  *
136
126
  * @example
137
127
  * ```ts
138
- * class MyDriver extends BaseDriver {
128
+ * class MyDriver extends BaseDriver<MyDriverConstraints> {
139
129
  * async createSession (w3ccaps: W3CDriverCaps<MyDriverConstraints>, ...args: any[]) {
140
130
  * const [
141
131
  * sessionId: string,
@@ -147,36 +137,33 @@ export type NSCapabilities<
147
137
  * ```
148
138
  */
149
139
 
150
- export type DriverCaps<
151
- C extends Constraints,
152
- Extra extends StringRecord | void = void
153
- > = Capabilities<BaseDriverCapConstraints & C, Extra>;
140
+ /**
141
+ * Normalized capabilities for drivers extending `BaseDriver`.
142
+ * Includes {@linkcode BaseCapabilities}.
143
+ */
144
+ export type DriverCaps<C extends Constraints = Constraints> = BaseCapabilities & Capabilities<C>;
154
145
 
155
146
  /**
156
147
  * W3C-style capabilities for drivers extending `BaseDriver`.
157
148
  *
158
- * Includes {@linkcode BaseCapabilities}.
149
+ * Includes {@linkcode BaseW3CCapabilities}.
159
150
  *
160
151
  * @example
161
152
  * ```ts
162
- * class MyDriver extends BaseDriver {
153
+ * class MyDriver extends BaseDriver<MyDriverConstraints> {
163
154
  * async createSession (w3ccaps: W3CDriverCaps<MyDriverConstraints>, ...args: any[]) {
164
155
  * // ...
165
156
  * }
166
157
  * }
167
158
  * ```
168
159
  */
169
- export type W3CDriverCaps<
170
- C extends Constraints,
171
- Extra extends StringRecord | void = void
172
- > = W3CCapabilities<BaseDriverCapConstraints & C, Extra>;
160
+ export type W3CDriverCaps<C extends Constraints = Constraints> = BaseW3CCapabilities &
161
+ W3CCapabilities<C>;
173
162
 
174
163
  /**
175
164
  * Namespaced capabilities for drivers extending `BaseDriver`.
176
165
  *
177
- * Includes {@linkcode BaseCapabilities}.
166
+ * Includes {@linkcode BaseNSCapabilities}.
178
167
  */
179
- export type NSDriverCaps<
180
- C extends Constraints,
181
- Extra extends StringRecord | void = void
182
- > = NSCapabilities<BaseDriverCapConstraints & C, Extra>;
168
+ export type NSDriverCaps<C extends Constraints = Constraints> = BaseNSCapabilities &
169
+ NSCapabilities<C>;
package/lib/command.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {ConditionalPick, MultidimensionalReadonlyArray} from 'type-fest';
2
2
  import {Driver, DriverCommand} from './driver';
3
3
  import {Plugin, PluginCommand} from './plugin';
4
+ import {StringRecord} from './util';
4
5
 
5
6
  /**
6
7
  * Defines the shape of a payload for a {@linkcode MethodDef}.
@@ -15,17 +16,30 @@ export interface PayloadParams {
15
16
  }
16
17
  /**
17
18
  * A mapping of URL paths to HTTP methods to either a {@linkcode DriverMethodDef} or {@linkcode PluginMethodDef}.
19
+ *
20
+ * Extensions can define new methods for the Appium server to map to command names, of the same
21
+ * format as used in Appium's `routes.js`.
22
+ *
23
+ * @example
24
+ * ```js
25
+ * {
26
+ * '/session/:sessionId/new_method': {
27
+ * GET: {command: 'getNewThing'},
28
+ * POST: {command: 'setNewThing', payloadParams: {required: ['someParam']}}
29
+ * }
30
+ * }
31
+ * ```
18
32
  */
19
- export type MethodMap<T extends Plugin | Driver> = T extends Plugin
33
+ export type MethodMap<T extends Plugin | Driver<any>> = T extends Plugin
20
34
  ? Readonly<PluginMethodMap<T>>
21
- : T extends Driver
35
+ : T extends Driver<any>
22
36
  ? Readonly<DriverMethodMap<T>>
23
37
  : never;
24
38
 
25
39
  /**
26
40
  * A {@linkcode MethodMap} for a {@linkcode Driver}.
27
41
  */
28
- export interface DriverMethodMap<T extends Driver> {
42
+ export interface DriverMethodMap<T extends Driver<any>> {
29
43
  [key: string]: {
30
44
  GET?: DriverMethodDef<T>;
31
45
  POST?: DriverMethodDef<T>;
@@ -50,11 +64,17 @@ export interface BaseMethodDef {
50
64
  /**
51
65
  * A definition of an exposed API command in a {@linkcode Driver}.
52
66
  */
53
- export interface DriverMethodDef<T extends Driver> extends BaseMethodDef {
67
+ export interface DriverMethodDef<T extends Driver, D extends boolean = boolean>
68
+ extends BaseMethodDef {
54
69
  /**
55
70
  * Name of the command.
56
71
  */
57
- readonly command?: keyof ConditionalPick<Required<T>, DriverCommand>;
72
+ readonly command?: D extends true ? string : keyof ConditionalPick<Required<T>, DriverCommand>;
73
+
74
+ /**
75
+ * If this is `true`, we do not validate `command`, because it may not exist in `ExternalDriver`.
76
+ */
77
+ readonly deprecated?: D;
58
78
  }
59
79
 
60
80
  /**
@@ -98,7 +118,7 @@ export interface BaseExecuteMethodDef {
98
118
  /**
99
119
  * A definition of an execute method in a {@linkcode Driver}.
100
120
  */
101
- export interface DriverExecuteMethodDef<T extends Driver> extends BaseExecuteMethodDef {
121
+ export interface DriverExecuteMethodDef<T extends Driver<any>> extends BaseExecuteMethodDef {
102
122
  command: keyof ConditionalPick<T, DriverCommand>;
103
123
  }
104
124
 
@@ -112,8 +132,8 @@ export interface PluginExecuteMethodDef<T extends Plugin> extends BaseExecuteMet
112
132
  /**
113
133
  * Definition of an execute method (which overloads the behavior of the `execute` command) in a {@linkcode Driver} or {@linkcode Plugin}.
114
134
  */
115
- export type ExecuteMethodMap<T extends Plugin | Driver> = T extends Plugin
116
- ? Readonly<Record<string, PluginExecuteMethodDef<T>>>
117
- : T extends Driver
118
- ? Readonly<Record<string, DriverExecuteMethodDef<T>>>
135
+ export type ExecuteMethodMap<T extends Plugin | Driver<any>> = T extends Plugin
136
+ ? Readonly<StringRecord<PluginExecuteMethodDef<T>>>
137
+ : T extends Driver<any>
138
+ ? Readonly<StringRecord<DriverExecuteMethodDef<T>>>
119
139
  : never;
package/lib/config.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {AppiumConfigJsonSchema} from '@appium/schema';
2
2
  import {AppiumConfiguration, ServerConfig} from './appium-config';
3
+ import {Associated, KebabToCamel} from './util';
3
4
 
4
5
  /**
5
6
  * The Appium configuration as it would be in a user-provided configuration file.
@@ -9,7 +10,7 @@ export type AppiumConfig = Partial<AppiumConfiguration>;
9
10
  /**
10
11
  * Derive the "constant" type of the server properties from the schema.
11
12
  */
12
- type AppiumServerJsonSchema = typeof AppiumConfigJsonSchema['properties']['server']['properties'];
13
+ type AppiumServerJsonSchema = (typeof AppiumConfigJsonSchema)['properties']['server']['properties'];
13
14
 
14
15
  /**
15
16
  * This type associates the types generated from the schema ({@linkcode AppiumConfiguration})
@@ -61,41 +62,6 @@ type KeyOrDefaultForProp<Prop extends keyof ServerConfigMapping> =
61
62
  export type ServerArgs = {
62
63
  [Prop in keyof ServerConfigMapping as SetKeyForProp<Prop>]: KeyOrDefaultForProp<Prop>;
63
64
  };
64
- // begin utils
65
-
66
- /**
67
- * Converts a kebab-cased string into a camel-cased string.
68
- */
69
- type KebabToCamel<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}`
70
- ? `${Lowercase<P1>}${Uppercase<P2>}${KebabToCamel<P3>}`
71
- : Lowercase<S>;
72
-
73
- /**
74
- * Converts an object with kebab-cased keys into camel-cased keys.
75
- */
76
- type ObjectToCamel<T> = {
77
- [K in keyof T as KebabToCamel<string & K>]: T[K] extends Record<string, any>
78
- ? KeysToCamelCase<T[K]>
79
- : T[K];
80
- };
81
-
82
- /**
83
- * Converts an object or array to have camel-cased keys.
84
- */
85
- type KeysToCamelCase<T> = {
86
- [K in keyof T as KebabToCamel<string & K>]: T[K] extends Array<any>
87
- ? KeysToCamelCase<T[K][number]>[]
88
- : ObjectToCamel<T[K]>;
89
- };
90
-
91
- /**
92
- * Object `B` has all the keys as object `A` (even if those keys in `A` are otherwise optional).
93
- */
94
- type Associated<A extends object, B extends {[key in keyof Required<A>]: unknown}> = {
95
- [Prop in keyof Required<A>]: B[Prop];
96
- };
97
-
98
- // end utils
99
65
 
100
66
  // begin conditionals
101
67
 
@@ -1,4 +1,6 @@
1
- export const BASE_DESIRED_CAP_CONSTRAINTS = /** @type {const} */ ({
1
+ import {Constraints} from './driver';
2
+
3
+ export const BASE_DESIRED_CAP_CONSTRAINTS = {
2
4
  platformName: {
3
5
  presence: true,
4
6
  isString: true,
@@ -51,8 +53,6 @@ export const BASE_DESIRED_CAP_CONSTRAINTS = /** @type {const} */ ({
51
53
  printPageSourceOnFindFailure: {
52
54
  isBoolean: true,
53
55
  },
54
- });
56
+ } as const satisfies Constraints;
55
57
 
56
- /**
57
- * @typedef {typeof BASE_DESIRED_CAP_CONSTRAINTS} BaseDriverCapConstraints
58
- */
58
+ export type BaseDriverCapConstraints = typeof BASE_DESIRED_CAP_CONSTRAINTS;