Skip to content

Commit d493850

Browse files
authored
Merge branch 'master' into release/13.0.0-beta.2
2 parents 9efd4c7 + 097667a commit d493850

File tree

4 files changed

+113
-19
lines changed

4 files changed

+113
-19
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# reason-node
1+
# reason-nodejs
22

33
## Project Status
44

@@ -26,7 +26,7 @@ This library is still under construction. Some of the core design details are st
2626
Using the [yarn](https://yarnpkg.com/) package manager:
2727

2828
```shell
29-
yarn install reason-nodejs
29+
yarn add reason-nodejs
3030
```
3131

3232
Using the [npm](https://www.npmjs.com/) package manager:
@@ -37,12 +37,12 @@ npm i reason-nodejs
3737

3838
## Goal of this library
3939

40-
Help all Reason Node.js apps and libaries to be built faster by reducing the time spent on hand written bindings.
40+
Help all Reason Node.js apps and libraries to be built faster by reducing the time spent on hand written bindings.
4141

4242
## Non-Goals
4343

4444
- Have 100% coverage of Node.js api surface - Due to lack of man power for testing and maintaining, we should only have enough surface to cover all common use cases. But we should have enough coverage that developers only rarely have to write a custom binding.
45-
- Ensure all APIs are idiomatic Reason and 100% typesafe - This library should be as barebones as possible to allow for minimal context switching between offical Node.js documentation and the Reason equilvalent. And due to the dynamic nature of the JS API, bending it to be idiomatic Reason will lead to a ton of bikeshedding in design as well as sacrificing maintainability.
45+
- Ensure all APIs are idiomatic Reason and 100% typesafe - This library should be as low-level as possible to allow for minimal context switching between offical Node.js documentation and the Reason equilvalent. And due to the dynamic nature of the JS API, bending it to be idiomatic Reason will lead to a ton of bikeshedding in design as well as sacrificing maintainability.
4646

4747
## Principles
4848

src/Fs.re

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,68 @@ module Stats = {
7373
};
7474

7575
module Constants = {
76-
[@bs.module "fs"] [@bs.val] [@bs.scope "constants"]
77-
external f_ok: int = "F_OK";
78-
[@bs.module "fs"] [@bs.val] [@bs.scope "constants"]
79-
external w_ok: int = "W_OK";
80-
[@bs.module "fs"] [@bs.val] [@bs.scope "constants"]
81-
external r_ok: int = "R_OK";
82-
[@bs.module "fs"] [@bs.val] [@bs.scope "constants"]
83-
external x_ok: int = "X_OK";
76+
type t = pri int;
77+
78+
/** Bitwise 'or' i.e. JavaScript [x | y] */
79+
external (lor): (t, t) => t = "%orint";
80+
81+
[@text "{1 File Access Constants}"];
82+
83+
[@bs.module "fs"] [@bs.scope "constants"] external f_ok: t = "F_OK";
84+
[@bs.module "fs"] [@bs.scope "constants"] external w_ok: t = "W_OK";
85+
[@bs.module "fs"] [@bs.scope "constants"] external r_ok: t = "R_OK";
86+
[@bs.module "fs"] [@bs.scope "constants"] external x_ok: t = "X_OK";
87+
88+
[@text "{1 File Copy Constants}"];
89+
90+
[@bs.module "fs"] [@bs.scope "constants"] external copyfile_excl: t = "COPYFILE_EXCL";
91+
[@bs.module "fs"] [@bs.scope "constants"] external copyfile_ficlone: t = "COPYFILE_FICLONE";
92+
[@bs.module "fs"] [@bs.scope "constants"] external copyfile_ficlone_force: t = "COPYFILE_FICLONE_FORCE";
93+
94+
[@text "{1 File Open Constants}"];
95+
96+
[@bs.module "fs"] [@bs.scope "constants"] external o_rdonly: t = "O_RDONLY";
97+
[@bs.module "fs"] [@bs.scope "constants"] external o_wronly: t = "O_WRONLY";
98+
[@bs.module "fs"] [@bs.scope "constants"] external o_rdwr: t = "O_RDWR";
99+
[@bs.module "fs"] [@bs.scope "constants"] external o_creat: t = "O_CREAT";
100+
[@bs.module "fs"] [@bs.scope "constants"] external o_excl: t = "O_EXCL";
101+
[@bs.module "fs"] [@bs.scope "constants"] external o_noctty: t = "O_NOCTTY";
102+
[@bs.module "fs"] [@bs.scope "constants"] external o_trunc: t = "O_TRUNC";
103+
[@bs.module "fs"] [@bs.scope "constants"] external o_append: t = "O_APPEND";
104+
[@bs.module "fs"] [@bs.scope "constants"] external o_directory: t = "O_DIRECTORY";
105+
[@bs.module "fs"] [@bs.scope "constants"] external o_noatime: t = "O_NOATIME";
106+
[@bs.module "fs"] [@bs.scope "constants"] external o_nofollow: t = "O_NOFOLLOW";
107+
[@bs.module "fs"] [@bs.scope "constants"] external o_sync: t = "O_SYNC";
108+
[@bs.module "fs"] [@bs.scope "constants"] external o_dsync: t = "O_DSYNC";
109+
[@bs.module "fs"] [@bs.scope "constants"] external o_symlink: t = "O_SYMLINK";
110+
[@bs.module "fs"] [@bs.scope "constants"] external o_direct: t = "O_DIRECT";
111+
[@bs.module "fs"] [@bs.scope "constants"] external o_nonblock: t = "O_NONBLOCK";
112+
113+
[@text "{1 File Type Constants}"];
114+
115+
[@bs.module "fs"] [@bs.scope "constants"] external s_ifmt: t = "S_IFMT";
116+
[@bs.module "fs"] [@bs.scope "constants"] external s_ifreg: t = "S_IFREG";
117+
[@bs.module "fs"] [@bs.scope "constants"] external s_ifdir: t = "S_IFDIR";
118+
[@bs.module "fs"] [@bs.scope "constants"] external s_ifchr: t = "S_IFCHR";
119+
[@bs.module "fs"] [@bs.scope "constants"] external s_ifblk: t = "S_IFBLK";
120+
[@bs.module "fs"] [@bs.scope "constants"] external s_ififo: t = "S_IFIFO";
121+
[@bs.module "fs"] [@bs.scope "constants"] external s_iflnk: t = "S_IFLNK";
122+
[@bs.module "fs"] [@bs.scope "constants"] external s_ifsock: t = "S_IFSOCK";
123+
124+
[@text "{1 File Mode Constants}"];
125+
126+
[@bs.module "fs"] [@bs.scope "constants"] external s_irwxu: t = "S_IRWXU";
127+
[@bs.module "fs"] [@bs.scope "constants"] external s_irusr: t = "S_IRUSR";
128+
[@bs.module "fs"] [@bs.scope "constants"] external s_iwusr: t = "S_IWUSR";
129+
[@bs.module "fs"] [@bs.scope "constants"] external s_ixusr: t = "S_IXUSR";
130+
[@bs.module "fs"] [@bs.scope "constants"] external s_irwxg: t = "S_IRWXG";
131+
[@bs.module "fs"] [@bs.scope "constants"] external s_irgrp: t = "S_IRGRP";
132+
[@bs.module "fs"] [@bs.scope "constants"] external s_iwgrp: t = "S_IWGRP";
133+
[@bs.module "fs"] [@bs.scope "constants"] external s_ixgrp: t = "S_IXGRP";
134+
[@bs.module "fs"] [@bs.scope "constants"] external s_irwxo: t = "S_IRWXO";
135+
[@bs.module "fs"] [@bs.scope "constants"] external s_iroth: t = "S_IROTH";
136+
[@bs.module "fs"] [@bs.scope "constants"] external s_iwoth: t = "S_IWOTH";
137+
[@bs.module "fs"] [@bs.scope "constants"] external s_ixoth: t = "S_IXOTH";
84138
};
85139

86140
module Flag: {
@@ -227,10 +281,10 @@ module FileHandle = {
227281
(t, Buffer.t, ~offset: int, ~length: int, ~position: int) =>
228282
Js.Promise.t(readInfo) =
229283
"read";
230-
[@bs.send] external readFile: t => Js.Promise.t(Buffer.t) = "read";
284+
[@bs.send] external readFile: t => Js.Promise.t(Buffer.t) = "readFile";
231285
[@bs.send]
232-
external readFileWith: (t, readFileOptions) => Js.Promise.t(Buffer.t) =
233-
"read";
286+
external readFileWith: (t, ~encoding: string) => Js.Promise.t(string) =
287+
"readFile";
234288

235289
[@bs.send] external stat: t => Js.Promise.t(Stats.t) = "stat";
236290
[@bs.send] external sync: t => Js.Promise.t(unit) = "sync";
@@ -305,7 +359,7 @@ external copyFile: (string, ~dest: string) => Js.Promise.t(unit) = "copyFile";
305359

306360
[@bs.module "fs"] [@bs.scope "promises"]
307361
external copyFileFlag:
308-
(string, ~dest: string, ~flag: string) => Js.Promise.t(unit) =
362+
(string, ~dest: string, ~flags: Constants.t) => Js.Promise.t(unit) =
309363
"copyFile";
310364

311365
[@bs.module "fs"] [@bs.scope "promises"]

test/__tests__/Fs_test.re

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
open Fs;
2+
open Jest;
3+
open Js.Promise;
4+
5+
describe("Fs", () => {
6+
testPromise("readFile should read entire file", () => {
7+
open_(Global.filename, Flag.read)
8+
|> then_(fh =>
9+
Fs.FileHandle.readFile(fh)
10+
|> then_(buffer =>
11+
FileHandle.close(fh) |> then_(_ => resolve(buffer))
12+
)
13+
)
14+
|> then_(buffer => {
15+
let needle = "Random string: Gh2e71pdHhPxU";
16+
Expect.(
17+
expect(buffer->Buffer.indexOfString(needle))
18+
|> toBeGreaterThan(0)
19+
|> resolve
20+
);
21+
})
22+
});
23+
testPromise("readFileWith should read entire file as a string", () => {
24+
open_(Global.filename, Flag.read)
25+
|> then_(fh =>
26+
Fs.FileHandle.readFileWith(fh, ~encoding="UTF-8")
27+
|> then_(buffer =>
28+
FileHandle.close(fh) |> then_(_ => resolve(buffer))
29+
)
30+
)
31+
|> then_(content => {
32+
let needle = "Random string: uCF6c5f3Arrq";
33+
Expect.(
34+
expect(Js.String.indexOf(needle, content))
35+
|> toBeGreaterThan(0)
36+
|> resolve
37+
);
38+
})
39+
});
40+
});

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,9 +2105,9 @@ lodash.sortby@^4.7.0:
21052105
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
21062106

21072107
lodash@^4.17.13, lodash@^4.17.15:
2108-
version "4.17.15"
2109-
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
2110-
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
2108+
version "4.17.19"
2109+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
2110+
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
21112111

21122112
loose-envify@^1.0.0:
21132113
version "1.4.0"

0 commit comments

Comments
 (0)