on master help sign in
Merge pull request #1228 from ynx0/graph-fixes
6ee82bdtinnus-napbus
content/docs/userspace/graph-store/data-structure-overview.md+47−26
@@ -6,11 +6,15 @@ template = "doc.html"
6insert_anchor_links = "right"
6insert_anchor_links = "right"
7+++
7+++
8
8
9−
10Let's go through the type definitions of some of the most used types when working with Graph Store.
9Let's go through the type definitions of some of the most used types when working with Graph Store.
11
10
12## Post
11## Post
12+
13Here's `sur/post.hoon`
13Here's `sur/post.hoon`
14+
15+<details>
16+ <summary> Code Listing (Click to Expand)</summary>
17+
14```hoon
18```hoon
15+$ index (list atom)
19+$ index (list atom)
16+$ uid [=resource =index]
20+$ uid [=resource =index]
@@ -41,6 +45,7 @@ Here's `sur/post.hoon`
41+$ reference
45+$ reference
42 $% [%graph group=resource =uid]
46 $% [%graph group=resource =uid]
43 [%group group=resource]
47 [%group group=resource]
48+ [%app =ship =desk =path]
44 ==
49 ==
45::
50::
46+$ content
51+$ content
@@ -50,11 +55,12 @@ Here's `sur/post.hoon`
50 [%code expression=cord output=(list tank)]
55 [%code expression=cord output=(list tank)]
51 [%reference =reference]
56 [%reference =reference]
52 ==
57 ==
53−--
54```
58```
55
59
60+</details>
56
61
57### Index
62### Index
63+
58```hoon
64```hoon
59+$ index (list atom)
65+$ index (list atom)
60+$ uid [=resource =index]
66+$ uid [=resource =index]
@@ -67,6 +73,7 @@ Here's `sur/post.hoon`
67An index fragment is not an explicitly defined type, but since an index is `(list atom)`, it follows that the type of an index fragment is `atom`. This is what gives the developer the flexibility to use more than just numbers in an index: any type that is representable as an atom can be used in the index.
73An index fragment is not an explicitly defined type, but since an index is `(list atom)`, it follows that the type of an index fragment is `atom`. This is what gives the developer the flexibility to use more than just numbers in an index: any type that is representable as an atom can be used in the index.
68
74
69### Hashing (Part 1)
75### Hashing (Part 1)
76+
70```hoon
77```hoon
71:: +sham (half sha-256) hash of +validated-portion
78:: +sham (half sha-256) hash of +validated-portion
72+$ hash @ux
79+$ hash @ux
@@ -78,10 +85,12 @@ An index fragment is not an explicitly defined type, but since an index is `(lis
78These types are used to cryptographically sign a given post, so that the host of some content cannot act as an imposter, and post content impersonating as someone else. `signature` represents a triple of signed message of hash, author, and author's life at time of posting. These can be used to cryptographically attest to a message. The implementation is a form of asymmetric/public-key encryption, where `q` and `r` are data necessary to look up a ship's public key on azimuth, which can be used to verify the validity of the message.
85These types are used to cryptographically sign a given post, so that the host of some content cannot act as an imposter, and post content impersonating as someone else. `signature` represents a triple of signed message of hash, author, and author's life at time of posting. These can be used to cryptographically attest to a message. The implementation is a form of asymmetric/public-key encryption, where `q` and `r` are data necessary to look up a ship's public key on azimuth, which can be used to verify the validity of the message.
79
86
80### Content Types
87### Content Types
88+
81```hoon
89```hoon
82+$ reference
90+$ reference
83 $% [%graph group=resource =uid]
91 $% [%graph group=resource =uid]
84 [%group group=resource]
92 [%group group=resource]
93+ [%app =ship =desk =path]
85 ==
94 ==
86::
95::
87+$ content
96+$ content
@@ -94,7 +103,11 @@ These types are used to cryptographically sign a given post, so that the host of
94::
103::
95```
104```
96
105
97−`reference` is a type that models a reference to a graph object. Currently, the valid types of references are either a reference to a specific node in a graph, or a specific group.
106+`reference` is a type that models a reference to a graph object.
107+
108+- `%graph` is a reference to a specific node in a given graph identified by its resource
109+- `%group` is a reference to a given resource itself
110+- `%app` is a reference to an application, hosted on `ship`, located at `desk`, with a `path` that the receiving application can use to link to some content (this is just `/` when unused).
98
111
99`content` enumerates all the possible content types that a post can have. The possible content types can be:
112`content` enumerates all the possible content types that a post can have. The possible content types can be:
100
113
@@ -107,6 +120,7 @@ These types are used to cryptographically sign a given post, so that the host of
107Currently, these are the only content types supported by Graph Store.
120Currently, these are the only content types supported by Graph Store.
108
121
109### Post
122### Post
123+
110```hoon
124```hoon
111+$ post
125+$ post
112 $: author=ship
126 $: author=ship
@@ -125,6 +139,7 @@ Post is a fundamental type that represents what we normally think of as a post o
125An `indexed-post` is a post with an associated index fragment that can be used to validate a post's index with an index fragment that is expected at the end of the index list.
139An `indexed-post` is a post with an associated index fragment that can be used to validate a post's index with an index fragment that is expected at the end of the index list.
126
140
127### Hashing (Part 2)
141### Hashing (Part 2)
142+
128```hoon
143```hoon
129+$ validated-portion
144+$ validated-portion
130 $: parent-hash=(unit hash)
145 $: parent-hash=(unit hash)
@@ -137,24 +152,26 @@ An `indexed-post` is a post with an associated index fragment that can be used t
137
152
138The parts of a `post` that are actually hashed to obtain a value of type the earlier type `hash`.
153The parts of a `post` that are actually hashed to obtain a value of type the earlier type `hash`.
139
154
140−
141## Graph Store
155## Graph Store
142
156
143Here's `sur/graph-store.hoon`
157Here's `sur/graph-store.hoon`
144
158
159+<details>
160+<summary>Code Listing (Click To Expand)</summary>
161+
145```hoon
162```hoon
146+$ graph ((mop atom node) gth)
163+$ graph ((mop atom node) gth)
147+$ marked-graph [p=graph q=(unit mark)]
164+$ marked-graph [p=graph q=(unit mark)]
148::
165::
166++$ maybe-post (each post hash)
149−+$ node [=post children=internal-graph]
167++$ node [post=maybe-post children=internal-graph]
150+$ graphs (map resource marked-graph)
168+$ graphs (map resource marked-graph)
151::
169::
152−+$ tag-queries (jug term resource)
170++$ tag-queries (jug term uid)
153::
171::
154+$ update-log ((mop time logged-update) gth)
172+$ update-log ((mop time logged-update) gth)
155+$ update-logs (map resource update-log)
173+$ update-logs (map resource update-log)
156::
174::
157−::
158+$ internal-graph
175+$ internal-graph
159 $~ [%empty ~]
176 $~ [%empty ~]
160 $% [%graph p=graph]
177 $% [%graph p=graph]
@@ -166,18 +183,18 @@ Here's `sur/graph-store.hoon`
166 =tag-queries
183 =tag-queries
167 =update-logs
184 =update-logs
168 archive=graphs
185 archive=graphs
169− validators=(set mark)
186+ ~
170 ==
187 ==
171::
188::
172+$ update [p=time q=action]
189+$ update [p=time q=action]
173::
190::
174+$ logged-update [p=time q=logged-action]
191+$ logged-update [p=time q=logged-action]
175−
192+
176::
193::
177+$ logged-action
194+$ logged-action
178 $% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
195 $% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
179 [%add-nodes =resource nodes=(map index node)]
196 [%add-nodes =resource nodes=(map index node)]
180− [%remove-nodes =resource indices=(set index)]
197+ [%remove-posts =resource indices=(set index)]
181 [%add-signatures =uid =signatures]
198 [%add-signatures =uid =signatures]
182 [%remove-signatures =uid =signatures]
199 [%remove-signatures =uid =signatures]
183 ==
200 ==
@@ -186,8 +203,8 @@ Here's `sur/graph-store.hoon`
186 $% logged-action
203 $% logged-action
187 [%remove-graph =resource]
204 [%remove-graph =resource]
188 ::
205 ::
189− [%add-tag =term =resource]
206+ [%add-tag =term =uid]
190− [%remove-tag =term =resource]
207+ [%remove-tag =term =uid]
191 ::
208 ::
192 [%archive-graph =resource]
209 [%archive-graph =resource]
193 [%unarchive-graph =resource]
210 [%unarchive-graph =resource]
@@ -199,22 +216,24 @@ Here's `sur/graph-store.hoon`
199 [%tags tags=(set term)]
216 [%tags tags=(set term)]
200 [%tag-queries =tag-queries]
217 [%tag-queries =tag-queries]
201 ==
218 ==
202−--
219+::
203−+$ permissions
220++$ permissions
204 [admin=permission-level writer=permission-level reader=permission-level]
221 [admin=permission-level writer=permission-level reader=permission-level]
205::
222::
206:: $permission-level: levels of permissions in increasing order
223:: $permission-level: levels of permissions in increasing order
207−::
224+::
208:: %no: May not add/remove node
225:: %no: May not add/remove node
209:: %self: May only nodes beneath nodes that were added by
226:: %self: May only nodes beneath nodes that were added by
210:: the same pilot, may remove nodes that the pilot 'owns'
227:: the same pilot, may remove nodes that the pilot 'owns'
211:: %yes: May add a node or remove node
228:: %yes: May add a node or remove node
212+$ permission-level
229+$ permission-level
213 ?(%no %self %yes)
230 ?(%no %self %yes)
214−::
215```
231```
216
232
233+</details>
234+
217### Graph, Node, and Related Objects
235### Graph, Node, and Related Objects
236+
218```hoon
237```hoon
219+$ graph ((mop atom node) gth)
238+$ graph ((mop atom node) gth)
220+$ marked-graph [p=graph q=(unit mark)]
239+$ marked-graph [p=graph q=(unit mark)]
@@ -238,18 +257,20 @@ Here's `sur/graph-store.hoon`
238 ==
257 ==
239::
258::
240```
259```
260+
241A graph is a loosely interconnected set of data which can reference each other and be arbitrarily nested and interconnected. This concept is based off of the mathematical concept of a graph: a collection of nodes, and connections between nodes called edges.
261A graph is a loosely interconnected set of data which can reference each other and be arbitrarily nested and interconnected. This concept is based off of the mathematical concept of a graph: a collection of nodes, and connections between nodes called edges.
242
262
243`graph` is a `mop`, a map which maintains ordering on its keys based on a sorting function also known as an ordered map. A graph's keys are `atom`s representing a node's index fragment and whose values are `node`s, where entries are sorted by largest valued keys first, using `gth` as the sorting function. This is the fundamental data structure used in Graph Store.
263`graph` is a `mop`, a map which maintains ordering on its keys based on a sorting function also known as an ordered map. A graph's keys are `atom`s representing a node's index fragment and whose values are `node`s, where entries are sorted by largest valued keys first, using `gth` as the sorting function. This is the fundamental data structure used in Graph Store.
244
264
245Here are some helpful Wikipedia pages for more info on what this data type represents:
265Here are some helpful Wikipedia pages for more info on what this data type represents:
266+
246−- [Graph (abstract data type)](https://en.wikipedia.org/wiki/Graph_(abstract_data_type))
267+- [Graph (abstract data type)](<https://en.wikipedia.org/wiki/Graph_(abstract_data_type)>)
247- [Graph database](https://en.wikipedia.org/wiki/Graph_database#Background)
268- [Graph database](https://en.wikipedia.org/wiki/Graph_database#Background)
248−- [Graph (discrete mathematics)](https://en.wikipedia.org/wiki/Graph_(discrete_mathematics))
269+- [Graph (discrete mathematics)](<https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)>)
249
270
250`node` represents a pair of a `post` and all of its children, which is an `internal-graph`.
271`node` represents a pair of a `post` and all of its children, which is an `internal-graph`.
251
272
252−`internal-graph` is a tagged union representing the state that children can be in. Either a `node` has children in the form of a `graph`, or does not have any and is labeled as `%empty`.
273+`internal-graph` is a tagged union representing the state that children can be in. Either a `node` has children in the form of a `graph`, or does not have any and is labeled as `%empty`.
253
274
254`marked-graph` is the pair of a `graph` and an optionally present `mark`, which is used by Graph Store to validate a graph against the provided validator.
275`marked-graph` is the pair of a `graph` and an optionally present `mark`, which is used by Graph Store to validate a graph against the provided validator.
255
276
@@ -257,8 +278,6 @@ Here are some helpful Wikipedia pages for more info on what this data type repre
257
278
258`network` is the highest level data structure used by Graph Store to represent all the information that the agent is aware of.
279`network` is the highest level data structure used by Graph Store to represent all the information that the agent is aware of.
259
280
260−
261−
262### Tag Queries
281### Tag Queries
263
282
264```hoon
283```hoon
@@ -268,13 +287,14 @@ Here are some helpful Wikipedia pages for more info on what this data type repre
268`tag-queries` is a mapping where the keys are `term`s and the values are a `set` of `resource`s (this pattern is called a `jug`). It is a simple tagging system that allows for various ad-hoc collections, similar to filesystem tags being used to sort different files/folders. While the type's name is `tag-queries`, there is no complex querying system as of now. Currently, you can add term/resources pairs into the tag queries, get a list of all terms in tag-queries, and get the whole `jug` out of Graph Store.
287`tag-queries` is a mapping where the keys are `term`s and the values are a `set` of `resource`s (this pattern is called a `jug`). It is a simple tagging system that allows for various ad-hoc collections, similar to filesystem tags being used to sort different files/folders. While the type's name is `tag-queries`, there is no complex querying system as of now. Currently, you can add term/resources pairs into the tag queries, get a list of all terms in tag-queries, and get the whole `jug` out of Graph Store.
269
288
270### Update (Part 1)
289### Update (Part 1)
290+
271```hoon
291```hoon
272+$ update [p=time q=action]
292+$ update [p=time q=action]
273::
293::
274+$ logged-action
294+$ logged-action
275 $% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
295 $% [%add-graph =resource =graph mark=(unit mark) overwrite=?]
276 [%add-nodes =resource nodes=(map index node)]
296 [%add-nodes =resource nodes=(map index node)]
277− [%remove-nodes =resource indices=(set index)]
297+ [%remove-posts =resource indices=(set index)]
278 [%add-signatures =uid =signatures]
298 [%add-signatures =uid =signatures]
279 [%remove-signatures =uid =signatures]
299 [%remove-signatures =uid =signatures]
280 ==
300 ==
@@ -283,8 +303,8 @@ Here are some helpful Wikipedia pages for more info on what this data type repre
283 $% logged-action
303 $% logged-action
284 [%remove-graph =resource]
304 [%remove-graph =resource]
285 ::
305 ::
286− [%add-tag =term =resource]
306+ [%add-tag =term =uid]
287− [%remove-tag =term =resource]
307+ [%remove-tag =term =uid]
288 ::
308 ::
289 [%archive-graph =resource]
309 [%archive-graph =resource]
290 [%unarchive-graph =resource]
310 [%unarchive-graph =resource]
@@ -301,9 +321,10 @@ Here are some helpful Wikipedia pages for more info on what this data type repre
301
321
302The `update` type is what is used to interact with Graph Store. It is used both to update subscribers with data (outgoing data) and to write to Graph Store itself (incoming data). All actions are meant to be sent as pokes to Graph Store in the form of a `action` (encapsulated by a `graph-update`), except for the last three actions ,`%keys`, `%tags`, and `%tag-queries`, which must be sent scry requests. All actions defined here allow you to create/read/update/delete various objects in a running Graph Store gall agent. An `action` encapsulates all `logged-action`; any `logged-action` is an `action`, but not necessarily the other way around.
322The `update` type is what is used to interact with Graph Store. It is used both to update subscribers with data (outgoing data) and to write to Graph Store itself (incoming data). All actions are meant to be sent as pokes to Graph Store in the form of a `action` (encapsulated by a `graph-update`), except for the last three actions ,`%keys`, `%tags`, and `%tag-queries`, which must be sent scry requests. All actions defined here allow you to create/read/update/delete various objects in a running Graph Store gall agent. An `action` encapsulates all `logged-action`; any `logged-action` is an `action`, but not necessarily the other way around.
303
323
304−If you want to check out a relevant code listing to see how graph store handles these pokes, check out the `graph-update` arm in the poke handler at [`app/graph-store.hoon`](https://github.com/urbit/urbit/blob/e2ad6e3e9219c8bfad62f27f05c7cac94c9effa8/pkg/arvo/app/graph-store.hoon#L221-L227)
324+<!-- todo link to reference explaining pokes -->
305
325
306### Update (Part 2)
326### Update (Part 2)
327+
307```hoon
328```hoon
308+$ update-log ((mop time logged-update) gth)
329+$ update-log ((mop time logged-update) gth)
309+$ update-logs (map resource update-log)
330+$ update-logs (map resource update-log)
@@ -320,6 +341,7 @@ It is important to note that the source of truth is actually the `update-logs`,
320The reason for having the main CRUD actions being `logged-update`s is so that Graph Store knows which order to process the log entries in when it is rebuilding its current state. The time associated with the `logged-update` is a way of specifying the canonical order to process operations. All other actions that aren't part of logged-update stand on their own and don't need a timestamp in order to properly apply them.
341The reason for having the main CRUD actions being `logged-update`s is so that Graph Store knows which order to process the log entries in when it is rebuilding its current state. The time associated with the `logged-update` is a way of specifying the canonical order to process operations. All other actions that aren't part of logged-update stand on their own and don't need a timestamp in order to properly apply them.
321
342
322### Permissions
343### Permissions
344+
323```hoon
345```hoon
324+$ permissions
346+$ permissions
325 [admin=permission-level writer=permission-level reader=permission-level]
347 [admin=permission-level writer=permission-level reader=permission-level]
@@ -335,4 +357,3 @@ The reason for having the main CRUD actions being `logged-update`s is so that Gr
335```
357```
336
358
337These are the types from the permissioning system explained earlier. `permissions` is just a length-3 cell of `permissions-level`s for Admins, Writers, and Readers respectively.
359These are the types from the permissioning system explained earlier. `permissions` is just a length-3 cell of `permissions-level`s for Admins, Writers, and Readers respectively.
338−
content/docs/userspace/graph-store/graph-store-reference.mdnew file+245
@@ -0,0 +1,245 @@
1++++
2+title = "Graph Store - Reference"
3+weight = 5
4+template = "doc.html"
5++++
6+
7+
8+## Pokes
9+
10+Graph Store can be poked with a `graph-update`, which can:
11+
12+### Add and remove a graph
13+
14+- `[%add-graph =resource =graph mark=(unit mark) overwrite=?]`
15+
16+- `[%remove-graph =resource]`
17+
18+### Add and remove a node
19+
20+- `[%add-nodes =resource nodes=(map index node)]`
21+
22+- `[%remove-posts =resource indices=(set index)]`
23+
24+### Add and remove signatures
25+
26+- `[%add-signatures =uid =signatures]`
27+
28+- `[%remove-signatures =uid =signatures]`
29+
30+### Add and remove tags
31+
32+- `[%add-tag =term =uid]`
33+
34+- `[%remove-tag =term =uid]`
35+
36+### Archive and unarchive a graph
37+
38+- `[%archive-graph =resource]`
39+
40+- `[%unarchive-graph =resource]`
41+
42+### Manually process an update log on a resource
43+
44+- `[%run-updates =resource =update-log]`
45+
46+## Scries
47+
48+What follows is a summary of the scries available in graph-store.
49+
50+<!-- enhancement: add examples -->
51+<!-- enhancement: add refrences to relevant sections in data structures explanation -->
52+
53+
54+### Export State
55+
56+Obtain a vase of the current state of graph-store as a noun.
57+
58+* Path: `/x/export`
59+* Output Type: `network:store`
60+
61+### Fetch keys
62+
63+Fetch the resources of all graphs that graph-store is currently tracking.
64+
65+* Path: `/x/keys`
66+* Output Type: `(set resource)`
67+
68+### Fetch tag queries
69+
70+Fetch the available tag queries from graph-store.
71+
72+* Path: `/x/tag-queries`
73+* Output Type: `tag-queries`
74+
75+### Fetch tags
76+
77+Fetch all available tags from graph-store.
78+
79+* Path: `/x/tag-queries/tags`
80+* Output Type: `(list term)`
81+
82+### Fetch the update log by resource
83+
84+This returns the full update log for the graph associated with the given resource.
85+
86+* Path: `/x/update-log/[ship]/[name]`
87+* Inputs
88+ * **ship** (`ship`) - The ship of the resource.
89+ * **name** (`@tas`) - The name of the resource.
90+* Output Type: `update-log:store`
91+
92+### Fetch time of the latest log entry by resource
93+
94+Fetch the time of the latest log entry by resource, if the update-log for the given resource exists.
95+
96+* Path: `/x/update-log/[ship]/[name]/latest`
97+* Inputs
98+ * **ship** (`ship`) - The ship of the resource.
99+ * **name** (`@tas`) - The name of the resource.
100+* Output Type: `(unit time)`
101+
102+### Fetch a subset of the update log
103+
104+* Path: `/x/update-log/[ship]/[name]/subset/[start]/[end]`
105+* Inputs
106+ * **ship** (`ship`) - The ship of the resource.
107+ * **name** (`@tas`) - The name of the resource.
108+ * **start** and **end** (`@da`) - All logs after **start** and before **end** are to be included in the result.
109+* Output Type: `update-log:store`
110+
111+### Fetch a specific graph by resource
112+
113+Returns the full graph for a given resource.
114+
115+* Path: `/x/graph/[ship]/[name]`
116+* Inputs:
117+ * **ship** (`ship`) - The ship of the resource.
118+ * **name** (`@tas`) - The name of the resource.
119+* Output Type: `update:store`, `%add-graph`
120+
121+
122+### Request the mark of a graph
123+
124+Returns the mark associated a given graph, if one exists.
125+
126+* Path: `/x/graph/[ship]/[name]/mark`
127+* Inputs:
128+ * **ship** (`ship`) - The ship of the resource.
129+ * **name** (`@tas`) - The name of the resource.
130+* Output Type: `(unit mark)`
131+
132+### Request a subset of the graph
133+
134+Returns a subset of nodes from a graph, with or without descendants, optionally filtering for ones that fall between the start and end indexes.
135+
136+* Path: `/x/graph/[ship]/[name]/subset/[mode]/[start?]/[end?]`
137+* Inputs:
138+ * **ship** (`ship`) - The ship of the resource.
139+ * **name** (`@tas`) - The name of the resource.
140+ * **mode** (`?(%kith %lone)`) - `%kith` to include descendants, `%lone` to exclude.
141+ * **start** and **end** (`(unit atom)`) - Atoms used to start and end the subset. If these are unable to be parsed, the subset will start at the smallest node.
142+* Output Type: `update:store` `%add-nodes`
143+
144+### Check if node exists
145+
146+Returns a flag, `%.y` if the node exists and `%.n` otherwise.
147+
148+* Path: `/x/graph/[ship]/[name]/node/exists/[index+]`
149+* Inputs:
150+ * **ship** (`ship`) - The ship of the resource.
151+ * **name** (`@tas`) - The name of the resource.
152+ * **[index+]** `(list atom)`- The index of the node to check. The index should be appended to the path as a list.
153+* Output Type: `flag`
154+
155+### Request a node
156+
157+Returns an `%add-nodes` update containing the node that was requested.
158+
159+* Path: `/x/graph/[ship]/[name]/node/index/[mode]/[index+]`
160+* Inputs
161+ * **ship** (`ship`) - The ship of the resource.
162+ * **name** (`@tas`) - The name of the resource.
163+ * **mode** (`?(%kith %lone)`) - `%kith` to include descendants, `%lone` to exclude
164+ * **[index+]** `(list atom)`- The index of the node being requested. The index should be appended to the path as a list.
165+* Output Type: `update:store` `%add-nodes`
166+
167+### Request a node's children
168+
169+Returns a subset of a node's children, with or without descendants, optionally filtering for ones that fall between the start and end indexes.
170+
171+
172+* Path: `/x/graph/[ship]/[name]/node/children/[mode]/[start?]/[end?]/[index+]`
173+* Inputs
174+ * **ship** (`ship`) - The ship of the resource.
175+ * **name** (`@tas`) - The name of the resource.
176+ * **mode** (`?(%kith %lone)`) - `%kith` to include descendants, `%lone` to exclude.
177+ * **start** and **end** (`(unit atom)`) - Atoms used to start and end the subset. If these are unable to be parsed, the subset will start at the smallest node.
178+ * **[index+]** `(list atom)`- The index of the node being requested. The index should be appended to the path as a list.
179+
180+* Output Type: `update:store` `%add-nodes`
181+
182+
183+### Request a node's siblings
184+
185+<!-- todo figure out behavior of %newest and %oldest -->
186+
187+* Path: `/x/graph/[ship]/[name]/node/siblings/[direction]/[mode]/[count]/[index+]`
188+* Inputs
189+ * **ship** (`ship`) - The ship of the resource.
190+ * **name** (`@tas`) - The name of the resource.
191+ * **direction** (`?(%older %newer %oldest %newest)`)-
192+ + `%newer` - Load the siblings with keys larger than the requested node.
193+ + `%older` - Load the siblings with keys smaller than the requested node.
194+ + `%newest` - Load the siblings with the largest keys.
195+ + `%oldest` - Load the siblings with the largest keys.
196+ * **mode** (`?(%kith %lone)`) - `%kith` to include descendants, `%lone` to exclude.
197+ * **count** (`atom`) - A limit to the number of nodes to return.
198+ * **[index+]** `(list atom)`- The index of the node being requested. The index should be appended to the path as a list.
199+* Output Type: `update:store` `%add-nodes`
200+
201+### Request a node's firstborn child
202+
203+<!-- todo explanation -->
204+
205+* Path: `/x/graph/[ship]/[name]/node/firstborn/[index+]`
206+* Inputs:
207+ * **ship** (`ship`) - The ship of the resource.
208+ * **name** (`@tas`) - The name of the resource.
209+ * **[index+]** `(list atom)`- The index of the node being requested. The index should be appended to the path as a list.
210+
211+* Output: `update:store` `%add-nodes`
212+
213+### Request nodes, depth first
214+
215+* Path: `/x/graph/[ship]/[name]/node/depth-first/[count]/[start]`
216+* Input
217+ * **ship** (`ship`) - The ship of the resource.
218+ * **name** (`@tas`) - The name of the resource.
219+ * **count** (`(unit atom)`) - A limit to the number of nodes to return.
220+ * **start** (`(unit atom)`) - The index fragment to start at.
221+
222+* Output Type: `update:store` `%add-nodes`
223+
224+
225+## Agent State
226+
227+The following is the definition of the agent state, known as `network`.
228+
229+```hoon
230++$ network
231+ $: =graphs
232+ =tag-queries
233+ =update-logs
234+ archive=graphs
235+ ~
236+ ==
237+```
238+
239+Briefly,
240+- `graphs` represents all graphs that graph store is aware of an is storing data about.
241+- `tag-queries` is how graph store implements its tagging system, and uses it to keep track of associations between tags and the respective index.
242+- `update-logs` is where graph-store stores the update-log that backs each graph, keyed by resource. <!-- refrence to advanced section talking about how this is the source of truth -->
243+- `archive` is where graph-store stores archived graphs. These are graphs which can no longer be updated through `%run-updates`. <!-- this nuance should/could also be present in the advanced info -->
244+
245+For more information on these types, please take a look at the [data structure overview](/docs/userspace/graph-store/data-structure-overview).
content/docs/userspace/landscape/reference/graph-store.mddeleted−160
@@ -1,160 +0,0 @@
1−+++
2−title = "Graph Store"
3−weight = 3
4−template = "doc.html"
5−+++
6−
7−`graph-store` is a gall agent that implements of a tree with additional virtual
8−edges by allowing nodes to reference other nodes. It is most comparable to
9−modern NoSQL databases in structure, though it allows for schemas to be written
10−in the form of marks. It is used as the backend for an increasing number of
11−Landscape applications, and is considered to be best used for social data.
12−
13−## Data types
14−
15−`graphs` is a map of `resource` to `marked-graph`
16−
17−`resource` is a pair of ship and term which is where the graph is hosted and the name of the resource. Every graph is it's own resource.
18−
19−`marked-graph` is a pair of `graph` and `(unit mark)`. The semantics of a graph are defined by the mark. This is just for validating the structure of the graph.
20−
21−`graph` is a `mop`, a mold builder for order map, of an atom and a `node`.
22−
23−`node` is a pair of `post` and `children`.
24−
25−`post` is defined in `sur/post`. It contains:
26−
27−```hoon
28−+$ post
29− $: author=ship
30− =index
31− time-sent=time
32− contents=(list content)
33− hash=(unit hash)
34− =signatures
35− ==
36−```
37−
38−
39−Most of these elements are self explanatory.
40−
41−`contents` is a `list` of `content` where `content` is a tagged union of text, url, code, or reference. This is where the contents of a publish post or an entry from links would be stored.
42−
43−`hash` is a `sham` hash of `validated-portion` which includes the parent hash, author, time sent, and contents.
44−
45−`signatures` is a set of `signature` which is used to cryptographically sign graph-store messages.
46−
47−When interacting with `graph-store` you will need to create an `update`
48−
49−`update` is a tagged union that currently only has one option
50−
51−`[%0 p=time q=update-0]`
52−
53−The reason this is a union is to serve as future proofing for version changes.
54−
55−An `update-0` can either be logged in the case of adding/removing nodes or signatures, or non-logged as in the case of adding/removing a graph. This logging refers to if this action adds an entry to the update log that is used to synchronize state between ships.
56−
57−Below is an excerpt of `sur/graph-store.hoon` at the time of writing, showing the definition of `logged-update-0` and `update-0` which should now be readable.
58−
59−```hoon
60−+$ logged-update-0
61− $% [%add-nodes =resource nodes=(map index node)]
62− [%remove-nodes =resource indices=(set index)]
63− [%add-signatures =uid =signatures]
64− [%remove-signatures =uid =signatures]
65− ==
66−::
67−+$ update-0
68− $% logged-update-0
69− [%add-graph =resource =graph mark=(unit mark)]
70− [%remove-graph =resource]
71− ::
72− [%add-tag =term =resource]
73− [%remove-tag =term =resource]
74− ::
75− [%archive-graph =resource]
76− [%unarchive-graph =resource]
77− [%run-updates =resource =update-log]
78− ::
79− :: NOTE: cannot be sent as pokes
80− ::
81− [%keys =resources]
82− [%tags tags=(set term)]
83− [%tag-queries =tag-queries]
84− ==
85−```
86−
87−
88−## Pokes
89−
90−Graph Store can be poked with a `graph-update`, which can:
91− - add and remove a graph
92−
93− `[%add-graph =resource =graph mark=(unit mark)]`
94−
95− `[%remove-graph =resource]`
96−
97− - add and remove a node to a graph
98−
99− `[%add-nodes =resource nodes=(map index node)]`
100−
101− `[%remove-nodes =resource indices=(set index)]`
102−
103− - add and remove signatures
104−
105− `[%add-signatures =uid =signatures]`
106−
107− `[%remove-signatures =uid =signatures]`
108−
109− - add and remove tags
110−
111− `[%add-tag =term =resource]`
112−
113− `[%remove-tag =term =resource]`
114−
115− - archive and unarchive a graph
116−
117− `[%archive-graph =resource]`
118−
119− `[%unarchive-graph =resource]`
120−
121−## Scries
122−
123−What follows is a summary of the scrys available in graph-store
124−
125−- Fetch keys
126− `[%x %keys ~]`
127−
128−- Fetch tags
129− `[%x %tags ~]`
130−
131−- Fetch tag queries
132− `[%x %tag-queries ~]`
133−
134−- Fetch a specific graph by resource
135− `[%x %graph @ @ ~]`
136−
137−- Archive a specific graph by resource
138− `[%x %archive @ @ ~]`
139−
140−- Fetch a subset of the graph by resource and start and end indices
141− `[%x %graph-subset @ @ @ @ ~]`
142−
143−- Select a node from a graph by resource and index
144− `[%x %node @ @ @ *]`
145−
146−- Fetch a subset of the children of a node by resource, index, and start and end indices
147− `[%x %node-children-subset @ @ @ @ @ *]`
148−
149−- Fetch a subset of the update log by resource and start and end indices
150− `[%x %update-log-subset @ @ @ @ ~]`
151−
152−- Fetch the update log by resource
153− `[%x %update-log @ @ ~]`
154−
155−- Fetch the time of the last entry of the update log
156− `[%x %peek-update-log @ @ ~]`
157−
158−## Marks
159−
160−There are marks in `mar/graph/validator` that are worth reviewing. They are each short enough to read quickly. They are used to validate the shapes of various nouns to be stored in the graph-store.