Skip to content

Commit

Permalink
fix(types): update some more types to reflect reality
Browse files Browse the repository at this point in the history
- added a `Protocol` type for some string constants
- `proxyRouteIsAvoided` optionally accepts a `body` arg
- `Core<C>.driverForSession` does not actually return something using type `C`.
- `ExternalDriver` passes thru all type args to `Driver`. this should be non-breaking
- `StringRecord` is more appropriate type for default driver settings
- `Constraints` should be readonly
  • Loading branch information
boneskull committed Jul 3, 2023
1 parent 26eb766 commit 62f4244
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions packages/types/lib/driver.ts
Expand Up @@ -371,7 +371,7 @@ export interface LogDef {
getter: (driver: any) => Promise<unknown> | unknown;
}

export interface ISettingsCommands<T extends StringRecord = StringRecord> {
export interface ISettingsCommands<T extends object = object> {
/**
* Update the session's settings dictionary with a new settings object
*
Expand Down Expand Up @@ -478,9 +478,9 @@ export interface Constraint {
/**
* A collection of constraints describing the allowed capabilities for a driver.
*/
export interface Constraints {
[name: string]: Constraint;
}
export type Constraints = {
readonly [name: string]: Constraint;
};

export interface DriverHelpers {
configureApp: (
Expand Down Expand Up @@ -568,6 +568,8 @@ export interface EventHistoryCommand {
endTime: number;
}

export type Protocol = 'MJSONWP' | 'W3C';

/**
* Methods and properties which both `AppiumDriver` and `BaseDriver` inherit.
*
Expand All @@ -578,7 +580,7 @@ export interface Core<C extends Constraints, Settings extends StringRecord = Str
sessionId: string | null;
opts: DriverOpts<C>;
initialOpts: InitialOpts;
protocol?: string;
protocol?: Protocol;
helpers: DriverHelpers;
basePath: string;
relaxedSecurityEnabled: boolean;
Expand Down Expand Up @@ -636,12 +638,12 @@ export interface Core<C extends Constraints, Settings extends StringRecord = Str
proxyActive(sessionId?: string): boolean;
getProxyAvoidList(sessionId?: string): RouteMatcher[];
canProxy(sessionId?: string): boolean;
proxyRouteIsAvoided(sessionId: string, method: string, url: string): boolean;
proxyRouteIsAvoided(sessionId: string, method: string, url: string, body?: any): boolean;
addManagedDriver(driver: Driver): void;
getManagedDrivers(): Driver<Constraints>[];
clearNewCommandTimeout(): Promise<void>;
logEvent(eventName: string): void;
driverForSession(sessionId: string): Core<C> | null;
driverForSession(sessionId: string): Core<Constraints> | null;
}

/**
Expand Down Expand Up @@ -762,8 +764,15 @@ export interface Driver<
* External drivers must subclass `BaseDriver`, and can implement any of these methods.
* None of these are implemented within Appium itself.
*/
export interface ExternalDriver<C extends Constraints = Constraints, Ctx = string>
extends Driver<C> {
export interface ExternalDriver<
C extends Constraints = Constraints,
Ctx = string,
CArgs extends StringRecord = StringRecord,
Settings extends StringRecord = StringRecord,
CreateResult = DefaultCreateSessionResult<C>,
DeleteResult = DefaultDeleteSessionResult,
SessionData extends StringRecord = StringRecord
> extends Driver<C, CArgs, Settings, CreateResult, DeleteResult, SessionData> {
// WebDriver spec commands

/**
Expand Down

0 comments on commit 62f4244

Please sign in to comment.