diff --git a/.gitignore b/.gitignore index d1eeb6c..09ad5bc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .merlin .bsb.lock npm-debug.log -/lib/bs +/lib/ /node_modules/ bsb package-lock.json diff --git a/README.md b/README.md index 6393928..c159ef4 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ or yarn add rescript-nodejs ``` -Then add rescript-nodejs to `bsconfig.json`: +Then add rescript-nodejs to `rescript.json`: ``` - "bs-dependencies": [ + "dependencies": [ "rescript-nodejs" ], ``` @@ -40,7 +40,7 @@ Help all ReScript Node.js apps and libraries to be built faster by reducing the ## Principles -- When available, prefer binding to the promise version of the library instead of the callback version to reduce binding surface. `Js.Promise2` is the new improved API. +- When available, prefer binding to the promise version of the library instead of the callback version to reduce binding surface. - Use subtyping only where the benefit is substantial. Subtyping is used for various APIs that implement Node Streams, such as HTTP Request and Response, FileSystem streams, Crypto streams, and etc. This provides a single set of functions to manipulate and combine streams across different modules. For example: ### Stream a file into stdout: @@ -50,7 +50,7 @@ open NodeJs Fs.createReadStream("/path") ->Stream.pipe(Process.stdout(Process.process)) - ->Stream.onError(_ => Js.log("handleError")) + ->Stream.onError(_ => Console.log("handleError")) ``` ### Echo server: @@ -59,7 +59,7 @@ Fs.createReadStream("/path") open NodeJs Http.createServer((request, response) => { - request->Stream.onData(data => Js.log(data)) + request->Stream.onData(data => Console.log(data)) request->Stream.pipe(response)->ignore }); ``` diff --git a/examples/ReadFileByLine.res b/examples/ReadFileByLine.res index 2420731..0212c86 100644 --- a/examples/ReadFileByLine.res +++ b/examples/ReadFileByLine.res @@ -5,6 +5,6 @@ let rl = Readline.make({input: Fs.createReadStream("sample.txt"), crlfDelay: inf rl ->Readline.Interface.on(Event.fromString("line"), line => { - Js.log(`Received: ${line}`) + Stdlib.Console.log(`Received: ${line}`) }) ->ignore diff --git a/examples/ReadFileByLine.res.js b/examples/ReadFileByLine.res.js new file mode 100644 index 0000000..517f701 --- /dev/null +++ b/examples/ReadFileByLine.res.js @@ -0,0 +1,18 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Nodefs = require("node:fs"); +let Pervasives = require("@rescript/runtime/lib/js/Pervasives.js"); +let Nodereadline = require("node:readline"); + +let rl = Nodereadline.createInterface({ + input: Nodefs.createReadStream("sample.txt"), + crlfDelay: Pervasives.infinity +}); + +rl.on("line", line => { + console.log(`Received: ` + line); +}); + +exports.rl = rl; +/* rl Not a pure module */ diff --git a/examples/StreamTextToFile.res b/examples/StreamTextToFile.res index ea67f60..cd11beb 100644 --- a/examples/StreamTextToFile.res +++ b/examples/StreamTextToFile.res @@ -7,19 +7,15 @@ let outputPath = Path.relative(~from=Process.cwd(process), ~to_="example__output let writeStream = Fs.createWriteStream(outputPath) let logErrorIfExists = maybeError => - switch Js.Nullable.toOption(maybeError) { - | Some(err) => Js.log2("An error occurred", err) + switch Nullable.toOption(maybeError) { + | Some(err) => Stdlib.Console.log2("An error occurred", err) | None => () } let () = writeStream - ->Stream.writeWith( - data, - ~callback=maybeError => { - logErrorIfExists(maybeError) - Js.log("Finished") - }, - (), - ) + ->Stream.writeWith(data, ~callback=maybeError => { + logErrorIfExists(maybeError) + Stdlib.Console.log("Finished") + }) ->ignore diff --git a/examples/StreamTextToFile.res.js b/examples/StreamTextToFile.res.js new file mode 100644 index 0000000..e94f083 --- /dev/null +++ b/examples/StreamTextToFile.res.js @@ -0,0 +1,33 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Nodefs = require("node:fs"); +let Process = require("process"); +let Nodepath = require("node:path"); + +let data = Buffer.from("Sample text to write to a file!"); + +let process = Process; + +let outputPath = Nodepath.relative(process.cwd(), "example__output.txt"); + +let writeStream = Nodefs.createWriteStream(outputPath); + +function logErrorIfExists(maybeError) { + if (!(maybeError == null)) { + console.log("An error occurred", maybeError); + return; + } +} + +writeStream.write(data, maybeError => { + logErrorIfExists(maybeError); + console.log("Finished"); +}); + +exports.data = data; +exports.process = process; +exports.outputPath = outputPath; +exports.writeStream = writeStream; +exports.logErrorIfExists = logErrorIfExists; +/* data Not a pure module */ diff --git a/lib/js/examples/ReadFileByLine.bs.js b/lib/js/examples/ReadFileByLine.bs.js deleted file mode 100644 index 7509e68..0000000 --- a/lib/js/examples/ReadFileByLine.bs.js +++ /dev/null @@ -1,18 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Nodefs = require("node:fs"); -var PervasivesU = require("rescript/lib/js/pervasivesU.js"); -var Nodereadline = require("node:readline"); - -var rl = Nodereadline.createInterface({ - input: Nodefs.createReadStream("sample.txt"), - crlfDelay: PervasivesU.infinity - }); - -rl.on("line", (function (line) { - console.log("Received: " + line); - })); - -exports.rl = rl; -/* rl Not a pure module */ diff --git a/lib/js/examples/StreamTextToFile.bs.js b/lib/js/examples/StreamTextToFile.bs.js deleted file mode 100644 index 461a983..0000000 --- a/lib/js/examples/StreamTextToFile.bs.js +++ /dev/null @@ -1,34 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Nodefs = require("node:fs"); -var Process = require("process"); -var Nodepath = require("node:path"); - -var data = Buffer.from("Sample text to write to a file!"); - -var $$process = Process; - -var outputPath = Nodepath.relative($$process.cwd(), "example__output.txt"); - -var writeStream = Nodefs.createWriteStream(outputPath); - -function logErrorIfExists(maybeError) { - if (!(maybeError == null)) { - console.log("An error occurred", maybeError); - return ; - } - -} - -writeStream.write(data, (function (maybeError) { - logErrorIfExists(maybeError); - console.log("Finished"); - })); - -exports.data = data; -exports.$$process = $$process; -exports.outputPath = outputPath; -exports.writeStream = writeStream; -exports.logErrorIfExists = logErrorIfExists; -/* data Not a pure module */ diff --git a/lib/js/src/BigInt.bs.js b/lib/js/src/BigInt.bs.js deleted file mode 100644 index 6a2db67..0000000 --- a/lib/js/src/BigInt.bs.js +++ /dev/null @@ -1,33 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -var _NEGATIVE_ONE = BigInt(-1); - -function mod(prim0, prim1) { - return prim0 % prim1; -} - -var $star$star = (function (a, b) { return (a ** b); }); - -function lnot(x) { - return x ^ _NEGATIVE_ONE; -} - -function modulo(prim0, prim1) { - return prim0 % prim1; -} - -function logicalNot(x) { - return x ^ _NEGATIVE_ONE; -} - -var power = $star$star; - -exports.mod = mod; -exports.$star$star = $star$star; -exports.lnot = lnot; -exports.modulo = modulo; -exports.power = power; -exports.logicalNot = logicalNot; -/* _NEGATIVE_ONE Not a pure module */ diff --git a/lib/js/src/Cluster.bs.js b/lib/js/src/Cluster.bs.js deleted file mode 100644 index bf3ec5a..0000000 --- a/lib/js/src/Cluster.bs.js +++ /dev/null @@ -1,105 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Js_dict = require("rescript/lib/js/js_dict.js"); -var Disconnect = require("disconnect"); -var Nodecluster = require("node:cluster"); -var Js_null_undefined = require("rescript/lib/js/js_null_undefined.js"); - -function classify(x) { - var addressType = x.addressType; - var intOrString = typeof addressType; - switch (intOrString) { - case "number" : - switch (addressType) { - case -1 : - return { - TAG: "UnixDomainSocket", - _0: x - }; - case 4 : - return { - TAG: "TcpV4", - _0: x - }; - case 6 : - return { - TAG: "TcpV6", - _0: x - }; - default: - return { - TAG: "Unknown", - _0: x - }; - } - case "string" : - switch (addressType) { - case "udp4" : - return { - TAG: "Udp4", - _0: x - }; - case "udp6" : - return { - TAG: "Udp6", - _0: x - }; - default: - return { - TAG: "Unknown", - _0: x - }; - } - default: - return { - TAG: "Unknown", - _0: x - }; - } -} - -var Address = { - classify: classify -}; - -var Message = {}; - -var Events = {}; - -function sendHttpServerHandle(options, msg, handle) { - msg.send(handle, Js_null_undefined.fromOption(options)); -} - -function sendSocketHandle(options, msg, handle) { - msg.send(handle, Js_null_undefined.fromOption(options)); -} - -var $$Worker = { - Events: Events, - sendHttpServerHandle: sendHttpServerHandle, - sendSocketHandle: sendSocketHandle -}; - -function disconnect(callback, param) { - Disconnect(Js_null_undefined.fromOption(callback)); -} - -function fork(env, param) { - return Nodecluster.fork(env); -} - -var decodeSchedulingPolicy = Nodecluster.schedulingPolicy === Nodecluster.SCHED_RR ? "SCHED_RR" : "SCHED_NONE"; - -function getWorker(_workers, id) { - return Js_dict.get(_workers, id.toString()); -} - -exports.Address = Address; -exports.Message = Message; -exports.$$Worker = $$Worker; -exports.disconnect = disconnect; -exports.fork = fork; -exports.decodeSchedulingPolicy = decodeSchedulingPolicy; -exports.getWorker = getWorker; -/* decodeSchedulingPolicy Not a pure module */ diff --git a/lib/js/src/Event.bs.js b/lib/js/src/Event.bs.js deleted file mode 100644 index 1007561..0000000 --- a/lib/js/src/Event.bs.js +++ /dev/null @@ -1,46 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function classify(evt) { - var match = typeof evt; - switch (match) { - case "string" : - return { - TAG: "String", - _0: evt - }; - case "symbol" : - return { - TAG: "Symbol", - _0: evt - }; - default: - return "Unknown"; - } -} - -function eq(event1, event2) { - var match = typeof event1; - var match$1 = typeof event2; - switch (match) { - case "string" : - if (match$1 === "string") { - return event1 === event2; - } else { - return false; - } - case "symbol" : - if (match$1 === "symbol") { - return event1 === event2; - } else { - return false; - } - default: - return false; - } -} - -exports.classify = classify; -exports.eq = eq; -/* No side effect */ diff --git a/lib/js/src/PerfHooks.bs.js b/lib/js/src/PerfHooks.bs.js deleted file mode 100644 index ffc8355..0000000 --- a/lib/js/src/PerfHooks.bs.js +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Nodeperf_hooks = require("node:perf_hooks"); -var Js_null_undefined = require("rescript/lib/js/js_null_undefined.js"); - -var $$PerformanceEntry = {}; - -var PerformanceNodeTiming = {}; - -var $$Performance = {}; - -var Histogram = {}; - -function getEntriesByName(entryList, type_, name) { - return entryList.getEntriesByName(name, Js_null_undefined.fromOption(type_)); -} - -var $$PerformanceObserverEntryList = { - getEntriesByName: getEntriesByName -}; - -var $$PerformanceObserver = {}; - -function monitorEventLoopDelay(resolution, param) { - return Nodeperf_hooks.eventLoopDelay(Js_null_undefined.fromOption(resolution)); -} - -exports.$$PerformanceEntry = $$PerformanceEntry; -exports.PerformanceNodeTiming = PerformanceNodeTiming; -exports.$$Performance = $$Performance; -exports.Histogram = Histogram; -exports.$$PerformanceObserverEntryList = $$PerformanceObserverEntryList; -exports.$$PerformanceObserver = $$PerformanceObserver; -exports.monitorEventLoopDelay = monitorEventLoopDelay; -/* node:perf_hooks Not a pure module */ diff --git a/lib/js/src/StringBuffer.bs.js b/lib/js/src/StringBuffer.bs.js deleted file mode 100644 index 36c8080..0000000 --- a/lib/js/src/StringBuffer.bs.js +++ /dev/null @@ -1,66 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var PervasivesU = require("rescript/lib/js/pervasivesU.js"); - -function classifyOpt(value) { - if (typeof value === "string") { - return { - TAG: "String", - _0: value - }; - } else if (Buffer.isBuffer(value)) { - return { - TAG: "Buffer", - _0: value - }; - } else { - return ; - } -} - -function classifyExn(value) { - if (typeof value === "string") { - return { - TAG: "String", - _0: value - }; - } else if (Buffer.isBuffer(value)) { - return { - TAG: "Buffer", - _0: value - }; - } else { - return PervasivesU.failwith("Unknown data type"); - } -} - -function classify(value) { - if (typeof value === "string") { - return { - TAG: "Ok", - _0: { - TAG: "String", - _0: value - } - }; - } else if (Buffer.isBuffer(value)) { - return { - TAG: "Ok", - _0: { - TAG: "Buffer", - _0: value - } - }; - } else { - return { - TAG: "Error", - _0: value - }; - } -} - -exports.classifyOpt = classifyOpt; -exports.classifyExn = classifyExn; -exports.classify = classify; -/* No side effect */ diff --git a/lib/js/src/Url.bs.js b/lib/js/src/Url.bs.js deleted file mode 100644 index 1d9802d..0000000 --- a/lib/js/src/Url.bs.js +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Nodeurl = require("node:url"); -var Js_null_undefined = require("rescript/lib/js/js_null_undefined.js"); - -var SearchParams = {}; - -function format(auth, fragment, search, unicode, url) { - return Nodeurl.format(url, { - auth: Js_null_undefined.fromOption(auth), - fragment: Js_null_undefined.fromOption(fragment), - search: Js_null_undefined.fromOption(search), - unicode: Js_null_undefined.fromOption(unicode) - }); -} - -exports.SearchParams = SearchParams; -exports.format = format; -/* node:url Not a pure module */ diff --git a/lib/js/test/atomic/BigInt.test.bs.js b/lib/js/test/atomic/BigInt.test.bs.js deleted file mode 100644 index 7f3f4d3..0000000 --- a/lib/js/test/atomic/BigInt.test.bs.js +++ /dev/null @@ -1,171 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Random = require("rescript/lib/js/random.js"); -var Belt_Array = require("rescript/lib/js/belt_Array.js"); -var Caml_int32 = require("rescript/lib/js/caml_int32.js"); -var PervasivesU = require("rescript/lib/js/pervasivesU.js"); -var BigInt$NodeJs = require("../../src/BigInt.bs.js"); - -Zora.test("BigInt", (function (t) { - Random.init(84611); - t.test("'BigInt.fromInt' and 'BigInt.toInt' are associative operations for all 32-bit integers", (function (t) { - var arrA = Belt_Array.makeByU(1000, (function (param) { - return Random.$$int(1000000); - })); - var arrB = Belt_Array.map(arrA, (function (prim) { - return BigInt(prim); - })); - var arrC = Belt_Array.map(arrB, (function (prim) { - return Number(prim); - })); - t.equal(arrA, arrC, ""); - })); - t.test("BigInt.add", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a + b | 0; - t.equal(BigInt(a) + BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(+)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a + b | 0; - t.equal(BigInt(a) + BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.subtract", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a - b | 0; - t.equal(BigInt(a) - BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(-)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a - b | 0; - t.equal(BigInt(a) - BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.multiply", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = Math.imul(a, b); - t.equal(BigInt(a) * BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(*)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = Math.imul(a, b); - t.equal(BigInt(a) * BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.divide", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = Caml_int32.div(a, b); - t.equal(BigInt(a) / BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(/)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = Caml_int32.div(a, b); - t.equal(BigInt(a) / BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.negate", (function (t) { - var a = Random.$$int(400); - var b = -a | 0; - t.equal(- BigInt(a), BigInt(b), ""); - })); - t.test("BigInt.(~-)", (function (t) { - var a = Random.$$int(400); - var b = -a | 0; - t.equal(- BigInt(a), BigInt(b), ""); - })); - t.test("BigInt.modulo", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = Caml_int32.mod_(a, b); - t.equal(BigInt$NodeJs.modulo(BigInt(a), BigInt(b)), BigInt(c), ""); - })); - t.test("BigInt.(mod)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = Caml_int32.mod_(a, b); - t.equal(BigInt$NodeJs.mod(BigInt(a), BigInt(b)), BigInt(c), ""); - })); - t.test("BigInt.power", (function (t) { - var a = Random.$$int(6); - var b = Random.$$int(8); - var c = Math.pow(a, b); - t.equal(BigInt$NodeJs.power(BigInt(a), BigInt(b)), BigInt(c), ""); - })); - t.test("BigInt.(**)", (function (t) { - var a = Random.$$int(6); - var b = Random.$$int(8); - var c = Math.pow(a, b); - t.equal(BigInt$NodeJs.$star$star(BigInt(a), BigInt(b)), BigInt(c), ""); - })); - t.test("BigInt.logicalAnd", (function (t) { - var a = Random.$$int(256); - var b = Random.$$int(256); - var c = a & b; - t.equal(BigInt(a) & BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(land)", (function (t) { - var a = Random.$$int(256); - var b = Random.$$int(256); - var c = a & b; - t.equal(BigInt(a) & BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.logicalOr", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a | b; - t.equal(BigInt(a) | BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(lor)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a | b; - t.equal(BigInt(a) | BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.logicalXor", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a ^ b; - t.equal(BigInt(a) ^ BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.(lxor)", (function (t) { - var a = Random.$$int(400); - var b = Random.$$int(400); - var c = a ^ b; - t.equal(BigInt(a) ^ BigInt(b), BigInt(c), ""); - })); - t.test("BigInt.logicalNot", (function (t) { - var a = Random.$$int(400); - var b = PervasivesU.lnot(a); - t.equal(BigInt$NodeJs.logicalNot(BigInt(a)), BigInt(b), ""); - })); - t.test("BigInt.(lnot)", (function (t) { - var a = Random.$$int(400); - var b = PervasivesU.lnot(a); - t.equal(BigInt$NodeJs.lnot(BigInt(a)), BigInt(b), ""); - })); - t.test("BigInt.logicalShiftLeft", (function (t) { - var c = 3328; - t.equal((BigInt(26) << BigInt(7)), BigInt(c), ""); - })); - t.test("BigInt.(lsl)", (function (t) { - var c = 3328; - t.equal((BigInt(26) << BigInt(7)), BigInt(c), ""); - })); - t.test("BigInt.arithmeticShiftRight", (function (t) { - var c = 2; - t.equal((BigInt(32) >> BigInt(4)), BigInt(c), ""); - })); - t.test("BigInt.(asr)", (function (t) { - var c = 2; - t.equal((BigInt(32) >> BigInt(4)), BigInt(c), ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/BinaryLike.test.bs.js b/lib/js/test/atomic/BinaryLike.test.bs.js deleted file mode 100644 index 2375dd2..0000000 --- a/lib/js/test/atomic/BinaryLike.test.bs.js +++ /dev/null @@ -1,95 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var BinaryLike$NodeJs = require("../../src/BinaryLike.bs.js"); - -Zora.test("BinaryLike", (function (t) { - var binaryLikeString = BinaryLike$NodeJs.string("test1234"); - var buffer_ = Buffer.from([ - 1, - 2, - 3, - 4 - ]); - var binaryLikeBuffer = BinaryLike$NodeJs.buffer(buffer_); - var uInt8Array = new Uint8Array([ - 1, - 2, - 3, - 4 - ]); - var binaryLikeUint8Array = BinaryLike$NodeJs.uInt8Array(uInt8Array); - var int8Array = new Int8Array([ - 1, - 2, - 3, - 4 - ]); - var binaryLikeInt8Array = BinaryLike$NodeJs.int8Array(int8Array); - var uInt8ClampedArray = new Uint8ClampedArray([ - 1, - 2, - 3, - 4 - ]); - var binaryLikeUint8ClampedArray = BinaryLike$NodeJs.uInt8ClampedArray(uInt8ClampedArray); - var uInt16Array = new Uint16Array([ - 1, - 2, - 3, - 4 - ]); - var binaryLikeUint16Array = BinaryLike$NodeJs.uInt16Array(uInt16Array); - var int16Array = new Int16Array([ - 1, - 2, - 3, - 4 - ]); - var binaryLikeInt16Array = BinaryLike$NodeJs.int16Array(int16Array); - t.test("BinaryLike.classify(string) should return a 'String' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeString); - var tmp; - tmp = match.TAG === "String" ? true : false; - t.ok(tmp, ""); - })); - t.test("BinaryLike.classify(buffer) should return a 'Buffer' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeBuffer); - var tmp; - tmp = match.TAG === "Buffer" ? true : false; - t.ok(tmp, ""); - })); - t.test("BinaryLike.classify(uInt8Array) should return a 'Uint8Array' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeUint8Array); - var tmp; - tmp = match.TAG === "Uint8Array" ? true : false; - t.ok(tmp, ""); - })); - t.test("BinaryLike.classify(int8Array) should return a 'Int8Array' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeInt8Array); - var tmp; - tmp = match.TAG === "Int8Array" ? true : false; - t.ok(tmp, ""); - })); - t.test("BinaryLike.classify(uInt8ClampedArray) should return a 'Uint8ClampedArray' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeUint8ClampedArray); - var tmp; - tmp = match.TAG === "Uint8ClampedArray" ? true : false; - t.ok(tmp, ""); - })); - t.test("BinaryLike.classify(uInt16Array) should return a 'Uint16Array' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeUint16Array); - var tmp; - tmp = match.TAG === "Uint16Array" ? true : false; - t.ok(tmp, ""); - })); - t.test("BinaryLike.classify(int16Array) should return a 'Int16Array' variant", (function (t) { - var match = BinaryLike$NodeJs.classify(binaryLikeInt16Array); - var tmp; - tmp = match.TAG === "Int16Array" ? true : false; - t.ok(tmp, ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Console.test.bs.js b/lib/js/test/atomic/Console.test.bs.js deleted file mode 100644 index c636d97..0000000 --- a/lib/js/test/atomic/Console.test.bs.js +++ /dev/null @@ -1,50 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Process = require("process"); -var Caml_option = require("rescript/lib/js/caml_option.js"); -var Nodeconsole = require("node:console"); - -var $$process = Process; - -Zora.test("Console", (function (t) { - var c1 = new Nodeconsole.Console({ - stdout: $$process.stdout, - stderr: Caml_option.some($$process.stderr), - ignoreErrors: false, - colorMode: true, - inspectOptions: {} - }); - var c2 = new Nodeconsole.Console({ - stderr: $$process.stderr, - ignoreErrors: false, - colorMode: true, - stdout: $$process.stdout - }); - console.log("=== Testing console output styles ==="); - c1.log("a", "b"); - c2.table([ - "hi", - "bye" - ]); - c2.table([{ - a: 1, - b: 2 - }]); - console.dir({ - hello: "world", - this: "is", - an: "object" - }); - console.log("=== END testing console output styles ==="); - t.test("New console instance should be defined", (function (t) { - t.notEqual(c1, undefined, ""); - })); - t.test("New console instance should be defined", (function (t) { - t.notEqual(c2, undefined, ""); - })); - })); - -exports.$$process = $$process; -/* process Not a pure module */ diff --git a/lib/js/test/atomic/EventEmitter.test.bs.js b/lib/js/test/atomic/EventEmitter.test.bs.js deleted file mode 100644 index f5aecf0..0000000 --- a/lib/js/test/atomic/EventEmitter.test.bs.js +++ /dev/null @@ -1,86 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Nodeassert = require("node:assert"); -var Nodeevents = require("node:events"); -var EventEmitterTestLib$NodeJs = require("../module/EventEmitterTestLib.bs.js"); - -Zora.test("EventEmitter", (function (t) { - t.notEqual(new Nodeevents.EventEmitter(), undefined, "'Emitter.make' should create a new emitter instance that is defined"); - t.equal(new Nodeevents.EventEmitter().addListener(EventEmitterTestLib$NodeJs.Emitter1.Events.text, (function (param) { - - })).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 1, "'Emitter.addListener' should add a new event listener"); - t.equal(new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, (function (param) { - - })).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 1, "'Emitter.on' should add a new event listener"); - t.equal(new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, (function (param) { - - })).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 1, "'Emitter.on' should add a new event listener"); - t.test("'Emitter.removeListener' should remove the event listener", (function (t) { - var eventListener = function (param) { - - }; - var listeners = (function (__x) { - return __x.listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text); - })((function (__x) { - return __x.removeListener(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })((function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })(new Nodeevents.EventEmitter()))); - t.equal(listeners.length, 0, ""); - })); - t.test("'Emitter.off' should remove the event listener", (function (t) { - var eventListener = function (param) { - - }; - var listeners = (function (__x) { - return __x.listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text); - })((function (__x) { - return __x.off(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })((function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })(new Nodeevents.EventEmitter()))); - t.equal(listeners.length, 0, ""); - })); - t.test("'Emitter.emit' should execute each listener for the correct event", (function (t) { - var ref1 = { - contents: 0 - }; - var ref2 = { - contents: 0 - }; - var listener1 = function (param) { - ref1.contents = 1; - }; - var listener2 = function (param) { - ref2.contents = 2; - }; - var emitter = (function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, listener2); - })((function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, listener1); - })(new Nodeevents.EventEmitter())); - emitter.emit(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, 1); - emitter.emit(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, 2); - t.equal(ref1.contents, 1, ""); - t.equal(ref2.contents, 2, ""); - })); - t.test("'Emitter.removeAllListeners' should remove all event listeners", (function (t) { - var eventListener = function (param) { - - }; - var emitter = (function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })((function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })((function (__x) { - return __x.on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); - })(new Nodeevents.EventEmitter()))); - Nodeassert.strictEqual(emitter.listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 3); - emitter.removeAllListeners(); - t.equal(emitter.listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 0, ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Fs.test.bs.js b/lib/js/test/atomic/Fs.test.bs.js deleted file mode 100644 index 463ccad..0000000 --- a/lib/js/test/atomic/Fs.test.bs.js +++ /dev/null @@ -1,25 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Nodefs = require("node:fs"); -var Js_string = require("rescript/lib/js/js_string.js"); - -Zora.test("Fs", (async function (t) { - t.test("readFile should read entire file", (async function (t) { - var fh = await Nodefs.promises.open(__filename, "r"); - var buffer = await fh.readFile(); - await fh.close(); - t.ok(buffer.indexOf("Random string: Gh2e71pdHhPxU") > 1, "buffer index was not greater than zero"); - })); - t.test("readFileWith should read entire file as a string", (async function (t) { - var fh = await Nodefs.promises.open(__filename, "r"); - var buffer = await fh.readFile({ - encoding: "UTF-8" - }); - await fh.close(); - t.ok(Js_string.indexOf("Random string: uCF6c5f3Arrq", buffer) > 0, "buffer string indexOf was not greater than zero"); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Global.test.bs.js b/lib/js/test/atomic/Global.test.bs.js deleted file mode 100644 index bffa79a..0000000 --- a/lib/js/test/atomic/Global.test.bs.js +++ /dev/null @@ -1,43 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); - -Zora.test("Global", (function (t) { - t.test("dirname should be defined", (function (t) { - t.notEqual(__dirname, undefined, ""); - })); - t.test("dirname should be of type 'string'", (function (t) { - t.equal(typeof __dirname, "string", ""); - })); - t.test("filename should be defined", (function (t) { - t.notEqual(__filename, undefined, ""); - })); - t.test("filename should be of type 'string'", (function (t) { - t.equal(typeof __filename, "string", ""); - })); - t.test("'global object' should be defined", (function (t) { - t.notEqual(global, undefined, ""); - })); - t.test("'global' object should be of type 'object'", (function (t) { - t.equal(typeof global, "object", ""); - })); - t.test("'require' function should be defined", (function (t) { - t.notEqual((function (prim) { - return require(prim); - }), undefined, ""); - })); - t.test("'require' function should be defined", (function (t) { - t.equal(typeof (function (prim) { - return require(prim); - }), "function", ""); - })); - t.test("'require' fuction should return a defined value from a relative path", (function (t) { - t.notEqual(require("path"), undefined, ""); - })); - t.test("'require' fuction should successfully import a module object from a relative path", (function (t) { - t.equal(typeof require("path"), "object", ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Path.test.bs.js b/lib/js/test/atomic/Path.test.bs.js deleted file mode 100644 index dda75b9..0000000 --- a/lib/js/test/atomic/Path.test.bs.js +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Nodepath = require("node:path"); - -Zora.test("Path", (function (t) { - t.test("basename should isolate filename with extension", (function (t) { - t.equal(Nodepath.posix.basename("/tmp/myfile.html"), "myfile.html", ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Stream.test.bs.js b/lib/js/test/atomic/Stream.test.bs.js deleted file mode 100644 index d21007a..0000000 --- a/lib/js/test/atomic/Stream.test.bs.js +++ /dev/null @@ -1,88 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Nodestream = require("node:stream"); -var StreamTestLib$NodeJs = require("../module/StreamTestLib.bs.js"); - -Zora.test("Stream.Readable", (function (t) { - t.test("'Stream.Readable.make' should return a defined value", (function (t) { - var readable = StreamTestLib$NodeJs.makeReadableEmpty(); - t.notEqual(readable, undefined, ""); - })); - t.test("'Stream.Readable.make' should return an instance of 'Readable'", (function (t) { - var readable = StreamTestLib$NodeJs.makeReadableEmpty(); - t.equal(readable.constructor.name, "Readable", ""); - })); - t.test("'Stream.Readable.pipe' returns a writable stream", (function (t) { - var readable = StreamTestLib$NodeJs.makeReadableEmpty(); - var writable = StreamTestLib$NodeJs.makeWritableEmpty(); - t.equal(readable.pipe(writable), writable, ""); - })); - t.test("'Stream.Readable.destroyWithError' should emit 'error' event", (function (t) { - var dummyError = new Error("Expected error: Stream destroyed"); - return new Promise((function (resolve, param) { - var stream = StreamTestLib$NodeJs.makeReadableEmpty().on("error", (function (err) { - t.equal(err, dummyError, ""); - resolve(); - })); - setTimeout((function () { - stream.destroy(dummyError); - }), 10); - })); - })); - t.test("'Stream.Readable.destroy' should return the exact same instance of 'Readable'", (function (t) { - var readable = StreamTestLib$NodeJs.makeReadableEmpty(); - t.equal(readable.destroy(), readable, ""); - })); - })); - -Zora.test("Stream.Writable", (function (t) { - t.test("'Stream.Writable.make' should return a defined value", (function (t) { - var writable = StreamTestLib$NodeJs.makeWritableEmpty(); - t.notEqual(writable, undefined, ""); - })); - t.test("'Stream.Writable.make' should return an instance of 'Writable'", (function (t) { - var writable = StreamTestLib$NodeJs.makeWritableEmpty(); - t.equal(writable.constructor.name, "Writable", ""); - })); - t.test("Stream.Writable.makeObjMode should have a 'write' function with the correct function signature", (function (t) { - var args = { - contents: undefined - }; - var options = { - objectMode: true, - write: (function (data, encoding, callback) { - var wstream = this ; - args.contents = [ - wstream, - data, - encoding, - callback - ]; - callback(undefined); - }) - }; - return new Promise((function (resolve, param) { - var writeStream = new Nodestream.Writable(options); - writeStream.write(42, (function (param) { - var match = args.contents; - var actual = match !== undefined ? [ - match[0].constructor.name, - typeof match[1], - match[2], - typeof match[3] - ] : undefined; - t.equal(actual, [ - "Writable", - "number", - null, - "function" - ], ""); - resolve(); - })); - })); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Timers.test.bs.js b/lib/js/test/atomic/Timers.test.bs.js deleted file mode 100644 index 1999ea1..0000000 --- a/lib/js/test/atomic/Timers.test.bs.js +++ /dev/null @@ -1,18 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Promises = require("node:timers/promises"); - -Zora.test("Timers (promises)", (async function (t) { - t.test("setTimeout", (async function (t) { - await Promises.setTimeout(100); - t.ok(true, ""); - })); - t.test("setImmediate", (async function (t) { - var yes = await Promises.setImmediate("yes"); - t.equal(yes, "yes", ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/atomic/Util.test.bs.js b/lib/js/test/atomic/Util.test.bs.js deleted file mode 100644 index 8a3adba..0000000 --- a/lib/js/test/atomic/Util.test.bs.js +++ /dev/null @@ -1,17 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Zora = require("zora"); -var Nodeutil = require("node:util"); - -Zora.test("Util.Types", (function (t) { - t.test("Util.Types.isAnyArrayBuffer(arrayBuffer) should return true", (function (t) { - var arrayBuffer = new ArrayBuffer(16); - t.equal(Nodeutil.types.isAnyArrayBuffer(arrayBuffer), true, ""); - })); - t.test("Util.Types.isAnyArrayBuffer(string) should return false", (function (t) { - t.equal(Nodeutil.types.isAnyArrayBuffer("not array buffer"), false, ""); - })); - })); - -/* Not a pure module */ diff --git a/lib/js/test/codegen/Readline.codegen.bs.js b/lib/js/test/codegen/Readline.codegen.bs.js deleted file mode 100644 index ca06604..0000000 --- a/lib/js/test/codegen/Readline.codegen.bs.js +++ /dev/null @@ -1,23 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Process = require("process"); -var Nodereadline = require("node:readline"); - -Nodereadline.clearLine(Process.stdout, 1, (function () { - console.log("line cleared"); - })); - -Nodereadline.clearScreenDown(Process.stdout, (function () { - console.log("screen cleared"); - })); - -Nodereadline.cursorTo(Process.stdout, 1, 2, (function () { - console.log("cursor to"); - })); - -Nodereadline.moveCursor(Process.stdout, 1, 2, (function () { - console.log("cursor moved"); - })); - -/* Not a pure module */ diff --git a/lib/js/test/module/StreamTestLib.bs.js b/lib/js/test/module/StreamTestLib.bs.js deleted file mode 100644 index 3acc741..0000000 --- a/lib/js/test/module/StreamTestLib.bs.js +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -var Caml_option = require("rescript/lib/js/caml_option.js"); -var Nodestream = require("node:stream"); - -function makeReadableEmpty() { - return new Nodestream.Readable({ - objectMode: false, - autoDestroy: true, - destroy: (function (error, callback) { - callback((error == null) ? undefined : Caml_option.some(error)); - }), - read: (function (param) { - - }) - }); -} - -function makeWritableEmpty() { - return new Nodestream.Writable({ - objectMode: false, - autoDestroy: true, - destroy: (function (error, callback) { - callback((error == null) ? undefined : Caml_option.some(error)); - }), - write: (function (param, param$1, callback) { - callback(undefined); - }) - }); -} - -exports.makeReadableEmpty = makeReadableEmpty; -exports.makeWritableEmpty = makeWritableEmpty; -/* node:stream Not a pure module */ diff --git a/package.json b/package.json index 85826f6..f1d342b 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,11 @@ "build": "rescript", "clean": "rescript clean", "start": "rescript build -w", - "test": "rescript && pta lib/js/test/atomic/*.test.bs.js", + "test": "rescript && pta test/atomic/*.test.res.js", "clean-build": "yarn clean && yarn build", "clean-start": "yarn clean && yarn start", "clean-test": "yarn clean && yarn build test", - "test-start": "onchange --await-write-finish 1000 --initial 'lib/js/{test,src}/**/*.bs.js' -- yarn test", + "test-start": "onchange --await-write-finish 1000 --initial '{src,test}/**/*.res.js' -- yarn test", "test-watchexec": "watchexec -r -d 0 -w src -w test -e res -- yarn test" }, "description": "Node bindings for ReScript", @@ -19,16 +19,13 @@ "changie": "^1.18.0", "onchange": "^7.1.0", "pta": "1.2.0", - "rescript": "^11.1.0", + "rescript": "^12.2.0", "zora": "^5.2.0" }, "files": [ - "docs", - "examples", - "lib/js", - "src", - "test", - "bsconfig.json", + "src/**/*.res", + "src/**/*.resi", + "rescript.json", "CHANGELOG.md" ], "keywords": [ diff --git a/rescript.json b/rescript.json index eee5733..03753a8 100644 --- a/rescript.json +++ b/rescript.json @@ -20,12 +20,12 @@ "package-specs": [ { "module": "commonjs", - "in-source": false + "in-source": true } ], - "suffix": ".bs.js", - "bs-dependencies": [], - "bs-dev-dependencies": ["@dusty-phillips/rescript-zora"], + "suffix": ".res.js", + "dependencies": [], + "dev-dependencies": ["@dusty-phillips/rescript-zora"], "warnings": { "number": "A-4-40-41-42-43-44+101-102-103", "error": "false" diff --git a/src/Assert.res b/src/Assert.res index ffc64d3..6449943 100644 --- a/src/Assert.res +++ b/src/Assert.res @@ -11,21 +11,21 @@ external deepStrictEqual: ('a, 'a) => unit = "deepStrictEqual" @module("node:assert") external notDeepStrictEqual: ('a, 'a) => unit = "notDeepStrictEqual" @module("node:assert") -external throws: (@uncurry (unit => 'a)) => unit = "throws" +external throws: (unit => 'a) => unit = "throws" @module("node:assert") -external throwsError: (@uncurry (unit => 'a), 'e) => unit = "throws" +external throwsError: (unit => 'a, 'e) => unit = "throws" @module("node:assert") -external doesNotThrow: (@uncurry (unit => 'a)) => unit = "doesNotThrow" +external doesNotThrow: (unit => 'a) => unit = "doesNotThrow" @module("node:assert") -external doesNotThrowError: (@uncurry (unit => 'a), 'e) => unit = "doesNotThrow" +external doesNotThrowError: (unit => 'a, 'e) => unit = "doesNotThrow" @module("node:assert") external ifError: 'a => unit = "ifError" @module("node:assert") -external rejects: (@uncurry (unit => Js.Promise.t<'a>)) => unit = "rejects" +external rejects: (unit => promise<'a>) => unit = "rejects" @module("node:assert") -external rejectsError: (@uncurry (unit => Js.Promise.t<'a>), 'e) => unit = "rejects" +external rejectsError: (unit => promise<'a>, 'e) => unit = "rejects" @module("node:assert") -external doesNotReject: (@uncurry (unit => Js.Promise.t<'a>)) => unit = "doesNotReject" +external doesNotReject: (unit => promise<'a>) => unit = "doesNotReject" @module("node:assert") -external doesNotRejectError: (@uncurry (unit => Js.Promise.t<'a>), 'e) => unit = "doesNotReject" +external doesNotRejectError: (unit => promise<'a>, 'e) => unit = "doesNotReject" module AssertionError = Errors.AssertionError diff --git a/lib/js/src/Assert.bs.js b/src/Assert.res.js similarity index 86% rename from lib/js/src/Assert.bs.js rename to src/Assert.res.js index d337734..acafe08 100644 --- a/lib/js/src/Assert.bs.js +++ b/src/Assert.res.js @@ -2,7 +2,7 @@ 'use strict'; -var AssertionError; +let AssertionError; exports.AssertionError = AssertionError; /* No side effect */ diff --git a/src/BigInt.res b/src/BigInt.res deleted file mode 100644 index a6f23b1..0000000 --- a/src/BigInt.res +++ /dev/null @@ -1,35 +0,0 @@ -type t - -@val external fromInt: int => t = "BigInt" -@val external fromFloat: float => t = "BigInt" -@val external toInt: t => int = "Number" - -%%private(let _NEGATIVE_ONE = fromInt(-1)) - -external \"~-": t => t = "%negfloat" -external \"+": (t, t) => t = "%addfloat" -external \"-": (t, t) => t = "%subfloat" -external \"*": (t, t) => t = "%mulfloat" -external \"/": (t, t) => t = "%divfloat" -let mod: (t, t) => t = Obj.magic(mod_float) -let \"**": (t, t) => t = %raw(`function (a, b) { return (a ** b); }`) -external land: (t, t) => t = "%andint" -external lor: (t, t) => t = "%orint" -external lxor: (t, t) => t = "%xorint" -let lnot: t => t = x => lxor(x, _NEGATIVE_ONE) -external lsl: (t, t) => t = "%lslint" -external asr: (t, t) => t = "%asrint" - -external negate: t => t = "%negfloat" -external add: (t, t) => t = "%addfloat" -external subtract: (t, t) => t = "%subfloat" -external multiply: (t, t) => t = "%mulfloat" -external divide: (t, t) => t = "%divfloat" -let modulo: (t, t) => t = Obj.magic(mod_float) -let power: (t, t) => t = \"**" -external logicalAnd: (t, t) => t = "%andint" -external logicalOr: (t, t) => t = "%orint" -external logicalXor: (t, t) => t = "%xorint" -let logicalNot: t => t = x => lxor(x, _NEGATIVE_ONE) -external logicalShiftLeft: (t, t) => t = "%lslint" -external arithmeticShiftRight: (t, t) => t = "%asrint" diff --git a/src/BinaryLike.res b/src/BinaryLike.res index 1a4757b..2f7bdf3 100644 --- a/src/BinaryLike.res +++ b/src/BinaryLike.res @@ -1,6 +1,4 @@ module Impl: { - open Js.TypedArray2 - type t type case = @@ -32,8 +30,6 @@ module Impl: { let dataView: DataView.t => t let classify: t => case } = { - open Js.TypedArray2 - @unboxed type rec t = BinaryLike('a): t @@ -68,7 +64,7 @@ module Impl: { let classify: t => case = x => switch x { | BinaryLike(binaryLike) => - if Js.typeof(binaryLike) === "string" { + if typeof(binaryLike) === #string { String(Obj.magic(binaryLike)) } else if Buffer.isBuffer(binaryLike) { Buffer(Obj.magic(binaryLike)) diff --git a/lib/js/src/BinaryLike.bs.js b/src/BinaryLike.res.js similarity index 70% rename from lib/js/src/BinaryLike.bs.js rename to src/BinaryLike.res.js index aca16fa..61235c4 100644 --- a/lib/js/src/BinaryLike.bs.js +++ b/src/BinaryLike.res.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var Nodeutil = require("node:util"); +let Nodeutil = require("node:util"); function string(x) { return x; @@ -54,78 +54,78 @@ function dataView(x) { function classify(x) { if (typeof x === "string") { return { - TAG: "String", - _0: x - }; + TAG: "String", + _0: x + }; } else if (Buffer.isBuffer(x)) { return { - TAG: "Buffer", - _0: x - }; + TAG: "Buffer", + _0: x + }; } else if (Nodeutil.types.isInt8Array(x)) { return { - TAG: "Int8Array", - _0: x - }; + TAG: "Int8Array", + _0: x + }; } else if (Nodeutil.types.isUint8Array(x)) { return { - TAG: "Uint8Array", - _0: x - }; + TAG: "Uint8Array", + _0: x + }; } else if (Nodeutil.types.isUint8ClampedArray(x)) { return { - TAG: "Uint8ClampedArray", - _0: x - }; + TAG: "Uint8ClampedArray", + _0: x + }; } else if (Nodeutil.types.isInt16Array(x)) { return { - TAG: "Int16Array", - _0: x - }; + TAG: "Int16Array", + _0: x + }; } else if (Nodeutil.types.isUint16Array(x)) { return { - TAG: "Uint16Array", - _0: x - }; + TAG: "Uint16Array", + _0: x + }; } else if (Nodeutil.types.isInt32Array(x)) { return { - TAG: "Int32Array", - _0: x - }; + TAG: "Int32Array", + _0: x + }; } else if (Nodeutil.types.isUint32Array(x)) { return { - TAG: "Uint32Array", - _0: x - }; + TAG: "Uint32Array", + _0: x + }; } else if (Nodeutil.types.isFloat32Array(x)) { return { - TAG: "Float32Array", - _0: x - }; + TAG: "Float32Array", + _0: x + }; } else if (Nodeutil.types.isFloat64Array(x)) { return { - TAG: "Float64Array", - _0: x - }; + TAG: "Float64Array", + _0: x + }; } else if (Nodeutil.types.isDataView(x)) { return { - TAG: "DataView", - _0: x - }; + TAG: "DataView", + _0: x + }; } else if (Nodeutil.types.isStringObject(x)) { return { - TAG: "String", - _0: x - }; + TAG: "String", + _0: x + }; } else { return { - TAG: "Unknown", - _0: x - }; + TAG: "Unknown", + _0: x + }; } } -var Impl = { +let Impl = { string: string, buffer: buffer, int8Array: int8Array, diff --git a/src/Buffer.res b/src/Buffer.res index 9014328..3181be0 100644 --- a/src/Buffer.res +++ b/src/Buffer.res @@ -1,5 +1,4 @@ type t = {length: int} -open Js.TypedArray2 module Constants = { @module("node:buffer") @scope("constants") @val @@ -296,7 +295,7 @@ external sliceToEnd: (t, ~start: int) => t = "slice" @send external swap32: t => t = "swap32" @send external swap64: t => t = "swap64" -@send external toJSON: t => Js.Json.t = "toJSON" +@send external toJSON: t => JSON.t = "toJSON" @send external toString: t => string = "toString" @send diff --git a/lib/js/src/Buffer.bs.js b/src/Buffer.res.js similarity index 85% rename from lib/js/src/Buffer.bs.js rename to src/Buffer.res.js index c6c4781..27d82ce 100644 --- a/lib/js/src/Buffer.bs.js +++ b/src/Buffer.res.js @@ -2,7 +2,7 @@ 'use strict'; -var Constants = {}; +let Constants = {}; exports.Constants = Constants; /* No side effect */ diff --git a/src/ChildProcess.res b/src/ChildProcess.res index c06dbb8..9333cab 100644 --- a/src/ChildProcess.res +++ b/src/ChildProcess.res @@ -7,44 +7,44 @@ type t = { module Events = { @send - external onData: (t, @as("data") _, @uncurry (Buffer.t => unit)) => t = "on" + external onData: (t, @as("data") _, Buffer.t => unit) => t = "on" @send - external onDisconnect: (t, @as("disconnect") _, @uncurry unit => unit) => t = "on" + external onDisconnect: (t, @as("disconnect") _, unit => unit) => t = "on" @send - external onError: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "on" + external onError: (t, @as("error") _, JsExn.t => unit) => t = "on" @send - external onExit: (t, @as("exit") _, @uncurry int => unit) => t = "on" + external onExit: (t, @as("exit") _, int => unit) => t = "on" @send - external onClose: (t, @as("close") _, @uncurry int => unit) => t = "on" + external onClose: (t, @as("close") _, int => unit) => t = "on" @send - external offData: (t, @as("data") _, @uncurry (Buffer.t => unit)) => t = "off" + external offData: (t, @as("data") _, Buffer.t => unit) => t = "off" @send - external offDisconnect: (t, @as("disconnect") _, @uncurry unit => unit) => t = "off" + external offDisconnect: (t, @as("disconnect") _, unit => unit) => t = "off" @send - external offError: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "off" + external offError: (t, @as("error") _, JsExn.t => unit) => t = "off" @send - external offExit: (t, @as("exit") _, @uncurry int => unit) => t = "off" + external offExit: (t, @as("exit") _, int => unit) => t = "off" @send - external offClose: (t, @as("close") _, @uncurry int => unit) => t = "off" + external offClose: (t, @as("close") _, int => unit) => t = "off" @send - external onDataOnce: (t, @as("data") _, @uncurry (Buffer.t => unit)) => t = "once" + external onDataOnce: (t, @as("data") _, Buffer.t => unit) => t = "once" @send - external onDisconnectOnce: (t, @as("disconnect") _, @uncurry unit => unit) => t = "once" + external onDisconnectOnce: (t, @as("disconnect") _, unit => unit) => t = "once" @send - external onErrorOnce: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "once" + external onErrorOnce: (t, @as("error") _, JsExn.t => unit) => t = "once" @send - external onExitOnce: (t, @as("exit") _, @uncurry int => unit) => t = "once" + external onExitOnce: (t, @as("exit") _, int => unit) => t = "once" @send - external onCloseOnce: (t, @as("close") _, @uncurry int => unit) => t = "once" + external onCloseOnce: (t, @as("close") _, int => unit) => t = "once" @send external emitData: (t, @as("data") _, Buffer.t) => bool = "emit" @send external emitDisconnect: (t, @as("disconnect") _) => bool = "emit" @send - external emitError: (t, @as("error") _, Js.Exn.t) => bool = "emit" + external emitError: (t, @as("error") _, JsExn.t) => bool = "emit" @send external emitExit: (t, @as("exit") _, int) => bool = "emit" @send external emitClose: (t, @as("close") _, int) => bool = "emit" @@ -68,7 +68,7 @@ external stdout: t => option> = "stdout" type execOptions = { cwd?: string, - env?: Js.Dict.t, + env?: dict, shell?: string, timeout?: int, maxBuffer?: int, @@ -80,15 +80,15 @@ type execOptions = { } @module("node:child_process") @val -external exec: (string, (Js.nullable, Buffer.t, Buffer.t) => unit) => t = "exec" +external exec: (string, (nullable, Buffer.t, Buffer.t) => unit) => t = "exec" @module("node:child_process") @val -external execWith: (string, execOptions, (Js.nullable, Buffer.t, Buffer.t) => unit) => t = +external execWith: (string, execOptions, (nullable, Buffer.t, Buffer.t) => unit) => t = "exec" type execFileOptions = { cwd?: string, - env?: Js.Dict.t, + env?: dict, timeout?: int, maxBuffer?: int, killSignal?: string, @@ -99,24 +99,21 @@ type execFileOptions = { } @module("node:child_process") @val -external execFile: ( - string, - array, - (Js.nullable, Buffer.t, Buffer.t) => unit, -) => t = "execFile" +external execFile: (string, array, (nullable, Buffer.t, Buffer.t) => unit) => t = + "execFile" @module("node:child_process") @val external execFileWith: ( string, array, execFileOptions, - (Js.nullable, Buffer.t, Buffer.t) => unit, + (nullable, Buffer.t, Buffer.t) => unit, ) => t = "execFile" type forkOptions = { cwd?: string, detached?: bool, - env?: Js.Dict.t, + env?: dict, execPath?: string, execArgv?: array, silent?: bool, @@ -134,7 +131,7 @@ external forkWith: (string, array, forkOptions) => t = "fork" type spawnOptions = { cwd?: string, - env?: Js.Dict.t, + env?: dict, argv0?: string, stdio?: string, detached?: bool, @@ -157,13 +154,13 @@ type spawnSyncResult<'a> = { stdout: Buffer.t, stderr: Buffer.t, status: int, - signal: Js.nullable, - error: Js.nullable, + signal: nullable, + error: nullable, } type spawnSyncOptions = { cwd?: string, - env?: Js.Dict.t, + env?: dict, input?: Buffer.t, argv0?: string, stdio?: string, @@ -184,7 +181,7 @@ external spawnSyncWith: (string, array, spawnSyncOptions) => spawnSyncRe type execSyncOptions = { cwd?: string, - env?: Js.Dict.t, + env?: dict, input?: Buffer.t, shell?: string, timeout?: int, @@ -204,7 +201,7 @@ external execSyncWith: (string, execSyncOptions) => Buffer.t = "execSync" type execFileSyncOptions = { cwd?: string, - env?: Js.Dict.t, + env?: dict, input?: Buffer.t, shell?: string, timeout?: int, diff --git a/lib/js/src/ChildProcess.bs.js b/src/ChildProcess.res.js similarity index 86% rename from lib/js/src/ChildProcess.bs.js rename to src/ChildProcess.res.js index b5506e4..bbe3860 100644 --- a/lib/js/src/ChildProcess.bs.js +++ b/src/ChildProcess.res.js @@ -2,7 +2,7 @@ 'use strict'; -var Events = {}; +let Events = {}; exports.Events = Events; /* No side effect */ diff --git a/src/Cluster.res b/src/Cluster.res index fd991e0..d8c7ef1 100644 --- a/src/Cluster.res +++ b/src/Cluster.res @@ -26,16 +26,16 @@ module Address = { | address => let internalReturn: internalView<'a> = Obj.magic(address) let addressType = internalReturn.addressType - let intOrString = Js.typeof(addressType) + let intOrString = typeof(addressType) switch intOrString { - | "number" => + | #number => switch (Obj.magic(addressType): int) { | 4 => TcpV4(address) | 6 => TcpV6(address) | -1 => UnixDomainSocket(address) | _ => Unknown(address) } - | "string" => + | #string => switch (Obj.magic(addressType): string) { | "udp4" => Udp4(address) | "udp6" => Udp6(address) @@ -54,67 +54,44 @@ module Worker = { type t = {id: int, process: ChildProcess.t} module Events = { @send - external onDisconnect: (t, @as("disconnect") _, @uncurry unit => unit) => t = "on" + external onDisconnect: (t, @as("disconnect") _, unit => unit) => t = "on" @send - external onError: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "on" + external onError: (t, @as("error") _, JsExn.t => unit) => t = "on" @send - external onExit: ( - t, - @as("exit") _, - @uncurry (Js.nullable, Js.nullable) => unit, - ) => t = "on" + external onExit: (t, @as("exit") _, (nullable, nullable) => unit) => t = "on" @send - external onListening: (t, @as("listening") _, @uncurry (Address.t => unit)) => t = "on" + external onListening: (t, @as("listening") _, Address.t => unit) => t = "on" @send - external onMessage: ( - t, - @as("message") _, - @uncurry (Message.t<'a>, Js.nullable<'a>) => unit, - ) => t = "on" + external onMessage: (t, @as("message") _, (Message.t<'a>, nullable<'a>) => unit) => t = "on" @send - external onOnline: (t, @as("online") _, @uncurry unit => unit) => t = "on" + external onOnline: (t, @as("online") _, unit => unit) => t = "on" @send - external offDisconnect: (t, @as("disconnect") _, @uncurry unit => unit) => t = "off" + external offDisconnect: (t, @as("disconnect") _, unit => unit) => t = "off" @send - external offError: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "off" + external offError: (t, @as("error") _, JsExn.t => unit) => t = "off" @send - external offExit: ( - t, - @as("exit") _, - @uncurry (Js.nullable, Js.nullable) => unit, - ) => t = "off" + external offExit: (t, @as("exit") _, (nullable, nullable) => unit) => t = "off" @send - external offListening: (t, @as("listening") _, @uncurry (Address.t => unit)) => t = "off" + external offListening: (t, @as("listening") _, Address.t => unit) => t = "off" @send - external offMessage: ( - t, - @as("message") _, - @uncurry (Message.t<'a>, Js.nullable<'a>) => unit, - ) => t = "off" + external offMessage: (t, @as("message") _, (Message.t<'a>, nullable<'a>) => unit) => t = "off" @send - external offOnline: (t, @as("online") _, @uncurry unit => unit) => t = "off" + external offOnline: (t, @as("online") _, unit => unit) => t = "off" @send - external onDisconnectOnce: (t, @as("disconnect") _, @uncurry unit => unit) => t = "once" + external onDisconnectOnce: (t, @as("disconnect") _, unit => unit) => t = "once" @send - external onErrorOnce: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "once" + external onErrorOnce: (t, @as("error") _, JsExn.t => unit) => t = "once" @send - external onExitOnce: ( - t, - @as("exit") _, - @uncurry (Js.nullable, Js.nullable) => unit, - ) => t = "once" + external onExitOnce: (t, @as("exit") _, (nullable, nullable) => unit) => t = "once" @send - external onListeningOnce: (t, @as("listening") _, @uncurry (Address.t => unit)) => t = "once" + external onListeningOnce: (t, @as("listening") _, Address.t => unit) => t = "once" @send - external onMessageOnce: ( - t, - @as("message") _, - @uncurry (Message.t<'a>, Js.nullable<'a>) => unit, - ) => t = "once" + external onMessageOnce: (t, @as("message") _, (Message.t<'a>, nullable<'a>) => unit) => t = + "once" @send - external onOnlineOnce: (t, @as("online") _, @uncurry unit => unit) => t = "once" + external onOnlineOnce: (t, @as("online") _, unit => unit) => t = "once" @send external removeAllListeners: t => unit = "removeAllListeners" } @@ -130,36 +107,36 @@ module Worker = { @send external send: string => unit = "send" @send - external sendHttpServerHandle: (string, Http.Server.t, Js.nullable<{..}>) => unit = "send" + external sendHttpServerHandle: (string, Http.Server.t, nullable<{..}>) => unit = "send" let sendHttpServerHandle = (~options=?, msg, handle) => - sendHttpServerHandle(msg, handle, Js.Nullable.fromOption(options)) + sendHttpServerHandle(msg, handle, Nullable.fromOption(options)) @send - external sendSocketHandle: (string, Net.Socket.subtype<'w, 'r, 'a>, Js.nullable<{..}>) => unit = + external sendSocketHandle: (string, Net.Socket.subtype<'w, 'r, 'a>, nullable<{..}>) => unit = "send" let sendSocketHandle = (~options=?, msg, handle) => - sendSocketHandle(msg, handle, Js.Nullable.fromOption(options)) + sendSocketHandle(msg, handle, Nullable.fromOption(options)) } type clusterSettings = private { - execArgv: Js.nullable>, - exec: Js.nullable, - args: Js.nullable>, - cwd: Js.nullable, - serialization: Js.nullable, - silent: Js.nullable, - stdio: Js.nullable>, - uid: Js.nullable, - gid: Js.nullable, - inspectPort: Js.nullable, - windowsHide: Js.nullable, + execArgv: nullable>, + exec: nullable, + args: nullable>, + cwd: nullable, + serialization: nullable, + silent: nullable, + stdio: nullable>, + uid: nullable, + gid: nullable, + inspectPort: nullable, + windowsHide: nullable, } @module -external disconnect: Js.Nullable.t unit> => unit = "disconnect" -let disconnect = (~callback=?, ()) => disconnect(Js.Nullable.fromOption(callback)) +external disconnect: nullable unit> => unit = "disconnect" +let disconnect = (~callback=?) => disconnect(Nullable.fromOption(callback)) @module("node:cluster") -external fork: option> => Worker.t = "fork" -let fork = (~env=?, ()) => fork(env) +external fork: option> => Worker.t = "fork" +let fork = (~env=?) => fork(env) @module("node:cluster") external isMaster: bool = "isMaster" @module("node:cluster") external isWorker: bool = "isWorker" @module("node:cluster") external settings: clusterSettings = "settings" @@ -177,6 +154,6 @@ let decodeSchedulingPolicy = if schedulingPolicy === _SCHED_RR { SCHED_NONE } @module("node:cluster") external worker: Worker.t = "worker" -@module("node:cluster") external workers: Js.Dict.t = "workers" -let getWorker: (Js.Dict.t, int) => option = (_workers, id) => - Js.Dict.get(_workers, Js.Int.toString(id)) +@module("node:cluster") external workers: dict = "workers" +let getWorker: (dict, int) => option = (_workers, id) => + Dict.get(_workers, Int.toString(id)) diff --git a/src/Cluster.res.js b/src/Cluster.res.js new file mode 100644 index 0000000..1a4d30a --- /dev/null +++ b/src/Cluster.res.js @@ -0,0 +1,104 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Disconnect = require("disconnect"); +let Nodecluster = require("node:cluster"); +let Stdlib_Nullable = require("@rescript/runtime/lib/js/Stdlib_Nullable.js"); + +function classify(x) { + let addressType = x.addressType; + let intOrString = typeof addressType; + if (intOrString === "string") { + switch (addressType) { + case "udp4" : + return { + TAG: "Udp4", + _0: x + }; + case "udp6" : + return { + TAG: "Udp6", + _0: x + }; + default: + return { + TAG: "Unknown", + _0: x + }; + } + } else { + if (intOrString !== "number") { + return { + TAG: "Unknown", + _0: x + }; + } + switch (addressType) { + case -1 : + return { + TAG: "UnixDomainSocket", + _0: x + }; + case 4 : + return { + TAG: "TcpV4", + _0: x + }; + case 6 : + return { + TAG: "TcpV6", + _0: x + }; + default: + return { + TAG: "Unknown", + _0: x + }; + } + } +} + +let Address = { + classify: classify +}; + +let Message = {}; + +let Events = {}; + +function sendHttpServerHandle(options, msg, handle) { + msg.send(handle, Stdlib_Nullable.fromOption(options)); +} + +function sendSocketHandle(options, msg, handle) { + msg.send(handle, Stdlib_Nullable.fromOption(options)); +} + +let Worker = { + Events: Events, + sendHttpServerHandle: sendHttpServerHandle, + sendSocketHandle: sendSocketHandle +}; + +function disconnect(callback) { + Disconnect(Stdlib_Nullable.fromOption(callback)); +} + +function fork(env) { + return Nodecluster.fork(env); +} + +let decodeSchedulingPolicy = Nodecluster.schedulingPolicy === Nodecluster.SCHED_RR ? "SCHED_RR" : "SCHED_NONE"; + +function getWorker(_workers, id) { + return _workers[id.toString()]; +} + +exports.Address = Address; +exports.Message = Message; +exports.Worker = Worker; +exports.disconnect = disconnect; +exports.fork = fork; +exports.decodeSchedulingPolicy = decodeSchedulingPolicy; +exports.getWorker = getWorker; +/* decodeSchedulingPolicy Not a pure module */ diff --git a/src/Console.res b/src/Console.res index 8d8e48d..5d1b724 100644 --- a/src/Console.res +++ b/src/Console.res @@ -1,5 +1,5 @@ // We'll only bind to the instance version of console.Console for now: https://nodejs.org/api/console.html -// For global console.log and others, use the existing Js.Console.* provided by BuckleScript out of the box +// For global console.log and others, use the existing Console.* provided by BuckleScript out of the box type t @val external console: t = "console" diff --git a/lib/js/src/Console.bs.js b/src/Console.res.js similarity index 100% rename from lib/js/src/Console.bs.js rename to src/Console.res.js diff --git a/src/Crypto.res b/src/Crypto.res index a0f7d0b..3dac2a9 100644 --- a/src/Crypto.res +++ b/src/Crypto.res @@ -125,13 +125,13 @@ module Cipher = { external make: ( ~algorithm: string, ~key: KeyObject.t<'a, [> KeyObject.secretKey]>, - ~iv: Js.Null.t, + ~iv: Null.t, ) => t = "createCipheriv" @module("node:crypto") external makeWith: ( ~algorithm: string, ~key: KeyObject.t<'a, [> KeyObject.secretKey]>, - ~iv: Js.Null.t, + ~iv: Null.t, ~options: Stream.Transform.makeOptions=?, ) => t = "createCipheriv" } @@ -164,13 +164,13 @@ module Decipher = { external make: ( ~algorithm: string, ~key: KeyObject.t<'a, [> KeyObject.secretKey]>, - ~iv: Js.Null.t, + ~iv: Null.t, ) => t = "createDecipheriv" @module("node:crypto") external makeWith: ( ~algorithm: string, ~key: KeyObject.t<'a, [> KeyObject.secretKey]>, - ~iv: Js.Null.t, + ~iv: Null.t, ~options: Stream.Transform.makeOptions=?, ) => t = "createDecipheriv" } /* } */ /* } */ /* module Verify = */ diff --git a/lib/js/src/Crypto.bs.js b/src/Crypto.res.js similarity index 63% rename from lib/js/src/Crypto.bs.js rename to src/Crypto.res.js index e853fba..8981248 100644 --- a/lib/js/src/Crypto.bs.js +++ b/src/Crypto.res.js @@ -2,53 +2,53 @@ 'use strict'; -var Impl = {}; +let Impl = {}; -var Symmetric = { +let Symmetric = { Impl: Impl }; -var Impl$1 = {}; +let Impl$1 = {}; -var Asymmetric = { +let Asymmetric = { Impl: Impl$1 }; -var Impl$2 = {}; +let Impl$2 = {}; -var KeyObject = { +let KeyObject = { Symmetric: Symmetric, Asymmetric: Asymmetric, Impl: Impl$2 }; -var PivateKey = {}; +let PivateKey = {}; -var PublicKey = {}; +let PublicKey = {}; -var Impl$3 = {}; +let Impl$3 = {}; -var Hash = { +let Hash = { Impl: Impl$3 }; -var Impl$4 = {}; +let Impl$4 = {}; -var Hmac = { +let Hmac = { Impl: Impl$4 }; -var Certificate = {}; +let Certificate = {}; -var Impl$5 = {}; +let Impl$5 = {}; -var Cipher = { +let Cipher = { Impl: Impl$5 }; -var Impl$6 = {}; +let Impl$6 = {}; -var Decipher = { +let Decipher = { Impl: Impl$6 }; diff --git a/src/Dns.res b/src/Dns.res index 0a17d5f..85b0448 100644 --- a/src/Dns.res +++ b/src/Dns.res @@ -5,34 +5,31 @@ type options = { verbatim?: bool, } @module("dns") @scope("promise") -external lookup: string => Js.Promise.t> = "lookup" +external lookup: string => promise> = "lookup" @module("node:dns") @scope("promise") external lookupWithOptions: ( string, options, -) => Js.Promise.t> = "lookup" +) => promise> = "lookup" @module("node:dns") @scope("promise") -external lookupService: (string, int) => Js.Promise.t<{"hostname": string, "service": string}> = +external lookupService: (string, int) => promise<{"hostname": string, "service": string}> = "lookupService" @module("node:dns") @scope("promise") -external resolve4: string => Js.Promise.t> = "resolve4" +external resolve4: string => promise> = "resolve4" @module("node:dns") @scope("promise") -external resolve4TTL: (string, @as(json` {"ttl": true} `) _) => Js.Promise.t> = - "resolve4" +external resolve4TTL: (string, @as(json` {"ttl": true} `) _) => promise> = "resolve4" @module("node:dns") @scope("promise") -external resolve6: string => Js.Promise.t> = "resolve6" +external resolve6: string => promise> = "resolve6" @module("node:dns") @scope("promise") -external resolve6TTL: (string, @as(json` {"ttl": true} `) _) => Js.Promise.t> = - "resolve6" +external resolve6TTL: (string, @as(json` {"ttl": true} `) _) => promise> = "resolve6" @module("node:dns") @scope("promise") -external resolveAny: string => Js.Promise.t> = "resolveAny" +external resolveAny: string => promise> = "resolveAny" @module("node:dns") @scope("promise") -external resolveCname: string => Js.Promise.t> = "resolveCname" +external resolveCname: string => promise> = "resolveCname" @module("node:dns") @scope("promise") -external resolveMx: string => Js.Promise.t> = - "resolveMx" +external resolveMx: string => promise> = "resolveMx" @module("node:dns") @scope("promise") -external resolveNaptr: string => Js.Promise.t< +external resolveNaptr: string => promise< array<{ "flags": string, "service": string, @@ -43,11 +40,11 @@ external resolveNaptr: string => Js.Promise.t< }>, > = "resolveNaptr" @module("node:dns") @scope("promise") -external resolveNs: string => Js.Promise.t> = "resolveNs" +external resolveNs: string => promise> = "resolveNs" @module("node:dns") @scope("promise") -external resolvePtr: string => Js.Promise.t> = "resolvePtr" +external resolvePtr: string => promise> = "resolvePtr" @module("node:dns") @scope("promise") -external resolveSoa: string => Js.Promise.t< +external resolveSoa: string => promise< array<{ "nsname": string, "hostmaster": string, @@ -60,7 +57,7 @@ external resolveSoa: string => Js.Promise.t< > = "resolveSoa" @module("node:dns") @scope("promise") -external resolveSrv: string => Js.Promise.t< +external resolveSrv: string => promise< array<{ "priority": int, "weight": int, @@ -69,48 +66,47 @@ external resolveSrv: string => Js.Promise.t< }>, > = "resolveSrv" @module("node:dns") @scope("promise") -external resolveTxt: string => Js.Promise.t>> = "resolveTxt" +external resolveTxt: string => promise>> = "resolveTxt" @module("node:dns") @scope("promise") -external reverse: string => Js.Promise.t> = "reverse" +external reverse: string => promise> = "reverse" @module("node:dns") @scope("promise") -external setServers: array => Js.Promise.t = "setServers" +external setServers: array => promise = "setServers" module CallbackAPI = { @module("node:dns") - external lookup: (string, (Js.Exn.t, string, int) => unit) => string = "lookup" + external lookup: (string, (JsExn.t, string, int) => unit) => string = "lookup" @module("node:dns") - external lookupWithOptions: (string, options, (Js.Exn.t, string, int) => unit) => string = - "lookup" + external lookupWithOptions: (string, options, (JsExn.t, string, int) => unit) => string = "lookup" @module("node:dns") external getServers: unit => array = "getServers" @module("node:dns") - external resolveAny: (string, (Js.Exn.t, array<{..}>) => unit) => unit = "resolveAny" + external resolveAny: (string, (JsExn.t, array<{..}>) => unit) => unit = "resolveAny" @module("node:dns") - external resolve4: (string, (Js.Exn.t, array) => unit) => unit = "resolve4" + external resolve4: (string, (JsExn.t, array) => unit) => unit = "resolve4" @module("node:dns") external resolve4TTL: ( string, @as(json` {"ttl": true} `) _, - (Js.Exn.t, array<{"address": string, "ttl": int}>) => unit, + (JsExn.t, array<{"address": string, "ttl": int}>) => unit, ) => unit = "resolve4" @module("node:dns") - external resolve6: (string, (Js.Exn.t, array) => unit) => unit = "resolve6" + external resolve6: (string, (JsExn.t, array) => unit) => unit = "resolve6" @module("node:dns") external resolve6TTL: ( string, @as(json` {"ttl": true} `) _, - (Js.Exn.t, array<{"address": string, "ttl": int}>) => unit, + (JsExn.t, array<{"address": string, "ttl": int}>) => unit, ) => unit = "resolve6" @module("node:dns") - external resolveCname: (string, (Js.Exn.t, array) => unit) => unit = "resolveCname" + external resolveCname: (string, (JsExn.t, array) => unit) => unit = "resolveCname" @module("node:dns") - external resolveMx: (string, (Js.Exn.t, array<{"exchange": string, "priority": int}>)) => unit = + external resolveMx: (string, (JsExn.t, array<{"exchange": string, "priority": int}>)) => unit = "resolveMx" @module("node:dns") external resolveNaptr: ( string, ( - Js.Exn.t, + JsExn.t, array<{ "flags": string, "service": string, @@ -122,14 +118,14 @@ module CallbackAPI = { ) => unit, ) => unit = "resolveNaptr" @module("node:dns") - external resolveNs: (string, (Js.Exn.t, array)) => unit = "resolveNs" + external resolveNs: (string, (JsExn.t, array)) => unit = "resolveNs" @module("node:dns") - external resolvePtr: (string, (Js.Exn.t, array)) => unit = "resolvePtr" + external resolvePtr: (string, (JsExn.t, array)) => unit = "resolvePtr" @module("node:dns") external resolveSoa: ( string, ( - Js.Exn.t, + JsExn.t, { "nsname": string, "hostmaster": string, @@ -144,12 +140,12 @@ module CallbackAPI = { @module("node:dns") external resolveSrv: ( string, - (Js.Exn.t, array<{"priority": int, "weight": int, "port": int, "name": string}>) => unit, + (JsExn.t, array<{"priority": int, "weight": int, "port": int, "name": string}>) => unit, ) => unit = "resolveSrv" @module("node:dns") - external resolveTxt: (string, (Js.Exn.t, array>)) => unit = "resolveTxt" + external resolveTxt: (string, (JsExn.t, array>)) => unit = "resolveTxt" @module("node:dns") - external reverse: (string, (Js.Exn.t, array) => unit) => unit = "reverse" + external reverse: (string, (JsExn.t, array) => unit) => unit = "reverse" @module("node:dns") external setServers: array => unit = "setServers" } diff --git a/lib/js/src/Dns.bs.js b/src/Dns.res.js similarity index 84% rename from lib/js/src/Dns.bs.js rename to src/Dns.res.js index 7afa630..ef665a0 100644 --- a/lib/js/src/Dns.bs.js +++ b/src/Dns.res.js @@ -2,7 +2,7 @@ 'use strict'; -var CallbackAPI = {}; +let CallbackAPI = {}; exports.CallbackAPI = CallbackAPI; /* No side effect */ diff --git a/src/Errors.res b/src/Errors.res index 92450e0..dd3a5b1 100644 --- a/src/Errors.res +++ b/src/Errors.res @@ -9,7 +9,7 @@ external stackTraceLimit: int = "captureStackTrace" } `) @val -external setStackTraceLimit: int => Js.Undefined.t<'a> = "setStackTraceLimit" +external setStackTraceLimit: int => undefined<'a> = "setStackTraceLimit" let setStackTraceLimit: int => unit = n => setStackTraceLimit(n)->ignore module Error = { @@ -22,12 +22,12 @@ module Error = { @get external message: t => string = "message" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isError: Js.Exn.t => bool = x => + let isError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "Error" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isError(exn) ? Some(fromJsExn(exn)) : None } module AssertionError = { @@ -52,12 +52,12 @@ module AssertionError = { @get external operator: t => string = "operator" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isAssertionError: Js.Exn.t => bool = x => + let isAssertionError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "AssertionError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isAssertionError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isAssertionError(exn) ? Some(fromJsExn(exn)) : None } module EvalError = { @@ -69,12 +69,12 @@ module EvalError = { @get external name: t => string = "name" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isEvalError: Js.Exn.t => bool = x => + let isEvalError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "EvalError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isEvalError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isEvalError(exn) ? Some(fromJsExn(exn)) : None } module RangeError = { @@ -87,12 +87,12 @@ module RangeError = { @get external message: t => string = "message" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isRangeError: Js.Exn.t => bool = x => + let isRangeError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "RangeError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isRangeError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isRangeError(exn) ? Some(fromJsExn(exn)) : None } module ReferenceError = { @@ -105,12 +105,12 @@ module ReferenceError = { @get external message: t => string = "message" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isReferenceError: Js.Exn.t => bool = x => + let isReferenceError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "ReferenceError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isReferenceError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isReferenceError(exn) ? Some(fromJsExn(exn)) : None } module SyntaxError = { @@ -123,12 +123,12 @@ module SyntaxError = { @get external message: t => string = "message" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isSyntaxError: Js.Exn.t => bool = x => + let isSyntaxError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "SyntaxError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isSyntaxError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isSyntaxError(exn) ? Some(fromJsExn(exn)) : None } // It's not clear that SystemError works as expressed in the Node API. @@ -161,13 +161,13 @@ module TypeError = { @get external code: t => string = "code" @get external message: t => string = "message" @get external stack: t => string = "stack" - external toJsExn: t => Js.Exn.t = "%identity" + external toJsExn: t => JsExn.t = "%identity" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isTypeError: Js.Exn.t => bool = x => + let isTypeError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "TypeError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isTypeError(exn) ? Some(fromJsExn(exn)) : None + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isTypeError(exn) ? Some(fromJsExn(exn)) : None } module URIError = { @@ -179,12 +179,12 @@ module URIError = { @get external name: t => string = "name" @get external stack: t => string = "stack" let instanceOf = x => Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - let isURIError: Js.Exn.t => bool = x => + let isURIError: JsExn.t => bool = x => Internal__JsTypeReflection.constructorName(x) == "URIError" && Internal__JsTypeReflection.instanceOfClass(~instance=x, ~class_=constructor) - external toJsExn: t => Js.Exn.t = "%identity" - external fromJsExn: Js.Exn.t => t = "%identity" - let fromJsExn: Js.Exn.t => option = exn => isURIError(exn) ? Some(fromJsExn(exn)) : None + external toJsExn: t => JsExn.t = "%identity" + external fromJsExn: JsExn.t => t = "%identity" + let fromJsExn: JsExn.t => option = exn => isURIError(exn) ? Some(fromJsExn(exn)) : None } type case = @@ -197,7 +197,7 @@ type case = | TypeError(TypeError.t) | URIError(URIError.t) -let classifyOpt: Js.Exn.t => option = value => +let classifyOpt: JsExn.t => option = value => if AssertionError.isAssertionError(value) { Some(AssertionError(Obj.magic(value))) } else if EvalError.isEvalError(value) { @@ -218,13 +218,13 @@ let classifyOpt: Js.Exn.t => option = value => None } -let classifyExn: Js.Exn.t => case = value => +let classifyExn: JsExn.t => case = value => switch classifyOpt(value) { | None => failwith("Unknown data type") | Some(err) => err } -let classify: Js.Exn.t => Belt.Result.t = value => +let classify: JsExn.t => Belt.Result.t = value => switch classifyOpt(value) { | None => Error(value) | Some(err) => Ok(err) diff --git a/lib/js/src/Errors.bs.js b/src/Errors.res.js similarity index 78% rename from lib/js/src/Errors.bs.js rename to src/Errors.res.js index f0d4f96..782120c 100644 --- a/lib/js/src/Errors.bs.js +++ b/src/Errors.res.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var PervasivesU = require("rescript/lib/js/pervasivesU.js"); -var Nodeassert = require("node:assert"); -var Internal__JsTypeReflection$NodeJs = require("./internal/Internal__JsTypeReflection.bs.js"); +let Pervasives = require("@rescript/runtime/lib/js/Pervasives.js"); +let Nodeassert = require("node:assert"); +let Internal__JsTypeReflection$NodeJs = require("./internal/Internal__JsTypeReflection.res.js"); function setStackTraceLimit(n) { Error.stackTraceLimit = n; @@ -11,8 +11,8 @@ function setStackTraceLimit(n) { } ; -function setStackTraceLimit$1(n) { - setStackTraceLimit(n); +function setStackTraceLimit(n) { + globalThis.setStackTraceLimit(n); } function instanceOf(x) { @@ -31,10 +31,9 @@ function fromJsExn(exn) { if (isError(exn)) { return exn; } - } -var $$Error$1 = { +let $$Error$1 = { instanceOf: instanceOf, isError: isError, fromJsExn: fromJsExn @@ -56,10 +55,9 @@ function fromJsExn$1(exn) { if (isAssertionError(exn)) { return exn; } - } -var AssertionError = { +let AssertionError = { instanceOf: instanceOf$1, isAssertionError: isAssertionError, fromJsExn: fromJsExn$1 @@ -81,10 +79,9 @@ function fromJsExn$2(exn) { if (isEvalError(exn)) { return exn; } - } -var $$EvalError$1 = { +let $$EvalError$1 = { instanceOf: instanceOf$2, isEvalError: isEvalError, fromJsExn: fromJsExn$2 @@ -106,10 +103,9 @@ function fromJsExn$3(exn) { if (isRangeError(exn)) { return exn; } - } -var $$RangeError$1 = { +let $$RangeError$1 = { instanceOf: instanceOf$3, isRangeError: isRangeError, fromJsExn: fromJsExn$3 @@ -131,10 +127,9 @@ function fromJsExn$4(exn) { if (isReferenceError(exn)) { return exn; } - } -var $$ReferenceError$1 = { +let $$ReferenceError$1 = { instanceOf: instanceOf$4, isReferenceError: isReferenceError, fromJsExn: fromJsExn$4 @@ -156,16 +151,15 @@ function fromJsExn$5(exn) { if (isSyntaxError(exn)) { return exn; } - } -var $$SyntaxError$1 = { +let $$SyntaxError$1 = { instanceOf: instanceOf$5, isSyntaxError: isSyntaxError, fromJsExn: fromJsExn$5 }; -var SystemError = {}; +let SystemError = {}; function instanceOf$6(x) { return Internal__JsTypeReflection$NodeJs.instanceOfClass(x, TypeError); @@ -183,10 +177,9 @@ function fromJsExn$6(exn) { if (isTypeError(exn)) { return exn; } - } -var $$TypeError$1 = { +let $$TypeError$1 = { instanceOf: instanceOf$6, isTypeError: isTypeError, fromJsExn: fromJsExn$6 @@ -208,10 +201,9 @@ function fromJsExn$7(exn) { if (isURIError(exn)) { return exn; } - } -var $$URIError$1 = { +let $$URIError$1 = { instanceOf: instanceOf$7, isURIError: isURIError, fromJsExn: fromJsExn$7 @@ -220,76 +212,76 @@ var $$URIError$1 = { function classifyOpt(value) { if (isAssertionError(value)) { return { - TAG: "AssertionError", - _0: value - }; + TAG: "AssertionError", + _0: value + }; } else if (isEvalError(value)) { return { - TAG: "EvalError", - _0: value - }; + TAG: "EvalError", + _0: value + }; } else if (isRangeError(value)) { return { - TAG: "RangeError", - _0: value - }; + TAG: "RangeError", + _0: value + }; } else if (isReferenceError(value)) { return { - TAG: "ReferenceError", - _0: value - }; + TAG: "ReferenceError", + _0: value + }; } else if (isSyntaxError(value)) { return { - TAG: "SyntaxError", - _0: value - }; + TAG: "SyntaxError", + _0: value + }; } else if (isTypeError(value)) { return { - TAG: "TypeError", - _0: value - }; + TAG: "TypeError", + _0: value + }; } else if (isURIError(value)) { return { - TAG: "URIError", - _0: value - }; + TAG: "URIError", + _0: value + }; } else if (isError(value)) { return { - TAG: "Error", - _0: value - }; + TAG: "Error", + _0: value + }; } else { - return ; + return; } } function classifyExn(value) { - var err = classifyOpt(value); + let err = classifyOpt(value); if (err !== undefined) { return err; } else { - return PervasivesU.failwith("Unknown data type"); + return Pervasives.failwith("Unknown data type"); } } function classify(value) { - var err = classifyOpt(value); + let err = classifyOpt(value); if (err !== undefined) { return { - TAG: "Ok", - _0: err - }; + TAG: "Ok", + _0: err + }; } else { return { - TAG: "Error", - _0: value - }; + TAG: "Error", + _0: value + }; } } -var ErrorCodes = {}; +let ErrorCodes = {}; -exports.setStackTraceLimit = setStackTraceLimit$1; +exports.setStackTraceLimit = setStackTraceLimit; exports.$$Error = $$Error$1; exports.AssertionError = AssertionError; exports.$$EvalError = $$EvalError$1; diff --git a/src/Event.res b/src/Event.res index daf471d..3276bd7 100644 --- a/src/Event.res +++ b/src/Event.res @@ -24,28 +24,28 @@ type t<'listener, 'ty> external fromString: string => t<'a => 'b, 'ty> = "%identity" external fromString2: string => t<('a, 'b) => 'c, 'ty> = "%identity" external fromString3: string => t<('a, 'b, 'c) => 'd, 'ty> = "%identity" -external fromSymbol: Js.Types.symbol => t<'a => 'b, 'ty> = "%identity" -external fromSymbol2: Js.Types.symbol => t<('a, 'b) => 'c, 'ty> = "%identity" -external fromSymbol3: Js.Types.symbol => t<('a, 'b, 'c) => 'd, 'ty> = "%identity" +external fromSymbol: Symbol.t => t<'a => 'b, 'ty> = "%identity" +external fromSymbol2: Symbol.t => t<('a, 'b) => 'c, 'ty> = "%identity" +external fromSymbol3: Symbol.t => t<('a, 'b, 'c) => 'd, 'ty> = "%identity" external unsafeToString: t<'a => 'b, 'ty> => string = "%identity" external unsafeToString2: t<('a, 'b) => 'c, 'ty> => string = "%identity" external unsafeToString3: t<('a, 'b, 'c) => 'd, 'ty> => string = "%identity" -external unsafeToSymbol: t<'a => 'b, 'ty> => Js.Types.symbol = "%identity" -external unsafeToSymbol2: t<('a, 'b) => 'c, 'ty> => Js.Types.symbol = "%identity" -external unsafeToSymbol3: t<('a, 'b, 'c) => 'd, 'ty> => Js.Types.symbol = "%identity" +external unsafeToSymbol: t<'a => 'b, 'ty> => Symbol.t = "%identity" +external unsafeToSymbol2: t<('a, 'b) => 'c, 'ty> => Symbol.t = "%identity" +external unsafeToSymbol3: t<('a, 'b, 'c) => 'd, 'ty> => Symbol.t = "%identity" type case = | String(string) - | Symbol(Js.Types.symbol) + | Symbol(Symbol.t) | Unknown let classify = evt => - switch Js.typeof(evt) { - | "string" => String(unsafeToString(evt)) - | "symbol" => Symbol(unsafeToSymbol(evt)) + switch typeof(evt) { + | #string => String(unsafeToString(evt)) + | #symbol => Symbol(unsafeToSymbol(evt)) | _ => Unknown } let eq = (event1, event2) => - switch (Js.typeof(event1), Js.typeof(event2)) { - | ("string", "string") => Obj.magic(event1) === Obj.magic(event2) - | ("symbol", "symbol") => Obj.magic(event1) === Obj.magic(event2) + switch (typeof(event1), typeof(event2)) { + | (#string, #string) => Obj.magic(event1) === Obj.magic(event2) + | (#symbol, #symbol) => Obj.magic(event1) === Obj.magic(event2) | _ => false - } \ No newline at end of file + } diff --git a/src/Event.res.js b/src/Event.res.js new file mode 100644 index 0000000..9ab1865 --- /dev/null +++ b/src/Event.res.js @@ -0,0 +1,40 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + + +function classify(evt) { + let match = typeof evt; + if (match === "symbol") { + return { + TAG: "Symbol", + _0: evt + }; + } else if (match === "string") { + return { + TAG: "String", + _0: evt + }; + } else { + return "Unknown"; + } +} + +function eq(event1, event2) { + let match = typeof event1; + let match$1 = typeof event2; + if (match === "symbol") { + if (match$1 === "symbol") { + return event1 === event2; + } else { + return false; + } + } else if (match === "string" && match$1 === "string") { + return event1 === event2; + } else { + return false; + } +} + +exports.classify = classify; +exports.eq = eq; +/* No side effect */ diff --git a/src/EventEmitter.res b/src/EventEmitter.res index 61c7cbe..c63a8ec 100644 --- a/src/EventEmitter.res +++ b/src/EventEmitter.res @@ -19,7 +19,7 @@ module Impl = ( @send external emit: (T.t, Event.t<'a => 'b, T.t>, 'a) => bool = "emit" - @get external errorMonitor: T.t => Js.Types.symbol = "errorMonitor" + @get external errorMonitor: T.t => Symbol.t = "errorMonitor" @send external eventNames: (T.t, Event.t<'a => 'b, T.t>) => array 'b, T.t>> = "eventNames" @@ -137,8 +137,6 @@ module Impl = ( ") module Make = () => { type t - include Impl({ - type t = t - }) + include Impl({type t = t}) @module("node:events") @new external make: unit => t = "EventEmitter" } diff --git a/lib/js/src/EventEmitter.bs.js b/src/EventEmitter.res.js similarity index 100% rename from lib/js/src/EventEmitter.bs.js rename to src/EventEmitter.res.js diff --git a/lib/js/src/Exports.bs.js b/src/Exports.res.js similarity index 100% rename from lib/js/src/Exports.bs.js rename to src/Exports.res.js diff --git a/src/Fs.res b/src/Fs.res index ed7f9ff..7e376e3 100644 --- a/src/Fs.res +++ b/src/Fs.res @@ -11,15 +11,15 @@ module Dirent = { module Dir = { type t = {path: string} - @send external close: t => Js.Promise.t = "close" + @send external close: t => promise = "close" @send - external closeWithCallback: (t, Js.nullable => unit) => unit = "close" + external closeWithCallback: (t, nullable => unit) => unit = "close" @send external closeSync: t => unit = "closeSync" @send - external read: t => Js.Promise.t> = "read" + external read: t => promise> = "read" @send - external readWithCallback: (t, (Js.Exn.t, Js.nullable) => unit) => unit = "read" - @send external readSync: t => Js.nullable = "readSync" + external readWithCallback: (t, (JsExn.t, nullable) => unit) => unit = "read" + @send external readSync: t => nullable = "readSync" } module Stats = { @@ -276,13 +276,13 @@ module FileHandle = { type t = {fd: fd} @send - external appendFile: (t, Buffer.t, appendFileOptions) => Js.Promise.t = "appendFile" + external appendFile: (t, Buffer.t, appendFileOptions) => promise = "appendFile" @send - external appendFileWith: (t, Buffer.t) => Js.Promise.t = "appendFile" - @send external chmod: (t, int) => Js.Promise.t = "chmod" - @send external chown: (t, int, int) => Js.Promise.t = "chown" - @send external close: t => Js.Promise.t = "close" - @send external datasync: t => Js.Promise.t = "datasync" + external appendFileWith: (t, Buffer.t) => promise = "appendFile" + @send external chmod: (t, int) => promise = "chmod" + @send external chown: (t, int, int) => promise = "chown" + @send external close: t => promise = "close" + @send external datasync: t => promise = "datasync" type readInfo = { bytesRead: int, @@ -290,28 +290,23 @@ module FileHandle = { } @send - external read: ( - t, - Buffer.t, - ~offset: int, - ~length: int, - ~position: int, - ) => Js.Promise.t = "read" - @send external readFile: t => Js.Promise.t = "readFile" + external read: (t, Buffer.t, ~offset: int, ~length: int, ~position: int) => promise = + "read" + @send external readFile: t => promise = "readFile" @send - external readFileWith: (t, readFileOptions) => Js.Promise.t = "readFile" + external readFileWith: (t, readFileOptions) => promise = "readFile" - @send external stat: t => Js.Promise.t = "stat" - @send external sync: t => Js.Promise.t = "sync" + @send external stat: t => promise = "stat" + @send external sync: t => promise = "sync" @send - external truncate: (t, ~length: int=?, unit) => Js.Promise.t = "truncate" + external truncate: (t, ~length: int=?) => promise = "truncate" type writeInfo = {bytesWritten: int} @send - external write: (t, Buffer.t) => Js.Promise.t = "write" + external write: (t, Buffer.t) => promise = "write" @send - external writeOffset: (t, Buffer.t, ~offset: int) => Js.Promise.t = "write" + external writeOffset: (t, Buffer.t, ~offset: int) => promise = "write" @send external writeRange: ( t, @@ -319,23 +314,23 @@ module FileHandle = { ~offset: int, ~length: int, ~position: int, - ) => Js.Promise.t = "write" + ) => promise = "write" @send - external writeFile: (t, Buffer.t) => Js.Promise.t = "writeFile" + external writeFile: (t, Buffer.t) => promise = "writeFile" @send - external writeFileWith: (t, Buffer.t, writeFileOptions) => Js.Promise.t = "writeFile" + external writeFileWith: (t, Buffer.t, writeFileOptions) => promise = "writeFile" } module PromiseAPI = { @module("node:fs") @scope("promises") - external access: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => Js.Promise.t = + external access: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => promise = "access" @module("node:fs") @scope("promises") external accessWithMode: ( @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~mode: int, - ) => Js.Promise.t = "access" + ) => promise = "access" type appendFileStrOptions = { encoding?: string, @@ -346,14 +341,14 @@ module PromiseAPI = { external appendFile: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t) | #Handle(FileHandle.t)], ~data: string, - ) => Js.Promise.t = "appendFile" + ) => promise = "appendFile" @module("node:fs") @scope("promises") external appendFileWith: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t) | #Handle(FileHandle.t)], ~data: string, ~options: appendFileStrOptions, - ) => Js.Promise.t = "appendFile" + ) => promise = "appendFile" type appendFileBufferOptions = { mode?: int, @@ -363,61 +358,60 @@ module PromiseAPI = { external appendFileBuffer: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t) | #Handle(FileHandle.t)], ~data: Buffer.t, - ) => Js.Promise.t = "appendFile" + ) => promise = "appendFile" @module("node:fs") @scope("promises") external appendFileBufferWith: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t) | #Handle(FileHandle.t)], ~data: Buffer.t, ~options: appendFileBufferOptions, - ) => Js.Promise.t = "appendFile" + ) => promise = "appendFile" @module("node:fs") @scope("promises") external chmod: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~mode: int, - ) => Js.Promise.t = "chmod" + ) => promise = "chmod" @module("node:fs") @scope("promises") external chown: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~uid: int, ~gid: int, - ) => Js.Promise.t = "chown" + ) => promise = "chown" @module("node:fs") @scope("promises") external copyFile: ( ~src: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~dest: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], - ) => Js.Promise.t = "copyFile" + ) => promise = "copyFile" @module("node:fs") @scope("promises") external copyFileFlag: ( ~src: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~dest: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~flags: Constants.t, - ) => Js.Promise.t = "copyFile" + ) => promise = "copyFile" @module("node:fs") @scope("promises") - external lchmod: (~path: @unwrap [#Str(string)], ~mode: int) => Js.Promise.t = "lchmod" + external lchmod: (~path: @unwrap [#Str(string)], ~mode: int) => promise = "lchmod" @module("node:fs") @scope("promises") external link: ( ~existingPath: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~newPath: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], - ) => Js.Promise.t = "link" + ) => promise = "link" type statOptions = {bigint: int} @module("node:fs") @scope("promises") - external lstat: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => Js.Promise.t< - Stats.t, - > = "lstat" + external lstat: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => promise = + "lstat" @module("node:fs") @scope("promises") external lstatBigInt: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~options: statOptions, - ) => Js.Promise.t = "lstat" + ) => promise = "lstat" type mkdirOptions = { recursive?: bool, @@ -425,102 +419,101 @@ module PromiseAPI = { } @module("node:fs") @scope("promises") - external mkdir: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => Js.Promise.t = + external mkdir: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => promise = "mkdir" @module("node:fs") @scope("promises") external mkdirWith: ( @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], mkdirOptions, - ) => Js.Promise.t = "mkdir" + ) => promise = "mkdir" type mkdtempOptions = {encoding?: string} @module("node:fs") @scope("promises") - external mkdtemp: string => Js.Promise.t = "mkdtemp" + external mkdtemp: string => promise = "mkdtemp" @module("node:fs") @scope("promises") external mkdtempWith: ( ~prefix: string, ~mkdtempOptions: @unwrap [#Str(string) | #Option(mkdtempOptions)], - ) => Js.Promise.t = "mkddtemp" + ) => promise = "mkddtemp" @module("node:fs") @scope("promises") external open_: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~flags: Flag.t, - ) => Js.Promise.t = "open" + ) => promise = "open" @module("node:fs") @scope("promises") external openWithMode: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~flags: Flag.t, ~mode: int, - ) => Js.Promise.t = "open" + ) => promise = "open" @module("node:fs") @scope("promises") - external stat: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => Js.Promise.t = + external stat: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)] => promise = "lstat" @module("node:fs") @scope("promises") external statWith: ( ~path: @unwrap [#Str(string) | #Buffer(Buffer.t) | #URL(Url.t)], ~options: statOptions, - ) => Js.Promise.t = "lstat" + ) => promise = "lstat" } @module("node:fs") @scope("promises") -external access: string => Js.Promise.t = "access" +external access: string => promise = "access" @module("node:fs") @scope("promises") -external accessWithMode: (string, ~mode: int) => Js.Promise.t = "access" +external accessWithMode: (string, ~mode: int) => promise = "access" @module("node:fs") @scope("promises") -external appendFile: (string, string, appendFileOptions) => Js.Promise.t = "appendFile" +external appendFile: (string, string, appendFileOptions) => promise = "appendFile" @module("node:fs") @scope("promises") -external appendFileWith: (string, string, appendFileOptions) => Js.Promise.t = "appendFile" +external appendFileWith: (string, string, appendFileOptions) => promise = "appendFile" type appendFileBufferOptions = {mode?: int, flag?: Flag.t} @module("node:fs") @scope("promises") -external appendFileBuffer: (string, Buffer.t) => Js.Promise.t = "appendFile" +external appendFileBuffer: (string, Buffer.t) => promise = "appendFile" @module("node:fs") @scope("promises") -external appendFileBufferWith: (string, Buffer.t, appendFileBufferOptions) => Js.Promise.t = +external appendFileBufferWith: (string, Buffer.t, appendFileBufferOptions) => promise = "appendFile" @module("node:fs") @scope("promises") -external chmod: (string, ~mode: int) => Js.Promise.t = "chmod" +external chmod: (string, ~mode: int) => promise = "chmod" @module("node:fs") @scope("promises") -external chown: (string, ~uid: int, ~gid: int) => Js.Promise.t = "chown" +external chown: (string, ~uid: int, ~gid: int) => promise = "chown" @module("node:fs") @scope("promises") -external copyFile: (string, ~dest: string) => Js.Promise.t = "copyFile" +external copyFile: (string, ~dest: string) => promise = "copyFile" @module("node:fs") @scope("promises") -external copyFileFlag: (string, ~dest: string, ~flags: Constants.t) => Js.Promise.t = - "copyFile" +external copyFileFlag: (string, ~dest: string, ~flags: Constants.t) => promise = "copyFile" @module("node:fs") @scope("promises") -external lchmod: (string, ~mode: int) => Js.Promise.t = "lchmod" +external lchmod: (string, ~mode: int) => promise = "lchmod" @module("node:fs") @scope("promises") -external link: (~existingPath: string, ~newPath: string) => Js.Promise.t = "link" +external link: (~existingPath: string, ~newPath: string) => promise = "link" @module("node:fs") @scope("promises") -external lstat: string => Js.Promise.t = "lstat" +external lstat: string => promise = "lstat" @module("node:fs") @scope("promises") -external lstatBigInt: (string, bool) => Js.Promise.t = "lstat" +external lstatBigInt: (string, bool) => promise = "lstat" type mkdirOptions = {recursive?: bool, mode?: int} @module("node:fs") @scope("promises") -external mkdir: (string, mkdirOptions) => Js.Promise.t = "mkdir" +external mkdir: (string, mkdirOptions) => promise = "mkdir" @module("node:fs") @scope("promises") -external mkdirWith: (string, mkdirOptions) => Js.Promise.t = "mkdir" +external mkdirWith: (string, mkdirOptions) => promise = "mkdir" @module("node:fs") external mkdirSync: string => unit = "mkdirSync" @@ -531,16 +524,16 @@ external mkdirSyncWith: (string, mkdirOptions) => unit = "mkdirSync" type mkdtempOptions = {encoding?: string} @module("node:fs") @scope("promises") -external mkdtemp: string => Js.Promise.t = "mkddtemp" +external mkdtemp: string => promise = "mkddtemp" @module("node:fs") @scope("promises") -external mkdtempWith: (string, mkdtempOptions) => Js.Promise.t = "mkddtemp" +external mkdtempWith: (string, mkdtempOptions) => promise = "mkddtemp" @module("node:fs") @scope("promises") -external open_: (string, Flag.t) => Js.Promise.t = "open" +external open_: (string, Flag.t) => promise = "open" @module("node:fs") @scope("promises") -external openWithMode: (string, Flag.t, ~mode: int) => Js.Promise.t = "open" +external openWithMode: (string, Flag.t, ~mode: int) => promise = "open" module WriteStream = { type kind<'w> = [Stream.writable<'w> | #FileSystem] @@ -555,16 +548,13 @@ module WriteStream = { @send external pending: subtype<'w, [> kind<'w>]> => bool = "pending" @send - external onOpen: ( - subtype<'w, [> kind<'w>]> as 'stream', - @as("open") _, - @uncurry fd => unit, - ) => 'stream = "on" + external onOpen: (subtype<'w, [> kind<'w>]> as 'stream', @as("open") _, fd => unit) => 'stream = + "on" @send external onReady: ( subtype<'w, [> kind<'w>]> as 'stream, @as("ready") _, - @uncurry unit => unit, + unit => unit, ) => 'stream = "on" } include Impl @@ -583,16 +573,13 @@ module ReadStream = { @send external pending: subtype<'r, [> kind<'r>]> => bool = "pending" @send - external onOpen: ( - subtype<'r, [> kind<'r>]> as 'stream, - @as("open") _, - @uncurry fd => unit, - ) => 'stream = "on" + external onOpen: (subtype<'r, [> kind<'r>]> as 'stream, @as("open") _, fd => unit) => 'stream = + "on" @send external onReady: ( subtype<'r, [> kind<'r>]> as 'stream, @as("ready") _, - @uncurry unit => unit, + unit => unit, ) => 'stream = "on" } include Impl diff --git a/lib/js/src/Fs.bs.js b/src/Fs.res.js similarity index 66% rename from lib/js/src/Fs.bs.js rename to src/Fs.res.js index 11990b7..f5d6353 100644 --- a/lib/js/src/Fs.bs.js +++ b/src/Fs.res.js @@ -2,29 +2,29 @@ 'use strict'; -var Dirent = {}; +let Dirent = {}; -var Dir = {}; +let Dir = {}; -var Stats = {}; +let Stats = {}; -var Constants = {}; +let Constants = {}; -var Flag = {}; +let Flag = {}; -var FileHandle = {}; +let FileHandle = {}; -var PromiseAPI = {}; +let PromiseAPI = {}; -var Impl = {}; +let Impl = {}; -var WriteStream = { +let WriteStream = { Impl: Impl }; -var Impl$1 = {}; +let Impl$1 = {}; -var ReadStream = { +let ReadStream = { Impl: Impl$1 }; diff --git a/lib/js/src/Global.bs.js b/src/Global.res.js similarity index 100% rename from lib/js/src/Global.bs.js rename to src/Global.res.js diff --git a/src/Http.res b/src/Http.res index 92ec1f6..3c77454 100644 --- a/src/Http.res +++ b/src/Http.res @@ -101,35 +101,20 @@ module IncomingMessage = { module Events = { include Stream.Readable.Events @send - external onAborted: ( - subtype<'r, 'a>, - @as("aborted") _, - @uncurry unit => unit, - ) => subtype<'r, 'a> = "on" - @send - external onClose: (subtype<'r, 'a>, @as("close") _, @uncurry unit => unit) => subtype<'r, 'a> = - "on" + external onAborted: (subtype<'r, 'a>, @as("aborted") _, unit => unit) => subtype<'r, 'a> = "on" @send - external offAborted: ( - subtype<'r, 'a>, - @as("aborted") _, - @uncurry unit => unit, - ) => subtype<'r, 'a> = "off" + external onClose: (subtype<'r, 'a>, @as("close") _, unit => unit) => subtype<'r, 'a> = "on" @send - external offClose: (subtype<'r, 'a>, @as("close") _, @uncurry unit => unit) => subtype<'r, 'a> = + external offAborted: (subtype<'r, 'a>, @as("aborted") _, unit => unit) => subtype<'r, 'a> = "off" @send - external onAbortedOnce: ( - subtype<'r, 'a>, - @as("aborted") _, - @uncurry unit => unit, - ) => subtype<'r, 'a> = "once" + external offClose: (subtype<'r, 'a>, @as("close") _, unit => unit) => subtype<'r, 'a> = "off" @send - external onCloseOnce: ( - subtype<'r, 'a>, - @as("close") _, - @uncurry unit => unit, - ) => subtype<'r, 'a> = "once" + external onAbortedOnce: (subtype<'r, 'a>, @as("aborted") _, unit => unit) => subtype<'r, 'a> = + "once" + @send + external onCloseOnce: (subtype<'r, 'a>, @as("close") _, unit => unit) => subtype<'r, 'a> = + "once" } module Impl = { @@ -149,7 +134,7 @@ module IncomingMessage = { @get external complete: subtype<'r, 'a> => bool = "complete" @send external destroy: subtype<'r, 'a> => unit = "destroy" @send - external destroyWithError: (subtype<'r, 'a>, Js.Exn.t) => bool = "destroy" + external destroyWithError: (subtype<'r, 'a>, JsExn.t) => bool = "destroy" @send external setTimeout: (subtype<'r, 'a>, int) => subtype<'r, 'a> = "setTimeout" @send @@ -163,7 +148,7 @@ module IncomingMessage = { @get external statusMessage: subtype<'r, 'a> => string = "statusMessage" @get - external trailers: subtype<'r, 'a> => Js.Dict.t = "trailers" + external trailers: subtype<'r, 'a> => dict = "trailers" } include Impl } @@ -185,11 +170,8 @@ module ClientRequest = { module Events = { include Stream.Duplex.Events @send - external onAbort: ( - subtype<'w, 'r, 'a>, - @as("abort") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'a> = "on" + external onAbort: (subtype<'w, 'r, 'a>, @as("abort") _, unit => unit) => subtype<'w, 'r, 'a> = + "on" @send external onConnect: ( subtype<'w, 'r, 'a>, @@ -200,45 +182,42 @@ module ClientRequest = { external onContinue: ( subtype<'w, 'r, 'a>, @as("continue") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "on" @send external onInformation: ( subtype<'w, 'r, 'a>, @as("information") _, - @uncurry information => unit, + information => unit, ) => subtype<'w, 'r, 'a> = "on" @send external onResponse: ( subtype<'w, 'r, 'a>, @as("response") _, - @uncurry IncomingMessage.t => unit, + IncomingMessage.t => unit, ) => subtype<'w, 'r, 'a> = "on" @send external onSocket: ( subtype<'w, 'r, 'a>, @as("socket") _, - @uncurry Net.TcpSocket.t => unit, + Net.TcpSocket.t => unit, ) => subtype<'w, 'r, 'a> = "on" @send external onTimeout: ( subtype<'w, 'r, 'a>, @as("timeout") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "on" @send external onUpgrade: ( subtype<'w, 'r, 'a>, @as("upgrade") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Buffer.t) => unit, + (IncomingMessage.t, Net.TcpSocket.t, Buffer.t) => unit, ) => subtype<'w, 'r, 'a> = "on" @send - external offAbort: ( - subtype<'w, 'r, 'a>, - @as("abort") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'a> = "off" + external offAbort: (subtype<'w, 'r, 'a>, @as("abort") _, unit => unit) => subtype<'w, 'r, 'a> = + "off" @send external offConnect: ( subtype<'w, 'r, 'a>, @@ -249,44 +228,44 @@ module ClientRequest = { external offContinue: ( subtype<'w, 'r, 'a>, @as("continue") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "off" @send external offInformation: ( subtype<'w, 'r, 'a>, @as("information") _, - @uncurry information => unit, + information => unit, ) => subtype<'w, 'r, 'a> = "off" @send external offResponse: ( subtype<'w, 'r, 'a>, @as("response") _, - @uncurry IncomingMessage.t => unit, + IncomingMessage.t => unit, ) => subtype<'w, 'r, 'a> = "off" @send external offSocket: ( subtype<'w, 'r, 'a>, @as("socket") _, - @uncurry Net.TcpSocket.t => unit, + Net.TcpSocket.t => unit, ) => subtype<'w, 'r, 'a> = "off" @send external offTimeout: ( subtype<'w, 'r, 'a>, @as("timeout") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "off" @send external offUpgrade: ( subtype<'w, 'r, 'a>, @as("upgrade") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Buffer.t) => unit, + (IncomingMessage.t, Net.TcpSocket.t, Buffer.t) => unit, ) => subtype<'w, 'r, 'a> = "off" @send external onAbortOnce: ( subtype<'w, 'r, 'a>, @as("abort") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onConnectOnce: ( @@ -298,37 +277,37 @@ module ClientRequest = { external onContinueOnce: ( subtype<'w, 'r, 'a>, @as("continue") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onInformationOnce: ( subtype<'w, 'r, 'a>, @as("information") _, - @uncurry information => unit, + information => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onResponseOnce: ( subtype<'w, 'r, 'a>, @as("response") _, - @uncurry IncomingMessage.t => unit, + IncomingMessage.t => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onSocketOnce: ( subtype<'w, 'r, 'a>, @as("socket") _, - @uncurry Net.TcpSocket.t => unit, + Net.TcpSocket.t => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onTimeoutOnce: ( subtype<'w, 'r, 'a>, @as("timeout") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onUpgradeOnce: ( subtype<'w, 'r, 'a>, @as("upgrade") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Buffer.t) => unit, + (IncomingMessage.t, Net.TcpSocket.t, Buffer.t) => unit, ) => subtype<'w, 'r, 'a> = "once" } module Impl = { @@ -388,40 +367,31 @@ module ServerResponse = { module Events = { include Stream.Duplex.Events @send - external onClose: ( - subtype<'w, 'r, 'a>, - @as("close") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'a> = "on" + external onClose: (subtype<'w, 'r, 'a>, @as("close") _, unit => unit) => subtype<'w, 'r, 'a> = + "on" @send - external onFinish: ( - subtype<'w, 'r, 'a>, - @as("finish") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'a> = "on" + external onFinish: (subtype<'w, 'r, 'a>, @as("finish") _, unit => unit) => subtype<'w, 'r, 'a> = + "on" @send - external offClose: ( - subtype<'w, 'r, 'a>, - @as("close") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'a> = "off" + external offClose: (subtype<'w, 'r, 'a>, @as("close") _, unit => unit) => subtype<'w, 'r, 'a> = + "off" @send external offFinish: ( subtype<'w, 'r, 'a>, @as("finish") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "off" @send external onCloseOnce: ( subtype<'w, 'r, 'a>, @as("close") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "once" @send external onFinishOnce: ( subtype<'w, 'r, 'a>, @as("finish") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'a> = "once" } module Impl = { @@ -522,133 +492,127 @@ module Server = { external onCheckContinue: ( subtype<'a>, @as("checkContinue") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "on" @send external onCheckExpectation: ( subtype<'a>, @as("checkExpectation") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "on" @send external onClientError: ( subtype<'a>, @as("clientError") _, - @uncurry (Js.Exn.t, Net.TcpSocket.t) => unit, + (JsExn.t, Net.TcpSocket.t) => unit, ) => subtype<'a> = "on" @send external onConnect: ( subtype<'a>, @as("connect") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Js.nullable) => unit, + (IncomingMessage.t, Net.TcpSocket.t, nullable) => unit, ) => subtype<'a> = "on" @send external onRequest: ( subtype<'a>, @as("request") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "on" @send external onUpgrade: ( subtype<'a>, @as("upgrade") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Js.nullable) => unit, + (IncomingMessage.t, Net.TcpSocket.t, nullable) => unit, ) => subtype<'a> = "on" @send - external onTimeout: ( - subtype<'a>, - @as("timeout") _, - @uncurry Net.TcpSocket.t => unit, - ) => subtype<'a> = "on" + external onTimeout: (subtype<'a>, @as("timeout") _, Net.TcpSocket.t => unit) => subtype<'a> = + "on" @send external offCheckContinue: ( subtype<'a>, @as("checkContinue") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "off" @send external offCheckExpectation: ( subtype<'a>, @as("checkExpectation") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "off" @send external offClientError: ( subtype<'a>, @as("clientError") _, - @uncurry (Js.Exn.t, Net.TcpSocket.t) => unit, + (JsExn.t, Net.TcpSocket.t) => unit, ) => subtype<'a> = "off" @send external offConnect: ( subtype<'a>, @as("connect") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Js.nullable) => unit, + (IncomingMessage.t, Net.TcpSocket.t, nullable) => unit, ) => subtype<'a> = "off" @send external offRequest: ( subtype<'a>, @as("request") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "off" @send external offUpgrade: ( subtype<'a>, @as("upgrade") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Js.nullable) => unit, + (IncomingMessage.t, Net.TcpSocket.t, nullable) => unit, ) => subtype<'a> = "off" @send - external offTimeout: ( - subtype<'a>, - @as("timeout") _, - @uncurry Net.TcpSocket.t => unit, - ) => subtype<'a> = "off" + external offTimeout: (subtype<'a>, @as("timeout") _, Net.TcpSocket.t => unit) => subtype<'a> = + "off" @send external onCheckContinueOnce: ( subtype<'a>, @as("checkContinue") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "once" @send external onCheckExpectationOnce: ( subtype<'a>, @as("checkExpectation") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "once" @send external onClientErrorOnce: ( subtype<'a>, @as("clientError") _, - @uncurry (Js.Exn.t, Net.TcpSocket.t) => unit, + (JsExn.t, Net.TcpSocket.t) => unit, ) => subtype<'a> = "once" @send external onConnectOnce: ( subtype<'a>, @as("connect") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Js.nullable) => unit, + (IncomingMessage.t, Net.TcpSocket.t, nullable) => unit, ) => subtype<'a> = "once" @send external onRequestOnce: ( subtype<'a>, @as("request") _, - @uncurry (IncomingMessage.t, ServerResponse.t) => unit, + (IncomingMessage.t, ServerResponse.t) => unit, ) => subtype<'a> = "once" @send external onUpgradeOnce: ( subtype<'a>, @as("upgrade") _, - @uncurry (IncomingMessage.t, Net.TcpSocket.t, Js.nullable) => unit, + (IncomingMessage.t, Net.TcpSocket.t, nullable) => unit, ) => subtype<'a> = "once" @send external onTimeoutOnce: ( subtype<'a>, @as("timeout") _, - @uncurry Net.TcpSocket.t => unit, + Net.TcpSocket.t => unit, ) => subtype<'a> = "once" } module Impl = { include Events @send - external setTimeout: (subtype<'a>, int, @uncurry Net.Socket.t => unit) => unit = "setTimeout" + external setTimeout: (subtype<'a>, int, Net.Socket.t => unit) => unit = "setTimeout" @get external timeout: subtype<'a> => int = "timeout" @send external keepAliveTimeout: (subtype<'a>, int) => unit = "keepAliveTimeout" @@ -656,7 +620,7 @@ module Server = { } @send - external listen: (t, ~port: int, ~host: string, ~callback: unit => unit=?, unit) => t = "listen" + external listen: (t, ~port: int, ~host: string, ~callback: unit => unit=?) => t = "listen" include Impl } @@ -668,8 +632,7 @@ type createServerOptions = { } @module("node:http") -external createServer: (@uncurry (IncomingMessage.t, ServerResponse.t) => unit) => Server.t = - "createServer" +external createServer: ((IncomingMessage.t, ServerResponse.t) => unit) => Server.t = "createServer" @module("node:http") external createServerWithOptions: ( @@ -679,7 +642,7 @@ external createServerWithOptions: ( @module("node:http") external _METHODS: array = "METHODS" @module("node:http") -external _STATUS_CODES: Js.Dict.t = "STATUS_CODES" +external _STATUS_CODES: dict = "STATUS_CODES" type requestOptions = { agent?: Agent.t, @@ -691,7 +654,7 @@ type requestOptions = { host?: string, hostName?: string, localAddress?: string, - lookup?: (string, Dns.options, (Js.Exn.t, string, int) => unit) => string, + lookup?: (string, Dns.options, (JsExn.t, string, int) => unit) => string, maxHeaderSize?: int, method?: string, path?: string, @@ -752,7 +715,7 @@ external getUrlWithOptionsCallback: ( @module("node:http") external globalAgent: Agent.t = "globalAgent" @module("node:http") external maxHeaderSize: int = "maxHeaderSize" -type statusCodes = Js.Dict.t +type statusCodes = dict @module("node:http") external _STATUS_CODES: statusCodes = "STATUS_CODES" type methods = array diff --git a/lib/js/src/Http.bs.js b/src/Http.res.js similarity index 60% rename from lib/js/src/Http.bs.js rename to src/Http.res.js index 16703d2..6c2f47d 100644 --- a/lib/js/src/Http.bs.js +++ b/src/Http.res.js @@ -1,42 +1,42 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var Net$NodeJs = require("./Net.bs.js"); +let Net$NodeJs = require("./Net.res.js"); -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; -var IncomingMessage = { +let IncomingMessage = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Impl$1 = {}; +let Impl$1 = {}; -var ClientRequest = { +let ClientRequest = { Events: Events$1, Impl: Impl$1 }; -var Events$2 = {}; +let Events$2 = {}; -var Impl$2 = {}; +let Impl$2 = {}; -var ServerResponse = { +let ServerResponse = { Events: Events$2, Impl: Impl$2 }; -var Agent = {}; +let Agent = {}; -var Events$3 = {}; +let Events$3 = {}; -var Impl$3 = {}; +let Impl$3 = {}; -var Server = { +let Server = { Events: Events$3, Impl: Impl$3 }; diff --git a/src/Http2.res b/src/Http2.res index 6c5abf5..c8e056e 100644 --- a/src/Http2.res +++ b/src/Http2.res @@ -65,52 +65,50 @@ module ServerHttp2Stream = { module Http2Session = { type t @send - external onClose: (t, @as("close") _, @uncurry unit => unit) => t = "on" + external onClose: (t, @as("close") _, unit => unit) => t = "on" @send - external onConnect: (t, @as("connect") _, @uncurry (t, Net.Socket.t) => unit) => t = "on" + external onConnect: (t, @as("connect") _, (t, Net.Socket.t) => unit) => t = "on" @send - external onError: (t, @as("error") _, @uncurry Js.Exn.t => unit) => t = "on" + external onError: (t, @as("error") _, JsExn.t => unit) => t = "on" @send external onFrameError: ( t, @as("frameError") _, - (@uncurry ~type_: int, ~errorCode: int, ~streamId: int) => unit, + (~type_: int, ~errorCode: int, ~streamId: int) => unit, ) => t = "on" @send external onGoAway: ( t, @as("goAway") _, - (@uncurry ~errorCode: int, ~lastStreamId: int, Buffer.t) => unit, + (~errorCode: int, ~lastStreamId: int, Buffer.t) => unit, ) => t = "on" @send - external onLocalSettings: (t, @as("localSettings") _, @uncurry settingsObject => unit) => t = "on" + external onLocalSettings: (t, @as("localSettings") _, settingsObject => unit) => t = "on" @send - external onPing: (t, @as("ping") _, @uncurry Buffer.t => unit) => t = "on" + external onPing: (t, @as("ping") _, Buffer.t => unit) => t = "on" @send - external onRemoteSettings: (t, @as("remoteSettings") _, @uncurry settingsObject => unit) => t = - "on" + external onRemoteSettings: (t, @as("remoteSettings") _, settingsObject => unit) => t = "on" @send external onStream: ( t, @as("stream") _, - @uncurry (t, {.."status": string, "content-type": string}, int, array<{..}>) => unit, + (t, {.."status": string, "content-type": string}, int, array<{..}>) => unit, ) => t = "on" @send - external onTimeout: (t, @as("timeout") _, @uncurry unit => unit) => t = "on" + external onTimeout: (t, @as("timeout") _, unit => unit) => t = "on" @get @return(nullable) external alpnProtocol: t => option = "alpnProtocol" @send external close: t => unit = "close" @get external closed: t => bool = "closed" @send external destroy: t => unit = "destroy" - @send external destroyWithError: (t, Js.Exn.t) => unit = "destroy" + @send external destroyWithError: (t, JsExn.t) => unit = "destroy" @send external destroyWithCode: (t, int) => unit = "destroy" @get external destroyed: t => bool = "destroyed" @get @return(nullable) external encrypted: t => option = "encrypted" @send external goaway: t => unit = "goaway" @send - external goawayWith: (t, ~code: int=?, ~lastStreamId: int=?, ~data: Buffer.t=?, unit) => unit = - "goaway" + external goawayWith: (t, ~code: int=?, ~lastStreamId: int=?, ~data: Buffer.t=?) => unit = "goaway" @get external localSettings: t => { "headerTableSize": int, @@ -125,13 +123,10 @@ module Http2Session = { external originSet: t => option> = "originSet" @get external pendingSettingsAck: t => bool = "pendingSettingsAck" @send - external ping: (t, (Js.Nullable.t, int, Buffer.t) => unit) => bool = "ping" + external ping: (t, (nullable, int, Buffer.t) => unit) => bool = "ping" @send - external pingWith: ( - t, - ~payload: Buffer.t, - (Js.Nullable.t, int, Buffer.t) => unit, - ) => bool = "ping" + external pingWith: (t, ~payload: Buffer.t, (nullable, int, Buffer.t) => unit) => bool = + "ping" @send external ref: t => unit = "ref" @get external remoteSettings: t => { @@ -161,7 +156,7 @@ module Http2Session = { external settings: ( t, settingsObject, - ~callback: (Js.Null.t, settingsObject, int) => unit=?, + ~callback: (Null.t, settingsObject, int) => unit=?, ) => unit = "settings" @get external type_: t => int = "type" } @@ -201,23 +196,16 @@ module Http2ServerRequest = { module Impl = { include Stream.Readable.Impl @send - external onAborted: ( - subtype<'r, 'ty>, - @as("aborted") _, - @uncurry unit => unit, - ) => subtype<'r, 'ty> = "on" + external onAborted: (subtype<'r, 'ty>, @as("aborted") _, unit => unit) => subtype<'r, 'ty> = + "on" @send - external onClose: ( - subtype<'r, 'ty>, - @as("close") _, - @uncurry unit => unit, - ) => subtype<'r, 'ty> = "on" + external onClose: (subtype<'r, 'ty>, @as("close") _, unit => unit) => subtype<'r, 'ty> = "on" @get external aborted: subtype<'r, 'ty> => bool = "aborted" @get external authority: subtype<'r, 'ty> => string = "authority" @get external complete: subtype<'r, 'ty> => bool = "complete" @send external destroy: subtype<'r, 'ty> => unit = "destroy" @send - external destroyWithError: (subtype<'r, 'ty>, Js.Exn.t) => unit = "destroy" + external destroyWithError: (subtype<'r, 'ty>, JsExn.t) => unit = "destroy" @get external headers: subtype<'r, 'ty> => {..} = "headers" @get external httpVersion: subtype<'r, 'ty> => string = "httpVersion" @@ -247,9 +235,9 @@ module Http2ServerResponse = { module Impl = { include Stream.Duplex.Impl @send - external onClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "on" @send - external onFinish: (subtype<'ty>, @as("finish") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onFinish: (subtype<'ty>, @as("finish") _, unit => unit) => subtype<'ty> = "on" @send external setTrailers: (subtype<'ty>, {..}) => unit = "setTrailers" @send external end_: subtype<'ty> => unit = "end" @@ -297,7 +285,7 @@ module Http2ServerResponse = { external createPushResponse: ( subtype<'ty>, {..}, - @uncurry (Js.Exn.t, ServerHttp2Stream.t) => unit, + (JsExn.t, ServerHttp2Stream.t) => unit, ) => unit = "writeHead" } include Impl diff --git a/lib/js/src/Http2.bs.js b/src/Http2.res.js similarity index 63% rename from lib/js/src/Http2.bs.js rename to src/Http2.res.js index 05104b3..f796d34 100644 --- a/lib/js/src/Http2.bs.js +++ b/src/Http2.res.js @@ -2,50 +2,50 @@ 'use strict'; -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; -var Http2Stream = { +let Http2Stream = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Impl$1 = {}; +let Impl$1 = {}; -var ClientHttp2Stream = { +let ClientHttp2Stream = { Events: Events$1, Impl: Impl$1 }; -var Events$2 = {}; +let Events$2 = {}; -var Impl$2 = {}; +let Impl$2 = {}; -var ServerHttp2Stream = { +let ServerHttp2Stream = { Events: Events$2, Impl: Impl$2 }; -var Http2Session = {}; +let Http2Session = {}; -var Origin = {}; +let Origin = {}; -var ServerHttp2Session = { +let ServerHttp2Session = { Origin: Origin }; -var Impl$3 = {}; +let Impl$3 = {}; -var Http2ServerRequest = { +let Http2ServerRequest = { Impl: Impl$3 }; -var Impl$4 = {}; +let Impl$4 = {}; -var Http2ServerResponse = { +let Http2ServerResponse = { Impl: Impl$4 }; diff --git a/src/Https.res b/src/Https.res index fe27880..89baa09 100644 --- a/src/Https.res +++ b/src/Https.res @@ -19,14 +19,11 @@ module Agent = { type t module Events = { @send - external onKeylog: (t, @as("keylog") _, @uncurry (Buffer.t, Tls.TlsSocket.t) => unit) => t = - "on" + external onKeylog: (t, @as("keylog") _, (Buffer.t, Tls.TlsSocket.t) => unit) => t = "on" @send - external onKeylogOnce: (t, @as("keylog") _, @uncurry (Buffer.t, Tls.TlsSocket.t) => unit) => t = - "once" + external onKeylogOnce: (t, @as("keylog") _, (Buffer.t, Tls.TlsSocket.t) => unit) => t = "once" @send - external offKeylog: (t, @as("keylog") _, @uncurry (Buffer.t, Tls.TlsSocket.t) => unit) => t = - "off" + external offKeylog: (t, @as("keylog") _, (Buffer.t, Tls.TlsSocket.t) => unit) => t = "off" } include Events } @@ -83,7 +80,7 @@ external getUrlWithOptionsCallback: ( @module("node:https") external globalAgent: Agent.t = "globalAgent" @module("node:https") external maxHeaderSize: int = "maxHeaderSize" -type statusCodes = Js.Dict.t +type statusCodes = dict @module("node:https") external _STATUS_CODES: statusCodes = "STATUS_CODES" type methods = array diff --git a/lib/js/src/Https.bs.js b/src/Https.res.js similarity index 63% rename from lib/js/src/Https.bs.js rename to src/Https.res.js index a18a6fc..ab27543 100644 --- a/lib/js/src/Https.bs.js +++ b/src/Https.res.js @@ -1,20 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var Tls$NodeJs = require("./Tls.bs.js"); +let Tls$NodeJs = require("./Tls.res.js"); -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; -var HttpsServer = { +let HttpsServer = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Agent = { +let Agent = { Events: Events$1 }; diff --git a/src/Module.res b/src/Module.res index 0c894af..a7a2f3b 100644 --- a/src/Module.res +++ b/src/Module.res @@ -2,7 +2,7 @@ type rec t = { id: string, exports: Exports.t, // in REPL V4 it is `undefined` in CLI it can be `null` - parrent: Js.Nullable.t, + parrent: nullable, filename: string, loaded: bool, children: array, @@ -10,4 +10,4 @@ type rec t = { } @val -external module_: {"__cache": Js.Dict.t} = "module" +external module_: {"__cache": dict} = "module" diff --git a/lib/js/src/Module.bs.js b/src/Module.res.js similarity index 100% rename from lib/js/src/Module.bs.js rename to src/Module.res.js diff --git a/src/Net.res b/src/Net.res index 183ba4c..57b66a9 100644 --- a/src/Net.res +++ b/src/Net.res @@ -18,53 +18,38 @@ module Socket = { module Events = { @send - external onClose: ( - subtype<'w, 'r, 'ty>, - @as("close") _, - @uncurry bool => unit, - ) => subtype<'w, 'r, 'ty> = "on" + external onClose: (subtype<'w, 'r, 'ty>, @as("close") _, bool => unit) => subtype<'w, 'r, 'ty> = + "on" @send external onConnect: ( subtype<'w, 'r, 'ty>, @as("connect") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "on" @send - external onData: ( - subtype<'w, 'r, 'ty>, - @as("data") _, - @uncurry 'r => unit, - ) => subtype<'w, 'r, 'ty> = "on" + external onData: (subtype<'w, 'r, 'ty>, @as("data") _, 'r => unit) => subtype<'w, 'r, 'ty> = + "on" @send - external onDrain: ( - subtype<'w, 'r, 'ty>, - @as("drain") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'ty> = "on" + external onDrain: (subtype<'w, 'r, 'ty>, @as("drain") _, unit => unit) => subtype<'w, 'r, 'ty> = + "on" @send - external onEnd: ( - subtype<'w, 'r, 'ty>, - @as("end") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'ty> = "on" + external onEnd: (subtype<'w, 'r, 'ty>, @as("end") _, unit => unit) => subtype<'w, 'r, 'ty> = + "on" @send external onError: ( subtype<'w, 'r, 'ty>, @as("error") _, - @uncurry Js.Exn.t => unit, + JsExn.t => unit, ) => subtype<'w, 'r, 'ty> = "on" @send external onLookup: ( subtype<'w, 'r, 'ty>, @as("lookup") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "on" @send - external onReady: ( - subtype<'w, 'r, 'ty>, - @as("ready") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'ty> = "on" + external onReady: (subtype<'w, 'r, 'ty>, @as("ready") _, unit => unit) => subtype<'w, 'r, 'ty> = + "on" @send external onTimeout: ( subtype<'w, 'r, 'ty>, @@ -76,110 +61,98 @@ module Socket = { external offClose: ( subtype<'w, 'r, 'ty>, @as("close") _, - @uncurry bool => unit, + bool => unit, ) => subtype<'w, 'r, 'ty> = "off" @send external offConnect: ( subtype<'w, 'r, 'ty>, @as("connect") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "off" @send - external offData: ( - subtype<'w, 'r, 'ty>, - @as("data") _, - @uncurry 'r => unit, - ) => subtype<'w, 'r, 'ty> = "off" + external offData: (subtype<'w, 'r, 'ty>, @as("data") _, 'r => unit) => subtype<'w, 'r, 'ty> = + "off" @send external offDrain: ( subtype<'w, 'r, 'ty>, @as("drain") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "off" @send - external offEnd: ( - subtype<'w, 'r, 'ty>, - @as("end") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'ty> = "off" + external offEnd: (subtype<'w, 'r, 'ty>, @as("end") _, unit => unit) => subtype<'w, 'r, 'ty> = + "off" @send external offError: ( subtype<'w, 'r, 'ty>, @as("error") _, - @uncurry Js.Exn.t => unit, + JsExn.t => unit, ) => subtype<'w, 'r, 'ty> = "off" @send external offLookup: ( subtype<'w, 'r, 'ty>, @as("lookup") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "off" @send external offReady: ( subtype<'w, 'r, 'ty>, @as("ready") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "off" @send external offTimeout: ( subtype<'w, 'r, 'ty>, @as("timeout") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "off" @send external onCloseOnce: ( subtype<'w, 'r, 'ty>, @as("close") _, - @uncurry bool => unit, + bool => unit, ) => subtype<'w, 'r, 'ty> = "once" @send external onConnectOnce: ( subtype<'w, 'r, 'ty>, @as("connect") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "once" @send - external onDataOnce: ( - subtype<'w, 'r, 'ty>, - @as("data") _, - @uncurry 'r => unit, - ) => subtype<'w, 'r, 'ty> = "once" + external onDataOnce: (subtype<'w, 'r, 'ty>, @as("data") _, 'r => unit) => subtype<'w, 'r, 'ty> = + "once" @send external onDrainOnce: ( subtype<'w, 'r, 'ty>, @as("drain") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "once" @send - external onEndOnce: ( - subtype<'w, 'r, 'ty>, - @as("end") _, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'ty> = "once" + external onEndOnce: (subtype<'w, 'r, 'ty>, @as("end") _, unit => unit) => subtype<'w, 'r, 'ty> = + "once" @send external onErrorOnce: ( subtype<'w, 'r, 'ty>, @as("error") _, - @uncurry Js.Exn.t => unit, + JsExn.t => unit, ) => subtype<'w, 'r, 'ty> = "once" @send external onLookupOnce: ( subtype<'w, 'r, 'ty>, @as("lookup") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "once" @send external onReadyOnce: ( subtype<'w, 'r, 'ty>, @as("ready") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "once" @send external onTimeoutOnce: ( subtype<'w, 'r, 'ty>, @as("timeout") _, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "once" } @@ -195,7 +168,7 @@ module Socket = { external connecting: subtype<'w, 'r, 'ty> => bool = "connecting" @get external destroyed: subtype<'w, 'r, 'ty> => bool = "destroyed" @send - external destroy: (subtype<'w, 'r, 'ty>, ~error: option) => subtype<'w, 'r, 'ty> = + external destroy: (subtype<'w, 'r, 'ty>, ~error: option) => subtype<'w, 'r, 'ty> = "destroy" @get external localAddress: subtype<'w, 'r, 'ty> => string = "localAddress" @@ -233,25 +206,23 @@ module Socket = { external connectIcp: ( subtype<'w, 'r, [> kind<'w, 'r> | icp]> as 'icpSocket, ~path: string, - @uncurry unit => unit, + unit => unit, ) => 'icpSocket = "connect" @send external connectTcp: ( subtype<'w, 'r, [> kind<'w, 'r> | tcp]> as 'tcpSocket, ~port: int, ~host: string, - @uncurry unit => unit, + unit => unit, ) => 'tcpSocket = "connect" } include Impl - include EventEmitter.Impl({ - type t = t - }) + include EventEmitter.Impl({type t = t}) type options = {fd?: int, readable?: bool, writable?: bool} @module("node:net") @new - external make: (~options: options=?, unit) => t = "Socket" + external make: (~options: options=?) => t = "Socket" } module TcpSocket = { @@ -270,7 +241,7 @@ module TcpSocket = { subtype<'w, 'r, 'ty>, ~port: int, ~host: string, - @uncurry unit => unit, + unit => unit, ) => subtype<'w, 'r, 'ty> = "connect" } include Impl @@ -288,11 +259,8 @@ module IcpSocket = { module Impl = { include Socket.Impl @send - external connect: ( - subtype<'w, 'r, 'ty>, - ~path: string, - @uncurry unit => unit, - ) => subtype<'w, 'r, 'ty> = "connect" + external connect: (subtype<'w, 'r, 'ty>, ~path: string, unit => unit) => subtype<'w, 'r, 'ty> = + "connect" } include Impl @module("node:net") @new external make: unit => t = "Socket" @@ -305,66 +273,43 @@ module Server = { type t<'ty> = subtype<'ty> module Events = { @send - external onClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "on" @send - external onError: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onError: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "on" @send - external onConnection: ( - subtype<'ty>, - @as("connection") _, - @uncurry Socket.t => unit, - ) => subtype<'ty> = "on" + external onConnection: (subtype<'ty>, @as("connection") _, Socket.t => unit) => subtype<'ty> = + "on" @send - external onListening: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "on" + external onListening: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = "on" @send - external offClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "off" + external offClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "off" @send - external offError: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = "off" + external offError: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "off" @send - external offConnection: ( - subtype<'ty>, - @as("connection") _, - @uncurry Socket.t => unit, - ) => subtype<'ty> = "off" + external offConnection: (subtype<'ty>, @as("connection") _, Socket.t => unit) => subtype<'ty> = + "off" @send - external offListening: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "off" + external offListening: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = "off" @send - external onCloseOnce: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = - "once" + external onCloseOnce: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "once" @send - external onErrorOnce: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = - "once" + external onErrorOnce: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "once" @send external onConnectionOnce: ( subtype<'ty>, @as("connection") _, - @uncurry Socket.t => unit, + Socket.t => unit, ) => subtype<'ty> = "once" @send - external onListeningOnce: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "once" + external onListeningOnce: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = + "once" } module Impl = { include Events @send - external close: ( - subtype<'ty>, - ~callback: Js.nullable => unit=?, - unit, - ) => subtype<'ty> = "close" + external close: (subtype<'ty>, ~callback: nullable => unit=?) => subtype<'ty> = "close" @send - external getConnections: (subtype<'ty>, (Js.nullable, int) => unit) => subtype<'ty> = + external getConnections: (subtype<'ty>, (nullable, int) => unit) => subtype<'ty> = "getConnections" @set external setMaxConnections: (subtype<'ty>, int) => unit = "maxConnections" @@ -384,63 +329,49 @@ module TcpServer = { type supertype<'ty> = Server.subtype<[< kind] as 'ty> module Events = { @send - external onClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "on" @send - external onError: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onError: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "on" @send external onConnection: ( subtype<'ty>, @as("connection") _, - @uncurry TcpSocket.t => unit, + TcpSocket.t => unit, ) => subtype<'ty> = "on" @send - external onListening: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "on" + external onListening: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = "on" @send - external offClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "off" + external offClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "off" @send - external offError: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = "off" + external offError: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "off" @send external offConnection: ( subtype<'ty>, @as("connection") _, - @uncurry TcpSocket.t => unit, + TcpSocket.t => unit, ) => subtype<'ty> = "off" @send - external offListening: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "off" + external offListening: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = "off" @send - external onCloseOnce: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = - "once" + external onCloseOnce: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "once" @send - external onErrorOnce: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = - "once" + external onErrorOnce: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "once" @send external onConnectionOnce: ( subtype<'ty>, @as("connection") _, - @uncurry TcpSocket.t => unit, + TcpSocket.t => unit, ) => subtype<'ty> = "once" @send - external onListeningOnce: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "once" + external onListeningOnce: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = + "once" } module Impl = { include Events @send - external close: (subtype<'ty>, ~callback: Js.nullable => unit) => subtype<'ty> = - "close" + external close: (subtype<'ty>, ~callback: nullable => unit) => subtype<'ty> = "close" @send - external getConnections: (subtype<'ty>, (Js.nullable, int) => unit) => subtype<'ty> = + external getConnections: (subtype<'ty>, (nullable, int) => unit) => subtype<'ty> = "getConnections" @set external setMaxConnections: (subtype<'ty>, int) => unit = "maxConnections" @@ -471,63 +402,49 @@ module IcpServer = { type supertype<'ty> = Server.subtype<[< kind] as 'ty> module Events = { @send - external onClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "on" @send - external onError: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = "on" + external onError: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "on" @send external onConnection: ( subtype<'ty>, @as("connection") _, - @uncurry IcpSocket.t => unit, + IcpSocket.t => unit, ) => subtype<'ty> = "on" @send - external onListening: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "on" + external onListening: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = "on" @send - external offClose: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = "off" + external offClose: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "off" @send - external offError: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = "off" + external offError: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "off" @send external offConnection: ( subtype<'ty>, @as("connection") _, - @uncurry IcpSocket.t => unit, + IcpSocket.t => unit, ) => subtype<'ty> = "off" @send - external offListening: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "off" + external offListening: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = "off" @send - external onCloseOnce: (subtype<'ty>, @as("close") _, @uncurry unit => unit) => subtype<'ty> = - "once" + external onCloseOnce: (subtype<'ty>, @as("close") _, unit => unit) => subtype<'ty> = "once" @send - external onErrorOnce: (subtype<'ty>, @as("error") _, @uncurry unit => unit) => subtype<'ty> = - "once" + external onErrorOnce: (subtype<'ty>, @as("error") _, unit => unit) => subtype<'ty> = "once" @send external onConnectionOnce: ( subtype<'ty>, @as("connection") _, - @uncurry IcpSocket.t => unit, + IcpSocket.t => unit, ) => subtype<'ty> = "once" @send - external onListeningOnce: ( - subtype<'ty>, - @as("listening") _, - @uncurry unit => unit, - ) => subtype<'ty> = "once" + external onListeningOnce: (subtype<'ty>, @as("listening") _, unit => unit) => subtype<'ty> = + "once" } module Impl = { include Events @send - external close: (subtype<'ty>, ~callback: Js.nullable => unit) => subtype<'ty> = - "close" + external close: (subtype<'ty>, ~callback: nullable => unit) => subtype<'ty> = "close" @send - external getConnections: (subtype<'ty>, (Js.nullable, int) => unit) => subtype<'ty> = + external getConnections: (subtype<'ty>, (nullable, int) => unit) => subtype<'ty> = "getConnections" @set external setMaxConnections: (subtype<'ty>, int) => unit = "maxConnections" diff --git a/lib/js/src/Net.bs.js b/src/Net.res.js similarity index 58% rename from lib/js/src/Net.bs.js rename to src/Net.res.js index 0fb0db9..4454b1b 100644 --- a/lib/js/src/Net.bs.js +++ b/src/Net.res.js @@ -1,60 +1,60 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var EventEmitter$NodeJs = require("./EventEmitter.bs.js"); +let EventEmitter$NodeJs = require("./EventEmitter.res.js"); -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; EventEmitter$NodeJs.Impl({}); -var Socket = { +let Socket = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Impl$1 = {}; +let Impl$1 = {}; -var TcpSocket = { +let TcpSocket = { Events: Events$1, Impl: Impl$1 }; -var Events$2 = {}; +let Events$2 = {}; -var Impl$2 = {}; +let Impl$2 = {}; -var IcpSocket = { +let IcpSocket = { Events: Events$2, Impl: Impl$2 }; -var Events$3 = {}; +let Events$3 = {}; -var Impl$3 = {}; +let Impl$3 = {}; -var Server = { +let Server = { Events: Events$3, Impl: Impl$3 }; -var Events$4 = {}; +let Events$4 = {}; -var Impl$4 = {}; +let Impl$4 = {}; -var TcpServer = { +let TcpServer = { Events: Events$4, Impl: Impl$4 }; -var Events$5 = {}; +let Events$5 = {}; -var Impl$5 = {}; +let Impl$5 = {}; -var IcpServer = { +let IcpServer = { Events: Events$5, Impl: Impl$5 }; diff --git a/lib/js/src/Os.bs.js b/src/Os.res.js similarity index 100% rename from lib/js/src/Os.bs.js rename to src/Os.res.js diff --git a/lib/js/src/Path.bs.js b/src/Path.res.js similarity index 80% rename from lib/js/src/Path.bs.js rename to src/Path.res.js index b187788..3c36313 100644 --- a/lib/js/src/Path.bs.js +++ b/src/Path.res.js @@ -2,9 +2,9 @@ 'use strict'; -var Posix = {}; +let Posix = {}; -var Win32 = {}; +let Win32 = {}; exports.Posix = Posix; exports.Win32 = Win32; diff --git a/src/PerfHooks.res b/src/PerfHooks.res index 3082a11..7ac6c0c 100644 --- a/src/PerfHooks.res +++ b/src/PerfHooks.res @@ -73,7 +73,7 @@ module Performance = { @send external now: t => float = "now" @send external timerify: (unit => unit, unit) => unit = "timerify" @send - external timerifyU: (@uncurry (unit => unit), unit) => unit = "timerify" + external timerifyU: (unit => unit, unit) => unit = "timerify" } module Histogram = { @@ -101,10 +101,10 @@ module PerformanceObserverEntryList = { @send external getEntries: t => array = "getEntries" @send - external getEntriesByName: (t, string, Js.Nullable.t) => array = + external getEntriesByName: (t, string, nullable) => array = "getEntriesByName" let getEntriesByName = (entryList, ~type_=?, name) => - getEntriesByName(entryList, name, Js.Nullable.fromOption(type_)) + getEntriesByName(entryList, name, Nullable.fromOption(type_)) @send external getEntriesByType: (t, string) => array = "getEntriesByType" } @@ -116,7 +116,6 @@ module PerformanceObserver = { } @module("node:perf_hooks") -external monitorEventLoopDelay: Js.Nullable.t<{"resolution": float}> => Histogram.t = - "eventLoopDelay" -let monitorEventLoopDelay = (~resolution=?, ()) => - monitorEventLoopDelay(Js.Nullable.fromOption(resolution)) +external monitorEventLoopDelay: nullable<{"resolution": float}> => Histogram.t = "eventLoopDelay" +let monitorEventLoopDelay = (~resolution=?) => + monitorEventLoopDelay(Nullable.fromOption(resolution)) diff --git a/src/PerfHooks.res.js b/src/PerfHooks.res.js new file mode 100644 index 0000000..8bfc25d --- /dev/null +++ b/src/PerfHooks.res.js @@ -0,0 +1,36 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Stdlib_Nullable = require("@rescript/runtime/lib/js/Stdlib_Nullable.js"); +let Nodeperf_hooks = require("node:perf_hooks"); + +let PerformanceEntry = {}; + +let PerformanceNodeTiming = {}; + +let Performance = {}; + +let Histogram = {}; + +function getEntriesByName(entryList, type_, name) { + return entryList.getEntriesByName(name, Stdlib_Nullable.fromOption(type_)); +} + +let PerformanceObserverEntryList = { + getEntriesByName: getEntriesByName +}; + +let PerformanceObserver = {}; + +function monitorEventLoopDelay(resolution) { + return Nodeperf_hooks.eventLoopDelay(Stdlib_Nullable.fromOption(resolution)); +} + +exports.PerformanceEntry = PerformanceEntry; +exports.PerformanceNodeTiming = PerformanceNodeTiming; +exports.Performance = Performance; +exports.Histogram = Histogram; +exports.PerformanceObserverEntryList = PerformanceObserverEntryList; +exports.PerformanceObserver = PerformanceObserver; +exports.monitorEventLoopDelay = monitorEventLoopDelay; +/* node:perf_hooks Not a pure module */ diff --git a/src/Process.res b/src/Process.res index 55cfdca..3a72b24 100644 --- a/src/Process.res +++ b/src/Process.res @@ -1,7 +1,7 @@ type t = { argv: array, argv0: string, - env: Js.Dict.t, + env: dict, execArgv: array, execPath: string, exitCode: int, @@ -16,103 +16,85 @@ type warning = { module Events = { @send - external onBeforeExit: (t, @as("beforeExit") _, @uncurry (int => unit)) => t = "on" + external onBeforeExit: (t, @as("beforeExit") _, int => unit) => t = "on" @send - external onDisconnect: (t, @as("disconnect") _, @uncurry (unit => unit)) => t = "on" + external onDisconnect: (t, @as("disconnect") _, unit => unit) => t = "on" @send - external onExit: (t, @as("exit") _, @uncurry (int => unit)) => t = "on" + external onExit: (t, @as("exit") _, int => unit) => t = "on" @send external onMultipleResolves: ( t, @as("multipleResolves") _, - @uncurry (string, Js.Promise.t<'a>, 'a) => unit, + (string, promise<'a>, 'a) => unit, ) => t = "on" @send - external onRejectionHandled: ( - t, - @as("rejectionHandled") _, - @uncurry (Js.Promise.t<'a> => unit), - ) => t = "on" + external onRejectionHandled: (t, @as("rejectionHandled") _, promise<'a> => unit) => t = "on" @send - external onUncaughtException: ( - t, - @as("uncaughtException") _, - @uncurry (Js.Exn.t, string) => unit, - ) => t = "on" + external onUncaughtException: (t, @as("uncaughtException") _, (JsExn.t, string) => unit) => t = + "on" @send external onUnhandledRejection: ( t, @as("unhandledRejection") _, - @uncurry (Js.Exn.t, Js.Promise.t<'a>) => unit, + (JsExn.t, promise<'a>) => unit, ) => t = "on" @send - external onWarning: (t, @as("warning") _, @uncurry (warning => unit)) => t = "on" + external onWarning: (t, @as("warning") _, warning => unit) => t = "on" @send - external offBeforeExit: (t, @as("beforeExit") _, @uncurry (int => unit)) => t = "off" + external offBeforeExit: (t, @as("beforeExit") _, int => unit) => t = "off" @send - external offDisconnect: (t, @as("disconnect") _, @uncurry (unit => unit)) => t = "off" + external offDisconnect: (t, @as("disconnect") _, unit => unit) => t = "off" @send - external offExit: (t, @as("exit") _, @uncurry (int => unit)) => t = "off" + external offExit: (t, @as("exit") _, int => unit) => t = "off" @send external offMultipleResolves: ( t, @as("multipleResolves") _, - @uncurry (string, Js.Promise.t<'a>, 'a) => unit, + (string, promise<'a>, 'a) => unit, ) => t = "off" @send - external offRejectionHandled: ( - t, - @as("rejectionHandled") _, - @uncurry (Js.Promise.t<'a> => unit), - ) => t = "off" + external offRejectionHandled: (t, @as("rejectionHandled") _, promise<'a> => unit) => t = "off" @send - external offUncaughtException: ( - t, - @as("uncaughtException") _, - @uncurry (Js.Exn.t, string) => unit, - ) => t = "off" + external offUncaughtException: (t, @as("uncaughtException") _, (JsExn.t, string) => unit) => t = + "off" @send external offUnhandledRejection: ( t, @as("unhandledRejection") _, - @uncurry (Js.Exn.t, Js.Promise.t<'a>) => unit, + (JsExn.t, promise<'a>) => unit, ) => t = "off" @send - external offWarning: (t, @as("warning") _, @uncurry (warning => unit)) => t = "off" + external offWarning: (t, @as("warning") _, warning => unit) => t = "off" @send - external onBeforeExitOnce: (t, @as("beforeExit") _, @uncurry (int => unit)) => t = "once" + external onBeforeExitOnce: (t, @as("beforeExit") _, int => unit) => t = "once" @send - external onDisconnectOnce: (t, @as("disconnect") _, @uncurry (unit => unit)) => t = "once" + external onDisconnectOnce: (t, @as("disconnect") _, unit => unit) => t = "once" @send - external onExitOnce: (t, @as("exit") _, @uncurry (int => unit)) => unit = "once" + external onExitOnce: (t, @as("exit") _, int => unit) => unit = "once" @send external onMultipleResolvesOnce: ( t, @as("multipleResolves") _, - @uncurry (string, Js.Promise.t<'a>, 'a) => unit, + (string, promise<'a>, 'a) => unit, ) => t = "once" @send - external onRejectionHandledOnce: ( - t, - @as("rejectionHandled") _, - @uncurry (Js.Promise.t<'a> => unit), - ) => t = "once" + external onRejectionHandledOnce: (t, @as("rejectionHandled") _, promise<'a> => unit) => t = "once" @send external onUncaughtExceptionOnce: ( t, @as("uncaughtException") _, - @uncurry (Js.Exn.t, string) => unit, + (JsExn.t, string) => unit, ) => t = "once" @send external onUnhandledRejectionOnce: ( t, @as("unhandledRejection") _, - @uncurry (Js.Exn.t, Js.Promise.t<'a>) => unit, + (JsExn.t, promise<'a>) => unit, ) => t = "once" @send - external onWarningOnce: (t, @as("warning") _, @uncurry (warning => unit)) => t = "once" + external onWarningOnce: (t, @as("warning") _, warning => unit) => t = "once" @send external removeAllListeners: t => t = "removeAllListeners" } @@ -124,25 +106,24 @@ include Events @send external chdir: (t, string) => unit = "chdir" @send external cwd: t => string = "cwd" @send external disconnect: t => unit = "disconnect" -@get external env: t => Js.Dict.t = "env" +@get external env: t => dict = "env" @get external execArgv: t => array = "execArgv" @get external execPath: t => string = "execPath" @send external exit: (t, unit) => unit = "exit" @send external exitWithCode: (t, int) => unit = "exit" @get external exitCode: t => int = "exitCode" @send -external nextTick: (t, @uncurry (unit => unit)) => unit = "nextTick" +external nextTick: (t, unit => unit) => unit = "nextTick" @send -external nextTickApply1: (t, @uncurry ('a => unit), 'a) => unit = "nextTick" +external nextTickApply1: (t, 'a => unit, 'a) => unit = "nextTick" @send -external nextTickApply2: (t, @uncurry ('a, 'b) => unit, 'a, 'b) => unit = "nextTick" +external nextTickApply2: (t, ('a, 'b) => unit, 'a, 'b) => unit = "nextTick" @send -external nextTickApply3: (t, @uncurry ('a, 'b, 'c) => unit, 'a, 'b, 'c) => unit = "nextTick" +external nextTickApply3: (t, ('a, 'b, 'c) => unit, 'a, 'b, 'c) => unit = "nextTick" @send -external nextTickApply4: (t, @uncurry ('a, 'b, 'c, 'd) => unit, 'a, 'b, 'c, 'd) => unit = "nextTick" +external nextTickApply4: (t, ('a, 'b, 'c, 'd) => unit, 'a, 'b, 'c, 'd) => unit = "nextTick" @send -external nextTickApply5: (t, @uncurry ('a, 'b, 'c, 'd, 'e) => unit, 'a, 'b, 'c, 'd, 'e) => unit = - "nextTick" +external nextTickApply5: (t, ('a, 'b, 'c, 'd, 'e) => unit, 'a, 'b, 'c, 'd, 'e) => unit = "nextTick" @send external hrtime: t => (int, int) = "hrtime" @send @scope("hrtime") external hrtimeBigInt: t => BigInt.t = "bigint" @@ -155,7 +136,7 @@ external hrtimeBigInt: t => BigInt.t = "bigint" @get external uptime: t => float = "uptime" @get external title: t => string = "title" @get external version: t => string = "version" -@get external versions: t => Js.Dict.t = "versions" +@get external versions: t => dict = "versions" type memoryUsageStats = { @as("rss") rss: int, diff --git a/lib/js/src/Process.bs.js b/src/Process.res.js similarity index 86% rename from lib/js/src/Process.bs.js rename to src/Process.res.js index b5506e4..bbe3860 100644 --- a/lib/js/src/Process.bs.js +++ b/src/Process.res.js @@ -2,7 +2,7 @@ 'use strict'; -var Events = {}; +let Events = {}; exports.Events = Events; /* No side effect */ diff --git a/src/QueryString.res b/src/QueryString.res index 2ea2c34..0ff7dc2 100644 --- a/src/QueryString.res +++ b/src/QueryString.res @@ -1,8 +1,8 @@ type t = string @module("node:querystring") -external parse: string => Js.Dict.t = "parse" +external parse: string => dict = "parse" @module("node:querystring") -external decode: string => Js.Dict.t = "decode" +external decode: string => dict = "decode" @module("node:querystring") -external stringify: Js.Dict.t => string = "stringify" +external stringify: dict => string = "stringify" diff --git a/lib/js/src/QueryString.bs.js b/src/QueryString.res.js similarity index 100% rename from lib/js/src/QueryString.bs.js rename to src/QueryString.res.js diff --git a/src/Readline.res b/src/Readline.res index 9746d7c..d0f9e1b 100644 --- a/src/Readline.res +++ b/src/Readline.res @@ -2,7 +2,7 @@ module Interface = { type t @send external close: t => unit = "close" @send external pause: t => unit = "pause" - @send external prompt: (t, Js.nullable) => unit = "prompt" + @send external prompt: (t, nullable) => unit = "prompt" @send external question: (t, string, string => unit) => unit = "question" @send external resume: t => unit = "resume" @@ -15,20 +15,18 @@ module Interface = { name?: string, } @send - external writeKey: (t, Js.Null.t, keyOptions) => unit = "write" + external writeKey: (t, Null.t, keyOptions) => unit = "write" @send external writeKey2: ( t, - Js.Null.t, + Null.t, {"ctrl": option, "meta": option, "shift": option, "name": option}, ) => unit = "write" @get @return(nullable) external line: t => option = "line" @get @return(nullable) external cursor: t => option = "cursor" - include EventEmitter.Impl({ - type t = t - }) + include EventEmitter.Impl({type t = t}) } module Events = { @@ -49,7 +47,8 @@ type interfaceOptions<'rtype, 'wtype> = { removeHistoryDuplicates?: bool, escapeCodeTimeout?: int, } -@module("node:readline") external make: interfaceOptions<'rtype, 'wtype> => Interface.t = "createInterface" +@module("node:readline") +external make: interfaceOptions<'rtype, 'wtype> => Interface.t = "createInterface" @module("node:readline") external clearLine: (Stream.Writable.subtype, int, ~callback: unit => unit) => bool = @@ -67,7 +66,6 @@ external cursorTo: ( ~x: int, ~y: int=?, ~callback: unit => unit=?, - @ignore unit, ) => bool = "cursorTo" @module("node:readline") @@ -76,5 +74,4 @@ external moveCursor: ( ~dx: int, ~dy: int, ~callback: unit => unit=?, - @ignore unit, ) => bool = "moveCursor" diff --git a/lib/js/src/Readline.bs.js b/src/Readline.res.js similarity index 80% rename from lib/js/src/Readline.bs.js rename to src/Readline.res.js index e603566..6c526e5 100644 --- a/lib/js/src/Readline.bs.js +++ b/src/Readline.res.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var EventEmitter$NodeJs = require("./EventEmitter.bs.js"); +let EventEmitter$NodeJs = require("./EventEmitter.res.js"); EventEmitter$NodeJs.Impl({}); -var Interface = {}; +let Interface = {}; function close(rl, f) { return rl.on("close", f); @@ -19,7 +19,7 @@ function history(rl, f) { return rl.on("history", f); } -var Events = { +let Events = { close: close, line: line, history: history diff --git a/src/Stream.res b/src/Stream.res index 90faa84..a397ca9 100644 --- a/src/Stream.res +++ b/src/Stream.res @@ -25,46 +25,24 @@ module Common = { module Events = { @send - external onError: ( - subtype<'ty> as 'stream, - @as("error") _, - @uncurry (Js.Exn.t => unit), - ) => 'stream = "on" + external onError: (subtype<'ty> as 'stream, @as("error") _, JsExn.t => unit) => 'stream = "on" @send - external onClose: ( - subtype<'ty> as 'stream, - @as("close") _, - @uncurry (unit => unit), - ) => 'stream = "on" + external onClose: (subtype<'ty> as 'stream, @as("close") _, unit => unit) => 'stream = "on" @send - external offError: ( - subtype<'ty> as 'stream, - @as("error") _, - @uncurry (Js.Exn.t => unit), - ) => 'stream = "off" + external offError: (subtype<'ty> as 'stream, @as("error") _, JsExn.t => unit) => 'stream = "off" @send - external offClose: ( - subtype<'ty> as 'stream, - @as("close") _, - @uncurry (unit => unit), - ) => 'stream = "off" + external offClose: (subtype<'ty> as 'stream, @as("close") _, unit => unit) => 'stream = "off" @send - external onCloseOnce: ( - subtype<'ty> as 'stream, - @as("close") _, - @uncurry (unit => unit), - ) => 'stream = "once" + external onCloseOnce: (subtype<'ty> as 'stream, @as("close") _, unit => unit) => 'stream = + "once" @send - external onErrorOnce: ( - subtype<'ty> as 'stream, - @as("error") _, - @uncurry (Js.Exn.t => unit), - ) => 'stream = "once" + external onErrorOnce: (subtype<'ty> as 'stream, @as("error") _, JsExn.t => unit) => 'stream = + "once" @send external removeAllListeners: (subtype<'ty> as 'stream) => 'stream = "removeAllListeners" @@ -75,7 +53,7 @@ module Common = { @send external destroy: (subtype<[> kind]> as 'stream) => 'stream = "destroy" @send - external destroyWithError: (subtype<[> kind]> as 'stream, Js.Exn.t) => 'stream = "destroy" + external destroyWithError: (subtype<[> kind]> as 'stream, JsExn.t) => 'stream = "destroy" @get external destroyed: subtype<[> kind]> => bool = "destroyed" } include Impl @@ -85,76 +63,60 @@ module Writable = { type kind<'w> = writable<'w> module Events = { @send - external onDrain: ( - subtype<[> writable<'w>]> as 'ws, - @as("drain") _, - @uncurry (unit => unit), - ) => 'ws = "on" + external onDrain: (subtype<[> writable<'w>]> as 'ws, @as("drain") _, unit => unit) => 'ws = "on" @send - external onFinish: ( - subtype<[> writable<'w>]> as 'ws, - @as("finish") _, - @uncurry (unit => unit), - ) => 'ws = "on" + external onFinish: (subtype<[> writable<'w>]> as 'ws, @as("finish") _, unit => unit) => 'ws = + "on" @send external onPipe: ( subtype<[> writable<'w>]> as 'ws, @as("pipe") _, - @uncurry (subtype<[> readable<'r>]> => unit), + subtype<[> readable<'r>]> => unit, ) => 'ws = "on" @send external onUnpipe: ( subtype<[> writable<'w>]> as 'ws, @as("unpipe") _, - @uncurry (subtype<[> readable<'r>]> => unit), + subtype<[> readable<'r>]> => unit, ) => 'ws = "on" @send - external offDrain: ( - subtype<[> writable<'w>]> as 'ws, - @as("drain") _, - @uncurry (unit => unit), - ) => 'ws = "off" + external offDrain: (subtype<[> writable<'w>]> as 'ws, @as("drain") _, unit => unit) => 'ws = + "off" @send - external offFinish: ( - subtype<[> writable<'w>]> as 'ws, - @as("finish") _, - @uncurry (unit => unit), - ) => 'ws = "off" + external offFinish: (subtype<[> writable<'w>]> as 'ws, @as("finish") _, unit => unit) => 'ws = + "off" @send external offPipe: ( subtype<[> writable<'w>]> as 'ws, @as("pipe") _, - @uncurry (subtype<[> readable<'r>]> => unit), + subtype<[> readable<'r>]> => unit, ) => 'ws = "off" @send external offUnpipe: ( subtype<[> writable<'w>]> as 'ws, @as("unpipe") _, - @uncurry (subtype<[> readable<'r>]> => unit), + subtype<[> readable<'r>]> => unit, ) => 'ws = "off" @send - external onDrainOnce: ( - subtype<[> writable<'w>]> as 'ws, - @as("drain") _, - @uncurry (unit => unit), - ) => 'ws = "once" + external onDrainOnce: (subtype<[> writable<'w>]> as 'ws, @as("drain") _, unit => unit) => 'ws = + "once" @send external onFinishOnce: ( subtype<[> writable<'w>]> as 'ws, @as("finish") _, - @uncurry (unit => unit), + unit => unit, ) => 'ws = "once" @send external onPipeOnce: ( subtype<[> writable<'w>]> as 'ws, @as("pipe") _, - @uncurry (subtype<[> readable<'r>]> => unit), + subtype<[> readable<'r>]> => unit, ) => 'ws = "once" @send external onUnpipeOnce: ( subtype<[> writable<'w>]> as 'ws, @as("unpipe") _, - @uncurry (subtype<[> readable<'r>]> => unit), + subtype<[> readable<'r>]> => unit, ) => 'ws = "once" } module Impl = { @@ -169,8 +131,7 @@ module Writable = { external writeWith: ( subtype<[> writable<'w>]>, 'w, - ~callback: Js.Nullable.t => unit=?, - unit, + ~callback: nullable => unit=?, ) => bool = "write" @get external writable: subtype<[> writable<'w>]> => bool = "writable" @@ -203,23 +164,22 @@ module Writable = { ~autoDestroy: bool=?, ~destroy: @this ( t<'w>, - ~error: Js.nullable, - ~callback: (~error: option) => unit, + ~error: nullable, + ~callback: (~error: option) => unit, ) => unit=?, - ~final: @this (t<'w>, ~callback: (~error: option) => unit) => unit=?, + ~final: @this (t<'w>, ~callback: (~error: option) => unit) => unit=?, ~writev: @this ( t<'w>, ~data: array>, ~encoding: StringEncoding.t, - ~callback: (~error: option) => unit, + ~callback: (~error: option) => unit, ) => unit=?, ~write: @this ( t<'w>, ~data: 'w, ~encoding: StringEncoding.t, - ~callback: (~error: option) => unit, + ~callback: (~error: option) => unit, ) => unit, - unit, ) => makeOptions<'w> = "" @module("node:stream") @new external make: makeOptions => t = "Writable" @@ -233,23 +193,22 @@ module Writable = { ~autoDestroy: bool=?, ~destroy: @this ( objStream<'w>, - ~error: Js.nullable, - ~callback: (~error: option) => unit, + ~error: nullable, + ~callback: (~error: option) => unit, ) => unit=?, - ~final: @this (objStream<'w>, ~callback: (~error: option) => unit) => unit=?, + ~final: @this (objStream<'w>, ~callback: (~error: option) => unit) => unit=?, ~writev: @this ( objStream<'w>, ~data: array>, - ~encoding: Js.null, - ~callback: (~error: option) => unit, + ~encoding: Null.t, + ~callback: (~error: option) => unit, ) => unit=?, ~write: @this ( objStream<'w>, ~data: 'w, - ~encoding: Js.null, - ~callback: (~error: option) => unit, + ~encoding: Null.t, + ~callback: (~error: option) => unit, ) => unit, - unit, ) => makeOptionsObjMode<'w> = "" @module("node:stream") @new external makeObjMode: makeOptionsObjMode<'w> => objStream<'w> = "Writable" @@ -263,94 +222,56 @@ module Readable = { module Events = { include Common.Events @send - external onData: ( - subtype<[> readable<'r>]> as 'rs, - @as("data") _, - @uncurry ('r => unit), - ) => 'rs = "on" + external onData: (subtype<[> readable<'r>]> as 'rs, @as("data") _, 'r => unit) => 'rs = "on" @send - external onEnd: ( - subtype<[> readable<'r>]> as 'rs, - @as("end") _, - @uncurry (unit => unit), - ) => 'rs = "on" + external onEnd: (subtype<[> readable<'r>]> as 'rs, @as("end") _, unit => unit) => 'rs = "on" @send - external onPause: ( - subtype<[> readable<'r>]> as 'rs, - @as("pause") _, - @uncurry (unit => unit), - ) => 'rs = "on" + external onPause: (subtype<[> readable<'r>]> as 'rs, @as("pause") _, unit => unit) => 'rs = "on" @send external onReadable: ( subtype<[> readable<'r>]> as 'rs, @as("readable") _, - @uncurry (unit => unit), + unit => unit, ) => 'rs = "on" @send - external onResume: ( - subtype<[> readable<'r>]> as 'rs, - @as("resume") _, - @uncurry (unit => unit), - ) => 'rs = "on" + external onResume: (subtype<[> readable<'r>]> as 'rs, @as("resume") _, unit => unit) => 'rs = + "on" @send - external offData: ( - subtype<[> readable<'r>]> as 'rs, - @as("data") _, - @uncurry ('r => unit), - ) => 'rs = "off" + external offData: (subtype<[> readable<'r>]> as 'rs, @as("data") _, 'r => unit) => 'rs = "off" @send - external offEnd: ( - subtype<[> readable<'r>]> as 'rs, - @as("end") _, - @uncurry (unit => unit), - ) => 'rs = "off" + external offEnd: (subtype<[> readable<'r>]> as 'rs, @as("end") _, unit => unit) => 'rs = "off" @send - external offPause: ( - subtype<[> readable<'r>]> as 'rs, - @as("pause") _, - @uncurry (unit => unit), - ) => 'rs = "off" + external offPause: (subtype<[> readable<'r>]> as 'rs, @as("pause") _, unit => unit) => 'rs = + "off" @send external offReadable: ( subtype<[> readable<'r>]> as 'rs, @as("readable") _, - @uncurry (unit => unit), + unit => unit, ) => 'rs = "off" @send - external offResume: ( - subtype<[> readable<'r>]> as 'rs, - @as("resume") _, - @uncurry (unit => unit), - ) => 'rs = "off" + external offResume: (subtype<[> readable<'r>]> as 'rs, @as("resume") _, unit => unit) => 'rs = + "off" @send - external onDataOnce: ( - subtype<[> readable<'r>]> as 'rs, - @as("data") _, - @uncurry ('r => unit), - ) => 'rs = "once" + external onDataOnce: (subtype<[> readable<'r>]> as 'rs, @as("data") _, 'r => unit) => 'rs = + "once" @send - external onEndOnce: ( - subtype<[> readable<'r>]> as 'rs, - @as("end") _, - @uncurry (unit => unit), - ) => 'rs = "once" + external onEndOnce: (subtype<[> readable<'r>]> as 'rs, @as("end") _, unit => unit) => 'rs = + "once" @send - external onPauseOnce: ( - subtype<[> readable<'r>]> as 'rs, - @as("pause") _, - @uncurry (unit => unit), - ) => 'rs = "once" + external onPauseOnce: (subtype<[> readable<'r>]> as 'rs, @as("pause") _, unit => unit) => 'rs = + "once" @send external onReadableOnce: ( subtype<[> readable<'r>]> as 'rs, @as("readable") _, - @uncurry (unit => unit), + unit => unit, ) => 'rs = "once" @send external onResumeOnce: ( subtype<[> readable<'r>]> as 'rs, @as("resume") _, - @uncurry (unit => unit), + unit => unit, ) => 'rs = "once" } module Impl = { @@ -370,7 +291,7 @@ module Readable = { @get external readable: subtype<[> readable<'r>]> => bool = "readable" @get - external readableEncoding: subtype<[> readable<'r>]> => Js.nullable = "readableEncoding" + external readableEncoding: subtype<[> readable<'r>]> => nullable = "readableEncoding" @get external readableEnded: subtype<[> readable<'r>]> => bool = "readableEnded" @get @@ -404,11 +325,10 @@ module Readable = { ~autoDestroy: bool=?, ~destroy: @this ( t<'r>, - ~error: Js.nullable, - ~callback: (~error: option) => unit, + ~error: nullable, + ~callback: (~error: option) => unit, ) => unit, - ~read: @this (t<'r>, ~size: Js.nullable) => unit, - unit, + ~read: @this (t<'r>, ~size: nullable) => unit, ) => makeOptions<'r> = "" @module("node:stream") @new external make: makeOptions => t = "Readable" @@ -422,11 +342,10 @@ module Readable = { ~autoDestroy: bool=?, ~destroy: @this ( objStream<'r>, - ~error: Js.nullable, - ~callback: (~error: option) => unit, + ~error: nullable, + ~callback: (~error: option) => unit, ) => unit, - ~read: @this (objStream<'r>, ~size: Js.nullable) => unit, - unit, + ~read: @this (objStream<'r>, ~size: nullable) => unit, ) => makeOptionsObjMode<'r> = "" @module("node:stream") @new @@ -461,24 +380,23 @@ module Duplex = { ~autoDestroy: bool=?, ~destroy: @this ( t<'w, 'r>, - ~error: Js.nullable, - ~callback: (~error: option) => unit, + ~error: nullable, + ~callback: (~error: option) => unit, ) => unit=?, - ~final: @this (t<'w, 'r>, ~data: 'w, ~callback: (~error: option) => unit) => unit=?, + ~final: @this (t<'w, 'r>, ~data: 'w, ~callback: (~error: option) => unit) => unit=?, ~writev: @this ( t<'w, 'r>, ~data: array>, ~encoding: StringEncoding.t, - ~callback: (~error: option) => unit, + ~callback: (~error: option) => unit, ) => unit=?, - ~read: @this (t<'w, 'r>, ~size: Js.nullable) => unit, + ~read: @this (t<'w, 'r>, ~size: nullable) => unit, ~write: @this ( t<'w, 'r>, ~data: 'w, ~encoding: StringEncoding.t, - ~callback: (~error: option) => unit, + ~callback: (~error: option) => unit, ) => unit, - unit, ) => makeOptions<'w, 'r> = "" @module("node:stream") @new @@ -494,24 +412,23 @@ module Duplex = { ~autoDestroy: bool=?, ~destroy: @this ( objStream<'w, 'r>, - ~error: Js.nullable, - ~callback: (~error: option) => unit, + ~error: nullable, + ~callback: (~error: option) => unit, ) => unit=?, - ~final: @this (objStream<'w, 'r>, ~callback: (~error: option) => unit) => unit=?, + ~final: @this (objStream<'w, 'r>, ~callback: (~error: option) => unit) => unit=?, ~writev: @this ( objStream<'w, 'r>, ~data: array>, ~encoding: StringEncoding.t, - ~callback: (~error: option) => unit, + ~callback: (~error: option) => unit, ) => unit=?, - ~read: @this (objStream<'w, 'r>, ~size: Js.nullable) => unit, + ~read: @this (objStream<'w, 'r>, ~size: nullable) => unit, ~write: @this ( objStream<'w, 'r>, ~data: 'w, ~encoding: StringEncoding.t, - ~callback: (~error: option) => unit, + ~callback: (~error: option) => unit, ) => unit, - unit, ) => makeOptionsObjMode<'w, 'r> = "" @module("node:stream") @new @@ -545,13 +462,12 @@ module Transform = { t<'w, 'r>, ~data: 'w, ~encoding: StringEncoding.t, - ~callback: (~error: option, ~data: option<'r>) => unit, + ~callback: (~error: option, ~data: option<'r>) => unit, ) => unit, ~flush: @this ( t<'w, 'r>, - ~callback: (~error: option, ~data: option<'r>) => unit, + ~callback: (~error: option, ~data: option<'r>) => unit, ) => unit, - unit, ) => makeOptions<'w, 'r> = "" @module("node:stream") @new @@ -568,13 +484,12 @@ module Transform = { objStream<'w, 'r>, ~data: 'w, ~encoding: StringEncoding.t, - ~callback: (~error: option, ~data: option<'r>) => unit, + ~callback: (~error: option, ~data: option<'r>) => unit, ) => unit, ~flush: @this ( objStream<'w, 'r>, - ~callback: (~error: option, ~data: option<'r>) => unit, + ~callback: (~error: option, ~data: option<'r>) => unit, ) => unit, - unit, ) => makeOptionsObjMode<'w, 'r> = "" @module("node:stream") @new @@ -611,13 +526,13 @@ include Events type cleanupFn = unit => unit @module("node:stream") -external finished: (subtype<'ty>, Js.nullable => unit) => cleanupFn = "finished" +external finished: (subtype<'ty>, nullable => unit) => cleanupFn = "finished" @module("node:stream") external pipeline2: ( subtype<[> readable<'t1>] as 'src>, subtype<[> writable<'t1>] as 'dest>, - Js.nullable => unit, + nullable => unit, ) => subtype<[> writable<'t1>] as 'dest> = "pipeline" @module("node:stream") @@ -625,7 +540,7 @@ external pipeline3: ( subtype<[> readable<'t1>] as 'src>, subtype<[> writable<'t1> | readable<'t2>] as 'kindA>, subtype<[> writable<'t2>] as 'dest>, - Js.nullable => unit, + nullable => unit, ) => subtype<[> writable<'t2>] as 'dest> = "pipeline" @module("node:stream") external pipeline4: ( @@ -633,5 +548,5 @@ external pipeline4: ( subtype<[> writable<'t1> | readable<'t2>] as 'kindA>, subtype<[> writable<'t2> | readable<'t3>] as 'kindA>, subtype<[> writable<'t3>] as 'dest>, - Js.nullable => unit, + nullable => unit, ) => subtype<[> writable<'t3>] as 'dest> = "pipeline" diff --git a/lib/js/src/Stream.bs.js b/src/Stream.res.js similarity index 61% rename from lib/js/src/Stream.bs.js rename to src/Stream.res.js index cb26a3c..35f3bcb 100644 --- a/lib/js/src/Stream.bs.js +++ b/src/Stream.res.js @@ -2,61 +2,61 @@ 'use strict'; -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; -var Common = { +let Common = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Impl$1 = {}; +let Impl$1 = {}; -var Writable = { +let Writable = { Events: Events$1, Impl: Impl$1 }; -var Events$2 = {}; +let Events$2 = {}; -var Impl$2 = {}; +let Impl$2 = {}; -var Readable = { +let Readable = { Events: Events$2, Impl: Impl$2 }; -var Events$3 = {}; +let Events$3 = {}; -var Impl$3 = {}; +let Impl$3 = {}; -var Duplex = { +let Duplex = { Events: Events$3, Impl: Impl$3 }; -var Events$4 = {}; +let Events$4 = {}; -var Impl$4 = {}; +let Impl$4 = {}; -var Transform = { +let Transform = { Events: Events$4, Impl: Impl$4 }; -var Events$5 = {}; +let Events$5 = {}; -var Impl$5 = {}; +let Impl$5 = {}; -var PassThrough = { +let PassThrough = { Events: Events$5, Impl: Impl$5 }; -var Events$6 = {}; +let Events$6 = {}; exports.Common = Common; exports.Writable = Writable; diff --git a/src/StringBuffer.res b/src/StringBuffer.res index 4983dad..e1c7c12 100644 --- a/src/StringBuffer.res +++ b/src/StringBuffer.res @@ -8,7 +8,7 @@ type case = | Buffer(Buffer.t) let classifyOpt = value => - if Js.typeof(value) === "string" { + if typeof(value) === #string { Some(String(Obj.magic(value))) } else if Buffer.isBuffer(value) { Some(Buffer(Obj.magic(value))) @@ -17,7 +17,7 @@ let classifyOpt = value => } let classifyExn = value => - if Js.typeof(value) === "string" { + if typeof(value) === #string { String(Obj.magic(value)) } else if Buffer.isBuffer(value) { Buffer(Obj.magic(value)) @@ -26,7 +26,7 @@ let classifyExn = value => } let classify = value => - if Js.typeof(value) === "string" { + if typeof(value) === #string { Ok(String(Obj.magic(value))) } else if Buffer.isBuffer(value) { Ok(Buffer(Obj.magic(value))) diff --git a/src/StringBuffer.res.js b/src/StringBuffer.res.js new file mode 100644 index 0000000..0b59dc7 --- /dev/null +++ b/src/StringBuffer.res.js @@ -0,0 +1,66 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Pervasives = require("@rescript/runtime/lib/js/Pervasives.js"); + +function classifyOpt(value) { + if (typeof value === "string") { + return { + TAG: "String", + _0: value + }; + } else if (Buffer.isBuffer(value)) { + return { + TAG: "Buffer", + _0: value + }; + } else { + return; + } +} + +function classifyExn(value) { + if (typeof value === "string") { + return { + TAG: "String", + _0: value + }; + } else if (Buffer.isBuffer(value)) { + return { + TAG: "Buffer", + _0: value + }; + } else { + return Pervasives.failwith("Unknown data type"); + } +} + +function classify(value) { + if (typeof value === "string") { + return { + TAG: "Ok", + _0: { + TAG: "String", + _0: value + } + }; + } else if (Buffer.isBuffer(value)) { + return { + TAG: "Ok", + _0: { + TAG: "Buffer", + _0: value + } + }; + } else { + return { + TAG: "Error", + _0: value + }; + } +} + +exports.classifyOpt = classifyOpt; +exports.classifyExn = classifyExn; +exports.classify = classify; +/* No side effect */ diff --git a/lib/js/src/StringDecoder.bs.js b/src/StringDecoder.res.js similarity index 100% rename from lib/js/src/StringDecoder.bs.js rename to src/StringDecoder.res.js diff --git a/lib/js/src/StringEncoding.bs.js b/src/StringEncoding.res.js similarity index 87% rename from lib/js/src/StringEncoding.bs.js rename to src/StringEncoding.res.js index 69750bd..63cef9b 100644 --- a/lib/js/src/StringEncoding.bs.js +++ b/src/StringEncoding.res.js @@ -2,7 +2,7 @@ 'use strict'; -var Impl = {}; +let Impl = {}; exports.Impl = Impl; /* No side effect */ diff --git a/src/Timers.res b/src/Timers.res index c314d63..b6e40ac 100644 --- a/src/Timers.res +++ b/src/Timers.res @@ -24,10 +24,10 @@ external setInterval: (unit => unit, int) => Timeout.t = "setInterval" module Promises = { @module("node:timers/promises") - external setTimeout: int => Js.Promise.t = "setTimeout" + external setTimeout: int => promise = "setTimeout" @module("node:timers/promises") - external setImmediate: 'a => Js.Promise.t<'a> = "setImmediate" + external setImmediate: 'a => promise<'a> = "setImmediate" // setInterval is not a promise, it's an async iterator // @module("node:timers/promises") - // external setInterval: (int, 'a) => Js.Promise.t<'a> = "setTimeout" + // external setInterval: (int, 'a) => promise<'a> = "setTimeout" } diff --git a/lib/js/src/Timers.bs.js b/src/Timers.res.js similarity index 75% rename from lib/js/src/Timers.bs.js rename to src/Timers.res.js index ae47576..52d16d1 100644 --- a/lib/js/src/Timers.bs.js +++ b/src/Timers.res.js @@ -2,11 +2,11 @@ 'use strict'; -var Immediate = {}; +let Immediate = {}; -var Timeout = {}; +let Timeout = {}; -var Promises = {}; +let Promises = {}; exports.Immediate = Immediate; exports.Timeout = Timeout; diff --git a/lib/js/src/Tls.bs.js b/src/Tls.res.js similarity index 62% rename from lib/js/src/Tls.bs.js rename to src/Tls.res.js index c2962fd..4816872 100644 --- a/lib/js/src/Tls.bs.js +++ b/src/Tls.res.js @@ -1,22 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var Net$NodeJs = require("./Net.bs.js"); +let Net$NodeJs = require("./Net.res.js"); -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; -var TlsSocket = { +let TlsSocket = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Impl$1 = {}; +let Impl$1 = {}; -var TlsServer = { +let TlsServer = { Events: Events$1, Impl: Impl$1 }; diff --git a/src/Tty.res b/src/Tty.res index c79c964..5f960a7 100644 --- a/src/Tty.res +++ b/src/Tty.res @@ -30,37 +30,34 @@ module WriteStream = { module Events = { include Stream.Writable.Events @send - external onResize: (subtype<'w, 'ty>, @as("resize") _, @uncurry (unit => unit)) => unit = "on" + external onResize: (subtype<'w, 'ty>, @as("resize") _, unit => unit) => unit = "on" @send - external offResize: (subtype<'w, 'ty>, @as("resize") _, @uncurry (unit => unit)) => unit = "off" + external offResize: (subtype<'w, 'ty>, @as("resize") _, unit => unit) => unit = "off" @send - external onResizeOnce: (subtype<'w, 'ty>, @as("resize") _, @uncurry (unit => unit)) => unit = - "once" + external onResizeOnce: (subtype<'w, 'ty>, @as("resize") _, unit => unit) => unit = "once" } module Impl = { include Stream.Writable.Impl @send - external clearLineLeft: (t, @as(json`-1`) _, @uncurry (unit => unit), unit) => bool = - "clearLine" + external clearLineLeft: (t, @as(json`-1`) _, unit => unit, unit) => bool = "clearLine" @send - external clearLineRight: (t, @as(json`1`) _, @uncurry (unit => unit), unit) => bool = - "clearLine" + external clearLineRight: (t, @as(json`1`) _, unit => unit, unit) => bool = "clearLine" @send - external clearLine: (t, @as(json`0`) _, @uncurry (unit => unit), unit) => bool = "clearLine" + external clearLine: (t, @as(json`0`) _, unit => unit, unit) => bool = "clearLine" @send - external clearScreenDown: (t, @uncurry (unit => unit), unit) => bool = "clearScreenDown" + external clearScreenDown: (t, unit => unit, unit) => bool = "clearScreenDown" @get external columns: t => int = "columns" @send external getColorDepth: t => int = "getColorDepth" @send - external getColorDepthFromEnv: (t, Js.Dict.t<'ty>) => int = "getColorDepth" + external getColorDepthFromEnv: (t, dict<'ty>) => int = "getColorDepth" @send external getWindowSize: t => (int, int) = "getWindowSize" @send external hasColors: (t, int) => bool = "hasColors" @send - external hasColorsFromEnv: (t, int, Js.Dict.t<'ty>) => bool = "hasColors" + external hasColorsFromEnv: (t, int, dict<'ty>) => bool = "hasColors" @send external hasAtLeast16Colors: t => bool = "hasColors" @send - external moveCursor: (t, int, int, @uncurry (unit => unit)) => bool = "moveCursor" + external moveCursor: (t, int, int, unit => unit) => bool = "moveCursor" @get external rows: t => int = "rows" @get external isTTY: t => bool = "isTTY" external unsafeCoerceToSocket: t => Net.Socket.t = "%identity" diff --git a/lib/js/src/Tty.bs.js b/src/Tty.res.js similarity index 68% rename from lib/js/src/Tty.bs.js rename to src/Tty.res.js index 08d3b91..9ead327 100644 --- a/lib/js/src/Tty.bs.js +++ b/src/Tty.res.js @@ -2,20 +2,20 @@ 'use strict'; -var Events = {}; +let Events = {}; -var Impl = {}; +let Impl = {}; -var ReadStream = { +let ReadStream = { Events: Events, Impl: Impl }; -var Events$1 = {}; +let Events$1 = {}; -var Impl$1 = {}; +let Impl$1 = {}; -var WriteStream = { +let WriteStream = { Events: Events$1, Impl: Impl$1 }; diff --git a/src/Url.res b/src/Url.res index 0eb0d2f..7330907 100644 --- a/src/Url.res +++ b/src/Url.res @@ -7,7 +7,7 @@ module SearchParams = { @as("forEach") forEach: ((~value: string, ~name: string=?, ~searchParams: t=?) => unit) => unit, @as("get") - get: string => Js.Null.t, + get: string => Null.t, @as("getAll") getAll: string => array, @as("has") @@ -25,7 +25,7 @@ module SearchParams = { } @new external empty: unit => t = "URLSearchParams" @new external fromString: string => t = "URLSearchParams" - @new external fromDict: Js.Dict.t => t = "URLSearchParams" + @new external fromDict: dict => t = "URLSearchParams" // [@bs.new] external fromIterable: iterable => t = "URLSearchParams"; // no type definition for 'iterator' } @@ -43,7 +43,7 @@ type t = { searchParams: SearchParams.t, username: string, toString: unit => string, - toJson: unit => Js.Json.t, + toJson: unit => JSON.t, } @module("node:url") @new external make: string => t = "URL" @@ -65,20 +65,20 @@ type urlFormatOptions = {"auth": bool, "fragment": bool, "search": bool, "unicod external format: ( t, { - "auth": Js.Nullable.t, - "fragment": Js.Nullable.t, - "search": Js.Nullable.t, - "unicode": Js.Nullable.t, + "auth": nullable, + "fragment": nullable, + "search": nullable, + "unicode": nullable, }, ) => string = "format" let format = (~auth=?, ~fragment=?, ~search=?, ~unicode=?, url) => format( url, { - "auth": Js.Nullable.fromOption(auth), - "fragment": Js.Nullable.fromOption(fragment), - "search": Js.Nullable.fromOption(search), - "unicode": Js.Nullable.fromOption(unicode), + "auth": Nullable.fromOption(auth), + "fragment": Nullable.fromOption(fragment), + "search": Nullable.fromOption(search), + "unicode": Nullable.fromOption(unicode), }, ) diff --git a/src/Url.res.js b/src/Url.res.js new file mode 100644 index 0000000..fc03f96 --- /dev/null +++ b/src/Url.res.js @@ -0,0 +1,20 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Nodeurl = require("node:url"); +let Stdlib_Nullable = require("@rescript/runtime/lib/js/Stdlib_Nullable.js"); + +let SearchParams = {}; + +function format(auth, fragment, search, unicode, url) { + return Nodeurl.format(url, { + auth: Stdlib_Nullable.fromOption(auth), + fragment: Stdlib_Nullable.fromOption(fragment), + search: Stdlib_Nullable.fromOption(search), + unicode: Stdlib_Nullable.fromOption(unicode) + }); +} + +exports.SearchParams = SearchParams; +exports.format = format; +/* node:url Not a pure module */ diff --git a/src/Util.res b/src/Util.res index a36d7c2..4e1d844 100644 --- a/src/Util.res +++ b/src/Util.res @@ -16,11 +16,11 @@ type inspectOptions = { type defaultInspectOptions = { mutable showHidden: bool, - mutable depth: Js.Null.t, + mutable depth: Null.t, mutable colors: bool, mutable customInspect: bool, mutable showProxy: bool, - mutable maxArrayLength: Js.Null.t, + mutable maxArrayLength: Null.t, mutable breakLength: int, mutable compact: bool, mutable sorted: bool, diff --git a/lib/js/src/Util.bs.js b/src/Util.res.js similarity index 87% rename from lib/js/src/Util.bs.js rename to src/Util.res.js index 972d97c..44a019d 100644 --- a/lib/js/src/Util.bs.js +++ b/src/Util.res.js @@ -2,7 +2,7 @@ 'use strict'; -var Types = {}; +let Types = {}; exports.Types = Types; /* No side effect */ diff --git a/src/V8.res b/src/V8.res index 52443c0..b6138ab 100644 --- a/src/V8.res +++ b/src/V8.res @@ -59,7 +59,7 @@ type heapCodeStats = { external getHeapCodeStatistics: unit => heapStats = "getHeapCodeStatistics" @module("node:v8") -external writeHeapSnapshot: string => Js.Json.t = "writeHeapSnapshot" +external writeHeapSnapshot: string => JSON.t = "writeHeapSnapshot" @module("node:v8") external serialize: 'a => Buffer.t = "serialize" @module("node:v8") external deserialize: Buffer.t => 'a = "deserialize" diff --git a/lib/js/src/V8.bs.js b/src/V8.res.js similarity index 100% rename from lib/js/src/V8.bs.js rename to src/V8.res.js diff --git a/src/VM.res b/src/VM.res index 37d7ab5..5ae4e37 100644 --- a/src/VM.res +++ b/src/VM.res @@ -27,6 +27,6 @@ module Script = { @send external runInContext: (t, contextifiedObject<'a>) => 'b = "runInContext" @send - external runInNewContext: (t, contextifiedObject<'a>) => 'b = "runInNewContext" + external runInNewContext: (t, contextifiedObject<'a>) => 'b = "runInNewContext" @send external runInThisContext: t => 'a = "runInThisContext" } diff --git a/lib/js/src/VM.bs.js b/src/VM.res.js similarity index 86% rename from lib/js/src/VM.bs.js rename to src/VM.res.js index 9d5c0b0..89b8a42 100644 --- a/lib/js/src/VM.bs.js +++ b/src/VM.res.js @@ -2,7 +2,7 @@ 'use strict'; -var Script = {}; +let Script = {}; exports.Script = Script; /* No side effect */ diff --git a/src/WorkerThreads.res b/src/WorkerThreads.res index 77a221d..f973689 100644 --- a/src/WorkerThreads.res +++ b/src/WorkerThreads.res @@ -11,9 +11,9 @@ module MessagePort = { type t<'a> @send - external onClose: (t<'a>, @as("close") _, @uncurry (unit => unit)) => t<'a> = "on" + external onClose: (t<'a>, @as("close") _, unit => unit) => t<'a> = "on" @send - external onMessage: (t<'a>, @as("message") _, @uncurry ('a => unit)) => t<'a> = "on" + external onMessage: (t<'a>, @as("message") _, 'a => unit) => t<'a> = "on" @send external close: t<'a> => unit = "close" @send external postMessage: (t<'a>, 'a) => unit = "postMessage" @send external ref: t<'a> => unit = "ref" @@ -27,9 +27,9 @@ module MessagePort = { ) => { type t = t @send - external onClose: (t, @as("close") _, @uncurry (unit => unit)) => t = "on" + external onClose: (t, @as("close") _, unit => unit) => t = "on" @send - external onMessage: (t, @as("message") _, @uncurry (T.message => unit)) => t = "on" + external onMessage: (t, @as("message") _, T.message => unit) => t = "on" @send external close: t => unit = "close" @send external postMessage: (t, T.message) => unit = "postMessage" @send external ref: t => unit = "ref" @@ -86,24 +86,24 @@ module Worker = { } @module("node:worker_threads") @new - external make: (~file: string, ~options: options<'a, 'env>=?, unit) => t<'a> = "Worker" + external make: (~file: string, ~options: options<'a, 'env>=?) => t<'a> = "Worker" @send - external onError: (t<'a>, @as("error") _, @uncurry (Js.Exn.t => unit)) => t<'a> = "on" + external onError: (t<'a>, @as("error") _, JsExn.t => unit) => t<'a> = "on" @send - external onMessage: (t<'a>, @as("message") _, @uncurry ('a => unit)) => t<'a> = "on" + external onMessage: (t<'a>, @as("message") _, 'a => unit) => t<'a> = "on" @send - external onExit: (t<'a>, @as("exit") _, @uncurry (int => unit)) => t<'a> = "on" + external onExit: (t<'a>, @as("exit") _, int => unit) => t<'a> = "on" @send - external onOnline: (t<'a>, @as("online") _, @uncurry (unit => unit)) => t<'a> = "on" + external onOnline: (t<'a>, @as("online") _, unit => unit) => t<'a> = "on" @send external postMessage: (t<'a>, 'a) => unit = "postMessage" @send external ref: t<'a> => unit = "ref" @send external resourceLimits: t<'a> => workerResourceLimits = "workerResourceLimits" @get external stderr: t<'a> => Stream.Readable.t<'a> = "stderr" @get - external stdin: t<'a> => Js.nullable> = "stdin" + external stdin: t<'a> => nullable> = "stdin" @get external stdout: t<'a> => Stream.Readable.t<'a> = "stdout" - @send external terminate: t<'a> => Js.Promise.t = "terminate" + @send external terminate: t<'a> => promise = "terminate" @get external threadId: t<'a> => int = "threadId" @send external unref: t<'a> => unit = "unref" @@ -127,24 +127,24 @@ module Worker = { } @module("node:worker_threads") @new - external make: (~file: string, ~options: options<'env>=?, unit) => t = "Worker" + external make: (~file: string, ~options: options<'env>=?) => t = "Worker" @send - external onError: (t, @as("error") _, @uncurry (Js.Exn.t => unit)) => t = "on" + external onError: (t, @as("error") _, JsExn.t => unit) => t = "on" @send - external onMessage: (t, @as("message") _, @uncurry (T.message => unit)) => t = "on" + external onMessage: (t, @as("message") _, T.message => unit) => t = "on" @send - external onExit: (t, @as("exit") _, @uncurry (int => unit)) => t = "on" + external onExit: (t, @as("exit") _, int => unit) => t = "on" @send - external onOnline: (t, @as("online") _, @uncurry (unit => unit)) => t = "on" + external onOnline: (t, @as("online") _, unit => unit) => t = "on" @send external postMessage: (t, T.message) => unit = "postMessage" @send external ref: t => unit = "ref" @send external resourceLimits: t => workerResourceLimits = "workerResourceLimits" @get external stderr: t => Stream.Readable.t<'a> = "stderr" @get - external stdin: t => Js.nullable> = "stdin" + external stdin: t => nullable> = "stdin" @get external stdout: t => Stream.Readable.t<'a> = "stdout" - @send external terminate: t => Js.Promise.t = "terminate" + @send external terminate: t => promise = "terminate" @get external threadId: t => int = "threadId" @send external unref: t => unit = "unref" } @@ -164,7 +164,7 @@ external receiveMessageOnPort: MessagePort.t<'a> => option<{..}> = "receiveMessa @val @module("node:worker_threads") external resourceLimits: workerResourceLimits = "resourceLimits" @val @module("node:worker_threads") -external _SHARE_ENV: Js.Types.symbol = "SHARE_ENV" +external _SHARE_ENV: Symbol.t = "SHARE_ENV" @val @module("node:worker_threads") external threadId: int = "threadId" @val @module("node:worker_threads") external workerData: 'a = "workerData" @@ -190,7 +190,7 @@ module WithMessageType = ( @val @module("node:worker_threads") external resourceLimits: workerResourceLimits = "resourceLimits" @val @module("node:worker_threads") - external _SHARE_ENV: Js.Types.symbol = "SHARE_ENV" + external _SHARE_ENV: Symbol.t = "SHARE_ENV" @val @module("node:worker_threads") external threadId: int = "threadId" @val @module("node:worker_threads") external workerData: T.message = "workerData" diff --git a/lib/js/src/WorkerThreads.bs.js b/src/WorkerThreads.res.js similarity index 64% rename from lib/js/src/WorkerThreads.bs.js rename to src/WorkerThreads.res.js index d495275..75e6cfb 100644 --- a/lib/js/src/WorkerThreads.bs.js +++ b/src/WorkerThreads.res.js @@ -6,7 +6,7 @@ function WithMessageType(T) { return {}; } -var $$MessagePort = { +let MessagePort = { WithMessageType: WithMessageType }; @@ -14,7 +14,7 @@ function WithMessageTypes(T) { return {}; } -var $$MessageChannel = { +let MessageChannel = { WithMessageTypes: WithMessageTypes }; @@ -22,19 +22,19 @@ function WithMessageType$1(T) { return {}; } -var $$Worker = { +let Worker = { WithMessageType: WithMessageType$1 }; function WithMessageType$2(T) { - var $$Worker = {}; + let Worker = {}; return { - $$Worker: $$Worker - }; + Worker: Worker + }; } -exports.$$MessagePort = $$MessagePort; -exports.$$MessageChannel = $$MessageChannel; -exports.$$Worker = $$Worker; +exports.MessagePort = MessagePort; +exports.MessageChannel = MessageChannel; +exports.Worker = Worker; exports.WithMessageType = WithMessageType$2; /* No side effect */ diff --git a/src/Zlib.res b/src/Zlib.res index af800a0..29ca399 100644 --- a/src/Zlib.res +++ b/src/Zlib.res @@ -1,4 +1,4 @@ @module("node:zlib") external deflateRawSync: Buffer.t => Buffer.t = "deflateRawSync" -@module("node:zlib") external deflateRaw: (Buffer.t, (. Buffer.t) => unit) => unit = "deflateRaw" +@module("node:zlib") external deflateRaw: (Buffer.t, Buffer.t => unit) => unit = "deflateRaw" @module("node:zlib") external inflateRawSync: Buffer.t => Buffer.t = "inflateRawSync" -@module("node:zlib") external inflateRaw: (Buffer.t, (. Buffer.t) => unit) => unit = "inflateRaw" +@module("node:zlib") external inflateRaw: (Buffer.t, Buffer.t => unit) => unit = "inflateRaw" diff --git a/lib/js/src/Zlib.bs.js b/src/Zlib.res.js similarity index 100% rename from lib/js/src/Zlib.bs.js rename to src/Zlib.res.js diff --git a/lib/js/src/internal/Internal__JsTypeReflection.bs.js b/src/internal/Internal__JsTypeReflection.res.js similarity index 61% rename from lib/js/src/internal/Internal__JsTypeReflection.bs.js rename to src/internal/Internal__JsTypeReflection.res.js index c7617ac..41210ed 100644 --- a/lib/js/src/internal/Internal__JsTypeReflection.bs.js +++ b/src/internal/Internal__JsTypeReflection.res.js @@ -11,9 +11,9 @@ function instanceOfClass(instance, _class) { } ; -function instanceOfClass$1(instance, class_) { - return instanceOfClass(instance, class_); +function instanceOfClass(instance, class_) { + return globalThis.instanceOfClass(instance, class_); } -exports.instanceOfClass = instanceOfClass$1; +exports.instanceOfClass = instanceOfClass; /* Not a pure module */ diff --git a/test/atomic/BigInt.test.res b/test/atomic/BigInt.test.res deleted file mode 100644 index fa32884..0000000 --- a/test/atomic/BigInt.test.res +++ /dev/null @@ -1,251 +0,0 @@ -open Zora - -zoraBlock("BigInt", t => { - Random.init(84611) - - let fourHundred = 400 - let randomInt = _ => Random.int(fourHundred) - - t->block( - "'BigInt.fromInt' and 'BigInt.toInt' are associative operations for all 32-bit integers", - t => { - let arrA = Belt.Array.makeByU(1000, (. _) => Random.int(1000000)) - let arrB = Belt.Array.map(arrA, BigInt.fromInt) - let arrC = Belt.Array.map(arrB, BigInt.toInt) - t->equal(arrA, arrC, "") - }, - ) - - t->block("BigInt.add", t => { - let a = randomInt() - let b = randomInt() - let c = a + b - - open BigInt - t->equal(add(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(+)", t => { - let a = randomInt() - let b = randomInt() - let c = a + b - - open! BigInt - t->equal(fromInt(a) + fromInt(b), BigInt.fromInt(c), "") - }) - - t->block("BigInt.subtract", t => { - let a = randomInt() - let b = randomInt() - let c = a - b - - open BigInt - t->equal(subtract(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(-)", t => { - let a = randomInt() - let b = randomInt() - let c = a - b - - open! BigInt - t->equal(fromInt(a) - fromInt(b), BigInt.fromInt(c), "") - }) - - t->block("BigInt.multiply", t => { - let a = randomInt() - let b = randomInt() - let c = a * b - - open BigInt - t->equal(multiply(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(*)", t => { - let a = randomInt() - let b = randomInt() - let c = a * b - - open! BigInt - t->equal(fromInt(a) * fromInt(b), BigInt.fromInt(c), "") - }) - - t->block("BigInt.divide", t => { - let a = randomInt() - let b = randomInt() - let c = a / b - - open BigInt - t->equal(divide(fromInt(a), fromInt(b)), fromInt(c), "") - }) - - t->block("BigInt.(/)", t => { - let a = randomInt() - let b = randomInt() - let c = a / b - - open! BigInt - t->equal(fromInt(a) / fromInt(b), BigInt.fromInt(c), "") - }) - - t->block("BigInt.negate", t => { - let a = randomInt() - let b = -a - - open BigInt - t->equal(negate(fromInt(a)), fromInt(b), "") - }) - - t->block("BigInt.(~-)", t => { - let a = randomInt() - let b = -a - - open! BigInt - t->equal(-fromInt(a), BigInt.fromInt(b), "") - }) - - t->block("BigInt.modulo", t => { - let a = randomInt() - let b = randomInt() - let c = mod(a, b) - - open BigInt - t->equal(modulo(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(mod)", t => { - let a = randomInt() - let b = randomInt() - let c = mod(a, b) - - open! BigInt - t->equal(mod(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.power", t => { - let a = Random.int(6)->Js.Int.toFloat - let b = Random.int(8)->Js.Int.toFloat - - let c = Js.Math.pow_float(~base=a, ~exp=b) - - open BigInt - t->equal(power(fromFloat(a), fromFloat(b)), BigInt.fromFloat(c), "") - }) - - t->block("BigInt.(**)", t => { - let a = Random.int(6)->Js.Int.toFloat - let b = Random.int(8)->Js.Int.toFloat - - @ocaml.warning("-3") - let c = Js.Math.pow_float(~base=a, ~exp=b) - - open! BigInt - t->equal(fromFloat(a) ** fromFloat(b), BigInt.fromFloat(c), "") - }) - - t->block("BigInt.logicalAnd", t => { - let a = Random.int(256) - let b = Random.int(256) - let c = land(a, b) - - open BigInt - t->equal(logicalAnd(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(land)", t => { - let a = Random.int(256) - let b = Random.int(256) - let c = land(a, b) - - open! BigInt - t->equal(land(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.logicalOr", t => { - let a = randomInt() - let b = randomInt() - let c = lor(a, b) - - open BigInt - t->equal(logicalOr(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(lor)", t => { - let a = randomInt() - let b = randomInt() - let c = lor(a, b) - - open! BigInt - t->equal(lor(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.logicalXor", t => { - let a = randomInt() - let b = randomInt() - let c = lxor(a, b) - - open BigInt - t->equal(logicalXor(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(lxor)", t => { - let a = randomInt() - let b = randomInt() - let c = lxor(a, b) - - open! BigInt - t->equal(lxor(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.logicalNot", t => { - let a = randomInt() - let b = lnot(a) - - open BigInt - t->equal(logicalNot(fromInt(a)), BigInt.fromInt(b), "") - }) - - t->block("BigInt.(lnot)", t => { - let a = randomInt() - let b = lnot(a) - - open! BigInt - t->equal(lnot(fromInt(a)), BigInt.fromInt(b), "") - }) - - t->block("BigInt.logicalShiftLeft", t => { - let a = 26 - let b = 7 - let c = lsl(a, b) - - open BigInt - t->equal(logicalShiftLeft(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(lsl)", t => { - let a = 26 - let b = 7 - let c = lsl(a, b) - - open! BigInt - t->equal(lsl(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.arithmeticShiftRight", t => { - let a = 32 - let b = 4 - let c = asr(a, b) - - open BigInt - t->equal(arithmeticShiftRight(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) - - t->block("BigInt.(asr)", t => { - let a = 32 - let b = 4 - let c = asr(a, b) - - open! BigInt - t->equal(asr(fromInt(a), fromInt(b)), BigInt.fromInt(c), "") - }) -}) diff --git a/test/atomic/BinaryLike.test.res b/test/atomic/BinaryLike.test.res index 4c5c629..a6bf571 100644 --- a/test/atomic/BinaryLike.test.res +++ b/test/atomic/BinaryLike.test.res @@ -1,26 +1,24 @@ open Zora zoraBlock("BinaryLike", t => { - open Js.TypedArray2 - let string_ = "test1234" let binaryLikeString = string_->BinaryLike.string let buffer_ = Buffer.fromArray([1, 2, 3, 4]) let binaryLikeBuffer = BinaryLike.buffer(buffer_) - let uInt8Array = Uint8Array.make([1, 2, 3, 4]) + let uInt8Array = Uint8Array.fromArray([1, 2, 3, 4]) let binaryLikeUint8Array = BinaryLike.uInt8Array(uInt8Array) - let int8Array = Int8Array.make([1, 2, 3, 4]) + let int8Array = Int8Array.fromArray([1, 2, 3, 4]) let binaryLikeInt8Array = BinaryLike.int8Array(int8Array) - let uInt8ClampedArray = Uint8ClampedArray.make([1, 2, 3, 4]) + let uInt8ClampedArray = Uint8ClampedArray.fromArray([1, 2, 3, 4]) let binaryLikeUint8ClampedArray = BinaryLike.uInt8ClampedArray(uInt8ClampedArray) - let uInt16Array = Uint16Array.make([1, 2, 3, 4]) + let uInt16Array = Uint16Array.fromArray([1, 2, 3, 4]) let binaryLikeUint16Array = BinaryLike.uInt16Array(uInt16Array) - let int16Array = Int16Array.make([1, 2, 3, 4]) + let int16Array = Int16Array.fromArray([1, 2, 3, 4]) let binaryLikeInt16Array = BinaryLike.int16Array(int16Array) t->block("BinaryLike.classify(string) should return a 'String' variant", t => { diff --git a/test/atomic/BinaryLike.test.res.js b/test/atomic/BinaryLike.test.res.js new file mode 100644 index 0000000..55546d9 --- /dev/null +++ b/test/atomic/BinaryLike.test.res.js @@ -0,0 +1,95 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let BinaryLike$NodeJs = require("../../src/BinaryLike.res.js"); + +Zora.test("BinaryLike", t => { + let binaryLikeString = BinaryLike$NodeJs.string("test1234"); + let buffer_ = Buffer.from([ + 1, + 2, + 3, + 4 + ]); + let binaryLikeBuffer = BinaryLike$NodeJs.buffer(buffer_); + let uInt8Array = new Uint8Array([ + 1, + 2, + 3, + 4 + ]); + let binaryLikeUint8Array = BinaryLike$NodeJs.uInt8Array(uInt8Array); + let int8Array = new Int8Array([ + 1, + 2, + 3, + 4 + ]); + let binaryLikeInt8Array = BinaryLike$NodeJs.int8Array(int8Array); + let uInt8ClampedArray = new Uint8ClampedArray([ + 1, + 2, + 3, + 4 + ]); + let binaryLikeUint8ClampedArray = BinaryLike$NodeJs.uInt8ClampedArray(uInt8ClampedArray); + let uInt16Array = new Uint16Array([ + 1, + 2, + 3, + 4 + ]); + let binaryLikeUint16Array = BinaryLike$NodeJs.uInt16Array(uInt16Array); + let int16Array = new Int16Array([ + 1, + 2, + 3, + 4 + ]); + let binaryLikeInt16Array = BinaryLike$NodeJs.int16Array(int16Array); + t.test("BinaryLike.classify(string) should return a 'String' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeString); + let tmp; + tmp = match.TAG === "String"; + t.ok(tmp, ""); + }); + t.test("BinaryLike.classify(buffer) should return a 'Buffer' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeBuffer); + let tmp; + tmp = match.TAG === "Buffer"; + t.ok(tmp, ""); + }); + t.test("BinaryLike.classify(uInt8Array) should return a 'Uint8Array' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeUint8Array); + let tmp; + tmp = match.TAG === "Uint8Array"; + t.ok(tmp, ""); + }); + t.test("BinaryLike.classify(int8Array) should return a 'Int8Array' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeInt8Array); + let tmp; + tmp = match.TAG === "Int8Array"; + t.ok(tmp, ""); + }); + t.test("BinaryLike.classify(uInt8ClampedArray) should return a 'Uint8ClampedArray' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeUint8ClampedArray); + let tmp; + tmp = match.TAG === "Uint8ClampedArray"; + t.ok(tmp, ""); + }); + t.test("BinaryLike.classify(uInt16Array) should return a 'Uint16Array' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeUint16Array); + let tmp; + tmp = match.TAG === "Uint16Array"; + t.ok(tmp, ""); + }); + t.test("BinaryLike.classify(int16Array) should return a 'Int16Array' variant", t => { + let match = BinaryLike$NodeJs.classify(binaryLikeInt16Array); + let tmp; + tmp = match.TAG === "Int16Array"; + t.ok(tmp, ""); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Console.test.res b/test/atomic/Console.test.res index 64bb2d6..d8731af 100644 --- a/test/atomic/Console.test.res +++ b/test/atomic/Console.test.res @@ -20,7 +20,7 @@ zoraBlock("Console", t => { "stdout": Process.stdout(process), }) - Js.log("=== Testing console output styles ===") + Stdlib.Console.log("=== Testing console output styles ===") c1->Console.logMany(["a", "b"]) c2->Console.table(["hi", "bye"]) c2->Console.table([ @@ -34,12 +34,12 @@ zoraBlock("Console", t => { "this": "is", "an": "object", }) - Js.log("=== END testing console output styles ===") + Stdlib.Console.log("=== END testing console output styles ===") t->block("New console instance should be defined", t => - t->notEqual(Js.Undefined.return(c1), Js.Undefined.empty, "") + t->notEqual(Nullable.make(c1), Nullable.undefined, "") ) t->block("New console instance should be defined", t => - t->notEqual(Js.Undefined.return(c2), Js.Undefined.empty, "") + t->notEqual(Nullable.make(c2), Nullable.undefined, "") ) }) diff --git a/test/atomic/Console.test.res.js b/test/atomic/Console.test.res.js new file mode 100644 index 0000000..7d7774c --- /dev/null +++ b/test/atomic/Console.test.res.js @@ -0,0 +1,50 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Process = require("process"); +let Nodeconsole = require("node:console"); +let Primitive_option = require("@rescript/runtime/lib/js/Primitive_option.js"); + +let process = Process; + +Zora.test("Console", t => { + let c1 = new Nodeconsole.Console({ + stdout: process.stdout, + stderr: Primitive_option.some(process.stderr), + ignoreErrors: false, + colorMode: true, + inspectOptions: {} + }); + let c2 = new Nodeconsole.Console({ + stderr: process.stderr, + ignoreErrors: false, + colorMode: true, + stdout: process.stdout + }); + console.log("=== Testing console output styles ==="); + c1.log("a", "b"); + c2.table([ + "hi", + "bye" + ]); + c2.table([{ + a: 1, + b: 2 + }]); + console.dir({ + hello: "world", + this: "is", + an: "object" + }); + console.log("=== END testing console output styles ==="); + t.test("New console instance should be defined", t => { + t.notEqual(c1, undefined, ""); + }); + t.test("New console instance should be defined", t => { + t.notEqual(c2, undefined, ""); + }); +}); + +exports.process = process; +/* process Not a pure module */ diff --git a/test/atomic/EventEmitter.test.res b/test/atomic/EventEmitter.test.res index 330265a..aa75269 100644 --- a/test/atomic/EventEmitter.test.res +++ b/test/atomic/EventEmitter.test.res @@ -3,8 +3,8 @@ open EventEmitterTestLib zoraBlock("EventEmitter", t => { t->notEqual( - Emitter1.make()->Js.Undefined.return, - Js.Undefined.empty, + Emitter1.make()->Nullable.make, + Nullable.undefined, "'Emitter.make' should create a new emitter instance that is defined", ) @@ -40,9 +40,9 @@ zoraBlock("EventEmitter", t => { let listeners = { open Emitter1 make() - |> on(_, Events.text, eventListener) - |> removeListener(_, Events.text, eventListener) - |> listeners(_, Events.text) + ->on(Events.text, eventListener) + ->removeListener(Events.text, eventListener) + ->listeners(Events.text) } t->equal(Array.length(listeners), 0, "") }) @@ -52,9 +52,9 @@ zoraBlock("EventEmitter", t => { let listeners = { open Emitter1 make() - |> on(_, Events.text, eventListener) - |> off(_, Events.text, eventListener) - |> listeners(_, Events.text) + ->on(Events.text, eventListener) + ->off(Events.text, eventListener) + ->listeners(Events.text) } t->equal(Array.length(listeners), 0, "") }) @@ -69,7 +69,7 @@ zoraBlock("EventEmitter", t => { { open Emitter1 - let emitter = make() |> on(_, Events.integer, listener1) |> on(_, Events.integer, listener2) + let emitter = make()->on(Events.integer, listener1)->on(Events.integer, listener2) emit(emitter, Events.integer, data1)->ignore emit(emitter, Events.integer, data2)->ignore } @@ -83,9 +83,9 @@ zoraBlock("EventEmitter", t => { let emitter = { open Emitter1 make() - |> on(_, Events.text, eventListener) - |> on(_, Events.text, eventListener) - |> on(_, Events.text, eventListener) + ->on(Events.text, eventListener) + ->on(Events.text, eventListener) + ->on(Events.text, eventListener) } // Make sure 3 listeners were indeed added: Assert.strictEqual( diff --git a/test/atomic/EventEmitter.test.res.js b/test/atomic/EventEmitter.test.res.js new file mode 100644 index 0000000..8b8f873 --- /dev/null +++ b/test/atomic/EventEmitter.test.res.js @@ -0,0 +1,52 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Nodeassert = require("node:assert"); +let Nodeevents = require("node:events"); +let EventEmitterTestLib$NodeJs = require("../module/EventEmitterTestLib.res.js"); + +Zora.test("EventEmitter", t => { + t.notEqual(new Nodeevents.EventEmitter(), undefined, "'Emitter.make' should create a new emitter instance that is defined"); + t.equal(new Nodeevents.EventEmitter().addListener(EventEmitterTestLib$NodeJs.Emitter1.Events.text, param => {}).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 1, "'Emitter.addListener' should add a new event listener"); + t.equal(new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, param => {}).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 1, "'Emitter.on' should add a new event listener"); + t.equal(new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, param => {}).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 1, "'Emitter.on' should add a new event listener"); + t.test("'Emitter.removeListener' should remove the event listener", t => { + let eventListener = param => {}; + let listeners = new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener).removeListener(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text); + t.equal(listeners.length, 0, ""); + }); + t.test("'Emitter.off' should remove the event listener", t => { + let eventListener = param => {}; + let listeners = new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener).off(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener).listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text); + t.equal(listeners.length, 0, ""); + }); + t.test("'Emitter.emit' should execute each listener for the correct event", t => { + let ref1 = { + contents: 0 + }; + let ref2 = { + contents: 0 + }; + let listener1 = param => { + ref1.contents = 1; + }; + let listener2 = param => { + ref2.contents = 2; + }; + let emitter = new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, listener1).on(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, listener2); + emitter.emit(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, 1); + emitter.emit(EventEmitterTestLib$NodeJs.Emitter1.Events.integer, 2); + t.equal(ref1.contents, 1, ""); + t.equal(ref2.contents, 2, ""); + }); + t.test("'Emitter.removeAllListeners' should remove all event listeners", t => { + let eventListener = param => {}; + let emitter = new Nodeevents.EventEmitter().on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener).on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener).on(EventEmitterTestLib$NodeJs.Emitter1.Events.text, eventListener); + Nodeassert.strictEqual(emitter.listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 3); + emitter.removeAllListeners(); + t.equal(emitter.listeners(EventEmitterTestLib$NodeJs.Emitter1.Events.text).length, 0, ""); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Fs.test.res b/test/atomic/Fs.test.res index 0815117..2ea172e 100644 --- a/test/atomic/Fs.test.res +++ b/test/atomic/Fs.test.res @@ -17,6 +17,6 @@ zora("Fs", async t => { let _ = await FileHandle.close(fh) let needle = "Random string: uCF6c5f3Arrq" - t->ok(Js.String.indexOf(needle, buffer) > 0, "buffer string indexOf was not greater than zero") + t->ok(buffer->String.indexOf(needle) > 0, "buffer string indexOf was not greater than zero") }) }) diff --git a/test/atomic/Fs.test.res.js b/test/atomic/Fs.test.res.js new file mode 100644 index 0000000..45b764d --- /dev/null +++ b/test/atomic/Fs.test.res.js @@ -0,0 +1,24 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Nodefs = require("node:fs"); + +Zora.test("Fs", async t => { + t.test("readFile should read entire file", async t => { + let fh = await Nodefs.promises.open(__filename, "r"); + let buffer = await fh.readFile(); + await fh.close(); + t.ok(buffer.indexOf("Random string: Gh2e71pdHhPxU") > 1, "buffer index was not greater than zero"); + }); + t.test("readFileWith should read entire file as a string", async t => { + let fh = await Nodefs.promises.open(__filename, "r"); + let buffer = await fh.readFile({ + encoding: "UTF-8" + }); + await fh.close(); + t.ok(buffer.indexOf("Random string: uCF6c5f3Arrq") > 0, "buffer string indexOf was not greater than zero"); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Global.test.res b/test/atomic/Global.test.res index 334af8e..207ef8b 100644 --- a/test/atomic/Global.test.res +++ b/test/atomic/Global.test.res @@ -2,37 +2,35 @@ open Zora zoraBlock("Global", t => { t->block("dirname should be defined", t => - t->notEqual(Js.Undefined.return(Global.dirname), Js.Undefined.empty, "") - ) - t->block("dirname should be of type 'string'", t => - t->equal(Global.dirname->Js.typeof, "string", "") + t->notEqual(Nullable.make(Global.dirname), Nullable.undefined, "") ) + t->block("dirname should be of type 'string'", t => t->equal(Global.dirname->typeof, #string, "")) t->block("filename should be defined", t => - t->notEqual(Js.Undefined.return(Global.filename), Js.Undefined.empty, "") + t->notEqual(Nullable.make(Global.filename), Nullable.undefined, "") ) t->block("filename should be of type 'string'", t => - t->equal(Global.filename->Js.typeof, "string", "") + t->equal(Global.filename->typeof, #string, "") ) t->block("'global object' should be defined", t => - t->notEqual(Js.Undefined.return(Global.global), Js.Undefined.empty, "") + t->notEqual(Nullable.make(Global.global), Nullable.undefined, "") ) t->block("'global' object should be of type 'object'", t => - t->equal(Global.global->Js.typeof, "object", "") + t->equal(Global.global->typeof, #object, "") ) t->block("'require' function should be defined", t => - t->notEqual(Js.Undefined.return(Global.require), Js.Undefined.empty, "") + t->notEqual(Nullable.make(Global.require), Nullable.undefined, "") ) t->block("'require' function should be defined", t => - t->equal(Global.require->Js.typeof, "function", "") + t->equal(Global.require->typeof, #function, "") ) t->block("'require' fuction should return a defined value from a relative path", t => - t->notEqual(Js.Undefined.return(Global.require("path")), Js.Undefined.empty, "") + t->notEqual(Nullable.make(Global.require("path")), Nullable.undefined, "") ) t->block("'require' fuction should successfully import a module object from a relative path", t => - t->equal(Global.require("path")->Js.typeof, "object", "") + t->equal(Global.require("path")->typeof, #object, "") ) }) diff --git a/test/atomic/Global.test.res.js b/test/atomic/Global.test.res.js new file mode 100644 index 0000000..12afcce --- /dev/null +++ b/test/atomic/Global.test.res.js @@ -0,0 +1,39 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); + +Zora.test("Global", t => { + t.test("dirname should be defined", t => { + t.notEqual(__dirname, undefined, ""); + }); + t.test("dirname should be of type 'string'", t => { + t.equal(typeof __dirname, "string", ""); + }); + t.test("filename should be defined", t => { + t.notEqual(__filename, undefined, ""); + }); + t.test("filename should be of type 'string'", t => { + t.equal(typeof __filename, "string", ""); + }); + t.test("'global object' should be defined", t => { + t.notEqual(global, undefined, ""); + }); + t.test("'global' object should be of type 'object'", t => { + t.equal(typeof global, "object", ""); + }); + t.test("'require' function should be defined", t => { + t.notEqual(prim => require(prim), undefined, ""); + }); + t.test("'require' function should be defined", t => { + t.equal(typeof (prim => require(prim)), "function", ""); + }); + t.test("'require' fuction should return a defined value from a relative path", t => { + t.notEqual(require("path"), undefined, ""); + }); + t.test("'require' fuction should successfully import a module object from a relative path", t => { + t.equal(typeof require("path"), "object", ""); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Path.test.res.js b/test/atomic/Path.test.res.js new file mode 100644 index 0000000..d8eedf9 --- /dev/null +++ b/test/atomic/Path.test.res.js @@ -0,0 +1,13 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Nodepath = require("node:path"); + +Zora.test("Path", t => { + t.test("basename should isolate filename with extension", t => { + t.equal(Nodepath.posix.basename("/tmp/myfile.html"), "myfile.html", ""); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Stream.test.res b/test/atomic/Stream.test.res index c614efc..7091986 100644 --- a/test/atomic/Stream.test.res +++ b/test/atomic/Stream.test.res @@ -4,7 +4,7 @@ open StreamTestLib zoraBlock("Stream.Readable", t => { t->block("'Stream.Readable.make' should return a defined value", t => { let readable = makeReadableEmpty() - t->notEqual(readable->Js.Undefined.return, Js.Undefined.empty, "") + t->notEqual(readable->Nullable.make, Nullable.undefined, "") }) t->block("'Stream.Readable.make' should return an instance of 'Readable'", t => { @@ -21,8 +21,8 @@ zoraBlock("Stream.Readable", t => { t->test("'Stream.Readable.destroyWithError' should emit 'error' event", t => { open! Errors let dummyError = Error.make("Expected error: Stream destroyed")->Error.toJsExn - Js.Promise2.make( - (~resolve, ~reject as _) => { + Promise.make( + (resolve, _) => { let stream = StreamTestLib.makeReadableEmpty()->Stream.onError( err => { t->equal(err, dummyError, "") @@ -30,7 +30,7 @@ zoraBlock("Stream.Readable", t => { }, ) - Js.Global.setTimeout(() => stream->Stream.destroyWithError(dummyError)->ignore, 10)->ignore + setTimeout(() => stream->Stream.destroyWithError(dummyError)->ignore, 10)->ignore }, ) }) @@ -44,7 +44,7 @@ zoraBlock("Stream.Readable", t => { zoraBlock("Stream.Writable", t => { t->block("'Stream.Writable.make' should return a defined value", t => { let writable = makeWritableEmpty() - t->notEqual(writable->Js.Undefined.return, Js.Undefined.empty, "") + t->notEqual(writable->Nullable.make, Nullable.undefined, "") }) t->block("'Stream.Writable.make' should return an instance of 'Writable'", t => { @@ -65,11 +65,10 @@ zoraBlock("Stream.Writable", t => { args := Some((wstream, data, encoding, callback)) callback(~error=None) }, - (), ) - Js.Promise2.make( - (~resolve, ~reject as _) => { + Promise.make( + (resolve, _) => { let writeStream = Writable.makeObjMode(options) Writable.writeWith( @@ -81,19 +80,18 @@ zoraBlock("Stream.Writable", t => { | Some((wstream, value, encoding, cb)) => Some(( Internal__JsTypeReflection.constructorName(wstream), - Js.typeof(value), + typeof(value), encoding, - Js.typeof(cb), + typeof(cb), )) } - t->equal(actual, Some(("Writable", "number", Js.null, "function")), "") + t->equal(actual, Some(("Writable", #number, Null.null, #function)), "") resolve() }, - (), )->ignore }, ) }, ) -}) \ No newline at end of file +}) diff --git a/test/atomic/Stream.test.res.js b/test/atomic/Stream.test.res.js new file mode 100644 index 0000000..f7d119e --- /dev/null +++ b/test/atomic/Stream.test.res.js @@ -0,0 +1,88 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Nodestream = require("node:stream"); +let StreamTestLib$NodeJs = require("../module/StreamTestLib.res.js"); + +Zora.test("Stream.Readable", t => { + t.test("'Stream.Readable.make' should return a defined value", t => { + let readable = StreamTestLib$NodeJs.makeReadableEmpty(); + t.notEqual(readable, undefined, ""); + }); + t.test("'Stream.Readable.make' should return an instance of 'Readable'", t => { + let readable = StreamTestLib$NodeJs.makeReadableEmpty(); + t.equal(readable.constructor.name, "Readable", ""); + }); + t.test("'Stream.Readable.pipe' returns a writable stream", t => { + let readable = StreamTestLib$NodeJs.makeReadableEmpty(); + let writable = StreamTestLib$NodeJs.makeWritableEmpty(); + t.equal(readable.pipe(writable), writable, ""); + }); + t.test("'Stream.Readable.destroyWithError' should emit 'error' event", t => { + let dummyError = new Error("Expected error: Stream destroyed"); + return new Promise((resolve, param) => { + let stream = StreamTestLib$NodeJs.makeReadableEmpty().on("error", err => { + t.equal(err, dummyError, ""); + resolve(); + }); + setTimeout(() => { + stream.destroy(dummyError); + }, 10); + }); + }); + t.test("'Stream.Readable.destroy' should return the exact same instance of 'Readable'", t => { + let readable = StreamTestLib$NodeJs.makeReadableEmpty(); + t.equal(readable.destroy(), readable, ""); + }); +}); + +Zora.test("Stream.Writable", t => { + t.test("'Stream.Writable.make' should return a defined value", t => { + let writable = StreamTestLib$NodeJs.makeWritableEmpty(); + t.notEqual(writable, undefined, ""); + }); + t.test("'Stream.Writable.make' should return an instance of 'Writable'", t => { + let writable = StreamTestLib$NodeJs.makeWritableEmpty(); + t.equal(writable.constructor.name, "Writable", ""); + }); + t.test("Stream.Writable.makeObjMode should have a 'write' function with the correct function signature", t => { + let args = { + contents: undefined + }; + let options = { + objectMode: true, + write: function (data, encoding, callback) { + let wstream = this ; + args.contents = [ + wstream, + data, + encoding, + callback + ]; + callback(undefined); + } + }; + return new Promise((resolve, param) => { + let writeStream = new Nodestream.Writable(options); + writeStream.write(42, param => { + let match = args.contents; + let actual = match !== undefined ? [ + match[0].constructor.name, + typeof match[1], + match[2], + typeof match[3] + ] : undefined; + t.equal(actual, [ + "Writable", + "number", + null, + "function" + ], ""); + resolve(); + }); + }); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Timers.test.res.js b/test/atomic/Timers.test.res.js new file mode 100644 index 0000000..4fe7e90 --- /dev/null +++ b/test/atomic/Timers.test.res.js @@ -0,0 +1,18 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Promises = require("node:timers/promises"); + +Zora.test("Timers (promises)", async t => { + t.test("setTimeout", async t => { + await Promises.setTimeout(100); + t.ok(true, ""); + }); + t.test("setImmediate", async t => { + let yes = await Promises.setImmediate("yes"); + t.equal(yes, "yes", ""); + }); +}); + +/* Not a pure module */ diff --git a/test/atomic/Util.test.res b/test/atomic/Util.test.res index d661192..9337aac 100644 --- a/test/atomic/Util.test.res +++ b/test/atomic/Util.test.res @@ -2,7 +2,7 @@ open Zora zoraBlock("Util.Types", t => { t->block("Util.Types.isAnyArrayBuffer(arrayBuffer) should return true", t => { - let arrayBuffer = Js.TypedArray2.ArrayBuffer.make(16) + let arrayBuffer = ArrayBuffer.make(16) t->equal(arrayBuffer->Util.Types.isAnyArrayBuffer, true, "") }) diff --git a/test/atomic/Util.test.res.js b/test/atomic/Util.test.res.js new file mode 100644 index 0000000..09c6490 --- /dev/null +++ b/test/atomic/Util.test.res.js @@ -0,0 +1,17 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Zora = require("zora"); +let Nodeutil = require("node:util"); + +Zora.test("Util.Types", t => { + t.test("Util.Types.isAnyArrayBuffer(arrayBuffer) should return true", t => { + let arrayBuffer = new ArrayBuffer(16); + t.equal(Nodeutil.types.isAnyArrayBuffer(arrayBuffer), true, ""); + }); + t.test("Util.Types.isAnyArrayBuffer(string) should return false", t => { + t.equal(Nodeutil.types.isAnyArrayBuffer("not array buffer"), false, ""); + }); +}); + +/* Not a pure module */ diff --git a/test/codegen/Readline.codegen.res b/test/codegen/Readline.codegen.res index d4a0288..69cfe0a 100644 --- a/test/codegen/Readline.codegen.res +++ b/test/codegen/Readline.codegen.res @@ -1,23 +1,15 @@ // codegen verification only, not intended to run Readline.clearLine(Process.stdout(Process.process), 1, ~callback=() => - Js.log("line cleared") + Stdlib.Console.log("line cleared") )->ignore Readline.clearScreenDown(Process.stdout(Process.process), ~callback=() => - Js.log("screen cleared") + Stdlib.Console.log("screen cleared") )->ignore -Readline.cursorTo( - Process.stdout(Process.process), - ~x=1, - ~y=2, - ~callback=() => Js.log("cursor to"), - (), +Readline.cursorTo(Process.stdout(Process.process), ~x=1, ~y=2, ~callback=() => + Stdlib.Console.log("cursor to") )->ignore -Readline.moveCursor( - Process.stdout(Process.process), - ~dx=1, - ~dy=2, - ~callback=() => Js.log("cursor moved"), - (), +Readline.moveCursor(Process.stdout(Process.process), ~dx=1, ~dy=2, ~callback=() => + Stdlib.Console.log("cursor moved") )->ignore diff --git a/test/codegen/Readline.codegen.res.js b/test/codegen/Readline.codegen.res.js new file mode 100644 index 0000000..4b72d7f --- /dev/null +++ b/test/codegen/Readline.codegen.res.js @@ -0,0 +1,23 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Process = require("process"); +let Nodereadline = require("node:readline"); + +Nodereadline.clearLine(Process.stdout, 1, () => { + console.log("line cleared"); +}); + +Nodereadline.clearScreenDown(Process.stdout, () => { + console.log("screen cleared"); +}); + +Nodereadline.cursorTo(Process.stdout, 1, 2, () => { + console.log("cursor to"); +}); + +Nodereadline.moveCursor(Process.stdout, 1, 2, () => { + console.log("cursor moved"); +}); + +/* Not a pure module */ diff --git a/test/module/EventEmitterTestLib.res b/test/module/EventEmitterTestLib.res index 61b898c..e36e5c8 100644 --- a/test/module/EventEmitterTestLib.res +++ b/test/module/EventEmitterTestLib.res @@ -1,12 +1,12 @@ module Emitter1 = { include EventEmitter.Make() - let uniqueSymbol: Js.Types.symbol = %raw(`Symbol("emitter1")`) + let uniqueSymbol: Symbol.t = %raw(`Symbol("emitter1")`) module Events = { - let symbol: Event.t unit, t> = Event.fromSymbol(uniqueSymbol) + let symbol: Event.t unit, t> = Event.fromSymbol(uniqueSymbol) let text: Event.t unit, t> = Event.fromString("text") let integer: Event.t unit, t> = Event.fromString("integer") let textAndInteger: Event.t<(string, int) => unit, t> = Event.fromString2("textAndInteger") } -} \ No newline at end of file +} diff --git a/lib/js/test/module/EventEmitterTestLib.bs.js b/test/module/EventEmitterTestLib.res.js similarity index 68% rename from lib/js/test/module/EventEmitterTestLib.bs.js rename to test/module/EventEmitterTestLib.res.js index a5a73f6..bbacdca 100644 --- a/lib/js/test/module/EventEmitterTestLib.bs.js +++ b/test/module/EventEmitterTestLib.res.js @@ -1,20 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -var EventEmitter$NodeJs = require("../../src/EventEmitter.bs.js"); +let EventEmitter$NodeJs = require("../../src/EventEmitter.res.js"); EventEmitter$NodeJs.Make({}); -var uniqueSymbol = (Symbol("emitter1")); +let uniqueSymbol = (Symbol("emitter1")); -var Events = { +let Events = { symbol: uniqueSymbol, text: "text", integer: "integer", textAndInteger: "textAndInteger" }; -var Emitter1 = { +let Emitter1 = { uniqueSymbol: uniqueSymbol, Events: Events }; diff --git a/test/module/StreamTestLib.res b/test/module/StreamTestLib.res index c338dd0..aed161a 100644 --- a/test/module/StreamTestLib.res +++ b/test/module/StreamTestLib.res @@ -2,10 +2,9 @@ let makeReadableEmpty = () => { open Stream.Readable let options = makeOptions( - ~destroy=@this (_, ~error, ~callback) => callback(~error=Js.Nullable.toOption(error)), + ~destroy=@this (_, ~error, ~callback) => callback(~error=Nullable.toOption(error)), ~read=@this (_, ~size as _) => (), ~autoDestroy=true, - (), ) make(options) } @@ -14,10 +13,9 @@ let makeReadableEmpty = () => { let makeWritableEmpty = () => { open Stream.Writable let options = makeOptions( - ~destroy=@this (_, ~error, ~callback) => callback(~error=Js.Nullable.toOption(error)), + ~destroy=@this (_, ~error, ~callback) => callback(~error=Nullable.toOption(error)), ~write=@this (_, ~data as _, ~encoding as _, ~callback) => callback(~error=None), ~autoDestroy=true, - (), ) make(options) } diff --git a/test/module/StreamTestLib.res.js b/test/module/StreamTestLib.res.js new file mode 100644 index 0000000..90b4d9e --- /dev/null +++ b/test/module/StreamTestLib.res.js @@ -0,0 +1,35 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +let Nodestream = require("node:stream"); +let Primitive_option = require("@rescript/runtime/lib/js/Primitive_option.js"); + +function makeReadableEmpty() { + return new Nodestream.Readable({ + objectMode: false, + autoDestroy: true, + destroy: function (error, callback) { + callback((error == null) ? undefined : Primitive_option.some(error)); + }, + read: function (param) { + + } + }); +} + +function makeWritableEmpty() { + return new Nodestream.Writable({ + objectMode: false, + autoDestroy: true, + destroy: function (error, callback) { + callback((error == null) ? undefined : Primitive_option.some(error)); + }, + write: function (param, param$1, callback) { + callback(undefined); + } + }); +} + +exports.makeReadableEmpty = makeReadableEmpty; +exports.makeWritableEmpty = makeWritableEmpty; +/* node:stream Not a pure module */ diff --git a/yarn.lock b/yarn.lock index 3626995..916bb44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -99,6 +99,48 @@ __metadata: languageName: node linkType: hard +"@rescript/darwin-arm64@npm:12.2.0": + version: 12.2.0 + resolution: "@rescript/darwin-arm64@npm:12.2.0" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@rescript/darwin-x64@npm:12.2.0": + version: 12.2.0 + resolution: "@rescript/darwin-x64@npm:12.2.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@rescript/linux-arm64@npm:12.2.0": + version: 12.2.0 + resolution: "@rescript/linux-arm64@npm:12.2.0" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"@rescript/linux-x64@npm:12.2.0": + version: 12.2.0 + resolution: "@rescript/linux-x64@npm:12.2.0" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@rescript/runtime@npm:12.2.0": + version: 12.2.0 + resolution: "@rescript/runtime@npm:12.2.0" + checksum: 59c0194ae52fbbaadc736bbf1cfac1ed6ffde92b2346e36b9f1a29bb136e38b7ef203c780647203912fa657d293eab5c4e208f04dd65ed4bf47d53843980f7e1 + languageName: node + linkType: hard + +"@rescript/win32-x64@npm:12.2.0": + version: 12.2.0 + resolution: "@rescript/win32-x64@npm:12.2.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "abbrev@npm:^2.0.0": version: 2.0.0 resolution: "abbrev@npm:2.0.0" @@ -971,19 +1013,39 @@ __metadata: changie: "npm:^1.18.0" onchange: "npm:^7.1.0" pta: "npm:1.2.0" - rescript: "npm:^11.1.0" + rescript: "npm:^12.2.0" zora: "npm:^5.2.0" languageName: unknown linkType: soft -"rescript@npm:^11.1.0": - version: 11.1.4 - resolution: "rescript@npm:11.1.4" +"rescript@npm:^12.2.0": + version: 12.2.0 + resolution: "rescript@npm:12.2.0" + dependencies: + "@rescript/darwin-arm64": "npm:12.2.0" + "@rescript/darwin-x64": "npm:12.2.0" + "@rescript/linux-arm64": "npm:12.2.0" + "@rescript/linux-x64": "npm:12.2.0" + "@rescript/runtime": "npm:12.2.0" + "@rescript/win32-x64": "npm:12.2.0" + dependenciesMeta: + "@rescript/darwin-arm64": + optional: true + "@rescript/darwin-x64": + optional: true + "@rescript/linux-arm64": + optional: true + "@rescript/linux-x64": + optional: true + "@rescript/win32-x64": + optional: true bin: - bsc: bsc - bstracing: lib/bstracing - rescript: rescript - checksum: 7f12186a84209f586457a60e65755fcdfbcbb503ac805c60ab5132ce4c927bc264c3b851419ed5498ba7dc4066723377bb7453f893f482a0ccd424986d02beba + bsc: cli/bsc.js + bstracing: cli/bstracing.js + rescript: cli/rescript.js + rescript-legacy: cli/rescript-legacy.js + rescript-tools: cli/rescript-tools.js + checksum: 7650a77a66e2f2ba2523eac54fd930f0b70bad922e9b498678e701e842a56c7b6facd0daf1ef9c7b71d344d9483a0293d17db72a67515a22d07856bdfc34fb46 languageName: node linkType: hard