@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,190 +1,190 @@
1
- import { PromiseResolver } from "@yume-chan/async";
2
- import Struct, { placeholder, type StructValueType } from "@yume-chan/struct";
3
- import type { Adb } from "../../../adb.js";
4
- import { AdbFeatures } from "../../../features.js";
5
- import type { AdbSocket } from "../../../socket/index.js";
6
- import { pipeFrom, PushReadableStream, ReadableStream, StructDeserializeStream, StructSerializeStream, TransformStream, WritableStream, WritableStreamDefaultWriter, type PushReadableStreamController } from "../../../stream/index.js";
7
- import { encodeUtf8 } from "../../../utils/index.js";
8
- import type { AdbSubprocessProtocol } from "./types.js";
9
-
10
- export enum AdbShellProtocolId {
11
- Stdin,
12
- Stdout,
13
- Stderr,
14
- Exit,
15
- CloseStdin,
16
- WindowSizeChange,
17
- }
18
-
19
- // This packet format is used in both direction.
20
- const AdbShellProtocolPacket =
21
- new Struct({ littleEndian: true })
22
- .uint8('id', placeholder<AdbShellProtocolId>())
23
- .uint32('length')
24
- .uint8Array('data', { lengthField: 'length' });
25
-
26
- type AdbShellProtocolPacketInit = typeof AdbShellProtocolPacket['TInit'];
27
-
28
- type AdbShellProtocolPacket = StructValueType<typeof AdbShellProtocolPacket>;
29
-
30
- class StdinSerializeStream extends TransformStream<Uint8Array, AdbShellProtocolPacketInit>{
31
- constructor() {
32
- super({
33
- transform(chunk, controller) {
34
- controller.enqueue({
35
- id: AdbShellProtocolId.Stdin,
36
- data: chunk,
37
- });
38
- },
39
- flush() {
40
- // TODO: AdbShellSubprocessProtocol: support closing stdin
41
- }
42
- });
43
- }
44
- }
45
-
46
- class StdoutDeserializeStream extends TransformStream<AdbShellProtocolPacket, Uint8Array>{
47
- constructor(type: AdbShellProtocolId.Stdout | AdbShellProtocolId.Stderr) {
48
- super({
49
- transform(chunk, controller) {
50
- if (chunk.id === type) {
51
- controller.enqueue(chunk.data);
52
- }
53
- },
54
- });
55
- }
56
- }
57
-
58
- class MultiplexStream<T>{
59
- private _readable: PushReadableStream<T>;
60
- private _readableController!: PushReadableStreamController<T>;
61
- public get readable() { return this._readable; }
62
-
63
- private _activeCount = 0;
64
-
65
- constructor() {
66
- this._readable = new PushReadableStream(controller => {
67
- this._readableController = controller;
68
- });
69
- }
70
-
71
- public createWriteable() {
72
- return new WritableStream<T>({
73
- start: () => {
74
- this._activeCount += 1;
75
- },
76
- write: async (chunk) => {
77
- await this._readableController.enqueue(chunk);
78
- },
79
- abort: async (e) => {
80
- this._activeCount -= 1;
81
- if (this._activeCount === 0) {
82
- this._readableController.close();
83
- }
84
- },
85
- close: async () => {
86
- this._activeCount -= 1;
87
- if (this._activeCount === 0) {
88
- this._readableController.close();
89
- }
90
- },
91
- });
92
- }
93
- }
94
-
95
- /**
96
- * Shell v2 a.k.a Shell Protocol
97
- *
98
- * Features:
99
- * * `stderr`: Yes
100
- * * `exit` exit code: Yes
101
- * * `resize`: Yes
102
- */
103
- export class AdbSubprocessShellProtocol implements AdbSubprocessProtocol {
104
- public static isSupported(adb: Adb) {
105
- return adb.features!.includes(AdbFeatures.ShellV2);
106
- }
107
-
108
- public static async pty(adb: Adb, command: string) {
109
- // TODO: AdbShellSubprocessProtocol: Support setting `XTERM` environment variable
110
- return new AdbSubprocessShellProtocol(await adb.createSocket(`shell,v2,pty:${command}`));
111
- }
112
-
113
- public static async raw(adb: Adb, command: string) {
114
- return new AdbSubprocessShellProtocol(await adb.createSocket(`shell,v2,raw:${command}`));
115
- }
116
-
117
- private readonly _socket: AdbSocket;
118
- private _socketWriter: WritableStreamDefaultWriter<AdbShellProtocolPacketInit>;
119
-
120
- private _stdin: WritableStream<Uint8Array>;
121
- public get stdin() { return this._stdin; }
122
-
123
- private _stdout: ReadableStream<Uint8Array>;
124
- public get stdout() { return this._stdout; }
125
-
126
- private _stderr: ReadableStream<Uint8Array>;
127
- public get stderr() { return this._stderr; }
128
-
129
- private readonly _exit = new PromiseResolver<number>();
130
- public get exit() { return this._exit.promise; }
131
-
132
- public constructor(socket: AdbSocket) {
133
- this._socket = socket;
134
-
135
- // Check this image to help you understand the stream graph
136
- // cspell: disable-next-line
137
- // https://www.plantuml.com/plantuml/png/bL91QiCm4Bpx5SAdv90lb1JISmiw5XzaQKf5PIkiLZIqzEyLSg8ks13gYtOykpFhiOw93N6UGjVDqK7rZsxKqNw0U_NTgVAy4empOy2mm4_olC0VEVEE47GUpnGjKdgXoD76q4GIEpyFhOwP_m28hW0NNzxNUig1_JdW0bA7muFIJDco1daJ_1SAX9bgvoPJPyIkSekhNYctvIGXrCH6tIsPL5fs-s6J5yc9BpWXhKtNdF2LgVYPGM_6GlMwfhWUsIt4lbScANrwlgVVUifPSVi__t44qStnwPvZwobdSmHHlL57p2vFuHS0
138
-
139
- // TODO: AdbShellSubprocessProtocol: Optimize stream graph
140
-
141
- const [stdout, stderr] = socket.readable
142
- .pipeThrough(new StructDeserializeStream(AdbShellProtocolPacket))
143
- .pipeThrough(new TransformStream<AdbShellProtocolPacket, AdbShellProtocolPacket>({
144
- transform: (chunk, controller) => {
145
- if (chunk.id === AdbShellProtocolId.Exit) {
146
- this._exit.resolve(new Uint8Array(chunk.data)[0]!);
147
- // We can let `StdoutDeserializeStream` to process `AdbShellProtocolId.Exit`,
148
- // but since we need this `TransformStream` to capture the exit code anyway,
149
- // terminating child streams here is killing two birds with one stone.
150
- controller.terminate();
151
- return;
152
- }
153
- controller.enqueue(chunk);
154
- }
155
- }))
156
- .tee();
157
- this._stdout = stdout
158
- .pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stdout));
159
- this._stderr = stderr
160
- .pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stderr));
161
-
162
- const multiplexer = new MultiplexStream<AdbShellProtocolPacketInit>();
163
- multiplexer.readable
164
- .pipeThrough(new StructSerializeStream(AdbShellProtocolPacket))
165
- .pipeTo(socket.writable);
166
-
167
- this._stdin = pipeFrom(
168
- multiplexer.createWriteable(),
169
- new StdinSerializeStream()
170
- );
171
-
172
- this._socketWriter = multiplexer.createWriteable().getWriter();
173
- }
174
-
175
- public async resize(rows: number, cols: number) {
176
- await this._socketWriter.write({
177
- id: AdbShellProtocolId.WindowSizeChange,
178
- data: encodeUtf8(
179
- // The "correct" format is `${rows}x${cols},${x_pixels}x${y_pixels}`
180
- // However, according to https://linux.die.net/man/4/tty_ioctl
181
- // `x_pixels` and `y_pixels` are not used, so always passing `0` is fine.
182
- `${rows}x${cols},0x0\0`
183
- ),
184
- });
185
- }
186
-
187
- public kill() {
188
- return this._socket.close();
189
- }
190
- }
1
+ import { PromiseResolver } from "@yume-chan/async";
2
+ import Struct, { placeholder, type StructValueType } from "@yume-chan/struct";
3
+ import type { Adb } from "../../../adb.js";
4
+ import { AdbFeatures } from "../../../features.js";
5
+ import type { AdbSocket } from "../../../socket/index.js";
6
+ import { pipeFrom, PushReadableStream, ReadableStream, StructDeserializeStream, StructSerializeStream, TransformStream, WritableStream, WritableStreamDefaultWriter, type PushReadableStreamController } from "../../../stream/index.js";
7
+ import { encodeUtf8 } from "../../../utils/index.js";
8
+ import type { AdbSubprocessProtocol } from "./types.js";
9
+
10
+ export enum AdbShellProtocolId {
11
+ Stdin,
12
+ Stdout,
13
+ Stderr,
14
+ Exit,
15
+ CloseStdin,
16
+ WindowSizeChange,
17
+ }
18
+
19
+ // This packet format is used in both direction.
20
+ const AdbShellProtocolPacket =
21
+ new Struct({ littleEndian: true })
22
+ .uint8('id', placeholder<AdbShellProtocolId>())
23
+ .uint32('length')
24
+ .uint8Array('data', { lengthField: 'length' });
25
+
26
+ type AdbShellProtocolPacketInit = typeof AdbShellProtocolPacket['TInit'];
27
+
28
+ type AdbShellProtocolPacket = StructValueType<typeof AdbShellProtocolPacket>;
29
+
30
+ class StdinSerializeStream extends TransformStream<Uint8Array, AdbShellProtocolPacketInit>{
31
+ constructor() {
32
+ super({
33
+ transform(chunk, controller) {
34
+ controller.enqueue({
35
+ id: AdbShellProtocolId.Stdin,
36
+ data: chunk,
37
+ });
38
+ },
39
+ flush() {
40
+ // TODO: AdbShellSubprocessProtocol: support closing stdin
41
+ }
42
+ });
43
+ }
44
+ }
45
+
46
+ class StdoutDeserializeStream extends TransformStream<AdbShellProtocolPacket, Uint8Array>{
47
+ constructor(type: AdbShellProtocolId.Stdout | AdbShellProtocolId.Stderr) {
48
+ super({
49
+ transform(chunk, controller) {
50
+ if (chunk.id === type) {
51
+ controller.enqueue(chunk.data);
52
+ }
53
+ },
54
+ });
55
+ }
56
+ }
57
+
58
+ class MultiplexStream<T>{
59
+ private _readable: PushReadableStream<T>;
60
+ private _readableController!: PushReadableStreamController<T>;
61
+ public get readable() { return this._readable; }
62
+
63
+ private _activeCount = 0;
64
+
65
+ constructor() {
66
+ this._readable = new PushReadableStream(controller => {
67
+ this._readableController = controller;
68
+ });
69
+ }
70
+
71
+ public createWriteable() {
72
+ return new WritableStream<T>({
73
+ start: () => {
74
+ this._activeCount += 1;
75
+ },
76
+ write: async (chunk) => {
77
+ await this._readableController.enqueue(chunk);
78
+ },
79
+ abort: async (e) => {
80
+ this._activeCount -= 1;
81
+ if (this._activeCount === 0) {
82
+ this._readableController.close();
83
+ }
84
+ },
85
+ close: async () => {
86
+ this._activeCount -= 1;
87
+ if (this._activeCount === 0) {
88
+ this._readableController.close();
89
+ }
90
+ },
91
+ });
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Shell v2 a.k.a Shell Protocol
97
+ *
98
+ * Features:
99
+ * * `stderr`: Yes
100
+ * * `exit` exit code: Yes
101
+ * * `resize`: Yes
102
+ */
103
+ export class AdbSubprocessShellProtocol implements AdbSubprocessProtocol {
104
+ public static isSupported(adb: Adb) {
105
+ return adb.features!.includes(AdbFeatures.ShellV2);
106
+ }
107
+
108
+ public static async pty(adb: Adb, command: string) {
109
+ // TODO: AdbShellSubprocessProtocol: Support setting `XTERM` environment variable
110
+ return new AdbSubprocessShellProtocol(await adb.createSocket(`shell,v2,pty:${command}`));
111
+ }
112
+
113
+ public static async raw(adb: Adb, command: string) {
114
+ return new AdbSubprocessShellProtocol(await adb.createSocket(`shell,v2,raw:${command}`));
115
+ }
116
+
117
+ private readonly _socket: AdbSocket;
118
+ private _socketWriter: WritableStreamDefaultWriter<AdbShellProtocolPacketInit>;
119
+
120
+ private _stdin: WritableStream<Uint8Array>;
121
+ public get stdin() { return this._stdin; }
122
+
123
+ private _stdout: ReadableStream<Uint8Array>;
124
+ public get stdout() { return this._stdout; }
125
+
126
+ private _stderr: ReadableStream<Uint8Array>;
127
+ public get stderr() { return this._stderr; }
128
+
129
+ private readonly _exit = new PromiseResolver<number>();
130
+ public get exit() { return this._exit.promise; }
131
+
132
+ public constructor(socket: AdbSocket) {
133
+ this._socket = socket;
134
+
135
+ // Check this image to help you understand the stream graph
136
+ // cspell: disable-next-line
137
+ // https://www.plantuml.com/plantuml/png/bL91QiCm4Bpx5SAdv90lb1JISmiw5XzaQKf5PIkiLZIqzEyLSg8ks13gYtOykpFhiOw93N6UGjVDqK7rZsxKqNw0U_NTgVAy4empOy2mm4_olC0VEVEE47GUpnGjKdgXoD76q4GIEpyFhOwP_m28hW0NNzxNUig1_JdW0bA7muFIJDco1daJ_1SAX9bgvoPJPyIkSekhNYctvIGXrCH6tIsPL5fs-s6J5yc9BpWXhKtNdF2LgVYPGM_6GlMwfhWUsIt4lbScANrwlgVVUifPSVi__t44qStnwPvZwobdSmHHlL57p2vFuHS0
138
+
139
+ // TODO: AdbShellSubprocessProtocol: Optimize stream graph
140
+
141
+ const [stdout, stderr] = socket.readable
142
+ .pipeThrough(new StructDeserializeStream(AdbShellProtocolPacket))
143
+ .pipeThrough(new TransformStream<AdbShellProtocolPacket, AdbShellProtocolPacket>({
144
+ transform: (chunk, controller) => {
145
+ if (chunk.id === AdbShellProtocolId.Exit) {
146
+ this._exit.resolve(new Uint8Array(chunk.data)[0]!);
147
+ // We can let `StdoutDeserializeStream` to process `AdbShellProtocolId.Exit`,
148
+ // but since we need this `TransformStream` to capture the exit code anyway,
149
+ // terminating child streams here is killing two birds with one stone.
150
+ controller.terminate();
151
+ return;
152
+ }
153
+ controller.enqueue(chunk);
154
+ }
155
+ }))
156
+ .tee();
157
+ this._stdout = stdout
158
+ .pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stdout));
159
+ this._stderr = stderr
160
+ .pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stderr));
161
+
162
+ const multiplexer = new MultiplexStream<AdbShellProtocolPacketInit>();
163
+ multiplexer.readable
164
+ .pipeThrough(new StructSerializeStream(AdbShellProtocolPacket))
165
+ .pipeTo(socket.writable);
166
+
167
+ this._stdin = pipeFrom(
168
+ multiplexer.createWriteable(),
169
+ new StdinSerializeStream()
170
+ );
171
+
172
+ this._socketWriter = multiplexer.createWriteable().getWriter();
173
+ }
174
+
175
+ public async resize(rows: number, cols: number) {
176
+ await this._socketWriter.write({
177
+ id: AdbShellProtocolId.WindowSizeChange,
178
+ data: encodeUtf8(
179
+ // The "correct" format is `${rows}x${cols},${x_pixels}x${y_pixels}`
180
+ // However, according to https://linux.die.net/man/4/tty_ioctl
181
+ // `x_pixels` and `y_pixels` are not used, so always passing `0` is fine.
182
+ `${rows}x${cols},0x0\0`
183
+ ),
184
+ });
185
+ }
186
+
187
+ public kill() {
188
+ return this._socket.close();
189
+ }
190
+ }
@@ -1,59 +1,59 @@
1
- import type { ValueOrPromise } from "@yume-chan/struct";
2
- import type { Adb } from "../../../adb.js";
3
- import type { AdbSocket } from "../../../socket/index.js";
4
- import type { ReadableStream, WritableStream } from "../../../stream/index.js";
5
-
6
- export interface AdbSubprocessProtocol {
7
- /**
8
- * A WritableStream that writes to the `stdin` pipe.
9
- */
10
- readonly stdin: WritableStream<Uint8Array>;
11
-
12
- /**
13
- * The `stdout` pipe of the process.
14
- */
15
- readonly stdout: ReadableStream<Uint8Array>;
16
-
17
- /**
18
- * The `stderr` pipe of the process.
19
- *
20
- * Note: Some `AdbSubprocessProtocol` doesn't separate `stdout` and `stderr`,
21
- * All output will be sent to `stdout`.
22
- */
23
- readonly stderr: ReadableStream<Uint8Array>;
24
-
25
- /**
26
- * A `Promise` that resolves to the exit code of the process.
27
- *
28
- * Note: Some `AdbSubprocessProtocol` doesn't support exit code,
29
- * They will always resolve it with `0`.
30
- */
31
- readonly exit: Promise<number>;
32
-
33
- /**
34
- * Resizes the current shell.
35
- *
36
- * Some `AdbSubprocessProtocol`s may not support resizing
37
- * and will ignore calls to this method.
38
- */
39
- resize(rows: number, cols: number): ValueOrPromise<void>;
40
-
41
- /**
42
- * Kills the current process.
43
- */
44
- kill(): ValueOrPromise<void>;
45
- }
46
-
47
- export interface AdbSubprocessProtocolConstructor {
48
- /** Returns `true` if the `adb` instance supports this shell */
49
- isSupported(adb: Adb): ValueOrPromise<boolean>;
50
-
51
- /** Spawns an executable in PTY (interactive) mode. */
52
- pty(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
53
-
54
- /** Spawns an executable and pipe the output. */
55
- raw(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
56
-
57
- /** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
58
- new(socket: AdbSocket): AdbSubprocessProtocol;
59
- }
1
+ import type { ValueOrPromise } from "@yume-chan/struct";
2
+ import type { Adb } from "../../../adb.js";
3
+ import type { AdbSocket } from "../../../socket/index.js";
4
+ import type { ReadableStream, WritableStream } from "../../../stream/index.js";
5
+
6
+ export interface AdbSubprocessProtocol {
7
+ /**
8
+ * A WritableStream that writes to the `stdin` pipe.
9
+ */
10
+ readonly stdin: WritableStream<Uint8Array>;
11
+
12
+ /**
13
+ * The `stdout` pipe of the process.
14
+ */
15
+ readonly stdout: ReadableStream<Uint8Array>;
16
+
17
+ /**
18
+ * The `stderr` pipe of the process.
19
+ *
20
+ * Note: Some `AdbSubprocessProtocol` doesn't separate `stdout` and `stderr`,
21
+ * All output will be sent to `stdout`.
22
+ */
23
+ readonly stderr: ReadableStream<Uint8Array>;
24
+
25
+ /**
26
+ * A `Promise` that resolves to the exit code of the process.
27
+ *
28
+ * Note: Some `AdbSubprocessProtocol` doesn't support exit code,
29
+ * They will always resolve it with `0`.
30
+ */
31
+ readonly exit: Promise<number>;
32
+
33
+ /**
34
+ * Resizes the current shell.
35
+ *
36
+ * Some `AdbSubprocessProtocol`s may not support resizing
37
+ * and will ignore calls to this method.
38
+ */
39
+ resize(rows: number, cols: number): ValueOrPromise<void>;
40
+
41
+ /**
42
+ * Kills the current process.
43
+ */
44
+ kill(): ValueOrPromise<void>;
45
+ }
46
+
47
+ export interface AdbSubprocessProtocolConstructor {
48
+ /** Returns `true` if the `adb` instance supports this shell */
49
+ isSupported(adb: Adb): ValueOrPromise<boolean>;
50
+
51
+ /** Spawns an executable in PTY (interactive) mode. */
52
+ pty(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
53
+
54
+ /** Spawns an executable and pipe the output. */
55
+ raw(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
56
+
57
+ /** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
58
+ new(socket: AdbSocket): AdbSubprocessProtocol;
59
+ }
@@ -1,20 +1,20 @@
1
- export function escapeArg(s: string) {
2
- let result = '';
3
- result += `'`;
4
-
5
- let base = 0;
6
- while (true) {
7
- const found = s.indexOf(`'`, base);
8
- if (found === -1) {
9
- result += s.substring(base);
10
- break;
11
- }
12
- result += s.substring(base, found);
13
- // a'b becomes a'\'b
14
- result += String.raw`'\''`;
15
- base = found + 1;
16
- }
17
-
18
- result += `'`;
19
- return result;
20
- }
1
+ export function escapeArg(s: string) {
2
+ let result = '';
3
+ result += `'`;
4
+
5
+ let base = 0;
6
+ while (true) {
7
+ const found = s.indexOf(`'`, base);
8
+ if (found === -1) {
9
+ result += s.substring(base);
10
+ break;
11
+ }
12
+ result += s.substring(base, found);
13
+ // a'b becomes a'\'b
14
+ result += String.raw`'\''`;
15
+ base = found + 1;
16
+ }
17
+
18
+ result += `'`;
19
+ return result;
20
+ }
@@ -1,7 +1,7 @@
1
- export * from './list.js';
2
- export * from './pull.js';
3
- export * from './request.js';
4
- export * from './response.js';
5
- export * from './push.js';
6
- export * from './stat.js';
7
- export * from './sync.js';
1
+ export * from './list.js';
2
+ export * from './pull.js';
3
+ export * from './request.js';
4
+ export * from './response.js';
5
+ export * from './push.js';
6
+ export * from './stat.js';
7
+ export * from './sync.js';