typenative 0.1.3 → 0.2.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 (500) hide show
  1. package/.gitattributes +1 -0
  2. package/.github/workflows/ci.yml +1 -1
  3. package/.github/workflows/npm-publish-github-packages.yml +1 -1
  4. package/CHANGELOG.md +247 -0
  5. package/CONTRIBUTION.md +1 -1
  6. package/README.md +4 -4
  7. package/bin/cli.js +3 -1
  8. package/bin/go/bridge.js +919 -0
  9. package/bin/go/convert.js +238 -0
  10. package/bin/go/metadata.js +211 -0
  11. package/bin/go/overrides.js +68 -0
  12. package/bin/go/stdlib.generated.js +175 -0
  13. package/bin/index.js +294 -240
  14. package/bin/main.js +4 -1
  15. package/bin/node/assert.js +344 -0
  16. package/bin/node/async_hooks.js +273 -0
  17. package/bin/node/buffer.js +765 -0
  18. package/bin/node/child_process.js +600 -0
  19. package/bin/node/cluster.js +1002 -0
  20. package/bin/node/console.js +121 -0
  21. package/bin/node/core.js +111 -0
  22. package/bin/node/crypto.js +414 -0
  23. package/bin/node/crypto_keys.js +2685 -0
  24. package/bin/node/dgram.js +388 -0
  25. package/bin/node/diagnostics_channel.js +534 -0
  26. package/bin/node/dns.js +635 -0
  27. package/bin/node/events.js +743 -0
  28. package/bin/node/fetch.js +737 -0
  29. package/bin/node/fs.js +998 -0
  30. package/bin/node/http.js +1500 -0
  31. package/bin/node/http2.js +688 -0
  32. package/bin/node/net.js +1143 -0
  33. package/bin/node/os.js +257 -0
  34. package/bin/node/path.js +758 -0
  35. package/bin/node/process.js +316 -0
  36. package/bin/node/punycode.js +195 -0
  37. package/bin/node/querystring.js +143 -0
  38. package/bin/node/readline.js +299 -0
  39. package/bin/node/registry.js +161 -0
  40. package/bin/node/sqlite.js +1142 -0
  41. package/bin/node/stream.js +1221 -0
  42. package/bin/node/stream_web.js +2259 -0
  43. package/bin/node/string_decoder.js +101 -0
  44. package/bin/node/system_extra.js +661 -0
  45. package/bin/node/test.js +1068 -0
  46. package/bin/node/timers.js +250 -0
  47. package/bin/node/tls.js +719 -0
  48. package/bin/node/url.js +861 -0
  49. package/bin/node/util.js +1311 -0
  50. package/bin/node/util_extra.js +599 -0
  51. package/bin/node/worker_threads.js +745 -0
  52. package/bin/node/zlib.js +263 -0
  53. package/bin/transpiler.js +2650 -575
  54. package/bin/version.js +2 -0
  55. package/conformance.md +707 -241
  56. package/govendor/github.com/ncruces/go-sqlite3/LICENSE +21 -0
  57. package/govendor/github.com/ncruces/go-sqlite3/README.md +121 -0
  58. package/govendor/github.com/ncruces/go-sqlite3/backup.go +132 -0
  59. package/govendor/github.com/ncruces/go-sqlite3/blob.go +266 -0
  60. package/govendor/github.com/ncruces/go-sqlite3/config.go +397 -0
  61. package/govendor/github.com/ncruces/go-sqlite3/conn.go +540 -0
  62. package/govendor/github.com/ncruces/go-sqlite3/conn_127.go +93 -0
  63. package/govendor/github.com/ncruces/go-sqlite3/const.go +436 -0
  64. package/govendor/github.com/ncruces/go-sqlite3/context.go +222 -0
  65. package/govendor/github.com/ncruces/go-sqlite3/error.go +182 -0
  66. package/govendor/github.com/ncruces/go-sqlite3/ext.go +153 -0
  67. package/govendor/github.com/ncruces/go-sqlite3/func.go +309 -0
  68. package/govendor/github.com/ncruces/go-sqlite3/go.mod +3 -0
  69. package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk.go +29 -0
  70. package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk_other.go +13 -0
  71. package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk_unix.go +57 -0
  72. package/govendor/github.com/ncruces/go-sqlite3/internal/errutil/error.go +41 -0
  73. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/alloc.go +128 -0
  74. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/const.go +122 -0
  75. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/error.go +77 -0
  76. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem.go +116 -0
  77. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_other.go +34 -0
  78. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_unix.go +87 -0
  79. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_windows.go +149 -0
  80. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mmap_unix.go +80 -0
  81. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mmap_windows.go +129 -0
  82. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/sys_windows.go +60 -0
  83. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap.go +82 -0
  84. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap_sys.go +113 -0
  85. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap_vfs.go +181 -0
  86. package/govendor/github.com/ncruces/go-sqlite3/internal/testenv/env.go +55 -0
  87. package/govendor/github.com/ncruces/go-sqlite3/internal/util/json.go +54 -0
  88. package/govendor/github.com/ncruces/go-sqlite3/internal/util/json_v2.go +54 -0
  89. package/govendor/github.com/ncruces/go-sqlite3/internal/util/math.go +29 -0
  90. package/govendor/github.com/ncruces/go-sqlite3/internal/util/page.go +5 -0
  91. package/govendor/github.com/ncruces/go-sqlite3/internal/util/parse.go +142 -0
  92. package/govendor/github.com/ncruces/go-sqlite3/internal/util/pointer.go +3 -0
  93. package/govendor/github.com/ncruces/go-sqlite3/internal/util/reflect.go +10 -0
  94. package/govendor/github.com/ncruces/go-sqlite3/json.go +100 -0
  95. package/govendor/github.com/ncruces/go-sqlite3/json_v2.go +116 -0
  96. package/govendor/github.com/ncruces/go-sqlite3/pointer.go +13 -0
  97. package/govendor/github.com/ncruces/go-sqlite3/quote.go +140 -0
  98. package/govendor/github.com/ncruces/go-sqlite3/stmt.go +692 -0
  99. package/govendor/github.com/ncruces/go-sqlite3/time.go +360 -0
  100. package/govendor/github.com/ncruces/go-sqlite3/txn.go +374 -0
  101. package/govendor/github.com/ncruces/go-sqlite3/value.go +212 -0
  102. package/govendor/github.com/ncruces/go-sqlite3/vfs/README.md +133 -0
  103. package/govendor/github.com/ncruces/go-sqlite3/vfs/api.go +239 -0
  104. package/govendor/github.com/ncruces/go-sqlite3/vfs/cksm.go +143 -0
  105. package/govendor/github.com/ncruces/go-sqlite3/vfs/const.go +256 -0
  106. package/govendor/github.com/ncruces/go-sqlite3/vfs/file.go +260 -0
  107. package/govendor/github.com/ncruces/go-sqlite3/vfs/filename.go +187 -0
  108. package/govendor/github.com/ncruces/go-sqlite3/vfs/lock.go +128 -0
  109. package/govendor/github.com/ncruces/go-sqlite3/vfs/lock_other.go +23 -0
  110. package/govendor/github.com/ncruces/go-sqlite3/vfs/map.go +63 -0
  111. package/govendor/github.com/ncruces/go-sqlite3/vfs/map_other.go +13 -0
  112. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go +110 -0
  113. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go +131 -0
  114. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_dotlk.go +140 -0
  115. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go +56 -0
  116. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_linux.go +117 -0
  117. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_ofd.go +59 -0
  118. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std.go +50 -0
  119. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_alloc.go +19 -0
  120. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_atomic.go +9 -0
  121. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_rw.go +13 -0
  122. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_sync.go +9 -0
  123. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_temp.go +16 -0
  124. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_unix.go +108 -0
  125. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go +180 -0
  126. package/govendor/github.com/ncruces/go-sqlite3/vfs/registry.go +48 -0
  127. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm.go +26 -0
  128. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go +258 -0
  129. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_copy.go +90 -0
  130. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_dotlk.go +168 -0
  131. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_memlk.go +52 -0
  132. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_ofd.go +185 -0
  133. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_other.go +21 -0
  134. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_windows.go +124 -0
  135. package/govendor/github.com/ncruces/go-sqlite3/vfs/vfs.go +455 -0
  136. package/govendor/github.com/ncruces/go-sqlite3/vtab.go +677 -0
  137. package/govendor/github.com/ncruces/go-sqlite3/wrap.go +48 -0
  138. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/LICENSE +18 -0
  139. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/README.md +11 -0
  140. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/go.mod +3 -0
  141. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/libc.go +215 -0
  142. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/sqlite3.dat +0 -0
  143. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/sqlite3.go +157903 -0
  144. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/tools.sh +38 -0
  145. package/govendor/github.com/ncruces/julianday/LICENSE +21 -0
  146. package/govendor/github.com/ncruces/julianday/README.md +9 -0
  147. package/govendor/github.com/ncruces/julianday/go.mod +3 -0
  148. package/govendor/github.com/ncruces/julianday/julianday.go +124 -0
  149. package/govendor/golang.org/x/sys/LICENSE +27 -0
  150. package/govendor/golang.org/x/sys/PATENTS +22 -0
  151. package/govendor/golang.org/x/sys/go.mod +3 -0
  152. package/govendor/golang.org/x/sys/unix/README.md +184 -0
  153. package/govendor/golang.org/x/sys/unix/affinity_linux.go +189 -0
  154. package/govendor/golang.org/x/sys/unix/aliases.go +13 -0
  155. package/govendor/golang.org/x/sys/unix/asm_aix_ppc64.s +17 -0
  156. package/govendor/golang.org/x/sys/unix/asm_bsd_386.s +27 -0
  157. package/govendor/golang.org/x/sys/unix/asm_bsd_amd64.s +27 -0
  158. package/govendor/golang.org/x/sys/unix/asm_bsd_arm.s +27 -0
  159. package/govendor/golang.org/x/sys/unix/asm_bsd_arm64.s +27 -0
  160. package/govendor/golang.org/x/sys/unix/asm_bsd_ppc64.s +29 -0
  161. package/govendor/golang.org/x/sys/unix/asm_bsd_riscv64.s +27 -0
  162. package/govendor/golang.org/x/sys/unix/asm_linux_386.s +65 -0
  163. package/govendor/golang.org/x/sys/unix/asm_linux_amd64.s +57 -0
  164. package/govendor/golang.org/x/sys/unix/asm_linux_arm.s +56 -0
  165. package/govendor/golang.org/x/sys/unix/asm_linux_arm64.s +50 -0
  166. package/govendor/golang.org/x/sys/unix/asm_linux_loong64.s +51 -0
  167. package/govendor/golang.org/x/sys/unix/asm_linux_mips64x.s +54 -0
  168. package/govendor/golang.org/x/sys/unix/asm_linux_mipsx.s +52 -0
  169. package/govendor/golang.org/x/sys/unix/asm_linux_ppc64x.s +42 -0
  170. package/govendor/golang.org/x/sys/unix/asm_linux_riscv64.s +47 -0
  171. package/govendor/golang.org/x/sys/unix/asm_linux_s390x.s +54 -0
  172. package/govendor/golang.org/x/sys/unix/asm_openbsd_mips64.s +29 -0
  173. package/govendor/golang.org/x/sys/unix/asm_solaris_amd64.s +17 -0
  174. package/govendor/golang.org/x/sys/unix/asm_zos_s390x.s +382 -0
  175. package/govendor/golang.org/x/sys/unix/auxv.go +36 -0
  176. package/govendor/golang.org/x/sys/unix/auxv_unsupported.go +13 -0
  177. package/govendor/golang.org/x/sys/unix/bluetooth_linux.go +36 -0
  178. package/govendor/golang.org/x/sys/unix/bpxsvc_zos.go +657 -0
  179. package/govendor/golang.org/x/sys/unix/bpxsvc_zos.s +192 -0
  180. package/govendor/golang.org/x/sys/unix/cap_freebsd.go +195 -0
  181. package/govendor/golang.org/x/sys/unix/constants.go +13 -0
  182. package/govendor/golang.org/x/sys/unix/dev_aix_ppc.go +26 -0
  183. package/govendor/golang.org/x/sys/unix/dev_aix_ppc64.go +28 -0
  184. package/govendor/golang.org/x/sys/unix/dev_darwin.go +24 -0
  185. package/govendor/golang.org/x/sys/unix/dev_dragonfly.go +30 -0
  186. package/govendor/golang.org/x/sys/unix/dev_freebsd.go +30 -0
  187. package/govendor/golang.org/x/sys/unix/dev_linux.go +42 -0
  188. package/govendor/golang.org/x/sys/unix/dev_netbsd.go +29 -0
  189. package/govendor/golang.org/x/sys/unix/dev_openbsd.go +29 -0
  190. package/govendor/golang.org/x/sys/unix/dev_zos.go +28 -0
  191. package/govendor/golang.org/x/sys/unix/dirent.go +102 -0
  192. package/govendor/golang.org/x/sys/unix/endian_big.go +9 -0
  193. package/govendor/golang.org/x/sys/unix/endian_little.go +9 -0
  194. package/govendor/golang.org/x/sys/unix/env_unix.go +31 -0
  195. package/govendor/golang.org/x/sys/unix/fcntl.go +36 -0
  196. package/govendor/golang.org/x/sys/unix/fcntl_darwin.go +24 -0
  197. package/govendor/golang.org/x/sys/unix/fcntl_linux_32bit.go +13 -0
  198. package/govendor/golang.org/x/sys/unix/fdset.go +27 -0
  199. package/govendor/golang.org/x/sys/unix/gccgo.go +59 -0
  200. package/govendor/golang.org/x/sys/unix/gccgo_c.c +44 -0
  201. package/govendor/golang.org/x/sys/unix/gccgo_linux_amd64.go +20 -0
  202. package/govendor/golang.org/x/sys/unix/ifreq_linux.go +145 -0
  203. package/govendor/golang.org/x/sys/unix/ioctl_linux.go +341 -0
  204. package/govendor/golang.org/x/sys/unix/ioctl_signed.go +74 -0
  205. package/govendor/golang.org/x/sys/unix/ioctl_unsigned.go +74 -0
  206. package/govendor/golang.org/x/sys/unix/ioctl_zos.go +71 -0
  207. package/govendor/golang.org/x/sys/unix/mkall.sh +250 -0
  208. package/govendor/golang.org/x/sys/unix/mkerrors.sh +807 -0
  209. package/govendor/golang.org/x/sys/unix/mmap_nomremap.go +13 -0
  210. package/govendor/golang.org/x/sys/unix/mremap.go +57 -0
  211. package/govendor/golang.org/x/sys/unix/pagesize_unix.go +15 -0
  212. package/govendor/golang.org/x/sys/unix/pledge_openbsd.go +111 -0
  213. package/govendor/golang.org/x/sys/unix/ptrace_darwin.go +11 -0
  214. package/govendor/golang.org/x/sys/unix/ptrace_ios.go +11 -0
  215. package/govendor/golang.org/x/sys/unix/race.go +30 -0
  216. package/govendor/golang.org/x/sys/unix/race0.go +25 -0
  217. package/govendor/golang.org/x/sys/unix/readdirent_getdents.go +12 -0
  218. package/govendor/golang.org/x/sys/unix/readdirent_getdirentries.go +19 -0
  219. package/govendor/golang.org/x/sys/unix/readv_unix.go +103 -0
  220. package/govendor/golang.org/x/sys/unix/sockcmsg_dragonfly.go +16 -0
  221. package/govendor/golang.org/x/sys/unix/sockcmsg_linux.go +85 -0
  222. package/govendor/golang.org/x/sys/unix/sockcmsg_unix.go +106 -0
  223. package/govendor/golang.org/x/sys/unix/sockcmsg_unix_other.go +46 -0
  224. package/govendor/golang.org/x/sys/unix/sockcmsg_zos.go +58 -0
  225. package/govendor/golang.org/x/sys/unix/symaddr_zos_s390x.s +75 -0
  226. package/govendor/golang.org/x/sys/unix/syscall.go +86 -0
  227. package/govendor/golang.org/x/sys/unix/syscall_aix.go +582 -0
  228. package/govendor/golang.org/x/sys/unix/syscall_aix_ppc.go +52 -0
  229. package/govendor/golang.org/x/sys/unix/syscall_aix_ppc64.go +83 -0
  230. package/govendor/golang.org/x/sys/unix/syscall_bsd.go +609 -0
  231. package/govendor/golang.org/x/sys/unix/syscall_darwin.go +711 -0
  232. package/govendor/golang.org/x/sys/unix/syscall_darwin_amd64.go +50 -0
  233. package/govendor/golang.org/x/sys/unix/syscall_darwin_arm64.go +50 -0
  234. package/govendor/golang.org/x/sys/unix/syscall_darwin_libSystem.go +26 -0
  235. package/govendor/golang.org/x/sys/unix/syscall_dragonfly.go +359 -0
  236. package/govendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go +56 -0
  237. package/govendor/golang.org/x/sys/unix/syscall_freebsd.go +455 -0
  238. package/govendor/golang.org/x/sys/unix/syscall_freebsd_386.go +64 -0
  239. package/govendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go +64 -0
  240. package/govendor/golang.org/x/sys/unix/syscall_freebsd_arm.go +60 -0
  241. package/govendor/golang.org/x/sys/unix/syscall_freebsd_arm64.go +60 -0
  242. package/govendor/golang.org/x/sys/unix/syscall_freebsd_riscv64.go +60 -0
  243. package/govendor/golang.org/x/sys/unix/syscall_hurd.go +30 -0
  244. package/govendor/golang.org/x/sys/unix/syscall_hurd_386.go +28 -0
  245. package/govendor/golang.org/x/sys/unix/syscall_illumos.go +78 -0
  246. package/govendor/golang.org/x/sys/unix/syscall_linux.go +2574 -0
  247. package/govendor/golang.org/x/sys/unix/syscall_linux_386.go +313 -0
  248. package/govendor/golang.org/x/sys/unix/syscall_linux_alarm.go +12 -0
  249. package/govendor/golang.org/x/sys/unix/syscall_linux_amd64.go +144 -0
  250. package/govendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go +12 -0
  251. package/govendor/golang.org/x/sys/unix/syscall_linux_arm.go +218 -0
  252. package/govendor/golang.org/x/sys/unix/syscall_linux_arm64.go +188 -0
  253. package/govendor/golang.org/x/sys/unix/syscall_linux_gc.go +14 -0
  254. package/govendor/golang.org/x/sys/unix/syscall_linux_gc_386.go +16 -0
  255. package/govendor/golang.org/x/sys/unix/syscall_linux_gc_arm.go +13 -0
  256. package/govendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go +30 -0
  257. package/govendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go +20 -0
  258. package/govendor/golang.org/x/sys/unix/syscall_linux_loong64.go +220 -0
  259. package/govendor/golang.org/x/sys/unix/syscall_linux_mips64x.go +187 -0
  260. package/govendor/golang.org/x/sys/unix/syscall_linux_mipsx.go +173 -0
  261. package/govendor/golang.org/x/sys/unix/syscall_linux_ppc.go +203 -0
  262. package/govendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go +114 -0
  263. package/govendor/golang.org/x/sys/unix/syscall_linux_riscv64.go +193 -0
  264. package/govendor/golang.org/x/sys/unix/syscall_linux_s390x.go +295 -0
  265. package/govendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +111 -0
  266. package/govendor/golang.org/x/sys/unix/syscall_netbsd.go +388 -0
  267. package/govendor/golang.org/x/sys/unix/syscall_netbsd_386.go +37 -0
  268. package/govendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go +37 -0
  269. package/govendor/golang.org/x/sys/unix/syscall_netbsd_arm.go +37 -0
  270. package/govendor/golang.org/x/sys/unix/syscall_netbsd_arm64.go +37 -0
  271. package/govendor/golang.org/x/sys/unix/syscall_openbsd.go +346 -0
  272. package/govendor/golang.org/x/sys/unix/syscall_openbsd_386.go +41 -0
  273. package/govendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go +41 -0
  274. package/govendor/golang.org/x/sys/unix/syscall_openbsd_arm.go +41 -0
  275. package/govendor/golang.org/x/sys/unix/syscall_openbsd_arm64.go +41 -0
  276. package/govendor/golang.org/x/sys/unix/syscall_openbsd_libc.go +26 -0
  277. package/govendor/golang.org/x/sys/unix/syscall_openbsd_mips64.go +39 -0
  278. package/govendor/golang.org/x/sys/unix/syscall_openbsd_ppc64.go +41 -0
  279. package/govendor/golang.org/x/sys/unix/syscall_openbsd_riscv64.go +41 -0
  280. package/govendor/golang.org/x/sys/unix/syscall_solaris.go +1183 -0
  281. package/govendor/golang.org/x/sys/unix/syscall_solaris_amd64.go +27 -0
  282. package/govendor/golang.org/x/sys/unix/syscall_unix.go +619 -0
  283. package/govendor/golang.org/x/sys/unix/syscall_unix_gc.go +14 -0
  284. package/govendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go +22 -0
  285. package/govendor/golang.org/x/sys/unix/syscall_zos_s390x.go +3213 -0
  286. package/govendor/golang.org/x/sys/unix/sysvshm_linux.go +20 -0
  287. package/govendor/golang.org/x/sys/unix/sysvshm_unix.go +51 -0
  288. package/govendor/golang.org/x/sys/unix/sysvshm_unix_other.go +13 -0
  289. package/govendor/golang.org/x/sys/unix/timestruct.go +76 -0
  290. package/govendor/golang.org/x/sys/unix/unveil_openbsd.go +51 -0
  291. package/govendor/golang.org/x/sys/unix/vgetrandom_linux.go +13 -0
  292. package/govendor/golang.org/x/sys/unix/vgetrandom_unsupported.go +11 -0
  293. package/govendor/golang.org/x/sys/unix/xattr_bsd.go +280 -0
  294. package/govendor/golang.org/x/sys/unix/zerrors_aix_ppc.go +1384 -0
  295. package/govendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go +1385 -0
  296. package/govendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +1922 -0
  297. package/govendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +1922 -0
  298. package/govendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go +1737 -0
  299. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_386.go +2042 -0
  300. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go +2039 -0
  301. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go +2033 -0
  302. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go +2033 -0
  303. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_riscv64.go +2147 -0
  304. package/govendor/golang.org/x/sys/unix/zerrors_linux.go +4209 -0
  305. package/govendor/golang.org/x/sys/unix/zerrors_linux_386.go +882 -0
  306. package/govendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +882 -0
  307. package/govendor/golang.org/x/sys/unix/zerrors_linux_arm.go +887 -0
  308. package/govendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +884 -0
  309. package/govendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +874 -0
  310. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips.go +888 -0
  311. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +888 -0
  312. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +888 -0
  313. package/govendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +888 -0
  314. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +940 -0
  315. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +944 -0
  316. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +944 -0
  317. package/govendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +884 -0
  318. package/govendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +943 -0
  319. package/govendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +992 -0
  320. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_386.go +1779 -0
  321. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go +1769 -0
  322. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go +1758 -0
  323. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_arm64.go +1769 -0
  324. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_386.go +1905 -0
  325. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go +1905 -0
  326. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go +1905 -0
  327. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_arm64.go +1905 -0
  328. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_mips64.go +1905 -0
  329. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_ppc64.go +1904 -0
  330. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_riscv64.go +1903 -0
  331. package/govendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go +1556 -0
  332. package/govendor/golang.org/x/sys/unix/zerrors_zos_s390x.go +990 -0
  333. package/govendor/golang.org/x/sys/unix/zptrace_armnn_linux.go +40 -0
  334. package/govendor/golang.org/x/sys/unix/zptrace_linux_arm64.go +17 -0
  335. package/govendor/golang.org/x/sys/unix/zptrace_mipsnn_linux.go +49 -0
  336. package/govendor/golang.org/x/sys/unix/zptrace_mipsnnle_linux.go +49 -0
  337. package/govendor/golang.org/x/sys/unix/zptrace_x86_linux.go +79 -0
  338. package/govendor/golang.org/x/sys/unix/zsymaddr_zos_s390x.s +364 -0
  339. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go +1461 -0
  340. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go +1420 -0
  341. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go +1188 -0
  342. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go +1069 -0
  343. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +2728 -0
  344. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +799 -0
  345. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +2728 -0
  346. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +799 -0
  347. package/govendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go +1666 -0
  348. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +1886 -0
  349. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +1886 -0
  350. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +1886 -0
  351. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +1886 -0
  352. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_riscv64.go +1886 -0
  353. package/govendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go +101 -0
  354. package/govendor/golang.org/x/sys/unix/zsyscall_linux.go +2267 -0
  355. package/govendor/golang.org/x/sys/unix/zsyscall_linux_386.go +469 -0
  356. package/govendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +636 -0
  357. package/govendor/golang.org/x/sys/unix/zsyscall_linux_arm.go +584 -0
  358. package/govendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go +535 -0
  359. package/govendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go +469 -0
  360. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +636 -0
  361. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +630 -0
  362. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go +619 -0
  363. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +636 -0
  364. package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +641 -0
  365. package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +687 -0
  366. package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +687 -0
  367. package/govendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go +531 -0
  368. package/govendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +478 -0
  369. package/govendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +631 -0
  370. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +1848 -0
  371. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +1848 -0
  372. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +1848 -0
  373. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +1848 -0
  374. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go +2407 -0
  375. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_386.s +719 -0
  376. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go +2407 -0
  377. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.s +719 -0
  378. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go +2407 -0
  379. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.s +719 -0
  380. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go +2407 -0
  381. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.s +719 -0
  382. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go +2407 -0
  383. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.s +719 -0
  384. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_ppc64.go +2407 -0
  385. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_ppc64.s +862 -0
  386. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_riscv64.go +2407 -0
  387. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_riscv64.s +719 -0
  388. package/govendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +2217 -0
  389. package/govendor/golang.org/x/sys/unix/zsyscall_zos_s390x.go +3458 -0
  390. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go +280 -0
  391. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go +280 -0
  392. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go +280 -0
  393. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_arm64.go +280 -0
  394. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_mips64.go +280 -0
  395. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_ppc64.go +280 -0
  396. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_riscv64.go +281 -0
  397. package/govendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go +439 -0
  398. package/govendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go +437 -0
  399. package/govendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go +316 -0
  400. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go +393 -0
  401. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go +393 -0
  402. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go +393 -0
  403. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_arm64.go +393 -0
  404. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_riscv64.go +393 -0
  405. package/govendor/golang.org/x/sys/unix/zsysnum_linux_386.go +470 -0
  406. package/govendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +394 -0
  407. package/govendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +434 -0
  408. package/govendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +337 -0
  409. package/govendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go +334 -0
  410. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +454 -0
  411. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +384 -0
  412. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +384 -0
  413. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +454 -0
  414. package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +461 -0
  415. package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +433 -0
  416. package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +433 -0
  417. package/govendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +338 -0
  418. package/govendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +399 -0
  419. package/govendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +413 -0
  420. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go +274 -0
  421. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go +274 -0
  422. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go +274 -0
  423. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_arm64.go +274 -0
  424. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go +219 -0
  425. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go +219 -0
  426. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go +219 -0
  427. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_arm64.go +218 -0
  428. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_mips64.go +221 -0
  429. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_ppc64.go +217 -0
  430. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_riscv64.go +218 -0
  431. package/govendor/golang.org/x/sys/unix/zsysnum_zos_s390x.go +2852 -0
  432. package/govendor/golang.org/x/sys/unix/ztypes_aix_ppc.go +353 -0
  433. package/govendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go +357 -0
  434. package/govendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go +878 -0
  435. package/govendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go +878 -0
  436. package/govendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go +473 -0
  437. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_386.go +651 -0
  438. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go +656 -0
  439. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go +642 -0
  440. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go +636 -0
  441. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_riscv64.go +638 -0
  442. package/govendor/golang.org/x/sys/unix/ztypes_linux.go +6547 -0
  443. package/govendor/golang.org/x/sys/unix/ztypes_linux_386.go +747 -0
  444. package/govendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +761 -0
  445. package/govendor/golang.org/x/sys/unix/ztypes_linux_arm.go +741 -0
  446. package/govendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +740 -0
  447. package/govendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +741 -0
  448. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips.go +746 -0
  449. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +743 -0
  450. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +743 -0
  451. package/govendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +746 -0
  452. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +754 -0
  453. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +749 -0
  454. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +749 -0
  455. package/govendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +828 -0
  456. package/govendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +763 -0
  457. package/govendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +744 -0
  458. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_386.go +585 -0
  459. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go +593 -0
  460. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go +590 -0
  461. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go +593 -0
  462. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_386.go +568 -0
  463. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go +568 -0
  464. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go +575 -0
  465. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go +568 -0
  466. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go +568 -0
  467. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_ppc64.go +570 -0
  468. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_riscv64.go +570 -0
  469. package/govendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go +516 -0
  470. package/govendor/golang.org/x/sys/unix/ztypes_zos_s390x.go +552 -0
  471. package/govendor/golang.org/x/sys/windows/aliases.go +13 -0
  472. package/govendor/golang.org/x/sys/windows/dll_windows.go +380 -0
  473. package/govendor/golang.org/x/sys/windows/env_windows.go +57 -0
  474. package/govendor/golang.org/x/sys/windows/eventlog.go +20 -0
  475. package/govendor/golang.org/x/sys/windows/exec_windows.go +248 -0
  476. package/govendor/golang.org/x/sys/windows/memory_windows.go +48 -0
  477. package/govendor/golang.org/x/sys/windows/mkerrors.bash +70 -0
  478. package/govendor/golang.org/x/sys/windows/mkknownfolderids.bash +27 -0
  479. package/govendor/golang.org/x/sys/windows/mksyscall.go +9 -0
  480. package/govendor/golang.org/x/sys/windows/race.go +30 -0
  481. package/govendor/golang.org/x/sys/windows/race0.go +25 -0
  482. package/govendor/golang.org/x/sys/windows/security_windows.go +1537 -0
  483. package/govendor/golang.org/x/sys/windows/service.go +257 -0
  484. package/govendor/golang.org/x/sys/windows/setupapi_windows.go +1425 -0
  485. package/govendor/golang.org/x/sys/windows/str.go +22 -0
  486. package/govendor/golang.org/x/sys/windows/syscall.go +104 -0
  487. package/govendor/golang.org/x/sys/windows/syscall_windows.go +1952 -0
  488. package/govendor/golang.org/x/sys/windows/types_windows.go +4058 -0
  489. package/govendor/golang.org/x/sys/windows/types_windows_386.go +35 -0
  490. package/govendor/golang.org/x/sys/windows/types_windows_amd64.go +34 -0
  491. package/govendor/golang.org/x/sys/windows/types_windows_arm.go +35 -0
  492. package/govendor/golang.org/x/sys/windows/types_windows_arm64.go +34 -0
  493. package/govendor/golang.org/x/sys/windows/zerrors_windows.go +9468 -0
  494. package/govendor/golang.org/x/sys/windows/zknownfolderids_windows.go +149 -0
  495. package/govendor/golang.org/x/sys/windows/zsyscall_windows.go +4828 -0
  496. package/govendor/manifest.txt +7 -0
  497. package/package.json +6 -1
  498. package/types/typenative-go.d.ts +15159 -5
  499. package/types/typenative-npm.d.ts +2637 -34
  500. package/types/typenative.d.ts +651 -8
@@ -0,0 +1,1221 @@
1
+ // node:stream (+ stream/promises, stream/consumers): Readable / Writable /
2
+ // Duplex / Transform / PassThrough on the event loop. Constructor options
3
+ // (read / write / transform / flush / final) and subclass overrides
4
+ // (_read / _write / _transform / _flush / _final) both work; pipe, pipeline,
5
+ // finished, Readable.from, async iteration. Also used by fs streams,
6
+ // process.stdin / stdout / stderr, zlib streams, child processes and readline.
7
+ import { defineClass, defineHelper, defineModule, setResults, getOption, isObjectLiteral } from './registry.js';
8
+ const streamHelper = `// node:stream
9
+ type tnWriteReq struct {
10
+ chunk interface{}
11
+ encoding string
12
+ cb interface{}
13
+ }
14
+
15
+ type TnStream struct {
16
+ TnEventEmitter
17
+ readableSide bool
18
+ writableSide bool
19
+ isTransform bool
20
+ objectMode bool
21
+ decodeStrings bool
22
+ encoding string
23
+ decoder *TnStringDecoder
24
+ options interface{}
25
+ hooks map[string]interface{}
26
+ tnSelf interface{}
27
+ // readable
28
+ queue []interface{}
29
+ readEnded bool
30
+ endEmitted bool
31
+ flowing int
32
+ reading bool
33
+ flowScheduled bool
34
+ source func(s *TnStream)
35
+ sourceStarted bool
36
+ // writable
37
+ writeQueue []tnWriteReq
38
+ writing bool
39
+ ending bool
40
+ writeEnded bool
41
+ finishing bool
42
+ finished bool
43
+ sink func(chunk interface{}, done func(err interface{}))
44
+ sinkFinal func(done func(err interface{}))
45
+ goTransform func(chunk []byte)
46
+ goFlush func() []byte
47
+ // state
48
+ destroyed bool
49
+ closed bool
50
+ errored interface{}
51
+ bytesRead float64
52
+ bytesWritten float64
53
+ path string
54
+ fd float64
55
+ // Releases an underlying handle (sockets) once the stream closes or is destroyed
56
+ onClose func()
57
+ // Defers 'close' past the end of both sides (client requests wait for their response)
58
+ closeHeld bool
59
+ // The async context the stream was created in (its events run in it)
60
+ asyncCtx TnAsyncContext
61
+ }
62
+
63
+ // Queues fn on the loop, in the stream's async context
64
+ func (s *TnStream) post(fn func()) {
65
+ ctx := s.asyncCtx
66
+ if ctx == nil {
67
+ TnLoopPost(fn)
68
+ return
69
+ }
70
+ TnLoopPost(func() { TnAsyncRun(ctx, fn) })
71
+ }
72
+
73
+ type tnStreamLike interface {
74
+ tnStream() *TnStream
75
+ }
76
+
77
+ func (s *TnStream) tnStream() *TnStream { return s }
78
+
79
+ func tnStreamOption(options interface{}, key string) interface{} {
80
+ if options == nil {
81
+ return nil
82
+ }
83
+ return TnGet(options, key)
84
+ }
85
+
86
+ func tnNewStreamBase(options []interface{}) *TnStream {
87
+ s := &TnStream{flowing: -1, decodeStrings: true, hooks: map[string]interface{}{}, asyncCtx: TnAsyncSnapshot()}
88
+ if len(options) > 0 && options[0] != nil {
89
+ s.options = options[0]
90
+ if b, ok := tnStreamOption(s.options, "objectMode").(bool); ok {
91
+ s.objectMode = b
92
+ }
93
+ if b, ok := tnStreamOption(s.options, "decodeStrings").(bool); ok {
94
+ s.decodeStrings = b
95
+ }
96
+ if enc, ok := tnStreamOption(s.options, "encoding").(string); ok && enc != "" {
97
+ s.setEncoding(enc)
98
+ }
99
+ for _, name := range []string{"read", "write", "transform", "flush", "final", "destroy"} {
100
+ if fn := tnStreamOption(s.options, name); fn != nil && reflect.ValueOf(fn).Kind() == reflect.Func && !reflect.ValueOf(fn).IsNil() {
101
+ s.hooks["_"+name] = fn
102
+ }
103
+ }
104
+ }
105
+ return s
106
+ }
107
+
108
+ func TnNewReadable(options ...interface{}) *TnStream {
109
+ s := tnNewStreamBase(options)
110
+ s.readableSide = true
111
+ return s
112
+ }
113
+
114
+ func TnNewWritable(options ...interface{}) *TnStream {
115
+ s := tnNewStreamBase(options)
116
+ s.writableSide = true
117
+ return s
118
+ }
119
+
120
+ func TnNewDuplex(options ...interface{}) *TnStream {
121
+ s := tnNewStreamBase(options)
122
+ s.readableSide, s.writableSide = true, true
123
+ return s
124
+ }
125
+
126
+ func TnNewTransform(options ...interface{}) *TnStream {
127
+ s := TnNewDuplex(options...)
128
+ s.isTransform = true
129
+ return s
130
+ }
131
+
132
+ func TnNewPassThrough(options ...interface{}) *TnStream {
133
+ return TnNewTransform(options...)
134
+ }
135
+
136
+ // Subclass overrides (_transform …) registered by the subclass constructor
137
+ func (s *TnStream) setHook(name string, fn interface{}) {
138
+ if s.hooks == nil {
139
+ s.hooks = map[string]interface{}{}
140
+ }
141
+ s.hooks[name] = fn
142
+ }
143
+
144
+ func (s *TnStream) hook(name string) interface{} {
145
+ if s.hooks == nil {
146
+ return nil
147
+ }
148
+ return s.hooks[name]
149
+ }
150
+
151
+ // --- readable side ---
152
+
153
+ func (s *TnStream) toChunk(chunk interface{}, enc string) interface{} {
154
+ if s.objectMode {
155
+ return chunk
156
+ }
157
+ switch c := chunk.(type) {
158
+ case string:
159
+ if s.encoding != "" {
160
+ return c
161
+ }
162
+ return TnBufferFromString(c, enc)
163
+ case []byte:
164
+ if s.decoder != nil {
165
+ return s.decoder.write(c)
166
+ }
167
+ return c
168
+ }
169
+ return chunk
170
+ }
171
+
172
+ func (s *TnStream) push(chunk interface{}, encoding ...string) bool {
173
+ if chunk == nil {
174
+ s.readEnded = true
175
+ if s.decoder != nil {
176
+ if rest := s.decoder.end(); rest != "" {
177
+ s.queue = append(s.queue, rest)
178
+ }
179
+ }
180
+ s.scheduleFlow()
181
+ return false
182
+ }
183
+ if s.readEnded {
184
+ s.errorLater(TnNodeError("Error", "ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF"))
185
+ return false
186
+ }
187
+ enc := ""
188
+ if len(encoding) > 0 {
189
+ enc = encoding[0]
190
+ }
191
+ c := s.toChunk(chunk, enc)
192
+ if b, ok := c.([]byte); ok {
193
+ s.bytesRead += float64(len(b))
194
+ }
195
+ s.queue = append(s.queue, c)
196
+ s.scheduleFlow()
197
+ return len(s.queue) < 16
198
+ }
199
+
200
+ func (s *TnStream) unshift(chunk interface{}, encoding ...string) {
201
+ s.queue = append([]interface{}{s.toChunk(chunk, "")}, s.queue...)
202
+ }
203
+
204
+ func (s *TnStream) scheduleFlow() {
205
+ if s.flowScheduled || s.destroyed {
206
+ return
207
+ }
208
+ s.flowScheduled = true
209
+ s.post(func() {
210
+ s.flowScheduled = false
211
+ s.flow()
212
+ })
213
+ }
214
+
215
+ func (s *TnStream) flow() {
216
+ if s.destroyed {
217
+ return
218
+ }
219
+ for s.flowing == 1 && len(s.queue) > 0 {
220
+ chunk := s.queue[0]
221
+ s.queue = s.queue[1:]
222
+ s.emit("data", chunk)
223
+ }
224
+ if len(s.queue) == 0 && s.readEnded {
225
+ s.emitEnd()
226
+ return
227
+ }
228
+ if s.flowing == 1 {
229
+ s.requestRead()
230
+ }
231
+ }
232
+
233
+ func (s *TnStream) requestRead() {
234
+ if s.reading || s.readEnded || s.destroyed {
235
+ return
236
+ }
237
+ if s.source != nil && !s.sourceStarted {
238
+ s.sourceStarted = true
239
+ s.source(s)
240
+ }
241
+ if fn := s.hook("_read"); fn != nil {
242
+ s.reading = true
243
+ TnInvoke(fn, float64(16384))
244
+ s.reading = false
245
+ }
246
+ }
247
+
248
+ func (s *TnStream) emitEnd() {
249
+ if s.endEmitted {
250
+ return
251
+ }
252
+ s.endEmitted = true
253
+ s.emit("end")
254
+ if !s.writableSide || s.finished {
255
+ s.emitClose()
256
+ }
257
+ }
258
+
259
+ func (s *TnStream) releaseHandle() {
260
+ if s.onClose != nil {
261
+ release := s.onClose
262
+ s.onClose = nil
263
+ release()
264
+ }
265
+ }
266
+
267
+ func (s *TnStream) emitClose() {
268
+ if s.closed || s.closeHeld {
269
+ return
270
+ }
271
+ s.closed = true
272
+ s.releaseHandle()
273
+ s.post(func() { s.emit("close") })
274
+ }
275
+
276
+ func (s *TnStream) errorLater(err interface{}) {
277
+ s.post(func() { s.destroy(err) })
278
+ }
279
+
280
+ // on('data') starts the flow (as in Node)
281
+ func (s *TnStream) on(event string, fn interface{}) *TnEventEmitter {
282
+ s.TnEventEmitter.on(event, fn)
283
+ s.listening(event)
284
+ return &s.TnEventEmitter
285
+ }
286
+
287
+ func (s *TnStream) addListener(event string, fn interface{}) *TnEventEmitter { return s.on(event, fn) }
288
+
289
+ func (s *TnStream) once(event string, fn interface{}) *TnEventEmitter {
290
+ s.TnEventEmitter.once(event, fn)
291
+ s.listening(event)
292
+ return &s.TnEventEmitter
293
+ }
294
+
295
+ func (s *TnStream) listening(event string) {
296
+ if event == "data" && s.flowing != 0 && s.readableSide {
297
+ s.resume()
298
+ }
299
+ if event == "end" && s.readableSide && s.flowing == -1 && s.endEmitted {
300
+ return
301
+ }
302
+ }
303
+
304
+ func (s *TnStream) resume() *TnStream {
305
+ s.flowing = 1
306
+ s.scheduleFlow()
307
+ return s
308
+ }
309
+
310
+ func (s *TnStream) pause() *TnStream {
311
+ s.flowing = 0
312
+ return s
313
+ }
314
+
315
+ func (s *TnStream) isPaused() bool { return s.flowing == 0 }
316
+
317
+ // read(): paused-mode pull of the next buffered chunk (null when none)
318
+ func (s *TnStream) read(size ...float64) interface{} {
319
+ if len(s.queue) == 0 {
320
+ s.requestRead()
321
+ if s.readEnded {
322
+ s.scheduleFlow()
323
+ }
324
+ return nil
325
+ }
326
+ chunk := s.queue[0]
327
+ s.queue = s.queue[1:]
328
+ return chunk
329
+ }
330
+
331
+ func (s *TnStream) setEncoding(enc string) *TnStream {
332
+ s.encoding = tnEncoding(enc)
333
+ s.decoder = TnNewStringDecoder(enc)
334
+ return s
335
+ }
336
+
337
+ func (s *TnStream) destroy(err ...interface{}) *TnStream {
338
+ if s.destroyed {
339
+ return s
340
+ }
341
+ s.destroyed = true
342
+ s.closeHeld = false
343
+ var e interface{}
344
+ if len(err) > 0 {
345
+ e = err[0]
346
+ }
347
+ finish := func() {
348
+ s.releaseHandle()
349
+ if e != nil {
350
+ s.errored = e
351
+ s.post(func() {
352
+ s.emit("error", e)
353
+ s.closed = true
354
+ s.emit("close")
355
+ })
356
+ return
357
+ }
358
+ s.emitClose()
359
+ }
360
+ if fn := s.hook("_destroy"); fn != nil {
361
+ TnInvoke(fn, e, func(args ...interface{}) {
362
+ if len(args) > 0 && args[0] != nil {
363
+ e = args[0]
364
+ }
365
+ finish()
366
+ })
367
+ return s
368
+ }
369
+ finish()
370
+ return s
371
+ }
372
+
373
+ // --- writable side ---
374
+
375
+ func (s *TnStream) write(chunk interface{}, args ...interface{}) bool {
376
+ enc := ""
377
+ var cb interface{}
378
+ for _, a := range args {
379
+ switch x := a.(type) {
380
+ case string:
381
+ enc = x
382
+ case nil:
383
+ default:
384
+ if reflect.ValueOf(a).Kind() == reflect.Func {
385
+ cb = x
386
+ }
387
+ }
388
+ }
389
+ if s.writeEnded || s.destroyed {
390
+ err := TnNodeError("Error", "ERR_STREAM_WRITE_AFTER_END", "write after end")
391
+ if cb != nil {
392
+ s.post(func() { TnInvoke(cb, err) })
393
+ }
394
+ s.errorLater(err)
395
+ return false
396
+ }
397
+ if !s.objectMode {
398
+ if str, ok := chunk.(string); ok && s.decodeStrings {
399
+ chunk = TnBufferFromString(str, enc)
400
+ }
401
+ }
402
+ if enc == "" {
403
+ enc = "buffer"
404
+ if _, ok := chunk.(string); ok {
405
+ enc = "utf8"
406
+ }
407
+ }
408
+ s.writeQueue = append(s.writeQueue, tnWriteReq{chunk: chunk, encoding: enc, cb: cb})
409
+ s.processWrites()
410
+ return len(s.writeQueue) < 16
411
+ }
412
+
413
+ func (s *TnStream) processWrites() {
414
+ if s.writing || s.destroyed {
415
+ return
416
+ }
417
+ if len(s.writeQueue) == 0 {
418
+ if s.ending {
419
+ s.finish()
420
+ }
421
+ return
422
+ }
423
+ req := s.writeQueue[0]
424
+ s.writeQueue = s.writeQueue[1:]
425
+ s.writing = true
426
+ called := false
427
+ done := func(args ...interface{}) {
428
+ if called {
429
+ return
430
+ }
431
+ called = true
432
+ var err interface{}
433
+ if len(args) > 0 {
434
+ err = args[0]
435
+ }
436
+ s.writing = false
437
+ if b, ok := req.chunk.([]byte); ok {
438
+ s.bytesWritten += float64(len(b))
439
+ }
440
+ if req.cb != nil {
441
+ TnInvoke(req.cb, err)
442
+ }
443
+ if err != nil && !TnIsNil(err) {
444
+ s.destroy(err)
445
+ return
446
+ }
447
+ if len(s.writeQueue) == 0 && !s.ending {
448
+ s.post(func() { s.emit("drain") })
449
+ }
450
+ s.post(s.processWrites)
451
+ }
452
+ switch {
453
+ case s.sink != nil:
454
+ s.sink(req.chunk, func(err interface{}) { done(err) })
455
+ case s.isTransform:
456
+ s.runTransform(req.chunk, req.encoding, done)
457
+ default:
458
+ fn := s.hook("_write")
459
+ if fn == nil {
460
+ done(TnNodeError("Error", "ERR_METHOD_NOT_IMPLEMENTED", "The _write() method is not implemented"))
461
+ return
462
+ }
463
+ TnInvoke(fn, req.chunk, req.encoding, done)
464
+ }
465
+ }
466
+
467
+ func (s *TnStream) runTransform(chunk interface{}, encoding string, done func(args ...interface{})) {
468
+ if s.goTransform != nil {
469
+ if b, ok := chunk.([]byte); ok {
470
+ s.goTransform(b)
471
+ }
472
+ done()
473
+ return
474
+ }
475
+ fn := s.hook("_transform")
476
+ if fn == nil {
477
+ s.push(chunk)
478
+ done()
479
+ return
480
+ }
481
+ TnInvoke(fn, chunk, encoding, func(args ...interface{}) {
482
+ if len(args) > 1 && args[1] != nil {
483
+ s.push(args[1])
484
+ }
485
+ if len(args) > 0 {
486
+ done(args[0])
487
+ } else {
488
+ done()
489
+ }
490
+ })
491
+ }
492
+
493
+ func (s *TnStream) end(args ...interface{}) *TnStream {
494
+ var cb interface{}
495
+ rest := []interface{}{}
496
+ for _, a := range args {
497
+ if a != nil && reflect.ValueOf(a).Kind() == reflect.Func {
498
+ cb = a
499
+ } else {
500
+ rest = append(rest, a)
501
+ }
502
+ }
503
+ if len(rest) > 0 && rest[0] != nil && !s.writeEnded {
504
+ s.write(rest[0], rest[1:]...)
505
+ }
506
+ if cb != nil {
507
+ s.TnEventEmitter.once("finish", cb)
508
+ }
509
+ if s.writeEnded {
510
+ return s
511
+ }
512
+ s.writeEnded = true
513
+ s.ending = true
514
+ s.processWrites()
515
+ return s
516
+ }
517
+
518
+ func (s *TnStream) finish() {
519
+ if s.finishing || s.finished {
520
+ return
521
+ }
522
+ s.finishing = true
523
+ complete := func(args ...interface{}) {
524
+ if len(args) > 0 && args[0] != nil && !TnIsNil(args[0]) {
525
+ s.destroy(args[0])
526
+ return
527
+ }
528
+ s.post(func() {
529
+ s.finished = true
530
+ s.emit("finish")
531
+ if !s.readableSide || s.endEmitted {
532
+ s.emitClose()
533
+ }
534
+ })
535
+ }
536
+ if s.isTransform {
537
+ flushed := func(args ...interface{}) {
538
+ if len(args) > 1 && args[1] != nil {
539
+ s.push(args[1])
540
+ }
541
+ s.push(nil)
542
+ if len(args) > 0 {
543
+ complete(args[0])
544
+ } else {
545
+ complete()
546
+ }
547
+ }
548
+ if s.goFlush != nil {
549
+ if out := s.goFlush(); len(out) > 0 {
550
+ s.push(out)
551
+ }
552
+ flushed()
553
+ return
554
+ }
555
+ if fn := s.hook("_flush"); fn != nil {
556
+ TnInvoke(fn, flushed)
557
+ return
558
+ }
559
+ flushed()
560
+ return
561
+ }
562
+ if fn := s.hook("_final"); fn != nil {
563
+ TnInvoke(fn, complete)
564
+ return
565
+ }
566
+ if s.sinkFinal != nil {
567
+ s.sinkFinal(func(err interface{}) { complete(err) })
568
+ return
569
+ }
570
+ complete()
571
+ }
572
+
573
+ func (s *TnStream) cork() {}
574
+ func (s *TnStream) uncork() {}
575
+ func (s *TnStream) setDefaultEncoding(enc string) *TnStream { return s }
576
+
577
+ func (s *TnStream) Get_readable() bool {
578
+ return s.readableSide && !s.destroyed && !s.endEmitted
579
+ }
580
+ func (s *TnStream) Get_writable() bool {
581
+ return s.writableSide && !s.destroyed && !s.writeEnded
582
+ }
583
+ func (s *TnStream) Get_readableEnded() bool { return s.endEmitted }
584
+ func (s *TnStream) Get_writableEnded() bool { return s.writeEnded }
585
+ func (s *TnStream) Get_writableFinished() bool { return s.finished }
586
+ func (s *TnStream) Get_destroyed() bool { return s.destroyed }
587
+ func (s *TnStream) Get_closed() bool { return s.closed }
588
+ func (s *TnStream) Get_errored() interface{} { return s.errored }
589
+ func (s *TnStream) Get_readableLength() float64 { return float64(len(s.queue)) }
590
+ func (s *TnStream) Get_writableLength() float64 { return float64(len(s.writeQueue)) }
591
+ func (s *TnStream) Get_readableObjectMode() bool { return s.objectMode }
592
+ func (s *TnStream) Get_writableObjectMode() bool { return s.objectMode }
593
+ func (s *TnStream) Get_readableFlowing() interface{} {
594
+ if s.flowing == -1 {
595
+ return nil
596
+ }
597
+ return s.flowing == 1
598
+ }
599
+ func (s *TnStream) Get_bytesRead() float64 { return s.bytesRead }
600
+ func (s *TnStream) Get_bytesWritten() float64 { return s.bytesWritten }
601
+ func (s *TnStream) Get_path() string { return s.path }
602
+
603
+ // src.pipe(dest, { end }): returns dest
604
+ func TnPipe[D tnStreamLike](source tnStreamLike, dest D, options ...interface{}) D {
605
+ src := source.tnStream()
606
+ dst := dest.tnStream()
607
+ end := true
608
+ if len(options) > 0 && options[0] != nil {
609
+ if e, ok := TnGet(options[0], "end").(bool); ok {
610
+ end = e
611
+ }
612
+ }
613
+ dst.emit("pipe", src)
614
+ src.on("data", func(chunk interface{}) {
615
+ if !dst.write(chunk) {
616
+ src.pause()
617
+ dst.TnEventEmitter.once("drain", func() { src.resume() })
618
+ }
619
+ })
620
+ if end {
621
+ src.TnEventEmitter.once("end", func() { dst.end() })
622
+ }
623
+ return dest
624
+ }
625
+
626
+ // Readable.from(iterable): arrays, strings, Buffers, async generators (channels)
627
+ func TnReadableFrom(iterable interface{}, options ...interface{}) *TnStream {
628
+ s := TnNewReadable(options...)
629
+ s.objectMode = true
630
+ if len(options) > 0 && options[0] != nil {
631
+ if b, ok := TnGet(options[0], "objectMode").(bool); ok {
632
+ s.objectMode = b
633
+ }
634
+ }
635
+ switch x := iterable.(type) {
636
+ case string, []byte:
637
+ s.queue = append(s.queue, x)
638
+ s.readEnded = true
639
+ return s
640
+ }
641
+ rv := reflect.ValueOf(iterable)
642
+ if rv.Kind() == reflect.Pointer && !rv.IsNil() && rv.Elem().Kind() == reflect.Slice {
643
+ rv = rv.Elem()
644
+ }
645
+ switch rv.Kind() {
646
+ case reflect.Slice, reflect.Array:
647
+ for i := 0; i < rv.Len(); i++ {
648
+ s.queue = append(s.queue, rv.Index(i).Interface())
649
+ }
650
+ s.readEnded = true
651
+ case reflect.Chan:
652
+ s.source = func(st *TnStream) {
653
+ TnLoopRef()
654
+ go func() {
655
+ for {
656
+ v, ok := rv.Recv()
657
+ if !ok {
658
+ break
659
+ }
660
+ value := v.Interface()
661
+ TnLoopPost(func() { st.push(value) })
662
+ }
663
+ TnLoopPost(func() {
664
+ defer TnLoopUnref()
665
+ st.push(nil)
666
+ })
667
+ }()
668
+ }
669
+ }
670
+ return s
671
+ }
672
+
673
+ // for await (const chunk of readable)
674
+ func (s *TnStream) tnIterator() chan interface{} {
675
+ ch := make(chan interface{}, 65536)
676
+ s.on("data", func(chunk interface{}) { ch <- chunk })
677
+ s.TnEventEmitter.once("end", func() { close(ch) })
678
+ s.TnEventEmitter.once("error", func(err interface{}) { TnReject(ch, err) })
679
+ return ch
680
+ }
681
+
682
+ // pipeline(...streams, callback?): errors destroy every stream
683
+ func TnPipeline(callback interface{}, streams ...tnStreamLike) *TnStream {
684
+ all := make([]*TnStream, len(streams))
685
+ for i, st := range streams {
686
+ all[i] = st.tnStream()
687
+ }
688
+ done := false
689
+ finish := func(err interface{}) {
690
+ if done {
691
+ return
692
+ }
693
+ done = true
694
+ if err != nil {
695
+ for _, st := range all {
696
+ st.destroy()
697
+ }
698
+ }
699
+ if callback != nil {
700
+ TnInvoke(callback, err)
701
+ }
702
+ }
703
+ for i := 0; i+1 < len(all); i++ {
704
+ TnPipe[tnStreamLike](all[i], all[i+1])
705
+ }
706
+ for _, st := range all {
707
+ st.TnEventEmitter.once("error", func(err interface{}) { finish(err) })
708
+ }
709
+ last := all[len(all)-1]
710
+ if last.writableSide {
711
+ last.TnEventEmitter.once("finish", func() { finish(nil) })
712
+ } else {
713
+ last.TnEventEmitter.once("end", func() { finish(nil) })
714
+ }
715
+ return last
716
+ }
717
+
718
+ func TnPipelinePromise(streams ...tnStreamLike) chan struct{} {
719
+ ch := make(chan struct{}, 1)
720
+ TnLoopRef()
721
+ TnPipeline(func(err interface{}) {
722
+ defer TnLoopUnref()
723
+ if err != nil {
724
+ TnReject(ch, err)
725
+ return
726
+ }
727
+ ch <- struct{}{}
728
+ }, streams...)
729
+ return ch
730
+ }
731
+
732
+ // finished(stream, callback): end / finish, or the error
733
+ func TnFinished(stream tnStreamLike, callback interface{}) {
734
+ s := stream.tnStream()
735
+ called := false
736
+ call := func(err interface{}) {
737
+ if !called {
738
+ called = true
739
+ TnInvoke(callback, err)
740
+ }
741
+ }
742
+ s.TnEventEmitter.once("error", func(err interface{}) { call(err) })
743
+ if s.readableSide {
744
+ s.TnEventEmitter.once("end", func() { call(nil) })
745
+ } else {
746
+ s.TnEventEmitter.once("finish", func() { call(nil) })
747
+ }
748
+ s.TnEventEmitter.once("close", func() { call(nil) })
749
+ }
750
+
751
+ func TnFinishedPromise(stream tnStreamLike) chan struct{} {
752
+ ch := make(chan struct{}, 1)
753
+ TnLoopRef()
754
+ TnFinished(stream, func(err interface{}) {
755
+ defer TnLoopUnref()
756
+ if err != nil {
757
+ TnReject(ch, err)
758
+ return
759
+ }
760
+ ch <- struct{}{}
761
+ })
762
+ return ch
763
+ }
764
+
765
+ // stream/consumers: collect the whole stream
766
+ func tnConsume[T any](stream tnStreamLike, convert func(chunks []interface{}) T) chan T {
767
+ s := stream.tnStream()
768
+ ch := make(chan T, 1)
769
+ chunks := []interface{}{}
770
+ TnLoopRef()
771
+ s.on("data", func(chunk interface{}) { chunks = append(chunks, chunk) })
772
+ s.TnEventEmitter.once("end", func() {
773
+ defer TnLoopUnref()
774
+ ch <- convert(chunks)
775
+ })
776
+ s.TnEventEmitter.once("error", func(err interface{}) {
777
+ defer TnLoopUnref()
778
+ TnReject(ch, err)
779
+ })
780
+ return ch
781
+ }
782
+
783
+ func tnChunksBytes(chunks []interface{}) []byte {
784
+ out := []byte{}
785
+ for _, c := range chunks {
786
+ switch x := c.(type) {
787
+ case []byte:
788
+ out = append(out, x...)
789
+ case string:
790
+ out = append(out, x...)
791
+ default:
792
+ out = append(out, TnJSString(x)...)
793
+ }
794
+ }
795
+ return out
796
+ }
797
+
798
+ func TnConsumeText(stream tnStreamLike) chan string {
799
+ return tnConsume(stream, func(chunks []interface{}) string { return tnDecodeUTF8(tnChunksBytes(chunks)) })
800
+ }
801
+
802
+ func TnConsumeBuffer(stream tnStreamLike) chan []byte {
803
+ return tnConsume(stream, func(chunks []interface{}) []byte { return tnChunksBytes(chunks) })
804
+ }
805
+
806
+ func TnConsumeJSON(stream tnStreamLike) chan interface{} {
807
+ return tnConsume(stream, func(chunks []interface{}) interface{} {
808
+ var v interface{}
809
+ if err := json.Unmarshal(tnChunksBytes(chunks), &v); err != nil {
810
+ panic(TnNodeError("SyntaxError", "", err.Error()))
811
+ }
812
+ return v
813
+ })
814
+ }
815
+
816
+ // process.stdout / stderr: writable streams over the Go files
817
+ var tnStdoutStream *TnStream
818
+ var tnStderrStream *TnStream
819
+ var tnStdinStream *TnStream
820
+
821
+ func tnFileSink(f *os.File) *TnStream {
822
+ s := TnNewWritable()
823
+ s.sink = func(chunk interface{}, done func(err interface{})) {
824
+ switch c := chunk.(type) {
825
+ case []byte:
826
+ f.Write(c)
827
+ case string:
828
+ f.WriteString(c)
829
+ default:
830
+ f.WriteString(TnJSString(c))
831
+ }
832
+ done(nil)
833
+ }
834
+ return s
835
+ }
836
+
837
+ func TnStdout() *TnStream {
838
+ if tnStdoutStream == nil {
839
+ tnStdoutStream = tnFileSink(os.Stdout)
840
+ tnStdoutStream.fd = 1
841
+ }
842
+ return tnStdoutStream
843
+ }
844
+
845
+ func TnStderr() *TnStream {
846
+ if tnStderrStream == nil {
847
+ tnStderrStream = tnFileSink(os.Stderr)
848
+ tnStderrStream.fd = 2
849
+ }
850
+ return tnStderrStream
851
+ }
852
+
853
+ // process.stdin: reads (on its own goroutine) while flowing; keeps the
854
+ // process alive only while flowing
855
+ func TnStdin() *TnStream {
856
+ if tnStdinStream != nil {
857
+ return tnStdinStream
858
+ }
859
+ s := TnNewReadable()
860
+ s.fd = 0
861
+ tnStdinStream = s
862
+ refHeld := false
863
+ s.source = func(st *TnStream) {
864
+ go func() {
865
+ buf := make([]byte, 65536)
866
+ for {
867
+ n, err := tnStdin().Read(buf)
868
+ if n > 0 {
869
+ chunk := append([]byte{}, buf[:n]...)
870
+ TnLoopPost(func() { st.push(chunk) })
871
+ }
872
+ if err != nil {
873
+ TnLoopPost(func() {
874
+ st.push(nil)
875
+ if refHeld {
876
+ refHeld = false
877
+ TnLoopUnref()
878
+ }
879
+ })
880
+ return
881
+ }
882
+ }
883
+ }()
884
+ }
885
+ s.hooks["_stdinRef"] = func(flowing bool) {
886
+ if flowing && !refHeld && !s.readEnded {
887
+ refHeld = true
888
+ TnLoopRef()
889
+ } else if !flowing && refHeld {
890
+ refHeld = false
891
+ TnLoopUnref()
892
+ }
893
+ }
894
+ return s
895
+ }
896
+
897
+ func (s *TnStream) stdinRef(flowing bool) {
898
+ if fn, ok := s.hooks["_stdinRef"].(func(bool)); ok {
899
+ fn(flowing)
900
+ }
901
+ }`;
902
+ const fileStreamHelper = `// fs.createReadStream / createWriteStream
903
+ func TnCreateReadStream(path string, options ...interface{}) *TnStream {
904
+ s := TnNewReadable()
905
+ s.path = path
906
+ start, end := int64(0), int64(-1)
907
+ chunkSize := 65536
908
+ if len(options) > 0 && options[0] != nil {
909
+ opts := options[0]
910
+ if enc, ok := opts.(string); ok {
911
+ s.setEncoding(enc)
912
+ } else {
913
+ if enc, ok := TnGet(opts, "encoding").(string); ok && enc != "" {
914
+ s.setEncoding(enc)
915
+ }
916
+ if v, ok := TnGet(opts, "start").(float64); ok {
917
+ start = int64(v)
918
+ }
919
+ if v, ok := TnGet(opts, "end").(float64); ok {
920
+ end = int64(v)
921
+ }
922
+ if v, ok := TnGet(opts, "highWaterMark").(float64); ok && v > 0 {
923
+ chunkSize = int(v)
924
+ }
925
+ }
926
+ }
927
+ s.source = func(st *TnStream) {
928
+ TnLoopRef()
929
+ go func() {
930
+ f, err := os.Open(path)
931
+ if err != nil {
932
+ sysErr := TnSysError(err, "open", path)
933
+ TnLoopPost(func() {
934
+ defer TnLoopUnref()
935
+ st.destroy(sysErr)
936
+ })
937
+ return
938
+ }
939
+ defer f.Close()
940
+ TnLoopPost(func() {
941
+ st.emit("open", float64(3))
942
+ st.emit("ready")
943
+ })
944
+ if start > 0 {
945
+ f.Seek(start, 0)
946
+ }
947
+ remaining := int64(-1)
948
+ if end >= 0 {
949
+ remaining = end - start + 1
950
+ }
951
+ buf := make([]byte, chunkSize)
952
+ for remaining != 0 {
953
+ want := len(buf)
954
+ if remaining > 0 && int64(want) > remaining {
955
+ want = int(remaining)
956
+ }
957
+ n, readErr := f.Read(buf[:want])
958
+ if n > 0 {
959
+ chunk := append([]byte{}, buf[:n]...)
960
+ TnLoopPost(func() { st.push(chunk) })
961
+ if remaining > 0 {
962
+ remaining -= int64(n)
963
+ }
964
+ }
965
+ if readErr != nil {
966
+ break
967
+ }
968
+ }
969
+ TnLoopPost(func() {
970
+ defer TnLoopUnref()
971
+ st.push(nil)
972
+ })
973
+ }()
974
+ }
975
+ return s
976
+ }
977
+
978
+ func TnCreateWriteStream(path string, options ...interface{}) *TnStream {
979
+ s := TnNewWritable()
980
+ s.path = path
981
+ flags := "w"
982
+ if len(options) > 0 && options[0] != nil {
983
+ if f, ok := TnGet(options[0], "flags").(string); ok && f != "" {
984
+ flags = f
985
+ }
986
+ if enc, ok := TnGet(options[0], "encoding").(string); ok && enc != "" {
987
+ s.decodeStrings = true
988
+ }
989
+ }
990
+ f, err := os.OpenFile(path, tnOpenFlags(flags), 0o666)
991
+ if err != nil {
992
+ s.errorLater(TnSysError(err, "open", path))
993
+ return s
994
+ }
995
+ TnLoopRef()
996
+ TnLoopPost(func() {
997
+ s.emit("open", float64(3))
998
+ s.emit("ready")
999
+ })
1000
+ s.sink = func(chunk interface{}, done func(err interface{})) {
1001
+ var b []byte
1002
+ switch c := chunk.(type) {
1003
+ case []byte:
1004
+ b = c
1005
+ case string:
1006
+ b = []byte(c)
1007
+ default:
1008
+ b = []byte(TnJSString(c))
1009
+ }
1010
+ if _, err := f.Write(b); err != nil {
1011
+ done(TnSysError(err, "write", path))
1012
+ return
1013
+ }
1014
+ done(nil)
1015
+ }
1016
+ s.sinkFinal = func(done func(err interface{})) {
1017
+ err := f.Close()
1018
+ TnLoopUnref()
1019
+ if err != nil {
1020
+ done(TnSysError(err, "close", path))
1021
+ return
1022
+ }
1023
+ done(nil)
1024
+ }
1025
+ return s
1026
+ }`;
1027
+ const zlibStreamHelper = `// zlib streams: Transforms buffering the input, (de)compressed at the end
1028
+ func TnZlibStream(format string, decompress bool, options ...interface{}) *TnStream {
1029
+ s := TnNewTransform()
1030
+ level := tnZlibLevel(options)
1031
+ input := []byte{}
1032
+ s.goTransform = func(chunk []byte) { input = append(input, chunk...) }
1033
+ s.goFlush = func() []byte {
1034
+ if decompress {
1035
+ return tnDecompress(format, input)
1036
+ }
1037
+ return tnCompress(format, input, level)
1038
+ }
1039
+ return s
1040
+ }`;
1041
+ // Go parameter types of option / override methods
1042
+ // Method and getter specs of TnStream, shared with classes that embed it (net.Socket, http messages)
1043
+ export const STREAM_METHODS = 'on=*TnEventEmitter; once=*TnEventEmitter; addListener=*TnEventEmitter; off=*TnEventEmitter; removeListener=*TnEventEmitter; removeAllListeners=*TnEventEmitter; emit=bool; listenerCount=float64; push=bool; unshift=; read=interface{}; resume=*TnStream; pause=*TnStream; isPaused=bool; setEncoding=*TnStream; destroy=*TnStream; write=bool; end=*TnStream; cork=; uncork=; setDefaultEncoding=*TnStream';
1044
+ export const STREAM_GETTERS = 'readable=bool; writable=bool; readableEnded=bool; writableEnded=bool; writableFinished=bool; destroyed=bool; closed=bool; errored=interface{}; readableLength=float64; writableLength=float64; readableObjectMode=bool; writableObjectMode=bool; readableFlowing=interface{}; bytesRead=float64; bytesWritten=float64; path=string';
1045
+ const STREAM_HOOK_PARAMS = {
1046
+ read: ['float64'],
1047
+ write: ['interface{}', 'string', 'TnCallback'],
1048
+ transform: ['interface{}', 'string', 'TnCallback'],
1049
+ flush: ['TnCallback'],
1050
+ final: ['TnCallback'],
1051
+ destroy: ['interface{}', 'TnCallback']
1052
+ };
1053
+ export function registerStream(r) {
1054
+ for (const mod of ['stream', 'stream/promises', 'stream/consumers'])
1055
+ defineModule(r, mod);
1056
+ r.namespaces['stream.promises'] = 'stream/promises';
1057
+ r.namespaces['stream.default'] = 'stream.Stream';
1058
+ defineHelper(r, 'nodeStream', ['encoding/json', 'os', 'reflect'], ['nodeEvents', 'buffer', 'stringDecoder', 'eventLoop', 'promise', 'dynamic', 'nodeInvoke', 'stdinReader'], streamHelper);
1059
+ defineHelper(r, 'stdinReader', ['bufio', 'os'], [], `// One buffered reader shared by process.stdin, readline and question()
1060
+ var tnStdinBuffered *bufio.Reader
1061
+
1062
+ func tnStdin() *bufio.Reader {
1063
+ if tnStdinBuffered == nil {
1064
+ tnStdinBuffered = bufio.NewReader(os.Stdin)
1065
+ }
1066
+ return tnStdinBuffered
1067
+ }`);
1068
+ const methods = STREAM_METHODS;
1069
+ const getters = STREAM_GETTERS;
1070
+ const cls = defineClass(r, 'stream.Duplex', '*TnStream', 'class', methods, 'tnSelf=interface{}', getters, '');
1071
+ for (const name of ['Readable', 'Writable', 'Transform', 'PassThrough', 'Stream'])
1072
+ r.classes[`stream.${name}`] = cls;
1073
+ for (const name of ['ReadStream', 'WriteStream'])
1074
+ r.classes[`fs.${name}`] = cls;
1075
+ r.classes['stream.default'] = cls;
1076
+ r.iterators['*TnStream'] = 'tnIterator';
1077
+ cls.methods['tnIterator'] = 'chan interface{}';
1078
+ const use = () => r.helper('nodeStream');
1079
+ const ctors = {
1080
+ Readable: 'TnNewReadable',
1081
+ Writable: 'TnNewWritable',
1082
+ Duplex: 'TnNewDuplex',
1083
+ Transform: 'TnNewTransform',
1084
+ PassThrough: 'TnNewPassThrough',
1085
+ Stream: 'TnNewDuplex'
1086
+ };
1087
+ for (const name of Object.keys(ctors)) {
1088
+ const goCtor = ctors[name];
1089
+ r.constructors[`stream.${name}`] = (call) => {
1090
+ use();
1091
+ return `${goCtor}(${call.args.slice(0, 1).join(', ')})`;
1092
+ };
1093
+ // Option methods (read / write / transform …) get Node's parameter types
1094
+ r.optionTypers[`stream.${name}`] = (node) => {
1095
+ const objectMode = isObjectLiteral(node) && getOption(node, 'objectMode')?.kind === 'TrueKeyword';
1096
+ const out = {};
1097
+ for (const hook of Object.keys(STREAM_HOOK_PARAMS)) {
1098
+ const params = [...STREAM_HOOK_PARAMS[hook]];
1099
+ if (!objectMode && (hook === 'write' || hook === 'transform'))
1100
+ params[0] = '[]byte';
1101
+ out[hook] = params;
1102
+ }
1103
+ return out;
1104
+ };
1105
+ r.hookPrefixes[`stream.${name}`] = '_';
1106
+ }
1107
+ r.constructors['stream.default'] = r.constructors['stream.Stream'];
1108
+ r.optionTypers['stream.default'] = r.optionTypers['stream.Stream'];
1109
+ for (const hook of Object.keys(STREAM_HOOK_PARAMS))
1110
+ r.hookParams[`_${hook}`] = STREAM_HOOK_PARAMS[hook];
1111
+ r.methods['stream.Duplex#pipe'] = (c) => {
1112
+ use();
1113
+ return `TnPipe(${c.recv}, ${c.args.join(', ')})`;
1114
+ };
1115
+ r.typers['stream.Duplex#pipe'] = (c) => c.types[0] || '*TnStream';
1116
+ r.paramTypers['stream.Duplex#on'] = (nodes) => streamListenerTypes(nodes);
1117
+ r.paramTypers['stream.Duplex#once'] = r.paramTypers['stream.Duplex#on'];
1118
+ r.functions['stream.Readable.from'] = (call) => {
1119
+ use();
1120
+ return `TnReadableFrom(${call.args.join(', ')})`;
1121
+ };
1122
+ r.results['stream.Readable.from'] = '*TnStream';
1123
+ const pipeline = (call) => {
1124
+ use();
1125
+ const last = call.nodes.length - 1;
1126
+ const hasCallback = last >= 0 && (call.nodes[last].kind === 'ArrowFunction' || call.nodes[last].kind === 'FunctionExpression');
1127
+ const streams = hasCallback ? call.args.slice(0, last) : call.args;
1128
+ return `TnPipeline(${hasCallback ? call.args[last] : 'nil'}, ${streams.join(', ')})`;
1129
+ };
1130
+ r.functions['stream.pipeline'] = pipeline;
1131
+ r.results['stream.pipeline'] = '*TnStream';
1132
+ r.paramTypers['stream.pipeline'] = (_n) => ['interface{}'];
1133
+ r.functions['stream.finished'] = (call) => {
1134
+ use();
1135
+ return `TnFinished(${call.args[0]}, ${call.args[call.args.length - 1]})`;
1136
+ };
1137
+ r.paramTypers['stream.finished'] = (_n) => ['interface{}'];
1138
+ r.functions['stream/promises.pipeline'] = (call) => {
1139
+ use();
1140
+ return `TnPipelinePromise(${call.args.join(', ')})`;
1141
+ };
1142
+ r.functions['stream/promises.finished'] = (call) => {
1143
+ use();
1144
+ return `TnFinishedPromise(${call.args[0]})`;
1145
+ };
1146
+ setResults(r, 'stream/promises', 'pipeline=chan struct{}; finished=chan struct{}');
1147
+ const consumer = (name, goName, result) => {
1148
+ r.functions[`stream/consumers.${name}`] = (call) => {
1149
+ use();
1150
+ return `${goName}(${call.args[0]})`;
1151
+ };
1152
+ r.results[`stream/consumers.${name}`] = result;
1153
+ };
1154
+ consumer('text', 'TnConsumeText', 'chan string');
1155
+ consumer('buffer', 'TnConsumeBuffer', 'chan []byte');
1156
+ consumer('json', 'TnConsumeJSON', 'chan interface{}');
1157
+ // process.stdout / stderr / stdin as streams (stdout.write stays a direct call)
1158
+ const stdio = (name, goName) => {
1159
+ r.values[`process.${name}`] = (_c) => {
1160
+ use();
1161
+ return `${goName}()`;
1162
+ };
1163
+ r.valueTypes[`process.${name}`] = '*TnStream';
1164
+ };
1165
+ stdio('stdout', 'TnStdout');
1166
+ stdio('stderr', 'TnStderr');
1167
+ stdio('stdin', 'TnStdin');
1168
+ // fs.createReadStream / createWriteStream
1169
+ defineHelper(r, 'fileStreams', ['os'], ['nodeStream', 'nodeFs'], fileStreamHelper);
1170
+ r.functions['fs.createReadStream'] = (call) => {
1171
+ r.helper('fileStreams');
1172
+ return `TnCreateReadStream(${call.args.join(', ')})`;
1173
+ };
1174
+ r.functions['fs.createWriteStream'] = (call) => {
1175
+ r.helper('fileStreams');
1176
+ return `TnCreateWriteStream(${call.args.join(', ')})`;
1177
+ };
1178
+ setResults(r, 'fs', 'createReadStream=*TnStream; createWriteStream=*TnStream');
1179
+ // zlib.createGzip() & co.
1180
+ defineHelper(r, 'zlibStreams', [], ['nodeStream', 'nodeZlib'], zlibStreamHelper);
1181
+ const zlibStreams = {
1182
+ createGzip: 'gzip:false',
1183
+ createGunzip: 'gunzip:true',
1184
+ createDeflate: 'deflate:false',
1185
+ createInflate: 'inflate:true',
1186
+ createDeflateRaw: 'deflateRaw:false',
1187
+ createInflateRaw: 'inflateRaw:true',
1188
+ createUnzip: 'unzip:true'
1189
+ };
1190
+ for (const name of Object.keys(zlibStreams)) {
1191
+ const parts = zlibStreams[name].split(':');
1192
+ r.functions[`zlib.${name}`] = (call) => {
1193
+ r.helper('zlibStreams');
1194
+ const options = call.args.length > 0 ? `, ${call.args[0]}` : '';
1195
+ return `TnZlibStream(${JSON.stringify(parts[0])}, ${parts[1]}${options})`;
1196
+ };
1197
+ r.results[`zlib.${name}`] = '*TnStream';
1198
+ }
1199
+ for (const method of ['on', 'once', 'resume', 'pause', 'setEncoding', 'pipe', 'read', 'destroy']) {
1200
+ r.functions[`process.stdin.${method}`] = (call) => {
1201
+ use();
1202
+ if (method === 'pipe')
1203
+ return `TnPipe(TnStdin(), ${call.args.join(', ')})`;
1204
+ const refCall = method === 'destroy' ? '; TnStdin().stdinRef(false)' : '; TnStdin().stdinRef(TnStdin().flowing == 1)';
1205
+ return `func() *TnStream { TnStdin().${method}(${call.args.join(', ')})${refCall}; return TnStdin() }()`;
1206
+ };
1207
+ r.results[`process.stdin.${method}`] = '*TnStream';
1208
+ }
1209
+ r.paramTypers['process.stdin.on'] = (nodes) => streamListenerTypes(nodes);
1210
+ r.paramTypers['process.stdin.once'] = r.paramTypers['process.stdin.on'];
1211
+ }
1212
+ // Listener parameters of stream events
1213
+ export function streamListenerTypes(nodes) {
1214
+ const event = nodes[0];
1215
+ const name = event && event.kind === 'StringLiteral' ? String(event.text) : '';
1216
+ if (name === 'data')
1217
+ return ['interface{}'];
1218
+ if (name === 'error')
1219
+ return ['interface{}'];
1220
+ return [];
1221
+ }