@yume-chan/adb 3.0.0-beta.0 → 3.0.0-beta.2
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/esm/adb.d.ts +7 -2
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +2 -2
- package/esm/adb.js.map +1 -1
- package/esm/banner.spec.d.ts +2 -0
- package/esm/banner.spec.d.ts.map +1 -0
- package/esm/daemon/auth/packet-processor.spec.d.ts +2 -0
- package/esm/daemon/auth/packet-processor.spec.d.ts.map +1 -0
- package/esm/daemon/auth/public-key.spec.d.ts +2 -0
- package/esm/daemon/auth/public-key.spec.d.ts.map +1 -0
- package/esm/daemon/crypto.spec.d.ts +2 -0
- package/esm/daemon/crypto.spec.d.ts.map +1 -0
- package/esm/server/client.d.ts +4 -3
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +13 -12
- package/esm/server/client.js.map +1 -1
- package/esm/server/client.spec.d.ts +2 -0
- package/esm/server/client.spec.d.ts.map +1 -0
- package/esm/server/transport.d.ts +1 -1
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +2 -2
- package/esm/server/transport.js.map +1 -1
- package/esm/service/reverse/response.spec.d.ts +2 -0
- package/esm/service/reverse/response.spec.d.ts.map +1 -0
- package/esm/service/subprocess/none/process.spec.d.ts +2 -0
- package/esm/service/subprocess/none/process.spec.d.ts.map +1 -0
- package/esm/service/subprocess/none/spawner.d.ts.map +1 -1
- package/esm/service/subprocess/none/spawner.js +10 -5
- package/esm/service/subprocess/none/spawner.js.map +1 -1
- package/esm/service/subprocess/none/spawner.spec.d.ts +2 -0
- package/esm/service/subprocess/none/spawner.spec.d.ts.map +1 -0
- package/esm/service/subprocess/shell/process.d.ts.map +1 -1
- package/esm/service/subprocess/shell/process.js +7 -9
- package/esm/service/subprocess/shell/process.js.map +1 -1
- package/esm/service/subprocess/shell/process.spec.d.ts +2 -0
- package/esm/service/subprocess/shell/process.spec.d.ts.map +1 -0
- package/esm/service/subprocess/shell/shared.spec.d.ts +2 -0
- package/esm/service/subprocess/shell/shared.spec.d.ts.map +1 -0
- package/esm/service/subprocess/shell/spawner.d.ts.map +1 -1
- package/esm/service/subprocess/shell/spawner.js +16 -11
- package/esm/service/subprocess/shell/spawner.js.map +1 -1
- package/esm/service/subprocess/shell/spawner.spec.d.ts +2 -0
- package/esm/service/subprocess/shell/spawner.spec.d.ts.map +1 -0
- package/esm/service/subprocess/utils.spec.d.ts +2 -0
- package/esm/service/subprocess/utils.spec.d.ts.map +1 -0
- package/esm/service/sync/compression/adapters.d.ts +16 -0
- package/esm/service/sync/compression/adapters.d.ts.map +1 -0
- package/esm/service/sync/compression/adapters.js +84 -0
- package/esm/service/sync/compression/adapters.js.map +1 -0
- package/esm/service/sync/compression/format-ns.d.ts.map +1 -1
- package/esm/service/sync/compression/format-ns.js +1 -0
- package/esm/service/sync/compression/format-ns.js.map +1 -1
- package/esm/service/sync/compression/format.d.ts +1 -0
- package/esm/service/sync/compression/format.d.ts.map +1 -1
- package/esm/service/sync/compression/format.js +1 -0
- package/esm/service/sync/compression/format.js.map +1 -1
- package/esm/service/sync/compression/index.d.ts +1 -1
- package/esm/service/sync/compression/index.d.ts.map +1 -1
- package/esm/service/sync/compression/index.js +1 -1
- package/esm/service/sync/compression/index.js.map +1 -1
- package/esm/service/sync/compression/mode.d.ts +6 -0
- package/esm/service/sync/compression/mode.d.ts.map +1 -0
- package/esm/service/sync/compression/mode.js +5 -0
- package/esm/service/sync/compression/mode.js.map +1 -0
- package/esm/service/sync/compression/native.d.ts +8 -0
- package/esm/service/sync/compression/native.d.ts.map +1 -0
- package/esm/service/sync/compression/native.js +53 -0
- package/esm/service/sync/compression/native.js.map +1 -0
- package/esm/service/sync/id/request.d.ts +1 -0
- package/esm/service/sync/id/request.d.ts.map +1 -1
- package/esm/service/sync/id/request.js +1 -0
- package/esm/service/sync/id/request.js.map +1 -1
- package/esm/service/sync/request/flag.d.ts +9 -0
- package/esm/service/sync/request/flag.d.ts.map +1 -0
- package/esm/service/sync/request/flag.js +8 -0
- package/esm/service/sync/request/flag.js.map +1 -0
- package/esm/service/sync/request/pull.d.ts +25 -2
- package/esm/service/sync/request/pull.d.ts.map +1 -1
- package/esm/service/sync/request/pull.js +76 -16
- package/esm/service/sync/request/pull.js.map +1 -1
- package/esm/service/sync/request/push.d.ts +36 -14
- package/esm/service/sync/request/push.d.ts.map +1 -1
- package/esm/service/sync/request/push.js +176 -60
- package/esm/service/sync/request/push.js.map +1 -1
- package/esm/service/sync/service.d.ts +32 -16
- package/esm/service/sync/service.d.ts.map +1 -1
- package/esm/service/sync/service.js +58 -13
- package/esm/service/sync/service.js.map +1 -1
- package/esm/service/sync/socket-pool.d.ts +1 -0
- package/esm/service/sync/socket-pool.d.ts.map +1 -1
- package/esm/service/sync/socket-pool.js +45 -9
- package/esm/service/sync/socket-pool.js.map +1 -1
- package/esm/service/sync/socket-pool.spec.d.ts +2 -0
- package/esm/service/sync/socket-pool.spec.d.ts.map +1 -0
- package/esm/service/sync/socket.d.ts +4 -0
- package/esm/service/sync/socket.d.ts.map +1 -1
- package/esm/service/sync/socket.js +16 -0
- package/esm/service/sync/socket.js.map +1 -1
- package/esm/service/sync/socket.spec.d.ts +2 -0
- package/esm/service/sync/socket.spec.d.ts.map +1 -0
- package/esm/utils/base64.spec.d.ts +2 -0
- package/esm/utils/base64.spec.d.ts.map +1 -0
- package/esm/utils/md5.spec.d.ts +2 -0
- package/esm/utils/md5.spec.d.ts.map +1 -0
- package/esm/utils/ref.d.ts +3 -5
- package/esm/utils/ref.d.ts.map +1 -1
- package/esm/utils/ref.js +12 -6
- package/esm/utils/ref.js.map +1 -1
- package/package.json +7 -7
- package/src/adb.ts +15 -3
- package/src/server/client.ts +18 -11
- package/src/server/transport.ts +5 -1
- package/src/service/subprocess/none/spawner.ts +9 -5
- package/src/service/subprocess/shell/process.ts +7 -10
- package/src/service/subprocess/shell/spawner.ts +15 -11
- package/src/service/sync/compression/adapters.ts +137 -0
- package/src/service/sync/compression/format-ns.ts +2 -0
- package/src/service/sync/compression/format.ts +5 -0
- package/src/service/sync/compression/index.ts +1 -1
- package/src/service/sync/compression/mode.ts +6 -0
- package/src/service/sync/compression/native.ts +73 -0
- package/src/service/sync/id/request.ts +1 -0
- package/src/service/sync/request/flag.ts +9 -0
- package/src/service/sync/request/pull.ts +135 -27
- package/src/service/sync/request/push.ts +241 -91
- package/src/service/sync/service.ts +87 -27
- package/src/service/sync/socket-pool.ts +50 -9
- package/src/service/sync/socket.ts +23 -1
- package/src/utils/ref.ts +17 -7
- package/esm/service/sync/compression/compression.d.ts +0 -17
- package/esm/service/sync/compression/compression.d.ts.map +0 -1
- package/esm/service/sync/compression/compression.js +0 -92
- package/esm/service/sync/compression/compression.js.map +0 -1
- package/src/service/sync/compression/compression.ts +0 -126
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-pool.js","sourceRoot":"","sources":["../../../src/service/sync/socket-pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"socket-pool.js","sourceRoot":"","sources":["../../../src/service/sync/socket-pool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,OAAO,UAAU;IACV,IAAI,CAAM;IACV,QAAQ,CAAS;IACjB,YAAY,CAAS;IACrB,iBAAiB,GAAa,EAAE,CAAC;IACjC,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IAC3C,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChC,OAAO,GAAG,KAAK,CAAC;IAEhB,YAAY,GAAQ,EAAE,OAAO,GAAG,CAAC,EAAE,WAAW,GAAG,KAAK;QAClD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,QA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AEpB,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC;IACjE,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-pool.spec.d.ts","sourceRoot":"","sources":["../../../src/service/sync/socket-pool.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { AsyncExactReadable, StructDeserializer } from "@yume-chan/struct";
|
|
2
2
|
import type { Adb } from "../../adb.js";
|
|
3
|
+
declare const AdbSyncErrorBrand: unique symbol;
|
|
3
4
|
declare class AdbSyncError extends Error {
|
|
5
|
+
[AdbSyncErrorBrand]: boolean;
|
|
6
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
4
7
|
}
|
|
5
8
|
export { AdbSyncError as Error };
|
|
6
9
|
export declare class Socket implements AsyncExactReadable {
|
|
@@ -15,6 +18,7 @@ export declare class Socket implements AsyncExactReadable {
|
|
|
15
18
|
static readonly FailResponse: import("@yume-chan/struct").Struct<{
|
|
16
19
|
message: import("@yume-chan/struct").Field<string, string, never, string>;
|
|
17
20
|
}, undefined, never>;
|
|
21
|
+
get id(): number;
|
|
18
22
|
get position(): number;
|
|
19
23
|
get closed(): Promise<undefined>;
|
|
20
24
|
constructor(socket: Adb.Socket, bufferSize: number);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/service/sync/socket.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGhF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAOxC,cAAM,YAAa,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/service/sync/socket.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAA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ct";
|
|
|
4
4
|
import { AutoResetEvent, encodeUtf8, unreachable } from "../../utils/index.js";
|
|
5
5
|
import { ResponseId } from "./id/index.js";
|
|
6
6
|
const NumberRequest = struct({ id: u32, arg: u32 }, { littleEndian: true });
|
|
7
|
+
const AdbSyncErrorBrand = Symbol.for("AdbSyncError.brand");
|
|
7
8
|
class AdbSyncError extends Error {
|
|
9
|
+
[AdbSyncErrorBrand] = true;
|
|
10
|
+
static [Symbol.hasInstance](value) {
|
|
11
|
+
return !!value?.[AdbSyncErrorBrand];
|
|
12
|
+
}
|
|
8
13
|
}
|
|
9
14
|
export { AdbSyncError as Error };
|
|
10
15
|
const FailResponse = struct({ message: string(u32) }, {
|
|
@@ -16,15 +21,20 @@ const FailResponse = struct({ message: string(u32) }, {
|
|
|
16
21
|
function i32ToHex(i) {
|
|
17
22
|
return "0x" + i.toString(16).padStart(8, "0");
|
|
18
23
|
}
|
|
24
|
+
let NextId = 0;
|
|
19
25
|
export class Socket {
|
|
20
26
|
static NumberRequest = NumberRequest;
|
|
21
27
|
static FailResponse = FailResponse;
|
|
28
|
+
#id;
|
|
22
29
|
#socket;
|
|
23
30
|
#writer;
|
|
24
31
|
#readable;
|
|
25
32
|
#writeLock = new AutoResetEvent();
|
|
26
33
|
#combiner;
|
|
27
34
|
#idleTimeoutId = null;
|
|
35
|
+
get id() {
|
|
36
|
+
return this.#id;
|
|
37
|
+
}
|
|
28
38
|
get position() {
|
|
29
39
|
return this.#readable.position;
|
|
30
40
|
}
|
|
@@ -32,6 +42,8 @@ export class Socket {
|
|
|
32
42
|
return this.#socket.closed;
|
|
33
43
|
}
|
|
34
44
|
constructor(socket, bufferSize) {
|
|
45
|
+
this.#id = NextId;
|
|
46
|
+
NextId += 1;
|
|
35
47
|
this.#socket = socket;
|
|
36
48
|
this.#writer = socket.writable.getWriter();
|
|
37
49
|
this.#readable = new BufferedReadableStream(socket.readable);
|
|
@@ -46,6 +58,10 @@ export class Socket {
|
|
|
46
58
|
startIdleTimer(timeout, callback) {
|
|
47
59
|
this.clearIdleTimer();
|
|
48
60
|
this.#idleTimeoutId = setTimeout(callback, timeout);
|
|
61
|
+
if (typeof this.#idleTimeoutId === "object") {
|
|
62
|
+
// Node.js: unref the timer so that it won't keep the process alive
|
|
63
|
+
this.#idleTimeoutId.unref?.();
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
66
|
/**
|
|
51
67
|
* Clear the idle timer.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../src/service/sync/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,OAAO,EACH,cAAc,EACd,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGpE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;AAE5E,MAAM,YAAa,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../src/service/sync/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,OAAO,EACH,cAAc,EACd,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,mBAA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AS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAClD,QAAQ,QAAQ,EAAE,CAAC;gBACf,KAAK,UAAU,CAAC,IAAI;oBAChB,MAAM,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;oBAC/C,WAAW,EAAE,CAAC;gBAClB,KAAK,UAAU,CAAC,IAAI;oBAChB,2EAA2E;oBAC3E,EAAE;oBACF,6FAA6F;oBAC7F,oFAAoF;oBACpF,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC5C,OAAO;gBACX,KAAK,UAAU;oBACX,MAAM,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;oBAC7C,MAAM;gBACV;oBACI,kBAAkB;oBAClB,MAAM,IAAI,KAAK,CACX,YAAY,QAAQ,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,QAAQ,CAAC,QAAQ,CAAC,EAAE,CACpG,CAAC;YACV,CAAC;QACL,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACP,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.spec.d.ts","sourceRoot":"","sources":["../../../src/service/sync/socket.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.spec.d.ts","sourceRoot":"","sources":["../../src/utils/base64.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"md5.spec.d.ts","sourceRoot":"","sources":["../../src/utils/md5.spec.ts"],"names":[],"mappings":""}
|
package/esm/utils/ref.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
import type { Disposable } from "@yume-chan/event";
|
|
1
2
|
/**
|
|
2
3
|
* An object to keep current Node.js process alive even when no code is running.
|
|
3
4
|
*
|
|
4
5
|
* Does nothing in Web environments.
|
|
5
|
-
*
|
|
6
|
-
* Note that it does't have reference counting. Calling `unref` will
|
|
7
|
-
* remove the ref no matter how many times `ref` has been previously called, and vice versa.
|
|
8
|
-
* This is the same as how Node.js works.
|
|
9
6
|
*/
|
|
10
|
-
export declare class Ref {
|
|
7
|
+
export declare class Ref implements Disposable {
|
|
11
8
|
#private;
|
|
12
9
|
constructor(options?: {
|
|
13
10
|
unref?: boolean | undefined;
|
|
14
11
|
});
|
|
15
12
|
ref(): void;
|
|
16
13
|
unref(): void;
|
|
14
|
+
dispose(): void;
|
|
17
15
|
}
|
|
18
16
|
//# sourceMappingURL=ref.d.ts.map
|
package/esm/utils/ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/utils/ref.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/utils/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AASnD;;;;GAIG;AACH,qBAAa,GAAI,YAAW,UAAU;;gBAKtB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE;IAMrD,GAAG;IAQH,KAAK;IAOL,OAAO,IAAI,IAAI;CAMlB"}
|
package/esm/utils/ref.js
CHANGED
|
@@ -3,23 +3,29 @@ const { setInterval, clearInterval } = globalThis;
|
|
|
3
3
|
* An object to keep current Node.js process alive even when no code is running.
|
|
4
4
|
*
|
|
5
5
|
* Does nothing in Web environments.
|
|
6
|
-
*
|
|
7
|
-
* Note that it does't have reference counting. Calling `unref` will
|
|
8
|
-
* remove the ref no matter how many times `ref` has been previously called, and vice versa.
|
|
9
|
-
* This is the same as how Node.js works.
|
|
10
6
|
*/
|
|
11
7
|
export class Ref {
|
|
12
8
|
#intervalId;
|
|
9
|
+
#count = 0;
|
|
13
10
|
constructor(options) {
|
|
14
11
|
if (!options?.unref) {
|
|
15
12
|
this.ref();
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
15
|
ref() {
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (this.#count === 0) {
|
|
17
|
+
// `setInterval` can keep current Node.js alive, the delay value doesn't matter
|
|
18
|
+
this.#intervalId = setInterval(() => { }, 60 * 1000);
|
|
19
|
+
}
|
|
20
|
+
this.#count += 1;
|
|
21
21
|
}
|
|
22
22
|
unref() {
|
|
23
|
+
this.#count -= 1;
|
|
24
|
+
if (this.#count === 0) {
|
|
25
|
+
this.dispose();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
dispose() {
|
|
23
29
|
if (this.#intervalId) {
|
|
24
30
|
clearInterval(this.#intervalId);
|
|
25
31
|
this.#intervalId = undefined;
|
package/esm/utils/ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/utils/ref.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/utils/ref.ts"],"names":[],"mappings":"AAOA,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,UAAwC,CAAC;AAEhF;;;;GAIG;AACH,MAAM,OAAO,GAAG;IACZ,WAAW,CAAqB;IAEhC,MAAM,GAAG,CAAC,CAAC;IAEX,YAAY,OAAyC;QACjD,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,EAAE,CAAC;QACf,CAAC;IACL,CAAC;IAED,GAAG;QACC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,+EAA+E;YAC/E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;QACjB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;IACL,CAAC;IAED,OAAO;QACH,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAChC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QACjC,CAAC;IACL,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/adb",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "TypeScript implementation of Android Debug Bridge (ADB) protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adb",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@yume-chan/async": "^4.1.3",
|
|
30
|
-
"@yume-chan/
|
|
31
|
-
"@yume-chan/
|
|
32
|
-
"@yume-chan/stream-extra": "3.0.0-beta.
|
|
33
|
-
"@yume-chan/struct": "3.0.0-beta.
|
|
30
|
+
"@yume-chan/no-data-view": "3.0.0-beta.2",
|
|
31
|
+
"@yume-chan/event": "3.0.0-beta.2",
|
|
32
|
+
"@yume-chan/stream-extra": "3.0.0-beta.2",
|
|
33
|
+
"@yume-chan/struct": "3.0.0-beta.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^26.
|
|
37
|
-
"prettier": "^3.
|
|
36
|
+
"@types/node": "^26.1.1",
|
|
37
|
+
"prettier": "^3.9.6",
|
|
38
38
|
"typescript": "^6.0.3",
|
|
39
39
|
"@yume-chan/eslint-config": "^1.0.0",
|
|
40
40
|
"@yume-chan/test-runner": "^1.0.0",
|
package/src/adb.ts
CHANGED
|
@@ -33,7 +33,10 @@ export interface AdbTransport extends Closeable {
|
|
|
33
33
|
|
|
34
34
|
readonly clientFeatures: readonly AdbFeature[];
|
|
35
35
|
|
|
36
|
-
connect(
|
|
36
|
+
connect(
|
|
37
|
+
service: string,
|
|
38
|
+
options?: AdbTransport.ConnectOptions,
|
|
39
|
+
): MaybePromiseLike<Adb.Socket>;
|
|
37
40
|
|
|
38
41
|
addReverseTunnel(
|
|
39
42
|
handler: Adb.IncomingSocketHandler,
|
|
@@ -45,6 +48,12 @@ export interface AdbTransport extends Closeable {
|
|
|
45
48
|
clearReverseTunnels(): MaybePromiseLike<void>;
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
export namespace AdbTransport {
|
|
52
|
+
export interface ConnectOptions {
|
|
53
|
+
unref?: boolean | undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
export class Adb implements Closeable {
|
|
49
58
|
readonly #transport: AdbTransport;
|
|
50
59
|
get transport(): AdbTransport {
|
|
@@ -101,8 +110,11 @@ export class Adb implements Closeable {
|
|
|
101
110
|
/**
|
|
102
111
|
* Creates a new ADB Socket to the specified service or socket address.
|
|
103
112
|
*/
|
|
104
|
-
async createSocket(
|
|
105
|
-
|
|
113
|
+
async createSocket(
|
|
114
|
+
service: string,
|
|
115
|
+
options?: AdbTransport.ConnectOptions,
|
|
116
|
+
): Promise<Adb.Socket> {
|
|
117
|
+
return await this.#transport.connect(service, options);
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
async createSocketAndWait(service: string): Promise<string> {
|
package/src/server/client.ts
CHANGED
|
@@ -193,8 +193,10 @@ export class AdbServerClient {
|
|
|
193
193
|
/**
|
|
194
194
|
* `adb version`
|
|
195
195
|
*/
|
|
196
|
-
async getVersion(
|
|
197
|
-
|
|
196
|
+
async getVersion(
|
|
197
|
+
options?: AdbServerClient.ServerConnectionOptions,
|
|
198
|
+
): Promise<number> {
|
|
199
|
+
const connection = await this.createConnection("host:version", options);
|
|
198
200
|
try {
|
|
199
201
|
const length = hexToNumber(await connection.readExactly(4));
|
|
200
202
|
const version = hexToNumber(await connection.readExactly(length));
|
|
@@ -204,8 +206,11 @@ export class AdbServerClient {
|
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
|
|
207
|
-
async validateVersion(
|
|
208
|
-
|
|
209
|
+
async validateVersion(
|
|
210
|
+
minimalVersion: number,
|
|
211
|
+
options?: AdbServerClient.ServerConnectionOptions,
|
|
212
|
+
) {
|
|
213
|
+
const version = await this.getVersion(options);
|
|
209
214
|
if (version < minimalVersion) {
|
|
210
215
|
throw new Error(
|
|
211
216
|
`adb server version (${version}) doesn't match this client (${minimalVersion})`,
|
|
@@ -324,34 +329,36 @@ export class AdbServerClient {
|
|
|
324
329
|
* Creates a connection that will forward the service to device.
|
|
325
330
|
* @param device The device selector
|
|
326
331
|
* @param service The service to forward
|
|
332
|
+
* @param options The server connection options
|
|
327
333
|
* @returns An `AdbServerClient.Socket` that can be used to communicate with the service
|
|
328
334
|
*/
|
|
329
335
|
async createDeviceConnection(
|
|
330
336
|
device: AdbServerClient.DeviceSelector,
|
|
331
337
|
service: string,
|
|
338
|
+
options?: AdbServerClient.ServerConnectionOptions,
|
|
332
339
|
): Promise<AdbServerClient.Socket> {
|
|
333
340
|
let switchService: string;
|
|
334
341
|
let transportId: bigint | undefined;
|
|
335
342
|
if (!device) {
|
|
336
|
-
await this.validateVersion(41);
|
|
343
|
+
await this.validateVersion(41, options);
|
|
337
344
|
switchService = `host:tport:any`;
|
|
338
345
|
} else if ("transportId" in device) {
|
|
339
346
|
switchService = `host:transport-id:${device.transportId}`;
|
|
340
347
|
transportId = device.transportId;
|
|
341
348
|
} else if ("serial" in device) {
|
|
342
|
-
await this.validateVersion(41);
|
|
349
|
+
await this.validateVersion(41, options);
|
|
343
350
|
switchService = `host:tport:serial:${device.serial}`;
|
|
344
351
|
} else if ("usb" in device) {
|
|
345
|
-
await this.validateVersion(41);
|
|
352
|
+
await this.validateVersion(41, options);
|
|
346
353
|
switchService = `host:tport:usb`;
|
|
347
354
|
} else if ("tcp" in device) {
|
|
348
|
-
await this.validateVersion(41);
|
|
355
|
+
await this.validateVersion(41, options);
|
|
349
356
|
switchService = `host:tport:local`;
|
|
350
357
|
} else {
|
|
351
358
|
throw new TypeError("Invalid device selector");
|
|
352
359
|
}
|
|
353
360
|
|
|
354
|
-
const connection = await this.createConnection(switchService);
|
|
361
|
+
const connection = await this.createConnection(switchService, options);
|
|
355
362
|
|
|
356
363
|
try {
|
|
357
364
|
await connection.writeString(service);
|
|
@@ -430,7 +437,7 @@ export class AdbServerClient {
|
|
|
430
437
|
options?: AdbServerClient.ServerConnectionOptions,
|
|
431
438
|
): Promise<void> {
|
|
432
439
|
if (state === "disconnect") {
|
|
433
|
-
await this.validateVersion(41);
|
|
440
|
+
await this.validateVersion(41, options);
|
|
434
441
|
}
|
|
435
442
|
|
|
436
443
|
return this.#waitForUnchecked(device, state, options);
|
|
@@ -440,7 +447,7 @@ export class AdbServerClient {
|
|
|
440
447
|
transportId: bigint,
|
|
441
448
|
options?: AdbServerClient.ServerConnectionOptions,
|
|
442
449
|
): Promise<void> {
|
|
443
|
-
const serverVersion = await this.getVersion();
|
|
450
|
+
const serverVersion = await this.getVersion(options);
|
|
444
451
|
if (serverVersion >= 41) {
|
|
445
452
|
return this.#waitForUnchecked(
|
|
446
453
|
{ transportId },
|
package/src/server/transport.ts
CHANGED
|
@@ -52,10 +52,14 @@ export class AdbServerTransport implements AdbTransport {
|
|
|
52
52
|
this.#disconnected = Promise.race([this.#closed.promise, disconnected]);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async connect(
|
|
55
|
+
async connect(
|
|
56
|
+
service: string,
|
|
57
|
+
options?: AdbTransport.ConnectOptions,
|
|
58
|
+
): Promise<Adb.Socket> {
|
|
56
59
|
const socket = await this.#client.createDeviceConnection(
|
|
57
60
|
{ transportId: this.transportId },
|
|
58
61
|
service,
|
|
62
|
+
options,
|
|
59
63
|
);
|
|
60
64
|
this.#sockets.push(socket);
|
|
61
65
|
return socket;
|
|
@@ -55,11 +55,15 @@ export function adbNoneProtocolSpawner(
|
|
|
55
55
|
|
|
56
56
|
processPromise.wait = (options) => {
|
|
57
57
|
const waitPromise = processPromise.then(async (process) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
try {
|
|
59
|
+
const [, output] = await Promise.all([
|
|
60
|
+
options?.stdin?.pipeTo(process.stdin),
|
|
61
|
+
process.output.pipeThrough(new ToArrayStream()),
|
|
62
|
+
]);
|
|
63
|
+
return output;
|
|
64
|
+
} finally {
|
|
65
|
+
await process.kill();
|
|
66
|
+
}
|
|
63
67
|
});
|
|
64
68
|
|
|
65
69
|
return createLazyPromise(
|
|
@@ -98,16 +98,13 @@ export class AdbShellProtocolProcessImpl implements AdbShellProtocolProcess {
|
|
|
98
98
|
},
|
|
99
99
|
);
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
this.#socket.close();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
101
|
+
// `signal` won't affect `this.stdout` and `this.stderr`
|
|
102
|
+
// So remaining data can still be read
|
|
103
|
+
// (call `controller.error` will discard all pending data)
|
|
104
|
+
signal?.addEventListener("abort", () => {
|
|
105
|
+
exited.reject(signal.reason);
|
|
106
|
+
this.#socket.close();
|
|
107
|
+
});
|
|
111
108
|
|
|
112
109
|
this.#writer = this.#socket.writable.getWriter();
|
|
113
110
|
this.#stdin = new MaybeConsumable.WritableStream<Uint8Array>({
|
|
@@ -67,17 +67,21 @@ export function adbShellProtocolSpawner(
|
|
|
67
67
|
|
|
68
68
|
processPromise.wait = (options) => {
|
|
69
69
|
const waitPromise = processPromise.then(async (process) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
try {
|
|
71
|
+
const [, stdout, stderr, exitCode] = await Promise.all([
|
|
72
|
+
options?.stdin?.pipeTo(process.stdin),
|
|
73
|
+
process.stdout.pipeThrough(new ToArrayStream()),
|
|
74
|
+
process.stderr.pipeThrough(new ToArrayStream()),
|
|
75
|
+
process.exited,
|
|
76
|
+
]);
|
|
77
|
+
return {
|
|
78
|
+
stdout,
|
|
79
|
+
stderr,
|
|
80
|
+
exitCode,
|
|
81
|
+
} satisfies AdbShellProtocolSpawner.WaitResult<Uint8Array[]>;
|
|
82
|
+
} finally {
|
|
83
|
+
await process.kill();
|
|
84
|
+
}
|
|
81
85
|
});
|
|
82
86
|
|
|
83
87
|
return createLazyPromise(
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { TransformStream } from "@yume-chan/stream-extra";
|
|
2
|
+
|
|
3
|
+
import type { Adb } from "../../../adb.js";
|
|
4
|
+
import { AdbFeature } from "../../../features.js";
|
|
5
|
+
|
|
6
|
+
import { Format, FormatNameMap } from "./format.js";
|
|
7
|
+
import { Mode } from "./mode.js";
|
|
8
|
+
import {
|
|
9
|
+
createNativeCompressionStream,
|
|
10
|
+
createNativeDecompressionStream,
|
|
11
|
+
hasNativeSupport,
|
|
12
|
+
} from "./native.js";
|
|
13
|
+
|
|
14
|
+
export { Format, FormatNameMap, Mode };
|
|
15
|
+
|
|
16
|
+
export type Adapter = () => TransformStream<Uint8Array, Uint8Array>;
|
|
17
|
+
|
|
18
|
+
const CompressionRegistry: Partial<
|
|
19
|
+
Record<Exclude<Format, typeof Format.None>, Adapter>
|
|
20
|
+
> = {};
|
|
21
|
+
|
|
22
|
+
const DecompressionRegistry: Partial<
|
|
23
|
+
Record<Exclude<Format, typeof Format.None>, Adapter>
|
|
24
|
+
> = {};
|
|
25
|
+
|
|
26
|
+
export function registerCompressionAdapter(
|
|
27
|
+
format: Exclude<Format, typeof Format.None>,
|
|
28
|
+
adapter: Adapter,
|
|
29
|
+
) {
|
|
30
|
+
CompressionRegistry[format] = adapter;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function registerDecompressionAdapter(
|
|
34
|
+
format: Exclude<Format, typeof Format.None>,
|
|
35
|
+
adapter: Adapter,
|
|
36
|
+
) {
|
|
37
|
+
DecompressionRegistry[format] = adapter;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function hasAdapterOrNativeSupport(format: Format, mode: Mode) {
|
|
41
|
+
if (format === Format.None) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const Registry =
|
|
46
|
+
mode === Mode.Compress ? CompressionRegistry : DecompressionRegistry;
|
|
47
|
+
if (Registry[format]) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return hasNativeSupport(format, mode);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function canUseBrotli(adb: Adb, mode: Mode) {
|
|
55
|
+
return (
|
|
56
|
+
adb.canUseFeature(AdbFeature.SendReceive2Brotli) &&
|
|
57
|
+
hasAdapterOrNativeSupport(Format.Brotli, mode)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function canUseLz4(adb: Adb, mode: Mode) {
|
|
62
|
+
return (
|
|
63
|
+
adb.canUseFeature(AdbFeature.SendReceive2Lz4) &&
|
|
64
|
+
hasAdapterOrNativeSupport(Format.Lz4, mode)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function canUseZstd(adb: Adb, mode: Mode) {
|
|
69
|
+
return (
|
|
70
|
+
adb.canUseFeature(AdbFeature.SendReceive2Zstd) &&
|
|
71
|
+
hasAdapterOrNativeSupport(Format.Zstd, mode)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function canUseFormat(adb: Adb, format: Format, mode: Mode) {
|
|
76
|
+
switch (format) {
|
|
77
|
+
case Format.None:
|
|
78
|
+
return true;
|
|
79
|
+
case Format.Brotli:
|
|
80
|
+
return canUseBrotli(adb, mode);
|
|
81
|
+
case Format.Lz4:
|
|
82
|
+
return canUseLz4(adb, mode);
|
|
83
|
+
case Format.Zstd:
|
|
84
|
+
return canUseZstd(adb, mode);
|
|
85
|
+
default:
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function chooseFormat(adb: Adb, mode: Mode) {
|
|
91
|
+
// The order follows
|
|
92
|
+
// https://android.googlesource.com/platform/packages/modules/adb/+/3da39565cad412a743a58b94b875a43ed3c640d3/client/file_sync_client.cpp#277
|
|
93
|
+
|
|
94
|
+
if (canUseZstd(adb, mode)) {
|
|
95
|
+
return Format.Zstd;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (canUseLz4(adb, mode)) {
|
|
99
|
+
return Format.Lz4;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (canUseBrotli(adb, mode)) {
|
|
103
|
+
return Format.Brotli;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return Format.None;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function createCompressionStream(
|
|
110
|
+
format: Exclude<Format, typeof Format.None>,
|
|
111
|
+
): TransformStream<Uint8Array, Uint8Array> {
|
|
112
|
+
const adapter = CompressionRegistry[format];
|
|
113
|
+
if (adapter) {
|
|
114
|
+
return adapter();
|
|
115
|
+
}
|
|
116
|
+
if (hasNativeSupport(format, Mode.Compress)) {
|
|
117
|
+
return createNativeCompressionStream(format);
|
|
118
|
+
}
|
|
119
|
+
throw new Error(
|
|
120
|
+
`No adapter registered for format ${FormatNameMap[format]}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function createDecompressionStream(
|
|
125
|
+
format: Exclude<Format, typeof Format.None>,
|
|
126
|
+
): TransformStream<Uint8Array, Uint8Array> {
|
|
127
|
+
const adapter = DecompressionRegistry[format];
|
|
128
|
+
if (adapter) {
|
|
129
|
+
return adapter();
|
|
130
|
+
}
|
|
131
|
+
if (hasNativeSupport(format, Mode.Decompress)) {
|
|
132
|
+
return createNativeDecompressionStream(format);
|
|
133
|
+
}
|
|
134
|
+
throw new Error(
|
|
135
|
+
`No adapter registered for format ${FormatNameMap[format]}`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
@@ -2,4 +2,9 @@ import * as Format from "./format-ns.js";
|
|
|
2
2
|
|
|
3
3
|
type Format = (typeof Format)[keyof typeof Format];
|
|
4
4
|
|
|
5
|
+
export const FormatNameMap = /* #__PURE__ */ (() =>
|
|
6
|
+
Object.fromEntries(
|
|
7
|
+
Object.entries(Format).map(([key, value]) => [value, key]),
|
|
8
|
+
))() as Record<Format, string>;
|
|
9
|
+
|
|
5
10
|
export { Format };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as Compression from "./
|
|
1
|
+
export * as Compression from "./adapters.js";
|