appium-uiautomator2-driver 9.2.2 → 10.0.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/CHANGELOG.md +18 -0
- package/README.md +0 -2295
- package/build/lib/commands/misc.d.ts +15 -1
- package/build/lib/commands/misc.d.ts.map +1 -1
- package/build/lib/commands/misc.js +16 -0
- package/build/lib/commands/misc.js.map +1 -1
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +6 -1
- package/build/lib/driver.js.map +1 -1
- package/lib/commands/misc.ts +21 -1
- package/lib/driver.ts +7 -0
- package/node_modules/@appium/strongbox/LICENSE +201 -0
- package/node_modules/@appium/strongbox/README.md +110 -0
- package/node_modules/@appium/strongbox/build/lib/base-item.d.ts +52 -0
- package/node_modules/@appium/strongbox/build/lib/base-item.d.ts.map +1 -0
- package/node_modules/@appium/strongbox/build/lib/base-item.js +101 -0
- package/node_modules/@appium/strongbox/build/lib/base-item.js.map +1 -0
- package/node_modules/@appium/strongbox/build/lib/index.d.ts +228 -0
- package/node_modules/@appium/strongbox/build/lib/index.d.ts.map +1 -0
- package/node_modules/@appium/strongbox/build/lib/index.js +283 -0
- package/node_modules/@appium/strongbox/build/lib/index.js.map +1 -0
- package/node_modules/@appium/strongbox/build/lib/util.d.ts +6 -0
- package/node_modules/@appium/strongbox/build/lib/util.d.ts.map +1 -0
- package/node_modules/@appium/strongbox/build/lib/util.js +13 -0
- package/node_modules/@appium/strongbox/build/lib/util.js.map +1 -0
- package/node_modules/@appium/strongbox/lib/base-item.ts +107 -0
- package/node_modules/@appium/strongbox/lib/index.ts +430 -0
- package/node_modules/@appium/strongbox/lib/util.ts +12 -0
- package/node_modules/@appium/strongbox/package.json +69 -0
- package/node_modules/@appium/strongbox/tsconfig.json +14 -0
- package/node_modules/appium-android-driver/CHANGELOG.md +56 -0
- package/node_modules/appium-android-driver/build/lib/commands/context/helpers.d.ts.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/context/helpers.js +2 -0
- package/node_modules/appium-android-driver/build/lib/commands/context/helpers.js.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/find.js +2 -2
- package/node_modules/appium-android-driver/build/lib/commands/find.js.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/constants.d.ts +3 -0
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/constants.d.ts.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/constants.js +4 -0
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/constants.js.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/exports.d.ts +10 -4
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/exports.d.ts.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/exports.js +37 -17
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/exports.js.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/stream.d.ts +34 -2
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/stream.d.ts.map +1 -1
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/stream.js +89 -43
- package/node_modules/appium-android-driver/build/lib/commands/media-stream/stream.js.map +1 -1
- package/node_modules/appium-android-driver/build/lib/driver.d.ts +1 -0
- package/node_modules/appium-android-driver/build/lib/driver.d.ts.map +1 -1
- package/node_modules/appium-android-driver/build/lib/driver.js +1 -0
- package/node_modules/appium-android-driver/build/lib/driver.js.map +1 -1
- package/node_modules/appium-android-driver/lib/commands/context/helpers.ts +2 -0
- package/node_modules/appium-android-driver/lib/commands/find.ts +2 -2
- package/node_modules/appium-android-driver/lib/commands/media-stream/constants.ts +4 -0
- package/node_modules/appium-android-driver/lib/commands/media-stream/exports.ts +51 -17
- package/node_modules/appium-android-driver/lib/commands/media-stream/stream.ts +90 -43
- package/node_modules/appium-android-driver/lib/driver.ts +1 -0
- package/node_modules/appium-android-driver/package.json +5 -5
- package/node_modules/appium-chromedriver/CHANGELOG.md +12 -0
- package/node_modules/appium-chromedriver/README.md +26 -0
- package/node_modules/appium-chromedriver/build/lib/checksums.d.ts +28 -0
- package/node_modules/appium-chromedriver/build/lib/checksums.d.ts.map +1 -0
- package/node_modules/appium-chromedriver/build/lib/checksums.js +73 -0
- package/node_modules/appium-chromedriver/build/lib/checksums.js.map +1 -0
- package/node_modules/appium-chromedriver/build/lib/chromedriver.d.ts +1 -0
- package/node_modules/appium-chromedriver/build/lib/chromedriver.d.ts.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/chromedriver.js +3 -1
- package/node_modules/appium-chromedriver/build/lib/chromedriver.js.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/commands/binary.d.ts.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/commands/binary.js +26 -1
- package/node_modules/appium-chromedriver/build/lib/commands/binary.js.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/commands/types.d.ts +1 -0
- package/node_modules/appium-chromedriver/build/lib/commands/types.d.ts.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/storage-client/storage-client.d.ts +1 -0
- package/node_modules/appium-chromedriver/build/lib/storage-client/storage-client.d.ts.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/storage-client/storage-client.js +8 -1
- package/node_modules/appium-chromedriver/build/lib/storage-client/storage-client.js.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/types.d.ts +4 -0
- package/node_modules/appium-chromedriver/build/lib/types.d.ts.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/utils.d.ts +8 -0
- package/node_modules/appium-chromedriver/build/lib/utils.d.ts.map +1 -1
- package/node_modules/appium-chromedriver/build/lib/utils.js +1 -1
- package/node_modules/appium-chromedriver/build/lib/utils.js.map +1 -1
- package/node_modules/appium-chromedriver/config/checksums.json +1665 -0
- package/node_modules/appium-chromedriver/config/edge-checksums.json +439 -0
- package/node_modules/appium-chromedriver/lib/checksums.ts +92 -0
- package/node_modules/appium-chromedriver/lib/chromedriver.ts +3 -0
- package/node_modules/appium-chromedriver/lib/commands/binary.ts +73 -42
- package/node_modules/appium-chromedriver/lib/commands/types.ts +1 -0
- package/node_modules/appium-chromedriver/lib/storage-client/storage-client.ts +9 -2
- package/node_modules/appium-chromedriver/lib/types.ts +4 -0
- package/node_modules/appium-chromedriver/lib/utils.ts +1 -1
- package/node_modules/appium-chromedriver/package.json +3 -2
- package/node_modules/appium-uiautomator2-server/CHANGELOG.md +120 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk +0 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk.idsig +0 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v11.3.0.apk +0 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v11.3.0.apk.idsig +0 -0
- package/node_modules/appium-uiautomator2-server/package.json +2 -2
- package/node_modules/asyncbox/README.md +7 -3
- package/node_modules/asyncbox/build/lib/shared/errors.d.ts +18 -2
- package/node_modules/asyncbox/build/lib/shared/errors.d.ts.map +1 -1
- package/node_modules/asyncbox/build/lib/shared/errors.js +24 -8
- package/node_modules/asyncbox/build/lib/shared/errors.js.map +1 -1
- package/node_modules/asyncbox/lib/shared/errors.ts +34 -8
- package/node_modules/asyncbox/package.json +1 -1
- package/node_modules/bare-fs/package.json +2 -2
- package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
- package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
- package/node_modules/env-paths/index.d.ts +90 -0
- package/node_modules/env-paths/index.js +69 -0
- package/node_modules/env-paths/license +9 -0
- package/node_modules/env-paths/package.json +55 -0
- package/node_modules/env-paths/readme.md +100 -0
- package/node_modules/io.appium.settings/CHANGELOG.md +14 -0
- package/node_modules/io.appium.settings/apks/settings_apk-debug.apk +0 -0
- package/node_modules/io.appium.settings/package.json +2 -2
- package/node_modules/is-safe-filename/index.d.ts +59 -0
- package/node_modules/is-safe-filename/index.js +41 -0
- package/node_modules/is-safe-filename/license +9 -0
- package/node_modules/is-safe-filename/package.json +45 -0
- package/node_modules/is-safe-filename/readme.md +62 -0
- package/node_modules/plist/dist/parse-binary.d.ts.map +1 -1
- package/node_modules/plist/dist/parse-binary.js +37 -9
- package/node_modules/plist/dist/parse-binary.js.map +1 -1
- package/node_modules/plist/package.json +1 -1
- package/node_modules/xpath/package.json +4 -3
- package/node_modules/xpath/xpath.d.ts +69 -21
- package/node_modules/xpath/xpath.js +233 -81
- package/package.json +5 -5
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v11.0.8.apk +0 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v11.0.8.apk.idsig +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,EAAE,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAuDlC;;;GAGG;AACH,MAAM,cAAc,GAAgC,IAAI,GAAG,CAAC;IAC1D,OAAO;IACP,MAAM;IACN,OAAO;IACP,SAAS;IACT,MAAM;IACN,OAAO;IACP,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,IAAI;CACL,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAS,UAAU,CAAC,KAAU;IAC5B,OAAO,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAA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,QAAQ,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IACpE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;AAE1C;;GAEG;AACH,OAAO,EAAC,QAAQ,EAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../lib/util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO7C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Produces a filesystem-safe slug from a string.
|
|
3
|
+
* @param value Raw value.
|
|
4
|
+
*/
|
|
5
|
+
export function slugify(value) {
|
|
6
|
+
return value
|
|
7
|
+
.normalize('NFKD')
|
|
8
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
9
|
+
.trim()
|
|
10
|
+
.replace(/[^a-zA-Z0-9]+/g, '-')
|
|
11
|
+
.replace(/^-+|-+$/g, '');
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../lib/util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK;SACT,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;SAC/B,IAAI,EAAE;SACN,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {mkdir, readFile, unlink, writeFile} from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import type {Item, ItemEncoding, Strongbox, Value} from './index.js';
|
|
5
|
+
import {slugify} from './util.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base item implementation
|
|
9
|
+
*
|
|
10
|
+
* @remarks This class is not intended to be instantiated directly
|
|
11
|
+
* @typeParam T - Type of data stored in the `Item`
|
|
12
|
+
*/
|
|
13
|
+
export class BaseItem<T extends Value, U extends Strongbox = Strongbox> implements Item<T> {
|
|
14
|
+
/**
|
|
15
|
+
* Parent Strongbox instance
|
|
16
|
+
*/
|
|
17
|
+
public readonly container: string;
|
|
18
|
+
/**
|
|
19
|
+
* Unique slugified identifier
|
|
20
|
+
*/
|
|
21
|
+
public readonly id: string;
|
|
22
|
+
/**
|
|
23
|
+
* {@inheritdoc Item.value}
|
|
24
|
+
*/
|
|
25
|
+
public readonly value: T | undefined;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* {@inheritdoc Item.value}
|
|
29
|
+
*/
|
|
30
|
+
protected _value?: T;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Slugifies the name
|
|
34
|
+
* @param name Name of instance
|
|
35
|
+
* @param parent Parent Strongbox
|
|
36
|
+
* @param encoding Defaults to `utf8`
|
|
37
|
+
*/
|
|
38
|
+
constructor(
|
|
39
|
+
public readonly name: string,
|
|
40
|
+
parent: U,
|
|
41
|
+
public readonly encoding: ItemEncoding = 'utf8',
|
|
42
|
+
) {
|
|
43
|
+
this.container = parent.container;
|
|
44
|
+
this.id = BaseItem.toFilePath(this.container, name);
|
|
45
|
+
Object.defineProperties(this, {
|
|
46
|
+
value: {
|
|
47
|
+
get() {
|
|
48
|
+
return this._value;
|
|
49
|
+
},
|
|
50
|
+
enumerable: true,
|
|
51
|
+
},
|
|
52
|
+
_value: {
|
|
53
|
+
enumerable: false,
|
|
54
|
+
writable: true,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Absolute filesystem path of the file backing an item: `container` + slugified `name`.
|
|
61
|
+
* Also used to convert a `name` to an `id`.
|
|
62
|
+
*/
|
|
63
|
+
public static toFilePath(container: string, name: string): string {
|
|
64
|
+
return path.join(container, slugify(name));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* {@inheritdoc Item.clear}
|
|
69
|
+
*/
|
|
70
|
+
public async clear(): Promise<void> {
|
|
71
|
+
try {
|
|
72
|
+
await unlink(this.id);
|
|
73
|
+
this._value = undefined;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* {@inheritdoc Item.read}
|
|
83
|
+
*/
|
|
84
|
+
public async read(): Promise<T | undefined> {
|
|
85
|
+
try {
|
|
86
|
+
this._value = (await readFile(this.id, {
|
|
87
|
+
encoding: this.encoding,
|
|
88
|
+
})) as T;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return this._value;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* {@inheritdoc Item.write}
|
|
99
|
+
*/
|
|
100
|
+
public async write(value: T): Promise<void> {
|
|
101
|
+
if (this._value !== value) {
|
|
102
|
+
await mkdir(path.dirname(this.id), {recursive: true});
|
|
103
|
+
await writeFile(this.id, value, this.encoding);
|
|
104
|
+
this._value = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import {opendir, rm} from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import envPaths from 'env-paths';
|
|
5
|
+
|
|
6
|
+
import {BaseItem} from './base-item.js';
|
|
7
|
+
import {slugify} from './util.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Valid file encodings.
|
|
11
|
+
*
|
|
12
|
+
* `null` means the file should be read and written as a `Buffer`.
|
|
13
|
+
*/
|
|
14
|
+
export type ItemEncoding = BufferEncoding | null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Valid value wrapped by {@linkcode Item}. Can be an encoded string or `Buffer`
|
|
18
|
+
*/
|
|
19
|
+
export type Value = string | Buffer;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An object representing a persisted item containing something of type `T` (which can be a {@linkcode Buffer} or an encoded string; see {@linkcode ItemEncoding}).
|
|
23
|
+
*
|
|
24
|
+
* A {@linkcode Item} does not know anything about where it is stored, or how it is stored.
|
|
25
|
+
* @typeParam T - Type of data stored in the item
|
|
26
|
+
*/
|
|
27
|
+
export interface Item<T extends Value> {
|
|
28
|
+
/**
|
|
29
|
+
* Encoding of underlying value
|
|
30
|
+
*/
|
|
31
|
+
encoding: ItemEncoding;
|
|
32
|
+
/**
|
|
33
|
+
* Slugified name
|
|
34
|
+
*/
|
|
35
|
+
id: string;
|
|
36
|
+
/**
|
|
37
|
+
* Name of item
|
|
38
|
+
*/
|
|
39
|
+
name: string;
|
|
40
|
+
/**
|
|
41
|
+
* Last known value (stored in memory)
|
|
42
|
+
*
|
|
43
|
+
* @remarks A custom {@linkcode Item} meant to handle very large files should probably not implement this.
|
|
44
|
+
*/
|
|
45
|
+
value?: T;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Deletes the item.
|
|
49
|
+
*/
|
|
50
|
+
clear(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Reads value
|
|
53
|
+
*/
|
|
54
|
+
read(): Promise<T | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Writes value
|
|
57
|
+
* @param value New value
|
|
58
|
+
*/
|
|
59
|
+
write(value: T): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Set of known `Item` encodings
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
const ITEM_ENCODINGS: Readonly<Set<ItemEncoding>> = new Set([
|
|
67
|
+
'ascii',
|
|
68
|
+
'utf8',
|
|
69
|
+
'utf-8',
|
|
70
|
+
'utf16le',
|
|
71
|
+
'ucs2',
|
|
72
|
+
'ucs-2',
|
|
73
|
+
'base64',
|
|
74
|
+
'base64url',
|
|
75
|
+
'latin1',
|
|
76
|
+
'binary',
|
|
77
|
+
'hex',
|
|
78
|
+
null,
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Type guard for encodings
|
|
83
|
+
* @param value any
|
|
84
|
+
* @returns `true` is `value` is a valid file encoding
|
|
85
|
+
*/
|
|
86
|
+
function isEncoding(value: any): value is ItemEncoding {
|
|
87
|
+
return ITEM_ENCODINGS.has(value);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Default container suffix if no explicit container is provided.
|
|
92
|
+
*
|
|
93
|
+
* @see {@linkcode StrongboxOpts}
|
|
94
|
+
*/
|
|
95
|
+
export const DEFAULT_SUFFIX = 'strongbox';
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A constructor function which instantiates a {@linkcode Item}.
|
|
99
|
+
*/
|
|
100
|
+
export type ItemCtor<
|
|
101
|
+
T extends Value,
|
|
102
|
+
U extends StrongboxOpts = StrongboxOpts,
|
|
103
|
+
V extends Strongbox<U> = Strongbox<U>,
|
|
104
|
+
> = new (name: string, parent: V, encoding?: ItemEncoding) => Item<T>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Options for {@linkcode strongbox}
|
|
108
|
+
*/
|
|
109
|
+
export interface StrongboxOpts {
|
|
110
|
+
/**
|
|
111
|
+
* Override default container, which is chosen according to environment.
|
|
112
|
+
*
|
|
113
|
+
* This must be a writable path.
|
|
114
|
+
*/
|
|
115
|
+
container: string;
|
|
116
|
+
/**
|
|
117
|
+
* Default {@linkcode Item} constructor.
|
|
118
|
+
*
|
|
119
|
+
* Unless a constructor is specified when calling {@linkcode Strongbox.createItem} or {@linkcode Strongbox.createItemWithValue}, this will be used.
|
|
120
|
+
* @defaultValue BaseItem
|
|
121
|
+
*/
|
|
122
|
+
defaultItemCtor: ItemCtor<any>;
|
|
123
|
+
/**
|
|
124
|
+
* Extra subdir to append to the auto-generated file directory hierarchy.
|
|
125
|
+
*
|
|
126
|
+
* This is ignored if `container` is provided.
|
|
127
|
+
* @defaultValue 'strongbox'
|
|
128
|
+
*/
|
|
129
|
+
suffix: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Main entry point for use of this module
|
|
134
|
+
*
|
|
135
|
+
* Manages multiple {@linkcode Item}s.
|
|
136
|
+
*/
|
|
137
|
+
export class Strongbox<Options extends StrongboxOpts = StrongboxOpts> implements AsyncIterable<Item<any>> {
|
|
138
|
+
/**
|
|
139
|
+
* Override the directory of this container.
|
|
140
|
+
*
|
|
141
|
+
* If this is present, `suffix` is ignored.
|
|
142
|
+
*/
|
|
143
|
+
public readonly container: string;
|
|
144
|
+
/**
|
|
145
|
+
* Slugified name of this instance; corresponds to the directory name.
|
|
146
|
+
*
|
|
147
|
+
* If `dir` is provided, this value is unused.
|
|
148
|
+
* If `suffix` is provided, then this will be the parent directory of `suffix`.
|
|
149
|
+
*/
|
|
150
|
+
public readonly id: string;
|
|
151
|
+
public readonly suffix: string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Default {@linkcode ItemCtor} to use when creating new {@linkcode Item}s
|
|
155
|
+
*/
|
|
156
|
+
protected defaultItemCtor: ItemCtor<any>;
|
|
157
|
+
/**
|
|
158
|
+
* Store of known {@linkcode Item}s
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
protected items: Map<string, WeakRef<Item<any>>>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Slugifies the name & determines the directory
|
|
165
|
+
* @param name Name of instance
|
|
166
|
+
* @param opts Options
|
|
167
|
+
*/
|
|
168
|
+
protected constructor(
|
|
169
|
+
public readonly name: string,
|
|
170
|
+
opts: Partial<Options> = {},
|
|
171
|
+
) {
|
|
172
|
+
this.id = slugify(name);
|
|
173
|
+
|
|
174
|
+
let newOpts = this.setDefaultOptions(opts);
|
|
175
|
+
newOpts = this.checkOptions(newOpts);
|
|
176
|
+
|
|
177
|
+
this.defaultItemCtor = newOpts.defaultItemCtor;
|
|
178
|
+
this.container = newOpts.container;
|
|
179
|
+
this.suffix = newOpts.suffix;
|
|
180
|
+
this.items = new Map();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Creates a new {@linkcode Strongbox}
|
|
185
|
+
* @param name Name of instance
|
|
186
|
+
* @param opts Options
|
|
187
|
+
* @returns New instance
|
|
188
|
+
*/
|
|
189
|
+
public static create<Options extends StrongboxOpts = StrongboxOpts>(name: string, opts?: Partial<Options>) {
|
|
190
|
+
return new Strongbox(name, opts);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Clears _all_ items.
|
|
195
|
+
*
|
|
196
|
+
* @param force - If `true`, will rimraf the container. Otherwise, will only delete individual items.
|
|
197
|
+
*/
|
|
198
|
+
public async clearAll(force = false): Promise<void> {
|
|
199
|
+
const items = [...this.items.values()].map((ref) => ref.deref()).filter(Boolean) as Item<any>[];
|
|
200
|
+
await Promise.all(items.map((item) => item.clear()));
|
|
201
|
+
if (force) {
|
|
202
|
+
await rm(this.container, {recursive: true});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Create a new {@linkcode Item}.
|
|
208
|
+
*
|
|
209
|
+
* Reads the item, if it is already persisted. Does not throw if missing.
|
|
210
|
+
* @param name Unique name of item
|
|
211
|
+
* @param encoding Encoding of item; defaults to `utf8`
|
|
212
|
+
* @returns New `Item`
|
|
213
|
+
* @typeParam T - Type of data stored in the `Item`
|
|
214
|
+
*/
|
|
215
|
+
async createItem<T extends Value>(name: string, ctor?: ItemCtor<T>, encoding?: ItemEncoding): Promise<Item<T>>;
|
|
216
|
+
async createItem<T extends Value>(name: string, encoding?: ItemEncoding): Promise<Item<T>>;
|
|
217
|
+
async createItem<T extends Value>(
|
|
218
|
+
name: string,
|
|
219
|
+
encodingOrCtor?: ItemEncoding | ItemCtor<T>,
|
|
220
|
+
encoding?: ItemEncoding,
|
|
221
|
+
): Promise<Item<T>> {
|
|
222
|
+
if (isEncoding(encodingOrCtor)) {
|
|
223
|
+
encoding = encodingOrCtor;
|
|
224
|
+
encodingOrCtor = this.defaultItemCtor;
|
|
225
|
+
}
|
|
226
|
+
if (!slugify(name)) {
|
|
227
|
+
// the slug is the filename; an empty one would resolve to the container directory itself
|
|
228
|
+
throw new TypeError(`Item name '${name}' must contain at least one alphanumeric character`);
|
|
229
|
+
}
|
|
230
|
+
const item = new (encodingOrCtor ?? (this.defaultItemCtor as ItemCtor<T>))(name, this, encoding);
|
|
231
|
+
if (this.getLiveItem(item.id)) {
|
|
232
|
+
throw new ReferenceError(`Item with id "${item.id}" already exists`);
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
await item.read();
|
|
236
|
+
} catch (e) {
|
|
237
|
+
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
238
|
+
throw e;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this.items.set(item.id, new WeakRef(item));
|
|
242
|
+
return item;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Creates a {@linkcode Item} then immediately writes value to it.
|
|
247
|
+
*
|
|
248
|
+
* If it exists already, it will be overwritten.
|
|
249
|
+
* @param name Name of `Item`
|
|
250
|
+
* @param value File value to write
|
|
251
|
+
* @param ctor Specific {@linkcode ItemCtor} to use
|
|
252
|
+
* @param encoding File encoding
|
|
253
|
+
* @returns New `Item` w/ value of `value`
|
|
254
|
+
*/
|
|
255
|
+
async createItemWithValue<T extends Value>(
|
|
256
|
+
name: string,
|
|
257
|
+
value: T,
|
|
258
|
+
ctor: ItemCtor<T>,
|
|
259
|
+
encoding?: ItemEncoding,
|
|
260
|
+
): Promise<Item<T>>;
|
|
261
|
+
async createItemWithValue<T extends Value>(name: string, value: T, encoding?: ItemEncoding): Promise<Item<T>>;
|
|
262
|
+
async createItemWithValue<T extends Value>(
|
|
263
|
+
name: string,
|
|
264
|
+
value: T,
|
|
265
|
+
encodingOrCtor?: ItemEncoding | ItemCtor<T>,
|
|
266
|
+
encoding?: ItemEncoding,
|
|
267
|
+
): Promise<Item<T>> {
|
|
268
|
+
const item = isEncoding(encodingOrCtor)
|
|
269
|
+
? await this.createItem<T>(name, encodingOrCtor)
|
|
270
|
+
: await this.createItem<T>(name, encodingOrCtor, encoding);
|
|
271
|
+
await item.write(value);
|
|
272
|
+
return item;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Attempts to retrieve an {@linkcode Item} by its `id`.
|
|
277
|
+
* Drops stale {@linkcode WeakRef} map entries when the value was collected.
|
|
278
|
+
* @param id ID of item
|
|
279
|
+
* @returns An `Item`, if found
|
|
280
|
+
*/
|
|
281
|
+
public getItem(id: string): Item<any> | undefined {
|
|
282
|
+
return this.getLiveItem(id);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Lists persisted items by scanning the container directory (one regular file per item).
|
|
287
|
+
*
|
|
288
|
+
* Filenames are matched to items by path; if an item was already registered (e.g. via
|
|
289
|
+
* {@linkcode Strongbox.createItem}), that instance is returned and keeps its original `name`.
|
|
290
|
+
* Otherwise a new item is created using the filename as `name` (see {@linkcode BaseItem}).
|
|
291
|
+
*
|
|
292
|
+
* @remarks Builds one array of every {@linkcode Item} reference. Does not read file contents;
|
|
293
|
+
* call {@linkcode Item.read} on each item as needed. Order follows directory iteration
|
|
294
|
+
* ({@linkcode opendir}), not lexicographic sort. For many items, `for await (const item of box)`
|
|
295
|
+
* ({@linkcode Symbol.asyncIterator}) streams entries without allocating a full {@linkcode Item}[]
|
|
296
|
+
* first.
|
|
297
|
+
*
|
|
298
|
+
* @returns Items in directory iteration order; empty if the container directory does not exist yet
|
|
299
|
+
*/
|
|
300
|
+
public async listItems(): Promise<Item<any>[]> {
|
|
301
|
+
const items: Item<any>[] = [];
|
|
302
|
+
for await (const basename of this.iterateFileBasenames()) {
|
|
303
|
+
items.push(this.resolveItemForBasename(basename));
|
|
304
|
+
}
|
|
305
|
+
return items;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Yields each persisted item in the same order as {@linkcode Strongbox.listItems}. Use
|
|
310
|
+
* `for await (const item of box)`.
|
|
311
|
+
*
|
|
312
|
+
* @remarks Walks the container with {@linkcode opendir} and yields one {@linkcode Item} per file
|
|
313
|
+
* as basenames are seen (no full-name buffer and no sort).
|
|
314
|
+
*/
|
|
315
|
+
public async *[Symbol.asyncIterator](): AsyncIterableIterator<Item<any>> {
|
|
316
|
+
for await (const basename of this.iterateFileBasenames()) {
|
|
317
|
+
yield this.resolveItemForBasename(basename);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Performs runtime validation (and optionally transformation) of options.
|
|
323
|
+
*
|
|
324
|
+
* Should not set defaults.
|
|
325
|
+
*
|
|
326
|
+
* The default implementation slugifies any custom container name and suffix.
|
|
327
|
+
*
|
|
328
|
+
* Subclasses should override this method to perform additional validation as needed.
|
|
329
|
+
* @param opts - Options
|
|
330
|
+
*/
|
|
331
|
+
protected checkOptions(opts: Options): Options {
|
|
332
|
+
opts.suffix = slugify(opts.suffix);
|
|
333
|
+
if (opts.container) {
|
|
334
|
+
if (!path.isAbsolute(opts.container)) {
|
|
335
|
+
throw new TypeError(`container slug ${opts.container} must be an absolute path`);
|
|
336
|
+
}
|
|
337
|
+
// slugify the folders only. the root is what makes the path absolute (a drive letter or UNC
|
|
338
|
+
// share on windows), and slugify would strip the colon. normalize first so mixed slashes
|
|
339
|
+
// still split into real segments.
|
|
340
|
+
const normalized = path.normalize(opts.container);
|
|
341
|
+
const {root} = path.parse(normalized);
|
|
342
|
+
const segments = normalized.slice(root.length).split(path.sep).filter(Boolean);
|
|
343
|
+
opts.container = path.join(root, ...segments.map(slugify));
|
|
344
|
+
} else {
|
|
345
|
+
opts.container = path.join(envPaths(this.id).data, opts.suffix);
|
|
346
|
+
}
|
|
347
|
+
return opts;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Sets defaults for options.
|
|
352
|
+
*
|
|
353
|
+
* Subclasses should override as necessary.
|
|
354
|
+
* @param opts Options
|
|
355
|
+
* @returns Options with defaults applied
|
|
356
|
+
*/
|
|
357
|
+
protected setDefaultOptions(opts: Partial<Options> = {}): Options {
|
|
358
|
+
const newOpts = opts as Options;
|
|
359
|
+
newOpts.suffix = opts.suffix ?? DEFAULT_SUFFIX;
|
|
360
|
+
newOpts.defaultItemCtor = opts.defaultItemCtor ?? BaseItem;
|
|
361
|
+
return newOpts;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Returns a live {@linkcode Item} or removes a stale {@linkcode WeakRef} from {@linkcode Strongbox.items}.
|
|
366
|
+
*/
|
|
367
|
+
private getLiveItem(id: string): Item<any> | undefined {
|
|
368
|
+
const ref = this.items.get(id);
|
|
369
|
+
if (!ref) {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
const item = ref.deref();
|
|
373
|
+
if (!item) {
|
|
374
|
+
this.items.delete(id);
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
return item;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Streams regular-file basenames from the container using {@linkcode opendir} (order is
|
|
382
|
+
* filesystem-defined, not sorted).
|
|
383
|
+
*/
|
|
384
|
+
private async *iterateFileBasenames(): AsyncIterableIterator<string> {
|
|
385
|
+
let dir: Awaited<ReturnType<typeof opendir>>;
|
|
386
|
+
try {
|
|
387
|
+
dir = await opendir(this.container);
|
|
388
|
+
} catch (e) {
|
|
389
|
+
if ((e as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
throw e;
|
|
393
|
+
}
|
|
394
|
+
for await (const ent of dir) {
|
|
395
|
+
// a basename with no alphanumerics has no slug, so it cannot belong to an item
|
|
396
|
+
if (ent.isFile() && slugify(ent.name)) {
|
|
397
|
+
yield ent.name;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Registers an {@linkcode Item} for a filename on disk without reading the file (see
|
|
404
|
+
* {@linkcode Strongbox.createItem}, which loads persisted contents eagerly). Uses the same
|
|
405
|
+
* constructor arity as {@linkcode Strongbox.createItem} when no encoding is given.
|
|
406
|
+
*/
|
|
407
|
+
private registerItemWithoutRead(name: string): Item<any> {
|
|
408
|
+
const item = new (this.defaultItemCtor as ItemCtor<any>)(name, this, undefined);
|
|
409
|
+
if (this.getLiveItem(item.id)) {
|
|
410
|
+
throw new ReferenceError(`Item with id "${item.id}" already exists`);
|
|
411
|
+
}
|
|
412
|
+
this.items.set(item.id, new WeakRef(item));
|
|
413
|
+
return item;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private resolveItemForBasename(basename: string): Item<any> {
|
|
417
|
+
const id = BaseItem.toFilePath(this.container, basename);
|
|
418
|
+
return this.getItem(id) ?? this.registerItemWithoutRead(basename);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* {@inheritdoc Strongbox.create}
|
|
424
|
+
*/
|
|
425
|
+
export const strongbox = Strongbox.create;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* This can be subclassed if needed.
|
|
429
|
+
*/
|
|
430
|
+
export {BaseItem};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Produces a filesystem-safe slug from a string.
|
|
3
|
+
* @param value Raw value.
|
|
4
|
+
*/
|
|
5
|
+
export function slugify(value: string): string {
|
|
6
|
+
return value
|
|
7
|
+
.normalize('NFKD')
|
|
8
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
9
|
+
.trim()
|
|
10
|
+
.replace(/[^a-zA-Z0-9]+/g, '-')
|
|
11
|
+
.replace(/^-+|-+$/g, '');
|
|
12
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appium/strongbox",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"gitHead": "3d9f50fa1609d8bc7269b298656be265e302c95a",
|
|
5
|
+
"description": "Persistent storage for Appium extensions",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"android",
|
|
8
|
+
"automation",
|
|
9
|
+
"firefoxos",
|
|
10
|
+
"ios",
|
|
11
|
+
"javascript",
|
|
12
|
+
"selenium",
|
|
13
|
+
"testing",
|
|
14
|
+
"webdriver"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://appium.io",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/appium/appium/issues"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"author": "https://github.com/appium",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/appium/appium.git",
|
|
25
|
+
"directory": "packages/strongbox"
|
|
26
|
+
},
|
|
27
|
+
"directories": {
|
|
28
|
+
"lib": "lib"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"build/lib",
|
|
32
|
+
"lib",
|
|
33
|
+
"tsconfig.json"
|
|
34
|
+
],
|
|
35
|
+
"type": "module",
|
|
36
|
+
"main": "./build/lib/index.js",
|
|
37
|
+
"types": "./build/lib/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./build/lib/index.d.ts",
|
|
41
|
+
"import": "./build/lib/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"test": "run-p test:unit test:types",
|
|
50
|
+
"test:smoke": "node .",
|
|
51
|
+
"test:unit": "node --test --experimental-test-module-mocks --enable-source-maps --test-timeout=5000 \"./build/test/unit/**/*.spec.js\"",
|
|
52
|
+
"test:types": "tsd",
|
|
53
|
+
"test:e2e": "node --test --enable-source-maps --test-force-exit --test-concurrency=1 --test-timeout=20000 \"./build/test/e2e/**/*.e2e.spec.js\""
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"env-paths": "^4.0.0"
|
|
57
|
+
},
|
|
58
|
+
"tsd": {
|
|
59
|
+
"compilerOptions": {
|
|
60
|
+
"composite": false,
|
|
61
|
+
"declarationMap": false
|
|
62
|
+
},
|
|
63
|
+
"directory": "test/types"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0",
|
|
67
|
+
"npm": ">=10"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@appium/tsconfig/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"outDir": "build",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"checkJs": true,
|
|
8
|
+
"module": "NodeNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"types": ["node"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["lib", "test/unit", "test/e2e"],
|
|
13
|
+
"exclude": ["build"]
|
|
14
|
+
}
|