diff --git a/editor/Unison/Jsonify.elm b/editor/Unison/Jsonify.elm index 511815212..32d72858a 100644 --- a/editor/Unison/Jsonify.elm +++ b/editor/Unison/Jsonify.elm @@ -30,9 +30,6 @@ boolean = J.Boolean array : Jsonify a -> Jsonify [a] 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 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 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 -> Jsonify b -> Jsonify c diff --git a/editor/Unison/Node.elm b/editor/Unison/Node.elm index 89eb2123e..46da466b4 100644 --- a/editor/Unison/Node.elm +++ b/editor/Unison/Node.elm @@ -1,15 +1,18 @@ -- Interface to the Unison node module Unison.Node where +import Dict as M import Either (Left, Right, Either) import Http import Http (Request, Response) import Json import Set as S +import Unison.Action as A +import Unison.Action (Action) import Unison.Hash as H import Unison.Hash (Hash) import Unison.Metadata as MD -import Unison.Metadata (Metadata) +import Unison.Metadata (Metadata, Query) import Unison.Term as E import Unison.Term (Term) import Unison.Type as T @@ -20,6 +23,7 @@ import Unison.Path as Path import Unison.Path (Path) import Unison.Parser as P import Unison.Parser (Parser) +import Unison.Var as V type Host = String @@ -74,12 +78,107 @@ dependencies host params = in parseResponse (P.set H.parse) <~ Http.send (lift2 req host params) dependents : Signal Host - -> Signal (Maybe (S.Set Hash), Hash) - -> Signal (Response (S.Set Hash)) + -> Signal (Maybe (S.Set Hash), Hash) + -> Signal (Response (S.Set Hash)) dependents host params = let body = J.tuple2 (J.optional (J.set H.jsonify)) H.jsonify req host params = jsonGet body host "dependents" 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 = undefined diff --git a/editor/Unison/Parser.elm b/editor/Unison/Parser.elm index ad6e1a4bb..0e605b8fa 100644 --- a/editor/Unison/Parser.elm +++ b/editor/Unison/Parser.elm @@ -72,6 +72,14 @@ number = value >>= \v -> case v of J.Number v -> unit 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 p = map Set.fromList (array p)