@appium/types
Advanced tools
Comparing version 0.10.1 to 0.10.2
@@ -0,4 +1,5 @@ | ||
import { BaseDriverCapConstraints } from './constraints'; | ||
import { Constraint, Constraints } from './driver'; | ||
import { StandardCapabilities } from './standard-caps'; | ||
import { StringRecord, Constraint, Constraints } from '.'; | ||
import { BaseDriverCapConstraints } from './constraints'; | ||
import { AnyCase, StringRecord } from './util'; | ||
export { StandardCapabilities }; | ||
@@ -9,11 +10,16 @@ export type W3C_APPIUM_PREFIX = 'appium'; | ||
*/ | ||
export type BaseCapabilities = ConstraintsToCaps<BaseDriverCapConstraints>; | ||
export type BaseCapabilities = Capabilities<BaseDriverCapConstraints>; | ||
/** | ||
* Like {@linkcode BaseCapabilities}, except all Appium-specific keys are namespaced. | ||
*/ | ||
export type BaseNSCapabilities = CapsToNSCaps<ConstraintsToCaps<BaseDriverCapConstraints>>; | ||
export type BaseNSCapabilities = NSCapabilities<BaseDriverCapConstraints>; | ||
/** | ||
* Like {@linkcode NSBaseCapabilities}, except W3C-style. | ||
* @see {@linkcode W3CCapabilities} | ||
*/ | ||
export type BaseW3CCapabilities = W3CCapabilities<BaseDriverCapConstraints>; | ||
/** | ||
* Given a {@linkcode Constraint} `C` and a type `T`, see if `inclusion`/`inclusionCaseInsensitive` is present, and create a union of its allowed literals; otherwise just use `T`. | ||
*/ | ||
type ConstraintChoice<C extends Constraint, T> = C['inclusionCaseInsensitive'] extends ReadonlyArray<T> ? AnyCase<C['inclusionCaseInsensitive'][number]> : C['inclusion'] extends ReadonlyArray<T> ? C['inclusion'][number] : T; | ||
export type ConstraintChoice<C extends Constraint, T> = C['inclusionCaseInsensitive'] extends T[] ? AnyCase<C['inclusionCaseInsensitive'][number]> : C['inclusion'] extends ReadonlyArray<T> ? C['inclusion'][number] : T; | ||
/** | ||
@@ -28,3 +34,3 @@ * Given {@linkcode Constraint} `C`, determine the associated type of the capability. | ||
*/ | ||
type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true ? ConstraintChoice<C, string> : C['isNumber'] extends true ? ConstraintChoice<C, number> : C['isBoolean'] extends true ? boolean : C['isArray'] extends true ? string[] : C['isObject'] extends true ? object : any; | ||
export type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true ? ConstraintChoice<C, string> : C['isNumber'] extends true ? ConstraintChoice<C, number> : C['isBoolean'] extends true ? boolean : C['isArray'] extends true ? string[] : C['isObject'] extends true ? object : unknown; | ||
/** | ||
@@ -39,6 +45,2 @@ * Given {@linkcode Constraint} `C`, determine if it is required or optional. | ||
/** | ||
* Given `string` `T`, this is a case-insensitive version of `T`. | ||
*/ | ||
export type AnyCase<T extends string> = string extends T ? string : T extends `${infer F1}${infer F2}${infer R}` ? `${Uppercase<F1> | Lowercase<F1>}${Uppercase<F2> | Lowercase<F2>}${AnyCase<R>}` : T extends `${infer F}${infer R}` ? `${Uppercase<F> | Lowercase<F>}${AnyCase<R>}` : ''; | ||
/** | ||
* Given {@linkcode StringRecord} `T` and namespace string `NS`, a type with the key names prefixed by `${NS}:` _except_ for standard capabilities. `NS` defaults to `appium`. | ||
@@ -51,5 +53,10 @@ * | ||
}; | ||
/** | ||
* A namespaced string of the format `<NS>:<S>` where `NS` defaults to the value of | ||
* {@linkcode W3C_APPIUM_PREFIX} and `S` is a string. | ||
*/ | ||
export type NamespacedString<S extends string, NS extends string = W3C_APPIUM_PREFIX> = `${NS}:${S}`; | ||
/** | ||
* Converts {@linkcode Constraint} `C` to a {@linkcode Capabilities} object. | ||
* @privateRemarks I would like to figure out how to simplify this type | ||
*/ | ||
@@ -64,3 +71,3 @@ export type ConstraintsToCaps<C extends Constraints> = { | ||
*/ | ||
export type Capabilities<C extends Constraints = BaseDriverCapConstraints, Extra extends StringRecord | void = void> = Partial<ConstraintsToCaps<C> & Extra>; | ||
export type Capabilities<C extends Constraints> = ConstraintsToCaps<C>; | ||
/** | ||
@@ -71,6 +78,6 @@ * Like {@linkcode Capabilities}, except W3C-style. | ||
*/ | ||
export type W3CCapabilities<C extends Constraints = BaseDriverCapConstraints, Extra extends StringRecord | void = void> = { | ||
alwaysMatch: NSCapabilities<C, Extra>; | ||
firstMatch: NSCapabilities<C, Extra>[]; | ||
}; | ||
export interface W3CCapabilities<C extends Constraints> { | ||
alwaysMatch: NSCapabilities<C>; | ||
firstMatch: NSCapabilities<C>[]; | ||
} | ||
/** | ||
@@ -81,3 +88,3 @@ * Namespaced caps (where appropriate). | ||
*/ | ||
export type NSCapabilities<C extends Constraints = BaseDriverCapConstraints, Extra extends StringRecord | void = void, NS extends string = W3C_APPIUM_PREFIX> = Partial<CapsToNSCaps<ConstraintsToCaps<C> & Extra, NS>>; | ||
export type NSCapabilities<C extends Constraints, NS extends string = W3C_APPIUM_PREFIX> = Partial<CapsToNSCaps<ConstraintsToCaps<C>, NS>>; | ||
/** | ||
@@ -90,3 +97,3 @@ * Capabilities for drivers extending `BaseDriver`. | ||
* ```ts | ||
* class MyDriver extends BaseDriver { | ||
* class MyDriver extends BaseDriver<MyDriverConstraints> { | ||
* async createSession (w3ccaps: W3CDriverCaps<MyDriverConstraints>, ...args: any[]) { | ||
@@ -102,11 +109,15 @@ * const [ | ||
*/ | ||
export type DriverCaps<C extends Constraints, Extra extends StringRecord | void = void> = Capabilities<BaseDriverCapConstraints & C, Extra>; | ||
/** | ||
* Normalized capabilities for drivers extending `BaseDriver`. | ||
* Includes {@linkcode BaseCapabilities}. | ||
*/ | ||
export type DriverCaps<C extends Constraints = Constraints> = BaseCapabilities & Capabilities<C>; | ||
/** | ||
* W3C-style capabilities for drivers extending `BaseDriver`. | ||
* | ||
* Includes {@linkcode BaseCapabilities}. | ||
* Includes {@linkcode BaseW3CCapabilities}. | ||
* | ||
* @example | ||
* ```ts | ||
* class MyDriver extends BaseDriver { | ||
* class MyDriver extends BaseDriver<MyDriverConstraints> { | ||
* async createSession (w3ccaps: W3CDriverCaps<MyDriverConstraints>, ...args: any[]) { | ||
@@ -118,9 +129,9 @@ * // ... | ||
*/ | ||
export type W3CDriverCaps<C extends Constraints, Extra extends StringRecord | void = void> = W3CCapabilities<BaseDriverCapConstraints & C, Extra>; | ||
export type W3CDriverCaps<C extends Constraints = Constraints> = BaseW3CCapabilities & W3CCapabilities<C>; | ||
/** | ||
* Namespaced capabilities for drivers extending `BaseDriver`. | ||
* | ||
* Includes {@linkcode BaseCapabilities}. | ||
* Includes {@linkcode BaseNSCapabilities}. | ||
*/ | ||
export type NSDriverCaps<C extends Constraints, Extra extends StringRecord | void = void> = NSCapabilities<BaseDriverCapConstraints & C, Extra>; | ||
export type NSDriverCaps<C extends Constraints = Constraints> = BaseNSCapabilities & NSCapabilities<C>; | ||
//# sourceMappingURL=capabilities.d.ts.map |
import { ConditionalPick, MultidimensionalReadonlyArray } from 'type-fest'; | ||
import { Driver, DriverCommand } from './driver'; | ||
import { Plugin, PluginCommand } from './plugin'; | ||
import { StringRecord } from './util'; | ||
/** | ||
@@ -17,8 +18,21 @@ * Defines the shape of a payload for a {@linkcode MethodDef}. | ||
* 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 | Driver> = T extends Plugin ? Readonly<PluginMethodMap<T>> : T extends Driver ? Readonly<DriverMethodMap<T>> : never; | ||
export type MethodMap<T extends Plugin | Driver<any>> = T extends Plugin ? Readonly<PluginMethodMap<T>> : T extends Driver<any> ? Readonly<DriverMethodMap<T>> : never; | ||
/** | ||
* A {@linkcode MethodMap} for a {@linkcode Driver}. | ||
*/ | ||
export interface DriverMethodMap<T extends Driver> { | ||
export interface DriverMethodMap<T extends Driver<any>> { | ||
[key: string]: { | ||
@@ -46,7 +60,11 @@ GET?: DriverMethodDef<T>; | ||
*/ | ||
export interface DriverMethodDef<T extends Driver> extends BaseMethodDef { | ||
export interface DriverMethodDef<T extends Driver, D extends boolean = boolean> extends BaseMethodDef { | ||
/** | ||
* Name of the command. | ||
*/ | ||
readonly command?: keyof ConditionalPick<Required<T>, DriverCommand>; | ||
readonly command?: D extends true ? string : keyof ConditionalPick<Required<T>, DriverCommand>; | ||
/** | ||
* If this is `true`, we do not validate `command`, because it may not exist in `ExternalDriver`. | ||
*/ | ||
readonly deprecated?: D; | ||
} | ||
@@ -87,3 +105,3 @@ /** | ||
*/ | ||
export interface DriverExecuteMethodDef<T extends Driver> extends BaseExecuteMethodDef { | ||
export interface DriverExecuteMethodDef<T extends Driver<any>> extends BaseExecuteMethodDef { | ||
command: keyof ConditionalPick<T, DriverCommand>; | ||
@@ -100,3 +118,3 @@ } | ||
*/ | ||
export type ExecuteMethodMap<T extends Plugin | Driver> = T extends Plugin ? Readonly<Record<string, PluginExecuteMethodDef<T>>> : T extends Driver ? Readonly<Record<string, DriverExecuteMethodDef<T>>> : never; | ||
export type ExecuteMethodMap<T extends Plugin | Driver<any>> = T extends Plugin ? Readonly<StringRecord<PluginExecuteMethodDef<T>>> : T extends Driver<any> ? Readonly<StringRecord<DriverExecuteMethodDef<T>>> : never; | ||
//# sourceMappingURL=command.d.ts.map |
import type { AppiumConfigJsonSchema } from '@appium/schema'; | ||
import { AppiumConfiguration, ServerConfig } from './appium-config'; | ||
import { Associated, KebabToCamel } from './util'; | ||
/** | ||
@@ -10,3 +11,3 @@ * The Appium configuration as it would be in a user-provided configuration file. | ||
*/ | ||
type AppiumServerJsonSchema = typeof AppiumConfigJsonSchema['properties']['server']['properties']; | ||
type AppiumServerJsonSchema = (typeof AppiumConfigJsonSchema)['properties']['server']['properties']; | ||
/** | ||
@@ -50,14 +51,2 @@ * This type associates the types generated from the schema ({@linkcode AppiumConfiguration}) | ||
/** | ||
* Converts a kebab-cased string into a camel-cased string. | ||
*/ | ||
type KebabToCamel<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${KebabToCamel<P3>}` : Lowercase<S>; | ||
/** | ||
* Object `B` has all the keys as object `A` (even if those keys in `A` are otherwise optional). | ||
*/ | ||
type Associated<A extends object, B extends { | ||
[key in keyof Required<A>]: unknown; | ||
}> = { | ||
[Prop in keyof Required<A>]: B[Prop]; | ||
}; | ||
/** | ||
* Certain properties have an `appiumCliDest` prop, which affects the shape of | ||
@@ -64,0 +53,0 @@ * `ParsedArgs`. This type helps recognize these properties. |
@@ -1,69 +0,56 @@ | ||
export namespace BASE_DESIRED_CAP_CONSTRAINTS { | ||
namespace platformName { | ||
const presence: true; | ||
const isString: true; | ||
} | ||
namespace app { | ||
const isString_1: true; | ||
export { isString_1 as isString }; | ||
} | ||
namespace deviceName { | ||
const isString_2: true; | ||
export { isString_2 as isString }; | ||
} | ||
namespace platformVersion { | ||
const isString_3: true; | ||
export { isString_3 as isString }; | ||
} | ||
namespace webSocketUrl { | ||
const isBoolean: true; | ||
} | ||
namespace newCommandTimeout { | ||
const isNumber: true; | ||
} | ||
namespace automationName { | ||
const isString_4: true; | ||
export { isString_4 as isString }; | ||
} | ||
namespace autoLaunch { | ||
const isBoolean_1: true; | ||
export { isBoolean_1 as isBoolean }; | ||
} | ||
namespace udid { | ||
const isString_5: true; | ||
export { isString_5 as isString }; | ||
} | ||
namespace orientation { | ||
const inclusion: readonly ["LANDSCAPE", "PORTRAIT"]; | ||
} | ||
namespace autoWebview { | ||
const isBoolean_2: true; | ||
export { isBoolean_2 as isBoolean }; | ||
} | ||
namespace noReset { | ||
const isBoolean_3: true; | ||
export { isBoolean_3 as isBoolean }; | ||
} | ||
namespace fullReset { | ||
const isBoolean_4: true; | ||
export { isBoolean_4 as isBoolean }; | ||
} | ||
namespace language { | ||
const isString_6: true; | ||
export { isString_6 as isString }; | ||
} | ||
namespace locale { | ||
const isString_7: true; | ||
export { isString_7 as isString }; | ||
} | ||
namespace eventTimings { | ||
const isBoolean_5: true; | ||
export { isBoolean_5 as isBoolean }; | ||
} | ||
namespace printPageSourceOnFindFailure { | ||
const isBoolean_6: true; | ||
export { isBoolean_6 as isBoolean }; | ||
} | ||
} | ||
export declare const BASE_DESIRED_CAP_CONSTRAINTS: { | ||
readonly platformName: { | ||
readonly presence: true; | ||
readonly isString: true; | ||
}; | ||
readonly app: { | ||
readonly isString: true; | ||
}; | ||
readonly deviceName: { | ||
readonly isString: true; | ||
}; | ||
readonly platformVersion: { | ||
readonly isString: true; | ||
}; | ||
readonly webSocketUrl: { | ||
readonly isBoolean: true; | ||
}; | ||
readonly newCommandTimeout: { | ||
readonly isNumber: true; | ||
}; | ||
readonly automationName: { | ||
readonly isString: true; | ||
}; | ||
readonly autoLaunch: { | ||
readonly isBoolean: true; | ||
}; | ||
readonly udid: { | ||
readonly isString: true; | ||
}; | ||
readonly orientation: { | ||
readonly inclusion: readonly ["LANDSCAPE", "PORTRAIT"]; | ||
}; | ||
readonly autoWebview: { | ||
readonly isBoolean: true; | ||
}; | ||
readonly noReset: { | ||
readonly isBoolean: true; | ||
}; | ||
readonly fullReset: { | ||
readonly isBoolean: true; | ||
}; | ||
readonly language: { | ||
readonly isString: true; | ||
}; | ||
readonly locale: { | ||
readonly isString: true; | ||
}; | ||
readonly eventTimings: { | ||
readonly isBoolean: true; | ||
}; | ||
readonly printPageSourceOnFindFailure: { | ||
readonly isBoolean: true; | ||
}; | ||
}; | ||
export type BaseDriverCapConstraints = typeof BASE_DESIRED_CAP_CONSTRAINTS; | ||
//# sourceMappingURL=constraints.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BASE_DESIRED_CAP_CONSTRAINTS = void 0; | ||
exports.BASE_DESIRED_CAP_CONSTRAINTS = ({ | ||
exports.BASE_DESIRED_CAP_CONSTRAINTS = { | ||
platformName: { | ||
@@ -57,6 +57,3 @@ presence: true, | ||
}, | ||
}); | ||
/** | ||
* @typedef {typeof BASE_DESIRED_CAP_CONSTRAINTS} BaseDriverCapConstraints | ||
*/ | ||
}; | ||
//# sourceMappingURL=constraints.js.map |
@@ -1,10 +0,1 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import type { Express } from 'express'; | ||
import type { Server } from 'http'; | ||
import type { Socket } from 'net'; | ||
import type { Logger } from 'npmlog'; | ||
import type { Class as _Class } from 'type-fest'; | ||
import type { Server as WSServer } from 'ws'; | ||
import { ServerArgs } from './config'; | ||
export * from './command'; | ||
@@ -15,99 +6,9 @@ export * from './action'; | ||
export * from './config'; | ||
export { BASE_DESIRED_CAP_CONSTRAINTS } from './constraints'; | ||
export type { BaseDriverCapConstraints } from './constraints'; | ||
export * from './constraints'; | ||
export * from './driver'; | ||
export * from './plugin'; | ||
/** | ||
* Utility type for a object with string-only props | ||
*/ | ||
export type StringRecord = Record<string, any>; | ||
/** | ||
* A log prefix for {@linkcode AppiumLogger} | ||
* | ||
* If a function, the function will return the prefix. Log messages will be prefixed with this value. | ||
*/ | ||
export type AppiumLoggerPrefix = string | (() => string); | ||
/** | ||
* Possible "log levels" for {@linkcode AppiumLogger}. | ||
* | ||
* Extracted from `npmlog`. | ||
*/ | ||
export type AppiumLoggerLevel = 'silly' | 'verbose' | 'debug' | 'info' | 'http' | 'warn' | 'error'; | ||
/** | ||
* Describes the `npmlog`-based internal logger. | ||
* | ||
* @see https://npm.im/npmlog | ||
*/ | ||
export interface AppiumLogger { | ||
/** | ||
* Returns the underlying `npmlog` {@link Logger}. | ||
*/ | ||
unwrap(): Logger; | ||
level: AppiumLoggerLevel; | ||
levels: AppiumLoggerLevel[]; | ||
/** | ||
* Log prefix, if applicable. | ||
*/ | ||
prefix?: AppiumLoggerPrefix; | ||
debug(...args: any[]): void; | ||
info(...args: any[]): void; | ||
warn(...args: any[]): void; | ||
error(...args: any[]): void; | ||
verbose(...args: any[]): void; | ||
silly(...args: any[]): void; | ||
http(...args: any[]): void; | ||
errorAndThrow(...args: any[]): never; | ||
} | ||
/** | ||
* Appium's slightly-modified {@linkcode Server http.Server}. | ||
*/ | ||
export type AppiumServer = Omit<Server, 'close'> & AppiumServerExtension; | ||
export interface AppiumServerExtension { | ||
close(): Promise<void>; | ||
addWebSocketHandler(handlerPathname: string, handlerServer: WSServer): Promise<void>; | ||
removeWebSocketHandler(handlerPathname: string): Promise<boolean>; | ||
removeAllWebSocketHandlers(): Promise<boolean>; | ||
getWebSocketHandlers(keysFilter: string | null | undefined): Promise<Record<string, WSServer>>; | ||
webSocketsMapping: Record<string, WSServer>; | ||
} | ||
export interface AppiumServerSocket extends Socket { | ||
_openReqCount: number; | ||
} | ||
/** | ||
* Wraps {@linkcode _Class `type-fest`'s `Class`} to include static members. | ||
*/ | ||
export type Class<Proto, StaticMembers extends object = object, Args extends unknown[] = any[]> = _Class<Proto, Args> & StaticMembers; | ||
/** | ||
* The string referring to a "driver"-type extension | ||
*/ | ||
export type DriverType = 'driver'; | ||
/** | ||
* The string referring to a "plugin"-type extension | ||
* | ||
*/ | ||
export type PluginType = 'plugin'; | ||
/** | ||
* The strings referring to all extension types. | ||
*/ | ||
export type ExtensionType = DriverType | PluginType; | ||
/** | ||
* Optionally updates an Appium express app and http server, by calling | ||
* methods that may mutate those objects. For example, you could call: | ||
* | ||
* `expressApp.get('/foo', handler)` | ||
* | ||
* In order to add a new route to Appium with this plugin. Or, you could add | ||
* new listeners to the httpServer object. | ||
* | ||
* @param expressApp - the Express 'app' object used by Appium for route handling | ||
* @param httpServer - the node HTTP server that hosts the app | ||
* @param cliArgs - Arguments from config files, CLI, etc. | ||
*/ | ||
export type UpdateServerCallback = (expressApp: Express, httpServer: AppiumServer, cliArgs: Partial<ServerArgs>) => Promise<void>; | ||
/** | ||
* Possible HTTP methods, as stolen from `axios`. | ||
* | ||
* @see https://npm.im/axios | ||
*/ | ||
export type HTTPMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; | ||
export * from './http'; | ||
export * from './util'; | ||
export * from './server'; | ||
export * from './logger'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,3 +17,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BASE_DESIRED_CAP_CONSTRAINTS = void 0; | ||
__exportStar(require("./command"), exports); | ||
@@ -24,6 +23,9 @@ __exportStar(require("./action"), exports); | ||
__exportStar(require("./config"), exports); | ||
var constraints_1 = require("./constraints"); | ||
Object.defineProperty(exports, "BASE_DESIRED_CAP_CONSTRAINTS", { enumerable: true, get: function () { return constraints_1.BASE_DESIRED_CAP_CONSTRAINTS; } }); | ||
__exportStar(require("./constraints"), exports); | ||
__exportStar(require("./driver"), exports); | ||
__exportStar(require("./plugin"), exports); | ||
__exportStar(require("./http"), exports); | ||
__exportStar(require("./util"), exports); | ||
__exportStar(require("./server"), exports); | ||
__exportStar(require("./logger"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,7 @@ | ||
import { AppiumLogger, Class, UpdateServerCallback } from '.'; | ||
import { AsyncReturnType } from 'type-fest'; | ||
import { ExecuteMethodMap, MethodMap } from './command'; | ||
import { ExternalDriver } from './driver'; | ||
import { DriverCommand, ExternalDriver } from './driver'; | ||
import { AppiumLogger } from './logger'; | ||
import { UpdateServerCallback } from './server'; | ||
import { Class, StringRecord } from './util'; | ||
/** | ||
@@ -27,2 +30,23 @@ * The interface describing the constructor and static properties of a Plugin. | ||
/** | ||
* This utility type can presently be used by Plugin authors to mark a method in their plugin as one | ||
* which overrides a method in a Driver. | ||
* @privateRemarks This would work well as a decorator. May want to accept a type arg for `Driver` | ||
* and use a string method name to lookup the method instead. | ||
* @example | ||
* | ||
* class MyPlugin extends BasePlugin implements Plugin { | ||
* public getPageSource: DriverCommandToPluginCommand< | ||
* ExternalDriver['getPageSource'], // method to override | ||
* [flag: boolean], // new arguments; defaults to the args of the method | ||
* string|Buffer, // new return type; defaults to the async return type of the method | ||
* string // async return type of `next()` | ||
* > = async function (next, driver, flag = boolean) { | ||
* const source = await next(); | ||
* return flag ? source : Buffer.from(source); | ||
* } | ||
* } | ||
* | ||
*/ | ||
export type DriverCommandToPluginCommand<DC extends DriverCommand, TArgs extends readonly any[] = Parameters<DC>, TReturn = AsyncReturnType<DC>, NextRetval = unknown> = PluginCommand<ExternalDriver, TArgs, TReturn, NextRetval>; | ||
/** | ||
* An instance of a "plugin" extension. | ||
@@ -71,3 +95,3 @@ * | ||
*/ | ||
export type NextPluginCallback = () => Promise<void>; | ||
export type NextPluginCallback<T = unknown> = () => Promise<T>; | ||
/** | ||
@@ -78,3 +102,3 @@ * Implementation of a command within a plugin | ||
*/ | ||
export type PluginCommand<D extends ExternalDriver = ExternalDriver, TArgs extends readonly any[] = any[], TReturn = any> = (next: NextPluginCallback, driver: D, ...args: TArgs) => Promise<TReturn>; | ||
export type PluginCommand<D extends ExternalDriver = ExternalDriver, TArgs extends readonly any[] = any[], TReturn = unknown, NextReturn = unknown> = (next: NextPluginCallback<NextReturn>, driver: D, ...args: TArgs) => Promise<TReturn>; | ||
/** | ||
@@ -87,4 +111,4 @@ * Mainly for internal use. | ||
pluginName: string, | ||
cliArgs: Record<string, unknown> | ||
cliArgs: StringRecord<unknown> | ||
]>; | ||
//# sourceMappingURL=plugin.d.ts.map |
@@ -0,4 +1,5 @@ | ||
import {BaseDriverCapConstraints} from './constraints'; | ||
import {Constraint, Constraints} from './driver'; | ||
import {StandardCapabilities} from './standard-caps'; | ||
import {StringRecord, Constraint, Constraints} from '.'; | ||
import {BaseDriverCapConstraints} from './constraints'; | ||
import {AnyCase, StringRecord} from './util'; | ||
@@ -12,3 +13,3 @@ export {StandardCapabilities}; | ||
*/ | ||
export type BaseCapabilities = ConstraintsToCaps<BaseDriverCapConstraints>; | ||
export type BaseCapabilities = Capabilities<BaseDriverCapConstraints>; | ||
@@ -18,11 +19,14 @@ /** | ||
*/ | ||
export type BaseNSCapabilities = CapsToNSCaps<ConstraintsToCaps<BaseDriverCapConstraints>>; | ||
export type BaseNSCapabilities = NSCapabilities<BaseDriverCapConstraints>; | ||
/** | ||
* Like {@linkcode NSBaseCapabilities}, except W3C-style. | ||
* @see {@linkcode W3CCapabilities} | ||
*/ | ||
export type BaseW3CCapabilities = W3CCapabilities<BaseDriverCapConstraints>; | ||
/** | ||
* Given a {@linkcode Constraint} `C` and a type `T`, see if `inclusion`/`inclusionCaseInsensitive` is present, and create a union of its allowed literals; otherwise just use `T`. | ||
*/ | ||
type ConstraintChoice< | ||
C extends Constraint, | ||
T | ||
> = C['inclusionCaseInsensitive'] extends ReadonlyArray<T> | ||
export type ConstraintChoice<C extends Constraint, T> = C['inclusionCaseInsensitive'] extends T[] | ||
? AnyCase<C['inclusionCaseInsensitive'][number]> | ||
@@ -42,3 +46,3 @@ : C['inclusion'] extends ReadonlyArray<T> | ||
*/ | ||
type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true | ||
export type ConstraintToCapKind<C extends Constraint> = C['isString'] extends true | ||
? ConstraintChoice<C, string> | ||
@@ -53,3 +57,3 @@ : C['isNumber'] extends true | ||
? object | ||
: any; | ||
: unknown; | ||
@@ -68,13 +72,2 @@ /** | ||
/** | ||
* Given `string` `T`, this is a case-insensitive version of `T`. | ||
*/ | ||
export type AnyCase<T extends string> = string extends T | ||
? string | ||
: T extends `${infer F1}${infer F2}${infer R}` | ||
? `${Uppercase<F1> | Lowercase<F1>}${Uppercase<F2> | Lowercase<F2>}${AnyCase<R>}` | ||
: T extends `${infer F}${infer R}` | ||
? `${Uppercase<F> | Lowercase<F>}${AnyCase<R>}` | ||
: ''; | ||
/** | ||
* Given {@linkcode StringRecord} `T` and namespace string `NS`, a type with the key names prefixed by `${NS}:` _except_ for standard capabilities. `NS` defaults to `appium`. | ||
@@ -90,2 +83,6 @@ * | ||
/** | ||
* A namespaced string of the format `<NS>:<S>` where `NS` defaults to the value of | ||
* {@linkcode W3C_APPIUM_PREFIX} and `S` is a string. | ||
*/ | ||
export type NamespacedString< | ||
@@ -98,2 +95,3 @@ S extends string, | ||
* Converts {@linkcode Constraint} `C` to a {@linkcode Capabilities} object. | ||
* @privateRemarks I would like to figure out how to simplify this type | ||
*/ | ||
@@ -109,6 +107,3 @@ export type ConstraintsToCaps<C extends Constraints> = { | ||
*/ | ||
export type Capabilities< | ||
C extends Constraints = BaseDriverCapConstraints, | ||
Extra extends StringRecord | void = void | ||
> = Partial<ConstraintsToCaps<C> & Extra>; | ||
export type Capabilities<C extends Constraints> = ConstraintsToCaps<C>; | ||
@@ -120,9 +115,6 @@ /** | ||
*/ | ||
export type W3CCapabilities< | ||
C extends Constraints = BaseDriverCapConstraints, | ||
Extra extends StringRecord | void = void | ||
> = { | ||
alwaysMatch: NSCapabilities<C, Extra>; | ||
firstMatch: NSCapabilities<C, Extra>[]; | ||
}; | ||
export interface W3CCapabilities<C extends Constraints> { | ||
alwaysMatch: NSCapabilities<C>; | ||
firstMatch: NSCapabilities<C>[]; | ||
} | ||
@@ -134,7 +126,5 @@ /** | ||
*/ | ||
export type NSCapabilities< | ||
C extends Constraints = BaseDriverCapConstraints, | ||
Extra extends StringRecord | void = void, | ||
NS extends string = W3C_APPIUM_PREFIX | ||
> = Partial<CapsToNSCaps<ConstraintsToCaps<C> & Extra, NS>>; | ||
export type NSCapabilities<C extends Constraints, NS extends string = W3C_APPIUM_PREFIX> = Partial< | ||
CapsToNSCaps<ConstraintsToCaps<C>, NS> | ||
>; | ||
@@ -148,3 +138,3 @@ /** | ||
* ```ts | ||
* class MyDriver extends BaseDriver { | ||
* class MyDriver extends BaseDriver<MyDriverConstraints> { | ||
* async createSession (w3ccaps: W3CDriverCaps<MyDriverConstraints>, ...args: any[]) { | ||
@@ -161,6 +151,7 @@ * const [ | ||
export type DriverCaps< | ||
C extends Constraints, | ||
Extra extends StringRecord | void = void | ||
> = Capabilities<BaseDriverCapConstraints & C, Extra>; | ||
/** | ||
* Normalized capabilities for drivers extending `BaseDriver`. | ||
* Includes {@linkcode BaseCapabilities}. | ||
*/ | ||
export type DriverCaps<C extends Constraints = Constraints> = BaseCapabilities & Capabilities<C>; | ||
@@ -170,7 +161,7 @@ /** | ||
* | ||
* Includes {@linkcode BaseCapabilities}. | ||
* Includes {@linkcode BaseW3CCapabilities}. | ||
* | ||
* @example | ||
* ```ts | ||
* class MyDriver extends BaseDriver { | ||
* class MyDriver extends BaseDriver<MyDriverConstraints> { | ||
* async createSession (w3ccaps: W3CDriverCaps<MyDriverConstraints>, ...args: any[]) { | ||
@@ -182,6 +173,4 @@ * // ... | ||
*/ | ||
export type W3CDriverCaps< | ||
C extends Constraints, | ||
Extra extends StringRecord | void = void | ||
> = W3CCapabilities<BaseDriverCapConstraints & C, Extra>; | ||
export type W3CDriverCaps<C extends Constraints = Constraints> = BaseW3CCapabilities & | ||
W3CCapabilities<C>; | ||
@@ -191,7 +180,5 @@ /** | ||
* | ||
* Includes {@linkcode BaseCapabilities}. | ||
* Includes {@linkcode BaseNSCapabilities}. | ||
*/ | ||
export type NSDriverCaps< | ||
C extends Constraints, | ||
Extra extends StringRecord | void = void | ||
> = NSCapabilities<BaseDriverCapConstraints & C, Extra>; | ||
export type NSDriverCaps<C extends Constraints = Constraints> = BaseNSCapabilities & | ||
NSCapabilities<C>; |
import {ConditionalPick, MultidimensionalReadonlyArray} from 'type-fest'; | ||
import {Driver, DriverCommand} from './driver'; | ||
import {Plugin, PluginCommand} from './plugin'; | ||
import {StringRecord} from './util'; | ||
@@ -18,6 +19,19 @@ /** | ||
* 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 | Driver> = T extends Plugin | ||
export type MethodMap<T extends Plugin | Driver<any>> = T extends Plugin | ||
? Readonly<PluginMethodMap<T>> | ||
: T extends Driver | ||
: T extends Driver<any> | ||
? Readonly<DriverMethodMap<T>> | ||
@@ -29,3 +43,3 @@ : never; | ||
*/ | ||
export interface DriverMethodMap<T extends Driver> { | ||
export interface DriverMethodMap<T extends Driver<any>> { | ||
[key: string]: { | ||
@@ -55,7 +69,13 @@ GET?: DriverMethodDef<T>; | ||
*/ | ||
export interface DriverMethodDef<T extends Driver> extends BaseMethodDef { | ||
export interface DriverMethodDef<T extends Driver, D extends boolean = boolean> | ||
extends BaseMethodDef { | ||
/** | ||
* Name of the command. | ||
*/ | ||
readonly command?: keyof ConditionalPick<Required<T>, DriverCommand>; | ||
readonly command?: D extends true ? string : keyof ConditionalPick<Required<T>, DriverCommand>; | ||
/** | ||
* If this is `true`, we do not validate `command`, because it may not exist in `ExternalDriver`. | ||
*/ | ||
readonly deprecated?: D; | ||
} | ||
@@ -104,3 +124,3 @@ | ||
*/ | ||
export interface DriverExecuteMethodDef<T extends Driver> extends BaseExecuteMethodDef { | ||
export interface DriverExecuteMethodDef<T extends Driver<any>> extends BaseExecuteMethodDef { | ||
command: keyof ConditionalPick<T, DriverCommand>; | ||
@@ -119,6 +139,6 @@ } | ||
*/ | ||
export type ExecuteMethodMap<T extends Plugin | Driver> = T extends Plugin | ||
? Readonly<Record<string, PluginExecuteMethodDef<T>>> | ||
: T extends Driver | ||
? Readonly<Record<string, DriverExecuteMethodDef<T>>> | ||
export type ExecuteMethodMap<T extends Plugin | Driver<any>> = T extends Plugin | ||
? Readonly<StringRecord<PluginExecuteMethodDef<T>>> | ||
: T extends Driver<any> | ||
? Readonly<StringRecord<DriverExecuteMethodDef<T>>> | ||
: never; |
import type {AppiumConfigJsonSchema} from '@appium/schema'; | ||
import {AppiumConfiguration, ServerConfig} from './appium-config'; | ||
import {Associated, KebabToCamel} from './util'; | ||
@@ -12,3 +13,3 @@ /** | ||
*/ | ||
type AppiumServerJsonSchema = typeof AppiumConfigJsonSchema['properties']['server']['properties']; | ||
type AppiumServerJsonSchema = (typeof AppiumConfigJsonSchema)['properties']['server']['properties']; | ||
@@ -65,38 +66,3 @@ /** | ||
}; | ||
// begin utils | ||
/** | ||
* Converts a kebab-cased string into a camel-cased string. | ||
*/ | ||
type KebabToCamel<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}` | ||
? `${Lowercase<P1>}${Uppercase<P2>}${KebabToCamel<P3>}` | ||
: Lowercase<S>; | ||
/** | ||
* Converts an object with kebab-cased keys into camel-cased keys. | ||
*/ | ||
type ObjectToCamel<T> = { | ||
[K in keyof T as KebabToCamel<string & K>]: T[K] extends Record<string, any> | ||
? KeysToCamelCase<T[K]> | ||
: T[K]; | ||
}; | ||
/** | ||
* Converts an object or array to have camel-cased keys. | ||
*/ | ||
type KeysToCamelCase<T> = { | ||
[K in keyof T as KebabToCamel<string & K>]: T[K] extends Array<any> | ||
? KeysToCamelCase<T[K][number]>[] | ||
: ObjectToCamel<T[K]>; | ||
}; | ||
/** | ||
* Object `B` has all the keys as object `A` (even if those keys in `A` are otherwise optional). | ||
*/ | ||
type Associated<A extends object, B extends {[key in keyof Required<A>]: unknown}> = { | ||
[Prop in keyof Required<A>]: B[Prop]; | ||
}; | ||
// end utils | ||
// begin conditionals | ||
@@ -103,0 +69,0 @@ |
148
lib/index.ts
@@ -1,8 +0,1 @@ | ||
import type {Express} from 'express'; | ||
import type {Server} from 'http'; | ||
import type {Socket} from 'net'; | ||
import type {Logger} from 'npmlog'; | ||
import type {Class as _Class} from 'type-fest'; | ||
import type {Server as WSServer} from 'ws'; | ||
import {ServerArgs} from './config'; | ||
export * from './command'; | ||
@@ -13,139 +6,8 @@ export * from './action'; | ||
export * from './config'; | ||
export {BASE_DESIRED_CAP_CONSTRAINTS} from './constraints'; | ||
export type {BaseDriverCapConstraints} from './constraints'; | ||
export * from './constraints'; | ||
export * from './driver'; | ||
export * from './plugin'; | ||
/** | ||
* Utility type for a object with string-only props | ||
*/ | ||
export type StringRecord = Record<string, any>; | ||
/** | ||
* A log prefix for {@linkcode AppiumLogger} | ||
* | ||
* If a function, the function will return the prefix. Log messages will be prefixed with this value. | ||
*/ | ||
export type AppiumLoggerPrefix = string | (() => string); | ||
/** | ||
* Possible "log levels" for {@linkcode AppiumLogger}. | ||
* | ||
* Extracted from `npmlog`. | ||
*/ | ||
export type AppiumLoggerLevel = 'silly' | 'verbose' | 'debug' | 'info' | 'http' | 'warn' | 'error'; | ||
/** | ||
* Describes the `npmlog`-based internal logger. | ||
* | ||
* @see https://npm.im/npmlog | ||
*/ | ||
export interface AppiumLogger { | ||
/** | ||
* Returns the underlying `npmlog` {@link Logger}. | ||
*/ | ||
unwrap(): Logger; | ||
level: AppiumLoggerLevel; | ||
levels: AppiumLoggerLevel[]; | ||
/** | ||
* Log prefix, if applicable. | ||
*/ | ||
prefix?: AppiumLoggerPrefix; | ||
debug(...args: any[]): void; | ||
info(...args: any[]): void; | ||
warn(...args: any[]): void; | ||
error(...args: any[]): void; | ||
verbose(...args: any[]): void; | ||
silly(...args: any[]): void; | ||
http(...args: any[]): void; | ||
errorAndThrow(...args: any[]): never; | ||
} | ||
/** | ||
* Appium's slightly-modified {@linkcode Server http.Server}. | ||
*/ | ||
export type AppiumServer = Omit<Server, 'close'> & AppiumServerExtension; | ||
export interface AppiumServerExtension { | ||
close(): Promise<void>; | ||
addWebSocketHandler(handlerPathname: string, handlerServer: WSServer): Promise<void>; | ||
removeWebSocketHandler(handlerPathname: string): Promise<boolean>; | ||
removeAllWebSocketHandlers(): Promise<boolean>; | ||
getWebSocketHandlers(keysFilter: string | null | undefined): Promise<Record<string, WSServer>>; | ||
webSocketsMapping: Record<string, WSServer>; | ||
} | ||
export interface AppiumServerSocket extends Socket { | ||
_openReqCount: number; | ||
} | ||
/** | ||
* Wraps {@linkcode _Class `type-fest`'s `Class`} to include static members. | ||
*/ | ||
export type Class< | ||
Proto, | ||
StaticMembers extends object = object, | ||
Args extends unknown[] = any[] | ||
> = _Class<Proto, Args> & StaticMembers; | ||
/** | ||
* The string referring to a "driver"-type extension | ||
*/ | ||
export type DriverType = 'driver'; | ||
/** | ||
* The string referring to a "plugin"-type extension | ||
* | ||
*/ | ||
export type PluginType = 'plugin'; | ||
/** | ||
* The strings referring to all extension types. | ||
*/ | ||
export type ExtensionType = DriverType | PluginType; | ||
/** | ||
* Optionally updates an Appium express app and http server, by calling | ||
* methods that may mutate those objects. For example, you could call: | ||
* | ||
* `expressApp.get('/foo', handler)` | ||
* | ||
* In order to add a new route to Appium with this plugin. Or, you could add | ||
* new listeners to the httpServer object. | ||
* | ||
* @param expressApp - the Express 'app' object used by Appium for route handling | ||
* @param httpServer - the node HTTP server that hosts the app | ||
* @param cliArgs - Arguments from config files, CLI, etc. | ||
*/ | ||
export type UpdateServerCallback = ( | ||
expressApp: Express, | ||
httpServer: AppiumServer, | ||
cliArgs: Partial<ServerArgs> | ||
) => Promise<void>; | ||
/** | ||
* Possible HTTP methods, as stolen from `axios`. | ||
* | ||
* @see https://npm.im/axios | ||
*/ | ||
export type HTTPMethod = | ||
| 'get' | ||
| 'GET' | ||
| 'delete' | ||
| 'DELETE' | ||
| 'head' | ||
| 'HEAD' | ||
| 'options' | ||
| 'OPTIONS' | ||
| 'post' | ||
| 'POST' | ||
| 'put' | ||
| 'PUT' | ||
| 'patch' | ||
| 'PATCH' | ||
| 'purge' | ||
| 'PURGE' | ||
| 'link' | ||
| 'LINK' | ||
| 'unlink' | ||
| 'UNLINK'; | ||
export * from './http'; | ||
export * from './util'; | ||
export * from './server'; | ||
export * from './logger'; |
@@ -1,4 +0,7 @@ | ||
import {AppiumLogger, Class, UpdateServerCallback} from '.'; | ||
import {AsyncReturnType} from 'type-fest'; | ||
import {ExecuteMethodMap, MethodMap} from './command'; | ||
import {ExternalDriver} from './driver'; | ||
import {DriverCommand, ExternalDriver} from './driver'; | ||
import {AppiumLogger} from './logger'; | ||
import {UpdateServerCallback} from './server'; | ||
import {Class, StringRecord} from './util'; | ||
@@ -29,2 +32,29 @@ /** | ||
/** | ||
* This utility type can presently be used by Plugin authors to mark a method in their plugin as one | ||
* which overrides a method in a Driver. | ||
* @privateRemarks This would work well as a decorator. May want to accept a type arg for `Driver` | ||
* and use a string method name to lookup the method instead. | ||
* @example | ||
* | ||
* class MyPlugin extends BasePlugin implements Plugin { | ||
* public getPageSource: DriverCommandToPluginCommand< | ||
* ExternalDriver['getPageSource'], // method to override | ||
* [flag: boolean], // new arguments; defaults to the args of the method | ||
* string|Buffer, // new return type; defaults to the async return type of the method | ||
* string // async return type of `next()` | ||
* > = async function (next, driver, flag = boolean) { | ||
* const source = await next(); | ||
* return flag ? source : Buffer.from(source); | ||
* } | ||
* } | ||
* | ||
*/ | ||
export type DriverCommandToPluginCommand< | ||
DC extends DriverCommand, | ||
TArgs extends readonly any[] = Parameters<DC>, | ||
TReturn = AsyncReturnType<DC>, | ||
NextRetval = unknown | ||
> = PluginCommand<ExternalDriver, TArgs, TReturn, NextRetval>; | ||
/** | ||
* An instance of a "plugin" extension. | ||
@@ -74,3 +104,3 @@ * | ||
*/ | ||
export type NextPluginCallback = () => Promise<void>; | ||
export type NextPluginCallback<T = unknown> = () => Promise<T>; | ||
@@ -85,4 +115,5 @@ /** | ||
TArgs extends readonly any[] = any[], | ||
TReturn = any | ||
> = (next: NextPluginCallback, driver: D, ...args: TArgs) => Promise<TReturn>; | ||
TReturn = unknown, | ||
NextReturn = unknown | ||
> = (next: NextPluginCallback<NextReturn>, driver: D, ...args: TArgs) => Promise<TReturn>; | ||
@@ -97,3 +128,3 @@ /** | ||
PluginStatic<P>, | ||
[pluginName: string, cliArgs: Record<string, unknown>] | ||
[pluginName: string, cliArgs: StringRecord<unknown>] | ||
>; |
{ | ||
"name": "@appium/types", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "Various type declarations used across Appium", | ||
@@ -37,3 +37,4 @@ "keywords": [ | ||
"clean": "git checkout -- ./types/lib/appium-config.ts || true", | ||
"test:smoke": "node ./index.js" | ||
"test:smoke": "node ./index.js", | ||
"test:types": "tsd" | ||
}, | ||
@@ -46,3 +47,3 @@ "dependencies": { | ||
"@types/ws": "8.5.4", | ||
"type-fest": "3.6.1" | ||
"type-fest": "3.7.1" | ||
}, | ||
@@ -56,3 +57,3 @@ "engines": { | ||
}, | ||
"gitHead": "872b924a97c13142bdb8bf4218a4db324f309ce4", | ||
"gitHead": "d514ebdd7ebd27bb236509d0a3d580f0f18a34e5", | ||
"typedoc": { | ||
@@ -59,0 +60,0 @@ "entryPoint": "./lib/index.ts" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
276703
75
6256
+ Addedtype-fest@3.7.1(transitive)
- Removedtype-fest@3.6.1(transitive)
Updatedtype-fest@3.7.1