Skip to content

Commit

Permalink
refactor: Change JS to be a library and be exposed to website
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Feb 8, 2022
1 parent ff3ffae commit e6557a6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 28 deletions.
24 changes: 1 addition & 23 deletions js/Js.re → js/QueryJsonJs.re
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
open Js_of_ocaml;
open Source;

let to_bs_result = (res: result(string, string)) => {
switch (res) {
| Ok(str) =>
Js.Unsafe.obj([|
("TAG", Js.Unsafe.inject(0)),
("_0", Js.Unsafe.inject(Js.string(str))),
|])
| Error(str) =>
Js.Unsafe.obj([|
("TAG", Js.Unsafe.inject(1)),
("_0", Js.Unsafe.inject(Js.string(str))),
|])
};
};

let run = (rawQuery, rawJson) => {
let query = Js.to_string(rawQuery);
let json = Js.to_string(rawJson);

let run = (query, json) => {
let result =
Main.parse(~debug=false, query)
|> Result.map(Compiler.compile)
Expand All @@ -45,7 +26,4 @@ let run = (rawQuery, rawJson) => {
| Error(err) => Error(err)
}
)
|> to_bs_result;
};

Js.export("run", run);
1 change: 1 addition & 0 deletions js/QueryJsonJs.rei
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let run: (string, string) => result(string, string);
9 changes: 4 additions & 5 deletions js/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(executable
(name Js)
(modes js)
(libraries console.lib source yojson cmdliner js_of_ocaml)
)
(library
(name QueryJsonJs)
(public_name query-json-js)
(libraries console.lib source yojson cmdliner js_of_ocaml))
Empty file added query-json-js.opam
Empty file.

0 comments on commit e6557a6

Please sign in to comment.