tmp progress on talk-json lib & marks

This commit is contained in:
Fang 2017-10-12 12:30:16 +02:00
parent 082ebfc8ae
commit c14970c228
5 changed files with 164 additions and 79 deletions

130
lib/talk-json.hoon Normal file
View File

@ -0,0 +1,130 @@
::
:::: /lib/talk-json/hoon
::
/- talk
::
::> rules for sur-json conversion: (proposal, adhered to below)
::> 1. to save the devs from having to learn multiple interfaces, try to match
::> the hoon structure as closely as possible, including attribute names.
::> 2. if these names are p/q/r, slightly more semantic naming is preferred.
::> 2. when dealing with $%, the tag is the variable name. ie `{$x ...}` -> `x`
::> for tagged unions with one piece of data, `x` holds that value.
::> for tagged unions with multiple pieces of data, `x` is an object.
::> 3. ...
::
=, talk
|%
++ en-json ::> sur to json
|%
++ spec ::> speech
--
::
++ de-json ::> json to sur
=, dejs-soft:format
|%
::TODO these first few should maybe make their way
:: into the stdlib...
++ as ::> array as set
|* a/fist
(cu ~(gas in *(set _(need *a))) (ar a))
::
++ dank ::> tank
^- $-(json (unit tank))
%- of :~
leaf+sa
palm+(ot style+(ot mid+sa cap+sa open+sa close+sa ~) lines+(ar dank) ~)
rose+(ot style+(ot mid+sa open+sa close+sa ~) lines+(ar dank) ~)
==
::
::
++ dist
^- $-(json (unit diff-status))
%- of :~
full+(ot pec+(su pres) man+huma ~)
presence+(su pres)
human+dihu
remove+ul
==
::
++ dihu
^- $-(json (unit diff-human))
%- of :~
full+huma
handle+(mu so)
true+
==
::
::> ||
::> || %circles
::> ||
::> messaging targets and their metadata.
::+|
::
++ circ ::> circle
^- $-(nail (like circle))
;~((glue fas) ;~(pfix sig fed:ag) urt:ab)
::
++ pres ::> presence
^- $-(nail (like presence))
(perk %gone %idle %hear %talk ~)
::
++ huma ::> human
^- $-(json (unit human))
%- ot :~
han+(mu so)
tru+(mu true)
==
::
++ true ::> truename
^- $-(json (unit truename))
(ot fir+so mid+(mu so) las+so ~)
::
::> ||
::> || %message-data
::> ||
::> structures for containing main message data.
::+|
::
++ thot ::> thought
^- $-(json (unit thought))
%- ot :~
uid+seri
aud+audi
wen+di
sep+spec
==
::
++ spec ::> speech
^- $-(json (unit speech))
%- of :~
lin+(ot pat+bo txt+so ~)
url+(su aurf:de-purl:html)
exp+(ot exp+so res+(ar dank) ~)
ire+(ot top+seri sep+spec ~)
fat+(ot tac+atta sep+spec ~)
inv+(ot inv+bo cir+(su circ) ~)
==
::
++ atta ::> attache
^- $-(json (unit attache))
%- of :~
name+(ot nom+so tac+atta ~)
text+(ar so)
tank+(ar dank)
==
::
::> ||
::> || %message-metadata
::> ||
:: structures for containing message metadata.
::+|
::
++ seri ::> serial
^- $-(json (unit serial))
(ci (slat %uv) so)
::
++ audi ::> audience
^- $-(json (unit audience))
(as (su circ))
--
--

26
mar/talk/action.hoon Normal file
View File

@ -0,0 +1,26 @@
::
:::: /mar/talk/rumor/hoon
::
/- talk
/+ talk-json
::
=, talk
|_ dif/action
::
++ grab ::> convert from
|%
++ noun action ::< from %noun
++ json ::> from %json
=, dejs-soft:format
=, talk-json:de-json
|= a/json ^- action
=- (need ((of -) a))
:~ create+ul
==
--
::
++ grow ::> convert to
|%
++ json ::> to %json
--
--

View File

@ -3,84 +3,13 @@
:: ::
/? 310 /? 310
/- talk /- talk
/+ talk-json
:: ::
=, talk =, talk
|_ cod/command |_ cod/command
:: ::
++ grab :: convert from ++ grab :: convert from
|% |%
++ noun command :: clam from %noun ++ noun command :: from %noun
++ json
=, dejs-soft:format
|= a/json ^- command
=- (need ((of -) a))
=< :~ publish+(ar thot)
bearing+ul
==
|%
++ op :: parse keys of map
|* {fel/rule wit/fist}
%+ cu malt
%+ ci
|= a/(map cord _(need *wit))
=, unity
^- (unit (list _[(wonk *fel) (need *wit)]))
(drop-list (turn ~(tap by a) (head-rush fel)))
(om wit)
::
++ ke :: callbacks
|* {gar/* sef/_|.(fist)}
|= jon/json
^- (unit _gar)
=- ~! gar ~! (need -) -
((sef) jon)
::
++ as :: array as set
|* a/fist
(cu ~(gas in *(set _(need *a))) (ar a))
::
++ peach
|* a/{rule rule}
|= tub/nail
^- (like (each _(wonk (-.a)) _(wonk (+.a))))
%. tub
;~(pose (stag %& -.a) (stag %| +.a))
::
++ head-rush
|* a/rule
|* {cord *}
=+ nit=(rush +<- a)
?~ nit ~
(some [u.nit +>->])
::
++ thot
^- $-(json (unit thought))
%- ot :~
serial+ceri
audience+audi
date+di
speech+spec
==
::
++ ceri
^- $-(json (unit serial))
(ci (slat %uv) so)
::
++ audi
^- $-(json (unit audience))
(as (su circ))
::
++ circ
^- $-(nail (like circle))
;~((glue fas) ;~(pfix sig fed:ag) urs:ab)
::
++ spec
^- $-(json (unit speech))
%- of :~
lin+(ot say+bo txt+so ~)
url+(su aurf:de-purl:html)
:: exp+(cu |=(a=cord [a ~]) so)
:: inv+(ot ship+(su fed:ag) party+(su urs:ab) ~)
==
-- --
-- -- --

View File

@ -1,6 +1,6 @@
:: ::
:::: /hoon/report/talk/mar :::: /hoon/report/talk/mar
:: ::TODO deleteme
/? 310 /? 310
/- talk /- talk
/+ talk, old-zuse /+ talk, old-zuse
@ -118,11 +118,11 @@
++ huma ++ huma
|= human |= human
%^ jobe %^ jobe
hand+?~(han ~ [%s u.han]) han+?~(han ~ [%s u.han])
:- %true :- %true
?~ tru ~ ?~ tru ~
=+ u.tru =+ u.tru
(jobe first+[%s p] middle+?~(q ~ [%s u.q]) last+[%s r] ~) (jobe fir+[%s fir] mid+?~(mid ~ [%s u.mid]) las+[%s las] ~)
~ ~
:: ::
++ loby ++ loby

View File

@ -12,7 +12,7 @@
=, old-zuse =, old-zuse
|_ gam/(list telegram) |_ gam/(list telegram)
:: ::
++ grab ++ grab :: convert from
|% |%
++ noun (list telegram) ++ noun (list telegram)
++ mime |=(^mime (json (rash q.q apex:de-json))) ++ mime |=(^mime (json (rash q.q apex:de-json)))
@ -102,7 +102,7 @@
-- --
-- --
:: ::
++ grow ++ grow :: convert to
|% |%
++ mime [/text/json (as-octs (crip (en-json json)))] ++ mime [/text/json (as-octs (crip (en-json json)))]
++ json ++ json