From c14970c228b57fb824f3ee5931f86d7c31074105 Mon Sep 17 00:00:00 2001 From: Fang Date: Thu, 12 Oct 2017 12:30:16 +0200 Subject: [PATCH] tmp progress on talk-json lib & marks --- lib/talk-json.hoon | 130 ++++++++++++++++++++++++++++++++++++++++ mar/talk/action.hoon | 26 ++++++++ mar/talk/command.hoon | 77 +----------------------- mar/talk/report.hoon | 6 +- mar/talk/telegrams.hoon | 4 +- 5 files changed, 164 insertions(+), 79 deletions(-) create mode 100644 lib/talk-json.hoon create mode 100644 mar/talk/action.hoon diff --git a/lib/talk-json.hoon b/lib/talk-json.hoon new file mode 100644 index 000000000..ed78b1099 --- /dev/null +++ b/lib/talk-json.hoon @@ -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)) + -- +-- diff --git a/mar/talk/action.hoon b/mar/talk/action.hoon new file mode 100644 index 000000000..8ca423cfd --- /dev/null +++ b/mar/talk/action.hoon @@ -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 + -- +-- diff --git a/mar/talk/command.hoon b/mar/talk/command.hoon index 1b4acb1b5..40ec26ad8 100644 --- a/mar/talk/command.hoon +++ b/mar/talk/command.hoon @@ -3,84 +3,13 @@ :: /? 310 /- talk +/+ talk-json :: =, talk |_ cod/command :: ++ grab :: convert from |% - ++ noun command :: clam 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) ~) - == + ++ noun command :: from %noun -- --- -- +-- diff --git a/mar/talk/report.hoon b/mar/talk/report.hoon index 6de9db1d5..bb2ba94b7 100644 --- a/mar/talk/report.hoon +++ b/mar/talk/report.hoon @@ -1,6 +1,6 @@ :: :::: /hoon/report/talk/mar - :: + ::TODO deleteme /? 310 /- talk /+ talk, old-zuse @@ -118,11 +118,11 @@ ++ huma |= human %^ jobe - hand+?~(han ~ [%s u.han]) + han+?~(han ~ [%s u.han]) :- %true ?~ 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 diff --git a/mar/talk/telegrams.hoon b/mar/talk/telegrams.hoon index 106e05c6b..d95942b08 100644 --- a/mar/talk/telegrams.hoon +++ b/mar/talk/telegrams.hoon @@ -12,7 +12,7 @@ =, old-zuse |_ gam/(list telegram) :: -++ grab +++ grab :: convert from |% ++ noun (list telegram) ++ 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)))] ++ json