chore(base-driver): Add types to proxy options (#21034)

This commit is contained in:
Mykola Mokhnach
2025-02-23 08:09:27 +01:00
committed by GitHub
parent 7a4fbb2ab3
commit b9a586d336
2 changed files with 64 additions and 4 deletions
@@ -53,12 +53,15 @@ export class JWProxy {
/** @type {number} */
timeout;
/**
* @param {import('@appium/types').ProxyOptions} [opts={}]
*/
constructor(opts = {}) {
opts = _.pick(opts, ALLOWED_OPTS);
const filteredOpts = _.pick(opts, ALLOWED_OPTS);
// omit 'log' in the defaults assignment here because 'log' is a getter and we are going to set
// it to this._log (which lies behind the getter) further down
const options = _.defaults(_.omit(opts, 'log'), {
/** @type {import('@appium/types').ProxyOptions} */
const options = _.defaults(_.omit(filteredOpts, 'log'), {
scheme: 'http',
server: 'localhost',
port: 4444,
@@ -67,7 +70,7 @@ export class JWProxy {
sessionId: null,
timeout: DEFAULT_REQUEST_TIMEOUT,
});
options.scheme = options.scheme.toLowerCase();
options.scheme = /** @type {string} */ (options.scheme).toLowerCase();
Object.assign(this, options);
this._activeRequests = [];
+57
View File
@@ -1,3 +1,5 @@
import type { AppiumLogger } from './logger';
/**
* An object of HTTP headers.
*/
@@ -36,4 +38,59 @@ export interface ProxyResponse<T = any> {
body: HTTPBody<T>;
}
export interface ProxyOptions {
/**
* Downstream URL scheme
*
* @default 'http'
*/
scheme?: string;
/**
* Downstream server hostname
*
* @default 'localhost'
*/
server?: string;
/**
* Downstream server port number
*
* @default 4444
*/
port?: number;
/**
* Downstream server pathname prefix
*
* @default ''
*/
base?: string;
/**
* Upstream server pathname prefix
*
* @default ''
*/
reqBasePath?: string;
/**
* Initial downstream session identifier value
*
* @default null
*/
sessionId?: string | null;
/**
* Downstream server timeout in milliseconds
*
* @default 240000
*/
timeout?: number;
/**
* Proxy logger instance. If unset then a default logger is used
*/
log?: AppiumLogger;
/**
* Whether to apply HTTP Keep-Alive to the downstream server
*
* @default true
*/
keepAlive?: boolean;
}
export type HTTPBody<T = any> = T;