import type {ConditionalPick, MultidimensionalReadonlyArray} from 'type-fest'; import type {Driver, DriverCommand} from './driver'; import type {Plugin, PluginCommand} from './plugin'; import type {StringRecord} from './util'; /** * Defines the shape of a payload for a {@linkcode MethodDef}. */ export interface PayloadParams { wrap?: string; unwrap?: string; required?: ReadonlyArray | MultidimensionalReadonlyArray; optional?: ReadonlyArray; validate?: (obj: any, protocol: string) => boolean | string | undefined; makeArgs?: (obj: any) => any; } /** * A mapping of URL paths to HTTP methods to either a {@linkcode DriverMethodDef} or {@linkcode PluginMethodDef}. * * Extensions can define new methods for the Appium server to map to command names, of the same * format as used in Appium's `routes.js`. * * @example * ```js * { * '/session/:sessionId/new_method': { * GET: {command: 'getNewThing'}, * POST: {command: 'setNewThing', payloadParams: {required: ['someParam']}} * } * } * ``` */ export type MethodMap = T extends Plugin ? Readonly> : T extends Driver ? Readonly> : never; /** * A {@linkcode MethodMap} for a {@linkcode Driver}. */ export interface DriverMethodMap { [key: string]: { GET?: DriverMethodDef; POST?: DriverMethodDef; DELETE?: DriverMethodDef; }; } /** * Both {@linkcode DriverMethodDef} and {@linkcode PluginMethodDef} share these properties. */ export interface BaseMethodDef { /** * If true, this `Method` will never proxy. */ readonly neverProxy?: boolean; /** * Specifies shape of payload */ readonly payloadParams?: PayloadParams; /** * If true, this `Method` will be removed and should not be used by clients */ readonly deprecated?: boolean; /** * Any additional info string or comments to this command. */ readonly info?: string; } /** * A definition of an exposed API command in a {@linkcode Driver}. */ export interface DriverMethodDef extends BaseMethodDef { /** * Name of the command. */ readonly command?: D extends true ? string : keyof ConditionalPick, DriverCommand>; } /** * A definition of an exposed API command in a {@linkcode Plugin}. */ export interface PluginMethodDef extends BaseMethodDef { /** * Name of the command. */ readonly command?: keyof ConditionalPick, PluginCommand>; } /** * A mapping of URL paths to HTTP methods to {@linkcode PluginMethodDef}. */ export interface PluginMethodMap { [key: string]: { GET?: PluginMethodDef; POST?: PluginMethodDef; DELETE?: PluginMethodDef; }; } export interface ExecuteMethodDef { command: keyof ConditionalPick< Required, Ext extends Plugin ? PluginCommand : Ext extends Driver ? DriverCommand : never >; } /** * Properties shared by execute method definitions in both plugins and drivers */ export interface BaseExecuteMethodDef { params?: { required?: ReadonlyArray; optional?: ReadonlyArray; }; /** * If this is `true`, then the method is marked for deprecation. */ readonly deprecated?: boolean; /** * Any additional info string or comments to this execute method. */ readonly info?: string; } /** * A definition of an execute method in a {@linkcode Driver}. */ export interface DriverExecuteMethodDef extends BaseExecuteMethodDef { command: keyof ConditionalPick; } /** * A definition of an execute method in a {@linkcode Plugin}. */ export interface PluginExecuteMethodDef extends BaseExecuteMethodDef { command: keyof ConditionalPick; } /** * Definition of an execute method (which overloads the behavior of the `execute` command) in a {@linkcode Driver} or {@linkcode Plugin}. */ export type ExecuteMethodMap = T extends Plugin ? Readonly>> : T extends Driver ? Readonly>> : never; export interface BidiMethodParams { required?: readonly string[]; optional?: readonly string[]; } export interface BidiMethodDef extends BaseExecuteMethodDef { command: string; params?: BidiMethodParams; } export interface BidiMethodMap { [k: string]: BidiMethodDef; } export interface BidiModuleMap { [k: string]: BidiMethodMap; } // https://w3c.github.io/webdriver-bidi/#protocol-definition export interface GenericBiDiCommandResponse { id: number; [key: string]: any; } export interface BiDiResultData { [key: string]: any; } export interface SuccessBiDiCommandResponse extends GenericBiDiCommandResponse { type: 'success'; result: BiDiResultData; } export interface ErrorBiDiCommandResponse extends GenericBiDiCommandResponse { type: 'error'; error: string; message: string; stacktrace?: string; } export interface RestCommandItemParam { /** * Command parameter name */ name: string; /** * True if the parameter is required for the given command */ required: boolean; } export interface RestCommandItem { /** * Command name */ command?: string; /** * Whether the command is marked for deprecation */ deprecated?: boolean; /** * Optional infostring about the command's purpose or a comment */ info?: string; /** * List of command parameters */ params?: RestCommandItemParam[]; } export interface RestMethodsToCommandsMap { /** * Method name to command info mapping */ [method: string]: RestCommandItem; } export interface RestCommandsMap { /** * Command paths to methods map in the base driver */ base: Record; /** * Command paths to methods map in the session-specific driver */ driver: Record; /** * Plugin name to command paths to methods map */ plugins?: Record>; } export interface BiDiCommandItemParam { /** * Command parameter name */ name: string; /** * True if the parameter is required for the given command */ required: boolean; } export interface BiDiCommandItem { /** * Command name */ command?: string; /** * Whether the command is marked for deprecation */ deprecated?: boolean; /** * Optional infostring about the command's purpose or a comment */ info?: string; /** * List of command parameters */ params?: BiDiCommandItemParam[]; } export interface BiDiCommandNamesToInfosMap { [name: string]: BiDiCommandItem; } export interface BiDiCommandsMap { /** * Domains to BiDi commands mapping in the base driver */ base: Record; /** * Domains to BiDi commands mapping in the session-specific driver */ driver: Record; /** * Plugin name to domains to BiDi commands mapping */ plugins?: Record>; } export interface ListCommandsResponse { /** * REST APIs mapping */ rest?: RestCommandsMap; /** * BiDi APIs mapping */ bidi?: BiDiCommandsMap; } export interface RestExtensionsMap { /** * Driver execute methods mapping */ driver: RestMethodsToCommandsMap; /** * Plugins execute methods mapping */ plugins?: Record; } export interface ListExtensionsResponse { /** * Rest extensions mapping */ rest?: RestExtensionsMap; }