cline 1.0.1 → 1.0.3

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 (299) hide show
  1. package/bin/cline +0 -0
  2. package/bin/cline-darwin-amd64 +0 -0
  3. package/bin/cline-darwin-arm64 +0 -0
  4. package/bin/cline-host +0 -0
  5. package/bin/cline-host-darwin-amd64 +0 -0
  6. package/bin/cline-host-darwin-arm64 +0 -0
  7. package/bin/cline-host-linux-amd64 +0 -0
  8. package/bin/cline-host-linux-arm64 +0 -0
  9. package/bin/cline-linux-amd64 +0 -0
  10. package/bin/cline-linux-arm64 +0 -0
  11. package/cline-core.js +24143 -16610
  12. package/extension/package.json +12 -4
  13. package/node_modules/b4a/LICENSE +201 -0
  14. package/node_modules/b4a/README.md +153 -0
  15. package/node_modules/b4a/browser.js +563 -0
  16. package/node_modules/b4a/index.js +188 -0
  17. package/node_modules/b4a/lib/ascii.js +31 -0
  18. package/node_modules/b4a/lib/base64.js +65 -0
  19. package/node_modules/b4a/lib/hex.js +51 -0
  20. package/node_modules/b4a/lib/utf16le.js +40 -0
  21. package/node_modules/b4a/lib/utf8.js +141 -0
  22. package/node_modules/b4a/package.json +49 -0
  23. package/node_modules/b4a/react-native.js +5 -0
  24. package/node_modules/bare-events/LICENSE +201 -0
  25. package/node_modules/bare-events/README.md +25 -0
  26. package/node_modules/bare-events/global.d.ts +15 -0
  27. package/node_modules/bare-events/global.js +5 -0
  28. package/node_modules/bare-events/index.d.ts +94 -0
  29. package/node_modules/bare-events/index.js +355 -0
  30. package/node_modules/bare-events/lib/errors.js +32 -0
  31. package/node_modules/bare-events/package.json +61 -0
  32. package/node_modules/bare-events/web.d.ts +79 -0
  33. package/node_modules/bare-events/web.js +347 -0
  34. package/node_modules/bare-fs/CMakeLists.txt +13 -0
  35. package/node_modules/bare-fs/LICENSE +201 -0
  36. package/node_modules/bare-fs/README.md +29 -0
  37. package/node_modules/bare-fs/binding.c +2238 -0
  38. package/node_modules/bare-fs/binding.js +1 -0
  39. package/node_modules/bare-fs/index.d.ts +1115 -0
  40. package/node_modules/bare-fs/index.js +2330 -0
  41. package/node_modules/bare-fs/lib/constants.d.ts +49 -0
  42. package/node_modules/bare-fs/lib/constants.js +49 -0
  43. package/node_modules/bare-fs/lib/errors.d.ts +11 -0
  44. package/node_modules/bare-fs/lib/errors.js +55 -0
  45. package/node_modules/bare-fs/package.json +71 -0
  46. package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
  47. package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
  48. package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
  49. package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
  50. package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
  51. package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
  52. package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
  53. package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
  54. package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
  55. package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
  56. package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
  57. package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
  58. package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
  59. package/node_modules/bare-fs/promises.d.ts +282 -0
  60. package/node_modules/bare-fs/promises.js +90 -0
  61. package/node_modules/bare-os/CMakeLists.txt +13 -0
  62. package/node_modules/bare-os/LICENSE +201 -0
  63. package/node_modules/bare-os/README.md +11 -0
  64. package/node_modules/bare-os/binding.c +1119 -0
  65. package/node_modules/bare-os/binding.js +1 -0
  66. package/node_modules/bare-os/index.d.ts +109 -0
  67. package/node_modules/bare-os/index.js +99 -0
  68. package/node_modules/bare-os/lib/constants.js +6 -0
  69. package/node_modules/bare-os/lib/errors.js +22 -0
  70. package/node_modules/bare-os/package.json +46 -0
  71. package/node_modules/bare-os/prebuilds/android-arm/bare-os.bare +0 -0
  72. package/node_modules/bare-os/prebuilds/android-arm64/bare-os.bare +0 -0
  73. package/node_modules/bare-os/prebuilds/android-ia32/bare-os.bare +0 -0
  74. package/node_modules/bare-os/prebuilds/android-x64/bare-os.bare +0 -0
  75. package/node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare +0 -0
  76. package/node_modules/bare-os/prebuilds/darwin-x64/bare-os.bare +0 -0
  77. package/node_modules/bare-os/prebuilds/ios-arm64/bare-os.bare +0 -0
  78. package/node_modules/bare-os/prebuilds/ios-arm64-simulator/bare-os.bare +0 -0
  79. package/node_modules/bare-os/prebuilds/ios-x64-simulator/bare-os.bare +0 -0
  80. package/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare +0 -0
  81. package/node_modules/bare-os/prebuilds/linux-x64/bare-os.bare +0 -0
  82. package/node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare +0 -0
  83. package/node_modules/bare-os/prebuilds/win32-x64/bare-os.bare +0 -0
  84. package/node_modules/bare-path/LICENSE +201 -0
  85. package/node_modules/bare-path/NOTICE +28 -0
  86. package/node_modules/bare-path/README.md +19 -0
  87. package/node_modules/bare-path/index.js +11 -0
  88. package/node_modules/bare-path/lib/constants.js +11 -0
  89. package/node_modules/bare-path/lib/posix.js +242 -0
  90. package/node_modules/bare-path/lib/shared.js +67 -0
  91. package/node_modules/bare-path/lib/win32.js +513 -0
  92. package/node_modules/bare-path/package.json +36 -0
  93. package/node_modules/bare-stream/LICENSE +201 -0
  94. package/node_modules/bare-stream/README.md +15 -0
  95. package/node_modules/bare-stream/global.js +8 -0
  96. package/node_modules/bare-stream/index.d.ts +237 -0
  97. package/node_modules/bare-stream/index.js +355 -0
  98. package/node_modules/bare-stream/package.json +61 -0
  99. package/node_modules/bare-stream/promises.js +3 -0
  100. package/node_modules/bare-stream/web.d.ts +73 -0
  101. package/node_modules/bare-stream/web.js +229 -0
  102. package/node_modules/bare-url/CMakeLists.txt +27 -0
  103. package/node_modules/bare-url/LICENSE +201 -0
  104. package/node_modules/bare-url/README.md +19 -0
  105. package/node_modules/bare-url/binding.c +188 -0
  106. package/node_modules/bare-url/binding.js +1 -0
  107. package/node_modules/bare-url/global.d.ts +12 -0
  108. package/node_modules/bare-url/global.js +2 -0
  109. package/node_modules/bare-url/index.d.ts +39 -0
  110. package/node_modules/bare-url/index.js +450 -0
  111. package/node_modules/bare-url/lib/errors.d.ts +8 -0
  112. package/node_modules/bare-url/lib/errors.js +38 -0
  113. package/node_modules/bare-url/lib/url-search-params.d.ts +21 -0
  114. package/node_modules/bare-url/lib/url-search-params.js +176 -0
  115. package/node_modules/bare-url/package.json +51 -0
  116. package/node_modules/bare-url/prebuilds/android-arm/bare-url.bare +0 -0
  117. package/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare +0 -0
  118. package/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare +0 -0
  119. package/node_modules/bare-url/prebuilds/android-x64/bare-url.bare +0 -0
  120. package/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare +0 -0
  121. package/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare +0 -0
  122. package/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare +0 -0
  123. package/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
  124. package/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
  125. package/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare +0 -0
  126. package/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare +0 -0
  127. package/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare +0 -0
  128. package/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare +0 -0
  129. package/node_modules/better-sqlite3/deps/download.sh +1 -1
  130. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.c +122 -81
  131. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.h +45 -45
  132. package/node_modules/better-sqlite3/lib/database.js +1 -1
  133. package/node_modules/better-sqlite3/package.json +4 -7
  134. package/node_modules/better-sqlite3/src/addon.cpp +47 -0
  135. package/node_modules/better-sqlite3/src/better_sqlite3.cpp +44 -2164
  136. package/node_modules/better-sqlite3/src/objects/backup.cpp +120 -0
  137. package/node_modules/better-sqlite3/src/objects/backup.hpp +36 -0
  138. package/node_modules/better-sqlite3/src/objects/database.cpp +417 -0
  139. package/node_modules/better-sqlite3/src/objects/database.hpp +103 -0
  140. package/node_modules/better-sqlite3/src/objects/statement-iterator.cpp +113 -0
  141. package/node_modules/better-sqlite3/src/objects/statement-iterator.hpp +50 -0
  142. package/node_modules/better-sqlite3/src/objects/statement.cpp +383 -0
  143. package/node_modules/better-sqlite3/src/objects/statement.hpp +58 -0
  144. package/node_modules/better-sqlite3/src/util/bind-map.cpp +73 -0
  145. package/node_modules/better-sqlite3/src/util/binder.cpp +193 -0
  146. package/node_modules/better-sqlite3/src/util/constants.cpp +172 -0
  147. package/node_modules/better-sqlite3/src/util/custom-aggregate.cpp +121 -0
  148. package/node_modules/better-sqlite3/src/util/custom-function.cpp +59 -0
  149. package/node_modules/better-sqlite3/src/util/custom-table.cpp +409 -0
  150. package/node_modules/better-sqlite3/src/util/data-converter.cpp +17 -0
  151. package/node_modules/better-sqlite3/src/util/data.cpp +194 -0
  152. package/node_modules/better-sqlite3/src/util/helpers.cpp +109 -0
  153. package/node_modules/better-sqlite3/src/util/macros.cpp +63 -0
  154. package/node_modules/better-sqlite3/src/util/query-macros.cpp +71 -0
  155. package/node_modules/better-sqlite3/src/util/row-builder.cpp +49 -0
  156. package/node_modules/events-universal/LICENSE +201 -0
  157. package/node_modules/events-universal/README.md +17 -0
  158. package/node_modules/events-universal/bare.js +1 -0
  159. package/node_modules/events-universal/default.js +1 -0
  160. package/node_modules/events-universal/index.js +1 -0
  161. package/node_modules/events-universal/package.json +39 -0
  162. package/node_modules/events-universal/react-native.js +1 -0
  163. package/node_modules/{fs-constants → fast-fifo}/LICENSE +1 -1
  164. package/node_modules/fast-fifo/README.md +78 -0
  165. package/node_modules/fast-fifo/fixed-size.js +39 -0
  166. package/node_modules/fast-fifo/index.js +48 -0
  167. package/node_modules/fast-fifo/package.json +28 -0
  168. package/node_modules/{base64-js → streamx}/LICENSE +1 -1
  169. package/node_modules/streamx/README.md +489 -0
  170. package/node_modules/streamx/index.js +1184 -0
  171. package/node_modules/streamx/package.json +34 -0
  172. package/node_modules/tar-fs/README.md +23 -34
  173. package/node_modules/tar-fs/index.js +211 -184
  174. package/node_modules/tar-fs/package.json +27 -7
  175. package/node_modules/tar-stream/README.md +34 -19
  176. package/node_modules/tar-stream/constants.js +14 -0
  177. package/node_modules/tar-stream/extract.js +341 -192
  178. package/node_modules/tar-stream/headers.js +201 -175
  179. package/node_modules/tar-stream/pack.js +226 -194
  180. package/node_modules/tar-stream/package.json +23 -46
  181. package/node_modules/text-decoder/LICENSE +201 -0
  182. package/node_modules/text-decoder/README.md +36 -0
  183. package/node_modules/text-decoder/index.js +64 -0
  184. package/node_modules/text-decoder/lib/browser-decoder.js +17 -0
  185. package/node_modules/text-decoder/lib/pass-through-decoder.js +19 -0
  186. package/node_modules/text-decoder/lib/utf8-decoder.js +104 -0
  187. package/node_modules/text-decoder/package.json +38 -0
  188. package/package.json +1 -1
  189. package/proto/cline/account.proto +10 -8
  190. package/proto/cline/browser.proto +3 -1
  191. package/proto/cline/checkpoints.proto +5 -3
  192. package/proto/cline/commands.proto +4 -2
  193. package/proto/cline/common.proto +5 -7
  194. package/proto/cline/dictation.proto +3 -1
  195. package/proto/cline/file.proto +36 -34
  196. package/proto/cline/hooks.proto +3 -2
  197. package/proto/cline/mcp.proto +6 -4
  198. package/proto/cline/models.proto +189 -19
  199. package/proto/cline/oca_account.proto +6 -7
  200. package/proto/cline/slash.proto +3 -1
  201. package/proto/cline/state.proto +144 -292
  202. package/proto/cline/task.proto +4 -2
  203. package/proto/cline/ui.proto +25 -24
  204. package/proto/cline/web.proto +3 -1
  205. package/proto/descriptor_set.pb +0 -0
  206. package/proto/host/diff.proto +5 -4
  207. package/proto/host/env.proto +8 -7
  208. package/proto/host/testing.proto +3 -3
  209. package/proto/host/window.proto +2 -2
  210. package/proto/host/workspace.proto +13 -12
  211. package/node_modules/base64-js/README.md +0 -34
  212. package/node_modules/base64-js/base64js.min.js +0 -1
  213. package/node_modules/base64-js/index.d.ts +0 -3
  214. package/node_modules/base64-js/index.js +0 -150
  215. package/node_modules/base64-js/package.json +0 -47
  216. package/node_modules/better-sqlite3/src/better_sqlite3.hpp +0 -1036
  217. package/node_modules/bl/.travis.yml +0 -17
  218. package/node_modules/bl/BufferList.js +0 -396
  219. package/node_modules/bl/LICENSE.md +0 -13
  220. package/node_modules/bl/README.md +0 -247
  221. package/node_modules/bl/bl.js +0 -84
  222. package/node_modules/bl/package.json +0 -37
  223. package/node_modules/bl/test/convert.js +0 -21
  224. package/node_modules/bl/test/indexOf.js +0 -492
  225. package/node_modules/bl/test/isBufferList.js +0 -32
  226. package/node_modules/bl/test/test.js +0 -869
  227. package/node_modules/buffer/AUTHORS.md +0 -70
  228. package/node_modules/buffer/LICENSE +0 -21
  229. package/node_modules/buffer/README.md +0 -410
  230. package/node_modules/buffer/index.d.ts +0 -186
  231. package/node_modules/buffer/index.js +0 -1817
  232. package/node_modules/buffer/package.json +0 -96
  233. package/node_modules/chownr/LICENSE +0 -15
  234. package/node_modules/chownr/README.md +0 -3
  235. package/node_modules/chownr/chownr.js +0 -167
  236. package/node_modules/chownr/package.json +0 -29
  237. package/node_modules/fs-constants/README.md +0 -26
  238. package/node_modules/fs-constants/browser.js +0 -1
  239. package/node_modules/fs-constants/index.js +0 -1
  240. package/node_modules/fs-constants/package.json +0 -19
  241. package/node_modules/ieee754/LICENSE +0 -11
  242. package/node_modules/ieee754/README.md +0 -51
  243. package/node_modules/ieee754/index.d.ts +0 -10
  244. package/node_modules/ieee754/index.js +0 -85
  245. package/node_modules/ieee754/package.json +0 -52
  246. package/node_modules/inherits/LICENSE +0 -16
  247. package/node_modules/inherits/README.md +0 -42
  248. package/node_modules/inherits/inherits.js +0 -9
  249. package/node_modules/inherits/inherits_browser.js +0 -27
  250. package/node_modules/inherits/package.json +0 -29
  251. package/node_modules/readable-stream/CONTRIBUTING.md +0 -38
  252. package/node_modules/readable-stream/GOVERNANCE.md +0 -136
  253. package/node_modules/readable-stream/LICENSE +0 -47
  254. package/node_modules/readable-stream/README.md +0 -106
  255. package/node_modules/readable-stream/errors-browser.js +0 -127
  256. package/node_modules/readable-stream/errors.js +0 -116
  257. package/node_modules/readable-stream/experimentalWarning.js +0 -17
  258. package/node_modules/readable-stream/lib/_stream_duplex.js +0 -126
  259. package/node_modules/readable-stream/lib/_stream_passthrough.js +0 -37
  260. package/node_modules/readable-stream/lib/_stream_readable.js +0 -1027
  261. package/node_modules/readable-stream/lib/_stream_transform.js +0 -190
  262. package/node_modules/readable-stream/lib/_stream_writable.js +0 -641
  263. package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -180
  264. package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -183
  265. package/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -96
  266. package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -86
  267. package/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
  268. package/node_modules/readable-stream/lib/internal/streams/from.js +0 -52
  269. package/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -86
  270. package/node_modules/readable-stream/lib/internal/streams/state.js +0 -22
  271. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  272. package/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  273. package/node_modules/readable-stream/package.json +0 -68
  274. package/node_modules/readable-stream/readable-browser.js +0 -9
  275. package/node_modules/readable-stream/readable.js +0 -16
  276. package/node_modules/string_decoder/LICENSE +0 -48
  277. package/node_modules/string_decoder/README.md +0 -47
  278. package/node_modules/string_decoder/lib/string_decoder.js +0 -296
  279. package/node_modules/string_decoder/package.json +0 -34
  280. package/node_modules/tar-fs/.travis.yml +0 -6
  281. package/node_modules/tar-fs/test/fixtures/a/hello.txt +0 -1
  282. package/node_modules/tar-fs/test/fixtures/b/a/test.txt +0 -1
  283. package/node_modules/tar-fs/test/fixtures/d/file1 +0 -0
  284. package/node_modules/tar-fs/test/fixtures/d/file2 +0 -0
  285. package/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 +0 -0
  286. package/node_modules/tar-fs/test/fixtures/d/sub-files/file3 +0 -0
  287. package/node_modules/tar-fs/test/fixtures/d/sub-files/file4 +0 -0
  288. package/node_modules/tar-fs/test/fixtures/e/directory/.ignore +0 -0
  289. package/node_modules/tar-fs/test/fixtures/e/file +0 -0
  290. package/node_modules/tar-fs/test/fixtures/invalid.tar +0 -0
  291. package/node_modules/tar-fs/test/index.js +0 -346
  292. package/node_modules/tar-stream/sandbox.js +0 -11
  293. package/node_modules/util-deprecate/History.md +0 -16
  294. package/node_modules/util-deprecate/LICENSE +0 -24
  295. package/node_modules/util-deprecate/README.md +0 -53
  296. package/node_modules/util-deprecate/browser.js +0 -67
  297. package/node_modules/util-deprecate/node.js +0 -6
  298. package/node_modules/util-deprecate/package.json +0 -27
  299. package/test-startup.sh +0 -14
@@ -0,0 +1,355 @@
1
+ const stream = require('streamx')
2
+
3
+ const defaultEncoding = 'utf8'
4
+
5
+ module.exports = exports = stream.Stream
6
+
7
+ exports.pipeline = stream.pipeline
8
+
9
+ exports.isStream = stream.isStream
10
+ exports.isEnded = stream.isEnded
11
+ exports.isFinished = stream.isFinished
12
+ exports.isDisturbed = stream.isDisturbed
13
+
14
+ exports.getStreamError = stream.getStreamError
15
+
16
+ exports.Stream = exports
17
+
18
+ exports.Readable = class Readable extends stream.Readable {
19
+ constructor(opts = {}) {
20
+ super({
21
+ ...opts,
22
+ byteLength: null,
23
+ byteLengthReadable: null,
24
+ map: null,
25
+ mapReadable: null
26
+ })
27
+
28
+ if (this._construct) this._open = this._construct
29
+
30
+ if (this._read !== stream.Readable.prototype._read) {
31
+ this._read = read.bind(this, this._read)
32
+ }
33
+
34
+ if (this._destroy !== stream.Stream.prototype._destroy) {
35
+ this._destroy = destroy.bind(this, this._destroy)
36
+ }
37
+ }
38
+
39
+ push(chunk, encoding) {
40
+ if (typeof chunk === 'string') {
41
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
42
+ }
43
+
44
+ return super.push(chunk)
45
+ }
46
+
47
+ unshift(chunk, encoding) {
48
+ if (typeof chunk === 'string') {
49
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
50
+ }
51
+
52
+ super.unshift(chunk)
53
+ }
54
+ }
55
+
56
+ exports.Writable = class Writable extends stream.Writable {
57
+ constructor(opts = {}) {
58
+ super({
59
+ ...opts,
60
+ byteLength: null,
61
+ byteLengthWritable,
62
+ map: null,
63
+ mapWritable: null
64
+ })
65
+
66
+ if (this._construct) this._open = this._construct
67
+
68
+ if (this._write !== stream.Writable.prototype._write) {
69
+ this._write = write.bind(this, this._write)
70
+ }
71
+
72
+ if (this._destroy !== stream.Stream.prototype._destroy) {
73
+ this._destroy = destroy.bind(this, this._destroy)
74
+ }
75
+ }
76
+
77
+ write(chunk, encoding, cb) {
78
+ if (typeof encoding === 'function') {
79
+ cb = encoding
80
+ encoding = null
81
+ }
82
+
83
+ if (typeof chunk === 'string') {
84
+ encoding = encoding || defaultEncoding
85
+ chunk = Buffer.from(chunk, encoding)
86
+ } else {
87
+ encoding = 'buffer'
88
+ }
89
+
90
+ const result = super.write({ chunk, encoding })
91
+
92
+ if (cb) stream.Writable.drained(this).then(() => cb(null), cb)
93
+
94
+ return result
95
+ }
96
+
97
+ end(chunk, encoding, cb) {
98
+ if (typeof chunk === 'function') {
99
+ cb = chunk
100
+ chunk = null
101
+ } else if (typeof encoding === 'function') {
102
+ cb = encoding
103
+ encoding = null
104
+ }
105
+
106
+ if (typeof chunk === 'string') {
107
+ encoding = encoding || defaultEncoding
108
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
109
+ } else {
110
+ encoding = 'buffer'
111
+ }
112
+
113
+ const result =
114
+ chunk !== undefined && chunk !== null
115
+ ? super.end({ chunk, encoding })
116
+ : super.end()
117
+
118
+ if (cb) this.once('finish', () => cb(null))
119
+
120
+ return result
121
+ }
122
+ }
123
+
124
+ exports.Duplex = class Duplex extends stream.Duplex {
125
+ constructor(opts = {}) {
126
+ super({
127
+ ...opts,
128
+ byteLength: null,
129
+ byteLengthReadable: null,
130
+ byteLengthWritable,
131
+ map: null,
132
+ mapReadable: null,
133
+ mapWritable: null
134
+ })
135
+
136
+ if (this._construct) this._open = this._construct
137
+
138
+ if (this._read !== stream.Readable.prototype._read) {
139
+ this._read = read.bind(this, this._read)
140
+ }
141
+
142
+ if (this._write !== stream.Duplex.prototype._write) {
143
+ this._write = write.bind(this, this._write)
144
+ }
145
+
146
+ if (this._destroy !== stream.Stream.prototype._destroy) {
147
+ this._destroy = destroy.bind(this, this._destroy)
148
+ }
149
+ }
150
+
151
+ push(chunk, encoding) {
152
+ if (typeof chunk === 'string') {
153
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
154
+ }
155
+
156
+ return super.push(chunk)
157
+ }
158
+
159
+ unshift(chunk, encoding) {
160
+ if (typeof chunk === 'string') {
161
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
162
+ }
163
+
164
+ super.unshift(chunk)
165
+ }
166
+
167
+ write(chunk, encoding, cb) {
168
+ if (typeof encoding === 'function') {
169
+ cb = encoding
170
+ encoding = null
171
+ }
172
+
173
+ if (typeof chunk === 'string') {
174
+ encoding = encoding || defaultEncoding
175
+ chunk = Buffer.from(chunk, encoding)
176
+ } else {
177
+ encoding = 'buffer'
178
+ }
179
+
180
+ const result = super.write({ chunk, encoding })
181
+
182
+ if (cb) stream.Writable.drained(this).then(() => cb(null), cb)
183
+
184
+ return result
185
+ }
186
+
187
+ end(chunk, encoding, cb) {
188
+ if (typeof chunk === 'function') {
189
+ cb = chunk
190
+ chunk = null
191
+ } else if (typeof encoding === 'function') {
192
+ cb = encoding
193
+ encoding = null
194
+ }
195
+
196
+ if (typeof chunk === 'string') {
197
+ encoding = encoding || defaultEncoding
198
+ chunk = Buffer.from(chunk, encoding)
199
+ } else {
200
+ encoding = 'buffer'
201
+ }
202
+
203
+ const result =
204
+ chunk !== undefined && chunk !== null
205
+ ? super.end({ chunk, encoding })
206
+ : super.end()
207
+
208
+ if (cb) this.once('finish', () => cb(null))
209
+
210
+ return result
211
+ }
212
+ }
213
+
214
+ exports.Transform = class Transform extends stream.Transform {
215
+ constructor(opts = {}) {
216
+ super({
217
+ ...opts,
218
+ byteLength: null,
219
+ byteLengthReadable: null,
220
+ byteLengthWritable,
221
+ map: null,
222
+ mapReadable: null,
223
+ mapWritable: null
224
+ })
225
+
226
+ if (this._transform !== stream.Transform.prototype._transform) {
227
+ this._transform = transform.bind(this, this._transform)
228
+ } else {
229
+ this._transform = passthrough
230
+ }
231
+ }
232
+
233
+ push(chunk, encoding) {
234
+ if (typeof chunk === 'string') {
235
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
236
+ }
237
+
238
+ return super.push(chunk)
239
+ }
240
+
241
+ unshift(chunk, encoding) {
242
+ if (typeof chunk === 'string') {
243
+ chunk = Buffer.from(chunk, encoding || defaultEncoding)
244
+ }
245
+
246
+ super.unshift(chunk)
247
+ }
248
+
249
+ write(chunk, encoding, cb) {
250
+ if (typeof encoding === 'function') {
251
+ cb = encoding
252
+ encoding = null
253
+ }
254
+
255
+ if (typeof chunk === 'string') {
256
+ encoding = encoding || defaultEncoding
257
+ chunk = Buffer.from(chunk, encoding)
258
+ } else {
259
+ encoding = 'buffer'
260
+ }
261
+
262
+ const result = super.write({ chunk, encoding })
263
+
264
+ if (cb) stream.Writable.drained(this).then(() => cb(null), cb)
265
+
266
+ return result
267
+ }
268
+
269
+ end(chunk, encoding, cb) {
270
+ if (typeof chunk === 'function') {
271
+ cb = chunk
272
+ chunk = null
273
+ } else if (typeof encoding === 'function') {
274
+ cb = encoding
275
+ encoding = null
276
+ }
277
+
278
+ if (typeof chunk === 'string') {
279
+ encoding = encoding || defaultEncoding
280
+ chunk = Buffer.from(chunk, encoding)
281
+ } else {
282
+ encoding = 'buffer'
283
+ }
284
+
285
+ const result =
286
+ chunk !== undefined && chunk !== null
287
+ ? super.end({ chunk, encoding })
288
+ : super.end()
289
+
290
+ if (cb) this.once('finish', () => cb(null))
291
+
292
+ return result
293
+ }
294
+ }
295
+
296
+ exports.PassThrough = class PassThrough extends exports.Transform {}
297
+
298
+ exports.finished = function finished(stream, opts, cb) {
299
+ if (typeof opts === 'function') {
300
+ cb = opts
301
+ opts = {}
302
+ }
303
+
304
+ if (!opts) opts = {}
305
+
306
+ const { cleanup = false } = opts
307
+
308
+ const done = () => {
309
+ cb(exports.getStreamError(stream, { all: true }))
310
+
311
+ if (cleanup) detach()
312
+ }
313
+
314
+ const detach = () => {
315
+ stream.off('close', done)
316
+ stream.off('error', noop)
317
+ }
318
+
319
+ if (stream.destroyed) {
320
+ done()
321
+ } else {
322
+ stream.on('close', done)
323
+ stream.on('error', noop)
324
+ }
325
+
326
+ return detach
327
+ }
328
+
329
+ function read(read, cb) {
330
+ read.call(this, 65536)
331
+
332
+ cb(null)
333
+ }
334
+
335
+ function write(write, data, cb) {
336
+ write.call(this, data.chunk, data.encoding, cb)
337
+ }
338
+
339
+ function transform(transform, data, cb) {
340
+ transform.call(this, data.chunk, data.encoding, cb)
341
+ }
342
+
343
+ function destroy(destroy, cb) {
344
+ destroy.call(this, exports.getStreamError(this), cb)
345
+ }
346
+
347
+ function passthrough(data, cb) {
348
+ cb(null, data.chunk)
349
+ }
350
+
351
+ function byteLengthWritable(data) {
352
+ return data.chunk.byteLength
353
+ }
354
+
355
+ function noop() {}
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "bare-stream",
3
+ "version": "2.7.0",
4
+ "description": "Streaming data for JavaScript",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./index.d.ts",
8
+ "default": "./index.js"
9
+ },
10
+ "./package": "./package.json",
11
+ "./promises": "./promises.js",
12
+ "./web": {
13
+ "types": "./web.d.ts",
14
+ "default": "./web.js"
15
+ },
16
+ "./global": "./global.js"
17
+ },
18
+ "files": [
19
+ "index.js",
20
+ "index.d.ts",
21
+ "promises.js",
22
+ "web.js",
23
+ "web.d.ts",
24
+ "global.js"
25
+ ],
26
+ "scripts": {
27
+ "test": "prettier . --check && bare test.js"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/holepunchto/bare-stream.git"
32
+ },
33
+ "author": "Holepunch",
34
+ "license": "Apache-2.0",
35
+ "bugs": {
36
+ "url": "https://github.com/holepunchto/bare-stream/issues"
37
+ },
38
+ "homepage": "https://github.com/holepunchto/bare-stream#readme",
39
+ "dependencies": {
40
+ "streamx": "^2.21.0"
41
+ },
42
+ "devDependencies": {
43
+ "bare-buffer": "^3.0.0",
44
+ "bare-events": "^2.5.4",
45
+ "brittle": "^3.5.2",
46
+ "prettier": "^3.3.3",
47
+ "prettier-config-standard": "^7.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "bare-buffer": "*",
51
+ "bare-events": "*"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "bare-buffer": {
55
+ "optional": true
56
+ },
57
+ "bare-events": {
58
+ "optional": true
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,3 @@
1
+ const stream = require('streamx')
2
+
3
+ exports.pipeline = stream.pipelinePromise
@@ -0,0 +1,73 @@
1
+ import { Writable } from '.'
2
+
3
+ export interface ReadableStreamDefaultReader {
4
+ read(): Promise<{ value: unknown; done: boolean }>
5
+ cancel(reason?: unknown): Promise<void>
6
+ }
7
+
8
+ export class ReadableStreamDefaultReader {
9
+ constructor(stream: ReadableStream)
10
+ }
11
+
12
+ export interface ReadableStreamDefaultController {
13
+ readonly desiredSize: number
14
+
15
+ enqueue(data: unknown): void
16
+ close(): void
17
+ error(error?: unknown): void
18
+ }
19
+
20
+ export class ReadableStreamDefaultController {
21
+ constructor(stream: ReadableStream)
22
+ }
23
+
24
+ export interface UnderlyingSource<S extends ReadableStream = ReadableStream> {
25
+ start?(this: S, controller: ReadableStreamDefaultController): void
26
+ pull?(this: S, controller: ReadableStreamDefaultController): void
27
+ }
28
+
29
+ export interface CustomQueuingStrategy {
30
+ highWaterMark?: number
31
+ size?: (chunk: unknown) => number
32
+ }
33
+
34
+ export interface ReadableStream extends AsyncIterable<unknown> {
35
+ getReader(): ReadableStreamDefaultReader
36
+ cancel(reason?: unknown): Promise<void>
37
+ pipeTo(destination: Writable): Promise<void>
38
+ }
39
+
40
+ export class ReadableStream {
41
+ constructor(
42
+ underlyingSource?: UnderlyingSource,
43
+ queuingStrategy?: CustomQueuingStrategy
44
+ )
45
+
46
+ static from(
47
+ iterable: unknown | unknown[] | AsyncIterable<unknown>
48
+ ): ReadableStream
49
+ }
50
+
51
+ export interface QueuingStrategyOptions {
52
+ highWaterMark?: number
53
+ }
54
+
55
+ interface QueuingStrategy {
56
+ readonly highWaterMark: number
57
+
58
+ size(chunk: unknown): number
59
+ }
60
+
61
+ declare class QueuingStrategy {
62
+ constructor(opts?: QueuingStrategyOptions)
63
+ }
64
+
65
+ export { type QueuingStrategy }
66
+
67
+ export class CountQueuingStrategy extends QueuingStrategy {}
68
+
69
+ export class ByteLengthQueuingStrategy extends QueuingStrategy {}
70
+
71
+ export function isReadableStream(value: unknown): value is ReadableStream
72
+
73
+ export function isReadableStreamDisturbed(stream: ReadableStream): boolean
@@ -0,0 +1,229 @@
1
+ const { Readable, getStreamError, isStreamx, isDisturbed } = require('streamx')
2
+
3
+ const readableKind = Symbol.for('bare.stream.readable.kind')
4
+
5
+ // https://streams.spec.whatwg.org/#readablestreamdefaultreader
6
+ exports.ReadableStreamDefaultReader = class ReadableStreamDefaultReader {
7
+ constructor(stream) {
8
+ this._stream = stream._stream
9
+ }
10
+
11
+ read() {
12
+ const stream = this._stream
13
+
14
+ return new Promise((resolve, reject) => {
15
+ const err = getStreamError(stream)
16
+
17
+ if (err) return reject(err)
18
+
19
+ if (stream.destroyed) {
20
+ return resolve({ value: undefined, done: true })
21
+ }
22
+
23
+ const value = stream.read()
24
+
25
+ if (value !== null) {
26
+ return resolve({ value, done: false })
27
+ }
28
+
29
+ stream
30
+ .once('readable', onreadable)
31
+ .once('close', onclose)
32
+ .once('error', onerror)
33
+
34
+ function onreadable() {
35
+ const value = stream.read()
36
+
37
+ ondone(
38
+ null,
39
+ value === null
40
+ ? { value: undefined, done: true }
41
+ : { value, done: false }
42
+ )
43
+ }
44
+
45
+ function onclose() {
46
+ ondone(null, { value: undefined, done: true })
47
+ }
48
+
49
+ function onerror(err) {
50
+ ondone(err, null)
51
+ }
52
+
53
+ function ondone(err, value) {
54
+ stream
55
+ .off('readable', onreadable)
56
+ .off('close', onclose)
57
+ .off('error', onerror)
58
+
59
+ if (err) reject(err)
60
+ else resolve(value)
61
+ }
62
+ })
63
+ }
64
+
65
+ cancel(reason) {
66
+ if (this._stream.destroyed) return Promise.resolve()
67
+
68
+ return new Promise((resolve) =>
69
+ this._stream.once('close', resolve).destroy(reason)
70
+ )
71
+ }
72
+ }
73
+
74
+ // https://streams.spec.whatwg.org/#readablestreamdefaultcontroller
75
+ exports.ReadableStreamDefaultController = class ReadableStreamDefaultController {
76
+ constructor(stream) {
77
+ this._stream = stream._stream
78
+ }
79
+
80
+ get desiredSize() {
81
+ return (
82
+ this._stream._readableState.highWaterMark -
83
+ this._stream._readableState.buffered
84
+ )
85
+ }
86
+
87
+ enqueue(data) {
88
+ this._stream.push(data)
89
+ }
90
+
91
+ close() {
92
+ this._stream.push(null)
93
+ }
94
+
95
+ error(err) {
96
+ this._stream.destroy(err)
97
+ }
98
+ }
99
+
100
+ // https://streams.spec.whatwg.org/#readablestream
101
+ class ReadableStream {
102
+ static get [readableKind]() {
103
+ return 0 // Compatibility version
104
+ }
105
+
106
+ constructor(underlyingSource = {}, queuingStrategy) {
107
+ if (isStreamx(underlyingSource)) {
108
+ this._stream = underlyingSource
109
+ } else {
110
+ if (queuingStrategy === undefined) {
111
+ queuingStrategy = new exports.CountQueuingStrategy()
112
+ }
113
+
114
+ const { start, pull } = underlyingSource
115
+ const { highWaterMark = 1, size = defaultSize } = queuingStrategy
116
+
117
+ this._stream = new Readable({ highWaterMark, byteLength: size })
118
+
119
+ const controller = new exports.ReadableStreamDefaultController(this)
120
+
121
+ if (start) {
122
+ this._stream._open = open.bind(this, start.call(this, controller))
123
+ }
124
+
125
+ if (pull) {
126
+ this._stream._read = read.bind(this, pull.bind(this, controller))
127
+ }
128
+ }
129
+ }
130
+
131
+ get [readableKind]() {
132
+ return ReadableStream[readableKind]
133
+ }
134
+
135
+ getReader() {
136
+ return new exports.ReadableStreamDefaultReader(this)
137
+ }
138
+
139
+ cancel(reason) {
140
+ if (this._stream.destroyed) return Promise.resolve()
141
+
142
+ return new Promise((resolve) =>
143
+ this._stream.once('close', resolve).destroy(reason)
144
+ )
145
+ }
146
+
147
+ pipeTo(destination) {
148
+ return new Promise((resolve, reject) =>
149
+ this._stream.pipe(destination, (err) => {
150
+ err ? reject(err) : resolve()
151
+ })
152
+ )
153
+ }
154
+
155
+ [Symbol.asyncIterator]() {
156
+ return this._stream[Symbol.asyncIterator]()
157
+ }
158
+
159
+ static from(iterable) {
160
+ return new ReadableStream(Readable.from(iterable))
161
+ }
162
+ }
163
+
164
+ async function open(starting, cb) {
165
+ try {
166
+ await starting
167
+
168
+ cb(null)
169
+ } catch (err) {
170
+ cb(err)
171
+ }
172
+ }
173
+
174
+ async function read(pull, cb) {
175
+ try {
176
+ await pull()
177
+
178
+ cb(null)
179
+ } catch (err) {
180
+ cb(err)
181
+ }
182
+ }
183
+
184
+ function defaultSize() {
185
+ return 1
186
+ }
187
+
188
+ exports.ReadableStream = ReadableStream
189
+
190
+ // https://streams.spec.whatwg.org/#countqueuingstrategy
191
+ exports.CountQueuingStrategy = class CountQueuingStrategy {
192
+ constructor(opts = {}) {
193
+ const { highWaterMark = 1 } = opts
194
+
195
+ this.highWaterMark = highWaterMark
196
+ }
197
+
198
+ size(chunk) {
199
+ return 1
200
+ }
201
+ }
202
+
203
+ // https://streams.spec.whatwg.org/#bytelengthqueuingstrategy
204
+ exports.ByteLengthQueuingStrategy = class ByteLengthQueuingStrategy {
205
+ constructor(opts = {}) {
206
+ const { highWaterMark = 16384 } = opts
207
+
208
+ this.highWaterMark = highWaterMark
209
+ }
210
+
211
+ size(chunk) {
212
+ return chunk.byteLength
213
+ }
214
+ }
215
+
216
+ exports.isReadableStream = function isReadableStream(value) {
217
+ if (value instanceof ReadableStream) return true
218
+
219
+ return (
220
+ typeof value === 'object' &&
221
+ value !== null &&
222
+ value[readableKind] === ReadableStream[readableKind]
223
+ )
224
+ }
225
+
226
+ // https://streams.spec.whatwg.org/#is-readable-stream-disturbed
227
+ exports.isReadableStreamDisturbed = function isReadableStreamDisturbed(stream) {
228
+ return isDisturbed(stream._stream)
229
+ }