@yume-chan/adb 0.0.13 → 0.0.16

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.
Files changed (116) hide show
  1. package/CHANGELOG.json +57 -0
  2. package/CHANGELOG.md +29 -1
  3. package/LICENSE +21 -21
  4. package/README.md +247 -247
  5. package/esm/adb.d.ts +12 -4
  6. package/esm/adb.d.ts.map +1 -1
  7. package/esm/adb.js +29 -19
  8. package/esm/adb.js.map +1 -1
  9. package/esm/commands/reverse.d.ts +9 -12
  10. package/esm/commands/reverse.d.ts.map +1 -1
  11. package/esm/commands/reverse.js +44 -36
  12. package/esm/commands/reverse.js.map +1 -1
  13. package/esm/commands/subprocess/protocols/none.d.ts +2 -1
  14. package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
  15. package/esm/commands/subprocess/protocols/none.js +10 -9
  16. package/esm/commands/subprocess/protocols/none.js.map +1 -1
  17. package/esm/commands/sync/pull.d.ts.map +1 -1
  18. package/esm/commands/sync/pull.js +6 -3
  19. package/esm/commands/sync/pull.js.map +1 -1
  20. package/esm/commands/sync/stat.d.ts.map +1 -1
  21. package/esm/commands/sync/stat.js +2 -2
  22. package/esm/commands/sync/stat.js.map +1 -1
  23. package/esm/commands/sync/sync.js +1 -1
  24. package/esm/commands/sync/sync.js.map +1 -1
  25. package/esm/socket/dispatcher.d.ts +25 -14
  26. package/esm/socket/dispatcher.d.ts.map +1 -1
  27. package/esm/socket/dispatcher.js +94 -63
  28. package/esm/socket/dispatcher.js.map +1 -1
  29. package/esm/socket/socket.d.ts +18 -4
  30. package/esm/socket/socket.d.ts.map +1 -1
  31. package/esm/socket/socket.js +36 -21
  32. package/esm/socket/socket.js.map +1 -1
  33. package/esm/stream/buffered.d.ts +7 -3
  34. package/esm/stream/buffered.d.ts.map +1 -1
  35. package/esm/stream/buffered.js +69 -49
  36. package/esm/stream/buffered.js.map +1 -1
  37. package/esm/stream/detect.js +1 -0
  38. package/esm/stream/detect.js.map +1 -1
  39. package/esm/stream/detect.polyfill.d.ts +1 -1
  40. package/esm/stream/detect.polyfill.d.ts.map +1 -1
  41. package/esm/stream/detect.polyfill.js +0 -5
  42. package/esm/stream/detect.polyfill.js.map +1 -1
  43. package/esm/stream/transform.d.ts +39 -13
  44. package/esm/stream/transform.d.ts.map +1 -1
  45. package/esm/stream/transform.js +67 -90
  46. package/esm/stream/transform.js.map +1 -1
  47. package/esm/utils/base64.js +5 -5
  48. package/esm/utils/base64.js.map +1 -1
  49. package/package.json +10 -10
  50. package/src/adb.ts +280 -270
  51. package/src/auth.ts +173 -173
  52. package/src/backend.ts +11 -11
  53. package/src/commands/base.ts +11 -11
  54. package/src/commands/framebuffer.ts +73 -73
  55. package/src/commands/index.ts +8 -8
  56. package/src/commands/install.ts +30 -30
  57. package/src/commands/power.ts +54 -54
  58. package/src/commands/reverse.ts +140 -136
  59. package/src/commands/subprocess/index.ts +139 -139
  60. package/src/commands/subprocess/protocols/none.ts +70 -68
  61. package/src/commands/subprocess/protocols/shell.ts +190 -190
  62. package/src/commands/subprocess/protocols/types.ts +59 -59
  63. package/src/commands/subprocess/utils.ts +20 -20
  64. package/src/commands/sync/index.ts +7 -7
  65. package/src/commands/sync/list.ts +86 -86
  66. package/src/commands/sync/pull.ts +46 -43
  67. package/src/commands/sync/push.ts +41 -41
  68. package/src/commands/sync/request.ts +50 -50
  69. package/src/commands/sync/response.ts +64 -64
  70. package/src/commands/sync/stat.ts +151 -150
  71. package/src/commands/sync/sync.ts +181 -181
  72. package/src/commands/tcpip.ts +21 -21
  73. package/src/crypto.ts +296 -296
  74. package/src/features.ts +9 -9
  75. package/src/index.ts +11 -11
  76. package/src/packet.ts +80 -80
  77. package/src/socket/dispatcher.ts +305 -270
  78. package/src/socket/index.ts +2 -2
  79. package/src/socket/socket.ts +155 -136
  80. package/src/stream/buffered.ts +168 -147
  81. package/src/stream/detect.native.ts +362 -362
  82. package/src/stream/detect.polyfill.ts +22 -28
  83. package/src/stream/detect.ts +7 -5
  84. package/src/stream/index.ts +3 -3
  85. package/src/stream/transform.ts +474 -483
  86. package/src/utils/auto-reset-event.ts +41 -41
  87. package/src/utils/base64.ts +306 -306
  88. package/src/utils/index.ts +3 -3
  89. package/tsconfig.build.json +3 -3
  90. package/tsconfig.build.tsbuildinfo +1 -1
  91. package/tsconfig.test.json +9 -10
  92. package/web-streams-polyfill-4.0.0-beta.2.tgz +0 -0
  93. package/esm/commands/subprocess/legacy.d.ts +0 -35
  94. package/esm/commands/subprocess/legacy.d.ts.map +0 -1
  95. package/esm/commands/subprocess/legacy.js +0 -53
  96. package/esm/commands/subprocess/legacy.js.map +0 -1
  97. package/esm/commands/subprocess/protocol.d.ts +0 -39
  98. package/esm/commands/subprocess/protocol.d.ts.map +0 -1
  99. package/esm/commands/subprocess/protocol.js +0 -157
  100. package/esm/commands/subprocess/protocol.js.map +0 -1
  101. package/esm/commands/subprocess/types.d.ts +0 -50
  102. package/esm/commands/subprocess/types.d.ts.map +0 -1
  103. package/esm/commands/subprocess/types.js +0 -2
  104. package/esm/commands/subprocess/types.js.map +0 -1
  105. package/esm/socket/controller.d.ts +0 -37
  106. package/esm/socket/controller.d.ts.map +0 -1
  107. package/esm/socket/controller.js +0 -66
  108. package/esm/socket/controller.js.map +0 -1
  109. package/esm/stream/detect.bak.d.ts +0 -240
  110. package/esm/stream/detect.bak.d.ts.map +0 -1
  111. package/esm/stream/detect.bak.js +0 -60
  112. package/esm/stream/detect.bak.js.map +0 -1
  113. package/esm/utils/encoding.d.ts +0 -3
  114. package/esm/utils/encoding.d.ts.map +0 -1
  115. package/esm/utils/encoding.js +0 -11
  116. package/esm/utils/encoding.js.map +0 -1
@@ -1,139 +1,139 @@
1
- import type { Adb } from '../../adb.js';
2
- import { DecodeUtf8Stream, GatherStringStream } from "../../stream/index.js";
3
- import { AdbSubprocessNoneProtocol, AdbSubprocessShellProtocol, type AdbSubprocessProtocol, type AdbSubprocessProtocolConstructor } from './protocols/index.js';
4
-
5
- export * from './protocols/index.js';
6
- export * from './utils.js';
7
-
8
- export interface AdbSubprocessOptions {
9
- /**
10
- * A list of `AdbSubprocessProtocolConstructor`s to be used.
11
- *
12
- * Different `AdbSubprocessProtocol` has different capabilities, thus requires specific adaptations.
13
- * Check their documentations for details.
14
- *
15
- * The first protocol whose `isSupported` returns `true` will be used.
16
- * If no `AdbSubprocessProtocol` is supported, an error will be thrown.
17
- *
18
- * @default [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol]
19
- */
20
- protocols: AdbSubprocessProtocolConstructor[];
21
- }
22
-
23
- const DEFAULT_OPTIONS: AdbSubprocessOptions = {
24
- protocols: [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol],
25
- };
26
-
27
- export interface AdbSubprocessWaitResult {
28
- stdout: string;
29
- stderr: string;
30
- exitCode: number;
31
- }
32
-
33
- export class AdbSubprocess {
34
- public readonly adb: Adb;
35
-
36
- public constructor(adb: Adb) {
37
- this.adb = adb;
38
- }
39
-
40
- private async createProtocol(
41
- mode: 'pty' | 'raw',
42
- command?: string | string[],
43
- options?: Partial<AdbSubprocessOptions>
44
- ): Promise<AdbSubprocessProtocol> {
45
- const { protocols } = { ...DEFAULT_OPTIONS, ...options };
46
-
47
- let Constructor: AdbSubprocessProtocolConstructor | undefined;
48
- for (const item of protocols) {
49
- // It's async so can't use `Array#find`
50
- if (await item.isSupported(this.adb)) {
51
- Constructor = item;
52
- break;
53
- }
54
- }
55
-
56
- if (!Constructor) {
57
- throw new Error('No specified protocol is supported by the device');
58
- }
59
-
60
- if (Array.isArray(command)) {
61
- command = command.join(' ');
62
- } else if (command === undefined) {
63
- // spawn the default shell
64
- command = '';
65
- }
66
- return await Constructor[mode](this.adb, command);
67
- }
68
-
69
- /**
70
- * Spawns an executable in PTY (interactive) mode.
71
- * @param command The command to run. If omitted, the default shell will be spawned.
72
- * @param options The options for creating the `AdbSubprocessProtocol`
73
- * @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
74
- */
75
- public shell(
76
- command?: string | string[],
77
- options?: Partial<AdbSubprocessOptions>
78
- ): Promise<AdbSubprocessProtocol> {
79
- return this.createProtocol('pty', command, options);
80
- }
81
-
82
- /**
83
- * Spawns an executable and pipe the output.
84
- * @param command The command to run, or an array of strings containing both command and args.
85
- * @param options The options for creating the `AdbSubprocessProtocol`
86
- * @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
87
- */
88
- public spawn(
89
- command: string | string[],
90
- options?: Partial<AdbSubprocessOptions>
91
- ): Promise<AdbSubprocessProtocol> {
92
- return this.createProtocol('raw', command, options);
93
- }
94
-
95
- /**
96
- * Spawns a new process, waits until it exits, and returns the entire output.
97
- * @param command The command to run
98
- * @param options The options for creating the `AdbSubprocessProtocol`
99
- * @returns The entire output of the command
100
- */
101
- public async spawnAndWait(
102
- command: string | string[],
103
- options?: Partial<AdbSubprocessOptions>
104
- ): Promise<AdbSubprocessWaitResult> {
105
- const shell = await this.spawn(command, options);
106
-
107
- const stdout = new GatherStringStream();
108
- const stderr = new GatherStringStream();
109
-
110
- const [, , exitCode] = await Promise.all([
111
- shell.stdout
112
- .pipeThrough(new DecodeUtf8Stream())
113
- .pipeTo(stdout),
114
- shell.stderr
115
- .pipeThrough(new DecodeUtf8Stream())
116
- .pipeTo(stderr),
117
- shell.exit
118
- ]);
119
-
120
- return {
121
- stdout: stdout.result,
122
- stderr: stderr.result,
123
- exitCode,
124
- };
125
- }
126
-
127
- /**
128
- * Spawns a new process, waits until it exits, and returns the entire output.
129
- * @param command The command to run
130
- * @returns The entire output of the command
131
- */
132
- public async spawnAndWaitLegacy(command: string | string[]): Promise<string> {
133
- const { stdout } = await this.spawnAndWait(
134
- command,
135
- { protocols: [AdbSubprocessNoneProtocol] }
136
- );
137
- return stdout;
138
- }
139
- }
1
+ import type { Adb } from '../../adb.js';
2
+ import { DecodeUtf8Stream, GatherStringStream } from "../../stream/index.js";
3
+ import { AdbSubprocessNoneProtocol, AdbSubprocessShellProtocol, type AdbSubprocessProtocol, type AdbSubprocessProtocolConstructor } from './protocols/index.js';
4
+
5
+ export * from './protocols/index.js';
6
+ export * from './utils.js';
7
+
8
+ export interface AdbSubprocessOptions {
9
+ /**
10
+ * A list of `AdbSubprocessProtocolConstructor`s to be used.
11
+ *
12
+ * Different `AdbSubprocessProtocol` has different capabilities, thus requires specific adaptations.
13
+ * Check their documentations for details.
14
+ *
15
+ * The first protocol whose `isSupported` returns `true` will be used.
16
+ * If no `AdbSubprocessProtocol` is supported, an error will be thrown.
17
+ *
18
+ * @default [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol]
19
+ */
20
+ protocols: AdbSubprocessProtocolConstructor[];
21
+ }
22
+
23
+ const DEFAULT_OPTIONS: AdbSubprocessOptions = {
24
+ protocols: [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol],
25
+ };
26
+
27
+ export interface AdbSubprocessWaitResult {
28
+ stdout: string;
29
+ stderr: string;
30
+ exitCode: number;
31
+ }
32
+
33
+ export class AdbSubprocess {
34
+ public readonly adb: Adb;
35
+
36
+ public constructor(adb: Adb) {
37
+ this.adb = adb;
38
+ }
39
+
40
+ private async createProtocol(
41
+ mode: 'pty' | 'raw',
42
+ command?: string | string[],
43
+ options?: Partial<AdbSubprocessOptions>
44
+ ): Promise<AdbSubprocessProtocol> {
45
+ const { protocols } = { ...DEFAULT_OPTIONS, ...options };
46
+
47
+ let Constructor: AdbSubprocessProtocolConstructor | undefined;
48
+ for (const item of protocols) {
49
+ // It's async so can't use `Array#find`
50
+ if (await item.isSupported(this.adb)) {
51
+ Constructor = item;
52
+ break;
53
+ }
54
+ }
55
+
56
+ if (!Constructor) {
57
+ throw new Error('No specified protocol is supported by the device');
58
+ }
59
+
60
+ if (Array.isArray(command)) {
61
+ command = command.join(' ');
62
+ } else if (command === undefined) {
63
+ // spawn the default shell
64
+ command = '';
65
+ }
66
+ return await Constructor[mode](this.adb, command);
67
+ }
68
+
69
+ /**
70
+ * Spawns an executable in PTY (interactive) mode.
71
+ * @param command The command to run. If omitted, the default shell will be spawned.
72
+ * @param options The options for creating the `AdbSubprocessProtocol`
73
+ * @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
74
+ */
75
+ public shell(
76
+ command?: string | string[],
77
+ options?: Partial<AdbSubprocessOptions>
78
+ ): Promise<AdbSubprocessProtocol> {
79
+ return this.createProtocol('pty', command, options);
80
+ }
81
+
82
+ /**
83
+ * Spawns an executable and pipe the output.
84
+ * @param command The command to run, or an array of strings containing both command and args.
85
+ * @param options The options for creating the `AdbSubprocessProtocol`
86
+ * @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
87
+ */
88
+ public spawn(
89
+ command: string | string[],
90
+ options?: Partial<AdbSubprocessOptions>
91
+ ): Promise<AdbSubprocessProtocol> {
92
+ return this.createProtocol('raw', command, options);
93
+ }
94
+
95
+ /**
96
+ * Spawns a new process, waits until it exits, and returns the entire output.
97
+ * @param command The command to run
98
+ * @param options The options for creating the `AdbSubprocessProtocol`
99
+ * @returns The entire output of the command
100
+ */
101
+ public async spawnAndWait(
102
+ command: string | string[],
103
+ options?: Partial<AdbSubprocessOptions>
104
+ ): Promise<AdbSubprocessWaitResult> {
105
+ const shell = await this.spawn(command, options);
106
+
107
+ const stdout = new GatherStringStream();
108
+ const stderr = new GatherStringStream();
109
+
110
+ const [, , exitCode] = await Promise.all([
111
+ shell.stdout
112
+ .pipeThrough(new DecodeUtf8Stream())
113
+ .pipeTo(stdout),
114
+ shell.stderr
115
+ .pipeThrough(new DecodeUtf8Stream())
116
+ .pipeTo(stderr),
117
+ shell.exit
118
+ ]);
119
+
120
+ return {
121
+ stdout: stdout.result,
122
+ stderr: stderr.result,
123
+ exitCode,
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Spawns a new process, waits until it exits, and returns the entire output.
129
+ * @param command The command to run
130
+ * @returns The entire output of the command
131
+ */
132
+ public async spawnAndWaitLegacy(command: string | string[]): Promise<string> {
133
+ const { stdout } = await this.spawnAndWait(
134
+ command,
135
+ { protocols: [AdbSubprocessNoneProtocol] }
136
+ );
137
+ return stdout;
138
+ }
139
+ }
@@ -1,68 +1,70 @@
1
- import type { Adb } from "../../../adb.js";
2
- import type { AdbSocket } from "../../../socket/index.js";
3
- import { DuplexStreamFactory, type ReadableStream } from "../../../stream/index.js";
4
- import type { AdbSubprocessProtocol } from "./types.js";
5
-
6
- /**
7
- * The legacy shell
8
- *
9
- * Features:
10
- * * `stderr`: No
11
- * * `exit` exit code: No
12
- * * `resize`: No
13
- */
14
- export class AdbSubprocessNoneProtocol implements AdbSubprocessProtocol {
15
- public static isSupported() { return true; }
16
-
17
- public static async pty(adb: Adb, command: string) {
18
- return new AdbSubprocessNoneProtocol(await adb.createSocket(`shell:${command}`));
19
- }
20
-
21
- public static async raw(adb: Adb, command: string) {
22
- // Native ADB client doesn't allow none protocol + raw mode,
23
- // But ADB daemon supports it.
24
- return new AdbSubprocessNoneProtocol(await adb.createSocket(`shell,raw:${command}`));
25
- }
26
-
27
- private readonly socket: AdbSocket;
28
-
29
- // Legacy shell forwards all data to stdin.
30
- public get stdin() { return this.socket.writable; }
31
-
32
- private _stdout: ReadableStream<Uint8Array>;
33
- /**
34
- * Legacy shell mixes stdout and stderr.
35
- */
36
- public get stdout() { return this._stdout; }
37
-
38
- private _stderr: ReadableStream<Uint8Array>;
39
- /**
40
- * `stderr` will always be empty.
41
- */
42
- public get stderr() { return this._stderr; }
43
-
44
- private _exit: Promise<number>;
45
- public get exit() { return this._exit; }
46
-
47
- public constructor(socket: AdbSocket) {
48
- this.socket = socket;
49
-
50
- const factory = new DuplexStreamFactory<Uint8Array, Uint8Array>({
51
- close: async () => {
52
- await this.socket.close();
53
- },
54
- });
55
-
56
- this._stdout = factory.createWrapReadable(this.socket.readable);
57
- this._stderr = factory.createReadable();
58
- this._exit = factory.closed.then(() => 0);
59
- }
60
-
61
- public resize() {
62
- // Not supported
63
- }
64
-
65
- public kill() {
66
- return this.socket.close();
67
- }
68
- }
1
+ import type { Adb } from "../../../adb.js";
2
+ import type { AdbSocket } from "../../../socket/index.js";
3
+ import { DuplexStreamFactory, ReadableStream } from "../../../stream/index.js";
4
+ import type { AdbSubprocessProtocol } from "./types.js";
5
+
6
+ /**
7
+ * The legacy shell
8
+ *
9
+ * Features:
10
+ * * `stderr`: No
11
+ * * `exit` exit code: No
12
+ * * `resize`: No
13
+ */
14
+ export class AdbSubprocessNoneProtocol implements AdbSubprocessProtocol {
15
+ public static isSupported() { return true; }
16
+
17
+ public static async pty(adb: Adb, command: string) {
18
+ return new AdbSubprocessNoneProtocol(await adb.createSocket(`shell:${command}`));
19
+ }
20
+
21
+ public static async raw(adb: Adb, command: string) {
22
+ // `shell,raw:${command}` also triggers raw mode,
23
+ // But is not supported before Android 7.
24
+ return new AdbSubprocessNoneProtocol(await adb.createSocket(`exec:${command}`));
25
+ }
26
+
27
+ private readonly socket: AdbSocket;
28
+
29
+ private readonly duplex: DuplexStreamFactory<Uint8Array, Uint8Array>;
30
+
31
+ // Legacy shell forwards all data to stdin.
32
+ public get stdin() { return this.socket.writable; }
33
+
34
+ private _stdout: ReadableStream<Uint8Array>;
35
+ /**
36
+ * Legacy shell mixes stdout and stderr.
37
+ */
38
+ public get stdout() { return this._stdout; }
39
+
40
+ private _stderr: ReadableStream<Uint8Array>;
41
+ /**
42
+ * `stderr` will always be empty.
43
+ */
44
+ public get stderr() { return this._stderr; }
45
+
46
+ private _exit: Promise<number>;
47
+ public get exit() { return this._exit; }
48
+
49
+ public constructor(socket: AdbSocket) {
50
+ this.socket = socket;
51
+
52
+ this.duplex = new DuplexStreamFactory<Uint8Array, Uint8Array>({
53
+ close: async () => {
54
+ await this.socket.close();
55
+ },
56
+ });
57
+
58
+ this._stdout = this.duplex.wrapReadable(this.socket.readable);
59
+ this._stderr = this.duplex.wrapReadable(new ReadableStream());
60
+ this._exit = this.duplex.closed.then(() => 0);
61
+ }
62
+
63
+ public resize() {
64
+ // Not supported
65
+ }
66
+
67
+ public kill() {
68
+ return this.duplex.close();
69
+ }
70
+ }