@yume-chan/adb 0.0.8 → 0.0.11

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 (407) hide show
  1. package/CHANGELOG.json +49 -0
  2. package/CHANGELOG.md +30 -0
  3. package/LICENSE +21 -21
  4. package/README.md +240 -257
  5. package/esm/adb.d.ts +48 -0
  6. package/esm/adb.d.ts.map +1 -0
  7. package/esm/adb.js +141 -145
  8. package/esm/adb.js.map +1 -1
  9. package/{dts → esm}/auth.d.ts +17 -7
  10. package/esm/auth.d.ts.map +1 -0
  11. package/esm/auth.js +69 -109
  12. package/esm/auth.js.map +1 -1
  13. package/esm/backend.d.ts +9 -0
  14. package/esm/backend.d.ts.map +1 -0
  15. package/{dts → esm}/commands/base.d.ts +1 -1
  16. package/esm/commands/base.d.ts.map +1 -0
  17. package/esm/commands/base.js +1 -0
  18. package/esm/commands/base.js.map +1 -1
  19. package/{dts → esm}/commands/framebuffer.d.ts +3 -3
  20. package/esm/commands/framebuffer.d.ts.map +1 -0
  21. package/esm/commands/framebuffer.js +15 -18
  22. package/esm/commands/framebuffer.js.map +1 -1
  23. package/esm/commands/index.d.ts +9 -0
  24. package/esm/commands/index.d.ts.map +1 -0
  25. package/esm/commands/index.js +8 -8
  26. package/esm/commands/index.js.map +1 -1
  27. package/esm/commands/install.d.ts +4 -0
  28. package/esm/commands/install.d.ts.map +1 -0
  29. package/esm/commands/install.js +21 -13
  30. package/esm/commands/install.js.map +1 -1
  31. package/esm/commands/power.d.ts +23 -0
  32. package/esm/commands/power.d.ts.map +1 -0
  33. package/esm/commands/power.js +45 -0
  34. package/esm/commands/power.js.map +1 -0
  35. package/{dts → esm}/commands/reverse.d.ts +3 -3
  36. package/esm/commands/reverse.d.ts.map +1 -0
  37. package/esm/commands/reverse.js +50 -60
  38. package/esm/commands/reverse.js.map +1 -1
  39. package/esm/commands/subprocess/index.d.ts +57 -0
  40. package/esm/commands/subprocess/index.d.ts.map +1 -0
  41. package/esm/commands/subprocess/index.js +83 -0
  42. package/esm/commands/subprocess/index.js.map +1 -0
  43. package/esm/commands/subprocess/legacy.d.ts +28 -0
  44. package/esm/commands/subprocess/legacy.d.ts.map +1 -0
  45. package/esm/commands/subprocess/legacy.js +44 -0
  46. package/esm/commands/subprocess/legacy.js.map +1 -0
  47. package/esm/commands/subprocess/protocol.d.ts +38 -0
  48. package/esm/commands/subprocess/protocol.d.ts.map +1 -0
  49. package/esm/commands/subprocess/protocol.js +155 -0
  50. package/esm/commands/subprocess/protocol.js.map +1 -0
  51. package/esm/commands/subprocess/types.d.ts +47 -0
  52. package/esm/commands/subprocess/types.d.ts.map +1 -0
  53. package/esm/commands/{shell → subprocess}/types.js +0 -0
  54. package/{cjs/commands/shell → esm/commands/subprocess}/types.js.map +1 -1
  55. package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
  56. package/esm/commands/subprocess/utils.d.ts.map +1 -0
  57. package/esm/commands/{shell → subprocess}/utils.js +0 -0
  58. package/esm/commands/subprocess/utils.js.map +1 -0
  59. package/esm/commands/sync/index.d.ts +8 -0
  60. package/esm/commands/sync/index.d.ts.map +1 -0
  61. package/esm/commands/sync/index.js +7 -7
  62. package/esm/commands/sync/index.js.map +1 -1
  63. package/{dts → esm}/commands/sync/list.d.ts +4 -4
  64. package/esm/commands/sync/list.d.ts.map +1 -0
  65. package/esm/commands/sync/list.js +16 -19
  66. package/esm/commands/sync/list.js.map +1 -1
  67. package/esm/commands/sync/pull.d.ts +11 -0
  68. package/esm/commands/sync/pull.d.ts.map +1 -0
  69. package/esm/commands/sync/pull.js +17 -11
  70. package/esm/commands/sync/pull.js.map +1 -1
  71. package/esm/commands/sync/push.d.ts +8 -0
  72. package/esm/commands/sync/push.d.ts.map +1 -0
  73. package/esm/commands/sync/push.js +19 -37
  74. package/esm/commands/sync/push.js.map +1 -1
  75. package/{dts → esm}/commands/sync/request.d.ts +3 -3
  76. package/esm/commands/sync/request.d.ts.map +1 -0
  77. package/esm/commands/sync/request.js +24 -26
  78. package/esm/commands/sync/request.js.map +1 -1
  79. package/{dts → esm}/commands/sync/response.d.ts +3 -3
  80. package/esm/commands/sync/response.d.ts.map +1 -0
  81. package/esm/commands/sync/response.js +16 -19
  82. package/esm/commands/sync/response.js.map +1 -1
  83. package/{dts → esm}/commands/sync/stat.d.ts +4 -4
  84. package/esm/commands/sync/stat.d.ts.map +1 -0
  85. package/esm/commands/sync/stat.js +22 -27
  86. package/esm/commands/sync/stat.js.map +1 -1
  87. package/esm/commands/sync/sync.d.ts +83 -0
  88. package/esm/commands/sync/sync.d.ts.map +1 -0
  89. package/esm/commands/sync/sync.js +92 -89
  90. package/esm/commands/sync/sync.js.map +1 -1
  91. package/{dts → esm}/commands/tcpip.d.ts +1 -1
  92. package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
  93. package/esm/commands/tcpip.js +14 -19
  94. package/esm/commands/tcpip.js.map +1 -1
  95. package/esm/crypto.d.ts +24 -0
  96. package/esm/crypto.d.ts.map +1 -0
  97. package/esm/crypto.js +33 -31
  98. package/esm/crypto.js.map +1 -1
  99. package/{dts → esm}/features.d.ts +0 -0
  100. package/{dts → esm}/features.d.ts.map +0 -0
  101. package/esm/features.js +1 -1
  102. package/esm/features.js.map +1 -1
  103. package/esm/index.d.ts +11 -0
  104. package/esm/index.d.ts.map +1 -0
  105. package/esm/index.js +10 -10
  106. package/esm/index.js.map +1 -1
  107. package/esm/packet.d.ts +28 -0
  108. package/esm/packet.d.ts.map +1 -0
  109. package/esm/packet.js +26 -53
  110. package/esm/packet.js.map +1 -1
  111. package/esm/socket/controller.d.ts +37 -0
  112. package/esm/socket/controller.d.ts.map +1 -0
  113. package/esm/socket/controller.js +52 -66
  114. package/esm/socket/controller.js.map +1 -1
  115. package/{dts → esm}/socket/dispatcher.d.ts +10 -23
  116. package/esm/socket/dispatcher.d.ts.map +1 -0
  117. package/esm/socket/dispatcher.js +148 -164
  118. package/esm/socket/dispatcher.js.map +1 -1
  119. package/esm/socket/index.d.ts +3 -0
  120. package/esm/socket/index.d.ts.map +1 -0
  121. package/esm/socket/index.js +2 -6
  122. package/esm/socket/index.js.map +1 -1
  123. package/esm/socket/socket.d.ts +34 -0
  124. package/esm/socket/socket.d.ts.map +1 -0
  125. package/esm/socket/socket.js +69 -14
  126. package/esm/socket/socket.js.map +1 -1
  127. package/esm/stream/buffered.d.ts +35 -0
  128. package/esm/stream/buffered.d.ts.map +1 -0
  129. package/esm/stream/buffered.js +123 -0
  130. package/esm/stream/buffered.js.map +1 -0
  131. package/esm/stream/detect.bak.d.ts +240 -0
  132. package/esm/stream/detect.bak.d.ts.map +1 -0
  133. package/esm/stream/detect.bak.js +60 -0
  134. package/esm/stream/detect.bak.js.map +1 -0
  135. package/esm/stream/detect.d.ts +18 -0
  136. package/esm/stream/detect.d.ts.map +1 -0
  137. package/esm/stream/detect.js +6 -0
  138. package/esm/stream/detect.js.map +1 -0
  139. package/esm/stream/detect.native.d.ts +240 -0
  140. package/esm/stream/detect.native.d.ts.map +1 -0
  141. package/esm/stream/detect.native.js +60 -0
  142. package/esm/stream/detect.native.js.map +1 -0
  143. package/esm/stream/detect.polyfill.d.ts +18 -0
  144. package/esm/stream/detect.polyfill.d.ts.map +1 -0
  145. package/esm/stream/detect.polyfill.js +6 -0
  146. package/esm/stream/detect.polyfill.js.map +1 -0
  147. package/esm/stream/index.d.ts +4 -0
  148. package/esm/stream/index.d.ts.map +1 -0
  149. package/esm/stream/index.js +3 -2
  150. package/esm/stream/index.js.map +1 -1
  151. package/esm/stream/transform.d.ts +98 -0
  152. package/esm/stream/transform.d.ts.map +1 -0
  153. package/esm/stream/transform.js +352 -0
  154. package/esm/stream/transform.js.map +1 -0
  155. package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
  156. package/esm/utils/auto-reset-event.d.ts.map +1 -0
  157. package/esm/utils/auto-reset-event.js +2 -1
  158. package/esm/utils/auto-reset-event.js.map +1 -1
  159. package/esm/utils/base64.d.ts +5 -0
  160. package/esm/utils/base64.d.ts.map +1 -0
  161. package/esm/utils/base64.js +116 -80
  162. package/esm/utils/base64.js.map +1 -1
  163. package/esm/utils/encoding.d.ts +3 -0
  164. package/esm/utils/encoding.d.ts.map +1 -0
  165. package/esm/utils/encoding.js +11 -0
  166. package/esm/utils/encoding.js.map +1 -0
  167. package/esm/utils/index.d.ts +4 -0
  168. package/esm/utils/index.d.ts.map +1 -0
  169. package/esm/utils/index.js +3 -4
  170. package/esm/utils/index.js.map +1 -1
  171. package/package.json +49 -50
  172. package/src/adb.ts +247 -242
  173. package/src/auth.ts +170 -156
  174. package/src/backend.ts +11 -24
  175. package/src/commands/base.ts +11 -11
  176. package/src/commands/framebuffer.ts +73 -73
  177. package/src/commands/index.ts +8 -8
  178. package/src/commands/install.ts +32 -21
  179. package/src/commands/power.ts +54 -0
  180. package/src/commands/reverse.ts +136 -133
  181. package/src/commands/subprocess/index.ts +124 -0
  182. package/src/commands/subprocess/legacy.ts +58 -0
  183. package/src/commands/subprocess/protocol.ts +185 -0
  184. package/src/commands/subprocess/types.ts +55 -0
  185. package/src/commands/{shell → subprocess}/utils.ts +20 -20
  186. package/src/commands/sync/index.ts +7 -7
  187. package/src/commands/sync/list.ts +40 -39
  188. package/src/commands/sync/pull.ts +43 -34
  189. package/src/commands/sync/push.ts +41 -46
  190. package/src/commands/sync/request.ts +49 -48
  191. package/src/commands/sync/response.ts +58 -57
  192. package/src/commands/sync/stat.ts +123 -121
  193. package/src/commands/sync/sync.ts +145 -113
  194. package/src/commands/tcpip.ts +21 -21
  195. package/src/crypto.ts +280 -280
  196. package/src/features.ts +5 -5
  197. package/src/index.ts +11 -10
  198. package/src/packet.ts +69 -89
  199. package/src/socket/dispatcher.ts +256 -269
  200. package/src/socket/index.ts +2 -6
  201. package/src/socket/socket.ts +129 -28
  202. package/src/stream/buffered.ts +147 -0
  203. package/src/stream/detect.native.ts +362 -0
  204. package/src/stream/detect.polyfill.ts +25 -0
  205. package/src/stream/detect.ts +25 -0
  206. package/src/stream/index.ts +3 -2
  207. package/src/stream/transform.ts +427 -0
  208. package/src/utils/auto-reset-event.ts +41 -41
  209. package/src/utils/base64.ts +306 -274
  210. package/src/utils/encoding.ts +13 -0
  211. package/src/utils/index.ts +3 -4
  212. package/tsconfig.build.json +3 -0
  213. package/tsconfig.build.tsbuildinfo +1 -0
  214. package/tsconfig.test.json +10 -0
  215. package/cjs/adb.js +0 -205
  216. package/cjs/adb.js.map +0 -1
  217. package/cjs/auth.js +0 -141
  218. package/cjs/auth.js.map +0 -1
  219. package/cjs/backend.js +0 -3
  220. package/cjs/backend.js.map +0 -1
  221. package/cjs/commands/base.js +0 -12
  222. package/cjs/commands/base.js.map +0 -1
  223. package/cjs/commands/demo-mode.js +0 -174
  224. package/cjs/commands/demo-mode.js.map +0 -1
  225. package/cjs/commands/framebuffer.js +0 -66
  226. package/cjs/commands/framebuffer.js.map +0 -1
  227. package/cjs/commands/index.js +0 -12
  228. package/cjs/commands/index.js.map +0 -1
  229. package/cjs/commands/install.js +0 -20
  230. package/cjs/commands/install.js.map +0 -1
  231. package/cjs/commands/reverse.js +0 -105
  232. package/cjs/commands/reverse.js.map +0 -1
  233. package/cjs/commands/shell/index.js +0 -56
  234. package/cjs/commands/shell/index.js.map +0 -1
  235. package/cjs/commands/shell/legacy.js +0 -37
  236. package/cjs/commands/shell/legacy.js.map +0 -1
  237. package/cjs/commands/shell/protocol.js +0 -83
  238. package/cjs/commands/shell/protocol.js.map +0 -1
  239. package/cjs/commands/shell/types.js +0 -3
  240. package/cjs/commands/shell/utils.js +0 -23
  241. package/cjs/commands/shell/utils.js.map +0 -1
  242. package/cjs/commands/sync/index.js +0 -11
  243. package/cjs/commands/sync/index.js.map +0 -1
  244. package/cjs/commands/sync/list.js +0 -36
  245. package/cjs/commands/sync/list.js.map +0 -1
  246. package/cjs/commands/sync/pull.js +0 -34
  247. package/cjs/commands/sync/pull.js.map +0 -1
  248. package/cjs/commands/sync/push.js +0 -49
  249. package/cjs/commands/sync/push.js.map +0 -1
  250. package/cjs/commands/sync/request.js +0 -48
  251. package/cjs/commands/sync/request.js.map +0 -1
  252. package/cjs/commands/sync/response.js +0 -53
  253. package/cjs/commands/sync/response.js.map +0 -1
  254. package/cjs/commands/sync/stat.js +0 -109
  255. package/cjs/commands/sync/stat.js.map +0 -1
  256. package/cjs/commands/sync/sync.js +0 -118
  257. package/cjs/commands/sync/sync.js.map +0 -1
  258. package/cjs/commands/tcpip.js +0 -28
  259. package/cjs/commands/tcpip.js.map +0 -1
  260. package/cjs/crypto.js +0 -231
  261. package/cjs/crypto.js.map +0 -1
  262. package/cjs/features.js +0 -10
  263. package/cjs/features.js.map +0 -1
  264. package/cjs/index.js +0 -14
  265. package/cjs/index.js.map +0 -1
  266. package/cjs/packet.js +0 -77
  267. package/cjs/packet.js.map +0 -1
  268. package/cjs/socket/close-event-emitter.js +0 -32
  269. package/cjs/socket/close-event-emitter.js.map +0 -1
  270. package/cjs/socket/controller.js +0 -84
  271. package/cjs/socket/controller.js.map +0 -1
  272. package/cjs/socket/data-event-emitter.js +0 -29
  273. package/cjs/socket/data-event-emitter.js.map +0 -1
  274. package/cjs/socket/dispatcher.js +0 -219
  275. package/cjs/socket/dispatcher.js.map +0 -1
  276. package/cjs/socket/index.js +0 -10
  277. package/cjs/socket/index.js.map +0 -1
  278. package/cjs/socket/logger.js +0 -3
  279. package/cjs/socket/logger.js.map +0 -1
  280. package/cjs/socket/socket.js +0 -24
  281. package/cjs/socket/socket.js.map +0 -1
  282. package/cjs/stream/buffered-stream.js +0 -78
  283. package/cjs/stream/buffered-stream.js.map +0 -1
  284. package/cjs/stream/index.js +0 -6
  285. package/cjs/stream/index.js.map +0 -1
  286. package/cjs/stream/stream.js +0 -45
  287. package/cjs/stream/stream.js.map +0 -1
  288. package/cjs/utils/auto-reset-event.js +0 -37
  289. package/cjs/utils/auto-reset-event.js.map +0 -1
  290. package/cjs/utils/base64.js +0 -210
  291. package/cjs/utils/base64.js.map +0 -1
  292. package/cjs/utils/chunk.js +0 -75
  293. package/cjs/utils/chunk.js.map +0 -1
  294. package/cjs/utils/event-queue.js +0 -108
  295. package/cjs/utils/event-queue.js.map +0 -1
  296. package/cjs/utils/index.js +0 -8
  297. package/cjs/utils/index.js.map +0 -1
  298. package/dts/adb.d.ts +0 -46
  299. package/dts/adb.d.ts.map +0 -1
  300. package/dts/auth.d.ts.map +0 -1
  301. package/dts/backend.d.ts +0 -15
  302. package/dts/backend.d.ts.map +0 -1
  303. package/dts/commands/base.d.ts.map +0 -1
  304. package/dts/commands/demo-mode.d.ts +0 -41
  305. package/dts/commands/demo-mode.d.ts.map +0 -1
  306. package/dts/commands/framebuffer.d.ts.map +0 -1
  307. package/dts/commands/index.d.ts +0 -9
  308. package/dts/commands/index.d.ts.map +0 -1
  309. package/dts/commands/install.d.ts +0 -3
  310. package/dts/commands/install.d.ts.map +0 -1
  311. package/dts/commands/reverse.d.ts.map +0 -1
  312. package/dts/commands/shell/index.d.ts +0 -20
  313. package/dts/commands/shell/index.d.ts.map +0 -1
  314. package/dts/commands/shell/legacy.d.ts +0 -27
  315. package/dts/commands/shell/legacy.d.ts.map +0 -1
  316. package/dts/commands/shell/protocol.d.ts +0 -37
  317. package/dts/commands/shell/protocol.d.ts.map +0 -1
  318. package/dts/commands/shell/types.d.ts +0 -15
  319. package/dts/commands/shell/types.d.ts.map +0 -1
  320. package/dts/commands/shell/utils.d.ts.map +0 -1
  321. package/dts/commands/sync/index.d.ts +0 -8
  322. package/dts/commands/sync/index.d.ts.map +0 -1
  323. package/dts/commands/sync/list.d.ts.map +0 -1
  324. package/dts/commands/sync/pull.d.ts +0 -11
  325. package/dts/commands/sync/pull.d.ts.map +0 -1
  326. package/dts/commands/sync/push.d.ts +0 -8
  327. package/dts/commands/sync/push.d.ts.map +0 -1
  328. package/dts/commands/sync/request.d.ts.map +0 -1
  329. package/dts/commands/sync/response.d.ts.map +0 -1
  330. package/dts/commands/sync/stat.d.ts.map +0 -1
  331. package/dts/commands/sync/sync.d.ts +0 -68
  332. package/dts/commands/sync/sync.d.ts.map +0 -1
  333. package/dts/crypto.d.ts +0 -17
  334. package/dts/crypto.d.ts.map +0 -1
  335. package/dts/index.d.ts +0 -11
  336. package/dts/index.d.ts.map +0 -1
  337. package/dts/packet.d.ts +0 -27
  338. package/dts/packet.d.ts.map +0 -1
  339. package/dts/socket/close-event-emitter.d.ts +0 -8
  340. package/dts/socket/close-event-emitter.d.ts.map +0 -1
  341. package/dts/socket/controller.d.ts +0 -43
  342. package/dts/socket/controller.d.ts.map +0 -1
  343. package/dts/socket/data-event-emitter.d.ts +0 -10
  344. package/dts/socket/data-event-emitter.d.ts.map +0 -1
  345. package/dts/socket/dispatcher.d.ts.map +0 -1
  346. package/dts/socket/index.d.ts +0 -7
  347. package/dts/socket/index.d.ts.map +0 -1
  348. package/dts/socket/logger.d.ts +0 -9
  349. package/dts/socket/logger.d.ts.map +0 -1
  350. package/dts/socket/socket.d.ts +0 -22
  351. package/dts/socket/socket.d.ts.map +0 -1
  352. package/dts/stream/buffered-stream.d.ts +0 -30
  353. package/dts/stream/buffered-stream.d.ts.map +0 -1
  354. package/dts/stream/index.d.ts +0 -3
  355. package/dts/stream/index.d.ts.map +0 -1
  356. package/dts/stream/stream.d.ts +0 -15
  357. package/dts/stream/stream.d.ts.map +0 -1
  358. package/dts/utils/auto-reset-event.d.ts.map +0 -1
  359. package/dts/utils/base64.d.ts +0 -7
  360. package/dts/utils/base64.d.ts.map +0 -1
  361. package/dts/utils/chunk.d.ts +0 -3
  362. package/dts/utils/chunk.d.ts.map +0 -1
  363. package/dts/utils/event-queue.d.ts +0 -35
  364. package/dts/utils/event-queue.d.ts.map +0 -1
  365. package/dts/utils/index.d.ts +0 -5
  366. package/dts/utils/index.d.ts.map +0 -1
  367. package/esm/commands/demo-mode.js +0 -170
  368. package/esm/commands/demo-mode.js.map +0 -1
  369. package/esm/commands/shell/index.js +0 -52
  370. package/esm/commands/shell/index.js.map +0 -1
  371. package/esm/commands/shell/legacy.js +0 -33
  372. package/esm/commands/shell/legacy.js.map +0 -1
  373. package/esm/commands/shell/protocol.js +0 -79
  374. package/esm/commands/shell/protocol.js.map +0 -1
  375. package/esm/commands/shell/types.js.map +0 -1
  376. package/esm/commands/shell/utils.js.map +0 -1
  377. package/esm/socket/close-event-emitter.js +0 -28
  378. package/esm/socket/close-event-emitter.js.map +0 -1
  379. package/esm/socket/data-event-emitter.js +0 -25
  380. package/esm/socket/data-event-emitter.js.map +0 -1
  381. package/esm/socket/logger.js +0 -2
  382. package/esm/socket/logger.js.map +0 -1
  383. package/esm/stream/buffered-stream.js +0 -73
  384. package/esm/stream/buffered-stream.js.map +0 -1
  385. package/esm/stream/stream.js +0 -41
  386. package/esm/stream/stream.js.map +0 -1
  387. package/esm/utils/chunk.js +0 -70
  388. package/esm/utils/chunk.js.map +0 -1
  389. package/esm/utils/event-queue.js +0 -104
  390. package/esm/utils/event-queue.js.map +0 -1
  391. package/src/commands/demo-mode.ts +0 -160
  392. package/src/commands/shell/index.ts +0 -68
  393. package/src/commands/shell/legacy.ts +0 -42
  394. package/src/commands/shell/protocol.ts +0 -94
  395. package/src/commands/shell/types.ts +0 -21
  396. package/src/socket/close-event-emitter.ts +0 -28
  397. package/src/socket/controller.ts +0 -105
  398. package/src/socket/data-event-emitter.ts +0 -27
  399. package/src/socket/logger.ts +0 -12
  400. package/src/stream/buffered-stream.ts +0 -100
  401. package/src/stream/stream.ts +0 -50
  402. package/src/utils/chunk.ts +0 -70
  403. package/src/utils/event-queue.ts +0 -145
  404. package/tsconfig.cjs.json +0 -11
  405. package/tsconfig.esm.json +0 -28
  406. package/tsconfig.esm.tsbuildinfo +0 -1305
  407. package/tsconfig.json +0 -18
@@ -1,28 +1,129 @@
1
- import { AdbSocketController, AdbSocketInfo } from './controller';
2
-
3
- export class AdbSocket implements AdbSocketInfo {
4
- private readonly controller: AdbSocketController;
5
-
6
- public get backend() { return this.controller.backend; }
7
- public get localId() { return this.controller.localId; }
8
- public get remoteId() { return this.controller.remoteId; }
9
- public get localCreated() { return this.controller.localCreated; }
10
- public get serviceString() { return this.controller.serviceString; }
11
-
12
- public get closed() { return this.controller.closed; }
13
-
14
- public get onData() { return this.controller.dataEvent.event; }
15
- public get onClose() { return this.controller.onClose; }
16
-
17
- public constructor(controller: AdbSocketController) {
18
- this.controller = controller;
19
- }
20
-
21
- public write(data: ArrayBuffer): Promise<void> {
22
- return this.controller.write(data);
23
- }
24
-
25
- public close(): Promise<void> {
26
- return this.controller.close();
27
- }
28
- }
1
+ import { PromiseResolver } from "@yume-chan/async";
2
+ import { AdbCommand } from '../packet.js';
3
+ import { ChunkStream, DuplexStreamFactory, pipeFrom, ReadableStream, WritableStream, type PushReadableStreamController } from '../stream/index.js';
4
+ import type { AdbPacketDispatcher } from './dispatcher.js';
5
+
6
+ export interface AdbSocketInfo {
7
+ localId: number;
8
+ remoteId: number;
9
+
10
+ localCreated: boolean;
11
+
12
+ serviceString: string;
13
+ }
14
+
15
+ export interface AdbSocketConstructionOptions {
16
+ dispatcher: AdbPacketDispatcher;
17
+
18
+ localId: number;
19
+
20
+ remoteId: number;
21
+
22
+ localCreated: boolean;
23
+
24
+ serviceString: string;
25
+
26
+ highWaterMark?: number | undefined;
27
+ }
28
+
29
+ export class AdbSocket implements AdbSocketInfo {
30
+ private readonly dispatcher!: AdbPacketDispatcher;
31
+
32
+ public readonly localId!: number;
33
+ public readonly remoteId!: number;
34
+ public readonly localCreated!: boolean;
35
+ public readonly serviceString!: string;
36
+
37
+ private _factory: DuplexStreamFactory<Uint8Array, Uint8Array>;
38
+
39
+ private _readable: ReadableStream<Uint8Array>;
40
+ private _readableController!: PushReadableStreamController<Uint8Array>;
41
+ public get readable() { return this._readable; }
42
+
43
+ private _writePromise: PromiseResolver<void> | undefined;
44
+ public readonly writable: WritableStream<Uint8Array>;
45
+
46
+ private _closed = false;
47
+ public get closed() { return this._closed; }
48
+
49
+ public constructor(options: AdbSocketConstructionOptions) {
50
+ Object.assign(this, options);
51
+
52
+ // Check this image to help you understand the stream graph
53
+ // cspell: disable-next-line
54
+ // https://www.plantuml.com/plantuml/png/TL0zoeGm4ErpYc3l5JxyS0yWM6mX5j4C6p4cxcJ25ejttuGX88ZftizxUKmJI275pGhXl0PP_UkfK_CAz5Z2hcWsW9Ny2fdU4C1f5aSchFVxA8vJjlTPRhqZzDQMRB7AklwJ0xXtX0ZSKH1h24ghoKAdGY23FhxC4nS2pDvxzIvxb-8THU0XlEQJ-ZB7SnXTAvc_LhOckhMdLBnbtndpb-SB7a8q2SRD_W00
55
+
56
+ this._factory = new DuplexStreamFactory<Uint8Array, Uint8Array>({
57
+ close: async () => {
58
+ await this.close();
59
+ },
60
+ });
61
+
62
+ this._readable = this._factory.createPushReadable(controller => {
63
+ this._readableController = controller;
64
+ }, {
65
+ highWaterMark: options.highWaterMark ?? 16 * 1024,
66
+ size(chunk) { return chunk.byteLength; }
67
+ });
68
+
69
+ this.writable = pipeFrom(
70
+ this._factory.createWritable({
71
+ write: async (chunk) => {
72
+ // Wait for an ack packet
73
+ this._writePromise = new PromiseResolver();
74
+ await this.dispatcher.sendPacket(
75
+ AdbCommand.Write,
76
+ this.localId,
77
+ this.remoteId,
78
+ chunk
79
+ );
80
+ await this._writePromise.promise;
81
+ },
82
+ }),
83
+ new ChunkStream(this.dispatcher.maxPayloadSize)
84
+ );
85
+ }
86
+
87
+ /**
88
+ * @internal
89
+ */
90
+ public async enqueue(packet: Uint8Array) {
91
+ await this._readableController.enqueue(packet);
92
+ }
93
+
94
+ /**
95
+ * @internal
96
+ */
97
+ public ack() {
98
+ this._writePromise?.resolve();
99
+ }
100
+
101
+ public async close(): Promise<void> {
102
+ // Error out the pending writes
103
+ this._writePromise?.reject(new Error('Socket closed'));
104
+
105
+ if (!this._closed) {
106
+ this._closed = true;
107
+
108
+ // Only send close packet when `close` is called before `dispose`
109
+ // (the client initiated the close)
110
+ await this.dispatcher.sendPacket(
111
+ AdbCommand.Close,
112
+ this.localId,
113
+ this.remoteId
114
+ );
115
+ }
116
+ }
117
+
118
+ /**
119
+ * @internal
120
+ */
121
+ public dispose() {
122
+ this._closed = true;
123
+
124
+ this._factory.close();
125
+
126
+ // Close `writable` side
127
+ this.close();
128
+ }
129
+ }
@@ -0,0 +1,147 @@
1
+ import type { StructAsyncDeserializeStream } from '@yume-chan/struct';
2
+ import type { AdbSocket, AdbSocketInfo } from '../socket/index.js';
3
+ import type { ReadableStream, ReadableStreamDefaultReader } from './detect.js';
4
+ import { PushReadableStream } from "./transform.js";
5
+
6
+ export class BufferedStreamEndedError extends Error {
7
+ public constructor() {
8
+ super('Stream ended');
9
+
10
+ // Fix Error's prototype chain when compiling to ES5
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+ }
13
+ }
14
+
15
+ export class BufferedStream {
16
+ private buffer: Uint8Array | undefined;
17
+
18
+ protected readonly stream: ReadableStream<Uint8Array>;
19
+
20
+ protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
21
+
22
+ public constructor(stream: ReadableStream<Uint8Array>) {
23
+ this.stream = stream;
24
+ this.reader = stream.getReader();
25
+ }
26
+
27
+ /**
28
+ *
29
+ * @param length
30
+ * @returns
31
+ */
32
+ public async read(length: number): Promise<Uint8Array> {
33
+ let array: Uint8Array;
34
+ let index: number;
35
+ if (this.buffer) {
36
+ const buffer = this.buffer;
37
+ if (buffer.byteLength > length) {
38
+ this.buffer = buffer.subarray(length);
39
+ return buffer.subarray(0, length);
40
+ }
41
+
42
+ array = new Uint8Array(length);
43
+ array.set(buffer);
44
+ index = buffer.byteLength;
45
+ this.buffer = undefined;
46
+ } else {
47
+ const { done, value } = await this.reader.read();
48
+ if (done) {
49
+ throw new BufferedStreamEndedError();
50
+ }
51
+
52
+ if (value.byteLength === length) {
53
+ return value;
54
+ }
55
+
56
+ if (value.byteLength > length) {
57
+ this.buffer = value.subarray(length);
58
+ return value.subarray(0, length);
59
+ }
60
+
61
+ array = new Uint8Array(length);
62
+ array.set(value);
63
+ index = value.byteLength;
64
+ }
65
+
66
+ while (index < length) {
67
+ const left = length - index;
68
+
69
+ const { done, value } = await this.reader.read();
70
+ if (done) {
71
+ throw new BufferedStreamEndedError();
72
+ }
73
+
74
+ if (value.byteLength === left) {
75
+ array.set(value, index);
76
+ return array;
77
+ }
78
+
79
+ if (value.byteLength > left) {
80
+ array.set(value.subarray(0, left), index);
81
+ this.buffer = value.subarray(left);
82
+ return array;
83
+ }
84
+
85
+ array.set(value, index);
86
+ index += value.byteLength;
87
+ }
88
+
89
+ return array;
90
+ }
91
+
92
+ /**
93
+ * Return a readable stream with unconsumed data (if any) and
94
+ * all data from the wrapped stream.
95
+ * @returns A `ReadableStream`
96
+ */
97
+ public release(): ReadableStream<Uint8Array> {
98
+ if (this.buffer) {
99
+ return new PushReadableStream<Uint8Array>(async controller => {
100
+ // Put the remaining data back to the stream
101
+ await controller.enqueue(this.buffer!);
102
+
103
+ // Manually pipe the stream
104
+ while (true) {
105
+ try {
106
+ const { done, value } = await this.reader.read();
107
+ if (done) {
108
+ controller.close();
109
+ break;
110
+ } else {
111
+ await controller.enqueue(value);
112
+ }
113
+ } catch (e) {
114
+ controller.error(e);
115
+ break;
116
+ }
117
+ }
118
+ });
119
+ } else {
120
+ // Simply release the reader and return the stream
121
+ this.reader.releaseLock();
122
+ return this.stream;
123
+ }
124
+ }
125
+
126
+ public close() {
127
+ this.reader.cancel();
128
+ }
129
+ }
130
+
131
+ export class AdbBufferedStream
132
+ extends BufferedStream
133
+ implements AdbSocketInfo, StructAsyncDeserializeStream {
134
+ protected readonly socket: AdbSocket;
135
+
136
+ public get localId() { return this.socket.localId; }
137
+ public get remoteId() { return this.socket.remoteId; }
138
+ public get localCreated() { return this.socket.localCreated; }
139
+ public get serviceString() { return this.socket.serviceString; }
140
+
141
+ public get writable() { return this.socket.writable; }
142
+
143
+ public constructor(socket: AdbSocket) {
144
+ super(socket.readable);
145
+ this.socket = socket;
146
+ }
147
+ }
@@ -0,0 +1,362 @@
1
+ // cspell: ignore chainable
2
+ // cspell: ignore backpressure
3
+ // cspell: ignore endregion
4
+
5
+ // Because Node.js exports Web Streams types from `stream/web` package,
6
+ // this module uses Top-Level Await to support both Web Browsers and Node.js.
7
+ // For Webpack, the `experimental.topLevelAwait` option is required.
8
+ // (See: https://webpack.js.org/configuration/experiments/)
9
+
10
+ // It's also possible to add fallback to some polyfill.
11
+
12
+ //#region borrowed
13
+ // from https://github.com/microsoft/TypeScript/blob/38da7c600c83e7b31193a62495239a0fe478cb67/lib/lib.webworker.d.ts#L633 until moved to separate lib
14
+ /** A controller object that allows you to abort one or more DOM requests as and when desired. */
15
+ export interface AbortController {
16
+ /**
17
+ * Returns the AbortSignal object associated with this object.
18
+ */
19
+
20
+ readonly signal: AbortSignal;
21
+ /**
22
+ * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
23
+ */
24
+ abort(): void;
25
+ }
26
+
27
+ // A simplified version of AbortSignal events.
28
+ export interface AbortSignalEventMap {
29
+ "abort": any;
30
+ }
31
+
32
+ export interface EventListenerOptions {
33
+ capture?: boolean;
34
+ }
35
+
36
+ export interface AddEventListenerOptions extends EventListenerOptions {
37
+ once?: boolean;
38
+ passive?: boolean;
39
+ signal?: AbortSignal;
40
+ }
41
+
42
+ /** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
43
+ export interface AbortSignal {
44
+ /**
45
+ * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
46
+ */
47
+ readonly aborted: boolean;
48
+
49
+ onabort: ((this: AbortSignal, ev: any) => any) | null;
50
+ addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
51
+ addEventListener(type: string, listener: (ev: any) => void, options?: boolean | AddEventListenerOptions): void;
52
+ removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
53
+ removeEventListener(type: string, listener: (ev: any) => void, options?: boolean | EventListenerOptions): void;
54
+ }
55
+
56
+ export let AbortController: {
57
+ prototype: AbortController;
58
+ new(): AbortController;
59
+ };
60
+
61
+ export let AbortSignal: {
62
+ prototype: AbortSignal;
63
+ new(): AbortSignal;
64
+ // TODO: Add abort() static
65
+ };
66
+
67
+ ({ AbortController, AbortSignal } = globalThis as any);
68
+ //#endregion borrowed
69
+
70
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L1194-L1206
71
+ export interface QueuingStrategy<T = any> {
72
+ highWaterMark?: number;
73
+ size?: QueuingStrategySize<T>;
74
+ }
75
+
76
+ export interface QueuingStrategyInit {
77
+ /**
78
+ * Creates a new ByteLengthQueuingStrategy with the provided high water mark.
79
+ *
80
+ * Note that the provided high water mark will not be validated ahead of time. Instead, if it is negative, NaN, or not a number, the resulting ByteLengthQueuingStrategy will cause the corresponding stream constructor to throw.
81
+ */
82
+ highWaterMark: number;
83
+ }
84
+
85
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L1450-L1468
86
+ export interface ReadableStreamDefaultReadDoneResult {
87
+ done: true;
88
+ value?: undefined;
89
+ }
90
+
91
+ export interface ReadableStreamDefaultReadValueResult<T> {
92
+ done: false;
93
+ value: T;
94
+ }
95
+
96
+ export interface ReadableWritablePair<R = any, W = any> {
97
+ readable: ReadableStream<R>;
98
+ /**
99
+ * Provides a convenient, chainable way of piping this readable stream through a transform stream (or any other { writable, readable } pair). It simply pipes the stream into the writable side of the supplied pair, and returns the readable side for further use.
100
+ *
101
+ * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
102
+ */
103
+ writable: WritableStream<W>;
104
+ }
105
+
106
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L1636
107
+ export interface StreamPipeOptions {
108
+ preventAbort?: boolean;
109
+ preventCancel?: boolean;
110
+ /**
111
+ * Pipes this readable stream to a given writable stream destination. The way in which the piping process behaves under various error conditions can be customized with a number of passed options. It returns a promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered.
112
+ *
113
+ * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
114
+ *
115
+ * Errors and closures of the source and destination streams propagate as follows:
116
+ *
117
+ * An error in this source readable stream will abort destination, unless preventAbort is truthy. The returned promise will be rejected with the source's error, or with any error that occurs during aborting the destination.
118
+ *
119
+ * An error in destination will cancel this source readable stream, unless preventCancel is truthy. The returned promise will be rejected with the destination's error, or with any error that occurs during canceling the source.
120
+ *
121
+ * When this source readable stream closes, destination will be closed, unless preventClose is truthy. The returned promise will be fulfilled once this process completes, unless an error is encountered while closing the destination, in which case it will be rejected with that error.
122
+ *
123
+ * If destination starts out closed or closing, this source readable stream will be canceled, unless preventCancel is true. The returned promise will be rejected with an error indicating piping to a closed stream failed, or with any error that occurs during canceling the source.
124
+ *
125
+ * The signal option can be set to an AbortSignal to allow aborting an ongoing pipe operation via the corresponding AbortController. In this case, this source readable stream will be canceled, and destination aborted, unless the respective options preventCancel or preventAbort are set.
126
+ */
127
+ preventClose?: boolean;
128
+ signal?: AbortSignal;
129
+ }
130
+
131
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L1710
132
+ export interface Transformer<I = any, O = any> {
133
+ flush?: TransformerFlushCallback<O>;
134
+ readableType?: undefined;
135
+ start?: TransformerStartCallback<O>;
136
+ transform?: TransformerTransformCallback<I, O>;
137
+ writableType?: undefined;
138
+ }
139
+
140
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L11132-L11172
141
+ /** This Streams API interface represents a readable stream of byte data. The Fetch API offers a concrete instance of a ReadableStream through the body property of a Response object. */
142
+ export interface ReadableStream<R = any> {
143
+ readonly locked: boolean;
144
+ cancel(reason?: any): Promise<void>;
145
+ getReader(): ReadableStreamDefaultReader<R>;
146
+ pipeThrough<T>(transform: ReadableWritablePair<T, R>, options?: StreamPipeOptions): ReadableStream<T>;
147
+ pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
148
+ tee(): [ReadableStream<R>, ReadableStream<R>];
149
+ }
150
+
151
+ export let ReadableStream: {
152
+ prototype: ReadableStream;
153
+ new <R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
154
+ };
155
+
156
+ export interface ReadableStreamDefaultController<R = any> {
157
+ readonly desiredSize: number | null;
158
+ close(): void;
159
+ enqueue(chunk?: R): void;
160
+ error(e?: any): void;
161
+ }
162
+
163
+ export let ReadableStreamDefaultController: {
164
+ prototype: ReadableStreamDefaultController;
165
+ new(): ReadableStreamDefaultController;
166
+ };
167
+
168
+ export interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
169
+ read(): Promise<ReadableStreamDefaultReadResult<R>>;
170
+ releaseLock(): void;
171
+ }
172
+
173
+ export let ReadableStreamDefaultReader: {
174
+ prototype: ReadableStreamDefaultReader;
175
+ new <R = any>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
176
+ };
177
+
178
+ export interface ReadableStreamGenericReader {
179
+ readonly closed: Promise<undefined>;
180
+ cancel(reason?: any): Promise<void>;
181
+ }
182
+
183
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L13924-L13944
184
+ export interface TransformStream<I = any, O = any> {
185
+ readonly readable: ReadableStream<O>;
186
+ readonly writable: WritableStream<I>;
187
+ }
188
+
189
+ export let TransformStream: {
190
+ prototype: TransformStream;
191
+ new <I = any, O = any>(transformer?: Transformer<I, O>, writableStrategy?: QueuingStrategy<I>, readableStrategy?: QueuingStrategy<O>): TransformStream<I, O>;
192
+ };
193
+
194
+ export interface TransformStreamDefaultController<O = any> {
195
+ readonly desiredSize: number | null;
196
+ enqueue(chunk?: O): void;
197
+ error(reason?: any): void;
198
+ terminate(): void;
199
+ }
200
+
201
+ export let TransformStreamDefaultController: {
202
+ prototype: TransformStreamDefaultController;
203
+ new(): TransformStreamDefaultController;
204
+ };
205
+
206
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L16509-L16546
207
+ /** This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing. */
208
+ export interface WritableStream<W = any> {
209
+ readonly locked: boolean;
210
+ abort(reason?: any): Promise<void>;
211
+ close(): Promise<void>;
212
+ getWriter(): WritableStreamDefaultWriter<W>;
213
+ }
214
+
215
+ export let WritableStream: {
216
+ prototype: WritableStream;
217
+ new <W = any>(underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>): WritableStream<W>;
218
+ };
219
+
220
+ /** This Streams API interface represents a controller allowing control of a WritableStream's state. When constructing a WritableStream, the underlying sink is given a corresponding WritableStreamDefaultController instance to manipulate. */
221
+ export interface WritableStreamDefaultController {
222
+ error(e?: any): void;
223
+ }
224
+
225
+ export let WritableStreamDefaultController: {
226
+ prototype: WritableStreamDefaultController;
227
+ new(): WritableStreamDefaultController;
228
+ };
229
+
230
+ /** This Streams API interface is the object returned by WritableStream.getWriter() and once created locks the < writer to the WritableStream ensuring that no other streams can write to the underlying sink. */
231
+ export interface WritableStreamDefaultWriter<W = any> {
232
+ readonly closed: Promise<undefined>;
233
+ readonly desiredSize: number | null;
234
+ readonly ready: Promise<undefined>;
235
+ abort(reason?: any): Promise<void>;
236
+ close(): Promise<void>;
237
+ releaseLock(): void;
238
+ write(chunk?: W): Promise<void>;
239
+ }
240
+
241
+ export let WritableStreamDefaultWriter: {
242
+ prototype: WritableStreamDefaultWriter;
243
+ new <W = any>(stream: WritableStream<W>): WritableStreamDefaultWriter<W>;
244
+ };
245
+
246
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L17045
247
+ export interface QueuingStrategySize<T = any> {
248
+ (chunk: T): number;
249
+ }
250
+
251
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L17065-L17103
252
+ export interface TransformerFlushCallback<O> {
253
+ (controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
254
+ }
255
+
256
+ export interface TransformerStartCallback<O> {
257
+ (controller: TransformStreamDefaultController<O>): any;
258
+ }
259
+
260
+ export interface TransformerTransformCallback<I, O> {
261
+ (chunk: I, controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
262
+ }
263
+
264
+ export interface UnderlyingSink<W = any> {
265
+ abort?: UnderlyingSinkAbortCallback;
266
+ close?: UnderlyingSinkCloseCallback;
267
+ start?: UnderlyingSinkStartCallback;
268
+ type?: undefined;
269
+ write?: UnderlyingSinkWriteCallback<W>;
270
+ }
271
+
272
+ export interface UnderlyingSource<R = any> {
273
+ cancel?: UnderlyingSourceCancelCallback;
274
+ pull?: UnderlyingSourcePullCallback<R> | undefined;
275
+ start?: UnderlyingSourceStartCallback<R>;
276
+ type?: undefined;
277
+ }
278
+
279
+ export interface UnderlyingSinkAbortCallback {
280
+ (reason?: any): void | PromiseLike<void>;
281
+ }
282
+
283
+ export interface UnderlyingSinkCloseCallback {
284
+ (): void | PromiseLike<void>;
285
+ }
286
+
287
+ export interface UnderlyingSinkStartCallback {
288
+ (controller: WritableStreamDefaultController): any;
289
+ }
290
+
291
+ export interface UnderlyingSinkWriteCallback<W> {
292
+ (chunk: W, controller: WritableStreamDefaultController): void | PromiseLike<void>;
293
+ }
294
+
295
+ export interface UnderlyingSourceCancelCallback {
296
+ (reason?: any): void | PromiseLike<void>;
297
+ }
298
+
299
+ export interface UnderlyingSourcePullCallback<R> {
300
+ (controller: ReadableStreamController<R>): void | PromiseLike<void>;
301
+ }
302
+
303
+ export interface UnderlyingSourceStartCallback<R> {
304
+ (controller: ReadableStreamController<R>): any;
305
+ }
306
+
307
+ // https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/11d922f302743cb3fcee9ab59b03d40074a2965c/baselines/dom.generated.d.ts#L17796-L17798
308
+ export type ReadableStreamController<T> = ReadableStreamDefaultController<T>;
309
+ export type ReadableStreamDefaultReadResult<T> = ReadableStreamDefaultReadValueResult<T> | ReadableStreamDefaultReadDoneResult;
310
+ export type ReadableStreamReader<T> = ReadableStreamDefaultReader<T>;
311
+
312
+ // Extra
313
+ export interface ReadableStreamIteratorOptions {
314
+ preventCancel?: boolean;
315
+ }
316
+
317
+ // This library can't use `@types/node` or `lib: dom`
318
+ // because they will pollute the global scope
319
+ // So `ReadableStream`, `WritableStream` and `TransformStream` are not available
320
+
321
+ if ('ReadableStream' in globalThis && 'WritableStream' in globalThis && 'TransformStream' in globalThis) {
322
+ ({
323
+ ReadableStream,
324
+ ReadableStreamDefaultController,
325
+ ReadableStreamDefaultReader,
326
+ TransformStream,
327
+ TransformStreamDefaultController,
328
+ WritableStream,
329
+ WritableStreamDefaultController,
330
+ WritableStreamDefaultWriter,
331
+ } = globalThis as any);
332
+ } else {
333
+ try {
334
+ // // Node.js 16 has Web Streams types in `stream/web` module
335
+ ({
336
+ // @ts-ignore
337
+ ReadableStream,
338
+ // @ts-ignore
339
+ ReadableStreamDefaultController,
340
+ // @ts-ignore
341
+ ReadableStreamDefaultReader,
342
+ // @ts-ignore
343
+ TransformStream,
344
+ // @ts-ignore
345
+ TransformStreamDefaultController,
346
+ // @ts-ignore
347
+ WritableStream,
348
+ // @ts-ignore
349
+ WritableStreamDefaultController,
350
+ // @ts-ignore
351
+ WritableStreamDefaultWriter,
352
+ // @ts-ignore
353
+ } = await import(/* webpackIgnore: true */ 'stream/web'));
354
+ } catch { }
355
+ }
356
+
357
+ // TODO: stream/detect: Load some polyfills
358
+
359
+ // @ts-ignore
360
+ if (!ReadableStream || !WritableStream || !TransformStream) {
361
+ // throw new Error('Web Streams API is not available');
362
+ }
@@ -0,0 +1,25 @@
1
+ // cspell: ignore ponyfill
2
+
3
+ import type { AbortSignal } from "web-streams-polyfill";
4
+ // TODO: import the ponyfill instead (as a library should do)
5
+ export * from 'web-streams-polyfill';
6
+
7
+ /** A controller object that allows you to abort one or more DOM requests as and when desired. */
8
+ export interface AbortController {
9
+ /**
10
+ * Returns the AbortSignal object associated with this object.
11
+ */
12
+
13
+ readonly signal: AbortSignal;
14
+ /**
15
+ * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
16
+ */
17
+ abort(): void;
18
+ }
19
+
20
+ export let AbortController: {
21
+ prototype: AbortController;
22
+ new(): AbortController;
23
+ };
24
+
25
+ ({ AbortController } = globalThis as any);