From c4efedc1d420af39aa514066557ddf7564ca9ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Paraniak?= Date: Wed, 11 Sep 2024 19:00:19 +0800 Subject: [PATCH] contacts: implement v1 json conversions --- desk/app/contacts.hoon | 6 +- desk/lib/contacts/json-0.hoon | 131 +++++++++++++++++++++++++++ desk/lib/contacts/json-1.hoon | 152 ++++++++++++++++++++++++++++++++ desk/lib/mark-warmer.hoon | 10 ++- desk/mar/contact-0.hoon | 14 +++ desk/mar/contact-1.hoon | 15 ++++ desk/mar/contact/action-1.hoon | 16 +++- desk/mar/contact/book.hoon | 14 +++ desk/mar/contact/directory.hoon | 14 +++ desk/mar/contact/news-1.hoon | 14 +++ desk/mar/contact/page-1.hoon | 14 +++ desk/mar/contact/update-0.hoon | 5 +- desk/mar/contact/update-1.hoon | 14 ++- desk/sur/contacts.hoon | 1 + 14 files changed, 409 insertions(+), 11 deletions(-) create mode 100644 desk/lib/contacts/json-0.hoon create mode 100644 desk/lib/contacts/json-1.hoon create mode 100644 desk/mar/contact-0.hoon create mode 100644 desk/mar/contact-1.hoon create mode 100644 desk/mar/contact/book.hoon create mode 100644 desk/mar/contact/directory.hoon create mode 100644 desk/mar/contact/news-1.hoon create mode 100644 desk/mar/contact/page-1.hoon diff --git a/desk/app/contacts.hoon b/desk/app/contacts.hoon index 1383210..84b3e57 100644 --- a/desk/app/contacts.hoon +++ b/desk/app/contacts.hoon @@ -2,7 +2,7 @@ /+ default-agent, dbug, verb /+ *contacts :: performance, keep warm -/+ contacts-json +/+ j0=contacts-json-0, j1=contacts-json-1 :: |% :: conventions @@ -621,11 +621,11 @@ :: :: v1 scries :: - :: /x/v1/self -> $@(~ $profile-1) + :: /x/v1/self -> $contact-1 :: /x/v1/book -> $book :: /x/v1/book/her=@p -> $page :: /x/v1/book/id/cid=@uv -> $page - :: /x/v1/all -> (map ship contact-1) + :: /x/v1/all -> $directory :: /x/v1/contact/her=@p -> $contact-1 :: /x/v1/peer/her=@p -> $contact-1 :: diff --git a/desk/lib/contacts/json-0.hoon b/desk/lib/contacts/json-0.hoon new file mode 100644 index 0000000..6f40421 --- /dev/null +++ b/desk/lib/contacts/json-0.hoon @@ -0,0 +1,131 @@ +/- c=contacts, g=groups +/+ gj=groups-json +|% +++ enjs + =, enjs:format + |% + :: XX shadowed for compat, +ship:enjs removes the ~ + :: + ++ ship + |=(her=@p n+(rap 3 '"' (scot %p her) '"' ~)) + :: + ++ action + |= a=action-0:c + ^- json + %+ frond -.a + ?- -.a + %anon ~ + %edit a+(turn p.a field) + %meet a+(turn p.a ship) + %heed a+(turn p.a ship) + %drop a+(turn p.a ship) + %snub a+(turn p.a ship) + == + :: + ++ contact + |= c=contact-0:c + ^- json + %- pairs + :~ nickname+s+nickname.c + bio+s+bio.c + status+s+status.c + color+s+(scot %ux color.c) + avatar+?~(avatar.c ~ s+u.avatar.c) + cover+?~(cover.c ~ s+u.cover.c) + :: + =- groups+a+- + %- ~(rep in groups.c) + |=([f=flag:g j=(list json)] [s+(flag:enjs:gj f) j]) + == + :: + ++ field + |= f=field-0:c + ^- json + %+ frond -.f + ?- -.f + %nickname s+nickname.f + %bio s+bio.f + %status s+status.f + %color s+(rsh 3^2 (scot %ux color.f)) :: XX confirm + %avatar ?~(avatar.f ~ s+u.avatar.f) + %cover ?~(cover.f ~ s+u.cover.f) + %add-group s+(flag:enjs:gj flag.f) + %del-group s+(flag:enjs:gj flag.f) + == + :: + ++ rolodex + |= r=rolodex-0:c + ^- json + %- pairs + %- ~(rep by r) + |= [[who=@p foreign-0:c] j=(list [@t json])] + [[(scot %p who) ?.(?=([@ ^] for) ~ (contact con.for))] j] :: XX stale flag per sub state? + :: + ++ news + |= n=news-0:c + ^- json + %- pairs + :~ who+(ship who.n) + con+?~(con.n ~ (contact con.n)) + == + -- +:: +++ dejs + =, dejs:format + |% + :: for performance, @p is serialized above to json %n (no escape) + :: for mark roundtrips, ships are parsed from either %s or %n + :: XX do this elsewhere in groups? + :: + ++ ship (se-ne %p) + ++ se-ne + |= aur=@tas + |= jon=json + ?+ jon !! + [%s *] (slav aur p.jon) + :: + [%n *] ~| bad-n+p.jon + =/ wyd (met 3 p.jon) + ?> ?& =('"' (end 3 p.jon)) + =('"' (cut 3 [(dec wyd) 1] p.jon)) + == + (slav aur (cut 3 [1 (sub wyd 2)] p.jon)) + == + :: + ++ action + ^- $-(json action-0:c) + %- of + :~ anon+ul + edit+(ar field) + meet+(ar ship) + heed+(ar ship) + drop+(ar ship) + snub+(ar ship) + == + :: + ++ contact + ^- $-(json contact-0:c) + %- ot + :~ nickname+so + bio+so + status+so + color+nu + avatar+(mu so) + cover+(mu so) + groups+(as flag:dejs:gj) + == + :: + ++ field + ^- $-(json field-0:c) + %- of + :~ nickname+so + bio+so + status+so + color+nu + avatar+(mu so) + cover+(mu so) + add-group+flag:dejs:gj + del-group+flag:dejs:gj + == + -- +-- diff --git a/desk/lib/contacts/json-1.hoon b/desk/lib/contacts/json-1.hoon new file mode 100644 index 0000000..66a72e9 --- /dev/null +++ b/desk/lib/contacts/json-1.hoon @@ -0,0 +1,152 @@ +/- c=contacts, g=groups +/+ gj=groups-json +|% +++ enjs + =, enjs:format + |% + :: XX shadowed for compat, +ship:enjs removes the ~ + :: + ++ ship + |=(her=@p n+(rap 3 '"' (scot %p her) '"' ~)) + :: + ++ cid + |= =cid:c + ^- json + s+(scot %uv cid) + :: + ++ kip + |= =kip:c + ^- json + ?@ kip + (ship kip) + (cid +.kip) + :: + ++ value + |= val=value-1:c + ^- json + ?- -.val + %text (pairs type+s/%text value+s/p.val ~) + %date (pairs type+s/%date value+s/(scot %da p.val) ~) + %tint (pairs type+s/%tint value+s/(rsh 3^2 (scot %ux p.val)) ~) + %ship (pairs type+s/%ship value+(ship p.val) ~) + %look (pairs type+s/%look value+s/p.val ~) + %cult (pairs type+s/%cult value+s/(flag:enjs:gj p.val) ~) + %set (pairs type+s/%set value+a/(turn ~(tap in p.val) value) ~) + == + :: + ++ contact + |= c=contact-1:c + ^- json + o+(~(run by c) value) + :: + ++ page + |= =page:c + ^- json + a+[(contact p.page) (contact q.page) ~] + :: +$ kip $@(@p [%id cid]) + :: +$ book (map kip page) + ++ book + |= =book:c + ^- json + =| kob=(map @ta json) + :- %o + %- ~(rep by book) + |= [[=kip:c =page:c] acc=_kob] + ?^ kip + (~(put by acc) (scot %uv +.kip) (^page page)) + (~(put by acc) (scot %p kip) (^page page)) + :: + ++ directory + |= =directory:c + ^- json + =| dir=(map @ta json) + :- %o + %- ~(rep by directory) + |= [[who=@p con=contact-1:c] acc=_dir] + (~(put by acc) (scot %p who) (contact con)) + :: + ++ news + |= n=news-1:c + ^- json + ?- -.n + %self (frond self+(contact con.n)) + %page %- pairs + :~ kip+(kip kip.n) + con+(contact con.n) + mod+(contact mod.n) + == + %wipe (frond kip+(kip kip.n)) + %peer %- pairs + :~ who+(ship who.n) + con+(contact con.n) + == + == + -- +:: +++ dejs + =, dejs:format + |% + :: + ++ ship (se %p) + :: + ++ cid + |= jon=json + ^- cid:c + ?> ?=(%s -.jon) + (slav %uv p.jon) + :: + ++ kip + |= jon=json + ^- kip:c + ?> ?=(%s -.jon) + ?: =('~' (end [3 1] p.jon)) + (ship jon) + id+(cid jon) + :: + ++ ta + |* [mas=@tas wit=fist] + |= jon=json + [mas (wit jon)] + :: + ++ value + ^- $-(json value-1:c) + |= jon=json + :: XX is there a way to do it in one go? + :: + =/ [type=@tas val=json] + %. jon + (ot text+(se %tas) value+json ~) + ?+ type !! + %text %. val (ta %text so) + %date %. val (ta %date (se %da)) + :: XX invert arguments in +cu: arguments likely + :: to be heavy should always be at the back + :: + %tint %. val + %+ ta %tint + %+ cu + |=(s=@t (slav %ux (cat 3 '0x' s))) + so + %ship %. val (ta %ship ship) + %look %. val (ta %look so) + %cult %. val (ta %cult flag:dejs:gj) + %set %. val (ta %set (as value)) + == + ++ contact + ^- $-(json contact-1:c) + (om value) + ++ action + ^- $-(json action-1:c) + %- of + :~ anon+ul + self+contact + page+(ot cid+cid contact+contact ~) + spot+(ot ship+ship contact+contact ~) + edit+(ot kip+kip contact+contact ~) + wipe+(ar kip) + meet+(ar ship) + drop+(ar ship) + snub+(ar ship) + == + -- +-- diff --git a/desk/lib/mark-warmer.hoon b/desk/lib/mark-warmer.hoon index 0bf6264..ad40eb9 100644 --- a/desk/lib/mark-warmer.hoon +++ b/desk/lib/mark-warmer.hoon @@ -1,9 +1,15 @@ /$ rolo %contact-rolodex %json -/$ contact %contact %json +/$ contact %contact-0 %json +/$ contact-1 %contact-1 %json +/$ page-1 %contact-page-1 %json +/$ book-1 %contact-book %json +/$ dir-1 %contact-directory %json +/$ news-1 %contact-news-1 %json /$ skeins %hark-skeins %json /$ carpet %hark-carpet %json /$ blanket %hark-blanket %json /$ settings %settings-data %json -/$ creds %update %json +:: XX defunct? +:: /$ creds %update %json /$ storage %storage-update %json ~ diff --git a/desk/mar/contact-0.hoon b/desk/mar/contact-0.hoon new file mode 100644 index 0000000..b9383f8 --- /dev/null +++ b/desk/mar/contact-0.hoon @@ -0,0 +1,14 @@ +/- c=contacts +/+ j=contacts-json-0 +|_ =contact-0:c +++ grad %noun +++ grow + |% + ++ noun contact-0 + ++ json (contact:enjs:j contact-0) + -- +++ grab + |% + ++ noun contact-0:c + -- +-- diff --git a/desk/mar/contact-1.hoon b/desk/mar/contact-1.hoon new file mode 100644 index 0000000..4418f7c --- /dev/null +++ b/desk/mar/contact-1.hoon @@ -0,0 +1,15 @@ +/- c=contacts +/+ j=contacts-json-1 +|_ contact=contact-1:c +++ grad %noun +++ grow + |% + ++ noun contact + ++ json (contact:enjs:j contact) + -- +++ grab + |% + ++ noun contact-1:c + ++ json contact:dejs:j + -- +-- diff --git a/desk/mar/contact/action-1.hoon b/desk/mar/contact/action-1.hoon index 623b233..3d8a88e 100644 --- a/desk/mar/contact/action-1.hoon +++ b/desk/mar/contact/action-1.hoon @@ -1,2 +1,14 @@ -/= mark /mar/dummy -mark +/- c=contacts +/+ j=contacts-json-1 +|_ action=action-1:c +++ grad %noun +++ grow + |% + ++ noun action + -- +++ grab + |% + ++ noun action-1:c + ++ json action:dejs:j + -- +-- diff --git a/desk/mar/contact/book.hoon b/desk/mar/contact/book.hoon new file mode 100644 index 0000000..2de84aa --- /dev/null +++ b/desk/mar/contact/book.hoon @@ -0,0 +1,14 @@ +/- c=contacts +/+ j=contacts-json-1 +|_ book=book:c +++ grad %noun +++ grow + |% + ++ noun book + ++ json (book:enjs:j book) + -- +++ grab + |% + ++ noun book:c + -- +-- diff --git a/desk/mar/contact/directory.hoon b/desk/mar/contact/directory.hoon new file mode 100644 index 0000000..6bdab66 --- /dev/null +++ b/desk/mar/contact/directory.hoon @@ -0,0 +1,14 @@ +/- c=contacts +/+ j=contacts-json-1 +|_ directory=directory:c +++ grad %noun +++ grow + |% + ++ noun directory + ++ json (directory:enjs:j directory) + -- +++ grab + |% + ++ noun directory:c + -- +-- diff --git a/desk/mar/contact/news-1.hoon b/desk/mar/contact/news-1.hoon new file mode 100644 index 0000000..7671e4d --- /dev/null +++ b/desk/mar/contact/news-1.hoon @@ -0,0 +1,14 @@ +/- c=contacts +/+ j=contacts-json-1 +|_ news=news-1:c +++ grad %noun +++ grow + |% + ++ noun news + ++ json (news:enjs:j news) + -- +++ grab + |% + ++ noun news-1:c + -- +-- diff --git a/desk/mar/contact/page-1.hoon b/desk/mar/contact/page-1.hoon new file mode 100644 index 0000000..ca62844 --- /dev/null +++ b/desk/mar/contact/page-1.hoon @@ -0,0 +1,14 @@ +/- c=contacts +/+ j=contacts-json-1 +|_ =page:c +++ grad %noun +++ grow + |% + ++ noun page + ++ json (page:enjs:j page) + -- +++ grab + |% + ++ noun page:c + -- +-- diff --git a/desk/mar/contact/update-0.hoon b/desk/mar/contact/update-0.hoon index 3bec860..8b7a43b 100644 --- a/desk/mar/contact/update-0.hoon +++ b/desk/mar/contact/update-0.hoon @@ -1,5 +1,5 @@ /- c=contacts -|_ =update:c +|_ update=update-0:c ++ grad %noun ++ grow |% @@ -7,6 +7,7 @@ -- ++ grab |% - ++ noun update:c + ++ noun update-0:c + -- -- diff --git a/desk/mar/contact/update-1.hoon b/desk/mar/contact/update-1.hoon index 623b233..d979d7a 100644 --- a/desk/mar/contact/update-1.hoon +++ b/desk/mar/contact/update-1.hoon @@ -1,2 +1,12 @@ -/= mark /mar/dummy -mark +/- c=contacts +|_ update=update-1:c +++ grad %noun +++ grow + |% + ++ noun update + -- +++ grab + |% + ++ noun update-1:c + -- +-- diff --git a/desk/sur/contacts.hoon b/desk/sur/contacts.hoon index 8f38261..0e3d4fe 100644 --- a/desk/sur/contacts.hoon +++ b/desk/sur/contacts.hoon @@ -90,6 +90,7 @@ :: :: uniform set [%set $|(p=(set value-1) unis)] + :: [%set p=(set value-1)] == :: $contact-1: contact data ::