├── deploy.hxml ├── .gitignore ├── package.json ├── hxnodejs.png ├── completion.hxml ├── extraParams.hxml ├── .vscode ├── tasks.json └── settings.json ├── examples ├── VmRunInContext.hx ├── VmRunInNewContext.hx ├── TcpServer.hx ├── StreamPipe.hx ├── VmScriptRunInNewContext.hx ├── VmScriptRunInThisContext.hx ├── VmScriptRunInContext.hx ├── DgramSendExample.hx ├── WebServer.hx ├── FsExample.hx ├── NetEchoServerExample.hx ├── ConsoleClass.hx ├── VmRunInThisContext.hx ├── StreamImplCounter.hx ├── CryptoECDHExample.hx ├── AssertThrows.hx ├── NetEchoClientExample.hx ├── Sha1Sum.hx ├── ChildProcessExample.hx ├── TlsConnectPfxExample.hx ├── DnsExample.hx ├── CryptoCipherExample.hx ├── DgramServerExample.hx ├── TlsServerPfxExample.hx ├── ReadlineTinyCLI.hx ├── ClusterExample.hx ├── TlsConnectPemExample.hx ├── TlsServerPemExample.hx ├── ReplExample.hx ├── StreamExample.hx ├── StreamImplSimpleProtocol2.hx └── StreamImplSimpleProtocol.hx ├── doc.hxml ├── ci ├── Config.hx ├── Utils.hx └── DeployGhPages.hx ├── haxelib.json ├── .travis.yml ├── BuildExamples.hx ├── src ├── haxe │ └── zip │ │ ├── Compress.hx │ │ └── Uncompress.hx ├── sys │ ├── NodeSync.hx │ ├── net │ │ ├── Host.hx │ │ └── Socket.hx │ ├── io │ │ ├── FileOutput.hx │ │ ├── FileInput.hx │ │ └── File.hx │ └── FileSystem.hx ├── _internal │ └── SuppressDeprecated.hx ├── js │ └── node │ │ ├── Buffer.hx │ │ ├── Report.hx │ │ ├── zlib │ │ ├── Gzip.hx │ │ ├── Gunzip.hx │ │ ├── Deflate.hx │ │ ├── Inflate.hx │ │ ├── InflateRaw.hx │ │ ├── DeflateRaw.hx │ │ ├── Unzip.hx │ │ └── Zlib.hx │ │ ├── https │ │ ├── Server.hx │ │ └── Agent.hx │ │ ├── Iterator.hx │ │ ├── KeyValue.hx │ │ ├── stream │ │ ├── PassThrough.hx │ │ └── Transform.hx │ │ ├── Domain.hx │ │ ├── Tty.hx │ │ ├── tty │ │ ├── ReadStream.hx │ │ └── WriteStream.hx │ │ ├── Dgram.hx │ │ ├── fs │ │ ├── ReadStream.hx │ │ ├── WriteStream.hx │ │ ├── FSWatcher.hx │ │ └── Stats.hx │ │ ├── tls │ │ ├── SecurePair.hx │ │ ├── SecureContext.hx │ │ └── Server.hx │ │ ├── util │ │ ├── TextEncoder.hx │ │ ├── Promisify.hx │ │ ├── Inspect.hx │ │ └── TextDecoder.hx │ │ ├── Constants.hx │ │ ├── crypto │ │ ├── Certificate.hx │ │ ├── Hmac.hx │ │ ├── Sign.hx │ │ ├── Hash.hx │ │ ├── Verify.hx │ │ ├── Decipher.hx │ │ ├── Cipher.hx │ │ ├── ECDH.hx │ │ └── DiffieHellman.hx │ │ ├── Events.hx │ │ ├── http │ │ └── Method.hx │ │ ├── buffer │ │ └── SlowBuffer.hx │ │ ├── StringDecoder.hx │ │ ├── V8.hx │ │ ├── Punycode.hx │ │ ├── assert │ │ └── AssertionError.hx │ │ ├── Stream.hx │ │ ├── vm │ │ └── Script.hx │ │ ├── Https.hx │ │ ├── url │ │ └── URL.hx │ │ ├── Module.hx │ │ ├── Require.hx │ │ ├── Net.hx │ │ ├── Vm.hx │ │ └── cluster │ │ └── Worker.hx └── Sys.hx ├── ImportAll.hx ├── LICENSE.md ├── Release.hx └── README.md /deploy.hxml: -------------------------------------------------------------------------------- 1 | -cp ci 2 | --run DeployGhPages -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*.hxproj 2 | /bin 3 | /examples/*.js 4 | /release.zip 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hxnodejs", 3 | "private": true 4 | } 5 | -------------------------------------------------------------------------------- /hxnodejs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HaxeFoundation/hxnodejs/HEAD/hxnodejs.png -------------------------------------------------------------------------------- /completion.hxml: -------------------------------------------------------------------------------- 1 | -cp src 2 | -js dummy 3 | --macro include('js', true, [], ['src']) 4 | --no-output 5 | -------------------------------------------------------------------------------- /extraParams.hxml: -------------------------------------------------------------------------------- 1 | --macro allowPackage('sys') 2 | # should behave like other target defines and not be defined in macro context 3 | --macro define('nodejs') 4 | --macro _internal.SuppressDeprecated.run() 5 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "hxml", 6 | "file": "build.hxml", 7 | "group": { 8 | "kind": "build", 9 | "isDefault": true 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "haxe.configurations": [ 3 | ["completion.hxml"] 4 | ], 5 | "[haxe]": { 6 | "editor.formatOnSave": true, 7 | // "editor.formatOnPaste": true, 8 | "editor.codeActionsOnSave": { 9 | "source.sortImports": true 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/VmRunInContext.hx: -------------------------------------------------------------------------------- 1 | import js.node.Vm; 2 | import js.node.Util; 3 | 4 | class VmRunInContext { 5 | static function main() { 6 | var sandbox = {globalVar: 1}; 7 | Vm.createContext(sandbox); 8 | for (i in 0...10) 9 | Vm.runInContext('globalVar *= 2;', sandbox); 10 | trace(Util.inspect(sandbox)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/VmRunInNewContext.hx: -------------------------------------------------------------------------------- 1 | import js.node.Vm; 2 | import js.node.Util; 3 | 4 | class VmRunInNewContext { 5 | static function main() { 6 | var sandbox = { 7 | animal: 'cat', 8 | count: 2 9 | }; 10 | Vm.runInNewContext('count += 1; name = "kitty"', sandbox); 11 | trace(Util.inspect(sandbox)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /doc.hxml: -------------------------------------------------------------------------------- 1 | -js dummy 2 | -D doc-gen 3 | --macro ImportAll.run("src") 4 | --no-output 5 | -xml bin/js.xml 6 | 7 | --next 8 | 9 | -cmd haxelib run dox -o bin/api -i bin --title "HXNODEJS - API documentation" -D themeColor 0xEEEEEE -D textColor 0x555555 -D logo http://take.ms/dlXH9 -D source-path https://github.com/HaxeFoundation/hxnodejs/blob/master/src/ 10 | -------------------------------------------------------------------------------- /examples/TcpServer.hx: -------------------------------------------------------------------------------- 1 | import js.node.Net; 2 | 3 | /** 4 | Example tcp server from the node.js main page 5 | **/ 6 | class TcpServer { 7 | static function main() { 8 | var server = Net.createServer(function(socket) { 9 | socket.write('Echo server\r\n'); 10 | socket.pipe(socket); 11 | }); 12 | server.listen(1337, '127.0.0.1'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/StreamPipe.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.node.Zlib; 3 | 4 | /** 5 | Pipe chaining example from the streams page 6 | **/ 7 | class StreamPipe { 8 | static function main() { 9 | var r = Fs.createReadStream('file.txt'); 10 | var z = Zlib.createGzip(); 11 | var w = Fs.createWriteStream('file.txt.gz'); 12 | r.pipe(z).pipe(w); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/VmScriptRunInNewContext.hx: -------------------------------------------------------------------------------- 1 | import js.node.Util; 2 | import js.node.vm.Script; 3 | 4 | class VmScriptRunInNewContext { 5 | static function main() { 6 | var sandboxes = [{}, {}, {}]; 7 | var script = new Script('globalVar = "set"'); 8 | for (sandbox in sandboxes) 9 | script.runInNewContext(sandbox); 10 | trace(Util.inspect(sandboxes)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/VmScriptRunInThisContext.hx: -------------------------------------------------------------------------------- 1 | import js.Node.global; 2 | import js.node.vm.Script; 3 | 4 | class VmScriptRunInThisContext { 5 | static function main() { 6 | global.globalVar = 0; 7 | var script = new Script('globalVar += 1', {filename: 'myfile.vm'}); 8 | for (i in 0...1000) 9 | script.runInThisContext(); 10 | trace(global.globalVar); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ci/Config.hx: -------------------------------------------------------------------------------- 1 | import Utils.*; 2 | 3 | class Config { 4 | static public var htmlDir = env("GHP_HTMLDIR", "bin/api"); 5 | static public var remote = env("GHP_REMOTE", null); // should be in the form of https://token@github.com/account/repo.git 6 | static public var branch = env("GHP_BRANCH", "gh-pages"); 7 | static public var username = env("GHP_USERNAME", null); 8 | static public var email = env("GHP_EMAIL", null); 9 | } 10 | -------------------------------------------------------------------------------- /examples/VmScriptRunInContext.hx: -------------------------------------------------------------------------------- 1 | import js.node.Util; 2 | import js.node.Vm; 3 | import js.node.vm.Script; 4 | 5 | class VmScriptRunInContext { 6 | static function main() { 7 | var sandbox = Vm.createContext({ 8 | animal: 'cat', 9 | count: 2 10 | }); 11 | var script = new Script('count += 1; name = "kitty"'); 12 | for (i in 0...10) 13 | script.runInContext(sandbox); 14 | trace(Util.inspect(sandbox)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/DgramSendExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Dgram; 2 | import js.node.Buffer; 3 | 4 | /** 5 | A `socket.send` example from the dgram API page. 6 | **/ 7 | class DgramSendExample { 8 | static function main() { 9 | var message = new Buffer("Some bytes"); 10 | var client = Dgram.createSocket("udp4"); 11 | client.send(message, 0, message.length, 41234, "localhost", function(err, bytes) { 12 | client.close(); 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/WebServer.hx: -------------------------------------------------------------------------------- 1 | import js.node.Http; 2 | import js.Node.console; 3 | 4 | /** 5 | Example web server from the node.js main page 6 | **/ 7 | class WebServer { 8 | static function main() { 9 | Http.createServer(function(req, res) { 10 | res.writeHead(200, {'Content-Type': 'text/plain'}); 11 | res.end('Hello World\n'); 12 | }).listen(1337, '127.0.0.1'); 13 | console.log('Server running at http://127.0.0.1:1337/'); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hxnodejs", 3 | "url": "https://github.com/HaxeFoundation/hxnodejs", 4 | "description": "Extern definitions for node.js", 5 | "license": "MIT", 6 | "version": "12.2.0", 7 | "releasenote": "Update some API, fix some deprecation warnings.", 8 | "classPath": "src", 9 | "contributors": ["nadako", "Simn", "Gama11", "HaxeFoundation"], 10 | "tags": ["js", "nodejs", "async", "net", "web", "extern"] 11 | } 12 | -------------------------------------------------------------------------------- /examples/FsExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.Node.console; 3 | 4 | /** 5 | Example from fs API page. 6 | **/ 7 | class FsExample { 8 | static function main() { 9 | Fs.rename('/tmp/hello', '/tmp/world', function(err) { 10 | if (err != null) 11 | throw err; 12 | Fs.stat('/tmp/world', function(err, stats) { 13 | if (err != null) 14 | throw err; 15 | console.log('stats: ' + haxe.Json.stringify(stats)); 16 | }); 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: haxe 2 | dist: xenial 3 | 4 | haxe: 5 | - 3.4.7 6 | - development 7 | 8 | install: 9 | haxelib dev hxnodejs . 10 | 11 | script: 12 | - haxe build.hxml 13 | - haxelib git dox https://github.com/HaxeFoundation/dox 14 | - haxe doc.hxml 15 | 16 | deploy: 17 | provider: script 18 | script: haxe deploy.hxml 19 | on: 20 | branch: master 21 | haxe: development 22 | condition: $TRAVIS_EVENT_TYPE != "cron" 23 | skip_cleanup: true 24 | -------------------------------------------------------------------------------- /examples/NetEchoServerExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Net; 2 | import js.node.net.Socket.SocketEvent; 3 | 4 | class NetEchoServerExample { 5 | static function main() { 6 | var server = Net.createServer(function(c) { // 'connection' listener 7 | trace('client connected'); 8 | c.on(SocketEvent.End, function() trace('client disconnected')); 9 | c.write('hello\r\n'); 10 | c.pipe(c); 11 | }); 12 | server.listen(8124, function() trace('server bound')); // 'listening' listener 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/ConsoleClass.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.node.console.Console; 3 | 4 | /** 5 | Example of the Console class usage. 6 | **/ 7 | class ConsoleClass { 8 | static function main() { 9 | var output = Fs.createWriteStream('./stdout.log'); 10 | var errorOutput = Fs.createWriteStream('./stderr.log'); 11 | // custom simple logger 12 | var logger = new Console(output, errorOutput); 13 | // use it like console 14 | var count = 5; 15 | logger.log('count: %d', count); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/VmRunInThisContext.hx: -------------------------------------------------------------------------------- 1 | import js.Node.console; 2 | import js.node.Vm; 3 | import js.node.Util; 4 | 5 | class VmRunInThisContext { 6 | static function main() { 7 | var localVar = 'initial value'; 8 | 9 | var vmResult = Vm.runInThisContext('localVar = "vm";'); 10 | console.log('vmResult: ', vmResult); 11 | console.log('localVar: ', localVar); 12 | 13 | var evalResult = js.Lib.eval('localVar = "eval";'); 14 | console.log('evalResult: ', evalResult); 15 | console.log('localVar: ', localVar); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/StreamImplCounter.hx: -------------------------------------------------------------------------------- 1 | import js.node.Buffer; 2 | import js.node.stream.Readable; 3 | 4 | /** 5 | A Counting Stream 6 | **/ 7 | @:keep 8 | class Counter extends Readable { 9 | var _max = 1000000; 10 | var _index = 1; 11 | 12 | override function _read(_) { 13 | var i = _index++; 14 | if (i > _max) 15 | push(null); 16 | else { 17 | var str = '' + i; 18 | var buf = new Buffer(str, 'ascii'); 19 | push(buf); 20 | } 21 | } 22 | } 23 | 24 | class StreamImplCounter { 25 | static function main() {} 26 | } 27 | -------------------------------------------------------------------------------- /examples/CryptoECDHExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Crypto; 2 | 3 | class CryptoECDHExample { 4 | static function main() { 5 | var alice = Crypto.createECDH('secp256k1'); 6 | var bob = Crypto.createECDH('secp256k1'); 7 | 8 | alice.generateKeys(); 9 | bob.generateKeys(); 10 | 11 | var alice_secret = alice.computeSecret(bob.getPublicKey(), null, 'hex'); 12 | var bob_secret = bob.computeSecret(alice.getPublicKey(), null, 'hex'); 13 | 14 | /* alice_secret and bob_secret should be the same */ 15 | trace(alice_secret == bob_secret); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/AssertThrows.hx: -------------------------------------------------------------------------------- 1 | #if haxe4 2 | import js.lib.Error; 3 | import js.lib.RegExp; 4 | #else 5 | import js.Error; 6 | import js.RegExp; 7 | #end 8 | import js.node.Assert; 9 | 10 | class AssertThrows { 11 | static function main() { 12 | Assert.throws(function() throw new Error("Wrong value"), Error); 13 | Assert.throws(function() throw new Error("Wrong value"), new RegExp("value")); 14 | Assert.throws(function() throw new Error("Wrong value"), function(err) return (Std.is(err, Error) && ~/value/.match(err.message)), "unexpected error"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/NetEchoClientExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Buffer; 2 | import js.node.Net; 3 | import js.node.net.Socket; 4 | 5 | class NetEchoClientExample { 6 | static function main() { 7 | var client:Socket; 8 | client = Net.connect({port: 8124}, function() { // 'connect' listener 9 | trace('connected to server!'); 10 | client.write('world!\r\n'); 11 | }); 12 | client.on(SocketEvent.Data, function(data:Buffer) { 13 | trace(data.toString()); 14 | client.end(); 15 | }); 16 | client.on(SocketEvent.End, function() trace('disconnected from server')); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/Sha1Sum.hx: -------------------------------------------------------------------------------- 1 | import js.node.Crypto; 2 | import js.node.Fs; 3 | import js.Node.process; 4 | import js.Node.console; 5 | 6 | /** 7 | Sha1 hash example from the crypto page 8 | **/ 9 | class Sha1Sum { 10 | static function main() { 11 | var filename = process.argv[2]; 12 | 13 | var shasum = Crypto.createHash('sha1'); 14 | 15 | var s = Fs.createReadStream(filename); 16 | s.on('data', function(d) { 17 | shasum.update(d); 18 | }); 19 | 20 | s.on('end', function() { 21 | var d = shasum.digest('hex'); 22 | console.log(d + ' ' + filename); 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/ChildProcessExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.ChildProcess.spawn; 2 | import js.Node.console; 3 | 4 | /** 5 | child_process.spawn example from child process page 6 | **/ 7 | class ChildProcessExample { 8 | static function main() { 9 | var ls = spawn('ls', ['-lh', '/usr']); 10 | 11 | ls.stdout.on('data', function(data) { 12 | console.log('stdout: ' + data); 13 | }); 14 | 15 | ls.stderr.on('data', function(data) { 16 | console.log('stderr: ' + data); 17 | }); 18 | 19 | ls.on('close', function(code) { 20 | console.log('child process exited with code ' + code); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BuildExamples.hx: -------------------------------------------------------------------------------- 1 | import haxe.io.Path; 2 | import sys.FileSystem; 3 | 4 | class BuildExamples { 5 | static function main() { 6 | Sys.setCwd("examples"); 7 | for (file in FileSystem.readDirectory(".")) { 8 | if (Path.extension(file) == "hx") { 9 | var main = Path.withoutExtension(file); 10 | var code = Sys.command("haxe", [ 11 | "-main", main, 12 | "-js", '$main.js', 13 | "-lib", "hxnodejs", 14 | "-D", "js-es5", 15 | "-D", "analyzer", 16 | "-dce", "full", 17 | ]); 18 | if (code != 0) 19 | Sys.exit(code); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/TlsConnectPfxExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.node.Tls; 3 | import js.node.tls.TLSSocket; 4 | import js.Node.process; 5 | 6 | class TlsConnectPfxExample { 7 | static function main() { 8 | var options = { 9 | pfx: Fs.readFileSync('client.pfx') 10 | }; 11 | 12 | var socket:TLSSocket; 13 | socket = Tls.connect(8000, options, function() { 14 | trace('client connected', socket.authorized ? 'authorized' : 'unauthorized'); 15 | process.stdin.pipe(socket); 16 | process.stdin.resume(); 17 | }); 18 | socket.setEncoding('utf8'); 19 | socket.on('data', function(data) trace(data)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/DnsExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Dns; 2 | import js.Node.console; 3 | 4 | /** 5 | An example from the dns page 6 | **/ 7 | class DnsExample { 8 | static function main() { 9 | Dns.resolve4('www.google.com', function(err, addresses) { 10 | if (err != null) 11 | throw err; 12 | 13 | console.log('addresses: ' + haxe.Json.stringify(addresses)); 14 | 15 | for (a in addresses) { 16 | Dns.reverse(a, function(err, domains) { 17 | if (err != null) { 18 | throw err; 19 | } 20 | 21 | console.log('reverse for ' + a + ': ' + haxe.Json.stringify(domains)); 22 | }); 23 | } 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/CryptoCipherExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Crypto; 2 | import js.node.Buffer; 3 | 4 | class CryptoCipherExample { 5 | static function main() { 6 | var cipher = Crypto.createCipher('aes192', 'a password'); 7 | 8 | var encrypted = ''; 9 | cipher.on('readable', function() { 10 | var data:Buffer = cipher.read(); 11 | if (data != null) 12 | encrypted += data.toString('hex'); 13 | }); 14 | cipher.on('end', function() { 15 | trace(encrypted); 16 | // Prints: ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504 17 | }); 18 | 19 | cipher.write('some clear text data'); 20 | cipher.end(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/haxe/zip/Compress.hx: -------------------------------------------------------------------------------- 1 | package haxe.zip; 2 | 3 | class Compress { 4 | public function new(level:Int) { 5 | throw "Not implemented for this platform"; 6 | } 7 | 8 | public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} { 9 | return null; 10 | } 11 | 12 | public function setFlushMode(f:FlushMode) {} 13 | 14 | public function close() {} 15 | 16 | public static function run(s:haxe.io.Bytes, level:Int):haxe.io.Bytes { 17 | var buffer = js.node.Zlib.deflateSync(js.node.Buffer.hxFromBytes(s), {level: level}); 18 | return buffer.hxToBytes(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/DgramServerExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Dgram; 2 | import js.Node.console; 3 | 4 | class DgramServerExample { 5 | static function main() { 6 | var server = Dgram.createSocket("udp4"); 7 | 8 | server.on("error", function(err) { 9 | console.log("server error:\n" + err.stack); 10 | server.close(); 11 | }); 12 | 13 | server.on("message", function(msg, rinfo) { 14 | console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port); 15 | }); 16 | 17 | server.on("listening", function() { 18 | var address = server.address(); 19 | console.log("server listening " + address.address + ":" + address.port); 20 | }); 21 | 22 | server.bind(41234); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/TlsServerPfxExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.node.Tls; 3 | 4 | /** 5 | example from the tls.createServer documentation 6 | **/ 7 | class TlsServerPfxExample { 8 | static function main() { 9 | var options = { 10 | pfx: Fs.readFileSync('server.pfx'), 11 | 12 | // This is necessary only if using the client certificate authentication. 13 | requestCert: true, 14 | }; 15 | 16 | var server = Tls.createServer(options, function(socket) { 17 | trace('server connected', socket.authorized ? 'authorized' : 'unauthorized'); 18 | socket.write("welcome!\n"); 19 | socket.setEncoding('utf8'); 20 | socket.pipe(socket); 21 | }); 22 | server.listen(8000, function() trace('server bound')); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/ReadlineTinyCLI.hx: -------------------------------------------------------------------------------- 1 | import js.node.Readline; 2 | import js.node.readline.Interface; 3 | import js.Node.process; 4 | import js.Node.console; 5 | 6 | using StringTools; 7 | 8 | class ReadlineTinyCLI { 9 | static function main() { 10 | var rl = Readline.createInterface(process.stdin, process.stdout); 11 | rl.setPrompt('OHAI> '); 12 | rl.prompt(); 13 | rl.on(InterfaceEvent.Line, function(line) { 14 | switch (line.trim()) { 15 | case 'hello': 16 | console.log('world!'); 17 | default: 18 | console.log('Say what? I might have heard `' + line.trim() + '`'); 19 | } 20 | rl.prompt(); 21 | }).on(InterfaceEvent.Close, function() { 22 | console.log('Have a great day!'); 23 | process.exit(0); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/sys/NodeSync.hx: -------------------------------------------------------------------------------- 1 | package sys; 2 | 3 | @:jsRequire('deasync') 4 | private extern class Deasync { 5 | public static function loopWhile(f:Void->Bool):Void; 6 | } 7 | 8 | class NodeSync { 9 | public static function callMany(f:Dynamic->Void):Array { 10 | var retArgs = null; 11 | var wait = Reflect.makeVarArgs(function(args) retArgs = args); 12 | f(wait); 13 | Deasync.loopWhile(function() return retArgs == null); 14 | return retArgs; 15 | } 16 | 17 | public static function callVoid(f:(Void->Void)->Void) { 18 | var called = false; 19 | f(function() called = true); 20 | Deasync.loopWhile(function() return !called); 21 | } 22 | 23 | public static inline function wait(f:Void->Bool) { 24 | Deasync.loopWhile(function() return !f()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/ClusterExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Cluster.instance as cluster; 2 | import js.node.cluster.Worker; 3 | import js.node.Http; 4 | import js.node.Os; 5 | import js.Node.console; 6 | 7 | /** 8 | Example from the cluster api doc 9 | **/ 10 | class ClusterExample { 11 | static function main() { 12 | var numCPUs = Os.cpus().length; 13 | if (cluster.isMaster) { 14 | // Fork workers. 15 | for (i in 0...numCPUs) { 16 | cluster.fork(); 17 | } 18 | 19 | cluster.on('exit', function(worker:Worker, code:Int, signal:String) { 20 | console.log('worker ' + worker.process.pid + ' died'); 21 | }); 22 | } else { 23 | // Workers can share any TCP connection 24 | // In this case its a HTTP server 25 | Http.createServer(function(req, res) { 26 | res.writeHead(200); 27 | res.end("hello world\n"); 28 | }).listen(8000); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/TlsConnectPemExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.node.Tls; 3 | import js.node.tls.TLSSocket; 4 | import js.Node.process; 5 | 6 | class TlsConnectPemExample { 7 | static function main() { 8 | var options = { 9 | // These are necessary only if using the client certificate authentication 10 | key: Fs.readFileSync('client-key.pem'), 11 | cert: Fs.readFileSync('client-cert.pem'), 12 | 13 | // This is necessary only if the server uses the self-signed certificate 14 | ca: [Fs.readFileSync('server-cert.pem')] 15 | }; 16 | 17 | var socket:TLSSocket; 18 | socket = Tls.connect(8000, options, function() { 19 | trace('client connected', socket.authorized ? 'authorized' : 'unauthorized'); 20 | process.stdin.pipe(socket); 21 | process.stdin.resume(); 22 | }); 23 | socket.setEncoding('utf8'); 24 | socket.on('data', function(data) trace(data)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/TlsServerPemExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Fs; 2 | import js.node.Tls; 3 | 4 | /** 5 | example from the tls.createServer documentation 6 | **/ 7 | class TlsServerPemExample { 8 | static function main() { 9 | var options = { 10 | key: Fs.readFileSync('server-key.pem'), 11 | cert: Fs.readFileSync('server-cert.pem'), 12 | 13 | // This is necessary only if using the client certificate authentication. 14 | requestCert: true, 15 | 16 | // This is necessary only if the client uses the self-signed certificate. 17 | ca: [Fs.readFileSync('client-cert.pem')] 18 | }; 19 | 20 | var server = Tls.createServer(options, function(socket) { 21 | trace('server connected', socket.authorized ? 'authorized' : 'unauthorized'); 22 | socket.write("welcome!\n"); 23 | socket.setEncoding('utf8'); 24 | socket.pipe(socket); 25 | }); 26 | server.listen(8000, function() trace('server bound')); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ReplExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Net; 2 | import js.node.Repl; 3 | import js.Node.process; 4 | 5 | /** 6 | Example from the REPL page 7 | **/ 8 | class ReplExample { 9 | static function main() { 10 | var connections = 0; 11 | 12 | Repl.start({ 13 | prompt: "node via stdin> ", 14 | input: process.stdin, 15 | output: process.stdout 16 | }); 17 | 18 | Net.createServer(function(socket) { 19 | connections += 1; 20 | Repl.start({ 21 | prompt: "node via Unix socket> ", 22 | input: socket, 23 | output: socket 24 | }).on('exit', function() { 25 | socket.end(); 26 | }); 27 | }).listen("/tmp/node-repl-sock"); 28 | 29 | Net.createServer(function(socket) { 30 | connections += 1; 31 | Repl.start({ 32 | prompt: "node via TCP socket> ", 33 | input: socket, 34 | output: socket 35 | }).on('exit', function() { 36 | socket.end(); 37 | }); 38 | }).listen(5001); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/sys/net/Host.hx: -------------------------------------------------------------------------------- 1 | package sys.net; 2 | 3 | @:coreApi 4 | @:allow(sys.net.Socket) 5 | class Host { 6 | #if (haxe_ver >= 3.3) public #end var host(default, null):String; 7 | 8 | public var ip(default, null):Int; 9 | 10 | var ipStr:String; 11 | 12 | public function new(name:String):Void { 13 | var ret = sys.NodeSync.callMany(function(callb) js.node.Dns.lookup(name, {family: 4}, callb)); 14 | if (ret[0] != null) 15 | throw ret[0]; // error 16 | this.host = name; 17 | ipStr = ret[1]; 18 | var parts = [for (p in ipStr.split(".")) Std.parseInt(p)]; 19 | ip = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]; 20 | } 21 | 22 | public function toString():String { 23 | return ipStr; 24 | } 25 | 26 | public function reverse():String { 27 | throw "Not implemented"; 28 | return null; 29 | } 30 | 31 | public static function localhost():String { 32 | throw "Not implemented"; 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ImportAll.hx: -------------------------------------------------------------------------------- 1 | import haxe.io.Path; 2 | import haxe.macro.Compiler; 3 | import haxe.macro.Context; 4 | import sys.FileSystem; 5 | 6 | class ImportAll { 7 | static function run(cp:String):Void { 8 | Compiler.addClassPath(cp); 9 | Compiler.allowPackage("sys"); 10 | Compiler.define("nodejs"); 11 | 12 | function loop(acc:Array):Void { 13 | var path = Path.join([cp].concat(acc)); 14 | if (FileSystem.isDirectory(path)) { 15 | if (acc.length > 0 && acc[acc.length - 1].charCodeAt(0) == "_".code) // skip hidden packages 16 | return; 17 | for (file in FileSystem.readDirectory(path)) 18 | if (!~/^_/.match(file)) 19 | loop(acc.concat([file])); 20 | } else if (Path.extension(path) == "hx") { 21 | var moduleName = Path.withoutExtension(acc[acc.length - 1]); 22 | var modulePath = acc.slice(0, acc.length - 1); 23 | var typePath = if (modulePath.length == 0) moduleName else modulePath.join(".") + "." + moduleName; 24 | Context.getType(typePath); 25 | } 26 | } 27 | loop([]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/haxe/zip/Uncompress.hx: -------------------------------------------------------------------------------- 1 | package haxe.zip; 2 | 3 | import js.node.Buffer; 4 | import js.node.Zlib; 5 | 6 | class Uncompress { 7 | var windowBits:Null; 8 | 9 | public function new(?windowBits:Int) { 10 | this.windowBits = windowBits; 11 | } 12 | 13 | public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} { 14 | var src = js.node.Buffer.hxFromBytes(src).slice(srcPos); 15 | var dst = js.node.Buffer.hxFromBytes(dst); 16 | var res = cast Zlib.inflateRawSync(src, cast {info: true, /* windowBits: windowBits */}); 17 | var engine = res.engine; 18 | var res:Buffer = res.buffer; 19 | dst.set(res, dstPos); 20 | return {done: true, read: engine.bytesRead, write: res.byteLength}; 21 | } 22 | 23 | public function setFlushMode(f:FlushMode) {} 24 | 25 | public function close() {} 26 | 27 | public static function run(src:haxe.io.Bytes, ?bufsize:Int):haxe.io.Bytes { 28 | var buffer = js.node.Zlib.inflateSync(js.node.Buffer.hxFromBytes(src), bufsize == null ? {} : {chunkSize: bufsize}); 29 | return buffer.hxToBytes(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Haxe Foundation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/_internal/SuppressDeprecated.hx: -------------------------------------------------------------------------------- 1 | #if macro 2 | package _internal; 3 | 4 | import haxe.macro.Context; 5 | 6 | @:noCompletion 7 | class SuppressDeprecated { 8 | public static function run() { 9 | #if haxe4 10 | Context.onAfterTyping(function(_) { 11 | Context.filterMessages(x -> switch x { 12 | case Warning(msg, pos) if (~/js\/node\/Url\.hx$/.match(Context.getPosInfos(pos).file)): 13 | msg != "This typedef is deprecated in favor of { ?slashes : Null, ?search : Null, ?query : Null>>, ?protocol : Null, ?port : Null, ?pathname : Null, ?path : Null, ?href : Null, ?hostname : Null, ?host : Null, ?hash : Null, ?auth : Null }"; 14 | case Warning(msg, pos) if (~/js\/node\/domain\/Domain\.hx$/.match(Context.getPosInfos(pos).file)): 15 | msg != "This typedef is deprecated in favor of { domainThrown : Bool, domainEmitter : js.node.events.IEventEmitter, domainBound : haxe.Function, domain : js.node.domain.Domain }"; 16 | case _: 17 | true; 18 | }); 19 | }); 20 | #end 21 | } 22 | } 23 | #end 24 | -------------------------------------------------------------------------------- /src/sys/io/FileOutput.hx: -------------------------------------------------------------------------------- 1 | package sys.io; 2 | 3 | import haxe.io.Bytes; 4 | import haxe.io.Eof; 5 | import haxe.io.Error; 6 | import js.node.Buffer; 7 | import js.node.Fs; 8 | 9 | @:coreApi 10 | class FileOutput extends haxe.io.Output { 11 | var fd:Int; 12 | var pos:Int; 13 | 14 | @:allow(sys.io.File) 15 | function new(fd:Int) { 16 | this.fd = fd; 17 | pos = 0; 18 | } 19 | 20 | override public function writeByte(b:Int):Void { 21 | var buf = Buffer.alloc(1); 22 | buf[0] = b; 23 | Fs.writeSync(fd, buf, 0, 1, pos); 24 | pos++; 25 | } 26 | 27 | override public function writeBytes(s:Bytes, pos:Int, len:Int):Int { 28 | var buf = Buffer.hxFromBytes(s); 29 | var wrote = Fs.writeSync(fd, buf, pos, len, this.pos); 30 | this.pos += wrote; 31 | return wrote; 32 | } 33 | 34 | override public function close():Void { 35 | Fs.closeSync(fd); 36 | } 37 | 38 | public function seek(p:Int, pos:FileSeek):Void { 39 | switch (pos) { 40 | case SeekBegin: 41 | this.pos = p; 42 | case SeekEnd: 43 | this.pos = cast Fs.fstatSync(fd).size + p; 44 | case SeekCur: 45 | this.pos += p; 46 | } 47 | } 48 | 49 | public function tell():Int { 50 | return pos; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/StreamExample.hx: -------------------------------------------------------------------------------- 1 | import js.node.Http; 2 | #if haxe4 3 | import js.lib.Error; 4 | #else 5 | import js.Error; 6 | #end 7 | 8 | /** 9 | An example from the stream page 10 | **/ 11 | class StreamExample { 12 | static function main() { 13 | var server = Http.createServer(function(req, res) { 14 | // req is an http.IncomingMessage, which is a Readable Stream 15 | // res is an http.ServerResponse, which is a Writable Stream 16 | 17 | var body = ''; 18 | // we want to get the data as utf8 strings 19 | // If you don't set an encoding, then you'll get Buffer objects 20 | req.setEncoding('utf8'); 21 | 22 | // Readable streams emit 'data' events once a listener is added 23 | req.on('data', function(chunk) { 24 | body += chunk; 25 | }); 26 | 27 | // the end event tells you that you have entire body 28 | req.on('end', function() { 29 | var data = try { 30 | haxe.Json.parse(body); 31 | } catch (er:Error) { 32 | // uh oh! bad json! 33 | res.statusCode = 400; 34 | return res.end('error: ' + er.message); 35 | } 36 | 37 | // write back something interesting to the user: 38 | res.write(Std.string(Type.typeof(data))); 39 | res.end(); 40 | }); 41 | }); 42 | 43 | server.listen(1337); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/js/node/Buffer.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | typedef Buffer = js.node.buffer.Buffer; 26 | -------------------------------------------------------------------------------- /src/js/node/Report.hx: -------------------------------------------------------------------------------- 1 | package js.node; 2 | 3 | #if haxe4 4 | import js.lib.Error; 5 | #else 6 | import js.Error; 7 | #end 8 | 9 | extern class Report { 10 | /** 11 | If the reports are written in compact mode. 12 | **/ 13 | var compact:Bool; 14 | 15 | /** 16 | The directory in which the reports are written. 17 | **/ 18 | var directory:String; 19 | 20 | /** 21 | The file in which the reports are written. 22 | **/ 23 | var filename:String; 24 | 25 | /** 26 | Returns the diagnostic report as an object. Optionally from an error object. 27 | **/ 28 | function getReport(?err:Error):Dynamic; 29 | 30 | /** 31 | When the diagnostic report was generated in case of fatal errors. 32 | **/ 33 | var reportOnFatalError:Bool; 34 | 35 | /** 36 | If the diagnostic report was generated by receiving a signal. 37 | **/ 38 | var reportOnSignal:Bool; 39 | 40 | /** 41 | When the diagnostic report was generated in case of a uncaught exception. 42 | **/ 43 | var reportOnUncaughtException:Bool; 44 | 45 | /** 46 | The signal that triggered the diagnostic report. 47 | **/ 48 | var signal:String; 49 | 50 | /** 51 | Writes a diagnostic report to a file. 52 | **/ 53 | function writeReport(?filename:String, ?err:Error):String; 54 | } 55 | -------------------------------------------------------------------------------- /src/js/node/zlib/Gzip.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Compress data using gzip. 27 | **/ 28 | @:jsRequire("zlib", "Gzip") 29 | extern class Gzip extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/zlib/Gunzip.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Decompress a gzip stream. 27 | **/ 28 | @:jsRequire("zlib", "Gunzip") 29 | extern class Gunzip extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/zlib/Deflate.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Compress data using deflate. 27 | **/ 28 | @:jsRequire("zlib", "Deflate") 29 | extern class Deflate extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/zlib/Inflate.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Decompress a deflate stream. 27 | **/ 28 | @:jsRequire("zlib", "Inflate") 29 | extern class Inflate extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/zlib/InflateRaw.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Decompress a raw deflate stream. 27 | **/ 28 | @:jsRequire("zlib", "InflateRaw") 29 | extern class InflateRaw extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/zlib/DeflateRaw.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Compress data using deflate, and do not append a zlib header. 27 | **/ 28 | @:jsRequire("zlib", "DeflateRaw") 29 | extern class DeflateRaw extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/zlib/Unzip.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Decompress either a Gzip- or Deflate-compressed stream by auto-detecting the header. 27 | **/ 28 | @:jsRequire("zlib", "Unzip") 29 | extern class Unzip extends Zlib {} 30 | -------------------------------------------------------------------------------- /src/js/node/https/Server.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.https; 24 | 25 | /** 26 | This class is a subclass of `tls.Server` and emits events same as `http.Server`. 27 | See [http.Server](https://nodejs.org/api/http.html#http_class_http_server) for more information. 28 | **/ 29 | @:jsRequire("https", "Server") 30 | extern class Server extends js.node.tls.Server {} 31 | -------------------------------------------------------------------------------- /src/js/node/Iterator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | #if haxe4 26 | typedef Iterator = js.lib.Iterator; 27 | typedef IteratorStep = js.lib.Iterator.IteratorStep; 28 | #else 29 | typedef Iterator = { 30 | function next():IteratorStep; 31 | } 32 | 33 | typedef IteratorStep = { 34 | done:Bool, 35 | ?value:T 36 | } 37 | #end 38 | -------------------------------------------------------------------------------- /ci/Utils.hx: -------------------------------------------------------------------------------- 1 | import Sys.*; 2 | import sys.io.*; 3 | import sys.FileSystem.*; 4 | import haxe.io.*; 5 | 6 | class Utils { 7 | static public function env(name:String, def:String):String { 8 | return switch (getEnv(name)) { 9 | case null: 10 | def; 11 | case v: 12 | v; 13 | } 14 | } 15 | 16 | static public function runCommand(cmd:String, args:Array):Void { 17 | println('run: $cmd $args'); 18 | switch (command(cmd, args)) { 19 | case 0: 20 | // pass 21 | case exitCode: 22 | exit(exitCode); 23 | } 24 | } 25 | 26 | static public function commandOutput(cmd:String, args:Array):String { 27 | var p = new Process(cmd, args); 28 | var exitCode = p.exitCode(); 29 | var output = p.stdout.readAll().toString(); 30 | p.close(); 31 | if (exitCode != 0) 32 | exit(exitCode); 33 | return output; 34 | } 35 | 36 | static public function copyRecursive(src:String, dest:String):Void { 37 | if (isDirectory(src)) { 38 | createDirectory(dest); 39 | for (item in readDirectory(src)) { 40 | var srcPath = Path.join([src, item]); 41 | var destPath = Path.join([dest, item]); 42 | copyRecursive(srcPath, destPath); 43 | } 44 | } else { 45 | File.copy(src, dest); 46 | } 47 | } 48 | 49 | static public function deleteRecursive(path:String):Void { 50 | if (!exists(path)) 51 | return; 52 | 53 | if (isDirectory(path)) { 54 | for (item in readDirectory(path)) { 55 | deleteRecursive(Path.join([path, item])); 56 | } 57 | deleteDirectory(path); 58 | } else { 59 | deleteFile(path); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Release.hx: -------------------------------------------------------------------------------- 1 | import haxe.crypto.Crc32; 2 | import haxe.zip.Entry; 3 | import haxe.zip.Writer; 4 | import haxe.zip.Tools; 5 | import sys.io.File; 6 | import sys.FileSystem; 7 | 8 | class Release { 9 | static var outPath = "release.zip"; 10 | static var files = ["haxelib.json", "extraParams.hxml", "src", "LICENSE.md", "README.md", "hxnodejs.png"]; 11 | 12 | static function makeZip() { 13 | var entries = new List(); 14 | 15 | function add(path:String, target:String) { 16 | if (!FileSystem.exists(path)) 17 | throw 'Invalid path: $path'; 18 | 19 | if (FileSystem.isDirectory(path)) { 20 | for (item in FileSystem.readDirectory(path)) 21 | add(path + "/" + item, target + "/" + item); 22 | } else { 23 | trace("Adding " + target); 24 | var bytes = File.getBytes(path); 25 | var entry:Entry = { 26 | fileName: target, 27 | fileSize: bytes.length, 28 | fileTime: FileSystem.stat(path).mtime, 29 | compressed: false, 30 | dataSize: 0, 31 | data: bytes, 32 | crc32: Crc32.make(bytes), 33 | } 34 | Tools.compress(entry, 9); 35 | entries.add(entry); 36 | } 37 | } 38 | 39 | for (file in files) 40 | add(file, file); 41 | 42 | trace("Saving to " + outPath); 43 | var out = File.write(outPath, true); 44 | var writer = new Writer(out); 45 | writer.write(entries); 46 | out.close(); 47 | } 48 | 49 | static function submitZip() { 50 | trace("Submitting " + outPath); 51 | Sys.command("haxelib", ["submit", outPath]); 52 | } 53 | 54 | static function main() { 55 | makeZip(); 56 | submitZip(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/js/node/KeyValue.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | /** 26 | Key/value access helper. 27 | **/ 28 | abstract KeyValue(Array) { 29 | public var key(get, never):K; 30 | public var value(get, never):V; 31 | 32 | inline function get_key():K { 33 | return this[0]; 34 | } 35 | 36 | inline function get_value():V { 37 | return this[1]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ci/DeployGhPages.hx: -------------------------------------------------------------------------------- 1 | import Sys.*; 2 | import Utils.*; 3 | import Config.*; 4 | 5 | using StringTools; 6 | 7 | class DeployGhPages { 8 | static function main():Void { 9 | var root = getCwd(); 10 | 11 | if (remote == null) { 12 | println('GHP_REMOTE is not set, skip deploy.'); 13 | return; 14 | } 15 | 16 | // TravisCI by default clones repositories to a depth of 50 commits. 17 | // We need a full clone inorder to do git operations. 18 | runCommand("git", ["fetch", "--unshallow"]); 19 | 20 | var sha = commandOutput("git", ["rev-parse", "HEAD"]).trim(); 21 | 22 | setCwd(htmlDir); 23 | runCommand("git", ["init"]); 24 | if (username != null) 25 | runCommand("git", ["config", "--local", "user.name", username]); 26 | if (email != null) 27 | runCommand("git", ["config", "--local", "user.email", email]); 28 | runCommand("git", ["remote", "add", "local", root]); 29 | runCommand("git", ["remote", "add", "remote", remote]); 30 | runCommand("git", ["fetch", "--all"]); 31 | runCommand("git", ["checkout", "--orphan", branch]); 32 | if (commandOutput("git", ["ls-remote", "--heads", "local", branch]).trim() != "") { 33 | runCommand("git", ["reset", "--soft", 'local/${branch}']); 34 | } 35 | if (commandOutput("git", ["ls-remote", "--heads", "remote", branch]).trim() != "") { 36 | runCommand("git", ["reset", "--soft", 'remote/${branch}']); 37 | } 38 | runCommand("git", ["add", "--all"]); 39 | runCommand("git", ["commit", "--allow-empty", "--quiet", "-m", 'deploy for ${sha}']); 40 | runCommand("git", ["push", "local", branch]); 41 | 42 | setCwd(root); 43 | runCommand("git", ["push", remote, branch]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/StreamImplSimpleProtocol2.hx: -------------------------------------------------------------------------------- 1 | import js.node.Buffer; 2 | import js.node.stream.Transform; 3 | #if haxe4 4 | import js.lib.Error; 5 | #else 6 | import js.Error; 7 | #end 8 | 9 | @:keep 10 | class SimpleProtocol extends Transform { 11 | var _inBody = false; 12 | var _sawFirstCr = false; 13 | var _rawHeader = []; 14 | var header:Buffer; 15 | 16 | override function _transform(chunk:Dynamic, encoding, callback) { 17 | if (!this._inBody) { 18 | // check if the chunk has a \n\n 19 | var split = -1; 20 | for (i in 0...chunk.length) { 21 | if (chunk[i] == 10) { // '\n' 22 | if (this._sawFirstCr) { 23 | split = i; 24 | break; 25 | } else { 26 | this._sawFirstCr = true; 27 | } 28 | } else { 29 | this._sawFirstCr = false; 30 | } 31 | } 32 | 33 | if (split == -1) { 34 | // still waiting for the \n\n 35 | // stash the chunk, and try again. 36 | this._rawHeader.push(chunk); 37 | } else { 38 | this._inBody = true; 39 | var h = chunk.slice(0, split); 40 | this._rawHeader.push(h); 41 | var header = Buffer.concat(this._rawHeader).toString(); 42 | try { 43 | this.header = haxe.Json.parse(header); 44 | } catch (_:Dynamic) { 45 | this.emit('error', new Error('invalid simple protocol data')); 46 | return; 47 | } 48 | // and let them know that we are done parsing the header. 49 | this.emit('header', this.header); 50 | 51 | // now, because we got some extra data, emit this first. 52 | this.push(chunk.slice(split)); 53 | } 54 | } else { 55 | // from there on, just provide the data to our consumer as-is. 56 | this.push(chunk); 57 | } 58 | callback(null, null); 59 | } 60 | } 61 | 62 | class StreamImplSimpleProtocol2 { 63 | static function main() {} 64 | } 65 | -------------------------------------------------------------------------------- /src/js/node/stream/PassThrough.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.stream; 24 | 25 | /** 26 | The `stream.PassThrough` class is a trivial implementation of a `Transform` stream 27 | that simply passes the input bytes across to the output. 28 | Its purpose is primarily for examples and testing, but there are some use cases 29 | where `stream.PassThrough` is useful as a building block for novel sorts of streams. 30 | 31 | @see https://nodejs.org/api/stream.html#stream_class_stream_passthrough 32 | **/ 33 | @:jsRequire("stream", "PassThrough") 34 | extern class PassThrough extends Transform { 35 | function new(); 36 | } 37 | -------------------------------------------------------------------------------- /src/sys/io/FileInput.hx: -------------------------------------------------------------------------------- 1 | package sys.io; 2 | 3 | import haxe.io.Bytes; 4 | import haxe.io.Eof; 5 | import haxe.io.Error; 6 | import js.node.Buffer; 7 | import js.node.Fs; 8 | 9 | @:coreApi 10 | class FileInput extends haxe.io.Input { 11 | var fd:Int; 12 | var pos:Int; 13 | 14 | var hasReachedEof = false; 15 | 16 | inline function throwEof():Void { 17 | hasReachedEof = true; 18 | throw new Eof(); 19 | } 20 | 21 | @:allow(sys.io.File) 22 | function new(fd:Int) { 23 | this.fd = fd; 24 | pos = 0; 25 | } 26 | 27 | override public function readByte():Int { 28 | var buf = Buffer.alloc(1); 29 | var bytesRead = try { 30 | Fs.readSync(fd, buf, 0, 1, pos); 31 | } catch (e:Dynamic) { 32 | if (e.code == "EOF") 33 | throwEof(); 34 | throw Error.Custom(e); 35 | } 36 | if (bytesRead == 0) 37 | throwEof(); 38 | pos++; 39 | return buf[0]; 40 | } 41 | 42 | override public function readBytes(s:Bytes, pos:Int, len:Int):Int { 43 | var buf = Buffer.hxFromBytes(s); 44 | var bytesRead = try { 45 | Fs.readSync(fd, buf, pos, len, this.pos); 46 | } catch (e:Dynamic) { 47 | if (e.code == "EOF") 48 | throwEof(); 49 | throw Error.Custom(e); 50 | } 51 | if (bytesRead == 0) 52 | throwEof(); 53 | this.pos += bytesRead; 54 | return bytesRead; 55 | } 56 | 57 | override public function close():Void { 58 | Fs.closeSync(fd); 59 | } 60 | 61 | public function seek(p:Int, pos:FileSeek):Void { 62 | hasReachedEof = false; 63 | switch (pos) { 64 | case SeekBegin: 65 | this.pos = p; 66 | case SeekEnd: 67 | this.pos = cast Fs.fstatSync(fd).size + p; 68 | case SeekCur: 69 | this.pos += p; 70 | } 71 | } 72 | 73 | public function tell():Int { 74 | return pos; 75 | } 76 | 77 | public function eof():Bool { 78 | return hasReachedEof; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/sys/io/File.hx: -------------------------------------------------------------------------------- 1 | package sys.io; 2 | 3 | import js.node.Fs; 4 | 5 | @:dce 6 | // @:coreApi 7 | class File { 8 | public static inline function append(path:String, binary:Bool = true):FileOutput { 9 | return new FileOutput(Fs.openSync(path, AppendCreate)); 10 | } 11 | 12 | public static inline function write(path:String, binary:Bool = true):FileOutput { 13 | return new FileOutput(Fs.openSync(path, WriteCreate)); 14 | } 15 | 16 | public static inline function read(path:String, binary:Bool = true):FileInput { 17 | return new FileInput(Fs.openSync(path, Read)); 18 | } 19 | 20 | public static inline function getContent(path:String):String { 21 | return Fs.readFileSync(path, {encoding: "utf8"}); 22 | } 23 | 24 | public static inline function saveContent(path:String, content:String):Void { 25 | Fs.writeFileSync(path, content); 26 | } 27 | 28 | public static inline function getBytes(path:String):haxe.io.Bytes { 29 | return Fs.readFileSync(path).hxToBytes(); 30 | } 31 | 32 | public static inline function saveBytes(path:String, bytes:haxe.io.Bytes):Void { 33 | Fs.writeFileSync(path, js.node.Buffer.hxFromBytes(bytes)); 34 | } 35 | 36 | public static inline function update(path:String, binary:Bool = true):FileOutput { 37 | return new FileOutput(Fs.openSync(path, ReadWrite)); 38 | } 39 | 40 | static inline var copyBufLen = 64 * 1024; 41 | static var copyBuf = js.node.Buffer.alloc(copyBufLen); 42 | 43 | public static function copy(srcPath:String, dstPath:String):Void { 44 | var src = Fs.openSync(srcPath, Read); 45 | var stat = Fs.fstatSync(src); 46 | var dst = Fs.openSync(dstPath, WriteCreate, stat.mode); 47 | var bytesRead, pos = 0; 48 | while ((bytesRead = Fs.readSync(src, copyBuf, 0, copyBufLen, pos)) > 0) { 49 | Fs.writeSync(dst, copyBuf, 0, bytesRead); 50 | pos += bytesRead; 51 | } 52 | Fs.closeSync(src); 53 | Fs.closeSync(dst); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/js/node/Domain.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import js.node.domain.Domain as DomainObject; 26 | 27 | /** 28 | Domains provide a way to handle multiple different IO operations as a single group. 29 | 30 | If any of the event emitters or callbacks registered to a domain emit an error event, or throw an error, 31 | then the domain object will be notified, rather than losing the context of the error in the process.on('uncaughtException') handler, 32 | or causing the program to exit immediately with an error code. 33 | **/ 34 | @:deprecated 35 | @:jsRequire("domain") 36 | extern class Domain { 37 | /** 38 | Returns a new Domain object. 39 | **/ 40 | static function create():DomainObject; 41 | } 42 | -------------------------------------------------------------------------------- /src/sys/net/Socket.hx: -------------------------------------------------------------------------------- 1 | package sys.net; 2 | 3 | class SocketInput extends haxe.io.Input { 4 | var s:Socket; 5 | 6 | public function new(s:Socket) { 7 | this.s = s; 8 | } 9 | 10 | override function readByte():Int { 11 | s.waitData(); 12 | var buf = s.inputData[0]; 13 | var b = buf[s.inputPos++]; 14 | if (s.inputPos == buf.length) { 15 | s.inputPos = 0; 16 | s.inputData.shift(); 17 | } 18 | return b; 19 | } 20 | 21 | override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int { 22 | s.waitData(); 23 | var nbuf = js.node.Buffer.hxFromBytes(buf); 24 | var startPos = pos; 25 | while (len > 0) { 26 | var buf = s.inputData[0]; 27 | if (buf == null) 28 | break; 29 | var avail = buf.length - s.inputPos; 30 | if (avail > len) { 31 | buf.copy(nbuf, pos, s.inputPos, s.inputPos + len); 32 | pos += len; 33 | s.inputPos += len; 34 | break; 35 | } 36 | buf.copy(nbuf, pos, s.inputPos, s.inputPos + avail); 37 | pos += avail; 38 | len -= avail; 39 | s.inputData.shift(); 40 | s.inputPos = 0; 41 | } 42 | return pos - startPos; 43 | } 44 | } 45 | 46 | @:allow(sys.net.SocketInput) 47 | class Socket { 48 | var s:js.node.net.Socket; 49 | var inputData:Array = []; 50 | var inputPos:Int = 0; 51 | 52 | public var input:haxe.io.Input; 53 | 54 | public function new() { 55 | input = new SocketInput(this); 56 | } 57 | 58 | public function connect(host:Host, port:Int) { 59 | s = new js.node.net.Socket(); 60 | s.on("data", function(buf:js.node.Buffer) inputData.push(buf)); 61 | NodeSync.callVoid(function(callb) s.connect(port, host.host, callb)); 62 | } 63 | 64 | function waitData() { 65 | if (inputData.length == 0) 66 | NodeSync.wait(function() return inputData.length > 0); 67 | } 68 | 69 | public function close() { 70 | if (s != null) { 71 | s.destroy(); 72 | s = null; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/js/node/Tty.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | /** 26 | The tty module houses the tty.ReadStream and tty.WriteStream classes. 27 | In most cases, you will not need to use this module directly. 28 | 29 | When node detects that it is being run inside a TTY context, then process.stdin will be a tty.ReadStream 30 | instance and process.stdout will be a tty.WriteStream instance. The preferred way to check if node is being 31 | run in a TTY context is to check process.stdout.isTTY. 32 | **/ 33 | @:jsRequire("tty") 34 | extern class Tty { 35 | /** 36 | Returns true or false depending on if the `fd` is associated with a terminal. 37 | **/ 38 | static function isatty(fd:Int):Bool; 39 | 40 | @:deprecated("Use tty.ReadStream#setRawMode() instead.") 41 | static function setRawMode(mode:Bool):Void; 42 | } 43 | -------------------------------------------------------------------------------- /src/js/node/tty/ReadStream.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.tty; 24 | 25 | /** 26 | A net.Socket subclass that represents the readable portion of a tty. 27 | In normal circumstances, process.stdin will be the only tty.ReadStream instance 28 | in any node program (only when isatty(0) is true). 29 | **/ 30 | @:jsRequire("tty", "ReadStream") 31 | extern class ReadStream extends js.node.net.Socket { 32 | /** 33 | A boolean that is initialized to false. 34 | It represents the current "raw" state of the tty.ReadStream instance. 35 | **/ 36 | var isRaw(default, null):Bool; 37 | 38 | /** 39 | `mode` should be true or false. 40 | This sets the properties of the tty.ReadStream to act either as a raw device or default. 41 | `isRaw` will be set to the resulting mode. 42 | **/ 43 | function setRawMode(mode:Bool):Void; 44 | } 45 | -------------------------------------------------------------------------------- /src/js/node/Dgram.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import js.node.dgram.Socket; 26 | 27 | /** 28 | Datagram sockets 29 | **/ 30 | @:jsRequire("dgram") 31 | extern class Dgram { 32 | /** 33 | Creates a datagram `Socket` of the specified types. 34 | 35 | Takes an optional `callback` which is added as a listener for 'message' events. 36 | 37 | Call `socket.bind` if you want to receive datagrams. `socket.bind` will bind to 38 | the "all interfaces" address on a random port (it does the right thing for both `udp4` and `udp6` sockets). 39 | You can then retrieve the address and port with `socket.address().address` and `socket.address().port`. 40 | **/ 41 | @:overload(function(type:SocketType, ?callback:MessageListener):Socket {}) 42 | static function createSocket(options:SocketOptions, ?callback:MessageListener):Socket; 43 | } 44 | -------------------------------------------------------------------------------- /src/js/node/fs/ReadStream.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.fs; 24 | 25 | import js.node.Fs.FsPath; 26 | import js.node.events.EventEmitter.Event; 27 | 28 | enum abstract ReadStreamEvent(Event) to Event { 29 | /** 30 | Emitted when the `ReadStream`'s file is opened. 31 | 32 | Listener arguments: 33 | fd - file descriptor used by the `ReadStream`. 34 | **/ 35 | var Open:ReadStreamEventVoid> = "open"; 36 | } 37 | 38 | /** 39 | Readable file stream. 40 | **/ 41 | extern class ReadStream extends js.node.stream.Readable { 42 | /** 43 | The path to the file the stream is reading from as specified in the first argument to `Fs.createReadStream`. 44 | 45 | If path is passed as a string, then readStream.path will be a string. 46 | If path is passed as a Buffer, then readStream.path will be a Buffer. 47 | **/ 48 | var path:FsPath; 49 | } 50 | -------------------------------------------------------------------------------- /src/js/node/tls/SecurePair.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.tls; 24 | 25 | import js.node.events.EventEmitter; 26 | 27 | /** 28 | Events emitted by `SecurePair`. 29 | **/ 30 | enum abstract SecurePairEvent(Event) to Event { 31 | /** 32 | The event is emitted from the `SecurePair` once the pair has successfully established a secure connection. 33 | 34 | Similarly to the checking for the server 'secureConnection' event, 35 | `SecurePair.cleartext.authorized` should be checked to confirm whether 36 | the certificate used properly authorized. 37 | **/ 38 | var Secure:SecurePairEventVoid> = "secure"; 39 | } 40 | 41 | /** 42 | Returned by `Tls.createSecurePair`. 43 | **/ 44 | extern class SecurePair extends EventEmitter { 45 | var cleartext(default, null):TLSSocket; 46 | var encrypted(default, null):js.node.stream.Duplex.IDuplex; 47 | } 48 | -------------------------------------------------------------------------------- /src/js/node/util/TextEncoder.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.util; 24 | 25 | #if haxe4 26 | import js.lib.Uint8Array; 27 | #else 28 | import js.html.Uint8Array; 29 | #end 30 | 31 | /** 32 | An implementation of the WHATWG Encoding Standard `TextEncoder` API. 33 | 34 | @see https://nodejs.org/api/util.html#util_class_util_textencoder 35 | **/ 36 | @:jsRequire("util", "TextEncoder") 37 | extern class TextEncoder { 38 | function new(); 39 | 40 | /** 41 | UTF-8 encodes the `input` string and returns a `Uint8Array` containing the encoded bytes. 42 | 43 | @see https://nodejs.org/api/util.html#util_textencoder_encode_input 44 | **/ 45 | function encode(?input:String):Uint8Array; 46 | 47 | /** 48 | The encoding supported by the `TextEncoder` instance. 49 | 50 | @see https://nodejs.org/api/util.html#util_textencoder_encoding 51 | **/ 52 | var encoding(default, null):String; 53 | } 54 | -------------------------------------------------------------------------------- /src/js/node/zlib/Zlib.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.zlib; 24 | 25 | /** 26 | Not exported by the zlib module. 27 | It is documented here because it is the base class of the compressor/decompressor classes. 28 | **/ 29 | extern class Zlib extends js.node.stream.Transform { 30 | /** 31 | Flush pending data. 32 | 33 | `kind` defaults to `Zlib.Z_FULL_FLUSH`. 34 | 35 | Don't call this frivolously, premature flushes negatively impact the effectiveness of the compression algorithm. 36 | **/ 37 | @:overload(function(kind:Int, callback:Void->Void):Void {}) 38 | function flush(callback:Void->Void):Void; 39 | 40 | /** 41 | Dynamically update the compression level and compression strategy. 42 | Only applicable to deflate algorithm. 43 | **/ 44 | function params(level:Int, strategy:Int, callback:Void->Void):Void; 45 | 46 | /** 47 | Reset the compressor/decompressor to factory defaults. 48 | Only applicable to the inflate and deflate algorithms. 49 | **/ 50 | function reset():Void; 51 | } 52 | -------------------------------------------------------------------------------- /src/js/node/Constants.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | @:jsRequire("constants") 26 | extern class Constants { 27 | static var ENGINE_METHOD_RSA(default, null):Int; 28 | static var ENGINE_METHOD_DSA(default, null):Int; 29 | static var ENGINE_METHOD_DH(default, null):Int; 30 | static var ENGINE_METHOD_RAND(default, null):Int; 31 | static var ENGINE_METHOD_ECDH(default, null):Int; 32 | static var ENGINE_METHOD_ECDSA(default, null):Int; 33 | static var ENGINE_METHOD_CIPHERS(default, null):Int; 34 | static var ENGINE_METHOD_DIGESTS(default, null):Int; 35 | static var ENGINE_METHOD_STORE(default, null):Int; 36 | static var ENGINE_METHOD_PKEY_METH(default, null):Int; 37 | static var ENGINE_METHOD_PKEY_ASN1_METH(default, null):Int; 38 | static var ENGINE_METHOD_ALL(default, null):Int; 39 | static var ENGINE_METHOD_NONE(default, null):Int; 40 | 41 | static var RSA_NO_PADDING(default, null):Int; 42 | static var RSA_PKCS1_PADDING(default, null):Int; 43 | static var RSA_PKCS1_OAEP_PADDING(default, null):Int; 44 | } 45 | -------------------------------------------------------------------------------- /src/js/node/fs/WriteStream.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.fs; 24 | 25 | import js.node.Fs.FsPath; 26 | import js.node.events.EventEmitter.Event; 27 | 28 | enum abstract WriteStreamEvent(Event) to Event { 29 | /** 30 | Emitted when the `WriteStream`'s file is opened. 31 | 32 | Listener arguments: 33 | fd - file descriptor used by the `WriteStream`. 34 | **/ 35 | var Open:WriteStreamEventVoid> = "open"; 36 | } 37 | 38 | /** 39 | Writable file stream. 40 | **/ 41 | extern class WriteStream extends js.node.stream.Writable { 42 | /** 43 | The path to the file the stream is writing to as specified in the first argument to `Fs.createWriteStream`. 44 | If path is passed as a string, then writeStream.path will be a string. 45 | If path is passed as a Buffer, then writeStream.path will be a Buffer. 46 | **/ 47 | var path:FsPath; 48 | 49 | /** 50 | The number of bytes written so far. 51 | Does not include data that is still queued for writing. 52 | **/ 53 | var bytesWritten:Int; 54 | } 55 | -------------------------------------------------------------------------------- /src/js/node/util/Promisify.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.util; 24 | 25 | import haxe.Constraints.Function; 26 | import haxe.extern.Rest; 27 | #if haxe4 28 | import js.lib.Promise; 29 | #else 30 | import js.Promise; 31 | #end 32 | 33 | @:jsRequire("util", "promisify") 34 | extern class Promisify { 35 | /** 36 | Takes a function following the common error-first callback style, i.e. taking an `(err, value) => ...` callback 37 | as the last argument, and returns a version that returns promises. 38 | 39 | @see https://nodejs.org/api/util.html#util_util_promisify_original 40 | **/ 41 | @:selfCall 42 | static function promisify(original:Function):Rest->Promise; 43 | 44 | /** 45 | That can be used to declare custom promisified variants of functions, see Custom promisified functions. 46 | 47 | @see https://nodejs.org/api/util.html#util_util_promisify_custom 48 | **/ 49 | #if haxe4 50 | static final custom:js.lib.Symbol; 51 | #else 52 | static var custom(default, never):Dynamic; 53 | #end 54 | } 55 | -------------------------------------------------------------------------------- /src/js/node/https/Agent.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.https; 24 | 25 | /** 26 | An Agent object for HTTPS similar to `http.Agent`. 27 | See [https.request](https://nodejs.org/api/http.html#http_http_request_options_callback) for more information. 28 | **/ 29 | @:jsRequire("https", "Agent") 30 | extern class Agent extends js.node.http.Agent { 31 | function new(?options:HttpsAgentOptions); 32 | } 33 | 34 | typedef HttpsAgentOptions = { 35 | > js.node.http.Agent.HttpAgentOptions, 36 | 37 | /** 38 | maximum number of TLS cached sessions. Use `0` to disable TLS session caching. 39 | 40 | Default: `100`. 41 | **/ 42 | @:optional var maxCachedSessions:Int; 43 | 44 | /** 45 | the value of [Server Name Indication extension](https://en.wikipedia.org/wiki/Server_Name_Indication) to be sent to the server. 46 | Use empty string `''` to disable sending the extension. 47 | 48 | Default: hostname of the target server, unless the target server is specified using an IP address, in which case the default is `''` (no extension). 49 | **/ 50 | @:optional var servername:String; 51 | } 52 | -------------------------------------------------------------------------------- /src/js/node/crypto/Certificate.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import js.node.Buffer; 26 | 27 | /** 28 | SPKAC is a Certificate Signing Request mechanism originally implemented by Netscape 29 | and now specified formally as part of HTML5's keygen element. 30 | **/ 31 | @:jsRequire("crypto", "Certificate") 32 | extern class Certificate { 33 | function new(); 34 | 35 | /** 36 | Returns the challenge component in the form of a Node.js `Buffer`. 37 | 38 | The `spkac` data structure includes a public key and a challenge. 39 | **/ 40 | @:overload(function(spkac:String):Buffer {}) 41 | function exportChallenge(spkac:Buffer):Buffer; 42 | 43 | /** 44 | Returns the public key component in the form of a Node.js `Buffer`. 45 | 46 | The `spkac` data structure includes a public key and a challenge. 47 | **/ 48 | @:overload(function(spkac:String):Buffer {}) 49 | function exportPublicKey(spkac:Buffer):Buffer; 50 | 51 | /** 52 | Returns true if the given `spkac` data structure is valid, false otherwise. 53 | **/ 54 | function verifySpkac(spkac:Buffer):Bool; 55 | } 56 | -------------------------------------------------------------------------------- /src/js/node/Events.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import haxe.Constraints.Function; 26 | import js.node.events.EventEmitter; 27 | #if haxe4 28 | import js.lib.Promise; 29 | #else 30 | import js.Promise; 31 | #end 32 | 33 | /** 34 | Much of the Node.js core API is built around an idiomatic asynchronous event-driven architecture 35 | in which certain kinds of objects (called "emitters") emit named events that cause `Function` objects 36 | ("listeners") to be called. 37 | 38 | @see https://nodejs.org/api/events.html#events_events 39 | */ 40 | @:jsRequire("events") 41 | extern class Events { 42 | /** 43 | Creates a `Promise` that is resolved when the `EventEmitter` emits the given 44 | event or that is rejected when the `EventEmitter` emits `'error'`. 45 | The `Promise` will resolve with an array of all the arguments emitted to the 46 | given event. 47 | 48 | @see https://nodejs.org/api/events.html#events_events_once_emitter_name 49 | **/ 50 | static function once(emitter:IEventEmitter, name:Event):Promise>; 51 | } 52 | -------------------------------------------------------------------------------- /src/js/node/tty/WriteStream.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.tty; 24 | 25 | import js.node.events.EventEmitter; 26 | 27 | /** 28 | Enumeration of events emitted by `WriteStream` objects in addition to its parents. 29 | **/ 30 | enum abstract WriteStreamEvent(Event) to Event { 31 | /** 32 | Emitted by refreshSize() when either of the columns or rows properties has changed. 33 | **/ 34 | var Resize:WriteStreamEventVoid> = "resize"; 35 | } 36 | 37 | /** 38 | A net.Socket subclass that represents the writable portion of a tty. 39 | In normal circumstances, process.stdout will be the only tty.WriteStream instance 40 | ever created (and only when isatty(1) is true). 41 | **/ 42 | @:jsRequire("tty", "WriteStream") 43 | extern class WriteStream extends js.node.net.Socket { 44 | /** 45 | The number of columns the TTY currently has. 46 | This property gets updated on "resize" events. 47 | **/ 48 | var columns(default, null):Int; 49 | 50 | /** 51 | The number of rows the TTY currently has. 52 | This property gets updated on "resize" events. 53 | **/ 54 | var rows(default, null):Int; 55 | } 56 | -------------------------------------------------------------------------------- /src/js/node/crypto/Hmac.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import js.node.Buffer; 26 | 27 | /** 28 | Class for creating cryptographic hmac content. 29 | 30 | It is a stream that is both readable and writable. The written data is used to compute the hmac. 31 | Once the writable side of the stream is ended, use the `read` method to get the computed digest. 32 | 33 | The legacy `update` and `digest` methods are also supported. 34 | 35 | Returned by `Crypto.createHmac`. 36 | **/ 37 | extern class Hmac extends js.node.stream.Transform { 38 | /** 39 | Update the hmac content with the given data. 40 | 41 | This can be called many times with new data as it is streamed. 42 | **/ 43 | @:overload(function(data:Buffer):Hmac {}) 44 | function update(data:String, ?input_encoding:String):Hmac; 45 | 46 | /** 47 | Calculates the digest of all of the passed data to the hmac. 48 | The `encoding` can be 'hex', 'binary' or 'base64'. 49 | If no `encoding` is provided, then a buffer is returned. 50 | 51 | Note: hmac object can not be used after `digest` method has been called. 52 | **/ 53 | @:overload(function():Buffer {}) 54 | function digest(encoding:String):String; 55 | } 56 | -------------------------------------------------------------------------------- /src/js/node/http/Method.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.http; 24 | 25 | /** 26 | Enumeration of possible HTTP methods as described in 27 | http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html 28 | **/ 29 | enum abstract Method(String) from String to String { 30 | var Acl = "ACL"; 31 | var Bind = "BIND"; 32 | var Checkout = "CHECKOUT"; 33 | var Connect = "CONNECT"; 34 | var Copy = "COPY"; 35 | var Delete = "DELETE"; 36 | var Get = "GET"; 37 | var Head = "HEAD"; 38 | var Link = "LINK'"; 39 | var Lock = "LOCK'"; 40 | var MSearch = "M-SEARCH'"; 41 | var Merge = "MERGE'"; 42 | var Mkactivity = "MKACTIVITY'"; 43 | var Mkcalendar = "MKCALENDAR'"; 44 | var Mkcol = "MKCOL'"; 45 | var Move = "MOVE'"; 46 | var Notify = "NOTIFY'"; 47 | var Options = "OPTIONS"; 48 | var Patch = "PATCH"; 49 | var Post = "POST"; 50 | var Propfind = "PROPFIND"; 51 | var Proppatch = "PROPPATCH"; 52 | var Purge = "PURGE"; 53 | var Put = "PUT"; 54 | var Rebind = "REBIND"; 55 | var Report = "REPORT"; 56 | var Search = "SEARCH"; 57 | var Subscribe = "SUBSCRIBE"; 58 | var Trace = "TRACE"; 59 | var Unbind = "UNBIND"; 60 | var Unlink = "UNLINK"; 61 | var Unlock = "UNLOCK"; 62 | var Unsubscribe = "UNSUBSCRIBE"; 63 | } 64 | -------------------------------------------------------------------------------- /src/sys/FileSystem.hx: -------------------------------------------------------------------------------- 1 | package sys; 2 | 3 | import js.node.Fs; 4 | import js.node.Path; 5 | #if haxe4 6 | import js.lib.Error; 7 | #else 8 | import js.Error; 9 | #end 10 | 11 | @:dce 12 | @:coreApi 13 | class FileSystem { 14 | public static function exists(path:String):Bool { 15 | return try { 16 | Fs.accessSync(path); 17 | true; 18 | } catch (_:Dynamic) false; 19 | } 20 | 21 | public static inline function rename(path:String, newPath:String):Void { 22 | Fs.renameSync(path, newPath); 23 | } 24 | 25 | public static inline function stat(path:String):sys.FileStat { 26 | return cast Fs.statSync(path); 27 | } 28 | 29 | public static inline function fullPath(relPath:String):String { 30 | return try Fs.realpathSync(relPath) catch (e:Dynamic) null; 31 | } 32 | 33 | public static inline function absolutePath(relPath:String):String { 34 | if (haxe.io.Path.isAbsolute(relPath)) 35 | return relPath; 36 | return js.node.Path.resolve(relPath); 37 | } 38 | 39 | public static function isDirectory(path:String):Bool { 40 | return try Fs.statSync(path).isDirectory() catch (e:Dynamic) false; 41 | } 42 | 43 | public static function createDirectory(path:String):Void { 44 | try { 45 | Fs.mkdirSync(path); 46 | } catch (e:Dynamic) { 47 | if (e.code == "ENOENT") { 48 | // parent doesn't exist - create parent and then this dir 49 | createDirectory(Path.dirname(path)); 50 | Fs.mkdirSync(path); 51 | } else { 52 | // some other error - check if path is a dir, rethrow the error if not 53 | // (the `(e : Error)` cast is here to avoid HaxeError wrapping, though we need to investigate this in Haxe itself) 54 | var stat = try Fs.statSync(path) catch (_:Dynamic) throw(e : Error); 55 | if (!stat.isDirectory()) 56 | throw(e : Error); 57 | } 58 | } 59 | } 60 | 61 | public static inline function deleteFile(path:String):Void { 62 | Fs.unlinkSync(path); 63 | } 64 | 65 | public static inline function deleteDirectory(path:String):Void { 66 | if (exists(path)) { 67 | for (file in readDirectory(path)) { 68 | var curPath = path + "/" + file; 69 | if (isDirectory(curPath)) { 70 | deleteDirectory(curPath); 71 | } else { 72 | deleteFile(curPath); 73 | } 74 | } 75 | js.node.Fs.rmdirSync(path); 76 | } 77 | } 78 | 79 | public static inline function readDirectory(path:String):Array { 80 | return Fs.readdirSync(path); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/js/node/fs/FSWatcher.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.fs; 24 | 25 | import js.node.Fs.FsPath; 26 | import js.node.events.EventEmitter; 27 | #if haxe4 28 | import js.lib.Error; 29 | #else 30 | import js.Error; 31 | #end 32 | 33 | /** 34 | Enumeration of possible types of changes for 'change' event. 35 | **/ 36 | enum abstract FSWatcherChangeType(String) from String to String { 37 | var Change = "change"; 38 | var Rename = "rename"; 39 | } 40 | 41 | /** 42 | Enumeration of the events emitted by `FSWatcher`. 43 | **/ 44 | enum abstract FSWatcherEvent(Event) to Event { 45 | /** 46 | Emitted when something changes in a watched directory or file. See more details in `Fs.watch`. 47 | 48 | Listener arguments: 49 | event - The type of fs change 50 | filename - The filename that changed (if relevant/available) 51 | **/ 52 | var Change:FSWatcherEventFsPath->Void> = "change"; 53 | 54 | /** 55 | Emitted when an error occurs. 56 | **/ 57 | var Error:FSWatcherEventVoid> = "error"; 58 | } 59 | 60 | /** 61 | Objects returned from `Fs.watch` are of this type. 62 | **/ 63 | extern class FSWatcher extends EventEmitter { 64 | /** 65 | Stop watching for changes on the given `FSWatcher`. 66 | **/ 67 | function close():Void; 68 | } 69 | -------------------------------------------------------------------------------- /src/js/node/crypto/Sign.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import haxe.extern.EitherType; 26 | import js.node.Buffer; 27 | import js.node.stream.Writable; 28 | 29 | /** 30 | Class for generating signatures. 31 | 32 | Returned by `Crypto.createSign`. 33 | 34 | Sign objects are writable streams. The written data is used to generate the signature. 35 | Once all of the data has been written, the sign method will return the signature. 36 | 37 | The legacy `update` method is also supported. 38 | **/ 39 | extern class Sign extends Writable { 40 | /** 41 | Updates the sign object with data. 42 | This can be called many times with new data as it is streamed. 43 | **/ 44 | @:overload(function(data:Buffer):Void {}) 45 | function update(data:String, ?encoding:String):Void; 46 | 47 | /** 48 | Calculates the signature on all the updated data passed through the sign. 49 | `private_key` is a string containing the PEM encoded private key for signing. 50 | Returns the signature in `output_format` which can be 'binary', 'hex' or 'base64'. 51 | If no encoding is provided, then a buffer is returned. 52 | 53 | Note: sign object can not be used after `sign` method has been called. 54 | **/ 55 | @:overload(function(private_key:EitherType):Buffer {}) 56 | function sign(private_key:EitherType, output_format:String):String; 57 | } 58 | -------------------------------------------------------------------------------- /src/js/node/crypto/Hash.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import js.node.Buffer; 26 | 27 | /** 28 | The class for creating hash digests of data. 29 | 30 | It is a stream that is both readable and writable. 31 | The written data is used to compute the hash. 32 | Once the writable side of the stream is ended, use the `read` method to get the computed hash digest. 33 | 34 | The legacy `update` and `digest` methods are also supported. 35 | 36 | Returned by `Crypto.createHash`. 37 | **/ 38 | extern class Hash extends js.node.stream.Transform { 39 | /** 40 | Updates the hash content with the given `data`, 41 | 42 | the `encoding` of which is given in `input_encoding` and can be 'utf8', 'ascii' or 'binary'. 43 | If no `encoding` is provided and the input is a string an encoding of 'binary' is enforced. 44 | If `data` is a `Buffer` then `input_encoding` is ignored. 45 | 46 | This can be called many times with new data as it is streamed. 47 | **/ 48 | @:overload(function(data:Buffer):Hash {}) 49 | function update(data:String, ?input_encoding:String):Hash; 50 | 51 | /** 52 | Calculates the digest of all of the passed data to be hashed. 53 | The `encoding` can be 'hex', 'binary' or 'base64'. 54 | If no `encoding` is provided, then a buffer is returned. 55 | 56 | Note: hash object can not be used after `digest` method has been called. 57 | **/ 58 | @:overload(function():Buffer {}) 59 | function digest(encoding:String):String; 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![hxnodejs](hxnodejs.png) 2 | 3 | # Haxe Node.JS 4 | 5 | [![Build Status](https://badgen.net/travis/HaxeFoundation/hxnodejs?label=build)](https://travis-ci.org/HaxeFoundation/hxnodejs) 6 | [![Haxelib Version](https://badgen.net/haxelib/v/hxnodejs)](https://lib.haxe.org/p/hxnodejs) 7 | [![Haxelib Downloads](https://badgen.net/haxelib/d/hxnodejs?color=blue)](https://lib.haxe.org/p/hxnodejs) 8 | [![Haxelib License](https://badgen.net/haxelib/license/hxnodejs)](LICENSE.md) 9 | 10 | Extern type definitions for Node.JS. Haxe **3.4** or newer is required. 11 | 12 | Haxe-generated API documentation is available at http://haxefoundation.github.io/hxnodejs/js/Node.html. 13 | 14 | Original node.js documentation can be found at http://nodejs.org/api/index.html. 15 | 16 | ## Features 17 | 18 | - Full node.js API with documentation. 19 | - Strict typing for everything, fully leveraging Haxe type system. 20 | - Optionally typed event listeners. 21 | - Automatic insert of "require" statements for used modules. 22 | - Clean output. 23 | 24 | ## Quick example 25 | 26 | 1. Install hxnodejs with `haxelib install hxnodejs` (released version) or `haxelib git hxnodejs https://github.com/HaxeFoundation/hxnodejs` (latest from GitHub). 27 | 2. Write some code and save to `Main.hx`: 28 | 29 | ```haxe 30 | class Main { 31 | static function main() { 32 | var server = js.node.Net.createServer(function(socket) { 33 | socket.write("Echo server\n\n"); 34 | socket.pipe(socket); 35 | }); 36 | server.listen(1337, "127.0.0.1"); 37 | } 38 | } 39 | ``` 40 | 41 | 3. Compile it with with `haxe -lib hxnodejs -main Main -js main.js` (optionally add `-D js-es=6` for cleaner JavaScript output, since node.js is ES6-compliant) 42 | 4. Look at generated `main.js`: 43 | 44 | ```js 45 | // Generated by Haxe 4.0.0-rc.2+63144f6db 46 | (function ($global) { "use strict"; 47 | class Main { 48 | static main() { 49 | var server = js_node_Net.createServer(function(socket) { 50 | socket.write("Echo server\n\n"); 51 | socket.pipe(socket); 52 | }); 53 | server.listen(1337,"127.0.0.1"); 54 | } 55 | } 56 | var js_node_Net = require("net"); 57 | Main.main(); 58 | })({}); 59 | ``` 60 | 61 | 5. You're awesome! (See more [examples](examples)) 62 | 63 | ## Status 64 | 65 | This library is considered complete, but testing and contributions are welcome. See [current issues](https://github.com/HaxeFoundation/hxnodejs/issues) and [extern guidelines](https://github.com/HaxeFoundation/hxnodejs/blob/master/HOWTO.md). 66 | 67 | -------------------------------------------------------------------------------- /src/js/node/buffer/SlowBuffer.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.buffer; 24 | 25 | /** 26 | Returns an un-pooled `Buffer`. 27 | 28 | In order to avoid the garbage collection overhead of creating many individually allocated Buffer instances, 29 | by default allocations under 4KB are sliced from a single larger allocated object. 30 | This approach improves both performance and memory usage since v8 does not need to track 31 | and cleanup as many Persistent objects. 32 | 33 | In the case where a developer may need to retain a small chunk of memory from a pool 34 | for an indeterminate amount of time, it may be appropriate to create an un-pooled `Buffer` instance 35 | using `SlowBuffer` then copy out the relevant bits. 36 | 37 | Use of `SlowBuffer` should be used only as a last resort after a developer has observed 38 | undue memory retention in their applications. 39 | **/ 40 | @:deprecated("SlowBuffer is deprecated, use Buffer.allocUnsafeSlow() instead") 41 | @:jsRequire("buffer", "SlowBuffer") 42 | extern class SlowBuffer extends Buffer { 43 | /** 44 | Allocates a new `SlowBuffer` of `size` bytes. 45 | The `size` must be less than or equal to the value of `Buffer.kMaxLength`. Otherwise, a `RangeError` is thrown. 46 | A zero-length Buffer will be created if size <= 0. 47 | 48 | The underlying memory for `SlowBuffer` instances is not initialized. The contents of a newly created `SlowBuffer` 49 | are unknown and could contain sensitive data. Use `buf.fill(0)` to initialize a `SlowBuffer` to zeroes. 50 | **/ 51 | function new(size:Int); 52 | } 53 | -------------------------------------------------------------------------------- /src/js/node/crypto/Verify.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import js.node.Buffer; 26 | import js.node.stream.Writable; 27 | 28 | /** 29 | Class for verifying signatures. 30 | Returned by `Crypto.createVerify`. 31 | 32 | Verify objects are writable streams. The written data is used to validate against the supplied signature. 33 | Once all of the data has been written, the verify method will return true if the supplied signature is valid. 34 | 35 | The legacy `update` method is also supported. 36 | **/ 37 | extern class Verify extends Writable { 38 | /** 39 | Updates the verifier object with data. This can be called many times with new data as it is streamed. 40 | **/ 41 | @:overload(function(data:Buffer):Void {}) 42 | function update(data:String, ?encoding:String):Void; 43 | 44 | /** 45 | Verifies the signed data by using the object and signature. 46 | 47 | `object` is a string containing a PEM encoded object, which can be one of RSA public key, 48 | DSA public key, or X.509 certificate. 49 | 50 | `signature` is the previously calculated signature for the data, 51 | in the `signature_format` which can be 'binary', 'hex' or 'base64'. 52 | If no encoding is specified, then a buffer is expected. 53 | 54 | Returns true or false depending on the validity of the signature for the data and public key. 55 | 56 | Note: verifier object can not be used after `verify` method has been called. 57 | **/ 58 | @:overload(function(object:String, signature:Buffer):Bool {}) 59 | function verify(object:String, signature:String, signature_format:String):Bool; 60 | } 61 | -------------------------------------------------------------------------------- /examples/StreamImplSimpleProtocol.hx: -------------------------------------------------------------------------------- 1 | import js.node.Buffer; 2 | import js.node.stream.Readable; 3 | #if haxe4 4 | import js.lib.Error; 5 | #else 6 | import js.Error; 7 | #end 8 | 9 | // A parser for a simple data protocol. 10 | // The "header" is a JSON object, followed by 2 \n characters, and 11 | // then a message body. 12 | // 13 | // NOTE: This can be done more simply as a Transform stream! 14 | // Using Readable directly for this is sub-optimal. See the 15 | // alternative example below under the Transform section. 16 | 17 | @:keep 18 | class SimpleProtocol extends Readable { 19 | var _inBody = false; 20 | var _sawFirstCr = false; 21 | var _rawHeader = []; 22 | var _source:IReadable; 23 | var header:Buffer; 24 | 25 | public function new(source, options) { 26 | super(options); 27 | // source is a readable stream, such as a socket or file 28 | _source = source; 29 | source.on('end', push.bind(null)); 30 | 31 | // give it a kick whenever the source is readable 32 | // read(0) will not consume any bytes 33 | source.on('readable', read.bind(0)); 34 | } 35 | 36 | override function _read(size:Int):Void { 37 | if (!_inBody) { 38 | var chunk:Buffer = _source.read(); 39 | 40 | // if the source doesn't have data, we don't have data yet. 41 | if (chunk == null) { 42 | push(''); 43 | return; 44 | } 45 | 46 | // check if the chunk has a \n\n 47 | var split = -1; 48 | for (i in 0...chunk.length) { 49 | if (chunk[i] == 10) { // '\n' 50 | if (_sawFirstCr) { 51 | split = i; 52 | break; 53 | } else { 54 | _sawFirstCr = true; 55 | } 56 | } else { 57 | _sawFirstCr = false; 58 | } 59 | } 60 | 61 | if (split == -1) { 62 | // still waiting for the \n\n 63 | // stash the chunk, and try again. 64 | _rawHeader.push(chunk); 65 | push(''); 66 | } else { 67 | _inBody = true; 68 | _rawHeader.push(chunk.slice(0, split)); 69 | var header = try { 70 | haxe.Json.parse(Buffer.concat(_rawHeader).toString()); 71 | } catch (_:Dynamic) { 72 | emit('error', new Error('invalid simple protocol data')); 73 | return; 74 | } 75 | // now, because we got some extra data, unshift the rest 76 | // back into the read queue so that our consumer will see it. 77 | var b = chunk.slice(split); 78 | unshift(b); 79 | 80 | // and let them know that we are done parsing the header. 81 | emit('header', this.header); 82 | } 83 | } else { 84 | // from there on, just provide the data to our consumer. 85 | // careful not to push(null), since that would indicate EOF. 86 | var chunk = this._source.read(); 87 | if (chunk != null) 88 | this.push(chunk); 89 | } 90 | } 91 | } 92 | 93 | class StreamImplSimpleProtocol { 94 | static function main() {} 95 | } 96 | -------------------------------------------------------------------------------- /src/js/node/util/Inspect.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.util; 24 | 25 | import haxe.DynamicAccess; 26 | import js.node.Util.InspectOptions; 27 | 28 | @:jsRequire("util", "inspect") 29 | extern class Inspect { 30 | /** 31 | The `util.inspect()` method returns a string representation of `object` that is intended for debugging. 32 | 33 | @see https://nodejs.org/api/util.html#util_util_inspect_object_options 34 | **/ 35 | @:selfCall 36 | @:overload(function(object:Dynamic, ?showHidden:Bool, ?depth:Int, ?colors:Bool):String {}) 37 | static function inspect(object:Dynamic, ?options:InspectOptions):String; 38 | 39 | /** 40 | `util.inspect.styles` is a map associating a style name to a color from `util.inspect.colors` properties. 41 | 42 | @see https://nodejs.org/api/util.html#util_customizing_util_inspect_colors 43 | **/ 44 | static var styles:DynamicAccess; 45 | 46 | /** 47 | The predefined color codes are: `white`, `grey`, `black`, `blue`, `cyan`, `green`, `magenta`, `red` and 48 | `yellow`. 49 | **/ 50 | static var colors:DynamicAccess>; 51 | 52 | /** 53 | In addition to being accessible through `util.inspect.custom`, this symbol is registered globally and can be 54 | accessed in any environment as `Symbol.for('nodejs.util.inspect.custom')`. 55 | 56 | @see https://nodejs.org/api/util.html#util_util_inspect_custom 57 | **/ 58 | #if haxe4 59 | static final custom:js.lib.Symbol; 60 | #else 61 | static var custom(default, never):Dynamic; 62 | #end 63 | 64 | /** 65 | The `defaultOptions` value allows customization of the default options used by `util.inspect`. 66 | 67 | @see https://nodejs.org/api/util.html#util_util_inspect_defaultoptions 68 | **/ 69 | static var defaultOptions:InspectOptions; 70 | } 71 | -------------------------------------------------------------------------------- /src/js/node/StringDecoder.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | #if haxe4 26 | import js.lib.ArrayBufferView; 27 | #else 28 | import js.html.ArrayBufferView; 29 | #end 30 | 31 | /** 32 | The `string_decoder` module provides an API for decoding `Buffer` objects into strings in a manner that preserves 33 | encoded multi-byte UTF-8 and UTF-16 characters. 34 | 35 | @see https://nodejs.org/api/string_decoder.html#string_decoder_string_decoder 36 | **/ 37 | @:jsRequire("string_decoder", "StringDecoder") 38 | extern class StringDecoder { 39 | /** 40 | Creates a new `StringDecoder` instance. 41 | 42 | @see https://nodejs.org/api/string_decoder.html#string_decoder_new_stringdecoder_encoding 43 | **/ 44 | function new(?encoding:String); 45 | 46 | /** 47 | Returns any remaining input stored in the internal buffer as a string. 48 | Bytes representing incomplete UTF-8 and UTF-16 characters will be replaced 49 | with substitution characters appropriate for the character encoding. 50 | 51 | @see https://nodejs.org/api/string_decoder.html#string_decoder_stringdecoder_end_buffer 52 | **/ 53 | @:overload(function(buffer:Buffer):String {}) 54 | @:overload(function(buffer:ArrayBufferView):String {}) 55 | function end():String; 56 | 57 | /** 58 | Returns a decoded string, ensuring that any incomplete multibyte characters at the end of the `Buffer`, or 59 | `TypedArray`, or `DataViewor` are omitted from the returned string and stored in an internal buffer for the next 60 | call to `stringDecoder.write()` or `stringDecoder.end()`. 61 | 62 | @see https://nodejs.org/api/string_decoder.html#string_decoder_stringdecoder_write_buffer 63 | **/ 64 | @:overload(function(buffer:ArrayBufferView):String {}) 65 | function write(buffer:Buffer):String; 66 | } 67 | -------------------------------------------------------------------------------- /src/js/node/V8.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | /** 26 | The v8 module exposes APIs that are specific to the version of V8 built into the Node.js binary. 27 | 28 | Note: The APIs and implementation are subject to change at any time. 29 | **/ 30 | @:jsRequire("v8") 31 | extern class V8 { 32 | static function getHeapStatistics():V8HeapStatistics; 33 | 34 | /** 35 | Returns statistics about the V8 heap spaces, i.e. the segments which make up the V8 heap. 36 | Neither the ordering of heap spaces, nor the availability of a heap space can be guaranteed 37 | as the statistics are provided via the V8 `GetHeapSpaceStatistics` function and may change 38 | from one V8 version to the next. 39 | **/ 40 | static function getHeapSpaceStatistics():Array; 41 | 42 | /** 43 | This method can be used to programmatically set V8 command line flags. This method should be used with care. 44 | Changing settings after the VM has started may result in unpredictable behavior, including crashes and data loss; 45 | or it may simply do nothing. 46 | 47 | The V8 options available for a version of Node.js may be determined by running `node --v8-options`. 48 | **/ 49 | static function setFlagsFromString(string:String):Void; 50 | } 51 | 52 | /** 53 | Object returned by `V8.getHeapStatistics` method. 54 | **/ 55 | typedef V8HeapStatistics = { 56 | var total_heap_size:Int; 57 | var total_heap_size_executable:Int; 58 | var total_physical_size:Int; 59 | var total_available_size:Int; 60 | var used_heap_size:Int; 61 | var heap_size_limit:Int; 62 | } 63 | 64 | /** 65 | Object returned by `V8.getHeapSpaceStatistics` method. 66 | **/ 67 | typedef V8HeapSpaceStatistics = { 68 | var space_name:String; 69 | var space_size:Int; 70 | var space_used_size:Int; 71 | var space_available_size:Int; 72 | var physical_space_size:Int; 73 | } 74 | -------------------------------------------------------------------------------- /src/js/node/fs/Stats.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.fs; 24 | 25 | /** 26 | Objects returned from `Fs.stat`, `Fs.lstat` and `Fs.fstat` and their synchronous counterparts are of this type. 27 | **/ 28 | extern class Stats { 29 | var dev:Int; 30 | var ino:Float; 31 | var mode:Int; 32 | var nlink:Int; 33 | var uid:Int; 34 | var gid:Int; 35 | var rdev:Int; 36 | var size:Float; 37 | var blksize:Null; 38 | var blocks:Null; 39 | 40 | /** 41 | "Access Time" - Time when file data last accessed. 42 | 43 | Changed by the mknod(2), utimes(2), and read(2) system calls. 44 | **/ 45 | var atime:Date; 46 | 47 | /** 48 | "Modified Time" - Time when file data last modified. 49 | 50 | Changed by the mknod(2), utimes(2), and write(2) system calls. 51 | **/ 52 | var mtime:Date; 53 | 54 | /** 55 | "Change Time" - Time when file status was last changed (inode data modification). 56 | 57 | Changed by the chmod(2), chown(2), link(2), mknod(2), rename(2), unlink(2), utimes(2), read(2), and write(2) system calls. 58 | **/ 59 | var ctime:Date; 60 | 61 | /** 62 | "Birth Time" - Time of file creation. Set once when the file is created. 63 | 64 | On filesystems where birthtime is not available, this field may instead hold either the ctime or 1970-01-01T00:00Z (ie, unix epoch timestamp 0). 65 | Note that this value may be greater than `atime` or `mtime` in this case. On Darwin and other FreeBSD variants, 66 | also set if the `atime` is explicitly set to an earlier value than the current birthtime using the utimes(2) system call. 67 | **/ 68 | var birthtime:Date; 69 | 70 | function isFile():Bool; 71 | function isDirectory():Bool; 72 | function isBlockDevice():Bool; 73 | function isCharacterDevice():Bool; 74 | 75 | /** 76 | Only valid with `Fs.lstat`. 77 | **/ 78 | function isSymbolicLink():Bool; 79 | 80 | function isFIFO():Bool; 81 | function isSocket():Bool; 82 | } 83 | -------------------------------------------------------------------------------- /src/js/node/Punycode.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | @:deprecated("In a future major version of Node.js punycode module will be removed") 26 | @:jsRequire("punycode") 27 | extern class Punycode { 28 | /** 29 | Converts a Punycode string of ASCII code points to a string of Unicode code points. 30 | **/ 31 | static function decode(string:String):String; 32 | 33 | /** 34 | Converts a string of Unicode code points to a Punycode string of ASCII code points. 35 | **/ 36 | static function encode(string:String):String; 37 | 38 | /** 39 | Converts a Punycode string representing a domain name to Unicode. 40 | 41 | Only the Punycoded parts of the domain name will be converted, i.e. it doesn't matter 42 | if you call it on a string that has already been converted to Unicode. 43 | **/ 44 | static function toUnicode(domain:String):String; 45 | 46 | /** 47 | Converts a Unicode string representing a domain name to Punycode. 48 | 49 | Only the non-ASCII parts of the domain name will be converted, i.e. it doesn't matter 50 | if you call it with a domain that's already in ASCII. 51 | **/ 52 | static function toASCII(domain:String):String; 53 | 54 | static var ucs2(default, null):PunycodeUcs2; 55 | 56 | /** 57 | The current Punycode.js version number. 58 | **/ 59 | static var version(default, null):String; 60 | } 61 | 62 | @:deprecated 63 | extern class PunycodeUcs2 { 64 | /** 65 | Creates an array containing the decimal code points of each Unicode character in the string. 66 | While JavaScript uses UCS-2 internally, this function will convert a pair of surrogate halves (each of which 67 | UCS-2 exposes as separate characters) into a single code point, matching UTF-16. 68 | **/ 69 | function decode(string:String):Array; 70 | 71 | /** 72 | Creates a string based on an array of decimal code points. 73 | **/ 74 | function encode(codePoints:Array):String; 75 | } 76 | -------------------------------------------------------------------------------- /src/js/node/assert/AssertionError.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.assert; 24 | 25 | #if haxe4 26 | import js.lib.Error; 27 | #else 28 | import js.Error; 29 | #end 30 | 31 | /** 32 | Indicates the failure of an assertion. All errors thrown by the `Assert` module will be instances of the `AssertionError` class. 33 | 34 | @see https://nodejs.org/api/assert.html#assert_class_assert_assertionerror 35 | **/ 36 | @:jsRequire("assert", "AssertionError") 37 | extern class AssertionError extends Error { 38 | /** 39 | A subclass of Error that indicates the failure of an assertion. 40 | **/ 41 | function new(options:AssertionErrorOptions); 42 | 43 | /** 44 | Set to the `actual` argument for methods such as `Assert.strictEqual()`. 45 | **/ 46 | var actual:Dynamic; 47 | 48 | /** 49 | Set to the `expected` value for methods such as `Assert.strictEqual()`. 50 | **/ 51 | var expected:Dynamic; 52 | 53 | /** 54 | Indicates if the message was auto-generated (`true`) or not. 55 | **/ 56 | var generatedMessage:Bool; 57 | 58 | /** 59 | Value is always `ERR_ASSERTION` to show that the error is an assertion error. 60 | **/ 61 | var code:String; 62 | 63 | /** 64 | Set to the passed in operator value. 65 | **/ 66 | @:native("operator") var operator_:String; 67 | } 68 | 69 | /** 70 | An options type for `new` of `AssertionError`. 71 | **/ 72 | typedef AssertionErrorOptions = { 73 | /** 74 | If provided, the error message is set to this value. 75 | **/ 76 | @:optional var message:String; 77 | 78 | /** 79 | The `actual` property on the error instance. 80 | **/ 81 | @:optional var actual:Dynamic; 82 | 83 | /** 84 | The `expected` property on the error instance. 85 | **/ 86 | @:optional var expected:Dynamic; 87 | 88 | #if (haxe_ver < 4) 89 | /** 90 | The `operator` property on the error instance. 91 | **/ 92 | @:optional var operator:String; 93 | #end 94 | 95 | /** 96 | If provided, the generated stack trace omits frames before this function. 97 | **/ 98 | @:optional var stackStartFunction:Dynamic; 99 | } 100 | -------------------------------------------------------------------------------- /src/js/node/stream/Transform.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.stream; 24 | 25 | #if haxe4 26 | import js.lib.Error; 27 | #else 28 | import js.Error; 29 | #end 30 | 31 | /** 32 | A `Transform` stream is a `Duplex` stream where the output is computed in some way from the input. 33 | Examples include `zlib` streams or `crypto` streams that compress, encrypt, or decrypt data. 34 | 35 | @see https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream 36 | **/ 37 | @:jsRequire("stream", "Transform") 38 | extern class Transform> extends Duplex implements ITransform { 39 | function new(?options:TransformNewOptions); 40 | 41 | /** 42 | This function **MUST NOT** be called by application code directly. 43 | It should be implemented by child classes, and called by the internal `Readable` class methods only. 44 | 45 | @see https://nodejs.org/api/stream.html#stream_transform_flush_callback 46 | **/ 47 | private function _flush(callback:Null->Void):Void; 48 | 49 | /** 50 | This function **MUST NOT** be called by application code directly. 51 | It should be implemented by child classes, and called by the internal `Readable` class methods only. 52 | 53 | @see https://nodejs.org/api/stream.html#stream_transform_transform_chunk_encoding_callback 54 | **/ 55 | #if haxe4 56 | private function _transform(chunk:Dynamic, encoding:String, callback:(error:Null, data:Dynamic) -> Void):Void; 57 | #else 58 | private function _transform(chunk:Dynamic, encoding:String, callback:Null->Dynamic->Void):Void; 59 | #end 60 | } 61 | 62 | /** 63 | @see https://nodejs.org/api/stream.html#stream_new_stream_transform_options 64 | **/ 65 | typedef TransformNewOptions = { 66 | > Duplex.DuplexNewOptions, 67 | 68 | /** 69 | Implementation for the `stream._transform()` method. 70 | **/ 71 | #if haxe4 72 | @:optional var transform:(chunk:Dynamic, encoding:String, callback:(error:Null, data:Dynamic) -> Void) -> Void; 73 | #else 74 | @:optional var transform:Dynamic->String->(Null->Dynamic->Void)->Void; 75 | #end 76 | 77 | /** 78 | Implementation for the `stream._flush()` method. 79 | **/ 80 | @:optional var flush:Null->Void; 81 | } 82 | 83 | @:remove 84 | extern interface ITransform extends Duplex.IDuplex {} 85 | -------------------------------------------------------------------------------- /src/js/node/crypto/Decipher.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import js.node.Buffer; 26 | 27 | /** 28 | Class for decrypting data. 29 | 30 | Returned by `Crypto.createDecipher` and `Crypto.createDecipheriv`. 31 | 32 | Decipher objects are streams that are both readable and writable. 33 | The written enciphered data is used to produce the plain-text data on the the readable side. 34 | 35 | The legacy `update` and `final` methods are also supported. 36 | **/ 37 | extern class Decipher extends js.node.stream.Transform { 38 | /** 39 | Updates the decipher with `data`, which is encoded in 'binary', 'base64' or 'hex'. 40 | If no encoding is provided, then a buffer is expected. 41 | 42 | The `output_decoding` specifies in what format to return the deciphered plaintext: 'binary', 'ascii' or 'utf8'. 43 | If no encoding is provided, then a buffer is returned. 44 | **/ 45 | @:overload(function(data:Buffer):Buffer {}) 46 | @:overload(function(data:String, input_encoding:String):Buffer {}) 47 | function update(data:String, input_encoding:String, output_encoding:String):String; 48 | 49 | /** 50 | Returns any remaining plaintext which is deciphered, 51 | with `output_encoding` being one of: 'binary', 'ascii' or 'utf8'. 52 | If no encoding is provided, then a buffer is returned. 53 | 54 | Note: decipher object can not be used after `final` method has been called. 55 | **/ 56 | @:native("final") @:overload(function():Buffer {}) 57 | function finalContents(output_encoding:String):String; 58 | 59 | /** 60 | You can disable auto padding if the data has been encrypted without standard block padding 61 | to prevent `final` from checking and removing it. 62 | 63 | Can only work if the input data's length is a multiple of the ciphers block size. 64 | 65 | You must call this before streaming data to `update`. 66 | **/ 67 | @:overload(function():Void {}) 68 | function setAutoPadding(auto_padding:Bool):Void; 69 | 70 | /** 71 | For authenticated encryption modes (currently supported: GCM), this method must be used 72 | to pass in the received authentication tag. If no tag is provided or if the ciphertext 73 | has been tampered with, `final` will throw, thus indicating that the ciphertext should be 74 | discarded due to failed authentication. 75 | **/ 76 | function setAuthTag(buffer:Buffer):Void; 77 | 78 | /** 79 | For authenticated encryption modes (currently supported: GCM), this method sets the value 80 | used for the additional authenticated data (AAD) input parameter. 81 | **/ 82 | function setAAD(buffer:Buffer):Void; 83 | } 84 | -------------------------------------------------------------------------------- /src/js/node/Stream.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import haxe.extern.Rest; 26 | import js.node.events.EventEmitter; 27 | import js.node.stream.Readable.IReadable; 28 | import js.node.stream.Writable.IWritable; 29 | #if haxe4 30 | import js.lib.Error; 31 | import js.lib.Promise; 32 | #else 33 | import js.Error; 34 | import js.Promise; 35 | #end 36 | 37 | /** 38 | Base class for all streams. 39 | **/ 40 | @:jsRequire("stream") // the module itself is also a class 41 | extern class Stream> extends EventEmitter implements IStream { 42 | private function new(); 43 | 44 | /** 45 | A module method to pipe between streams forwarding errors and properly cleaning up 46 | and provide a callback when the pipeline is complete. 47 | 48 | @see https://nodejs.org/api/stream.html#stream_stream_pipeline_streams_callback 49 | **/ 50 | @:overload(function(readable:IReadable, callback:Null->Void):Void {}) 51 | @:overload(function(readable:IReadable, writable1:IWritable, callback:Null->Void):Void {}) 52 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, callback:Null->Void):Void {}) 53 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, writable3:IWritable, callback:Null->Void):Void {}) 54 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, writable3:IWritable, writable4:IWritable, 55 | callback:Null->Void):Void {}) 56 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, writable3:IWritable, writable4:IWritable, writable5:IWritable, 57 | callback:Null->Void):Void {}) 58 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, writable3:IWritable, writable4:IWritable, writable5:IWritable, 59 | writable6:IWritable, callback:Null->Void):Void {}) 60 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, writable3:IWritable, writable4:IWritable, writable5:IWritable, 61 | writable6:IWritable, writable7:IWritable, callback:Null->Void):Void {}) 62 | @:overload(function(readable:IReadable, writable1:IWritable, writable2:IWritable, writable3:IWritable, writable4:IWritable, writable5:IWritable, 63 | writable6:IWritable, writable7:IWritable, writable8:IWritable, callback:Null->Void):Void {}) 64 | static function pipeline(readable:IReadable, streams:Rest):Promise; 65 | } 66 | 67 | /** 68 | `IStream` interface is used as "any Stream". 69 | 70 | See `Stream` for actual class. 71 | **/ 72 | @:remove 73 | extern interface IStream extends IEventEmitter {} 74 | -------------------------------------------------------------------------------- /src/js/node/crypto/Cipher.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import js.node.Buffer; 26 | 27 | /** 28 | Class for encrypting data. 29 | 30 | Returned by `Crypto.createCipher` and `Crypto.createCipheriv`. 31 | 32 | Cipher objects are streams that are both readable and writable. 33 | The written plain text data is used to produce the encrypted data on the readable side. 34 | 35 | The legacy `update` and `final` methods are also supported. 36 | **/ 37 | extern class Cipher extends js.node.stream.Transform { 38 | /** 39 | Updates the cipher with `data`, the encoding of which is given in `input_encoding` 40 | and can be 'utf8', 'ascii' or 'binary'. If no encoding is provided, then a buffer is expected. 41 | If data is a Buffer then `input_encoding` is ignored. 42 | 43 | The `output_encoding` specifies the output format of the enciphered data, 44 | and can be 'binary', 'base64' or 'hex'. If no encoding is provided, then a buffer is returned. 45 | 46 | Returns the enciphered contents, and can be called many times with new data as it is streamed. 47 | **/ 48 | @:overload(function(data:Buffer):Buffer {}) 49 | @:overload(function(data:String, input_encoding:String):Buffer {}) 50 | function update(data:String, input_encoding:String, output_encoding:String):String; 51 | 52 | /** 53 | Returns any remaining enciphered contents, with `output_encoding` being one of: 'binary', 'base64' or 'hex'. 54 | If no encoding is provided, then a buffer is returned. 55 | 56 | Note: cipher object can not be used after `final` method has been called. 57 | **/ 58 | @:native("final") @:overload(function():Buffer {}) 59 | function finalContents(output_encoding:String):String; 60 | 61 | /** 62 | You can disable automatic padding of the input data to block size. 63 | If `auto_padding` is false, the length of the entire input data 64 | must be a multiple of the cipher's block size or `final` will fail. 65 | 66 | Useful for non-standard padding, e.g. using 0x0 instead of PKCS padding. 67 | You must call this before `final`. 68 | **/ 69 | @:overload(function():Void {}) 70 | function setAutoPadding(auto_padding:Bool):Void; 71 | 72 | /** 73 | For authenticated encryption modes (currently supported: GCM), this method returns a `Buffer` 74 | that represents the authentication tag that has been computed from the given data. 75 | Should be called after encryption has been completed using the `final` method! 76 | **/ 77 | function getAuthTag():Buffer; 78 | 79 | /** 80 | For authenticated encryption modes (currently supported: GCM), this method sets the value 81 | used for the additional authenticated data (AAD) input parameter. 82 | **/ 83 | function setAAD(buffer:Buffer):Void; 84 | } 85 | -------------------------------------------------------------------------------- /src/js/node/util/TextDecoder.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.util; 24 | 25 | import haxe.extern.EitherType; 26 | #if haxe4 27 | import js.lib.ArrayBuffer; 28 | import js.lib.ArrayBufferView; 29 | #else 30 | import js.html.ArrayBuffer; 31 | import js.html.ArrayBufferView; 32 | #end 33 | 34 | /** 35 | An implementation of the WHATWG Encoding Standard `TextDecoder` API. 36 | 37 | @see https://nodejs.org/api/util.html#util_class_util_textdecoder 38 | **/ 39 | @:jsRequire("util", "TextDecoder") 40 | extern class TextDecoder { 41 | /** 42 | Creates an new `TextDecoder` instance. 43 | 44 | @see https://nodejs.org/api/util.html#util_new_textdecoder_encoding_options 45 | **/ 46 | function new(?encoding:String, ?options:TextDecoderOptions); 47 | 48 | /** 49 | Decodes the `input` and returns a string. 50 | 51 | @see https://nodejs.org/api/util.html#util_textdecoder_decode_input_options 52 | **/ 53 | function decode(?input:EitherType, ?options:TextDecodeOptions):String; 54 | 55 | /** 56 | The encoding supported by the `TextDecoder` instance. 57 | 58 | @see https://nodejs.org/api/util.html#util_textdecoder_encoding 59 | **/ 60 | var encoding(default, null):String; 61 | 62 | /** 63 | The value will be `true` if decoding errors result in a `TypeError` being thrown. 64 | 65 | @see https://nodejs.org/api/util.html#util_textdecoder_fatal 66 | **/ 67 | var fatal(default, null):Bool; 68 | 69 | /** 70 | The value will be `true` if the decoding result will include the byte order mark. 71 | 72 | @see https://nodejs.org/api/util.html#util_textdecoder_ignorebom 73 | **/ 74 | var ignoreBOM(default, null):Bool; 75 | } 76 | 77 | /** 78 | Options object used by `new TextDecoder()`. 79 | 80 | @see https://nodejs.org/api/util.html#util_new_textdecoder_encoding_options 81 | **/ 82 | typedef TextDecoderOptions = { 83 | /** 84 | `true` if decoding failures are fatal. 85 | This option is only supported when ICU is enabled (see Internationalization). 86 | 87 | Default: `false`. 88 | **/ 89 | @:optional var fatal:Bool; 90 | 91 | /** 92 | When `true`, the `TextDecoder` will include the byte order mark in the decoded result. 93 | When `false`, the byte order mark will be removed from the output. 94 | This option is only used when `encoding` is `'utf-8'`, `'utf-16be'` or `'utf-16le'`. 95 | 96 | Default: `false`. 97 | **/ 98 | @:optional var ignoreBOM:Bool; 99 | } 100 | 101 | /** 102 | Options object used by `TextDecoder.decode`. 103 | **/ 104 | typedef TextDecodeOptions = { 105 | /** 106 | `true` if additional chunks of data are expected. 107 | 108 | Default: `false`. 109 | **/ 110 | @:optional var stream:Bool; 111 | } 112 | -------------------------------------------------------------------------------- /src/js/node/vm/Script.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.vm; 24 | 25 | import js.node.Vm.VmContext; 26 | 27 | typedef ScriptOptions = { 28 | /** 29 | The filename that shows up in any stack traces produced. 30 | **/ 31 | @:optional var filename:String; 32 | 33 | /** 34 | Whether or not to print any errors to stderr, with the line of code that caused them highlighted, 35 | before throwing an exception. 36 | 37 | Will capture both syntax errors from compiling code and runtime errors thrown by executing the compiled code. 38 | 39 | Defaults to true. 40 | **/ 41 | @:optional var displayErrors:Bool; 42 | } 43 | 44 | typedef ScriptRunOptions = { 45 | /** 46 | Whether or not to print any errors to stderr, with the line of code that caused them highlighted, 47 | before throwing an exception. 48 | 49 | Will capture both syntax errors from compiling code and runtime errors thrown by executing the compiled code. 50 | 51 | Defaults to true. 52 | **/ 53 | @:optional var displayErrors:Bool; 54 | 55 | /** 56 | Number of milliseconds to execute code before terminating execution. 57 | If execution is terminated, an Error will be thrown. 58 | **/ 59 | @:optional var timeout:Int; 60 | } 61 | 62 | /** 63 | A class for holding precompiled scripts, and running them in specific sandboxes. 64 | **/ 65 | @:jsRequire("vm", "Script") 66 | extern class Script { 67 | /** 68 | Creating a new `Script` compiles `code` but does not run it. Instead, the created `Script` object 69 | represents this compiled code. 70 | 71 | This script can be run later many times using methods below. 72 | 73 | The returned script is not bound to any global object. It is bound before each run, just for that run. 74 | **/ 75 | function new(code:String, ?options:ScriptOptions); 76 | 77 | /** 78 | Similar to `Vm.runInThisContext` but a method of a precompiled `Script` object. 79 | `runInThisContext` runs the code of script and returns the result. 80 | Running code does not have access to local scope, but does have access to the current global object. 81 | **/ 82 | function runInThisContext(?options:ScriptRunOptions):Dynamic; 83 | 84 | /** 85 | Similar to `Vm.runInContext` but a method of a precompiled `Script` object. 86 | `runInContext` runs script's compiled code in `contextifiedSandbox` and returns the result. 87 | Running code does not have access to local scope. 88 | **/ 89 | function runInContext(contextifiedSandbox:VmContext, ?options:ScriptRunOptions):Dynamic; 90 | 91 | /** 92 | Similar to `Vm.runInNewContext` but a method of a precompiled `Script` object. 93 | `runInNewContext` contextifies sandbox if passed or creates a new contextified sandbox if it's omitted, 94 | and then runs script's compiled code with the sandbox as the global object and returns the result. 95 | Running code does not have access to local scope. 96 | **/ 97 | @:overload(function(sandbox:{}, ?options:ScriptRunOptions):Dynamic {}) 98 | function runInNewContext(?sandbox:{}):Dynamic; 99 | } 100 | -------------------------------------------------------------------------------- /src/js/node/tls/SecureContext.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.tls; 24 | 25 | import haxe.extern.EitherType; 26 | 27 | typedef SecureContextOptions = { 28 | /** 29 | private key, certificate and CA certs of the server in PFX or PKCS12 format. 30 | **/ 31 | @:optional var pfx:EitherType; 32 | 33 | /** 34 | passphrase for the private key or pfx. 35 | **/ 36 | @:optional var passphrase:String; 37 | 38 | /** 39 | private key of the server in PEM format. 40 | **/ 41 | @:optional var key:EitherType; 42 | 43 | /** 44 | certificate key of the server in PEM format. 45 | **/ 46 | @:optional var cert:EitherType; 47 | 48 | /** 49 | trusted certificates in PEM format. 50 | If this is omitted several well known "root" CAs will be used, like VeriSign. 51 | These are used to authorize connections. 52 | **/ 53 | @:optional var ca:Array>; 54 | 55 | /** 56 | PEM encoded CRLs (Certificate Revocation List) 57 | **/ 58 | @:optional var crl:EitherType>; 59 | 60 | /** 61 | ciphers to use or exclude. 62 | 63 | To mitigate BEAST attacks it is recommended that you use this option in conjunction with the `honorCipherOrder` 64 | option described below to prioritize the non-CBC cipher. 65 | 66 | Defaults to AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH. 67 | 68 | Consult the OpenSSL cipher list format documentation for details on the format. 69 | ECDH (Elliptic Curve Diffie-Hellman) ciphers are not yet supported. 70 | **/ 71 | @:optional var ciphers:String; 72 | 73 | /** 74 | named curve to use for ECDH key agreement or false to disable ECDH. 75 | 76 | Defaults to prime256v1 (NIST P-256). Use `Crypto.getCurves` to obtain a list of available curve names. 77 | On recent releases, openssl ecparam -list_curves will also display the name and description 78 | of each available elliptic curve. 79 | **/ 80 | @:optional var ecdhCurve:String; 81 | 82 | /** 83 | Diffie Hellman parameters, required for Perfect Forward Secrecy. 84 | 85 | Use openssl dhparam to create it. Its key length should be greater than or equal to 1024 bits, 86 | otherwise it throws an error. It is strongly recommended to use 2048 bits or more for stronger security. 87 | If omitted or invalid, it is silently discarded and DHE ciphers won't be available. 88 | **/ 89 | @:optional var dhparam:EitherType; 90 | 91 | /** 92 | The SSL method to use, e.g. SSLv3_method to force SSL version 3. 93 | The possible values depend on your installation of OpenSSL and are defined in the constant SSL_METHODS. 94 | **/ 95 | @:optional var secureProtocol:String; 96 | 97 | /** 98 | opaque identifier for session resumption. 99 | If `requestCert` is true, the default is MD5 hash value generated from command-line. 100 | Otherwise, the default is not provided. 101 | **/ 102 | @:optional var sessionIdContext:String; 103 | 104 | /** 105 | When choosing a cipher, use the server's preferences instead of the client preferences. 106 | Default: true. 107 | **/ 108 | @:optional var honorCipherOrder:Bool; 109 | } 110 | 111 | extern class SecureContext {} 112 | -------------------------------------------------------------------------------- /src/js/node/crypto/ECDH.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.crypto; 24 | 25 | import haxe.extern.EitherType; 26 | import js.node.Buffer; 27 | 28 | enum abstract ECDHFormat(String) from String to String { 29 | var Compressed = "compressed"; 30 | var Uncompressed = "uncompressed"; 31 | var Hybrid = "hybrid"; 32 | } 33 | 34 | /** 35 | The class for creating EC Diffie-Hellman key exchanges. 36 | 37 | Returned by `Crypto.createECDH`. 38 | **/ 39 | extern class ECDH { 40 | /** 41 | Generates private and public EC Diffie-Hellman key values, and returns the public key 42 | in the specified `format` and `encoding`. This key should be transferred to the other party. 43 | 44 | Format specifies point encoding and can be 'compressed', 'uncompressed', or 'hybrid'. 45 | If no format is provided - the point will be returned in 'uncompressed' format. 46 | 47 | Encoding can be 'binary', 'hex', or 'base64'. If no encoding is provided, then a buffer is returned. 48 | **/ 49 | function generateKeys(?encoding:String, ?format:ECDHFormat):EitherType; 50 | 51 | /** 52 | Computes the shared secret using `other_public_key` as the other party's public key 53 | and returns the computed shared secret. Supplied key is interpreted using specified `input_encoding`, 54 | and secret is encoded using specified `output_encoding`. 55 | 56 | Encodings can be 'binary', 'hex', or 'base64'. 57 | 58 | If the input encoding is not provided, then a buffer is expected. 59 | If no output encoding is given, then a buffer is returned. 60 | **/ 61 | @:overload(function(other_public_key:String, input_encoding:String, output_encoding:String):String {}) 62 | @:overload(function(other_public_key:String, input_encoding:String):Buffer {}) 63 | function computeSecret(other_public_key:Buffer):Buffer; 64 | 65 | /** 66 | Returns the EC Diffie-Hellman public key in the specified `encoding` and `format`. 67 | 68 | Format specifies point encoding and can be 'compressed', 'uncompressed', or 'hybrid'. 69 | If no format is provided - the point will be returned in 'uncompressed' format. 70 | 71 | Encoding can be 'binary', 'hex', or 'base64'. If no encoding is provided, then a buffer is returned. 72 | **/ 73 | function getPublicKey(?encoding:String, ?format:ECDHFormat):EitherType; 74 | 75 | /** 76 | Returns the EC Diffie-Hellman private key in the specified encoding, which can be 'binary', 'hex', or 'base64'. 77 | If no `encoding` is provided, then a buffer is returned. 78 | **/ 79 | @:overload(function():Buffer {}) 80 | function getPrivateKey(encoding:String):String; 81 | 82 | /** 83 | Sets the EC Diffie-Hellman public key. 84 | 85 | Key encoding can be 'binary', 'hex' or 'base64'. 86 | If no encoding is provided, then a buffer is expected. 87 | **/ 88 | @:overload(function(public_key:Buffer):Void {}) 89 | function setPublicKey(public_key:String, encoding:String):Void; 90 | 91 | /** 92 | Sets the EC Diffie-Hellman private key. 93 | 94 | Key encoding can be 'binary', 'hex' or 'base64'. 95 | If no encoding is provided, then a buffer is expected. 96 | **/ 97 | @:overload(function(private_key:Buffer):Void {}) 98 | function setPrivateKey(private_key:String, encoding:String):Void; 99 | } 100 | -------------------------------------------------------------------------------- /src/js/node/Https.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import js.node.http.ClientRequest; 26 | import js.node.http.IncomingMessage; 27 | import js.node.http.ServerResponse; 28 | import js.node.https.*; 29 | import js.node.url.URL; 30 | 31 | /** 32 | HTTPS is the HTTP protocol over TLS/SSL. 33 | In Node.js this is implemented as a separate module. 34 | **/ 35 | @:jsRequire("https") 36 | extern class Https { 37 | /** 38 | Returns a new HTTPS web server object. 39 | **/ 40 | #if haxe4 41 | @:overload(function(options:HttpsCreateServerOptions, ?requestListener:(request:IncomingMessage, response:ServerResponse) -> Void):Server {}) 42 | static function createServer(?requestListener:(request:IncomingMessage, response:ServerResponse) -> Void):Server; 43 | #else 44 | @:overload(function(options:HttpsCreateServerOptions, ?requestListener:IncomingMessage->ServerResponse->Void):Server {}) 45 | static function createServer(?requestListener:IncomingMessage->ServerResponse->Void):Server; 46 | #end 47 | 48 | /** 49 | Like `Http.get` but for HTTPS. 50 | 51 | `options` can be an object, a string, or a `URL` object. 52 | If `options` is a string, it is automatically parsed with `new URL()`. 53 | If it is a `URL` object, it will be automatically converted to an ordinary `options` object. 54 | **/ 55 | @:overload(function(url:URL, ?callback:IncomingMessage->Void):ClientRequest {}) 56 | @:overload(function(url:URL, options:HttpsRequestOptions, ?callback:IncomingMessage->Void):ClientRequest {}) 57 | @:overload(function(url:String, ?callback:IncomingMessage->Void):ClientRequest {}) 58 | @:overload(function(url:String, options:HttpsRequestOptions, ?callback:IncomingMessage->Void):ClientRequest {}) 59 | static function get(options:HttpsRequestOptions, ?callback:IncomingMessage->Void):ClientRequest; 60 | 61 | /** 62 | Global instance of `https.Agent` for all HTTPS client requests. 63 | **/ 64 | static var globalAgent:Agent; 65 | 66 | /** 67 | Makes a request to a secure web server. 68 | 69 | The following additional `options` from `tls.connect()` are also accepted: 70 | `ca`, `cert`, `ciphers`, `clientCertEngine`, `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`, `key`, `passphrase`, `pfx`, 71 | `rejectUnauthorized`, `secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`. 72 | 73 | `options` can be an object, a string, or a `URL` object. 74 | If `options` is a string, it is automatically parsed with `new URL()`. 75 | If it is a `URL` object, it will be automatically converted to an ordinary `options` object. 76 | **/ 77 | @:overload(function(url:URL, ?callback:IncomingMessage->Void):ClientRequest {}) 78 | @:overload(function(url:URL, options:HttpsRequestOptions, ?callback:IncomingMessage->Void):ClientRequest {}) 79 | @:overload(function(url:String, ?callback:IncomingMessage->Void):ClientRequest {}) 80 | @:overload(function(url:String, options:HttpsRequestOptions, ?callback:IncomingMessage->Void):ClientRequest {}) 81 | static function request(options:HttpsRequestOptions, ?callback:IncomingMessage->Void):ClientRequest; 82 | } 83 | 84 | typedef HttpsCreateServerOptions = { 85 | > js.node.Tls.TlsCreateServerOptions, 86 | > js.node.tls.SecureContext.SecureContextOptions, 87 | > js.node.Http.HttpCreateServerOptions, 88 | } 89 | 90 | typedef HttpsRequestOptions = { 91 | > js.node.Http.HttpRequestOptions, 92 | > js.node.Tls.TlsConnectOptions, 93 | // TODO: clean those options up 94 | } 95 | -------------------------------------------------------------------------------- /src/js/node/url/URL.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node.url; 24 | 25 | /** 26 | Browser-compatible URL class, implemented by following the WHATWG URL Standard. 27 | [Examples of parsed URLs](https://url.spec.whatwg.org/#example-url-parsing) may be found in the Standard itself. 28 | **/ 29 | @:jsRequire("url", "URL") 30 | extern class URL { 31 | /** 32 | Creates a new `URL` object by parsing the `input` relative to the `base`. 33 | If `base` is passed as a string, it will be parsed equivalent to `new URL(base)`. 34 | **/ 35 | @:overload(function(input:String, ?base:URL):Void {}) 36 | function new(input:String, ?base:String):Void; 37 | 38 | /** 39 | Gets and sets the fragment portion of the URL. 40 | **/ 41 | var hash:String; 42 | 43 | /** 44 | Gets and sets the host portion of the URL. 45 | **/ 46 | var host:String; 47 | 48 | /** 49 | Gets and sets the hostname portion of the URL 50 | The key difference between `url.host` and `url.hostname` is that `url.hostname` does not include the port. 51 | **/ 52 | var hostname:String; 53 | 54 | /** 55 | Gets and sets the serialized URL. 56 | **/ 57 | var href:String; 58 | 59 | /** 60 | Gets the read-only serialization of the URL's origin. 61 | **/ 62 | var origin(default, null):String; 63 | 64 | /** 65 | Gets and sets the password portion of the URL. 66 | **/ 67 | var password:String; 68 | 69 | /** 70 | Gets and sets the path portion of the URL. 71 | **/ 72 | var pathname:String; 73 | 74 | /** 75 | Gets and sets the port portion of the URL. 76 | 77 | The port value may be a number or a string containing a number in the range `0` to `65535` (inclusive). 78 | Setting the value to the default port of the `URL` objects given `protocol` will result in the port value becoming the empty string (`''`). 79 | **/ 80 | var port:String; 81 | 82 | /** 83 | Gets and sets the protocol portion of the URL. 84 | **/ 85 | var protocol:String; 86 | 87 | /** 88 | Gets and sets the serialized query portion of the URL. 89 | **/ 90 | var search:String; 91 | 92 | /** 93 | Gets the `URLSearchParams` object representing the query parameters of the URL. 94 | This property is read-only; to replace the entirety of query parameters of the URL, use the `url.search` setter. 95 | See [URLSearchParams](https://nodejs.org/api/url.html#url_class_urlsearchparams) documentation for details. 96 | **/ 97 | var searchParams(default, null):URLSearchParams; 98 | 99 | /** 100 | Gets and sets the username portion of the URL. 101 | **/ 102 | var username:String; 103 | 104 | /** 105 | The `toString()` method on the `URL` object returns the serialized URL. 106 | The value returned is equivalent to that of `url.href` and `url.toJSON()`. 107 | 108 | Because of the need for standard compliance, this method does not allow users to customize the serialization process of the URL. 109 | For more flexibility, `require('url').format()` method might be of interest. 110 | **/ 111 | function toString():String; 112 | 113 | /** 114 | The `toJSON()` method on the `URL` object returns the serialized URL. 115 | The value returned is equivalent to that of `url.href` and `url.toString()`. 116 | 117 | This method is automatically called when an `URL` object is serialized with `JSON.stringify()`. 118 | **/ 119 | function toJSON():String; 120 | } 121 | -------------------------------------------------------------------------------- /src/js/node/Module.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import js.node.url.URL; 26 | 27 | /** 28 | In each module, the `module` free variable is a reference to the object representing the current module. 29 | For convenience, `module.exports` is also accessible via the `exports` module-global. 30 | `module` is not actually a global but rather local to each module. 31 | 32 | @see https://nodejs.org/api/modules.html#modules_the_module_object 33 | **/ 34 | @:jsRequire("module") 35 | extern class Module { 36 | /** 37 | The module objects required for the first time by this one. 38 | 39 | @see https://nodejs.org/api/modules.html#modules_module_children 40 | **/ 41 | var children(default, null):Array; 42 | 43 | /** 44 | The `module.exports` object is created by the Module system. 45 | Sometimes this is not acceptable; many want their module to be an instance of some class. 46 | To do this, assign the desired export object to `module.exports`. 47 | Assigning the desired object to `exports` will simply rebind the local `exports` variable, which is probably not 48 | what is desired. 49 | 50 | @see https://nodejs.org/api/modules.html#modules_module_exports 51 | **/ 52 | var exports:Dynamic; 53 | 54 | /** 55 | The fully resolved filename of the module. 56 | 57 | @see https://nodejs.org/api/modules.html#modules_module_filename 58 | **/ 59 | var filename(default, null):String; 60 | 61 | /** 62 | The identifier for the module. 63 | Typically this is the fully resolved filename. 64 | 65 | @see https://nodejs.org/api/modules.html#modules_module_id 66 | **/ 67 | var id(default, null):String; 68 | 69 | /** 70 | Whether or not the module is done loading, or is in the process of loading. 71 | 72 | @see https://nodejs.org/api/modules.html#modules_module_loaded 73 | **/ 74 | var loaded(default, null):Bool; 75 | 76 | /** 77 | The module that first required this one. 78 | 79 | @see https://nodejs.org/api/modules.html#modules_module_parent 80 | **/ 81 | var parent(default, null):Module; 82 | 83 | /** 84 | The search paths for the module. 85 | 86 | @see https://nodejs.org/api/modules.html#modules_module_paths 87 | **/ 88 | var paths(default, null):Array; 89 | 90 | /** 91 | The `module.require()` method provides a way to load a module as if `require()` was called from the original 92 | module. 93 | 94 | @see https://nodejs.org/api/modules.html#modules_module_require_id 95 | **/ 96 | function require(id:String):Dynamic; 97 | 98 | /** 99 | A list of the names of all modules provided by Node.js. 100 | Can be used to verify if a module is maintained by a third party or not. 101 | 102 | @see https://nodejs.org/api/modules.html#modules_module_builtinmodules 103 | **/ 104 | static var builtinModules(default, null):Array; 105 | 106 | /** 107 | @see https://nodejs.org/api/modules.html#modules_module_createrequire_filename 108 | **/ 109 | @:overload(function(filename:URL):String->Dynamic {}) 110 | static function createRequire(filename:String):String->Dynamic; 111 | 112 | /** 113 | The `module.syncBuiltinESMExports()` method updates all the live bindings for builtin ES Modules to match the 114 | properties of the CommonJS exports. 115 | It does not add or remove exported names from the ES Modules. 116 | 117 | @see https://nodejs.org/api/modules.html#modules_module_syncbuiltinesmexports 118 | **/ 119 | static function syncBuiltinESMExports():Void; 120 | } 121 | -------------------------------------------------------------------------------- /src/Sys.hx: -------------------------------------------------------------------------------- 1 | import haxe.io.Bytes; 2 | import haxe.io.Eof; 3 | import haxe.io.Error; 4 | import haxe.io.Output; 5 | import js.Node.process; 6 | import js.node.Buffer; 7 | import js.node.ChildProcess; 8 | import js.node.Fs; 9 | 10 | @:dce 11 | @:coreApi 12 | class Sys { 13 | public static inline function print(v:Dynamic):Void { 14 | process.stdout.write(Std.string(v)); 15 | } 16 | 17 | public static inline function println(v:Dynamic):Void { 18 | process.stdout.write(Std.string(v)); 19 | process.stdout.write("\n"); 20 | } 21 | 22 | public static inline function args():Array { 23 | return process.argv.slice(2); 24 | } 25 | 26 | public static inline function getEnv(s:String):String { 27 | return process.env[s]; 28 | } 29 | 30 | public static inline function putEnv(s:String, v:Null):Void { 31 | if (v == null) 32 | process.env.remove(s); 33 | else 34 | process.env[s] = v; 35 | } 36 | 37 | public static function environment():Map { 38 | var m = new Map(); 39 | for (key in process.env.keys()) 40 | m[key] = process.env[key]; 41 | return m; 42 | } 43 | 44 | public inline static function setTimeLocale(loc:String):Bool { 45 | return false; 46 | } 47 | 48 | public inline static function getCwd():String { 49 | return haxe.io.Path.addTrailingSlash(process.cwd()); 50 | } 51 | 52 | public static inline function setCwd(s:String):Void { 53 | process.chdir(s); 54 | } 55 | 56 | public static function systemName():String { 57 | return switch (process.platform) { 58 | case "darwin": "Mac"; 59 | case "freebsd": "BSD"; 60 | case "linux": "Linux"; 61 | case "win32": "Windows"; 62 | case other: other; // throw? 63 | } 64 | } 65 | 66 | public static inline function command(cmd:String, ?args:Array):Int { 67 | if (args == null) 68 | return ChildProcess.spawnSync(cmd, {shell: true, stdio: "inherit"}).status; 69 | else 70 | return ChildProcess.spawnSync(cmd, args, {stdio: "inherit"}).status; 71 | } 72 | 73 | public static inline function exit(code:Int):Void { 74 | process.exit(code); 75 | } 76 | 77 | public static inline function time():Float { 78 | return (cast Date).now() / 1000; 79 | } 80 | 81 | public static inline function cpuTime():Float { 82 | return process.uptime(); 83 | } 84 | 85 | #if (haxe_ver >= 3.3) 86 | @:deprecated("Use programPath instead") 87 | #end 88 | public static inline function executablePath():String { 89 | return process.argv[0]; 90 | } 91 | 92 | #if (haxe_ver >= 3.3) 93 | public static inline function programPath():String { 94 | return js.Node.__filename; 95 | } 96 | #end 97 | 98 | public static function getChar(echo:Bool):Int { 99 | throw "Sys.getChar is currently not implemented on node.js"; 100 | } 101 | 102 | public static function sleep(seconds:Float):Void { 103 | var end = (cast Date).now() + seconds * 1000; 104 | while ((cast Date).now() <= end) {} 105 | } 106 | 107 | public static inline function stdin():haxe.io.Input { 108 | return new FileInput(0); 109 | } 110 | 111 | public static inline function stdout():haxe.io.Output { 112 | return new FileOutput(1); 113 | } 114 | 115 | public static inline function stderr():haxe.io.Output { 116 | return new FileOutput(2); 117 | } 118 | } 119 | 120 | private class FileOutput extends haxe.io.Output { 121 | var fd:Int; 122 | 123 | public function new(fd:Int) { 124 | this.fd = fd; 125 | } 126 | 127 | override public function writeByte(c:Int) { 128 | Fs.writeSync(fd, String.fromCharCode(c)); 129 | } 130 | 131 | override public function writeBytes(s:Bytes, pos:Int, len:Int):Int { 132 | return Fs.writeSync(fd, Buffer.hxFromBytes(s), pos, len); 133 | } 134 | 135 | override public function writeString(s:String #if (haxe_ver >= 4), ?encoding:haxe.io.Encoding #end) { 136 | Fs.writeSync(fd, s); 137 | } 138 | 139 | override public function flush() { 140 | Fs.fsyncSync(fd); 141 | } 142 | 143 | override public function close() { 144 | Fs.closeSync(fd); 145 | } 146 | } 147 | 148 | private class FileInput extends haxe.io.Input { 149 | var fd:Int; 150 | 151 | public function new(fd:Int) { 152 | this.fd = fd; 153 | } 154 | 155 | override public function readByte():Int { 156 | var buf = Buffer.alloc(1); 157 | try { 158 | Fs.readSync(fd, buf, 0, 1, null); 159 | } catch (e:Dynamic) { 160 | if (e.code == "EOF") 161 | throw new Eof(); 162 | else 163 | throw Error.Custom(e); 164 | } 165 | return buf[0]; 166 | } 167 | 168 | override public function readBytes(s:Bytes, pos:Int, len:Int):Int { 169 | var buf = Buffer.hxFromBytes(s); 170 | try { 171 | return Fs.readSync(fd, buf, pos, len, null); 172 | } catch (e:Dynamic) { 173 | if (e.code == "EOF") 174 | throw new Eof(); 175 | else 176 | throw Error.Custom(e); 177 | } 178 | } 179 | 180 | override public function close():Void { 181 | Fs.closeSync(fd); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/js/node/Require.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import haxe.DynamicAccess; 26 | 27 | @:native("require") 28 | extern class Require { 29 | /** 30 | Used to import modules, `JSON`, and local files. 31 | Modules can be imported from `node_modules`. 32 | Local modules and JSON files can be imported using a relative path (e.g. `./`, .`/foo`, `./bar/baz`, `../foo`) 33 | that will be resolved against the directory named by `__dirname` (if defined) or the current working directory. 34 | 35 | @see https://nodejs.org/api/modules.html#modules_module_id 36 | **/ 37 | @:selfCall 38 | static function require(id:String):Dynamic; 39 | 40 | /** 41 | Modules are cached in this object when they are required. 42 | By deleting a key value from this object, the next `require` will reload the module. 43 | This does not apply to native addons, for which reloading will result in an error. 44 | 45 | @see https://nodejs.org/api/modules.html#modules_require_cache 46 | **/ 47 | static var cache(default, null):DynamicAccess; 48 | 49 | /** 50 | Instruct require on how to handle certain file extensions. 51 | 52 | Deprecated: In the past, this list has been used to load non-JavaScript modules into Node by compiling them on-demand. 53 | However, in practice, there are much better ways to do this, such as loading modules via some other Node program, 54 | or compiling them to JavaScript ahead of time. 55 | 56 | Since the `Module` system is locked, this feature will probably never go away. However, it may have subtle bugs 57 | and complexities that are best left untouched. 58 | **/ 59 | @:deprecated 60 | static var extensions(default, null):DynamicAccess; 61 | 62 | /** 63 | The `Module` object representing the entry script loaded when the Node.js process launched. 64 | See ["Accessing the main module"](https://nodejs.org/api/modules.html#modules_accessing_the_main_module). 65 | 66 | @see https://nodejs.org/api/modules.html#modules_require_main 67 | **/ 68 | static var main(default, null):Module; 69 | 70 | /** 71 | Use the internal `require()` machinery to look up the location of a module, 72 | but rather than loading the module, just return the resolved filename. 73 | 74 | @see https://nodejs.org/api/modules.html#modules_require_resolve_request_options 75 | **/ 76 | static function resolve(module:String, ?options:RequireResolveOptions):String; 77 | } 78 | 79 | @:native("require.resolve") 80 | extern class RequireResolve { 81 | /** 82 | Use the internal `require()` machinery to look up the location of a module, 83 | but rather than loading the module, just return the resolved filename. 84 | 85 | @see https://nodejs.org/api/modules.html#modules_require_resolve_request_options 86 | **/ 87 | @:selfCall 88 | static function resolve(module:String, ?options:RequireResolveOptions):String; 89 | 90 | /** 91 | Returns an array containing the paths searched during resolution of `request` or `null` 92 | if the `request` string references a core module, for example `http` or `fs`. 93 | 94 | @see https://nodejs.org/api/modules.html#modules_require_resolve_paths_request 95 | **/ 96 | static function paths(request:String):Null>; 97 | } 98 | 99 | typedef RequireResolveOptions = { 100 | /** 101 | Paths to resolve module location from. 102 | If present, these paths are used instead of the default resolution paths, 103 | with the exception of `GLOBAL_FOLDERS` like $HOME/.node_modules, which are always included. 104 | Each of these paths is used as a starting point for the module resolution algorithm, 105 | meaning that the node_modules hierarchy is checked from this location. 106 | **/ 107 | @:optional var paths:Array; 108 | } 109 | -------------------------------------------------------------------------------- /src/js/node/Net.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import haxe.extern.EitherType; 26 | import js.node.net.Server; 27 | import js.node.net.Socket; 28 | 29 | typedef NetCreateServerOptions = { 30 | > SocketOptionsBase, 31 | 32 | /** 33 | If true, then the socket associated with each incoming connection will be paused, 34 | and no data will be read from its handle. 35 | 36 | This allows connections to be passed between processes without any data being read by the original process. 37 | To begin reading data from a paused socket, call `resume`. 38 | 39 | Default: false 40 | **/ 41 | @:optional var pauseOnConnect:Bool; 42 | } 43 | 44 | /** 45 | Options for the `Net.connect` method (TCP version). 46 | **/ 47 | typedef NetConnectOptionsTcp = { 48 | > SocketOptions, 49 | > SocketConnectOptionsTcp, 50 | } 51 | 52 | /** 53 | Options for the `Net.connect` method (Local domain socket version). 54 | **/ 55 | typedef NetConnectOptionsUnix = { 56 | > SocketOptions, 57 | > SocketConnectOptionsUnix, 58 | } 59 | 60 | /** 61 | Enumeration of possible values for `Net.isIP` return. 62 | **/ 63 | enum abstract NetIsIPResult(Int) to Int { 64 | var Invalid = 0; 65 | var IPv4 = 4; 66 | var IPv6 = 6; 67 | } 68 | 69 | /** 70 | The net module provides you with an asynchronous network wrapper. 71 | It contains methods for creating both servers and clients (called streams). 72 | **/ 73 | @:jsRequire("net") 74 | extern class Net { 75 | /** 76 | Creates a new TCP server. 77 | 78 | The `connectionListener` argument is automatically set as a listener for the 'connection' event. 79 | **/ 80 | @:overload(function(options:NetCreateServerOptions, ?connectionListener:Socket->Void):Server {}) 81 | static function createServer(?connectionListener:Socket->Void):Server; 82 | 83 | /** 84 | A factory function, which returns a new `Socket` and automatically connects with the supplied `options`. 85 | 86 | The `options` are passed to both the `Socket` constructor and the `socket.connect` method. 87 | 88 | The `connectListener` parameter will be added as a listener for the `connect` event once. 89 | 90 | If `port` is provided, creates a TCP connection to `port` on `host`. 91 | If `host` is omitted, 'localhost' will be assumed. 92 | 93 | If `path` is provided, creates unix socket connection to `path`. 94 | 95 | Otherwise `options` argument should be provided. 96 | **/ 97 | @:overload(function(path:String, ?connectListener:Void->Void):Socket {}) 98 | @:overload(function(port:Int, ?connectListener:Void->Void):Socket {}) 99 | @:overload(function(port:Int, host:String, ?connectListener:Void->Void):Socket {}) 100 | static function connect(options:EitherType, ?connectListener:Void->Void):Socket; 101 | 102 | /** 103 | Same as `connect`. 104 | **/ 105 | @:overload(function(path:String, ?connectListener:Void->Void):Socket {}) 106 | @:overload(function(port:Int, ?connectListener:Void->Void):Socket {}) 107 | @:overload(function(port:Int, host:String, ?connectListener:Void->Void):Socket {}) 108 | static function createConnection(options:EitherType, ?connectListener:Void->Void):Socket; 109 | 110 | /** 111 | Tests if input is an IP address. 112 | Returns 0 for invalid strings, returns 4 for IP version 4 addresses, and returns 6 for IP version 6 addresses. 113 | **/ 114 | static function isIP(input:String):NetIsIPResult; 115 | 116 | /** 117 | Returns true if input is a version 4 IP address, otherwise returns false. 118 | **/ 119 | static function isIPv4(input:String):Bool; 120 | 121 | /** 122 | Returns true if input is a version 6 IP address, otherwise returns false. 123 | **/ 124 | static function isIPv6(input:String):Bool; 125 | } 126 | -------------------------------------------------------------------------------- /src/js/node/Vm.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2014-2020 Haxe Foundation 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | package js.node; 24 | 25 | import js.node.vm.Script; 26 | 27 | /** 28 | Options object used by Vm.run* methods. 29 | **/ 30 | typedef VmRunOptions = { 31 | > ScriptOptions, 32 | > ScriptRunOptions, 33 | } 34 | 35 | /** 36 | Using this class JavaScript code can be compiled and 37 | run immediately or compiled, saved, and run later. 38 | **/ 39 | @:jsRequire("vm") 40 | extern class Vm { 41 | /** 42 | Compiles `code`, runs it and returns the result. 43 | Running code does not have access to local scope. 44 | 45 | `filename` is optional, it's used only in stack traces. 46 | 47 | In case of syntax error in `code` emits the syntax error to stderr and throws an exception. 48 | **/ 49 | static function runInThisContext(code:String, ?options:VmRunOptions):Dynamic; 50 | 51 | /** 52 | Compiles `code`, contextifies `sandbox` if passed or creates a new contextified sandbox if it's omitted, 53 | and then runs the code with the sandbox as the global object and returns the result. 54 | 55 | `runInNewContext` takes the same options as `runInThisContext`. 56 | 57 | Note that running untrusted code is a tricky business requiring great care. `runInNewContext` is quite useful, 58 | but safely running untrusted code requires a separate process. 59 | **/ 60 | @:overload(function(code:String, ?sandbox:{}):Dynamic {}) 61 | static function runInNewContext(code:String, sandbox:{}, ?options:VmRunOptions):Dynamic; 62 | 63 | /** 64 | Compiles `code`, then runs it in `contextifiedSandbox` and returns the result. 65 | 66 | Running code does not have access to local scope. The `contextifiedSandbox` object must have been previously 67 | contextified via `createContext`; it will be used as the global object for code. 68 | 69 | `runInContext` takes the same options as `runInThisContext`. 70 | 71 | Note that running untrusted code is a tricky business requiring great care. `runInContext` is quite useful, 72 | but safely running untrusted code requires a separate process. 73 | **/ 74 | static function runInContext(code:String, contextifiedSandbox:VmContext, ?options:VmRunOptions):Dynamic; 75 | 76 | /** 77 | 78 | If given a sandbox object, will "contextify" that sandbox so that it can be used in calls to `runInContext` or 79 | `Script.runInContext`. Inside scripts run as such, sandbox will be the global object, retaining all its existing 80 | properties but also having the built-in objects and functions any standard global object has. Outside of scripts 81 | run by the vm module, sandbox will be unchanged. 82 | 83 | If not given a sandbox object, returns a new, empty contextified sandbox object you can use. 84 | 85 | This function is useful for creating a sandbox that can be used to run multiple scripts, e.g. if you were 86 | emulating a web browser it could be used to create a single sandbox representing a window's global object, 87 | then run all