mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 22:33:06 +03:00
wip: all JSON decoders but %add-graph work
This commit is contained in:
parent
37f332dcb6
commit
6493c75463
@ -42,10 +42,10 @@
|
||||
|^
|
||||
?> ?=(%0 -.action)
|
||||
?- +<.action
|
||||
::%add-graph (add-graph +>.action)
|
||||
:: %add-graph (add-graph +>.action)
|
||||
%remove-graph (remove-graph +>.action)
|
||||
:: %add-nodes (add-nodes +>.action)
|
||||
:: %remove-nodes (remove-nodes +>.action)
|
||||
%add-nodes (add-nodes +>.action)
|
||||
%remove-nodes (remove-nodes +>.action)
|
||||
%add-signatures (add-signatures +>.action)
|
||||
%remove-signatures (remove-signatures +>.action)
|
||||
%add-tag (add-tag +>.action)
|
||||
@ -75,20 +75,20 @@
|
||||
++ add-nodes
|
||||
|= [=resource:store nodes=(map index:store node:store)]
|
||||
^- (quip card _state)
|
||||
|^ [~ state]
|
||||
:: =/ =graph:store (~(got by graphs) resource)
|
||||
:: =/ =action-log:store (~(got by action-logs) resource)
|
||||
:: =. action-log
|
||||
:: (put:orm-log action-log now.bowl [%0 [%add-nodes resource nodes]])
|
||||
:: ::
|
||||
:: :- (give [/updates]~ [%add-nodes resource nodes])
|
||||
:: %_ state
|
||||
:: action-logs (~(put by action-logs) resource action-log)
|
||||
:: graphs
|
||||
:: %+ ~(put by graphs)
|
||||
:: resource
|
||||
:: (add-node-list resource graph ~(tap by nodes))
|
||||
:: ==
|
||||
|^
|
||||
=/ =graph:store (~(got by graphs) resource)
|
||||
=/ =action-log:store (~(got by action-logs) resource)
|
||||
=. action-log
|
||||
(put:orm-log action-log now.bowl [%0 [%add-nodes resource nodes]])
|
||||
::
|
||||
:- (give [/updates]~ [%add-nodes resource nodes])
|
||||
%_ state
|
||||
action-logs (~(put by action-logs) resource action-log)
|
||||
graphs
|
||||
%+ ~(put by graphs)
|
||||
resource
|
||||
(add-node-list resource graph ~(tap by nodes))
|
||||
==
|
||||
::
|
||||
++ add-node-list
|
||||
|= $: =resource:store
|
||||
@ -142,8 +142,6 @@
|
||||
our.bowl
|
||||
.^(=life %j /=life/(scot %p our.bowl))
|
||||
==
|
||||
:: multiple indices left in list
|
||||
::
|
||||
~| "index does not exist to add a node to!"
|
||||
=/ parent=node:store (need (get:orm graph atom))
|
||||
%_ parent
|
||||
@ -155,11 +153,7 @@
|
||||
parent-hash hash.post.parent
|
||||
graph
|
||||
?: ?=(%graph -.children.parent)
|
||||
:: recurse into children
|
||||
::
|
||||
p.children.parent
|
||||
:: replace empty graph with graph containing one child
|
||||
::
|
||||
(gas:orm ~ ~)
|
||||
==
|
||||
==
|
||||
@ -168,20 +162,20 @@
|
||||
++ remove-nodes
|
||||
|= [=resource:store indices=(set index:store)]
|
||||
^- (quip card _state)
|
||||
|^ [~ state]
|
||||
:: =/ =graph:store (~(got by graphs) resource)
|
||||
:: =/ =action-log:store (~(got by action-logs) resource)
|
||||
:: =. action-log
|
||||
:: (put:orm-log action-log now.bowl [%0 [%remove-nodes resource indices]])
|
||||
:: ::
|
||||
:: :- (give [/updates]~ [%remove-nodes resource indices])
|
||||
:: %_ state
|
||||
:: action-logs (~(put by action-logs) resource action-log)
|
||||
:: graphs
|
||||
:: %+ ~(put by graphs)
|
||||
:: resource
|
||||
:: (remove-indices resource graph ~(tap in indices))
|
||||
:: ==
|
||||
|^
|
||||
=/ =graph:store (~(got by graphs) resource)
|
||||
=/ =action-log:store (~(got by action-logs) resource)
|
||||
=. action-log
|
||||
(put:orm-log action-log now.bowl [%0 [%remove-nodes resource indices]])
|
||||
::
|
||||
:- (give [/updates]~ [%remove-nodes resource indices])
|
||||
%_ state
|
||||
action-logs (~(put by action-logs) resource action-log)
|
||||
graphs
|
||||
%+ ~(put by graphs)
|
||||
resource
|
||||
(remove-indices resource graph ~(tap in indices))
|
||||
==
|
||||
::
|
||||
++ remove-indices
|
||||
|= [=resource:store =graph:store indices=(list index:store)]
|
||||
@ -201,14 +195,10 @@
|
||||
::
|
||||
?~ t.index
|
||||
+:`[* graph:store]`(del:orm graph atom)
|
||||
:: multiple indices left in list
|
||||
::
|
||||
~| "parent index does not exist to remove a node from!"
|
||||
=/ =node:store (need (get:orm graph atom))
|
||||
~| "child index does not exist to remove a node from!"
|
||||
?> ?=(%graph -.children.node)
|
||||
:: recurse into children
|
||||
::
|
||||
%^ put:orm
|
||||
graph
|
||||
atom
|
||||
@ -218,19 +208,19 @@
|
||||
++ add-signatures
|
||||
|= [=uid:store =signatures:store]
|
||||
^- (quip card _state)
|
||||
|^ [~ state]
|
||||
:: =* resource resource.uid
|
||||
:: =/ =graph:store (~(got by graphs) resource)
|
||||
:: =/ =action-log:store (~(got by action-logs) resource)
|
||||
:: =. action-log
|
||||
:: (put:orm-log action-log now.bowl [%0 [%add-signatures uid signatures]])
|
||||
:: ::
|
||||
:: :- (give [/updates]~ [%add-signatures uid signatures])
|
||||
:: %_ state
|
||||
:: action-logs (~(put by action-logs) resource action-log)
|
||||
:: graphs
|
||||
:: (~(put by graphs) resource (add-at-index graph index.uid signatures))
|
||||
:: ==
|
||||
|^
|
||||
=* resource resource.uid
|
||||
=/ =graph:store (~(got by graphs) resource)
|
||||
=/ =action-log:store (~(got by action-logs) resource)
|
||||
=. action-log
|
||||
(put:orm-log action-log now.bowl [%0 [%add-signatures uid signatures]])
|
||||
::
|
||||
:- (give [/updates]~ [%add-signatures uid signatures])
|
||||
%_ state
|
||||
action-logs (~(put by action-logs) resource action-log)
|
||||
graphs
|
||||
(~(put by graphs) resource (add-at-index graph index.uid signatures))
|
||||
==
|
||||
::
|
||||
++ add-at-index
|
||||
|= [=graph:store =index:store =signatures:store]
|
||||
@ -250,34 +240,30 @@
|
||||
~| "signatures did not match public keys!"
|
||||
?> (are-signatures-valid:sigs signatures u.hash.post.node now.bowl)
|
||||
node(signatures.post (~(uni in signatures) signatures.post.node))
|
||||
:: multiple indices left in list
|
||||
::
|
||||
~| "child graph does not exist to add signatures to!"
|
||||
?> ?=(%graph -.children.node)
|
||||
:: recurse into children
|
||||
::
|
||||
node(p.children $(graph p.children.node, index t.index))
|
||||
--
|
||||
::
|
||||
++ remove-signatures
|
||||
|= [=uid:store =signatures:store]
|
||||
^- (quip card _state)
|
||||
|^ [~ state]
|
||||
:: =* resource resource.uid
|
||||
:: =/ =graph:store (~(got by graphs) resource)
|
||||
:: =/ =action-log:store (~(got by action-logs) resource)
|
||||
:: =. action-log
|
||||
:: %^ put:orm-log action-log
|
||||
:: now.bowl
|
||||
:: [%0 [%remove-signatures uid signatures]]
|
||||
:: ::
|
||||
:: :- (give [/updates]~ [%remove-signatures uid signatures])
|
||||
:: %_ state
|
||||
:: action-logs (~(put by action-logs) resource action-log)
|
||||
:: graphs
|
||||
:: %+ ~(put by graphs) resource
|
||||
:: (remove-at-index graph index.uid signatures)
|
||||
:: ==
|
||||
|^
|
||||
=* resource resource.uid
|
||||
=/ =graph:store (~(got by graphs) resource)
|
||||
=/ =action-log:store (~(got by action-logs) resource)
|
||||
=. action-log
|
||||
%^ put:orm-log action-log
|
||||
now.bowl
|
||||
[%0 [%remove-signatures uid signatures]]
|
||||
::
|
||||
:- (give [/updates]~ [%remove-signatures uid signatures])
|
||||
%_ state
|
||||
action-logs (~(put by action-logs) resource action-log)
|
||||
graphs
|
||||
%+ ~(put by graphs) resource
|
||||
(remove-at-index graph index.uid signatures)
|
||||
==
|
||||
::
|
||||
++ remove-at-index
|
||||
|= [=graph:store =index:store =signatures:store]
|
||||
@ -293,12 +279,8 @@
|
||||
atom
|
||||
?~ t.index
|
||||
node(signatures.post (~(dif in signatures) signatures.post.node))
|
||||
:: multiple indices left in list
|
||||
::
|
||||
~| "child graph does not exist to add signatures to!"
|
||||
?> ?=(%graph -.children.node)
|
||||
:: recurse into children
|
||||
::
|
||||
node(p.children $(graph p.children.node, index t.index))
|
||||
--
|
||||
::
|
||||
|
@ -57,20 +57,20 @@
|
||||
%remove-graph
|
||||
[%remove-graph (enjs:res resource.upd)]
|
||||
::
|
||||
:: %add-nodes
|
||||
:: :- %add-nodes
|
||||
:: %- pairs
|
||||
:: :~ [%resource (enjs:res resource.upd)]
|
||||
:: [%nodes (nodes nodes.upd)]
|
||||
:: ==
|
||||
%add-nodes
|
||||
:- %add-nodes
|
||||
%- pairs
|
||||
:~ [%resource (enjs:res resource.upd)]
|
||||
[%nodes (nodes nodes.upd)]
|
||||
==
|
||||
::
|
||||
%remove-nodes
|
||||
:- %remove-nodes
|
||||
%- pairs
|
||||
:~ [%resource (enjs:res resource.upd)]
|
||||
[%indices (indices indices.upd)]
|
||||
==
|
||||
::
|
||||
:: %remove-nodes
|
||||
:: :- %remove-nodes
|
||||
:: %- pairs
|
||||
:: :~ [%resource (enjs:res resource.upd)]
|
||||
:: [%indices (indices indices.upd)]
|
||||
:: ==
|
||||
:: ::
|
||||
%add-signatures
|
||||
:- %add-signatures
|
||||
%- pairs
|
||||
@ -117,8 +117,7 @@
|
||||
^- json
|
||||
=/ j=^tape ""
|
||||
|-
|
||||
?~ i
|
||||
[%s (crip j)]
|
||||
?~ i [%s (crip j)]
|
||||
=/ k=json (numb i.i)
|
||||
?> ?=(%n -.k)
|
||||
%_ $
|
||||
@ -217,6 +216,71 @@
|
||||
++ dejs
|
||||
=, dejs:format
|
||||
|%
|
||||
++ or :: parse keys of ordered map
|
||||
|* [fel=rule wit=fist]
|
||||
=/ key=mold _(wonk *fel)
|
||||
=/ val=mold _*wit
|
||||
|= ord=$-([key key] ?)
|
||||
^- fist
|
||||
=/ or-mp ((or-map key val) ord)
|
||||
|= jan=json
|
||||
=/ jom ((om wit) jan)
|
||||
%+ gas:or-mp ~
|
||||
%+ turn ~(tap by jom)
|
||||
|* [a=cord b=*]
|
||||
^- [key val]
|
||||
=> .(+< [a b]=+<)
|
||||
[(rash a fel) b]
|
||||
::
|
||||
++ graph (or dem node)
|
||||
::
|
||||
++ node
|
||||
%- ot
|
||||
:~ [%post post]
|
||||
:: TODO: support adding nodes with children by supporting the
|
||||
:: graph key
|
||||
[%children (of [%empty ul]~)]
|
||||
==
|
||||
::
|
||||
++ post
|
||||
%- ot
|
||||
:~ [%author (su ;~(pfix sig fed:ag))]
|
||||
[%index index]
|
||||
[%time-sent di]
|
||||
[%contents (ar content)]
|
||||
[%hash (mu nu)]
|
||||
[%signatures (as signature)]
|
||||
==
|
||||
::
|
||||
++ content
|
||||
%- of
|
||||
:~ [%text so]
|
||||
[%url so]
|
||||
[%reference uid]
|
||||
[%code eval]
|
||||
==
|
||||
::
|
||||
++ eval
|
||||
|= a=^json
|
||||
^- [cord (list tank)]
|
||||
=, ^? dejs-soft:format
|
||||
=+ exp=((ot expression+so ~) a)
|
||||
%- need
|
||||
?~ exp [~ '' ~]
|
||||
:+ ~ u.exp
|
||||
:: NOTE: when sending, if output is an empty list,
|
||||
:: graph-store will evaluate
|
||||
(fall ((ot output+(ar dank) ~) a) ~)
|
||||
::
|
||||
++ signature
|
||||
%- ot
|
||||
:~ [%hash nu]
|
||||
[%ship (su ;~(pfix sig fed:ag))]
|
||||
[%life ni]
|
||||
==
|
||||
::
|
||||
++ index (su ;~(pfix net (more net dem)))
|
||||
::
|
||||
++ action
|
||||
|= jon=json
|
||||
^- ^action
|
||||
@ -226,12 +290,11 @@
|
||||
|%
|
||||
++ decode
|
||||
%- of
|
||||
:~
|
||||
:: [%add-graph add-graph]
|
||||
:~ ::[%add-graph add-graph]
|
||||
[%remove-graph remove-graph]
|
||||
:: [%add-nodes add-nodes]
|
||||
:: [%remove-nodes remove-nodes]
|
||||
:: [%add-signatures add-signatures]
|
||||
[%add-nodes add-nodes]
|
||||
[%remove-nodes remove-nodes]
|
||||
[%add-signatures add-signatures]
|
||||
[%remove-signatures remove-signatures]
|
||||
[%add-tag add-tag]
|
||||
[%remove-tag remove-tag]
|
||||
@ -240,61 +303,67 @@
|
||||
:: ++ add-graph
|
||||
:: %- ot
|
||||
:: :~ [%resource dejs:res]
|
||||
:: [%graph !!]
|
||||
:: [%graph graph]
|
||||
:: ==
|
||||
::
|
||||
::
|
||||
++ graph (or dem node)
|
||||
::
|
||||
::
|
||||
++ remove-graph (ot [%resource dejs:res]~)
|
||||
::
|
||||
:: ++ add-nodes
|
||||
:: %- ot
|
||||
:: :~ [%resource dejs:res]
|
||||
:: [%nodes nodes]
|
||||
:: ==
|
||||
++ add-nodes
|
||||
%- ot
|
||||
:~ [%resource dejs:res]
|
||||
[%nodes nodes]
|
||||
==
|
||||
::
|
||||
:: ++ nodes (op index node)
|
||||
++ nodes (op ;~(pfix net (more net dem)) node)
|
||||
::
|
||||
:: ++ node
|
||||
:: %- ot
|
||||
:: :~ [%post post]
|
||||
:: [%children (ot [%empty ul]~)]
|
||||
:: ==
|
||||
:: ::
|
||||
:: ++ post
|
||||
:: %- ot
|
||||
:: :~ [%author (su ;~(pfix sig fed:ag))]
|
||||
:: [%index index]
|
||||
:: [%time-sent di]
|
||||
:: [%contents (ar content)]
|
||||
:: [%hash (mu nu)]
|
||||
:: [%signatures (as signature)]
|
||||
:: ==
|
||||
:: ::
|
||||
:: ++ content
|
||||
:: %- of
|
||||
:: :~ [%text so]
|
||||
:: [%url so]
|
||||
:: [%reference uid]
|
||||
:: [%code eval]
|
||||
:: ==
|
||||
:: ::
|
||||
:: ++ eval
|
||||
:: |= a=^json
|
||||
:: ^- [cord (list tank)]
|
||||
:: =, ^? dejs-soft:format
|
||||
:: =+ exp=((ot expression+so ~) a)
|
||||
:: %- need
|
||||
:: ?~ exp [~ '' ~]
|
||||
:: :+ ~ u.exp
|
||||
:: :: NOTE: when sending, if output is an empty list,
|
||||
:: :: graph-store will evaluate
|
||||
:: (fall ((ot output+(ar dank) ~) a) ~)
|
||||
++ node
|
||||
%- ot
|
||||
:~ [%post post]
|
||||
:: TODO: support adding nodes with children by supporting the
|
||||
:: graph key
|
||||
[%children (of [%empty ul]~)]
|
||||
==
|
||||
::
|
||||
++ post
|
||||
%- ot
|
||||
:~ [%author (su ;~(pfix sig fed:ag))]
|
||||
[%index index]
|
||||
[%time-sent di]
|
||||
[%contents (ar content)]
|
||||
[%hash (mu nu)]
|
||||
[%signatures (as signature)]
|
||||
==
|
||||
::
|
||||
++ content
|
||||
%- of
|
||||
:~ [%text so]
|
||||
[%url so]
|
||||
[%reference uid]
|
||||
[%code eval]
|
||||
==
|
||||
::
|
||||
++ eval
|
||||
|= a=^json
|
||||
^- [cord (list tank)]
|
||||
=, ^? dejs-soft:format
|
||||
=+ exp=((ot expression+so ~) a)
|
||||
%- need
|
||||
?~ exp [~ '' ~]
|
||||
:+ ~ u.exp
|
||||
:: NOTE: when sending, if output is an empty list,
|
||||
:: graph-store will evaluate
|
||||
(fall ((ot output+(ar dank) ~) a) ~)
|
||||
::
|
||||
++ remove-nodes
|
||||
%- ot
|
||||
:~ [%resource dejs:res]
|
||||
[%indices (as index)]
|
||||
==
|
||||
::
|
||||
:: ++ remove-nodes
|
||||
:: %- ot
|
||||
:: :~ [%resource dejs:res]
|
||||
:: [%indices (as index)]
|
||||
:: ==
|
||||
:: ::
|
||||
++ add-signatures
|
||||
%- ot
|
||||
:~ [%uid uid]
|
||||
|
@ -33,11 +33,11 @@
|
||||
==
|
||||
::
|
||||
+$ action-0
|
||||
$% :: [%add-graph =resource =graph]
|
||||
$% ::[%add-graph =resource =graph]
|
||||
[%remove-graph =resource]
|
||||
::
|
||||
:: [%add-nodes =resource nodes=(map index node)]
|
||||
:: [%remove-nodes =resource indices=(set index)]
|
||||
[%add-nodes =resource nodes=(map index node)]
|
||||
[%remove-nodes =resource indices=(set index)]
|
||||
::
|
||||
[%add-signatures =uid =signatures]
|
||||
[%remove-signatures =uid =signatures]
|
||||
|
Loading…
Reference in New Issue
Block a user