mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-15 14:35:01 +03:00
finished with node API
This commit is contained in:
parent
dd22538c78
commit
5dbb49e8a7
@ -30,9 +30,6 @@ boolean = J.Boolean
|
|||||||
array : Jsonify a -> Jsonify [a]
|
array : Jsonify a -> Jsonify [a]
|
||||||
array f vs = J.Array (map f vs)
|
array f vs = J.Array (map f vs)
|
||||||
|
|
||||||
tuple2 : Jsonify a -> Jsonify b -> Jsonify (a,b)
|
|
||||||
tuple2 a b p = J.Array [a (fst p), b (snd p)]
|
|
||||||
|
|
||||||
set : Jsonify comparable -> Jsonify (S.Set comparable)
|
set : Jsonify comparable -> Jsonify (S.Set comparable)
|
||||||
set a = array a . S.toList
|
set a = array a . S.toList
|
||||||
|
|
||||||
@ -42,6 +39,17 @@ dict k v = array (tuple2 k v) . M.toList
|
|||||||
object : Jsonify v -> Jsonify (M.Dict String v)
|
object : Jsonify v -> Jsonify (M.Dict String v)
|
||||||
object v = J.Object . M.map v
|
object v = J.Object . M.map v
|
||||||
|
|
||||||
|
tuple2 : Jsonify a -> Jsonify b -> Jsonify (a,b)
|
||||||
|
tuple2 a b p = J.Array [a (fst p), b (snd p)]
|
||||||
|
|
||||||
|
tuple3 : Jsonify a -> Jsonify b -> Jsonify c -> Jsonify (a,b,c)
|
||||||
|
tuple3 ja jb jc p = case p of
|
||||||
|
(a,b,c) -> J.Array [ja a, jb b, jc c]
|
||||||
|
|
||||||
|
tuple4 : Jsonify a -> Jsonify b -> Jsonify c -> Jsonify d -> Jsonify (a,b,c,d)
|
||||||
|
tuple4 ja jb jc jd p = case p of
|
||||||
|
(a,b,c,d) -> J.Array [ja a, jb b, jc c, jd d]
|
||||||
|
|
||||||
tuple5 : Jsonify a
|
tuple5 : Jsonify a
|
||||||
-> Jsonify b
|
-> Jsonify b
|
||||||
-> Jsonify c
|
-> Jsonify c
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
-- Interface to the Unison node
|
-- Interface to the Unison node
|
||||||
module Unison.Node where
|
module Unison.Node where
|
||||||
|
|
||||||
|
import Dict as M
|
||||||
import Either (Left, Right, Either)
|
import Either (Left, Right, Either)
|
||||||
import Http
|
import Http
|
||||||
import Http (Request, Response)
|
import Http (Request, Response)
|
||||||
import Json
|
import Json
|
||||||
import Set as S
|
import Set as S
|
||||||
|
import Unison.Action as A
|
||||||
|
import Unison.Action (Action)
|
||||||
import Unison.Hash as H
|
import Unison.Hash as H
|
||||||
import Unison.Hash (Hash)
|
import Unison.Hash (Hash)
|
||||||
import Unison.Metadata as MD
|
import Unison.Metadata as MD
|
||||||
import Unison.Metadata (Metadata)
|
import Unison.Metadata (Metadata, Query)
|
||||||
import Unison.Term as E
|
import Unison.Term as E
|
||||||
import Unison.Term (Term)
|
import Unison.Term (Term)
|
||||||
import Unison.Type as T
|
import Unison.Type as T
|
||||||
@ -20,6 +23,7 @@ import Unison.Path as Path
|
|||||||
import Unison.Path (Path)
|
import Unison.Path (Path)
|
||||||
import Unison.Parser as P
|
import Unison.Parser as P
|
||||||
import Unison.Parser (Parser)
|
import Unison.Parser (Parser)
|
||||||
|
import Unison.Var as V
|
||||||
|
|
||||||
type Host = String
|
type Host = String
|
||||||
|
|
||||||
@ -74,12 +78,107 @@ dependencies host params =
|
|||||||
in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params)
|
in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
dependents : Signal Host
|
dependents : Signal Host
|
||||||
-> Signal (Maybe (S.Set Hash), Hash)
|
-> Signal (Maybe (S.Set Hash), Hash)
|
||||||
-> Signal (Response (S.Set Hash))
|
-> Signal (Response (S.Set Hash))
|
||||||
dependents host params =
|
dependents host params =
|
||||||
let body = J.tuple2 (J.optional (J.set H.jsonify)) H.jsonify
|
let body = J.tuple2 (J.optional (J.set H.jsonify)) H.jsonify
|
||||||
req host params = jsonGet body host "dependents" params
|
req host params = jsonGet body host "dependents" params
|
||||||
in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params)
|
in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
editTerm : Signal Host
|
||||||
|
-> Signal (Hash, Path, Action)
|
||||||
|
-> Signal (Response (Hash, Term))
|
||||||
|
editTerm host params =
|
||||||
|
let body = J.tuple3 H.jsonify Path.jsonify A.jsonify
|
||||||
|
req host params = jsonGet body host "edit-term" params
|
||||||
|
parse = parseResponse (P.tuple2 H.parse E.parseTerm)
|
||||||
|
in parse <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
{-
|
||||||
|
editType : Signal Host
|
||||||
|
-> Signal (Hash, Path, Action)
|
||||||
|
-> Signal (Response (Hash, Term))
|
||||||
|
editTerm host params =
|
||||||
|
let body = J.tuple3 H.jsonify Path.jsonify A.jsonify
|
||||||
|
req host params = jsonGet body host "edit-type" params
|
||||||
|
parse = parseResponse (P.tuple2 H.parse E.parseTerm)
|
||||||
|
in parse <~ Http.send (lift2 req host params)
|
||||||
|
-}
|
||||||
|
|
||||||
|
metadata : Signal Host -> Signal Hash -> Signal (Response Metadata)
|
||||||
|
metadata host params =
|
||||||
|
let req host params = Http.get (host ++ "/metadata/" ++ J.render H.jsonify params)
|
||||||
|
in parseResponse MD.parseMetadata <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
-- panel : Signal Host -> Signal Hash -> Signal (Response Panel)
|
||||||
|
|
||||||
|
search : Signal Host
|
||||||
|
-> Signal (Maybe Type, Maybe (S.Set Hash), Query)
|
||||||
|
-> Signal (Response (M.Dict Hash Metadata))
|
||||||
|
search host params =
|
||||||
|
let body = J.tuple3 (J.optional T.jsonifyType)
|
||||||
|
(J.optional (J.set H.jsonify))
|
||||||
|
MD.jsonifyQuery
|
||||||
|
req host params = jsonGet body host "search" params
|
||||||
|
parse = parseResponse (P.object MD.parseMetadata)
|
||||||
|
in parse <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
searchLocal : Signal Host
|
||||||
|
-> Signal (Hash, Path, Maybe Type, Query)
|
||||||
|
-> Signal (Response (Metadata, [(V.I, Type)]))
|
||||||
|
searchLocal host params =
|
||||||
|
let body = J.tuple4 H.jsonify
|
||||||
|
Path.jsonify
|
||||||
|
(J.optional T.jsonifyType)
|
||||||
|
MD.jsonifyQuery
|
||||||
|
req host params = jsonGet body host "search-local" params
|
||||||
|
parse = P.tuple2 MD.parseMetadata
|
||||||
|
(P.array (P.tuple2 V.parse T.parseType))
|
||||||
|
in parseResponse parse <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
term : Signal Host -> Signal Hash -> Signal (Response Term)
|
||||||
|
term host params =
|
||||||
|
let req host params = Http.get (host ++ "/term/" ++ J.render H.jsonify params)
|
||||||
|
in parseResponse E.parseTerm <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
transitiveDependencies : Signal Host
|
||||||
|
-> Signal (Maybe (S.Set Hash), Hash)
|
||||||
|
-> Signal (Response (S.Set Hash))
|
||||||
|
transitiveDependencies host params =
|
||||||
|
let body = J.tuple2 (J.optional (J.set H.jsonify)) H.jsonify
|
||||||
|
req host params = jsonGet body host "transitive-dependencies" params
|
||||||
|
in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
transitiveDependents : Signal Host
|
||||||
|
-> Signal (Maybe (S.Set Hash), Hash)
|
||||||
|
-> Signal (Response (S.Set Hash))
|
||||||
|
transitiveDependents host params =
|
||||||
|
let body = J.tuple2 (J.optional (J.set H.jsonify)) H.jsonify
|
||||||
|
req host params = jsonGet body host "transitive-dependents" params
|
||||||
|
in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
typ : Signal Host -> Signal Hash -> Signal (Response Type)
|
||||||
|
typ host params =
|
||||||
|
let req host params = Http.get (host ++ "/type/" ++ J.render H.jsonify params)
|
||||||
|
in parseResponse T.parseType <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
typeOf : Signal Host
|
||||||
|
-> Signal (Hash, Path)
|
||||||
|
-> Signal (Response Type)
|
||||||
|
typeOf host params =
|
||||||
|
let body = J.tuple2 H.jsonify Path.jsonify
|
||||||
|
req host params = jsonGet body host "type-of" params
|
||||||
|
parse = parseResponse T.parseType
|
||||||
|
in parse <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
|
updateMetadata : Signal Host
|
||||||
|
-> Signal (Hash, Metadata)
|
||||||
|
-> Signal (Response ())
|
||||||
|
updateMetadata host params =
|
||||||
|
let body = J.tuple2 H.jsonify MD.jsonifyMetadata
|
||||||
|
req host params = jsonPost body host "update-metadata" params
|
||||||
|
parse = parseResponse (P.unit ())
|
||||||
|
in parse <~ Http.send (lift2 req host params)
|
||||||
|
|
||||||
undefined : a
|
undefined : a
|
||||||
undefined = undefined
|
undefined = undefined
|
||||||
|
@ -72,6 +72,14 @@ number = value >>= \v -> case v of
|
|||||||
J.Number v -> unit v
|
J.Number v -> unit v
|
||||||
_ -> fail ("not a number: " ++ J.toString "" v)
|
_ -> fail ("not a number: " ++ J.toString "" v)
|
||||||
|
|
||||||
|
todo : a
|
||||||
|
todo = todo
|
||||||
|
|
||||||
|
object : Parser v -> Parser (M.Dict String v)
|
||||||
|
object v j = case j of
|
||||||
|
J.Object dict -> todo
|
||||||
|
_ -> Left ["not an object: " ++ J.toString "" j]
|
||||||
|
|
||||||
set : Parser comparable -> Parser (Set comparable)
|
set : Parser comparable -> Parser (Set comparable)
|
||||||
set p = map Set.fromList (array p)
|
set p = map Set.fromList (array p)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user