UNPKG

3.46 kBTypeScriptView Raw
1import type { EventEmitter } from 'node:events';
2import type { Options, Capabilities, ThenArg } from '@wdio/types';
3import type { WebDriverBidiProtocol, ProtocolCommands } from '@wdio/protocols';
4import type { BidiHandler } from './bidi/handler.js';
5import type { EventData } from './bidi/localTypes.js';
6import type { CommandData } from './bidi/remoteTypes.js';
7import type { CommandResponse } from './bidi/localTypes.js';
8import type { RequestStartEvent, RequestEndEvent, RequestPerformanceEvent, RequestRetryEvent } from './request/types.js';
9export interface JSONWPCommandError extends Error {
10 code?: string;
11 statusCode?: string;
12 statusMessage?: string;
13}
14export interface SessionFlags {
15 isW3C: boolean;
16 isChromium: boolean;
17 isFirefox: boolean;
18 isAndroid: boolean;
19 isMobile: boolean;
20 isNativeContext: boolean;
21 mobileContext: string | undefined;
22 isIOS: boolean;
23 isSauce: boolean;
24 isSeleniumStandalone: boolean;
25 isBidi: boolean;
26}
27type Fn = (...args: unknown[]) => unknown;
28type ValueOf<T> = T[keyof T];
29type ObtainMethods<T> = {
30 [Prop in keyof T]: T[Prop] extends Fn ? ThenArg<ReturnType<T[Prop]>> : never;
31};
32type WebDriverBidiCommands = typeof WebDriverBidiProtocol;
33export type BidiCommands = WebDriverBidiCommands[keyof WebDriverBidiCommands]['socket']['command'];
34export type BidiResponses = ValueOf<ObtainMethods<Pick<BidiHandler, BidiCommands>>>;
35export type RemoteConfig = Options.WebDriver & Capabilities.WithRequestedCapabilities;
36type BidiInterface = ObtainMethods<Pick<BidiHandler, BidiCommands>>;
37type WebDriverClassicEvents = {
38 command: {
39 command: string;
40 method: string;
41 endpoint: string;
42 body: unknown;
43 };
44 result: {
45 command: string;
46 method: string;
47 endpoint: string;
48 body: unknown;
49 result: unknown;
50 };
51 bidiCommand: Omit<CommandData, 'id'>;
52 bidiResult: CommandResponse;
53 'request.performance': RequestPerformanceEvent;
54 'request.retry': RequestRetryEvent;
55 'request.start': RequestStartEvent;
56 'request.end': RequestEndEvent;
57};
58export type BidiEventMap = {
59 [Event in keyof Omit<WebDriverBidiCommands, 'sendCommand' | 'sendAsyncCommand'>]: BidiInterface[WebDriverBidiCommands[Event]['socket']['command']];
60};
61type GetParam<T extends {
62 method: string;
63 params: unknown;
64}, U extends string> = T extends {
65 method: U;
66} ? T['params'] : never;
67export type EventMap = {
68 [Event in EventData['method']]: GetParam<EventData, Event>;
69} & WebDriverClassicEvents;
70interface BidiEventHandler {
71 on<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
72 once<K extends keyof EventMap>(event: K, listener: (this: Client, param: EventMap[K]) => void): this;
73}
74export interface BaseClient extends EventEmitter, SessionFlags {
75 sessionId: string;
76 capabilities: WebdriverIO.Capabilities;
77 requestedCapabilities: Capabilities.WithRequestedCapabilities['capabilities'];
78 options: Options.WebDriver;
79}
80export interface Client extends Omit<BaseClient, keyof BidiEventHandler>, ProtocolCommands, BidiHandler, BidiEventHandler {
81}
82export interface AttachOptions extends Partial<SessionFlags>, Partial<Options.WebDriver> {
83 sessionId: string;
84 capabilities?: WebdriverIO.Capabilities;
85 requestedCapabilities?: Capabilities.WithRequestedCapabilities['capabilities'];
86}
87export {};
88//# sourceMappingURL=types.d.ts.map
\No newline at end of file