import type { BaseDriverCapConstraints, Constraint, Constraints } from './constraints'; import type { StandardCapabilities } from './standard-caps'; import type { AnyCase, StringRecord } from './util'; export type { StandardCapabilities }; export type W3C_APPIUM_PREFIX = 'appium'; /** * Base capabilities as derived from {@linkcode BaseDriverCapConstraints}. */ export type BaseCapabilities = Capabilities; /** * Like {@linkcode BaseCapabilities}, except all Appium-specific keys are namespaced. */ export type BaseNSCapabilities = NSCapabilities; /** * Like {@linkcode NSBaseCapabilities}, except W3C-style. * @see {@linkcode W3CCapabilities} */ export type BaseW3CCapabilities = W3CCapabilities; /** * 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`. */ export type ConstraintChoice = C['inclusionCaseInsensitive'] extends T[] ? AnyCase : C['inclusion'] extends ReadonlyArray ? C['inclusion'][number] : T; /** * Given {@linkcode Constraint} `C`, determine the associated type of the capability. * * Notes: * * - Only `number` and `string` values can have "choices" (`inclusion`/`inclusionCaseInesnsitive`) associated with them. * - If `isArray` is `true`, the type is always of type `string[]`. If this is incorrect, then it will be `any[]`. * - There is no way to express the shape of an object if `ifObject` is `true`. */ export type ConstraintToCapKind = C['isString'] extends true ? ConstraintChoice : C['isNumber'] extends true ? ConstraintChoice : C['isBoolean'] extends true ? boolean : C['isArray'] extends true ? string[] : C['isObject'] extends true ? StringRecord : unknown; /** * Given {@linkcode Constraint} `C`, determine if it is required or optional. * * In practice, _all_ capabilities are considered optional per types, but various errors might be thrown if some are not present. */ export type ConstraintToCap = C['presence'] extends true | { allowEmpty: boolean; } ? ConstraintToCapKind : ConstraintToCapKind | undefined; /** * 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`. * * If `T` is already namespaced, well, it'll get _double_-namespaced. */ export type CapsToNSCaps = { [K in keyof T as K extends keyof StandardCapabilities ? K : NamespacedString]: T[K]; }; /** * A namespaced string of the format `:` where `NS` defaults to the value of * {@linkcode W3C_APPIUM_PREFIX} and `S` is a string. */ export type NamespacedString = `${NS}:${S}`; /** * Converts {@linkcode Constraint} `C` to a {@linkcode Capabilities} object. * @privateRemarks I would like to figure out how to simplify this type */ export type ConstraintsToCaps = { -readonly [K in keyof C]: ConstraintToCap; }; /** * Given some constraints, return the entire set of supported capabilities it supports (including whatever is in its desired caps). * * Does not contain {@linkcode BaseCapabilities}; see {@linkcode DriverCaps}. */ export type Capabilities = ConstraintsToCaps; /** * Like {@linkcode Capabilities}, except W3C-style. * * Does not contain {@linkcode BaseCapabilities}; see {@linkcode W3CDriverCaps}. */ export interface W3CCapabilities { alwaysMatch: NSCapabilities; firstMatch: NSCapabilities[]; } /** * Namespaced caps (where appropriate). * * Does not contain {@linkcode BaseCapabilities}; see {@linkcode NSDriverCaps}. */ export type NSCapabilities = Partial, NS>>; /** * Capabilities for drivers extending `BaseDriver`. * * Includes {@linkcode BaseCapabilities}. * * @example * ```ts * class MyDriver extends BaseDriver { * async createSession (w3ccaps: W3CDriverCaps, ...args: any[]) { * const [ * sessionId: string, * caps: DriverCaps * ] = await super.createSession(w3ccaps, ...args); * // ... * } * } * ``` */ /** * Normalized capabilities for drivers extending `BaseDriver`. * Includes {@linkcode BaseCapabilities}. */ export type DriverCaps = BaseCapabilities & Capabilities; /** * W3C-style capabilities for drivers extending `BaseDriver`. * * Includes {@linkcode BaseW3CCapabilities}. * * @example * ```ts * class MyDriver extends BaseDriver { * async createSession (w3ccaps: W3CDriverCaps, ...args: any[]) { * // ... * } * } * ``` */ export type W3CDriverCaps = BaseW3CCapabilities & W3CCapabilities; /** * Namespaced capabilities for drivers extending `BaseDriver`. * * Includes {@linkcode BaseNSCapabilities}. */ export type NSDriverCaps = BaseNSCapabilities & NSCapabilities; //# sourceMappingURL=capabilities.d.ts.map