Skip to content

Commit

Permalink
fix(base-driver): allow subclass to define shape of settings object
Browse files Browse the repository at this point in the history
The mixin approach prevented subclasses of BaseDriver from narrowing the type of `this.settings`.  Now, that's possible.

Also:
- removed an unused type argument from BD constructor
- and did some typedef aliasing
- remove unneeded type assertion from log mixin
  • Loading branch information
boneskull committed Jul 3, 2023
1 parent ee9b2a3 commit 3d614d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
1 change: 0 additions & 1 deletion packages/base-driver/lib/basedriver/commands/index.ts
@@ -1,6 +1,5 @@
import './event';
import './find';
import './log';
import './settings';
import './timeout';
import './execute';
6 changes: 3 additions & 3 deletions packages/base-driver/lib/basedriver/commands/log.ts
@@ -1,6 +1,6 @@
import {Constraints, Driver, ILogCommands, LogDefRecord} from '@appium/types';
import type {Constraints, Driver, ILogCommands} from '@appium/types';
import _ from 'lodash';
import {BaseDriver} from '../driver';
import type {BaseDriver} from '../driver';
import {mixin} from './mixin';

declare module '../driver' {
Expand All @@ -9,7 +9,7 @@ declare module '../driver' {
}

const LogCommands: ILogCommands = {
supportedLogTypes: <LogDefRecord>{},
supportedLogTypes: {},

async getLogTypes<C extends Constraints>(this: BaseDriver<C>) {
this.log.debug('Retrieving supported log types');
Expand Down
26 changes: 0 additions & 26 deletions packages/base-driver/lib/basedriver/commands/settings.ts

This file was deleted.

8 changes: 6 additions & 2 deletions packages/base-driver/lib/basedriver/device-settings.js
Expand Up @@ -9,7 +9,7 @@ import {errors} from '../protocol/errors';
export const MAX_SETTINGS_SIZE = 20 * 1024 * 1024; // 20 MB

/**
* @template {import('@appium/types').StringRecord} T
* @template {StringRecord} T
* @implements {IDeviceSettings<T>}
*/
export class DeviceSettings {
Expand Down Expand Up @@ -74,6 +74,10 @@ export class DeviceSettings {
export default DeviceSettings;

/**
* @template {import('@appium/types').StringRecord} [T=import('@appium/types').StringRecord]
* @typedef {import('@appium/types').StringRecord} StringRecord
*/

/**
* @template {StringRecord} [T=StringRecord]
* @typedef {import('@appium/types').IDeviceSettings<T>} IDeviceSettings
*/
19 changes: 16 additions & 3 deletions packages/base-driver/lib/basedriver/driver.ts
Expand Up @@ -33,11 +33,10 @@ const ON_UNEXPECTED_SHUTDOWN_EVENT = 'onUnexpectedShutdown';
export class BaseDriver<
C extends Constraints,
CArgs extends StringRecord = StringRecord,
Settings extends StringRecord = StringRecord,
SessionData extends StringRecord = StringRecord
Settings extends StringRecord = StringRecord
>
extends DriverCore<C, Settings>
implements Driver<C, CArgs>
implements Driver<C, CArgs, Settings>
{
cliArgs: CArgs & ServerArgs;

Expand Down Expand Up @@ -380,6 +379,20 @@ export class BaseDriver<

return true;
}

async updateSettings(newSettings: Settings) {
if (!this.settings) {
this.log.errorAndThrow('Cannot update settings; settings object not found');
}
return await this.settings.update(newSettings);
}

async getSettings() {
if (!this.settings) {
this.log.errorAndThrow('Cannot get settings; settings object not found');
}
return this.settings.getSettings();
}
}

export * from './commands';
Expand Down

0 comments on commit 3d614d6

Please sign in to comment.