@appium/types 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/plugin.ts ADDED
@@ -0,0 +1,92 @@
1
+ import {MethodMap, UpdateServerCallback, Class, AppiumLogger} from '.';
2
+ import {Driver, ExternalDriver} from './driver';
3
+
4
+ /**
5
+ * The interface describing the constructor and static properties of a Plugin.
6
+ */
7
+ export interface PluginStatic<T extends Plugin = Plugin> {
8
+ /**
9
+ * Allows a plugin to modify the Appium server instance.
10
+ */
11
+ updateServer?: UpdateServerCallback;
12
+ /**
13
+ * Plugins can define new methods for the Appium server to map to command names, of the same
14
+ * format as used in Appium's `routes.js`, for example, this would be a valid `newMethodMap`:
15
+ * @example
16
+ * {
17
+ * '/session/:sessionId/new_method': {
18
+ * GET: {command: 'getNewThing'},
19
+ * POST: {command: 'setNewThing', payloadParams: {required: ['someParam']}}
20
+ * }
21
+ * }
22
+ */
23
+ newMethodMap?: MethodMap<T>;
24
+ }
25
+
26
+ /**
27
+ * An instance of a "plugin" extension.
28
+ *
29
+ * Likewise, the `prototype` of a {@link PluginClass `Plugin` class}.
30
+ */
31
+ export interface Plugin {
32
+ /**
33
+ * Name of the plugin. Derived from the metadata.
34
+ */
35
+ name: string;
36
+ /**
37
+ * A logger with prefix identifying the plugin
38
+ */
39
+ logger: AppiumLogger;
40
+ /**
41
+ * CLI args for this plugin (if any are accepted and provided).
42
+ */
43
+ cliArgs: Record<string, any>;
44
+ /**
45
+ * Listener for unexpected server shutdown, which allows a plugin to do cleanup or take custom actions.
46
+ */
47
+ onUnexpectedShutdown?: (driver: Driver, cause: Error | string) => Promise<void>;
48
+ /**
49
+ * Handle an Appium command, optionally running and using or throwing away the value of the
50
+ * original Appium behavior (or the behavior of the next plugin in a plugin chain).
51
+ */
52
+ handle?: (
53
+ next: NextPluginCallback,
54
+ driver: Driver,
55
+ cmdName: string,
56
+ ...args: any[]
57
+ ) => Promise<void>;
58
+ }
59
+
60
+ /**
61
+ * A reference to an async function which encapsulates what would normally
62
+ * happen if this plugin were not handling a command. Used by {@link PluginInterface.handle}.
63
+ *
64
+ * Given `next()` is a `NextPluginCallback`: if this is the only plugin
65
+ * handling the command, `await next()` would therefore trigger the normal
66
+ * handling logic in the driver which is in use. If another plugin is
67
+ * registered, it would run *that* plugin's `handle` method and return the
68
+ * result for use here. Note that if this plugin does *not* call `await next()`,
69
+ * then the normal command logic will not be run, and this plugin is responsible
70
+ * for managing new command timeouts and command logging, for example:
71
+ * `driver.stopNewCommandTimeout()` -- before running plugin logic
72
+ * `driver.startNewCommandTimeout()` -- after running plugin logic
73
+ * `driver._eventHistory.commands.push({cmd: cmdName, startTime, endTime}) --
74
+ * after running plugin logic
75
+ */
76
+ export type NextPluginCallback = () => Promise<void>;
77
+
78
+ /**
79
+ * Implementation of a command within a plugin
80
+ */
81
+ export type PluginCommand<TArgs = any> = (
82
+ next: NextPluginCallback,
83
+ driver: ExternalDriver,
84
+ ...args: TArgs[]
85
+ ) => Promise<void>;
86
+
87
+ /**
88
+ * Mainly for internal use.
89
+ *
90
+ * The third parameter is the possible constructor signatures for the plugin class.
91
+ */
92
+ export type PluginClass = Class<Plugin, PluginStatic, [string, Record<string, unknown>]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/types",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Various type declarations used across Appium",
5
5
  "keywords": [
6
6
  "appium",
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "license": "Apache-2.0",
20
20
  "author": "https://github.com/appium",
21
+ "types": "./build/index.d.ts",
21
22
  "files": [
22
23
  "build",
23
24
  "lib"
@@ -26,18 +27,23 @@
26
27
  "build": "node ./scripts/generate-schema-types.js",
27
28
  "dev": "npm run build -- --watch",
28
29
  "fix": "npm run lint -- --fix",
29
- "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore ."
30
+ "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
31
+ "prepare": "npm run build",
32
+ "test:smoke": "echo 'No smoke test for this package'"
33
+ },
34
+ "dependencies": {
35
+ "@appium/schema": "^0.0.8",
36
+ "@types/express": "4.17.13",
37
+ "@types/npmlog": "4.1.4",
38
+ "@wdio/types": "7.20.7",
39
+ "type-fest": "2.17.0"
30
40
  },
31
41
  "engines": {
32
- "node": ">=12",
42
+ "node": ">=14",
33
43
  "npm": ">=6"
34
44
  },
35
- "types": "./build/index.d.ts",
36
45
  "publishConfig": {
37
46
  "access": "public"
38
47
  },
39
- "gitHead": "5482c921bc187ed8807922c00bd2355585f4971a",
40
- "dependencies": {
41
- "@appium/schema": "^0.0.5"
42
- }
48
+ "gitHead": "f6e6d7234e7fe92f989f4e37a71007044985dedf"
43
49
  }