typenative 0.4.1 → 0.6.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 (270) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/.github/workflows/npm-publish-github-packages.yml +2 -2
  3. package/CHANGELOG.md +442 -1
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +73 -25
  6. package/bin/cli.js +2 -0
  7. package/bin/index.js +75 -5
  8. package/bin/main.js +2 -0
  9. package/bin/node/assert.js +2 -2
  10. package/bin/node/async_hooks.js +1 -1
  11. package/bin/node/buffer.js +16 -5
  12. package/bin/node/child_process.js +7 -7
  13. package/bin/node/cluster.js +3 -3
  14. package/bin/node/core.js +41 -0
  15. package/bin/node/crypto_keys.js +21 -21
  16. package/bin/node/dgram.js +1 -1
  17. package/bin/node/diagnostics_channel.js +3 -3
  18. package/bin/node/dns.js +2 -2
  19. package/bin/node/events.js +18 -13
  20. package/bin/node/fetch.js +2 -2
  21. package/bin/node/fs.js +3 -3
  22. package/bin/node/fs_watch.js +5 -5
  23. package/bin/node/http.js +3 -3
  24. package/bin/node/http2.js +3 -3
  25. package/bin/node/net.js +8 -8
  26. package/bin/node/path.js +17 -3
  27. package/bin/node/process.js +47 -11
  28. package/bin/node/punycode.js +2 -2
  29. package/bin/node/readline.js +1 -1
  30. package/bin/node/registry.js +4 -1
  31. package/bin/node/sqlite.js +6 -6
  32. package/bin/node/stream.js +81 -15
  33. package/bin/node/stream_web.js +10 -10
  34. package/bin/node/system_extra.js +3 -3
  35. package/bin/node/test.js +674 -366
  36. package/bin/node/test_coverage.js +187 -0
  37. package/bin/node/test_report.js +1392 -0
  38. package/bin/node/test_run.js +575 -0
  39. package/bin/node/timers.js +8 -6
  40. package/bin/node/tls.js +5 -5
  41. package/bin/node/url.js +1 -1
  42. package/bin/node/util.js +31 -7
  43. package/bin/node/util_extra.js +7 -7
  44. package/bin/node/webview.js +654 -0
  45. package/bin/node/worker_threads.js +1 -1
  46. package/bin/node/zlib.js +3 -3
  47. package/bin/parse-node.js +6 -2
  48. package/bin/regex_vm.js +2057 -0
  49. package/bin/transpiler.js +32872 -11265
  50. package/bin/typecheck-node.js +2 -1
  51. package/bin/version.js +1 -1
  52. package/conformance.md +515 -345
  53. package/examples/README.md +71 -11
  54. package/examples/angular-templates/README.md +139 -0
  55. package/examples/angular-templates/bench.mjs +173 -0
  56. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  57. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  58. package/examples/angular-templates/main.ts +135 -0
  59. package/examples/angular-templates/parity.mjs +157 -0
  60. package/examples/angular-templates/run-node.mjs +69 -0
  61. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  62. package/examples/desktop-notes/README.md +106 -0
  63. package/examples/desktop-notes/bench.mjs +125 -0
  64. package/examples/desktop-notes/main.ts +131 -0
  65. package/examples/desktop-notes/package-lock.json +726 -0
  66. package/examples/desktop-notes/package.json +9 -0
  67. package/examples/desktop-notes/ui.ts +176 -0
  68. package/examples/dupe-finder/README.md +78 -0
  69. package/examples/dupe-finder/bench.mjs +120 -0
  70. package/examples/dupe-finder/main.ts +87 -0
  71. package/examples/fibonacci/README.md +7 -7
  72. package/examples/hello-world/README.md +6 -6
  73. package/examples/json-server/README.md +19 -18
  74. package/examples/mandelbrot-png/README.md +63 -0
  75. package/examples/mandelbrot-png/bench.mjs +95 -0
  76. package/examples/mandelbrot-png/main.ts +98 -0
  77. package/examples/mandelbrot-png/preview.png +0 -0
  78. package/examples/marked-cli/README.md +160 -0
  79. package/examples/marked-cli/bench.mjs +178 -0
  80. package/examples/marked-cli/main.ts +292 -0
  81. package/examples/marked-cli/parity.mjs +185 -0
  82. package/examples/marked-cli/vendor/marked/LICENSE +44 -0
  83. package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
  84. package/examples/openai-chat/README.md +148 -0
  85. package/examples/openai-chat/bench.mjs +175 -0
  86. package/examples/openai-chat/main.ts +488 -0
  87. package/examples/react-compiler/README.md +170 -0
  88. package/examples/react-compiler/bench.mjs +181 -0
  89. package/examples/react-compiler/main.ts +158 -0
  90. package/examples/react-compiler/parity.mjs +362 -0
  91. package/examples/react-compiler/run-node.mjs +88 -0
  92. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  93. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  94. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  95. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  96. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  97. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  98. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  99. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  100. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  101. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  102. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  103. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  104. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  105. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  106. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  107. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  108. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  109. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  110. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  111. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  112. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  113. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  114. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  115. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  116. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  117. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  118. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  119. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  120. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  121. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  145. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  146. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  147. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  148. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  149. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  150. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  151. package/examples/react-compiler/vendor.mjs +688 -0
  152. package/examples/todo-cli/README.md +69 -0
  153. package/examples/todo-cli/bench.mjs +89 -0
  154. package/examples/todo-cli/main.ts +92 -0
  155. package/examples/yaml-cli/README.md +146 -0
  156. package/examples/yaml-cli/bench.mjs +265 -0
  157. package/examples/yaml-cli/main.ts +29 -0
  158. package/examples/yaml-cli/parity.mjs +156 -0
  159. package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
  160. package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
  161. package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
  162. package/govendor/github.com/jchv/go-webview2/README.md +21 -0
  163. package/govendor/github.com/jchv/go-webview2/common.go +84 -0
  164. package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
  165. package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
  166. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
  167. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
  168. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
  169. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
  170. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
  171. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
  172. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
  173. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
  174. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
  175. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
  176. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
  177. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
  178. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
  179. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
  180. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
  181. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
  182. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
  183. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
  184. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
  185. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
  186. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
  187. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
  188. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
  189. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
  190. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
  191. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
  192. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
  193. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
  194. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
  195. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
  196. package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
  197. package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
  198. package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
  199. package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
  200. package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
  201. package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
  202. package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
  203. package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
  204. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
  205. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
  206. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
  207. package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
  208. package/govendor/github.com/jchv/go-winloader/README.md +124 -0
  209. package/govendor/github.com/jchv/go-winloader/common.go +11 -0
  210. package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
  211. package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
  212. package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
  213. package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
  214. package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
  215. package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
  216. package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
  217. package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
  218. package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
  219. package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
  220. package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
  221. package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
  222. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
  223. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
  224. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
  225. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
  226. package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
  227. package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
  228. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
  229. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
  230. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
  231. package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
  232. package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
  233. package/govendor/manifest.txt +3 -1
  234. package/package.json +8 -5
  235. package/performance/README.md +195 -0
  236. package/performance/any-dynamic.ts +21 -0
  237. package/performance/any-record-view.ts +20 -0
  238. package/performance/arr-hof.ts +21 -0
  239. package/performance/arr-push-index.ts +15 -0
  240. package/performance/arr-sort.ts +21 -0
  241. package/performance/async-await.ts +24 -0
  242. package/performance/class-dispatch.ts +52 -0
  243. package/performance/events-emit.ts +27 -0
  244. package/performance/exc-throw-rare.ts +25 -0
  245. package/performance/exc-try-catch.ts +26 -0
  246. package/performance/fn-closures.ts +29 -0
  247. package/performance/fn-recursion-tree.ts +31 -0
  248. package/performance/gen-for-of.ts +46 -0
  249. package/performance/json-roundtrip.ts +27 -0
  250. package/performance/map-delete.ts +24 -0
  251. package/performance/map-string-keys.ts +22 -0
  252. package/performance/num-arith-loop.ts +14 -0
  253. package/performance/num-bitwise.ts +21 -0
  254. package/performance/num-mod-int.ts +16 -0
  255. package/performance/num-to-string.ts +16 -0
  256. package/performance/obj-alloc.ts +32 -0
  257. package/performance/regex-exec.ts +29 -0
  258. package/performance/regex-site.ts +28 -0
  259. package/performance/set-ops.ts +20 -0
  260. package/performance/str-char-scan.ts +35 -0
  261. package/performance/str-concat-plus.ts +18 -0
  262. package/performance/str-concat.ts +24 -0
  263. package/performance/str-short-scan.ts +26 -0
  264. package/performance/str-split-join.ts +23 -0
  265. package/performance/str-template.ts +16 -0
  266. package/performance/union-switch.ts +57 -0
  267. package/tsparser/check.go +2 -1
  268. package/tsparser/main.go +5 -0
  269. package/types/typenative-npm.d.ts +193 -4
  270. package/types/typenative.d.ts +138 -41
@@ -113,7 +113,7 @@ func tnSqliteFlag(options interface{}, key string, def bool) bool {
113
113
  if options == nil {
114
114
  return def
115
115
  }
116
- switch v := TnGet(options, key).(type) {
116
+ switch v := TnGetValue(options, key).(type) {
117
117
  case bool:
118
118
  return v
119
119
  case *bool:
@@ -128,7 +128,7 @@ func tnSqliteNumber(options interface{}, key string, def float64) float64 {
128
128
  if options == nil {
129
129
  return def
130
130
  }
131
- switch v := TnGet(options, key).(type) {
131
+ switch v := TnGetValue(options, key).(type) {
132
132
  case float64:
133
133
  return v
134
134
  case *float64:
@@ -143,7 +143,7 @@ func tnSqliteString(options interface{}, key string, def string) string {
143
143
  if options == nil {
144
144
  return def
145
145
  }
146
- switch v := TnGet(options, key).(type) {
146
+ switch v := TnGetValue(options, key).(type) {
147
147
  case string:
148
148
  return v
149
149
  case *string:
@@ -184,7 +184,7 @@ func TnNewSqliteDb(path interface{}, opts ...interface{}) *TnSqliteDb {
184
184
  case []byte:
185
185
  db.path = string(p)
186
186
  default:
187
- if href, ok := TnGet(path, "href").(string); ok && path != nil {
187
+ if href, ok := TnGetValue(path, "href").(string); ok && path != nil {
188
188
  db.path = href
189
189
  } else {
190
190
  panic(tnSqliteArgType("The \\"path\\" argument must be a string, Uint8Array, or URL without null bytes."))
@@ -264,7 +264,7 @@ func (db *TnSqliteDb) open() {
264
264
  }
265
265
  if db.limitOptions != nil {
266
266
  for i, name := range tnSqliteLimitNames {
267
- if v, ok := TnGet(db.limitOptions, name).(float64); ok {
267
+ if v, ok := TnGetValue(db.limitOptions, name).(float64); ok {
268
268
  db.limits.set(i, v)
269
269
  }
270
270
  }
@@ -667,7 +667,7 @@ func (db *TnSqliteDb) deserialize(data []byte, options ...interface{}) {
667
667
  db.requireOpen()
668
668
  schema := "main"
669
669
  if len(options) > 0 && options[0] != nil {
670
- if s, ok := TnGet(options[0], "dbName").(string); ok {
670
+ if s, ok := TnGetValue(options[0], "dbName").(string); ok {
671
671
  schema = s
672
672
  }
673
673
  }
@@ -317,6 +317,8 @@ func (s *TnStream) errorLater(err interface{}) {
317
317
  func (s *TnStream) on(event string, fn interface{}) *TnEventEmitter {
318
318
  s.TnEventEmitter.on(event, fn)
319
319
  s.listening(event)
320
+ // (process.stdin, used through any reference: alive while flowing)
321
+ s.stdinRef(s.flowing == 1)
320
322
  return &s.TnEventEmitter
321
323
  }
322
324
 
@@ -325,9 +327,28 @@ func (s *TnStream) addListener(event string, fn interface{}) *TnEventEmitter { r
325
327
  func (s *TnStream) once(event string, fn interface{}) *TnEventEmitter {
326
328
  s.TnEventEmitter.once(event, fn)
327
329
  s.listening(event)
330
+ s.stdinRef(s.flowing == 1)
328
331
  return &s.TnEventEmitter
329
332
  }
330
333
 
334
+ // stream.on(…) / once(…) in TypeScript: the stream itself, for chaining (as in Node)
335
+ func (s *TnStream) onChain(event string, fn interface{}) *TnStream {
336
+ s.on(event, fn)
337
+ return s
338
+ }
339
+
340
+ func (s *TnStream) onceChain(event string, fn interface{}) *TnStream {
341
+ s.once(event, fn)
342
+ return s
343
+ }
344
+
345
+ // process.stdin holds the event loop while it flows (a no-op for other streams)
346
+ func (s *TnStream) stdinRef(flowing bool) {
347
+ if fn, ok := s.hooks["_stdinRef"].(func(bool)); ok {
348
+ fn(flowing)
349
+ }
350
+ }
351
+
331
352
  func (s *TnStream) listening(event string) {
332
353
  if event == "readable" && s.readableSide {
333
354
  s.readableListening = true
@@ -347,11 +368,13 @@ func (s *TnStream) listening(event string) {
347
368
  func (s *TnStream) resume() *TnStream {
348
369
  s.flowing = 1
349
370
  s.scheduleFlow()
371
+ s.stdinRef(true)
350
372
  return s
351
373
  }
352
374
 
353
375
  func (s *TnStream) pause() *TnStream {
354
376
  s.flowing = 0
377
+ s.stdinRef(false)
355
378
  return s
356
379
  }
357
380
 
@@ -726,7 +749,7 @@ func TnPipe[D tnStreamLike](source tnStreamLike, dest D, options ...interface{})
726
749
  dst := dest.tnStream()
727
750
  end := true
728
751
  if len(options) > 0 && options[0] != nil {
729
- if e, ok := TnGet(options[0], "end").(bool); ok {
752
+ if e, ok := TnGetValue(options[0], "end").(bool); ok {
730
753
  end = e
731
754
  }
732
755
  }
@@ -748,7 +771,7 @@ func TnReadableFrom(iterable interface{}, options ...interface{}) *TnStream {
748
771
  s := TnNewReadable(options...)
749
772
  s.objectMode = true
750
773
  if len(options) > 0 && options[0] != nil {
751
- if b, ok := TnGet(options[0], "objectMode").(bool); ok {
774
+ if b, ok := TnGetValue(options[0], "objectMode").(bool); ok {
752
775
  s.objectMode = b
753
776
  }
754
777
  }
@@ -790,6 +813,46 @@ func TnReadableFrom(iterable interface{}, options ...interface{}) *TnStream {
790
813
  return s
791
814
  }
792
815
 
816
+ // readable.compose(stream | fn): the source piped into a stream, or handed to
817
+ // a function (an async generator over the chunks, a node:test reporter) whose
818
+ // output becomes a readable
819
+ func (s *TnStream) compose(target interface{}, options ...interface{}) *TnStream {
820
+ if dst, ok := target.(tnStreamLike); ok {
821
+ return TnPipe(s, dst.tnStream())
822
+ }
823
+ fv := reflect.ValueOf(target)
824
+ if fv.Kind() != reflect.Func || fv.IsNil() {
825
+ panic(TnNodeError("TypeError", "ERR_INVALID_ARG_TYPE", "The \\"stream\\" argument must be of type function or an instance of Stream, Iterable, or AsyncIterable. Received "+TnJSString(target)))
826
+ }
827
+ ft := fv.Type()
828
+ var out []reflect.Value
829
+ if ft.NumIn() == 0 {
830
+ // a stream factory (node:test/reporters' spec / lcov)
831
+ out = fv.Call(nil)
832
+ } else if in := ft.In(0); in.Kind() == reflect.Chan {
833
+ // an async generator function: the chunks as a channel of its element type
834
+ src := s.tnIterator()
835
+ ch := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, in.Elem()), 65536)
836
+ go func() {
837
+ for v := range src {
838
+ ch.Send(tnInvokeArg(v, in.Elem()))
839
+ }
840
+ ch.Close()
841
+ }()
842
+ out = fv.Call([]reflect.Value{ch})
843
+ } else {
844
+ out = fv.Call([]reflect.Value{tnInvokeArg(s, in)})
845
+ }
846
+ if len(out) == 0 {
847
+ return s
848
+ }
849
+ result := out[0].Interface()
850
+ if dst, ok := result.(tnStreamLike); ok {
851
+ return TnPipe(s, dst.tnStream())
852
+ }
853
+ return TnReadableFrom(result)
854
+ }
855
+
793
856
  // for await (const chunk of readable)
794
857
  func (s *TnStream) tnIterator() chan interface{} {
795
858
  ch := make(chan interface{}, 65536)
@@ -1012,12 +1075,6 @@ func TnStdin() *TnStream {
1012
1075
  }
1013
1076
  }
1014
1077
  return s
1015
- }
1016
-
1017
- func (s *TnStream) stdinRef(flowing bool) {
1018
- if fn, ok := s.hooks["_stdinRef"].(func(bool)); ok {
1019
- fn(flowing)
1020
- }
1021
1078
  }`;
1022
1079
  const fileStreamHelper = `// fs.createReadStream / createWriteStream
1023
1080
  func TnCreateReadStream(path string, options ...interface{}) *TnStream {
@@ -1030,16 +1087,16 @@ func TnCreateReadStream(path string, options ...interface{}) *TnStream {
1030
1087
  if enc, ok := opts.(string); ok {
1031
1088
  s.setEncoding(enc)
1032
1089
  } else {
1033
- if enc, ok := TnGet(opts, "encoding").(string); ok && enc != "" {
1090
+ if enc, ok := TnGetValue(opts, "encoding").(string); ok && enc != "" {
1034
1091
  s.setEncoding(enc)
1035
1092
  }
1036
- if v, ok := TnGet(opts, "start").(float64); ok {
1093
+ if v, ok := TnGetValue(opts, "start").(float64); ok {
1037
1094
  start = int64(v)
1038
1095
  }
1039
- if v, ok := TnGet(opts, "end").(float64); ok {
1096
+ if v, ok := TnGetValue(opts, "end").(float64); ok {
1040
1097
  end = int64(v)
1041
1098
  }
1042
- if v, ok := TnGet(opts, "highWaterMark").(float64); ok && v > 0 {
1099
+ if v, ok := TnGetValue(opts, "highWaterMark").(float64); ok && v > 0 {
1043
1100
  chunkSize = int(v)
1044
1101
  }
1045
1102
  }
@@ -1100,10 +1157,10 @@ func TnCreateWriteStream(path string, options ...interface{}) *TnStream {
1100
1157
  s.path = path
1101
1158
  flags := "w"
1102
1159
  if len(options) > 0 && options[0] != nil {
1103
- if f, ok := TnGet(options[0], "flags").(string); ok && f != "" {
1160
+ if f, ok := TnGetValue(options[0], "flags").(string); ok && f != "" {
1104
1161
  flags = f
1105
1162
  }
1106
- if enc, ok := TnGet(options[0], "encoding").(string); ok && enc != "" {
1163
+ if enc, ok := TnGetValue(options[0], "encoding").(string); ok && enc != "" {
1107
1164
  s.decodeStrings = true
1108
1165
  }
1109
1166
  }
@@ -1159,7 +1216,7 @@ func TnZlibStream(format string, decompress bool, options ...interface{}) *TnStr
1159
1216
  }`;
1160
1217
  // Go parameter types of option / override methods
1161
1218
  // Method and getter specs of TnStream, shared with classes that embed it (net.Socket, http messages)
1162
- 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';
1219
+ export const STREAM_METHODS = 'on=*TnStream; once=*TnStream; addListener=*TnEventEmitter; off=*TnEventEmitter; removeListener=*TnEventEmitter; removeAllListeners=*TnEventEmitter; emit=bool; listenerCount=float64; compose=*TnStream; push=bool; unshift=; read=interface{}; resume=*TnStream; pause=*TnStream; isPaused=bool; setEncoding=*TnStream; destroy=*TnStream; write=bool; end=*TnStream; cork=; uncork=; setDefaultEncoding=*TnStream';
1163
1220
  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';
1164
1221
  const STREAM_HOOK_PARAMS = {
1165
1222
  read: ['float64'],
@@ -1191,6 +1248,9 @@ func tnStdin() *bufio.Reader {
1191
1248
  r.classes[`stream.${name}`] = cls;
1192
1249
  for (const name of ['ReadStream', 'WriteStream'])
1193
1250
  r.classes[`fs.${name}`] = cls;
1251
+ // the global stream interfaces of Node's typings (process.stdin is one)
1252
+ for (const name of ['ReadableStream', 'WritableStream', 'ReadWriteStream'])
1253
+ r.classes[`NodeJS.${name}`] = cls;
1194
1254
  r.classes['stream.default'] = cls;
1195
1255
  r.iterators['*TnStream'] = 'tnIterator';
1196
1256
  cls.methods['tnIterator'] = 'chan interface{}';
@@ -1234,6 +1294,12 @@ func tnStdin() *bufio.Reader {
1234
1294
  };
1235
1295
  r.typers['stream.Duplex#pipe'] = (c) => c.types[0] || '*TnStream';
1236
1296
  r.paramTypers['stream.Duplex#on'] = (nodes) => streamListenerTypes(nodes);
1297
+ for (const method of ['on', 'once']) {
1298
+ r.methods[`stream.Duplex#${method}`] = (c) => {
1299
+ use();
1300
+ return `${c.recv}.${method}Chain(${c.args.join(', ')})`;
1301
+ };
1302
+ }
1237
1303
  r.paramTypers['stream.Duplex#once'] = r.paramTypers['stream.Duplex#on'];
1238
1304
  r.functions['stream.Readable.from'] = (call) => {
1239
1305
  use();
@@ -255,7 +255,7 @@ func TnNewReadableStream(args ...interface{}) *TnReadableStream {
255
255
  s.startWith(nil)
256
256
  return s
257
257
  }
258
- if t, _ := TnGet(source, "type").(string); t == "bytes" {
258
+ if t, _ := TnGetValue(source, "type").(string); t == "bytes" {
259
259
  s.strategy.bytes = true
260
260
  if len(rest) == 0 {
261
261
  s.strategy.hwm = 0
@@ -823,7 +823,7 @@ func (s *TnReadableStream) pipeTo(dest *TnWritableStream, options ...interface{}
823
823
  ch := make(chan struct{})
824
824
  opts := tnWebArg(options)
825
825
  flag := func(name string) bool {
826
- b, _ := TnGet(opts, name).(bool)
826
+ b, _ := TnGetValue(opts, name).(bool)
827
827
  return b
828
828
  }
829
829
  preventClose, preventAbort, preventCancel := flag("preventClose"), flag("preventAbort"), flag("preventCancel")
@@ -847,7 +847,7 @@ func (s *TnReadableStream) pipeTo(dest *TnWritableStream, options ...interface{}
847
847
  }
848
848
  close(ch)
849
849
  }
850
- if signal, ok := TnGet(opts, "signal").(*TnAbortSignal); ok && signal != nil {
850
+ if signal, ok := TnGetValue(opts, "signal").(*TnAbortSignal); ok && signal != nil {
851
851
  onAbort := func() {
852
852
  reason := tnWebAbortReason(signal)
853
853
  if !preventAbort {
@@ -932,8 +932,8 @@ func (s *TnReadableStream) pipeThrough(transform interface{}, options ...interfa
932
932
  if t, ok := transform.(*TnTransformStream); ok {
933
933
  writable, readable = t.writable, t.readable
934
934
  } else {
935
- writable, _ = TnGet(transform, "writable").(*TnWritableStream)
936
- readable, _ = TnGet(transform, "readable").(*TnReadableStream)
935
+ writable, _ = TnGetValue(transform, "writable").(*TnWritableStream)
936
+ readable, _ = TnGetValue(transform, "readable").(*TnReadableStream)
937
937
  }
938
938
  if writable == nil || readable == nil {
939
939
  panic(tnWebTypeError("ERR_INVALID_ARG_TYPE", "The \\"transform\\" argument must have readable and writable streams"))
@@ -1533,8 +1533,8 @@ func TnNewTextDecoderStream(args ...interface{}) *TnTransformStream {
1533
1533
  ts.encoding = "utf-8"
1534
1534
  }
1535
1535
  if len(args) > 1 && args[1] != nil {
1536
- ts.fatal, _ = TnGet(args[1], "fatal").(bool)
1537
- ts.ignoreBOM, _ = TnGet(args[1], "ignoreBOM").(bool)
1536
+ ts.fatal, _ = TnGetValue(args[1], "fatal").(bool)
1537
+ ts.ignoreBOM, _ = TnGetValue(args[1], "ignoreBOM").(bool)
1538
1538
  }
1539
1539
  return ts
1540
1540
  }
@@ -1747,8 +1747,8 @@ func TnDuplexFromWeb(pair interface{}, options ...interface{}) *TnStream {
1747
1747
  if t, ok := pair.(*TnTransformStream); ok {
1748
1748
  readable, writable = t.readable, t.writable
1749
1749
  } else {
1750
- readable, _ = TnGet(pair, "readable").(*TnReadableStream)
1751
- writable, _ = TnGet(pair, "writable").(*TnWritableStream)
1750
+ readable, _ = TnGetValue(pair, "readable").(*TnReadableStream)
1751
+ writable, _ = TnGetValue(pair, "writable").(*TnWritableStream)
1752
1752
  }
1753
1753
  r := TnReadableFromWeb(readable, options...)
1754
1754
  w := TnWritableFromWeb(writable, options...)
@@ -1855,7 +1855,7 @@ func tnBlobParts(parts interface{}) []byte {
1855
1855
  }
1856
1856
 
1857
1857
  func tnBlobType(options interface{}) string {
1858
- t, _ := TnGet(options, "type").(string)
1858
+ t, _ := TnGetValue(options, "type").(string)
1859
1859
  for _, c := range t {
1860
1860
  if c < 0x20 || c > 0x7e {
1861
1861
  return ""
@@ -303,9 +303,9 @@ func (o *TnPerformanceObserver) observe(options interface{}) {
303
303
  o.types[TnJSString(rv.Index(i).Interface())] = true
304
304
  }
305
305
  }
306
- if t, ok := TnGet(options, "type").(string); ok {
306
+ if t, ok := TnGetValue(options, "type").(string); ok {
307
307
  o.types[t] = true
308
- if buffered, _ := TnGet(options, "buffered").(bool); buffered {
308
+ if buffered, _ := TnGetValue(options, "buffered").(bool); buffered {
309
309
  for _, e := range TnPerfEntries("", t) {
310
310
  o.queue(e)
311
311
  }
@@ -516,7 +516,7 @@ func (h *TnHistogram) reset() {
516
516
  func TnMonitorEventLoopDelay(options ...interface{}) *TnHistogram {
517
517
  h := &TnHistogram{interval: 10}
518
518
  if len(options) > 0 && options[0] != nil {
519
- if n, ok := TnGet(options[0], "resolution").(float64); ok && n > 0 {
519
+ if n, ok := TnGetValue(options[0], "resolution").(float64); ok && n > 0 {
520
520
  h.interval = n
521
521
  }
522
522
  }