From 4d745a2aad8e336896c620eb69d97c50ac66ced8 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Mon, 13 Jul 2026 22:22:11 +1000 Subject: [PATCH 1/2] Add net BlockList/SocketAddress, buffer utils, cluster aliases Expose newer Node.js net blocklist/address APIs, buffer module helpers, and cluster primary aliases. Co-authored-by: Cursor --- src/js/node/Cluster.hx | 12 ++++++ src/js/node/Net.hx | 44 ++++++++++++++++++++ src/js/node/buffer/Buffer.hx | 48 ++++++++++++++++++++++ src/js/node/net/BlockList.hx | 70 ++++++++++++++++++++++++++++++++ src/js/node/net/SocketAddress.hx | 65 +++++++++++++++++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 src/js/node/net/BlockList.hx create mode 100644 src/js/node/net/SocketAddress.hx diff --git a/src/js/node/Cluster.hx b/src/js/node/Cluster.hx index 3673863d..a81059ad 100644 --- a/src/js/node/Cluster.hx +++ b/src/js/node/Cluster.hx @@ -168,6 +168,13 @@ extern class Cluster extends EventEmitter { **/ var isMaster(default, null):Bool; + /** + True if the process is a primary (alias of `isMaster`). + This is determined by the process.env.NODE_UNIQUE_ID. + If process.env.NODE_UNIQUE_ID is undefined, then `isPrimary` is true. + **/ + var isPrimary(default, null):Bool; + /** True if the process is not a master (it is the negation of `isMaster`). **/ @@ -189,6 +196,11 @@ extern class Cluster extends EventEmitter { **/ function setupMaster(?settings:{?exec:String, ?args:Array, ?silent:Bool}):Void; + /** + Alias of `setupMaster`. + **/ + function setupPrimary(?settings:{?exec:String, ?args:Array, ?silent:Bool}):Void; + /** Spawn a new worker process. diff --git a/src/js/node/Net.hx b/src/js/node/Net.hx index dc011b82..9ceeca67 100644 --- a/src/js/node/Net.hx +++ b/src/js/node/Net.hx @@ -23,8 +23,10 @@ package js.node; import haxe.extern.EitherType; +import js.node.net.BlockList as BlockListObject; import js.node.net.Server; import js.node.net.Socket; +import js.node.net.SocketAddress as SocketAddressObject; typedef NetCreateServerOptions = { > SocketOptionsBase, @@ -122,4 +124,46 @@ extern class Net { Returns true if input is a version 6 IP address, otherwise returns false. **/ static function isIPv6(input:String):Bool; + + /** + `BlockList` class constructor. + + @see https://nodejs.org/api/net.html#class-netblocklist + **/ + static var BlockList:Class; + + /** + `SocketAddress` class constructor. + + @see https://nodejs.org/api/net.html#class-netsocketaddress + **/ + static var SocketAddress:Class; + + /** + Gets the current default value of the `autoSelectFamily` option of `socket.connect(options)`. + + @see https://nodejs.org/api/net.html#netgetdefaultautoselectfamily + **/ + static function getDefaultAutoSelectFamily():Bool; + + /** + Sets the default value of the `autoSelectFamily` option of `socket.connect(options)`. + + @see https://nodejs.org/api/net.html#netsetdefaultautoselectfamilyvalue + **/ + static function setDefaultAutoSelectFamily(value:Bool):Void; + + /** + Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`. + + @see https://nodejs.org/api/net.html#netgetdefaultautoselectfamilyattempttimeout + **/ + static function getDefaultAutoSelectFamilyAttemptTimeout():Int; + + /** + Sets the default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`. + + @see https://nodejs.org/api/net.html#netsetdefaultautoselectfamilyattempttimeoutvalue + **/ + static function setDefaultAutoSelectFamilyAttemptTimeout(ms:Int):Void; } diff --git a/src/js/node/buffer/Buffer.hx b/src/js/node/buffer/Buffer.hx index c4e8e08b..7622be3f 100644 --- a/src/js/node/buffer/Buffer.hx +++ b/src/js/node/buffer/Buffer.hx @@ -691,6 +691,50 @@ extern class Buffer extends Uint8Array { return BufferModule.transcode(source, fromEnc, toEnc); }; + /** + Returns `true` if the given `input` contains only valid UTF-8-encoded data, `false` otherwise. + + This is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. + + @see https://nodejs.org/api/buffer.html#bufferisutf8input + **/ + static inline function isUtf8(input:Uint8Array):Bool { + return BufferModule.isUtf8(input); + } + + /** + Returns `true` if the given `input` contains only valid ASCII-encoded data, `false` otherwise. + + This is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. + + @see https://nodejs.org/api/buffer.html#bufferisasciiinput + **/ + static inline function isAscii(input:Uint8Array):Bool { + return BufferModule.isAscii(input); + } + + /** + Decodes a string of Base64-encoded data into bytes, and encodes those bytes into a string using Latin-1 (ISO-8859-1). + + This is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. + + @see https://nodejs.org/api/buffer.html#bufferatobdata + **/ + static inline function atob(data:String):String { + return BufferModule.atob(data); + } + + /** + Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes into a string using Base64. + + This is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. + + @see https://nodejs.org/api/buffer.html#bufferbtoadata + **/ + static inline function btoa(data:String):String { + return BufferModule.btoa(data); + } + /** `buffer.constants` is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. @@ -741,6 +785,10 @@ private extern class BufferModule { static var INSPECT_MAX_BYTES:Int; static var kMaxLength(default, never):Int; static function transcode(source:Uint8Array, fromEnc:String, toEnc:String):Buffer; + static function isUtf8(input:Uint8Array):Bool; + static function isAscii(input:Uint8Array):Bool; + static function atob(data:String):String; + static function btoa(data:String):String; static var constants(default, never):BufferConstants; } diff --git a/src/js/node/net/BlockList.hx b/src/js/node/net/BlockList.hx new file mode 100644 index 00000000..eff4bff6 --- /dev/null +++ b/src/js/node/net/BlockList.hx @@ -0,0 +1,70 @@ +/* + * Copyright (C)2014-2020 Haxe Foundation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package js.node.net; + +import haxe.extern.EitherType; + +/** + The `BlockList` object can be used with some network APIs to specify rules + for disabling inbound or outbound access to specific IP addresses, IP ranges, or IP subnets. +**/ +@:jsRequire("net", "BlockList") +extern class BlockList { + function new(); + + /** + Adds a rule to block the given IP address. + + `type` is either `'ipv4'` or `'ipv6'`. Default: `'ipv4'`. + **/ + function addAddress(address:EitherType, ?type:String):Void; + + /** + Adds a rule to block a range of IP addresses from `start` (inclusive) to `end` (inclusive). + + `type` is either `'ipv4'` or `'ipv6'`. Default: `'ipv4'`. + **/ + function addRange(start:EitherType, end:EitherType, ?type:String):Void; + + /** + Adds a rule to block a range of IP addresses specified as a subnet mask. + + `prefix` is the number of CIDR prefix bits. For IPv4, this must be between 0 and 32. + For IPv6, this must be between 0 and 128. + + `type` is either `'ipv4'` or `'ipv6'`. Default: `'ipv4'`. + **/ + function addSubnet(net:EitherType, prefix:Int, ?type:String):Void; + + /** + Returns `true` if the given IP address matches any of the rules added to the `BlockList`. + + `type` is either `'ipv4'` or `'ipv6'`. Default: `'ipv4'`. + **/ + function check(address:EitherType, ?type:String):Bool; + + /** + The list of rules added to the blocklist. + **/ + var rules(default, null):Array; +} diff --git a/src/js/node/net/SocketAddress.hx b/src/js/node/net/SocketAddress.hx new file mode 100644 index 00000000..525960ee --- /dev/null +++ b/src/js/node/net/SocketAddress.hx @@ -0,0 +1,65 @@ +/* + * Copyright (C)2014-2020 Haxe Foundation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package js.node.net; + +import haxe.extern.EitherType; + +/** + Represents a network endpoint as an IP address and port pair. + + @see https://nodejs.org/api/net.html#class-netsocketaddress +**/ +@:jsRequire("net", "SocketAddress") +extern class SocketAddress { + /** + Creates a new `SocketAddress`. + + @see https://nodejs.org/api/net.html#new-netsocketaddressoptions + **/ + function new(?options:{ + ?address:String, + ?family:EitherType, + ?flowlabel:Int, + ?port:Int + }):Void; + + /** + The network address as either an IPv4 or IPv6 string. + **/ + var address(default, null):String; + + /** + Either `'ipv4'` or `'ipv6'`. + **/ + var family(default, null):String; + + /** + An IP port. + **/ + var port(default, null):Int; + + /** + An IPv6 flow-label used only if `family` is `'ipv6'`. + **/ + var flowlabel(default, null):Int; +} From c42934e8204867f69a54033799cca5a926a8988e Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Mon, 13 Jul 2026 22:33:51 +1000 Subject: [PATCH 2/2] Align net/buffer/cluster externs with Node 24 LTS APIs. Add BlockList.isBlockList/fromJSON/toJSON and SocketAddress.parse, fix SocketAddress family typing, widen buffer isUtf8/isAscii inputs, and correct primary alias docs. Co-authored-by: Cursor --- src/js/node/Cluster.hx | 8 ++++++-- src/js/node/buffer/Buffer.hx | 11 +++++++---- src/js/node/net/BlockList.hx | 25 +++++++++++++++++++++++++ src/js/node/net/SocketAddress.hx | 16 +++++++++++++--- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/js/node/Cluster.hx b/src/js/node/Cluster.hx index a81059ad..9235377a 100644 --- a/src/js/node/Cluster.hx +++ b/src/js/node/Cluster.hx @@ -169,9 +169,11 @@ extern class Cluster extends EventEmitter { var isMaster(default, null):Bool; /** - True if the process is a primary (alias of `isMaster`). + True if the process is a primary. This is determined by the process.env.NODE_UNIQUE_ID. If process.env.NODE_UNIQUE_ID is undefined, then `isPrimary` is true. + + `isMaster` is a deprecated alias of `isPrimary`. **/ var isPrimary(default, null):Bool; @@ -197,7 +199,9 @@ extern class Cluster extends EventEmitter { function setupMaster(?settings:{?exec:String, ?args:Array, ?silent:Bool}):Void; /** - Alias of `setupMaster`. + Used to change the default `fork` behavior. Once called, the settings will be present in `settings`. + + `setupMaster` is a deprecated alias of `setupPrimary`. **/ function setupPrimary(?settings:{?exec:String, ?args:Array, ?silent:Bool}):Void; diff --git a/src/js/node/buffer/Buffer.hx b/src/js/node/buffer/Buffer.hx index 7622be3f..41ba2eb7 100644 --- a/src/js/node/buffer/Buffer.hx +++ b/src/js/node/buffer/Buffer.hx @@ -22,6 +22,7 @@ package js.node.buffer; +import haxe.extern.EitherType; import haxe.io.Bytes; import haxe.io.UInt8Array; #if haxe4 @@ -694,22 +695,24 @@ extern class Buffer extends Uint8Array { /** Returns `true` if the given `input` contains only valid UTF-8-encoded data, `false` otherwise. + `input` may be a `TypedArray`/`ArrayBufferView` or an `ArrayBuffer`. This is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. @see https://nodejs.org/api/buffer.html#bufferisutf8input **/ - static inline function isUtf8(input:Uint8Array):Bool { + static inline function isUtf8(input:EitherType):Bool { return BufferModule.isUtf8(input); } /** Returns `true` if the given `input` contains only valid ASCII-encoded data, `false` otherwise. + `input` may be a `TypedArray`/`ArrayBufferView` or an `ArrayBuffer`. This is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. @see https://nodejs.org/api/buffer.html#bufferisasciiinput **/ - static inline function isAscii(input:Uint8Array):Bool { + static inline function isAscii(input:EitherType):Bool { return BufferModule.isAscii(input); } @@ -785,8 +788,8 @@ private extern class BufferModule { static var INSPECT_MAX_BYTES:Int; static var kMaxLength(default, never):Int; static function transcode(source:Uint8Array, fromEnc:String, toEnc:String):Buffer; - static function isUtf8(input:Uint8Array):Bool; - static function isAscii(input:Uint8Array):Bool; + static function isUtf8(input:EitherType):Bool; + static function isAscii(input:EitherType):Bool; static function atob(data:String):String; static function btoa(data:String):String; static var constants(default, never):BufferConstants; diff --git a/src/js/node/net/BlockList.hx b/src/js/node/net/BlockList.hx index eff4bff6..64ed4c2b 100644 --- a/src/js/node/net/BlockList.hx +++ b/src/js/node/net/BlockList.hx @@ -32,6 +32,13 @@ import haxe.extern.EitherType; extern class BlockList { function new(); + /** + Returns `true` if the `value` is a `net.BlockList`. + + @see https://nodejs.org/api/net.html#blocklistisblocklistvalue + **/ + static function isBlockList(value:Dynamic):Bool; + /** Adds a rule to block the given IP address. @@ -67,4 +74,22 @@ extern class BlockList { The list of rules added to the blocklist. **/ var rules(default, null):Array; + + /** + Loads rules from a JSON string or an array of rule strings (same format as `rules`). + + Stability: 1 - Experimental. + + @see https://nodejs.org/api/net.html#blocklistfromjsonvalue + **/ + function fromJSON(value:EitherType>):Void; + + /** + Returns the rules as a JSON-serializable array of strings (same format as `rules`). + + Stability: 1 - Experimental. + + @see https://nodejs.org/api/net.html#blocklisttojson + **/ + function toJSON():Array; } diff --git a/src/js/node/net/SocketAddress.hx b/src/js/node/net/SocketAddress.hx index 525960ee..19c5fb1e 100644 --- a/src/js/node/net/SocketAddress.hx +++ b/src/js/node/net/SocketAddress.hx @@ -22,8 +22,6 @@ package js.node.net; -import haxe.extern.EitherType; - /** Represents a network endpoint as an IP address and port pair. @@ -34,15 +32,27 @@ extern class SocketAddress { /** Creates a new `SocketAddress`. + `family` is either `'ipv4'` or `'ipv6'`. Default: `'ipv4'`. + @see https://nodejs.org/api/net.html#new-netsocketaddressoptions **/ function new(?options:{ ?address:String, - ?family:EitherType, + ?family:String, ?flowlabel:Int, ?port:Int }):Void; + /** + Parses an IP address and optional port string into a `SocketAddress`. + + `input` examples: `123.1.2.3:1234` or `[1::1]:1234`. + Returns `null`/`undefined` if parsing fails. + + @see https://nodejs.org/api/net.html#socketaddressparseinput + **/ + static function parse(input:String):Null; + /** The network address as either an IPv4 or IPv6 string. **/