@yume-chan/adb 0.0.24 → 1.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.
Files changed (146) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +4 -1
  3. package/esm/adb.d.ts +13 -7
  4. package/esm/adb.d.ts.map +1 -1
  5. package/esm/adb.js +3 -0
  6. package/esm/adb.js.map +1 -1
  7. package/esm/banner.d.ts +7 -6
  8. package/esm/banner.d.ts.map +1 -1
  9. package/esm/banner.js +6 -7
  10. package/esm/banner.js.map +1 -1
  11. package/esm/commands/framebuffer.d.ts +63 -34
  12. package/esm/commands/framebuffer.d.ts.map +1 -1
  13. package/esm/commands/framebuffer.js +35 -33
  14. package/esm/commands/framebuffer.js.map +1 -1
  15. package/esm/commands/reverse.d.ts +12 -12
  16. package/esm/commands/reverse.d.ts.map +1 -1
  17. package/esm/commands/reverse.js +39 -30
  18. package/esm/commands/reverse.js.map +1 -1
  19. package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
  20. package/esm/commands/subprocess/protocols/none.js +3 -5
  21. package/esm/commands/subprocess/protocols/none.js.map +1 -1
  22. package/esm/commands/subprocess/protocols/shell.d.ts +20 -12
  23. package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
  24. package/esm/commands/subprocess/protocols/shell.js +16 -21
  25. package/esm/commands/subprocess/protocols/shell.js.map +1 -1
  26. package/esm/commands/subprocess/protocols/types.d.ts +6 -6
  27. package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
  28. package/esm/commands/sync/list.d.ts +49 -27
  29. package/esm/commands/sync/list.d.ts.map +1 -1
  30. package/esm/commands/sync/list.js +9 -9
  31. package/esm/commands/sync/list.js.map +1 -1
  32. package/esm/commands/sync/pull.d.ts +7 -6
  33. package/esm/commands/sync/pull.d.ts.map +1 -1
  34. package/esm/commands/sync/pull.js +3 -5
  35. package/esm/commands/sync/pull.js.map +1 -1
  36. package/esm/commands/sync/push.d.ts +22 -16
  37. package/esm/commands/sync/push.d.ts.map +1 -1
  38. package/esm/commands/sync/push.js +12 -16
  39. package/esm/commands/sync/push.js.map +1 -1
  40. package/esm/commands/sync/request.d.ts +19 -17
  41. package/esm/commands/sync/request.d.ts.map +1 -1
  42. package/esm/commands/sync/request.js +14 -18
  43. package/esm/commands/sync/request.js.map +1 -1
  44. package/esm/commands/sync/response.d.ts +18 -18
  45. package/esm/commands/sync/response.d.ts.map +1 -1
  46. package/esm/commands/sync/response.js +20 -19
  47. package/esm/commands/sync/response.js.map +1 -1
  48. package/esm/commands/sync/socket.d.ts +1 -1
  49. package/esm/commands/sync/socket.js +2 -2
  50. package/esm/commands/sync/socket.js.map +1 -1
  51. package/esm/commands/sync/stat.d.ts +75 -51
  52. package/esm/commands/sync/stat.d.ts.map +1 -1
  53. package/esm/commands/sync/stat.js +73 -67
  54. package/esm/commands/sync/stat.js.map +1 -1
  55. package/esm/commands/sync/sync.d.ts +14 -14
  56. package/esm/commands/sync/sync.d.ts.map +1 -1
  57. package/esm/commands/sync/sync.js +4 -7
  58. package/esm/commands/sync/sync.js.map +1 -1
  59. package/esm/commands/tcpip.d.ts +0 -1
  60. package/esm/commands/tcpip.d.ts.map +1 -1
  61. package/esm/commands/tcpip.js +8 -8
  62. package/esm/commands/tcpip.js.map +1 -1
  63. package/esm/daemon/auth.d.ts +8 -7
  64. package/esm/daemon/auth.d.ts.map +1 -1
  65. package/esm/daemon/auth.js +7 -8
  66. package/esm/daemon/auth.js.map +1 -1
  67. package/esm/daemon/crypto.d.ts +1 -1
  68. package/esm/daemon/crypto.d.ts.map +1 -1
  69. package/esm/daemon/crypto.js +1 -0
  70. package/esm/daemon/crypto.js.map +1 -1
  71. package/esm/daemon/device.d.ts +2 -2
  72. package/esm/daemon/device.d.ts.map +1 -1
  73. package/esm/daemon/dispatcher.js +6 -6
  74. package/esm/daemon/dispatcher.js.map +1 -1
  75. package/esm/daemon/packet.d.ts +46 -30
  76. package/esm/daemon/packet.d.ts.map +1 -1
  77. package/esm/daemon/packet.js +24 -21
  78. package/esm/daemon/packet.js.map +1 -1
  79. package/esm/daemon/socket.d.ts +1 -6
  80. package/esm/daemon/socket.d.ts.map +1 -1
  81. package/esm/daemon/socket.js +4 -27
  82. package/esm/daemon/socket.js.map +1 -1
  83. package/esm/daemon/transport.d.ts +14 -14
  84. package/esm/daemon/transport.d.ts.map +1 -1
  85. package/esm/daemon/transport.js +6 -8
  86. package/esm/daemon/transport.js.map +1 -1
  87. package/esm/device-observer.d.ts +10 -0
  88. package/esm/device-observer.d.ts.map +1 -0
  89. package/esm/device-observer.js +2 -0
  90. package/esm/device-observer.js.map +1 -0
  91. package/esm/features.d.ts +12 -11
  92. package/esm/features.d.ts.map +1 -1
  93. package/esm/features.js +11 -12
  94. package/esm/features.js.map +1 -1
  95. package/esm/index.d.ts +1 -0
  96. package/esm/index.d.ts.map +1 -1
  97. package/esm/index.js +1 -0
  98. package/esm/index.js.map +1 -1
  99. package/esm/server/client.d.ts +34 -22
  100. package/esm/server/client.d.ts.map +1 -1
  101. package/esm/server/client.js +151 -136
  102. package/esm/server/client.js.map +1 -1
  103. package/esm/server/transport.d.ts +2 -2
  104. package/esm/server/transport.d.ts.map +1 -1
  105. package/esm/server/transport.js +1 -3
  106. package/esm/server/transport.js.map +1 -1
  107. package/esm/utils/base64.d.ts.map +1 -1
  108. package/esm/utils/base64.js +19 -16
  109. package/esm/utils/base64.js.map +1 -1
  110. package/esm/utils/no-op.d.ts.map +1 -1
  111. package/esm/utils/no-op.js +1 -0
  112. package/esm/utils/no-op.js.map +1 -1
  113. package/package.json +14 -17
  114. package/src/adb.ts +13 -7
  115. package/src/banner.ts +8 -6
  116. package/src/commands/framebuffer.ts +44 -35
  117. package/src/commands/reverse.ts +49 -31
  118. package/src/commands/subprocess/protocols/none.ts +3 -5
  119. package/src/commands/subprocess/protocols/shell.ts +26 -24
  120. package/src/commands/subprocess/protocols/types.ts +6 -6
  121. package/src/commands/sync/list.ts +20 -13
  122. package/src/commands/sync/pull.ts +8 -7
  123. package/src/commands/sync/push.ts +20 -16
  124. package/src/commands/sync/request.ts +18 -19
  125. package/src/commands/sync/response.ts +28 -29
  126. package/src/commands/sync/socket.ts +2 -2
  127. package/src/commands/sync/stat.ts +93 -71
  128. package/src/commands/sync/sync.ts +4 -8
  129. package/src/commands/tcpip.ts +8 -8
  130. package/src/daemon/auth.ts +11 -9
  131. package/src/daemon/crypto.ts +2 -0
  132. package/src/daemon/device.ts +2 -2
  133. package/src/daemon/dispatcher.ts +6 -6
  134. package/src/daemon/packet.ts +37 -25
  135. package/src/daemon/socket.ts +4 -27
  136. package/src/daemon/transport.ts +36 -35
  137. package/src/device-observer.ts +10 -0
  138. package/src/features.ts +13 -11
  139. package/src/index.ts +1 -0
  140. package/src/server/client.ts +185 -160
  141. package/src/server/transport.ts +3 -5
  142. package/src/utils/base64.ts +26 -18
  143. package/src/utils/no-op.ts +1 -0
  144. package/tsconfig.build.json +1 -12
  145. package/tsconfig.build.tsbuildinfo +1 -1
  146. package/CHANGELOG.json +0 -298
@@ -1,4 +1,5 @@
1
- import Struct from "@yume-chan/struct";
1
+ import type { StructValue } from "@yume-chan/struct";
2
+ import { string, struct, u32 } from "@yume-chan/struct";
2
3
 
3
4
  import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js";
4
5
  import { AdbSyncResponseId, adbSyncReadResponses } from "./response.js";
@@ -14,21 +15,27 @@ export interface AdbSyncEntry extends AdbSyncStat {
14
15
  name: string;
15
16
  }
16
17
 
17
- export const AdbSyncEntryResponse = new Struct({ littleEndian: true })
18
- .concat(AdbSyncLstatResponse)
19
- .uint32("nameLength")
20
- .string("name", { lengthField: "nameLength" });
18
+ export const AdbSyncEntryResponse = /* #__PURE__ */ (() =>
19
+ struct(
20
+ {
21
+ ...AdbSyncLstatResponse.fields,
22
+ name: string(u32),
23
+ },
24
+ { littleEndian: true, extra: AdbSyncLstatResponse.extra },
25
+ ))();
21
26
 
22
- export type AdbSyncEntryResponse =
23
- (typeof AdbSyncEntryResponse)["TDeserializeResult"];
27
+ export type AdbSyncEntryResponse = StructValue<typeof AdbSyncEntryResponse>;
24
28
 
25
- export const AdbSyncEntry2Response = new Struct({ littleEndian: true })
26
- .concat(AdbSyncStatResponse)
27
- .uint32("nameLength")
28
- .string("name", { lengthField: "nameLength" });
29
+ export const AdbSyncEntry2Response = /* #__PURE__ */ (() =>
30
+ struct(
31
+ {
32
+ ...AdbSyncStatResponse.fields,
33
+ name: string(u32),
34
+ },
35
+ { littleEndian: true, extra: AdbSyncStatResponse.extra },
36
+ ))();
29
37
 
30
- export type AdbSyncEntry2Response =
31
- (typeof AdbSyncEntry2Response)["TDeserializeResult"];
38
+ export type AdbSyncEntry2Response = StructValue<typeof AdbSyncEntry2Response>;
32
39
 
33
40
  export async function* adbSyncOpenDirV2(
34
41
  socket: AdbSyncSocket,
@@ -1,17 +1,18 @@
1
1
  import type { ReadableStream } from "@yume-chan/stream-extra";
2
2
  import { PushReadableStream } from "@yume-chan/stream-extra";
3
- import Struct from "@yume-chan/struct";
3
+ import type { StructValue } from "@yume-chan/struct";
4
+ import { buffer, struct, u32 } from "@yume-chan/struct";
4
5
 
5
6
  import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js";
6
- import { AdbSyncResponseId, adbSyncReadResponses } from "./response.js";
7
+ import { adbSyncReadResponses, AdbSyncResponseId } from "./response.js";
7
8
  import type { AdbSyncSocket } from "./socket.js";
8
9
 
9
- export const AdbSyncDataResponse = new Struct({ littleEndian: true })
10
- .uint32("dataLength")
11
- .uint8Array("data", { lengthField: "dataLength" });
10
+ export const AdbSyncDataResponse = struct(
11
+ { data: buffer(u32) },
12
+ { littleEndian: true },
13
+ );
12
14
 
13
- export type AdbSyncDataResponse =
14
- (typeof AdbSyncDataResponse)["TDeserializeResult"];
15
+ export type AdbSyncDataResponse = StructValue<typeof AdbSyncDataResponse>;
15
16
 
16
17
  export async function* adbSyncPullGenerator(
17
18
  socket: AdbSyncSocket,
@@ -4,7 +4,7 @@ import {
4
4
  DistributionStream,
5
5
  MaybeConsumable,
6
6
  } from "@yume-chan/stream-extra";
7
- import Struct, { placeholder } from "@yume-chan/struct";
7
+ import { struct, u32 } from "@yume-chan/struct";
8
8
 
9
9
  import { NOOP } from "../../utils/index.js";
10
10
 
@@ -25,8 +25,9 @@ export interface AdbSyncPushV1Options {
25
25
  packetSize?: number;
26
26
  }
27
27
 
28
- export const AdbSyncOkResponse = new Struct({ littleEndian: true }).uint32(
29
- "unused",
28
+ export const AdbSyncOkResponse = struct(
29
+ { unused: u32 },
30
+ { littleEndian: true },
30
31
  );
31
32
 
32
33
  async function pipeFileData(
@@ -41,8 +42,8 @@ async function pipeFileData(
41
42
  file.pipeThrough(new DistributionStream(packetSize, true))
42
43
  .pipeTo(
43
44
  new MaybeConsumable.WritableStream({
44
- write: async (chunk) => {
45
- await adbSyncWriteRequest(
45
+ write(chunk) {
46
+ return adbSyncWriteRequest(
46
47
  locked,
47
48
  AdbSyncRequestId.Data,
48
49
  chunk,
@@ -86,19 +87,22 @@ export async function adbSyncPushV1({
86
87
  }
87
88
  }
88
89
 
89
- export enum AdbSyncSendV2Flags {
90
- None = 0,
91
- Brotli = 1,
90
+ export const AdbSyncSendV2Flags = {
91
+ None: 0,
92
+ Brotli: 1,
92
93
  /**
93
94
  * 2
94
95
  */
95
- Lz4 = 1 << 1,
96
+ Lz4: 1 << 1,
96
97
  /**
97
98
  * 4
98
99
  */
99
- Zstd = 1 << 2,
100
- DryRun = 0x80000000,
101
- }
100
+ Zstd: 1 << 2,
101
+ DryRun: 0x80000000,
102
+ } as const;
103
+
104
+ export type AdbSyncSendV2Flags =
105
+ (typeof AdbSyncSendV2Flags)[keyof typeof AdbSyncSendV2Flags];
102
106
 
103
107
  export interface AdbSyncPushV2Options extends AdbSyncPushV1Options {
104
108
  /**
@@ -110,10 +114,10 @@ export interface AdbSyncPushV2Options extends AdbSyncPushV1Options {
110
114
  dryRun?: boolean;
111
115
  }
112
116
 
113
- export const AdbSyncSendV2Request = new Struct({ littleEndian: true })
114
- .uint32("id")
115
- .uint32("mode")
116
- .uint32("flags", placeholder<AdbSyncSendV2Flags>());
117
+ export const AdbSyncSendV2Request = struct(
118
+ { id: u32, mode: u32, flags: u32<AdbSyncSendV2Flags>() },
119
+ { littleEndian: true },
120
+ );
117
121
 
118
122
  export async function adbSyncPushV2({
119
123
  socket,
@@ -1,25 +1,24 @@
1
- import Struct from "@yume-chan/struct";
2
-
3
- import { encodeUtf8 } from "../../utils/index.js";
1
+ import { encodeUtf8, struct, u32 } from "@yume-chan/struct";
4
2
 
5
3
  import { adbSyncEncodeId } from "./response.js";
6
4
 
7
- export namespace AdbSyncRequestId {
8
- export const List = adbSyncEncodeId("LIST");
9
- export const ListV2 = adbSyncEncodeId("LIS2");
10
- export const Send = adbSyncEncodeId("SEND");
11
- export const SendV2 = adbSyncEncodeId("SND2");
12
- export const Lstat = adbSyncEncodeId("STAT");
13
- export const Stat = adbSyncEncodeId("STA2");
14
- export const LstatV2 = adbSyncEncodeId("LST2");
15
- export const Data = adbSyncEncodeId("DATA");
16
- export const Done = adbSyncEncodeId("DONE");
17
- export const Receive = adbSyncEncodeId("RECV");
18
- }
19
-
20
- export const AdbSyncNumberRequest = new Struct({ littleEndian: true })
21
- .uint32("id")
22
- .uint32("arg");
5
+ export const AdbSyncRequestId = {
6
+ List: adbSyncEncodeId("LIST"),
7
+ ListV2: adbSyncEncodeId("LIS2"),
8
+ Send: adbSyncEncodeId("SEND"),
9
+ SendV2: adbSyncEncodeId("SND2"),
10
+ Lstat: adbSyncEncodeId("STAT"),
11
+ Stat: adbSyncEncodeId("STA2"),
12
+ LstatV2: adbSyncEncodeId("LST2"),
13
+ Data: adbSyncEncodeId("DATA"),
14
+ Done: adbSyncEncodeId("DONE"),
15
+ Receive: adbSyncEncodeId("RECV"),
16
+ } as const;
17
+
18
+ export const AdbSyncNumberRequest = struct(
19
+ { id: u32, arg: u32 },
20
+ { littleEndian: true },
21
+ );
23
22
 
24
23
  export interface AdbSyncWritable {
25
24
  write(buffer: Uint8Array): Promise<void>;
@@ -1,10 +1,6 @@
1
1
  import { getUint32LittleEndian } from "@yume-chan/no-data-view";
2
- import type {
3
- AsyncExactReadable,
4
- StructLike,
5
- StructValueType,
6
- } from "@yume-chan/struct";
7
- import Struct, { decodeUtf8 } from "@yume-chan/struct";
2
+ import type { AsyncExactReadable, StructLike } from "@yume-chan/struct";
3
+ import { decodeUtf8, string, struct, u32 } from "@yume-chan/struct";
8
4
 
9
5
  function encodeAsciiUnchecked(value: string): Uint8Array {
10
6
  const result = new Uint8Array(value.length);
@@ -18,32 +14,37 @@ function encodeAsciiUnchecked(value: string): Uint8Array {
18
14
  * Encode ID to numbers for faster comparison
19
15
  * @param value A 4-character string
20
16
  * @returns A 32-bit integer by encoding the string as little-endian
17
+ *
18
+ * #__NO_SIDE_EFFECTS__
21
19
  */
22
20
  export function adbSyncEncodeId(value: string): number {
23
21
  const buffer = encodeAsciiUnchecked(value);
24
22
  return getUint32LittleEndian(buffer, 0);
25
23
  }
26
24
 
27
- export namespace AdbSyncResponseId {
28
- export const Entry = adbSyncEncodeId("DENT");
29
- export const Entry2 = adbSyncEncodeId("DNT2");
30
- export const Lstat = adbSyncEncodeId("STAT");
31
- export const Stat = adbSyncEncodeId("STA2");
32
- export const Lstat2 = adbSyncEncodeId("LST2");
33
- export const Done = adbSyncEncodeId("DONE");
34
- export const Data = adbSyncEncodeId("DATA");
35
- export const Ok = adbSyncEncodeId("OKAY");
36
- export const Fail = adbSyncEncodeId("FAIL");
37
- }
25
+ export const AdbSyncResponseId = {
26
+ Entry: adbSyncEncodeId("DENT"),
27
+ Entry2: adbSyncEncodeId("DNT2"),
28
+ Lstat: adbSyncEncodeId("STAT"),
29
+ Stat: adbSyncEncodeId("STA2"),
30
+ Lstat2: adbSyncEncodeId("LST2"),
31
+ Done: adbSyncEncodeId("DONE"),
32
+ Data: adbSyncEncodeId("DATA"),
33
+ Ok: adbSyncEncodeId("OKAY"),
34
+ Fail: adbSyncEncodeId("FAIL"),
35
+ };
38
36
 
39
37
  export class AdbSyncError extends Error {}
40
38
 
41
- export const AdbSyncFailResponse = new Struct({ littleEndian: true })
42
- .uint32("messageLength")
43
- .string("message", { lengthField: "messageLength" })
44
- .postDeserialize((object) => {
45
- throw new AdbSyncError(object.message);
46
- });
39
+ export const AdbSyncFailResponse = struct(
40
+ { message: string(u32) },
41
+ {
42
+ littleEndian: true,
43
+ postDeserialize(value) {
44
+ throw new AdbSyncError(value.message);
45
+ },
46
+ },
47
+ );
47
48
 
48
49
  export async function adbSyncReadResponse<T>(
49
50
  stream: AsyncExactReadable,
@@ -68,13 +69,11 @@ export async function adbSyncReadResponse<T>(
68
69
  }
69
70
  }
70
71
 
71
- export async function* adbSyncReadResponses<
72
- T extends Struct<object, PropertyKey, object, unknown>,
73
- >(
72
+ export async function* adbSyncReadResponses<T>(
74
73
  stream: AsyncExactReadable,
75
74
  id: number | string,
76
- type: T,
77
- ): AsyncGenerator<StructValueType<T>, void, void> {
75
+ type: StructLike<T>,
76
+ ): AsyncGenerator<T, void, void> {
78
77
  if (typeof id === "string") {
79
78
  id = adbSyncEncodeId(id);
80
79
  }
@@ -93,7 +92,7 @@ export async function* adbSyncReadResponses<
93
92
  await stream.readExactly(type.size);
94
93
  return;
95
94
  case id:
96
- yield (await type.deserialize(stream)) as StructValueType<T>;
95
+ yield await type.deserialize(stream);
97
96
  break;
98
97
  default:
99
98
  throw new Error(
@@ -35,9 +35,9 @@ export class AdbSyncSocketLocked implements AsyncExactReadable {
35
35
  this.#combiner = new BufferCombiner(bufferSize);
36
36
  }
37
37
 
38
- async #write(buffer: Uint8Array) {
38
+ #write(buffer: Uint8Array) {
39
39
  // `#combiner` will reuse the buffer, so we need to use the Consumable pattern
40
- await Consumable.WritableStream.write(this.#writer, buffer);
40
+ return Consumable.WritableStream.write(this.#writer, buffer);
41
41
  }
42
42
 
43
43
  async flush() {
@@ -1,15 +1,18 @@
1
- import Struct, { placeholder } from "@yume-chan/struct";
1
+ import type { StructValue } from "@yume-chan/struct";
2
+ import { struct, u32, u64 } from "@yume-chan/struct";
2
3
 
3
4
  import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js";
4
5
  import { AdbSyncResponseId, adbSyncReadResponse } from "./response.js";
5
6
  import type { AdbSyncSocket } from "./socket.js";
6
7
 
7
8
  // https://github.com/python/cpython/blob/4e581d64b8aff3e2eda99b12f080c877bb78dfca/Lib/stat.py#L36
8
- export enum LinuxFileType {
9
- Directory = 0o04,
10
- File = 0o10,
11
- Link = 0o12,
12
- }
9
+ export const LinuxFileType = {
10
+ Directory: 0o04,
11
+ File: 0o10,
12
+ Link: 0o12,
13
+ } as const;
14
+
15
+ export type LinuxFileType = (typeof LinuxFileType)[keyof typeof LinuxFileType];
13
16
 
14
17
  export interface AdbSyncStat {
15
18
  mode: number;
@@ -24,79 +27,98 @@ export interface AdbSyncStat {
24
27
  ctime?: bigint;
25
28
  }
26
29
 
27
- export const AdbSyncLstatResponse = new Struct({ littleEndian: true })
28
- .int32("mode")
29
- .int32("size")
30
- .int32("mtime")
31
- .extra({
32
- get type() {
33
- return (this.mode >> 12) as LinuxFileType;
30
+ export const AdbSyncLstatResponse = struct(
31
+ { mode: u32, size: u32, mtime: u32 },
32
+ {
33
+ littleEndian: true,
34
+ extra: {
35
+ get type(): LinuxFileType {
36
+ return (this.mode >> 12) as LinuxFileType;
37
+ },
38
+ get permission(): number {
39
+ return this.mode & 0b00001111_11111111;
40
+ },
34
41
  },
35
- get permission() {
36
- return this.mode & 0b00001111_11111111;
42
+ postDeserialize(value) {
43
+ if (value.mode === 0 && value.size === 0 && value.mtime === 0) {
44
+ throw new Error("lstat error");
45
+ }
46
+ return value;
37
47
  },
38
- })
39
- .postDeserialize((object) => {
40
- if (object.mode === 0 && object.size === 0 && object.mtime === 0) {
41
- throw new Error("lstat error");
42
- }
43
- });
48
+ },
49
+ );
44
50
 
45
- export type AdbSyncLstatResponse =
46
- (typeof AdbSyncLstatResponse)["TDeserializeResult"];
51
+ export type AdbSyncLstatResponse = StructValue<typeof AdbSyncLstatResponse>;
47
52
 
48
- export enum AdbSyncStatErrorCode {
49
- SUCCESS = 0,
50
- EACCES = 13,
51
- EEXIST = 17,
52
- EFAULT = 14,
53
- EFBIG = 27,
54
- EINTR = 4,
55
- EINVAL = 22,
56
- EIO = 5,
57
- EISDIR = 21,
58
- ELOOP = 40,
59
- EMFILE = 24,
60
- ENAMETOOLONG = 36,
61
- ENFILE = 23,
62
- ENOENT = 2,
63
- ENOMEM = 12,
64
- ENOSPC = 28,
65
- ENOTDIR = 20,
66
- EOVERFLOW = 75,
67
- EPERM = 1,
68
- EROFS = 30,
69
- ETXTBSY = 26,
70
- }
53
+ export const AdbSyncStatErrorCode = {
54
+ SUCCESS: 0,
55
+ EACCES: 13,
56
+ EEXIST: 17,
57
+ EFAULT: 14,
58
+ EFBIG: 27,
59
+ EINTR: 4,
60
+ EINVAL: 22,
61
+ EIO: 5,
62
+ EISDIR: 21,
63
+ ELOOP: 40,
64
+ EMFILE: 24,
65
+ ENAMETOOLONG: 36,
66
+ ENFILE: 23,
67
+ ENOENT: 2,
68
+ ENOMEM: 12,
69
+ ENOSPC: 28,
70
+ ENOTDIR: 20,
71
+ EOVERFLOW: 75,
72
+ EPERM: 1,
73
+ EROFS: 30,
74
+ ETXTBSY: 26,
75
+ } as const;
71
76
 
72
- export const AdbSyncStatResponse = new Struct({ littleEndian: true })
73
- .uint32("error", placeholder<AdbSyncStatErrorCode>())
74
- .uint64("dev")
75
- .uint64("ino")
76
- .uint32("mode")
77
- .uint32("nlink")
78
- .uint32("uid")
79
- .uint32("gid")
80
- .uint64("size")
81
- .uint64("atime")
82
- .uint64("mtime")
83
- .uint64("ctime")
84
- .extra({
85
- get type() {
86
- return (this.mode >> 12) as LinuxFileType;
77
+ export type AdbSyncStatErrorCode =
78
+ (typeof AdbSyncStatErrorCode)[keyof typeof AdbSyncStatErrorCode];
79
+
80
+ const AdbSyncStatErrorName = /* #__PURE__ */ (() =>
81
+ Object.fromEntries(
82
+ Object.entries(AdbSyncStatErrorCode).map(([key, value]) => [
83
+ value,
84
+ key,
85
+ ]),
86
+ ))();
87
+
88
+ export const AdbSyncStatResponse = struct(
89
+ {
90
+ error: u32<AdbSyncStatErrorCode>(),
91
+ dev: u64,
92
+ ino: u64,
93
+ mode: u32,
94
+ nlink: u32,
95
+ uid: u32,
96
+ gid: u32,
97
+ size: u64,
98
+ atime: u64,
99
+ mtime: u64,
100
+ ctime: u64,
101
+ },
102
+ {
103
+ littleEndian: true,
104
+ extra: {
105
+ get type(): LinuxFileType {
106
+ return (this.mode >> 12) as LinuxFileType;
107
+ },
108
+ get permission(): number {
109
+ return this.mode & 0b00001111_11111111;
110
+ },
87
111
  },
88
- get permission() {
89
- return this.mode & 0b00001111_11111111;
112
+ postDeserialize(value) {
113
+ if (value.error) {
114
+ throw new Error(AdbSyncStatErrorName[value.error]);
115
+ }
116
+ return value;
90
117
  },
91
- })
92
- .postDeserialize((object) => {
93
- if (object.error) {
94
- throw new Error(AdbSyncStatErrorCode[object.error]);
95
- }
96
- });
118
+ },
119
+ );
97
120
 
98
- export type AdbSyncStatResponse =
99
- (typeof AdbSyncStatResponse)["TDeserializeResult"];
121
+ export type AdbSyncStatResponse = StructValue<typeof AdbSyncStatResponse>;
100
122
 
101
123
  export async function adbSyncLstat(
102
124
  socket: AdbSyncSocket,
@@ -1,4 +1,3 @@
1
- import { AutoDisposable } from "@yume-chan/event";
2
1
  import type { MaybeConsumable, ReadableStream } from "@yume-chan/stream-extra";
3
2
 
4
3
  import type { Adb, AdbSocket } from "../../adb.js";
@@ -39,7 +38,7 @@ export interface AdbSyncWriteOptions {
39
38
  dryRun?: boolean;
40
39
  }
41
40
 
42
- export class AdbSync extends AutoDisposable {
41
+ export class AdbSync {
43
42
  protected _adb: Adb;
44
43
  protected _socket: AdbSyncSocket;
45
44
 
@@ -70,8 +69,6 @@ export class AdbSync extends AutoDisposable {
70
69
  }
71
70
 
72
71
  constructor(adb: Adb, socket: AdbSocket) {
73
- super();
74
-
75
72
  this._adb = adb;
76
73
  this._socket = new AdbSyncSocket(socket, adb.maxPayloadSize);
77
74
 
@@ -117,7 +114,7 @@ export class AdbSync extends AutoDisposable {
117
114
  try {
118
115
  await this.lstat(path + "/");
119
116
  return true;
120
- } catch (e) {
117
+ } catch {
121
118
  return false;
122
119
  }
123
120
  }
@@ -172,8 +169,7 @@ export class AdbSync extends AutoDisposable {
172
169
  return this._socket.lock();
173
170
  }
174
171
 
175
- override async dispose() {
176
- super.dispose();
177
- await this._socket.close();
172
+ dispose() {
173
+ return this._socket.close();
178
174
  }
179
175
  }
@@ -20,14 +20,14 @@ export interface AdbTcpIpListenAddresses {
20
20
  persistPort: number | undefined;
21
21
  }
22
22
 
23
- export class AdbTcpIpCommand extends AdbCommandBase {
24
- #parsePort(value: string): number | undefined {
25
- if (!value || value === "0") {
26
- return undefined;
27
- }
28
- return Number.parseInt(value, 10);
23
+ function parsePort(value: string): number | undefined {
24
+ if (!value || value === "0") {
25
+ return undefined;
29
26
  }
27
+ return Number.parseInt(value, 10);
28
+ }
30
29
 
30
+ export class AdbTcpIpCommand extends AdbCommandBase {
31
31
  async getListenAddresses(): Promise<AdbTcpIpListenAddresses> {
32
32
  const serviceListenAddresses = await this.adb.getProp(
33
33
  "service.adb.listen_addrs",
@@ -40,8 +40,8 @@ export class AdbTcpIpCommand extends AdbCommandBase {
40
40
  serviceListenAddresses != ""
41
41
  ? serviceListenAddresses.split(",")
42
42
  : [],
43
- servicePort: this.#parsePort(servicePort),
44
- persistPort: this.#parsePort(persistPort),
43
+ servicePort: parsePort(servicePort),
44
+ persistPort: parsePort(persistPort),
45
45
  };
46
46
  }
47
47
 
@@ -1,7 +1,7 @@
1
+ import type { MaybePromiseLike } from "@yume-chan/async";
1
2
  import { PromiseResolver } from "@yume-chan/async";
2
3
  import type { Disposable } from "@yume-chan/event";
3
- import type { ValueOrPromise } from "@yume-chan/struct";
4
- import { EMPTY_UINT8_ARRAY } from "@yume-chan/struct";
4
+ import { EmptyUint8Array } from "@yume-chan/struct";
5
5
 
6
6
  import {
7
7
  calculateBase64EncodedLength,
@@ -33,7 +33,7 @@ export interface AdbCredentialStore {
33
33
  /**
34
34
  * Generates and stores a RSA private key with modulus length `2048` and public exponent `65537`.
35
35
  */
36
- generateKey(): ValueOrPromise<AdbPrivateKey>;
36
+ generateKey(): MaybePromiseLike<AdbPrivateKey>;
37
37
 
38
38
  /**
39
39
  * Synchronously or asynchronously iterates through all stored RSA private keys.
@@ -43,11 +43,13 @@ export interface AdbCredentialStore {
43
43
  iterateKeys(): AdbKeyIterable;
44
44
  }
45
45
 
46
- export enum AdbAuthType {
47
- Token = 1,
48
- Signature = 2,
49
- PublicKey = 3,
50
- }
46
+ export const AdbAuthType = {
47
+ Token: 1,
48
+ Signature: 2,
49
+ PublicKey: 3,
50
+ } as const;
51
+
52
+ export type AdbAuthType = (typeof AdbAuthType)[keyof typeof AdbAuthType];
51
53
 
52
54
  export interface AdbAuthenticator {
53
55
  /**
@@ -114,7 +116,7 @@ export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function* (
114
116
 
115
117
  const nameBuffer = privateKey.name?.length
116
118
  ? encodeUtf8(privateKey.name)
117
- : EMPTY_UINT8_ARRAY;
119
+ : EmptyUint8Array;
118
120
  const publicKeyBuffer = new Uint8Array(
119
121
  publicKeyBase64Length +
120
122
  (nameBuffer.length ? nameBuffer.length + 1 : 0) + // Space character + name
@@ -38,6 +38,8 @@ export function getBigUint(
38
38
  * @param littleEndian If `false` or `undefined`, a big-endian value should be written,
39
39
  * otherwise a little-endian value should be written.
40
40
  */
41
+
42
+ // eslint-disable-next-line @typescript-eslint/max-params
41
43
  export function setBigUint(
42
44
  array: Uint8Array,
43
45
  byteOffset: number,
@@ -1,5 +1,5 @@
1
+ import type { MaybePromiseLike } from "@yume-chan/async";
1
2
  import type { Consumable, ReadableWritablePair } from "@yume-chan/stream-extra";
2
- import type { ValueOrPromise } from "@yume-chan/struct";
3
3
 
4
4
  import type { AdbPacketData, AdbPacketInit } from "./packet.js";
5
5
 
@@ -8,7 +8,7 @@ export interface AdbDaemonDevice {
8
8
 
9
9
  readonly name: string | undefined;
10
10
 
11
- connect(): ValueOrPromise<
11
+ connect(): MaybePromiseLike<
12
12
  ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>
13
13
  >;
14
14
  }