figbus / elm-urbit-api / Urbit.Graph

Store


type Store

A collection of Graphs identified by Resources.

emptyStore : Store

Create an empty Store.

getFromStore : Resource -> Store -> Maybe Graph

Get a graph from a Store using a resource.

Resource


type alias Resource =
{ ship : Urbit.Encoding.Atom.Atom
, name : String 
}

A pair of a ship and a name uniquely identifying a graph.

parseResource : String -> Result (List Parser.DeadEnd) Resource

Parses a resource string into a Resource type.

parseResource "~zod/hello"

encodeResource : Resource -> Json.Encode.Value

Encode a Resource into a JSON value of the form:

{
  "ship": "~zod",
  "name": "example"
}

resourceToString : Resource -> String

Encode a Resource into a string of the form:

"~zod/example"

resourceToPath : Resource -> String

Encode a Resource into a path string of the form:

"/ship/~zod/example"

Graph


type alias Graph =
Dict String Node

An ordered dict of nodes.


type Node

A node in a graph. Contains a Post and possibly children.

getNodeChildren : Node -> Graph

Get the children of a node.

getNodePost : Node -> Post

Get the post associated with a node.


type alias Post =
{ index : Index
, author : Urbit.Encoding.Atom.Atom
, timeSent : Time.Posix
, contents : List Json.Encode.Value
, hash : Maybe String 
}

A post in a graph. The contents are a list of JSON values.


type alias Index =
List String

An index uniquely identifying a node within a graph.

newNode : Post -> Node

Create a new node from a post.

textContent : String -> Json.Encode.Value

Create a text content type for a post.

urlContent : String -> Json.Encode.Value

Create a url content type for a post.

mentionContent : String -> Json.Encode.Value

Create a mention content type for a post.

codeContent : { expression : String, output : String } -> Json.Encode.Value

Create a code content type for a post.

Requests

getGraph : { url : String, resource : Resource } -> (Result Http.Error Update -> msg) -> Platform.Cmd.Cmd msg

Get a graph from the graph store.

subscribeToGraphUpdates : Urbit.Encoding.Atom.Atom -> Urbit.OutMsg

Subscribe to changes to the graph store.

addNodes : { resource : Resource, nodes : List Node, session : Urbit.Session } -> Urbit.OutMsg

Add nodes to the graph store.

addNodesSpider : { url : String, resource : Resource, nodes : List Node } -> (Result Http.Error Json.Decode.Value -> msg) -> Platform.Cmd.Cmd msg

Add nodes to the graph store via a spider thread.

createManagedGraph : { url : String, group : Resource, resource : Resource, title : String, description : String, graphModule : String, mark : String } -> (Result Http.Error () -> msg) -> Platform.Cmd.Cmd msg

Create a new graph associated with an existing group.

createUnmanagedGraph : { url : String, resource : Resource, title : String, description : String, invites : List Urbit.Encoding.Atom.Atom, graphModule : String, mark : String } -> (Result Http.Error () -> msg) -> Platform.Cmd.Cmd msg

Create a new graph unassociated with any group.

deleteGraphSpider : { url : String, resource : Resource } -> (Result Http.Error () -> msg) -> Platform.Cmd.Cmd msg

Delete a graph from the graph store via a spider thread.

Updates


type Update

Represents a change to the graph store.

updateDecoder : Json.Decode.Decoder Update

Decode a graph store update, typically from an incoming diff or scry request.

updateStore : Update -> Store -> Store

Apply a change to the graph store.