diff options
| author | polwex <polwex@sortug.com> | 2025-10-06 01:01:41 +0700 |
|---|---|---|
| committer | polwex <polwex@sortug.com> | 2025-10-06 01:01:41 +0700 |
| commit | c4b392a179048f936c062f5ffccc2bc25627e500 (patch) | |
| tree | 09be0904be8ec4d7ea52992ef7580d42ed0c28c1 /app/lib/json | |
working
Diffstat (limited to 'app/lib/json')
| -rw-r--r-- | app/lib/json/common.hoon | 30 | ||||
| -rw-r--r-- | app/lib/json/nostr.hoon | 197 | ||||
| -rw-r--r-- | app/lib/json/nostrill.hoon | 245 | ||||
| -rw-r--r-- | app/lib/json/trill.hoon | 219 |
4 files changed, 691 insertions, 0 deletions
diff --git a/app/lib/json/common.hoon b/app/lib/json/common.hoon new file mode 100644 index 0000000..0ed54cd --- /dev/null +++ b/app/lib/json/common.hoon @@ -0,0 +1,30 @@ +/+ sr=sortug +|% +++ en +=, enjs:format + |% + ++ cord |= s=@t ^- json s+s + ++ hex |= h=@ux ^- json + =/ scoww scow:sr + [%s (crip (scoww(min-chars 64) %ux h))] + ++ b64 |= h=@uv ^- json + [%s (crip (scow:sr %uv h))] + ++ ud |= n=@ ^- json + [%s (crip (scow:sr %ud n))] + ++ patp |= p=@p ^- json + [%s (scot %p p)] + -- +++ de +=, dejs-soft:format + |% + ++ hex |= jon=json ^- (unit @ux) + ?. ?=(%s -.jon) ~ + =/ atom=(unit @) (slaw:sr %ux p.jon) + ?~ atom ~ + atom + ++ se |= aur=@tas |= jon=json + ?. ?=(%s -.jon) ~ + (slaw aur p.jon) + -- + +-- diff --git a/app/lib/json/nostr.hoon b/app/lib/json/nostr.hoon new file mode 100644 index 0000000..cb10c1d --- /dev/null +++ b/app/lib/json/nostr.hoon @@ -0,0 +1,197 @@ +/- sur=nostr +/+ common=json-common, sr=sortug +|% +++ en +=, enjs:format + |% + :: shim comms + ++ bulk-req |= [relays=(list @t) r=req:shim:sur] ^- json + %+ frond %ws + %: pairs + relays+a+(turn relays cord:en:common) + req+(req r) + ~ + == + ++ http-req |= [relay=@t delay=@ud sub-id=@t fs=(list filter:sur)] + %+ frond %http + %: pairs + relay+s+relay + delay+(numb delay) + ['subscription_id' %s sub-id] + filters+a+(turn fs filter) + ~ + == + ++ req |= =req:shim:sur ^- json + =/ en-ev event + :- %a :- s+(crip (cuss (trip -.req))) + ?- -.req + %req (enreq +.req) + %event :_ ~ (en-ev(nostr .y) +.req) + %auth :_ ~ (en-ev(nostr .y) +.req) + %close :_ ~ [%s +.req] + == +++ enreq + |= [sub-id=@t fs=(list filter:sur)] + ^- (list json) + :- [%s sub-id] + %+ turn fs filter + + :: + ++ raw-event |= raw-event:sur + :: WTF nostr doesn't want the prefix on the pubkey + :: =/ scw scow:sr + :: =/ pubkeyt (scw(min-chars 64) %ux pubkey) + =/ pubkeyt (scow:sr %ux pubkey) + ?~ pubkeyt !! + =/ pubkeyj [%s (crip t.pubkeyt)] + :: =/ pubkeyj [%s (crip pubkeyt)] + :- %a :~ + [%n '0'] + pubkeyj + (numb created-at) + (numb kind) + a+(turn tags tag) + s+content + == + ++ event + =/ nostr=? .n + |= e=event:sur ^- json + =/ pubkey ?. nostr + (hex:en:common pubkey.e) + =/ pubkeyt (scow:sr %ux pubkey.e) + ?~ pubkeyt !! + [%s (crip t.pubkeyt)] + %: pairs + id+(hex:en:common id.e) + pubkey+pubkey + sig+(hex:en:common sig.e) + ['created_at' (numb created-at.e)] + kind+(numb kind.e) + content+s+content.e + tags+a+(turn tags.e tag) + ~ + == + ++ tag + |= t=tag:sur ^- json [%a (turn t cord:en:common)] + :: :- s+key.t + :: :- s+value.t + :: (turn rest.t |=(tt=@t s+tt)) + :: + ++ filter + |= f=filter:sur ^- json + =| l=(list [key=@t jon=json]) + =. l ?~ ids.f l :_ l ['ids' %a (turn ~(tap in u.ids.f) hex:en:common)] + =. l ?~ authors.f l :_ l ['authors' %a (turn ~(tap in u.authors.f) hex:en:common)] + =. l ?~ kinds.f l :_ l ['kinds' %a (turn ~(tap in u.kinds.f) numb)] + =. l ?~ tags.f l %+ weld l (tags u.tags.f) + + =. l ?~ since.f l :_ l ['since' (sect u.since.f)] + =. l ?~ until.f l :_ l ['until' (sect u.until.f)] + =. l ?~ limit.f l :_ l ['limit' (numb u.limit.f)] + :: + %- pairs l + + + ++ tags + |= tm=(map @t (set @t)) ^- (list [@t json]) :: entries to the filter obeject + %+ turn ~(tap by tm) |= [key=@t values=(set @t)] + =/ nkey (cat 3 '#' key) + [nkey %a (turn ~(tap in values) cord:en:common)] + + ++ user-meta + |= meta=user-meta:sur + %: pairs + name+s+name.meta + picture+s+picture.meta + about+s+about.meta + other+o+other.meta + ~ + == + -- +++ de +=, dejs-soft:format + |% + :: shim + ++ shim-res + %- of :~ + http+(ar relay-msg) + ws+msg + == + ++ msg + %- ot :~ + relay+so + msg+relay-msg + == + ++ relay-msg + %- of :~ + event+event-sub + ok+relay-ok + eose+so + closed+closed + notice+so + error+so + == + + + :: | { event: { subscription_id: string; event: NostrEvent } } + :: | { ok: { event_id: string; accepted: boolean; message: string } } + :: | { eose: string } + :: | { closed: { subscription_id: string; message: string } } + :: | { notice: string } + :: // this is ours + :: | { error: string }; + ++ event-sub + %- ot :~ + ['subscription_id' so] + event+event + == + ++ relay-ok + %- ot :~ + ['event_id' hex:de:common] + accepted+bo + message+so + == + ++ closed + %- ot :~ + ['subscription_id' so] + message+so + == + ++ event + %- ot :~ + id+hex:de:common + pubkey+hex:de:common + ['created_at' ni] + kind+ni + tags+(ar (ar so)) + content+so + sig+hex:de:common + == + ++ user-meta |= jon=json + ^- (unit user-meta:sur) + ?. ?=(%o -.jon) ~ + =| um=user-meta:sur + =/ fields ~(tap by p.jon) + |- ?~ fields (some um) + =/ k -.i.fields + =/ jn=json +.i.fields + ?+ k + =/ ot (~(put by other.um) k jn) + =. um um(other ot) $(fields t.fields) + %'name' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(name u.crd)) + %'display_name' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(name u.crd)) + %'displayName' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(name u.crd)) + %'about' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(picture u.crd)) + %'picture' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(picture u.crd)) + == + -- +-- diff --git a/app/lib/json/nostrill.hoon b/app/lib/json/nostrill.hoon new file mode 100644 index 0000000..b07de61 --- /dev/null +++ b/app/lib/json/nostrill.hoon @@ -0,0 +1,245 @@ +/- sur=nostrill, nsur=nostr, feed=trill-feed, comms=nostrill-comms +/+ sr=sortug, common=json-common, trill=json-trill, nostr=json-nostr +|% +++ en +=, enjs:format +|% + :: UI comms + ++ state |= state-0:sur ^- json + %+ frond %state + %: pairs + relays+(en-relays relays) + key+(hex:en:common pub.i.keys) + profiles+(en-profiles profiles) + :: TODO proper cursors + feed+(feed-with-cursor:en:trill feed ~ ~) + nostr+(en-nostr-feed nostr-feed) + following+(enfollowing following) + ['followGraph' (engraph follow-graph)] + ~ + == + ++ en-nostr-feed + |= feed=nostr-feed:sur ^- json + :- %a %+ turn (tap:norm:sur feed) |= [id=@ud ev=event:nsur] + (event:en:nostr ev) + + ++ en-relays + |= r=(map @t relay-stats:nsur) ^- json + %- pairs %+ turn ~(tap by r) + |= [url=@t rs=relay-stats:nsur] + :- url %- pairs + :~ :- %connected ?~ connected.rs ~ (time u.connected.rs) + :- %reqs (relay-stats reqs.rs) + == + ++ relay-stats |= rm=(map @t event-stats:nsur) + %- pairs %+ turn ~(tap by rm) |= [sub-id=@t es=event-stats:nsur] + :: TODO do we even need this + :- sub-id (numb received.es) + + ++ en-profiles |= m=(map user:sur user-meta:nsur) + %- pairs + %+ turn ~(tap by m) |= [key=user:sur p=user-meta:nsur] + =/ jkey (user key) + ?> ?=(%s -.jkey) + :- +.jkey (user-meta:en:nostr p) + + ++ enfollowing + |= m=(map user:sur feed:feed) + ^- json + %- pairs %+ turn ~(tap by m) |= [key=user:sur f=feed:feed] + =/ jkey (user key) + ?> ?=(%s -.jkey) + :: TODO proper cursor stuff + :- +.jkey (feed-with-cursor:en:trill f ~ ~) + + ++ engraph + |= m=(map user:sur (set user:sur)) + ^- json + %- pairs %+ turn ~(tap by m) |= [key=user:sur s=(set user:sur)] + =/ jkey (user key) + ?> ?=(%s -.jkey) + :- +.jkey + :- %a %+ turn ~(tap in s) user + + ++ follow + |= f=follow:sur + %- pairs + :~ pubkey+(hex:en:common pubkey.f) + name+s+name.f + :- %relay ?~ relay.f ~ s+u.relay.f + == + ++ user |= u=user:sur ^- json + ?- -.u + %urbit (patp:en:common +.u) + %nostr (hex:en:common +.u) + == + :: ui facts + ++ fact |= f=fact:ui:sur ^- json + %+ frond %fact + %+ frond -.f + ?- -.f + %nostr (en-nostr-feed +.f) + %post (postfact +.f) + %enga (enga +.f) + %fols (fols +.f) + == + ++ fols |= ff=fols-fact:ui:sur ^- json + %+ frond -.ff + ?- -.ff + %quit (user +.ff) + %new %: pairs + user+(user user.ff) + feed+(feed-with-cursor:en:trill fc.ff) + :- 'profile' ?~ meta.ff ~ (user-meta:en:nostr u.meta.ff) + ~ + == + == + ++ tedfact |= pf=post-fact:ui:sur ^- json + %+ frond -.pf + (post-wrapper +.pf) + ++ postfact |= pf=post-fact:ui:sur ^- json + %+ frond -.pf + (post-wrapper +.pf) + + ++ enga |= [pw=post-wrapper:sur reaction=*] + ^- json + ~ + + ++ post-wrapper |= p=post-wrapper:sur + %- pairs + :~ post+(poast:en:trill post.p) + ['nostrMeta' (nostr-meta nostr-meta.p)] + == + ++ nostr-meta |= p=nostr-meta:sur + =| l=(list [@t json]) + =. l ?~ pub.p l :_ l ['pubkey' (hex:en:common u.pub.p)] + =. l ?~ ev-id.p l :_ l ['eventId' (hex:en:common u.ev-id.p)] + =. l ?~ relay.p l :_ l ['relay' %s u.relay.p] + =. l ?~ pr.p l :_ l ['profile' (user-meta:en:nostr u.pr.p)] + %- pairs l + + ++ beg-res |= =res:comms ^- json + %+ frond %begs %+ frond -.res + ?- -.res + %ok (resd +.res) + %ng [%s msg.res] + == + ++ resd |= rd=res-data:comms ^- json + ?- -.rd + %feed (user-data +.rd) + :: TODO wrap it for nostr shit + %thread (frond -.rd (full-node:en:trill +.rd)) + == + ++ user-data + |= ud=[=fc:feed profile=(unit user-meta:nsur)] + %: pairs + feed+(feed-with-cursor:en:trill fc.ud) + :- %profile ?~ profile.ud ~ (user-meta:en:nostr u.profile.ud) + ~ + == + -- +++ de +=, dejs-soft:format +|% +++ user + %- of :~ + urbit+(se:de:common %p) + nostr+hex:de:common + == + :: ui +++ ui + %- of :~ + keys+ul + fols+ui-fols + begs+ui-begs + prof+ui-prof + post+ui-post + rela+ui-relay + == +++ ui-fols + %- of :~ + add+user + del+user + == +++ ui-begs + %- of :~ + feed+(se:de:common %p) + thread+de-pid + == +++ de-pid + %- ot :~ + host+(se:de:common %p) + id+de-atom-id + == +++ ui-prof + %- of :~ + add+ui-meta + del+ul + == +++ ui-meta + %- ot :~ + name+so + about+so + picture+so + other+other-meta + == +++ other-meta |= jon=json + ?. ?=(%o -.jon) ~ (some p.jon) +++ ui-post + %- of :~ + add+postadd + reply+reply + quote+quote + rp+rp + :: rt+de-rt + :: del+hex:de:common + == +++ postadd + %- ot :~ + content+so + == +++ reply + %- ot :~ + content+so + host+(se:de:common %p) + id+de-atom-id + thread+de-atom-id + == +++ quote + %- ot :~ + content+so + host+(se:de:common %p) + id+de-atom-id + == +++ rp + %- ot :~ + host+(se:de:common %p) + id+de-atom-id + == +++ rt + %- ot :~ + id+hex:de:common + pubkey+hex:de:common + relay+so + == +++ ui-relay + %- of :~ + add+so + del+so + sync+ul + send+de-relay-send + == +++ de-relay-send %- ot :~ + host+(se:de:common %p) + id+de-atom-id + relays+(ar so) + == +++ de-atom-id + |= jon=json ^- (unit @) + ?. ?=([%s @t] jon) ~ + (rush p.jon dem) + + -- + +-- + diff --git a/app/lib/json/trill.hoon b/app/lib/json/trill.hoon new file mode 100644 index 0000000..415d2f4 --- /dev/null +++ b/app/lib/json/trill.hoon @@ -0,0 +1,219 @@ +/- feed=trill-feed, post=trill-post +/+ common=json-common, sr=sortug +|% +++ en +=, enjs:format + |% + ++ feed-with-cursor + |= [f=feed:^feed start=(unit @da) end=(unit @da)] ^- json + %: pairs + feed+(feed f) + start+(cursor start) + end+(cursor end) + ~ + == + ++ cursor |= c=(unit @da) + ?~ c ~ (time u.c) + ++ feed + |= f=feed:^feed ^- json + %- pairs + %+ turn (tap:orm:^feed f) + |= [post-id=@da p=post:post] + ^- [@ta json] + :- (crip (scow:sr %ud `@ud`post-id)) + (poast p) + + ++ poast + |= p=post:post ^- json + %- pairs + :~ id+(ud:en:common id.p) + host+(patp:en:common host.p) + author+(patp:en:common author.p) + thread+(ud:en:common thread.p) + parent+?~(parent.p ~ (ud:en:common u.parent.p)) + contents+(content contents.p) + hash+(b64:en:common hash.p) + engagement+(engagement engagement.p) + children+a+(turn ~(tap in children.p) ud:en:common) + time+(time id.p) + == + + ++ content + |= cm=content-map:post ^- json + =/ last (pry:corm:post cm) + ?~ last ~ + =/ blocks=content-list:post +.u.last + :- %a %+ turn blocks en-block + ++ en-block + |= b=block:post ^- json + %+ frond -.b + ?- -.b + %paragraph a+(turn p.b inline) + %blockquote a+(turn p.b inline) + %table a+(turn rows.b table-row) + %heading (heading +.b) + %list (ilist +.b) + %media (media media.b) + %codeblock (codespan +.b) + %eval s+hoon.b + %ref (en-ref +.b) + %json (external +.b) + %poll ~ + == + ++ table-row + |= l=(list content-list:post) + :- %a %+ turn l + |= b=content-list:post + :- %a %+ turn b en-block + ++ heading + |= [p=cord q=@] + %- pairs + :~ text+s+p + num+(numb q) + == + ++ ilist + |= [p=(list inline:post) q=?] + %- pairs + :~ text+a+(turn p inline) + ordered+b+q + == + ++ media + |= =media:post + %+ frond -.media + ?- -.media + %images a+(turn p.media string) + %video s+p.media + %audio s+p.media + == + ++ string + |= c=cord s+c + ++ en-ref :: TODO should the backend fetch this shit + |= [type=term s=@p p=^path] + %- pairs + :~ type+s+type + ship+(patp:en:common s) + path+(path p) + == + ++ external + |= [p=term q=cord] + %- pairs + :~ origin+s+p + content+s+q + == + ++ inline + |= i=inline:post ^- json + %+ frond -.i + ?+ -.i s+p.i + %ship (patp:en:common p.i) + %link (link +.i) + %ruby (ruby +.i) + %break ~ + == + ++ ruby + |= [p=@t q=@t] + %- pairs + :~ text+s+p + ruby+s+q + == + ++ codespan + |= [code=cord lang=cord] + %- pairs + :~ code+s+code + lang+s+lang + == + ++ link + |= [href=cord show=cord] + %- pairs + :~ href+s+href + show+s+show + == + + ++ engagement + |= =engagement:post ^- json + %- pairs + :~ reacts+(reacts reacts.engagement) + quoted+a+(turn ~(tap in quoted.engagement) signed-pid) + shared+a+(turn ~(tap in shared.engagement) signed-pid) + == + ++ reacts + |= rs=(map @p [react:post signature:post]) + ^- json + %- pairs + %+ turn ~(val by rs) + |= [r=react:post s=signature:post] + ^- [@ta json] + :- (scot %p q.s) + s+r + ++ signed-pid + |= =signed-pid:post + ^- json + %- pairs + :~ ship+(patp:en:common q.signature.signed-pid) + pid+(pid pid.signed-pid) + == + ++ time-pid + |= [t=@da s=@p =id:post] + %- pairs + :~ id+(ud:en:common id) + ship+(patp:en:common s) + time+(time t) + == + ++ time-ship + |= [t=@da s=@p] ^- json + %- pairs + :~ ship+(patp:en:common s) + time+(time t) + == + ++ mention + |= [t=@da s=@p p=pid:post] ^- json + %- pairs + :~ pid+(pid p) + ship+(patp:en:common s) + time+(time t) + == + ++ react + |= [t=@da s=@p p=pid:post react=@t] ^- json + %- pairs + :~ pid+(pid p) + ship+(patp:en:common s) + react+s+react + time+(time t) + == + ++ pid + |= =pid:post + %- pairs + :~ ship+(patp:en:common ship.pid) + id+(ud:en:common id.pid) + == + ++ full-node + |= p=full-node:post ^- json + %- pairs + :~ id+(ud:en:common id.p) + host+(patp:en:common host.p) + author+(patp:en:common author.p) + thread+(ud:en:common thread.p) + parent+?~(parent.p ~ (ud:en:common u.parent.p)) + contents+(content contents.p) + hash+(b64:en:common hash.p) + engagement+(engagement engagement.p) + children+(internal-graph children.p) + time+(time id.p) + == + ++ internal-graph + |= int=internal-graph:post ^- json + ?- -.int + %empty ~ + %full (full-graph +.int) + == + ++ full-graph + |= f=full-graph:post + ^- json + %- pairs + %+ turn (tap:form:post f) + |= [post-id=@da fn=full-node:post] + ^- [@ta json] + :- (crip (scow:sr %ud `@ud`post-id)) + (full-node fn) + :: + -- +-- |
